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"
71 #include "filestuff.h"
74 #include "gdb_string.h"
75 #include "gdb_assert.h"
76 #include <sys/types.h>
78 typedef struct symbol
*symbolp
;
81 /* When non-zero, print basic high level tracing messages.
82 This is in contrast to the low level DIE reading of dwarf2_die_debug. */
83 static int dwarf2_read_debug
= 0;
85 /* When non-zero, dump DIEs after they are read in. */
86 static unsigned int dwarf2_die_debug
= 0;
88 /* When non-zero, cross-check physname against demangler. */
89 static int check_physname
= 0;
91 /* When non-zero, do not reject deprecated .gdb_index sections. */
92 static int use_deprecated_index_sections
= 0;
94 static const struct objfile_data
*dwarf2_objfile_data_key
;
96 /* The "aclass" indices for various kinds of computed DWARF symbols. */
98 static int dwarf2_locexpr_index
;
99 static int dwarf2_loclist_index
;
100 static int dwarf2_locexpr_block_index
;
101 static int dwarf2_loclist_block_index
;
103 struct dwarf2_section_info
106 const gdb_byte
*buffer
;
108 /* True if we have tried to read this section. */
112 typedef struct dwarf2_section_info dwarf2_section_info_def
;
113 DEF_VEC_O (dwarf2_section_info_def
);
115 /* All offsets in the index are of this type. It must be
116 architecture-independent. */
117 typedef uint32_t offset_type
;
119 DEF_VEC_I (offset_type
);
121 /* Ensure only legit values are used. */
122 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
124 gdb_assert ((unsigned int) (value) <= 1); \
125 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
128 /* Ensure only legit values are used. */
129 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
131 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
132 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
133 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
136 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
137 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
139 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
140 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
143 /* A description of the mapped index. The file format is described in
144 a comment by the code that writes the index. */
147 /* Index data format version. */
150 /* The total length of the buffer. */
153 /* A pointer to the address table data. */
154 const gdb_byte
*address_table
;
156 /* Size of the address table data in bytes. */
157 offset_type address_table_size
;
159 /* The symbol table, implemented as a hash table. */
160 const offset_type
*symbol_table
;
162 /* Size in slots, each slot is 2 offset_types. */
163 offset_type symbol_table_slots
;
165 /* A pointer to the constant pool. */
166 const char *constant_pool
;
169 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
170 DEF_VEC_P (dwarf2_per_cu_ptr
);
172 /* Collection of data recorded per objfile.
173 This hangs off of dwarf2_objfile_data_key. */
175 struct dwarf2_per_objfile
177 struct dwarf2_section_info info
;
178 struct dwarf2_section_info abbrev
;
179 struct dwarf2_section_info line
;
180 struct dwarf2_section_info loc
;
181 struct dwarf2_section_info macinfo
;
182 struct dwarf2_section_info macro
;
183 struct dwarf2_section_info str
;
184 struct dwarf2_section_info ranges
;
185 struct dwarf2_section_info addr
;
186 struct dwarf2_section_info frame
;
187 struct dwarf2_section_info eh_frame
;
188 struct dwarf2_section_info gdb_index
;
190 VEC (dwarf2_section_info_def
) *types
;
193 struct objfile
*objfile
;
195 /* Table of all the compilation units. This is used to locate
196 the target compilation unit of a particular reference. */
197 struct dwarf2_per_cu_data
**all_comp_units
;
199 /* The number of compilation units in ALL_COMP_UNITS. */
202 /* The number of .debug_types-related CUs. */
205 /* The .debug_types-related CUs (TUs).
206 This is stored in malloc space because we may realloc it. */
207 struct signatured_type
**all_type_units
;
209 /* The number of entries in all_type_unit_groups. */
210 int n_type_unit_groups
;
212 /* Table of type unit groups.
213 This exists to make it easy to iterate over all CUs and TU groups. */
214 struct type_unit_group
**all_type_unit_groups
;
216 /* Table of struct type_unit_group objects.
217 The hash key is the DW_AT_stmt_list value. */
218 htab_t type_unit_groups
;
220 /* A table mapping .debug_types signatures to its signatured_type entry.
221 This is NULL if the .debug_types section hasn't been read in yet. */
222 htab_t signatured_types
;
224 /* Type unit statistics, to see how well the scaling improvements
228 int nr_uniq_abbrev_tables
;
230 int nr_symtab_sharers
;
231 int nr_stmt_less_type_units
;
234 /* A chain of compilation units that are currently read in, so that
235 they can be freed later. */
236 struct dwarf2_per_cu_data
*read_in_chain
;
238 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
239 This is NULL if the table hasn't been allocated yet. */
242 /* Non-zero if we've check for whether there is a DWP file. */
245 /* The DWP file if there is one, or NULL. */
246 struct dwp_file
*dwp_file
;
248 /* The shared '.dwz' file, if one exists. This is used when the
249 original data was compressed using 'dwz -m'. */
250 struct dwz_file
*dwz_file
;
252 /* A flag indicating wether this objfile has a section loaded at a
254 int has_section_at_zero
;
256 /* True if we are using the mapped index,
257 or we are faking it for OBJF_READNOW's sake. */
258 unsigned char using_index
;
260 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
261 struct mapped_index
*index_table
;
263 /* When using index_table, this keeps track of all quick_file_names entries.
264 TUs typically share line table entries with a CU, so we maintain a
265 separate table of all line table entries to support the sharing.
266 Note that while there can be way more TUs than CUs, we've already
267 sorted all the TUs into "type unit groups", grouped by their
268 DW_AT_stmt_list value. Therefore the only sharing done here is with a
269 CU and its associated TU group if there is one. */
270 htab_t quick_file_names_table
;
272 /* Set during partial symbol reading, to prevent queueing of full
274 int reading_partial_symbols
;
276 /* Table mapping type DIEs to their struct type *.
277 This is NULL if not allocated yet.
278 The mapping is done via (CU/TU + DIE offset) -> type. */
279 htab_t die_type_hash
;
281 /* The CUs we recently read. */
282 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
285 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
287 /* Default names of the debugging sections. */
289 /* Note that if the debugging section has been compressed, it might
290 have a name like .zdebug_info. */
292 static const struct dwarf2_debug_sections dwarf2_elf_names
=
294 { ".debug_info", ".zdebug_info" },
295 { ".debug_abbrev", ".zdebug_abbrev" },
296 { ".debug_line", ".zdebug_line" },
297 { ".debug_loc", ".zdebug_loc" },
298 { ".debug_macinfo", ".zdebug_macinfo" },
299 { ".debug_macro", ".zdebug_macro" },
300 { ".debug_str", ".zdebug_str" },
301 { ".debug_ranges", ".zdebug_ranges" },
302 { ".debug_types", ".zdebug_types" },
303 { ".debug_addr", ".zdebug_addr" },
304 { ".debug_frame", ".zdebug_frame" },
305 { ".eh_frame", NULL
},
306 { ".gdb_index", ".zgdb_index" },
310 /* List of DWO/DWP sections. */
312 static const struct dwop_section_names
314 struct dwarf2_section_names abbrev_dwo
;
315 struct dwarf2_section_names info_dwo
;
316 struct dwarf2_section_names line_dwo
;
317 struct dwarf2_section_names loc_dwo
;
318 struct dwarf2_section_names macinfo_dwo
;
319 struct dwarf2_section_names macro_dwo
;
320 struct dwarf2_section_names str_dwo
;
321 struct dwarf2_section_names str_offsets_dwo
;
322 struct dwarf2_section_names types_dwo
;
323 struct dwarf2_section_names cu_index
;
324 struct dwarf2_section_names tu_index
;
328 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
329 { ".debug_info.dwo", ".zdebug_info.dwo" },
330 { ".debug_line.dwo", ".zdebug_line.dwo" },
331 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
332 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
333 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
334 { ".debug_str.dwo", ".zdebug_str.dwo" },
335 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
336 { ".debug_types.dwo", ".zdebug_types.dwo" },
337 { ".debug_cu_index", ".zdebug_cu_index" },
338 { ".debug_tu_index", ".zdebug_tu_index" },
341 /* local data types */
343 /* The data in a compilation unit header, after target2host
344 translation, looks like this. */
345 struct comp_unit_head
349 unsigned char addr_size
;
350 unsigned char signed_addr_p
;
351 sect_offset abbrev_offset
;
353 /* Size of file offsets; either 4 or 8. */
354 unsigned int offset_size
;
356 /* Size of the length field; either 4 or 12. */
357 unsigned int initial_length_size
;
359 /* Offset to the first byte of this compilation unit header in the
360 .debug_info section, for resolving relative reference dies. */
363 /* Offset to first die in this cu from the start of the cu.
364 This will be the first byte following the compilation unit header. */
365 cu_offset first_die_offset
;
368 /* Type used for delaying computation of method physnames.
369 See comments for compute_delayed_physnames. */
370 struct delayed_method_info
372 /* The type to which the method is attached, i.e., its parent class. */
375 /* The index of the method in the type's function fieldlists. */
378 /* The index of the method in the fieldlist. */
381 /* The name of the DIE. */
384 /* The DIE associated with this method. */
385 struct die_info
*die
;
388 typedef struct delayed_method_info delayed_method_info
;
389 DEF_VEC_O (delayed_method_info
);
391 /* Internal state when decoding a particular compilation unit. */
394 /* The objfile containing this compilation unit. */
395 struct objfile
*objfile
;
397 /* The header of the compilation unit. */
398 struct comp_unit_head header
;
400 /* Base address of this compilation unit. */
401 CORE_ADDR base_address
;
403 /* Non-zero if base_address has been set. */
406 /* The language we are debugging. */
407 enum language language
;
408 const struct language_defn
*language_defn
;
410 const char *producer
;
412 /* The generic symbol table building routines have separate lists for
413 file scope symbols and all all other scopes (local scopes). So
414 we need to select the right one to pass to add_symbol_to_list().
415 We do it by keeping a pointer to the correct list in list_in_scope.
417 FIXME: The original dwarf code just treated the file scope as the
418 first local scope, and all other local scopes as nested local
419 scopes, and worked fine. Check to see if we really need to
420 distinguish these in buildsym.c. */
421 struct pending
**list_in_scope
;
423 /* The abbrev table for this CU.
424 Normally this points to the abbrev table in the objfile.
425 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
426 struct abbrev_table
*abbrev_table
;
428 /* Hash table holding all the loaded partial DIEs
429 with partial_die->offset.SECT_OFF as hash. */
432 /* Storage for things with the same lifetime as this read-in compilation
433 unit, including partial DIEs. */
434 struct obstack comp_unit_obstack
;
436 /* When multiple dwarf2_cu structures are living in memory, this field
437 chains them all together, so that they can be released efficiently.
438 We will probably also want a generation counter so that most-recently-used
439 compilation units are cached... */
440 struct dwarf2_per_cu_data
*read_in_chain
;
442 /* Backchain to our per_cu entry if the tree has been built. */
443 struct dwarf2_per_cu_data
*per_cu
;
445 /* How many compilation units ago was this CU last referenced? */
448 /* A hash table of DIE cu_offset for following references with
449 die_info->offset.sect_off as hash. */
452 /* Full DIEs if read in. */
453 struct die_info
*dies
;
455 /* A set of pointers to dwarf2_per_cu_data objects for compilation
456 units referenced by this one. Only set during full symbol processing;
457 partial symbol tables do not have dependencies. */
460 /* Header data from the line table, during full symbol processing. */
461 struct line_header
*line_header
;
463 /* A list of methods which need to have physnames computed
464 after all type information has been read. */
465 VEC (delayed_method_info
) *method_list
;
467 /* To be copied to symtab->call_site_htab. */
468 htab_t call_site_htab
;
470 /* Non-NULL if this CU came from a DWO file.
471 There is an invariant here that is important to remember:
472 Except for attributes copied from the top level DIE in the "main"
473 (or "stub") file in preparation for reading the DWO file
474 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
475 Either there isn't a DWO file (in which case this is NULL and the point
476 is moot), or there is and either we're not going to read it (in which
477 case this is NULL) or there is and we are reading it (in which case this
479 struct dwo_unit
*dwo_unit
;
481 /* The DW_AT_addr_base attribute if present, zero otherwise
482 (zero is a valid value though).
483 Note this value comes from the stub CU/TU's DIE. */
486 /* The DW_AT_ranges_base attribute if present, zero otherwise
487 (zero is a valid value though).
488 Note this value comes from the stub CU/TU's DIE.
489 Also note that the value is zero in the non-DWO case so this value can
490 be used without needing to know whether DWO files are in use or not.
491 N.B. This does not apply to DW_AT_ranges appearing in
492 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
493 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
494 DW_AT_ranges_base *would* have to be applied, and we'd have to care
495 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
496 ULONGEST ranges_base
;
498 /* Mark used when releasing cached dies. */
499 unsigned int mark
: 1;
501 /* This CU references .debug_loc. See the symtab->locations_valid field.
502 This test is imperfect as there may exist optimized debug code not using
503 any location list and still facing inlining issues if handled as
504 unoptimized code. For a future better test see GCC PR other/32998. */
505 unsigned int has_loclist
: 1;
507 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
508 if all the producer_is_* fields are valid. This information is cached
509 because profiling CU expansion showed excessive time spent in
510 producer_is_gxx_lt_4_6. */
511 unsigned int checked_producer
: 1;
512 unsigned int producer_is_gxx_lt_4_6
: 1;
513 unsigned int producer_is_gcc_lt_4_3
: 1;
514 unsigned int producer_is_icc
: 1;
516 /* When set, the file that we're processing is known to have
517 debugging info for C++ namespaces. GCC 3.3.x did not produce
518 this information, but later versions do. */
520 unsigned int processing_has_namespace_info
: 1;
523 /* Persistent data held for a compilation unit, even when not
524 processing it. We put a pointer to this structure in the
525 read_symtab_private field of the psymtab. */
527 struct dwarf2_per_cu_data
529 /* The start offset and length of this compilation unit.
530 NOTE: Unlike comp_unit_head.length, this length includes
532 If the DIE refers to a DWO file, this is always of the original die,
537 /* Flag indicating this compilation unit will be read in before
538 any of the current compilation units are processed. */
539 unsigned int queued
: 1;
541 /* This flag will be set when reading partial DIEs if we need to load
542 absolutely all DIEs for this compilation unit, instead of just the ones
543 we think are interesting. It gets set if we look for a DIE in the
544 hash table and don't find it. */
545 unsigned int load_all_dies
: 1;
547 /* Non-zero if this CU is from .debug_types.
548 Struct dwarf2_per_cu_data is contained in struct signatured_type iff
550 unsigned int is_debug_types
: 1;
552 /* Non-zero if this CU is from the .dwz file. */
553 unsigned int is_dwz
: 1;
555 /* Non-zero if reading a TU directly from a DWO file, bypassing the stub.
556 This flag is only valid if is_debug_types is true.
557 We can't read a CU directly from a DWO file: There are required
558 attributes in the stub. */
559 unsigned int reading_dwo_directly
: 1;
561 /* The section this CU/TU lives in.
562 If the DIE refers to a DWO file, this is always the original die,
564 struct dwarf2_section_info
*section
;
566 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
567 of the CU cache it gets reset to NULL again. */
568 struct dwarf2_cu
*cu
;
570 /* The corresponding objfile.
571 Normally we can get the objfile from dwarf2_per_objfile.
572 However we can enter this file with just a "per_cu" handle. */
573 struct objfile
*objfile
;
575 /* When using partial symbol tables, the 'psymtab' field is active.
576 Otherwise the 'quick' field is active. */
579 /* The partial symbol table associated with this compilation unit,
580 or NULL for unread partial units. */
581 struct partial_symtab
*psymtab
;
583 /* Data needed by the "quick" functions. */
584 struct dwarf2_per_cu_quick_data
*quick
;
587 /* The CUs we import using DW_TAG_imported_unit. This is filled in
588 while reading psymtabs, used to compute the psymtab dependencies,
589 and then cleared. Then it is filled in again while reading full
590 symbols, and only deleted when the objfile is destroyed.
592 This is also used to work around a difference between the way gold
593 generates .gdb_index version <=7 and the way gdb does. Arguably this
594 is a gold bug. For symbols coming from TUs, gold records in the index
595 the CU that includes the TU instead of the TU itself. This breaks
596 dw2_lookup_symbol: It assumes that if the index says symbol X lives
597 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
598 will find X. Alas TUs live in their own symtab, so after expanding CU Y
599 we need to look in TU Z to find X. Fortunately, this is akin to
600 DW_TAG_imported_unit, so we just use the same mechanism: For
601 .gdb_index version <=7 this also records the TUs that the CU referred
602 to. Concurrently with this change gdb was modified to emit version 8
603 indices so we only pay a price for gold generated indices. */
604 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
607 /* Entry in the signatured_types hash table. */
609 struct signatured_type
611 /* The "per_cu" object of this type.
612 This struct is used iff per_cu.is_debug_types.
613 N.B.: This is the first member so that it's easy to convert pointers
615 struct dwarf2_per_cu_data per_cu
;
617 /* The type's signature. */
620 /* Offset in the TU of the type's DIE, as read from the TU header.
621 If this TU is a DWO stub and the definition lives in a DWO file
622 (specified by DW_AT_GNU_dwo_name), this value is unusable. */
623 cu_offset type_offset_in_tu
;
625 /* Offset in the section of the type's DIE.
626 If the definition lives in a DWO file, this is the offset in the
627 .debug_types.dwo section.
628 The value is zero until the actual value is known.
629 Zero is otherwise not a valid section offset. */
630 sect_offset type_offset_in_section
;
632 /* Type units are grouped by their DW_AT_stmt_list entry so that they
633 can share them. This points to the containing symtab. */
634 struct type_unit_group
*type_unit_group
;
637 The first time we encounter this type we fully read it in and install it
638 in the symbol tables. Subsequent times we only need the type. */
641 /* Containing DWO unit.
642 This field is valid iff per_cu.reading_dwo_directly. */
643 struct dwo_unit
*dwo_unit
;
646 typedef struct signatured_type
*sig_type_ptr
;
647 DEF_VEC_P (sig_type_ptr
);
649 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
650 This includes type_unit_group and quick_file_names. */
652 struct stmt_list_hash
654 /* The DWO unit this table is from or NULL if there is none. */
655 struct dwo_unit
*dwo_unit
;
657 /* Offset in .debug_line or .debug_line.dwo. */
658 sect_offset line_offset
;
661 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
662 an object of this type. */
664 struct type_unit_group
666 /* dwarf2read.c's main "handle" on a TU symtab.
667 To simplify things we create an artificial CU that "includes" all the
668 type units using this stmt_list so that the rest of the code still has
669 a "per_cu" handle on the symtab.
670 This PER_CU is recognized by having no section. */
671 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
672 struct dwarf2_per_cu_data per_cu
;
674 /* The TUs that share this DW_AT_stmt_list entry.
675 This is added to while parsing type units to build partial symtabs,
676 and is deleted afterwards and not used again. */
677 VEC (sig_type_ptr
) *tus
;
679 /* The primary symtab.
680 Type units in a group needn't all be defined in the same source file,
681 so we create an essentially anonymous symtab as the primary symtab. */
682 struct symtab
*primary_symtab
;
684 /* The data used to construct the hash key. */
685 struct stmt_list_hash hash
;
687 /* The number of symtabs from the line header.
688 The value here must match line_header.num_file_names. */
689 unsigned int num_symtabs
;
691 /* The symbol tables for this TU (obtained from the files listed in
693 WARNING: The order of entries here must match the order of entries
694 in the line header. After the first TU using this type_unit_group, the
695 line header for the subsequent TUs is recreated from this. This is done
696 because we need to use the same symtabs for each TU using the same
697 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
698 there's no guarantee the line header doesn't have duplicate entries. */
699 struct symtab
**symtabs
;
702 /* These sections are what may appear in a DWO file. */
706 struct dwarf2_section_info abbrev
;
707 struct dwarf2_section_info line
;
708 struct dwarf2_section_info loc
;
709 struct dwarf2_section_info macinfo
;
710 struct dwarf2_section_info macro
;
711 struct dwarf2_section_info str
;
712 struct dwarf2_section_info str_offsets
;
713 /* In the case of a virtual DWO file, these two are unused. */
714 struct dwarf2_section_info info
;
715 VEC (dwarf2_section_info_def
) *types
;
718 /* CUs/TUs in DWP/DWO files. */
722 /* Backlink to the containing struct dwo_file. */
723 struct dwo_file
*dwo_file
;
725 /* The "id" that distinguishes this CU/TU.
726 .debug_info calls this "dwo_id", .debug_types calls this "signature".
727 Since signatures came first, we stick with it for consistency. */
730 /* The section this CU/TU lives in, in the DWO file. */
731 struct dwarf2_section_info
*section
;
733 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
737 /* For types, offset in the type's DIE of the type defined by this TU. */
738 cu_offset type_offset_in_tu
;
741 /* Data for one DWO file.
742 This includes virtual DWO files that have been packaged into a
747 /* The DW_AT_GNU_dwo_name attribute.
748 For virtual DWO files the name is constructed from the section offsets
749 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
750 from related CU+TUs. */
751 const char *dwo_name
;
753 /* The DW_AT_comp_dir attribute. */
754 const char *comp_dir
;
756 /* The bfd, when the file is open. Otherwise this is NULL.
757 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
760 /* Section info for this file. */
761 struct dwo_sections sections
;
763 /* The CU in the file.
764 We only support one because having more than one requires hacking the
765 dwo_name of each to match, which is highly unlikely to happen.
766 Doing this means all TUs can share comp_dir: We also assume that
767 DW_AT_comp_dir across all TUs in a DWO file will be identical. */
770 /* Table of TUs in the file.
771 Each element is a struct dwo_unit. */
775 /* These sections are what may appear in a DWP file. */
779 struct dwarf2_section_info str
;
780 struct dwarf2_section_info cu_index
;
781 struct dwarf2_section_info tu_index
;
782 /* The .debug_info.dwo, .debug_types.dwo, and other sections are referenced
783 by section number. We don't need to record them here. */
786 /* These sections are what may appear in a virtual DWO file. */
788 struct virtual_dwo_sections
790 struct dwarf2_section_info abbrev
;
791 struct dwarf2_section_info line
;
792 struct dwarf2_section_info loc
;
793 struct dwarf2_section_info macinfo
;
794 struct dwarf2_section_info macro
;
795 struct dwarf2_section_info str_offsets
;
796 /* Each DWP hash table entry records one CU or one TU.
797 That is recorded here, and copied to dwo_unit.section. */
798 struct dwarf2_section_info info_or_types
;
801 /* Contents of DWP hash tables. */
803 struct dwp_hash_table
805 uint32_t nr_units
, nr_slots
;
806 const gdb_byte
*hash_table
, *unit_table
, *section_pool
;
809 /* Data for one DWP file. */
813 /* Name of the file. */
816 /* The bfd, when the file is open. Otherwise this is NULL. */
819 /* Section info for this file. */
820 struct dwp_sections sections
;
822 /* Table of CUs in the file. */
823 const struct dwp_hash_table
*cus
;
825 /* Table of TUs in the file. */
826 const struct dwp_hash_table
*tus
;
828 /* Table of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
831 /* Table to map ELF section numbers to their sections. */
832 unsigned int num_sections
;
833 asection
**elf_sections
;
836 /* This represents a '.dwz' file. */
840 /* A dwz file can only contain a few sections. */
841 struct dwarf2_section_info abbrev
;
842 struct dwarf2_section_info info
;
843 struct dwarf2_section_info str
;
844 struct dwarf2_section_info line
;
845 struct dwarf2_section_info macro
;
846 struct dwarf2_section_info gdb_index
;
852 /* Struct used to pass misc. parameters to read_die_and_children, et
853 al. which are used for both .debug_info and .debug_types dies.
854 All parameters here are unchanging for the life of the call. This
855 struct exists to abstract away the constant parameters of die reading. */
857 struct die_reader_specs
859 /* die_section->asection->owner. */
862 /* The CU of the DIE we are parsing. */
863 struct dwarf2_cu
*cu
;
865 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
866 struct dwo_file
*dwo_file
;
868 /* The section the die comes from.
869 This is either .debug_info or .debug_types, or the .dwo variants. */
870 struct dwarf2_section_info
*die_section
;
872 /* die_section->buffer. */
873 const gdb_byte
*buffer
;
875 /* The end of the buffer. */
876 const gdb_byte
*buffer_end
;
878 /* The value of the DW_AT_comp_dir attribute. */
879 const char *comp_dir
;
882 /* Type of function passed to init_cutu_and_read_dies, et.al. */
883 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
884 const gdb_byte
*info_ptr
,
885 struct die_info
*comp_unit_die
,
889 /* The line number information for a compilation unit (found in the
890 .debug_line section) begins with a "statement program header",
891 which contains the following information. */
894 unsigned int total_length
;
895 unsigned short version
;
896 unsigned int header_length
;
897 unsigned char minimum_instruction_length
;
898 unsigned char maximum_ops_per_instruction
;
899 unsigned char default_is_stmt
;
901 unsigned char line_range
;
902 unsigned char opcode_base
;
904 /* standard_opcode_lengths[i] is the number of operands for the
905 standard opcode whose value is i. This means that
906 standard_opcode_lengths[0] is unused, and the last meaningful
907 element is standard_opcode_lengths[opcode_base - 1]. */
908 unsigned char *standard_opcode_lengths
;
910 /* The include_directories table. NOTE! These strings are not
911 allocated with xmalloc; instead, they are pointers into
912 debug_line_buffer. If you try to free them, `free' will get
914 unsigned int num_include_dirs
, include_dirs_size
;
915 const char **include_dirs
;
917 /* The file_names table. NOTE! These strings are not allocated
918 with xmalloc; instead, they are pointers into debug_line_buffer.
919 Don't try to free them directly. */
920 unsigned int num_file_names
, file_names_size
;
924 unsigned int dir_index
;
925 unsigned int mod_time
;
927 int included_p
; /* Non-zero if referenced by the Line Number Program. */
928 struct symtab
*symtab
; /* The associated symbol table, if any. */
931 /* The start and end of the statement program following this
932 header. These point into dwarf2_per_objfile->line_buffer. */
933 const gdb_byte
*statement_program_start
, *statement_program_end
;
936 /* When we construct a partial symbol table entry we only
937 need this much information. */
938 struct partial_die_info
940 /* Offset of this DIE. */
943 /* DWARF-2 tag for this DIE. */
944 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
946 /* Assorted flags describing the data found in this DIE. */
947 unsigned int has_children
: 1;
948 unsigned int is_external
: 1;
949 unsigned int is_declaration
: 1;
950 unsigned int has_type
: 1;
951 unsigned int has_specification
: 1;
952 unsigned int has_pc_info
: 1;
953 unsigned int may_be_inlined
: 1;
955 /* Flag set if the SCOPE field of this structure has been
957 unsigned int scope_set
: 1;
959 /* Flag set if the DIE has a byte_size attribute. */
960 unsigned int has_byte_size
: 1;
962 /* Flag set if any of the DIE's children are template arguments. */
963 unsigned int has_template_arguments
: 1;
965 /* Flag set if fixup_partial_die has been called on this die. */
966 unsigned int fixup_called
: 1;
968 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
969 unsigned int is_dwz
: 1;
971 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
972 unsigned int spec_is_dwz
: 1;
974 /* The name of this DIE. Normally the value of DW_AT_name, but
975 sometimes a default name for unnamed DIEs. */
978 /* The linkage name, if present. */
979 const char *linkage_name
;
981 /* The scope to prepend to our children. This is generally
982 allocated on the comp_unit_obstack, so will disappear
983 when this compilation unit leaves the cache. */
986 /* Some data associated with the partial DIE. The tag determines
987 which field is live. */
990 /* The location description associated with this DIE, if any. */
991 struct dwarf_block
*locdesc
;
992 /* The offset of an import, for DW_TAG_imported_unit. */
996 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1000 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1001 DW_AT_sibling, if any. */
1002 /* NOTE: This member isn't strictly necessary, read_partial_die could
1003 return DW_AT_sibling values to its caller load_partial_dies. */
1004 const gdb_byte
*sibling
;
1006 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1007 DW_AT_specification (or DW_AT_abstract_origin or
1008 DW_AT_extension). */
1009 sect_offset spec_offset
;
1011 /* Pointers to this DIE's parent, first child, and next sibling,
1013 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
1016 /* This data structure holds the information of an abbrev. */
1019 unsigned int number
; /* number identifying abbrev */
1020 enum dwarf_tag tag
; /* dwarf tag */
1021 unsigned short has_children
; /* boolean */
1022 unsigned short num_attrs
; /* number of attributes */
1023 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1024 struct abbrev_info
*next
; /* next in chain */
1029 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1030 ENUM_BITFIELD(dwarf_form
) form
: 16;
1033 /* Size of abbrev_table.abbrev_hash_table. */
1034 #define ABBREV_HASH_SIZE 121
1036 /* Top level data structure to contain an abbreviation table. */
1040 /* Where the abbrev table came from.
1041 This is used as a sanity check when the table is used. */
1044 /* Storage for the abbrev table. */
1045 struct obstack abbrev_obstack
;
1047 /* Hash table of abbrevs.
1048 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1049 It could be statically allocated, but the previous code didn't so we
1051 struct abbrev_info
**abbrevs
;
1054 /* Attributes have a name and a value. */
1057 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1058 ENUM_BITFIELD(dwarf_form
) form
: 15;
1060 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1061 field should be in u.str (existing only for DW_STRING) but it is kept
1062 here for better struct attribute alignment. */
1063 unsigned int string_is_canonical
: 1;
1068 struct dwarf_block
*blk
;
1077 /* This data structure holds a complete die structure. */
1080 /* DWARF-2 tag for this DIE. */
1081 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1083 /* Number of attributes */
1084 unsigned char num_attrs
;
1086 /* True if we're presently building the full type name for the
1087 type derived from this DIE. */
1088 unsigned char building_fullname
: 1;
1091 unsigned int abbrev
;
1093 /* Offset in .debug_info or .debug_types section. */
1096 /* The dies in a compilation unit form an n-ary tree. PARENT
1097 points to this die's parent; CHILD points to the first child of
1098 this node; and all the children of a given node are chained
1099 together via their SIBLING fields. */
1100 struct die_info
*child
; /* Its first child, if any. */
1101 struct die_info
*sibling
; /* Its next sibling, if any. */
1102 struct die_info
*parent
; /* Its parent, if any. */
1104 /* An array of attributes, with NUM_ATTRS elements. There may be
1105 zero, but it's not common and zero-sized arrays are not
1106 sufficiently portable C. */
1107 struct attribute attrs
[1];
1110 /* Get at parts of an attribute structure. */
1112 #define DW_STRING(attr) ((attr)->u.str)
1113 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1114 #define DW_UNSND(attr) ((attr)->u.unsnd)
1115 #define DW_BLOCK(attr) ((attr)->u.blk)
1116 #define DW_SND(attr) ((attr)->u.snd)
1117 #define DW_ADDR(attr) ((attr)->u.addr)
1118 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1120 /* Blocks are a bunch of untyped bytes. */
1125 /* Valid only if SIZE is not zero. */
1126 const gdb_byte
*data
;
1129 #ifndef ATTR_ALLOC_CHUNK
1130 #define ATTR_ALLOC_CHUNK 4
1133 /* Allocate fields for structs, unions and enums in this size. */
1134 #ifndef DW_FIELD_ALLOC_CHUNK
1135 #define DW_FIELD_ALLOC_CHUNK 4
1138 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1139 but this would require a corresponding change in unpack_field_as_long
1141 static int bits_per_byte
= 8;
1143 /* The routines that read and process dies for a C struct or C++ class
1144 pass lists of data member fields and lists of member function fields
1145 in an instance of a field_info structure, as defined below. */
1148 /* List of data member and baseclasses fields. */
1151 struct nextfield
*next
;
1156 *fields
, *baseclasses
;
1158 /* Number of fields (including baseclasses). */
1161 /* Number of baseclasses. */
1164 /* Set if the accesibility of one of the fields is not public. */
1165 int non_public_fields
;
1167 /* Member function fields array, entries are allocated in the order they
1168 are encountered in the object file. */
1171 struct nextfnfield
*next
;
1172 struct fn_field fnfield
;
1176 /* Member function fieldlist array, contains name of possibly overloaded
1177 member function, number of overloaded member functions and a pointer
1178 to the head of the member function field chain. */
1183 struct nextfnfield
*head
;
1187 /* Number of entries in the fnfieldlists array. */
1190 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1191 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1192 struct typedef_field_list
1194 struct typedef_field field
;
1195 struct typedef_field_list
*next
;
1197 *typedef_field_list
;
1198 unsigned typedef_field_list_count
;
1201 /* One item on the queue of compilation units to read in full symbols
1203 struct dwarf2_queue_item
1205 struct dwarf2_per_cu_data
*per_cu
;
1206 enum language pretend_language
;
1207 struct dwarf2_queue_item
*next
;
1210 /* The current queue. */
1211 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1213 /* Loaded secondary compilation units are kept in memory until they
1214 have not been referenced for the processing of this many
1215 compilation units. Set this to zero to disable caching. Cache
1216 sizes of up to at least twenty will improve startup time for
1217 typical inter-CU-reference binaries, at an obvious memory cost. */
1218 static int dwarf2_max_cache_age
= 5;
1220 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
1221 struct cmd_list_element
*c
, const char *value
)
1223 fprintf_filtered (file
, _("The upper bound on the age of cached "
1224 "dwarf2 compilation units is %s.\n"),
1229 /* Various complaints about symbol reading that don't abort the process. */
1232 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1234 complaint (&symfile_complaints
,
1235 _("statement list doesn't fit in .debug_line section"));
1239 dwarf2_debug_line_missing_file_complaint (void)
1241 complaint (&symfile_complaints
,
1242 _(".debug_line section has line data without a file"));
1246 dwarf2_debug_line_missing_end_sequence_complaint (void)
1248 complaint (&symfile_complaints
,
1249 _(".debug_line section has line "
1250 "program sequence without an end"));
1254 dwarf2_complex_location_expr_complaint (void)
1256 complaint (&symfile_complaints
, _("location expression too complex"));
1260 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1263 complaint (&symfile_complaints
,
1264 _("const value length mismatch for '%s', got %d, expected %d"),
1269 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1271 complaint (&symfile_complaints
,
1272 _("debug info runs off end of %s section"
1274 section
->asection
->name
,
1275 bfd_get_filename (section
->asection
->owner
));
1279 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1281 complaint (&symfile_complaints
,
1282 _("macro debug info contains a "
1283 "malformed macro definition:\n`%s'"),
1288 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1290 complaint (&symfile_complaints
,
1291 _("invalid attribute class or form for '%s' in '%s'"),
1295 /* local function prototypes */
1297 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1299 static void dwarf2_find_base_address (struct die_info
*die
,
1300 struct dwarf2_cu
*cu
);
1302 static struct partial_symtab
*create_partial_symtab
1303 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1305 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1307 static void scan_partial_symbols (struct partial_die_info
*,
1308 CORE_ADDR
*, CORE_ADDR
*,
1309 int, struct dwarf2_cu
*);
1311 static void add_partial_symbol (struct partial_die_info
*,
1312 struct dwarf2_cu
*);
1314 static void add_partial_namespace (struct partial_die_info
*pdi
,
1315 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1316 int need_pc
, struct dwarf2_cu
*cu
);
1318 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1319 CORE_ADDR
*highpc
, int need_pc
,
1320 struct dwarf2_cu
*cu
);
1322 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1323 struct dwarf2_cu
*cu
);
1325 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1326 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1327 int need_pc
, struct dwarf2_cu
*cu
);
1329 static void dwarf2_read_symtab (struct partial_symtab
*,
1332 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1334 static struct abbrev_info
*abbrev_table_lookup_abbrev
1335 (const struct abbrev_table
*, unsigned int);
1337 static struct abbrev_table
*abbrev_table_read_table
1338 (struct dwarf2_section_info
*, sect_offset
);
1340 static void abbrev_table_free (struct abbrev_table
*);
1342 static void abbrev_table_free_cleanup (void *);
1344 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1345 struct dwarf2_section_info
*);
1347 static void dwarf2_free_abbrev_table (void *);
1349 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1351 static struct partial_die_info
*load_partial_dies
1352 (const struct die_reader_specs
*, const gdb_byte
*, int);
1354 static const gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1355 struct partial_die_info
*,
1356 struct abbrev_info
*,
1360 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1361 struct dwarf2_cu
*);
1363 static void fixup_partial_die (struct partial_die_info
*,
1364 struct dwarf2_cu
*);
1366 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1367 struct attribute
*, struct attr_abbrev
*,
1370 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1372 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1374 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1376 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1378 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1380 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1383 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1385 static LONGEST read_checked_initial_length_and_offset
1386 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1387 unsigned int *, unsigned int *);
1389 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1390 const struct comp_unit_head
*,
1393 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1395 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1398 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1400 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1402 static const char *read_indirect_string (bfd
*, const gdb_byte
*,
1403 const struct comp_unit_head
*,
1406 static const char *read_indirect_string_from_dwz (struct dwz_file
*, LONGEST
);
1408 static ULONGEST
read_unsigned_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1410 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1412 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1416 static const char *read_str_index (const struct die_reader_specs
*reader
,
1417 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1419 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1421 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1422 struct dwarf2_cu
*);
1424 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1427 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1428 struct dwarf2_cu
*cu
);
1430 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1432 static struct die_info
*die_specification (struct die_info
*die
,
1433 struct dwarf2_cu
**);
1435 static void free_line_header (struct line_header
*lh
);
1437 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1438 struct dwarf2_cu
*cu
);
1440 static void dwarf_decode_lines (struct line_header
*, const char *,
1441 struct dwarf2_cu
*, struct partial_symtab
*,
1444 static void dwarf2_start_subfile (const char *, const char *, const char *);
1446 static void dwarf2_start_symtab (struct dwarf2_cu
*,
1447 const char *, const char *, CORE_ADDR
);
1449 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1450 struct dwarf2_cu
*);
1452 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1453 struct dwarf2_cu
*, struct symbol
*);
1455 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1456 struct dwarf2_cu
*);
1458 static void dwarf2_const_value_attr (struct attribute
*attr
,
1461 struct obstack
*obstack
,
1462 struct dwarf2_cu
*cu
, LONGEST
*value
,
1463 const gdb_byte
**bytes
,
1464 struct dwarf2_locexpr_baton
**baton
);
1466 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1468 static int need_gnat_info (struct dwarf2_cu
*);
1470 static struct type
*die_descriptive_type (struct die_info
*,
1471 struct dwarf2_cu
*);
1473 static void set_descriptive_type (struct type
*, struct die_info
*,
1474 struct dwarf2_cu
*);
1476 static struct type
*die_containing_type (struct die_info
*,
1477 struct dwarf2_cu
*);
1479 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1480 struct dwarf2_cu
*);
1482 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1484 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1486 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1488 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1489 const char *suffix
, int physname
,
1490 struct dwarf2_cu
*cu
);
1492 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1494 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1496 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1498 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1500 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1502 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1503 struct dwarf2_cu
*, struct partial_symtab
*);
1505 static int dwarf2_get_pc_bounds (struct die_info
*,
1506 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1507 struct partial_symtab
*);
1509 static void get_scope_pc_bounds (struct die_info
*,
1510 CORE_ADDR
*, CORE_ADDR
*,
1511 struct dwarf2_cu
*);
1513 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1514 CORE_ADDR
, struct dwarf2_cu
*);
1516 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1517 struct dwarf2_cu
*);
1519 static void dwarf2_attach_fields_to_type (struct field_info
*,
1520 struct type
*, struct dwarf2_cu
*);
1522 static void dwarf2_add_member_fn (struct field_info
*,
1523 struct die_info
*, struct type
*,
1524 struct dwarf2_cu
*);
1526 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1528 struct dwarf2_cu
*);
1530 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1532 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1534 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1536 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1538 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1540 static struct type
*read_module_type (struct die_info
*die
,
1541 struct dwarf2_cu
*cu
);
1543 static const char *namespace_name (struct die_info
*die
,
1544 int *is_anonymous
, struct dwarf2_cu
*);
1546 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1548 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1550 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1551 struct dwarf2_cu
*);
1553 static struct die_info
*read_die_and_siblings_1
1554 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1557 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1558 const gdb_byte
*info_ptr
,
1559 const gdb_byte
**new_info_ptr
,
1560 struct die_info
*parent
);
1562 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1563 struct die_info
**, const gdb_byte
*,
1566 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1567 struct die_info
**, const gdb_byte
*,
1570 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1572 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1575 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1577 static const char *dwarf2_full_name (const char *name
,
1578 struct die_info
*die
,
1579 struct dwarf2_cu
*cu
);
1581 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1582 struct dwarf2_cu
*cu
);
1584 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1585 struct dwarf2_cu
**);
1587 static const char *dwarf_tag_name (unsigned int);
1589 static const char *dwarf_attr_name (unsigned int);
1591 static const char *dwarf_form_name (unsigned int);
1593 static char *dwarf_bool_name (unsigned int);
1595 static const char *dwarf_type_encoding_name (unsigned int);
1597 static struct die_info
*sibling_die (struct die_info
*);
1599 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1601 static void dump_die_for_error (struct die_info
*);
1603 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1606 /*static*/ void dump_die (struct die_info
*, int max_level
);
1608 static void store_in_ref_table (struct die_info
*,
1609 struct dwarf2_cu
*);
1611 static int is_ref_attr (struct attribute
*);
1613 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1615 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1617 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1619 struct dwarf2_cu
**);
1621 static struct die_info
*follow_die_ref (struct die_info
*,
1623 struct dwarf2_cu
**);
1625 static struct die_info
*follow_die_sig (struct die_info
*,
1627 struct dwarf2_cu
**);
1629 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1630 struct dwarf2_cu
*);
1632 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1634 struct dwarf2_cu
*);
1636 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1638 static void read_signatured_type (struct signatured_type
*);
1640 static struct type_unit_group
*get_type_unit_group
1641 (struct dwarf2_cu
*, struct attribute
*);
1643 static void build_type_unit_groups (die_reader_func_ftype
*, void *);
1645 /* memory allocation interface */
1647 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1649 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1651 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int,
1654 static int attr_form_is_block (struct attribute
*);
1656 static int attr_form_is_section_offset (struct attribute
*);
1658 static int attr_form_is_constant (struct attribute
*);
1660 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1661 struct dwarf2_loclist_baton
*baton
,
1662 struct attribute
*attr
);
1664 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1666 struct dwarf2_cu
*cu
,
1669 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1670 const gdb_byte
*info_ptr
,
1671 struct abbrev_info
*abbrev
);
1673 static void free_stack_comp_unit (void *);
1675 static hashval_t
partial_die_hash (const void *item
);
1677 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1679 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1680 (sect_offset offset
, unsigned int offset_in_dwz
, struct objfile
*objfile
);
1682 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1683 struct dwarf2_per_cu_data
*per_cu
);
1685 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1686 struct die_info
*comp_unit_die
,
1687 enum language pretend_language
);
1689 static void free_heap_comp_unit (void *);
1691 static void free_cached_comp_units (void *);
1693 static void age_cached_comp_units (void);
1695 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1697 static struct type
*set_die_type (struct die_info
*, struct type
*,
1698 struct dwarf2_cu
*);
1700 static void create_all_comp_units (struct objfile
*);
1702 static int create_all_type_units (struct objfile
*);
1704 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1707 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1710 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1713 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1714 struct dwarf2_per_cu_data
*);
1716 static void dwarf2_mark (struct dwarf2_cu
*);
1718 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1720 static struct type
*get_die_type_at_offset (sect_offset
,
1721 struct dwarf2_per_cu_data
*);
1723 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1725 static void dwarf2_release_queue (void *dummy
);
1727 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1728 enum language pretend_language
);
1730 static int maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
1731 struct dwarf2_per_cu_data
*per_cu
,
1732 enum language pretend_language
);
1734 static void process_queue (void);
1736 static void find_file_and_directory (struct die_info
*die
,
1737 struct dwarf2_cu
*cu
,
1738 const char **name
, const char **comp_dir
);
1740 static char *file_full_name (int file
, struct line_header
*lh
,
1741 const char *comp_dir
);
1743 static const gdb_byte
*read_and_check_comp_unit_head
1744 (struct comp_unit_head
*header
,
1745 struct dwarf2_section_info
*section
,
1746 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1747 int is_debug_types_section
);
1749 static void init_cutu_and_read_dies
1750 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1751 int use_existing_cu
, int keep
,
1752 die_reader_func_ftype
*die_reader_func
, void *data
);
1754 static void init_cutu_and_read_dies_simple
1755 (struct dwarf2_per_cu_data
*this_cu
,
1756 die_reader_func_ftype
*die_reader_func
, void *data
);
1758 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1760 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1762 static struct dwo_unit
*lookup_dwo_in_dwp
1763 (struct dwp_file
*dwp_file
, const struct dwp_hash_table
*htab
,
1764 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1766 static struct dwp_file
*get_dwp_file (void);
1768 static struct dwo_unit
*lookup_dwo_comp_unit
1769 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1771 static struct dwo_unit
*lookup_dwo_type_unit
1772 (struct signatured_type
*, const char *, const char *);
1774 static void free_dwo_file_cleanup (void *);
1776 static void process_cu_includes (void);
1778 static void check_producer (struct dwarf2_cu
*cu
);
1782 /* Convert VALUE between big- and little-endian. */
1784 byte_swap (offset_type value
)
1788 result
= (value
& 0xff) << 24;
1789 result
|= (value
& 0xff00) << 8;
1790 result
|= (value
& 0xff0000) >> 8;
1791 result
|= (value
& 0xff000000) >> 24;
1795 #define MAYBE_SWAP(V) byte_swap (V)
1798 #define MAYBE_SWAP(V) (V)
1799 #endif /* WORDS_BIGENDIAN */
1801 /* The suffix for an index file. */
1802 #define INDEX_SUFFIX ".gdb-index"
1804 /* Try to locate the sections we need for DWARF 2 debugging
1805 information and return true if we have enough to do something.
1806 NAMES points to the dwarf2 section names, or is NULL if the standard
1807 ELF names are used. */
1810 dwarf2_has_info (struct objfile
*objfile
,
1811 const struct dwarf2_debug_sections
*names
)
1813 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1814 if (!dwarf2_per_objfile
)
1816 /* Initialize per-objfile state. */
1817 struct dwarf2_per_objfile
*data
1818 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1820 memset (data
, 0, sizeof (*data
));
1821 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1822 dwarf2_per_objfile
= data
;
1824 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1826 dwarf2_per_objfile
->objfile
= objfile
;
1828 return (dwarf2_per_objfile
->info
.asection
!= NULL
1829 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1832 /* When loading sections, we look either for uncompressed section or for
1833 compressed section names. */
1836 section_is_p (const char *section_name
,
1837 const struct dwarf2_section_names
*names
)
1839 if (names
->normal
!= NULL
1840 && strcmp (section_name
, names
->normal
) == 0)
1842 if (names
->compressed
!= NULL
1843 && strcmp (section_name
, names
->compressed
) == 0)
1848 /* This function is mapped across the sections and remembers the
1849 offset and size of each of the debugging sections we are interested
1853 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1855 const struct dwarf2_debug_sections
*names
;
1856 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
1859 names
= &dwarf2_elf_names
;
1861 names
= (const struct dwarf2_debug_sections
*) vnames
;
1863 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1866 else if (section_is_p (sectp
->name
, &names
->info
))
1868 dwarf2_per_objfile
->info
.asection
= sectp
;
1869 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1871 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1873 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1874 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1876 else if (section_is_p (sectp
->name
, &names
->line
))
1878 dwarf2_per_objfile
->line
.asection
= sectp
;
1879 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1881 else if (section_is_p (sectp
->name
, &names
->loc
))
1883 dwarf2_per_objfile
->loc
.asection
= sectp
;
1884 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1886 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1888 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1889 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1891 else if (section_is_p (sectp
->name
, &names
->macro
))
1893 dwarf2_per_objfile
->macro
.asection
= sectp
;
1894 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1896 else if (section_is_p (sectp
->name
, &names
->str
))
1898 dwarf2_per_objfile
->str
.asection
= sectp
;
1899 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1901 else if (section_is_p (sectp
->name
, &names
->addr
))
1903 dwarf2_per_objfile
->addr
.asection
= sectp
;
1904 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
1906 else if (section_is_p (sectp
->name
, &names
->frame
))
1908 dwarf2_per_objfile
->frame
.asection
= sectp
;
1909 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1911 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1913 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1914 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1916 else if (section_is_p (sectp
->name
, &names
->ranges
))
1918 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1919 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1921 else if (section_is_p (sectp
->name
, &names
->types
))
1923 struct dwarf2_section_info type_section
;
1925 memset (&type_section
, 0, sizeof (type_section
));
1926 type_section
.asection
= sectp
;
1927 type_section
.size
= bfd_get_section_size (sectp
);
1929 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1932 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1934 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1935 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1938 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1939 && bfd_section_vma (abfd
, sectp
) == 0)
1940 dwarf2_per_objfile
->has_section_at_zero
= 1;
1943 /* A helper function that decides whether a section is empty,
1947 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1949 return info
->asection
== NULL
|| info
->size
== 0;
1952 /* Read the contents of the section INFO.
1953 OBJFILE is the main object file, but not necessarily the file where
1954 the section comes from. E.g., for DWO files INFO->asection->owner
1955 is the bfd of the DWO file.
1956 If the section is compressed, uncompress it before returning. */
1959 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1961 asection
*sectp
= info
->asection
;
1963 gdb_byte
*buf
, *retbuf
;
1964 unsigned char header
[4];
1968 info
->buffer
= NULL
;
1971 if (dwarf2_section_empty_p (info
))
1974 abfd
= sectp
->owner
;
1976 /* If the section has relocations, we must read it ourselves.
1977 Otherwise we attach it to the BFD. */
1978 if ((sectp
->flags
& SEC_RELOC
) == 0)
1980 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
1984 buf
= obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1987 /* When debugging .o files, we may need to apply relocations; see
1988 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1989 We never compress sections in .o files, so we only need to
1990 try this when the section is not compressed. */
1991 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1994 info
->buffer
= retbuf
;
1998 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1999 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2000 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
2001 bfd_get_filename (abfd
));
2004 /* A helper function that returns the size of a section in a safe way.
2005 If you are positive that the section has been read before using the
2006 size, then it is safe to refer to the dwarf2_section_info object's
2007 "size" field directly. In other cases, you must call this
2008 function, because for compressed sections the size field is not set
2009 correctly until the section has been read. */
2011 static bfd_size_type
2012 dwarf2_section_size (struct objfile
*objfile
,
2013 struct dwarf2_section_info
*info
)
2016 dwarf2_read_section (objfile
, info
);
2020 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2024 dwarf2_get_section_info (struct objfile
*objfile
,
2025 enum dwarf2_section_enum sect
,
2026 asection
**sectp
, const gdb_byte
**bufp
,
2027 bfd_size_type
*sizep
)
2029 struct dwarf2_per_objfile
*data
2030 = objfile_data (objfile
, dwarf2_objfile_data_key
);
2031 struct dwarf2_section_info
*info
;
2033 /* We may see an objfile without any DWARF, in which case we just
2044 case DWARF2_DEBUG_FRAME
:
2045 info
= &data
->frame
;
2047 case DWARF2_EH_FRAME
:
2048 info
= &data
->eh_frame
;
2051 gdb_assert_not_reached ("unexpected section");
2054 dwarf2_read_section (objfile
, info
);
2056 *sectp
= info
->asection
;
2057 *bufp
= info
->buffer
;
2058 *sizep
= info
->size
;
2061 /* A helper function to find the sections for a .dwz file. */
2064 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2066 struct dwz_file
*dwz_file
= arg
;
2068 /* Note that we only support the standard ELF names, because .dwz
2069 is ELF-only (at the time of writing). */
2070 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2072 dwz_file
->abbrev
.asection
= sectp
;
2073 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2075 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2077 dwz_file
->info
.asection
= sectp
;
2078 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2080 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2082 dwz_file
->str
.asection
= sectp
;
2083 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2085 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2087 dwz_file
->line
.asection
= sectp
;
2088 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2090 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2092 dwz_file
->macro
.asection
= sectp
;
2093 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2095 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2097 dwz_file
->gdb_index
.asection
= sectp
;
2098 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2102 /* Open the separate '.dwz' debug file, if needed. Error if the file
2105 static struct dwz_file
*
2106 dwarf2_get_dwz_file (void)
2108 bfd
*abfd
, *dwz_bfd
;
2111 struct cleanup
*cleanup
;
2112 const char *filename
;
2113 struct dwz_file
*result
;
2115 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2116 return dwarf2_per_objfile
->dwz_file
;
2118 abfd
= dwarf2_per_objfile
->objfile
->obfd
;
2119 section
= bfd_get_section_by_name (abfd
, ".gnu_debugaltlink");
2120 if (section
== NULL
)
2121 error (_("could not find '.gnu_debugaltlink' section"));
2122 if (!bfd_malloc_and_get_section (abfd
, section
, &data
))
2123 error (_("could not read '.gnu_debugaltlink' section: %s"),
2124 bfd_errmsg (bfd_get_error ()));
2125 cleanup
= make_cleanup (xfree
, data
);
2127 filename
= (const char *) data
;
2128 if (!IS_ABSOLUTE_PATH (filename
))
2130 char *abs
= gdb_realpath (dwarf2_per_objfile
->objfile
->name
);
2133 make_cleanup (xfree
, abs
);
2134 abs
= ldirname (abs
);
2135 make_cleanup (xfree
, abs
);
2137 rel
= concat (abs
, SLASH_STRING
, filename
, (char *) NULL
);
2138 make_cleanup (xfree
, rel
);
2142 /* The format is just a NUL-terminated file name, followed by the
2143 build-id. For now, though, we ignore the build-id. */
2144 dwz_bfd
= gdb_bfd_open (filename
, gnutarget
, -1);
2145 if (dwz_bfd
== NULL
)
2146 error (_("could not read '%s': %s"), filename
,
2147 bfd_errmsg (bfd_get_error ()));
2149 if (!bfd_check_format (dwz_bfd
, bfd_object
))
2151 gdb_bfd_unref (dwz_bfd
);
2152 error (_("file '%s' was not usable: %s"), filename
,
2153 bfd_errmsg (bfd_get_error ()));
2156 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2158 result
->dwz_bfd
= dwz_bfd
;
2160 bfd_map_over_sections (dwz_bfd
, locate_dwz_sections
, result
);
2162 do_cleanups (cleanup
);
2164 dwarf2_per_objfile
->dwz_file
= result
;
2168 /* DWARF quick_symbols_functions support. */
2170 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2171 unique line tables, so we maintain a separate table of all .debug_line
2172 derived entries to support the sharing.
2173 All the quick functions need is the list of file names. We discard the
2174 line_header when we're done and don't need to record it here. */
2175 struct quick_file_names
2177 /* The data used to construct the hash key. */
2178 struct stmt_list_hash hash
;
2180 /* The number of entries in file_names, real_names. */
2181 unsigned int num_file_names
;
2183 /* The file names from the line table, after being run through
2185 const char **file_names
;
2187 /* The file names from the line table after being run through
2188 gdb_realpath. These are computed lazily. */
2189 const char **real_names
;
2192 /* When using the index (and thus not using psymtabs), each CU has an
2193 object of this type. This is used to hold information needed by
2194 the various "quick" methods. */
2195 struct dwarf2_per_cu_quick_data
2197 /* The file table. This can be NULL if there was no file table
2198 or it's currently not read in.
2199 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2200 struct quick_file_names
*file_names
;
2202 /* The corresponding symbol table. This is NULL if symbols for this
2203 CU have not yet been read. */
2204 struct symtab
*symtab
;
2206 /* A temporary mark bit used when iterating over all CUs in
2207 expand_symtabs_matching. */
2208 unsigned int mark
: 1;
2210 /* True if we've tried to read the file table and found there isn't one.
2211 There will be no point in trying to read it again next time. */
2212 unsigned int no_file_data
: 1;
2215 /* Utility hash function for a stmt_list_hash. */
2218 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2222 if (stmt_list_hash
->dwo_unit
!= NULL
)
2223 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2224 v
+= stmt_list_hash
->line_offset
.sect_off
;
2228 /* Utility equality function for a stmt_list_hash. */
2231 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2232 const struct stmt_list_hash
*rhs
)
2234 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2236 if (lhs
->dwo_unit
!= NULL
2237 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2240 return lhs
->line_offset
.sect_off
== rhs
->line_offset
.sect_off
;
2243 /* Hash function for a quick_file_names. */
2246 hash_file_name_entry (const void *e
)
2248 const struct quick_file_names
*file_data
= e
;
2250 return hash_stmt_list_entry (&file_data
->hash
);
2253 /* Equality function for a quick_file_names. */
2256 eq_file_name_entry (const void *a
, const void *b
)
2258 const struct quick_file_names
*ea
= a
;
2259 const struct quick_file_names
*eb
= b
;
2261 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2264 /* Delete function for a quick_file_names. */
2267 delete_file_name_entry (void *e
)
2269 struct quick_file_names
*file_data
= e
;
2272 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2274 xfree ((void*) file_data
->file_names
[i
]);
2275 if (file_data
->real_names
)
2276 xfree ((void*) file_data
->real_names
[i
]);
2279 /* The space for the struct itself lives on objfile_obstack,
2280 so we don't free it here. */
2283 /* Create a quick_file_names hash table. */
2286 create_quick_file_names_table (unsigned int nr_initial_entries
)
2288 return htab_create_alloc (nr_initial_entries
,
2289 hash_file_name_entry
, eq_file_name_entry
,
2290 delete_file_name_entry
, xcalloc
, xfree
);
2293 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2294 have to be created afterwards. You should call age_cached_comp_units after
2295 processing PER_CU->CU. dw2_setup must have been already called. */
2298 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2300 if (per_cu
->is_debug_types
)
2301 load_full_type_unit (per_cu
);
2303 load_full_comp_unit (per_cu
, language_minimal
);
2305 gdb_assert (per_cu
->cu
!= NULL
);
2307 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2310 /* Read in the symbols for PER_CU. */
2313 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2315 struct cleanup
*back_to
;
2317 /* Skip type_unit_groups, reading the type units they contain
2318 is handled elsewhere. */
2319 if (IS_TYPE_UNIT_GROUP (per_cu
))
2322 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2324 if (dwarf2_per_objfile
->using_index
2325 ? per_cu
->v
.quick
->symtab
== NULL
2326 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2328 queue_comp_unit (per_cu
, language_minimal
);
2334 /* Age the cache, releasing compilation units that have not
2335 been used recently. */
2336 age_cached_comp_units ();
2338 do_cleanups (back_to
);
2341 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2342 the objfile from which this CU came. Returns the resulting symbol
2345 static struct symtab
*
2346 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2348 gdb_assert (dwarf2_per_objfile
->using_index
);
2349 if (!per_cu
->v
.quick
->symtab
)
2351 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2352 increment_reading_symtab ();
2353 dw2_do_instantiate_symtab (per_cu
);
2354 process_cu_includes ();
2355 do_cleanups (back_to
);
2357 return per_cu
->v
.quick
->symtab
;
2360 /* Return the CU given its index.
2362 This is intended for loops like:
2364 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2365 + dwarf2_per_objfile->n_type_units); ++i)
2367 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2373 static struct dwarf2_per_cu_data
*
2374 dw2_get_cu (int index
)
2376 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2378 index
-= dwarf2_per_objfile
->n_comp_units
;
2379 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
2380 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
2383 return dwarf2_per_objfile
->all_comp_units
[index
];
2386 /* Return the primary CU given its index.
2387 The difference between this function and dw2_get_cu is in the handling
2388 of type units (TUs). Here we return the type_unit_group object.
2390 This is intended for loops like:
2392 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2393 + dwarf2_per_objfile->n_type_unit_groups); ++i)
2395 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
2401 static struct dwarf2_per_cu_data
*
2402 dw2_get_primary_cu (int index
)
2404 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2406 index
-= dwarf2_per_objfile
->n_comp_units
;
2407 gdb_assert (index
< dwarf2_per_objfile
->n_type_unit_groups
);
2408 return &dwarf2_per_objfile
->all_type_unit_groups
[index
]->per_cu
;
2411 return dwarf2_per_objfile
->all_comp_units
[index
];
2414 /* A helper for create_cus_from_index that handles a given list of
2418 create_cus_from_index_list (struct objfile
*objfile
,
2419 const gdb_byte
*cu_list
, offset_type n_elements
,
2420 struct dwarf2_section_info
*section
,
2426 for (i
= 0; i
< n_elements
; i
+= 2)
2428 struct dwarf2_per_cu_data
*the_cu
;
2429 ULONGEST offset
, length
;
2431 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2432 offset
= extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2433 length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2436 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2437 struct dwarf2_per_cu_data
);
2438 the_cu
->offset
.sect_off
= offset
;
2439 the_cu
->length
= length
;
2440 the_cu
->objfile
= objfile
;
2441 the_cu
->section
= section
;
2442 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2443 struct dwarf2_per_cu_quick_data
);
2444 the_cu
->is_dwz
= is_dwz
;
2445 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2] = the_cu
;
2449 /* Read the CU list from the mapped index, and use it to create all
2450 the CU objects for this objfile. */
2453 create_cus_from_index (struct objfile
*objfile
,
2454 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2455 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2457 struct dwz_file
*dwz
;
2459 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
2460 dwarf2_per_objfile
->all_comp_units
2461 = obstack_alloc (&objfile
->objfile_obstack
,
2462 dwarf2_per_objfile
->n_comp_units
2463 * sizeof (struct dwarf2_per_cu_data
*));
2465 create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
2466 &dwarf2_per_objfile
->info
, 0, 0);
2468 if (dwz_elements
== 0)
2471 dwz
= dwarf2_get_dwz_file ();
2472 create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
, &dwz
->info
, 1,
2473 cu_list_elements
/ 2);
2476 /* Create the signatured type hash table from the index. */
2479 create_signatured_type_table_from_index (struct objfile
*objfile
,
2480 struct dwarf2_section_info
*section
,
2481 const gdb_byte
*bytes
,
2482 offset_type elements
)
2485 htab_t sig_types_hash
;
2487 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2488 dwarf2_per_objfile
->all_type_units
2489 = xmalloc (dwarf2_per_objfile
->n_type_units
2490 * sizeof (struct signatured_type
*));
2492 sig_types_hash
= allocate_signatured_type_table (objfile
);
2494 for (i
= 0; i
< elements
; i
+= 3)
2496 struct signatured_type
*sig_type
;
2497 ULONGEST offset
, type_offset_in_tu
, signature
;
2500 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2501 offset
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2502 type_offset_in_tu
= extract_unsigned_integer (bytes
+ 8, 8,
2504 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2507 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2508 struct signatured_type
);
2509 sig_type
->signature
= signature
;
2510 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2511 sig_type
->per_cu
.is_debug_types
= 1;
2512 sig_type
->per_cu
.section
= section
;
2513 sig_type
->per_cu
.offset
.sect_off
= offset
;
2514 sig_type
->per_cu
.objfile
= objfile
;
2515 sig_type
->per_cu
.v
.quick
2516 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2517 struct dwarf2_per_cu_quick_data
);
2519 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2522 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
2525 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2528 /* Read the address map data from the mapped index, and use it to
2529 populate the objfile's psymtabs_addrmap. */
2532 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2534 const gdb_byte
*iter
, *end
;
2535 struct obstack temp_obstack
;
2536 struct addrmap
*mutable_map
;
2537 struct cleanup
*cleanup
;
2540 obstack_init (&temp_obstack
);
2541 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2542 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2544 iter
= index
->address_table
;
2545 end
= iter
+ index
->address_table_size
;
2547 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2551 ULONGEST hi
, lo
, cu_index
;
2552 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2554 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2556 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2559 if (cu_index
< dwarf2_per_objfile
->n_comp_units
)
2561 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2562 dw2_get_cu (cu_index
));
2566 complaint (&symfile_complaints
,
2567 _(".gdb_index address table has invalid CU number %u"),
2568 (unsigned) cu_index
);
2572 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2573 &objfile
->objfile_obstack
);
2574 do_cleanups (cleanup
);
2577 /* The hash function for strings in the mapped index. This is the same as
2578 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2579 implementation. This is necessary because the hash function is tied to the
2580 format of the mapped index file. The hash values do not have to match with
2583 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2586 mapped_index_string_hash (int index_version
, const void *p
)
2588 const unsigned char *str
= (const unsigned char *) p
;
2592 while ((c
= *str
++) != 0)
2594 if (index_version
>= 5)
2596 r
= r
* 67 + c
- 113;
2602 /* Find a slot in the mapped index INDEX for the object named NAME.
2603 If NAME is found, set *VEC_OUT to point to the CU vector in the
2604 constant pool and return 1. If NAME cannot be found, return 0. */
2607 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2608 offset_type
**vec_out
)
2610 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2612 offset_type slot
, step
;
2613 int (*cmp
) (const char *, const char *);
2615 if (current_language
->la_language
== language_cplus
2616 || current_language
->la_language
== language_java
2617 || current_language
->la_language
== language_fortran
)
2619 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2621 const char *paren
= strchr (name
, '(');
2627 dup
= xmalloc (paren
- name
+ 1);
2628 memcpy (dup
, name
, paren
- name
);
2629 dup
[paren
- name
] = 0;
2631 make_cleanup (xfree
, dup
);
2636 /* Index version 4 did not support case insensitive searches. But the
2637 indices for case insensitive languages are built in lowercase, therefore
2638 simulate our NAME being searched is also lowercased. */
2639 hash
= mapped_index_string_hash ((index
->version
== 4
2640 && case_sensitivity
== case_sensitive_off
2641 ? 5 : index
->version
),
2644 slot
= hash
& (index
->symbol_table_slots
- 1);
2645 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2646 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2650 /* Convert a slot number to an offset into the table. */
2651 offset_type i
= 2 * slot
;
2653 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2655 do_cleanups (back_to
);
2659 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2660 if (!cmp (name
, str
))
2662 *vec_out
= (offset_type
*) (index
->constant_pool
2663 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2664 do_cleanups (back_to
);
2668 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2672 /* A helper function that reads the .gdb_index from SECTION and fills
2673 in MAP. FILENAME is the name of the file containing the section;
2674 it is used for error reporting. DEPRECATED_OK is nonzero if it is
2675 ok to use deprecated sections.
2677 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2678 out parameters that are filled in with information about the CU and
2679 TU lists in the section.
2681 Returns 1 if all went well, 0 otherwise. */
2684 read_index_from_section (struct objfile
*objfile
,
2685 const char *filename
,
2687 struct dwarf2_section_info
*section
,
2688 struct mapped_index
*map
,
2689 const gdb_byte
**cu_list
,
2690 offset_type
*cu_list_elements
,
2691 const gdb_byte
**types_list
,
2692 offset_type
*types_list_elements
)
2694 const gdb_byte
*addr
;
2695 offset_type version
;
2696 offset_type
*metadata
;
2699 if (dwarf2_section_empty_p (section
))
2702 /* Older elfutils strip versions could keep the section in the main
2703 executable while splitting it for the separate debug info file. */
2704 if ((bfd_get_file_flags (section
->asection
) & SEC_HAS_CONTENTS
) == 0)
2707 dwarf2_read_section (objfile
, section
);
2709 addr
= section
->buffer
;
2710 /* Version check. */
2711 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2712 /* Versions earlier than 3 emitted every copy of a psymbol. This
2713 causes the index to behave very poorly for certain requests. Version 3
2714 contained incomplete addrmap. So, it seems better to just ignore such
2718 static int warning_printed
= 0;
2719 if (!warning_printed
)
2721 warning (_("Skipping obsolete .gdb_index section in %s."),
2723 warning_printed
= 1;
2727 /* Index version 4 uses a different hash function than index version
2730 Versions earlier than 6 did not emit psymbols for inlined
2731 functions. Using these files will cause GDB not to be able to
2732 set breakpoints on inlined functions by name, so we ignore these
2733 indices unless the user has done
2734 "set use-deprecated-index-sections on". */
2735 if (version
< 6 && !deprecated_ok
)
2737 static int warning_printed
= 0;
2738 if (!warning_printed
)
2741 Skipping deprecated .gdb_index section in %s.\n\
2742 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2743 to use the section anyway."),
2745 warning_printed
= 1;
2749 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2750 of the TU (for symbols coming from TUs). It's just a performance bug, and
2751 we can't distinguish gdb-generated indices from gold-generated ones, so
2752 nothing to do here. */
2754 /* Indexes with higher version than the one supported by GDB may be no
2755 longer backward compatible. */
2759 map
->version
= version
;
2760 map
->total_size
= section
->size
;
2762 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2765 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2766 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2770 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2771 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2772 - MAYBE_SWAP (metadata
[i
]))
2776 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2777 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2778 - MAYBE_SWAP (metadata
[i
]));
2781 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2782 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2783 - MAYBE_SWAP (metadata
[i
]))
2784 / (2 * sizeof (offset_type
)));
2787 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
2793 /* Read the index file. If everything went ok, initialize the "quick"
2794 elements of all the CUs and return 1. Otherwise, return 0. */
2797 dwarf2_read_index (struct objfile
*objfile
)
2799 struct mapped_index local_map
, *map
;
2800 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2801 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2803 if (!read_index_from_section (objfile
, objfile
->name
,
2804 use_deprecated_index_sections
,
2805 &dwarf2_per_objfile
->gdb_index
, &local_map
,
2806 &cu_list
, &cu_list_elements
,
2807 &types_list
, &types_list_elements
))
2810 /* Don't use the index if it's empty. */
2811 if (local_map
.symbol_table_slots
== 0)
2814 /* If there is a .dwz file, read it so we can get its CU list as
2816 if (bfd_get_section_by_name (objfile
->obfd
, ".gnu_debugaltlink") != NULL
)
2818 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
2819 struct mapped_index dwz_map
;
2820 const gdb_byte
*dwz_types_ignore
;
2821 offset_type dwz_types_elements_ignore
;
2823 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
2825 &dwz
->gdb_index
, &dwz_map
,
2826 &dwz_list
, &dwz_list_elements
,
2828 &dwz_types_elements_ignore
))
2830 warning (_("could not read '.gdb_index' section from %s; skipping"),
2831 bfd_get_filename (dwz
->dwz_bfd
));
2836 create_cus_from_index (objfile
, cu_list
, cu_list_elements
, dwz_list
,
2839 if (types_list_elements
)
2841 struct dwarf2_section_info
*section
;
2843 /* We can only handle a single .debug_types when we have an
2845 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2848 section
= VEC_index (dwarf2_section_info_def
,
2849 dwarf2_per_objfile
->types
, 0);
2851 create_signatured_type_table_from_index (objfile
, section
, types_list
,
2852 types_list_elements
);
2855 create_addrmap_from_index (objfile
, &local_map
);
2857 map
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct mapped_index
));
2860 dwarf2_per_objfile
->index_table
= map
;
2861 dwarf2_per_objfile
->using_index
= 1;
2862 dwarf2_per_objfile
->quick_file_names_table
=
2863 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2868 /* A helper for the "quick" functions which sets the global
2869 dwarf2_per_objfile according to OBJFILE. */
2872 dw2_setup (struct objfile
*objfile
)
2874 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2875 gdb_assert (dwarf2_per_objfile
);
2878 /* die_reader_func for dw2_get_file_names. */
2881 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2882 const gdb_byte
*info_ptr
,
2883 struct die_info
*comp_unit_die
,
2887 struct dwarf2_cu
*cu
= reader
->cu
;
2888 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2889 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2890 struct dwarf2_per_cu_data
*lh_cu
;
2891 struct line_header
*lh
;
2892 struct attribute
*attr
;
2894 const char *name
, *comp_dir
;
2896 struct quick_file_names
*qfn
;
2897 unsigned int line_offset
;
2899 gdb_assert (! this_cu
->is_debug_types
);
2901 /* Our callers never want to match partial units -- instead they
2902 will match the enclosing full CU. */
2903 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2905 this_cu
->v
.quick
->no_file_data
= 1;
2914 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2917 struct quick_file_names find_entry
;
2919 line_offset
= DW_UNSND (attr
);
2921 /* We may have already read in this line header (TU line header sharing).
2922 If we have we're done. */
2923 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
2924 find_entry
.hash
.line_offset
.sect_off
= line_offset
;
2925 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2926 &find_entry
, INSERT
);
2929 lh_cu
->v
.quick
->file_names
= *slot
;
2933 lh
= dwarf_decode_line_header (line_offset
, cu
);
2937 lh_cu
->v
.quick
->no_file_data
= 1;
2941 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2942 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
2943 qfn
->hash
.line_offset
.sect_off
= line_offset
;
2944 gdb_assert (slot
!= NULL
);
2947 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2949 qfn
->num_file_names
= lh
->num_file_names
;
2950 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2951 lh
->num_file_names
* sizeof (char *));
2952 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2953 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2954 qfn
->real_names
= NULL
;
2956 free_line_header (lh
);
2958 lh_cu
->v
.quick
->file_names
= qfn
;
2961 /* A helper for the "quick" functions which attempts to read the line
2962 table for THIS_CU. */
2964 static struct quick_file_names
*
2965 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
2967 /* This should never be called for TUs. */
2968 gdb_assert (! this_cu
->is_debug_types
);
2969 /* Nor type unit groups. */
2970 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
2972 if (this_cu
->v
.quick
->file_names
!= NULL
)
2973 return this_cu
->v
.quick
->file_names
;
2974 /* If we know there is no line data, no point in looking again. */
2975 if (this_cu
->v
.quick
->no_file_data
)
2978 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2980 if (this_cu
->v
.quick
->no_file_data
)
2982 return this_cu
->v
.quick
->file_names
;
2985 /* A helper for the "quick" functions which computes and caches the
2986 real path for a given file name from the line table. */
2989 dw2_get_real_path (struct objfile
*objfile
,
2990 struct quick_file_names
*qfn
, int index
)
2992 if (qfn
->real_names
== NULL
)
2993 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2994 qfn
->num_file_names
, sizeof (char *));
2996 if (qfn
->real_names
[index
] == NULL
)
2997 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2999 return qfn
->real_names
[index
];
3002 static struct symtab
*
3003 dw2_find_last_source_symtab (struct objfile
*objfile
)
3007 dw2_setup (objfile
);
3008 index
= dwarf2_per_objfile
->n_comp_units
- 1;
3009 return dw2_instantiate_symtab (dw2_get_cu (index
));
3012 /* Traversal function for dw2_forget_cached_source_info. */
3015 dw2_free_cached_file_names (void **slot
, void *info
)
3017 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3019 if (file_data
->real_names
)
3023 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3025 xfree ((void*) file_data
->real_names
[i
]);
3026 file_data
->real_names
[i
] = NULL
;
3034 dw2_forget_cached_source_info (struct objfile
*objfile
)
3036 dw2_setup (objfile
);
3038 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3039 dw2_free_cached_file_names
, NULL
);
3042 /* Helper function for dw2_map_symtabs_matching_filename that expands
3043 the symtabs and calls the iterator. */
3046 dw2_map_expand_apply (struct objfile
*objfile
,
3047 struct dwarf2_per_cu_data
*per_cu
,
3048 const char *name
, const char *real_path
,
3049 int (*callback
) (struct symtab
*, void *),
3052 struct symtab
*last_made
= objfile
->symtabs
;
3054 /* Don't visit already-expanded CUs. */
3055 if (per_cu
->v
.quick
->symtab
)
3058 /* This may expand more than one symtab, and we want to iterate over
3060 dw2_instantiate_symtab (per_cu
);
3062 return iterate_over_some_symtabs (name
, real_path
, callback
, data
,
3063 objfile
->symtabs
, last_made
);
3066 /* Implementation of the map_symtabs_matching_filename method. */
3069 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
3070 const char *real_path
,
3071 int (*callback
) (struct symtab
*, void *),
3075 const char *name_basename
= lbasename (name
);
3077 dw2_setup (objfile
);
3079 /* The rule is CUs specify all the files, including those used by
3080 any TU, so there's no need to scan TUs here. */
3082 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3085 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3086 struct quick_file_names
*file_data
;
3088 /* We only need to look at symtabs not already expanded. */
3089 if (per_cu
->v
.quick
->symtab
)
3092 file_data
= dw2_get_file_names (per_cu
);
3093 if (file_data
== NULL
)
3096 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3098 const char *this_name
= file_data
->file_names
[j
];
3099 const char *this_real_name
;
3101 if (compare_filenames_for_search (this_name
, name
))
3103 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3109 /* Before we invoke realpath, which can get expensive when many
3110 files are involved, do a quick comparison of the basenames. */
3111 if (! basenames_may_differ
3112 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3115 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3116 if (compare_filenames_for_search (this_real_name
, name
))
3118 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3124 if (real_path
!= NULL
)
3126 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3127 gdb_assert (IS_ABSOLUTE_PATH (name
));
3128 if (this_real_name
!= NULL
3129 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3131 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3143 /* Struct used to manage iterating over all CUs looking for a symbol. */
3145 struct dw2_symtab_iterator
3147 /* The internalized form of .gdb_index. */
3148 struct mapped_index
*index
;
3149 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
3150 int want_specific_block
;
3151 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
3152 Unused if !WANT_SPECIFIC_BLOCK. */
3154 /* The kind of symbol we're looking for. */
3156 /* The list of CUs from the index entry of the symbol,
3157 or NULL if not found. */
3159 /* The next element in VEC to look at. */
3161 /* The number of elements in VEC, or zero if there is no match. */
3165 /* Initialize the index symtab iterator ITER.
3166 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
3167 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
3170 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3171 struct mapped_index
*index
,
3172 int want_specific_block
,
3177 iter
->index
= index
;
3178 iter
->want_specific_block
= want_specific_block
;
3179 iter
->block_index
= block_index
;
3180 iter
->domain
= domain
;
3183 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3184 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3192 /* Return the next matching CU or NULL if there are no more. */
3194 static struct dwarf2_per_cu_data
*
3195 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3197 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3199 offset_type cu_index_and_attrs
=
3200 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3201 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3202 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
3203 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
3204 /* This value is only valid for index versions >= 7. */
3205 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3206 gdb_index_symbol_kind symbol_kind
=
3207 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3208 /* Only check the symbol attributes if they're present.
3209 Indices prior to version 7 don't record them,
3210 and indices >= 7 may elide them for certain symbols
3211 (gold does this). */
3213 (iter
->index
->version
>= 7
3214 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3216 /* Skip if already read in. */
3217 if (per_cu
->v
.quick
->symtab
)
3221 && iter
->want_specific_block
3222 && want_static
!= is_static
)
3225 /* Only check the symbol's kind if it has one. */
3228 switch (iter
->domain
)
3231 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3232 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3233 /* Some types are also in VAR_DOMAIN. */
3234 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3238 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3242 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3257 static struct symtab
*
3258 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
3259 const char *name
, domain_enum domain
)
3261 struct symtab
*stab_best
= NULL
;
3262 struct mapped_index
*index
;
3264 dw2_setup (objfile
);
3266 index
= dwarf2_per_objfile
->index_table
;
3268 /* index is NULL if OBJF_READNOW. */
3271 struct dw2_symtab_iterator iter
;
3272 struct dwarf2_per_cu_data
*per_cu
;
3274 dw2_symtab_iter_init (&iter
, index
, 1, block_index
, domain
, name
);
3276 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3278 struct symbol
*sym
= NULL
;
3279 struct symtab
*stab
= dw2_instantiate_symtab (per_cu
);
3281 /* Some caution must be observed with overloaded functions
3282 and methods, since the index will not contain any overload
3283 information (but NAME might contain it). */
3286 struct blockvector
*bv
= BLOCKVECTOR (stab
);
3287 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3289 sym
= lookup_block_symbol (block
, name
, domain
);
3292 if (sym
&& strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
3294 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
3300 /* Keep looking through other CUs. */
3308 dw2_print_stats (struct objfile
*objfile
)
3310 int i
, total
, count
;
3312 dw2_setup (objfile
);
3313 total
= dwarf2_per_objfile
->n_comp_units
+ dwarf2_per_objfile
->n_type_units
;
3315 for (i
= 0; i
< total
; ++i
)
3317 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3319 if (!per_cu
->v
.quick
->symtab
)
3322 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3323 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3327 dw2_dump (struct objfile
*objfile
)
3329 /* Nothing worth printing. */
3333 dw2_relocate (struct objfile
*objfile
,
3334 const struct section_offsets
*new_offsets
,
3335 const struct section_offsets
*delta
)
3337 /* There's nothing to relocate here. */
3341 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3342 const char *func_name
)
3344 struct mapped_index
*index
;
3346 dw2_setup (objfile
);
3348 index
= dwarf2_per_objfile
->index_table
;
3350 /* index is NULL if OBJF_READNOW. */
3353 struct dw2_symtab_iterator iter
;
3354 struct dwarf2_per_cu_data
*per_cu
;
3356 /* Note: It doesn't matter what we pass for block_index here. */
3357 dw2_symtab_iter_init (&iter
, index
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
3360 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3361 dw2_instantiate_symtab (per_cu
);
3366 dw2_expand_all_symtabs (struct objfile
*objfile
)
3370 dw2_setup (objfile
);
3372 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3373 + dwarf2_per_objfile
->n_type_units
); ++i
)
3375 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3377 dw2_instantiate_symtab (per_cu
);
3382 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3383 const char *fullname
)
3387 dw2_setup (objfile
);
3389 /* We don't need to consider type units here.
3390 This is only called for examining code, e.g. expand_line_sal.
3391 There can be an order of magnitude (or more) more type units
3392 than comp units, and we avoid them if we can. */
3394 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3397 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3398 struct quick_file_names
*file_data
;
3400 /* We only need to look at symtabs not already expanded. */
3401 if (per_cu
->v
.quick
->symtab
)
3404 file_data
= dw2_get_file_names (per_cu
);
3405 if (file_data
== NULL
)
3408 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3410 const char *this_fullname
= file_data
->file_names
[j
];
3412 if (filename_cmp (this_fullname
, fullname
) == 0)
3414 dw2_instantiate_symtab (per_cu
);
3421 /* A helper function for dw2_find_symbol_file that finds the primary
3422 file name for a given CU. This is a die_reader_func. */
3425 dw2_get_primary_filename_reader (const struct die_reader_specs
*reader
,
3426 const gdb_byte
*info_ptr
,
3427 struct die_info
*comp_unit_die
,
3431 const char **result_ptr
= data
;
3432 struct dwarf2_cu
*cu
= reader
->cu
;
3433 struct attribute
*attr
;
3435 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
3439 *result_ptr
= DW_STRING (attr
);
3443 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
3445 struct dwarf2_per_cu_data
*per_cu
;
3447 const char *filename
;
3449 dw2_setup (objfile
);
3451 /* index_table is NULL if OBJF_READNOW. */
3452 if (!dwarf2_per_objfile
->index_table
)
3456 ALL_OBJFILE_PRIMARY_SYMTABS (objfile
, s
)
3458 struct blockvector
*bv
= BLOCKVECTOR (s
);
3459 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
3460 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
3464 /* Only file extension of returned filename is recognized. */
3465 return SYMBOL_SYMTAB (sym
)->filename
;
3471 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
3475 /* Note that this just looks at the very first one named NAME -- but
3476 actually we are looking for a function. find_main_filename
3477 should be rewritten so that it doesn't require a custom hook. It
3478 could just use the ordinary symbol tables. */
3479 /* vec[0] is the length, which must always be >0. */
3480 per_cu
= dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec
[1])));
3482 if (per_cu
->v
.quick
->symtab
!= NULL
)
3484 /* Only file extension of returned filename is recognized. */
3485 return per_cu
->v
.quick
->symtab
->filename
;
3488 /* Initialize filename in case there's a problem reading the DWARF,
3489 dw2_get_primary_filename_reader may not get called. */
3491 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
3492 dw2_get_primary_filename_reader
, &filename
);
3494 /* Only file extension of returned filename is recognized. */
3499 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
3500 struct objfile
*objfile
, int global
,
3501 int (*callback
) (struct block
*,
3502 struct symbol
*, void *),
3503 void *data
, symbol_compare_ftype
*match
,
3504 symbol_compare_ftype
*ordered_compare
)
3506 /* Currently unimplemented; used for Ada. The function can be called if the
3507 current language is Ada for a non-Ada objfile using GNU index. As Ada
3508 does not look for non-Ada symbols this function should just return. */
3512 dw2_expand_symtabs_matching
3513 (struct objfile
*objfile
,
3514 int (*file_matcher
) (const char *, void *, int basenames
),
3515 int (*name_matcher
) (const char *, void *),
3516 enum search_domain kind
,
3521 struct mapped_index
*index
;
3523 dw2_setup (objfile
);
3525 /* index_table is NULL if OBJF_READNOW. */
3526 if (!dwarf2_per_objfile
->index_table
)
3528 index
= dwarf2_per_objfile
->index_table
;
3530 if (file_matcher
!= NULL
)
3532 struct cleanup
*cleanup
;
3533 htab_t visited_found
, visited_not_found
;
3535 visited_found
= htab_create_alloc (10,
3536 htab_hash_pointer
, htab_eq_pointer
,
3537 NULL
, xcalloc
, xfree
);
3538 cleanup
= make_cleanup_htab_delete (visited_found
);
3539 visited_not_found
= htab_create_alloc (10,
3540 htab_hash_pointer
, htab_eq_pointer
,
3541 NULL
, xcalloc
, xfree
);
3542 make_cleanup_htab_delete (visited_not_found
);
3544 /* The rule is CUs specify all the files, including those used by
3545 any TU, so there's no need to scan TUs here. */
3547 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3550 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3551 struct quick_file_names
*file_data
;
3554 per_cu
->v
.quick
->mark
= 0;
3556 /* We only need to look at symtabs not already expanded. */
3557 if (per_cu
->v
.quick
->symtab
)
3560 file_data
= dw2_get_file_names (per_cu
);
3561 if (file_data
== NULL
)
3564 if (htab_find (visited_not_found
, file_data
) != NULL
)
3566 else if (htab_find (visited_found
, file_data
) != NULL
)
3568 per_cu
->v
.quick
->mark
= 1;
3572 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3574 const char *this_real_name
;
3576 if (file_matcher (file_data
->file_names
[j
], data
, 0))
3578 per_cu
->v
.quick
->mark
= 1;
3582 /* Before we invoke realpath, which can get expensive when many
3583 files are involved, do a quick comparison of the basenames. */
3584 if (!basenames_may_differ
3585 && !file_matcher (lbasename (file_data
->file_names
[j
]),
3589 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3590 if (file_matcher (this_real_name
, data
, 0))
3592 per_cu
->v
.quick
->mark
= 1;
3597 slot
= htab_find_slot (per_cu
->v
.quick
->mark
3599 : visited_not_found
,
3604 do_cleanups (cleanup
);
3607 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
3609 offset_type idx
= 2 * iter
;
3611 offset_type
*vec
, vec_len
, vec_idx
;
3613 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
3616 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
3618 if (! (*name_matcher
) (name
, data
))
3621 /* The name was matched, now expand corresponding CUs that were
3623 vec
= (offset_type
*) (index
->constant_pool
3624 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
3625 vec_len
= MAYBE_SWAP (vec
[0]);
3626 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
3628 struct dwarf2_per_cu_data
*per_cu
;
3629 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
3630 gdb_index_symbol_kind symbol_kind
=
3631 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3632 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3634 /* Don't crash on bad data. */
3635 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3636 + dwarf2_per_objfile
->n_type_units
))
3639 /* Only check the symbol's kind if it has one.
3640 Indices prior to version 7 don't record it. */
3641 if (index
->version
>= 7)
3645 case VARIABLES_DOMAIN
:
3646 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
3649 case FUNCTIONS_DOMAIN
:
3650 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
3654 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3662 per_cu
= dw2_get_cu (cu_index
);
3663 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
3664 dw2_instantiate_symtab (per_cu
);
3669 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
3672 static struct symtab
*
3673 recursively_find_pc_sect_symtab (struct symtab
*symtab
, CORE_ADDR pc
)
3677 if (BLOCKVECTOR (symtab
) != NULL
3678 && blockvector_contains_pc (BLOCKVECTOR (symtab
), pc
))
3681 if (symtab
->includes
== NULL
)
3684 for (i
= 0; symtab
->includes
[i
]; ++i
)
3686 struct symtab
*s
= symtab
->includes
[i
];
3688 s
= recursively_find_pc_sect_symtab (s
, pc
);
3696 static struct symtab
*
3697 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
3698 struct minimal_symbol
*msymbol
,
3700 struct obj_section
*section
,
3703 struct dwarf2_per_cu_data
*data
;
3704 struct symtab
*result
;
3706 dw2_setup (objfile
);
3708 if (!objfile
->psymtabs_addrmap
)
3711 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
3715 if (warn_if_readin
&& data
->v
.quick
->symtab
)
3716 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3717 paddress (get_objfile_arch (objfile
), pc
));
3719 result
= recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data
), pc
);
3720 gdb_assert (result
!= NULL
);
3725 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
3726 void *data
, int need_fullname
)
3729 struct cleanup
*cleanup
;
3730 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
3731 NULL
, xcalloc
, xfree
);
3733 cleanup
= make_cleanup_htab_delete (visited
);
3734 dw2_setup (objfile
);
3736 /* The rule is CUs specify all the files, including those used by
3737 any TU, so there's no need to scan TUs here.
3738 We can ignore file names coming from already-expanded CUs. */
3740 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3742 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3744 if (per_cu
->v
.quick
->symtab
)
3746 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3749 *slot
= per_cu
->v
.quick
->file_names
;
3753 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3756 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3757 struct quick_file_names
*file_data
;
3760 /* We only need to look at symtabs not already expanded. */
3761 if (per_cu
->v
.quick
->symtab
)
3764 file_data
= dw2_get_file_names (per_cu
);
3765 if (file_data
== NULL
)
3768 slot
= htab_find_slot (visited
, file_data
, INSERT
);
3771 /* Already visited. */
3776 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3778 const char *this_real_name
;
3781 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3783 this_real_name
= NULL
;
3784 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
3788 do_cleanups (cleanup
);
3792 dw2_has_symbols (struct objfile
*objfile
)
3797 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
3800 dw2_find_last_source_symtab
,
3801 dw2_forget_cached_source_info
,
3802 dw2_map_symtabs_matching_filename
,
3807 dw2_expand_symtabs_for_function
,
3808 dw2_expand_all_symtabs
,
3809 dw2_expand_symtabs_with_fullname
,
3810 dw2_find_symbol_file
,
3811 dw2_map_matching_symbols
,
3812 dw2_expand_symtabs_matching
,
3813 dw2_find_pc_sect_symtab
,
3814 dw2_map_symbol_filenames
3817 /* Initialize for reading DWARF for this objfile. Return 0 if this
3818 file will use psymtabs, or 1 if using the GNU index. */
3821 dwarf2_initialize_objfile (struct objfile
*objfile
)
3823 /* If we're about to read full symbols, don't bother with the
3824 indices. In this case we also don't care if some other debug
3825 format is making psymtabs, because they are all about to be
3827 if ((objfile
->flags
& OBJF_READNOW
))
3831 dwarf2_per_objfile
->using_index
= 1;
3832 create_all_comp_units (objfile
);
3833 create_all_type_units (objfile
);
3834 dwarf2_per_objfile
->quick_file_names_table
=
3835 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3837 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3838 + dwarf2_per_objfile
->n_type_units
); ++i
)
3840 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3842 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3843 struct dwarf2_per_cu_quick_data
);
3846 /* Return 1 so that gdb sees the "quick" functions. However,
3847 these functions will be no-ops because we will have expanded
3852 if (dwarf2_read_index (objfile
))
3860 /* Build a partial symbol table. */
3863 dwarf2_build_psymtabs (struct objfile
*objfile
)
3865 volatile struct gdb_exception except
;
3867 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3869 init_psymbol_list (objfile
, 1024);
3872 TRY_CATCH (except
, RETURN_MASK_ERROR
)
3874 /* This isn't really ideal: all the data we allocate on the
3875 objfile's obstack is still uselessly kept around. However,
3876 freeing it seems unsafe. */
3877 struct cleanup
*cleanups
= make_cleanup_discard_psymtabs (objfile
);
3879 dwarf2_build_psymtabs_hard (objfile
);
3880 discard_cleanups (cleanups
);
3882 if (except
.reason
< 0)
3883 exception_print (gdb_stderr
, except
);
3886 /* Return the total length of the CU described by HEADER. */
3889 get_cu_length (const struct comp_unit_head
*header
)
3891 return header
->initial_length_size
+ header
->length
;
3894 /* Return TRUE if OFFSET is within CU_HEADER. */
3897 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3899 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3900 sect_offset top
= { cu_header
->offset
.sect_off
+ get_cu_length (cu_header
) };
3902 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3905 /* Find the base address of the compilation unit for range lists and
3906 location lists. It will normally be specified by DW_AT_low_pc.
3907 In DWARF-3 draft 4, the base address could be overridden by
3908 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3909 compilation units with discontinuous ranges. */
3912 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3914 struct attribute
*attr
;
3917 cu
->base_address
= 0;
3919 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3922 cu
->base_address
= DW_ADDR (attr
);
3927 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3930 cu
->base_address
= DW_ADDR (attr
);
3936 /* Read in the comp unit header information from the debug_info at info_ptr.
3937 NOTE: This leaves members offset, first_die_offset to be filled in
3940 static const gdb_byte
*
3941 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3942 const gdb_byte
*info_ptr
, bfd
*abfd
)
3945 unsigned int bytes_read
;
3947 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3948 cu_header
->initial_length_size
= bytes_read
;
3949 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3950 info_ptr
+= bytes_read
;
3951 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3953 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3955 info_ptr
+= bytes_read
;
3956 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3958 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3959 if (signed_addr
< 0)
3960 internal_error (__FILE__
, __LINE__
,
3961 _("read_comp_unit_head: dwarf from non elf file"));
3962 cu_header
->signed_addr_p
= signed_addr
;
3967 /* Helper function that returns the proper abbrev section for
3970 static struct dwarf2_section_info
*
3971 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
3973 struct dwarf2_section_info
*abbrev
;
3975 if (this_cu
->is_dwz
)
3976 abbrev
= &dwarf2_get_dwz_file ()->abbrev
;
3978 abbrev
= &dwarf2_per_objfile
->abbrev
;
3983 /* Subroutine of read_and_check_comp_unit_head and
3984 read_and_check_type_unit_head to simplify them.
3985 Perform various error checking on the header. */
3988 error_check_comp_unit_head (struct comp_unit_head
*header
,
3989 struct dwarf2_section_info
*section
,
3990 struct dwarf2_section_info
*abbrev_section
)
3992 bfd
*abfd
= section
->asection
->owner
;
3993 const char *filename
= bfd_get_filename (abfd
);
3995 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3996 error (_("Dwarf Error: wrong version in compilation unit header "
3997 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
4000 if (header
->abbrev_offset
.sect_off
4001 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
4002 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
4003 "(offset 0x%lx + 6) [in module %s]"),
4004 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
4007 /* Cast to unsigned long to use 64-bit arithmetic when possible to
4008 avoid potential 32-bit overflow. */
4009 if (((unsigned long) header
->offset
.sect_off
+ get_cu_length (header
))
4011 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
4012 "(offset 0x%lx + 0) [in module %s]"),
4013 (long) header
->length
, (long) header
->offset
.sect_off
,
4017 /* Read in a CU/TU header and perform some basic error checking.
4018 The contents of the header are stored in HEADER.
4019 The result is a pointer to the start of the first DIE. */
4021 static const gdb_byte
*
4022 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
4023 struct dwarf2_section_info
*section
,
4024 struct dwarf2_section_info
*abbrev_section
,
4025 const gdb_byte
*info_ptr
,
4026 int is_debug_types_section
)
4028 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
4029 bfd
*abfd
= section
->asection
->owner
;
4031 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
4033 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
4035 /* If we're reading a type unit, skip over the signature and
4036 type_offset fields. */
4037 if (is_debug_types_section
)
4038 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
4040 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
4042 error_check_comp_unit_head (header
, section
, abbrev_section
);
4047 /* Read in the types comp unit header information from .debug_types entry at
4048 types_ptr. The result is a pointer to one past the end of the header. */
4050 static const gdb_byte
*
4051 read_and_check_type_unit_head (struct comp_unit_head
*header
,
4052 struct dwarf2_section_info
*section
,
4053 struct dwarf2_section_info
*abbrev_section
,
4054 const gdb_byte
*info_ptr
,
4055 ULONGEST
*signature
,
4056 cu_offset
*type_offset_in_tu
)
4058 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
4059 bfd
*abfd
= section
->asection
->owner
;
4061 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
4063 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
4065 /* If we're reading a type unit, skip over the signature and
4066 type_offset fields. */
4067 if (signature
!= NULL
)
4068 *signature
= read_8_bytes (abfd
, info_ptr
);
4070 if (type_offset_in_tu
!= NULL
)
4071 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
4072 header
->offset_size
);
4073 info_ptr
+= header
->offset_size
;
4075 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
4077 error_check_comp_unit_head (header
, section
, abbrev_section
);
4082 /* Fetch the abbreviation table offset from a comp or type unit header. */
4085 read_abbrev_offset (struct dwarf2_section_info
*section
,
4088 bfd
*abfd
= section
->asection
->owner
;
4089 const gdb_byte
*info_ptr
;
4090 unsigned int length
, initial_length_size
, offset_size
;
4091 sect_offset abbrev_offset
;
4093 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
4094 info_ptr
= section
->buffer
+ offset
.sect_off
;
4095 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
4096 offset_size
= initial_length_size
== 4 ? 4 : 8;
4097 info_ptr
+= initial_length_size
+ 2 /*version*/;
4098 abbrev_offset
.sect_off
= read_offset_1 (abfd
, info_ptr
, offset_size
);
4099 return abbrev_offset
;
4102 /* Allocate a new partial symtab for file named NAME and mark this new
4103 partial symtab as being an include of PST. */
4106 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
4107 struct objfile
*objfile
)
4109 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
4111 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
4113 /* It shares objfile->objfile_obstack. */
4114 subpst
->dirname
= pst
->dirname
;
4117 subpst
->section_offsets
= pst
->section_offsets
;
4118 subpst
->textlow
= 0;
4119 subpst
->texthigh
= 0;
4121 subpst
->dependencies
= (struct partial_symtab
**)
4122 obstack_alloc (&objfile
->objfile_obstack
,
4123 sizeof (struct partial_symtab
*));
4124 subpst
->dependencies
[0] = pst
;
4125 subpst
->number_of_dependencies
= 1;
4127 subpst
->globals_offset
= 0;
4128 subpst
->n_global_syms
= 0;
4129 subpst
->statics_offset
= 0;
4130 subpst
->n_static_syms
= 0;
4131 subpst
->symtab
= NULL
;
4132 subpst
->read_symtab
= pst
->read_symtab
;
4135 /* No private part is necessary for include psymtabs. This property
4136 can be used to differentiate between such include psymtabs and
4137 the regular ones. */
4138 subpst
->read_symtab_private
= NULL
;
4141 /* Read the Line Number Program data and extract the list of files
4142 included by the source file represented by PST. Build an include
4143 partial symtab for each of these included files. */
4146 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
4147 struct die_info
*die
,
4148 struct partial_symtab
*pst
)
4150 struct line_header
*lh
= NULL
;
4151 struct attribute
*attr
;
4153 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
4155 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
4157 return; /* No linetable, so no includes. */
4159 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
4160 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
4162 free_line_header (lh
);
4166 hash_signatured_type (const void *item
)
4168 const struct signatured_type
*sig_type
= item
;
4170 /* This drops the top 32 bits of the signature, but is ok for a hash. */
4171 return sig_type
->signature
;
4175 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
4177 const struct signatured_type
*lhs
= item_lhs
;
4178 const struct signatured_type
*rhs
= item_rhs
;
4180 return lhs
->signature
== rhs
->signature
;
4183 /* Allocate a hash table for signatured types. */
4186 allocate_signatured_type_table (struct objfile
*objfile
)
4188 return htab_create_alloc_ex (41,
4189 hash_signatured_type
,
4192 &objfile
->objfile_obstack
,
4193 hashtab_obstack_allocate
,
4194 dummy_obstack_deallocate
);
4197 /* A helper function to add a signatured type CU to a table. */
4200 add_signatured_type_cu_to_table (void **slot
, void *datum
)
4202 struct signatured_type
*sigt
= *slot
;
4203 struct signatured_type
***datap
= datum
;
4211 /* Create the hash table of all entries in the .debug_types
4212 (or .debug_types.dwo) section(s).
4213 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
4214 otherwise it is NULL.
4216 The result is a pointer to the hash table or NULL if there are no types.
4218 Note: This function processes DWO files only, not DWP files. */
4221 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
4222 VEC (dwarf2_section_info_def
) *types
)
4224 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4225 htab_t types_htab
= NULL
;
4227 struct dwarf2_section_info
*section
;
4228 struct dwarf2_section_info
*abbrev_section
;
4230 if (VEC_empty (dwarf2_section_info_def
, types
))
4233 abbrev_section
= (dwo_file
!= NULL
4234 ? &dwo_file
->sections
.abbrev
4235 : &dwarf2_per_objfile
->abbrev
);
4237 if (dwarf2_read_debug
)
4238 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_types%s for %s:\n",
4239 dwo_file
? ".dwo" : "",
4240 bfd_get_filename (abbrev_section
->asection
->owner
));
4243 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
4247 const gdb_byte
*info_ptr
, *end_ptr
;
4248 struct dwarf2_section_info
*abbrev_section
;
4250 dwarf2_read_section (objfile
, section
);
4251 info_ptr
= section
->buffer
;
4253 if (info_ptr
== NULL
)
4256 /* We can't set abfd until now because the section may be empty or
4257 not present, in which case section->asection will be NULL. */
4258 abfd
= section
->asection
->owner
;
4261 abbrev_section
= &dwo_file
->sections
.abbrev
;
4263 abbrev_section
= &dwarf2_per_objfile
->abbrev
;
4265 /* We don't use init_cutu_and_read_dies_simple, or some such, here
4266 because we don't need to read any dies: the signature is in the
4269 end_ptr
= info_ptr
+ section
->size
;
4270 while (info_ptr
< end_ptr
)
4273 cu_offset type_offset_in_tu
;
4275 struct signatured_type
*sig_type
;
4276 struct dwo_unit
*dwo_tu
;
4278 const gdb_byte
*ptr
= info_ptr
;
4279 struct comp_unit_head header
;
4280 unsigned int length
;
4282 offset
.sect_off
= ptr
- section
->buffer
;
4284 /* We need to read the type's signature in order to build the hash
4285 table, but we don't need anything else just yet. */
4287 ptr
= read_and_check_type_unit_head (&header
, section
,
4288 abbrev_section
, ptr
,
4289 &signature
, &type_offset_in_tu
);
4291 length
= get_cu_length (&header
);
4293 /* Skip dummy type units. */
4294 if (ptr
>= info_ptr
+ length
4295 || peek_abbrev_code (abfd
, ptr
) == 0)
4301 if (types_htab
== NULL
)
4304 types_htab
= allocate_dwo_unit_table (objfile
);
4306 types_htab
= allocate_signatured_type_table (objfile
);
4312 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4314 dwo_tu
->dwo_file
= dwo_file
;
4315 dwo_tu
->signature
= signature
;
4316 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
4317 dwo_tu
->section
= section
;
4318 dwo_tu
->offset
= offset
;
4319 dwo_tu
->length
= length
;
4323 /* N.B.: type_offset is not usable if this type uses a DWO file.
4324 The real type_offset is in the DWO file. */
4326 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4327 struct signatured_type
);
4328 sig_type
->signature
= signature
;
4329 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
4330 sig_type
->per_cu
.objfile
= objfile
;
4331 sig_type
->per_cu
.is_debug_types
= 1;
4332 sig_type
->per_cu
.section
= section
;
4333 sig_type
->per_cu
.offset
= offset
;
4334 sig_type
->per_cu
.length
= length
;
4337 slot
= htab_find_slot (types_htab
,
4338 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
4340 gdb_assert (slot
!= NULL
);
4343 sect_offset dup_offset
;
4347 const struct dwo_unit
*dup_tu
= *slot
;
4349 dup_offset
= dup_tu
->offset
;
4353 const struct signatured_type
*dup_tu
= *slot
;
4355 dup_offset
= dup_tu
->per_cu
.offset
;
4358 complaint (&symfile_complaints
,
4359 _("debug type entry at offset 0x%x is duplicate to"
4360 " the entry at offset 0x%x, signature %s"),
4361 offset
.sect_off
, dup_offset
.sect_off
,
4362 hex_string (signature
));
4364 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
4366 if (dwarf2_read_debug
)
4367 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature %s\n",
4369 hex_string (signature
));
4378 /* Create the hash table of all entries in the .debug_types section,
4379 and initialize all_type_units.
4380 The result is zero if there is an error (e.g. missing .debug_types section),
4381 otherwise non-zero. */
4384 create_all_type_units (struct objfile
*objfile
)
4387 struct signatured_type
**iter
;
4389 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
4390 if (types_htab
== NULL
)
4392 dwarf2_per_objfile
->signatured_types
= NULL
;
4396 dwarf2_per_objfile
->signatured_types
= types_htab
;
4398 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
4399 dwarf2_per_objfile
->all_type_units
4400 = xmalloc (dwarf2_per_objfile
->n_type_units
4401 * sizeof (struct signatured_type
*));
4402 iter
= &dwarf2_per_objfile
->all_type_units
[0];
4403 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
4404 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
4405 == dwarf2_per_objfile
->n_type_units
);
4410 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
4411 Fill in SIG_ENTRY with DWO_ENTRY. */
4414 fill_in_sig_entry_from_dwo_entry (struct objfile
*objfile
,
4415 struct signatured_type
*sig_entry
,
4416 struct dwo_unit
*dwo_entry
)
4418 sig_entry
->per_cu
.section
= dwo_entry
->section
;
4419 sig_entry
->per_cu
.offset
= dwo_entry
->offset
;
4420 sig_entry
->per_cu
.length
= dwo_entry
->length
;
4421 sig_entry
->per_cu
.reading_dwo_directly
= 1;
4422 sig_entry
->per_cu
.objfile
= objfile
;
4423 gdb_assert (! sig_entry
->per_cu
.queued
);
4424 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
4425 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
4426 gdb_assert (sig_entry
->per_cu
.v
.quick
->symtab
== NULL
);
4427 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
4428 gdb_assert (sig_entry
->type_offset_in_section
.sect_off
== 0);
4429 gdb_assert (sig_entry
->type_unit_group
== NULL
);
4430 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
4431 sig_entry
->dwo_unit
= dwo_entry
;
4434 /* Subroutine of lookup_signatured_type.
4435 Create the signatured_type data structure for a TU to be read in
4436 directly from a DWO file, bypassing the stub.
4437 We do this for the case where there is no DWP file and we're using
4438 .gdb_index: When reading a CU we want to stay in the DWO file containing
4439 that CU. Otherwise we could end up reading several other DWO files (due
4440 to comdat folding) to process the transitive closure of all the mentioned
4441 TUs, and that can be slow. The current DWO file will have every type
4442 signature that it needs.
4443 We only do this for .gdb_index because in the psymtab case we already have
4444 to read all the DWOs to build the type unit groups. */
4446 static struct signatured_type
*
4447 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
4449 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4450 struct dwo_file
*dwo_file
;
4451 struct dwo_unit find_dwo_entry
, *dwo_entry
;
4452 struct signatured_type find_sig_entry
, *sig_entry
;
4454 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
4456 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
4457 dwo_unit of the TU itself. */
4458 dwo_file
= cu
->dwo_unit
->dwo_file
;
4460 /* We only ever need to read in one copy of a signatured type.
4461 Just use the global signatured_types array. If this is the first time
4462 we're reading this type, replace the recorded data from .gdb_index with
4465 if (dwarf2_per_objfile
->signatured_types
== NULL
)
4467 find_sig_entry
.signature
= sig
;
4468 sig_entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_sig_entry
);
4469 if (sig_entry
== NULL
)
4471 /* Have we already tried to read this TU? */
4472 if (sig_entry
->dwo_unit
!= NULL
)
4475 /* Ok, this is the first time we're reading this TU. */
4476 if (dwo_file
->tus
== NULL
)
4478 find_dwo_entry
.signature
= sig
;
4479 dwo_entry
= htab_find (dwo_file
->tus
, &find_dwo_entry
);
4480 if (dwo_entry
== NULL
)
4483 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
4487 /* Subroutine of lookup_dwp_signatured_type.
4488 Add an entry for signature SIG to dwarf2_per_objfile->signatured_types. */
4490 static struct signatured_type
*
4491 add_type_unit (ULONGEST sig
)
4493 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4494 int n_type_units
= dwarf2_per_objfile
->n_type_units
;
4495 struct signatured_type
*sig_type
;
4499 dwarf2_per_objfile
->all_type_units
=
4500 xrealloc (dwarf2_per_objfile
->all_type_units
,
4501 n_type_units
* sizeof (struct signatured_type
*));
4502 dwarf2_per_objfile
->n_type_units
= n_type_units
;
4503 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4504 struct signatured_type
);
4505 dwarf2_per_objfile
->all_type_units
[n_type_units
- 1] = sig_type
;
4506 sig_type
->signature
= sig
;
4507 sig_type
->per_cu
.is_debug_types
= 1;
4508 sig_type
->per_cu
.v
.quick
=
4509 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4510 struct dwarf2_per_cu_quick_data
);
4511 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
4513 gdb_assert (*slot
== NULL
);
4515 /* The rest of sig_type must be filled in by the caller. */
4519 /* Subroutine of lookup_signatured_type.
4520 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
4521 then try the DWP file.
4522 Normally this "can't happen", but if there's a bug in signature
4523 generation and/or the DWP file is built incorrectly, it can happen.
4524 Using the type directly from the DWP file means we don't have the stub
4525 which has some useful attributes (e.g., DW_AT_comp_dir), but they're
4526 not critical. [Eventually the stub may go away for type units anyway.] */
4528 static struct signatured_type
*
4529 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
4531 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4532 struct dwp_file
*dwp_file
= get_dwp_file ();
4533 struct dwo_unit
*dwo_entry
;
4534 struct signatured_type find_sig_entry
, *sig_entry
;
4536 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
4537 gdb_assert (dwp_file
!= NULL
);
4539 if (dwarf2_per_objfile
->signatured_types
!= NULL
)
4541 find_sig_entry
.signature
= sig
;
4542 sig_entry
= htab_find (dwarf2_per_objfile
->signatured_types
,
4544 if (sig_entry
!= NULL
)
4548 /* This is the "shouldn't happen" case.
4549 Try the DWP file and hope for the best. */
4550 if (dwp_file
->tus
== NULL
)
4552 dwo_entry
= lookup_dwo_in_dwp (dwp_file
, dwp_file
->tus
, NULL
,
4553 sig
, 1 /* is_debug_types */);
4554 if (dwo_entry
== NULL
)
4557 sig_entry
= add_type_unit (sig
);
4558 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
4560 /* The caller will signal a complaint if we return NULL.
4561 Here we don't return NULL but we still want to complain. */
4562 complaint (&symfile_complaints
,
4563 _("Bad type signature %s referenced by %s at 0x%x,"
4564 " coping by using copy in DWP [in module %s]"),
4566 cu
->per_cu
->is_debug_types
? "TU" : "CU",
4567 cu
->per_cu
->offset
.sect_off
,
4573 /* Lookup a signature based type for DW_FORM_ref_sig8.
4574 Returns NULL if signature SIG is not present in the table.
4575 It is up to the caller to complain about this. */
4577 static struct signatured_type
*
4578 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
4581 && dwarf2_per_objfile
->using_index
)
4583 /* We're in a DWO/DWP file, and we're using .gdb_index.
4584 These cases require special processing. */
4585 if (get_dwp_file () == NULL
)
4586 return lookup_dwo_signatured_type (cu
, sig
);
4588 return lookup_dwp_signatured_type (cu
, sig
);
4592 struct signatured_type find_entry
, *entry
;
4594 if (dwarf2_per_objfile
->signatured_types
== NULL
)
4596 find_entry
.signature
= sig
;
4597 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
4602 /* Low level DIE reading support. */
4604 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
4607 init_cu_die_reader (struct die_reader_specs
*reader
,
4608 struct dwarf2_cu
*cu
,
4609 struct dwarf2_section_info
*section
,
4610 struct dwo_file
*dwo_file
)
4612 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
4613 reader
->abfd
= section
->asection
->owner
;
4615 reader
->dwo_file
= dwo_file
;
4616 reader
->die_section
= section
;
4617 reader
->buffer
= section
->buffer
;
4618 reader
->buffer_end
= section
->buffer
+ section
->size
;
4619 reader
->comp_dir
= NULL
;
4622 /* Subroutine of init_cutu_and_read_dies to simplify it.
4623 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
4624 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
4627 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
4628 from it to the DIE in the DWO. If NULL we are skipping the stub.
4629 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
4630 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
4631 attribute of the referencing CU. Exactly one of STUB_COMP_UNIT_DIE and
4632 COMP_DIR must be non-NULL.
4633 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
4634 are filled in with the info of the DIE from the DWO file.
4635 ABBREV_TABLE_PROVIDED is non-zero if the caller of init_cutu_and_read_dies
4636 provided an abbrev table to use.
4637 The result is non-zero if a valid (non-dummy) DIE was found. */
4640 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
4641 struct dwo_unit
*dwo_unit
,
4642 int abbrev_table_provided
,
4643 struct die_info
*stub_comp_unit_die
,
4644 const char *stub_comp_dir
,
4645 struct die_reader_specs
*result_reader
,
4646 const gdb_byte
**result_info_ptr
,
4647 struct die_info
**result_comp_unit_die
,
4648 int *result_has_children
)
4650 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4651 struct dwarf2_cu
*cu
= this_cu
->cu
;
4652 struct dwarf2_section_info
*section
;
4654 const gdb_byte
*begin_info_ptr
, *info_ptr
;
4655 const char *comp_dir_string
;
4656 ULONGEST signature
; /* Or dwo_id. */
4657 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
4658 int i
,num_extra_attrs
;
4659 struct dwarf2_section_info
*dwo_abbrev_section
;
4660 struct attribute
*attr
;
4661 struct attribute comp_dir_attr
;
4662 struct die_info
*comp_unit_die
;
4664 /* Both can't be provided. */
4665 gdb_assert (! (stub_comp_unit_die
&& stub_comp_dir
));
4667 /* These attributes aren't processed until later:
4668 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
4669 However, the attribute is found in the stub which we won't have later.
4670 In order to not impose this complication on the rest of the code,
4671 we read them here and copy them to the DWO CU/TU die. */
4679 if (stub_comp_unit_die
!= NULL
)
4681 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
4683 if (! this_cu
->is_debug_types
)
4684 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
4685 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
4686 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
4687 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
4688 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
4690 /* There should be a DW_AT_addr_base attribute here (if needed).
4691 We need the value before we can process DW_FORM_GNU_addr_index. */
4693 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
4695 cu
->addr_base
= DW_UNSND (attr
);
4697 /* There should be a DW_AT_ranges_base attribute here (if needed).
4698 We need the value before we can process DW_AT_ranges. */
4699 cu
->ranges_base
= 0;
4700 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
4702 cu
->ranges_base
= DW_UNSND (attr
);
4704 else if (stub_comp_dir
!= NULL
)
4706 /* Reconstruct the comp_dir attribute to simplify the code below. */
4707 comp_dir
= (struct attribute
*)
4708 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (*comp_dir
));
4709 comp_dir
->name
= DW_AT_comp_dir
;
4710 comp_dir
->form
= DW_FORM_string
;
4711 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
4712 DW_STRING (comp_dir
) = stub_comp_dir
;
4715 /* Set up for reading the DWO CU/TU. */
4716 cu
->dwo_unit
= dwo_unit
;
4717 section
= dwo_unit
->section
;
4718 dwarf2_read_section (objfile
, section
);
4719 abfd
= section
->asection
->owner
;
4720 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
4721 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
4722 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
);
4724 if (this_cu
->is_debug_types
)
4726 ULONGEST header_signature
;
4727 cu_offset type_offset_in_tu
;
4728 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
4730 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4734 &type_offset_in_tu
);
4735 /* This is not an assert because it can be caused by bad debug info. */
4736 if (sig_type
->signature
!= header_signature
)
4738 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
4739 " TU at offset 0x%x [in module %s]"),
4740 hex_string (sig_type
->signature
),
4741 hex_string (header_signature
),
4742 dwo_unit
->offset
.sect_off
,
4743 bfd_get_filename (abfd
));
4745 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4746 /* For DWOs coming from DWP files, we don't know the CU length
4747 nor the type's offset in the TU until now. */
4748 dwo_unit
->length
= get_cu_length (&cu
->header
);
4749 dwo_unit
->type_offset_in_tu
= type_offset_in_tu
;
4751 /* Establish the type offset that can be used to lookup the type.
4752 For DWO files, we don't know it until now. */
4753 sig_type
->type_offset_in_section
.sect_off
=
4754 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
4758 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4761 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4762 /* For DWOs coming from DWP files, we don't know the CU length
4764 dwo_unit
->length
= get_cu_length (&cu
->header
);
4767 /* Replace the CU's original abbrev table with the DWO's.
4768 Reminder: We can't read the abbrev table until we've read the header. */
4769 if (abbrev_table_provided
)
4771 /* Don't free the provided abbrev table, the caller of
4772 init_cutu_and_read_dies owns it. */
4773 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4774 /* Ensure the DWO abbrev table gets freed. */
4775 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4779 dwarf2_free_abbrev_table (cu
);
4780 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4781 /* Leave any existing abbrev table cleanup as is. */
4784 /* Read in the die, but leave space to copy over the attributes
4785 from the stub. This has the benefit of simplifying the rest of
4786 the code - all the work to maintain the illusion of a single
4787 DW_TAG_{compile,type}_unit DIE is done here. */
4788 num_extra_attrs
= ((stmt_list
!= NULL
)
4792 + (comp_dir
!= NULL
));
4793 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
4794 result_has_children
, num_extra_attrs
);
4796 /* Copy over the attributes from the stub to the DIE we just read in. */
4797 comp_unit_die
= *result_comp_unit_die
;
4798 i
= comp_unit_die
->num_attrs
;
4799 if (stmt_list
!= NULL
)
4800 comp_unit_die
->attrs
[i
++] = *stmt_list
;
4802 comp_unit_die
->attrs
[i
++] = *low_pc
;
4803 if (high_pc
!= NULL
)
4804 comp_unit_die
->attrs
[i
++] = *high_pc
;
4806 comp_unit_die
->attrs
[i
++] = *ranges
;
4807 if (comp_dir
!= NULL
)
4808 comp_unit_die
->attrs
[i
++] = *comp_dir
;
4809 comp_unit_die
->num_attrs
+= num_extra_attrs
;
4811 if (dwarf2_die_debug
)
4813 fprintf_unfiltered (gdb_stdlog
,
4814 "Read die from %s@0x%x of %s:\n",
4815 bfd_section_name (abfd
, section
->asection
),
4816 (unsigned) (begin_info_ptr
- section
->buffer
),
4817 bfd_get_filename (abfd
));
4818 dump_die (comp_unit_die
, dwarf2_die_debug
);
4821 /* Save the comp_dir attribute. If there is no DWP file then we'll read
4822 TUs by skipping the stub and going directly to the entry in the DWO file.
4823 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
4824 to get it via circuitous means. Blech. */
4825 if (comp_dir
!= NULL
)
4826 result_reader
->comp_dir
= DW_STRING (comp_dir
);
4828 /* Skip dummy compilation units. */
4829 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
4830 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4833 *result_info_ptr
= info_ptr
;
4837 /* Subroutine of init_cutu_and_read_dies to simplify it.
4838 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
4839 Returns NULL if the specified DWO unit cannot be found. */
4841 static struct dwo_unit
*
4842 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
4843 struct die_info
*comp_unit_die
)
4845 struct dwarf2_cu
*cu
= this_cu
->cu
;
4846 struct attribute
*attr
;
4848 struct dwo_unit
*dwo_unit
;
4849 const char *comp_dir
, *dwo_name
;
4851 gdb_assert (cu
!= NULL
);
4853 /* Yeah, we look dwo_name up again, but it simplifies the code. */
4854 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
4855 gdb_assert (attr
!= NULL
);
4856 dwo_name
= DW_STRING (attr
);
4858 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4860 comp_dir
= DW_STRING (attr
);
4862 if (this_cu
->is_debug_types
)
4864 struct signatured_type
*sig_type
;
4866 /* Since this_cu is the first member of struct signatured_type,
4867 we can go from a pointer to one to a pointer to the other. */
4868 sig_type
= (struct signatured_type
*) this_cu
;
4869 signature
= sig_type
->signature
;
4870 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
4874 struct attribute
*attr
;
4876 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
4878 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
4880 dwo_name
, this_cu
->objfile
->name
);
4881 signature
= DW_UNSND (attr
);
4882 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
4889 /* Subroutine of init_cutu_and_read_dies to simplify it.
4890 Read a TU directly from a DWO file, bypassing the stub. */
4893 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
, int keep
,
4894 die_reader_func_ftype
*die_reader_func
,
4897 struct dwarf2_cu
*cu
;
4898 struct signatured_type
*sig_type
;
4899 struct cleanup
*cleanups
, *free_cu_cleanup
;
4900 struct die_reader_specs reader
;
4901 const gdb_byte
*info_ptr
;
4902 struct die_info
*comp_unit_die
;
4905 /* Verify we can do the following downcast, and that we have the
4907 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
4908 sig_type
= (struct signatured_type
*) this_cu
;
4909 gdb_assert (sig_type
->dwo_unit
!= NULL
);
4911 cleanups
= make_cleanup (null_cleanup
, NULL
);
4913 gdb_assert (this_cu
->cu
== NULL
);
4914 cu
= xmalloc (sizeof (*cu
));
4915 init_one_comp_unit (cu
, this_cu
);
4916 /* If an error occurs while loading, release our storage. */
4917 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
4919 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
4920 0 /* abbrev_table_provided */,
4921 NULL
/* stub_comp_unit_die */,
4922 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
4924 &comp_unit_die
, &has_children
) == 0)
4927 do_cleanups (cleanups
);
4931 /* All the "real" work is done here. */
4932 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4934 /* This duplicates some code in init_cutu_and_read_dies,
4935 but the alternative is making the latter more complex.
4936 This function is only for the special case of using DWO files directly:
4937 no point in overly complicating the general case just to handle this. */
4940 /* We've successfully allocated this compilation unit. Let our
4941 caller clean it up when finished with it. */
4942 discard_cleanups (free_cu_cleanup
);
4944 /* We can only discard free_cu_cleanup and all subsequent cleanups.
4945 So we have to manually free the abbrev table. */
4946 dwarf2_free_abbrev_table (cu
);
4948 /* Link this CU into read_in_chain. */
4949 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4950 dwarf2_per_objfile
->read_in_chain
= this_cu
;
4953 do_cleanups (free_cu_cleanup
);
4955 do_cleanups (cleanups
);
4958 /* Initialize a CU (or TU) and read its DIEs.
4959 If the CU defers to a DWO file, read the DWO file as well.
4961 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
4962 Otherwise the table specified in the comp unit header is read in and used.
4963 This is an optimization for when we already have the abbrev table.
4965 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
4966 Otherwise, a new CU is allocated with xmalloc.
4968 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
4969 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
4971 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4972 linker) then DIE_READER_FUNC will not get called. */
4975 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
4976 struct abbrev_table
*abbrev_table
,
4977 int use_existing_cu
, int keep
,
4978 die_reader_func_ftype
*die_reader_func
,
4981 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4982 struct dwarf2_section_info
*section
= this_cu
->section
;
4983 bfd
*abfd
= section
->asection
->owner
;
4984 struct dwarf2_cu
*cu
;
4985 const gdb_byte
*begin_info_ptr
, *info_ptr
;
4986 struct die_reader_specs reader
;
4987 struct die_info
*comp_unit_die
;
4989 struct attribute
*attr
;
4990 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
4991 struct signatured_type
*sig_type
= NULL
;
4992 struct dwarf2_section_info
*abbrev_section
;
4993 /* Non-zero if CU currently points to a DWO file and we need to
4994 reread it. When this happens we need to reread the skeleton die
4995 before we can reread the DWO file (this only applies to CUs, not TUs). */
4996 int rereading_dwo_cu
= 0;
4998 if (dwarf2_die_debug
)
4999 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
5000 this_cu
->is_debug_types
? "type" : "comp",
5001 this_cu
->offset
.sect_off
);
5003 if (use_existing_cu
)
5006 /* If we're reading a TU directly from a DWO file, including a virtual DWO
5007 file (instead of going through the stub), short-circuit all of this. */
5008 if (this_cu
->reading_dwo_directly
)
5010 /* Narrow down the scope of possibilities to have to understand. */
5011 gdb_assert (this_cu
->is_debug_types
);
5012 gdb_assert (abbrev_table
== NULL
);
5013 gdb_assert (!use_existing_cu
);
5014 init_tu_and_read_dwo_dies (this_cu
, keep
, die_reader_func
, data
);
5018 cleanups
= make_cleanup (null_cleanup
, NULL
);
5020 /* This is cheap if the section is already read in. */
5021 dwarf2_read_section (objfile
, section
);
5023 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
5025 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
5027 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
5031 /* If this CU is from a DWO file we need to start over, we need to
5032 refetch the attributes from the skeleton CU.
5033 This could be optimized by retrieving those attributes from when we
5034 were here the first time: the previous comp_unit_die was stored in
5035 comp_unit_obstack. But there's no data yet that we need this
5037 if (cu
->dwo_unit
!= NULL
)
5038 rereading_dwo_cu
= 1;
5042 /* If !use_existing_cu, this_cu->cu must be NULL. */
5043 gdb_assert (this_cu
->cu
== NULL
);
5045 cu
= xmalloc (sizeof (*cu
));
5046 init_one_comp_unit (cu
, this_cu
);
5048 /* If an error occurs while loading, release our storage. */
5049 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
5052 /* Get the header. */
5053 if (cu
->header
.first_die_offset
.cu_off
!= 0 && ! rereading_dwo_cu
)
5055 /* We already have the header, there's no need to read it in again. */
5056 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
5060 if (this_cu
->is_debug_types
)
5063 cu_offset type_offset_in_tu
;
5065 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
5066 abbrev_section
, info_ptr
,
5068 &type_offset_in_tu
);
5070 /* Since per_cu is the first member of struct signatured_type,
5071 we can go from a pointer to one to a pointer to the other. */
5072 sig_type
= (struct signatured_type
*) this_cu
;
5073 gdb_assert (sig_type
->signature
== signature
);
5074 gdb_assert (sig_type
->type_offset_in_tu
.cu_off
5075 == type_offset_in_tu
.cu_off
);
5076 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
5078 /* LENGTH has not been set yet for type units if we're
5079 using .gdb_index. */
5080 this_cu
->length
= get_cu_length (&cu
->header
);
5082 /* Establish the type offset that can be used to lookup the type. */
5083 sig_type
->type_offset_in_section
.sect_off
=
5084 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
5088 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5092 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
5093 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
5097 /* Skip dummy compilation units. */
5098 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
5099 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5101 do_cleanups (cleanups
);
5105 /* If we don't have them yet, read the abbrevs for this compilation unit.
5106 And if we need to read them now, make sure they're freed when we're
5107 done. Note that it's important that if the CU had an abbrev table
5108 on entry we don't free it when we're done: Somewhere up the call stack
5109 it may be in use. */
5110 if (abbrev_table
!= NULL
)
5112 gdb_assert (cu
->abbrev_table
== NULL
);
5113 gdb_assert (cu
->header
.abbrev_offset
.sect_off
5114 == abbrev_table
->offset
.sect_off
);
5115 cu
->abbrev_table
= abbrev_table
;
5117 else if (cu
->abbrev_table
== NULL
)
5119 dwarf2_read_abbrevs (cu
, abbrev_section
);
5120 make_cleanup (dwarf2_free_abbrev_table
, cu
);
5122 else if (rereading_dwo_cu
)
5124 dwarf2_free_abbrev_table (cu
);
5125 dwarf2_read_abbrevs (cu
, abbrev_section
);
5128 /* Read the top level CU/TU die. */
5129 init_cu_die_reader (&reader
, cu
, section
, NULL
);
5130 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
5132 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
5134 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
5135 DWO CU, that this test will fail (the attribute will not be present). */
5136 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
5139 struct dwo_unit
*dwo_unit
;
5140 struct die_info
*dwo_comp_unit_die
;
5144 complaint (&symfile_complaints
,
5145 _("compilation unit with DW_AT_GNU_dwo_name"
5146 " has children (offset 0x%x) [in module %s]"),
5147 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
5149 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
5150 if (dwo_unit
!= NULL
)
5152 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
5153 abbrev_table
!= NULL
,
5154 comp_unit_die
, NULL
,
5156 &dwo_comp_unit_die
, &has_children
) == 0)
5159 do_cleanups (cleanups
);
5162 comp_unit_die
= dwo_comp_unit_die
;
5166 /* Yikes, we couldn't find the rest of the DIE, we only have
5167 the stub. A complaint has already been logged. There's
5168 not much more we can do except pass on the stub DIE to
5169 die_reader_func. We don't want to throw an error on bad
5174 /* All of the above is setup for this call. Yikes. */
5175 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5177 /* Done, clean up. */
5178 if (free_cu_cleanup
!= NULL
)
5182 /* We've successfully allocated this compilation unit. Let our
5183 caller clean it up when finished with it. */
5184 discard_cleanups (free_cu_cleanup
);
5186 /* We can only discard free_cu_cleanup and all subsequent cleanups.
5187 So we have to manually free the abbrev table. */
5188 dwarf2_free_abbrev_table (cu
);
5190 /* Link this CU into read_in_chain. */
5191 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5192 dwarf2_per_objfile
->read_in_chain
= this_cu
;
5195 do_cleanups (free_cu_cleanup
);
5198 do_cleanups (cleanups
);
5201 /* Read CU/TU THIS_CU in section SECTION,
5202 but do not follow DW_AT_GNU_dwo_name if present.
5203 DWOP_FILE, if non-NULL, is the DWO/DWP file to read (the caller is assumed
5204 to have already done the lookup to find the DWO/DWP file).
5206 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
5207 THIS_CU->is_debug_types, but nothing else.
5209 We fill in THIS_CU->length.
5211 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
5212 linker) then DIE_READER_FUNC will not get called.
5214 THIS_CU->cu is always freed when done.
5215 This is done in order to not leave THIS_CU->cu in a state where we have
5216 to care whether it refers to the "main" CU or the DWO CU. */
5219 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
5220 struct dwarf2_section_info
*abbrev_section
,
5221 struct dwo_file
*dwo_file
,
5222 die_reader_func_ftype
*die_reader_func
,
5225 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5226 struct dwarf2_section_info
*section
= this_cu
->section
;
5227 bfd
*abfd
= section
->asection
->owner
;
5228 struct dwarf2_cu cu
;
5229 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5230 struct die_reader_specs reader
;
5231 struct cleanup
*cleanups
;
5232 struct die_info
*comp_unit_die
;
5235 if (dwarf2_die_debug
)
5236 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
5237 this_cu
->is_debug_types
? "type" : "comp",
5238 this_cu
->offset
.sect_off
);
5240 gdb_assert (this_cu
->cu
== NULL
);
5242 /* This is cheap if the section is already read in. */
5243 dwarf2_read_section (objfile
, section
);
5245 init_one_comp_unit (&cu
, this_cu
);
5247 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
5249 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
5250 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
5251 abbrev_section
, info_ptr
,
5252 this_cu
->is_debug_types
);
5254 this_cu
->length
= get_cu_length (&cu
.header
);
5256 /* Skip dummy compilation units. */
5257 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
5258 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5260 do_cleanups (cleanups
);
5264 dwarf2_read_abbrevs (&cu
, abbrev_section
);
5265 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
5267 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
5268 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
5270 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5272 do_cleanups (cleanups
);
5275 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
5276 does not lookup the specified DWO file.
5277 This cannot be used to read DWO files.
5279 THIS_CU->cu is always freed when done.
5280 This is done in order to not leave THIS_CU->cu in a state where we have
5281 to care whether it refers to the "main" CU or the DWO CU.
5282 We can revisit this if the data shows there's a performance issue. */
5285 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
5286 die_reader_func_ftype
*die_reader_func
,
5289 init_cutu_and_read_dies_no_follow (this_cu
,
5290 get_abbrev_section_for_cu (this_cu
),
5292 die_reader_func
, data
);
5295 /* Type Unit Groups.
5297 Type Unit Groups are a way to collapse the set of all TUs (type units) into
5298 a more manageable set. The grouping is done by DW_AT_stmt_list entry
5299 so that all types coming from the same compilation (.o file) are grouped
5300 together. A future step could be to put the types in the same symtab as
5301 the CU the types ultimately came from. */
5304 hash_type_unit_group (const void *item
)
5306 const struct type_unit_group
*tu_group
= item
;
5308 return hash_stmt_list_entry (&tu_group
->hash
);
5312 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
5314 const struct type_unit_group
*lhs
= item_lhs
;
5315 const struct type_unit_group
*rhs
= item_rhs
;
5317 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
5320 /* Allocate a hash table for type unit groups. */
5323 allocate_type_unit_groups_table (void)
5325 return htab_create_alloc_ex (3,
5326 hash_type_unit_group
,
5329 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
5330 hashtab_obstack_allocate
,
5331 dummy_obstack_deallocate
);
5334 /* Type units that don't have DW_AT_stmt_list are grouped into their own
5335 partial symtabs. We combine several TUs per psymtab to not let the size
5336 of any one psymtab grow too big. */
5337 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
5338 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
5340 /* Helper routine for get_type_unit_group.
5341 Create the type_unit_group object used to hold one or more TUs. */
5343 static struct type_unit_group
*
5344 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
5346 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5347 struct dwarf2_per_cu_data
*per_cu
;
5348 struct type_unit_group
*tu_group
;
5350 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5351 struct type_unit_group
);
5352 per_cu
= &tu_group
->per_cu
;
5353 per_cu
->objfile
= objfile
;
5355 if (dwarf2_per_objfile
->using_index
)
5357 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5358 struct dwarf2_per_cu_quick_data
);
5362 unsigned int line_offset
= line_offset_struct
.sect_off
;
5363 struct partial_symtab
*pst
;
5366 /* Give the symtab a useful name for debug purposes. */
5367 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
5368 name
= xstrprintf ("<type_units_%d>",
5369 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
5371 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
5373 pst
= create_partial_symtab (per_cu
, name
);
5379 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
5380 tu_group
->hash
.line_offset
= line_offset_struct
;
5385 /* Look up the type_unit_group for type unit CU, and create it if necessary.
5386 STMT_LIST is a DW_AT_stmt_list attribute. */
5388 static struct type_unit_group
*
5389 get_type_unit_group (struct dwarf2_cu
*cu
, struct attribute
*stmt_list
)
5391 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
5392 struct type_unit_group
*tu_group
;
5394 unsigned int line_offset
;
5395 struct type_unit_group type_unit_group_for_lookup
;
5397 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
5399 dwarf2_per_objfile
->type_unit_groups
=
5400 allocate_type_unit_groups_table ();
5403 /* Do we need to create a new group, or can we use an existing one? */
5407 line_offset
= DW_UNSND (stmt_list
);
5408 ++tu_stats
->nr_symtab_sharers
;
5412 /* Ugh, no stmt_list. Rare, but we have to handle it.
5413 We can do various things here like create one group per TU or
5414 spread them over multiple groups to split up the expansion work.
5415 To avoid worst case scenarios (too many groups or too large groups)
5416 we, umm, group them in bunches. */
5417 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
5418 | (tu_stats
->nr_stmt_less_type_units
5419 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
5420 ++tu_stats
->nr_stmt_less_type_units
;
5423 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
5424 type_unit_group_for_lookup
.hash
.line_offset
.sect_off
= line_offset
;
5425 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
5426 &type_unit_group_for_lookup
, INSERT
);
5430 gdb_assert (tu_group
!= NULL
);
5434 sect_offset line_offset_struct
;
5436 line_offset_struct
.sect_off
= line_offset
;
5437 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
5439 ++tu_stats
->nr_symtabs
;
5445 /* Struct used to sort TUs by their abbreviation table offset. */
5447 struct tu_abbrev_offset
5449 struct signatured_type
*sig_type
;
5450 sect_offset abbrev_offset
;
5453 /* Helper routine for build_type_unit_groups, passed to qsort. */
5456 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
5458 const struct tu_abbrev_offset
* const *a
= ap
;
5459 const struct tu_abbrev_offset
* const *b
= bp
;
5460 unsigned int aoff
= (*a
)->abbrev_offset
.sect_off
;
5461 unsigned int boff
= (*b
)->abbrev_offset
.sect_off
;
5463 return (aoff
> boff
) - (aoff
< boff
);
5466 /* A helper function to add a type_unit_group to a table. */
5469 add_type_unit_group_to_table (void **slot
, void *datum
)
5471 struct type_unit_group
*tu_group
= *slot
;
5472 struct type_unit_group
***datap
= datum
;
5480 /* Efficiently read all the type units, calling init_cutu_and_read_dies on
5481 each one passing FUNC,DATA.
5483 The efficiency is because we sort TUs by the abbrev table they use and
5484 only read each abbrev table once. In one program there are 200K TUs
5485 sharing 8K abbrev tables.
5487 The main purpose of this function is to support building the
5488 dwarf2_per_objfile->type_unit_groups table.
5489 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
5490 can collapse the search space by grouping them by stmt_list.
5491 The savings can be significant, in the same program from above the 200K TUs
5492 share 8K stmt_list tables.
5494 FUNC is expected to call get_type_unit_group, which will create the
5495 struct type_unit_group if necessary and add it to
5496 dwarf2_per_objfile->type_unit_groups. */
5499 build_type_unit_groups (die_reader_func_ftype
*func
, void *data
)
5501 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5502 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
5503 struct cleanup
*cleanups
;
5504 struct abbrev_table
*abbrev_table
;
5505 sect_offset abbrev_offset
;
5506 struct tu_abbrev_offset
*sorted_by_abbrev
;
5507 struct type_unit_group
**iter
;
5510 /* It's up to the caller to not call us multiple times. */
5511 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
5513 if (dwarf2_per_objfile
->n_type_units
== 0)
5516 /* TUs typically share abbrev tables, and there can be way more TUs than
5517 abbrev tables. Sort by abbrev table to reduce the number of times we
5518 read each abbrev table in.
5519 Alternatives are to punt or to maintain a cache of abbrev tables.
5520 This is simpler and efficient enough for now.
5522 Later we group TUs by their DW_AT_stmt_list value (as this defines the
5523 symtab to use). Typically TUs with the same abbrev offset have the same
5524 stmt_list value too so in practice this should work well.
5526 The basic algorithm here is:
5528 sort TUs by abbrev table
5529 for each TU with same abbrev table:
5530 read abbrev table if first user
5531 read TU top level DIE
5532 [IWBN if DWO skeletons had DW_AT_stmt_list]
5535 if (dwarf2_read_debug
)
5536 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
5538 /* Sort in a separate table to maintain the order of all_type_units
5539 for .gdb_index: TU indices directly index all_type_units. */
5540 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
5541 dwarf2_per_objfile
->n_type_units
);
5542 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5544 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
5546 sorted_by_abbrev
[i
].sig_type
= sig_type
;
5547 sorted_by_abbrev
[i
].abbrev_offset
=
5548 read_abbrev_offset (sig_type
->per_cu
.section
,
5549 sig_type
->per_cu
.offset
);
5551 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
5552 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
5553 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
5555 /* Note: In the .gdb_index case, get_type_unit_group may have already been
5556 called any number of times, so we don't reset tu_stats here. */
5558 abbrev_offset
.sect_off
= ~(unsigned) 0;
5559 abbrev_table
= NULL
;
5560 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
5562 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5564 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
5566 /* Switch to the next abbrev table if necessary. */
5567 if (abbrev_table
== NULL
5568 || tu
->abbrev_offset
.sect_off
!= abbrev_offset
.sect_off
)
5570 if (abbrev_table
!= NULL
)
5572 abbrev_table_free (abbrev_table
);
5573 /* Reset to NULL in case abbrev_table_read_table throws
5574 an error: abbrev_table_free_cleanup will get called. */
5575 abbrev_table
= NULL
;
5577 abbrev_offset
= tu
->abbrev_offset
;
5579 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
5581 ++tu_stats
->nr_uniq_abbrev_tables
;
5584 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
5588 /* type_unit_groups can be NULL if there is an error in the debug info.
5589 Just create an empty table so the rest of gdb doesn't have to watch
5590 for this error case. */
5591 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
5593 dwarf2_per_objfile
->type_unit_groups
=
5594 allocate_type_unit_groups_table ();
5595 dwarf2_per_objfile
->n_type_unit_groups
= 0;
5598 /* Create a vector of pointers to primary type units to make it easy to
5599 iterate over them and CUs. See dw2_get_primary_cu. */
5600 dwarf2_per_objfile
->n_type_unit_groups
=
5601 htab_elements (dwarf2_per_objfile
->type_unit_groups
);
5602 dwarf2_per_objfile
->all_type_unit_groups
=
5603 obstack_alloc (&objfile
->objfile_obstack
,
5604 dwarf2_per_objfile
->n_type_unit_groups
5605 * sizeof (struct type_unit_group
*));
5606 iter
= &dwarf2_per_objfile
->all_type_unit_groups
[0];
5607 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5608 add_type_unit_group_to_table
, &iter
);
5609 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_unit_groups
[0]
5610 == dwarf2_per_objfile
->n_type_unit_groups
);
5612 do_cleanups (cleanups
);
5614 if (dwarf2_read_debug
)
5616 fprintf_unfiltered (gdb_stdlog
, "Done building type unit groups:\n");
5617 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
5618 dwarf2_per_objfile
->n_type_units
);
5619 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
5620 tu_stats
->nr_uniq_abbrev_tables
);
5621 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
5622 tu_stats
->nr_symtabs
);
5623 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
5624 tu_stats
->nr_symtab_sharers
);
5625 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
5626 tu_stats
->nr_stmt_less_type_units
);
5630 /* Partial symbol tables. */
5632 /* Create a psymtab named NAME and assign it to PER_CU.
5634 The caller must fill in the following details:
5635 dirname, textlow, texthigh. */
5637 static struct partial_symtab
*
5638 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
5640 struct objfile
*objfile
= per_cu
->objfile
;
5641 struct partial_symtab
*pst
;
5643 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
5645 objfile
->global_psymbols
.next
,
5646 objfile
->static_psymbols
.next
);
5648 pst
->psymtabs_addrmap_supported
= 1;
5650 /* This is the glue that links PST into GDB's symbol API. */
5651 pst
->read_symtab_private
= per_cu
;
5652 pst
->read_symtab
= dwarf2_read_symtab
;
5653 per_cu
->v
.psymtab
= pst
;
5658 /* die_reader_func for process_psymtab_comp_unit. */
5661 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
5662 const gdb_byte
*info_ptr
,
5663 struct die_info
*comp_unit_die
,
5667 struct dwarf2_cu
*cu
= reader
->cu
;
5668 struct objfile
*objfile
= cu
->objfile
;
5669 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
5670 struct attribute
*attr
;
5672 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
5673 struct partial_symtab
*pst
;
5675 const char *filename
;
5676 int *want_partial_unit_ptr
= data
;
5678 if (comp_unit_die
->tag
== DW_TAG_partial_unit
5679 && (want_partial_unit_ptr
== NULL
5680 || !*want_partial_unit_ptr
))
5683 gdb_assert (! per_cu
->is_debug_types
);
5685 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
5687 cu
->list_in_scope
= &file_symbols
;
5689 /* Allocate a new partial symbol table structure. */
5690 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
5691 if (attr
== NULL
|| !DW_STRING (attr
))
5694 filename
= DW_STRING (attr
);
5696 pst
= create_partial_symtab (per_cu
, filename
);
5698 /* This must be done before calling dwarf2_build_include_psymtabs. */
5699 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
5701 pst
->dirname
= DW_STRING (attr
);
5703 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5705 dwarf2_find_base_address (comp_unit_die
, cu
);
5707 /* Possibly set the default values of LOWPC and HIGHPC from
5709 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
5710 &best_highpc
, cu
, pst
);
5711 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
5712 /* Store the contiguous range if it is not empty; it can be empty for
5713 CUs with no code. */
5714 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5715 best_lowpc
+ baseaddr
,
5716 best_highpc
+ baseaddr
- 1, pst
);
5718 /* Check if comp unit has_children.
5719 If so, read the rest of the partial symbols from this comp unit.
5720 If not, there's no more debug_info for this comp unit. */
5723 struct partial_die_info
*first_die
;
5724 CORE_ADDR lowpc
, highpc
;
5726 lowpc
= ((CORE_ADDR
) -1);
5727 highpc
= ((CORE_ADDR
) 0);
5729 first_die
= load_partial_dies (reader
, info_ptr
, 1);
5731 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
5734 /* If we didn't find a lowpc, set it to highpc to avoid
5735 complaints from `maint check'. */
5736 if (lowpc
== ((CORE_ADDR
) -1))
5739 /* If the compilation unit didn't have an explicit address range,
5740 then use the information extracted from its child dies. */
5744 best_highpc
= highpc
;
5747 pst
->textlow
= best_lowpc
+ baseaddr
;
5748 pst
->texthigh
= best_highpc
+ baseaddr
;
5750 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
5751 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
5752 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
5753 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
5754 sort_pst_symbols (objfile
, pst
);
5756 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
5759 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
5760 struct dwarf2_per_cu_data
*iter
;
5762 /* Fill in 'dependencies' here; we fill in 'users' in a
5764 pst
->number_of_dependencies
= len
;
5765 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
5766 len
* sizeof (struct symtab
*));
5768 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
5771 pst
->dependencies
[i
] = iter
->v
.psymtab
;
5773 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
5776 /* Get the list of files included in the current compilation unit,
5777 and build a psymtab for each of them. */
5778 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
5780 if (dwarf2_read_debug
)
5782 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5784 fprintf_unfiltered (gdb_stdlog
,
5785 "Psymtab for %s unit @0x%x: %s - %s"
5786 ", %d global, %d static syms\n",
5787 per_cu
->is_debug_types
? "type" : "comp",
5788 per_cu
->offset
.sect_off
,
5789 paddress (gdbarch
, pst
->textlow
),
5790 paddress (gdbarch
, pst
->texthigh
),
5791 pst
->n_global_syms
, pst
->n_static_syms
);
5795 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
5796 Process compilation unit THIS_CU for a psymtab. */
5799 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
5800 int want_partial_unit
)
5802 /* If this compilation unit was already read in, free the
5803 cached copy in order to read it in again. This is
5804 necessary because we skipped some symbols when we first
5805 read in the compilation unit (see load_partial_dies).
5806 This problem could be avoided, but the benefit is unclear. */
5807 if (this_cu
->cu
!= NULL
)
5808 free_one_cached_comp_unit (this_cu
);
5810 gdb_assert (! this_cu
->is_debug_types
);
5811 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
5812 process_psymtab_comp_unit_reader
,
5813 &want_partial_unit
);
5815 /* Age out any secondary CUs. */
5816 age_cached_comp_units ();
5819 /* Reader function for build_type_psymtabs. */
5822 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
5823 const gdb_byte
*info_ptr
,
5824 struct die_info
*type_unit_die
,
5828 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5829 struct dwarf2_cu
*cu
= reader
->cu
;
5830 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
5831 struct signatured_type
*sig_type
;
5832 struct type_unit_group
*tu_group
;
5833 struct attribute
*attr
;
5834 struct partial_die_info
*first_die
;
5835 CORE_ADDR lowpc
, highpc
;
5836 struct partial_symtab
*pst
;
5838 gdb_assert (data
== NULL
);
5839 gdb_assert (per_cu
->is_debug_types
);
5840 sig_type
= (struct signatured_type
*) per_cu
;
5845 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
5846 tu_group
= get_type_unit_group (cu
, attr
);
5848 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
5850 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
5851 cu
->list_in_scope
= &file_symbols
;
5852 pst
= create_partial_symtab (per_cu
, "");
5855 first_die
= load_partial_dies (reader
, info_ptr
, 1);
5857 lowpc
= (CORE_ADDR
) -1;
5858 highpc
= (CORE_ADDR
) 0;
5859 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
5861 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
5862 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
5863 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
5864 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
5865 sort_pst_symbols (objfile
, pst
);
5868 /* Traversal function for build_type_psymtabs. */
5871 build_type_psymtab_dependencies (void **slot
, void *info
)
5873 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5874 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
5875 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
5876 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5877 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
5878 struct signatured_type
*iter
;
5881 gdb_assert (len
> 0);
5882 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
5884 pst
->number_of_dependencies
= len
;
5885 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
5886 len
* sizeof (struct psymtab
*));
5888 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
5891 gdb_assert (iter
->per_cu
.is_debug_types
);
5892 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
5893 iter
->type_unit_group
= tu_group
;
5896 VEC_free (sig_type_ptr
, tu_group
->tus
);
5901 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
5902 Build partial symbol tables for the .debug_types comp-units. */
5905 build_type_psymtabs (struct objfile
*objfile
)
5907 if (! create_all_type_units (objfile
))
5910 build_type_unit_groups (build_type_psymtabs_reader
, NULL
);
5912 /* Now that all TUs have been processed we can fill in the dependencies. */
5913 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5914 build_type_psymtab_dependencies
, NULL
);
5917 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
5920 psymtabs_addrmap_cleanup (void *o
)
5922 struct objfile
*objfile
= o
;
5924 objfile
->psymtabs_addrmap
= NULL
;
5927 /* Compute the 'user' field for each psymtab in OBJFILE. */
5930 set_partial_user (struct objfile
*objfile
)
5934 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5936 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5937 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5943 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
5945 /* Set the 'user' field only if it is not already set. */
5946 if (pst
->dependencies
[j
]->user
== NULL
)
5947 pst
->dependencies
[j
]->user
= pst
;
5952 /* Build the partial symbol table by doing a quick pass through the
5953 .debug_info and .debug_abbrev sections. */
5956 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
5958 struct cleanup
*back_to
, *addrmap_cleanup
;
5959 struct obstack temp_obstack
;
5962 if (dwarf2_read_debug
)
5964 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
5968 dwarf2_per_objfile
->reading_partial_symbols
= 1;
5970 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
5972 /* Any cached compilation units will be linked by the per-objfile
5973 read_in_chain. Make sure to free them when we're done. */
5974 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
5976 build_type_psymtabs (objfile
);
5978 create_all_comp_units (objfile
);
5980 /* Create a temporary address map on a temporary obstack. We later
5981 copy this to the final obstack. */
5982 obstack_init (&temp_obstack
);
5983 make_cleanup_obstack_free (&temp_obstack
);
5984 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
5985 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
5987 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5989 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5991 process_psymtab_comp_unit (per_cu
, 0);
5994 set_partial_user (objfile
);
5996 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
5997 &objfile
->objfile_obstack
);
5998 discard_cleanups (addrmap_cleanup
);
6000 do_cleanups (back_to
);
6002 if (dwarf2_read_debug
)
6003 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
6007 /* die_reader_func for load_partial_comp_unit. */
6010 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
6011 const gdb_byte
*info_ptr
,
6012 struct die_info
*comp_unit_die
,
6016 struct dwarf2_cu
*cu
= reader
->cu
;
6018 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
6020 /* Check if comp unit has_children.
6021 If so, read the rest of the partial symbols from this comp unit.
6022 If not, there's no more debug_info for this comp unit. */
6024 load_partial_dies (reader
, info_ptr
, 0);
6027 /* Load the partial DIEs for a secondary CU into memory.
6028 This is also used when rereading a primary CU with load_all_dies. */
6031 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
6033 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
6034 load_partial_comp_unit_reader
, NULL
);
6038 read_comp_units_from_section (struct objfile
*objfile
,
6039 struct dwarf2_section_info
*section
,
6040 unsigned int is_dwz
,
6043 struct dwarf2_per_cu_data
***all_comp_units
)
6045 const gdb_byte
*info_ptr
;
6046 bfd
*abfd
= section
->asection
->owner
;
6048 if (dwarf2_read_debug
)
6049 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
6050 section
->asection
->name
, bfd_get_filename (abfd
));
6052 dwarf2_read_section (objfile
, section
);
6054 info_ptr
= section
->buffer
;
6056 while (info_ptr
< section
->buffer
+ section
->size
)
6058 unsigned int length
, initial_length_size
;
6059 struct dwarf2_per_cu_data
*this_cu
;
6062 offset
.sect_off
= info_ptr
- section
->buffer
;
6064 /* Read just enough information to find out where the next
6065 compilation unit is. */
6066 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6068 /* Save the compilation unit for later lookup. */
6069 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
6070 sizeof (struct dwarf2_per_cu_data
));
6071 memset (this_cu
, 0, sizeof (*this_cu
));
6072 this_cu
->offset
= offset
;
6073 this_cu
->length
= length
+ initial_length_size
;
6074 this_cu
->is_dwz
= is_dwz
;
6075 this_cu
->objfile
= objfile
;
6076 this_cu
->section
= section
;
6078 if (*n_comp_units
== *n_allocated
)
6081 *all_comp_units
= xrealloc (*all_comp_units
,
6083 * sizeof (struct dwarf2_per_cu_data
*));
6085 (*all_comp_units
)[*n_comp_units
] = this_cu
;
6088 info_ptr
= info_ptr
+ this_cu
->length
;
6092 /* Create a list of all compilation units in OBJFILE.
6093 This is only done for -readnow and building partial symtabs. */
6096 create_all_comp_units (struct objfile
*objfile
)
6100 struct dwarf2_per_cu_data
**all_comp_units
;
6104 all_comp_units
= xmalloc (n_allocated
6105 * sizeof (struct dwarf2_per_cu_data
*));
6107 read_comp_units_from_section (objfile
, &dwarf2_per_objfile
->info
, 0,
6108 &n_allocated
, &n_comp_units
, &all_comp_units
);
6110 if (bfd_get_section_by_name (objfile
->obfd
, ".gnu_debugaltlink") != NULL
)
6112 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
6114 read_comp_units_from_section (objfile
, &dwz
->info
, 1,
6115 &n_allocated
, &n_comp_units
,
6119 dwarf2_per_objfile
->all_comp_units
6120 = obstack_alloc (&objfile
->objfile_obstack
,
6121 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
6122 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
6123 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
6124 xfree (all_comp_units
);
6125 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
6128 /* Process all loaded DIEs for compilation unit CU, starting at
6129 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
6130 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
6131 DW_AT_ranges). If NEED_PC is set, then this function will set
6132 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
6133 and record the covered ranges in the addrmap. */
6136 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
6137 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
6139 struct partial_die_info
*pdi
;
6141 /* Now, march along the PDI's, descending into ones which have
6142 interesting children but skipping the children of the other ones,
6143 until we reach the end of the compilation unit. */
6149 fixup_partial_die (pdi
, cu
);
6151 /* Anonymous namespaces or modules have no name but have interesting
6152 children, so we need to look at them. Ditto for anonymous
6155 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
6156 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
6157 || pdi
->tag
== DW_TAG_imported_unit
)
6161 case DW_TAG_subprogram
:
6162 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
6164 case DW_TAG_constant
:
6165 case DW_TAG_variable
:
6166 case DW_TAG_typedef
:
6167 case DW_TAG_union_type
:
6168 if (!pdi
->is_declaration
)
6170 add_partial_symbol (pdi
, cu
);
6173 case DW_TAG_class_type
:
6174 case DW_TAG_interface_type
:
6175 case DW_TAG_structure_type
:
6176 if (!pdi
->is_declaration
)
6178 add_partial_symbol (pdi
, cu
);
6181 case DW_TAG_enumeration_type
:
6182 if (!pdi
->is_declaration
)
6183 add_partial_enumeration (pdi
, cu
);
6185 case DW_TAG_base_type
:
6186 case DW_TAG_subrange_type
:
6187 /* File scope base type definitions are added to the partial
6189 add_partial_symbol (pdi
, cu
);
6191 case DW_TAG_namespace
:
6192 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
6195 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
6197 case DW_TAG_imported_unit
:
6199 struct dwarf2_per_cu_data
*per_cu
;
6201 /* For now we don't handle imported units in type units. */
6202 if (cu
->per_cu
->is_debug_types
)
6204 error (_("Dwarf Error: DW_TAG_imported_unit is not"
6205 " supported in type units [in module %s]"),
6209 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
6213 /* Go read the partial unit, if needed. */
6214 if (per_cu
->v
.psymtab
== NULL
)
6215 process_psymtab_comp_unit (per_cu
, 1);
6217 VEC_safe_push (dwarf2_per_cu_ptr
,
6218 cu
->per_cu
->imported_symtabs
, per_cu
);
6226 /* If the die has a sibling, skip to the sibling. */
6228 pdi
= pdi
->die_sibling
;
6232 /* Functions used to compute the fully scoped name of a partial DIE.
6234 Normally, this is simple. For C++, the parent DIE's fully scoped
6235 name is concatenated with "::" and the partial DIE's name. For
6236 Java, the same thing occurs except that "." is used instead of "::".
6237 Enumerators are an exception; they use the scope of their parent
6238 enumeration type, i.e. the name of the enumeration type is not
6239 prepended to the enumerator.
6241 There are two complexities. One is DW_AT_specification; in this
6242 case "parent" means the parent of the target of the specification,
6243 instead of the direct parent of the DIE. The other is compilers
6244 which do not emit DW_TAG_namespace; in this case we try to guess
6245 the fully qualified name of structure types from their members'
6246 linkage names. This must be done using the DIE's children rather
6247 than the children of any DW_AT_specification target. We only need
6248 to do this for structures at the top level, i.e. if the target of
6249 any DW_AT_specification (if any; otherwise the DIE itself) does not
6252 /* Compute the scope prefix associated with PDI's parent, in
6253 compilation unit CU. The result will be allocated on CU's
6254 comp_unit_obstack, or a copy of the already allocated PDI->NAME
6255 field. NULL is returned if no prefix is necessary. */
6257 partial_die_parent_scope (struct partial_die_info
*pdi
,
6258 struct dwarf2_cu
*cu
)
6260 const char *grandparent_scope
;
6261 struct partial_die_info
*parent
, *real_pdi
;
6263 /* We need to look at our parent DIE; if we have a DW_AT_specification,
6264 then this means the parent of the specification DIE. */
6267 while (real_pdi
->has_specification
)
6268 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
6269 real_pdi
->spec_is_dwz
, cu
);
6271 parent
= real_pdi
->die_parent
;
6275 if (parent
->scope_set
)
6276 return parent
->scope
;
6278 fixup_partial_die (parent
, cu
);
6280 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
6282 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
6283 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
6284 Work around this problem here. */
6285 if (cu
->language
== language_cplus
6286 && parent
->tag
== DW_TAG_namespace
6287 && strcmp (parent
->name
, "::") == 0
6288 && grandparent_scope
== NULL
)
6290 parent
->scope
= NULL
;
6291 parent
->scope_set
= 1;
6295 if (pdi
->tag
== DW_TAG_enumerator
)
6296 /* Enumerators should not get the name of the enumeration as a prefix. */
6297 parent
->scope
= grandparent_scope
;
6298 else if (parent
->tag
== DW_TAG_namespace
6299 || parent
->tag
== DW_TAG_module
6300 || parent
->tag
== DW_TAG_structure_type
6301 || parent
->tag
== DW_TAG_class_type
6302 || parent
->tag
== DW_TAG_interface_type
6303 || parent
->tag
== DW_TAG_union_type
6304 || parent
->tag
== DW_TAG_enumeration_type
)
6306 if (grandparent_scope
== NULL
)
6307 parent
->scope
= parent
->name
;
6309 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
6311 parent
->name
, 0, cu
);
6315 /* FIXME drow/2004-04-01: What should we be doing with
6316 function-local names? For partial symbols, we should probably be
6318 complaint (&symfile_complaints
,
6319 _("unhandled containing DIE tag %d for DIE at %d"),
6320 parent
->tag
, pdi
->offset
.sect_off
);
6321 parent
->scope
= grandparent_scope
;
6324 parent
->scope_set
= 1;
6325 return parent
->scope
;
6328 /* Return the fully scoped name associated with PDI, from compilation unit
6329 CU. The result will be allocated with malloc. */
6332 partial_die_full_name (struct partial_die_info
*pdi
,
6333 struct dwarf2_cu
*cu
)
6335 const char *parent_scope
;
6337 /* If this is a template instantiation, we can not work out the
6338 template arguments from partial DIEs. So, unfortunately, we have
6339 to go through the full DIEs. At least any work we do building
6340 types here will be reused if full symbols are loaded later. */
6341 if (pdi
->has_template_arguments
)
6343 fixup_partial_die (pdi
, cu
);
6345 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
6347 struct die_info
*die
;
6348 struct attribute attr
;
6349 struct dwarf2_cu
*ref_cu
= cu
;
6351 /* DW_FORM_ref_addr is using section offset. */
6353 attr
.form
= DW_FORM_ref_addr
;
6354 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
6355 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
6357 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
6361 parent_scope
= partial_die_parent_scope (pdi
, cu
);
6362 if (parent_scope
== NULL
)
6365 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
6369 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
6371 struct objfile
*objfile
= cu
->objfile
;
6373 const char *actual_name
= NULL
;
6375 char *built_actual_name
;
6377 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6379 built_actual_name
= partial_die_full_name (pdi
, cu
);
6380 if (built_actual_name
!= NULL
)
6381 actual_name
= built_actual_name
;
6383 if (actual_name
== NULL
)
6384 actual_name
= pdi
->name
;
6388 case DW_TAG_subprogram
:
6389 if (pdi
->is_external
|| cu
->language
== language_ada
)
6391 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
6392 of the global scope. But in Ada, we want to be able to access
6393 nested procedures globally. So all Ada subprograms are stored
6394 in the global scope. */
6395 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
6396 mst_text, objfile); */
6397 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6398 built_actual_name
!= NULL
,
6399 VAR_DOMAIN
, LOC_BLOCK
,
6400 &objfile
->global_psymbols
,
6401 0, pdi
->lowpc
+ baseaddr
,
6402 cu
->language
, objfile
);
6406 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
6407 mst_file_text, objfile); */
6408 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6409 built_actual_name
!= NULL
,
6410 VAR_DOMAIN
, LOC_BLOCK
,
6411 &objfile
->static_psymbols
,
6412 0, pdi
->lowpc
+ baseaddr
,
6413 cu
->language
, objfile
);
6416 case DW_TAG_constant
:
6418 struct psymbol_allocation_list
*list
;
6420 if (pdi
->is_external
)
6421 list
= &objfile
->global_psymbols
;
6423 list
= &objfile
->static_psymbols
;
6424 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6425 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
6426 list
, 0, 0, cu
->language
, objfile
);
6429 case DW_TAG_variable
:
6431 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
6435 && !dwarf2_per_objfile
->has_section_at_zero
)
6437 /* A global or static variable may also have been stripped
6438 out by the linker if unused, in which case its address
6439 will be nullified; do not add such variables into partial
6440 symbol table then. */
6442 else if (pdi
->is_external
)
6445 Don't enter into the minimal symbol tables as there is
6446 a minimal symbol table entry from the ELF symbols already.
6447 Enter into partial symbol table if it has a location
6448 descriptor or a type.
6449 If the location descriptor is missing, new_symbol will create
6450 a LOC_UNRESOLVED symbol, the address of the variable will then
6451 be determined from the minimal symbol table whenever the variable
6453 The address for the partial symbol table entry is not
6454 used by GDB, but it comes in handy for debugging partial symbol
6457 if (pdi
->d
.locdesc
|| pdi
->has_type
)
6458 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6459 built_actual_name
!= NULL
,
6460 VAR_DOMAIN
, LOC_STATIC
,
6461 &objfile
->global_psymbols
,
6463 cu
->language
, objfile
);
6467 /* Static Variable. Skip symbols without location descriptors. */
6468 if (pdi
->d
.locdesc
== NULL
)
6470 xfree (built_actual_name
);
6473 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
6474 mst_file_data, objfile); */
6475 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6476 built_actual_name
!= NULL
,
6477 VAR_DOMAIN
, LOC_STATIC
,
6478 &objfile
->static_psymbols
,
6480 cu
->language
, objfile
);
6483 case DW_TAG_typedef
:
6484 case DW_TAG_base_type
:
6485 case DW_TAG_subrange_type
:
6486 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6487 built_actual_name
!= NULL
,
6488 VAR_DOMAIN
, LOC_TYPEDEF
,
6489 &objfile
->static_psymbols
,
6490 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
6492 case DW_TAG_namespace
:
6493 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6494 built_actual_name
!= NULL
,
6495 VAR_DOMAIN
, LOC_TYPEDEF
,
6496 &objfile
->global_psymbols
,
6497 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
6499 case DW_TAG_class_type
:
6500 case DW_TAG_interface_type
:
6501 case DW_TAG_structure_type
:
6502 case DW_TAG_union_type
:
6503 case DW_TAG_enumeration_type
:
6504 /* Skip external references. The DWARF standard says in the section
6505 about "Structure, Union, and Class Type Entries": "An incomplete
6506 structure, union or class type is represented by a structure,
6507 union or class entry that does not have a byte size attribute
6508 and that has a DW_AT_declaration attribute." */
6509 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
6511 xfree (built_actual_name
);
6515 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
6516 static vs. global. */
6517 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6518 built_actual_name
!= NULL
,
6519 STRUCT_DOMAIN
, LOC_TYPEDEF
,
6520 (cu
->language
== language_cplus
6521 || cu
->language
== language_java
)
6522 ? &objfile
->global_psymbols
6523 : &objfile
->static_psymbols
,
6524 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
6527 case DW_TAG_enumerator
:
6528 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6529 built_actual_name
!= NULL
,
6530 VAR_DOMAIN
, LOC_CONST
,
6531 (cu
->language
== language_cplus
6532 || cu
->language
== language_java
)
6533 ? &objfile
->global_psymbols
6534 : &objfile
->static_psymbols
,
6535 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
6541 xfree (built_actual_name
);
6544 /* Read a partial die corresponding to a namespace; also, add a symbol
6545 corresponding to that namespace to the symbol table. NAMESPACE is
6546 the name of the enclosing namespace. */
6549 add_partial_namespace (struct partial_die_info
*pdi
,
6550 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6551 int need_pc
, struct dwarf2_cu
*cu
)
6553 /* Add a symbol for the namespace. */
6555 add_partial_symbol (pdi
, cu
);
6557 /* Now scan partial symbols in that namespace. */
6559 if (pdi
->has_children
)
6560 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
6563 /* Read a partial die corresponding to a Fortran module. */
6566 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
6567 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
6569 /* Now scan partial symbols in that module. */
6571 if (pdi
->has_children
)
6572 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
6575 /* Read a partial die corresponding to a subprogram and create a partial
6576 symbol for that subprogram. When the CU language allows it, this
6577 routine also defines a partial symbol for each nested subprogram
6578 that this subprogram contains.
6580 DIE my also be a lexical block, in which case we simply search
6581 recursively for suprograms defined inside that lexical block.
6582 Again, this is only performed when the CU language allows this
6583 type of definitions. */
6586 add_partial_subprogram (struct partial_die_info
*pdi
,
6587 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6588 int need_pc
, struct dwarf2_cu
*cu
)
6590 if (pdi
->tag
== DW_TAG_subprogram
)
6592 if (pdi
->has_pc_info
)
6594 if (pdi
->lowpc
< *lowpc
)
6595 *lowpc
= pdi
->lowpc
;
6596 if (pdi
->highpc
> *highpc
)
6597 *highpc
= pdi
->highpc
;
6601 struct objfile
*objfile
= cu
->objfile
;
6603 baseaddr
= ANOFFSET (objfile
->section_offsets
,
6604 SECT_OFF_TEXT (objfile
));
6605 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6606 pdi
->lowpc
+ baseaddr
,
6607 pdi
->highpc
- 1 + baseaddr
,
6608 cu
->per_cu
->v
.psymtab
);
6612 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
6614 if (!pdi
->is_declaration
)
6615 /* Ignore subprogram DIEs that do not have a name, they are
6616 illegal. Do not emit a complaint at this point, we will
6617 do so when we convert this psymtab into a symtab. */
6619 add_partial_symbol (pdi
, cu
);
6623 if (! pdi
->has_children
)
6626 if (cu
->language
== language_ada
)
6628 pdi
= pdi
->die_child
;
6631 fixup_partial_die (pdi
, cu
);
6632 if (pdi
->tag
== DW_TAG_subprogram
6633 || pdi
->tag
== DW_TAG_lexical_block
)
6634 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
6635 pdi
= pdi
->die_sibling
;
6640 /* Read a partial die corresponding to an enumeration type. */
6643 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
6644 struct dwarf2_cu
*cu
)
6646 struct partial_die_info
*pdi
;
6648 if (enum_pdi
->name
!= NULL
)
6649 add_partial_symbol (enum_pdi
, cu
);
6651 pdi
= enum_pdi
->die_child
;
6654 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
6655 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
6657 add_partial_symbol (pdi
, cu
);
6658 pdi
= pdi
->die_sibling
;
6662 /* Return the initial uleb128 in the die at INFO_PTR. */
6665 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
6667 unsigned int bytes_read
;
6669 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6672 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
6673 Return the corresponding abbrev, or NULL if the number is zero (indicating
6674 an empty DIE). In either case *BYTES_READ will be set to the length of
6675 the initial number. */
6677 static struct abbrev_info
*
6678 peek_die_abbrev (const gdb_byte
*info_ptr
, unsigned int *bytes_read
,
6679 struct dwarf2_cu
*cu
)
6681 bfd
*abfd
= cu
->objfile
->obfd
;
6682 unsigned int abbrev_number
;
6683 struct abbrev_info
*abbrev
;
6685 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
6687 if (abbrev_number
== 0)
6690 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
6693 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
6694 abbrev_number
, bfd_get_filename (abfd
));
6700 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6701 Returns a pointer to the end of a series of DIEs, terminated by an empty
6702 DIE. Any children of the skipped DIEs will also be skipped. */
6704 static const gdb_byte
*
6705 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
6707 struct dwarf2_cu
*cu
= reader
->cu
;
6708 struct abbrev_info
*abbrev
;
6709 unsigned int bytes_read
;
6713 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
6715 return info_ptr
+ bytes_read
;
6717 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
6721 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6722 INFO_PTR should point just after the initial uleb128 of a DIE, and the
6723 abbrev corresponding to that skipped uleb128 should be passed in
6724 ABBREV. Returns a pointer to this DIE's sibling, skipping any
6727 static const gdb_byte
*
6728 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
6729 struct abbrev_info
*abbrev
)
6731 unsigned int bytes_read
;
6732 struct attribute attr
;
6733 bfd
*abfd
= reader
->abfd
;
6734 struct dwarf2_cu
*cu
= reader
->cu
;
6735 const gdb_byte
*buffer
= reader
->buffer
;
6736 const gdb_byte
*buffer_end
= reader
->buffer_end
;
6737 const gdb_byte
*start_info_ptr
= info_ptr
;
6738 unsigned int form
, i
;
6740 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
6742 /* The only abbrev we care about is DW_AT_sibling. */
6743 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
6745 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
6746 if (attr
.form
== DW_FORM_ref_addr
)
6747 complaint (&symfile_complaints
,
6748 _("ignoring absolute DW_AT_sibling"));
6750 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
6753 /* If it isn't DW_AT_sibling, skip this attribute. */
6754 form
= abbrev
->attrs
[i
].form
;
6758 case DW_FORM_ref_addr
:
6759 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
6760 and later it is offset sized. */
6761 if (cu
->header
.version
== 2)
6762 info_ptr
+= cu
->header
.addr_size
;
6764 info_ptr
+= cu
->header
.offset_size
;
6766 case DW_FORM_GNU_ref_alt
:
6767 info_ptr
+= cu
->header
.offset_size
;
6770 info_ptr
+= cu
->header
.addr_size
;
6777 case DW_FORM_flag_present
:
6789 case DW_FORM_ref_sig8
:
6792 case DW_FORM_string
:
6793 read_direct_string (abfd
, info_ptr
, &bytes_read
);
6794 info_ptr
+= bytes_read
;
6796 case DW_FORM_sec_offset
:
6798 case DW_FORM_GNU_strp_alt
:
6799 info_ptr
+= cu
->header
.offset_size
;
6801 case DW_FORM_exprloc
:
6803 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6804 info_ptr
+= bytes_read
;
6806 case DW_FORM_block1
:
6807 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
6809 case DW_FORM_block2
:
6810 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
6812 case DW_FORM_block4
:
6813 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
6817 case DW_FORM_ref_udata
:
6818 case DW_FORM_GNU_addr_index
:
6819 case DW_FORM_GNU_str_index
:
6820 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
6822 case DW_FORM_indirect
:
6823 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6824 info_ptr
+= bytes_read
;
6825 /* We need to continue parsing from here, so just go back to
6827 goto skip_attribute
;
6830 error (_("Dwarf Error: Cannot handle %s "
6831 "in DWARF reader [in module %s]"),
6832 dwarf_form_name (form
),
6833 bfd_get_filename (abfd
));
6837 if (abbrev
->has_children
)
6838 return skip_children (reader
, info_ptr
);
6843 /* Locate ORIG_PDI's sibling.
6844 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
6846 static const gdb_byte
*
6847 locate_pdi_sibling (const struct die_reader_specs
*reader
,
6848 struct partial_die_info
*orig_pdi
,
6849 const gdb_byte
*info_ptr
)
6851 /* Do we know the sibling already? */
6853 if (orig_pdi
->sibling
)
6854 return orig_pdi
->sibling
;
6856 /* Are there any children to deal with? */
6858 if (!orig_pdi
->has_children
)
6861 /* Skip the children the long way. */
6863 return skip_children (reader
, info_ptr
);
6866 /* Expand this partial symbol table into a full symbol table. SELF is
6870 dwarf2_read_symtab (struct partial_symtab
*self
,
6871 struct objfile
*objfile
)
6875 warning (_("bug: psymtab for %s is already read in."),
6882 printf_filtered (_("Reading in symbols for %s..."),
6884 gdb_flush (gdb_stdout
);
6887 /* Restore our global data. */
6888 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
6890 /* If this psymtab is constructed from a debug-only objfile, the
6891 has_section_at_zero flag will not necessarily be correct. We
6892 can get the correct value for this flag by looking at the data
6893 associated with the (presumably stripped) associated objfile. */
6894 if (objfile
->separate_debug_objfile_backlink
)
6896 struct dwarf2_per_objfile
*dpo_backlink
6897 = objfile_data (objfile
->separate_debug_objfile_backlink
,
6898 dwarf2_objfile_data_key
);
6900 dwarf2_per_objfile
->has_section_at_zero
6901 = dpo_backlink
->has_section_at_zero
;
6904 dwarf2_per_objfile
->reading_partial_symbols
= 0;
6906 psymtab_to_symtab_1 (self
);
6908 /* Finish up the debug error message. */
6910 printf_filtered (_("done.\n"));
6913 process_cu_includes ();
6916 /* Reading in full CUs. */
6918 /* Add PER_CU to the queue. */
6921 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6922 enum language pretend_language
)
6924 struct dwarf2_queue_item
*item
;
6927 item
= xmalloc (sizeof (*item
));
6928 item
->per_cu
= per_cu
;
6929 item
->pretend_language
= pretend_language
;
6932 if (dwarf2_queue
== NULL
)
6933 dwarf2_queue
= item
;
6935 dwarf2_queue_tail
->next
= item
;
6937 dwarf2_queue_tail
= item
;
6940 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
6941 unit and add it to our queue.
6942 The result is non-zero if PER_CU was queued, otherwise the result is zero
6943 meaning either PER_CU is already queued or it is already loaded. */
6946 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
6947 struct dwarf2_per_cu_data
*per_cu
,
6948 enum language pretend_language
)
6950 /* We may arrive here during partial symbol reading, if we need full
6951 DIEs to process an unusual case (e.g. template arguments). Do
6952 not queue PER_CU, just tell our caller to load its DIEs. */
6953 if (dwarf2_per_objfile
->reading_partial_symbols
)
6955 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
6960 /* Mark the dependence relation so that we don't flush PER_CU
6962 dwarf2_add_dependence (this_cu
, per_cu
);
6964 /* If it's already on the queue, we have nothing to do. */
6968 /* If the compilation unit is already loaded, just mark it as
6970 if (per_cu
->cu
!= NULL
)
6972 per_cu
->cu
->last_used
= 0;
6976 /* Add it to the queue. */
6977 queue_comp_unit (per_cu
, pretend_language
);
6982 /* Process the queue. */
6985 process_queue (void)
6987 struct dwarf2_queue_item
*item
, *next_item
;
6989 if (dwarf2_read_debug
)
6991 fprintf_unfiltered (gdb_stdlog
,
6992 "Expanding one or more symtabs of objfile %s ...\n",
6993 dwarf2_per_objfile
->objfile
->name
);
6996 /* The queue starts out with one item, but following a DIE reference
6997 may load a new CU, adding it to the end of the queue. */
6998 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
7000 if (dwarf2_per_objfile
->using_index
7001 ? !item
->per_cu
->v
.quick
->symtab
7002 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
7004 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
7006 if (dwarf2_read_debug
)
7008 fprintf_unfiltered (gdb_stdlog
,
7009 "Expanding symtab of %s at offset 0x%x\n",
7010 per_cu
->is_debug_types
? "TU" : "CU",
7011 per_cu
->offset
.sect_off
);
7014 if (per_cu
->is_debug_types
)
7015 process_full_type_unit (per_cu
, item
->pretend_language
);
7017 process_full_comp_unit (per_cu
, item
->pretend_language
);
7019 if (dwarf2_read_debug
)
7021 fprintf_unfiltered (gdb_stdlog
,
7022 "Done expanding %s at offset 0x%x\n",
7023 per_cu
->is_debug_types
? "TU" : "CU",
7024 per_cu
->offset
.sect_off
);
7028 item
->per_cu
->queued
= 0;
7029 next_item
= item
->next
;
7033 dwarf2_queue_tail
= NULL
;
7035 if (dwarf2_read_debug
)
7037 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
7038 dwarf2_per_objfile
->objfile
->name
);
7042 /* Free all allocated queue entries. This function only releases anything if
7043 an error was thrown; if the queue was processed then it would have been
7044 freed as we went along. */
7047 dwarf2_release_queue (void *dummy
)
7049 struct dwarf2_queue_item
*item
, *last
;
7051 item
= dwarf2_queue
;
7054 /* Anything still marked queued is likely to be in an
7055 inconsistent state, so discard it. */
7056 if (item
->per_cu
->queued
)
7058 if (item
->per_cu
->cu
!= NULL
)
7059 free_one_cached_comp_unit (item
->per_cu
);
7060 item
->per_cu
->queued
= 0;
7068 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
7071 /* Read in full symbols for PST, and anything it depends on. */
7074 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
7076 struct dwarf2_per_cu_data
*per_cu
;
7082 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
7083 if (!pst
->dependencies
[i
]->readin
7084 && pst
->dependencies
[i
]->user
== NULL
)
7086 /* Inform about additional files that need to be read in. */
7089 /* FIXME: i18n: Need to make this a single string. */
7090 fputs_filtered (" ", gdb_stdout
);
7092 fputs_filtered ("and ", gdb_stdout
);
7094 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
7095 wrap_here (""); /* Flush output. */
7096 gdb_flush (gdb_stdout
);
7098 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
7101 per_cu
= pst
->read_symtab_private
;
7105 /* It's an include file, no symbols to read for it.
7106 Everything is in the parent symtab. */
7111 dw2_do_instantiate_symtab (per_cu
);
7114 /* Trivial hash function for die_info: the hash value of a DIE
7115 is its offset in .debug_info for this objfile. */
7118 die_hash (const void *item
)
7120 const struct die_info
*die
= item
;
7122 return die
->offset
.sect_off
;
7125 /* Trivial comparison function for die_info structures: two DIEs
7126 are equal if they have the same offset. */
7129 die_eq (const void *item_lhs
, const void *item_rhs
)
7131 const struct die_info
*die_lhs
= item_lhs
;
7132 const struct die_info
*die_rhs
= item_rhs
;
7134 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
7137 /* die_reader_func for load_full_comp_unit.
7138 This is identical to read_signatured_type_reader,
7139 but is kept separate for now. */
7142 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
7143 const gdb_byte
*info_ptr
,
7144 struct die_info
*comp_unit_die
,
7148 struct dwarf2_cu
*cu
= reader
->cu
;
7149 enum language
*language_ptr
= data
;
7151 gdb_assert (cu
->die_hash
== NULL
);
7153 htab_create_alloc_ex (cu
->header
.length
/ 12,
7157 &cu
->comp_unit_obstack
,
7158 hashtab_obstack_allocate
,
7159 dummy_obstack_deallocate
);
7162 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
7163 &info_ptr
, comp_unit_die
);
7164 cu
->dies
= comp_unit_die
;
7165 /* comp_unit_die is not stored in die_hash, no need. */
7167 /* We try not to read any attributes in this function, because not
7168 all CUs needed for references have been loaded yet, and symbol
7169 table processing isn't initialized. But we have to set the CU language,
7170 or we won't be able to build types correctly.
7171 Similarly, if we do not read the producer, we can not apply
7172 producer-specific interpretation. */
7173 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
7176 /* Load the DIEs associated with PER_CU into memory. */
7179 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7180 enum language pretend_language
)
7182 gdb_assert (! this_cu
->is_debug_types
);
7184 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
7185 load_full_comp_unit_reader
, &pretend_language
);
7188 /* Add a DIE to the delayed physname list. */
7191 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
7192 const char *name
, struct die_info
*die
,
7193 struct dwarf2_cu
*cu
)
7195 struct delayed_method_info mi
;
7197 mi
.fnfield_index
= fnfield_index
;
7201 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
7204 /* A cleanup for freeing the delayed method list. */
7207 free_delayed_list (void *ptr
)
7209 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
7210 if (cu
->method_list
!= NULL
)
7212 VEC_free (delayed_method_info
, cu
->method_list
);
7213 cu
->method_list
= NULL
;
7217 /* Compute the physnames of any methods on the CU's method list.
7219 The computation of method physnames is delayed in order to avoid the
7220 (bad) condition that one of the method's formal parameters is of an as yet
7224 compute_delayed_physnames (struct dwarf2_cu
*cu
)
7227 struct delayed_method_info
*mi
;
7228 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
7230 const char *physname
;
7231 struct fn_fieldlist
*fn_flp
7232 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
7233 physname
= dwarf2_physname (mi
->name
, mi
->die
, cu
);
7234 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
7238 /* Go objects should be embedded in a DW_TAG_module DIE,
7239 and it's not clear if/how imported objects will appear.
7240 To keep Go support simple until that's worked out,
7241 go back through what we've read and create something usable.
7242 We could do this while processing each DIE, and feels kinda cleaner,
7243 but that way is more invasive.
7244 This is to, for example, allow the user to type "p var" or "b main"
7245 without having to specify the package name, and allow lookups
7246 of module.object to work in contexts that use the expression
7250 fixup_go_packaging (struct dwarf2_cu
*cu
)
7252 char *package_name
= NULL
;
7253 struct pending
*list
;
7256 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
7258 for (i
= 0; i
< list
->nsyms
; ++i
)
7260 struct symbol
*sym
= list
->symbol
[i
];
7262 if (SYMBOL_LANGUAGE (sym
) == language_go
7263 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
7265 char *this_package_name
= go_symbol_package_name (sym
);
7267 if (this_package_name
== NULL
)
7269 if (package_name
== NULL
)
7270 package_name
= this_package_name
;
7273 if (strcmp (package_name
, this_package_name
) != 0)
7274 complaint (&symfile_complaints
,
7275 _("Symtab %s has objects from two different Go packages: %s and %s"),
7276 (SYMBOL_SYMTAB (sym
)
7277 ? symtab_to_filename_for_display (SYMBOL_SYMTAB (sym
))
7278 : cu
->objfile
->name
),
7279 this_package_name
, package_name
);
7280 xfree (this_package_name
);
7286 if (package_name
!= NULL
)
7288 struct objfile
*objfile
= cu
->objfile
;
7289 const char *saved_package_name
= obstack_copy0 (&objfile
->objfile_obstack
,
7291 strlen (package_name
));
7292 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
7293 saved_package_name
, objfile
);
7296 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7298 sym
= allocate_symbol (objfile
);
7299 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
7300 SYMBOL_SET_NAMES (sym
, saved_package_name
,
7301 strlen (saved_package_name
), 0, objfile
);
7302 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
7303 e.g., "main" finds the "main" module and not C's main(). */
7304 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7305 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
7306 SYMBOL_TYPE (sym
) = type
;
7308 add_symbol_to_list (sym
, &global_symbols
);
7310 xfree (package_name
);
7314 /* Return the symtab for PER_CU. This works properly regardless of
7315 whether we're using the index or psymtabs. */
7317 static struct symtab
*
7318 get_symtab (struct dwarf2_per_cu_data
*per_cu
)
7320 return (dwarf2_per_objfile
->using_index
7321 ? per_cu
->v
.quick
->symtab
7322 : per_cu
->v
.psymtab
->symtab
);
7325 /* A helper function for computing the list of all symbol tables
7326 included by PER_CU. */
7329 recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr
) **result
,
7330 htab_t all_children
,
7331 struct dwarf2_per_cu_data
*per_cu
)
7335 struct dwarf2_per_cu_data
*iter
;
7337 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
7340 /* This inclusion and its children have been processed. */
7345 /* Only add a CU if it has a symbol table. */
7346 if (get_symtab (per_cu
) != NULL
)
7347 VEC_safe_push (dwarf2_per_cu_ptr
, *result
, per_cu
);
7350 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
7352 recursively_compute_inclusions (result
, all_children
, iter
);
7355 /* Compute the symtab 'includes' fields for the symtab related to
7359 compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
7361 gdb_assert (! per_cu
->is_debug_types
);
7363 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
7366 struct dwarf2_per_cu_data
*iter
;
7367 VEC (dwarf2_per_cu_ptr
) *result_children
= NULL
;
7368 htab_t all_children
;
7369 struct symtab
*symtab
= get_symtab (per_cu
);
7371 /* If we don't have a symtab, we can just skip this case. */
7375 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
7376 NULL
, xcalloc
, xfree
);
7379 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
7382 recursively_compute_inclusions (&result_children
, all_children
, iter
);
7384 /* Now we have a transitive closure of all the included CUs, and
7385 for .gdb_index version 7 the included TUs, so we can convert it
7386 to a list of symtabs. */
7387 len
= VEC_length (dwarf2_per_cu_ptr
, result_children
);
7389 = obstack_alloc (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
7390 (len
+ 1) * sizeof (struct symtab
*));
7392 VEC_iterate (dwarf2_per_cu_ptr
, result_children
, ix
, iter
);
7394 symtab
->includes
[ix
] = get_symtab (iter
);
7395 symtab
->includes
[len
] = NULL
;
7397 VEC_free (dwarf2_per_cu_ptr
, result_children
);
7398 htab_delete (all_children
);
7402 /* Compute the 'includes' field for the symtabs of all the CUs we just
7406 process_cu_includes (void)
7409 struct dwarf2_per_cu_data
*iter
;
7412 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
7416 if (! iter
->is_debug_types
)
7417 compute_symtab_includes (iter
);
7420 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
7423 /* Generate full symbol information for PER_CU, whose DIEs have
7424 already been loaded into memory. */
7427 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
7428 enum language pretend_language
)
7430 struct dwarf2_cu
*cu
= per_cu
->cu
;
7431 struct objfile
*objfile
= per_cu
->objfile
;
7432 CORE_ADDR lowpc
, highpc
;
7433 struct symtab
*symtab
;
7434 struct cleanup
*back_to
, *delayed_list_cleanup
;
7436 struct block
*static_block
;
7438 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7441 back_to
= make_cleanup (really_free_pendings
, NULL
);
7442 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
7444 cu
->list_in_scope
= &file_symbols
;
7446 cu
->language
= pretend_language
;
7447 cu
->language_defn
= language_def (cu
->language
);
7449 /* Do line number decoding in read_file_scope () */
7450 process_die (cu
->dies
, cu
);
7452 /* For now fudge the Go package. */
7453 if (cu
->language
== language_go
)
7454 fixup_go_packaging (cu
);
7456 /* Now that we have processed all the DIEs in the CU, all the types
7457 should be complete, and it should now be safe to compute all of the
7459 compute_delayed_physnames (cu
);
7460 do_cleanups (delayed_list_cleanup
);
7462 /* Some compilers don't define a DW_AT_high_pc attribute for the
7463 compilation unit. If the DW_AT_high_pc is missing, synthesize
7464 it, by scanning the DIE's below the compilation unit. */
7465 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
7468 = end_symtab_get_static_block (highpc
+ baseaddr
, objfile
, 0, 1);
7470 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
7471 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
7472 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
7473 addrmap to help ensure it has an accurate map of pc values belonging to
7475 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
7477 symtab
= end_symtab_from_static_block (static_block
, objfile
,
7478 SECT_OFF_TEXT (objfile
), 0);
7482 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
7484 /* Set symtab language to language from DW_AT_language. If the
7485 compilation is from a C file generated by language preprocessors, do
7486 not set the language if it was already deduced by start_subfile. */
7487 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
7488 symtab
->language
= cu
->language
;
7490 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
7491 produce DW_AT_location with location lists but it can be possibly
7492 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
7493 there were bugs in prologue debug info, fixed later in GCC-4.5
7494 by "unwind info for epilogues" patch (which is not directly related).
7496 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
7497 needed, it would be wrong due to missing DW_AT_producer there.
7499 Still one can confuse GDB by using non-standard GCC compilation
7500 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
7502 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
7503 symtab
->locations_valid
= 1;
7505 if (gcc_4_minor
>= 5)
7506 symtab
->epilogue_unwind_valid
= 1;
7508 symtab
->call_site_htab
= cu
->call_site_htab
;
7511 if (dwarf2_per_objfile
->using_index
)
7512 per_cu
->v
.quick
->symtab
= symtab
;
7515 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
7516 pst
->symtab
= symtab
;
7520 /* Push it for inclusion processing later. */
7521 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
7523 do_cleanups (back_to
);
7526 /* Generate full symbol information for type unit PER_CU, whose DIEs have
7527 already been loaded into memory. */
7530 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
7531 enum language pretend_language
)
7533 struct dwarf2_cu
*cu
= per_cu
->cu
;
7534 struct objfile
*objfile
= per_cu
->objfile
;
7535 struct symtab
*symtab
;
7536 struct cleanup
*back_to
, *delayed_list_cleanup
;
7537 struct signatured_type
*sig_type
;
7539 gdb_assert (per_cu
->is_debug_types
);
7540 sig_type
= (struct signatured_type
*) per_cu
;
7543 back_to
= make_cleanup (really_free_pendings
, NULL
);
7544 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
7546 cu
->list_in_scope
= &file_symbols
;
7548 cu
->language
= pretend_language
;
7549 cu
->language_defn
= language_def (cu
->language
);
7551 /* The symbol tables are set up in read_type_unit_scope. */
7552 process_die (cu
->dies
, cu
);
7554 /* For now fudge the Go package. */
7555 if (cu
->language
== language_go
)
7556 fixup_go_packaging (cu
);
7558 /* Now that we have processed all the DIEs in the CU, all the types
7559 should be complete, and it should now be safe to compute all of the
7561 compute_delayed_physnames (cu
);
7562 do_cleanups (delayed_list_cleanup
);
7564 /* TUs share symbol tables.
7565 If this is the first TU to use this symtab, complete the construction
7566 of it with end_expandable_symtab. Otherwise, complete the addition of
7567 this TU's symbols to the existing symtab. */
7568 if (sig_type
->type_unit_group
->primary_symtab
== NULL
)
7570 symtab
= end_expandable_symtab (0, objfile
, SECT_OFF_TEXT (objfile
));
7571 sig_type
->type_unit_group
->primary_symtab
= symtab
;
7575 /* Set symtab language to language from DW_AT_language. If the
7576 compilation is from a C file generated by language preprocessors,
7577 do not set the language if it was already deduced by
7579 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
7580 symtab
->language
= cu
->language
;
7585 augment_type_symtab (objfile
,
7586 sig_type
->type_unit_group
->primary_symtab
);
7587 symtab
= sig_type
->type_unit_group
->primary_symtab
;
7590 if (dwarf2_per_objfile
->using_index
)
7591 per_cu
->v
.quick
->symtab
= symtab
;
7594 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
7595 pst
->symtab
= symtab
;
7599 do_cleanups (back_to
);
7602 /* Process an imported unit DIE. */
7605 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7607 struct attribute
*attr
;
7609 /* For now we don't handle imported units in type units. */
7610 if (cu
->per_cu
->is_debug_types
)
7612 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7613 " supported in type units [in module %s]"),
7617 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7620 struct dwarf2_per_cu_data
*per_cu
;
7621 struct symtab
*imported_symtab
;
7625 offset
= dwarf2_get_ref_die_offset (attr
);
7626 is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
7627 per_cu
= dwarf2_find_containing_comp_unit (offset
, is_dwz
, cu
->objfile
);
7629 /* Queue the unit, if needed. */
7630 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
7631 load_full_comp_unit (per_cu
, cu
->language
);
7633 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
7638 /* Process a die and its children. */
7641 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7645 case DW_TAG_padding
:
7647 case DW_TAG_compile_unit
:
7648 case DW_TAG_partial_unit
:
7649 read_file_scope (die
, cu
);
7651 case DW_TAG_type_unit
:
7652 read_type_unit_scope (die
, cu
);
7654 case DW_TAG_subprogram
:
7655 case DW_TAG_inlined_subroutine
:
7656 read_func_scope (die
, cu
);
7658 case DW_TAG_lexical_block
:
7659 case DW_TAG_try_block
:
7660 case DW_TAG_catch_block
:
7661 read_lexical_block_scope (die
, cu
);
7663 case DW_TAG_GNU_call_site
:
7664 read_call_site_scope (die
, cu
);
7666 case DW_TAG_class_type
:
7667 case DW_TAG_interface_type
:
7668 case DW_TAG_structure_type
:
7669 case DW_TAG_union_type
:
7670 process_structure_scope (die
, cu
);
7672 case DW_TAG_enumeration_type
:
7673 process_enumeration_scope (die
, cu
);
7676 /* These dies have a type, but processing them does not create
7677 a symbol or recurse to process the children. Therefore we can
7678 read them on-demand through read_type_die. */
7679 case DW_TAG_subroutine_type
:
7680 case DW_TAG_set_type
:
7681 case DW_TAG_array_type
:
7682 case DW_TAG_pointer_type
:
7683 case DW_TAG_ptr_to_member_type
:
7684 case DW_TAG_reference_type
:
7685 case DW_TAG_string_type
:
7688 case DW_TAG_base_type
:
7689 case DW_TAG_subrange_type
:
7690 case DW_TAG_typedef
:
7691 /* Add a typedef symbol for the type definition, if it has a
7693 new_symbol (die
, read_type_die (die
, cu
), cu
);
7695 case DW_TAG_common_block
:
7696 read_common_block (die
, cu
);
7698 case DW_TAG_common_inclusion
:
7700 case DW_TAG_namespace
:
7701 cu
->processing_has_namespace_info
= 1;
7702 read_namespace (die
, cu
);
7705 cu
->processing_has_namespace_info
= 1;
7706 read_module (die
, cu
);
7708 case DW_TAG_imported_declaration
:
7709 case DW_TAG_imported_module
:
7710 cu
->processing_has_namespace_info
= 1;
7711 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
7712 || cu
->language
!= language_fortran
))
7713 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
7714 dwarf_tag_name (die
->tag
));
7715 read_import_statement (die
, cu
);
7718 case DW_TAG_imported_unit
:
7719 process_imported_unit_die (die
, cu
);
7723 new_symbol (die
, NULL
, cu
);
7728 /* DWARF name computation. */
7730 /* A helper function for dwarf2_compute_name which determines whether DIE
7731 needs to have the name of the scope prepended to the name listed in the
7735 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7737 struct attribute
*attr
;
7741 case DW_TAG_namespace
:
7742 case DW_TAG_typedef
:
7743 case DW_TAG_class_type
:
7744 case DW_TAG_interface_type
:
7745 case DW_TAG_structure_type
:
7746 case DW_TAG_union_type
:
7747 case DW_TAG_enumeration_type
:
7748 case DW_TAG_enumerator
:
7749 case DW_TAG_subprogram
:
7753 case DW_TAG_variable
:
7754 case DW_TAG_constant
:
7755 /* We only need to prefix "globally" visible variables. These include
7756 any variable marked with DW_AT_external or any variable that
7757 lives in a namespace. [Variables in anonymous namespaces
7758 require prefixing, but they are not DW_AT_external.] */
7760 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
7762 struct dwarf2_cu
*spec_cu
= cu
;
7764 return die_needs_namespace (die_specification (die
, &spec_cu
),
7768 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
7769 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
7770 && die
->parent
->tag
!= DW_TAG_module
)
7772 /* A variable in a lexical block of some kind does not need a
7773 namespace, even though in C++ such variables may be external
7774 and have a mangled name. */
7775 if (die
->parent
->tag
== DW_TAG_lexical_block
7776 || die
->parent
->tag
== DW_TAG_try_block
7777 || die
->parent
->tag
== DW_TAG_catch_block
7778 || die
->parent
->tag
== DW_TAG_subprogram
)
7787 /* Retrieve the last character from a mem_file. */
7790 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
7792 char *last_char_p
= (char *) object
;
7795 *last_char_p
= buffer
[length
- 1];
7798 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
7799 compute the physname for the object, which include a method's:
7800 - formal parameters (C++/Java),
7801 - receiver type (Go),
7802 - return type (Java).
7804 The term "physname" is a bit confusing.
7805 For C++, for example, it is the demangled name.
7806 For Go, for example, it's the mangled name.
7808 For Ada, return the DIE's linkage name rather than the fully qualified
7809 name. PHYSNAME is ignored..
7811 The result is allocated on the objfile_obstack and canonicalized. */
7814 dwarf2_compute_name (const char *name
,
7815 struct die_info
*die
, struct dwarf2_cu
*cu
,
7818 struct objfile
*objfile
= cu
->objfile
;
7821 name
= dwarf2_name (die
, cu
);
7823 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
7824 compute it by typename_concat inside GDB. */
7825 if (cu
->language
== language_ada
7826 || (cu
->language
== language_fortran
&& physname
))
7828 /* For Ada unit, we prefer the linkage name over the name, as
7829 the former contains the exported name, which the user expects
7830 to be able to reference. Ideally, we want the user to be able
7831 to reference this entity using either natural or linkage name,
7832 but we haven't started looking at this enhancement yet. */
7833 struct attribute
*attr
;
7835 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
7837 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7838 if (attr
&& DW_STRING (attr
))
7839 return DW_STRING (attr
);
7842 /* These are the only languages we know how to qualify names in. */
7844 && (cu
->language
== language_cplus
|| cu
->language
== language_java
7845 || cu
->language
== language_fortran
))
7847 if (die_needs_namespace (die
, cu
))
7851 struct ui_file
*buf
;
7853 prefix
= determine_prefix (die
, cu
);
7854 buf
= mem_fileopen ();
7855 if (*prefix
!= '\0')
7857 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
7860 fputs_unfiltered (prefixed_name
, buf
);
7861 xfree (prefixed_name
);
7864 fputs_unfiltered (name
, buf
);
7866 /* Template parameters may be specified in the DIE's DW_AT_name, or
7867 as children with DW_TAG_template_type_param or
7868 DW_TAG_value_type_param. If the latter, add them to the name
7869 here. If the name already has template parameters, then
7870 skip this step; some versions of GCC emit both, and
7871 it is more efficient to use the pre-computed name.
7873 Something to keep in mind about this process: it is very
7874 unlikely, or in some cases downright impossible, to produce
7875 something that will match the mangled name of a function.
7876 If the definition of the function has the same debug info,
7877 we should be able to match up with it anyway. But fallbacks
7878 using the minimal symbol, for instance to find a method
7879 implemented in a stripped copy of libstdc++, will not work.
7880 If we do not have debug info for the definition, we will have to
7881 match them up some other way.
7883 When we do name matching there is a related problem with function
7884 templates; two instantiated function templates are allowed to
7885 differ only by their return types, which we do not add here. */
7887 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
7889 struct attribute
*attr
;
7890 struct die_info
*child
;
7893 die
->building_fullname
= 1;
7895 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
7899 const gdb_byte
*bytes
;
7900 struct dwarf2_locexpr_baton
*baton
;
7903 if (child
->tag
!= DW_TAG_template_type_param
7904 && child
->tag
!= DW_TAG_template_value_param
)
7909 fputs_unfiltered ("<", buf
);
7913 fputs_unfiltered (", ", buf
);
7915 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
7918 complaint (&symfile_complaints
,
7919 _("template parameter missing DW_AT_type"));
7920 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
7923 type
= die_type (child
, cu
);
7925 if (child
->tag
== DW_TAG_template_type_param
)
7927 c_print_type (type
, "", buf
, -1, 0, &type_print_raw_options
);
7931 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
7934 complaint (&symfile_complaints
,
7935 _("template parameter missing "
7936 "DW_AT_const_value"));
7937 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
7941 dwarf2_const_value_attr (attr
, type
, name
,
7942 &cu
->comp_unit_obstack
, cu
,
7943 &value
, &bytes
, &baton
);
7945 if (TYPE_NOSIGN (type
))
7946 /* GDB prints characters as NUMBER 'CHAR'. If that's
7947 changed, this can use value_print instead. */
7948 c_printchar (value
, type
, buf
);
7951 struct value_print_options opts
;
7954 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
7958 else if (bytes
!= NULL
)
7960 v
= allocate_value (type
);
7961 memcpy (value_contents_writeable (v
), bytes
,
7962 TYPE_LENGTH (type
));
7965 v
= value_from_longest (type
, value
);
7967 /* Specify decimal so that we do not depend on
7969 get_formatted_print_options (&opts
, 'd');
7971 value_print (v
, buf
, &opts
);
7977 die
->building_fullname
= 0;
7981 /* Close the argument list, with a space if necessary
7982 (nested templates). */
7983 char last_char
= '\0';
7984 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
7985 if (last_char
== '>')
7986 fputs_unfiltered (" >", buf
);
7988 fputs_unfiltered (">", buf
);
7992 /* For Java and C++ methods, append formal parameter type
7993 information, if PHYSNAME. */
7995 if (physname
&& die
->tag
== DW_TAG_subprogram
7996 && (cu
->language
== language_cplus
7997 || cu
->language
== language_java
))
7999 struct type
*type
= read_type_die (die
, cu
);
8001 c_type_print_args (type
, buf
, 1, cu
->language
,
8002 &type_print_raw_options
);
8004 if (cu
->language
== language_java
)
8006 /* For java, we must append the return type to method
8008 if (die
->tag
== DW_TAG_subprogram
)
8009 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
8010 0, 0, &type_print_raw_options
);
8012 else if (cu
->language
== language_cplus
)
8014 /* Assume that an artificial first parameter is
8015 "this", but do not crash if it is not. RealView
8016 marks unnamed (and thus unused) parameters as
8017 artificial; there is no way to differentiate
8019 if (TYPE_NFIELDS (type
) > 0
8020 && TYPE_FIELD_ARTIFICIAL (type
, 0)
8021 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
8022 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
8024 fputs_unfiltered (" const", buf
);
8028 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
8030 ui_file_delete (buf
);
8032 if (cu
->language
== language_cplus
)
8035 = dwarf2_canonicalize_name (name
, cu
,
8036 &objfile
->objfile_obstack
);
8047 /* Return the fully qualified name of DIE, based on its DW_AT_name.
8048 If scope qualifiers are appropriate they will be added. The result
8049 will be allocated on the objfile_obstack, or NULL if the DIE does
8050 not have a name. NAME may either be from a previous call to
8051 dwarf2_name or NULL.
8053 The output string will be canonicalized (if C++/Java). */
8056 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
8058 return dwarf2_compute_name (name
, die
, cu
, 0);
8061 /* Construct a physname for the given DIE in CU. NAME may either be
8062 from a previous call to dwarf2_name or NULL. The result will be
8063 allocated on the objfile_objstack or NULL if the DIE does not have a
8066 The output string will be canonicalized (if C++/Java). */
8069 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
8071 struct objfile
*objfile
= cu
->objfile
;
8072 struct attribute
*attr
;
8073 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
8074 struct cleanup
*back_to
;
8077 /* In this case dwarf2_compute_name is just a shortcut not building anything
8079 if (!die_needs_namespace (die
, cu
))
8080 return dwarf2_compute_name (name
, die
, cu
, 1);
8082 back_to
= make_cleanup (null_cleanup
, NULL
);
8084 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
8086 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8088 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
8090 if (attr
&& DW_STRING (attr
))
8094 mangled
= DW_STRING (attr
);
8096 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
8097 type. It is easier for GDB users to search for such functions as
8098 `name(params)' than `long name(params)'. In such case the minimal
8099 symbol names do not match the full symbol names but for template
8100 functions there is never a need to look up their definition from their
8101 declaration so the only disadvantage remains the minimal symbol
8102 variant `long name(params)' does not have the proper inferior type.
8105 if (cu
->language
== language_go
)
8107 /* This is a lie, but we already lie to the caller new_symbol_full.
8108 new_symbol_full assumes we return the mangled name.
8109 This just undoes that lie until things are cleaned up. */
8114 demangled
= gdb_demangle (mangled
,
8115 (DMGL_PARAMS
| DMGL_ANSI
8116 | (cu
->language
== language_java
8117 ? DMGL_JAVA
| DMGL_RET_POSTFIX
8122 make_cleanup (xfree
, demangled
);
8132 if (canon
== NULL
|| check_physname
)
8134 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
8136 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
8138 /* It may not mean a bug in GDB. The compiler could also
8139 compute DW_AT_linkage_name incorrectly. But in such case
8140 GDB would need to be bug-to-bug compatible. */
8142 complaint (&symfile_complaints
,
8143 _("Computed physname <%s> does not match demangled <%s> "
8144 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
8145 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
8147 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
8148 is available here - over computed PHYSNAME. It is safer
8149 against both buggy GDB and buggy compilers. */
8163 retval
= obstack_copy0 (&objfile
->objfile_obstack
, retval
, strlen (retval
));
8165 do_cleanups (back_to
);
8169 /* Read the import statement specified by the given die and record it. */
8172 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
8174 struct objfile
*objfile
= cu
->objfile
;
8175 struct attribute
*import_attr
;
8176 struct die_info
*imported_die
, *child_die
;
8177 struct dwarf2_cu
*imported_cu
;
8178 const char *imported_name
;
8179 const char *imported_name_prefix
;
8180 const char *canonical_name
;
8181 const char *import_alias
;
8182 const char *imported_declaration
= NULL
;
8183 const char *import_prefix
;
8184 VEC (const_char_ptr
) *excludes
= NULL
;
8185 struct cleanup
*cleanups
;
8187 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
8188 if (import_attr
== NULL
)
8190 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
8191 dwarf_tag_name (die
->tag
));
8196 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
8197 imported_name
= dwarf2_name (imported_die
, imported_cu
);
8198 if (imported_name
== NULL
)
8200 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
8202 The import in the following code:
8216 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
8217 <52> DW_AT_decl_file : 1
8218 <53> DW_AT_decl_line : 6
8219 <54> DW_AT_import : <0x75>
8220 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
8222 <5b> DW_AT_decl_file : 1
8223 <5c> DW_AT_decl_line : 2
8224 <5d> DW_AT_type : <0x6e>
8226 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
8227 <76> DW_AT_byte_size : 4
8228 <77> DW_AT_encoding : 5 (signed)
8230 imports the wrong die ( 0x75 instead of 0x58 ).
8231 This case will be ignored until the gcc bug is fixed. */
8235 /* Figure out the local name after import. */
8236 import_alias
= dwarf2_name (die
, cu
);
8238 /* Figure out where the statement is being imported to. */
8239 import_prefix
= determine_prefix (die
, cu
);
8241 /* Figure out what the scope of the imported die is and prepend it
8242 to the name of the imported die. */
8243 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
8245 if (imported_die
->tag
!= DW_TAG_namespace
8246 && imported_die
->tag
!= DW_TAG_module
)
8248 imported_declaration
= imported_name
;
8249 canonical_name
= imported_name_prefix
;
8251 else if (strlen (imported_name_prefix
) > 0)
8252 canonical_name
= obconcat (&objfile
->objfile_obstack
,
8253 imported_name_prefix
, "::", imported_name
,
8256 canonical_name
= imported_name
;
8258 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
8260 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
8261 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
8262 child_die
= sibling_die (child_die
))
8264 /* DWARF-4: A Fortran use statement with a “rename list” may be
8265 represented by an imported module entry with an import attribute
8266 referring to the module and owned entries corresponding to those
8267 entities that are renamed as part of being imported. */
8269 if (child_die
->tag
!= DW_TAG_imported_declaration
)
8271 complaint (&symfile_complaints
,
8272 _("child DW_TAG_imported_declaration expected "
8273 "- DIE at 0x%x [in module %s]"),
8274 child_die
->offset
.sect_off
, objfile
->name
);
8278 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
8279 if (import_attr
== NULL
)
8281 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
8282 dwarf_tag_name (child_die
->tag
));
8287 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
8289 imported_name
= dwarf2_name (imported_die
, imported_cu
);
8290 if (imported_name
== NULL
)
8292 complaint (&symfile_complaints
,
8293 _("child DW_TAG_imported_declaration has unknown "
8294 "imported name - DIE at 0x%x [in module %s]"),
8295 child_die
->offset
.sect_off
, objfile
->name
);
8299 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
8301 process_die (child_die
, cu
);
8304 cp_add_using_directive (import_prefix
,
8307 imported_declaration
,
8310 &objfile
->objfile_obstack
);
8312 do_cleanups (cleanups
);
8315 /* Cleanup function for handle_DW_AT_stmt_list. */
8318 free_cu_line_header (void *arg
)
8320 struct dwarf2_cu
*cu
= arg
;
8322 free_line_header (cu
->line_header
);
8323 cu
->line_header
= NULL
;
8326 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
8327 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
8328 this, it was first present in GCC release 4.3.0. */
8331 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
8333 if (!cu
->checked_producer
)
8334 check_producer (cu
);
8336 return cu
->producer_is_gcc_lt_4_3
;
8340 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
8341 const char **name
, const char **comp_dir
)
8343 struct attribute
*attr
;
8348 /* Find the filename. Do not use dwarf2_name here, since the filename
8349 is not a source language identifier. */
8350 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8353 *name
= DW_STRING (attr
);
8356 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
8358 *comp_dir
= DW_STRING (attr
);
8359 else if (producer_is_gcc_lt_4_3 (cu
) && *name
!= NULL
8360 && IS_ABSOLUTE_PATH (*name
))
8362 char *d
= ldirname (*name
);
8366 make_cleanup (xfree
, d
);
8368 if (*comp_dir
!= NULL
)
8370 /* Irix 6.2 native cc prepends <machine>.: to the compilation
8371 directory, get rid of it. */
8372 char *cp
= strchr (*comp_dir
, ':');
8374 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
8379 *name
= "<unknown>";
8382 /* Handle DW_AT_stmt_list for a compilation unit.
8383 DIE is the DW_TAG_compile_unit die for CU.
8384 COMP_DIR is the compilation directory.
8385 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
8388 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
8389 const char *comp_dir
) /* ARI: editCase function */
8391 struct attribute
*attr
;
8393 gdb_assert (! cu
->per_cu
->is_debug_types
);
8395 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
8398 unsigned int line_offset
= DW_UNSND (attr
);
8399 struct line_header
*line_header
8400 = dwarf_decode_line_header (line_offset
, cu
);
8404 cu
->line_header
= line_header
;
8405 make_cleanup (free_cu_line_header
, cu
);
8406 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, 1);
8411 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
8414 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8416 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8417 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
8418 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
8419 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
8420 struct attribute
*attr
;
8421 const char *name
= NULL
;
8422 const char *comp_dir
= NULL
;
8423 struct die_info
*child_die
;
8424 bfd
*abfd
= objfile
->obfd
;
8427 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8429 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
8431 /* If we didn't find a lowpc, set it to highpc to avoid complaints
8432 from finish_block. */
8433 if (lowpc
== ((CORE_ADDR
) -1))
8438 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
8440 prepare_one_comp_unit (cu
, die
, cu
->language
);
8442 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
8443 standardised yet. As a workaround for the language detection we fall
8444 back to the DW_AT_producer string. */
8445 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
8446 cu
->language
= language_opencl
;
8448 /* Similar hack for Go. */
8449 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
8450 set_cu_language (DW_LANG_Go
, cu
);
8452 dwarf2_start_symtab (cu
, name
, comp_dir
, lowpc
);
8454 /* Decode line number information if present. We do this before
8455 processing child DIEs, so that the line header table is available
8456 for DW_AT_decl_file. */
8457 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
8459 /* Process all dies in compilation unit. */
8460 if (die
->child
!= NULL
)
8462 child_die
= die
->child
;
8463 while (child_die
&& child_die
->tag
)
8465 process_die (child_die
, cu
);
8466 child_die
= sibling_die (child_die
);
8470 /* Decode macro information, if present. Dwarf 2 macro information
8471 refers to information in the line number info statement program
8472 header, so we can only read it if we've read the header
8474 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
8475 if (attr
&& cu
->line_header
)
8477 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
8478 complaint (&symfile_complaints
,
8479 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
8481 dwarf_decode_macros (cu
, DW_UNSND (attr
), comp_dir
, 1);
8485 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
8486 if (attr
&& cu
->line_header
)
8488 unsigned int macro_offset
= DW_UNSND (attr
);
8490 dwarf_decode_macros (cu
, macro_offset
, comp_dir
, 0);
8494 do_cleanups (back_to
);
8497 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
8498 Create the set of symtabs used by this TU, or if this TU is sharing
8499 symtabs with another TU and the symtabs have already been created
8500 then restore those symtabs in the line header.
8501 We don't need the pc/line-number mapping for type units. */
8504 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
8506 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8507 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8508 struct type_unit_group
*tu_group
;
8510 struct line_header
*lh
;
8511 struct attribute
*attr
;
8512 unsigned int i
, line_offset
;
8513 struct signatured_type
*sig_type
;
8515 gdb_assert (per_cu
->is_debug_types
);
8516 sig_type
= (struct signatured_type
*) per_cu
;
8518 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
8520 /* If we're using .gdb_index (includes -readnow) then
8521 per_cu->type_unit_group may not have been set up yet. */
8522 if (sig_type
->type_unit_group
== NULL
)
8523 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
8524 tu_group
= sig_type
->type_unit_group
;
8526 /* If we've already processed this stmt_list there's no real need to
8527 do it again, we could fake it and just recreate the part we need
8528 (file name,index -> symtab mapping). If data shows this optimization
8529 is useful we can do it then. */
8530 first_time
= tu_group
->primary_symtab
== NULL
;
8532 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
8537 line_offset
= DW_UNSND (attr
);
8538 lh
= dwarf_decode_line_header (line_offset
, cu
);
8543 dwarf2_start_symtab (cu
, "", NULL
, 0);
8546 gdb_assert (tu_group
->symtabs
== NULL
);
8549 /* Note: The primary symtab will get allocated at the end. */
8553 cu
->line_header
= lh
;
8554 make_cleanup (free_cu_line_header
, cu
);
8558 dwarf2_start_symtab (cu
, "", NULL
, 0);
8560 tu_group
->num_symtabs
= lh
->num_file_names
;
8561 tu_group
->symtabs
= XNEWVEC (struct symtab
*, lh
->num_file_names
);
8563 for (i
= 0; i
< lh
->num_file_names
; ++i
)
8565 const char *dir
= NULL
;
8566 struct file_entry
*fe
= &lh
->file_names
[i
];
8569 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8570 dwarf2_start_subfile (fe
->name
, dir
, NULL
);
8572 /* Note: We don't have to watch for the main subfile here, type units
8573 don't have DW_AT_name. */
8575 if (current_subfile
->symtab
== NULL
)
8577 /* NOTE: start_subfile will recognize when it's been passed
8578 a file it has already seen. So we can't assume there's a
8579 simple mapping from lh->file_names to subfiles,
8580 lh->file_names may contain dups. */
8581 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
8585 fe
->symtab
= current_subfile
->symtab
;
8586 tu_group
->symtabs
[i
] = fe
->symtab
;
8593 for (i
= 0; i
< lh
->num_file_names
; ++i
)
8595 struct file_entry
*fe
= &lh
->file_names
[i
];
8597 fe
->symtab
= tu_group
->symtabs
[i
];
8601 /* The main symtab is allocated last. Type units don't have DW_AT_name
8602 so they don't have a "real" (so to speak) symtab anyway.
8603 There is later code that will assign the main symtab to all symbols
8604 that don't have one. We need to handle the case of a symbol with a
8605 missing symtab (DW_AT_decl_file) anyway. */
8608 /* Process DW_TAG_type_unit.
8609 For TUs we want to skip the first top level sibling if it's not the
8610 actual type being defined by this TU. In this case the first top
8611 level sibling is there to provide context only. */
8614 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8616 struct die_info
*child_die
;
8618 prepare_one_comp_unit (cu
, die
, language_minimal
);
8620 /* Initialize (or reinitialize) the machinery for building symtabs.
8621 We do this before processing child DIEs, so that the line header table
8622 is available for DW_AT_decl_file. */
8623 setup_type_unit_groups (die
, cu
);
8625 if (die
->child
!= NULL
)
8627 child_die
= die
->child
;
8628 while (child_die
&& child_die
->tag
)
8630 process_die (child_die
, cu
);
8631 child_die
= sibling_die (child_die
);
8638 http://gcc.gnu.org/wiki/DebugFission
8639 http://gcc.gnu.org/wiki/DebugFissionDWP
8641 To simplify handling of both DWO files ("object" files with the DWARF info)
8642 and DWP files (a file with the DWOs packaged up into one file), we treat
8643 DWP files as having a collection of virtual DWO files. */
8646 hash_dwo_file (const void *item
)
8648 const struct dwo_file
*dwo_file
= item
;
8651 hash
= htab_hash_string (dwo_file
->dwo_name
);
8652 if (dwo_file
->comp_dir
!= NULL
)
8653 hash
+= htab_hash_string (dwo_file
->comp_dir
);
8658 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
8660 const struct dwo_file
*lhs
= item_lhs
;
8661 const struct dwo_file
*rhs
= item_rhs
;
8663 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
8665 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
8666 return lhs
->comp_dir
== rhs
->comp_dir
;
8667 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
8670 /* Allocate a hash table for DWO files. */
8673 allocate_dwo_file_hash_table (void)
8675 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8677 return htab_create_alloc_ex (41,
8681 &objfile
->objfile_obstack
,
8682 hashtab_obstack_allocate
,
8683 dummy_obstack_deallocate
);
8686 /* Lookup DWO file DWO_NAME. */
8689 lookup_dwo_file_slot (const char *dwo_name
, const char *comp_dir
)
8691 struct dwo_file find_entry
;
8694 if (dwarf2_per_objfile
->dwo_files
== NULL
)
8695 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
8697 memset (&find_entry
, 0, sizeof (find_entry
));
8698 find_entry
.dwo_name
= dwo_name
;
8699 find_entry
.comp_dir
= comp_dir
;
8700 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
8706 hash_dwo_unit (const void *item
)
8708 const struct dwo_unit
*dwo_unit
= item
;
8710 /* This drops the top 32 bits of the id, but is ok for a hash. */
8711 return dwo_unit
->signature
;
8715 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
8717 const struct dwo_unit
*lhs
= item_lhs
;
8718 const struct dwo_unit
*rhs
= item_rhs
;
8720 /* The signature is assumed to be unique within the DWO file.
8721 So while object file CU dwo_id's always have the value zero,
8722 that's OK, assuming each object file DWO file has only one CU,
8723 and that's the rule for now. */
8724 return lhs
->signature
== rhs
->signature
;
8727 /* Allocate a hash table for DWO CUs,TUs.
8728 There is one of these tables for each of CUs,TUs for each DWO file. */
8731 allocate_dwo_unit_table (struct objfile
*objfile
)
8733 /* Start out with a pretty small number.
8734 Generally DWO files contain only one CU and maybe some TUs. */
8735 return htab_create_alloc_ex (3,
8739 &objfile
->objfile_obstack
,
8740 hashtab_obstack_allocate
,
8741 dummy_obstack_deallocate
);
8744 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
8746 struct create_dwo_cu_data
8748 struct dwo_file
*dwo_file
;
8749 struct dwo_unit dwo_unit
;
8752 /* die_reader_func for create_dwo_cu. */
8755 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
8756 const gdb_byte
*info_ptr
,
8757 struct die_info
*comp_unit_die
,
8761 struct dwarf2_cu
*cu
= reader
->cu
;
8762 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8763 sect_offset offset
= cu
->per_cu
->offset
;
8764 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
8765 struct create_dwo_cu_data
*data
= datap
;
8766 struct dwo_file
*dwo_file
= data
->dwo_file
;
8767 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
8768 struct attribute
*attr
;
8770 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
8773 complaint (&symfile_complaints
,
8774 _("Dwarf Error: debug entry at offset 0x%x is missing"
8775 " its dwo_id [in module %s]"),
8776 offset
.sect_off
, dwo_file
->dwo_name
);
8780 dwo_unit
->dwo_file
= dwo_file
;
8781 dwo_unit
->signature
= DW_UNSND (attr
);
8782 dwo_unit
->section
= section
;
8783 dwo_unit
->offset
= offset
;
8784 dwo_unit
->length
= cu
->per_cu
->length
;
8786 if (dwarf2_read_debug
)
8787 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id %s\n",
8788 offset
.sect_off
, hex_string (dwo_unit
->signature
));
8791 /* Create the dwo_unit for the lone CU in DWO_FILE.
8792 Note: This function processes DWO files only, not DWP files. */
8794 static struct dwo_unit
*
8795 create_dwo_cu (struct dwo_file
*dwo_file
)
8797 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8798 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
8801 const gdb_byte
*info_ptr
, *end_ptr
;
8802 struct create_dwo_cu_data create_dwo_cu_data
;
8803 struct dwo_unit
*dwo_unit
;
8805 dwarf2_read_section (objfile
, section
);
8806 info_ptr
= section
->buffer
;
8808 if (info_ptr
== NULL
)
8811 /* We can't set abfd until now because the section may be empty or
8812 not present, in which case section->asection will be NULL. */
8813 abfd
= section
->asection
->owner
;
8815 if (dwarf2_read_debug
)
8817 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
8818 bfd_section_name (abfd
, section
->asection
),
8819 bfd_get_filename (abfd
));
8822 create_dwo_cu_data
.dwo_file
= dwo_file
;
8825 end_ptr
= info_ptr
+ section
->size
;
8826 while (info_ptr
< end_ptr
)
8828 struct dwarf2_per_cu_data per_cu
;
8830 memset (&create_dwo_cu_data
.dwo_unit
, 0,
8831 sizeof (create_dwo_cu_data
.dwo_unit
));
8832 memset (&per_cu
, 0, sizeof (per_cu
));
8833 per_cu
.objfile
= objfile
;
8834 per_cu
.is_debug_types
= 0;
8835 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
8836 per_cu
.section
= section
;
8838 init_cutu_and_read_dies_no_follow (&per_cu
,
8839 &dwo_file
->sections
.abbrev
,
8841 create_dwo_cu_reader
,
8842 &create_dwo_cu_data
);
8844 if (create_dwo_cu_data
.dwo_unit
.dwo_file
!= NULL
)
8846 /* If we've already found one, complain. We only support one
8847 because having more than one requires hacking the dwo_name of
8848 each to match, which is highly unlikely to happen. */
8849 if (dwo_unit
!= NULL
)
8851 complaint (&symfile_complaints
,
8852 _("Multiple CUs in DWO file %s [in module %s]"),
8853 dwo_file
->dwo_name
, objfile
->name
);
8857 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
8858 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
8861 info_ptr
+= per_cu
.length
;
8867 /* DWP file .debug_{cu,tu}_index section format:
8868 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
8870 Both index sections have the same format, and serve to map a 64-bit
8871 signature to a set of section numbers. Each section begins with a header,
8872 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
8873 indexes, and a pool of 32-bit section numbers. The index sections will be
8874 aligned at 8-byte boundaries in the file.
8876 The index section header contains two unsigned 32-bit values (using the
8877 byte order of the application binary):
8879 N, the number of compilation units or type units in the index
8880 M, the number of slots in the hash table
8882 (We assume that N and M will not exceed 2^32 - 1.)
8884 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
8886 The hash table begins at offset 8 in the section, and consists of an array
8887 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
8888 order of the application binary). Unused slots in the hash table are 0.
8889 (We rely on the extreme unlikeliness of a signature being exactly 0.)
8891 The parallel table begins immediately after the hash table
8892 (at offset 8 + 8 * M from the beginning of the section), and consists of an
8893 array of 32-bit indexes (using the byte order of the application binary),
8894 corresponding 1-1 with slots in the hash table. Each entry in the parallel
8895 table contains a 32-bit index into the pool of section numbers. For unused
8896 hash table slots, the corresponding entry in the parallel table will be 0.
8898 Given a 64-bit compilation unit signature or a type signature S, an entry
8899 in the hash table is located as follows:
8901 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
8902 the low-order k bits all set to 1.
8904 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
8906 3) If the hash table entry at index H matches the signature, use that
8907 entry. If the hash table entry at index H is unused (all zeroes),
8908 terminate the search: the signature is not present in the table.
8910 4) Let H = (H + H') modulo M. Repeat at Step 3.
8912 Because M > N and H' and M are relatively prime, the search is guaranteed
8913 to stop at an unused slot or find the match.
8915 The pool of section numbers begins immediately following the hash table
8916 (at offset 8 + 12 * M from the beginning of the section). The pool of
8917 section numbers consists of an array of 32-bit words (using the byte order
8918 of the application binary). Each item in the array is indexed starting
8919 from 0. The hash table entry provides the index of the first section
8920 number in the set. Additional section numbers in the set follow, and the
8921 set is terminated by a 0 entry (section number 0 is not used in ELF).
8923 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
8924 section must be the first entry in the set, and the .debug_abbrev.dwo must
8925 be the second entry. Other members of the set may follow in any order. */
8927 /* Create a hash table to map DWO IDs to their CU/TU entry in
8928 .debug_{info,types}.dwo in DWP_FILE.
8929 Returns NULL if there isn't one.
8930 Note: This function processes DWP files only, not DWO files. */
8932 static struct dwp_hash_table
*
8933 create_dwp_hash_table (struct dwp_file
*dwp_file
, int is_debug_types
)
8935 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8936 bfd
*dbfd
= dwp_file
->dbfd
;
8937 const gdb_byte
*index_ptr
, *index_end
;
8938 struct dwarf2_section_info
*index
;
8939 uint32_t version
, nr_units
, nr_slots
;
8940 struct dwp_hash_table
*htab
;
8943 index
= &dwp_file
->sections
.tu_index
;
8945 index
= &dwp_file
->sections
.cu_index
;
8947 if (dwarf2_section_empty_p (index
))
8949 dwarf2_read_section (objfile
, index
);
8951 index_ptr
= index
->buffer
;
8952 index_end
= index_ptr
+ index
->size
;
8954 version
= read_4_bytes (dbfd
, index_ptr
);
8955 index_ptr
+= 8; /* Skip the unused word. */
8956 nr_units
= read_4_bytes (dbfd
, index_ptr
);
8958 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
8963 error (_("Dwarf Error: unsupported DWP file version (%s)"
8965 pulongest (version
), dwp_file
->name
);
8967 if (nr_slots
!= (nr_slots
& -nr_slots
))
8969 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
8970 " is not power of 2 [in module %s]"),
8971 pulongest (nr_slots
), dwp_file
->name
);
8974 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
8975 htab
->nr_units
= nr_units
;
8976 htab
->nr_slots
= nr_slots
;
8977 htab
->hash_table
= index_ptr
;
8978 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
8979 htab
->section_pool
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
8984 /* Update SECTIONS with the data from SECTP.
8986 This function is like the other "locate" section routines that are
8987 passed to bfd_map_over_sections, but in this context the sections to
8988 read comes from the DWP hash table, not the full ELF section table.
8990 The result is non-zero for success, or zero if an error was found. */
8993 locate_virtual_dwo_sections (asection
*sectp
,
8994 struct virtual_dwo_sections
*sections
)
8996 const struct dwop_section_names
*names
= &dwop_section_names
;
8998 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
9000 /* There can be only one. */
9001 if (sections
->abbrev
.asection
!= NULL
)
9003 sections
->abbrev
.asection
= sectp
;
9004 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
9006 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
9007 || section_is_p (sectp
->name
, &names
->types_dwo
))
9009 /* There can be only one. */
9010 if (sections
->info_or_types
.asection
!= NULL
)
9012 sections
->info_or_types
.asection
= sectp
;
9013 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
9015 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
9017 /* There can be only one. */
9018 if (sections
->line
.asection
!= NULL
)
9020 sections
->line
.asection
= sectp
;
9021 sections
->line
.size
= bfd_get_section_size (sectp
);
9023 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
9025 /* There can be only one. */
9026 if (sections
->loc
.asection
!= NULL
)
9028 sections
->loc
.asection
= sectp
;
9029 sections
->loc
.size
= bfd_get_section_size (sectp
);
9031 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
9033 /* There can be only one. */
9034 if (sections
->macinfo
.asection
!= NULL
)
9036 sections
->macinfo
.asection
= sectp
;
9037 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
9039 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
9041 /* There can be only one. */
9042 if (sections
->macro
.asection
!= NULL
)
9044 sections
->macro
.asection
= sectp
;
9045 sections
->macro
.size
= bfd_get_section_size (sectp
);
9047 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
9049 /* There can be only one. */
9050 if (sections
->str_offsets
.asection
!= NULL
)
9052 sections
->str_offsets
.asection
= sectp
;
9053 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
9057 /* No other kind of section is valid. */
9064 /* Create a dwo_unit object for the DWO with signature SIGNATURE.
9065 HTAB is the hash table from the DWP file.
9066 SECTION_INDEX is the index of the DWO in HTAB.
9067 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU. */
9069 static struct dwo_unit
*
9070 create_dwo_in_dwp (struct dwp_file
*dwp_file
,
9071 const struct dwp_hash_table
*htab
,
9072 uint32_t section_index
,
9073 const char *comp_dir
,
9074 ULONGEST signature
, int is_debug_types
)
9076 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9077 bfd
*dbfd
= dwp_file
->dbfd
;
9078 const char *kind
= is_debug_types
? "TU" : "CU";
9079 struct dwo_file
*dwo_file
;
9080 struct dwo_unit
*dwo_unit
;
9081 struct virtual_dwo_sections sections
;
9082 void **dwo_file_slot
;
9083 char *virtual_dwo_name
;
9084 struct dwarf2_section_info
*cutu
;
9085 struct cleanup
*cleanups
;
9088 if (dwarf2_read_debug
)
9090 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP file: %s\n",
9092 pulongest (section_index
), hex_string (signature
),
9096 /* Fetch the sections of this DWO.
9097 Put a limit on the number of sections we look for so that bad data
9098 doesn't cause us to loop forever. */
9100 #define MAX_NR_DWO_SECTIONS \
9101 (1 /* .debug_info or .debug_types */ \
9102 + 1 /* .debug_abbrev */ \
9103 + 1 /* .debug_line */ \
9104 + 1 /* .debug_loc */ \
9105 + 1 /* .debug_str_offsets */ \
9106 + 1 /* .debug_macro */ \
9107 + 1 /* .debug_macinfo */ \
9108 + 1 /* trailing zero */)
9110 memset (§ions
, 0, sizeof (sections
));
9111 cleanups
= make_cleanup (null_cleanup
, 0);
9113 for (i
= 0; i
< MAX_NR_DWO_SECTIONS
; ++i
)
9116 uint32_t section_nr
=
9119 + (section_index
+ i
) * sizeof (uint32_t));
9121 if (section_nr
== 0)
9123 if (section_nr
>= dwp_file
->num_sections
)
9125 error (_("Dwarf Error: bad DWP hash table, section number too large"
9130 sectp
= dwp_file
->elf_sections
[section_nr
];
9131 if (! locate_virtual_dwo_sections (sectp
, §ions
))
9133 error (_("Dwarf Error: bad DWP hash table, invalid section found"
9140 || sections
.info_or_types
.asection
== NULL
9141 || sections
.abbrev
.asection
== NULL
)
9143 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
9147 if (i
== MAX_NR_DWO_SECTIONS
)
9149 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
9154 /* It's easier for the rest of the code if we fake a struct dwo_file and
9155 have dwo_unit "live" in that. At least for now.
9157 The DWP file can be made up of a random collection of CUs and TUs.
9158 However, for each CU + set of TUs that came from the same original DWO
9159 file, we want to combine them back into a virtual DWO file to save space
9160 (fewer struct dwo_file objects to allocated). Remember that for really
9161 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
9164 xstrprintf ("virtual-dwo/%d-%d-%d-%d",
9165 sections
.abbrev
.asection
? sections
.abbrev
.asection
->id
: 0,
9166 sections
.line
.asection
? sections
.line
.asection
->id
: 0,
9167 sections
.loc
.asection
? sections
.loc
.asection
->id
: 0,
9168 (sections
.str_offsets
.asection
9169 ? sections
.str_offsets
.asection
->id
9171 make_cleanup (xfree
, virtual_dwo_name
);
9172 /* Can we use an existing virtual DWO file? */
9173 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
, comp_dir
);
9174 /* Create one if necessary. */
9175 if (*dwo_file_slot
== NULL
)
9177 if (dwarf2_read_debug
)
9179 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
9182 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
9183 dwo_file
->dwo_name
= obstack_copy0 (&objfile
->objfile_obstack
,
9185 strlen (virtual_dwo_name
));
9186 dwo_file
->comp_dir
= comp_dir
;
9187 dwo_file
->sections
.abbrev
= sections
.abbrev
;
9188 dwo_file
->sections
.line
= sections
.line
;
9189 dwo_file
->sections
.loc
= sections
.loc
;
9190 dwo_file
->sections
.macinfo
= sections
.macinfo
;
9191 dwo_file
->sections
.macro
= sections
.macro
;
9192 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
9193 /* The "str" section is global to the entire DWP file. */
9194 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
9195 /* The info or types section is assigned later to dwo_unit,
9196 there's no need to record it in dwo_file.
9197 Also, we can't simply record type sections in dwo_file because
9198 we record a pointer into the vector in dwo_unit. As we collect more
9199 types we'll grow the vector and eventually have to reallocate space
9200 for it, invalidating all the pointers into the current copy. */
9201 *dwo_file_slot
= dwo_file
;
9205 if (dwarf2_read_debug
)
9207 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
9210 dwo_file
= *dwo_file_slot
;
9212 do_cleanups (cleanups
);
9214 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
9215 dwo_unit
->dwo_file
= dwo_file
;
9216 dwo_unit
->signature
= signature
;
9217 dwo_unit
->section
= obstack_alloc (&objfile
->objfile_obstack
,
9218 sizeof (struct dwarf2_section_info
));
9219 *dwo_unit
->section
= sections
.info_or_types
;
9220 /* offset, length, type_offset_in_tu are set later. */
9225 /* Lookup the DWO with SIGNATURE in DWP_FILE. */
9227 static struct dwo_unit
*
9228 lookup_dwo_in_dwp (struct dwp_file
*dwp_file
,
9229 const struct dwp_hash_table
*htab
,
9230 const char *comp_dir
,
9231 ULONGEST signature
, int is_debug_types
)
9233 bfd
*dbfd
= dwp_file
->dbfd
;
9234 uint32_t mask
= htab
->nr_slots
- 1;
9235 uint32_t hash
= signature
& mask
;
9236 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
9239 struct dwo_unit find_dwo_cu
, *dwo_cu
;
9241 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
9242 find_dwo_cu
.signature
= signature
;
9243 slot
= htab_find_slot (dwp_file
->loaded_cutus
, &find_dwo_cu
, INSERT
);
9248 /* Use a for loop so that we don't loop forever on bad debug info. */
9249 for (i
= 0; i
< htab
->nr_slots
; ++i
)
9251 ULONGEST signature_in_table
;
9253 signature_in_table
=
9254 read_8_bytes (dbfd
, htab
->hash_table
+ hash
* sizeof (uint64_t));
9255 if (signature_in_table
== signature
)
9257 uint32_t section_index
=
9258 read_4_bytes (dbfd
, htab
->unit_table
+ hash
* sizeof (uint32_t));
9260 *slot
= create_dwo_in_dwp (dwp_file
, htab
, section_index
,
9261 comp_dir
, signature
, is_debug_types
);
9264 if (signature_in_table
== 0)
9266 hash
= (hash
+ hash2
) & mask
;
9269 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
9274 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
9275 Open the file specified by FILE_NAME and hand it off to BFD for
9276 preliminary analysis. Return a newly initialized bfd *, which
9277 includes a canonicalized copy of FILE_NAME.
9278 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
9279 In case of trouble, return NULL.
9280 NOTE: This function is derived from symfile_bfd_open. */
9283 try_open_dwop_file (const char *file_name
, int is_dwp
)
9287 char *absolute_name
;
9289 flags
= OPF_TRY_CWD_FIRST
;
9291 flags
|= OPF_SEARCH_IN_PATH
;
9292 desc
= openp (debug_file_directory
, flags
, file_name
,
9293 O_RDONLY
| O_BINARY
, &absolute_name
);
9297 sym_bfd
= gdb_bfd_open (absolute_name
, gnutarget
, desc
);
9300 xfree (absolute_name
);
9303 xfree (absolute_name
);
9304 bfd_set_cacheable (sym_bfd
, 1);
9306 if (!bfd_check_format (sym_bfd
, bfd_object
))
9308 gdb_bfd_unref (sym_bfd
); /* This also closes desc. */
9315 /* Try to open DWO file FILE_NAME.
9316 COMP_DIR is the DW_AT_comp_dir attribute.
9317 The result is the bfd handle of the file.
9318 If there is a problem finding or opening the file, return NULL.
9319 Upon success, the canonicalized path of the file is stored in the bfd,
9320 same as symfile_bfd_open. */
9323 open_dwo_file (const char *file_name
, const char *comp_dir
)
9327 if (IS_ABSOLUTE_PATH (file_name
))
9328 return try_open_dwop_file (file_name
, 0 /*is_dwp*/);
9330 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
9332 if (comp_dir
!= NULL
)
9334 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, file_name
, NULL
);
9336 /* NOTE: If comp_dir is a relative path, this will also try the
9337 search path, which seems useful. */
9338 abfd
= try_open_dwop_file (path_to_try
, 0 /*is_dwp*/);
9339 xfree (path_to_try
);
9344 /* That didn't work, try debug-file-directory, which, despite its name,
9345 is a list of paths. */
9347 if (*debug_file_directory
== '\0')
9350 return try_open_dwop_file (file_name
, 0 /*is_dwp*/);
9353 /* This function is mapped across the sections and remembers the offset and
9354 size of each of the DWO debugging sections we are interested in. */
9357 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
9359 struct dwo_sections
*dwo_sections
= dwo_sections_ptr
;
9360 const struct dwop_section_names
*names
= &dwop_section_names
;
9362 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
9364 dwo_sections
->abbrev
.asection
= sectp
;
9365 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
9367 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
9369 dwo_sections
->info
.asection
= sectp
;
9370 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
9372 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
9374 dwo_sections
->line
.asection
= sectp
;
9375 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
9377 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
9379 dwo_sections
->loc
.asection
= sectp
;
9380 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
9382 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
9384 dwo_sections
->macinfo
.asection
= sectp
;
9385 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
9387 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
9389 dwo_sections
->macro
.asection
= sectp
;
9390 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
9392 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
9394 dwo_sections
->str
.asection
= sectp
;
9395 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
9397 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
9399 dwo_sections
->str_offsets
.asection
= sectp
;
9400 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
9402 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
9404 struct dwarf2_section_info type_section
;
9406 memset (&type_section
, 0, sizeof (type_section
));
9407 type_section
.asection
= sectp
;
9408 type_section
.size
= bfd_get_section_size (sectp
);
9409 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
9414 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
9415 by PER_CU. This is for the non-DWP case.
9416 The result is NULL if DWO_NAME can't be found. */
9418 static struct dwo_file
*
9419 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
9420 const char *dwo_name
, const char *comp_dir
)
9422 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9423 struct dwo_file
*dwo_file
;
9425 struct cleanup
*cleanups
;
9427 dbfd
= open_dwo_file (dwo_name
, comp_dir
);
9430 if (dwarf2_read_debug
)
9431 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
9434 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
9435 dwo_file
->dwo_name
= dwo_name
;
9436 dwo_file
->comp_dir
= comp_dir
;
9437 dwo_file
->dbfd
= dbfd
;
9439 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
9441 bfd_map_over_sections (dbfd
, dwarf2_locate_dwo_sections
, &dwo_file
->sections
);
9443 dwo_file
->cu
= create_dwo_cu (dwo_file
);
9445 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
9446 dwo_file
->sections
.types
);
9448 discard_cleanups (cleanups
);
9450 if (dwarf2_read_debug
)
9451 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
9456 /* This function is mapped across the sections and remembers the offset and
9457 size of each of the DWP debugging sections we are interested in. */
9460 dwarf2_locate_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
9462 struct dwp_file
*dwp_file
= dwp_file_ptr
;
9463 const struct dwop_section_names
*names
= &dwop_section_names
;
9464 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
9466 /* Record the ELF section number for later lookup: this is what the
9467 .debug_cu_index,.debug_tu_index tables use. */
9468 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
9469 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
9471 /* Look for specific sections that we need. */
9472 if (section_is_p (sectp
->name
, &names
->str_dwo
))
9474 dwp_file
->sections
.str
.asection
= sectp
;
9475 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
9477 else if (section_is_p (sectp
->name
, &names
->cu_index
))
9479 dwp_file
->sections
.cu_index
.asection
= sectp
;
9480 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
9482 else if (section_is_p (sectp
->name
, &names
->tu_index
))
9484 dwp_file
->sections
.tu_index
.asection
= sectp
;
9485 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
9489 /* Hash function for dwp_file loaded CUs/TUs. */
9492 hash_dwp_loaded_cutus (const void *item
)
9494 const struct dwo_unit
*dwo_unit
= item
;
9496 /* This drops the top 32 bits of the signature, but is ok for a hash. */
9497 return dwo_unit
->signature
;
9500 /* Equality function for dwp_file loaded CUs/TUs. */
9503 eq_dwp_loaded_cutus (const void *a
, const void *b
)
9505 const struct dwo_unit
*dua
= a
;
9506 const struct dwo_unit
*dub
= b
;
9508 return dua
->signature
== dub
->signature
;
9511 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
9514 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
9516 return htab_create_alloc_ex (3,
9517 hash_dwp_loaded_cutus
,
9518 eq_dwp_loaded_cutus
,
9520 &objfile
->objfile_obstack
,
9521 hashtab_obstack_allocate
,
9522 dummy_obstack_deallocate
);
9525 /* Try to open DWP file FILE_NAME.
9526 The result is the bfd handle of the file.
9527 If there is a problem finding or opening the file, return NULL.
9528 Upon success, the canonicalized path of the file is stored in the bfd,
9529 same as symfile_bfd_open. */
9532 open_dwp_file (const char *file_name
)
9534 return try_open_dwop_file (file_name
, 1 /*is_dwp*/);
9537 /* Initialize the use of the DWP file for the current objfile.
9538 By convention the name of the DWP file is ${objfile}.dwp.
9539 The result is NULL if it can't be found. */
9541 static struct dwp_file
*
9542 open_and_init_dwp_file (void)
9544 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9545 struct dwp_file
*dwp_file
;
9548 struct cleanup
*cleanups
;
9550 dwp_name
= xstrprintf ("%s.dwp", dwarf2_per_objfile
->objfile
->name
);
9551 cleanups
= make_cleanup (xfree
, dwp_name
);
9553 dbfd
= open_dwp_file (dwp_name
);
9556 if (dwarf2_read_debug
)
9557 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
);
9558 do_cleanups (cleanups
);
9561 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
9562 dwp_file
->name
= obstack_copy0 (&objfile
->objfile_obstack
,
9563 dwp_name
, strlen (dwp_name
));
9564 dwp_file
->dbfd
= dbfd
;
9565 do_cleanups (cleanups
);
9567 /* +1: section 0 is unused */
9568 dwp_file
->num_sections
= bfd_count_sections (dbfd
) + 1;
9569 dwp_file
->elf_sections
=
9570 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
9571 dwp_file
->num_sections
, asection
*);
9573 bfd_map_over_sections (dbfd
, dwarf2_locate_dwp_sections
, dwp_file
);
9575 dwp_file
->cus
= create_dwp_hash_table (dwp_file
, 0);
9577 dwp_file
->tus
= create_dwp_hash_table (dwp_file
, 1);
9579 dwp_file
->loaded_cutus
= allocate_dwp_loaded_cutus_table (objfile
);
9581 if (dwarf2_read_debug
)
9583 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
9584 fprintf_unfiltered (gdb_stdlog
,
9585 " %s CUs, %s TUs\n",
9586 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
9587 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
9593 /* Wrapper around open_and_init_dwp_file, only open it once. */
9595 static struct dwp_file
*
9598 if (! dwarf2_per_objfile
->dwp_checked
)
9600 dwarf2_per_objfile
->dwp_file
= open_and_init_dwp_file ();
9601 dwarf2_per_objfile
->dwp_checked
= 1;
9603 return dwarf2_per_objfile
->dwp_file
;
9606 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
9607 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
9608 or in the DWP file for the objfile, referenced by THIS_UNIT.
9609 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
9610 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
9612 This is called, for example, when wanting to read a variable with a
9613 complex location. Therefore we don't want to do file i/o for every call.
9614 Therefore we don't want to look for a DWO file on every call.
9615 Therefore we first see if we've already seen SIGNATURE in a DWP file,
9616 then we check if we've already seen DWO_NAME, and only THEN do we check
9619 The result is a pointer to the dwo_unit object or NULL if we didn't find it
9620 (dwo_id mismatch or couldn't find the DWO/DWP file). */
9622 static struct dwo_unit
*
9623 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
9624 const char *dwo_name
, const char *comp_dir
,
9625 ULONGEST signature
, int is_debug_types
)
9627 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9628 const char *kind
= is_debug_types
? "TU" : "CU";
9629 void **dwo_file_slot
;
9630 struct dwo_file
*dwo_file
;
9631 struct dwp_file
*dwp_file
;
9633 /* First see if there's a DWP file.
9634 If we have a DWP file but didn't find the DWO inside it, don't
9635 look for the original DWO file. It makes gdb behave differently
9636 depending on whether one is debugging in the build tree. */
9638 dwp_file
= get_dwp_file ();
9639 if (dwp_file
!= NULL
)
9641 const struct dwp_hash_table
*dwp_htab
=
9642 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
9644 if (dwp_htab
!= NULL
)
9646 struct dwo_unit
*dwo_cutu
=
9647 lookup_dwo_in_dwp (dwp_file
, dwp_htab
, comp_dir
,
9648 signature
, is_debug_types
);
9650 if (dwo_cutu
!= NULL
)
9652 if (dwarf2_read_debug
)
9654 fprintf_unfiltered (gdb_stdlog
,
9655 "Virtual DWO %s %s found: @%s\n",
9656 kind
, hex_string (signature
),
9657 host_address_to_string (dwo_cutu
));
9665 /* No DWP file, look for the DWO file. */
9667 dwo_file_slot
= lookup_dwo_file_slot (dwo_name
, comp_dir
);
9668 if (*dwo_file_slot
== NULL
)
9670 /* Read in the file and build a table of the CUs/TUs it contains. */
9671 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
9673 /* NOTE: This will be NULL if unable to open the file. */
9674 dwo_file
= *dwo_file_slot
;
9676 if (dwo_file
!= NULL
)
9678 struct dwo_unit
*dwo_cutu
= NULL
;
9680 if (is_debug_types
&& dwo_file
->tus
)
9682 struct dwo_unit find_dwo_cutu
;
9684 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
9685 find_dwo_cutu
.signature
= signature
;
9686 dwo_cutu
= htab_find (dwo_file
->tus
, &find_dwo_cutu
);
9688 else if (!is_debug_types
&& dwo_file
->cu
)
9690 if (signature
== dwo_file
->cu
->signature
)
9691 dwo_cutu
= dwo_file
->cu
;
9694 if (dwo_cutu
!= NULL
)
9696 if (dwarf2_read_debug
)
9698 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
9699 kind
, dwo_name
, hex_string (signature
),
9700 host_address_to_string (dwo_cutu
));
9707 /* We didn't find it. This could mean a dwo_id mismatch, or
9708 someone deleted the DWO/DWP file, or the search path isn't set up
9709 correctly to find the file. */
9711 if (dwarf2_read_debug
)
9713 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
9714 kind
, dwo_name
, hex_string (signature
));
9717 complaint (&symfile_complaints
,
9718 _("Could not find DWO %s %s(%s) referenced by %s at offset 0x%x"
9720 kind
, dwo_name
, hex_string (signature
),
9721 this_unit
->is_debug_types
? "TU" : "CU",
9722 this_unit
->offset
.sect_off
, objfile
->name
);
9726 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
9727 See lookup_dwo_cutu_unit for details. */
9729 static struct dwo_unit
*
9730 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9731 const char *dwo_name
, const char *comp_dir
,
9734 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
9737 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
9738 See lookup_dwo_cutu_unit for details. */
9740 static struct dwo_unit
*
9741 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
9742 const char *dwo_name
, const char *comp_dir
)
9744 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
9747 /* Free all resources associated with DWO_FILE.
9748 Close the DWO file and munmap the sections.
9749 All memory should be on the objfile obstack. */
9752 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
9755 struct dwarf2_section_info
*section
;
9757 /* Note: dbfd is NULL for virtual DWO files. */
9758 gdb_bfd_unref (dwo_file
->dbfd
);
9760 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
9763 /* Wrapper for free_dwo_file for use in cleanups. */
9766 free_dwo_file_cleanup (void *arg
)
9768 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
9769 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9771 free_dwo_file (dwo_file
, objfile
);
9774 /* Traversal function for free_dwo_files. */
9777 free_dwo_file_from_slot (void **slot
, void *info
)
9779 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
9780 struct objfile
*objfile
= (struct objfile
*) info
;
9782 free_dwo_file (dwo_file
, objfile
);
9787 /* Free all resources associated with DWO_FILES. */
9790 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
9792 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
9795 /* Read in various DIEs. */
9797 /* qsort helper for inherit_abstract_dies. */
9800 unsigned_int_compar (const void *ap
, const void *bp
)
9802 unsigned int a
= *(unsigned int *) ap
;
9803 unsigned int b
= *(unsigned int *) bp
;
9805 return (a
> b
) - (b
> a
);
9808 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
9809 Inherit only the children of the DW_AT_abstract_origin DIE not being
9810 already referenced by DW_AT_abstract_origin from the children of the
9814 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
9816 struct die_info
*child_die
;
9817 unsigned die_children_count
;
9818 /* CU offsets which were referenced by children of the current DIE. */
9819 sect_offset
*offsets
;
9820 sect_offset
*offsets_end
, *offsetp
;
9821 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
9822 struct die_info
*origin_die
;
9823 /* Iterator of the ORIGIN_DIE children. */
9824 struct die_info
*origin_child_die
;
9825 struct cleanup
*cleanups
;
9826 struct attribute
*attr
;
9827 struct dwarf2_cu
*origin_cu
;
9828 struct pending
**origin_previous_list_in_scope
;
9830 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
9834 /* Note that following die references may follow to a die in a
9838 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
9840 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
9842 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
9843 origin_cu
->list_in_scope
= cu
->list_in_scope
;
9845 if (die
->tag
!= origin_die
->tag
9846 && !(die
->tag
== DW_TAG_inlined_subroutine
9847 && origin_die
->tag
== DW_TAG_subprogram
))
9848 complaint (&symfile_complaints
,
9849 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
9850 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
9852 child_die
= die
->child
;
9853 die_children_count
= 0;
9854 while (child_die
&& child_die
->tag
)
9856 child_die
= sibling_die (child_die
);
9857 die_children_count
++;
9859 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
9860 cleanups
= make_cleanup (xfree
, offsets
);
9862 offsets_end
= offsets
;
9863 child_die
= die
->child
;
9864 while (child_die
&& child_die
->tag
)
9866 /* For each CHILD_DIE, find the corresponding child of
9867 ORIGIN_DIE. If there is more than one layer of
9868 DW_AT_abstract_origin, follow them all; there shouldn't be,
9869 but GCC versions at least through 4.4 generate this (GCC PR
9871 struct die_info
*child_origin_die
= child_die
;
9872 struct dwarf2_cu
*child_origin_cu
= cu
;
9876 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
9880 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
9884 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
9885 counterpart may exist. */
9886 if (child_origin_die
!= child_die
)
9888 if (child_die
->tag
!= child_origin_die
->tag
9889 && !(child_die
->tag
== DW_TAG_inlined_subroutine
9890 && child_origin_die
->tag
== DW_TAG_subprogram
))
9891 complaint (&symfile_complaints
,
9892 _("Child DIE 0x%x and its abstract origin 0x%x have "
9893 "different tags"), child_die
->offset
.sect_off
,
9894 child_origin_die
->offset
.sect_off
);
9895 if (child_origin_die
->parent
!= origin_die
)
9896 complaint (&symfile_complaints
,
9897 _("Child DIE 0x%x and its abstract origin 0x%x have "
9898 "different parents"), child_die
->offset
.sect_off
,
9899 child_origin_die
->offset
.sect_off
);
9901 *offsets_end
++ = child_origin_die
->offset
;
9903 child_die
= sibling_die (child_die
);
9905 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
9906 unsigned_int_compar
);
9907 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
9908 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
9909 complaint (&symfile_complaints
,
9910 _("Multiple children of DIE 0x%x refer "
9911 "to DIE 0x%x as their abstract origin"),
9912 die
->offset
.sect_off
, offsetp
->sect_off
);
9915 origin_child_die
= origin_die
->child
;
9916 while (origin_child_die
&& origin_child_die
->tag
)
9918 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
9919 while (offsetp
< offsets_end
9920 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
9922 if (offsetp
>= offsets_end
9923 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
9925 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
9926 process_die (origin_child_die
, origin_cu
);
9928 origin_child_die
= sibling_die (origin_child_die
);
9930 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
9932 do_cleanups (cleanups
);
9936 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9938 struct objfile
*objfile
= cu
->objfile
;
9939 struct context_stack
*new;
9942 struct die_info
*child_die
;
9943 struct attribute
*attr
, *call_line
, *call_file
;
9946 struct block
*block
;
9947 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
9948 VEC (symbolp
) *template_args
= NULL
;
9949 struct template_symbol
*templ_func
= NULL
;
9953 /* If we do not have call site information, we can't show the
9954 caller of this inlined function. That's too confusing, so
9955 only use the scope for local variables. */
9956 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
9957 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
9958 if (call_line
== NULL
|| call_file
== NULL
)
9960 read_lexical_block_scope (die
, cu
);
9965 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9967 name
= dwarf2_name (die
, cu
);
9969 /* Ignore functions with missing or empty names. These are actually
9970 illegal according to the DWARF standard. */
9973 complaint (&symfile_complaints
,
9974 _("missing name for subprogram DIE at %d"),
9975 die
->offset
.sect_off
);
9979 /* Ignore functions with missing or invalid low and high pc attributes. */
9980 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
9982 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9983 if (!attr
|| !DW_UNSND (attr
))
9984 complaint (&symfile_complaints
,
9985 _("cannot get low and high bounds "
9986 "for subprogram DIE at %d"),
9987 die
->offset
.sect_off
);
9994 /* If we have any template arguments, then we must allocate a
9995 different sort of symbol. */
9996 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
9998 if (child_die
->tag
== DW_TAG_template_type_param
9999 || child_die
->tag
== DW_TAG_template_value_param
)
10001 templ_func
= allocate_template_symbol (objfile
);
10002 templ_func
->base
.is_cplus_template_function
= 1;
10007 new = push_context (0, lowpc
);
10008 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
10009 (struct symbol
*) templ_func
);
10011 /* If there is a location expression for DW_AT_frame_base, record
10013 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
10015 dwarf2_symbol_mark_computed (attr
, new->name
, cu
, 1);
10017 cu
->list_in_scope
= &local_symbols
;
10019 if (die
->child
!= NULL
)
10021 child_die
= die
->child
;
10022 while (child_die
&& child_die
->tag
)
10024 if (child_die
->tag
== DW_TAG_template_type_param
10025 || child_die
->tag
== DW_TAG_template_value_param
)
10027 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
10030 VEC_safe_push (symbolp
, template_args
, arg
);
10033 process_die (child_die
, cu
);
10034 child_die
= sibling_die (child_die
);
10038 inherit_abstract_dies (die
, cu
);
10040 /* If we have a DW_AT_specification, we might need to import using
10041 directives from the context of the specification DIE. See the
10042 comment in determine_prefix. */
10043 if (cu
->language
== language_cplus
10044 && dwarf2_attr (die
, DW_AT_specification
, cu
))
10046 struct dwarf2_cu
*spec_cu
= cu
;
10047 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
10051 child_die
= spec_die
->child
;
10052 while (child_die
&& child_die
->tag
)
10054 if (child_die
->tag
== DW_TAG_imported_module
)
10055 process_die (child_die
, spec_cu
);
10056 child_die
= sibling_die (child_die
);
10059 /* In some cases, GCC generates specification DIEs that
10060 themselves contain DW_AT_specification attributes. */
10061 spec_die
= die_specification (spec_die
, &spec_cu
);
10065 new = pop_context ();
10066 /* Make a block for the local symbols within. */
10067 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
10068 lowpc
, highpc
, objfile
);
10070 /* For C++, set the block's scope. */
10071 if ((cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
10072 && cu
->processing_has_namespace_info
)
10073 block_set_scope (block
, determine_prefix (die
, cu
),
10074 &objfile
->objfile_obstack
);
10076 /* If we have address ranges, record them. */
10077 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
10079 /* Attach template arguments to function. */
10080 if (! VEC_empty (symbolp
, template_args
))
10082 gdb_assert (templ_func
!= NULL
);
10084 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
10085 templ_func
->template_arguments
10086 = obstack_alloc (&objfile
->objfile_obstack
,
10087 (templ_func
->n_template_arguments
10088 * sizeof (struct symbol
*)));
10089 memcpy (templ_func
->template_arguments
,
10090 VEC_address (symbolp
, template_args
),
10091 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
10092 VEC_free (symbolp
, template_args
);
10095 /* In C++, we can have functions nested inside functions (e.g., when
10096 a function declares a class that has methods). This means that
10097 when we finish processing a function scope, we may need to go
10098 back to building a containing block's symbol lists. */
10099 local_symbols
= new->locals
;
10100 using_directives
= new->using_directives
;
10102 /* If we've finished processing a top-level function, subsequent
10103 symbols go in the file symbol list. */
10104 if (outermost_context_p ())
10105 cu
->list_in_scope
= &file_symbols
;
10108 /* Process all the DIES contained within a lexical block scope. Start
10109 a new scope, process the dies, and then close the scope. */
10112 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10114 struct objfile
*objfile
= cu
->objfile
;
10115 struct context_stack
*new;
10116 CORE_ADDR lowpc
, highpc
;
10117 struct die_info
*child_die
;
10118 CORE_ADDR baseaddr
;
10120 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10122 /* Ignore blocks with missing or invalid low and high pc attributes. */
10123 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
10124 as multiple lexical blocks? Handling children in a sane way would
10125 be nasty. Might be easier to properly extend generic blocks to
10126 describe ranges. */
10127 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
10130 highpc
+= baseaddr
;
10132 push_context (0, lowpc
);
10133 if (die
->child
!= NULL
)
10135 child_die
= die
->child
;
10136 while (child_die
&& child_die
->tag
)
10138 process_die (child_die
, cu
);
10139 child_die
= sibling_die (child_die
);
10142 new = pop_context ();
10144 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
10146 struct block
*block
10147 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
10150 /* Note that recording ranges after traversing children, as we
10151 do here, means that recording a parent's ranges entails
10152 walking across all its children's ranges as they appear in
10153 the address map, which is quadratic behavior.
10155 It would be nicer to record the parent's ranges before
10156 traversing its children, simply overriding whatever you find
10157 there. But since we don't even decide whether to create a
10158 block until after we've traversed its children, that's hard
10160 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
10162 local_symbols
= new->locals
;
10163 using_directives
= new->using_directives
;
10166 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
10169 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10171 struct objfile
*objfile
= cu
->objfile
;
10172 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10173 CORE_ADDR pc
, baseaddr
;
10174 struct attribute
*attr
;
10175 struct call_site
*call_site
, call_site_local
;
10178 struct die_info
*child_die
;
10180 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10182 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10185 complaint (&symfile_complaints
,
10186 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
10187 "DIE 0x%x [in module %s]"),
10188 die
->offset
.sect_off
, objfile
->name
);
10191 pc
= DW_ADDR (attr
) + baseaddr
;
10193 if (cu
->call_site_htab
== NULL
)
10194 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
10195 NULL
, &objfile
->objfile_obstack
,
10196 hashtab_obstack_allocate
, NULL
);
10197 call_site_local
.pc
= pc
;
10198 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
10201 complaint (&symfile_complaints
,
10202 _("Duplicate PC %s for DW_TAG_GNU_call_site "
10203 "DIE 0x%x [in module %s]"),
10204 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
10208 /* Count parameters at the caller. */
10211 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10212 child_die
= sibling_die (child_die
))
10214 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
10216 complaint (&symfile_complaints
,
10217 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
10218 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
10219 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
10226 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
10227 (sizeof (*call_site
)
10228 + (sizeof (*call_site
->parameter
)
10229 * (nparams
- 1))));
10231 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
10232 call_site
->pc
= pc
;
10234 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
10236 struct die_info
*func_die
;
10238 /* Skip also over DW_TAG_inlined_subroutine. */
10239 for (func_die
= die
->parent
;
10240 func_die
&& func_die
->tag
!= DW_TAG_subprogram
10241 && func_die
->tag
!= DW_TAG_subroutine_type
;
10242 func_die
= func_die
->parent
);
10244 /* DW_AT_GNU_all_call_sites is a superset
10245 of DW_AT_GNU_all_tail_call_sites. */
10247 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
10248 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
10250 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
10251 not complete. But keep CALL_SITE for look ups via call_site_htab,
10252 both the initial caller containing the real return address PC and
10253 the final callee containing the current PC of a chain of tail
10254 calls do not need to have the tail call list complete. But any
10255 function candidate for a virtual tail call frame searched via
10256 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
10257 determined unambiguously. */
10261 struct type
*func_type
= NULL
;
10264 func_type
= get_die_type (func_die
, cu
);
10265 if (func_type
!= NULL
)
10267 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
10269 /* Enlist this call site to the function. */
10270 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
10271 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
10274 complaint (&symfile_complaints
,
10275 _("Cannot find function owning DW_TAG_GNU_call_site "
10276 "DIE 0x%x [in module %s]"),
10277 die
->offset
.sect_off
, objfile
->name
);
10281 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
10283 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
10284 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
10285 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
10286 /* Keep NULL DWARF_BLOCK. */;
10287 else if (attr_form_is_block (attr
))
10289 struct dwarf2_locexpr_baton
*dlbaton
;
10291 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
10292 dlbaton
->data
= DW_BLOCK (attr
)->data
;
10293 dlbaton
->size
= DW_BLOCK (attr
)->size
;
10294 dlbaton
->per_cu
= cu
->per_cu
;
10296 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
10298 else if (is_ref_attr (attr
))
10300 struct dwarf2_cu
*target_cu
= cu
;
10301 struct die_info
*target_die
;
10303 target_die
= follow_die_ref (die
, attr
, &target_cu
);
10304 gdb_assert (target_cu
->objfile
== objfile
);
10305 if (die_is_declaration (target_die
, target_cu
))
10307 const char *target_physname
= NULL
;
10308 struct attribute
*target_attr
;
10310 /* Prefer the mangled name; otherwise compute the demangled one. */
10311 target_attr
= dwarf2_attr (target_die
, DW_AT_linkage_name
, target_cu
);
10312 if (target_attr
== NULL
)
10313 target_attr
= dwarf2_attr (target_die
, DW_AT_MIPS_linkage_name
,
10315 if (target_attr
!= NULL
&& DW_STRING (target_attr
) != NULL
)
10316 target_physname
= DW_STRING (target_attr
);
10318 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
10319 if (target_physname
== NULL
)
10320 complaint (&symfile_complaints
,
10321 _("DW_AT_GNU_call_site_target target DIE has invalid "
10322 "physname, for referencing DIE 0x%x [in module %s]"),
10323 die
->offset
.sect_off
, objfile
->name
);
10325 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
10331 /* DW_AT_entry_pc should be preferred. */
10332 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
10333 complaint (&symfile_complaints
,
10334 _("DW_AT_GNU_call_site_target target DIE has invalid "
10335 "low pc, for referencing DIE 0x%x [in module %s]"),
10336 die
->offset
.sect_off
, objfile
->name
);
10338 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
10342 complaint (&symfile_complaints
,
10343 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
10344 "block nor reference, for DIE 0x%x [in module %s]"),
10345 die
->offset
.sect_off
, objfile
->name
);
10347 call_site
->per_cu
= cu
->per_cu
;
10349 for (child_die
= die
->child
;
10350 child_die
&& child_die
->tag
;
10351 child_die
= sibling_die (child_die
))
10353 struct call_site_parameter
*parameter
;
10354 struct attribute
*loc
, *origin
;
10356 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
10358 /* Already printed the complaint above. */
10362 gdb_assert (call_site
->parameter_count
< nparams
);
10363 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
10365 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
10366 specifies DW_TAG_formal_parameter. Value of the data assumed for the
10367 register is contained in DW_AT_GNU_call_site_value. */
10369 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
10370 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
10371 if (loc
== NULL
&& origin
!= NULL
&& is_ref_attr (origin
))
10373 sect_offset offset
;
10375 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
10376 offset
= dwarf2_get_ref_die_offset (origin
);
10377 if (!offset_in_cu_p (&cu
->header
, offset
))
10379 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
10380 binding can be done only inside one CU. Such referenced DIE
10381 therefore cannot be even moved to DW_TAG_partial_unit. */
10382 complaint (&symfile_complaints
,
10383 _("DW_AT_abstract_origin offset is not in CU for "
10384 "DW_TAG_GNU_call_site child DIE 0x%x "
10386 child_die
->offset
.sect_off
, objfile
->name
);
10389 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
10390 - cu
->header
.offset
.sect_off
);
10392 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
10394 complaint (&symfile_complaints
,
10395 _("No DW_FORM_block* DW_AT_location for "
10396 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
10397 child_die
->offset
.sect_off
, objfile
->name
);
10402 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
10403 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
10404 if (parameter
->u
.dwarf_reg
!= -1)
10405 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
10406 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
10407 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
10408 ¶meter
->u
.fb_offset
))
10409 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
10412 complaint (&symfile_complaints
,
10413 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
10414 "for DW_FORM_block* DW_AT_location is supported for "
10415 "DW_TAG_GNU_call_site child DIE 0x%x "
10417 child_die
->offset
.sect_off
, objfile
->name
);
10422 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
10423 if (!attr_form_is_block (attr
))
10425 complaint (&symfile_complaints
,
10426 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
10427 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
10428 child_die
->offset
.sect_off
, objfile
->name
);
10431 parameter
->value
= DW_BLOCK (attr
)->data
;
10432 parameter
->value_size
= DW_BLOCK (attr
)->size
;
10434 /* Parameters are not pre-cleared by memset above. */
10435 parameter
->data_value
= NULL
;
10436 parameter
->data_value_size
= 0;
10437 call_site
->parameter_count
++;
10439 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
10442 if (!attr_form_is_block (attr
))
10443 complaint (&symfile_complaints
,
10444 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
10445 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
10446 child_die
->offset
.sect_off
, objfile
->name
);
10449 parameter
->data_value
= DW_BLOCK (attr
)->data
;
10450 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
10456 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
10457 Return 1 if the attributes are present and valid, otherwise, return 0.
10458 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
10461 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
10462 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
10463 struct partial_symtab
*ranges_pst
)
10465 struct objfile
*objfile
= cu
->objfile
;
10466 struct comp_unit_head
*cu_header
= &cu
->header
;
10467 bfd
*obfd
= objfile
->obfd
;
10468 unsigned int addr_size
= cu_header
->addr_size
;
10469 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
10470 /* Base address selection entry. */
10473 unsigned int dummy
;
10474 const gdb_byte
*buffer
;
10478 CORE_ADDR high
= 0;
10479 CORE_ADDR baseaddr
;
10481 found_base
= cu
->base_known
;
10482 base
= cu
->base_address
;
10484 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
10485 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
10487 complaint (&symfile_complaints
,
10488 _("Offset %d out of bounds for DW_AT_ranges attribute"),
10492 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
10494 /* Read in the largest possible address. */
10495 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
10496 if ((marker
& mask
) == mask
)
10498 /* If we found the largest possible address, then
10499 read the base address. */
10500 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
10501 buffer
+= 2 * addr_size
;
10502 offset
+= 2 * addr_size
;
10508 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10512 CORE_ADDR range_beginning
, range_end
;
10514 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
10515 buffer
+= addr_size
;
10516 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
10517 buffer
+= addr_size
;
10518 offset
+= 2 * addr_size
;
10520 /* An end of list marker is a pair of zero addresses. */
10521 if (range_beginning
== 0 && range_end
== 0)
10522 /* Found the end of list entry. */
10525 /* Each base address selection entry is a pair of 2 values.
10526 The first is the largest possible address, the second is
10527 the base address. Check for a base address here. */
10528 if ((range_beginning
& mask
) == mask
)
10530 /* If we found the largest possible address, then
10531 read the base address. */
10532 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
10539 /* We have no valid base address for the ranges
10541 complaint (&symfile_complaints
,
10542 _("Invalid .debug_ranges data (no base address)"));
10546 if (range_beginning
> range_end
)
10548 /* Inverted range entries are invalid. */
10549 complaint (&symfile_complaints
,
10550 _("Invalid .debug_ranges data (inverted range)"));
10554 /* Empty range entries have no effect. */
10555 if (range_beginning
== range_end
)
10558 range_beginning
+= base
;
10561 /* A not-uncommon case of bad debug info.
10562 Don't pollute the addrmap with bad data. */
10563 if (range_beginning
+ baseaddr
== 0
10564 && !dwarf2_per_objfile
->has_section_at_zero
)
10566 complaint (&symfile_complaints
,
10567 _(".debug_ranges entry has start address of zero"
10568 " [in module %s]"), objfile
->name
);
10572 if (ranges_pst
!= NULL
)
10573 addrmap_set_empty (objfile
->psymtabs_addrmap
,
10574 range_beginning
+ baseaddr
,
10575 range_end
- 1 + baseaddr
,
10578 /* FIXME: This is recording everything as a low-high
10579 segment of consecutive addresses. We should have a
10580 data structure for discontiguous block ranges
10584 low
= range_beginning
;
10590 if (range_beginning
< low
)
10591 low
= range_beginning
;
10592 if (range_end
> high
)
10598 /* If the first entry is an end-of-list marker, the range
10599 describes an empty scope, i.e. no instructions. */
10605 *high_return
= high
;
10609 /* Get low and high pc attributes from a die. Return 1 if the attributes
10610 are present and valid, otherwise, return 0. Return -1 if the range is
10611 discontinuous, i.e. derived from DW_AT_ranges information. */
10614 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
10615 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
10616 struct partial_symtab
*pst
)
10618 struct attribute
*attr
;
10619 struct attribute
*attr_high
;
10621 CORE_ADDR high
= 0;
10624 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
10627 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10630 low
= DW_ADDR (attr
);
10631 if (attr_high
->form
== DW_FORM_addr
10632 || attr_high
->form
== DW_FORM_GNU_addr_index
)
10633 high
= DW_ADDR (attr_high
);
10635 high
= low
+ DW_UNSND (attr_high
);
10638 /* Found high w/o low attribute. */
10641 /* Found consecutive range of addresses. */
10646 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
10649 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
10650 We take advantage of the fact that DW_AT_ranges does not appear
10651 in DW_TAG_compile_unit of DWO files. */
10652 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
10653 unsigned int ranges_offset
= (DW_UNSND (attr
)
10654 + (need_ranges_base
10658 /* Value of the DW_AT_ranges attribute is the offset in the
10659 .debug_ranges section. */
10660 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
10662 /* Found discontinuous range of addresses. */
10667 /* read_partial_die has also the strict LOW < HIGH requirement. */
10671 /* When using the GNU linker, .gnu.linkonce. sections are used to
10672 eliminate duplicate copies of functions and vtables and such.
10673 The linker will arbitrarily choose one and discard the others.
10674 The AT_*_pc values for such functions refer to local labels in
10675 these sections. If the section from that file was discarded, the
10676 labels are not in the output, so the relocs get a value of 0.
10677 If this is a discarded function, mark the pc bounds as invalid,
10678 so that GDB will ignore it. */
10679 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10688 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
10689 its low and high PC addresses. Do nothing if these addresses could not
10690 be determined. Otherwise, set LOWPC to the low address if it is smaller,
10691 and HIGHPC to the high address if greater than HIGHPC. */
10694 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
10695 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
10696 struct dwarf2_cu
*cu
)
10698 CORE_ADDR low
, high
;
10699 struct die_info
*child
= die
->child
;
10701 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
10703 *lowpc
= min (*lowpc
, low
);
10704 *highpc
= max (*highpc
, high
);
10707 /* If the language does not allow nested subprograms (either inside
10708 subprograms or lexical blocks), we're done. */
10709 if (cu
->language
!= language_ada
)
10712 /* Check all the children of the given DIE. If it contains nested
10713 subprograms, then check their pc bounds. Likewise, we need to
10714 check lexical blocks as well, as they may also contain subprogram
10716 while (child
&& child
->tag
)
10718 if (child
->tag
== DW_TAG_subprogram
10719 || child
->tag
== DW_TAG_lexical_block
)
10720 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
10721 child
= sibling_die (child
);
10725 /* Get the low and high pc's represented by the scope DIE, and store
10726 them in *LOWPC and *HIGHPC. If the correct values can't be
10727 determined, set *LOWPC to -1 and *HIGHPC to 0. */
10730 get_scope_pc_bounds (struct die_info
*die
,
10731 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
10732 struct dwarf2_cu
*cu
)
10734 CORE_ADDR best_low
= (CORE_ADDR
) -1;
10735 CORE_ADDR best_high
= (CORE_ADDR
) 0;
10736 CORE_ADDR current_low
, current_high
;
10738 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
10740 best_low
= current_low
;
10741 best_high
= current_high
;
10745 struct die_info
*child
= die
->child
;
10747 while (child
&& child
->tag
)
10749 switch (child
->tag
) {
10750 case DW_TAG_subprogram
:
10751 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
10753 case DW_TAG_namespace
:
10754 case DW_TAG_module
:
10755 /* FIXME: carlton/2004-01-16: Should we do this for
10756 DW_TAG_class_type/DW_TAG_structure_type, too? I think
10757 that current GCC's always emit the DIEs corresponding
10758 to definitions of methods of classes as children of a
10759 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
10760 the DIEs giving the declarations, which could be
10761 anywhere). But I don't see any reason why the
10762 standards says that they have to be there. */
10763 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
10765 if (current_low
!= ((CORE_ADDR
) -1))
10767 best_low
= min (best_low
, current_low
);
10768 best_high
= max (best_high
, current_high
);
10776 child
= sibling_die (child
);
10781 *highpc
= best_high
;
10784 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
10788 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
10789 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
10791 struct objfile
*objfile
= cu
->objfile
;
10792 struct attribute
*attr
;
10793 struct attribute
*attr_high
;
10795 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
10798 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10801 CORE_ADDR low
= DW_ADDR (attr
);
10803 if (attr_high
->form
== DW_FORM_addr
10804 || attr_high
->form
== DW_FORM_GNU_addr_index
)
10805 high
= DW_ADDR (attr_high
);
10807 high
= low
+ DW_UNSND (attr_high
);
10809 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
10813 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
10816 bfd
*obfd
= objfile
->obfd
;
10817 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
10818 We take advantage of the fact that DW_AT_ranges does not appear
10819 in DW_TAG_compile_unit of DWO files. */
10820 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
10822 /* The value of the DW_AT_ranges attribute is the offset of the
10823 address range list in the .debug_ranges section. */
10824 unsigned long offset
= (DW_UNSND (attr
)
10825 + (need_ranges_base
? cu
->ranges_base
: 0));
10826 const gdb_byte
*buffer
;
10828 /* For some target architectures, but not others, the
10829 read_address function sign-extends the addresses it returns.
10830 To recognize base address selection entries, we need a
10832 unsigned int addr_size
= cu
->header
.addr_size
;
10833 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
10835 /* The base address, to which the next pair is relative. Note
10836 that this 'base' is a DWARF concept: most entries in a range
10837 list are relative, to reduce the number of relocs against the
10838 debugging information. This is separate from this function's
10839 'baseaddr' argument, which GDB uses to relocate debugging
10840 information from a shared library based on the address at
10841 which the library was loaded. */
10842 CORE_ADDR base
= cu
->base_address
;
10843 int base_known
= cu
->base_known
;
10845 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
10846 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
10848 complaint (&symfile_complaints
,
10849 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
10853 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
10857 unsigned int bytes_read
;
10858 CORE_ADDR start
, end
;
10860 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
10861 buffer
+= bytes_read
;
10862 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
10863 buffer
+= bytes_read
;
10865 /* Did we find the end of the range list? */
10866 if (start
== 0 && end
== 0)
10869 /* Did we find a base address selection entry? */
10870 else if ((start
& base_select_mask
) == base_select_mask
)
10876 /* We found an ordinary address range. */
10881 complaint (&symfile_complaints
,
10882 _("Invalid .debug_ranges data "
10883 "(no base address)"));
10889 /* Inverted range entries are invalid. */
10890 complaint (&symfile_complaints
,
10891 _("Invalid .debug_ranges data "
10892 "(inverted range)"));
10896 /* Empty range entries have no effect. */
10900 start
+= base
+ baseaddr
;
10901 end
+= base
+ baseaddr
;
10903 /* A not-uncommon case of bad debug info.
10904 Don't pollute the addrmap with bad data. */
10905 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10907 complaint (&symfile_complaints
,
10908 _(".debug_ranges entry has start address of zero"
10909 " [in module %s]"), objfile
->name
);
10913 record_block_range (block
, start
, end
- 1);
10919 /* Check whether the producer field indicates either of GCC < 4.6, or the
10920 Intel C/C++ compiler, and cache the result in CU. */
10923 check_producer (struct dwarf2_cu
*cu
)
10926 int major
, minor
, release
;
10928 if (cu
->producer
== NULL
)
10930 /* For unknown compilers expect their behavior is DWARF version
10933 GCC started to support .debug_types sections by -gdwarf-4 since
10934 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
10935 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
10936 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
10937 interpreted incorrectly by GDB now - GCC PR debug/48229. */
10939 else if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) == 0)
10941 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
10943 cs
= &cu
->producer
[strlen ("GNU ")];
10944 while (*cs
&& !isdigit (*cs
))
10946 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
10948 /* Not recognized as GCC. */
10952 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
10953 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
10956 else if (strncmp (cu
->producer
, "Intel(R) C", strlen ("Intel(R) C")) == 0)
10957 cu
->producer_is_icc
= 1;
10960 /* For other non-GCC compilers, expect their behavior is DWARF version
10964 cu
->checked_producer
= 1;
10967 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
10968 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
10969 during 4.6.0 experimental. */
10972 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
10974 if (!cu
->checked_producer
)
10975 check_producer (cu
);
10977 return cu
->producer_is_gxx_lt_4_6
;
10980 /* Return the default accessibility type if it is not overriden by
10981 DW_AT_accessibility. */
10983 static enum dwarf_access_attribute
10984 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
10986 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
10988 /* The default DWARF 2 accessibility for members is public, the default
10989 accessibility for inheritance is private. */
10991 if (die
->tag
!= DW_TAG_inheritance
)
10992 return DW_ACCESS_public
;
10994 return DW_ACCESS_private
;
10998 /* DWARF 3+ defines the default accessibility a different way. The same
10999 rules apply now for DW_TAG_inheritance as for the members and it only
11000 depends on the container kind. */
11002 if (die
->parent
->tag
== DW_TAG_class_type
)
11003 return DW_ACCESS_private
;
11005 return DW_ACCESS_public
;
11009 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
11010 offset. If the attribute was not found return 0, otherwise return
11011 1. If it was found but could not properly be handled, set *OFFSET
11015 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
11018 struct attribute
*attr
;
11020 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
11025 /* Note that we do not check for a section offset first here.
11026 This is because DW_AT_data_member_location is new in DWARF 4,
11027 so if we see it, we can assume that a constant form is really
11028 a constant and not a section offset. */
11029 if (attr_form_is_constant (attr
))
11030 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
11031 else if (attr_form_is_section_offset (attr
))
11032 dwarf2_complex_location_expr_complaint ();
11033 else if (attr_form_is_block (attr
))
11034 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
11036 dwarf2_complex_location_expr_complaint ();
11044 /* Add an aggregate field to the field list. */
11047 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
11048 struct dwarf2_cu
*cu
)
11050 struct objfile
*objfile
= cu
->objfile
;
11051 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11052 struct nextfield
*new_field
;
11053 struct attribute
*attr
;
11055 const char *fieldname
= "";
11057 /* Allocate a new field list entry and link it in. */
11058 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
11059 make_cleanup (xfree
, new_field
);
11060 memset (new_field
, 0, sizeof (struct nextfield
));
11062 if (die
->tag
== DW_TAG_inheritance
)
11064 new_field
->next
= fip
->baseclasses
;
11065 fip
->baseclasses
= new_field
;
11069 new_field
->next
= fip
->fields
;
11070 fip
->fields
= new_field
;
11074 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
11076 new_field
->accessibility
= DW_UNSND (attr
);
11078 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
11079 if (new_field
->accessibility
!= DW_ACCESS_public
)
11080 fip
->non_public_fields
= 1;
11082 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
11084 new_field
->virtuality
= DW_UNSND (attr
);
11086 new_field
->virtuality
= DW_VIRTUALITY_none
;
11088 fp
= &new_field
->field
;
11090 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
11094 /* Data member other than a C++ static data member. */
11096 /* Get type of field. */
11097 fp
->type
= die_type (die
, cu
);
11099 SET_FIELD_BITPOS (*fp
, 0);
11101 /* Get bit size of field (zero if none). */
11102 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
11105 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
11109 FIELD_BITSIZE (*fp
) = 0;
11112 /* Get bit offset of field. */
11113 if (handle_data_member_location (die
, cu
, &offset
))
11114 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
11115 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
11118 if (gdbarch_bits_big_endian (gdbarch
))
11120 /* For big endian bits, the DW_AT_bit_offset gives the
11121 additional bit offset from the MSB of the containing
11122 anonymous object to the MSB of the field. We don't
11123 have to do anything special since we don't need to
11124 know the size of the anonymous object. */
11125 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
11129 /* For little endian bits, compute the bit offset to the
11130 MSB of the anonymous object, subtract off the number of
11131 bits from the MSB of the field to the MSB of the
11132 object, and then subtract off the number of bits of
11133 the field itself. The result is the bit offset of
11134 the LSB of the field. */
11135 int anonymous_size
;
11136 int bit_offset
= DW_UNSND (attr
);
11138 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11141 /* The size of the anonymous object containing
11142 the bit field is explicit, so use the
11143 indicated size (in bytes). */
11144 anonymous_size
= DW_UNSND (attr
);
11148 /* The size of the anonymous object containing
11149 the bit field must be inferred from the type
11150 attribute of the data member containing the
11152 anonymous_size
= TYPE_LENGTH (fp
->type
);
11154 SET_FIELD_BITPOS (*fp
,
11155 (FIELD_BITPOS (*fp
)
11156 + anonymous_size
* bits_per_byte
11157 - bit_offset
- FIELD_BITSIZE (*fp
)));
11161 /* Get name of field. */
11162 fieldname
= dwarf2_name (die
, cu
);
11163 if (fieldname
== NULL
)
11166 /* The name is already allocated along with this objfile, so we don't
11167 need to duplicate it for the type. */
11168 fp
->name
= fieldname
;
11170 /* Change accessibility for artificial fields (e.g. virtual table
11171 pointer or virtual base class pointer) to private. */
11172 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
11174 FIELD_ARTIFICIAL (*fp
) = 1;
11175 new_field
->accessibility
= DW_ACCESS_private
;
11176 fip
->non_public_fields
= 1;
11179 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
11181 /* C++ static member. */
11183 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
11184 is a declaration, but all versions of G++ as of this writing
11185 (so through at least 3.2.1) incorrectly generate
11186 DW_TAG_variable tags. */
11188 const char *physname
;
11190 /* Get name of field. */
11191 fieldname
= dwarf2_name (die
, cu
);
11192 if (fieldname
== NULL
)
11195 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11197 /* Only create a symbol if this is an external value.
11198 new_symbol checks this and puts the value in the global symbol
11199 table, which we want. If it is not external, new_symbol
11200 will try to put the value in cu->list_in_scope which is wrong. */
11201 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
11203 /* A static const member, not much different than an enum as far as
11204 we're concerned, except that we can support more types. */
11205 new_symbol (die
, NULL
, cu
);
11208 /* Get physical name. */
11209 physname
= dwarf2_physname (fieldname
, die
, cu
);
11211 /* The name is already allocated along with this objfile, so we don't
11212 need to duplicate it for the type. */
11213 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
11214 FIELD_TYPE (*fp
) = die_type (die
, cu
);
11215 FIELD_NAME (*fp
) = fieldname
;
11217 else if (die
->tag
== DW_TAG_inheritance
)
11221 /* C++ base class field. */
11222 if (handle_data_member_location (die
, cu
, &offset
))
11223 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
11224 FIELD_BITSIZE (*fp
) = 0;
11225 FIELD_TYPE (*fp
) = die_type (die
, cu
);
11226 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
11227 fip
->nbaseclasses
++;
11231 /* Add a typedef defined in the scope of the FIP's class. */
11234 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
11235 struct dwarf2_cu
*cu
)
11237 struct objfile
*objfile
= cu
->objfile
;
11238 struct typedef_field_list
*new_field
;
11239 struct attribute
*attr
;
11240 struct typedef_field
*fp
;
11241 char *fieldname
= "";
11243 /* Allocate a new field list entry and link it in. */
11244 new_field
= xzalloc (sizeof (*new_field
));
11245 make_cleanup (xfree
, new_field
);
11247 gdb_assert (die
->tag
== DW_TAG_typedef
);
11249 fp
= &new_field
->field
;
11251 /* Get name of field. */
11252 fp
->name
= dwarf2_name (die
, cu
);
11253 if (fp
->name
== NULL
)
11256 fp
->type
= read_type_die (die
, cu
);
11258 new_field
->next
= fip
->typedef_field_list
;
11259 fip
->typedef_field_list
= new_field
;
11260 fip
->typedef_field_list_count
++;
11263 /* Create the vector of fields, and attach it to the type. */
11266 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
11267 struct dwarf2_cu
*cu
)
11269 int nfields
= fip
->nfields
;
11271 /* Record the field count, allocate space for the array of fields,
11272 and create blank accessibility bitfields if necessary. */
11273 TYPE_NFIELDS (type
) = nfields
;
11274 TYPE_FIELDS (type
) = (struct field
*)
11275 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
11276 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
11278 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
11280 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11282 TYPE_FIELD_PRIVATE_BITS (type
) =
11283 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
11284 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
11286 TYPE_FIELD_PROTECTED_BITS (type
) =
11287 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
11288 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
11290 TYPE_FIELD_IGNORE_BITS (type
) =
11291 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
11292 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
11295 /* If the type has baseclasses, allocate and clear a bit vector for
11296 TYPE_FIELD_VIRTUAL_BITS. */
11297 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
11299 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
11300 unsigned char *pointer
;
11302 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11303 pointer
= TYPE_ALLOC (type
, num_bytes
);
11304 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
11305 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
11306 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
11309 /* Copy the saved-up fields into the field vector. Start from the head of
11310 the list, adding to the tail of the field array, so that they end up in
11311 the same order in the array in which they were added to the list. */
11312 while (nfields
-- > 0)
11314 struct nextfield
*fieldp
;
11318 fieldp
= fip
->fields
;
11319 fip
->fields
= fieldp
->next
;
11323 fieldp
= fip
->baseclasses
;
11324 fip
->baseclasses
= fieldp
->next
;
11327 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
11328 switch (fieldp
->accessibility
)
11330 case DW_ACCESS_private
:
11331 if (cu
->language
!= language_ada
)
11332 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
11335 case DW_ACCESS_protected
:
11336 if (cu
->language
!= language_ada
)
11337 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
11340 case DW_ACCESS_public
:
11344 /* Unknown accessibility. Complain and treat it as public. */
11346 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
11347 fieldp
->accessibility
);
11351 if (nfields
< fip
->nbaseclasses
)
11353 switch (fieldp
->virtuality
)
11355 case DW_VIRTUALITY_virtual
:
11356 case DW_VIRTUALITY_pure_virtual
:
11357 if (cu
->language
== language_ada
)
11358 error (_("unexpected virtuality in component of Ada type"));
11359 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
11366 /* Return true if this member function is a constructor, false
11370 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
11372 const char *fieldname
;
11373 const char *typename
;
11376 if (die
->parent
== NULL
)
11379 if (die
->parent
->tag
!= DW_TAG_structure_type
11380 && die
->parent
->tag
!= DW_TAG_union_type
11381 && die
->parent
->tag
!= DW_TAG_class_type
)
11384 fieldname
= dwarf2_name (die
, cu
);
11385 typename
= dwarf2_name (die
->parent
, cu
);
11386 if (fieldname
== NULL
|| typename
== NULL
)
11389 len
= strlen (fieldname
);
11390 return (strncmp (fieldname
, typename
, len
) == 0
11391 && (typename
[len
] == '\0' || typename
[len
] == '<'));
11394 /* Add a member function to the proper fieldlist. */
11397 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
11398 struct type
*type
, struct dwarf2_cu
*cu
)
11400 struct objfile
*objfile
= cu
->objfile
;
11401 struct attribute
*attr
;
11402 struct fnfieldlist
*flp
;
11404 struct fn_field
*fnp
;
11405 const char *fieldname
;
11406 struct nextfnfield
*new_fnfield
;
11407 struct type
*this_type
;
11408 enum dwarf_access_attribute accessibility
;
11410 if (cu
->language
== language_ada
)
11411 error (_("unexpected member function in Ada type"));
11413 /* Get name of member function. */
11414 fieldname
= dwarf2_name (die
, cu
);
11415 if (fieldname
== NULL
)
11418 /* Look up member function name in fieldlist. */
11419 for (i
= 0; i
< fip
->nfnfields
; i
++)
11421 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
11425 /* Create new list element if necessary. */
11426 if (i
< fip
->nfnfields
)
11427 flp
= &fip
->fnfieldlists
[i
];
11430 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
11432 fip
->fnfieldlists
= (struct fnfieldlist
*)
11433 xrealloc (fip
->fnfieldlists
,
11434 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
11435 * sizeof (struct fnfieldlist
));
11436 if (fip
->nfnfields
== 0)
11437 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
11439 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
11440 flp
->name
= fieldname
;
11443 i
= fip
->nfnfields
++;
11446 /* Create a new member function field and chain it to the field list
11448 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
11449 make_cleanup (xfree
, new_fnfield
);
11450 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
11451 new_fnfield
->next
= flp
->head
;
11452 flp
->head
= new_fnfield
;
11455 /* Fill in the member function field info. */
11456 fnp
= &new_fnfield
->fnfield
;
11458 /* Delay processing of the physname until later. */
11459 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
11461 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
11466 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
11467 fnp
->physname
= physname
? physname
: "";
11470 fnp
->type
= alloc_type (objfile
);
11471 this_type
= read_type_die (die
, cu
);
11472 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
11474 int nparams
= TYPE_NFIELDS (this_type
);
11476 /* TYPE is the domain of this method, and THIS_TYPE is the type
11477 of the method itself (TYPE_CODE_METHOD). */
11478 smash_to_method_type (fnp
->type
, type
,
11479 TYPE_TARGET_TYPE (this_type
),
11480 TYPE_FIELDS (this_type
),
11481 TYPE_NFIELDS (this_type
),
11482 TYPE_VARARGS (this_type
));
11484 /* Handle static member functions.
11485 Dwarf2 has no clean way to discern C++ static and non-static
11486 member functions. G++ helps GDB by marking the first
11487 parameter for non-static member functions (which is the this
11488 pointer) as artificial. We obtain this information from
11489 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
11490 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
11491 fnp
->voffset
= VOFFSET_STATIC
;
11494 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
11495 dwarf2_full_name (fieldname
, die
, cu
));
11497 /* Get fcontext from DW_AT_containing_type if present. */
11498 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
11499 fnp
->fcontext
= die_containing_type (die
, cu
);
11501 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
11502 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
11504 /* Get accessibility. */
11505 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
11507 accessibility
= DW_UNSND (attr
);
11509 accessibility
= dwarf2_default_access_attribute (die
, cu
);
11510 switch (accessibility
)
11512 case DW_ACCESS_private
:
11513 fnp
->is_private
= 1;
11515 case DW_ACCESS_protected
:
11516 fnp
->is_protected
= 1;
11520 /* Check for artificial methods. */
11521 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
11522 if (attr
&& DW_UNSND (attr
) != 0)
11523 fnp
->is_artificial
= 1;
11525 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
11527 /* Get index in virtual function table if it is a virtual member
11528 function. For older versions of GCC, this is an offset in the
11529 appropriate virtual table, as specified by DW_AT_containing_type.
11530 For everyone else, it is an expression to be evaluated relative
11531 to the object address. */
11533 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
11536 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
11538 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
11540 /* Old-style GCC. */
11541 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
11543 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
11544 || (DW_BLOCK (attr
)->size
> 1
11545 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
11546 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
11548 struct dwarf_block blk
;
11551 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
11553 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
11554 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
11555 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
11556 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
11557 dwarf2_complex_location_expr_complaint ();
11559 fnp
->voffset
/= cu
->header
.addr_size
;
11563 dwarf2_complex_location_expr_complaint ();
11565 if (!fnp
->fcontext
)
11566 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
11568 else if (attr_form_is_section_offset (attr
))
11570 dwarf2_complex_location_expr_complaint ();
11574 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
11580 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
11581 if (attr
&& DW_UNSND (attr
))
11583 /* GCC does this, as of 2008-08-25; PR debug/37237. */
11584 complaint (&symfile_complaints
,
11585 _("Member function \"%s\" (offset %d) is virtual "
11586 "but the vtable offset is not specified"),
11587 fieldname
, die
->offset
.sect_off
);
11588 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11589 TYPE_CPLUS_DYNAMIC (type
) = 1;
11594 /* Create the vector of member function fields, and attach it to the type. */
11597 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
11598 struct dwarf2_cu
*cu
)
11600 struct fnfieldlist
*flp
;
11603 if (cu
->language
== language_ada
)
11604 error (_("unexpected member functions in Ada type"));
11606 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11607 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
11608 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
11610 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
11612 struct nextfnfield
*nfp
= flp
->head
;
11613 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
11616 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
11617 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
11618 fn_flp
->fn_fields
= (struct fn_field
*)
11619 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
11620 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
11621 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
11624 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
11627 /* Returns non-zero if NAME is the name of a vtable member in CU's
11628 language, zero otherwise. */
11630 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
11632 static const char vptr
[] = "_vptr";
11633 static const char vtable
[] = "vtable";
11635 /* Look for the C++ and Java forms of the vtable. */
11636 if ((cu
->language
== language_java
11637 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
11638 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
11639 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
11645 /* GCC outputs unnamed structures that are really pointers to member
11646 functions, with the ABI-specified layout. If TYPE describes
11647 such a structure, smash it into a member function type.
11649 GCC shouldn't do this; it should just output pointer to member DIEs.
11650 This is GCC PR debug/28767. */
11653 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
11655 struct type
*pfn_type
, *domain_type
, *new_type
;
11657 /* Check for a structure with no name and two children. */
11658 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
11661 /* Check for __pfn and __delta members. */
11662 if (TYPE_FIELD_NAME (type
, 0) == NULL
11663 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
11664 || TYPE_FIELD_NAME (type
, 1) == NULL
11665 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
11668 /* Find the type of the method. */
11669 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
11670 if (pfn_type
== NULL
11671 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
11672 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
11675 /* Look for the "this" argument. */
11676 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
11677 if (TYPE_NFIELDS (pfn_type
) == 0
11678 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
11679 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
11682 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
11683 new_type
= alloc_type (objfile
);
11684 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
11685 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
11686 TYPE_VARARGS (pfn_type
));
11687 smash_to_methodptr_type (type
, new_type
);
11690 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
11694 producer_is_icc (struct dwarf2_cu
*cu
)
11696 if (!cu
->checked_producer
)
11697 check_producer (cu
);
11699 return cu
->producer_is_icc
;
11702 /* Called when we find the DIE that starts a structure or union scope
11703 (definition) to create a type for the structure or union. Fill in
11704 the type's name and general properties; the members will not be
11705 processed until process_structure_scope.
11707 NOTE: we need to call these functions regardless of whether or not the
11708 DIE has a DW_AT_name attribute, since it might be an anonymous
11709 structure or union. This gets the type entered into our set of
11710 user defined types.
11712 However, if the structure is incomplete (an opaque struct/union)
11713 then suppress creating a symbol table entry for it since gdb only
11714 wants to find the one with the complete definition. Note that if
11715 it is complete, we just call new_symbol, which does it's own
11716 checking about whether the struct/union is anonymous or not (and
11717 suppresses creating a symbol table entry itself). */
11719 static struct type
*
11720 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11722 struct objfile
*objfile
= cu
->objfile
;
11724 struct attribute
*attr
;
11727 /* If the definition of this type lives in .debug_types, read that type.
11728 Don't follow DW_AT_specification though, that will take us back up
11729 the chain and we want to go down. */
11730 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
11733 type
= get_DW_AT_signature_type (die
, attr
, cu
);
11735 /* The type's CU may not be the same as CU.
11736 Ensure TYPE is recorded with CU in die_type_hash. */
11737 return set_die_type (die
, type
, cu
);
11740 type
= alloc_type (objfile
);
11741 INIT_CPLUS_SPECIFIC (type
);
11743 name
= dwarf2_name (die
, cu
);
11746 if (cu
->language
== language_cplus
11747 || cu
->language
== language_java
)
11749 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
11751 /* dwarf2_full_name might have already finished building the DIE's
11752 type. If so, there is no need to continue. */
11753 if (get_die_type (die
, cu
) != NULL
)
11754 return get_die_type (die
, cu
);
11756 TYPE_TAG_NAME (type
) = full_name
;
11757 if (die
->tag
== DW_TAG_structure_type
11758 || die
->tag
== DW_TAG_class_type
)
11759 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
11763 /* The name is already allocated along with this objfile, so
11764 we don't need to duplicate it for the type. */
11765 TYPE_TAG_NAME (type
) = name
;
11766 if (die
->tag
== DW_TAG_class_type
)
11767 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
11771 if (die
->tag
== DW_TAG_structure_type
)
11773 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
11775 else if (die
->tag
== DW_TAG_union_type
)
11777 TYPE_CODE (type
) = TYPE_CODE_UNION
;
11781 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
11784 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
11785 TYPE_DECLARED_CLASS (type
) = 1;
11787 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11790 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11794 TYPE_LENGTH (type
) = 0;
11797 if (producer_is_icc (cu
))
11799 /* ICC does not output the required DW_AT_declaration
11800 on incomplete types, but gives them a size of zero. */
11803 TYPE_STUB_SUPPORTED (type
) = 1;
11805 if (die_is_declaration (die
, cu
))
11806 TYPE_STUB (type
) = 1;
11807 else if (attr
== NULL
&& die
->child
== NULL
11808 && producer_is_realview (cu
->producer
))
11809 /* RealView does not output the required DW_AT_declaration
11810 on incomplete types. */
11811 TYPE_STUB (type
) = 1;
11813 /* We need to add the type field to the die immediately so we don't
11814 infinitely recurse when dealing with pointers to the structure
11815 type within the structure itself. */
11816 set_die_type (die
, type
, cu
);
11818 /* set_die_type should be already done. */
11819 set_descriptive_type (type
, die
, cu
);
11824 /* Finish creating a structure or union type, including filling in
11825 its members and creating a symbol for it. */
11828 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11830 struct objfile
*objfile
= cu
->objfile
;
11831 struct die_info
*child_die
= die
->child
;
11834 type
= get_die_type (die
, cu
);
11836 type
= read_structure_type (die
, cu
);
11838 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
11840 struct field_info fi
;
11841 struct die_info
*child_die
;
11842 VEC (symbolp
) *template_args
= NULL
;
11843 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
11845 memset (&fi
, 0, sizeof (struct field_info
));
11847 child_die
= die
->child
;
11849 while (child_die
&& child_die
->tag
)
11851 if (child_die
->tag
== DW_TAG_member
11852 || child_die
->tag
== DW_TAG_variable
)
11854 /* NOTE: carlton/2002-11-05: A C++ static data member
11855 should be a DW_TAG_member that is a declaration, but
11856 all versions of G++ as of this writing (so through at
11857 least 3.2.1) incorrectly generate DW_TAG_variable
11858 tags for them instead. */
11859 dwarf2_add_field (&fi
, child_die
, cu
);
11861 else if (child_die
->tag
== DW_TAG_subprogram
)
11863 /* C++ member function. */
11864 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
11866 else if (child_die
->tag
== DW_TAG_inheritance
)
11868 /* C++ base class field. */
11869 dwarf2_add_field (&fi
, child_die
, cu
);
11871 else if (child_die
->tag
== DW_TAG_typedef
)
11872 dwarf2_add_typedef (&fi
, child_die
, cu
);
11873 else if (child_die
->tag
== DW_TAG_template_type_param
11874 || child_die
->tag
== DW_TAG_template_value_param
)
11876 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
11879 VEC_safe_push (symbolp
, template_args
, arg
);
11882 child_die
= sibling_die (child_die
);
11885 /* Attach template arguments to type. */
11886 if (! VEC_empty (symbolp
, template_args
))
11888 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11889 TYPE_N_TEMPLATE_ARGUMENTS (type
)
11890 = VEC_length (symbolp
, template_args
);
11891 TYPE_TEMPLATE_ARGUMENTS (type
)
11892 = obstack_alloc (&objfile
->objfile_obstack
,
11893 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
11894 * sizeof (struct symbol
*)));
11895 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
11896 VEC_address (symbolp
, template_args
),
11897 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
11898 * sizeof (struct symbol
*)));
11899 VEC_free (symbolp
, template_args
);
11902 /* Attach fields and member functions to the type. */
11904 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
11907 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
11909 /* Get the type which refers to the base class (possibly this
11910 class itself) which contains the vtable pointer for the current
11911 class from the DW_AT_containing_type attribute. This use of
11912 DW_AT_containing_type is a GNU extension. */
11914 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
11916 struct type
*t
= die_containing_type (die
, cu
);
11918 TYPE_VPTR_BASETYPE (type
) = t
;
11923 /* Our own class provides vtbl ptr. */
11924 for (i
= TYPE_NFIELDS (t
) - 1;
11925 i
>= TYPE_N_BASECLASSES (t
);
11928 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
11930 if (is_vtable_name (fieldname
, cu
))
11932 TYPE_VPTR_FIELDNO (type
) = i
;
11937 /* Complain if virtual function table field not found. */
11938 if (i
< TYPE_N_BASECLASSES (t
))
11939 complaint (&symfile_complaints
,
11940 _("virtual function table pointer "
11941 "not found when defining class '%s'"),
11942 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
11947 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
11950 else if (cu
->producer
11951 && strncmp (cu
->producer
,
11952 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
11954 /* The IBM XLC compiler does not provide direct indication
11955 of the containing type, but the vtable pointer is
11956 always named __vfp. */
11960 for (i
= TYPE_NFIELDS (type
) - 1;
11961 i
>= TYPE_N_BASECLASSES (type
);
11964 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
11966 TYPE_VPTR_FIELDNO (type
) = i
;
11967 TYPE_VPTR_BASETYPE (type
) = type
;
11974 /* Copy fi.typedef_field_list linked list elements content into the
11975 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
11976 if (fi
.typedef_field_list
)
11978 int i
= fi
.typedef_field_list_count
;
11980 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11981 TYPE_TYPEDEF_FIELD_ARRAY (type
)
11982 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
11983 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
11985 /* Reverse the list order to keep the debug info elements order. */
11988 struct typedef_field
*dest
, *src
;
11990 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
11991 src
= &fi
.typedef_field_list
->field
;
11992 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
11997 do_cleanups (back_to
);
11999 if (HAVE_CPLUS_STRUCT (type
))
12000 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
12003 quirk_gcc_member_function_pointer (type
, objfile
);
12005 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
12006 snapshots) has been known to create a die giving a declaration
12007 for a class that has, as a child, a die giving a definition for a
12008 nested class. So we have to process our children even if the
12009 current die is a declaration. Normally, of course, a declaration
12010 won't have any children at all. */
12012 while (child_die
!= NULL
&& child_die
->tag
)
12014 if (child_die
->tag
== DW_TAG_member
12015 || child_die
->tag
== DW_TAG_variable
12016 || child_die
->tag
== DW_TAG_inheritance
12017 || child_die
->tag
== DW_TAG_template_value_param
12018 || child_die
->tag
== DW_TAG_template_type_param
)
12023 process_die (child_die
, cu
);
12025 child_die
= sibling_die (child_die
);
12028 /* Do not consider external references. According to the DWARF standard,
12029 these DIEs are identified by the fact that they have no byte_size
12030 attribute, and a declaration attribute. */
12031 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
12032 || !die_is_declaration (die
, cu
))
12033 new_symbol (die
, type
, cu
);
12036 /* Given a DW_AT_enumeration_type die, set its type. We do not
12037 complete the type's fields yet, or create any symbols. */
12039 static struct type
*
12040 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12042 struct objfile
*objfile
= cu
->objfile
;
12044 struct attribute
*attr
;
12047 /* If the definition of this type lives in .debug_types, read that type.
12048 Don't follow DW_AT_specification though, that will take us back up
12049 the chain and we want to go down. */
12050 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
12053 type
= get_DW_AT_signature_type (die
, attr
, cu
);
12055 /* The type's CU may not be the same as CU.
12056 Ensure TYPE is recorded with CU in die_type_hash. */
12057 return set_die_type (die
, type
, cu
);
12060 type
= alloc_type (objfile
);
12062 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
12063 name
= dwarf2_full_name (NULL
, die
, cu
);
12065 TYPE_TAG_NAME (type
) = name
;
12067 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12070 TYPE_LENGTH (type
) = DW_UNSND (attr
);
12074 TYPE_LENGTH (type
) = 0;
12077 /* The enumeration DIE can be incomplete. In Ada, any type can be
12078 declared as private in the package spec, and then defined only
12079 inside the package body. Such types are known as Taft Amendment
12080 Types. When another package uses such a type, an incomplete DIE
12081 may be generated by the compiler. */
12082 if (die_is_declaration (die
, cu
))
12083 TYPE_STUB (type
) = 1;
12085 return set_die_type (die
, type
, cu
);
12088 /* Given a pointer to a die which begins an enumeration, process all
12089 the dies that define the members of the enumeration, and create the
12090 symbol for the enumeration type.
12092 NOTE: We reverse the order of the element list. */
12095 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12097 struct type
*this_type
;
12099 this_type
= get_die_type (die
, cu
);
12100 if (this_type
== NULL
)
12101 this_type
= read_enumeration_type (die
, cu
);
12103 if (die
->child
!= NULL
)
12105 struct die_info
*child_die
;
12106 struct symbol
*sym
;
12107 struct field
*fields
= NULL
;
12108 int num_fields
= 0;
12109 int unsigned_enum
= 1;
12114 child_die
= die
->child
;
12115 while (child_die
&& child_die
->tag
)
12117 if (child_die
->tag
!= DW_TAG_enumerator
)
12119 process_die (child_die
, cu
);
12123 name
= dwarf2_name (child_die
, cu
);
12126 sym
= new_symbol (child_die
, this_type
, cu
);
12127 if (SYMBOL_VALUE (sym
) < 0)
12132 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
12135 mask
|= SYMBOL_VALUE (sym
);
12137 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
12139 fields
= (struct field
*)
12141 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
12142 * sizeof (struct field
));
12145 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
12146 FIELD_TYPE (fields
[num_fields
]) = NULL
;
12147 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
12148 FIELD_BITSIZE (fields
[num_fields
]) = 0;
12154 child_die
= sibling_die (child_die
);
12159 TYPE_NFIELDS (this_type
) = num_fields
;
12160 TYPE_FIELDS (this_type
) = (struct field
*)
12161 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
12162 memcpy (TYPE_FIELDS (this_type
), fields
,
12163 sizeof (struct field
) * num_fields
);
12167 TYPE_UNSIGNED (this_type
) = 1;
12169 TYPE_FLAG_ENUM (this_type
) = 1;
12172 /* If we are reading an enum from a .debug_types unit, and the enum
12173 is a declaration, and the enum is not the signatured type in the
12174 unit, then we do not want to add a symbol for it. Adding a
12175 symbol would in some cases obscure the true definition of the
12176 enum, giving users an incomplete type when the definition is
12177 actually available. Note that we do not want to do this for all
12178 enums which are just declarations, because C++0x allows forward
12179 enum declarations. */
12180 if (cu
->per_cu
->is_debug_types
12181 && die_is_declaration (die
, cu
))
12183 struct signatured_type
*sig_type
;
12185 sig_type
= (struct signatured_type
*) cu
->per_cu
;
12186 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
12187 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
12191 new_symbol (die
, this_type
, cu
);
12194 /* Extract all information from a DW_TAG_array_type DIE and put it in
12195 the DIE's type field. For now, this only handles one dimensional
12198 static struct type
*
12199 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12201 struct objfile
*objfile
= cu
->objfile
;
12202 struct die_info
*child_die
;
12204 struct type
*element_type
, *range_type
, *index_type
;
12205 struct type
**range_types
= NULL
;
12206 struct attribute
*attr
;
12208 struct cleanup
*back_to
;
12211 element_type
= die_type (die
, cu
);
12213 /* The die_type call above may have already set the type for this DIE. */
12214 type
= get_die_type (die
, cu
);
12218 /* Irix 6.2 native cc creates array types without children for
12219 arrays with unspecified length. */
12220 if (die
->child
== NULL
)
12222 index_type
= objfile_type (objfile
)->builtin_int
;
12223 range_type
= create_range_type (NULL
, index_type
, 0, -1);
12224 type
= create_array_type (NULL
, element_type
, range_type
);
12225 return set_die_type (die
, type
, cu
);
12228 back_to
= make_cleanup (null_cleanup
, NULL
);
12229 child_die
= die
->child
;
12230 while (child_die
&& child_die
->tag
)
12232 if (child_die
->tag
== DW_TAG_subrange_type
)
12234 struct type
*child_type
= read_type_die (child_die
, cu
);
12236 if (child_type
!= NULL
)
12238 /* The range type was succesfully read. Save it for the
12239 array type creation. */
12240 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
12242 range_types
= (struct type
**)
12243 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
12244 * sizeof (struct type
*));
12246 make_cleanup (free_current_contents
, &range_types
);
12248 range_types
[ndim
++] = child_type
;
12251 child_die
= sibling_die (child_die
);
12254 /* Dwarf2 dimensions are output from left to right, create the
12255 necessary array types in backwards order. */
12257 type
= element_type
;
12259 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
12264 type
= create_array_type (NULL
, type
, range_types
[i
++]);
12269 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
12272 /* Understand Dwarf2 support for vector types (like they occur on
12273 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
12274 array type. This is not part of the Dwarf2/3 standard yet, but a
12275 custom vendor extension. The main difference between a regular
12276 array and the vector variant is that vectors are passed by value
12278 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
12280 make_vector_type (type
);
12282 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
12283 implementation may choose to implement triple vectors using this
12285 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12288 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
12289 TYPE_LENGTH (type
) = DW_UNSND (attr
);
12291 complaint (&symfile_complaints
,
12292 _("DW_AT_byte_size for array type smaller "
12293 "than the total size of elements"));
12296 name
= dwarf2_name (die
, cu
);
12298 TYPE_NAME (type
) = name
;
12300 /* Install the type in the die. */
12301 set_die_type (die
, type
, cu
);
12303 /* set_die_type should be already done. */
12304 set_descriptive_type (type
, die
, cu
);
12306 do_cleanups (back_to
);
12311 static enum dwarf_array_dim_ordering
12312 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
12314 struct attribute
*attr
;
12316 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
12318 if (attr
) return DW_SND (attr
);
12320 /* GNU F77 is a special case, as at 08/2004 array type info is the
12321 opposite order to the dwarf2 specification, but data is still
12322 laid out as per normal fortran.
12324 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
12325 version checking. */
12327 if (cu
->language
== language_fortran
12328 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
12330 return DW_ORD_row_major
;
12333 switch (cu
->language_defn
->la_array_ordering
)
12335 case array_column_major
:
12336 return DW_ORD_col_major
;
12337 case array_row_major
:
12339 return DW_ORD_row_major
;
12343 /* Extract all information from a DW_TAG_set_type DIE and put it in
12344 the DIE's type field. */
12346 static struct type
*
12347 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12349 struct type
*domain_type
, *set_type
;
12350 struct attribute
*attr
;
12352 domain_type
= die_type (die
, cu
);
12354 /* The die_type call above may have already set the type for this DIE. */
12355 set_type
= get_die_type (die
, cu
);
12359 set_type
= create_set_type (NULL
, domain_type
);
12361 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12363 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
12365 return set_die_type (die
, set_type
, cu
);
12368 /* A helper for read_common_block that creates a locexpr baton.
12369 SYM is the symbol which we are marking as computed.
12370 COMMON_DIE is the DIE for the common block.
12371 COMMON_LOC is the location expression attribute for the common
12373 MEMBER_LOC is the location expression attribute for the particular
12374 member of the common block that we are processing.
12375 CU is the CU from which the above come. */
12378 mark_common_block_symbol_computed (struct symbol
*sym
,
12379 struct die_info
*common_die
,
12380 struct attribute
*common_loc
,
12381 struct attribute
*member_loc
,
12382 struct dwarf2_cu
*cu
)
12384 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12385 struct dwarf2_locexpr_baton
*baton
;
12387 unsigned int cu_off
;
12388 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
12389 LONGEST offset
= 0;
12391 gdb_assert (common_loc
&& member_loc
);
12392 gdb_assert (attr_form_is_block (common_loc
));
12393 gdb_assert (attr_form_is_block (member_loc
)
12394 || attr_form_is_constant (member_loc
));
12396 baton
= obstack_alloc (&objfile
->objfile_obstack
,
12397 sizeof (struct dwarf2_locexpr_baton
));
12398 baton
->per_cu
= cu
->per_cu
;
12399 gdb_assert (baton
->per_cu
);
12401 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
12403 if (attr_form_is_constant (member_loc
))
12405 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
12406 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
12409 baton
->size
+= DW_BLOCK (member_loc
)->size
;
12411 ptr
= obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
12414 *ptr
++ = DW_OP_call4
;
12415 cu_off
= common_die
->offset
.sect_off
- cu
->per_cu
->offset
.sect_off
;
12416 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
12419 if (attr_form_is_constant (member_loc
))
12421 *ptr
++ = DW_OP_addr
;
12422 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
12423 ptr
+= cu
->header
.addr_size
;
12427 /* We have to copy the data here, because DW_OP_call4 will only
12428 use a DW_AT_location attribute. */
12429 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
12430 ptr
+= DW_BLOCK (member_loc
)->size
;
12433 *ptr
++ = DW_OP_plus
;
12434 gdb_assert (ptr
- baton
->data
== baton
->size
);
12436 SYMBOL_LOCATION_BATON (sym
) = baton
;
12437 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
12440 /* Create appropriate locally-scoped variables for all the
12441 DW_TAG_common_block entries. Also create a struct common_block
12442 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
12443 is used to sepate the common blocks name namespace from regular
12447 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
12449 struct attribute
*attr
;
12451 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
12454 /* Support the .debug_loc offsets. */
12455 if (attr_form_is_block (attr
))
12459 else if (attr_form_is_section_offset (attr
))
12461 dwarf2_complex_location_expr_complaint ();
12466 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
12467 "common block member");
12472 if (die
->child
!= NULL
)
12474 struct objfile
*objfile
= cu
->objfile
;
12475 struct die_info
*child_die
;
12476 size_t n_entries
= 0, size
;
12477 struct common_block
*common_block
;
12478 struct symbol
*sym
;
12480 for (child_die
= die
->child
;
12481 child_die
&& child_die
->tag
;
12482 child_die
= sibling_die (child_die
))
12485 size
= (sizeof (struct common_block
)
12486 + (n_entries
- 1) * sizeof (struct symbol
*));
12487 common_block
= obstack_alloc (&objfile
->objfile_obstack
, size
);
12488 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
12489 common_block
->n_entries
= 0;
12491 for (child_die
= die
->child
;
12492 child_die
&& child_die
->tag
;
12493 child_die
= sibling_die (child_die
))
12495 /* Create the symbol in the DW_TAG_common_block block in the current
12497 sym
= new_symbol (child_die
, NULL
, cu
);
12500 struct attribute
*member_loc
;
12502 common_block
->contents
[common_block
->n_entries
++] = sym
;
12504 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
12508 /* GDB has handled this for a long time, but it is
12509 not specified by DWARF. It seems to have been
12510 emitted by gfortran at least as recently as:
12511 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
12512 complaint (&symfile_complaints
,
12513 _("Variable in common block has "
12514 "DW_AT_data_member_location "
12515 "- DIE at 0x%x [in module %s]"),
12516 child_die
->offset
.sect_off
, cu
->objfile
->name
);
12518 if (attr_form_is_section_offset (member_loc
))
12519 dwarf2_complex_location_expr_complaint ();
12520 else if (attr_form_is_constant (member_loc
)
12521 || attr_form_is_block (member_loc
))
12524 mark_common_block_symbol_computed (sym
, die
, attr
,
12528 dwarf2_complex_location_expr_complaint ();
12533 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
12534 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
12538 /* Create a type for a C++ namespace. */
12540 static struct type
*
12541 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12543 struct objfile
*objfile
= cu
->objfile
;
12544 const char *previous_prefix
, *name
;
12548 /* For extensions, reuse the type of the original namespace. */
12549 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
12551 struct die_info
*ext_die
;
12552 struct dwarf2_cu
*ext_cu
= cu
;
12554 ext_die
= dwarf2_extension (die
, &ext_cu
);
12555 type
= read_type_die (ext_die
, ext_cu
);
12557 /* EXT_CU may not be the same as CU.
12558 Ensure TYPE is recorded with CU in die_type_hash. */
12559 return set_die_type (die
, type
, cu
);
12562 name
= namespace_name (die
, &is_anonymous
, cu
);
12564 /* Now build the name of the current namespace. */
12566 previous_prefix
= determine_prefix (die
, cu
);
12567 if (previous_prefix
[0] != '\0')
12568 name
= typename_concat (&objfile
->objfile_obstack
,
12569 previous_prefix
, name
, 0, cu
);
12571 /* Create the type. */
12572 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
12574 TYPE_NAME (type
) = name
;
12575 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
12577 return set_die_type (die
, type
, cu
);
12580 /* Read a C++ namespace. */
12583 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
12585 struct objfile
*objfile
= cu
->objfile
;
12588 /* Add a symbol associated to this if we haven't seen the namespace
12589 before. Also, add a using directive if it's an anonymous
12592 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
12596 type
= read_type_die (die
, cu
);
12597 new_symbol (die
, type
, cu
);
12599 namespace_name (die
, &is_anonymous
, cu
);
12602 const char *previous_prefix
= determine_prefix (die
, cu
);
12604 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
12605 NULL
, NULL
, 0, &objfile
->objfile_obstack
);
12609 if (die
->child
!= NULL
)
12611 struct die_info
*child_die
= die
->child
;
12613 while (child_die
&& child_die
->tag
)
12615 process_die (child_die
, cu
);
12616 child_die
= sibling_die (child_die
);
12621 /* Read a Fortran module as type. This DIE can be only a declaration used for
12622 imported module. Still we need that type as local Fortran "use ... only"
12623 declaration imports depend on the created type in determine_prefix. */
12625 static struct type
*
12626 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12628 struct objfile
*objfile
= cu
->objfile
;
12629 const char *module_name
;
12632 module_name
= dwarf2_name (die
, cu
);
12634 complaint (&symfile_complaints
,
12635 _("DW_TAG_module has no name, offset 0x%x"),
12636 die
->offset
.sect_off
);
12637 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
12639 /* determine_prefix uses TYPE_TAG_NAME. */
12640 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
12642 return set_die_type (die
, type
, cu
);
12645 /* Read a Fortran module. */
12648 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
12650 struct die_info
*child_die
= die
->child
;
12652 while (child_die
&& child_die
->tag
)
12654 process_die (child_die
, cu
);
12655 child_die
= sibling_die (child_die
);
12659 /* Return the name of the namespace represented by DIE. Set
12660 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
12663 static const char *
12664 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
12666 struct die_info
*current_die
;
12667 const char *name
= NULL
;
12669 /* Loop through the extensions until we find a name. */
12671 for (current_die
= die
;
12672 current_die
!= NULL
;
12673 current_die
= dwarf2_extension (die
, &cu
))
12675 name
= dwarf2_name (current_die
, cu
);
12680 /* Is it an anonymous namespace? */
12682 *is_anonymous
= (name
== NULL
);
12684 name
= CP_ANONYMOUS_NAMESPACE_STR
;
12689 /* Extract all information from a DW_TAG_pointer_type DIE and add to
12690 the user defined type vector. */
12692 static struct type
*
12693 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12695 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
12696 struct comp_unit_head
*cu_header
= &cu
->header
;
12698 struct attribute
*attr_byte_size
;
12699 struct attribute
*attr_address_class
;
12700 int byte_size
, addr_class
;
12701 struct type
*target_type
;
12703 target_type
= die_type (die
, cu
);
12705 /* The die_type call above may have already set the type for this DIE. */
12706 type
= get_die_type (die
, cu
);
12710 type
= lookup_pointer_type (target_type
);
12712 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12713 if (attr_byte_size
)
12714 byte_size
= DW_UNSND (attr_byte_size
);
12716 byte_size
= cu_header
->addr_size
;
12718 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
12719 if (attr_address_class
)
12720 addr_class
= DW_UNSND (attr_address_class
);
12722 addr_class
= DW_ADDR_none
;
12724 /* If the pointer size or address class is different than the
12725 default, create a type variant marked as such and set the
12726 length accordingly. */
12727 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
12729 if (gdbarch_address_class_type_flags_p (gdbarch
))
12733 type_flags
= gdbarch_address_class_type_flags
12734 (gdbarch
, byte_size
, addr_class
);
12735 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
12737 type
= make_type_with_address_space (type
, type_flags
);
12739 else if (TYPE_LENGTH (type
) != byte_size
)
12741 complaint (&symfile_complaints
,
12742 _("invalid pointer size %d"), byte_size
);
12746 /* Should we also complain about unhandled address classes? */
12750 TYPE_LENGTH (type
) = byte_size
;
12751 return set_die_type (die
, type
, cu
);
12754 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
12755 the user defined type vector. */
12757 static struct type
*
12758 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12761 struct type
*to_type
;
12762 struct type
*domain
;
12764 to_type
= die_type (die
, cu
);
12765 domain
= die_containing_type (die
, cu
);
12767 /* The calls above may have already set the type for this DIE. */
12768 type
= get_die_type (die
, cu
);
12772 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
12773 type
= lookup_methodptr_type (to_type
);
12774 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
12776 struct type
*new_type
= alloc_type (cu
->objfile
);
12778 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
12779 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
12780 TYPE_VARARGS (to_type
));
12781 type
= lookup_methodptr_type (new_type
);
12784 type
= lookup_memberptr_type (to_type
, domain
);
12786 return set_die_type (die
, type
, cu
);
12789 /* Extract all information from a DW_TAG_reference_type DIE and add to
12790 the user defined type vector. */
12792 static struct type
*
12793 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12795 struct comp_unit_head
*cu_header
= &cu
->header
;
12796 struct type
*type
, *target_type
;
12797 struct attribute
*attr
;
12799 target_type
= die_type (die
, cu
);
12801 /* The die_type call above may have already set the type for this DIE. */
12802 type
= get_die_type (die
, cu
);
12806 type
= lookup_reference_type (target_type
);
12807 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12810 TYPE_LENGTH (type
) = DW_UNSND (attr
);
12814 TYPE_LENGTH (type
) = cu_header
->addr_size
;
12816 return set_die_type (die
, type
, cu
);
12819 static struct type
*
12820 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12822 struct type
*base_type
, *cv_type
;
12824 base_type
= die_type (die
, cu
);
12826 /* The die_type call above may have already set the type for this DIE. */
12827 cv_type
= get_die_type (die
, cu
);
12831 /* In case the const qualifier is applied to an array type, the element type
12832 is so qualified, not the array type (section 6.7.3 of C99). */
12833 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
12835 struct type
*el_type
, *inner_array
;
12837 base_type
= copy_type (base_type
);
12838 inner_array
= base_type
;
12840 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
12842 TYPE_TARGET_TYPE (inner_array
) =
12843 copy_type (TYPE_TARGET_TYPE (inner_array
));
12844 inner_array
= TYPE_TARGET_TYPE (inner_array
);
12847 el_type
= TYPE_TARGET_TYPE (inner_array
);
12848 TYPE_TARGET_TYPE (inner_array
) =
12849 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
12851 return set_die_type (die
, base_type
, cu
);
12854 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
12855 return set_die_type (die
, cv_type
, cu
);
12858 static struct type
*
12859 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12861 struct type
*base_type
, *cv_type
;
12863 base_type
= die_type (die
, cu
);
12865 /* The die_type call above may have already set the type for this DIE. */
12866 cv_type
= get_die_type (die
, cu
);
12870 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
12871 return set_die_type (die
, cv_type
, cu
);
12874 /* Handle DW_TAG_restrict_type. */
12876 static struct type
*
12877 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12879 struct type
*base_type
, *cv_type
;
12881 base_type
= die_type (die
, cu
);
12883 /* The die_type call above may have already set the type for this DIE. */
12884 cv_type
= get_die_type (die
, cu
);
12888 cv_type
= make_restrict_type (base_type
);
12889 return set_die_type (die
, cv_type
, cu
);
12892 /* Extract all information from a DW_TAG_string_type DIE and add to
12893 the user defined type vector. It isn't really a user defined type,
12894 but it behaves like one, with other DIE's using an AT_user_def_type
12895 attribute to reference it. */
12897 static struct type
*
12898 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12900 struct objfile
*objfile
= cu
->objfile
;
12901 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12902 struct type
*type
, *range_type
, *index_type
, *char_type
;
12903 struct attribute
*attr
;
12904 unsigned int length
;
12906 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
12909 length
= DW_UNSND (attr
);
12913 /* Check for the DW_AT_byte_size attribute. */
12914 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12917 length
= DW_UNSND (attr
);
12925 index_type
= objfile_type (objfile
)->builtin_int
;
12926 range_type
= create_range_type (NULL
, index_type
, 1, length
);
12927 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
12928 type
= create_string_type (NULL
, char_type
, range_type
);
12930 return set_die_type (die
, type
, cu
);
12933 /* Assuming that DIE corresponds to a function, returns nonzero
12934 if the function is prototyped. */
12937 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
12939 struct attribute
*attr
;
12941 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
12942 if (attr
&& (DW_UNSND (attr
) != 0))
12945 /* The DWARF standard implies that the DW_AT_prototyped attribute
12946 is only meaninful for C, but the concept also extends to other
12947 languages that allow unprototyped functions (Eg: Objective C).
12948 For all other languages, assume that functions are always
12950 if (cu
->language
!= language_c
12951 && cu
->language
!= language_objc
12952 && cu
->language
!= language_opencl
)
12955 /* RealView does not emit DW_AT_prototyped. We can not distinguish
12956 prototyped and unprototyped functions; default to prototyped,
12957 since that is more common in modern code (and RealView warns
12958 about unprototyped functions). */
12959 if (producer_is_realview (cu
->producer
))
12965 /* Handle DIES due to C code like:
12969 int (*funcp)(int a, long l);
12973 ('funcp' generates a DW_TAG_subroutine_type DIE). */
12975 static struct type
*
12976 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12978 struct objfile
*objfile
= cu
->objfile
;
12979 struct type
*type
; /* Type that this function returns. */
12980 struct type
*ftype
; /* Function that returns above type. */
12981 struct attribute
*attr
;
12983 type
= die_type (die
, cu
);
12985 /* The die_type call above may have already set the type for this DIE. */
12986 ftype
= get_die_type (die
, cu
);
12990 ftype
= lookup_function_type (type
);
12992 if (prototyped_function_p (die
, cu
))
12993 TYPE_PROTOTYPED (ftype
) = 1;
12995 /* Store the calling convention in the type if it's available in
12996 the subroutine die. Otherwise set the calling convention to
12997 the default value DW_CC_normal. */
12998 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
13000 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
13001 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
13002 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
13004 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
13006 /* We need to add the subroutine type to the die immediately so
13007 we don't infinitely recurse when dealing with parameters
13008 declared as the same subroutine type. */
13009 set_die_type (die
, ftype
, cu
);
13011 if (die
->child
!= NULL
)
13013 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
13014 struct die_info
*child_die
;
13015 int nparams
, iparams
;
13017 /* Count the number of parameters.
13018 FIXME: GDB currently ignores vararg functions, but knows about
13019 vararg member functions. */
13021 child_die
= die
->child
;
13022 while (child_die
&& child_die
->tag
)
13024 if (child_die
->tag
== DW_TAG_formal_parameter
)
13026 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
13027 TYPE_VARARGS (ftype
) = 1;
13028 child_die
= sibling_die (child_die
);
13031 /* Allocate storage for parameters and fill them in. */
13032 TYPE_NFIELDS (ftype
) = nparams
;
13033 TYPE_FIELDS (ftype
) = (struct field
*)
13034 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
13036 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
13037 even if we error out during the parameters reading below. */
13038 for (iparams
= 0; iparams
< nparams
; iparams
++)
13039 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
13042 child_die
= die
->child
;
13043 while (child_die
&& child_die
->tag
)
13045 if (child_die
->tag
== DW_TAG_formal_parameter
)
13047 struct type
*arg_type
;
13049 /* DWARF version 2 has no clean way to discern C++
13050 static and non-static member functions. G++ helps
13051 GDB by marking the first parameter for non-static
13052 member functions (which is the this pointer) as
13053 artificial. We pass this information to
13054 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
13056 DWARF version 3 added DW_AT_object_pointer, which GCC
13057 4.5 does not yet generate. */
13058 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
13060 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
13063 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
13065 /* GCC/43521: In java, the formal parameter
13066 "this" is sometimes not marked with DW_AT_artificial. */
13067 if (cu
->language
== language_java
)
13069 const char *name
= dwarf2_name (child_die
, cu
);
13071 if (name
&& !strcmp (name
, "this"))
13072 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
13075 arg_type
= die_type (child_die
, cu
);
13077 /* RealView does not mark THIS as const, which the testsuite
13078 expects. GCC marks THIS as const in method definitions,
13079 but not in the class specifications (GCC PR 43053). */
13080 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
13081 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
13084 struct dwarf2_cu
*arg_cu
= cu
;
13085 const char *name
= dwarf2_name (child_die
, cu
);
13087 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
13090 /* If the compiler emits this, use it. */
13091 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
13094 else if (name
&& strcmp (name
, "this") == 0)
13095 /* Function definitions will have the argument names. */
13097 else if (name
== NULL
&& iparams
== 0)
13098 /* Declarations may not have the names, so like
13099 elsewhere in GDB, assume an artificial first
13100 argument is "this". */
13104 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
13108 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
13111 child_die
= sibling_die (child_die
);
13118 static struct type
*
13119 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
13121 struct objfile
*objfile
= cu
->objfile
;
13122 const char *name
= NULL
;
13123 struct type
*this_type
, *target_type
;
13125 name
= dwarf2_full_name (NULL
, die
, cu
);
13126 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
13127 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
13128 TYPE_NAME (this_type
) = name
;
13129 set_die_type (die
, this_type
, cu
);
13130 target_type
= die_type (die
, cu
);
13131 if (target_type
!= this_type
)
13132 TYPE_TARGET_TYPE (this_type
) = target_type
;
13135 /* Self-referential typedefs are, it seems, not allowed by the DWARF
13136 spec and cause infinite loops in GDB. */
13137 complaint (&symfile_complaints
,
13138 _("Self-referential DW_TAG_typedef "
13139 "- DIE at 0x%x [in module %s]"),
13140 die
->offset
.sect_off
, objfile
->name
);
13141 TYPE_TARGET_TYPE (this_type
) = NULL
;
13146 /* Find a representation of a given base type and install
13147 it in the TYPE field of the die. */
13149 static struct type
*
13150 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13152 struct objfile
*objfile
= cu
->objfile
;
13154 struct attribute
*attr
;
13155 int encoding
= 0, size
= 0;
13157 enum type_code code
= TYPE_CODE_INT
;
13158 int type_flags
= 0;
13159 struct type
*target_type
= NULL
;
13161 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
13164 encoding
= DW_UNSND (attr
);
13166 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13169 size
= DW_UNSND (attr
);
13171 name
= dwarf2_name (die
, cu
);
13174 complaint (&symfile_complaints
,
13175 _("DW_AT_name missing from DW_TAG_base_type"));
13180 case DW_ATE_address
:
13181 /* Turn DW_ATE_address into a void * pointer. */
13182 code
= TYPE_CODE_PTR
;
13183 type_flags
|= TYPE_FLAG_UNSIGNED
;
13184 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
13186 case DW_ATE_boolean
:
13187 code
= TYPE_CODE_BOOL
;
13188 type_flags
|= TYPE_FLAG_UNSIGNED
;
13190 case DW_ATE_complex_float
:
13191 code
= TYPE_CODE_COMPLEX
;
13192 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
13194 case DW_ATE_decimal_float
:
13195 code
= TYPE_CODE_DECFLOAT
;
13198 code
= TYPE_CODE_FLT
;
13200 case DW_ATE_signed
:
13202 case DW_ATE_unsigned
:
13203 type_flags
|= TYPE_FLAG_UNSIGNED
;
13204 if (cu
->language
== language_fortran
13206 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
13207 code
= TYPE_CODE_CHAR
;
13209 case DW_ATE_signed_char
:
13210 if (cu
->language
== language_ada
|| cu
->language
== language_m2
13211 || cu
->language
== language_pascal
13212 || cu
->language
== language_fortran
)
13213 code
= TYPE_CODE_CHAR
;
13215 case DW_ATE_unsigned_char
:
13216 if (cu
->language
== language_ada
|| cu
->language
== language_m2
13217 || cu
->language
== language_pascal
13218 || cu
->language
== language_fortran
)
13219 code
= TYPE_CODE_CHAR
;
13220 type_flags
|= TYPE_FLAG_UNSIGNED
;
13223 /* We just treat this as an integer and then recognize the
13224 type by name elsewhere. */
13228 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
13229 dwarf_type_encoding_name (encoding
));
13233 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
13234 TYPE_NAME (type
) = name
;
13235 TYPE_TARGET_TYPE (type
) = target_type
;
13237 if (name
&& strcmp (name
, "char") == 0)
13238 TYPE_NOSIGN (type
) = 1;
13240 return set_die_type (die
, type
, cu
);
13243 /* Read the given DW_AT_subrange DIE. */
13245 static struct type
*
13246 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13248 struct type
*base_type
, *orig_base_type
;
13249 struct type
*range_type
;
13250 struct attribute
*attr
;
13252 int low_default_is_valid
;
13254 LONGEST negative_mask
;
13256 orig_base_type
= die_type (die
, cu
);
13257 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
13258 whereas the real type might be. So, we use ORIG_BASE_TYPE when
13259 creating the range type, but we use the result of check_typedef
13260 when examining properties of the type. */
13261 base_type
= check_typedef (orig_base_type
);
13263 /* The die_type call above may have already set the type for this DIE. */
13264 range_type
= get_die_type (die
, cu
);
13268 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
13269 omitting DW_AT_lower_bound. */
13270 switch (cu
->language
)
13273 case language_cplus
:
13275 low_default_is_valid
= 1;
13277 case language_fortran
:
13279 low_default_is_valid
= 1;
13282 case language_java
:
13283 case language_objc
:
13285 low_default_is_valid
= (cu
->header
.version
>= 4);
13289 case language_pascal
:
13291 low_default_is_valid
= (cu
->header
.version
>= 4);
13295 low_default_is_valid
= 0;
13299 /* FIXME: For variable sized arrays either of these could be
13300 a variable rather than a constant value. We'll allow it,
13301 but we don't know how to handle it. */
13302 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
13304 low
= dwarf2_get_attr_constant_value (attr
, low
);
13305 else if (!low_default_is_valid
)
13306 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
13307 "- DIE at 0x%x [in module %s]"),
13308 die
->offset
.sect_off
, cu
->objfile
->name
);
13310 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
13313 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
13315 /* GCC encodes arrays with unspecified or dynamic length
13316 with a DW_FORM_block1 attribute or a reference attribute.
13317 FIXME: GDB does not yet know how to handle dynamic
13318 arrays properly, treat them as arrays with unspecified
13321 FIXME: jimb/2003-09-22: GDB does not really know
13322 how to handle arrays of unspecified length
13323 either; we just represent them as zero-length
13324 arrays. Choose an appropriate upper bound given
13325 the lower bound we've computed above. */
13329 high
= dwarf2_get_attr_constant_value (attr
, 1);
13333 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
13336 int count
= dwarf2_get_attr_constant_value (attr
, 1);
13337 high
= low
+ count
- 1;
13341 /* Unspecified array length. */
13346 /* Dwarf-2 specifications explicitly allows to create subrange types
13347 without specifying a base type.
13348 In that case, the base type must be set to the type of
13349 the lower bound, upper bound or count, in that order, if any of these
13350 three attributes references an object that has a type.
13351 If no base type is found, the Dwarf-2 specifications say that
13352 a signed integer type of size equal to the size of an address should
13354 For the following C code: `extern char gdb_int [];'
13355 GCC produces an empty range DIE.
13356 FIXME: muller/2010-05-28: Possible references to object for low bound,
13357 high bound or count are not yet handled by this code. */
13358 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
13360 struct objfile
*objfile
= cu
->objfile
;
13361 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13362 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
13363 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
13365 /* Test "int", "long int", and "long long int" objfile types,
13366 and select the first one having a size above or equal to the
13367 architecture address size. */
13368 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
13369 base_type
= int_type
;
13372 int_type
= objfile_type (objfile
)->builtin_long
;
13373 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
13374 base_type
= int_type
;
13377 int_type
= objfile_type (objfile
)->builtin_long_long
;
13378 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
13379 base_type
= int_type
;
13385 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
13386 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
13387 low
|= negative_mask
;
13388 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
13389 high
|= negative_mask
;
13391 range_type
= create_range_type (NULL
, orig_base_type
, low
, high
);
13393 /* Mark arrays with dynamic length at least as an array of unspecified
13394 length. GDB could check the boundary but before it gets implemented at
13395 least allow accessing the array elements. */
13396 if (attr
&& attr_form_is_block (attr
))
13397 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
13399 /* Ada expects an empty array on no boundary attributes. */
13400 if (attr
== NULL
&& cu
->language
!= language_ada
)
13401 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
13403 name
= dwarf2_name (die
, cu
);
13405 TYPE_NAME (range_type
) = name
;
13407 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13409 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
13411 set_die_type (die
, range_type
, cu
);
13413 /* set_die_type should be already done. */
13414 set_descriptive_type (range_type
, die
, cu
);
13419 static struct type
*
13420 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13424 /* For now, we only support the C meaning of an unspecified type: void. */
13426 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
13427 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
13429 return set_die_type (die
, type
, cu
);
13432 /* Read a single die and all its descendents. Set the die's sibling
13433 field to NULL; set other fields in the die correctly, and set all
13434 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
13435 location of the info_ptr after reading all of those dies. PARENT
13436 is the parent of the die in question. */
13438 static struct die_info
*
13439 read_die_and_children (const struct die_reader_specs
*reader
,
13440 const gdb_byte
*info_ptr
,
13441 const gdb_byte
**new_info_ptr
,
13442 struct die_info
*parent
)
13444 struct die_info
*die
;
13445 const gdb_byte
*cur_ptr
;
13448 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
13451 *new_info_ptr
= cur_ptr
;
13454 store_in_ref_table (die
, reader
->cu
);
13457 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
13461 *new_info_ptr
= cur_ptr
;
13464 die
->sibling
= NULL
;
13465 die
->parent
= parent
;
13469 /* Read a die, all of its descendents, and all of its siblings; set
13470 all of the fields of all of the dies correctly. Arguments are as
13471 in read_die_and_children. */
13473 static struct die_info
*
13474 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
13475 const gdb_byte
*info_ptr
,
13476 const gdb_byte
**new_info_ptr
,
13477 struct die_info
*parent
)
13479 struct die_info
*first_die
, *last_sibling
;
13480 const gdb_byte
*cur_ptr
;
13482 cur_ptr
= info_ptr
;
13483 first_die
= last_sibling
= NULL
;
13487 struct die_info
*die
13488 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
13492 *new_info_ptr
= cur_ptr
;
13499 last_sibling
->sibling
= die
;
13501 last_sibling
= die
;
13505 /* Read a die, all of its descendents, and all of its siblings; set
13506 all of the fields of all of the dies correctly. Arguments are as
13507 in read_die_and_children.
13508 This the main entry point for reading a DIE and all its children. */
13510 static struct die_info
*
13511 read_die_and_siblings (const struct die_reader_specs
*reader
,
13512 const gdb_byte
*info_ptr
,
13513 const gdb_byte
**new_info_ptr
,
13514 struct die_info
*parent
)
13516 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
13517 new_info_ptr
, parent
);
13519 if (dwarf2_die_debug
)
13521 fprintf_unfiltered (gdb_stdlog
,
13522 "Read die from %s@0x%x of %s:\n",
13523 bfd_section_name (reader
->abfd
,
13524 reader
->die_section
->asection
),
13525 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
13526 bfd_get_filename (reader
->abfd
));
13527 dump_die (die
, dwarf2_die_debug
);
13533 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
13535 The caller is responsible for filling in the extra attributes
13536 and updating (*DIEP)->num_attrs.
13537 Set DIEP to point to a newly allocated die with its information,
13538 except for its child, sibling, and parent fields.
13539 Set HAS_CHILDREN to tell whether the die has children or not. */
13541 static const gdb_byte
*
13542 read_full_die_1 (const struct die_reader_specs
*reader
,
13543 struct die_info
**diep
, const gdb_byte
*info_ptr
,
13544 int *has_children
, int num_extra_attrs
)
13546 unsigned int abbrev_number
, bytes_read
, i
;
13547 sect_offset offset
;
13548 struct abbrev_info
*abbrev
;
13549 struct die_info
*die
;
13550 struct dwarf2_cu
*cu
= reader
->cu
;
13551 bfd
*abfd
= reader
->abfd
;
13553 offset
.sect_off
= info_ptr
- reader
->buffer
;
13554 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
13555 info_ptr
+= bytes_read
;
13556 if (!abbrev_number
)
13563 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
13565 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
13567 bfd_get_filename (abfd
));
13569 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
13570 die
->offset
= offset
;
13571 die
->tag
= abbrev
->tag
;
13572 die
->abbrev
= abbrev_number
;
13574 /* Make the result usable.
13575 The caller needs to update num_attrs after adding the extra
13577 die
->num_attrs
= abbrev
->num_attrs
;
13579 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
13580 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
13584 *has_children
= abbrev
->has_children
;
13588 /* Read a die and all its attributes.
13589 Set DIEP to point to a newly allocated die with its information,
13590 except for its child, sibling, and parent fields.
13591 Set HAS_CHILDREN to tell whether the die has children or not. */
13593 static const gdb_byte
*
13594 read_full_die (const struct die_reader_specs
*reader
,
13595 struct die_info
**diep
, const gdb_byte
*info_ptr
,
13598 const gdb_byte
*result
;
13600 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
13602 if (dwarf2_die_debug
)
13604 fprintf_unfiltered (gdb_stdlog
,
13605 "Read die from %s@0x%x of %s:\n",
13606 bfd_section_name (reader
->abfd
,
13607 reader
->die_section
->asection
),
13608 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
13609 bfd_get_filename (reader
->abfd
));
13610 dump_die (*diep
, dwarf2_die_debug
);
13616 /* Abbreviation tables.
13618 In DWARF version 2, the description of the debugging information is
13619 stored in a separate .debug_abbrev section. Before we read any
13620 dies from a section we read in all abbreviations and install them
13621 in a hash table. */
13623 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
13625 static struct abbrev_info
*
13626 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
13628 struct abbrev_info
*abbrev
;
13630 abbrev
= (struct abbrev_info
*)
13631 obstack_alloc (&abbrev_table
->abbrev_obstack
, sizeof (struct abbrev_info
));
13632 memset (abbrev
, 0, sizeof (struct abbrev_info
));
13636 /* Add an abbreviation to the table. */
13639 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
13640 unsigned int abbrev_number
,
13641 struct abbrev_info
*abbrev
)
13643 unsigned int hash_number
;
13645 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
13646 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
13647 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
13650 /* Look up an abbrev in the table.
13651 Returns NULL if the abbrev is not found. */
13653 static struct abbrev_info
*
13654 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
13655 unsigned int abbrev_number
)
13657 unsigned int hash_number
;
13658 struct abbrev_info
*abbrev
;
13660 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
13661 abbrev
= abbrev_table
->abbrevs
[hash_number
];
13665 if (abbrev
->number
== abbrev_number
)
13667 abbrev
= abbrev
->next
;
13672 /* Read in an abbrev table. */
13674 static struct abbrev_table
*
13675 abbrev_table_read_table (struct dwarf2_section_info
*section
,
13676 sect_offset offset
)
13678 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13679 bfd
*abfd
= section
->asection
->owner
;
13680 struct abbrev_table
*abbrev_table
;
13681 const gdb_byte
*abbrev_ptr
;
13682 struct abbrev_info
*cur_abbrev
;
13683 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
13684 unsigned int abbrev_form
;
13685 struct attr_abbrev
*cur_attrs
;
13686 unsigned int allocated_attrs
;
13688 abbrev_table
= XMALLOC (struct abbrev_table
);
13689 abbrev_table
->offset
= offset
;
13690 obstack_init (&abbrev_table
->abbrev_obstack
);
13691 abbrev_table
->abbrevs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
13693 * sizeof (struct abbrev_info
*)));
13694 memset (abbrev_table
->abbrevs
, 0,
13695 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
13697 dwarf2_read_section (objfile
, section
);
13698 abbrev_ptr
= section
->buffer
+ offset
.sect_off
;
13699 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13700 abbrev_ptr
+= bytes_read
;
13702 allocated_attrs
= ATTR_ALLOC_CHUNK
;
13703 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
13705 /* Loop until we reach an abbrev number of 0. */
13706 while (abbrev_number
)
13708 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
13710 /* read in abbrev header */
13711 cur_abbrev
->number
= abbrev_number
;
13712 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13713 abbrev_ptr
+= bytes_read
;
13714 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
13717 /* now read in declarations */
13718 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13719 abbrev_ptr
+= bytes_read
;
13720 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13721 abbrev_ptr
+= bytes_read
;
13722 while (abbrev_name
)
13724 if (cur_abbrev
->num_attrs
== allocated_attrs
)
13726 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
13728 = xrealloc (cur_attrs
, (allocated_attrs
13729 * sizeof (struct attr_abbrev
)));
13732 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
13733 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
13734 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13735 abbrev_ptr
+= bytes_read
;
13736 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13737 abbrev_ptr
+= bytes_read
;
13740 cur_abbrev
->attrs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
13741 (cur_abbrev
->num_attrs
13742 * sizeof (struct attr_abbrev
)));
13743 memcpy (cur_abbrev
->attrs
, cur_attrs
,
13744 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
13746 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
13748 /* Get next abbreviation.
13749 Under Irix6 the abbreviations for a compilation unit are not
13750 always properly terminated with an abbrev number of 0.
13751 Exit loop if we encounter an abbreviation which we have
13752 already read (which means we are about to read the abbreviations
13753 for the next compile unit) or if the end of the abbreviation
13754 table is reached. */
13755 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
13757 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13758 abbrev_ptr
+= bytes_read
;
13759 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
13764 return abbrev_table
;
13767 /* Free the resources held by ABBREV_TABLE. */
13770 abbrev_table_free (struct abbrev_table
*abbrev_table
)
13772 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
13773 xfree (abbrev_table
);
13776 /* Same as abbrev_table_free but as a cleanup.
13777 We pass in a pointer to the pointer to the table so that we can
13778 set the pointer to NULL when we're done. It also simplifies
13779 build_type_unit_groups. */
13782 abbrev_table_free_cleanup (void *table_ptr
)
13784 struct abbrev_table
**abbrev_table_ptr
= table_ptr
;
13786 if (*abbrev_table_ptr
!= NULL
)
13787 abbrev_table_free (*abbrev_table_ptr
);
13788 *abbrev_table_ptr
= NULL
;
13791 /* Read the abbrev table for CU from ABBREV_SECTION. */
13794 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
13795 struct dwarf2_section_info
*abbrev_section
)
13798 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_offset
);
13801 /* Release the memory used by the abbrev table for a compilation unit. */
13804 dwarf2_free_abbrev_table (void *ptr_to_cu
)
13806 struct dwarf2_cu
*cu
= ptr_to_cu
;
13808 if (cu
->abbrev_table
!= NULL
)
13809 abbrev_table_free (cu
->abbrev_table
);
13810 /* Set this to NULL so that we SEGV if we try to read it later,
13811 and also because free_comp_unit verifies this is NULL. */
13812 cu
->abbrev_table
= NULL
;
13815 /* Returns nonzero if TAG represents a type that we might generate a partial
13819 is_type_tag_for_partial (int tag
)
13824 /* Some types that would be reasonable to generate partial symbols for,
13825 that we don't at present. */
13826 case DW_TAG_array_type
:
13827 case DW_TAG_file_type
:
13828 case DW_TAG_ptr_to_member_type
:
13829 case DW_TAG_set_type
:
13830 case DW_TAG_string_type
:
13831 case DW_TAG_subroutine_type
:
13833 case DW_TAG_base_type
:
13834 case DW_TAG_class_type
:
13835 case DW_TAG_interface_type
:
13836 case DW_TAG_enumeration_type
:
13837 case DW_TAG_structure_type
:
13838 case DW_TAG_subrange_type
:
13839 case DW_TAG_typedef
:
13840 case DW_TAG_union_type
:
13847 /* Load all DIEs that are interesting for partial symbols into memory. */
13849 static struct partial_die_info
*
13850 load_partial_dies (const struct die_reader_specs
*reader
,
13851 const gdb_byte
*info_ptr
, int building_psymtab
)
13853 struct dwarf2_cu
*cu
= reader
->cu
;
13854 struct objfile
*objfile
= cu
->objfile
;
13855 struct partial_die_info
*part_die
;
13856 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
13857 struct abbrev_info
*abbrev
;
13858 unsigned int bytes_read
;
13859 unsigned int load_all
= 0;
13860 int nesting_level
= 1;
13865 gdb_assert (cu
->per_cu
!= NULL
);
13866 if (cu
->per_cu
->load_all_dies
)
13870 = htab_create_alloc_ex (cu
->header
.length
/ 12,
13874 &cu
->comp_unit_obstack
,
13875 hashtab_obstack_allocate
,
13876 dummy_obstack_deallocate
);
13878 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
13879 sizeof (struct partial_die_info
));
13883 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
13885 /* A NULL abbrev means the end of a series of children. */
13886 if (abbrev
== NULL
)
13888 if (--nesting_level
== 0)
13890 /* PART_DIE was probably the last thing allocated on the
13891 comp_unit_obstack, so we could call obstack_free
13892 here. We don't do that because the waste is small,
13893 and will be cleaned up when we're done with this
13894 compilation unit. This way, we're also more robust
13895 against other users of the comp_unit_obstack. */
13898 info_ptr
+= bytes_read
;
13899 last_die
= parent_die
;
13900 parent_die
= parent_die
->die_parent
;
13904 /* Check for template arguments. We never save these; if
13905 they're seen, we just mark the parent, and go on our way. */
13906 if (parent_die
!= NULL
13907 && cu
->language
== language_cplus
13908 && (abbrev
->tag
== DW_TAG_template_type_param
13909 || abbrev
->tag
== DW_TAG_template_value_param
))
13911 parent_die
->has_template_arguments
= 1;
13915 /* We don't need a partial DIE for the template argument. */
13916 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
13921 /* We only recurse into c++ subprograms looking for template arguments.
13922 Skip their other children. */
13924 && cu
->language
== language_cplus
13925 && parent_die
!= NULL
13926 && parent_die
->tag
== DW_TAG_subprogram
)
13928 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
13932 /* Check whether this DIE is interesting enough to save. Normally
13933 we would not be interested in members here, but there may be
13934 later variables referencing them via DW_AT_specification (for
13935 static members). */
13937 && !is_type_tag_for_partial (abbrev
->tag
)
13938 && abbrev
->tag
!= DW_TAG_constant
13939 && abbrev
->tag
!= DW_TAG_enumerator
13940 && abbrev
->tag
!= DW_TAG_subprogram
13941 && abbrev
->tag
!= DW_TAG_lexical_block
13942 && abbrev
->tag
!= DW_TAG_variable
13943 && abbrev
->tag
!= DW_TAG_namespace
13944 && abbrev
->tag
!= DW_TAG_module
13945 && abbrev
->tag
!= DW_TAG_member
13946 && abbrev
->tag
!= DW_TAG_imported_unit
)
13948 /* Otherwise we skip to the next sibling, if any. */
13949 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
13953 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
13956 /* This two-pass algorithm for processing partial symbols has a
13957 high cost in cache pressure. Thus, handle some simple cases
13958 here which cover the majority of C partial symbols. DIEs
13959 which neither have specification tags in them, nor could have
13960 specification tags elsewhere pointing at them, can simply be
13961 processed and discarded.
13963 This segment is also optional; scan_partial_symbols and
13964 add_partial_symbol will handle these DIEs if we chain
13965 them in normally. When compilers which do not emit large
13966 quantities of duplicate debug information are more common,
13967 this code can probably be removed. */
13969 /* Any complete simple types at the top level (pretty much all
13970 of them, for a language without namespaces), can be processed
13972 if (parent_die
== NULL
13973 && part_die
->has_specification
== 0
13974 && part_die
->is_declaration
== 0
13975 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
13976 || part_die
->tag
== DW_TAG_base_type
13977 || part_die
->tag
== DW_TAG_subrange_type
))
13979 if (building_psymtab
&& part_die
->name
!= NULL
)
13980 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
13981 VAR_DOMAIN
, LOC_TYPEDEF
,
13982 &objfile
->static_psymbols
,
13983 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
13984 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
13988 /* The exception for DW_TAG_typedef with has_children above is
13989 a workaround of GCC PR debug/47510. In the case of this complaint
13990 type_name_no_tag_or_error will error on such types later.
13992 GDB skipped children of DW_TAG_typedef by the shortcut above and then
13993 it could not find the child DIEs referenced later, this is checked
13994 above. In correct DWARF DW_TAG_typedef should have no children. */
13996 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
13997 complaint (&symfile_complaints
,
13998 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
13999 "- DIE at 0x%x [in module %s]"),
14000 part_die
->offset
.sect_off
, objfile
->name
);
14002 /* If we're at the second level, and we're an enumerator, and
14003 our parent has no specification (meaning possibly lives in a
14004 namespace elsewhere), then we can add the partial symbol now
14005 instead of queueing it. */
14006 if (part_die
->tag
== DW_TAG_enumerator
14007 && parent_die
!= NULL
14008 && parent_die
->die_parent
== NULL
14009 && parent_die
->tag
== DW_TAG_enumeration_type
14010 && parent_die
->has_specification
== 0)
14012 if (part_die
->name
== NULL
)
14013 complaint (&symfile_complaints
,
14014 _("malformed enumerator DIE ignored"));
14015 else if (building_psymtab
)
14016 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
14017 VAR_DOMAIN
, LOC_CONST
,
14018 (cu
->language
== language_cplus
14019 || cu
->language
== language_java
)
14020 ? &objfile
->global_psymbols
14021 : &objfile
->static_psymbols
,
14022 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
14024 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
14028 /* We'll save this DIE so link it in. */
14029 part_die
->die_parent
= parent_die
;
14030 part_die
->die_sibling
= NULL
;
14031 part_die
->die_child
= NULL
;
14033 if (last_die
&& last_die
== parent_die
)
14034 last_die
->die_child
= part_die
;
14036 last_die
->die_sibling
= part_die
;
14038 last_die
= part_die
;
14040 if (first_die
== NULL
)
14041 first_die
= part_die
;
14043 /* Maybe add the DIE to the hash table. Not all DIEs that we
14044 find interesting need to be in the hash table, because we
14045 also have the parent/sibling/child chains; only those that we
14046 might refer to by offset later during partial symbol reading.
14048 For now this means things that might have be the target of a
14049 DW_AT_specification, DW_AT_abstract_origin, or
14050 DW_AT_extension. DW_AT_extension will refer only to
14051 namespaces; DW_AT_abstract_origin refers to functions (and
14052 many things under the function DIE, but we do not recurse
14053 into function DIEs during partial symbol reading) and
14054 possibly variables as well; DW_AT_specification refers to
14055 declarations. Declarations ought to have the DW_AT_declaration
14056 flag. It happens that GCC forgets to put it in sometimes, but
14057 only for functions, not for types.
14059 Adding more things than necessary to the hash table is harmless
14060 except for the performance cost. Adding too few will result in
14061 wasted time in find_partial_die, when we reread the compilation
14062 unit with load_all_dies set. */
14065 || abbrev
->tag
== DW_TAG_constant
14066 || abbrev
->tag
== DW_TAG_subprogram
14067 || abbrev
->tag
== DW_TAG_variable
14068 || abbrev
->tag
== DW_TAG_namespace
14069 || part_die
->is_declaration
)
14073 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
14074 part_die
->offset
.sect_off
, INSERT
);
14078 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
14079 sizeof (struct partial_die_info
));
14081 /* For some DIEs we want to follow their children (if any). For C
14082 we have no reason to follow the children of structures; for other
14083 languages we have to, so that we can get at method physnames
14084 to infer fully qualified class names, for DW_AT_specification,
14085 and for C++ template arguments. For C++, we also look one level
14086 inside functions to find template arguments (if the name of the
14087 function does not already contain the template arguments).
14089 For Ada, we need to scan the children of subprograms and lexical
14090 blocks as well because Ada allows the definition of nested
14091 entities that could be interesting for the debugger, such as
14092 nested subprograms for instance. */
14093 if (last_die
->has_children
14095 || last_die
->tag
== DW_TAG_namespace
14096 || last_die
->tag
== DW_TAG_module
14097 || last_die
->tag
== DW_TAG_enumeration_type
14098 || (cu
->language
== language_cplus
14099 && last_die
->tag
== DW_TAG_subprogram
14100 && (last_die
->name
== NULL
14101 || strchr (last_die
->name
, '<') == NULL
))
14102 || (cu
->language
!= language_c
14103 && (last_die
->tag
== DW_TAG_class_type
14104 || last_die
->tag
== DW_TAG_interface_type
14105 || last_die
->tag
== DW_TAG_structure_type
14106 || last_die
->tag
== DW_TAG_union_type
))
14107 || (cu
->language
== language_ada
14108 && (last_die
->tag
== DW_TAG_subprogram
14109 || last_die
->tag
== DW_TAG_lexical_block
))))
14112 parent_die
= last_die
;
14116 /* Otherwise we skip to the next sibling, if any. */
14117 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
14119 /* Back to the top, do it again. */
14123 /* Read a minimal amount of information into the minimal die structure. */
14125 static const gdb_byte
*
14126 read_partial_die (const struct die_reader_specs
*reader
,
14127 struct partial_die_info
*part_die
,
14128 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
14129 const gdb_byte
*info_ptr
)
14131 struct dwarf2_cu
*cu
= reader
->cu
;
14132 struct objfile
*objfile
= cu
->objfile
;
14133 const gdb_byte
*buffer
= reader
->buffer
;
14135 struct attribute attr
;
14136 int has_low_pc_attr
= 0;
14137 int has_high_pc_attr
= 0;
14138 int high_pc_relative
= 0;
14140 memset (part_die
, 0, sizeof (struct partial_die_info
));
14142 part_die
->offset
.sect_off
= info_ptr
- buffer
;
14144 info_ptr
+= abbrev_len
;
14146 if (abbrev
== NULL
)
14149 part_die
->tag
= abbrev
->tag
;
14150 part_die
->has_children
= abbrev
->has_children
;
14152 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
14154 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
14156 /* Store the data if it is of an attribute we want to keep in a
14157 partial symbol table. */
14161 switch (part_die
->tag
)
14163 case DW_TAG_compile_unit
:
14164 case DW_TAG_partial_unit
:
14165 case DW_TAG_type_unit
:
14166 /* Compilation units have a DW_AT_name that is a filename, not
14167 a source language identifier. */
14168 case DW_TAG_enumeration_type
:
14169 case DW_TAG_enumerator
:
14170 /* These tags always have simple identifiers already; no need
14171 to canonicalize them. */
14172 part_die
->name
= DW_STRING (&attr
);
14176 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
14177 &objfile
->objfile_obstack
);
14181 case DW_AT_linkage_name
:
14182 case DW_AT_MIPS_linkage_name
:
14183 /* Note that both forms of linkage name might appear. We
14184 assume they will be the same, and we only store the last
14186 if (cu
->language
== language_ada
)
14187 part_die
->name
= DW_STRING (&attr
);
14188 part_die
->linkage_name
= DW_STRING (&attr
);
14191 has_low_pc_attr
= 1;
14192 part_die
->lowpc
= DW_ADDR (&attr
);
14194 case DW_AT_high_pc
:
14195 has_high_pc_attr
= 1;
14196 if (attr
.form
== DW_FORM_addr
14197 || attr
.form
== DW_FORM_GNU_addr_index
)
14198 part_die
->highpc
= DW_ADDR (&attr
);
14201 high_pc_relative
= 1;
14202 part_die
->highpc
= DW_UNSND (&attr
);
14205 case DW_AT_location
:
14206 /* Support the .debug_loc offsets. */
14207 if (attr_form_is_block (&attr
))
14209 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
14211 else if (attr_form_is_section_offset (&attr
))
14213 dwarf2_complex_location_expr_complaint ();
14217 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
14218 "partial symbol information");
14221 case DW_AT_external
:
14222 part_die
->is_external
= DW_UNSND (&attr
);
14224 case DW_AT_declaration
:
14225 part_die
->is_declaration
= DW_UNSND (&attr
);
14228 part_die
->has_type
= 1;
14230 case DW_AT_abstract_origin
:
14231 case DW_AT_specification
:
14232 case DW_AT_extension
:
14233 part_die
->has_specification
= 1;
14234 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
14235 part_die
->spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
14236 || cu
->per_cu
->is_dwz
);
14238 case DW_AT_sibling
:
14239 /* Ignore absolute siblings, they might point outside of
14240 the current compile unit. */
14241 if (attr
.form
== DW_FORM_ref_addr
)
14242 complaint (&symfile_complaints
,
14243 _("ignoring absolute DW_AT_sibling"));
14245 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
14247 case DW_AT_byte_size
:
14248 part_die
->has_byte_size
= 1;
14250 case DW_AT_calling_convention
:
14251 /* DWARF doesn't provide a way to identify a program's source-level
14252 entry point. DW_AT_calling_convention attributes are only meant
14253 to describe functions' calling conventions.
14255 However, because it's a necessary piece of information in
14256 Fortran, and because DW_CC_program is the only piece of debugging
14257 information whose definition refers to a 'main program' at all,
14258 several compilers have begun marking Fortran main programs with
14259 DW_CC_program --- even when those functions use the standard
14260 calling conventions.
14262 So until DWARF specifies a way to provide this information and
14263 compilers pick up the new representation, we'll support this
14265 if (DW_UNSND (&attr
) == DW_CC_program
14266 && cu
->language
== language_fortran
)
14268 set_main_name (part_die
->name
);
14270 /* As this DIE has a static linkage the name would be difficult
14271 to look up later. */
14272 language_of_main
= language_fortran
;
14276 if (DW_UNSND (&attr
) == DW_INL_inlined
14277 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
14278 part_die
->may_be_inlined
= 1;
14282 if (part_die
->tag
== DW_TAG_imported_unit
)
14284 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
14285 part_die
->is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
14286 || cu
->per_cu
->is_dwz
);
14295 if (high_pc_relative
)
14296 part_die
->highpc
+= part_die
->lowpc
;
14298 if (has_low_pc_attr
&& has_high_pc_attr
)
14300 /* When using the GNU linker, .gnu.linkonce. sections are used to
14301 eliminate duplicate copies of functions and vtables and such.
14302 The linker will arbitrarily choose one and discard the others.
14303 The AT_*_pc values for such functions refer to local labels in
14304 these sections. If the section from that file was discarded, the
14305 labels are not in the output, so the relocs get a value of 0.
14306 If this is a discarded function, mark the pc bounds as invalid,
14307 so that GDB will ignore it. */
14308 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14310 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14312 complaint (&symfile_complaints
,
14313 _("DW_AT_low_pc %s is zero "
14314 "for DIE at 0x%x [in module %s]"),
14315 paddress (gdbarch
, part_die
->lowpc
),
14316 part_die
->offset
.sect_off
, objfile
->name
);
14318 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
14319 else if (part_die
->lowpc
>= part_die
->highpc
)
14321 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14323 complaint (&symfile_complaints
,
14324 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
14325 "for DIE at 0x%x [in module %s]"),
14326 paddress (gdbarch
, part_die
->lowpc
),
14327 paddress (gdbarch
, part_die
->highpc
),
14328 part_die
->offset
.sect_off
, objfile
->name
);
14331 part_die
->has_pc_info
= 1;
14337 /* Find a cached partial DIE at OFFSET in CU. */
14339 static struct partial_die_info
*
14340 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
14342 struct partial_die_info
*lookup_die
= NULL
;
14343 struct partial_die_info part_die
;
14345 part_die
.offset
= offset
;
14346 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
14352 /* Find a partial DIE at OFFSET, which may or may not be in CU,
14353 except in the case of .debug_types DIEs which do not reference
14354 outside their CU (they do however referencing other types via
14355 DW_FORM_ref_sig8). */
14357 static struct partial_die_info
*
14358 find_partial_die (sect_offset offset
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
14360 struct objfile
*objfile
= cu
->objfile
;
14361 struct dwarf2_per_cu_data
*per_cu
= NULL
;
14362 struct partial_die_info
*pd
= NULL
;
14364 if (offset_in_dwz
== cu
->per_cu
->is_dwz
14365 && offset_in_cu_p (&cu
->header
, offset
))
14367 pd
= find_partial_die_in_comp_unit (offset
, cu
);
14370 /* We missed recording what we needed.
14371 Load all dies and try again. */
14372 per_cu
= cu
->per_cu
;
14376 /* TUs don't reference other CUs/TUs (except via type signatures). */
14377 if (cu
->per_cu
->is_debug_types
)
14379 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
14380 " external reference to offset 0x%lx [in module %s].\n"),
14381 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
14382 bfd_get_filename (objfile
->obfd
));
14384 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
14387 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
14388 load_partial_comp_unit (per_cu
);
14390 per_cu
->cu
->last_used
= 0;
14391 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
14394 /* If we didn't find it, and not all dies have been loaded,
14395 load them all and try again. */
14397 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
14399 per_cu
->load_all_dies
= 1;
14401 /* This is nasty. When we reread the DIEs, somewhere up the call chain
14402 THIS_CU->cu may already be in use. So we can't just free it and
14403 replace its DIEs with the ones we read in. Instead, we leave those
14404 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
14405 and clobber THIS_CU->cu->partial_dies with the hash table for the new
14407 load_partial_comp_unit (per_cu
);
14409 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
14413 internal_error (__FILE__
, __LINE__
,
14414 _("could not find partial DIE 0x%x "
14415 "in cache [from module %s]\n"),
14416 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
14420 /* See if we can figure out if the class lives in a namespace. We do
14421 this by looking for a member function; its demangled name will
14422 contain namespace info, if there is any. */
14425 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
14426 struct dwarf2_cu
*cu
)
14428 /* NOTE: carlton/2003-10-07: Getting the info this way changes
14429 what template types look like, because the demangler
14430 frequently doesn't give the same name as the debug info. We
14431 could fix this by only using the demangled name to get the
14432 prefix (but see comment in read_structure_type). */
14434 struct partial_die_info
*real_pdi
;
14435 struct partial_die_info
*child_pdi
;
14437 /* If this DIE (this DIE's specification, if any) has a parent, then
14438 we should not do this. We'll prepend the parent's fully qualified
14439 name when we create the partial symbol. */
14441 real_pdi
= struct_pdi
;
14442 while (real_pdi
->has_specification
)
14443 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
14444 real_pdi
->spec_is_dwz
, cu
);
14446 if (real_pdi
->die_parent
!= NULL
)
14449 for (child_pdi
= struct_pdi
->die_child
;
14451 child_pdi
= child_pdi
->die_sibling
)
14453 if (child_pdi
->tag
== DW_TAG_subprogram
14454 && child_pdi
->linkage_name
!= NULL
)
14456 char *actual_class_name
14457 = language_class_name_from_physname (cu
->language_defn
,
14458 child_pdi
->linkage_name
);
14459 if (actual_class_name
!= NULL
)
14462 = obstack_copy0 (&cu
->objfile
->objfile_obstack
,
14464 strlen (actual_class_name
));
14465 xfree (actual_class_name
);
14472 /* Adjust PART_DIE before generating a symbol for it. This function
14473 may set the is_external flag or change the DIE's name. */
14476 fixup_partial_die (struct partial_die_info
*part_die
,
14477 struct dwarf2_cu
*cu
)
14479 /* Once we've fixed up a die, there's no point in doing so again.
14480 This also avoids a memory leak if we were to call
14481 guess_partial_die_structure_name multiple times. */
14482 if (part_die
->fixup_called
)
14485 /* If we found a reference attribute and the DIE has no name, try
14486 to find a name in the referred to DIE. */
14488 if (part_die
->name
== NULL
&& part_die
->has_specification
)
14490 struct partial_die_info
*spec_die
;
14492 spec_die
= find_partial_die (part_die
->spec_offset
,
14493 part_die
->spec_is_dwz
, cu
);
14495 fixup_partial_die (spec_die
, cu
);
14497 if (spec_die
->name
)
14499 part_die
->name
= spec_die
->name
;
14501 /* Copy DW_AT_external attribute if it is set. */
14502 if (spec_die
->is_external
)
14503 part_die
->is_external
= spec_die
->is_external
;
14507 /* Set default names for some unnamed DIEs. */
14509 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
14510 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
14512 /* If there is no parent die to provide a namespace, and there are
14513 children, see if we can determine the namespace from their linkage
14515 if (cu
->language
== language_cplus
14516 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
14517 && part_die
->die_parent
== NULL
14518 && part_die
->has_children
14519 && (part_die
->tag
== DW_TAG_class_type
14520 || part_die
->tag
== DW_TAG_structure_type
14521 || part_die
->tag
== DW_TAG_union_type
))
14522 guess_partial_die_structure_name (part_die
, cu
);
14524 /* GCC might emit a nameless struct or union that has a linkage
14525 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
14526 if (part_die
->name
== NULL
14527 && (part_die
->tag
== DW_TAG_class_type
14528 || part_die
->tag
== DW_TAG_interface_type
14529 || part_die
->tag
== DW_TAG_structure_type
14530 || part_die
->tag
== DW_TAG_union_type
)
14531 && part_die
->linkage_name
!= NULL
)
14535 demangled
= gdb_demangle (part_die
->linkage_name
, DMGL_TYPES
);
14540 /* Strip any leading namespaces/classes, keep only the base name.
14541 DW_AT_name for named DIEs does not contain the prefixes. */
14542 base
= strrchr (demangled
, ':');
14543 if (base
&& base
> demangled
&& base
[-1] == ':')
14548 part_die
->name
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
14549 base
, strlen (base
));
14554 part_die
->fixup_called
= 1;
14557 /* Read an attribute value described by an attribute form. */
14559 static const gdb_byte
*
14560 read_attribute_value (const struct die_reader_specs
*reader
,
14561 struct attribute
*attr
, unsigned form
,
14562 const gdb_byte
*info_ptr
)
14564 struct dwarf2_cu
*cu
= reader
->cu
;
14565 bfd
*abfd
= reader
->abfd
;
14566 struct comp_unit_head
*cu_header
= &cu
->header
;
14567 unsigned int bytes_read
;
14568 struct dwarf_block
*blk
;
14573 case DW_FORM_ref_addr
:
14574 if (cu
->header
.version
== 2)
14575 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
14577 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
14578 &cu
->header
, &bytes_read
);
14579 info_ptr
+= bytes_read
;
14581 case DW_FORM_GNU_ref_alt
:
14582 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
14583 info_ptr
+= bytes_read
;
14586 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
14587 info_ptr
+= bytes_read
;
14589 case DW_FORM_block2
:
14590 blk
= dwarf_alloc_block (cu
);
14591 blk
->size
= read_2_bytes (abfd
, info_ptr
);
14593 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
14594 info_ptr
+= blk
->size
;
14595 DW_BLOCK (attr
) = blk
;
14597 case DW_FORM_block4
:
14598 blk
= dwarf_alloc_block (cu
);
14599 blk
->size
= read_4_bytes (abfd
, info_ptr
);
14601 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
14602 info_ptr
+= blk
->size
;
14603 DW_BLOCK (attr
) = blk
;
14605 case DW_FORM_data2
:
14606 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
14609 case DW_FORM_data4
:
14610 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
14613 case DW_FORM_data8
:
14614 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
14617 case DW_FORM_sec_offset
:
14618 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
14619 info_ptr
+= bytes_read
;
14621 case DW_FORM_string
:
14622 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
14623 DW_STRING_IS_CANONICAL (attr
) = 0;
14624 info_ptr
+= bytes_read
;
14627 if (!cu
->per_cu
->is_dwz
)
14629 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
14631 DW_STRING_IS_CANONICAL (attr
) = 0;
14632 info_ptr
+= bytes_read
;
14636 case DW_FORM_GNU_strp_alt
:
14638 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
14639 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
14642 DW_STRING (attr
) = read_indirect_string_from_dwz (dwz
, str_offset
);
14643 DW_STRING_IS_CANONICAL (attr
) = 0;
14644 info_ptr
+= bytes_read
;
14647 case DW_FORM_exprloc
:
14648 case DW_FORM_block
:
14649 blk
= dwarf_alloc_block (cu
);
14650 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14651 info_ptr
+= bytes_read
;
14652 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
14653 info_ptr
+= blk
->size
;
14654 DW_BLOCK (attr
) = blk
;
14656 case DW_FORM_block1
:
14657 blk
= dwarf_alloc_block (cu
);
14658 blk
->size
= read_1_byte (abfd
, info_ptr
);
14660 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
14661 info_ptr
+= blk
->size
;
14662 DW_BLOCK (attr
) = blk
;
14664 case DW_FORM_data1
:
14665 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
14669 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
14672 case DW_FORM_flag_present
:
14673 DW_UNSND (attr
) = 1;
14675 case DW_FORM_sdata
:
14676 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
14677 info_ptr
+= bytes_read
;
14679 case DW_FORM_udata
:
14680 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14681 info_ptr
+= bytes_read
;
14684 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14685 + read_1_byte (abfd
, info_ptr
));
14689 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14690 + read_2_bytes (abfd
, info_ptr
));
14694 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14695 + read_4_bytes (abfd
, info_ptr
));
14699 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14700 + read_8_bytes (abfd
, info_ptr
));
14703 case DW_FORM_ref_sig8
:
14704 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
14707 case DW_FORM_ref_udata
:
14708 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14709 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
14710 info_ptr
+= bytes_read
;
14712 case DW_FORM_indirect
:
14713 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14714 info_ptr
+= bytes_read
;
14715 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
14717 case DW_FORM_GNU_addr_index
:
14718 if (reader
->dwo_file
== NULL
)
14720 /* For now flag a hard error.
14721 Later we can turn this into a complaint. */
14722 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
14723 dwarf_form_name (form
),
14724 bfd_get_filename (abfd
));
14726 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
14727 info_ptr
+= bytes_read
;
14729 case DW_FORM_GNU_str_index
:
14730 if (reader
->dwo_file
== NULL
)
14732 /* For now flag a hard error.
14733 Later we can turn this into a complaint if warranted. */
14734 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
14735 dwarf_form_name (form
),
14736 bfd_get_filename (abfd
));
14739 ULONGEST str_index
=
14740 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14742 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
14743 DW_STRING_IS_CANONICAL (attr
) = 0;
14744 info_ptr
+= bytes_read
;
14748 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
14749 dwarf_form_name (form
),
14750 bfd_get_filename (abfd
));
14754 if (cu
->per_cu
->is_dwz
&& is_ref_attr (attr
))
14755 attr
->form
= DW_FORM_GNU_ref_alt
;
14757 /* We have seen instances where the compiler tried to emit a byte
14758 size attribute of -1 which ended up being encoded as an unsigned
14759 0xffffffff. Although 0xffffffff is technically a valid size value,
14760 an object of this size seems pretty unlikely so we can relatively
14761 safely treat these cases as if the size attribute was invalid and
14762 treat them as zero by default. */
14763 if (attr
->name
== DW_AT_byte_size
14764 && form
== DW_FORM_data4
14765 && DW_UNSND (attr
) >= 0xffffffff)
14768 (&symfile_complaints
,
14769 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
14770 hex_string (DW_UNSND (attr
)));
14771 DW_UNSND (attr
) = 0;
14777 /* Read an attribute described by an abbreviated attribute. */
14779 static const gdb_byte
*
14780 read_attribute (const struct die_reader_specs
*reader
,
14781 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
14782 const gdb_byte
*info_ptr
)
14784 attr
->name
= abbrev
->name
;
14785 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
14788 /* Read dwarf information from a buffer. */
14790 static unsigned int
14791 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
14793 return bfd_get_8 (abfd
, buf
);
14797 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
14799 return bfd_get_signed_8 (abfd
, buf
);
14802 static unsigned int
14803 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14805 return bfd_get_16 (abfd
, buf
);
14809 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14811 return bfd_get_signed_16 (abfd
, buf
);
14814 static unsigned int
14815 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14817 return bfd_get_32 (abfd
, buf
);
14821 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14823 return bfd_get_signed_32 (abfd
, buf
);
14827 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14829 return bfd_get_64 (abfd
, buf
);
14833 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
14834 unsigned int *bytes_read
)
14836 struct comp_unit_head
*cu_header
= &cu
->header
;
14837 CORE_ADDR retval
= 0;
14839 if (cu_header
->signed_addr_p
)
14841 switch (cu_header
->addr_size
)
14844 retval
= bfd_get_signed_16 (abfd
, buf
);
14847 retval
= bfd_get_signed_32 (abfd
, buf
);
14850 retval
= bfd_get_signed_64 (abfd
, buf
);
14853 internal_error (__FILE__
, __LINE__
,
14854 _("read_address: bad switch, signed [in module %s]"),
14855 bfd_get_filename (abfd
));
14860 switch (cu_header
->addr_size
)
14863 retval
= bfd_get_16 (abfd
, buf
);
14866 retval
= bfd_get_32 (abfd
, buf
);
14869 retval
= bfd_get_64 (abfd
, buf
);
14872 internal_error (__FILE__
, __LINE__
,
14873 _("read_address: bad switch, "
14874 "unsigned [in module %s]"),
14875 bfd_get_filename (abfd
));
14879 *bytes_read
= cu_header
->addr_size
;
14883 /* Read the initial length from a section. The (draft) DWARF 3
14884 specification allows the initial length to take up either 4 bytes
14885 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
14886 bytes describe the length and all offsets will be 8 bytes in length
14889 An older, non-standard 64-bit format is also handled by this
14890 function. The older format in question stores the initial length
14891 as an 8-byte quantity without an escape value. Lengths greater
14892 than 2^32 aren't very common which means that the initial 4 bytes
14893 is almost always zero. Since a length value of zero doesn't make
14894 sense for the 32-bit format, this initial zero can be considered to
14895 be an escape value which indicates the presence of the older 64-bit
14896 format. As written, the code can't detect (old format) lengths
14897 greater than 4GB. If it becomes necessary to handle lengths
14898 somewhat larger than 4GB, we could allow other small values (such
14899 as the non-sensical values of 1, 2, and 3) to also be used as
14900 escape values indicating the presence of the old format.
14902 The value returned via bytes_read should be used to increment the
14903 relevant pointer after calling read_initial_length().
14905 [ Note: read_initial_length() and read_offset() are based on the
14906 document entitled "DWARF Debugging Information Format", revision
14907 3, draft 8, dated November 19, 2001. This document was obtained
14910 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
14912 This document is only a draft and is subject to change. (So beware.)
14914 Details regarding the older, non-standard 64-bit format were
14915 determined empirically by examining 64-bit ELF files produced by
14916 the SGI toolchain on an IRIX 6.5 machine.
14918 - Kevin, July 16, 2002
14922 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
14924 LONGEST length
= bfd_get_32 (abfd
, buf
);
14926 if (length
== 0xffffffff)
14928 length
= bfd_get_64 (abfd
, buf
+ 4);
14931 else if (length
== 0)
14933 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
14934 length
= bfd_get_64 (abfd
, buf
);
14945 /* Cover function for read_initial_length.
14946 Returns the length of the object at BUF, and stores the size of the
14947 initial length in *BYTES_READ and stores the size that offsets will be in
14949 If the initial length size is not equivalent to that specified in
14950 CU_HEADER then issue a complaint.
14951 This is useful when reading non-comp-unit headers. */
14954 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
14955 const struct comp_unit_head
*cu_header
,
14956 unsigned int *bytes_read
,
14957 unsigned int *offset_size
)
14959 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
14961 gdb_assert (cu_header
->initial_length_size
== 4
14962 || cu_header
->initial_length_size
== 8
14963 || cu_header
->initial_length_size
== 12);
14965 if (cu_header
->initial_length_size
!= *bytes_read
)
14966 complaint (&symfile_complaints
,
14967 _("intermixed 32-bit and 64-bit DWARF sections"));
14969 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
14973 /* Read an offset from the data stream. The size of the offset is
14974 given by cu_header->offset_size. */
14977 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
14978 const struct comp_unit_head
*cu_header
,
14979 unsigned int *bytes_read
)
14981 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
14983 *bytes_read
= cu_header
->offset_size
;
14987 /* Read an offset from the data stream. */
14990 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
14992 LONGEST retval
= 0;
14994 switch (offset_size
)
14997 retval
= bfd_get_32 (abfd
, buf
);
15000 retval
= bfd_get_64 (abfd
, buf
);
15003 internal_error (__FILE__
, __LINE__
,
15004 _("read_offset_1: bad switch [in module %s]"),
15005 bfd_get_filename (abfd
));
15011 static const gdb_byte
*
15012 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
15014 /* If the size of a host char is 8 bits, we can return a pointer
15015 to the buffer, otherwise we have to copy the data to a buffer
15016 allocated on the temporary obstack. */
15017 gdb_assert (HOST_CHAR_BIT
== 8);
15021 static const char *
15022 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
15023 unsigned int *bytes_read_ptr
)
15025 /* If the size of a host char is 8 bits, we can return a pointer
15026 to the string, otherwise we have to copy the string to a buffer
15027 allocated on the temporary obstack. */
15028 gdb_assert (HOST_CHAR_BIT
== 8);
15031 *bytes_read_ptr
= 1;
15034 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
15035 return (const char *) buf
;
15038 static const char *
15039 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
15041 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
15042 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
15043 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
15044 bfd_get_filename (abfd
));
15045 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
15046 error (_("DW_FORM_strp pointing outside of "
15047 ".debug_str section [in module %s]"),
15048 bfd_get_filename (abfd
));
15049 gdb_assert (HOST_CHAR_BIT
== 8);
15050 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
15052 return (const char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
15055 /* Read a string at offset STR_OFFSET in the .debug_str section from
15056 the .dwz file DWZ. Throw an error if the offset is too large. If
15057 the string consists of a single NUL byte, return NULL; otherwise
15058 return a pointer to the string. */
15060 static const char *
15061 read_indirect_string_from_dwz (struct dwz_file
*dwz
, LONGEST str_offset
)
15063 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwz
->str
);
15065 if (dwz
->str
.buffer
== NULL
)
15066 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
15067 "section [in module %s]"),
15068 bfd_get_filename (dwz
->dwz_bfd
));
15069 if (str_offset
>= dwz
->str
.size
)
15070 error (_("DW_FORM_GNU_strp_alt pointing outside of "
15071 ".debug_str section [in module %s]"),
15072 bfd_get_filename (dwz
->dwz_bfd
));
15073 gdb_assert (HOST_CHAR_BIT
== 8);
15074 if (dwz
->str
.buffer
[str_offset
] == '\0')
15076 return (const char *) (dwz
->str
.buffer
+ str_offset
);
15079 static const char *
15080 read_indirect_string (bfd
*abfd
, const gdb_byte
*buf
,
15081 const struct comp_unit_head
*cu_header
,
15082 unsigned int *bytes_read_ptr
)
15084 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
15086 return read_indirect_string_at_offset (abfd
, str_offset
);
15090 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
15091 unsigned int *bytes_read_ptr
)
15094 unsigned int num_read
;
15096 unsigned char byte
;
15104 byte
= bfd_get_8 (abfd
, buf
);
15107 result
|= ((ULONGEST
) (byte
& 127) << shift
);
15108 if ((byte
& 128) == 0)
15114 *bytes_read_ptr
= num_read
;
15119 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
15120 unsigned int *bytes_read_ptr
)
15123 int i
, shift
, num_read
;
15124 unsigned char byte
;
15132 byte
= bfd_get_8 (abfd
, buf
);
15135 result
|= ((LONGEST
) (byte
& 127) << shift
);
15137 if ((byte
& 128) == 0)
15142 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
15143 result
|= -(((LONGEST
) 1) << shift
);
15144 *bytes_read_ptr
= num_read
;
15148 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
15149 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
15150 ADDR_SIZE is the size of addresses from the CU header. */
15153 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
15155 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15156 bfd
*abfd
= objfile
->obfd
;
15157 const gdb_byte
*info_ptr
;
15159 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
15160 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
15161 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
15163 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
15164 error (_("DW_FORM_addr_index pointing outside of "
15165 ".debug_addr section [in module %s]"),
15167 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
15168 + addr_base
+ addr_index
* addr_size
);
15169 if (addr_size
== 4)
15170 return bfd_get_32 (abfd
, info_ptr
);
15172 return bfd_get_64 (abfd
, info_ptr
);
15175 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
15178 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
15180 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
15183 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
15186 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
15187 unsigned int *bytes_read
)
15189 bfd
*abfd
= cu
->objfile
->obfd
;
15190 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
15192 return read_addr_index (cu
, addr_index
);
15195 /* Data structure to pass results from dwarf2_read_addr_index_reader
15196 back to dwarf2_read_addr_index. */
15198 struct dwarf2_read_addr_index_data
15200 ULONGEST addr_base
;
15204 /* die_reader_func for dwarf2_read_addr_index. */
15207 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
15208 const gdb_byte
*info_ptr
,
15209 struct die_info
*comp_unit_die
,
15213 struct dwarf2_cu
*cu
= reader
->cu
;
15214 struct dwarf2_read_addr_index_data
*aidata
=
15215 (struct dwarf2_read_addr_index_data
*) data
;
15217 aidata
->addr_base
= cu
->addr_base
;
15218 aidata
->addr_size
= cu
->header
.addr_size
;
15221 /* Given an index in .debug_addr, fetch the value.
15222 NOTE: This can be called during dwarf expression evaluation,
15223 long after the debug information has been read, and thus per_cu->cu
15224 may no longer exist. */
15227 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
15228 unsigned int addr_index
)
15230 struct objfile
*objfile
= per_cu
->objfile
;
15231 struct dwarf2_cu
*cu
= per_cu
->cu
;
15232 ULONGEST addr_base
;
15235 /* This is intended to be called from outside this file. */
15236 dw2_setup (objfile
);
15238 /* We need addr_base and addr_size.
15239 If we don't have PER_CU->cu, we have to get it.
15240 Nasty, but the alternative is storing the needed info in PER_CU,
15241 which at this point doesn't seem justified: it's not clear how frequently
15242 it would get used and it would increase the size of every PER_CU.
15243 Entry points like dwarf2_per_cu_addr_size do a similar thing
15244 so we're not in uncharted territory here.
15245 Alas we need to be a bit more complicated as addr_base is contained
15248 We don't need to read the entire CU(/TU).
15249 We just need the header and top level die.
15251 IWBN to use the aging mechanism to let us lazily later discard the CU.
15252 For now we skip this optimization. */
15256 addr_base
= cu
->addr_base
;
15257 addr_size
= cu
->header
.addr_size
;
15261 struct dwarf2_read_addr_index_data aidata
;
15263 /* Note: We can't use init_cutu_and_read_dies_simple here,
15264 we need addr_base. */
15265 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
15266 dwarf2_read_addr_index_reader
, &aidata
);
15267 addr_base
= aidata
.addr_base
;
15268 addr_size
= aidata
.addr_size
;
15271 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
15274 /* Given a DW_AT_str_index, fetch the string. */
15276 static const char *
15277 read_str_index (const struct die_reader_specs
*reader
,
15278 struct dwarf2_cu
*cu
, ULONGEST str_index
)
15280 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15281 const char *dwo_name
= objfile
->name
;
15282 bfd
*abfd
= objfile
->obfd
;
15283 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
15284 const gdb_byte
*info_ptr
;
15285 ULONGEST str_offset
;
15287 dwarf2_read_section (objfile
, §ions
->str
);
15288 dwarf2_read_section (objfile
, §ions
->str_offsets
);
15289 if (sections
->str
.buffer
== NULL
)
15290 error (_("DW_FORM_str_index used without .debug_str.dwo section"
15291 " in CU at offset 0x%lx [in module %s]"),
15292 (long) cu
->header
.offset
.sect_off
, dwo_name
);
15293 if (sections
->str_offsets
.buffer
== NULL
)
15294 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
15295 " in CU at offset 0x%lx [in module %s]"),
15296 (long) cu
->header
.offset
.sect_off
, dwo_name
);
15297 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
15298 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
15299 " section in CU at offset 0x%lx [in module %s]"),
15300 (long) cu
->header
.offset
.sect_off
, dwo_name
);
15301 info_ptr
= (sections
->str_offsets
.buffer
15302 + str_index
* cu
->header
.offset_size
);
15303 if (cu
->header
.offset_size
== 4)
15304 str_offset
= bfd_get_32 (abfd
, info_ptr
);
15306 str_offset
= bfd_get_64 (abfd
, info_ptr
);
15307 if (str_offset
>= sections
->str
.size
)
15308 error (_("Offset from DW_FORM_str_index pointing outside of"
15309 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
15310 (long) cu
->header
.offset
.sect_off
, dwo_name
);
15311 return (const char *) (sections
->str
.buffer
+ str_offset
);
15314 /* Return the length of an LEB128 number in BUF. */
15317 leb128_size (const gdb_byte
*buf
)
15319 const gdb_byte
*begin
= buf
;
15325 if ((byte
& 128) == 0)
15326 return buf
- begin
;
15331 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
15339 cu
->language
= language_c
;
15341 case DW_LANG_C_plus_plus
:
15342 cu
->language
= language_cplus
;
15345 cu
->language
= language_d
;
15347 case DW_LANG_Fortran77
:
15348 case DW_LANG_Fortran90
:
15349 case DW_LANG_Fortran95
:
15350 cu
->language
= language_fortran
;
15353 cu
->language
= language_go
;
15355 case DW_LANG_Mips_Assembler
:
15356 cu
->language
= language_asm
;
15359 cu
->language
= language_java
;
15361 case DW_LANG_Ada83
:
15362 case DW_LANG_Ada95
:
15363 cu
->language
= language_ada
;
15365 case DW_LANG_Modula2
:
15366 cu
->language
= language_m2
;
15368 case DW_LANG_Pascal83
:
15369 cu
->language
= language_pascal
;
15372 cu
->language
= language_objc
;
15374 case DW_LANG_Cobol74
:
15375 case DW_LANG_Cobol85
:
15377 cu
->language
= language_minimal
;
15380 cu
->language_defn
= language_def (cu
->language
);
15383 /* Return the named attribute or NULL if not there. */
15385 static struct attribute
*
15386 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
15391 struct attribute
*spec
= NULL
;
15393 for (i
= 0; i
< die
->num_attrs
; ++i
)
15395 if (die
->attrs
[i
].name
== name
)
15396 return &die
->attrs
[i
];
15397 if (die
->attrs
[i
].name
== DW_AT_specification
15398 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
15399 spec
= &die
->attrs
[i
];
15405 die
= follow_die_ref (die
, spec
, &cu
);
15411 /* Return the named attribute or NULL if not there,
15412 but do not follow DW_AT_specification, etc.
15413 This is for use in contexts where we're reading .debug_types dies.
15414 Following DW_AT_specification, DW_AT_abstract_origin will take us
15415 back up the chain, and we want to go down. */
15417 static struct attribute
*
15418 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
15422 for (i
= 0; i
< die
->num_attrs
; ++i
)
15423 if (die
->attrs
[i
].name
== name
)
15424 return &die
->attrs
[i
];
15429 /* Return non-zero iff the attribute NAME is defined for the given DIE,
15430 and holds a non-zero value. This function should only be used for
15431 DW_FORM_flag or DW_FORM_flag_present attributes. */
15434 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
15436 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
15438 return (attr
&& DW_UNSND (attr
));
15442 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
15444 /* A DIE is a declaration if it has a DW_AT_declaration attribute
15445 which value is non-zero. However, we have to be careful with
15446 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
15447 (via dwarf2_flag_true_p) follows this attribute. So we may
15448 end up accidently finding a declaration attribute that belongs
15449 to a different DIE referenced by the specification attribute,
15450 even though the given DIE does not have a declaration attribute. */
15451 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
15452 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
15455 /* Return the die giving the specification for DIE, if there is
15456 one. *SPEC_CU is the CU containing DIE on input, and the CU
15457 containing the return value on output. If there is no
15458 specification, but there is an abstract origin, that is
15461 static struct die_info
*
15462 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
15464 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
15467 if (spec_attr
== NULL
)
15468 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
15470 if (spec_attr
== NULL
)
15473 return follow_die_ref (die
, spec_attr
, spec_cu
);
15476 /* Free the line_header structure *LH, and any arrays and strings it
15478 NOTE: This is also used as a "cleanup" function. */
15481 free_line_header (struct line_header
*lh
)
15483 if (lh
->standard_opcode_lengths
)
15484 xfree (lh
->standard_opcode_lengths
);
15486 /* Remember that all the lh->file_names[i].name pointers are
15487 pointers into debug_line_buffer, and don't need to be freed. */
15488 if (lh
->file_names
)
15489 xfree (lh
->file_names
);
15491 /* Similarly for the include directory names. */
15492 if (lh
->include_dirs
)
15493 xfree (lh
->include_dirs
);
15498 /* Add an entry to LH's include directory table. */
15501 add_include_dir (struct line_header
*lh
, const char *include_dir
)
15503 /* Grow the array if necessary. */
15504 if (lh
->include_dirs_size
== 0)
15506 lh
->include_dirs_size
= 1; /* for testing */
15507 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
15508 * sizeof (*lh
->include_dirs
));
15510 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
15512 lh
->include_dirs_size
*= 2;
15513 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
15514 (lh
->include_dirs_size
15515 * sizeof (*lh
->include_dirs
)));
15518 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
15521 /* Add an entry to LH's file name table. */
15524 add_file_name (struct line_header
*lh
,
15526 unsigned int dir_index
,
15527 unsigned int mod_time
,
15528 unsigned int length
)
15530 struct file_entry
*fe
;
15532 /* Grow the array if necessary. */
15533 if (lh
->file_names_size
== 0)
15535 lh
->file_names_size
= 1; /* for testing */
15536 lh
->file_names
= xmalloc (lh
->file_names_size
15537 * sizeof (*lh
->file_names
));
15539 else if (lh
->num_file_names
>= lh
->file_names_size
)
15541 lh
->file_names_size
*= 2;
15542 lh
->file_names
= xrealloc (lh
->file_names
,
15543 (lh
->file_names_size
15544 * sizeof (*lh
->file_names
)));
15547 fe
= &lh
->file_names
[lh
->num_file_names
++];
15549 fe
->dir_index
= dir_index
;
15550 fe
->mod_time
= mod_time
;
15551 fe
->length
= length
;
15552 fe
->included_p
= 0;
15556 /* A convenience function to find the proper .debug_line section for a
15559 static struct dwarf2_section_info
*
15560 get_debug_line_section (struct dwarf2_cu
*cu
)
15562 struct dwarf2_section_info
*section
;
15564 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
15566 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
15567 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
15568 else if (cu
->per_cu
->is_dwz
)
15570 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
15572 section
= &dwz
->line
;
15575 section
= &dwarf2_per_objfile
->line
;
15580 /* Read the statement program header starting at OFFSET in
15581 .debug_line, or .debug_line.dwo. Return a pointer
15582 to a struct line_header, allocated using xmalloc.
15584 NOTE: the strings in the include directory and file name tables of
15585 the returned object point into the dwarf line section buffer,
15586 and must not be freed. */
15588 static struct line_header
*
15589 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
15591 struct cleanup
*back_to
;
15592 struct line_header
*lh
;
15593 const gdb_byte
*line_ptr
;
15594 unsigned int bytes_read
, offset_size
;
15596 const char *cur_dir
, *cur_file
;
15597 struct dwarf2_section_info
*section
;
15600 section
= get_debug_line_section (cu
);
15601 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
15602 if (section
->buffer
== NULL
)
15604 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
15605 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
15607 complaint (&symfile_complaints
, _("missing .debug_line section"));
15611 /* We can't do this until we know the section is non-empty.
15612 Only then do we know we have such a section. */
15613 abfd
= section
->asection
->owner
;
15615 /* Make sure that at least there's room for the total_length field.
15616 That could be 12 bytes long, but we're just going to fudge that. */
15617 if (offset
+ 4 >= section
->size
)
15619 dwarf2_statement_list_fits_in_line_number_section_complaint ();
15623 lh
= xmalloc (sizeof (*lh
));
15624 memset (lh
, 0, sizeof (*lh
));
15625 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
15628 line_ptr
= section
->buffer
+ offset
;
15630 /* Read in the header. */
15632 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
15633 &bytes_read
, &offset_size
);
15634 line_ptr
+= bytes_read
;
15635 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
15637 dwarf2_statement_list_fits_in_line_number_section_complaint ();
15640 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
15641 lh
->version
= read_2_bytes (abfd
, line_ptr
);
15643 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
15644 line_ptr
+= offset_size
;
15645 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
15647 if (lh
->version
>= 4)
15649 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
15653 lh
->maximum_ops_per_instruction
= 1;
15655 if (lh
->maximum_ops_per_instruction
== 0)
15657 lh
->maximum_ops_per_instruction
= 1;
15658 complaint (&symfile_complaints
,
15659 _("invalid maximum_ops_per_instruction "
15660 "in `.debug_line' section"));
15663 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
15665 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
15667 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
15669 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
15671 lh
->standard_opcode_lengths
15672 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
15674 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
15675 for (i
= 1; i
< lh
->opcode_base
; ++i
)
15677 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
15681 /* Read directory table. */
15682 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
15684 line_ptr
+= bytes_read
;
15685 add_include_dir (lh
, cur_dir
);
15687 line_ptr
+= bytes_read
;
15689 /* Read file name table. */
15690 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
15692 unsigned int dir_index
, mod_time
, length
;
15694 line_ptr
+= bytes_read
;
15695 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15696 line_ptr
+= bytes_read
;
15697 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15698 line_ptr
+= bytes_read
;
15699 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15700 line_ptr
+= bytes_read
;
15702 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
15704 line_ptr
+= bytes_read
;
15705 lh
->statement_program_start
= line_ptr
;
15707 if (line_ptr
> (section
->buffer
+ section
->size
))
15708 complaint (&symfile_complaints
,
15709 _("line number info header doesn't "
15710 "fit in `.debug_line' section"));
15712 discard_cleanups (back_to
);
15716 /* Subroutine of dwarf_decode_lines to simplify it.
15717 Return the file name of the psymtab for included file FILE_INDEX
15718 in line header LH of PST.
15719 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
15720 If space for the result is malloc'd, it will be freed by a cleanup.
15721 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename.
15723 The function creates dangling cleanup registration. */
15725 static const char *
15726 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
15727 const struct partial_symtab
*pst
,
15728 const char *comp_dir
)
15730 const struct file_entry fe
= lh
->file_names
[file_index
];
15731 const char *include_name
= fe
.name
;
15732 const char *include_name_to_compare
= include_name
;
15733 const char *dir_name
= NULL
;
15734 const char *pst_filename
;
15735 char *copied_name
= NULL
;
15739 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
15741 if (!IS_ABSOLUTE_PATH (include_name
)
15742 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
15744 /* Avoid creating a duplicate psymtab for PST.
15745 We do this by comparing INCLUDE_NAME and PST_FILENAME.
15746 Before we do the comparison, however, we need to account
15747 for DIR_NAME and COMP_DIR.
15748 First prepend dir_name (if non-NULL). If we still don't
15749 have an absolute path prepend comp_dir (if non-NULL).
15750 However, the directory we record in the include-file's
15751 psymtab does not contain COMP_DIR (to match the
15752 corresponding symtab(s)).
15757 bash$ gcc -g ./hello.c
15758 include_name = "hello.c"
15760 DW_AT_comp_dir = comp_dir = "/tmp"
15761 DW_AT_name = "./hello.c" */
15763 if (dir_name
!= NULL
)
15765 char *tem
= concat (dir_name
, SLASH_STRING
,
15766 include_name
, (char *)NULL
);
15768 make_cleanup (xfree
, tem
);
15769 include_name
= tem
;
15770 include_name_to_compare
= include_name
;
15772 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
15774 char *tem
= concat (comp_dir
, SLASH_STRING
,
15775 include_name
, (char *)NULL
);
15777 make_cleanup (xfree
, tem
);
15778 include_name_to_compare
= tem
;
15782 pst_filename
= pst
->filename
;
15783 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
15785 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
15786 pst_filename
, (char *)NULL
);
15787 pst_filename
= copied_name
;
15790 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
15792 if (copied_name
!= NULL
)
15793 xfree (copied_name
);
15797 return include_name
;
15800 /* Ignore this record_line request. */
15803 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
15808 /* Subroutine of dwarf_decode_lines to simplify it.
15809 Process the line number information in LH. */
15812 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
15813 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
15815 const gdb_byte
*line_ptr
, *extended_end
;
15816 const gdb_byte
*line_end
;
15817 unsigned int bytes_read
, extended_len
;
15818 unsigned char op_code
, extended_op
, adj_opcode
;
15819 CORE_ADDR baseaddr
;
15820 struct objfile
*objfile
= cu
->objfile
;
15821 bfd
*abfd
= objfile
->obfd
;
15822 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15823 const int decode_for_pst_p
= (pst
!= NULL
);
15824 struct subfile
*last_subfile
= NULL
;
15825 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
15828 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15830 line_ptr
= lh
->statement_program_start
;
15831 line_end
= lh
->statement_program_end
;
15833 /* Read the statement sequences until there's nothing left. */
15834 while (line_ptr
< line_end
)
15836 /* state machine registers */
15837 CORE_ADDR address
= 0;
15838 unsigned int file
= 1;
15839 unsigned int line
= 1;
15840 unsigned int column
= 0;
15841 int is_stmt
= lh
->default_is_stmt
;
15842 int basic_block
= 0;
15843 int end_sequence
= 0;
15845 unsigned char op_index
= 0;
15847 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
15849 /* Start a subfile for the current file of the state machine. */
15850 /* lh->include_dirs and lh->file_names are 0-based, but the
15851 directory and file name numbers in the statement program
15853 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
15854 const char *dir
= NULL
;
15857 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15859 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
15862 /* Decode the table. */
15863 while (!end_sequence
)
15865 op_code
= read_1_byte (abfd
, line_ptr
);
15867 if (line_ptr
> line_end
)
15869 dwarf2_debug_line_missing_end_sequence_complaint ();
15873 if (op_code
>= lh
->opcode_base
)
15875 /* Special operand. */
15876 adj_opcode
= op_code
- lh
->opcode_base
;
15877 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
15878 / lh
->maximum_ops_per_instruction
)
15879 * lh
->minimum_instruction_length
);
15880 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
15881 % lh
->maximum_ops_per_instruction
);
15882 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
15883 if (lh
->num_file_names
< file
|| file
== 0)
15884 dwarf2_debug_line_missing_file_complaint ();
15885 /* For now we ignore lines not starting on an
15886 instruction boundary. */
15887 else if (op_index
== 0)
15889 lh
->file_names
[file
- 1].included_p
= 1;
15890 if (!decode_for_pst_p
&& is_stmt
)
15892 if (last_subfile
!= current_subfile
)
15894 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15896 (*p_record_line
) (last_subfile
, 0, addr
);
15897 last_subfile
= current_subfile
;
15899 /* Append row to matrix using current values. */
15900 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15901 (*p_record_line
) (current_subfile
, line
, addr
);
15906 else switch (op_code
)
15908 case DW_LNS_extended_op
:
15909 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
15911 line_ptr
+= bytes_read
;
15912 extended_end
= line_ptr
+ extended_len
;
15913 extended_op
= read_1_byte (abfd
, line_ptr
);
15915 switch (extended_op
)
15917 case DW_LNE_end_sequence
:
15918 p_record_line
= record_line
;
15921 case DW_LNE_set_address
:
15922 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
15924 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
15926 /* This line table is for a function which has been
15927 GCd by the linker. Ignore it. PR gdb/12528 */
15930 = line_ptr
- get_debug_line_section (cu
)->buffer
;
15932 complaint (&symfile_complaints
,
15933 _(".debug_line address at offset 0x%lx is 0 "
15935 line_offset
, objfile
->name
);
15936 p_record_line
= noop_record_line
;
15940 line_ptr
+= bytes_read
;
15941 address
+= baseaddr
;
15943 case DW_LNE_define_file
:
15945 const char *cur_file
;
15946 unsigned int dir_index
, mod_time
, length
;
15948 cur_file
= read_direct_string (abfd
, line_ptr
,
15950 line_ptr
+= bytes_read
;
15952 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15953 line_ptr
+= bytes_read
;
15955 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15956 line_ptr
+= bytes_read
;
15958 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15959 line_ptr
+= bytes_read
;
15960 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
15963 case DW_LNE_set_discriminator
:
15964 /* The discriminator is not interesting to the debugger;
15966 line_ptr
= extended_end
;
15969 complaint (&symfile_complaints
,
15970 _("mangled .debug_line section"));
15973 /* Make sure that we parsed the extended op correctly. If e.g.
15974 we expected a different address size than the producer used,
15975 we may have read the wrong number of bytes. */
15976 if (line_ptr
!= extended_end
)
15978 complaint (&symfile_complaints
,
15979 _("mangled .debug_line section"));
15984 if (lh
->num_file_names
< file
|| file
== 0)
15985 dwarf2_debug_line_missing_file_complaint ();
15988 lh
->file_names
[file
- 1].included_p
= 1;
15989 if (!decode_for_pst_p
&& is_stmt
)
15991 if (last_subfile
!= current_subfile
)
15993 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15995 (*p_record_line
) (last_subfile
, 0, addr
);
15996 last_subfile
= current_subfile
;
15998 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15999 (*p_record_line
) (current_subfile
, line
, addr
);
16004 case DW_LNS_advance_pc
:
16007 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
16009 address
+= (((op_index
+ adjust
)
16010 / lh
->maximum_ops_per_instruction
)
16011 * lh
->minimum_instruction_length
);
16012 op_index
= ((op_index
+ adjust
)
16013 % lh
->maximum_ops_per_instruction
);
16014 line_ptr
+= bytes_read
;
16017 case DW_LNS_advance_line
:
16018 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
16019 line_ptr
+= bytes_read
;
16021 case DW_LNS_set_file
:
16023 /* The arrays lh->include_dirs and lh->file_names are
16024 0-based, but the directory and file name numbers in
16025 the statement program are 1-based. */
16026 struct file_entry
*fe
;
16027 const char *dir
= NULL
;
16029 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
16030 line_ptr
+= bytes_read
;
16031 if (lh
->num_file_names
< file
|| file
== 0)
16032 dwarf2_debug_line_missing_file_complaint ();
16035 fe
= &lh
->file_names
[file
- 1];
16037 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
16038 if (!decode_for_pst_p
)
16040 last_subfile
= current_subfile
;
16041 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
16046 case DW_LNS_set_column
:
16047 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
16048 line_ptr
+= bytes_read
;
16050 case DW_LNS_negate_stmt
:
16051 is_stmt
= (!is_stmt
);
16053 case DW_LNS_set_basic_block
:
16056 /* Add to the address register of the state machine the
16057 address increment value corresponding to special opcode
16058 255. I.e., this value is scaled by the minimum
16059 instruction length since special opcode 255 would have
16060 scaled the increment. */
16061 case DW_LNS_const_add_pc
:
16063 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
16065 address
+= (((op_index
+ adjust
)
16066 / lh
->maximum_ops_per_instruction
)
16067 * lh
->minimum_instruction_length
);
16068 op_index
= ((op_index
+ adjust
)
16069 % lh
->maximum_ops_per_instruction
);
16072 case DW_LNS_fixed_advance_pc
:
16073 address
+= read_2_bytes (abfd
, line_ptr
);
16079 /* Unknown standard opcode, ignore it. */
16082 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
16084 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
16085 line_ptr
+= bytes_read
;
16090 if (lh
->num_file_names
< file
|| file
== 0)
16091 dwarf2_debug_line_missing_file_complaint ();
16094 lh
->file_names
[file
- 1].included_p
= 1;
16095 if (!decode_for_pst_p
)
16097 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
16098 (*p_record_line
) (current_subfile
, 0, addr
);
16104 /* Decode the Line Number Program (LNP) for the given line_header
16105 structure and CU. The actual information extracted and the type
16106 of structures created from the LNP depends on the value of PST.
16108 1. If PST is NULL, then this procedure uses the data from the program
16109 to create all necessary symbol tables, and their linetables.
16111 2. If PST is not NULL, this procedure reads the program to determine
16112 the list of files included by the unit represented by PST, and
16113 builds all the associated partial symbol tables.
16115 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
16116 It is used for relative paths in the line table.
16117 NOTE: When processing partial symtabs (pst != NULL),
16118 comp_dir == pst->dirname.
16120 NOTE: It is important that psymtabs have the same file name (via strcmp)
16121 as the corresponding symtab. Since COMP_DIR is not used in the name of the
16122 symtab we don't use it in the name of the psymtabs we create.
16123 E.g. expand_line_sal requires this when finding psymtabs to expand.
16124 A good testcase for this is mb-inline.exp. */
16127 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
16128 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
16129 int want_line_info
)
16131 struct objfile
*objfile
= cu
->objfile
;
16132 const int decode_for_pst_p
= (pst
!= NULL
);
16133 struct subfile
*first_subfile
= current_subfile
;
16135 if (want_line_info
)
16136 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
16138 if (decode_for_pst_p
)
16142 /* Now that we're done scanning the Line Header Program, we can
16143 create the psymtab of each included file. */
16144 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
16145 if (lh
->file_names
[file_index
].included_p
== 1)
16147 const char *include_name
=
16148 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
16149 if (include_name
!= NULL
)
16150 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
16155 /* Make sure a symtab is created for every file, even files
16156 which contain only variables (i.e. no code with associated
16160 for (i
= 0; i
< lh
->num_file_names
; i
++)
16162 const char *dir
= NULL
;
16163 struct file_entry
*fe
;
16165 fe
= &lh
->file_names
[i
];
16167 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
16168 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
16170 /* Skip the main file; we don't need it, and it must be
16171 allocated last, so that it will show up before the
16172 non-primary symtabs in the objfile's symtab list. */
16173 if (current_subfile
== first_subfile
)
16176 if (current_subfile
->symtab
== NULL
)
16177 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
16179 fe
->symtab
= current_subfile
->symtab
;
16184 /* Start a subfile for DWARF. FILENAME is the name of the file and
16185 DIRNAME the name of the source directory which contains FILENAME
16186 or NULL if not known. COMP_DIR is the compilation directory for the
16187 linetable's compilation unit or NULL if not known.
16188 This routine tries to keep line numbers from identical absolute and
16189 relative file names in a common subfile.
16191 Using the `list' example from the GDB testsuite, which resides in
16192 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
16193 of /srcdir/list0.c yields the following debugging information for list0.c:
16195 DW_AT_name: /srcdir/list0.c
16196 DW_AT_comp_dir: /compdir
16197 files.files[0].name: list0.h
16198 files.files[0].dir: /srcdir
16199 files.files[1].name: list0.c
16200 files.files[1].dir: /srcdir
16202 The line number information for list0.c has to end up in a single
16203 subfile, so that `break /srcdir/list0.c:1' works as expected.
16204 start_subfile will ensure that this happens provided that we pass the
16205 concatenation of files.files[1].dir and files.files[1].name as the
16209 dwarf2_start_subfile (const char *filename
, const char *dirname
,
16210 const char *comp_dir
)
16214 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
16215 `start_symtab' will always pass the contents of DW_AT_comp_dir as
16216 second argument to start_subfile. To be consistent, we do the
16217 same here. In order not to lose the line information directory,
16218 we concatenate it to the filename when it makes sense.
16219 Note that the Dwarf3 standard says (speaking of filenames in line
16220 information): ``The directory index is ignored for file names
16221 that represent full path names''. Thus ignoring dirname in the
16222 `else' branch below isn't an issue. */
16224 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
16226 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
16230 start_subfile (filename
, comp_dir
);
16236 /* Start a symtab for DWARF.
16237 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
16240 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
16241 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
16243 start_symtab (name
, comp_dir
, low_pc
);
16244 record_debugformat ("DWARF 2");
16245 record_producer (cu
->producer
);
16247 /* We assume that we're processing GCC output. */
16248 processing_gcc_compilation
= 2;
16250 cu
->processing_has_namespace_info
= 0;
16254 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
16255 struct dwarf2_cu
*cu
)
16257 struct objfile
*objfile
= cu
->objfile
;
16258 struct comp_unit_head
*cu_header
= &cu
->header
;
16260 /* NOTE drow/2003-01-30: There used to be a comment and some special
16261 code here to turn a symbol with DW_AT_external and a
16262 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
16263 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
16264 with some versions of binutils) where shared libraries could have
16265 relocations against symbols in their debug information - the
16266 minimal symbol would have the right address, but the debug info
16267 would not. It's no longer necessary, because we will explicitly
16268 apply relocations when we read in the debug information now. */
16270 /* A DW_AT_location attribute with no contents indicates that a
16271 variable has been optimized away. */
16272 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
16274 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
16278 /* Handle one degenerate form of location expression specially, to
16279 preserve GDB's previous behavior when section offsets are
16280 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
16281 then mark this symbol as LOC_STATIC. */
16283 if (attr_form_is_block (attr
)
16284 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
16285 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
16286 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
16287 && (DW_BLOCK (attr
)->size
16288 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
16290 unsigned int dummy
;
16292 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
16293 SYMBOL_VALUE_ADDRESS (sym
) =
16294 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
16296 SYMBOL_VALUE_ADDRESS (sym
) =
16297 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
16298 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
16299 fixup_symbol_section (sym
, objfile
);
16300 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
16301 SYMBOL_SECTION (sym
));
16305 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
16306 expression evaluator, and use LOC_COMPUTED only when necessary
16307 (i.e. when the value of a register or memory location is
16308 referenced, or a thread-local block, etc.). Then again, it might
16309 not be worthwhile. I'm assuming that it isn't unless performance
16310 or memory numbers show me otherwise. */
16312 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
16314 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
16315 cu
->has_loclist
= 1;
16318 /* Given a pointer to a DWARF information entry, figure out if we need
16319 to make a symbol table entry for it, and if so, create a new entry
16320 and return a pointer to it.
16321 If TYPE is NULL, determine symbol type from the die, otherwise
16322 used the passed type.
16323 If SPACE is not NULL, use it to hold the new symbol. If it is
16324 NULL, allocate a new symbol on the objfile's obstack. */
16326 static struct symbol
*
16327 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
16328 struct symbol
*space
)
16330 struct objfile
*objfile
= cu
->objfile
;
16331 struct symbol
*sym
= NULL
;
16333 struct attribute
*attr
= NULL
;
16334 struct attribute
*attr2
= NULL
;
16335 CORE_ADDR baseaddr
;
16336 struct pending
**list_to_add
= NULL
;
16338 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
16340 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16342 name
= dwarf2_name (die
, cu
);
16345 const char *linkagename
;
16346 int suppress_add
= 0;
16351 sym
= allocate_symbol (objfile
);
16352 OBJSTAT (objfile
, n_syms
++);
16354 /* Cache this symbol's name and the name's demangled form (if any). */
16355 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
16356 linkagename
= dwarf2_physname (name
, die
, cu
);
16357 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
16359 /* Fortran does not have mangling standard and the mangling does differ
16360 between gfortran, iFort etc. */
16361 if (cu
->language
== language_fortran
16362 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
16363 symbol_set_demangled_name (&(sym
->ginfo
),
16364 dwarf2_full_name (name
, die
, cu
),
16367 /* Default assumptions.
16368 Use the passed type or decode it from the die. */
16369 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
16370 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
16372 SYMBOL_TYPE (sym
) = type
;
16374 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
16375 attr
= dwarf2_attr (die
,
16376 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
16380 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
16383 attr
= dwarf2_attr (die
,
16384 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
16388 int file_index
= DW_UNSND (attr
);
16390 if (cu
->line_header
== NULL
16391 || file_index
> cu
->line_header
->num_file_names
)
16392 complaint (&symfile_complaints
,
16393 _("file index out of range"));
16394 else if (file_index
> 0)
16396 struct file_entry
*fe
;
16398 fe
= &cu
->line_header
->file_names
[file_index
- 1];
16399 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
16406 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
16409 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
16411 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
16412 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
16413 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
16414 add_symbol_to_list (sym
, cu
->list_in_scope
);
16416 case DW_TAG_subprogram
:
16417 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
16419 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
16420 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
16421 if ((attr2
&& (DW_UNSND (attr2
) != 0))
16422 || cu
->language
== language_ada
)
16424 /* Subprograms marked external are stored as a global symbol.
16425 Ada subprograms, whether marked external or not, are always
16426 stored as a global symbol, because we want to be able to
16427 access them globally. For instance, we want to be able
16428 to break on a nested subprogram without having to
16429 specify the context. */
16430 list_to_add
= &global_symbols
;
16434 list_to_add
= cu
->list_in_scope
;
16437 case DW_TAG_inlined_subroutine
:
16438 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
16440 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
16441 SYMBOL_INLINED (sym
) = 1;
16442 list_to_add
= cu
->list_in_scope
;
16444 case DW_TAG_template_value_param
:
16446 /* Fall through. */
16447 case DW_TAG_constant
:
16448 case DW_TAG_variable
:
16449 case DW_TAG_member
:
16450 /* Compilation with minimal debug info may result in
16451 variables with missing type entries. Change the
16452 misleading `void' type to something sensible. */
16453 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
16455 = objfile_type (objfile
)->nodebug_data_symbol
;
16457 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
16458 /* In the case of DW_TAG_member, we should only be called for
16459 static const members. */
16460 if (die
->tag
== DW_TAG_member
)
16462 /* dwarf2_add_field uses die_is_declaration,
16463 so we do the same. */
16464 gdb_assert (die_is_declaration (die
, cu
));
16469 dwarf2_const_value (attr
, sym
, cu
);
16470 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
16473 if (attr2
&& (DW_UNSND (attr2
) != 0))
16474 list_to_add
= &global_symbols
;
16476 list_to_add
= cu
->list_in_scope
;
16480 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16483 var_decode_location (attr
, sym
, cu
);
16484 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
16486 /* Fortran explicitly imports any global symbols to the local
16487 scope by DW_TAG_common_block. */
16488 if (cu
->language
== language_fortran
&& die
->parent
16489 && die
->parent
->tag
== DW_TAG_common_block
)
16492 if (SYMBOL_CLASS (sym
) == LOC_STATIC
16493 && SYMBOL_VALUE_ADDRESS (sym
) == 0
16494 && !dwarf2_per_objfile
->has_section_at_zero
)
16496 /* When a static variable is eliminated by the linker,
16497 the corresponding debug information is not stripped
16498 out, but the variable address is set to null;
16499 do not add such variables into symbol table. */
16501 else if (attr2
&& (DW_UNSND (attr2
) != 0))
16503 /* Workaround gfortran PR debug/40040 - it uses
16504 DW_AT_location for variables in -fPIC libraries which may
16505 get overriden by other libraries/executable and get
16506 a different address. Resolve it by the minimal symbol
16507 which may come from inferior's executable using copy
16508 relocation. Make this workaround only for gfortran as for
16509 other compilers GDB cannot guess the minimal symbol
16510 Fortran mangling kind. */
16511 if (cu
->language
== language_fortran
&& die
->parent
16512 && die
->parent
->tag
== DW_TAG_module
16514 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
16515 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
16517 /* A variable with DW_AT_external is never static,
16518 but it may be block-scoped. */
16519 list_to_add
= (cu
->list_in_scope
== &file_symbols
16520 ? &global_symbols
: cu
->list_in_scope
);
16523 list_to_add
= cu
->list_in_scope
;
16527 /* We do not know the address of this symbol.
16528 If it is an external symbol and we have type information
16529 for it, enter the symbol as a LOC_UNRESOLVED symbol.
16530 The address of the variable will then be determined from
16531 the minimal symbol table whenever the variable is
16533 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
16535 /* Fortran explicitly imports any global symbols to the local
16536 scope by DW_TAG_common_block. */
16537 if (cu
->language
== language_fortran
&& die
->parent
16538 && die
->parent
->tag
== DW_TAG_common_block
)
16540 /* SYMBOL_CLASS doesn't matter here because
16541 read_common_block is going to reset it. */
16543 list_to_add
= cu
->list_in_scope
;
16545 else if (attr2
&& (DW_UNSND (attr2
) != 0)
16546 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
16548 /* A variable with DW_AT_external is never static, but it
16549 may be block-scoped. */
16550 list_to_add
= (cu
->list_in_scope
== &file_symbols
16551 ? &global_symbols
: cu
->list_in_scope
);
16553 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
16555 else if (!die_is_declaration (die
, cu
))
16557 /* Use the default LOC_OPTIMIZED_OUT class. */
16558 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
16560 list_to_add
= cu
->list_in_scope
;
16564 case DW_TAG_formal_parameter
:
16565 /* If we are inside a function, mark this as an argument. If
16566 not, we might be looking at an argument to an inlined function
16567 when we do not have enough information to show inlined frames;
16568 pretend it's a local variable in that case so that the user can
16570 if (context_stack_depth
> 0
16571 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
16572 SYMBOL_IS_ARGUMENT (sym
) = 1;
16573 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16576 var_decode_location (attr
, sym
, cu
);
16578 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
16581 dwarf2_const_value (attr
, sym
, cu
);
16584 list_to_add
= cu
->list_in_scope
;
16586 case DW_TAG_unspecified_parameters
:
16587 /* From varargs functions; gdb doesn't seem to have any
16588 interest in this information, so just ignore it for now.
16591 case DW_TAG_template_type_param
:
16593 /* Fall through. */
16594 case DW_TAG_class_type
:
16595 case DW_TAG_interface_type
:
16596 case DW_TAG_structure_type
:
16597 case DW_TAG_union_type
:
16598 case DW_TAG_set_type
:
16599 case DW_TAG_enumeration_type
:
16600 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
16601 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
16604 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
16605 really ever be static objects: otherwise, if you try
16606 to, say, break of a class's method and you're in a file
16607 which doesn't mention that class, it won't work unless
16608 the check for all static symbols in lookup_symbol_aux
16609 saves you. See the OtherFileClass tests in
16610 gdb.c++/namespace.exp. */
16614 list_to_add
= (cu
->list_in_scope
== &file_symbols
16615 && (cu
->language
== language_cplus
16616 || cu
->language
== language_java
)
16617 ? &global_symbols
: cu
->list_in_scope
);
16619 /* The semantics of C++ state that "struct foo {
16620 ... }" also defines a typedef for "foo". A Java
16621 class declaration also defines a typedef for the
16623 if (cu
->language
== language_cplus
16624 || cu
->language
== language_java
16625 || cu
->language
== language_ada
)
16627 /* The symbol's name is already allocated along
16628 with this objfile, so we don't need to
16629 duplicate it for the type. */
16630 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
16631 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
16636 case DW_TAG_typedef
:
16637 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
16638 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
16639 list_to_add
= cu
->list_in_scope
;
16641 case DW_TAG_base_type
:
16642 case DW_TAG_subrange_type
:
16643 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
16644 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
16645 list_to_add
= cu
->list_in_scope
;
16647 case DW_TAG_enumerator
:
16648 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
16651 dwarf2_const_value (attr
, sym
, cu
);
16654 /* NOTE: carlton/2003-11-10: See comment above in the
16655 DW_TAG_class_type, etc. block. */
16657 list_to_add
= (cu
->list_in_scope
== &file_symbols
16658 && (cu
->language
== language_cplus
16659 || cu
->language
== language_java
)
16660 ? &global_symbols
: cu
->list_in_scope
);
16663 case DW_TAG_namespace
:
16664 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
16665 list_to_add
= &global_symbols
;
16667 case DW_TAG_common_block
:
16668 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
16669 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
16670 add_symbol_to_list (sym
, cu
->list_in_scope
);
16673 /* Not a tag we recognize. Hopefully we aren't processing
16674 trash data, but since we must specifically ignore things
16675 we don't recognize, there is nothing else we should do at
16677 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
16678 dwarf_tag_name (die
->tag
));
16684 sym
->hash_next
= objfile
->template_symbols
;
16685 objfile
->template_symbols
= sym
;
16686 list_to_add
= NULL
;
16689 if (list_to_add
!= NULL
)
16690 add_symbol_to_list (sym
, list_to_add
);
16692 /* For the benefit of old versions of GCC, check for anonymous
16693 namespaces based on the demangled name. */
16694 if (!cu
->processing_has_namespace_info
16695 && cu
->language
== language_cplus
)
16696 cp_scan_for_anonymous_namespaces (sym
, objfile
);
16701 /* A wrapper for new_symbol_full that always allocates a new symbol. */
16703 static struct symbol
*
16704 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
16706 return new_symbol_full (die
, type
, cu
, NULL
);
16709 /* Given an attr with a DW_FORM_dataN value in host byte order,
16710 zero-extend it as appropriate for the symbol's type. The DWARF
16711 standard (v4) is not entirely clear about the meaning of using
16712 DW_FORM_dataN for a constant with a signed type, where the type is
16713 wider than the data. The conclusion of a discussion on the DWARF
16714 list was that this is unspecified. We choose to always zero-extend
16715 because that is the interpretation long in use by GCC. */
16718 dwarf2_const_value_data (struct attribute
*attr
, struct obstack
*obstack
,
16719 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
16721 struct objfile
*objfile
= cu
->objfile
;
16722 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
16723 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
16724 LONGEST l
= DW_UNSND (attr
);
16726 if (bits
< sizeof (*value
) * 8)
16728 l
&= ((LONGEST
) 1 << bits
) - 1;
16731 else if (bits
== sizeof (*value
) * 8)
16735 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
16736 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
16743 /* Read a constant value from an attribute. Either set *VALUE, or if
16744 the value does not fit in *VALUE, set *BYTES - either already
16745 allocated on the objfile obstack, or newly allocated on OBSTACK,
16746 or, set *BATON, if we translated the constant to a location
16750 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
16751 const char *name
, struct obstack
*obstack
,
16752 struct dwarf2_cu
*cu
,
16753 LONGEST
*value
, const gdb_byte
**bytes
,
16754 struct dwarf2_locexpr_baton
**baton
)
16756 struct objfile
*objfile
= cu
->objfile
;
16757 struct comp_unit_head
*cu_header
= &cu
->header
;
16758 struct dwarf_block
*blk
;
16759 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
16760 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
16766 switch (attr
->form
)
16769 case DW_FORM_GNU_addr_index
:
16773 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
16774 dwarf2_const_value_length_mismatch_complaint (name
,
16775 cu_header
->addr_size
,
16776 TYPE_LENGTH (type
));
16777 /* Symbols of this form are reasonably rare, so we just
16778 piggyback on the existing location code rather than writing
16779 a new implementation of symbol_computed_ops. */
16780 *baton
= obstack_alloc (obstack
, sizeof (struct dwarf2_locexpr_baton
));
16781 (*baton
)->per_cu
= cu
->per_cu
;
16782 gdb_assert ((*baton
)->per_cu
);
16784 (*baton
)->size
= 2 + cu_header
->addr_size
;
16785 data
= obstack_alloc (obstack
, (*baton
)->size
);
16786 (*baton
)->data
= data
;
16788 data
[0] = DW_OP_addr
;
16789 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
16790 byte_order
, DW_ADDR (attr
));
16791 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
16794 case DW_FORM_string
:
16796 case DW_FORM_GNU_str_index
:
16797 case DW_FORM_GNU_strp_alt
:
16798 /* DW_STRING is already allocated on the objfile obstack, point
16800 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
16802 case DW_FORM_block1
:
16803 case DW_FORM_block2
:
16804 case DW_FORM_block4
:
16805 case DW_FORM_block
:
16806 case DW_FORM_exprloc
:
16807 blk
= DW_BLOCK (attr
);
16808 if (TYPE_LENGTH (type
) != blk
->size
)
16809 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
16810 TYPE_LENGTH (type
));
16811 *bytes
= blk
->data
;
16814 /* The DW_AT_const_value attributes are supposed to carry the
16815 symbol's value "represented as it would be on the target
16816 architecture." By the time we get here, it's already been
16817 converted to host endianness, so we just need to sign- or
16818 zero-extend it as appropriate. */
16819 case DW_FORM_data1
:
16820 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
16822 case DW_FORM_data2
:
16823 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
16825 case DW_FORM_data4
:
16826 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
16828 case DW_FORM_data8
:
16829 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
16832 case DW_FORM_sdata
:
16833 *value
= DW_SND (attr
);
16836 case DW_FORM_udata
:
16837 *value
= DW_UNSND (attr
);
16841 complaint (&symfile_complaints
,
16842 _("unsupported const value attribute form: '%s'"),
16843 dwarf_form_name (attr
->form
));
16850 /* Copy constant value from an attribute to a symbol. */
16853 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
16854 struct dwarf2_cu
*cu
)
16856 struct objfile
*objfile
= cu
->objfile
;
16857 struct comp_unit_head
*cu_header
= &cu
->header
;
16859 const gdb_byte
*bytes
;
16860 struct dwarf2_locexpr_baton
*baton
;
16862 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
16863 SYMBOL_PRINT_NAME (sym
),
16864 &objfile
->objfile_obstack
, cu
,
16865 &value
, &bytes
, &baton
);
16869 SYMBOL_LOCATION_BATON (sym
) = baton
;
16870 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16872 else if (bytes
!= NULL
)
16874 SYMBOL_VALUE_BYTES (sym
) = bytes
;
16875 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
16879 SYMBOL_VALUE (sym
) = value
;
16880 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
16884 /* Return the type of the die in question using its DW_AT_type attribute. */
16886 static struct type
*
16887 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16889 struct attribute
*type_attr
;
16891 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16894 /* A missing DW_AT_type represents a void type. */
16895 return objfile_type (cu
->objfile
)->builtin_void
;
16898 return lookup_die_type (die
, type_attr
, cu
);
16901 /* True iff CU's producer generates GNAT Ada auxiliary information
16902 that allows to find parallel types through that information instead
16903 of having to do expensive parallel lookups by type name. */
16906 need_gnat_info (struct dwarf2_cu
*cu
)
16908 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
16909 of GNAT produces this auxiliary information, without any indication
16910 that it is produced. Part of enhancing the FSF version of GNAT
16911 to produce that information will be to put in place an indicator
16912 that we can use in order to determine whether the descriptive type
16913 info is available or not. One suggestion that has been made is
16914 to use a new attribute, attached to the CU die. For now, assume
16915 that the descriptive type info is not available. */
16919 /* Return the auxiliary type of the die in question using its
16920 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
16921 attribute is not present. */
16923 static struct type
*
16924 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16926 struct attribute
*type_attr
;
16928 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
16932 return lookup_die_type (die
, type_attr
, cu
);
16935 /* If DIE has a descriptive_type attribute, then set the TYPE's
16936 descriptive type accordingly. */
16939 set_descriptive_type (struct type
*type
, struct die_info
*die
,
16940 struct dwarf2_cu
*cu
)
16942 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
16944 if (descriptive_type
)
16946 ALLOCATE_GNAT_AUX_TYPE (type
);
16947 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
16951 /* Return the containing type of the die in question using its
16952 DW_AT_containing_type attribute. */
16954 static struct type
*
16955 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16957 struct attribute
*type_attr
;
16959 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
16961 error (_("Dwarf Error: Problem turning containing type into gdb type "
16962 "[in module %s]"), cu
->objfile
->name
);
16964 return lookup_die_type (die
, type_attr
, cu
);
16967 /* Return an error marker type to use for the ill formed type in DIE/CU. */
16969 static struct type
*
16970 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
16972 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16973 char *message
, *saved
;
16975 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
16977 cu
->header
.offset
.sect_off
,
16978 die
->offset
.sect_off
);
16979 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
16980 message
, strlen (message
));
16983 return init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
16986 /* Look up the type of DIE in CU using its type attribute ATTR.
16987 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
16988 DW_AT_containing_type.
16989 If there is no type substitute an error marker. */
16991 static struct type
*
16992 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
16993 struct dwarf2_cu
*cu
)
16995 struct objfile
*objfile
= cu
->objfile
;
16996 struct type
*this_type
;
16998 gdb_assert (attr
->name
== DW_AT_type
16999 || attr
->name
== DW_AT_GNAT_descriptive_type
17000 || attr
->name
== DW_AT_containing_type
);
17002 /* First see if we have it cached. */
17004 if (attr
->form
== DW_FORM_GNU_ref_alt
)
17006 struct dwarf2_per_cu_data
*per_cu
;
17007 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
17009 per_cu
= dwarf2_find_containing_comp_unit (offset
, 1, cu
->objfile
);
17010 this_type
= get_die_type_at_offset (offset
, per_cu
);
17012 else if (is_ref_attr (attr
))
17014 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
17016 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
17018 else if (attr
->form
== DW_FORM_ref_sig8
)
17020 ULONGEST signature
= DW_SIGNATURE (attr
);
17022 return get_signatured_type (die
, signature
, cu
);
17026 complaint (&symfile_complaints
,
17027 _("Dwarf Error: Bad type attribute %s in DIE"
17028 " at 0x%x [in module %s]"),
17029 dwarf_attr_name (attr
->name
), die
->offset
.sect_off
,
17031 return build_error_marker_type (cu
, die
);
17034 /* If not cached we need to read it in. */
17036 if (this_type
== NULL
)
17038 struct die_info
*type_die
= NULL
;
17039 struct dwarf2_cu
*type_cu
= cu
;
17041 if (is_ref_attr (attr
))
17042 type_die
= follow_die_ref (die
, attr
, &type_cu
);
17043 if (type_die
== NULL
)
17044 return build_error_marker_type (cu
, die
);
17045 /* If we find the type now, it's probably because the type came
17046 from an inter-CU reference and the type's CU got expanded before
17048 this_type
= read_type_die (type_die
, type_cu
);
17051 /* If we still don't have a type use an error marker. */
17053 if (this_type
== NULL
)
17054 return build_error_marker_type (cu
, die
);
17059 /* Return the type in DIE, CU.
17060 Returns NULL for invalid types.
17062 This first does a lookup in die_type_hash,
17063 and only reads the die in if necessary.
17065 NOTE: This can be called when reading in partial or full symbols. */
17067 static struct type
*
17068 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
17070 struct type
*this_type
;
17072 this_type
= get_die_type (die
, cu
);
17076 return read_type_die_1 (die
, cu
);
17079 /* Read the type in DIE, CU.
17080 Returns NULL for invalid types. */
17082 static struct type
*
17083 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
17085 struct type
*this_type
= NULL
;
17089 case DW_TAG_class_type
:
17090 case DW_TAG_interface_type
:
17091 case DW_TAG_structure_type
:
17092 case DW_TAG_union_type
:
17093 this_type
= read_structure_type (die
, cu
);
17095 case DW_TAG_enumeration_type
:
17096 this_type
= read_enumeration_type (die
, cu
);
17098 case DW_TAG_subprogram
:
17099 case DW_TAG_subroutine_type
:
17100 case DW_TAG_inlined_subroutine
:
17101 this_type
= read_subroutine_type (die
, cu
);
17103 case DW_TAG_array_type
:
17104 this_type
= read_array_type (die
, cu
);
17106 case DW_TAG_set_type
:
17107 this_type
= read_set_type (die
, cu
);
17109 case DW_TAG_pointer_type
:
17110 this_type
= read_tag_pointer_type (die
, cu
);
17112 case DW_TAG_ptr_to_member_type
:
17113 this_type
= read_tag_ptr_to_member_type (die
, cu
);
17115 case DW_TAG_reference_type
:
17116 this_type
= read_tag_reference_type (die
, cu
);
17118 case DW_TAG_const_type
:
17119 this_type
= read_tag_const_type (die
, cu
);
17121 case DW_TAG_volatile_type
:
17122 this_type
= read_tag_volatile_type (die
, cu
);
17124 case DW_TAG_restrict_type
:
17125 this_type
= read_tag_restrict_type (die
, cu
);
17127 case DW_TAG_string_type
:
17128 this_type
= read_tag_string_type (die
, cu
);
17130 case DW_TAG_typedef
:
17131 this_type
= read_typedef (die
, cu
);
17133 case DW_TAG_subrange_type
:
17134 this_type
= read_subrange_type (die
, cu
);
17136 case DW_TAG_base_type
:
17137 this_type
= read_base_type (die
, cu
);
17139 case DW_TAG_unspecified_type
:
17140 this_type
= read_unspecified_type (die
, cu
);
17142 case DW_TAG_namespace
:
17143 this_type
= read_namespace_type (die
, cu
);
17145 case DW_TAG_module
:
17146 this_type
= read_module_type (die
, cu
);
17149 complaint (&symfile_complaints
,
17150 _("unexpected tag in read_type_die: '%s'"),
17151 dwarf_tag_name (die
->tag
));
17158 /* See if we can figure out if the class lives in a namespace. We do
17159 this by looking for a member function; its demangled name will
17160 contain namespace info, if there is any.
17161 Return the computed name or NULL.
17162 Space for the result is allocated on the objfile's obstack.
17163 This is the full-die version of guess_partial_die_structure_name.
17164 In this case we know DIE has no useful parent. */
17167 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
17169 struct die_info
*spec_die
;
17170 struct dwarf2_cu
*spec_cu
;
17171 struct die_info
*child
;
17174 spec_die
= die_specification (die
, &spec_cu
);
17175 if (spec_die
!= NULL
)
17181 for (child
= die
->child
;
17183 child
= child
->sibling
)
17185 if (child
->tag
== DW_TAG_subprogram
)
17187 struct attribute
*attr
;
17189 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
17191 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
17195 = language_class_name_from_physname (cu
->language_defn
,
17199 if (actual_name
!= NULL
)
17201 const char *die_name
= dwarf2_name (die
, cu
);
17203 if (die_name
!= NULL
17204 && strcmp (die_name
, actual_name
) != 0)
17206 /* Strip off the class name from the full name.
17207 We want the prefix. */
17208 int die_name_len
= strlen (die_name
);
17209 int actual_name_len
= strlen (actual_name
);
17211 /* Test for '::' as a sanity check. */
17212 if (actual_name_len
> die_name_len
+ 2
17213 && actual_name
[actual_name_len
17214 - die_name_len
- 1] == ':')
17216 obstack_copy0 (&cu
->objfile
->objfile_obstack
,
17218 actual_name_len
- die_name_len
- 2);
17221 xfree (actual_name
);
17230 /* GCC might emit a nameless typedef that has a linkage name. Determine the
17231 prefix part in such case. See
17232 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
17235 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
17237 struct attribute
*attr
;
17240 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
17241 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
17244 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
17245 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
17248 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
17250 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
17251 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
17254 /* dwarf2_name had to be already called. */
17255 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
17257 /* Strip the base name, keep any leading namespaces/classes. */
17258 base
= strrchr (DW_STRING (attr
), ':');
17259 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
17262 return obstack_copy0 (&cu
->objfile
->objfile_obstack
,
17263 DW_STRING (attr
), &base
[-1] - DW_STRING (attr
));
17266 /* Return the name of the namespace/class that DIE is defined within,
17267 or "" if we can't tell. The caller should not xfree the result.
17269 For example, if we're within the method foo() in the following
17279 then determine_prefix on foo's die will return "N::C". */
17281 static const char *
17282 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
17284 struct die_info
*parent
, *spec_die
;
17285 struct dwarf2_cu
*spec_cu
;
17286 struct type
*parent_type
;
17289 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
17290 && cu
->language
!= language_fortran
)
17293 retval
= anonymous_struct_prefix (die
, cu
);
17297 /* We have to be careful in the presence of DW_AT_specification.
17298 For example, with GCC 3.4, given the code
17302 // Definition of N::foo.
17306 then we'll have a tree of DIEs like this:
17308 1: DW_TAG_compile_unit
17309 2: DW_TAG_namespace // N
17310 3: DW_TAG_subprogram // declaration of N::foo
17311 4: DW_TAG_subprogram // definition of N::foo
17312 DW_AT_specification // refers to die #3
17314 Thus, when processing die #4, we have to pretend that we're in
17315 the context of its DW_AT_specification, namely the contex of die
17318 spec_die
= die_specification (die
, &spec_cu
);
17319 if (spec_die
== NULL
)
17320 parent
= die
->parent
;
17323 parent
= spec_die
->parent
;
17327 if (parent
== NULL
)
17329 else if (parent
->building_fullname
)
17332 const char *parent_name
;
17334 /* It has been seen on RealView 2.2 built binaries,
17335 DW_TAG_template_type_param types actually _defined_ as
17336 children of the parent class:
17339 template class <class Enum> Class{};
17340 Class<enum E> class_e;
17342 1: DW_TAG_class_type (Class)
17343 2: DW_TAG_enumeration_type (E)
17344 3: DW_TAG_enumerator (enum1:0)
17345 3: DW_TAG_enumerator (enum2:1)
17347 2: DW_TAG_template_type_param
17348 DW_AT_type DW_FORM_ref_udata (E)
17350 Besides being broken debug info, it can put GDB into an
17351 infinite loop. Consider:
17353 When we're building the full name for Class<E>, we'll start
17354 at Class, and go look over its template type parameters,
17355 finding E. We'll then try to build the full name of E, and
17356 reach here. We're now trying to build the full name of E,
17357 and look over the parent DIE for containing scope. In the
17358 broken case, if we followed the parent DIE of E, we'd again
17359 find Class, and once again go look at its template type
17360 arguments, etc., etc. Simply don't consider such parent die
17361 as source-level parent of this die (it can't be, the language
17362 doesn't allow it), and break the loop here. */
17363 name
= dwarf2_name (die
, cu
);
17364 parent_name
= dwarf2_name (parent
, cu
);
17365 complaint (&symfile_complaints
,
17366 _("template param type '%s' defined within parent '%s'"),
17367 name
? name
: "<unknown>",
17368 parent_name
? parent_name
: "<unknown>");
17372 switch (parent
->tag
)
17374 case DW_TAG_namespace
:
17375 parent_type
= read_type_die (parent
, cu
);
17376 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
17377 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
17378 Work around this problem here. */
17379 if (cu
->language
== language_cplus
17380 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
17382 /* We give a name to even anonymous namespaces. */
17383 return TYPE_TAG_NAME (parent_type
);
17384 case DW_TAG_class_type
:
17385 case DW_TAG_interface_type
:
17386 case DW_TAG_structure_type
:
17387 case DW_TAG_union_type
:
17388 case DW_TAG_module
:
17389 parent_type
= read_type_die (parent
, cu
);
17390 if (TYPE_TAG_NAME (parent_type
) != NULL
)
17391 return TYPE_TAG_NAME (parent_type
);
17393 /* An anonymous structure is only allowed non-static data
17394 members; no typedefs, no member functions, et cetera.
17395 So it does not need a prefix. */
17397 case DW_TAG_compile_unit
:
17398 case DW_TAG_partial_unit
:
17399 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
17400 if (cu
->language
== language_cplus
17401 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
17402 && die
->child
!= NULL
17403 && (die
->tag
== DW_TAG_class_type
17404 || die
->tag
== DW_TAG_structure_type
17405 || die
->tag
== DW_TAG_union_type
))
17407 char *name
= guess_full_die_structure_name (die
, cu
);
17413 return determine_prefix (parent
, cu
);
17417 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
17418 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
17419 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
17420 an obconcat, otherwise allocate storage for the result. The CU argument is
17421 used to determine the language and hence, the appropriate separator. */
17423 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
17426 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
17427 int physname
, struct dwarf2_cu
*cu
)
17429 const char *lead
= "";
17432 if (suffix
== NULL
|| suffix
[0] == '\0'
17433 || prefix
== NULL
|| prefix
[0] == '\0')
17435 else if (cu
->language
== language_java
)
17437 else if (cu
->language
== language_fortran
&& physname
)
17439 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
17440 DW_AT_MIPS_linkage_name is preferred and used instead. */
17448 if (prefix
== NULL
)
17450 if (suffix
== NULL
)
17456 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
17458 strcpy (retval
, lead
);
17459 strcat (retval
, prefix
);
17460 strcat (retval
, sep
);
17461 strcat (retval
, suffix
);
17466 /* We have an obstack. */
17467 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
17471 /* Return sibling of die, NULL if no sibling. */
17473 static struct die_info
*
17474 sibling_die (struct die_info
*die
)
17476 return die
->sibling
;
17479 /* Get name of a die, return NULL if not found. */
17481 static const char *
17482 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
17483 struct obstack
*obstack
)
17485 if (name
&& cu
->language
== language_cplus
)
17487 char *canon_name
= cp_canonicalize_string (name
);
17489 if (canon_name
!= NULL
)
17491 if (strcmp (canon_name
, name
) != 0)
17492 name
= obstack_copy0 (obstack
, canon_name
, strlen (canon_name
));
17493 xfree (canon_name
);
17500 /* Get name of a die, return NULL if not found. */
17502 static const char *
17503 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
17505 struct attribute
*attr
;
17507 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
17508 if ((!attr
|| !DW_STRING (attr
))
17509 && die
->tag
!= DW_TAG_class_type
17510 && die
->tag
!= DW_TAG_interface_type
17511 && die
->tag
!= DW_TAG_structure_type
17512 && die
->tag
!= DW_TAG_union_type
)
17517 case DW_TAG_compile_unit
:
17518 case DW_TAG_partial_unit
:
17519 /* Compilation units have a DW_AT_name that is a filename, not
17520 a source language identifier. */
17521 case DW_TAG_enumeration_type
:
17522 case DW_TAG_enumerator
:
17523 /* These tags always have simple identifiers already; no need
17524 to canonicalize them. */
17525 return DW_STRING (attr
);
17527 case DW_TAG_subprogram
:
17528 /* Java constructors will all be named "<init>", so return
17529 the class name when we see this special case. */
17530 if (cu
->language
== language_java
17531 && DW_STRING (attr
) != NULL
17532 && strcmp (DW_STRING (attr
), "<init>") == 0)
17534 struct dwarf2_cu
*spec_cu
= cu
;
17535 struct die_info
*spec_die
;
17537 /* GCJ will output '<init>' for Java constructor names.
17538 For this special case, return the name of the parent class. */
17540 /* GCJ may output suprogram DIEs with AT_specification set.
17541 If so, use the name of the specified DIE. */
17542 spec_die
= die_specification (die
, &spec_cu
);
17543 if (spec_die
!= NULL
)
17544 return dwarf2_name (spec_die
, spec_cu
);
17549 if (die
->tag
== DW_TAG_class_type
)
17550 return dwarf2_name (die
, cu
);
17552 while (die
->tag
!= DW_TAG_compile_unit
17553 && die
->tag
!= DW_TAG_partial_unit
);
17557 case DW_TAG_class_type
:
17558 case DW_TAG_interface_type
:
17559 case DW_TAG_structure_type
:
17560 case DW_TAG_union_type
:
17561 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
17562 structures or unions. These were of the form "._%d" in GCC 4.1,
17563 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
17564 and GCC 4.4. We work around this problem by ignoring these. */
17565 if (attr
&& DW_STRING (attr
)
17566 && (strncmp (DW_STRING (attr
), "._", 2) == 0
17567 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
17570 /* GCC might emit a nameless typedef that has a linkage name. See
17571 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
17572 if (!attr
|| DW_STRING (attr
) == NULL
)
17574 char *demangled
= NULL
;
17576 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
17578 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
17580 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
17583 /* Avoid demangling DW_STRING (attr) the second time on a second
17584 call for the same DIE. */
17585 if (!DW_STRING_IS_CANONICAL (attr
))
17586 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
17592 /* FIXME: we already did this for the partial symbol... */
17593 DW_STRING (attr
) = obstack_copy0 (&cu
->objfile
->objfile_obstack
,
17594 demangled
, strlen (demangled
));
17595 DW_STRING_IS_CANONICAL (attr
) = 1;
17598 /* Strip any leading namespaces/classes, keep only the base name.
17599 DW_AT_name for named DIEs does not contain the prefixes. */
17600 base
= strrchr (DW_STRING (attr
), ':');
17601 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
17604 return DW_STRING (attr
);
17613 if (!DW_STRING_IS_CANONICAL (attr
))
17616 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
17617 &cu
->objfile
->objfile_obstack
);
17618 DW_STRING_IS_CANONICAL (attr
) = 1;
17620 return DW_STRING (attr
);
17623 /* Return the die that this die in an extension of, or NULL if there
17624 is none. *EXT_CU is the CU containing DIE on input, and the CU
17625 containing the return value on output. */
17627 static struct die_info
*
17628 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
17630 struct attribute
*attr
;
17632 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
17636 return follow_die_ref (die
, attr
, ext_cu
);
17639 /* Convert a DIE tag into its string name. */
17641 static const char *
17642 dwarf_tag_name (unsigned tag
)
17644 const char *name
= get_DW_TAG_name (tag
);
17647 return "DW_TAG_<unknown>";
17652 /* Convert a DWARF attribute code into its string name. */
17654 static const char *
17655 dwarf_attr_name (unsigned attr
)
17659 #ifdef MIPS /* collides with DW_AT_HP_block_index */
17660 if (attr
== DW_AT_MIPS_fde
)
17661 return "DW_AT_MIPS_fde";
17663 if (attr
== DW_AT_HP_block_index
)
17664 return "DW_AT_HP_block_index";
17667 name
= get_DW_AT_name (attr
);
17670 return "DW_AT_<unknown>";
17675 /* Convert a DWARF value form code into its string name. */
17677 static const char *
17678 dwarf_form_name (unsigned form
)
17680 const char *name
= get_DW_FORM_name (form
);
17683 return "DW_FORM_<unknown>";
17689 dwarf_bool_name (unsigned mybool
)
17697 /* Convert a DWARF type code into its string name. */
17699 static const char *
17700 dwarf_type_encoding_name (unsigned enc
)
17702 const char *name
= get_DW_ATE_name (enc
);
17705 return "DW_ATE_<unknown>";
17711 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
17715 print_spaces (indent
, f
);
17716 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
17717 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
17719 if (die
->parent
!= NULL
)
17721 print_spaces (indent
, f
);
17722 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
17723 die
->parent
->offset
.sect_off
);
17726 print_spaces (indent
, f
);
17727 fprintf_unfiltered (f
, " has children: %s\n",
17728 dwarf_bool_name (die
->child
!= NULL
));
17730 print_spaces (indent
, f
);
17731 fprintf_unfiltered (f
, " attributes:\n");
17733 for (i
= 0; i
< die
->num_attrs
; ++i
)
17735 print_spaces (indent
, f
);
17736 fprintf_unfiltered (f
, " %s (%s) ",
17737 dwarf_attr_name (die
->attrs
[i
].name
),
17738 dwarf_form_name (die
->attrs
[i
].form
));
17740 switch (die
->attrs
[i
].form
)
17743 case DW_FORM_GNU_addr_index
:
17744 fprintf_unfiltered (f
, "address: ");
17745 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
17747 case DW_FORM_block2
:
17748 case DW_FORM_block4
:
17749 case DW_FORM_block
:
17750 case DW_FORM_block1
:
17751 fprintf_unfiltered (f
, "block: size %s",
17752 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
17754 case DW_FORM_exprloc
:
17755 fprintf_unfiltered (f
, "expression: size %s",
17756 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
17758 case DW_FORM_ref_addr
:
17759 fprintf_unfiltered (f
, "ref address: ");
17760 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
17762 case DW_FORM_GNU_ref_alt
:
17763 fprintf_unfiltered (f
, "alt ref address: ");
17764 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
17770 case DW_FORM_ref_udata
:
17771 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
17772 (long) (DW_UNSND (&die
->attrs
[i
])));
17774 case DW_FORM_data1
:
17775 case DW_FORM_data2
:
17776 case DW_FORM_data4
:
17777 case DW_FORM_data8
:
17778 case DW_FORM_udata
:
17779 case DW_FORM_sdata
:
17780 fprintf_unfiltered (f
, "constant: %s",
17781 pulongest (DW_UNSND (&die
->attrs
[i
])));
17783 case DW_FORM_sec_offset
:
17784 fprintf_unfiltered (f
, "section offset: %s",
17785 pulongest (DW_UNSND (&die
->attrs
[i
])));
17787 case DW_FORM_ref_sig8
:
17788 fprintf_unfiltered (f
, "signature: %s",
17789 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
17791 case DW_FORM_string
:
17793 case DW_FORM_GNU_str_index
:
17794 case DW_FORM_GNU_strp_alt
:
17795 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
17796 DW_STRING (&die
->attrs
[i
])
17797 ? DW_STRING (&die
->attrs
[i
]) : "",
17798 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
17801 if (DW_UNSND (&die
->attrs
[i
]))
17802 fprintf_unfiltered (f
, "flag: TRUE");
17804 fprintf_unfiltered (f
, "flag: FALSE");
17806 case DW_FORM_flag_present
:
17807 fprintf_unfiltered (f
, "flag: TRUE");
17809 case DW_FORM_indirect
:
17810 /* The reader will have reduced the indirect form to
17811 the "base form" so this form should not occur. */
17812 fprintf_unfiltered (f
,
17813 "unexpected attribute form: DW_FORM_indirect");
17816 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
17817 die
->attrs
[i
].form
);
17820 fprintf_unfiltered (f
, "\n");
17825 dump_die_for_error (struct die_info
*die
)
17827 dump_die_shallow (gdb_stderr
, 0, die
);
17831 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
17833 int indent
= level
* 4;
17835 gdb_assert (die
!= NULL
);
17837 if (level
>= max_level
)
17840 dump_die_shallow (f
, indent
, die
);
17842 if (die
->child
!= NULL
)
17844 print_spaces (indent
, f
);
17845 fprintf_unfiltered (f
, " Children:");
17846 if (level
+ 1 < max_level
)
17848 fprintf_unfiltered (f
, "\n");
17849 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
17853 fprintf_unfiltered (f
,
17854 " [not printed, max nesting level reached]\n");
17858 if (die
->sibling
!= NULL
&& level
> 0)
17860 dump_die_1 (f
, level
, max_level
, die
->sibling
);
17864 /* This is called from the pdie macro in gdbinit.in.
17865 It's not static so gcc will keep a copy callable from gdb. */
17868 dump_die (struct die_info
*die
, int max_level
)
17870 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
17874 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
17878 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
17884 /* DW_ADDR is always stored already as sect_offset; despite for the forms
17885 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
17888 is_ref_attr (struct attribute
*attr
)
17890 switch (attr
->form
)
17892 case DW_FORM_ref_addr
:
17897 case DW_FORM_ref_udata
:
17898 case DW_FORM_GNU_ref_alt
:
17905 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
17909 dwarf2_get_ref_die_offset (struct attribute
*attr
)
17911 sect_offset retval
= { DW_UNSND (attr
) };
17913 if (is_ref_attr (attr
))
17916 retval
.sect_off
= 0;
17917 complaint (&symfile_complaints
,
17918 _("unsupported die ref attribute form: '%s'"),
17919 dwarf_form_name (attr
->form
));
17923 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
17924 * the value held by the attribute is not constant. */
17927 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
17929 if (attr
->form
== DW_FORM_sdata
)
17930 return DW_SND (attr
);
17931 else if (attr
->form
== DW_FORM_udata
17932 || attr
->form
== DW_FORM_data1
17933 || attr
->form
== DW_FORM_data2
17934 || attr
->form
== DW_FORM_data4
17935 || attr
->form
== DW_FORM_data8
)
17936 return DW_UNSND (attr
);
17939 complaint (&symfile_complaints
,
17940 _("Attribute value is not a constant (%s)"),
17941 dwarf_form_name (attr
->form
));
17942 return default_value
;
17946 /* Follow reference or signature attribute ATTR of SRC_DIE.
17947 On entry *REF_CU is the CU of SRC_DIE.
17948 On exit *REF_CU is the CU of the result. */
17950 static struct die_info
*
17951 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
17952 struct dwarf2_cu
**ref_cu
)
17954 struct die_info
*die
;
17956 if (is_ref_attr (attr
))
17957 die
= follow_die_ref (src_die
, attr
, ref_cu
);
17958 else if (attr
->form
== DW_FORM_ref_sig8
)
17959 die
= follow_die_sig (src_die
, attr
, ref_cu
);
17962 dump_die_for_error (src_die
);
17963 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
17964 (*ref_cu
)->objfile
->name
);
17970 /* Follow reference OFFSET.
17971 On entry *REF_CU is the CU of the source die referencing OFFSET.
17972 On exit *REF_CU is the CU of the result.
17973 Returns NULL if OFFSET is invalid. */
17975 static struct die_info
*
17976 follow_die_offset (sect_offset offset
, int offset_in_dwz
,
17977 struct dwarf2_cu
**ref_cu
)
17979 struct die_info temp_die
;
17980 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
17982 gdb_assert (cu
->per_cu
!= NULL
);
17986 if (cu
->per_cu
->is_debug_types
)
17988 /* .debug_types CUs cannot reference anything outside their CU.
17989 If they need to, they have to reference a signatured type via
17990 DW_FORM_ref_sig8. */
17991 if (! offset_in_cu_p (&cu
->header
, offset
))
17994 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
17995 || ! offset_in_cu_p (&cu
->header
, offset
))
17997 struct dwarf2_per_cu_data
*per_cu
;
17999 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
18002 /* If necessary, add it to the queue and load its DIEs. */
18003 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
18004 load_full_comp_unit (per_cu
, cu
->language
);
18006 target_cu
= per_cu
->cu
;
18008 else if (cu
->dies
== NULL
)
18010 /* We're loading full DIEs during partial symbol reading. */
18011 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
18012 load_full_comp_unit (cu
->per_cu
, language_minimal
);
18015 *ref_cu
= target_cu
;
18016 temp_die
.offset
= offset
;
18017 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
18020 /* Follow reference attribute ATTR of SRC_DIE.
18021 On entry *REF_CU is the CU of SRC_DIE.
18022 On exit *REF_CU is the CU of the result. */
18024 static struct die_info
*
18025 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
18026 struct dwarf2_cu
**ref_cu
)
18028 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
18029 struct dwarf2_cu
*cu
= *ref_cu
;
18030 struct die_info
*die
;
18032 die
= follow_die_offset (offset
,
18033 (attr
->form
== DW_FORM_GNU_ref_alt
18034 || cu
->per_cu
->is_dwz
),
18037 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
18038 "at 0x%x [in module %s]"),
18039 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
18044 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
18045 Returned value is intended for DW_OP_call*. Returned
18046 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
18048 struct dwarf2_locexpr_baton
18049 dwarf2_fetch_die_loc_sect_off (sect_offset offset
,
18050 struct dwarf2_per_cu_data
*per_cu
,
18051 CORE_ADDR (*get_frame_pc
) (void *baton
),
18054 struct dwarf2_cu
*cu
;
18055 struct die_info
*die
;
18056 struct attribute
*attr
;
18057 struct dwarf2_locexpr_baton retval
;
18059 dw2_setup (per_cu
->objfile
);
18061 if (per_cu
->cu
== NULL
)
18065 die
= follow_die_offset (offset
, per_cu
->is_dwz
, &cu
);
18067 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
18068 offset
.sect_off
, per_cu
->objfile
->name
);
18070 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
18073 /* DWARF: "If there is no such attribute, then there is no effect.".
18074 DATA is ignored if SIZE is 0. */
18076 retval
.data
= NULL
;
18079 else if (attr_form_is_section_offset (attr
))
18081 struct dwarf2_loclist_baton loclist_baton
;
18082 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
18085 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
18087 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
18089 retval
.size
= size
;
18093 if (!attr_form_is_block (attr
))
18094 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
18095 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
18096 offset
.sect_off
, per_cu
->objfile
->name
);
18098 retval
.data
= DW_BLOCK (attr
)->data
;
18099 retval
.size
= DW_BLOCK (attr
)->size
;
18101 retval
.per_cu
= cu
->per_cu
;
18103 age_cached_comp_units ();
18108 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
18111 struct dwarf2_locexpr_baton
18112 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
18113 struct dwarf2_per_cu_data
*per_cu
,
18114 CORE_ADDR (*get_frame_pc
) (void *baton
),
18117 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
18119 return dwarf2_fetch_die_loc_sect_off (offset
, per_cu
, get_frame_pc
, baton
);
18122 /* Write a constant of a given type as target-ordered bytes into
18125 static const gdb_byte
*
18126 write_constant_as_bytes (struct obstack
*obstack
,
18127 enum bfd_endian byte_order
,
18134 *len
= TYPE_LENGTH (type
);
18135 result
= obstack_alloc (obstack
, *len
);
18136 store_unsigned_integer (result
, *len
, byte_order
, value
);
18141 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
18142 pointer to the constant bytes and set LEN to the length of the
18143 data. If memory is needed, allocate it on OBSTACK. If the DIE
18144 does not have a DW_AT_const_value, return NULL. */
18147 dwarf2_fetch_constant_bytes (sect_offset offset
,
18148 struct dwarf2_per_cu_data
*per_cu
,
18149 struct obstack
*obstack
,
18152 struct dwarf2_cu
*cu
;
18153 struct die_info
*die
;
18154 struct attribute
*attr
;
18155 const gdb_byte
*result
= NULL
;
18158 enum bfd_endian byte_order
;
18160 dw2_setup (per_cu
->objfile
);
18162 if (per_cu
->cu
== NULL
)
18166 die
= follow_die_offset (offset
, per_cu
->is_dwz
, &cu
);
18168 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
18169 offset
.sect_off
, per_cu
->objfile
->name
);
18172 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
18176 byte_order
= (bfd_big_endian (per_cu
->objfile
->obfd
)
18177 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
18179 switch (attr
->form
)
18182 case DW_FORM_GNU_addr_index
:
18186 *len
= cu
->header
.addr_size
;
18187 tem
= obstack_alloc (obstack
, *len
);
18188 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
18192 case DW_FORM_string
:
18194 case DW_FORM_GNU_str_index
:
18195 case DW_FORM_GNU_strp_alt
:
18196 /* DW_STRING is already allocated on the objfile obstack, point
18198 result
= (const gdb_byte
*) DW_STRING (attr
);
18199 *len
= strlen (DW_STRING (attr
));
18201 case DW_FORM_block1
:
18202 case DW_FORM_block2
:
18203 case DW_FORM_block4
:
18204 case DW_FORM_block
:
18205 case DW_FORM_exprloc
:
18206 result
= DW_BLOCK (attr
)->data
;
18207 *len
= DW_BLOCK (attr
)->size
;
18210 /* The DW_AT_const_value attributes are supposed to carry the
18211 symbol's value "represented as it would be on the target
18212 architecture." By the time we get here, it's already been
18213 converted to host endianness, so we just need to sign- or
18214 zero-extend it as appropriate. */
18215 case DW_FORM_data1
:
18216 type
= die_type (die
, cu
);
18217 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
18218 if (result
== NULL
)
18219 result
= write_constant_as_bytes (obstack
, byte_order
,
18222 case DW_FORM_data2
:
18223 type
= die_type (die
, cu
);
18224 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
18225 if (result
== NULL
)
18226 result
= write_constant_as_bytes (obstack
, byte_order
,
18229 case DW_FORM_data4
:
18230 type
= die_type (die
, cu
);
18231 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
18232 if (result
== NULL
)
18233 result
= write_constant_as_bytes (obstack
, byte_order
,
18236 case DW_FORM_data8
:
18237 type
= die_type (die
, cu
);
18238 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
18239 if (result
== NULL
)
18240 result
= write_constant_as_bytes (obstack
, byte_order
,
18244 case DW_FORM_sdata
:
18245 type
= die_type (die
, cu
);
18246 result
= write_constant_as_bytes (obstack
, byte_order
,
18247 type
, DW_SND (attr
), len
);
18250 case DW_FORM_udata
:
18251 type
= die_type (die
, cu
);
18252 result
= write_constant_as_bytes (obstack
, byte_order
,
18253 type
, DW_UNSND (attr
), len
);
18257 complaint (&symfile_complaints
,
18258 _("unsupported const value attribute form: '%s'"),
18259 dwarf_form_name (attr
->form
));
18266 /* Return the type of the DIE at DIE_OFFSET in the CU named by
18270 dwarf2_get_die_type (cu_offset die_offset
,
18271 struct dwarf2_per_cu_data
*per_cu
)
18273 sect_offset die_offset_sect
;
18275 dw2_setup (per_cu
->objfile
);
18277 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
18278 return get_die_type_at_offset (die_offset_sect
, per_cu
);
18281 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
18282 On entry *REF_CU is the CU of SRC_DIE.
18283 On exit *REF_CU is the CU of the result.
18284 Returns NULL if the referenced DIE isn't found. */
18286 static struct die_info
*
18287 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
18288 struct dwarf2_cu
**ref_cu
)
18290 struct objfile
*objfile
= (*ref_cu
)->objfile
;
18291 struct die_info temp_die
;
18292 struct dwarf2_cu
*sig_cu
;
18293 struct die_info
*die
;
18295 /* While it might be nice to assert sig_type->type == NULL here,
18296 we can get here for DW_AT_imported_declaration where we need
18297 the DIE not the type. */
18299 /* If necessary, add it to the queue and load its DIEs. */
18301 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
18302 read_signatured_type (sig_type
);
18304 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
18306 sig_cu
= sig_type
->per_cu
.cu
;
18307 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
18308 temp_die
.offset
= sig_type
->type_offset_in_section
;
18309 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
18310 temp_die
.offset
.sect_off
);
18313 /* For .gdb_index version 7 keep track of included TUs.
18314 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
18315 if (dwarf2_per_objfile
->index_table
!= NULL
18316 && dwarf2_per_objfile
->index_table
->version
<= 7)
18318 VEC_safe_push (dwarf2_per_cu_ptr
,
18319 (*ref_cu
)->per_cu
->imported_symtabs
,
18330 /* Follow signatured type referenced by ATTR in SRC_DIE.
18331 On entry *REF_CU is the CU of SRC_DIE.
18332 On exit *REF_CU is the CU of the result.
18333 The result is the DIE of the type.
18334 If the referenced type cannot be found an error is thrown. */
18336 static struct die_info
*
18337 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
18338 struct dwarf2_cu
**ref_cu
)
18340 ULONGEST signature
= DW_SIGNATURE (attr
);
18341 struct signatured_type
*sig_type
;
18342 struct die_info
*die
;
18344 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
18346 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
18347 /* sig_type will be NULL if the signatured type is missing from
18349 if (sig_type
== NULL
)
18351 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
18352 " from DIE at 0x%x [in module %s]"),
18353 hex_string (signature
), src_die
->offset
.sect_off
,
18354 (*ref_cu
)->objfile
->name
);
18357 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
18360 dump_die_for_error (src_die
);
18361 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
18362 " from DIE at 0x%x [in module %s]"),
18363 hex_string (signature
), src_die
->offset
.sect_off
,
18364 (*ref_cu
)->objfile
->name
);
18370 /* Get the type specified by SIGNATURE referenced in DIE/CU,
18371 reading in and processing the type unit if necessary. */
18373 static struct type
*
18374 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
18375 struct dwarf2_cu
*cu
)
18377 struct signatured_type
*sig_type
;
18378 struct dwarf2_cu
*type_cu
;
18379 struct die_info
*type_die
;
18382 sig_type
= lookup_signatured_type (cu
, signature
);
18383 /* sig_type will be NULL if the signatured type is missing from
18385 if (sig_type
== NULL
)
18387 complaint (&symfile_complaints
,
18388 _("Dwarf Error: Cannot find signatured DIE %s referenced"
18389 " from DIE at 0x%x [in module %s]"),
18390 hex_string (signature
), die
->offset
.sect_off
,
18391 dwarf2_per_objfile
->objfile
->name
);
18392 return build_error_marker_type (cu
, die
);
18395 /* If we already know the type we're done. */
18396 if (sig_type
->type
!= NULL
)
18397 return sig_type
->type
;
18400 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
18401 if (type_die
!= NULL
)
18403 /* N.B. We need to call get_die_type to ensure only one type for this DIE
18404 is created. This is important, for example, because for c++ classes
18405 we need TYPE_NAME set which is only done by new_symbol. Blech. */
18406 type
= read_type_die (type_die
, type_cu
);
18409 complaint (&symfile_complaints
,
18410 _("Dwarf Error: Cannot build signatured type %s"
18411 " referenced from DIE at 0x%x [in module %s]"),
18412 hex_string (signature
), die
->offset
.sect_off
,
18413 dwarf2_per_objfile
->objfile
->name
);
18414 type
= build_error_marker_type (cu
, die
);
18419 complaint (&symfile_complaints
,
18420 _("Dwarf Error: Problem reading signatured DIE %s referenced"
18421 " from DIE at 0x%x [in module %s]"),
18422 hex_string (signature
), die
->offset
.sect_off
,
18423 dwarf2_per_objfile
->objfile
->name
);
18424 type
= build_error_marker_type (cu
, die
);
18426 sig_type
->type
= type
;
18431 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
18432 reading in and processing the type unit if necessary. */
18434 static struct type
*
18435 get_DW_AT_signature_type (struct die_info
*die
, struct attribute
*attr
,
18436 struct dwarf2_cu
*cu
) /* ARI: editCase function */
18438 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
18439 if (is_ref_attr (attr
))
18441 struct dwarf2_cu
*type_cu
= cu
;
18442 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
18444 return read_type_die (type_die
, type_cu
);
18446 else if (attr
->form
== DW_FORM_ref_sig8
)
18448 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
18452 complaint (&symfile_complaints
,
18453 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
18454 " at 0x%x [in module %s]"),
18455 dwarf_form_name (attr
->form
), die
->offset
.sect_off
,
18456 dwarf2_per_objfile
->objfile
->name
);
18457 return build_error_marker_type (cu
, die
);
18461 /* Load the DIEs associated with type unit PER_CU into memory. */
18464 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
18466 struct signatured_type
*sig_type
;
18468 /* Caller is responsible for ensuring type_unit_groups don't get here. */
18469 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
18471 /* We have the per_cu, but we need the signatured_type.
18472 Fortunately this is an easy translation. */
18473 gdb_assert (per_cu
->is_debug_types
);
18474 sig_type
= (struct signatured_type
*) per_cu
;
18476 gdb_assert (per_cu
->cu
== NULL
);
18478 read_signatured_type (sig_type
);
18480 gdb_assert (per_cu
->cu
!= NULL
);
18483 /* die_reader_func for read_signatured_type.
18484 This is identical to load_full_comp_unit_reader,
18485 but is kept separate for now. */
18488 read_signatured_type_reader (const struct die_reader_specs
*reader
,
18489 const gdb_byte
*info_ptr
,
18490 struct die_info
*comp_unit_die
,
18494 struct dwarf2_cu
*cu
= reader
->cu
;
18496 gdb_assert (cu
->die_hash
== NULL
);
18498 htab_create_alloc_ex (cu
->header
.length
/ 12,
18502 &cu
->comp_unit_obstack
,
18503 hashtab_obstack_allocate
,
18504 dummy_obstack_deallocate
);
18507 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
18508 &info_ptr
, comp_unit_die
);
18509 cu
->dies
= comp_unit_die
;
18510 /* comp_unit_die is not stored in die_hash, no need. */
18512 /* We try not to read any attributes in this function, because not
18513 all CUs needed for references have been loaded yet, and symbol
18514 table processing isn't initialized. But we have to set the CU language,
18515 or we won't be able to build types correctly.
18516 Similarly, if we do not read the producer, we can not apply
18517 producer-specific interpretation. */
18518 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
18521 /* Read in a signatured type and build its CU and DIEs.
18522 If the type is a stub for the real type in a DWO file,
18523 read in the real type from the DWO file as well. */
18526 read_signatured_type (struct signatured_type
*sig_type
)
18528 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
18530 gdb_assert (per_cu
->is_debug_types
);
18531 gdb_assert (per_cu
->cu
== NULL
);
18533 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
18534 read_signatured_type_reader
, NULL
);
18537 /* Decode simple location descriptions.
18538 Given a pointer to a dwarf block that defines a location, compute
18539 the location and return the value.
18541 NOTE drow/2003-11-18: This function is called in two situations
18542 now: for the address of static or global variables (partial symbols
18543 only) and for offsets into structures which are expected to be
18544 (more or less) constant. The partial symbol case should go away,
18545 and only the constant case should remain. That will let this
18546 function complain more accurately. A few special modes are allowed
18547 without complaint for global variables (for instance, global
18548 register values and thread-local values).
18550 A location description containing no operations indicates that the
18551 object is optimized out. The return value is 0 for that case.
18552 FIXME drow/2003-11-16: No callers check for this case any more; soon all
18553 callers will only want a very basic result and this can become a
18556 Note that stack[0] is unused except as a default error return. */
18559 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
18561 struct objfile
*objfile
= cu
->objfile
;
18563 size_t size
= blk
->size
;
18564 const gdb_byte
*data
= blk
->data
;
18565 CORE_ADDR stack
[64];
18567 unsigned int bytes_read
, unsnd
;
18573 stack
[++stacki
] = 0;
18612 stack
[++stacki
] = op
- DW_OP_lit0
;
18647 stack
[++stacki
] = op
- DW_OP_reg0
;
18649 dwarf2_complex_location_expr_complaint ();
18653 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
18655 stack
[++stacki
] = unsnd
;
18657 dwarf2_complex_location_expr_complaint ();
18661 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
18666 case DW_OP_const1u
:
18667 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
18671 case DW_OP_const1s
:
18672 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
18676 case DW_OP_const2u
:
18677 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
18681 case DW_OP_const2s
:
18682 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
18686 case DW_OP_const4u
:
18687 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
18691 case DW_OP_const4s
:
18692 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
18696 case DW_OP_const8u
:
18697 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
18702 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
18708 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
18713 stack
[stacki
+ 1] = stack
[stacki
];
18718 stack
[stacki
- 1] += stack
[stacki
];
18722 case DW_OP_plus_uconst
:
18723 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
18729 stack
[stacki
- 1] -= stack
[stacki
];
18734 /* If we're not the last op, then we definitely can't encode
18735 this using GDB's address_class enum. This is valid for partial
18736 global symbols, although the variable's address will be bogus
18739 dwarf2_complex_location_expr_complaint ();
18742 case DW_OP_GNU_push_tls_address
:
18743 /* The top of the stack has the offset from the beginning
18744 of the thread control block at which the variable is located. */
18745 /* Nothing should follow this operator, so the top of stack would
18747 /* This is valid for partial global symbols, but the variable's
18748 address will be bogus in the psymtab. Make it always at least
18749 non-zero to not look as a variable garbage collected by linker
18750 which have DW_OP_addr 0. */
18752 dwarf2_complex_location_expr_complaint ();
18756 case DW_OP_GNU_uninit
:
18759 case DW_OP_GNU_addr_index
:
18760 case DW_OP_GNU_const_index
:
18761 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
18768 const char *name
= get_DW_OP_name (op
);
18771 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
18774 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
18778 return (stack
[stacki
]);
18781 /* Enforce maximum stack depth of SIZE-1 to avoid writing
18782 outside of the allocated space. Also enforce minimum>0. */
18783 if (stacki
>= ARRAY_SIZE (stack
) - 1)
18785 complaint (&symfile_complaints
,
18786 _("location description stack overflow"));
18792 complaint (&symfile_complaints
,
18793 _("location description stack underflow"));
18797 return (stack
[stacki
]);
18800 /* memory allocation interface */
18802 static struct dwarf_block
*
18803 dwarf_alloc_block (struct dwarf2_cu
*cu
)
18805 struct dwarf_block
*blk
;
18807 blk
= (struct dwarf_block
*)
18808 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
18812 static struct die_info
*
18813 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
18815 struct die_info
*die
;
18816 size_t size
= sizeof (struct die_info
);
18819 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
18821 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
18822 memset (die
, 0, sizeof (struct die_info
));
18827 /* Macro support. */
18829 /* Return file name relative to the compilation directory of file number I in
18830 *LH's file name table. The result is allocated using xmalloc; the caller is
18831 responsible for freeing it. */
18834 file_file_name (int file
, struct line_header
*lh
)
18836 /* Is the file number a valid index into the line header's file name
18837 table? Remember that file numbers start with one, not zero. */
18838 if (1 <= file
&& file
<= lh
->num_file_names
)
18840 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
18842 if (IS_ABSOLUTE_PATH (fe
->name
) || fe
->dir_index
== 0)
18843 return xstrdup (fe
->name
);
18844 return concat (lh
->include_dirs
[fe
->dir_index
- 1], SLASH_STRING
,
18849 /* The compiler produced a bogus file number. We can at least
18850 record the macro definitions made in the file, even if we
18851 won't be able to find the file by name. */
18852 char fake_name
[80];
18854 xsnprintf (fake_name
, sizeof (fake_name
),
18855 "<bad macro file number %d>", file
);
18857 complaint (&symfile_complaints
,
18858 _("bad file number in macro information (%d)"),
18861 return xstrdup (fake_name
);
18865 /* Return the full name of file number I in *LH's file name table.
18866 Use COMP_DIR as the name of the current directory of the
18867 compilation. The result is allocated using xmalloc; the caller is
18868 responsible for freeing it. */
18870 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
18872 /* Is the file number a valid index into the line header's file name
18873 table? Remember that file numbers start with one, not zero. */
18874 if (1 <= file
&& file
<= lh
->num_file_names
)
18876 char *relative
= file_file_name (file
, lh
);
18878 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
18880 return reconcat (relative
, comp_dir
, SLASH_STRING
, relative
, NULL
);
18883 return file_file_name (file
, lh
);
18887 static struct macro_source_file
*
18888 macro_start_file (int file
, int line
,
18889 struct macro_source_file
*current_file
,
18890 const char *comp_dir
,
18891 struct line_header
*lh
, struct objfile
*objfile
)
18893 /* File name relative to the compilation directory of this source file. */
18894 char *file_name
= file_file_name (file
, lh
);
18896 /* We don't create a macro table for this compilation unit
18897 at all until we actually get a filename. */
18898 if (! pending_macros
)
18899 pending_macros
= new_macro_table (&objfile
->per_bfd
->storage_obstack
,
18900 objfile
->per_bfd
->macro_cache
,
18903 if (! current_file
)
18905 /* If we have no current file, then this must be the start_file
18906 directive for the compilation unit's main source file. */
18907 current_file
= macro_set_main (pending_macros
, file_name
);
18908 macro_define_special (pending_macros
);
18911 current_file
= macro_include (current_file
, line
, file_name
);
18915 return current_file
;
18919 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
18920 followed by a null byte. */
18922 copy_string (const char *buf
, int len
)
18924 char *s
= xmalloc (len
+ 1);
18926 memcpy (s
, buf
, len
);
18932 static const char *
18933 consume_improper_spaces (const char *p
, const char *body
)
18937 complaint (&symfile_complaints
,
18938 _("macro definition contains spaces "
18939 "in formal argument list:\n`%s'"),
18951 parse_macro_definition (struct macro_source_file
*file
, int line
,
18956 /* The body string takes one of two forms. For object-like macro
18957 definitions, it should be:
18959 <macro name> " " <definition>
18961 For function-like macro definitions, it should be:
18963 <macro name> "() " <definition>
18965 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
18967 Spaces may appear only where explicitly indicated, and in the
18970 The Dwarf 2 spec says that an object-like macro's name is always
18971 followed by a space, but versions of GCC around March 2002 omit
18972 the space when the macro's definition is the empty string.
18974 The Dwarf 2 spec says that there should be no spaces between the
18975 formal arguments in a function-like macro's formal argument list,
18976 but versions of GCC around March 2002 include spaces after the
18980 /* Find the extent of the macro name. The macro name is terminated
18981 by either a space or null character (for an object-like macro) or
18982 an opening paren (for a function-like macro). */
18983 for (p
= body
; *p
; p
++)
18984 if (*p
== ' ' || *p
== '(')
18987 if (*p
== ' ' || *p
== '\0')
18989 /* It's an object-like macro. */
18990 int name_len
= p
- body
;
18991 char *name
= copy_string (body
, name_len
);
18992 const char *replacement
;
18995 replacement
= body
+ name_len
+ 1;
18998 dwarf2_macro_malformed_definition_complaint (body
);
18999 replacement
= body
+ name_len
;
19002 macro_define_object (file
, line
, name
, replacement
);
19006 else if (*p
== '(')
19008 /* It's a function-like macro. */
19009 char *name
= copy_string (body
, p
- body
);
19012 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
19016 p
= consume_improper_spaces (p
, body
);
19018 /* Parse the formal argument list. */
19019 while (*p
&& *p
!= ')')
19021 /* Find the extent of the current argument name. */
19022 const char *arg_start
= p
;
19024 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
19027 if (! *p
|| p
== arg_start
)
19028 dwarf2_macro_malformed_definition_complaint (body
);
19031 /* Make sure argv has room for the new argument. */
19032 if (argc
>= argv_size
)
19035 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
19038 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
19041 p
= consume_improper_spaces (p
, body
);
19043 /* Consume the comma, if present. */
19048 p
= consume_improper_spaces (p
, body
);
19057 /* Perfectly formed definition, no complaints. */
19058 macro_define_function (file
, line
, name
,
19059 argc
, (const char **) argv
,
19061 else if (*p
== '\0')
19063 /* Complain, but do define it. */
19064 dwarf2_macro_malformed_definition_complaint (body
);
19065 macro_define_function (file
, line
, name
,
19066 argc
, (const char **) argv
,
19070 /* Just complain. */
19071 dwarf2_macro_malformed_definition_complaint (body
);
19074 /* Just complain. */
19075 dwarf2_macro_malformed_definition_complaint (body
);
19081 for (i
= 0; i
< argc
; i
++)
19087 dwarf2_macro_malformed_definition_complaint (body
);
19090 /* Skip some bytes from BYTES according to the form given in FORM.
19091 Returns the new pointer. */
19093 static const gdb_byte
*
19094 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
19095 enum dwarf_form form
,
19096 unsigned int offset_size
,
19097 struct dwarf2_section_info
*section
)
19099 unsigned int bytes_read
;
19103 case DW_FORM_data1
:
19108 case DW_FORM_data2
:
19112 case DW_FORM_data4
:
19116 case DW_FORM_data8
:
19120 case DW_FORM_string
:
19121 read_direct_string (abfd
, bytes
, &bytes_read
);
19122 bytes
+= bytes_read
;
19125 case DW_FORM_sec_offset
:
19127 case DW_FORM_GNU_strp_alt
:
19128 bytes
+= offset_size
;
19131 case DW_FORM_block
:
19132 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
19133 bytes
+= bytes_read
;
19136 case DW_FORM_block1
:
19137 bytes
+= 1 + read_1_byte (abfd
, bytes
);
19139 case DW_FORM_block2
:
19140 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
19142 case DW_FORM_block4
:
19143 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
19146 case DW_FORM_sdata
:
19147 case DW_FORM_udata
:
19148 case DW_FORM_GNU_addr_index
:
19149 case DW_FORM_GNU_str_index
:
19150 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
19153 dwarf2_section_buffer_overflow_complaint (section
);
19161 complaint (&symfile_complaints
,
19162 _("invalid form 0x%x in `%s'"),
19164 section
->asection
->name
);
19172 /* A helper for dwarf_decode_macros that handles skipping an unknown
19173 opcode. Returns an updated pointer to the macro data buffer; or,
19174 on error, issues a complaint and returns NULL. */
19176 static const gdb_byte
*
19177 skip_unknown_opcode (unsigned int opcode
,
19178 const gdb_byte
**opcode_definitions
,
19179 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
19181 unsigned int offset_size
,
19182 struct dwarf2_section_info
*section
)
19184 unsigned int bytes_read
, i
;
19186 const gdb_byte
*defn
;
19188 if (opcode_definitions
[opcode
] == NULL
)
19190 complaint (&symfile_complaints
,
19191 _("unrecognized DW_MACFINO opcode 0x%x"),
19196 defn
= opcode_definitions
[opcode
];
19197 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
19198 defn
+= bytes_read
;
19200 for (i
= 0; i
< arg
; ++i
)
19202 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
, defn
[i
], offset_size
,
19204 if (mac_ptr
== NULL
)
19206 /* skip_form_bytes already issued the complaint. */
19214 /* A helper function which parses the header of a macro section.
19215 If the macro section is the extended (for now called "GNU") type,
19216 then this updates *OFFSET_SIZE. Returns a pointer to just after
19217 the header, or issues a complaint and returns NULL on error. */
19219 static const gdb_byte
*
19220 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
19222 const gdb_byte
*mac_ptr
,
19223 unsigned int *offset_size
,
19224 int section_is_gnu
)
19226 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
19228 if (section_is_gnu
)
19230 unsigned int version
, flags
;
19232 version
= read_2_bytes (abfd
, mac_ptr
);
19235 complaint (&symfile_complaints
,
19236 _("unrecognized version `%d' in .debug_macro section"),
19242 flags
= read_1_byte (abfd
, mac_ptr
);
19244 *offset_size
= (flags
& 1) ? 8 : 4;
19246 if ((flags
& 2) != 0)
19247 /* We don't need the line table offset. */
19248 mac_ptr
+= *offset_size
;
19250 /* Vendor opcode descriptions. */
19251 if ((flags
& 4) != 0)
19253 unsigned int i
, count
;
19255 count
= read_1_byte (abfd
, mac_ptr
);
19257 for (i
= 0; i
< count
; ++i
)
19259 unsigned int opcode
, bytes_read
;
19262 opcode
= read_1_byte (abfd
, mac_ptr
);
19264 opcode_definitions
[opcode
] = mac_ptr
;
19265 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
19266 mac_ptr
+= bytes_read
;
19275 /* A helper for dwarf_decode_macros that handles the GNU extensions,
19276 including DW_MACRO_GNU_transparent_include. */
19279 dwarf_decode_macro_bytes (bfd
*abfd
,
19280 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
19281 struct macro_source_file
*current_file
,
19282 struct line_header
*lh
, const char *comp_dir
,
19283 struct dwarf2_section_info
*section
,
19284 int section_is_gnu
, int section_is_dwz
,
19285 unsigned int offset_size
,
19286 struct objfile
*objfile
,
19287 htab_t include_hash
)
19289 enum dwarf_macro_record_type macinfo_type
;
19290 int at_commandline
;
19291 const gdb_byte
*opcode_definitions
[256];
19293 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
19294 &offset_size
, section_is_gnu
);
19295 if (mac_ptr
== NULL
)
19297 /* We already issued a complaint. */
19301 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
19302 GDB is still reading the definitions from command line. First
19303 DW_MACINFO_start_file will need to be ignored as it was already executed
19304 to create CURRENT_FILE for the main source holding also the command line
19305 definitions. On first met DW_MACINFO_start_file this flag is reset to
19306 normally execute all the remaining DW_MACINFO_start_file macinfos. */
19308 at_commandline
= 1;
19312 /* Do we at least have room for a macinfo type byte? */
19313 if (mac_ptr
>= mac_end
)
19315 dwarf2_section_buffer_overflow_complaint (section
);
19319 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
19322 /* Note that we rely on the fact that the corresponding GNU and
19323 DWARF constants are the same. */
19324 switch (macinfo_type
)
19326 /* A zero macinfo type indicates the end of the macro
19331 case DW_MACRO_GNU_define
:
19332 case DW_MACRO_GNU_undef
:
19333 case DW_MACRO_GNU_define_indirect
:
19334 case DW_MACRO_GNU_undef_indirect
:
19335 case DW_MACRO_GNU_define_indirect_alt
:
19336 case DW_MACRO_GNU_undef_indirect_alt
:
19338 unsigned int bytes_read
;
19343 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
19344 mac_ptr
+= bytes_read
;
19346 if (macinfo_type
== DW_MACRO_GNU_define
19347 || macinfo_type
== DW_MACRO_GNU_undef
)
19349 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
19350 mac_ptr
+= bytes_read
;
19354 LONGEST str_offset
;
19356 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
19357 mac_ptr
+= offset_size
;
19359 if (macinfo_type
== DW_MACRO_GNU_define_indirect_alt
19360 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
19363 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
19365 body
= read_indirect_string_from_dwz (dwz
, str_offset
);
19368 body
= read_indirect_string_at_offset (abfd
, str_offset
);
19371 is_define
= (macinfo_type
== DW_MACRO_GNU_define
19372 || macinfo_type
== DW_MACRO_GNU_define_indirect
19373 || macinfo_type
== DW_MACRO_GNU_define_indirect_alt
);
19374 if (! current_file
)
19376 /* DWARF violation as no main source is present. */
19377 complaint (&symfile_complaints
,
19378 _("debug info with no main source gives macro %s "
19380 is_define
? _("definition") : _("undefinition"),
19384 if ((line
== 0 && !at_commandline
)
19385 || (line
!= 0 && at_commandline
))
19386 complaint (&symfile_complaints
,
19387 _("debug info gives %s macro %s with %s line %d: %s"),
19388 at_commandline
? _("command-line") : _("in-file"),
19389 is_define
? _("definition") : _("undefinition"),
19390 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
19393 parse_macro_definition (current_file
, line
, body
);
19396 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
19397 || macinfo_type
== DW_MACRO_GNU_undef_indirect
19398 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
);
19399 macro_undef (current_file
, line
, body
);
19404 case DW_MACRO_GNU_start_file
:
19406 unsigned int bytes_read
;
19409 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
19410 mac_ptr
+= bytes_read
;
19411 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
19412 mac_ptr
+= bytes_read
;
19414 if ((line
== 0 && !at_commandline
)
19415 || (line
!= 0 && at_commandline
))
19416 complaint (&symfile_complaints
,
19417 _("debug info gives source %d included "
19418 "from %s at %s line %d"),
19419 file
, at_commandline
? _("command-line") : _("file"),
19420 line
== 0 ? _("zero") : _("non-zero"), line
);
19422 if (at_commandline
)
19424 /* This DW_MACRO_GNU_start_file was executed in the
19426 at_commandline
= 0;
19429 current_file
= macro_start_file (file
, line
,
19430 current_file
, comp_dir
,
19435 case DW_MACRO_GNU_end_file
:
19436 if (! current_file
)
19437 complaint (&symfile_complaints
,
19438 _("macro debug info has an unmatched "
19439 "`close_file' directive"));
19442 current_file
= current_file
->included_by
;
19443 if (! current_file
)
19445 enum dwarf_macro_record_type next_type
;
19447 /* GCC circa March 2002 doesn't produce the zero
19448 type byte marking the end of the compilation
19449 unit. Complain if it's not there, but exit no
19452 /* Do we at least have room for a macinfo type byte? */
19453 if (mac_ptr
>= mac_end
)
19455 dwarf2_section_buffer_overflow_complaint (section
);
19459 /* We don't increment mac_ptr here, so this is just
19461 next_type
= read_1_byte (abfd
, mac_ptr
);
19462 if (next_type
!= 0)
19463 complaint (&symfile_complaints
,
19464 _("no terminating 0-type entry for "
19465 "macros in `.debug_macinfo' section"));
19472 case DW_MACRO_GNU_transparent_include
:
19473 case DW_MACRO_GNU_transparent_include_alt
:
19477 bfd
*include_bfd
= abfd
;
19478 struct dwarf2_section_info
*include_section
= section
;
19479 struct dwarf2_section_info alt_section
;
19480 const gdb_byte
*include_mac_end
= mac_end
;
19481 int is_dwz
= section_is_dwz
;
19482 const gdb_byte
*new_mac_ptr
;
19484 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
19485 mac_ptr
+= offset_size
;
19487 if (macinfo_type
== DW_MACRO_GNU_transparent_include_alt
)
19489 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
19491 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
19494 include_bfd
= dwz
->macro
.asection
->owner
;
19495 include_section
= &dwz
->macro
;
19496 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
19500 new_mac_ptr
= include_section
->buffer
+ offset
;
19501 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
19505 /* This has actually happened; see
19506 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
19507 complaint (&symfile_complaints
,
19508 _("recursive DW_MACRO_GNU_transparent_include in "
19509 ".debug_macro section"));
19513 *slot
= (void *) new_mac_ptr
;
19515 dwarf_decode_macro_bytes (include_bfd
, new_mac_ptr
,
19516 include_mac_end
, current_file
,
19518 section
, section_is_gnu
, is_dwz
,
19519 offset_size
, objfile
, include_hash
);
19521 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
19526 case DW_MACINFO_vendor_ext
:
19527 if (!section_is_gnu
)
19529 unsigned int bytes_read
;
19532 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
19533 mac_ptr
+= bytes_read
;
19534 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
19535 mac_ptr
+= bytes_read
;
19537 /* We don't recognize any vendor extensions. */
19543 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
19544 mac_ptr
, mac_end
, abfd
, offset_size
,
19546 if (mac_ptr
== NULL
)
19550 } while (macinfo_type
!= 0);
19554 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
19555 const char *comp_dir
, int section_is_gnu
)
19557 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19558 struct line_header
*lh
= cu
->line_header
;
19560 const gdb_byte
*mac_ptr
, *mac_end
;
19561 struct macro_source_file
*current_file
= 0;
19562 enum dwarf_macro_record_type macinfo_type
;
19563 unsigned int offset_size
= cu
->header
.offset_size
;
19564 const gdb_byte
*opcode_definitions
[256];
19565 struct cleanup
*cleanup
;
19566 htab_t include_hash
;
19568 struct dwarf2_section_info
*section
;
19569 const char *section_name
;
19571 if (cu
->dwo_unit
!= NULL
)
19573 if (section_is_gnu
)
19575 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
19576 section_name
= ".debug_macro.dwo";
19580 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
19581 section_name
= ".debug_macinfo.dwo";
19586 if (section_is_gnu
)
19588 section
= &dwarf2_per_objfile
->macro
;
19589 section_name
= ".debug_macro";
19593 section
= &dwarf2_per_objfile
->macinfo
;
19594 section_name
= ".debug_macinfo";
19598 dwarf2_read_section (objfile
, section
);
19599 if (section
->buffer
== NULL
)
19601 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
19604 abfd
= section
->asection
->owner
;
19606 /* First pass: Find the name of the base filename.
19607 This filename is needed in order to process all macros whose definition
19608 (or undefinition) comes from the command line. These macros are defined
19609 before the first DW_MACINFO_start_file entry, and yet still need to be
19610 associated to the base file.
19612 To determine the base file name, we scan the macro definitions until we
19613 reach the first DW_MACINFO_start_file entry. We then initialize
19614 CURRENT_FILE accordingly so that any macro definition found before the
19615 first DW_MACINFO_start_file can still be associated to the base file. */
19617 mac_ptr
= section
->buffer
+ offset
;
19618 mac_end
= section
->buffer
+ section
->size
;
19620 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
19621 &offset_size
, section_is_gnu
);
19622 if (mac_ptr
== NULL
)
19624 /* We already issued a complaint. */
19630 /* Do we at least have room for a macinfo type byte? */
19631 if (mac_ptr
>= mac_end
)
19633 /* Complaint is printed during the second pass as GDB will probably
19634 stop the first pass earlier upon finding
19635 DW_MACINFO_start_file. */
19639 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
19642 /* Note that we rely on the fact that the corresponding GNU and
19643 DWARF constants are the same. */
19644 switch (macinfo_type
)
19646 /* A zero macinfo type indicates the end of the macro
19651 case DW_MACRO_GNU_define
:
19652 case DW_MACRO_GNU_undef
:
19653 /* Only skip the data by MAC_PTR. */
19655 unsigned int bytes_read
;
19657 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
19658 mac_ptr
+= bytes_read
;
19659 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
19660 mac_ptr
+= bytes_read
;
19664 case DW_MACRO_GNU_start_file
:
19666 unsigned int bytes_read
;
19669 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
19670 mac_ptr
+= bytes_read
;
19671 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
19672 mac_ptr
+= bytes_read
;
19674 current_file
= macro_start_file (file
, line
, current_file
,
19675 comp_dir
, lh
, objfile
);
19679 case DW_MACRO_GNU_end_file
:
19680 /* No data to skip by MAC_PTR. */
19683 case DW_MACRO_GNU_define_indirect
:
19684 case DW_MACRO_GNU_undef_indirect
:
19685 case DW_MACRO_GNU_define_indirect_alt
:
19686 case DW_MACRO_GNU_undef_indirect_alt
:
19688 unsigned int bytes_read
;
19690 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
19691 mac_ptr
+= bytes_read
;
19692 mac_ptr
+= offset_size
;
19696 case DW_MACRO_GNU_transparent_include
:
19697 case DW_MACRO_GNU_transparent_include_alt
:
19698 /* Note that, according to the spec, a transparent include
19699 chain cannot call DW_MACRO_GNU_start_file. So, we can just
19700 skip this opcode. */
19701 mac_ptr
+= offset_size
;
19704 case DW_MACINFO_vendor_ext
:
19705 /* Only skip the data by MAC_PTR. */
19706 if (!section_is_gnu
)
19708 unsigned int bytes_read
;
19710 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
19711 mac_ptr
+= bytes_read
;
19712 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
19713 mac_ptr
+= bytes_read
;
19718 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
19719 mac_ptr
, mac_end
, abfd
, offset_size
,
19721 if (mac_ptr
== NULL
)
19725 } while (macinfo_type
!= 0 && current_file
== NULL
);
19727 /* Second pass: Process all entries.
19729 Use the AT_COMMAND_LINE flag to determine whether we are still processing
19730 command-line macro definitions/undefinitions. This flag is unset when we
19731 reach the first DW_MACINFO_start_file entry. */
19733 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
19734 NULL
, xcalloc
, xfree
);
19735 cleanup
= make_cleanup_htab_delete (include_hash
);
19736 mac_ptr
= section
->buffer
+ offset
;
19737 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
19738 *slot
= (void *) mac_ptr
;
19739 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
19740 current_file
, lh
, comp_dir
, section
,
19742 offset_size
, objfile
, include_hash
);
19743 do_cleanups (cleanup
);
19746 /* Check if the attribute's form is a DW_FORM_block*
19747 if so return true else false. */
19750 attr_form_is_block (struct attribute
*attr
)
19752 return (attr
== NULL
? 0 :
19753 attr
->form
== DW_FORM_block1
19754 || attr
->form
== DW_FORM_block2
19755 || attr
->form
== DW_FORM_block4
19756 || attr
->form
== DW_FORM_block
19757 || attr
->form
== DW_FORM_exprloc
);
19760 /* Return non-zero if ATTR's value is a section offset --- classes
19761 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
19762 You may use DW_UNSND (attr) to retrieve such offsets.
19764 Section 7.5.4, "Attribute Encodings", explains that no attribute
19765 may have a value that belongs to more than one of these classes; it
19766 would be ambiguous if we did, because we use the same forms for all
19770 attr_form_is_section_offset (struct attribute
*attr
)
19772 return (attr
->form
== DW_FORM_data4
19773 || attr
->form
== DW_FORM_data8
19774 || attr
->form
== DW_FORM_sec_offset
);
19777 /* Return non-zero if ATTR's value falls in the 'constant' class, or
19778 zero otherwise. When this function returns true, you can apply
19779 dwarf2_get_attr_constant_value to it.
19781 However, note that for some attributes you must check
19782 attr_form_is_section_offset before using this test. DW_FORM_data4
19783 and DW_FORM_data8 are members of both the constant class, and of
19784 the classes that contain offsets into other debug sections
19785 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
19786 that, if an attribute's can be either a constant or one of the
19787 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
19788 taken as section offsets, not constants. */
19791 attr_form_is_constant (struct attribute
*attr
)
19793 switch (attr
->form
)
19795 case DW_FORM_sdata
:
19796 case DW_FORM_udata
:
19797 case DW_FORM_data1
:
19798 case DW_FORM_data2
:
19799 case DW_FORM_data4
:
19800 case DW_FORM_data8
:
19807 /* Return the .debug_loc section to use for CU.
19808 For DWO files use .debug_loc.dwo. */
19810 static struct dwarf2_section_info
*
19811 cu_debug_loc_section (struct dwarf2_cu
*cu
)
19814 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
19815 return &dwarf2_per_objfile
->loc
;
19818 /* A helper function that fills in a dwarf2_loclist_baton. */
19821 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
19822 struct dwarf2_loclist_baton
*baton
,
19823 struct attribute
*attr
)
19825 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19827 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
19829 baton
->per_cu
= cu
->per_cu
;
19830 gdb_assert (baton
->per_cu
);
19831 /* We don't know how long the location list is, but make sure we
19832 don't run off the edge of the section. */
19833 baton
->size
= section
->size
- DW_UNSND (attr
);
19834 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
19835 baton
->base_address
= cu
->base_address
;
19836 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
19840 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
19841 struct dwarf2_cu
*cu
, int is_block
)
19843 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19844 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19846 if (attr_form_is_section_offset (attr
)
19847 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
19848 the section. If so, fall through to the complaint in the
19850 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
19852 struct dwarf2_loclist_baton
*baton
;
19854 baton
= obstack_alloc (&objfile
->objfile_obstack
,
19855 sizeof (struct dwarf2_loclist_baton
));
19857 fill_in_loclist_baton (cu
, baton
, attr
);
19859 if (cu
->base_known
== 0)
19860 complaint (&symfile_complaints
,
19861 _("Location list used without "
19862 "specifying the CU base address."));
19864 SYMBOL_ACLASS_INDEX (sym
) = (is_block
19865 ? dwarf2_loclist_block_index
19866 : dwarf2_loclist_index
);
19867 SYMBOL_LOCATION_BATON (sym
) = baton
;
19871 struct dwarf2_locexpr_baton
*baton
;
19873 baton
= obstack_alloc (&objfile
->objfile_obstack
,
19874 sizeof (struct dwarf2_locexpr_baton
));
19875 baton
->per_cu
= cu
->per_cu
;
19876 gdb_assert (baton
->per_cu
);
19878 if (attr_form_is_block (attr
))
19880 /* Note that we're just copying the block's data pointer
19881 here, not the actual data. We're still pointing into the
19882 info_buffer for SYM's objfile; right now we never release
19883 that buffer, but when we do clean up properly this may
19885 baton
->size
= DW_BLOCK (attr
)->size
;
19886 baton
->data
= DW_BLOCK (attr
)->data
;
19890 dwarf2_invalid_attrib_class_complaint ("location description",
19891 SYMBOL_NATURAL_NAME (sym
));
19895 SYMBOL_ACLASS_INDEX (sym
) = (is_block
19896 ? dwarf2_locexpr_block_index
19897 : dwarf2_locexpr_index
);
19898 SYMBOL_LOCATION_BATON (sym
) = baton
;
19902 /* Return the OBJFILE associated with the compilation unit CU. If CU
19903 came from a separate debuginfo file, then the master objfile is
19907 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
19909 struct objfile
*objfile
= per_cu
->objfile
;
19911 /* Return the master objfile, so that we can report and look up the
19912 correct file containing this variable. */
19913 if (objfile
->separate_debug_objfile_backlink
)
19914 objfile
= objfile
->separate_debug_objfile_backlink
;
19919 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
19920 (CU_HEADERP is unused in such case) or prepare a temporary copy at
19921 CU_HEADERP first. */
19923 static const struct comp_unit_head
*
19924 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
19925 struct dwarf2_per_cu_data
*per_cu
)
19927 const gdb_byte
*info_ptr
;
19930 return &per_cu
->cu
->header
;
19932 info_ptr
= per_cu
->section
->buffer
+ per_cu
->offset
.sect_off
;
19934 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
19935 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->objfile
->obfd
);
19940 /* Return the address size given in the compilation unit header for CU. */
19943 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
19945 struct comp_unit_head cu_header_local
;
19946 const struct comp_unit_head
*cu_headerp
;
19948 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
19950 return cu_headerp
->addr_size
;
19953 /* Return the offset size given in the compilation unit header for CU. */
19956 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
19958 struct comp_unit_head cu_header_local
;
19959 const struct comp_unit_head
*cu_headerp
;
19961 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
19963 return cu_headerp
->offset_size
;
19966 /* See its dwarf2loc.h declaration. */
19969 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
19971 struct comp_unit_head cu_header_local
;
19972 const struct comp_unit_head
*cu_headerp
;
19974 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
19976 if (cu_headerp
->version
== 2)
19977 return cu_headerp
->addr_size
;
19979 return cu_headerp
->offset_size
;
19982 /* Return the text offset of the CU. The returned offset comes from
19983 this CU's objfile. If this objfile came from a separate debuginfo
19984 file, then the offset may be different from the corresponding
19985 offset in the parent objfile. */
19988 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
19990 struct objfile
*objfile
= per_cu
->objfile
;
19992 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
19995 /* Locate the .debug_info compilation unit from CU's objfile which contains
19996 the DIE at OFFSET. Raises an error on failure. */
19998 static struct dwarf2_per_cu_data
*
19999 dwarf2_find_containing_comp_unit (sect_offset offset
,
20000 unsigned int offset_in_dwz
,
20001 struct objfile
*objfile
)
20003 struct dwarf2_per_cu_data
*this_cu
;
20005 const sect_offset
*cu_off
;
20008 high
= dwarf2_per_objfile
->n_comp_units
- 1;
20011 struct dwarf2_per_cu_data
*mid_cu
;
20012 int mid
= low
+ (high
- low
) / 2;
20014 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
20015 cu_off
= &mid_cu
->offset
;
20016 if (mid_cu
->is_dwz
> offset_in_dwz
20017 || (mid_cu
->is_dwz
== offset_in_dwz
20018 && cu_off
->sect_off
>= offset
.sect_off
))
20023 gdb_assert (low
== high
);
20024 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
20025 cu_off
= &this_cu
->offset
;
20026 if (this_cu
->is_dwz
!= offset_in_dwz
|| cu_off
->sect_off
> offset
.sect_off
)
20028 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
20029 error (_("Dwarf Error: could not find partial DIE containing "
20030 "offset 0x%lx [in module %s]"),
20031 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
20033 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
20034 <= offset
.sect_off
);
20035 return dwarf2_per_objfile
->all_comp_units
[low
-1];
20039 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
20040 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
20041 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
20042 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
20043 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
20048 /* Initialize dwarf2_cu CU, owned by PER_CU. */
20051 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
20053 memset (cu
, 0, sizeof (*cu
));
20055 cu
->per_cu
= per_cu
;
20056 cu
->objfile
= per_cu
->objfile
;
20057 obstack_init (&cu
->comp_unit_obstack
);
20060 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
20063 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
20064 enum language pretend_language
)
20066 struct attribute
*attr
;
20068 /* Set the language we're debugging. */
20069 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
20071 set_cu_language (DW_UNSND (attr
), cu
);
20074 cu
->language
= pretend_language
;
20075 cu
->language_defn
= language_def (cu
->language
);
20078 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
20080 cu
->producer
= DW_STRING (attr
);
20083 /* Release one cached compilation unit, CU. We unlink it from the tree
20084 of compilation units, but we don't remove it from the read_in_chain;
20085 the caller is responsible for that.
20086 NOTE: DATA is a void * because this function is also used as a
20087 cleanup routine. */
20090 free_heap_comp_unit (void *data
)
20092 struct dwarf2_cu
*cu
= data
;
20094 gdb_assert (cu
->per_cu
!= NULL
);
20095 cu
->per_cu
->cu
= NULL
;
20098 obstack_free (&cu
->comp_unit_obstack
, NULL
);
20103 /* This cleanup function is passed the address of a dwarf2_cu on the stack
20104 when we're finished with it. We can't free the pointer itself, but be
20105 sure to unlink it from the cache. Also release any associated storage. */
20108 free_stack_comp_unit (void *data
)
20110 struct dwarf2_cu
*cu
= data
;
20112 gdb_assert (cu
->per_cu
!= NULL
);
20113 cu
->per_cu
->cu
= NULL
;
20116 obstack_free (&cu
->comp_unit_obstack
, NULL
);
20117 cu
->partial_dies
= NULL
;
20120 /* Free all cached compilation units. */
20123 free_cached_comp_units (void *data
)
20125 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
20127 per_cu
= dwarf2_per_objfile
->read_in_chain
;
20128 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
20129 while (per_cu
!= NULL
)
20131 struct dwarf2_per_cu_data
*next_cu
;
20133 next_cu
= per_cu
->cu
->read_in_chain
;
20135 free_heap_comp_unit (per_cu
->cu
);
20136 *last_chain
= next_cu
;
20142 /* Increase the age counter on each cached compilation unit, and free
20143 any that are too old. */
20146 age_cached_comp_units (void)
20148 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
20150 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
20151 per_cu
= dwarf2_per_objfile
->read_in_chain
;
20152 while (per_cu
!= NULL
)
20154 per_cu
->cu
->last_used
++;
20155 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
20156 dwarf2_mark (per_cu
->cu
);
20157 per_cu
= per_cu
->cu
->read_in_chain
;
20160 per_cu
= dwarf2_per_objfile
->read_in_chain
;
20161 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
20162 while (per_cu
!= NULL
)
20164 struct dwarf2_per_cu_data
*next_cu
;
20166 next_cu
= per_cu
->cu
->read_in_chain
;
20168 if (!per_cu
->cu
->mark
)
20170 free_heap_comp_unit (per_cu
->cu
);
20171 *last_chain
= next_cu
;
20174 last_chain
= &per_cu
->cu
->read_in_chain
;
20180 /* Remove a single compilation unit from the cache. */
20183 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
20185 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
20187 per_cu
= dwarf2_per_objfile
->read_in_chain
;
20188 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
20189 while (per_cu
!= NULL
)
20191 struct dwarf2_per_cu_data
*next_cu
;
20193 next_cu
= per_cu
->cu
->read_in_chain
;
20195 if (per_cu
== target_per_cu
)
20197 free_heap_comp_unit (per_cu
->cu
);
20199 *last_chain
= next_cu
;
20203 last_chain
= &per_cu
->cu
->read_in_chain
;
20209 /* Release all extra memory associated with OBJFILE. */
20212 dwarf2_free_objfile (struct objfile
*objfile
)
20214 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
20216 if (dwarf2_per_objfile
== NULL
)
20219 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
20220 free_cached_comp_units (NULL
);
20222 if (dwarf2_per_objfile
->quick_file_names_table
)
20223 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
20225 /* Everything else should be on the objfile obstack. */
20228 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
20229 We store these in a hash table separate from the DIEs, and preserve them
20230 when the DIEs are flushed out of cache.
20232 The CU "per_cu" pointer is needed because offset alone is not enough to
20233 uniquely identify the type. A file may have multiple .debug_types sections,
20234 or the type may come from a DWO file. Furthermore, while it's more logical
20235 to use per_cu->section+offset, with Fission the section with the data is in
20236 the DWO file but we don't know that section at the point we need it.
20237 We have to use something in dwarf2_per_cu_data (or the pointer to it)
20238 because we can enter the lookup routine, get_die_type_at_offset, from
20239 outside this file, and thus won't necessarily have PER_CU->cu.
20240 Fortunately, PER_CU is stable for the life of the objfile. */
20242 struct dwarf2_per_cu_offset_and_type
20244 const struct dwarf2_per_cu_data
*per_cu
;
20245 sect_offset offset
;
20249 /* Hash function for a dwarf2_per_cu_offset_and_type. */
20252 per_cu_offset_and_type_hash (const void *item
)
20254 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
20256 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
20259 /* Equality function for a dwarf2_per_cu_offset_and_type. */
20262 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
20264 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
20265 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
20267 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
20268 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
20271 /* Set the type associated with DIE to TYPE. Save it in CU's hash
20272 table if necessary. For convenience, return TYPE.
20274 The DIEs reading must have careful ordering to:
20275 * Not cause infite loops trying to read in DIEs as a prerequisite for
20276 reading current DIE.
20277 * Not trying to dereference contents of still incompletely read in types
20278 while reading in other DIEs.
20279 * Enable referencing still incompletely read in types just by a pointer to
20280 the type without accessing its fields.
20282 Therefore caller should follow these rules:
20283 * Try to fetch any prerequisite types we may need to build this DIE type
20284 before building the type and calling set_die_type.
20285 * After building type call set_die_type for current DIE as soon as
20286 possible before fetching more types to complete the current type.
20287 * Make the type as complete as possible before fetching more types. */
20289 static struct type
*
20290 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
20292 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
20293 struct objfile
*objfile
= cu
->objfile
;
20295 /* For Ada types, make sure that the gnat-specific data is always
20296 initialized (if not already set). There are a few types where
20297 we should not be doing so, because the type-specific area is
20298 already used to hold some other piece of info (eg: TYPE_CODE_FLT
20299 where the type-specific area is used to store the floatformat).
20300 But this is not a problem, because the gnat-specific information
20301 is actually not needed for these types. */
20302 if (need_gnat_info (cu
)
20303 && TYPE_CODE (type
) != TYPE_CODE_FUNC
20304 && TYPE_CODE (type
) != TYPE_CODE_FLT
20305 && !HAVE_GNAT_AUX_INFO (type
))
20306 INIT_GNAT_SPECIFIC (type
);
20308 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
20310 dwarf2_per_objfile
->die_type_hash
=
20311 htab_create_alloc_ex (127,
20312 per_cu_offset_and_type_hash
,
20313 per_cu_offset_and_type_eq
,
20315 &objfile
->objfile_obstack
,
20316 hashtab_obstack_allocate
,
20317 dummy_obstack_deallocate
);
20320 ofs
.per_cu
= cu
->per_cu
;
20321 ofs
.offset
= die
->offset
;
20323 slot
= (struct dwarf2_per_cu_offset_and_type
**)
20324 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
20326 complaint (&symfile_complaints
,
20327 _("A problem internal to GDB: DIE 0x%x has type already set"),
20328 die
->offset
.sect_off
);
20329 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
20334 /* Look up the type for the die at OFFSET in PER_CU in die_type_hash,
20335 or return NULL if the die does not have a saved type. */
20337 static struct type
*
20338 get_die_type_at_offset (sect_offset offset
,
20339 struct dwarf2_per_cu_data
*per_cu
)
20341 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
20343 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
20346 ofs
.per_cu
= per_cu
;
20347 ofs
.offset
= offset
;
20348 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
20355 /* Look up the type for DIE in CU in die_type_hash,
20356 or return NULL if DIE does not have a saved type. */
20358 static struct type
*
20359 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20361 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
20364 /* Add a dependence relationship from CU to REF_PER_CU. */
20367 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
20368 struct dwarf2_per_cu_data
*ref_per_cu
)
20372 if (cu
->dependencies
== NULL
)
20374 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
20375 NULL
, &cu
->comp_unit_obstack
,
20376 hashtab_obstack_allocate
,
20377 dummy_obstack_deallocate
);
20379 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
20381 *slot
= ref_per_cu
;
20384 /* Subroutine of dwarf2_mark to pass to htab_traverse.
20385 Set the mark field in every compilation unit in the
20386 cache that we must keep because we are keeping CU. */
20389 dwarf2_mark_helper (void **slot
, void *data
)
20391 struct dwarf2_per_cu_data
*per_cu
;
20393 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
20395 /* cu->dependencies references may not yet have been ever read if QUIT aborts
20396 reading of the chain. As such dependencies remain valid it is not much
20397 useful to track and undo them during QUIT cleanups. */
20398 if (per_cu
->cu
== NULL
)
20401 if (per_cu
->cu
->mark
)
20403 per_cu
->cu
->mark
= 1;
20405 if (per_cu
->cu
->dependencies
!= NULL
)
20406 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
20411 /* Set the mark field in CU and in every other compilation unit in the
20412 cache that we must keep because we are keeping CU. */
20415 dwarf2_mark (struct dwarf2_cu
*cu
)
20420 if (cu
->dependencies
!= NULL
)
20421 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
20425 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
20429 per_cu
->cu
->mark
= 0;
20430 per_cu
= per_cu
->cu
->read_in_chain
;
20434 /* Trivial hash function for partial_die_info: the hash value of a DIE
20435 is its offset in .debug_info for this objfile. */
20438 partial_die_hash (const void *item
)
20440 const struct partial_die_info
*part_die
= item
;
20442 return part_die
->offset
.sect_off
;
20445 /* Trivial comparison function for partial_die_info structures: two DIEs
20446 are equal if they have the same offset. */
20449 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
20451 const struct partial_die_info
*part_die_lhs
= item_lhs
;
20452 const struct partial_die_info
*part_die_rhs
= item_rhs
;
20454 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
20457 static struct cmd_list_element
*set_dwarf2_cmdlist
;
20458 static struct cmd_list_element
*show_dwarf2_cmdlist
;
20461 set_dwarf2_cmd (char *args
, int from_tty
)
20463 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
20467 show_dwarf2_cmd (char *args
, int from_tty
)
20469 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
20472 /* Free data associated with OBJFILE, if necessary. */
20475 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
20477 struct dwarf2_per_objfile
*data
= d
;
20480 for (ix
= 0; ix
< dwarf2_per_objfile
->n_comp_units
; ++ix
)
20481 VEC_free (dwarf2_per_cu_ptr
,
20482 dwarf2_per_objfile
->all_comp_units
[ix
]->imported_symtabs
);
20484 for (ix
= 0; ix
< dwarf2_per_objfile
->n_type_units
; ++ix
)
20485 VEC_free (dwarf2_per_cu_ptr
,
20486 dwarf2_per_objfile
->all_type_units
[ix
]->per_cu
.imported_symtabs
);
20487 xfree (dwarf2_per_objfile
->all_type_units
);
20489 VEC_free (dwarf2_section_info_def
, data
->types
);
20491 if (data
->dwo_files
)
20492 free_dwo_files (data
->dwo_files
, objfile
);
20493 if (data
->dwp_file
)
20494 gdb_bfd_unref (data
->dwp_file
->dbfd
);
20496 if (data
->dwz_file
&& data
->dwz_file
->dwz_bfd
)
20497 gdb_bfd_unref (data
->dwz_file
->dwz_bfd
);
20501 /* The "save gdb-index" command. */
20503 /* The contents of the hash table we create when building the string
20505 struct strtab_entry
20507 offset_type offset
;
20511 /* Hash function for a strtab_entry.
20513 Function is used only during write_hash_table so no index format backward
20514 compatibility is needed. */
20517 hash_strtab_entry (const void *e
)
20519 const struct strtab_entry
*entry
= e
;
20520 return mapped_index_string_hash (INT_MAX
, entry
->str
);
20523 /* Equality function for a strtab_entry. */
20526 eq_strtab_entry (const void *a
, const void *b
)
20528 const struct strtab_entry
*ea
= a
;
20529 const struct strtab_entry
*eb
= b
;
20530 return !strcmp (ea
->str
, eb
->str
);
20533 /* Create a strtab_entry hash table. */
20536 create_strtab (void)
20538 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
20539 xfree
, xcalloc
, xfree
);
20542 /* Add a string to the constant pool. Return the string's offset in
20546 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
20549 struct strtab_entry entry
;
20550 struct strtab_entry
*result
;
20553 slot
= htab_find_slot (table
, &entry
, INSERT
);
20558 result
= XNEW (struct strtab_entry
);
20559 result
->offset
= obstack_object_size (cpool
);
20561 obstack_grow_str0 (cpool
, str
);
20564 return result
->offset
;
20567 /* An entry in the symbol table. */
20568 struct symtab_index_entry
20570 /* The name of the symbol. */
20572 /* The offset of the name in the constant pool. */
20573 offset_type index_offset
;
20574 /* A sorted vector of the indices of all the CUs that hold an object
20576 VEC (offset_type
) *cu_indices
;
20579 /* The symbol table. This is a power-of-2-sized hash table. */
20580 struct mapped_symtab
20582 offset_type n_elements
;
20584 struct symtab_index_entry
**data
;
20587 /* Hash function for a symtab_index_entry. */
20590 hash_symtab_entry (const void *e
)
20592 const struct symtab_index_entry
*entry
= e
;
20593 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
20594 sizeof (offset_type
) * VEC_length (offset_type
,
20595 entry
->cu_indices
),
20599 /* Equality function for a symtab_index_entry. */
20602 eq_symtab_entry (const void *a
, const void *b
)
20604 const struct symtab_index_entry
*ea
= a
;
20605 const struct symtab_index_entry
*eb
= b
;
20606 int len
= VEC_length (offset_type
, ea
->cu_indices
);
20607 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
20609 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
20610 VEC_address (offset_type
, eb
->cu_indices
),
20611 sizeof (offset_type
) * len
);
20614 /* Destroy a symtab_index_entry. */
20617 delete_symtab_entry (void *p
)
20619 struct symtab_index_entry
*entry
= p
;
20620 VEC_free (offset_type
, entry
->cu_indices
);
20624 /* Create a hash table holding symtab_index_entry objects. */
20627 create_symbol_hash_table (void)
20629 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
20630 delete_symtab_entry
, xcalloc
, xfree
);
20633 /* Create a new mapped symtab object. */
20635 static struct mapped_symtab
*
20636 create_mapped_symtab (void)
20638 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
20639 symtab
->n_elements
= 0;
20640 symtab
->size
= 1024;
20641 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
20645 /* Destroy a mapped_symtab. */
20648 cleanup_mapped_symtab (void *p
)
20650 struct mapped_symtab
*symtab
= p
;
20651 /* The contents of the array are freed when the other hash table is
20653 xfree (symtab
->data
);
20657 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
20660 Function is used only during write_hash_table so no index format backward
20661 compatibility is needed. */
20663 static struct symtab_index_entry
**
20664 find_slot (struct mapped_symtab
*symtab
, const char *name
)
20666 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
20668 index
= hash
& (symtab
->size
- 1);
20669 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
20673 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
20674 return &symtab
->data
[index
];
20675 index
= (index
+ step
) & (symtab
->size
- 1);
20679 /* Expand SYMTAB's hash table. */
20682 hash_expand (struct mapped_symtab
*symtab
)
20684 offset_type old_size
= symtab
->size
;
20686 struct symtab_index_entry
**old_entries
= symtab
->data
;
20689 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
20691 for (i
= 0; i
< old_size
; ++i
)
20693 if (old_entries
[i
])
20695 struct symtab_index_entry
**slot
= find_slot (symtab
,
20696 old_entries
[i
]->name
);
20697 *slot
= old_entries
[i
];
20701 xfree (old_entries
);
20704 /* Add an entry to SYMTAB. NAME is the name of the symbol.
20705 CU_INDEX is the index of the CU in which the symbol appears.
20706 IS_STATIC is one if the symbol is static, otherwise zero (global). */
20709 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
20710 int is_static
, gdb_index_symbol_kind kind
,
20711 offset_type cu_index
)
20713 struct symtab_index_entry
**slot
;
20714 offset_type cu_index_and_attrs
;
20716 ++symtab
->n_elements
;
20717 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
20718 hash_expand (symtab
);
20720 slot
= find_slot (symtab
, name
);
20723 *slot
= XNEW (struct symtab_index_entry
);
20724 (*slot
)->name
= name
;
20725 /* index_offset is set later. */
20726 (*slot
)->cu_indices
= NULL
;
20729 cu_index_and_attrs
= 0;
20730 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
20731 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
20732 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
20734 /* We don't want to record an index value twice as we want to avoid the
20736 We process all global symbols and then all static symbols
20737 (which would allow us to avoid the duplication by only having to check
20738 the last entry pushed), but a symbol could have multiple kinds in one CU.
20739 To keep things simple we don't worry about the duplication here and
20740 sort and uniqufy the list after we've processed all symbols. */
20741 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
20744 /* qsort helper routine for uniquify_cu_indices. */
20747 offset_type_compare (const void *ap
, const void *bp
)
20749 offset_type a
= *(offset_type
*) ap
;
20750 offset_type b
= *(offset_type
*) bp
;
20752 return (a
> b
) - (b
> a
);
20755 /* Sort and remove duplicates of all symbols' cu_indices lists. */
20758 uniquify_cu_indices (struct mapped_symtab
*symtab
)
20762 for (i
= 0; i
< symtab
->size
; ++i
)
20764 struct symtab_index_entry
*entry
= symtab
->data
[i
];
20767 && entry
->cu_indices
!= NULL
)
20769 unsigned int next_to_insert
, next_to_check
;
20770 offset_type last_value
;
20772 qsort (VEC_address (offset_type
, entry
->cu_indices
),
20773 VEC_length (offset_type
, entry
->cu_indices
),
20774 sizeof (offset_type
), offset_type_compare
);
20776 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
20777 next_to_insert
= 1;
20778 for (next_to_check
= 1;
20779 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
20782 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
20785 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
20787 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
20792 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
20797 /* Add a vector of indices to the constant pool. */
20800 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
20801 struct symtab_index_entry
*entry
)
20805 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
20808 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
20809 offset_type val
= MAYBE_SWAP (len
);
20814 entry
->index_offset
= obstack_object_size (cpool
);
20816 obstack_grow (cpool
, &val
, sizeof (val
));
20818 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
20821 val
= MAYBE_SWAP (iter
);
20822 obstack_grow (cpool
, &val
, sizeof (val
));
20827 struct symtab_index_entry
*old_entry
= *slot
;
20828 entry
->index_offset
= old_entry
->index_offset
;
20831 return entry
->index_offset
;
20834 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
20835 constant pool entries going into the obstack CPOOL. */
20838 write_hash_table (struct mapped_symtab
*symtab
,
20839 struct obstack
*output
, struct obstack
*cpool
)
20842 htab_t symbol_hash_table
;
20845 symbol_hash_table
= create_symbol_hash_table ();
20846 str_table
= create_strtab ();
20848 /* We add all the index vectors to the constant pool first, to
20849 ensure alignment is ok. */
20850 for (i
= 0; i
< symtab
->size
; ++i
)
20852 if (symtab
->data
[i
])
20853 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
20856 /* Now write out the hash table. */
20857 for (i
= 0; i
< symtab
->size
; ++i
)
20859 offset_type str_off
, vec_off
;
20861 if (symtab
->data
[i
])
20863 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
20864 vec_off
= symtab
->data
[i
]->index_offset
;
20868 /* While 0 is a valid constant pool index, it is not valid
20869 to have 0 for both offsets. */
20874 str_off
= MAYBE_SWAP (str_off
);
20875 vec_off
= MAYBE_SWAP (vec_off
);
20877 obstack_grow (output
, &str_off
, sizeof (str_off
));
20878 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
20881 htab_delete (str_table
);
20882 htab_delete (symbol_hash_table
);
20885 /* Struct to map psymtab to CU index in the index file. */
20886 struct psymtab_cu_index_map
20888 struct partial_symtab
*psymtab
;
20889 unsigned int cu_index
;
20893 hash_psymtab_cu_index (const void *item
)
20895 const struct psymtab_cu_index_map
*map
= item
;
20897 return htab_hash_pointer (map
->psymtab
);
20901 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
20903 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
20904 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
20906 return lhs
->psymtab
== rhs
->psymtab
;
20909 /* Helper struct for building the address table. */
20910 struct addrmap_index_data
20912 struct objfile
*objfile
;
20913 struct obstack
*addr_obstack
;
20914 htab_t cu_index_htab
;
20916 /* Non-zero if the previous_* fields are valid.
20917 We can't write an entry until we see the next entry (since it is only then
20918 that we know the end of the entry). */
20919 int previous_valid
;
20920 /* Index of the CU in the table of all CUs in the index file. */
20921 unsigned int previous_cu_index
;
20922 /* Start address of the CU. */
20923 CORE_ADDR previous_cu_start
;
20926 /* Write an address entry to OBSTACK. */
20929 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
20930 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
20932 offset_type cu_index_to_write
;
20934 CORE_ADDR baseaddr
;
20936 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
20938 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
20939 obstack_grow (obstack
, addr
, 8);
20940 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
20941 obstack_grow (obstack
, addr
, 8);
20942 cu_index_to_write
= MAYBE_SWAP (cu_index
);
20943 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
20946 /* Worker function for traversing an addrmap to build the address table. */
20949 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
20951 struct addrmap_index_data
*data
= datap
;
20952 struct partial_symtab
*pst
= obj
;
20954 if (data
->previous_valid
)
20955 add_address_entry (data
->objfile
, data
->addr_obstack
,
20956 data
->previous_cu_start
, start_addr
,
20957 data
->previous_cu_index
);
20959 data
->previous_cu_start
= start_addr
;
20962 struct psymtab_cu_index_map find_map
, *map
;
20963 find_map
.psymtab
= pst
;
20964 map
= htab_find (data
->cu_index_htab
, &find_map
);
20965 gdb_assert (map
!= NULL
);
20966 data
->previous_cu_index
= map
->cu_index
;
20967 data
->previous_valid
= 1;
20970 data
->previous_valid
= 0;
20975 /* Write OBJFILE's address map to OBSTACK.
20976 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
20977 in the index file. */
20980 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
20981 htab_t cu_index_htab
)
20983 struct addrmap_index_data addrmap_index_data
;
20985 /* When writing the address table, we have to cope with the fact that
20986 the addrmap iterator only provides the start of a region; we have to
20987 wait until the next invocation to get the start of the next region. */
20989 addrmap_index_data
.objfile
= objfile
;
20990 addrmap_index_data
.addr_obstack
= obstack
;
20991 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
20992 addrmap_index_data
.previous_valid
= 0;
20994 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
20995 &addrmap_index_data
);
20997 /* It's highly unlikely the last entry (end address = 0xff...ff)
20998 is valid, but we should still handle it.
20999 The end address is recorded as the start of the next region, but that
21000 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
21002 if (addrmap_index_data
.previous_valid
)
21003 add_address_entry (objfile
, obstack
,
21004 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
21005 addrmap_index_data
.previous_cu_index
);
21008 /* Return the symbol kind of PSYM. */
21010 static gdb_index_symbol_kind
21011 symbol_kind (struct partial_symbol
*psym
)
21013 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
21014 enum address_class aclass
= PSYMBOL_CLASS (psym
);
21022 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
21024 return GDB_INDEX_SYMBOL_KIND_TYPE
;
21026 case LOC_CONST_BYTES
:
21027 case LOC_OPTIMIZED_OUT
:
21029 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
21031 /* Note: It's currently impossible to recognize psyms as enum values
21032 short of reading the type info. For now punt. */
21033 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
21035 /* There are other LOC_FOO values that one might want to classify
21036 as variables, but dwarf2read.c doesn't currently use them. */
21037 return GDB_INDEX_SYMBOL_KIND_OTHER
;
21039 case STRUCT_DOMAIN
:
21040 return GDB_INDEX_SYMBOL_KIND_TYPE
;
21042 return GDB_INDEX_SYMBOL_KIND_OTHER
;
21046 /* Add a list of partial symbols to SYMTAB. */
21049 write_psymbols (struct mapped_symtab
*symtab
,
21051 struct partial_symbol
**psymp
,
21053 offset_type cu_index
,
21056 for (; count
-- > 0; ++psymp
)
21058 struct partial_symbol
*psym
= *psymp
;
21061 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
21062 error (_("Ada is not currently supported by the index"));
21064 /* Only add a given psymbol once. */
21065 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
21068 gdb_index_symbol_kind kind
= symbol_kind (psym
);
21071 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
21072 is_static
, kind
, cu_index
);
21077 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
21078 exception if there is an error. */
21081 write_obstack (FILE *file
, struct obstack
*obstack
)
21083 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
21085 != obstack_object_size (obstack
))
21086 error (_("couldn't data write to file"));
21089 /* Unlink a file if the argument is not NULL. */
21092 unlink_if_set (void *p
)
21094 char **filename
= p
;
21096 unlink (*filename
);
21099 /* A helper struct used when iterating over debug_types. */
21100 struct signatured_type_index_data
21102 struct objfile
*objfile
;
21103 struct mapped_symtab
*symtab
;
21104 struct obstack
*types_list
;
21109 /* A helper function that writes a single signatured_type to an
21113 write_one_signatured_type (void **slot
, void *d
)
21115 struct signatured_type_index_data
*info
= d
;
21116 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
21117 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
21120 write_psymbols (info
->symtab
,
21122 info
->objfile
->global_psymbols
.list
21123 + psymtab
->globals_offset
,
21124 psymtab
->n_global_syms
, info
->cu_index
,
21126 write_psymbols (info
->symtab
,
21128 info
->objfile
->static_psymbols
.list
21129 + psymtab
->statics_offset
,
21130 psymtab
->n_static_syms
, info
->cu_index
,
21133 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
21134 entry
->per_cu
.offset
.sect_off
);
21135 obstack_grow (info
->types_list
, val
, 8);
21136 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
21137 entry
->type_offset_in_tu
.cu_off
);
21138 obstack_grow (info
->types_list
, val
, 8);
21139 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
21140 obstack_grow (info
->types_list
, val
, 8);
21147 /* Recurse into all "included" dependencies and write their symbols as
21148 if they appeared in this psymtab. */
21151 recursively_write_psymbols (struct objfile
*objfile
,
21152 struct partial_symtab
*psymtab
,
21153 struct mapped_symtab
*symtab
,
21155 offset_type cu_index
)
21159 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
21160 if (psymtab
->dependencies
[i
]->user
!= NULL
)
21161 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
21162 symtab
, psyms_seen
, cu_index
);
21164 write_psymbols (symtab
,
21166 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
21167 psymtab
->n_global_syms
, cu_index
,
21169 write_psymbols (symtab
,
21171 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
21172 psymtab
->n_static_syms
, cu_index
,
21176 /* Create an index file for OBJFILE in the directory DIR. */
21179 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
21181 struct cleanup
*cleanup
;
21182 char *filename
, *cleanup_filename
;
21183 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
21184 struct obstack cu_list
, types_cu_list
;
21187 struct mapped_symtab
*symtab
;
21188 offset_type val
, size_of_contents
, total_len
;
21191 htab_t cu_index_htab
;
21192 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
21194 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
21197 if (dwarf2_per_objfile
->using_index
)
21198 error (_("Cannot use an index to create the index"));
21200 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
21201 error (_("Cannot make an index when the file has multiple .debug_types sections"));
21203 if (stat (objfile
->name
, &st
) < 0)
21204 perror_with_name (objfile
->name
);
21206 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
21207 INDEX_SUFFIX
, (char *) NULL
);
21208 cleanup
= make_cleanup (xfree
, filename
);
21210 out_file
= gdb_fopen_cloexec (filename
, "wb");
21212 error (_("Can't open `%s' for writing"), filename
);
21214 cleanup_filename
= filename
;
21215 make_cleanup (unlink_if_set
, &cleanup_filename
);
21217 symtab
= create_mapped_symtab ();
21218 make_cleanup (cleanup_mapped_symtab
, symtab
);
21220 obstack_init (&addr_obstack
);
21221 make_cleanup_obstack_free (&addr_obstack
);
21223 obstack_init (&cu_list
);
21224 make_cleanup_obstack_free (&cu_list
);
21226 obstack_init (&types_cu_list
);
21227 make_cleanup_obstack_free (&types_cu_list
);
21229 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
21230 NULL
, xcalloc
, xfree
);
21231 make_cleanup_htab_delete (psyms_seen
);
21233 /* While we're scanning CU's create a table that maps a psymtab pointer
21234 (which is what addrmap records) to its index (which is what is recorded
21235 in the index file). This will later be needed to write the address
21237 cu_index_htab
= htab_create_alloc (100,
21238 hash_psymtab_cu_index
,
21239 eq_psymtab_cu_index
,
21240 NULL
, xcalloc
, xfree
);
21241 make_cleanup_htab_delete (cu_index_htab
);
21242 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
21243 xmalloc (sizeof (struct psymtab_cu_index_map
)
21244 * dwarf2_per_objfile
->n_comp_units
);
21245 make_cleanup (xfree
, psymtab_cu_index_map
);
21247 /* The CU list is already sorted, so we don't need to do additional
21248 work here. Also, the debug_types entries do not appear in
21249 all_comp_units, but only in their own hash table. */
21250 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
21252 struct dwarf2_per_cu_data
*per_cu
21253 = dwarf2_per_objfile
->all_comp_units
[i
];
21254 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
21256 struct psymtab_cu_index_map
*map
;
21259 if (psymtab
->user
== NULL
)
21260 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
21262 map
= &psymtab_cu_index_map
[i
];
21263 map
->psymtab
= psymtab
;
21265 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
21266 gdb_assert (slot
!= NULL
);
21267 gdb_assert (*slot
== NULL
);
21270 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
21271 per_cu
->offset
.sect_off
);
21272 obstack_grow (&cu_list
, val
, 8);
21273 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
21274 obstack_grow (&cu_list
, val
, 8);
21277 /* Dump the address map. */
21278 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
21280 /* Write out the .debug_type entries, if any. */
21281 if (dwarf2_per_objfile
->signatured_types
)
21283 struct signatured_type_index_data sig_data
;
21285 sig_data
.objfile
= objfile
;
21286 sig_data
.symtab
= symtab
;
21287 sig_data
.types_list
= &types_cu_list
;
21288 sig_data
.psyms_seen
= psyms_seen
;
21289 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
21290 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
21291 write_one_signatured_type
, &sig_data
);
21294 /* Now that we've processed all symbols we can shrink their cu_indices
21296 uniquify_cu_indices (symtab
);
21298 obstack_init (&constant_pool
);
21299 make_cleanup_obstack_free (&constant_pool
);
21300 obstack_init (&symtab_obstack
);
21301 make_cleanup_obstack_free (&symtab_obstack
);
21302 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
21304 obstack_init (&contents
);
21305 make_cleanup_obstack_free (&contents
);
21306 size_of_contents
= 6 * sizeof (offset_type
);
21307 total_len
= size_of_contents
;
21309 /* The version number. */
21310 val
= MAYBE_SWAP (8);
21311 obstack_grow (&contents
, &val
, sizeof (val
));
21313 /* The offset of the CU list from the start of the file. */
21314 val
= MAYBE_SWAP (total_len
);
21315 obstack_grow (&contents
, &val
, sizeof (val
));
21316 total_len
+= obstack_object_size (&cu_list
);
21318 /* The offset of the types CU list from the start of the file. */
21319 val
= MAYBE_SWAP (total_len
);
21320 obstack_grow (&contents
, &val
, sizeof (val
));
21321 total_len
+= obstack_object_size (&types_cu_list
);
21323 /* The offset of the address table from the start of the file. */
21324 val
= MAYBE_SWAP (total_len
);
21325 obstack_grow (&contents
, &val
, sizeof (val
));
21326 total_len
+= obstack_object_size (&addr_obstack
);
21328 /* The offset of the symbol table from the start of the file. */
21329 val
= MAYBE_SWAP (total_len
);
21330 obstack_grow (&contents
, &val
, sizeof (val
));
21331 total_len
+= obstack_object_size (&symtab_obstack
);
21333 /* The offset of the constant pool from the start of the file. */
21334 val
= MAYBE_SWAP (total_len
);
21335 obstack_grow (&contents
, &val
, sizeof (val
));
21336 total_len
+= obstack_object_size (&constant_pool
);
21338 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
21340 write_obstack (out_file
, &contents
);
21341 write_obstack (out_file
, &cu_list
);
21342 write_obstack (out_file
, &types_cu_list
);
21343 write_obstack (out_file
, &addr_obstack
);
21344 write_obstack (out_file
, &symtab_obstack
);
21345 write_obstack (out_file
, &constant_pool
);
21349 /* We want to keep the file, so we set cleanup_filename to NULL
21350 here. See unlink_if_set. */
21351 cleanup_filename
= NULL
;
21353 do_cleanups (cleanup
);
21356 /* Implementation of the `save gdb-index' command.
21358 Note that the file format used by this command is documented in the
21359 GDB manual. Any changes here must be documented there. */
21362 save_gdb_index_command (char *arg
, int from_tty
)
21364 struct objfile
*objfile
;
21367 error (_("usage: save gdb-index DIRECTORY"));
21369 ALL_OBJFILES (objfile
)
21373 /* If the objfile does not correspond to an actual file, skip it. */
21374 if (stat (objfile
->name
, &st
) < 0)
21377 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
21378 if (dwarf2_per_objfile
)
21380 volatile struct gdb_exception except
;
21382 TRY_CATCH (except
, RETURN_MASK_ERROR
)
21384 write_psymtabs_to_index (objfile
, arg
);
21386 if (except
.reason
< 0)
21387 exception_fprintf (gdb_stderr
, except
,
21388 _("Error while writing index for `%s': "),
21396 int dwarf2_always_disassemble
;
21399 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
21400 struct cmd_list_element
*c
, const char *value
)
21402 fprintf_filtered (file
,
21403 _("Whether to always disassemble "
21404 "DWARF expressions is %s.\n"),
21409 show_check_physname (struct ui_file
*file
, int from_tty
,
21410 struct cmd_list_element
*c
, const char *value
)
21412 fprintf_filtered (file
,
21413 _("Whether to check \"physname\" is %s.\n"),
21417 void _initialize_dwarf2_read (void);
21420 _initialize_dwarf2_read (void)
21422 struct cmd_list_element
*c
;
21424 dwarf2_objfile_data_key
21425 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
21427 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
21428 Set DWARF 2 specific variables.\n\
21429 Configure DWARF 2 variables such as the cache size"),
21430 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
21431 0/*allow-unknown*/, &maintenance_set_cmdlist
);
21433 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
21434 Show DWARF 2 specific variables\n\
21435 Show DWARF 2 variables such as the cache size"),
21436 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
21437 0/*allow-unknown*/, &maintenance_show_cmdlist
);
21439 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
21440 &dwarf2_max_cache_age
, _("\
21441 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
21442 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
21443 A higher limit means that cached compilation units will be stored\n\
21444 in memory longer, and more total memory will be used. Zero disables\n\
21445 caching, which can slow down startup."),
21447 show_dwarf2_max_cache_age
,
21448 &set_dwarf2_cmdlist
,
21449 &show_dwarf2_cmdlist
);
21451 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
21452 &dwarf2_always_disassemble
, _("\
21453 Set whether `info address' always disassembles DWARF expressions."), _("\
21454 Show whether `info address' always disassembles DWARF expressions."), _("\
21455 When enabled, DWARF expressions are always printed in an assembly-like\n\
21456 syntax. When disabled, expressions will be printed in a more\n\
21457 conversational style, when possible."),
21459 show_dwarf2_always_disassemble
,
21460 &set_dwarf2_cmdlist
,
21461 &show_dwarf2_cmdlist
);
21463 add_setshow_boolean_cmd ("dwarf2-read", no_class
, &dwarf2_read_debug
, _("\
21464 Set debugging of the dwarf2 reader."), _("\
21465 Show debugging of the dwarf2 reader."), _("\
21466 When enabled, debugging messages are printed during dwarf2 reading\n\
21467 and symtab expansion."),
21470 &setdebuglist
, &showdebuglist
);
21472 add_setshow_zuinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
21473 Set debugging of the dwarf2 DIE reader."), _("\
21474 Show debugging of the dwarf2 DIE reader."), _("\
21475 When enabled (non-zero), DIEs are dumped after they are read in.\n\
21476 The value is the maximum depth to print."),
21479 &setdebuglist
, &showdebuglist
);
21481 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
21482 Set cross-checking of \"physname\" code against demangler."), _("\
21483 Show cross-checking of \"physname\" code against demangler."), _("\
21484 When enabled, GDB's internal \"physname\" code is checked against\n\
21486 NULL
, show_check_physname
,
21487 &setdebuglist
, &showdebuglist
);
21489 add_setshow_boolean_cmd ("use-deprecated-index-sections",
21490 no_class
, &use_deprecated_index_sections
, _("\
21491 Set whether to use deprecated gdb_index sections."), _("\
21492 Show whether to use deprecated gdb_index sections."), _("\
21493 When enabled, deprecated .gdb_index sections are used anyway.\n\
21494 Normally they are ignored either because of a missing feature or\n\
21495 performance issue.\n\
21496 Warning: This option must be enabled before gdb reads the file."),
21499 &setlist
, &showlist
);
21501 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
21503 Save a gdb-index file.\n\
21504 Usage: save gdb-index DIRECTORY"),
21506 set_cmd_completer (c
, filename_completer
);
21508 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
21509 &dwarf2_locexpr_funcs
);
21510 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
21511 &dwarf2_loclist_funcs
);
21513 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
21514 &dwarf2_block_frame_base_locexpr_funcs
);
21515 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
21516 &dwarf2_block_frame_base_loclist_funcs
);