1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2013 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
40 #include "gdb-demangle.h"
41 #include "expression.h"
42 #include "filenames.h" /* for DOSish file names */
45 #include "complaints.h"
47 #include "dwarf2expr.h"
48 #include "dwarf2loc.h"
49 #include "cp-support.h"
55 #include "typeprint.h"
58 #include "exceptions.h"
60 #include "completer.h"
65 #include "gdbcore.h" /* for gnutarget */
66 #include "gdb/gdb-index.h"
72 #include "gdb_string.h"
73 #include "gdb_assert.h"
74 #include <sys/types.h>
76 typedef struct symbol
*symbolp
;
79 /* When non-zero, print basic high level tracing messages.
80 This is in contrast to the low level DIE reading of dwarf2_die_debug. */
81 static int dwarf2_read_debug
= 0;
83 /* When non-zero, dump DIEs after they are read in. */
84 static unsigned int dwarf2_die_debug
= 0;
86 /* When non-zero, cross-check physname against demangler. */
87 static int check_physname
= 0;
89 /* When non-zero, do not reject deprecated .gdb_index sections. */
90 static int use_deprecated_index_sections
= 0;
92 /* When set, the file that we're processing is known to have debugging
93 info for C++ namespaces. GCC 3.3.x did not produce this information,
94 but later versions do. */
96 static int processing_has_namespace_info
;
98 static const struct objfile_data
*dwarf2_objfile_data_key
;
100 struct dwarf2_section_info
105 /* True if we have tried to read this section. */
109 typedef struct dwarf2_section_info dwarf2_section_info_def
;
110 DEF_VEC_O (dwarf2_section_info_def
);
112 /* All offsets in the index are of this type. It must be
113 architecture-independent. */
114 typedef uint32_t offset_type
;
116 DEF_VEC_I (offset_type
);
118 /* Ensure only legit values are used. */
119 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
121 gdb_assert ((unsigned int) (value) <= 1); \
122 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
125 /* Ensure only legit values are used. */
126 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
128 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
129 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
130 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
133 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
134 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
136 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
137 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
140 /* A description of the mapped index. The file format is described in
141 a comment by the code that writes the index. */
144 /* Index data format version. */
147 /* The total length of the buffer. */
150 /* A pointer to the address table data. */
151 const gdb_byte
*address_table
;
153 /* Size of the address table data in bytes. */
154 offset_type address_table_size
;
156 /* The symbol table, implemented as a hash table. */
157 const offset_type
*symbol_table
;
159 /* Size in slots, each slot is 2 offset_types. */
160 offset_type symbol_table_slots
;
162 /* A pointer to the constant pool. */
163 const char *constant_pool
;
166 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
167 DEF_VEC_P (dwarf2_per_cu_ptr
);
169 /* Collection of data recorded per objfile.
170 This hangs off of dwarf2_objfile_data_key. */
172 struct dwarf2_per_objfile
174 struct dwarf2_section_info info
;
175 struct dwarf2_section_info abbrev
;
176 struct dwarf2_section_info line
;
177 struct dwarf2_section_info loc
;
178 struct dwarf2_section_info macinfo
;
179 struct dwarf2_section_info macro
;
180 struct dwarf2_section_info str
;
181 struct dwarf2_section_info ranges
;
182 struct dwarf2_section_info addr
;
183 struct dwarf2_section_info frame
;
184 struct dwarf2_section_info eh_frame
;
185 struct dwarf2_section_info gdb_index
;
187 VEC (dwarf2_section_info_def
) *types
;
190 struct objfile
*objfile
;
192 /* Table of all the compilation units. This is used to locate
193 the target compilation unit of a particular reference. */
194 struct dwarf2_per_cu_data
**all_comp_units
;
196 /* The number of compilation units in ALL_COMP_UNITS. */
199 /* The number of .debug_types-related CUs. */
202 /* The .debug_types-related CUs (TUs). */
203 struct signatured_type
**all_type_units
;
205 /* The number of entries in all_type_unit_groups. */
206 int n_type_unit_groups
;
208 /* Table of type unit groups.
209 This exists to make it easy to iterate over all CUs and TU groups. */
210 struct type_unit_group
**all_type_unit_groups
;
212 /* Table of struct type_unit_group objects.
213 The hash key is the DW_AT_stmt_list value. */
214 htab_t type_unit_groups
;
216 /* A table mapping .debug_types signatures to its signatured_type entry.
217 This is NULL if the .debug_types section hasn't been read in yet. */
218 htab_t signatured_types
;
220 /* Type unit statistics, to see how well the scaling improvements
224 int nr_uniq_abbrev_tables
;
226 int nr_symtab_sharers
;
227 int nr_stmt_less_type_units
;
230 /* A chain of compilation units that are currently read in, so that
231 they can be freed later. */
232 struct dwarf2_per_cu_data
*read_in_chain
;
234 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
235 This is NULL if the table hasn't been allocated yet. */
238 /* Non-zero if we've check for whether there is a DWP file. */
241 /* The DWP file if there is one, or NULL. */
242 struct dwp_file
*dwp_file
;
244 /* The shared '.dwz' file, if one exists. This is used when the
245 original data was compressed using 'dwz -m'. */
246 struct dwz_file
*dwz_file
;
248 /* A flag indicating wether this objfile has a section loaded at a
250 int has_section_at_zero
;
252 /* True if we are using the mapped index,
253 or we are faking it for OBJF_READNOW's sake. */
254 unsigned char using_index
;
256 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
257 struct mapped_index
*index_table
;
259 /* When using index_table, this keeps track of all quick_file_names entries.
260 TUs typically share line table entries with a CU, so we maintain a
261 separate table of all line table entries to support the sharing.
262 Note that while there can be way more TUs than CUs, we've already
263 sorted all the TUs into "type unit groups", grouped by their
264 DW_AT_stmt_list value. Therefore the only sharing done here is with a
265 CU and its associated TU group if there is one. */
266 htab_t quick_file_names_table
;
268 /* Set during partial symbol reading, to prevent queueing of full
270 int reading_partial_symbols
;
272 /* Table mapping type DIEs to their struct type *.
273 This is NULL if not allocated yet.
274 The mapping is done via (CU/TU signature + DIE offset) -> type. */
275 htab_t die_type_hash
;
277 /* The CUs we recently read. */
278 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
281 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
283 /* Default names of the debugging sections. */
285 /* Note that if the debugging section has been compressed, it might
286 have a name like .zdebug_info. */
288 static const struct dwarf2_debug_sections dwarf2_elf_names
=
290 { ".debug_info", ".zdebug_info" },
291 { ".debug_abbrev", ".zdebug_abbrev" },
292 { ".debug_line", ".zdebug_line" },
293 { ".debug_loc", ".zdebug_loc" },
294 { ".debug_macinfo", ".zdebug_macinfo" },
295 { ".debug_macro", ".zdebug_macro" },
296 { ".debug_str", ".zdebug_str" },
297 { ".debug_ranges", ".zdebug_ranges" },
298 { ".debug_types", ".zdebug_types" },
299 { ".debug_addr", ".zdebug_addr" },
300 { ".debug_frame", ".zdebug_frame" },
301 { ".eh_frame", NULL
},
302 { ".gdb_index", ".zgdb_index" },
306 /* List of DWO/DWP sections. */
308 static const struct dwop_section_names
310 struct dwarf2_section_names abbrev_dwo
;
311 struct dwarf2_section_names info_dwo
;
312 struct dwarf2_section_names line_dwo
;
313 struct dwarf2_section_names loc_dwo
;
314 struct dwarf2_section_names macinfo_dwo
;
315 struct dwarf2_section_names macro_dwo
;
316 struct dwarf2_section_names str_dwo
;
317 struct dwarf2_section_names str_offsets_dwo
;
318 struct dwarf2_section_names types_dwo
;
319 struct dwarf2_section_names cu_index
;
320 struct dwarf2_section_names tu_index
;
324 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
325 { ".debug_info.dwo", ".zdebug_info.dwo" },
326 { ".debug_line.dwo", ".zdebug_line.dwo" },
327 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
328 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
329 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
330 { ".debug_str.dwo", ".zdebug_str.dwo" },
331 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
332 { ".debug_types.dwo", ".zdebug_types.dwo" },
333 { ".debug_cu_index", ".zdebug_cu_index" },
334 { ".debug_tu_index", ".zdebug_tu_index" },
337 /* local data types */
339 /* The data in a compilation unit header, after target2host
340 translation, looks like this. */
341 struct comp_unit_head
345 unsigned char addr_size
;
346 unsigned char signed_addr_p
;
347 sect_offset abbrev_offset
;
349 /* Size of file offsets; either 4 or 8. */
350 unsigned int offset_size
;
352 /* Size of the length field; either 4 or 12. */
353 unsigned int initial_length_size
;
355 /* Offset to the first byte of this compilation unit header in the
356 .debug_info section, for resolving relative reference dies. */
359 /* Offset to first die in this cu from the start of the cu.
360 This will be the first byte following the compilation unit header. */
361 cu_offset first_die_offset
;
364 /* Type used for delaying computation of method physnames.
365 See comments for compute_delayed_physnames. */
366 struct delayed_method_info
368 /* The type to which the method is attached, i.e., its parent class. */
371 /* The index of the method in the type's function fieldlists. */
374 /* The index of the method in the fieldlist. */
377 /* The name of the DIE. */
380 /* The DIE associated with this method. */
381 struct die_info
*die
;
384 typedef struct delayed_method_info delayed_method_info
;
385 DEF_VEC_O (delayed_method_info
);
387 /* Internal state when decoding a particular compilation unit. */
390 /* The objfile containing this compilation unit. */
391 struct objfile
*objfile
;
393 /* The header of the compilation unit. */
394 struct comp_unit_head header
;
396 /* Base address of this compilation unit. */
397 CORE_ADDR base_address
;
399 /* Non-zero if base_address has been set. */
402 /* The language we are debugging. */
403 enum language language
;
404 const struct language_defn
*language_defn
;
406 const char *producer
;
408 /* The generic symbol table building routines have separate lists for
409 file scope symbols and all all other scopes (local scopes). So
410 we need to select the right one to pass to add_symbol_to_list().
411 We do it by keeping a pointer to the correct list in list_in_scope.
413 FIXME: The original dwarf code just treated the file scope as the
414 first local scope, and all other local scopes as nested local
415 scopes, and worked fine. Check to see if we really need to
416 distinguish these in buildsym.c. */
417 struct pending
**list_in_scope
;
419 /* The abbrev table for this CU.
420 Normally this points to the abbrev table in the objfile.
421 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
422 struct abbrev_table
*abbrev_table
;
424 /* Hash table holding all the loaded partial DIEs
425 with partial_die->offset.SECT_OFF as hash. */
428 /* Storage for things with the same lifetime as this read-in compilation
429 unit, including partial DIEs. */
430 struct obstack comp_unit_obstack
;
432 /* When multiple dwarf2_cu structures are living in memory, this field
433 chains them all together, so that they can be released efficiently.
434 We will probably also want a generation counter so that most-recently-used
435 compilation units are cached... */
436 struct dwarf2_per_cu_data
*read_in_chain
;
438 /* Backchain to our per_cu entry if the tree has been built. */
439 struct dwarf2_per_cu_data
*per_cu
;
441 /* How many compilation units ago was this CU last referenced? */
444 /* A hash table of DIE cu_offset for following references with
445 die_info->offset.sect_off as hash. */
448 /* Full DIEs if read in. */
449 struct die_info
*dies
;
451 /* A set of pointers to dwarf2_per_cu_data objects for compilation
452 units referenced by this one. Only set during full symbol processing;
453 partial symbol tables do not have dependencies. */
456 /* Header data from the line table, during full symbol processing. */
457 struct line_header
*line_header
;
459 /* A list of methods which need to have physnames computed
460 after all type information has been read. */
461 VEC (delayed_method_info
) *method_list
;
463 /* To be copied to symtab->call_site_htab. */
464 htab_t call_site_htab
;
466 /* Non-NULL if this CU came from a DWO file.
467 There is an invariant here that is important to remember:
468 Except for attributes copied from the top level DIE in the "main"
469 (or "stub") file in preparation for reading the DWO file
470 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
471 Either there isn't a DWO file (in which case this is NULL and the point
472 is moot), or there is and either we're not going to read it (in which
473 case this is NULL) or there is and we are reading it (in which case this
475 struct dwo_unit
*dwo_unit
;
477 /* The DW_AT_addr_base attribute if present, zero otherwise
478 (zero is a valid value though).
479 Note this value comes from the stub CU/TU's DIE. */
482 /* The DW_AT_ranges_base attribute if present, zero otherwise
483 (zero is a valid value though).
484 Note this value comes from the stub CU/TU's DIE.
485 Also note that the value is zero in the non-DWO case so this value can
486 be used without needing to know whether DWO files are in use or not.
487 N.B. This does not apply to DW_AT_ranges appearing in
488 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
489 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
490 DW_AT_ranges_base *would* have to be applied, and we'd have to care
491 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
492 ULONGEST ranges_base
;
494 /* Mark used when releasing cached dies. */
495 unsigned int mark
: 1;
497 /* This CU references .debug_loc. See the symtab->locations_valid field.
498 This test is imperfect as there may exist optimized debug code not using
499 any location list and still facing inlining issues if handled as
500 unoptimized code. For a future better test see GCC PR other/32998. */
501 unsigned int has_loclist
: 1;
503 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
504 if all the producer_is_* fields are valid. This information is cached
505 because profiling CU expansion showed excessive time spent in
506 producer_is_gxx_lt_4_6. */
507 unsigned int checked_producer
: 1;
508 unsigned int producer_is_gxx_lt_4_6
: 1;
509 unsigned int producer_is_gcc_lt_4_3
: 1;
510 unsigned int producer_is_icc
: 1;
513 /* Persistent data held for a compilation unit, even when not
514 processing it. We put a pointer to this structure in the
515 read_symtab_private field of the psymtab. */
517 struct dwarf2_per_cu_data
519 /* The start offset and length of this compilation unit.
520 NOTE: Unlike comp_unit_head.length, this length includes
522 If the DIE refers to a DWO file, this is always of the original die,
527 /* Flag indicating this compilation unit will be read in before
528 any of the current compilation units are processed. */
529 unsigned int queued
: 1;
531 /* This flag will be set when reading partial DIEs if we need to load
532 absolutely all DIEs for this compilation unit, instead of just the ones
533 we think are interesting. It gets set if we look for a DIE in the
534 hash table and don't find it. */
535 unsigned int load_all_dies
: 1;
537 /* Non-zero if this CU is from .debug_types. */
538 unsigned int is_debug_types
: 1;
540 /* Non-zero if this CU is from the .dwz file. */
541 unsigned int is_dwz
: 1;
543 /* The section this CU/TU lives in.
544 If the DIE refers to a DWO file, this is always the original die,
546 struct dwarf2_section_info
*info_or_types_section
;
548 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
549 of the CU cache it gets reset to NULL again. */
550 struct dwarf2_cu
*cu
;
552 /* The corresponding objfile.
553 Normally we can get the objfile from dwarf2_per_objfile.
554 However we can enter this file with just a "per_cu" handle. */
555 struct objfile
*objfile
;
557 /* When using partial symbol tables, the 'psymtab' field is active.
558 Otherwise the 'quick' field is active. */
561 /* The partial symbol table associated with this compilation unit,
562 or NULL for unread partial units. */
563 struct partial_symtab
*psymtab
;
565 /* Data needed by the "quick" functions. */
566 struct dwarf2_per_cu_quick_data
*quick
;
571 /* The CUs we import using DW_TAG_imported_unit. This is filled in
572 while reading psymtabs, used to compute the psymtab dependencies,
573 and then cleared. Then it is filled in again while reading full
574 symbols, and only deleted when the objfile is destroyed. */
575 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
577 /* Type units are grouped by their DW_AT_stmt_list entry so that they
578 can share them. If this is a TU, this points to the containing
580 struct type_unit_group
*type_unit_group
;
584 /* Entry in the signatured_types hash table. */
586 struct signatured_type
588 /* The "per_cu" object of this type.
589 N.B.: This is the first member so that it's easy to convert pointers
591 struct dwarf2_per_cu_data per_cu
;
593 /* The type's signature. */
596 /* Offset in the TU of the type's DIE, as read from the TU header.
597 If the definition lives in a DWO file, this value is unusable. */
598 cu_offset type_offset_in_tu
;
600 /* Offset in the section of the type's DIE.
601 If the definition lives in a DWO file, this is the offset in the
602 .debug_types.dwo section.
603 The value is zero until the actual value is known.
604 Zero is otherwise not a valid section offset. */
605 sect_offset type_offset_in_section
;
608 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
609 This includes type_unit_group and quick_file_names. */
611 struct stmt_list_hash
613 /* The DWO unit this table is from or NULL if there is none. */
614 struct dwo_unit
*dwo_unit
;
616 /* Offset in .debug_line or .debug_line.dwo. */
617 sect_offset line_offset
;
620 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
621 an object of this type. */
623 struct type_unit_group
625 /* dwarf2read.c's main "handle" on the symtab.
626 To simplify things we create an artificial CU that "includes" all the
627 type units using this stmt_list so that the rest of the code still has
628 a "per_cu" handle on the symtab.
629 This PER_CU is recognized by having no section. */
630 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->info_or_types_section == NULL)
631 struct dwarf2_per_cu_data per_cu
;
635 /* The TUs that share this DW_AT_stmt_list entry.
636 This is added to while parsing type units to build partial symtabs,
637 and is deleted afterwards and not used again. */
638 VEC (dwarf2_per_cu_ptr
) *tus
;
640 /* When reading the line table in "quick" functions, we need a real TU.
641 Any will do, we know they all share the same DW_AT_stmt_list entry.
642 For simplicity's sake, we pick the first one. */
643 struct dwarf2_per_cu_data
*first_tu
;
646 /* The primary symtab.
647 Type units in a group needn't all be defined in the same source file,
648 so we create an essentially anonymous symtab as the primary symtab. */
649 struct symtab
*primary_symtab
;
651 /* The data used to construct the hash key. */
652 struct stmt_list_hash hash
;
654 /* The number of symtabs from the line header.
655 The value here must match line_header.num_file_names. */
656 unsigned int num_symtabs
;
658 /* The symbol tables for this TU (obtained from the files listed in
660 WARNING: The order of entries here must match the order of entries
661 in the line header. After the first TU using this type_unit_group, the
662 line header for the subsequent TUs is recreated from this. This is done
663 because we need to use the same symtabs for each TU using the same
664 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
665 there's no guarantee the line header doesn't have duplicate entries. */
666 struct symtab
**symtabs
;
669 /* These sections are what may appear in a DWO file. */
673 struct dwarf2_section_info abbrev
;
674 struct dwarf2_section_info line
;
675 struct dwarf2_section_info loc
;
676 struct dwarf2_section_info macinfo
;
677 struct dwarf2_section_info macro
;
678 struct dwarf2_section_info str
;
679 struct dwarf2_section_info str_offsets
;
680 /* In the case of a virtual DWO file, these two are unused. */
681 struct dwarf2_section_info info
;
682 VEC (dwarf2_section_info_def
) *types
;
685 /* Common bits of DWO CUs/TUs. */
689 /* Backlink to the containing struct dwo_file. */
690 struct dwo_file
*dwo_file
;
692 /* The "id" that distinguishes this CU/TU.
693 .debug_info calls this "dwo_id", .debug_types calls this "signature".
694 Since signatures came first, we stick with it for consistency. */
697 /* The section this CU/TU lives in, in the DWO file. */
698 struct dwarf2_section_info
*info_or_types_section
;
700 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
704 /* For types, offset in the type's DIE of the type defined by this TU. */
705 cu_offset type_offset_in_tu
;
708 /* Data for one DWO file.
709 This includes virtual DWO files that have been packaged into a
714 /* The DW_AT_GNU_dwo_name attribute. This is the hash key.
715 For virtual DWO files the name is constructed from the section offsets
716 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
717 from related CU+TUs. */
720 /* The bfd, when the file is open. Otherwise this is NULL.
721 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
724 /* Section info for this file. */
725 struct dwo_sections sections
;
727 /* Table of CUs in the file.
728 Each element is a struct dwo_unit. */
731 /* Table of TUs in the file.
732 Each element is a struct dwo_unit. */
736 /* These sections are what may appear in a DWP file. */
740 struct dwarf2_section_info str
;
741 struct dwarf2_section_info cu_index
;
742 struct dwarf2_section_info tu_index
;
743 /* The .debug_info.dwo, .debug_types.dwo, and other sections are referenced
744 by section number. We don't need to record them here. */
747 /* These sections are what may appear in a virtual DWO file. */
749 struct virtual_dwo_sections
751 struct dwarf2_section_info abbrev
;
752 struct dwarf2_section_info line
;
753 struct dwarf2_section_info loc
;
754 struct dwarf2_section_info macinfo
;
755 struct dwarf2_section_info macro
;
756 struct dwarf2_section_info str_offsets
;
757 /* Each DWP hash table entry records one CU or one TU.
758 That is recorded here, and copied to dwo_unit.info_or_types_section. */
759 struct dwarf2_section_info info_or_types
;
762 /* Contents of DWP hash tables. */
764 struct dwp_hash_table
766 uint32_t nr_units
, nr_slots
;
767 const gdb_byte
*hash_table
, *unit_table
, *section_pool
;
770 /* Data for one DWP file. */
774 /* Name of the file. */
777 /* The bfd, when the file is open. Otherwise this is NULL. */
780 /* Section info for this file. */
781 struct dwp_sections sections
;
783 /* Table of CUs in the file. */
784 const struct dwp_hash_table
*cus
;
786 /* Table of TUs in the file. */
787 const struct dwp_hash_table
*tus
;
789 /* Table of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
792 /* Table to map ELF section numbers to their sections. */
793 unsigned int num_sections
;
794 asection
**elf_sections
;
797 /* This represents a '.dwz' file. */
801 /* A dwz file can only contain a few sections. */
802 struct dwarf2_section_info abbrev
;
803 struct dwarf2_section_info info
;
804 struct dwarf2_section_info str
;
805 struct dwarf2_section_info line
;
806 struct dwarf2_section_info macro
;
807 struct dwarf2_section_info gdb_index
;
813 /* Struct used to pass misc. parameters to read_die_and_children, et
814 al. which are used for both .debug_info and .debug_types dies.
815 All parameters here are unchanging for the life of the call. This
816 struct exists to abstract away the constant parameters of die reading. */
818 struct die_reader_specs
820 /* die_section->asection->owner. */
823 /* The CU of the DIE we are parsing. */
824 struct dwarf2_cu
*cu
;
826 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
827 struct dwo_file
*dwo_file
;
829 /* The section the die comes from.
830 This is either .debug_info or .debug_types, or the .dwo variants. */
831 struct dwarf2_section_info
*die_section
;
833 /* die_section->buffer. */
836 /* The end of the buffer. */
837 const gdb_byte
*buffer_end
;
840 /* Type of function passed to init_cutu_and_read_dies, et.al. */
841 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
843 struct die_info
*comp_unit_die
,
847 /* The line number information for a compilation unit (found in the
848 .debug_line section) begins with a "statement program header",
849 which contains the following information. */
852 unsigned int total_length
;
853 unsigned short version
;
854 unsigned int header_length
;
855 unsigned char minimum_instruction_length
;
856 unsigned char maximum_ops_per_instruction
;
857 unsigned char default_is_stmt
;
859 unsigned char line_range
;
860 unsigned char opcode_base
;
862 /* standard_opcode_lengths[i] is the number of operands for the
863 standard opcode whose value is i. This means that
864 standard_opcode_lengths[0] is unused, and the last meaningful
865 element is standard_opcode_lengths[opcode_base - 1]. */
866 unsigned char *standard_opcode_lengths
;
868 /* The include_directories table. NOTE! These strings are not
869 allocated with xmalloc; instead, they are pointers into
870 debug_line_buffer. If you try to free them, `free' will get
872 unsigned int num_include_dirs
, include_dirs_size
;
875 /* The file_names table. NOTE! These strings are not allocated
876 with xmalloc; instead, they are pointers into debug_line_buffer.
877 Don't try to free them directly. */
878 unsigned int num_file_names
, file_names_size
;
882 unsigned int dir_index
;
883 unsigned int mod_time
;
885 int included_p
; /* Non-zero if referenced by the Line Number Program. */
886 struct symtab
*symtab
; /* The associated symbol table, if any. */
889 /* The start and end of the statement program following this
890 header. These point into dwarf2_per_objfile->line_buffer. */
891 gdb_byte
*statement_program_start
, *statement_program_end
;
894 /* When we construct a partial symbol table entry we only
895 need this much information. */
896 struct partial_die_info
898 /* Offset of this DIE. */
901 /* DWARF-2 tag for this DIE. */
902 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
904 /* Assorted flags describing the data found in this DIE. */
905 unsigned int has_children
: 1;
906 unsigned int is_external
: 1;
907 unsigned int is_declaration
: 1;
908 unsigned int has_type
: 1;
909 unsigned int has_specification
: 1;
910 unsigned int has_pc_info
: 1;
911 unsigned int may_be_inlined
: 1;
913 /* Flag set if the SCOPE field of this structure has been
915 unsigned int scope_set
: 1;
917 /* Flag set if the DIE has a byte_size attribute. */
918 unsigned int has_byte_size
: 1;
920 /* Flag set if any of the DIE's children are template arguments. */
921 unsigned int has_template_arguments
: 1;
923 /* Flag set if fixup_partial_die has been called on this die. */
924 unsigned int fixup_called
: 1;
926 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
927 unsigned int is_dwz
: 1;
929 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
930 unsigned int spec_is_dwz
: 1;
932 /* The name of this DIE. Normally the value of DW_AT_name, but
933 sometimes a default name for unnamed DIEs. */
936 /* The linkage name, if present. */
937 const char *linkage_name
;
939 /* The scope to prepend to our children. This is generally
940 allocated on the comp_unit_obstack, so will disappear
941 when this compilation unit leaves the cache. */
944 /* Some data associated with the partial DIE. The tag determines
945 which field is live. */
948 /* The location description associated with this DIE, if any. */
949 struct dwarf_block
*locdesc
;
950 /* The offset of an import, for DW_TAG_imported_unit. */
954 /* If HAS_PC_INFO, the PC range associated with this DIE. */
958 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
959 DW_AT_sibling, if any. */
960 /* NOTE: This member isn't strictly necessary, read_partial_die could
961 return DW_AT_sibling values to its caller load_partial_dies. */
964 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
965 DW_AT_specification (or DW_AT_abstract_origin or
967 sect_offset spec_offset
;
969 /* Pointers to this DIE's parent, first child, and next sibling,
971 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
974 /* This data structure holds the information of an abbrev. */
977 unsigned int number
; /* number identifying abbrev */
978 enum dwarf_tag tag
; /* dwarf tag */
979 unsigned short has_children
; /* boolean */
980 unsigned short num_attrs
; /* number of attributes */
981 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
982 struct abbrev_info
*next
; /* next in chain */
987 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
988 ENUM_BITFIELD(dwarf_form
) form
: 16;
991 /* Size of abbrev_table.abbrev_hash_table. */
992 #define ABBREV_HASH_SIZE 121
994 /* Top level data structure to contain an abbreviation table. */
998 /* Where the abbrev table came from.
999 This is used as a sanity check when the table is used. */
1002 /* Storage for the abbrev table. */
1003 struct obstack abbrev_obstack
;
1005 /* Hash table of abbrevs.
1006 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1007 It could be statically allocated, but the previous code didn't so we
1009 struct abbrev_info
**abbrevs
;
1012 /* Attributes have a name and a value. */
1015 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1016 ENUM_BITFIELD(dwarf_form
) form
: 15;
1018 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1019 field should be in u.str (existing only for DW_STRING) but it is kept
1020 here for better struct attribute alignment. */
1021 unsigned int string_is_canonical
: 1;
1026 struct dwarf_block
*blk
;
1030 struct signatured_type
*signatured_type
;
1035 /* This data structure holds a complete die structure. */
1038 /* DWARF-2 tag for this DIE. */
1039 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1041 /* Number of attributes */
1042 unsigned char num_attrs
;
1044 /* True if we're presently building the full type name for the
1045 type derived from this DIE. */
1046 unsigned char building_fullname
: 1;
1049 unsigned int abbrev
;
1051 /* Offset in .debug_info or .debug_types section. */
1054 /* The dies in a compilation unit form an n-ary tree. PARENT
1055 points to this die's parent; CHILD points to the first child of
1056 this node; and all the children of a given node are chained
1057 together via their SIBLING fields. */
1058 struct die_info
*child
; /* Its first child, if any. */
1059 struct die_info
*sibling
; /* Its next sibling, if any. */
1060 struct die_info
*parent
; /* Its parent, if any. */
1062 /* An array of attributes, with NUM_ATTRS elements. There may be
1063 zero, but it's not common and zero-sized arrays are not
1064 sufficiently portable C. */
1065 struct attribute attrs
[1];
1068 /* Get at parts of an attribute structure. */
1070 #define DW_STRING(attr) ((attr)->u.str)
1071 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1072 #define DW_UNSND(attr) ((attr)->u.unsnd)
1073 #define DW_BLOCK(attr) ((attr)->u.blk)
1074 #define DW_SND(attr) ((attr)->u.snd)
1075 #define DW_ADDR(attr) ((attr)->u.addr)
1076 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
1078 /* Blocks are a bunch of untyped bytes. */
1083 /* Valid only if SIZE is not zero. */
1087 #ifndef ATTR_ALLOC_CHUNK
1088 #define ATTR_ALLOC_CHUNK 4
1091 /* Allocate fields for structs, unions and enums in this size. */
1092 #ifndef DW_FIELD_ALLOC_CHUNK
1093 #define DW_FIELD_ALLOC_CHUNK 4
1096 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1097 but this would require a corresponding change in unpack_field_as_long
1099 static int bits_per_byte
= 8;
1101 /* The routines that read and process dies for a C struct or C++ class
1102 pass lists of data member fields and lists of member function fields
1103 in an instance of a field_info structure, as defined below. */
1106 /* List of data member and baseclasses fields. */
1109 struct nextfield
*next
;
1114 *fields
, *baseclasses
;
1116 /* Number of fields (including baseclasses). */
1119 /* Number of baseclasses. */
1122 /* Set if the accesibility of one of the fields is not public. */
1123 int non_public_fields
;
1125 /* Member function fields array, entries are allocated in the order they
1126 are encountered in the object file. */
1129 struct nextfnfield
*next
;
1130 struct fn_field fnfield
;
1134 /* Member function fieldlist array, contains name of possibly overloaded
1135 member function, number of overloaded member functions and a pointer
1136 to the head of the member function field chain. */
1141 struct nextfnfield
*head
;
1145 /* Number of entries in the fnfieldlists array. */
1148 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1149 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1150 struct typedef_field_list
1152 struct typedef_field field
;
1153 struct typedef_field_list
*next
;
1155 *typedef_field_list
;
1156 unsigned typedef_field_list_count
;
1159 /* One item on the queue of compilation units to read in full symbols
1161 struct dwarf2_queue_item
1163 struct dwarf2_per_cu_data
*per_cu
;
1164 enum language pretend_language
;
1165 struct dwarf2_queue_item
*next
;
1168 /* The current queue. */
1169 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1171 /* Loaded secondary compilation units are kept in memory until they
1172 have not been referenced for the processing of this many
1173 compilation units. Set this to zero to disable caching. Cache
1174 sizes of up to at least twenty will improve startup time for
1175 typical inter-CU-reference binaries, at an obvious memory cost. */
1176 static int dwarf2_max_cache_age
= 5;
1178 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
1179 struct cmd_list_element
*c
, const char *value
)
1181 fprintf_filtered (file
, _("The upper bound on the age of cached "
1182 "dwarf2 compilation units is %s.\n"),
1187 /* Various complaints about symbol reading that don't abort the process. */
1190 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1192 complaint (&symfile_complaints
,
1193 _("statement list doesn't fit in .debug_line section"));
1197 dwarf2_debug_line_missing_file_complaint (void)
1199 complaint (&symfile_complaints
,
1200 _(".debug_line section has line data without a file"));
1204 dwarf2_debug_line_missing_end_sequence_complaint (void)
1206 complaint (&symfile_complaints
,
1207 _(".debug_line section has line "
1208 "program sequence without an end"));
1212 dwarf2_complex_location_expr_complaint (void)
1214 complaint (&symfile_complaints
, _("location expression too complex"));
1218 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1221 complaint (&symfile_complaints
,
1222 _("const value length mismatch for '%s', got %d, expected %d"),
1227 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1229 complaint (&symfile_complaints
,
1230 _("debug info runs off end of %s section"
1232 section
->asection
->name
,
1233 bfd_get_filename (section
->asection
->owner
));
1237 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1239 complaint (&symfile_complaints
,
1240 _("macro debug info contains a "
1241 "malformed macro definition:\n`%s'"),
1246 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1248 complaint (&symfile_complaints
,
1249 _("invalid attribute class or form for '%s' in '%s'"),
1253 /* local function prototypes */
1255 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1257 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
1260 static void dwarf2_find_base_address (struct die_info
*die
,
1261 struct dwarf2_cu
*cu
);
1263 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1265 static void scan_partial_symbols (struct partial_die_info
*,
1266 CORE_ADDR
*, CORE_ADDR
*,
1267 int, struct dwarf2_cu
*);
1269 static void add_partial_symbol (struct partial_die_info
*,
1270 struct dwarf2_cu
*);
1272 static void add_partial_namespace (struct partial_die_info
*pdi
,
1273 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1274 int need_pc
, struct dwarf2_cu
*cu
);
1276 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1277 CORE_ADDR
*highpc
, int need_pc
,
1278 struct dwarf2_cu
*cu
);
1280 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1281 struct dwarf2_cu
*cu
);
1283 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1284 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1285 int need_pc
, struct dwarf2_cu
*cu
);
1287 static void dwarf2_psymtab_to_symtab (struct objfile
*,
1288 struct partial_symtab
*);
1290 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1292 static struct abbrev_info
*abbrev_table_lookup_abbrev
1293 (const struct abbrev_table
*, unsigned int);
1295 static struct abbrev_table
*abbrev_table_read_table
1296 (struct dwarf2_section_info
*, sect_offset
);
1298 static void abbrev_table_free (struct abbrev_table
*);
1300 static void abbrev_table_free_cleanup (void *);
1302 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1303 struct dwarf2_section_info
*);
1305 static void dwarf2_free_abbrev_table (void *);
1307 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
1309 static struct partial_die_info
*load_partial_dies
1310 (const struct die_reader_specs
*, gdb_byte
*, int);
1312 static gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1313 struct partial_die_info
*,
1314 struct abbrev_info
*,
1318 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1319 struct dwarf2_cu
*);
1321 static void fixup_partial_die (struct partial_die_info
*,
1322 struct dwarf2_cu
*);
1324 static gdb_byte
*read_attribute (const struct die_reader_specs
*,
1325 struct attribute
*, struct attr_abbrev
*,
1328 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1330 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1332 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1334 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1336 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1338 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
1341 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
1343 static LONGEST read_checked_initial_length_and_offset
1344 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1345 unsigned int *, unsigned int *);
1347 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1350 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
1352 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1355 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
1357 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
1359 static char *read_indirect_string (bfd
*, gdb_byte
*,
1360 const struct comp_unit_head
*,
1363 static char *read_indirect_string_from_dwz (struct dwz_file
*, LONGEST
);
1365 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1367 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1369 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*, gdb_byte
*,
1372 static char *read_str_index (const struct die_reader_specs
*reader
,
1373 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1375 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1377 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1378 struct dwarf2_cu
*);
1380 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1383 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1384 struct dwarf2_cu
*cu
);
1386 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1388 static struct die_info
*die_specification (struct die_info
*die
,
1389 struct dwarf2_cu
**);
1391 static void free_line_header (struct line_header
*lh
);
1393 static void add_file_name (struct line_header
*, char *, unsigned int,
1394 unsigned int, unsigned int);
1396 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1397 struct dwarf2_cu
*cu
);
1399 static void dwarf_decode_lines (struct line_header
*, const char *,
1400 struct dwarf2_cu
*, struct partial_symtab
*,
1403 static void dwarf2_start_subfile (char *, const char *, const char *);
1405 static void dwarf2_start_symtab (struct dwarf2_cu
*,
1406 char *, char *, CORE_ADDR
);
1408 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1409 struct dwarf2_cu
*);
1411 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1412 struct dwarf2_cu
*, struct symbol
*);
1414 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1415 struct dwarf2_cu
*);
1417 static void dwarf2_const_value_attr (struct attribute
*attr
,
1420 struct obstack
*obstack
,
1421 struct dwarf2_cu
*cu
, LONGEST
*value
,
1423 struct dwarf2_locexpr_baton
**baton
);
1425 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1427 static int need_gnat_info (struct dwarf2_cu
*);
1429 static struct type
*die_descriptive_type (struct die_info
*,
1430 struct dwarf2_cu
*);
1432 static void set_descriptive_type (struct type
*, struct die_info
*,
1433 struct dwarf2_cu
*);
1435 static struct type
*die_containing_type (struct die_info
*,
1436 struct dwarf2_cu
*);
1438 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1439 struct dwarf2_cu
*);
1441 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1443 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1445 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1447 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1448 const char *suffix
, int physname
,
1449 struct dwarf2_cu
*cu
);
1451 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1453 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1455 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1457 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1459 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1461 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1462 struct dwarf2_cu
*, struct partial_symtab
*);
1464 static int dwarf2_get_pc_bounds (struct die_info
*,
1465 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1466 struct partial_symtab
*);
1468 static void get_scope_pc_bounds (struct die_info
*,
1469 CORE_ADDR
*, CORE_ADDR
*,
1470 struct dwarf2_cu
*);
1472 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1473 CORE_ADDR
, struct dwarf2_cu
*);
1475 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1476 struct dwarf2_cu
*);
1478 static void dwarf2_attach_fields_to_type (struct field_info
*,
1479 struct type
*, struct dwarf2_cu
*);
1481 static void dwarf2_add_member_fn (struct field_info
*,
1482 struct die_info
*, struct type
*,
1483 struct dwarf2_cu
*);
1485 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1487 struct dwarf2_cu
*);
1489 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1491 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1493 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1495 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1497 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1499 static struct type
*read_module_type (struct die_info
*die
,
1500 struct dwarf2_cu
*cu
);
1502 static const char *namespace_name (struct die_info
*die
,
1503 int *is_anonymous
, struct dwarf2_cu
*);
1505 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1507 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1509 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1510 struct dwarf2_cu
*);
1512 static struct die_info
*read_die_and_children (const struct die_reader_specs
*,
1514 gdb_byte
**new_info_ptr
,
1515 struct die_info
*parent
);
1517 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1519 gdb_byte
**new_info_ptr
,
1520 struct die_info
*parent
);
1522 static gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1523 struct die_info
**, gdb_byte
*, int *, int);
1525 static gdb_byte
*read_full_die (const struct die_reader_specs
*,
1526 struct die_info
**, gdb_byte
*, int *);
1528 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1530 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1533 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1535 static const char *dwarf2_full_name (char *name
,
1536 struct die_info
*die
,
1537 struct dwarf2_cu
*cu
);
1539 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1540 struct dwarf2_cu
**);
1542 static const char *dwarf_tag_name (unsigned int);
1544 static const char *dwarf_attr_name (unsigned int);
1546 static const char *dwarf_form_name (unsigned int);
1548 static char *dwarf_bool_name (unsigned int);
1550 static const char *dwarf_type_encoding_name (unsigned int);
1552 static struct die_info
*sibling_die (struct die_info
*);
1554 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1556 static void dump_die_for_error (struct die_info
*);
1558 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1561 /*static*/ void dump_die (struct die_info
*, int max_level
);
1563 static void store_in_ref_table (struct die_info
*,
1564 struct dwarf2_cu
*);
1566 static int is_ref_attr (struct attribute
*);
1568 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1570 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1572 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1574 struct dwarf2_cu
**);
1576 static struct die_info
*follow_die_ref (struct die_info
*,
1578 struct dwarf2_cu
**);
1580 static struct die_info
*follow_die_sig (struct die_info
*,
1582 struct dwarf2_cu
**);
1584 static struct signatured_type
*lookup_signatured_type_at_offset
1585 (struct objfile
*objfile
,
1586 struct dwarf2_section_info
*section
, sect_offset offset
);
1588 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1590 static void read_signatured_type (struct signatured_type
*);
1592 static struct type_unit_group
*get_type_unit_group
1593 (struct dwarf2_cu
*, struct attribute
*);
1595 static void build_type_unit_groups (die_reader_func_ftype
*, void *);
1597 /* memory allocation interface */
1599 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1601 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1603 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int,
1606 static int attr_form_is_block (struct attribute
*);
1608 static int attr_form_is_section_offset (struct attribute
*);
1610 static int attr_form_is_constant (struct attribute
*);
1612 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1613 struct dwarf2_loclist_baton
*baton
,
1614 struct attribute
*attr
);
1616 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1618 struct dwarf2_cu
*cu
);
1620 static gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1622 struct abbrev_info
*abbrev
);
1624 static void free_stack_comp_unit (void *);
1626 static hashval_t
partial_die_hash (const void *item
);
1628 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1630 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1631 (sect_offset offset
, unsigned int offset_in_dwz
, struct objfile
*objfile
);
1633 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1634 struct dwarf2_per_cu_data
*per_cu
);
1636 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1637 struct die_info
*comp_unit_die
,
1638 enum language pretend_language
);
1640 static void free_heap_comp_unit (void *);
1642 static void free_cached_comp_units (void *);
1644 static void age_cached_comp_units (void);
1646 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1648 static struct type
*set_die_type (struct die_info
*, struct type
*,
1649 struct dwarf2_cu
*);
1651 static void create_all_comp_units (struct objfile
*);
1653 static int create_all_type_units (struct objfile
*);
1655 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1658 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1661 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1664 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1665 struct dwarf2_per_cu_data
*);
1667 static void dwarf2_mark (struct dwarf2_cu
*);
1669 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1671 static struct type
*get_die_type_at_offset (sect_offset
,
1672 struct dwarf2_per_cu_data
*per_cu
);
1674 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1676 static void dwarf2_release_queue (void *dummy
);
1678 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1679 enum language pretend_language
);
1681 static int maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
1682 struct dwarf2_per_cu_data
*per_cu
,
1683 enum language pretend_language
);
1685 static void process_queue (void);
1687 static void find_file_and_directory (struct die_info
*die
,
1688 struct dwarf2_cu
*cu
,
1689 char **name
, char **comp_dir
);
1691 static char *file_full_name (int file
, struct line_header
*lh
,
1692 const char *comp_dir
);
1694 static gdb_byte
*read_and_check_comp_unit_head
1695 (struct comp_unit_head
*header
,
1696 struct dwarf2_section_info
*section
,
1697 struct dwarf2_section_info
*abbrev_section
, gdb_byte
*info_ptr
,
1698 int is_debug_types_section
);
1700 static void init_cutu_and_read_dies
1701 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1702 int use_existing_cu
, int keep
,
1703 die_reader_func_ftype
*die_reader_func
, void *data
);
1705 static void init_cutu_and_read_dies_simple
1706 (struct dwarf2_per_cu_data
*this_cu
,
1707 die_reader_func_ftype
*die_reader_func
, void *data
);
1709 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1711 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1713 static struct dwo_unit
*lookup_dwo_comp_unit
1714 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1716 static struct dwo_unit
*lookup_dwo_type_unit
1717 (struct signatured_type
*, const char *, const char *);
1719 static void free_dwo_file_cleanup (void *);
1721 static void process_cu_includes (void);
1723 static void check_producer (struct dwarf2_cu
*cu
);
1727 /* Convert VALUE between big- and little-endian. */
1729 byte_swap (offset_type value
)
1733 result
= (value
& 0xff) << 24;
1734 result
|= (value
& 0xff00) << 8;
1735 result
|= (value
& 0xff0000) >> 8;
1736 result
|= (value
& 0xff000000) >> 24;
1740 #define MAYBE_SWAP(V) byte_swap (V)
1743 #define MAYBE_SWAP(V) (V)
1744 #endif /* WORDS_BIGENDIAN */
1746 /* The suffix for an index file. */
1747 #define INDEX_SUFFIX ".gdb-index"
1749 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1750 struct dwarf2_cu
*cu
);
1752 /* Try to locate the sections we need for DWARF 2 debugging
1753 information and return true if we have enough to do something.
1754 NAMES points to the dwarf2 section names, or is NULL if the standard
1755 ELF names are used. */
1758 dwarf2_has_info (struct objfile
*objfile
,
1759 const struct dwarf2_debug_sections
*names
)
1761 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1762 if (!dwarf2_per_objfile
)
1764 /* Initialize per-objfile state. */
1765 struct dwarf2_per_objfile
*data
1766 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1768 memset (data
, 0, sizeof (*data
));
1769 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1770 dwarf2_per_objfile
= data
;
1772 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1774 dwarf2_per_objfile
->objfile
= objfile
;
1776 return (dwarf2_per_objfile
->info
.asection
!= NULL
1777 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1780 /* When loading sections, we look either for uncompressed section or for
1781 compressed section names. */
1784 section_is_p (const char *section_name
,
1785 const struct dwarf2_section_names
*names
)
1787 if (names
->normal
!= NULL
1788 && strcmp (section_name
, names
->normal
) == 0)
1790 if (names
->compressed
!= NULL
1791 && strcmp (section_name
, names
->compressed
) == 0)
1796 /* This function is mapped across the sections and remembers the
1797 offset and size of each of the debugging sections we are interested
1801 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1803 const struct dwarf2_debug_sections
*names
;
1804 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
1807 names
= &dwarf2_elf_names
;
1809 names
= (const struct dwarf2_debug_sections
*) vnames
;
1811 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1814 else if (section_is_p (sectp
->name
, &names
->info
))
1816 dwarf2_per_objfile
->info
.asection
= sectp
;
1817 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1819 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1821 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1822 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1824 else if (section_is_p (sectp
->name
, &names
->line
))
1826 dwarf2_per_objfile
->line
.asection
= sectp
;
1827 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1829 else if (section_is_p (sectp
->name
, &names
->loc
))
1831 dwarf2_per_objfile
->loc
.asection
= sectp
;
1832 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1834 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1836 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1837 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1839 else if (section_is_p (sectp
->name
, &names
->macro
))
1841 dwarf2_per_objfile
->macro
.asection
= sectp
;
1842 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1844 else if (section_is_p (sectp
->name
, &names
->str
))
1846 dwarf2_per_objfile
->str
.asection
= sectp
;
1847 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1849 else if (section_is_p (sectp
->name
, &names
->addr
))
1851 dwarf2_per_objfile
->addr
.asection
= sectp
;
1852 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
1854 else if (section_is_p (sectp
->name
, &names
->frame
))
1856 dwarf2_per_objfile
->frame
.asection
= sectp
;
1857 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1859 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1861 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1862 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1864 else if (section_is_p (sectp
->name
, &names
->ranges
))
1866 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1867 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1869 else if (section_is_p (sectp
->name
, &names
->types
))
1871 struct dwarf2_section_info type_section
;
1873 memset (&type_section
, 0, sizeof (type_section
));
1874 type_section
.asection
= sectp
;
1875 type_section
.size
= bfd_get_section_size (sectp
);
1877 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1880 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1882 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1883 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1886 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1887 && bfd_section_vma (abfd
, sectp
) == 0)
1888 dwarf2_per_objfile
->has_section_at_zero
= 1;
1891 /* A helper function that decides whether a section is empty,
1895 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1897 return info
->asection
== NULL
|| info
->size
== 0;
1900 /* Read the contents of the section INFO.
1901 OBJFILE is the main object file, but not necessarily the file where
1902 the section comes from. E.g., for DWO files INFO->asection->owner
1903 is the bfd of the DWO file.
1904 If the section is compressed, uncompress it before returning. */
1907 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1909 asection
*sectp
= info
->asection
;
1911 gdb_byte
*buf
, *retbuf
;
1912 unsigned char header
[4];
1916 info
->buffer
= NULL
;
1919 if (dwarf2_section_empty_p (info
))
1922 abfd
= sectp
->owner
;
1924 /* If the section has relocations, we must read it ourselves.
1925 Otherwise we attach it to the BFD. */
1926 if ((sectp
->flags
& SEC_RELOC
) == 0)
1928 const gdb_byte
*bytes
= gdb_bfd_map_section (sectp
, &info
->size
);
1930 /* We have to cast away const here for historical reasons.
1931 Fixing dwarf2read to be const-correct would be quite nice. */
1932 info
->buffer
= (gdb_byte
*) bytes
;
1936 buf
= obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1939 /* When debugging .o files, we may need to apply relocations; see
1940 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1941 We never compress sections in .o files, so we only need to
1942 try this when the section is not compressed. */
1943 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1946 info
->buffer
= retbuf
;
1950 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1951 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1952 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1953 bfd_get_filename (abfd
));
1956 /* A helper function that returns the size of a section in a safe way.
1957 If you are positive that the section has been read before using the
1958 size, then it is safe to refer to the dwarf2_section_info object's
1959 "size" field directly. In other cases, you must call this
1960 function, because for compressed sections the size field is not set
1961 correctly until the section has been read. */
1963 static bfd_size_type
1964 dwarf2_section_size (struct objfile
*objfile
,
1965 struct dwarf2_section_info
*info
)
1968 dwarf2_read_section (objfile
, info
);
1972 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1976 dwarf2_get_section_info (struct objfile
*objfile
,
1977 enum dwarf2_section_enum sect
,
1978 asection
**sectp
, gdb_byte
**bufp
,
1979 bfd_size_type
*sizep
)
1981 struct dwarf2_per_objfile
*data
1982 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1983 struct dwarf2_section_info
*info
;
1985 /* We may see an objfile without any DWARF, in which case we just
1996 case DWARF2_DEBUG_FRAME
:
1997 info
= &data
->frame
;
1999 case DWARF2_EH_FRAME
:
2000 info
= &data
->eh_frame
;
2003 gdb_assert_not_reached ("unexpected section");
2006 dwarf2_read_section (objfile
, info
);
2008 *sectp
= info
->asection
;
2009 *bufp
= info
->buffer
;
2010 *sizep
= info
->size
;
2013 /* A helper function to find the sections for a .dwz file. */
2016 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2018 struct dwz_file
*dwz_file
= arg
;
2020 /* Note that we only support the standard ELF names, because .dwz
2021 is ELF-only (at the time of writing). */
2022 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2024 dwz_file
->abbrev
.asection
= sectp
;
2025 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2027 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2029 dwz_file
->info
.asection
= sectp
;
2030 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2032 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2034 dwz_file
->str
.asection
= sectp
;
2035 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2037 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2039 dwz_file
->line
.asection
= sectp
;
2040 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2042 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2044 dwz_file
->macro
.asection
= sectp
;
2045 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2047 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2049 dwz_file
->gdb_index
.asection
= sectp
;
2050 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2054 /* Open the separate '.dwz' debug file, if needed. Error if the file
2057 static struct dwz_file
*
2058 dwarf2_get_dwz_file (void)
2060 bfd
*abfd
, *dwz_bfd
;
2063 struct cleanup
*cleanup
;
2064 const char *filename
;
2065 struct dwz_file
*result
;
2067 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2068 return dwarf2_per_objfile
->dwz_file
;
2070 abfd
= dwarf2_per_objfile
->objfile
->obfd
;
2071 section
= bfd_get_section_by_name (abfd
, ".gnu_debugaltlink");
2072 if (section
== NULL
)
2073 error (_("could not find '.gnu_debugaltlink' section"));
2074 if (!bfd_malloc_and_get_section (abfd
, section
, &data
))
2075 error (_("could not read '.gnu_debugaltlink' section: %s"),
2076 bfd_errmsg (bfd_get_error ()));
2077 cleanup
= make_cleanup (xfree
, data
);
2080 if (!IS_ABSOLUTE_PATH (filename
))
2082 char *abs
= gdb_realpath (dwarf2_per_objfile
->objfile
->name
);
2085 make_cleanup (xfree
, abs
);
2086 abs
= ldirname (abs
);
2087 make_cleanup (xfree
, abs
);
2089 rel
= concat (abs
, SLASH_STRING
, filename
, (char *) NULL
);
2090 make_cleanup (xfree
, rel
);
2094 /* The format is just a NUL-terminated file name, followed by the
2095 build-id. For now, though, we ignore the build-id. */
2096 dwz_bfd
= gdb_bfd_open (filename
, gnutarget
, -1);
2097 if (dwz_bfd
== NULL
)
2098 error (_("could not read '%s': %s"), filename
,
2099 bfd_errmsg (bfd_get_error ()));
2101 if (!bfd_check_format (dwz_bfd
, bfd_object
))
2103 gdb_bfd_unref (dwz_bfd
);
2104 error (_("file '%s' was not usable: %s"), filename
,
2105 bfd_errmsg (bfd_get_error ()));
2108 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2110 result
->dwz_bfd
= dwz_bfd
;
2112 bfd_map_over_sections (dwz_bfd
, locate_dwz_sections
, result
);
2114 do_cleanups (cleanup
);
2116 dwarf2_per_objfile
->dwz_file
= result
;
2120 /* DWARF quick_symbols_functions support. */
2122 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2123 unique line tables, so we maintain a separate table of all .debug_line
2124 derived entries to support the sharing.
2125 All the quick functions need is the list of file names. We discard the
2126 line_header when we're done and don't need to record it here. */
2127 struct quick_file_names
2129 /* The data used to construct the hash key. */
2130 struct stmt_list_hash hash
;
2132 /* The number of entries in file_names, real_names. */
2133 unsigned int num_file_names
;
2135 /* The file names from the line table, after being run through
2137 const char **file_names
;
2139 /* The file names from the line table after being run through
2140 gdb_realpath. These are computed lazily. */
2141 const char **real_names
;
2144 /* When using the index (and thus not using psymtabs), each CU has an
2145 object of this type. This is used to hold information needed by
2146 the various "quick" methods. */
2147 struct dwarf2_per_cu_quick_data
2149 /* The file table. This can be NULL if there was no file table
2150 or it's currently not read in.
2151 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2152 struct quick_file_names
*file_names
;
2154 /* The corresponding symbol table. This is NULL if symbols for this
2155 CU have not yet been read. */
2156 struct symtab
*symtab
;
2158 /* A temporary mark bit used when iterating over all CUs in
2159 expand_symtabs_matching. */
2160 unsigned int mark
: 1;
2162 /* True if we've tried to read the file table and found there isn't one.
2163 There will be no point in trying to read it again next time. */
2164 unsigned int no_file_data
: 1;
2167 /* Utility hash function for a stmt_list_hash. */
2170 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2174 if (stmt_list_hash
->dwo_unit
!= NULL
)
2175 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2176 v
+= stmt_list_hash
->line_offset
.sect_off
;
2180 /* Utility equality function for a stmt_list_hash. */
2183 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2184 const struct stmt_list_hash
*rhs
)
2186 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2188 if (lhs
->dwo_unit
!= NULL
2189 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2192 return lhs
->line_offset
.sect_off
== rhs
->line_offset
.sect_off
;
2195 /* Hash function for a quick_file_names. */
2198 hash_file_name_entry (const void *e
)
2200 const struct quick_file_names
*file_data
= e
;
2202 return hash_stmt_list_entry (&file_data
->hash
);
2205 /* Equality function for a quick_file_names. */
2208 eq_file_name_entry (const void *a
, const void *b
)
2210 const struct quick_file_names
*ea
= a
;
2211 const struct quick_file_names
*eb
= b
;
2213 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2216 /* Delete function for a quick_file_names. */
2219 delete_file_name_entry (void *e
)
2221 struct quick_file_names
*file_data
= e
;
2224 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2226 xfree ((void*) file_data
->file_names
[i
]);
2227 if (file_data
->real_names
)
2228 xfree ((void*) file_data
->real_names
[i
]);
2231 /* The space for the struct itself lives on objfile_obstack,
2232 so we don't free it here. */
2235 /* Create a quick_file_names hash table. */
2238 create_quick_file_names_table (unsigned int nr_initial_entries
)
2240 return htab_create_alloc (nr_initial_entries
,
2241 hash_file_name_entry
, eq_file_name_entry
,
2242 delete_file_name_entry
, xcalloc
, xfree
);
2245 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2246 have to be created afterwards. You should call age_cached_comp_units after
2247 processing PER_CU->CU. dw2_setup must have been already called. */
2250 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2252 if (per_cu
->is_debug_types
)
2253 load_full_type_unit (per_cu
);
2255 load_full_comp_unit (per_cu
, language_minimal
);
2257 gdb_assert (per_cu
->cu
!= NULL
);
2259 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2262 /* Read in the symbols for PER_CU. */
2265 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2267 struct cleanup
*back_to
;
2269 /* Skip type_unit_groups, reading the type units they contain
2270 is handled elsewhere. */
2271 if (IS_TYPE_UNIT_GROUP (per_cu
))
2274 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2276 if (dwarf2_per_objfile
->using_index
2277 ? per_cu
->v
.quick
->symtab
== NULL
2278 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2280 queue_comp_unit (per_cu
, language_minimal
);
2286 /* Age the cache, releasing compilation units that have not
2287 been used recently. */
2288 age_cached_comp_units ();
2290 do_cleanups (back_to
);
2293 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2294 the objfile from which this CU came. Returns the resulting symbol
2297 static struct symtab
*
2298 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2300 gdb_assert (dwarf2_per_objfile
->using_index
);
2301 if (!per_cu
->v
.quick
->symtab
)
2303 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2304 increment_reading_symtab ();
2305 dw2_do_instantiate_symtab (per_cu
);
2306 process_cu_includes ();
2307 do_cleanups (back_to
);
2309 return per_cu
->v
.quick
->symtab
;
2312 /* Return the CU given its index.
2314 This is intended for loops like:
2316 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2317 + dwarf2_per_objfile->n_type_units); ++i)
2319 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2325 static struct dwarf2_per_cu_data
*
2326 dw2_get_cu (int index
)
2328 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2330 index
-= dwarf2_per_objfile
->n_comp_units
;
2331 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
2332 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
2335 return dwarf2_per_objfile
->all_comp_units
[index
];
2338 /* Return the primary CU given its index.
2339 The difference between this function and dw2_get_cu is in the handling
2340 of type units (TUs). Here we return the type_unit_group object.
2342 This is intended for loops like:
2344 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2345 + dwarf2_per_objfile->n_type_unit_groups); ++i)
2347 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
2353 static struct dwarf2_per_cu_data
*
2354 dw2_get_primary_cu (int index
)
2356 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2358 index
-= dwarf2_per_objfile
->n_comp_units
;
2359 gdb_assert (index
< dwarf2_per_objfile
->n_type_unit_groups
);
2360 return &dwarf2_per_objfile
->all_type_unit_groups
[index
]->per_cu
;
2363 return dwarf2_per_objfile
->all_comp_units
[index
];
2366 /* A helper for create_cus_from_index that handles a given list of
2370 create_cus_from_index_list (struct objfile
*objfile
,
2371 const gdb_byte
*cu_list
, offset_type n_elements
,
2372 struct dwarf2_section_info
*section
,
2378 for (i
= 0; i
< n_elements
; i
+= 2)
2380 struct dwarf2_per_cu_data
*the_cu
;
2381 ULONGEST offset
, length
;
2383 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2384 offset
= extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2385 length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2388 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2389 struct dwarf2_per_cu_data
);
2390 the_cu
->offset
.sect_off
= offset
;
2391 the_cu
->length
= length
;
2392 the_cu
->objfile
= objfile
;
2393 the_cu
->info_or_types_section
= section
;
2394 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2395 struct dwarf2_per_cu_quick_data
);
2396 the_cu
->is_dwz
= is_dwz
;
2397 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2] = the_cu
;
2401 /* Read the CU list from the mapped index, and use it to create all
2402 the CU objects for this objfile. */
2405 create_cus_from_index (struct objfile
*objfile
,
2406 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2407 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2409 struct dwz_file
*dwz
;
2411 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
2412 dwarf2_per_objfile
->all_comp_units
2413 = obstack_alloc (&objfile
->objfile_obstack
,
2414 dwarf2_per_objfile
->n_comp_units
2415 * sizeof (struct dwarf2_per_cu_data
*));
2417 create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
2418 &dwarf2_per_objfile
->info
, 0, 0);
2420 if (dwz_elements
== 0)
2423 dwz
= dwarf2_get_dwz_file ();
2424 create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
, &dwz
->info
, 1,
2425 cu_list_elements
/ 2);
2428 /* Create the signatured type hash table from the index. */
2431 create_signatured_type_table_from_index (struct objfile
*objfile
,
2432 struct dwarf2_section_info
*section
,
2433 const gdb_byte
*bytes
,
2434 offset_type elements
)
2437 htab_t sig_types_hash
;
2439 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2440 dwarf2_per_objfile
->all_type_units
2441 = obstack_alloc (&objfile
->objfile_obstack
,
2442 dwarf2_per_objfile
->n_type_units
2443 * sizeof (struct signatured_type
*));
2445 sig_types_hash
= allocate_signatured_type_table (objfile
);
2447 for (i
= 0; i
< elements
; i
+= 3)
2449 struct signatured_type
*sig_type
;
2450 ULONGEST offset
, type_offset_in_tu
, signature
;
2453 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2454 offset
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2455 type_offset_in_tu
= extract_unsigned_integer (bytes
+ 8, 8,
2457 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2460 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2461 struct signatured_type
);
2462 sig_type
->signature
= signature
;
2463 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2464 sig_type
->per_cu
.is_debug_types
= 1;
2465 sig_type
->per_cu
.info_or_types_section
= section
;
2466 sig_type
->per_cu
.offset
.sect_off
= offset
;
2467 sig_type
->per_cu
.objfile
= objfile
;
2468 sig_type
->per_cu
.v
.quick
2469 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2470 struct dwarf2_per_cu_quick_data
);
2472 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2475 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
2478 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2481 /* Read the address map data from the mapped index, and use it to
2482 populate the objfile's psymtabs_addrmap. */
2485 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2487 const gdb_byte
*iter
, *end
;
2488 struct obstack temp_obstack
;
2489 struct addrmap
*mutable_map
;
2490 struct cleanup
*cleanup
;
2493 obstack_init (&temp_obstack
);
2494 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2495 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2497 iter
= index
->address_table
;
2498 end
= iter
+ index
->address_table_size
;
2500 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2504 ULONGEST hi
, lo
, cu_index
;
2505 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2507 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2509 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2512 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2513 dw2_get_cu (cu_index
));
2516 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2517 &objfile
->objfile_obstack
);
2518 do_cleanups (cleanup
);
2521 /* The hash function for strings in the mapped index. This is the same as
2522 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2523 implementation. This is necessary because the hash function is tied to the
2524 format of the mapped index file. The hash values do not have to match with
2527 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2530 mapped_index_string_hash (int index_version
, const void *p
)
2532 const unsigned char *str
= (const unsigned char *) p
;
2536 while ((c
= *str
++) != 0)
2538 if (index_version
>= 5)
2540 r
= r
* 67 + c
- 113;
2546 /* Find a slot in the mapped index INDEX for the object named NAME.
2547 If NAME is found, set *VEC_OUT to point to the CU vector in the
2548 constant pool and return 1. If NAME cannot be found, return 0. */
2551 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2552 offset_type
**vec_out
)
2554 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2556 offset_type slot
, step
;
2557 int (*cmp
) (const char *, const char *);
2559 if (current_language
->la_language
== language_cplus
2560 || current_language
->la_language
== language_java
2561 || current_language
->la_language
== language_fortran
)
2563 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2565 const char *paren
= strchr (name
, '(');
2571 dup
= xmalloc (paren
- name
+ 1);
2572 memcpy (dup
, name
, paren
- name
);
2573 dup
[paren
- name
] = 0;
2575 make_cleanup (xfree
, dup
);
2580 /* Index version 4 did not support case insensitive searches. But the
2581 indices for case insensitive languages are built in lowercase, therefore
2582 simulate our NAME being searched is also lowercased. */
2583 hash
= mapped_index_string_hash ((index
->version
== 4
2584 && case_sensitivity
== case_sensitive_off
2585 ? 5 : index
->version
),
2588 slot
= hash
& (index
->symbol_table_slots
- 1);
2589 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2590 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2594 /* Convert a slot number to an offset into the table. */
2595 offset_type i
= 2 * slot
;
2597 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2599 do_cleanups (back_to
);
2603 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2604 if (!cmp (name
, str
))
2606 *vec_out
= (offset_type
*) (index
->constant_pool
2607 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2608 do_cleanups (back_to
);
2612 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2616 /* A helper function that reads the .gdb_index from SECTION and fills
2617 in MAP. FILENAME is the name of the file containing the section;
2618 it is used for error reporting. DEPRECATED_OK is nonzero if it is
2619 ok to use deprecated sections.
2621 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2622 out parameters that are filled in with information about the CU and
2623 TU lists in the section.
2625 Returns 1 if all went well, 0 otherwise. */
2628 read_index_from_section (struct objfile
*objfile
,
2629 const char *filename
,
2631 struct dwarf2_section_info
*section
,
2632 struct mapped_index
*map
,
2633 const gdb_byte
**cu_list
,
2634 offset_type
*cu_list_elements
,
2635 const gdb_byte
**types_list
,
2636 offset_type
*types_list_elements
)
2639 offset_type version
;
2640 offset_type
*metadata
;
2643 if (dwarf2_section_empty_p (section
))
2646 /* Older elfutils strip versions could keep the section in the main
2647 executable while splitting it for the separate debug info file. */
2648 if ((bfd_get_file_flags (section
->asection
) & SEC_HAS_CONTENTS
) == 0)
2651 dwarf2_read_section (objfile
, section
);
2653 addr
= section
->buffer
;
2654 /* Version check. */
2655 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2656 /* Versions earlier than 3 emitted every copy of a psymbol. This
2657 causes the index to behave very poorly for certain requests. Version 3
2658 contained incomplete addrmap. So, it seems better to just ignore such
2662 static int warning_printed
= 0;
2663 if (!warning_printed
)
2665 warning (_("Skipping obsolete .gdb_index section in %s."),
2667 warning_printed
= 1;
2671 /* Index version 4 uses a different hash function than index version
2674 Versions earlier than 6 did not emit psymbols for inlined
2675 functions. Using these files will cause GDB not to be able to
2676 set breakpoints on inlined functions by name, so we ignore these
2677 indices unless the user has done
2678 "set use-deprecated-index-sections on". */
2679 if (version
< 6 && !deprecated_ok
)
2681 static int warning_printed
= 0;
2682 if (!warning_printed
)
2685 Skipping deprecated .gdb_index section in %s.\n\
2686 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2687 to use the section anyway."),
2689 warning_printed
= 1;
2693 /* Indexes with higher version than the one supported by GDB may be no
2694 longer backward compatible. */
2698 map
->version
= version
;
2699 map
->total_size
= section
->size
;
2701 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2704 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2705 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2709 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2710 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2711 - MAYBE_SWAP (metadata
[i
]))
2715 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2716 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2717 - MAYBE_SWAP (metadata
[i
]));
2720 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2721 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2722 - MAYBE_SWAP (metadata
[i
]))
2723 / (2 * sizeof (offset_type
)));
2726 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2732 /* Read the index file. If everything went ok, initialize the "quick"
2733 elements of all the CUs and return 1. Otherwise, return 0. */
2736 dwarf2_read_index (struct objfile
*objfile
)
2738 struct mapped_index local_map
, *map
;
2739 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2740 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2742 if (!read_index_from_section (objfile
, objfile
->name
,
2743 use_deprecated_index_sections
,
2744 &dwarf2_per_objfile
->gdb_index
, &local_map
,
2745 &cu_list
, &cu_list_elements
,
2746 &types_list
, &types_list_elements
))
2749 /* Don't use the index if it's empty. */
2750 if (local_map
.symbol_table_slots
== 0)
2753 /* If there is a .dwz file, read it so we can get its CU list as
2755 if (bfd_get_section_by_name (objfile
->obfd
, ".gnu_debugaltlink") != NULL
)
2757 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
2758 struct mapped_index dwz_map
;
2759 const gdb_byte
*dwz_types_ignore
;
2760 offset_type dwz_types_elements_ignore
;
2762 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
2764 &dwz
->gdb_index
, &dwz_map
,
2765 &dwz_list
, &dwz_list_elements
,
2767 &dwz_types_elements_ignore
))
2769 warning (_("could not read '.gdb_index' section from %s; skipping"),
2770 bfd_get_filename (dwz
->dwz_bfd
));
2775 create_cus_from_index (objfile
, cu_list
, cu_list_elements
, dwz_list
,
2778 if (types_list_elements
)
2780 struct dwarf2_section_info
*section
;
2782 /* We can only handle a single .debug_types when we have an
2784 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2787 section
= VEC_index (dwarf2_section_info_def
,
2788 dwarf2_per_objfile
->types
, 0);
2790 create_signatured_type_table_from_index (objfile
, section
, types_list
,
2791 types_list_elements
);
2794 create_addrmap_from_index (objfile
, &local_map
);
2796 map
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct mapped_index
));
2799 dwarf2_per_objfile
->index_table
= map
;
2800 dwarf2_per_objfile
->using_index
= 1;
2801 dwarf2_per_objfile
->quick_file_names_table
=
2802 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2807 /* A helper for the "quick" functions which sets the global
2808 dwarf2_per_objfile according to OBJFILE. */
2811 dw2_setup (struct objfile
*objfile
)
2813 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2814 gdb_assert (dwarf2_per_objfile
);
2817 /* Reader function for dw2_build_type_unit_groups. */
2820 dw2_build_type_unit_groups_reader (const struct die_reader_specs
*reader
,
2822 struct die_info
*type_unit_die
,
2826 struct dwarf2_cu
*cu
= reader
->cu
;
2827 struct attribute
*attr
;
2828 struct type_unit_group
*tu_group
;
2830 gdb_assert (data
== NULL
);
2835 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
2836 /* Call this for its side-effect of creating the associated
2837 struct type_unit_group if it doesn't already exist. */
2838 tu_group
= get_type_unit_group (cu
, attr
);
2841 /* Build dwarf2_per_objfile->type_unit_groups.
2842 This function may be called multiple times. */
2845 dw2_build_type_unit_groups (void)
2847 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
2848 build_type_unit_groups (dw2_build_type_unit_groups_reader
, NULL
);
2851 /* die_reader_func for dw2_get_file_names. */
2854 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2856 struct die_info
*comp_unit_die
,
2860 struct dwarf2_cu
*cu
= reader
->cu
;
2861 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2862 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2863 struct dwarf2_per_cu_data
*lh_cu
;
2864 struct line_header
*lh
;
2865 struct attribute
*attr
;
2867 char *name
, *comp_dir
;
2869 struct quick_file_names
*qfn
;
2870 unsigned int line_offset
;
2872 /* Our callers never want to match partial units -- instead they
2873 will match the enclosing full CU. */
2874 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2876 this_cu
->v
.quick
->no_file_data
= 1;
2880 /* If we're reading the line header for TUs, store it in the "per_cu"
2882 if (this_cu
->is_debug_types
)
2884 struct type_unit_group
*tu_group
= data
;
2886 gdb_assert (tu_group
!= NULL
);
2887 lh_cu
= &tu_group
->per_cu
;
2896 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2899 struct quick_file_names find_entry
;
2901 line_offset
= DW_UNSND (attr
);
2903 /* We may have already read in this line header (TU line header sharing).
2904 If we have we're done. */
2905 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
2906 find_entry
.hash
.line_offset
.sect_off
= line_offset
;
2907 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2908 &find_entry
, INSERT
);
2911 lh_cu
->v
.quick
->file_names
= *slot
;
2915 lh
= dwarf_decode_line_header (line_offset
, cu
);
2919 lh_cu
->v
.quick
->no_file_data
= 1;
2923 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2924 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
2925 qfn
->hash
.line_offset
.sect_off
= line_offset
;
2926 gdb_assert (slot
!= NULL
);
2929 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2931 qfn
->num_file_names
= lh
->num_file_names
;
2932 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2933 lh
->num_file_names
* sizeof (char *));
2934 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2935 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2936 qfn
->real_names
= NULL
;
2938 free_line_header (lh
);
2940 lh_cu
->v
.quick
->file_names
= qfn
;
2943 /* A helper for the "quick" functions which attempts to read the line
2944 table for THIS_CU. */
2946 static struct quick_file_names
*
2947 dw2_get_file_names (struct objfile
*objfile
,
2948 struct dwarf2_per_cu_data
*this_cu
)
2950 /* For TUs this should only be called on the parent group. */
2951 if (this_cu
->is_debug_types
)
2952 gdb_assert (IS_TYPE_UNIT_GROUP (this_cu
));
2954 if (this_cu
->v
.quick
->file_names
!= NULL
)
2955 return this_cu
->v
.quick
->file_names
;
2956 /* If we know there is no line data, no point in looking again. */
2957 if (this_cu
->v
.quick
->no_file_data
)
2960 /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute
2961 in the stub for CUs, there's is no need to lookup the DWO file.
2962 However, that's not the case for TUs where DW_AT_stmt_list lives in the
2964 if (this_cu
->is_debug_types
)
2966 struct type_unit_group
*tu_group
= this_cu
->s
.type_unit_group
;
2968 init_cutu_and_read_dies (tu_group
->t
.first_tu
, NULL
, 0, 0,
2969 dw2_get_file_names_reader
, tu_group
);
2972 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2974 if (this_cu
->v
.quick
->no_file_data
)
2976 return this_cu
->v
.quick
->file_names
;
2979 /* A helper for the "quick" functions which computes and caches the
2980 real path for a given file name from the line table. */
2983 dw2_get_real_path (struct objfile
*objfile
,
2984 struct quick_file_names
*qfn
, int index
)
2986 if (qfn
->real_names
== NULL
)
2987 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2988 qfn
->num_file_names
, sizeof (char *));
2990 if (qfn
->real_names
[index
] == NULL
)
2991 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2993 return qfn
->real_names
[index
];
2996 static struct symtab
*
2997 dw2_find_last_source_symtab (struct objfile
*objfile
)
3001 dw2_setup (objfile
);
3002 index
= dwarf2_per_objfile
->n_comp_units
- 1;
3003 return dw2_instantiate_symtab (dw2_get_cu (index
));
3006 /* Traversal function for dw2_forget_cached_source_info. */
3009 dw2_free_cached_file_names (void **slot
, void *info
)
3011 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3013 if (file_data
->real_names
)
3017 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3019 xfree ((void*) file_data
->real_names
[i
]);
3020 file_data
->real_names
[i
] = NULL
;
3028 dw2_forget_cached_source_info (struct objfile
*objfile
)
3030 dw2_setup (objfile
);
3032 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3033 dw2_free_cached_file_names
, NULL
);
3036 /* Helper function for dw2_map_symtabs_matching_filename that expands
3037 the symtabs and calls the iterator. */
3040 dw2_map_expand_apply (struct objfile
*objfile
,
3041 struct dwarf2_per_cu_data
*per_cu
,
3043 const char *full_path
, const char *real_path
,
3044 int (*callback
) (struct symtab
*, void *),
3047 struct symtab
*last_made
= objfile
->symtabs
;
3049 /* Don't visit already-expanded CUs. */
3050 if (per_cu
->v
.quick
->symtab
)
3053 /* This may expand more than one symtab, and we want to iterate over
3055 dw2_instantiate_symtab (per_cu
);
3057 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
3058 objfile
->symtabs
, last_made
);
3061 /* Implementation of the map_symtabs_matching_filename method. */
3064 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
3065 const char *full_path
, const char *real_path
,
3066 int (*callback
) (struct symtab
*, void *),
3070 const char *name_basename
= lbasename (name
);
3071 int is_abs
= IS_ABSOLUTE_PATH (name
);
3073 dw2_setup (objfile
);
3075 dw2_build_type_unit_groups ();
3077 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3078 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3081 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3082 struct quick_file_names
*file_data
;
3084 /* We only need to look at symtabs not already expanded. */
3085 if (per_cu
->v
.quick
->symtab
)
3088 file_data
= dw2_get_file_names (objfile
, per_cu
);
3089 if (file_data
== NULL
)
3092 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3094 const char *this_name
= file_data
->file_names
[j
];
3096 if (FILENAME_CMP (name
, this_name
) == 0
3097 || (!is_abs
&& compare_filenames_for_search (this_name
, name
)))
3099 if (dw2_map_expand_apply (objfile
, per_cu
,
3100 name
, full_path
, real_path
,
3105 /* Before we invoke realpath, which can get expensive when many
3106 files are involved, do a quick comparison of the basenames. */
3107 if (! basenames_may_differ
3108 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3111 if (full_path
!= NULL
)
3113 const char *this_real_name
= dw2_get_real_path (objfile
,
3116 if (this_real_name
!= NULL
3117 && (FILENAME_CMP (full_path
, this_real_name
) == 0
3119 && compare_filenames_for_search (this_real_name
,
3122 if (dw2_map_expand_apply (objfile
, per_cu
,
3123 name
, full_path
, real_path
,
3129 if (real_path
!= NULL
)
3131 const char *this_real_name
= dw2_get_real_path (objfile
,
3134 if (this_real_name
!= NULL
3135 && (FILENAME_CMP (real_path
, this_real_name
) == 0
3137 && compare_filenames_for_search (this_real_name
,
3140 if (dw2_map_expand_apply (objfile
, per_cu
,
3141 name
, full_path
, real_path
,
3152 /* Struct used to manage iterating over all CUs looking for a symbol. */
3154 struct dw2_symtab_iterator
3156 /* The internalized form of .gdb_index. */
3157 struct mapped_index
*index
;
3158 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
3159 int want_specific_block
;
3160 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
3161 Unused if !WANT_SPECIFIC_BLOCK. */
3163 /* The kind of symbol we're looking for. */
3165 /* The list of CUs from the index entry of the symbol,
3166 or NULL if not found. */
3168 /* The next element in VEC to look at. */
3170 /* The number of elements in VEC, or zero if there is no match. */
3174 /* Initialize the index symtab iterator ITER.
3175 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
3176 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
3179 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3180 struct mapped_index
*index
,
3181 int want_specific_block
,
3186 iter
->index
= index
;
3187 iter
->want_specific_block
= want_specific_block
;
3188 iter
->block_index
= block_index
;
3189 iter
->domain
= domain
;
3192 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3193 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3201 /* Return the next matching CU or NULL if there are no more. */
3203 static struct dwarf2_per_cu_data
*
3204 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3206 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3208 offset_type cu_index_and_attrs
=
3209 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3210 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3211 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
3212 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
3213 /* This value is only valid for index versions >= 7. */
3214 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3215 gdb_index_symbol_kind symbol_kind
=
3216 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3217 /* Only check the symbol attributes if they're present.
3218 Indices prior to version 7 don't record them,
3219 and indices >= 7 may elide them for certain symbols
3220 (gold does this). */
3222 (iter
->index
->version
>= 7
3223 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3225 /* Skip if already read in. */
3226 if (per_cu
->v
.quick
->symtab
)
3230 && iter
->want_specific_block
3231 && want_static
!= is_static
)
3234 /* Only check the symbol's kind if it has one. */
3237 switch (iter
->domain
)
3240 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3241 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3242 /* Some types are also in VAR_DOMAIN. */
3243 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3247 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3251 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3266 static struct symtab
*
3267 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
3268 const char *name
, domain_enum domain
)
3270 struct symtab
*stab_best
= NULL
;
3271 struct mapped_index
*index
;
3273 dw2_setup (objfile
);
3275 index
= dwarf2_per_objfile
->index_table
;
3277 /* index is NULL if OBJF_READNOW. */
3280 struct dw2_symtab_iterator iter
;
3281 struct dwarf2_per_cu_data
*per_cu
;
3283 dw2_symtab_iter_init (&iter
, index
, 1, block_index
, domain
, name
);
3285 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3287 struct symbol
*sym
= NULL
;
3288 struct symtab
*stab
= dw2_instantiate_symtab (per_cu
);
3290 /* Some caution must be observed with overloaded functions
3291 and methods, since the index will not contain any overload
3292 information (but NAME might contain it). */
3295 struct blockvector
*bv
= BLOCKVECTOR (stab
);
3296 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3298 sym
= lookup_block_symbol (block
, name
, domain
);
3301 if (sym
&& strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
3303 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
3309 /* Keep looking through other CUs. */
3317 dw2_print_stats (struct objfile
*objfile
)
3321 dw2_setup (objfile
);
3323 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3324 + dwarf2_per_objfile
->n_type_units
); ++i
)
3326 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3328 if (!per_cu
->v
.quick
->symtab
)
3331 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3335 dw2_dump (struct objfile
*objfile
)
3337 /* Nothing worth printing. */
3341 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
3342 struct section_offsets
*delta
)
3344 /* There's nothing to relocate here. */
3348 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3349 const char *func_name
)
3351 struct mapped_index
*index
;
3353 dw2_setup (objfile
);
3355 index
= dwarf2_per_objfile
->index_table
;
3357 /* index is NULL if OBJF_READNOW. */
3360 struct dw2_symtab_iterator iter
;
3361 struct dwarf2_per_cu_data
*per_cu
;
3363 /* Note: It doesn't matter what we pass for block_index here. */
3364 dw2_symtab_iter_init (&iter
, index
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
3367 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3368 dw2_instantiate_symtab (per_cu
);
3373 dw2_expand_all_symtabs (struct objfile
*objfile
)
3377 dw2_setup (objfile
);
3379 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3380 + dwarf2_per_objfile
->n_type_units
); ++i
)
3382 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3384 dw2_instantiate_symtab (per_cu
);
3389 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
3390 const char *filename
)
3394 dw2_setup (objfile
);
3396 /* We don't need to consider type units here.
3397 This is only called for examining code, e.g. expand_line_sal.
3398 There can be an order of magnitude (or more) more type units
3399 than comp units, and we avoid them if we can. */
3401 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3404 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3405 struct quick_file_names
*file_data
;
3407 /* We only need to look at symtabs not already expanded. */
3408 if (per_cu
->v
.quick
->symtab
)
3411 file_data
= dw2_get_file_names (objfile
, per_cu
);
3412 if (file_data
== NULL
)
3415 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3417 const char *this_name
= file_data
->file_names
[j
];
3418 if (FILENAME_CMP (this_name
, filename
) == 0)
3420 dw2_instantiate_symtab (per_cu
);
3427 /* A helper function for dw2_find_symbol_file that finds the primary
3428 file name for a given CU. This is a die_reader_func. */
3431 dw2_get_primary_filename_reader (const struct die_reader_specs
*reader
,
3433 struct die_info
*comp_unit_die
,
3437 const char **result_ptr
= data
;
3438 struct dwarf2_cu
*cu
= reader
->cu
;
3439 struct attribute
*attr
;
3441 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
3445 *result_ptr
= DW_STRING (attr
);
3449 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
3451 struct dwarf2_per_cu_data
*per_cu
;
3453 const char *filename
;
3455 dw2_setup (objfile
);
3457 /* index_table is NULL if OBJF_READNOW. */
3458 if (!dwarf2_per_objfile
->index_table
)
3462 ALL_OBJFILE_PRIMARY_SYMTABS (objfile
, s
)
3464 struct blockvector
*bv
= BLOCKVECTOR (s
);
3465 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
3466 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
3469 return SYMBOL_SYMTAB (sym
)->filename
;
3474 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
3478 /* Note that this just looks at the very first one named NAME -- but
3479 actually we are looking for a function. find_main_filename
3480 should be rewritten so that it doesn't require a custom hook. It
3481 could just use the ordinary symbol tables. */
3482 /* vec[0] is the length, which must always be >0. */
3483 per_cu
= dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec
[1])));
3485 if (per_cu
->v
.quick
->symtab
!= NULL
)
3486 return per_cu
->v
.quick
->symtab
->filename
;
3488 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
3489 dw2_get_primary_filename_reader
, &filename
);
3495 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
3496 struct objfile
*objfile
, int global
,
3497 int (*callback
) (struct block
*,
3498 struct symbol
*, void *),
3499 void *data
, symbol_compare_ftype
*match
,
3500 symbol_compare_ftype
*ordered_compare
)
3502 /* Currently unimplemented; used for Ada. The function can be called if the
3503 current language is Ada for a non-Ada objfile using GNU index. As Ada
3504 does not look for non-Ada symbols this function should just return. */
3508 dw2_expand_symtabs_matching
3509 (struct objfile
*objfile
,
3510 int (*file_matcher
) (const char *, void *),
3511 int (*name_matcher
) (const char *, void *),
3512 enum search_domain kind
,
3517 struct mapped_index
*index
;
3519 dw2_setup (objfile
);
3521 /* index_table is NULL if OBJF_READNOW. */
3522 if (!dwarf2_per_objfile
->index_table
)
3524 index
= dwarf2_per_objfile
->index_table
;
3526 if (file_matcher
!= NULL
)
3528 struct cleanup
*cleanup
;
3529 htab_t visited_found
, visited_not_found
;
3531 dw2_build_type_unit_groups ();
3533 visited_found
= htab_create_alloc (10,
3534 htab_hash_pointer
, htab_eq_pointer
,
3535 NULL
, xcalloc
, xfree
);
3536 cleanup
= make_cleanup_htab_delete (visited_found
);
3537 visited_not_found
= htab_create_alloc (10,
3538 htab_hash_pointer
, htab_eq_pointer
,
3539 NULL
, xcalloc
, xfree
);
3540 make_cleanup_htab_delete (visited_not_found
);
3542 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3543 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3546 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3547 struct quick_file_names
*file_data
;
3550 per_cu
->v
.quick
->mark
= 0;
3552 /* We only need to look at symtabs not already expanded. */
3553 if (per_cu
->v
.quick
->symtab
)
3556 file_data
= dw2_get_file_names (objfile
, per_cu
);
3557 if (file_data
== NULL
)
3560 if (htab_find (visited_not_found
, file_data
) != NULL
)
3562 else if (htab_find (visited_found
, file_data
) != NULL
)
3564 per_cu
->v
.quick
->mark
= 1;
3568 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3570 if (file_matcher (file_data
->file_names
[j
], data
))
3572 per_cu
->v
.quick
->mark
= 1;
3577 slot
= htab_find_slot (per_cu
->v
.quick
->mark
3579 : visited_not_found
,
3584 do_cleanups (cleanup
);
3587 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
3589 offset_type idx
= 2 * iter
;
3591 offset_type
*vec
, vec_len
, vec_idx
;
3593 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
3596 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
3598 if (! (*name_matcher
) (name
, data
))
3601 /* The name was matched, now expand corresponding CUs that were
3603 vec
= (offset_type
*) (index
->constant_pool
3604 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
3605 vec_len
= MAYBE_SWAP (vec
[0]);
3606 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
3608 struct dwarf2_per_cu_data
*per_cu
;
3609 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
3610 gdb_index_symbol_kind symbol_kind
=
3611 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3612 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3614 /* Don't crash on bad data. */
3615 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3616 + dwarf2_per_objfile
->n_type_units
))
3619 /* Only check the symbol's kind if it has one.
3620 Indices prior to version 7 don't record it. */
3621 if (index
->version
>= 7)
3625 case VARIABLES_DOMAIN
:
3626 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
3629 case FUNCTIONS_DOMAIN
:
3630 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
3634 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3642 per_cu
= dw2_get_cu (cu_index
);
3643 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
3644 dw2_instantiate_symtab (per_cu
);
3649 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
3652 static struct symtab
*
3653 recursively_find_pc_sect_symtab (struct symtab
*symtab
, CORE_ADDR pc
)
3657 if (BLOCKVECTOR (symtab
) != NULL
3658 && blockvector_contains_pc (BLOCKVECTOR (symtab
), pc
))
3661 if (symtab
->includes
== NULL
)
3664 for (i
= 0; symtab
->includes
[i
]; ++i
)
3666 struct symtab
*s
= symtab
->includes
[i
];
3668 s
= recursively_find_pc_sect_symtab (s
, pc
);
3676 static struct symtab
*
3677 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
3678 struct minimal_symbol
*msymbol
,
3680 struct obj_section
*section
,
3683 struct dwarf2_per_cu_data
*data
;
3684 struct symtab
*result
;
3686 dw2_setup (objfile
);
3688 if (!objfile
->psymtabs_addrmap
)
3691 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
3695 if (warn_if_readin
&& data
->v
.quick
->symtab
)
3696 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3697 paddress (get_objfile_arch (objfile
), pc
));
3699 result
= recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data
), pc
);
3700 gdb_assert (result
!= NULL
);
3705 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
3706 void *data
, int need_fullname
)
3709 struct cleanup
*cleanup
;
3710 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
3711 NULL
, xcalloc
, xfree
);
3713 cleanup
= make_cleanup_htab_delete (visited
);
3714 dw2_setup (objfile
);
3716 dw2_build_type_unit_groups ();
3718 /* We can ignore file names coming from already-expanded CUs. */
3719 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3720 + dwarf2_per_objfile
->n_type_units
); ++i
)
3722 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3724 if (per_cu
->v
.quick
->symtab
)
3726 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3729 *slot
= per_cu
->v
.quick
->file_names
;
3733 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3734 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3737 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3738 struct quick_file_names
*file_data
;
3741 /* We only need to look at symtabs not already expanded. */
3742 if (per_cu
->v
.quick
->symtab
)
3745 file_data
= dw2_get_file_names (objfile
, per_cu
);
3746 if (file_data
== NULL
)
3749 slot
= htab_find_slot (visited
, file_data
, INSERT
);
3752 /* Already visited. */
3757 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3759 const char *this_real_name
;
3762 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3764 this_real_name
= NULL
;
3765 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
3769 do_cleanups (cleanup
);
3773 dw2_has_symbols (struct objfile
*objfile
)
3778 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
3781 dw2_find_last_source_symtab
,
3782 dw2_forget_cached_source_info
,
3783 dw2_map_symtabs_matching_filename
,
3788 dw2_expand_symtabs_for_function
,
3789 dw2_expand_all_symtabs
,
3790 dw2_expand_symtabs_with_filename
,
3791 dw2_find_symbol_file
,
3792 dw2_map_matching_symbols
,
3793 dw2_expand_symtabs_matching
,
3794 dw2_find_pc_sect_symtab
,
3795 dw2_map_symbol_filenames
3798 /* Initialize for reading DWARF for this objfile. Return 0 if this
3799 file will use psymtabs, or 1 if using the GNU index. */
3802 dwarf2_initialize_objfile (struct objfile
*objfile
)
3804 /* If we're about to read full symbols, don't bother with the
3805 indices. In this case we also don't care if some other debug
3806 format is making psymtabs, because they are all about to be
3808 if ((objfile
->flags
& OBJF_READNOW
))
3812 dwarf2_per_objfile
->using_index
= 1;
3813 create_all_comp_units (objfile
);
3814 create_all_type_units (objfile
);
3815 dwarf2_per_objfile
->quick_file_names_table
=
3816 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3818 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3819 + dwarf2_per_objfile
->n_type_units
); ++i
)
3821 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3823 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3824 struct dwarf2_per_cu_quick_data
);
3827 /* Return 1 so that gdb sees the "quick" functions. However,
3828 these functions will be no-ops because we will have expanded
3833 if (dwarf2_read_index (objfile
))
3841 /* Build a partial symbol table. */
3844 dwarf2_build_psymtabs (struct objfile
*objfile
)
3846 volatile struct gdb_exception except
;
3848 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3850 init_psymbol_list (objfile
, 1024);
3853 TRY_CATCH (except
, RETURN_MASK_ERROR
)
3855 /* This isn't really ideal: all the data we allocate on the
3856 objfile's obstack is still uselessly kept around. However,
3857 freeing it seems unsafe. */
3858 struct cleanup
*cleanups
= make_cleanup_discard_psymtabs (objfile
);
3860 dwarf2_build_psymtabs_hard (objfile
);
3861 discard_cleanups (cleanups
);
3863 if (except
.reason
< 0)
3864 exception_print (gdb_stderr
, except
);
3867 /* Return the total length of the CU described by HEADER. */
3870 get_cu_length (const struct comp_unit_head
*header
)
3872 return header
->initial_length_size
+ header
->length
;
3875 /* Return TRUE if OFFSET is within CU_HEADER. */
3878 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3880 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3881 sect_offset top
= { cu_header
->offset
.sect_off
+ get_cu_length (cu_header
) };
3883 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3886 /* Find the base address of the compilation unit for range lists and
3887 location lists. It will normally be specified by DW_AT_low_pc.
3888 In DWARF-3 draft 4, the base address could be overridden by
3889 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3890 compilation units with discontinuous ranges. */
3893 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3895 struct attribute
*attr
;
3898 cu
->base_address
= 0;
3900 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3903 cu
->base_address
= DW_ADDR (attr
);
3908 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3911 cu
->base_address
= DW_ADDR (attr
);
3917 /* Read in the comp unit header information from the debug_info at info_ptr.
3918 NOTE: This leaves members offset, first_die_offset to be filled in
3922 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3923 gdb_byte
*info_ptr
, bfd
*abfd
)
3926 unsigned int bytes_read
;
3928 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3929 cu_header
->initial_length_size
= bytes_read
;
3930 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3931 info_ptr
+= bytes_read
;
3932 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3934 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3936 info_ptr
+= bytes_read
;
3937 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3939 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3940 if (signed_addr
< 0)
3941 internal_error (__FILE__
, __LINE__
,
3942 _("read_comp_unit_head: dwarf from non elf file"));
3943 cu_header
->signed_addr_p
= signed_addr
;
3948 /* Helper function that returns the proper abbrev section for
3951 static struct dwarf2_section_info
*
3952 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
3954 struct dwarf2_section_info
*abbrev
;
3956 if (this_cu
->is_dwz
)
3957 abbrev
= &dwarf2_get_dwz_file ()->abbrev
;
3959 abbrev
= &dwarf2_per_objfile
->abbrev
;
3964 /* Subroutine of read_and_check_comp_unit_head and
3965 read_and_check_type_unit_head to simplify them.
3966 Perform various error checking on the header. */
3969 error_check_comp_unit_head (struct comp_unit_head
*header
,
3970 struct dwarf2_section_info
*section
,
3971 struct dwarf2_section_info
*abbrev_section
)
3973 bfd
*abfd
= section
->asection
->owner
;
3974 const char *filename
= bfd_get_filename (abfd
);
3976 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3977 error (_("Dwarf Error: wrong version in compilation unit header "
3978 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3981 if (header
->abbrev_offset
.sect_off
3982 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
3983 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3984 "(offset 0x%lx + 6) [in module %s]"),
3985 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3988 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3989 avoid potential 32-bit overflow. */
3990 if (((unsigned long) header
->offset
.sect_off
+ get_cu_length (header
))
3992 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3993 "(offset 0x%lx + 0) [in module %s]"),
3994 (long) header
->length
, (long) header
->offset
.sect_off
,
3998 /* Read in a CU/TU header and perform some basic error checking.
3999 The contents of the header are stored in HEADER.
4000 The result is a pointer to the start of the first DIE. */
4003 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
4004 struct dwarf2_section_info
*section
,
4005 struct dwarf2_section_info
*abbrev_section
,
4007 int is_debug_types_section
)
4009 gdb_byte
*beg_of_comp_unit
= info_ptr
;
4010 bfd
*abfd
= section
->asection
->owner
;
4012 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
4014 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
4016 /* If we're reading a type unit, skip over the signature and
4017 type_offset fields. */
4018 if (is_debug_types_section
)
4019 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
4021 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
4023 error_check_comp_unit_head (header
, section
, abbrev_section
);
4028 /* Read in the types comp unit header information from .debug_types entry at
4029 types_ptr. The result is a pointer to one past the end of the header. */
4032 read_and_check_type_unit_head (struct comp_unit_head
*header
,
4033 struct dwarf2_section_info
*section
,
4034 struct dwarf2_section_info
*abbrev_section
,
4036 ULONGEST
*signature
,
4037 cu_offset
*type_offset_in_tu
)
4039 gdb_byte
*beg_of_comp_unit
= info_ptr
;
4040 bfd
*abfd
= section
->asection
->owner
;
4042 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
4044 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
4046 /* If we're reading a type unit, skip over the signature and
4047 type_offset fields. */
4048 if (signature
!= NULL
)
4049 *signature
= read_8_bytes (abfd
, info_ptr
);
4051 if (type_offset_in_tu
!= NULL
)
4052 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
4053 header
->offset_size
);
4054 info_ptr
+= header
->offset_size
;
4056 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
4058 error_check_comp_unit_head (header
, section
, abbrev_section
);
4063 /* Fetch the abbreviation table offset from a comp or type unit header. */
4066 read_abbrev_offset (struct dwarf2_section_info
*section
,
4069 bfd
*abfd
= section
->asection
->owner
;
4071 unsigned int length
, initial_length_size
, offset_size
;
4072 sect_offset abbrev_offset
;
4074 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
4075 info_ptr
= section
->buffer
+ offset
.sect_off
;
4076 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
4077 offset_size
= initial_length_size
== 4 ? 4 : 8;
4078 info_ptr
+= initial_length_size
+ 2 /*version*/;
4079 abbrev_offset
.sect_off
= read_offset_1 (abfd
, info_ptr
, offset_size
);
4080 return abbrev_offset
;
4083 /* Allocate a new partial symtab for file named NAME and mark this new
4084 partial symtab as being an include of PST. */
4087 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
4088 struct objfile
*objfile
)
4090 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
4092 subpst
->section_offsets
= pst
->section_offsets
;
4093 subpst
->textlow
= 0;
4094 subpst
->texthigh
= 0;
4096 subpst
->dependencies
= (struct partial_symtab
**)
4097 obstack_alloc (&objfile
->objfile_obstack
,
4098 sizeof (struct partial_symtab
*));
4099 subpst
->dependencies
[0] = pst
;
4100 subpst
->number_of_dependencies
= 1;
4102 subpst
->globals_offset
= 0;
4103 subpst
->n_global_syms
= 0;
4104 subpst
->statics_offset
= 0;
4105 subpst
->n_static_syms
= 0;
4106 subpst
->symtab
= NULL
;
4107 subpst
->read_symtab
= pst
->read_symtab
;
4110 /* No private part is necessary for include psymtabs. This property
4111 can be used to differentiate between such include psymtabs and
4112 the regular ones. */
4113 subpst
->read_symtab_private
= NULL
;
4116 /* Read the Line Number Program data and extract the list of files
4117 included by the source file represented by PST. Build an include
4118 partial symtab for each of these included files. */
4121 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
4122 struct die_info
*die
,
4123 struct partial_symtab
*pst
)
4125 struct line_header
*lh
= NULL
;
4126 struct attribute
*attr
;
4128 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
4130 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
4132 return; /* No linetable, so no includes. */
4134 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
4135 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
4137 free_line_header (lh
);
4141 hash_signatured_type (const void *item
)
4143 const struct signatured_type
*sig_type
= item
;
4145 /* This drops the top 32 bits of the signature, but is ok for a hash. */
4146 return sig_type
->signature
;
4150 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
4152 const struct signatured_type
*lhs
= item_lhs
;
4153 const struct signatured_type
*rhs
= item_rhs
;
4155 return lhs
->signature
== rhs
->signature
;
4158 /* Allocate a hash table for signatured types. */
4161 allocate_signatured_type_table (struct objfile
*objfile
)
4163 return htab_create_alloc_ex (41,
4164 hash_signatured_type
,
4167 &objfile
->objfile_obstack
,
4168 hashtab_obstack_allocate
,
4169 dummy_obstack_deallocate
);
4172 /* A helper function to add a signatured type CU to a table. */
4175 add_signatured_type_cu_to_table (void **slot
, void *datum
)
4177 struct signatured_type
*sigt
= *slot
;
4178 struct signatured_type
***datap
= datum
;
4186 /* Create the hash table of all entries in the .debug_types section.
4187 DWO_FILE is a pointer to the DWO file for .debug_types.dwo,
4189 Note: This function processes DWO files only, not DWP files.
4190 The result is a pointer to the hash table or NULL if there are
4194 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
4195 VEC (dwarf2_section_info_def
) *types
)
4197 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4198 htab_t types_htab
= NULL
;
4200 struct dwarf2_section_info
*section
;
4201 struct dwarf2_section_info
*abbrev_section
;
4203 if (VEC_empty (dwarf2_section_info_def
, types
))
4206 abbrev_section
= (dwo_file
!= NULL
4207 ? &dwo_file
->sections
.abbrev
4208 : &dwarf2_per_objfile
->abbrev
);
4210 if (dwarf2_read_debug
)
4211 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_types%s for %s:\n",
4212 dwo_file
? ".dwo" : "",
4213 bfd_get_filename (abbrev_section
->asection
->owner
));
4216 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
4220 gdb_byte
*info_ptr
, *end_ptr
;
4221 struct dwarf2_section_info
*abbrev_section
;
4223 dwarf2_read_section (objfile
, section
);
4224 info_ptr
= section
->buffer
;
4226 if (info_ptr
== NULL
)
4229 /* We can't set abfd until now because the section may be empty or
4230 not present, in which case section->asection will be NULL. */
4231 abfd
= section
->asection
->owner
;
4234 abbrev_section
= &dwo_file
->sections
.abbrev
;
4236 abbrev_section
= &dwarf2_per_objfile
->abbrev
;
4238 if (types_htab
== NULL
)
4241 types_htab
= allocate_dwo_unit_table (objfile
);
4243 types_htab
= allocate_signatured_type_table (objfile
);
4246 /* We don't use init_cutu_and_read_dies_simple, or some such, here
4247 because we don't need to read any dies: the signature is in the
4250 end_ptr
= info_ptr
+ section
->size
;
4251 while (info_ptr
< end_ptr
)
4254 cu_offset type_offset_in_tu
;
4256 struct signatured_type
*sig_type
;
4257 struct dwo_unit
*dwo_tu
;
4259 gdb_byte
*ptr
= info_ptr
;
4260 struct comp_unit_head header
;
4261 unsigned int length
;
4263 offset
.sect_off
= ptr
- section
->buffer
;
4265 /* We need to read the type's signature in order to build the hash
4266 table, but we don't need anything else just yet. */
4268 ptr
= read_and_check_type_unit_head (&header
, section
,
4269 abbrev_section
, ptr
,
4270 &signature
, &type_offset_in_tu
);
4272 length
= get_cu_length (&header
);
4274 /* Skip dummy type units. */
4275 if (ptr
>= info_ptr
+ length
4276 || peek_abbrev_code (abfd
, ptr
) == 0)
4285 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4287 dwo_tu
->dwo_file
= dwo_file
;
4288 dwo_tu
->signature
= signature
;
4289 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
4290 dwo_tu
->info_or_types_section
= section
;
4291 dwo_tu
->offset
= offset
;
4292 dwo_tu
->length
= length
;
4296 /* N.B.: type_offset is not usable if this type uses a DWO file.
4297 The real type_offset is in the DWO file. */
4299 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4300 struct signatured_type
);
4301 sig_type
->signature
= signature
;
4302 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
4303 sig_type
->per_cu
.objfile
= objfile
;
4304 sig_type
->per_cu
.is_debug_types
= 1;
4305 sig_type
->per_cu
.info_or_types_section
= section
;
4306 sig_type
->per_cu
.offset
= offset
;
4307 sig_type
->per_cu
.length
= length
;
4310 slot
= htab_find_slot (types_htab
,
4311 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
4313 gdb_assert (slot
!= NULL
);
4316 sect_offset dup_offset
;
4320 const struct dwo_unit
*dup_tu
= *slot
;
4322 dup_offset
= dup_tu
->offset
;
4326 const struct signatured_type
*dup_tu
= *slot
;
4328 dup_offset
= dup_tu
->per_cu
.offset
;
4331 complaint (&symfile_complaints
,
4332 _("debug type entry at offset 0x%x is duplicate to the "
4333 "entry at offset 0x%x, signature 0x%s"),
4334 offset
.sect_off
, dup_offset
.sect_off
,
4335 phex (signature
, sizeof (signature
)));
4337 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
4339 if (dwarf2_read_debug
)
4340 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
4342 phex (signature
, sizeof (signature
)));
4351 /* Create the hash table of all entries in the .debug_types section,
4352 and initialize all_type_units.
4353 The result is zero if there is an error (e.g. missing .debug_types section),
4354 otherwise non-zero. */
4357 create_all_type_units (struct objfile
*objfile
)
4360 struct signatured_type
**iter
;
4362 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
4363 if (types_htab
== NULL
)
4365 dwarf2_per_objfile
->signatured_types
= NULL
;
4369 dwarf2_per_objfile
->signatured_types
= types_htab
;
4371 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
4372 dwarf2_per_objfile
->all_type_units
4373 = obstack_alloc (&objfile
->objfile_obstack
,
4374 dwarf2_per_objfile
->n_type_units
4375 * sizeof (struct signatured_type
*));
4376 iter
= &dwarf2_per_objfile
->all_type_units
[0];
4377 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
4378 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
4379 == dwarf2_per_objfile
->n_type_units
);
4384 /* Lookup a signature based type for DW_FORM_ref_sig8.
4385 Returns NULL if signature SIG is not present in the table. */
4387 static struct signatured_type
*
4388 lookup_signatured_type (ULONGEST sig
)
4390 struct signatured_type find_entry
, *entry
;
4392 if (dwarf2_per_objfile
->signatured_types
== NULL
)
4394 complaint (&symfile_complaints
,
4395 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
4399 find_entry
.signature
= sig
;
4400 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
4404 /* Low level DIE reading support. */
4406 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
4409 init_cu_die_reader (struct die_reader_specs
*reader
,
4410 struct dwarf2_cu
*cu
,
4411 struct dwarf2_section_info
*section
,
4412 struct dwo_file
*dwo_file
)
4414 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
4415 reader
->abfd
= section
->asection
->owner
;
4417 reader
->dwo_file
= dwo_file
;
4418 reader
->die_section
= section
;
4419 reader
->buffer
= section
->buffer
;
4420 reader
->buffer_end
= section
->buffer
+ section
->size
;
4423 /* Initialize a CU (or TU) and read its DIEs.
4424 If the CU defers to a DWO file, read the DWO file as well.
4426 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
4427 Otherwise the table specified in the comp unit header is read in and used.
4428 This is an optimization for when we already have the abbrev table.
4430 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
4431 Otherwise, a new CU is allocated with xmalloc.
4433 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
4434 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
4436 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4437 linker) then DIE_READER_FUNC will not get called. */
4440 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
4441 struct abbrev_table
*abbrev_table
,
4442 int use_existing_cu
, int keep
,
4443 die_reader_func_ftype
*die_reader_func
,
4446 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4447 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4448 bfd
*abfd
= section
->asection
->owner
;
4449 struct dwarf2_cu
*cu
;
4450 gdb_byte
*begin_info_ptr
, *info_ptr
;
4451 struct die_reader_specs reader
;
4452 struct die_info
*comp_unit_die
;
4454 struct attribute
*attr
;
4455 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
4456 struct signatured_type
*sig_type
= NULL
;
4457 struct dwarf2_section_info
*abbrev_section
;
4458 /* Non-zero if CU currently points to a DWO file and we need to
4459 reread it. When this happens we need to reread the skeleton die
4460 before we can reread the DWO file. */
4461 int rereading_dwo_cu
= 0;
4463 if (dwarf2_die_debug
)
4464 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4465 this_cu
->is_debug_types
? "type" : "comp",
4466 this_cu
->offset
.sect_off
);
4468 if (use_existing_cu
)
4471 cleanups
= make_cleanup (null_cleanup
, NULL
);
4473 /* This is cheap if the section is already read in. */
4474 dwarf2_read_section (objfile
, section
);
4476 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4478 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
4480 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
4484 /* If this CU is from a DWO file we need to start over, we need to
4485 refetch the attributes from the skeleton CU.
4486 This could be optimized by retrieving those attributes from when we
4487 were here the first time: the previous comp_unit_die was stored in
4488 comp_unit_obstack. But there's no data yet that we need this
4490 if (cu
->dwo_unit
!= NULL
)
4491 rereading_dwo_cu
= 1;
4495 /* If !use_existing_cu, this_cu->cu must be NULL. */
4496 gdb_assert (this_cu
->cu
== NULL
);
4498 cu
= xmalloc (sizeof (*cu
));
4499 init_one_comp_unit (cu
, this_cu
);
4501 /* If an error occurs while loading, release our storage. */
4502 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
4505 if (cu
->header
.first_die_offset
.cu_off
!= 0 && ! rereading_dwo_cu
)
4507 /* We already have the header, there's no need to read it in again. */
4508 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
4512 if (this_cu
->is_debug_types
)
4515 cu_offset type_offset_in_tu
;
4517 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4518 abbrev_section
, info_ptr
,
4520 &type_offset_in_tu
);
4522 /* Since per_cu is the first member of struct signatured_type,
4523 we can go from a pointer to one to a pointer to the other. */
4524 sig_type
= (struct signatured_type
*) this_cu
;
4525 gdb_assert (sig_type
->signature
== signature
);
4526 gdb_assert (sig_type
->type_offset_in_tu
.cu_off
4527 == type_offset_in_tu
.cu_off
);
4528 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4530 /* LENGTH has not been set yet for type units if we're
4531 using .gdb_index. */
4532 this_cu
->length
= get_cu_length (&cu
->header
);
4534 /* Establish the type offset that can be used to lookup the type. */
4535 sig_type
->type_offset_in_section
.sect_off
=
4536 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
4540 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4544 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4545 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
4549 /* Skip dummy compilation units. */
4550 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4551 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4553 do_cleanups (cleanups
);
4557 /* If we don't have them yet, read the abbrevs for this compilation unit.
4558 And if we need to read them now, make sure they're freed when we're
4559 done. Note that it's important that if the CU had an abbrev table
4560 on entry we don't free it when we're done: Somewhere up the call stack
4561 it may be in use. */
4562 if (abbrev_table
!= NULL
)
4564 gdb_assert (cu
->abbrev_table
== NULL
);
4565 gdb_assert (cu
->header
.abbrev_offset
.sect_off
4566 == abbrev_table
->offset
.sect_off
);
4567 cu
->abbrev_table
= abbrev_table
;
4569 else if (cu
->abbrev_table
== NULL
)
4571 dwarf2_read_abbrevs (cu
, abbrev_section
);
4572 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4574 else if (rereading_dwo_cu
)
4576 dwarf2_free_abbrev_table (cu
);
4577 dwarf2_read_abbrevs (cu
, abbrev_section
);
4580 /* Read the top level CU/TU die. */
4581 init_cu_die_reader (&reader
, cu
, section
, NULL
);
4582 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4584 /* If we have a DWO stub, process it and then read in the DWO file.
4585 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains
4586 a DWO CU, that this test will fail. */
4587 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
4590 char *dwo_name
= DW_STRING (attr
);
4591 const char *comp_dir_string
;
4592 struct dwo_unit
*dwo_unit
;
4593 ULONGEST signature
; /* Or dwo_id. */
4594 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
4595 int i
,num_extra_attrs
;
4596 struct dwarf2_section_info
*dwo_abbrev_section
;
4599 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
4600 " has children (offset 0x%x) [in module %s]"),
4601 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
4603 /* These attributes aren't processed until later:
4604 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
4605 However, the attribute is found in the stub which we won't have later.
4606 In order to not impose this complication on the rest of the code,
4607 we read them here and copy them to the DWO CU/TU die. */
4609 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
4612 if (! this_cu
->is_debug_types
)
4613 stmt_list
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
4614 low_pc
= dwarf2_attr (comp_unit_die
, DW_AT_low_pc
, cu
);
4615 high_pc
= dwarf2_attr (comp_unit_die
, DW_AT_high_pc
, cu
);
4616 ranges
= dwarf2_attr (comp_unit_die
, DW_AT_ranges
, cu
);
4617 comp_dir
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4619 /* There should be a DW_AT_addr_base attribute here (if needed).
4620 We need the value before we can process DW_FORM_GNU_addr_index. */
4622 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
4624 cu
->addr_base
= DW_UNSND (attr
);
4626 /* There should be a DW_AT_ranges_base attribute here (if needed).
4627 We need the value before we can process DW_AT_ranges. */
4628 cu
->ranges_base
= 0;
4629 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
4631 cu
->ranges_base
= DW_UNSND (attr
);
4633 if (this_cu
->is_debug_types
)
4635 gdb_assert (sig_type
!= NULL
);
4636 signature
= sig_type
->signature
;
4640 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
4642 error (_("Dwarf Error: missing dwo_id [in module %s]"),
4644 signature
= DW_UNSND (attr
);
4647 /* We may need the comp_dir in order to find the DWO file. */
4648 comp_dir_string
= NULL
;
4650 comp_dir_string
= DW_STRING (comp_dir
);
4652 if (this_cu
->is_debug_types
)
4653 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir_string
);
4655 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir_string
,
4658 if (dwo_unit
== NULL
)
4660 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
4661 " with ID %s [in module %s]"),
4662 this_cu
->offset
.sect_off
,
4663 phex (signature
, sizeof (signature
)),
4667 /* Set up for reading the DWO CU/TU. */
4668 cu
->dwo_unit
= dwo_unit
;
4669 section
= dwo_unit
->info_or_types_section
;
4670 dwarf2_read_section (objfile
, section
);
4671 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
4672 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
4673 init_cu_die_reader (&reader
, cu
, section
, dwo_unit
->dwo_file
);
4675 if (this_cu
->is_debug_types
)
4678 cu_offset type_offset_in_tu
;
4680 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4684 &type_offset_in_tu
);
4685 gdb_assert (sig_type
->signature
== signature
);
4686 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4687 /* For DWOs coming from DWP files, we don't know the CU length
4688 nor the type's offset in the TU until now. */
4689 dwo_unit
->length
= get_cu_length (&cu
->header
);
4690 dwo_unit
->type_offset_in_tu
= type_offset_in_tu
;
4692 /* Establish the type offset that can be used to lookup the type.
4693 For DWO files, we don't know it until now. */
4694 sig_type
->type_offset_in_section
.sect_off
=
4695 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
4699 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4702 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4703 /* For DWOs coming from DWP files, we don't know the CU length
4705 dwo_unit
->length
= get_cu_length (&cu
->header
);
4708 /* Discard the original CU's abbrev table, and read the DWO's. */
4709 if (abbrev_table
== NULL
)
4711 dwarf2_free_abbrev_table (cu
);
4712 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4716 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4717 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4720 /* Read in the die, but leave space to copy over the attributes
4721 from the stub. This has the benefit of simplifying the rest of
4722 the code - all the real work is done here. */
4723 num_extra_attrs
= ((stmt_list
!= NULL
)
4727 + (comp_dir
!= NULL
));
4728 info_ptr
= read_full_die_1 (&reader
, &comp_unit_die
, info_ptr
,
4729 &has_children
, num_extra_attrs
);
4731 /* Copy over the attributes from the stub to the DWO die. */
4732 i
= comp_unit_die
->num_attrs
;
4733 if (stmt_list
!= NULL
)
4734 comp_unit_die
->attrs
[i
++] = *stmt_list
;
4736 comp_unit_die
->attrs
[i
++] = *low_pc
;
4737 if (high_pc
!= NULL
)
4738 comp_unit_die
->attrs
[i
++] = *high_pc
;
4740 comp_unit_die
->attrs
[i
++] = *ranges
;
4741 if (comp_dir
!= NULL
)
4742 comp_unit_die
->attrs
[i
++] = *comp_dir
;
4743 comp_unit_die
->num_attrs
+= num_extra_attrs
;
4745 /* Skip dummy compilation units. */
4746 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
4747 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4749 do_cleanups (cleanups
);
4754 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4756 if (free_cu_cleanup
!= NULL
)
4760 /* We've successfully allocated this compilation unit. Let our
4761 caller clean it up when finished with it. */
4762 discard_cleanups (free_cu_cleanup
);
4764 /* We can only discard free_cu_cleanup and all subsequent cleanups.
4765 So we have to manually free the abbrev table. */
4766 dwarf2_free_abbrev_table (cu
);
4768 /* Link this CU into read_in_chain. */
4769 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4770 dwarf2_per_objfile
->read_in_chain
= this_cu
;
4773 do_cleanups (free_cu_cleanup
);
4776 do_cleanups (cleanups
);
4779 /* Read CU/TU THIS_CU in section SECTION,
4780 but do not follow DW_AT_GNU_dwo_name if present.
4781 DWOP_FILE, if non-NULL, is the DWO/DWP file to read (the caller is assumed
4782 to have already done the lookup to find the DWO/DWP file).
4784 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
4785 THIS_CU->is_debug_types, but nothing else.
4787 We fill in THIS_CU->length.
4789 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4790 linker) then DIE_READER_FUNC will not get called.
4792 THIS_CU->cu is always freed when done.
4793 This is done in order to not leave THIS_CU->cu in a state where we have
4794 to care whether it refers to the "main" CU or the DWO CU. */
4797 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
4798 struct dwarf2_section_info
*abbrev_section
,
4799 struct dwo_file
*dwo_file
,
4800 die_reader_func_ftype
*die_reader_func
,
4803 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4804 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4805 bfd
*abfd
= section
->asection
->owner
;
4806 struct dwarf2_cu cu
;
4807 gdb_byte
*begin_info_ptr
, *info_ptr
;
4808 struct die_reader_specs reader
;
4809 struct cleanup
*cleanups
;
4810 struct die_info
*comp_unit_die
;
4813 if (dwarf2_die_debug
)
4814 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4815 this_cu
->is_debug_types
? "type" : "comp",
4816 this_cu
->offset
.sect_off
);
4818 gdb_assert (this_cu
->cu
== NULL
);
4820 /* This is cheap if the section is already read in. */
4821 dwarf2_read_section (objfile
, section
);
4823 init_one_comp_unit (&cu
, this_cu
);
4825 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
4827 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4828 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
4829 abbrev_section
, info_ptr
,
4830 this_cu
->is_debug_types
);
4832 this_cu
->length
= get_cu_length (&cu
.header
);
4834 /* Skip dummy compilation units. */
4835 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4836 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4838 do_cleanups (cleanups
);
4842 dwarf2_read_abbrevs (&cu
, abbrev_section
);
4843 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
4845 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
4846 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4848 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4850 do_cleanups (cleanups
);
4853 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
4854 does not lookup the specified DWO file.
4855 This cannot be used to read DWO files.
4857 THIS_CU->cu is always freed when done.
4858 This is done in order to not leave THIS_CU->cu in a state where we have
4859 to care whether it refers to the "main" CU or the DWO CU.
4860 We can revisit this if the data shows there's a performance issue. */
4863 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
4864 die_reader_func_ftype
*die_reader_func
,
4867 init_cutu_and_read_dies_no_follow (this_cu
,
4868 get_abbrev_section_for_cu (this_cu
),
4870 die_reader_func
, data
);
4873 /* Create a psymtab named NAME and assign it to PER_CU.
4875 The caller must fill in the following details:
4876 dirname, textlow, texthigh. */
4878 static struct partial_symtab
*
4879 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
4881 struct objfile
*objfile
= per_cu
->objfile
;
4882 struct partial_symtab
*pst
;
4884 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
4886 objfile
->global_psymbols
.next
,
4887 objfile
->static_psymbols
.next
);
4889 pst
->psymtabs_addrmap_supported
= 1;
4891 /* This is the glue that links PST into GDB's symbol API. */
4892 pst
->read_symtab_private
= per_cu
;
4893 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
4894 per_cu
->v
.psymtab
= pst
;
4899 /* die_reader_func for process_psymtab_comp_unit. */
4902 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
4904 struct die_info
*comp_unit_die
,
4908 struct dwarf2_cu
*cu
= reader
->cu
;
4909 struct objfile
*objfile
= cu
->objfile
;
4910 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4911 struct attribute
*attr
;
4913 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
4914 struct partial_symtab
*pst
;
4916 const char *filename
;
4917 int *want_partial_unit_ptr
= data
;
4919 if (comp_unit_die
->tag
== DW_TAG_partial_unit
4920 && (want_partial_unit_ptr
== NULL
4921 || !*want_partial_unit_ptr
))
4924 gdb_assert (! per_cu
->is_debug_types
);
4926 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4928 cu
->list_in_scope
= &file_symbols
;
4930 /* Allocate a new partial symbol table structure. */
4931 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
4932 if (attr
== NULL
|| !DW_STRING (attr
))
4935 filename
= DW_STRING (attr
);
4937 pst
= create_partial_symtab (per_cu
, filename
);
4939 /* This must be done before calling dwarf2_build_include_psymtabs. */
4940 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4942 pst
->dirname
= DW_STRING (attr
);
4944 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4946 dwarf2_find_base_address (comp_unit_die
, cu
);
4948 /* Possibly set the default values of LOWPC and HIGHPC from
4950 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
4951 &best_highpc
, cu
, pst
);
4952 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
4953 /* Store the contiguous range if it is not empty; it can be empty for
4954 CUs with no code. */
4955 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4956 best_lowpc
+ baseaddr
,
4957 best_highpc
+ baseaddr
- 1, pst
);
4959 /* Check if comp unit has_children.
4960 If so, read the rest of the partial symbols from this comp unit.
4961 If not, there's no more debug_info for this comp unit. */
4964 struct partial_die_info
*first_die
;
4965 CORE_ADDR lowpc
, highpc
;
4967 lowpc
= ((CORE_ADDR
) -1);
4968 highpc
= ((CORE_ADDR
) 0);
4970 first_die
= load_partial_dies (reader
, info_ptr
, 1);
4972 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
4975 /* If we didn't find a lowpc, set it to highpc to avoid
4976 complaints from `maint check'. */
4977 if (lowpc
== ((CORE_ADDR
) -1))
4980 /* If the compilation unit didn't have an explicit address range,
4981 then use the information extracted from its child dies. */
4985 best_highpc
= highpc
;
4988 pst
->textlow
= best_lowpc
+ baseaddr
;
4989 pst
->texthigh
= best_highpc
+ baseaddr
;
4991 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
4992 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
4993 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
4994 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4995 sort_pst_symbols (objfile
, pst
);
4997 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
))
5000 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
);
5001 struct dwarf2_per_cu_data
*iter
;
5003 /* Fill in 'dependencies' here; we fill in 'users' in a
5005 pst
->number_of_dependencies
= len
;
5006 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
5007 len
* sizeof (struct symtab
*));
5009 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
,
5012 pst
->dependencies
[i
] = iter
->v
.psymtab
;
5014 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
);
5017 /* Get the list of files included in the current compilation unit,
5018 and build a psymtab for each of them. */
5019 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
5021 if (dwarf2_read_debug
)
5023 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5025 fprintf_unfiltered (gdb_stdlog
,
5026 "Psymtab for %s unit @0x%x: %s - %s"
5027 ", %d global, %d static syms\n",
5028 per_cu
->is_debug_types
? "type" : "comp",
5029 per_cu
->offset
.sect_off
,
5030 paddress (gdbarch
, pst
->textlow
),
5031 paddress (gdbarch
, pst
->texthigh
),
5032 pst
->n_global_syms
, pst
->n_static_syms
);
5036 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
5037 Process compilation unit THIS_CU for a psymtab. */
5040 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
5041 int want_partial_unit
)
5043 /* If this compilation unit was already read in, free the
5044 cached copy in order to read it in again. This is
5045 necessary because we skipped some symbols when we first
5046 read in the compilation unit (see load_partial_dies).
5047 This problem could be avoided, but the benefit is unclear. */
5048 if (this_cu
->cu
!= NULL
)
5049 free_one_cached_comp_unit (this_cu
);
5051 gdb_assert (! this_cu
->is_debug_types
);
5052 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
5053 process_psymtab_comp_unit_reader
,
5054 &want_partial_unit
);
5056 /* Age out any secondary CUs. */
5057 age_cached_comp_units ();
5061 hash_type_unit_group (const void *item
)
5063 const struct type_unit_group
*tu_group
= item
;
5065 return hash_stmt_list_entry (&tu_group
->hash
);
5069 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
5071 const struct type_unit_group
*lhs
= item_lhs
;
5072 const struct type_unit_group
*rhs
= item_rhs
;
5074 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
5077 /* Allocate a hash table for type unit groups. */
5080 allocate_type_unit_groups_table (void)
5082 return htab_create_alloc_ex (3,
5083 hash_type_unit_group
,
5086 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
5087 hashtab_obstack_allocate
,
5088 dummy_obstack_deallocate
);
5091 /* Type units that don't have DW_AT_stmt_list are grouped into their own
5092 partial symtabs. We combine several TUs per psymtab to not let the size
5093 of any one psymtab grow too big. */
5094 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
5095 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
5097 /* Helper routine for get_type_unit_group.
5098 Create the type_unit_group object used to hold one or more TUs. */
5100 static struct type_unit_group
*
5101 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
5103 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5104 struct dwarf2_per_cu_data
*per_cu
;
5105 struct type_unit_group
*tu_group
;
5107 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5108 struct type_unit_group
);
5109 per_cu
= &tu_group
->per_cu
;
5110 per_cu
->objfile
= objfile
;
5111 per_cu
->is_debug_types
= 1;
5112 per_cu
->s
.type_unit_group
= tu_group
;
5114 if (dwarf2_per_objfile
->using_index
)
5116 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5117 struct dwarf2_per_cu_quick_data
);
5118 tu_group
->t
.first_tu
= cu
->per_cu
;
5122 unsigned int line_offset
= line_offset_struct
.sect_off
;
5123 struct partial_symtab
*pst
;
5126 /* Give the symtab a useful name for debug purposes. */
5127 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
5128 name
= xstrprintf ("<type_units_%d>",
5129 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
5131 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
5133 pst
= create_partial_symtab (per_cu
, name
);
5139 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
5140 tu_group
->hash
.line_offset
= line_offset_struct
;
5145 /* Look up the type_unit_group for type unit CU, and create it if necessary.
5146 STMT_LIST is a DW_AT_stmt_list attribute. */
5148 static struct type_unit_group
*
5149 get_type_unit_group (struct dwarf2_cu
*cu
, struct attribute
*stmt_list
)
5151 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
5152 struct type_unit_group
*tu_group
;
5154 unsigned int line_offset
;
5155 struct type_unit_group type_unit_group_for_lookup
;
5157 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
5159 dwarf2_per_objfile
->type_unit_groups
=
5160 allocate_type_unit_groups_table ();
5163 /* Do we need to create a new group, or can we use an existing one? */
5167 line_offset
= DW_UNSND (stmt_list
);
5168 ++tu_stats
->nr_symtab_sharers
;
5172 /* Ugh, no stmt_list. Rare, but we have to handle it.
5173 We can do various things here like create one group per TU or
5174 spread them over multiple groups to split up the expansion work.
5175 To avoid worst case scenarios (too many groups or too large groups)
5176 we, umm, group them in bunches. */
5177 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
5178 | (tu_stats
->nr_stmt_less_type_units
5179 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
5180 ++tu_stats
->nr_stmt_less_type_units
;
5183 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
5184 type_unit_group_for_lookup
.hash
.line_offset
.sect_off
= line_offset
;
5185 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
5186 &type_unit_group_for_lookup
, INSERT
);
5190 gdb_assert (tu_group
!= NULL
);
5194 sect_offset line_offset_struct
;
5196 line_offset_struct
.sect_off
= line_offset
;
5197 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
5199 ++tu_stats
->nr_symtabs
;
5205 /* Struct used to sort TUs by their abbreviation table offset. */
5207 struct tu_abbrev_offset
5209 struct signatured_type
*sig_type
;
5210 sect_offset abbrev_offset
;
5213 /* Helper routine for build_type_unit_groups, passed to qsort. */
5216 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
5218 const struct tu_abbrev_offset
* const *a
= ap
;
5219 const struct tu_abbrev_offset
* const *b
= bp
;
5220 unsigned int aoff
= (*a
)->abbrev_offset
.sect_off
;
5221 unsigned int boff
= (*b
)->abbrev_offset
.sect_off
;
5223 return (aoff
> boff
) - (aoff
< boff
);
5226 /* A helper function to add a type_unit_group to a table. */
5229 add_type_unit_group_to_table (void **slot
, void *datum
)
5231 struct type_unit_group
*tu_group
= *slot
;
5232 struct type_unit_group
***datap
= datum
;
5240 /* Efficiently read all the type units, calling init_cutu_and_read_dies on
5241 each one passing FUNC,DATA.
5243 The efficiency is because we sort TUs by the abbrev table they use and
5244 only read each abbrev table once. In one program there are 200K TUs
5245 sharing 8K abbrev tables.
5247 The main purpose of this function is to support building the
5248 dwarf2_per_objfile->type_unit_groups table.
5249 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
5250 can collapse the search space by grouping them by stmt_list.
5251 The savings can be significant, in the same program from above the 200K TUs
5252 share 8K stmt_list tables.
5254 FUNC is expected to call get_type_unit_group, which will create the
5255 struct type_unit_group if necessary and add it to
5256 dwarf2_per_objfile->type_unit_groups. */
5259 build_type_unit_groups (die_reader_func_ftype
*func
, void *data
)
5261 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5262 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
5263 struct cleanup
*cleanups
;
5264 struct abbrev_table
*abbrev_table
;
5265 sect_offset abbrev_offset
;
5266 struct tu_abbrev_offset
*sorted_by_abbrev
;
5267 struct type_unit_group
**iter
;
5270 /* It's up to the caller to not call us multiple times. */
5271 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
5273 if (dwarf2_per_objfile
->n_type_units
== 0)
5276 /* TUs typically share abbrev tables, and there can be way more TUs than
5277 abbrev tables. Sort by abbrev table to reduce the number of times we
5278 read each abbrev table in.
5279 Alternatives are to punt or to maintain a cache of abbrev tables.
5280 This is simpler and efficient enough for now.
5282 Later we group TUs by their DW_AT_stmt_list value (as this defines the
5283 symtab to use). Typically TUs with the same abbrev offset have the same
5284 stmt_list value too so in practice this should work well.
5286 The basic algorithm here is:
5288 sort TUs by abbrev table
5289 for each TU with same abbrev table:
5290 read abbrev table if first user
5291 read TU top level DIE
5292 [IWBN if DWO skeletons had DW_AT_stmt_list]
5295 if (dwarf2_read_debug
)
5296 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
5298 /* Sort in a separate table to maintain the order of all_type_units
5299 for .gdb_index: TU indices directly index all_type_units. */
5300 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
5301 dwarf2_per_objfile
->n_type_units
);
5302 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5304 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
5306 sorted_by_abbrev
[i
].sig_type
= sig_type
;
5307 sorted_by_abbrev
[i
].abbrev_offset
=
5308 read_abbrev_offset (sig_type
->per_cu
.info_or_types_section
,
5309 sig_type
->per_cu
.offset
);
5311 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
5312 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
5313 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
5315 /* Note: In the .gdb_index case, get_type_unit_group may have already been
5316 called any number of times, so we don't reset tu_stats here. */
5318 abbrev_offset
.sect_off
= ~(unsigned) 0;
5319 abbrev_table
= NULL
;
5320 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
5322 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5324 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
5326 /* Switch to the next abbrev table if necessary. */
5327 if (abbrev_table
== NULL
5328 || tu
->abbrev_offset
.sect_off
!= abbrev_offset
.sect_off
)
5330 if (abbrev_table
!= NULL
)
5332 abbrev_table_free (abbrev_table
);
5333 /* Reset to NULL in case abbrev_table_read_table throws
5334 an error: abbrev_table_free_cleanup will get called. */
5335 abbrev_table
= NULL
;
5337 abbrev_offset
= tu
->abbrev_offset
;
5339 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
5341 ++tu_stats
->nr_uniq_abbrev_tables
;
5344 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
5348 /* Create a vector of pointers to primary type units to make it easy to
5349 iterate over them and CUs. See dw2_get_primary_cu. */
5350 dwarf2_per_objfile
->n_type_unit_groups
=
5351 htab_elements (dwarf2_per_objfile
->type_unit_groups
);
5352 dwarf2_per_objfile
->all_type_unit_groups
=
5353 obstack_alloc (&objfile
->objfile_obstack
,
5354 dwarf2_per_objfile
->n_type_unit_groups
5355 * sizeof (struct type_unit_group
*));
5356 iter
= &dwarf2_per_objfile
->all_type_unit_groups
[0];
5357 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5358 add_type_unit_group_to_table
, &iter
);
5359 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_unit_groups
[0]
5360 == dwarf2_per_objfile
->n_type_unit_groups
);
5362 do_cleanups (cleanups
);
5364 if (dwarf2_read_debug
)
5366 fprintf_unfiltered (gdb_stdlog
, "Done building type unit groups:\n");
5367 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
5368 dwarf2_per_objfile
->n_type_units
);
5369 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
5370 tu_stats
->nr_uniq_abbrev_tables
);
5371 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
5372 tu_stats
->nr_symtabs
);
5373 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
5374 tu_stats
->nr_symtab_sharers
);
5375 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
5376 tu_stats
->nr_stmt_less_type_units
);
5380 /* Reader function for build_type_psymtabs. */
5383 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
5385 struct die_info
*type_unit_die
,
5389 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5390 struct dwarf2_cu
*cu
= reader
->cu
;
5391 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
5392 struct type_unit_group
*tu_group
;
5393 struct attribute
*attr
;
5394 struct partial_die_info
*first_die
;
5395 CORE_ADDR lowpc
, highpc
;
5396 struct partial_symtab
*pst
;
5398 gdb_assert (data
== NULL
);
5403 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
5404 tu_group
= get_type_unit_group (cu
, attr
);
5406 VEC_safe_push (dwarf2_per_cu_ptr
, tu_group
->t
.tus
, per_cu
);
5408 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
5409 cu
->list_in_scope
= &file_symbols
;
5410 pst
= create_partial_symtab (per_cu
, "");
5413 first_die
= load_partial_dies (reader
, info_ptr
, 1);
5415 lowpc
= (CORE_ADDR
) -1;
5416 highpc
= (CORE_ADDR
) 0;
5417 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
5419 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
5420 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
5421 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
5422 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
5423 sort_pst_symbols (objfile
, pst
);
5426 /* Traversal function for build_type_psymtabs. */
5429 build_type_psymtab_dependencies (void **slot
, void *info
)
5431 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5432 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
5433 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
5434 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5435 int len
= VEC_length (dwarf2_per_cu_ptr
, tu_group
->t
.tus
);
5436 struct dwarf2_per_cu_data
*iter
;
5439 gdb_assert (len
> 0);
5441 pst
->number_of_dependencies
= len
;
5442 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
5443 len
* sizeof (struct psymtab
*));
5445 VEC_iterate (dwarf2_per_cu_ptr
, tu_group
->t
.tus
, i
, iter
);
5448 pst
->dependencies
[i
] = iter
->v
.psymtab
;
5449 iter
->s
.type_unit_group
= tu_group
;
5452 VEC_free (dwarf2_per_cu_ptr
, tu_group
->t
.tus
);
5457 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
5458 Build partial symbol tables for the .debug_types comp-units. */
5461 build_type_psymtabs (struct objfile
*objfile
)
5463 if (! create_all_type_units (objfile
))
5466 build_type_unit_groups (build_type_psymtabs_reader
, NULL
);
5468 /* Now that all TUs have been processed we can fill in the dependencies. */
5469 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5470 build_type_psymtab_dependencies
, NULL
);
5473 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
5476 psymtabs_addrmap_cleanup (void *o
)
5478 struct objfile
*objfile
= o
;
5480 objfile
->psymtabs_addrmap
= NULL
;
5483 /* Compute the 'user' field for each psymtab in OBJFILE. */
5486 set_partial_user (struct objfile
*objfile
)
5490 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5492 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5493 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5499 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
5501 /* Set the 'user' field only if it is not already set. */
5502 if (pst
->dependencies
[j
]->user
== NULL
)
5503 pst
->dependencies
[j
]->user
= pst
;
5508 /* Build the partial symbol table by doing a quick pass through the
5509 .debug_info and .debug_abbrev sections. */
5512 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
5514 struct cleanup
*back_to
, *addrmap_cleanup
;
5515 struct obstack temp_obstack
;
5518 if (dwarf2_read_debug
)
5520 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
5524 dwarf2_per_objfile
->reading_partial_symbols
= 1;
5526 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
5528 /* Any cached compilation units will be linked by the per-objfile
5529 read_in_chain. Make sure to free them when we're done. */
5530 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
5532 build_type_psymtabs (objfile
);
5534 create_all_comp_units (objfile
);
5536 /* Create a temporary address map on a temporary obstack. We later
5537 copy this to the final obstack. */
5538 obstack_init (&temp_obstack
);
5539 make_cleanup_obstack_free (&temp_obstack
);
5540 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
5541 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
5543 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5545 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5547 process_psymtab_comp_unit (per_cu
, 0);
5550 set_partial_user (objfile
);
5552 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
5553 &objfile
->objfile_obstack
);
5554 discard_cleanups (addrmap_cleanup
);
5556 do_cleanups (back_to
);
5558 if (dwarf2_read_debug
)
5559 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
5563 /* die_reader_func for load_partial_comp_unit. */
5566 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
5568 struct die_info
*comp_unit_die
,
5572 struct dwarf2_cu
*cu
= reader
->cu
;
5574 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
5576 /* Check if comp unit has_children.
5577 If so, read the rest of the partial symbols from this comp unit.
5578 If not, there's no more debug_info for this comp unit. */
5580 load_partial_dies (reader
, info_ptr
, 0);
5583 /* Load the partial DIEs for a secondary CU into memory.
5584 This is also used when rereading a primary CU with load_all_dies. */
5587 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
5589 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
5590 load_partial_comp_unit_reader
, NULL
);
5594 read_comp_units_from_section (struct objfile
*objfile
,
5595 struct dwarf2_section_info
*section
,
5596 unsigned int is_dwz
,
5599 struct dwarf2_per_cu_data
***all_comp_units
)
5602 bfd
*abfd
= section
->asection
->owner
;
5604 dwarf2_read_section (objfile
, section
);
5606 info_ptr
= section
->buffer
;
5608 while (info_ptr
< section
->buffer
+ section
->size
)
5610 unsigned int length
, initial_length_size
;
5611 struct dwarf2_per_cu_data
*this_cu
;
5614 offset
.sect_off
= info_ptr
- section
->buffer
;
5616 /* Read just enough information to find out where the next
5617 compilation unit is. */
5618 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5620 /* Save the compilation unit for later lookup. */
5621 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
5622 sizeof (struct dwarf2_per_cu_data
));
5623 memset (this_cu
, 0, sizeof (*this_cu
));
5624 this_cu
->offset
= offset
;
5625 this_cu
->length
= length
+ initial_length_size
;
5626 this_cu
->is_dwz
= is_dwz
;
5627 this_cu
->objfile
= objfile
;
5628 this_cu
->info_or_types_section
= section
;
5630 if (*n_comp_units
== *n_allocated
)
5633 *all_comp_units
= xrealloc (*all_comp_units
,
5635 * sizeof (struct dwarf2_per_cu_data
*));
5637 (*all_comp_units
)[*n_comp_units
] = this_cu
;
5640 info_ptr
= info_ptr
+ this_cu
->length
;
5644 /* Create a list of all compilation units in OBJFILE.
5645 This is only done for -readnow and building partial symtabs. */
5648 create_all_comp_units (struct objfile
*objfile
)
5652 struct dwarf2_per_cu_data
**all_comp_units
;
5656 all_comp_units
= xmalloc (n_allocated
5657 * sizeof (struct dwarf2_per_cu_data
*));
5659 read_comp_units_from_section (objfile
, &dwarf2_per_objfile
->info
, 0,
5660 &n_allocated
, &n_comp_units
, &all_comp_units
);
5662 if (bfd_get_section_by_name (objfile
->obfd
, ".gnu_debugaltlink") != NULL
)
5664 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
5666 read_comp_units_from_section (objfile
, &dwz
->info
, 1,
5667 &n_allocated
, &n_comp_units
,
5671 dwarf2_per_objfile
->all_comp_units
5672 = obstack_alloc (&objfile
->objfile_obstack
,
5673 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5674 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
5675 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5676 xfree (all_comp_units
);
5677 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
5680 /* Process all loaded DIEs for compilation unit CU, starting at
5681 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
5682 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
5683 DW_AT_ranges). If NEED_PC is set, then this function will set
5684 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
5685 and record the covered ranges in the addrmap. */
5688 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
5689 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
5691 struct partial_die_info
*pdi
;
5693 /* Now, march along the PDI's, descending into ones which have
5694 interesting children but skipping the children of the other ones,
5695 until we reach the end of the compilation unit. */
5701 fixup_partial_die (pdi
, cu
);
5703 /* Anonymous namespaces or modules have no name but have interesting
5704 children, so we need to look at them. Ditto for anonymous
5707 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
5708 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
5709 || pdi
->tag
== DW_TAG_imported_unit
)
5713 case DW_TAG_subprogram
:
5714 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
5716 case DW_TAG_constant
:
5717 case DW_TAG_variable
:
5718 case DW_TAG_typedef
:
5719 case DW_TAG_union_type
:
5720 if (!pdi
->is_declaration
)
5722 add_partial_symbol (pdi
, cu
);
5725 case DW_TAG_class_type
:
5726 case DW_TAG_interface_type
:
5727 case DW_TAG_structure_type
:
5728 if (!pdi
->is_declaration
)
5730 add_partial_symbol (pdi
, cu
);
5733 case DW_TAG_enumeration_type
:
5734 if (!pdi
->is_declaration
)
5735 add_partial_enumeration (pdi
, cu
);
5737 case DW_TAG_base_type
:
5738 case DW_TAG_subrange_type
:
5739 /* File scope base type definitions are added to the partial
5741 add_partial_symbol (pdi
, cu
);
5743 case DW_TAG_namespace
:
5744 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
5747 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
5749 case DW_TAG_imported_unit
:
5751 struct dwarf2_per_cu_data
*per_cu
;
5753 /* For now we don't handle imported units in type units. */
5754 if (cu
->per_cu
->is_debug_types
)
5756 error (_("Dwarf Error: DW_TAG_imported_unit is not"
5757 " supported in type units [in module %s]"),
5761 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
5765 /* Go read the partial unit, if needed. */
5766 if (per_cu
->v
.psymtab
== NULL
)
5767 process_psymtab_comp_unit (per_cu
, 1);
5769 VEC_safe_push (dwarf2_per_cu_ptr
,
5770 cu
->per_cu
->s
.imported_symtabs
, per_cu
);
5778 /* If the die has a sibling, skip to the sibling. */
5780 pdi
= pdi
->die_sibling
;
5784 /* Functions used to compute the fully scoped name of a partial DIE.
5786 Normally, this is simple. For C++, the parent DIE's fully scoped
5787 name is concatenated with "::" and the partial DIE's name. For
5788 Java, the same thing occurs except that "." is used instead of "::".
5789 Enumerators are an exception; they use the scope of their parent
5790 enumeration type, i.e. the name of the enumeration type is not
5791 prepended to the enumerator.
5793 There are two complexities. One is DW_AT_specification; in this
5794 case "parent" means the parent of the target of the specification,
5795 instead of the direct parent of the DIE. The other is compilers
5796 which do not emit DW_TAG_namespace; in this case we try to guess
5797 the fully qualified name of structure types from their members'
5798 linkage names. This must be done using the DIE's children rather
5799 than the children of any DW_AT_specification target. We only need
5800 to do this for structures at the top level, i.e. if the target of
5801 any DW_AT_specification (if any; otherwise the DIE itself) does not
5804 /* Compute the scope prefix associated with PDI's parent, in
5805 compilation unit CU. The result will be allocated on CU's
5806 comp_unit_obstack, or a copy of the already allocated PDI->NAME
5807 field. NULL is returned if no prefix is necessary. */
5809 partial_die_parent_scope (struct partial_die_info
*pdi
,
5810 struct dwarf2_cu
*cu
)
5812 char *grandparent_scope
;
5813 struct partial_die_info
*parent
, *real_pdi
;
5815 /* We need to look at our parent DIE; if we have a DW_AT_specification,
5816 then this means the parent of the specification DIE. */
5819 while (real_pdi
->has_specification
)
5820 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
5821 real_pdi
->spec_is_dwz
, cu
);
5823 parent
= real_pdi
->die_parent
;
5827 if (parent
->scope_set
)
5828 return parent
->scope
;
5830 fixup_partial_die (parent
, cu
);
5832 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
5834 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
5835 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
5836 Work around this problem here. */
5837 if (cu
->language
== language_cplus
5838 && parent
->tag
== DW_TAG_namespace
5839 && strcmp (parent
->name
, "::") == 0
5840 && grandparent_scope
== NULL
)
5842 parent
->scope
= NULL
;
5843 parent
->scope_set
= 1;
5847 if (pdi
->tag
== DW_TAG_enumerator
)
5848 /* Enumerators should not get the name of the enumeration as a prefix. */
5849 parent
->scope
= grandparent_scope
;
5850 else if (parent
->tag
== DW_TAG_namespace
5851 || parent
->tag
== DW_TAG_module
5852 || parent
->tag
== DW_TAG_structure_type
5853 || parent
->tag
== DW_TAG_class_type
5854 || parent
->tag
== DW_TAG_interface_type
5855 || parent
->tag
== DW_TAG_union_type
5856 || parent
->tag
== DW_TAG_enumeration_type
)
5858 if (grandparent_scope
== NULL
)
5859 parent
->scope
= parent
->name
;
5861 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
5863 parent
->name
, 0, cu
);
5867 /* FIXME drow/2004-04-01: What should we be doing with
5868 function-local names? For partial symbols, we should probably be
5870 complaint (&symfile_complaints
,
5871 _("unhandled containing DIE tag %d for DIE at %d"),
5872 parent
->tag
, pdi
->offset
.sect_off
);
5873 parent
->scope
= grandparent_scope
;
5876 parent
->scope_set
= 1;
5877 return parent
->scope
;
5880 /* Return the fully scoped name associated with PDI, from compilation unit
5881 CU. The result will be allocated with malloc. */
5884 partial_die_full_name (struct partial_die_info
*pdi
,
5885 struct dwarf2_cu
*cu
)
5889 /* If this is a template instantiation, we can not work out the
5890 template arguments from partial DIEs. So, unfortunately, we have
5891 to go through the full DIEs. At least any work we do building
5892 types here will be reused if full symbols are loaded later. */
5893 if (pdi
->has_template_arguments
)
5895 fixup_partial_die (pdi
, cu
);
5897 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
5899 struct die_info
*die
;
5900 struct attribute attr
;
5901 struct dwarf2_cu
*ref_cu
= cu
;
5903 /* DW_FORM_ref_addr is using section offset. */
5905 attr
.form
= DW_FORM_ref_addr
;
5906 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
5907 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
5909 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
5913 parent_scope
= partial_die_parent_scope (pdi
, cu
);
5914 if (parent_scope
== NULL
)
5917 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
5921 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
5923 struct objfile
*objfile
= cu
->objfile
;
5925 char *actual_name
= NULL
;
5927 int built_actual_name
= 0;
5929 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5931 actual_name
= partial_die_full_name (pdi
, cu
);
5933 built_actual_name
= 1;
5935 if (actual_name
== NULL
)
5936 actual_name
= pdi
->name
;
5940 case DW_TAG_subprogram
:
5941 if (pdi
->is_external
|| cu
->language
== language_ada
)
5943 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
5944 of the global scope. But in Ada, we want to be able to access
5945 nested procedures globally. So all Ada subprograms are stored
5946 in the global scope. */
5947 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5948 mst_text, objfile); */
5949 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5951 VAR_DOMAIN
, LOC_BLOCK
,
5952 &objfile
->global_psymbols
,
5953 0, pdi
->lowpc
+ baseaddr
,
5954 cu
->language
, objfile
);
5958 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5959 mst_file_text, objfile); */
5960 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5962 VAR_DOMAIN
, LOC_BLOCK
,
5963 &objfile
->static_psymbols
,
5964 0, pdi
->lowpc
+ baseaddr
,
5965 cu
->language
, objfile
);
5968 case DW_TAG_constant
:
5970 struct psymbol_allocation_list
*list
;
5972 if (pdi
->is_external
)
5973 list
= &objfile
->global_psymbols
;
5975 list
= &objfile
->static_psymbols
;
5976 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5977 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
5978 list
, 0, 0, cu
->language
, objfile
);
5981 case DW_TAG_variable
:
5983 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
5987 && !dwarf2_per_objfile
->has_section_at_zero
)
5989 /* A global or static variable may also have been stripped
5990 out by the linker if unused, in which case its address
5991 will be nullified; do not add such variables into partial
5992 symbol table then. */
5994 else if (pdi
->is_external
)
5997 Don't enter into the minimal symbol tables as there is
5998 a minimal symbol table entry from the ELF symbols already.
5999 Enter into partial symbol table if it has a location
6000 descriptor or a type.
6001 If the location descriptor is missing, new_symbol will create
6002 a LOC_UNRESOLVED symbol, the address of the variable will then
6003 be determined from the minimal symbol table whenever the variable
6005 The address for the partial symbol table entry is not
6006 used by GDB, but it comes in handy for debugging partial symbol
6009 if (pdi
->d
.locdesc
|| pdi
->has_type
)
6010 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6012 VAR_DOMAIN
, LOC_STATIC
,
6013 &objfile
->global_psymbols
,
6015 cu
->language
, objfile
);
6019 /* Static Variable. Skip symbols without location descriptors. */
6020 if (pdi
->d
.locdesc
== NULL
)
6022 if (built_actual_name
)
6023 xfree (actual_name
);
6026 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
6027 mst_file_data, objfile); */
6028 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6030 VAR_DOMAIN
, LOC_STATIC
,
6031 &objfile
->static_psymbols
,
6033 cu
->language
, objfile
);
6036 case DW_TAG_typedef
:
6037 case DW_TAG_base_type
:
6038 case DW_TAG_subrange_type
:
6039 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6041 VAR_DOMAIN
, LOC_TYPEDEF
,
6042 &objfile
->static_psymbols
,
6043 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
6045 case DW_TAG_namespace
:
6046 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6048 VAR_DOMAIN
, LOC_TYPEDEF
,
6049 &objfile
->global_psymbols
,
6050 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
6052 case DW_TAG_class_type
:
6053 case DW_TAG_interface_type
:
6054 case DW_TAG_structure_type
:
6055 case DW_TAG_union_type
:
6056 case DW_TAG_enumeration_type
:
6057 /* Skip external references. The DWARF standard says in the section
6058 about "Structure, Union, and Class Type Entries": "An incomplete
6059 structure, union or class type is represented by a structure,
6060 union or class entry that does not have a byte size attribute
6061 and that has a DW_AT_declaration attribute." */
6062 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
6064 if (built_actual_name
)
6065 xfree (actual_name
);
6069 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
6070 static vs. global. */
6071 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6073 STRUCT_DOMAIN
, LOC_TYPEDEF
,
6074 (cu
->language
== language_cplus
6075 || cu
->language
== language_java
)
6076 ? &objfile
->global_psymbols
6077 : &objfile
->static_psymbols
,
6078 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
6081 case DW_TAG_enumerator
:
6082 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6084 VAR_DOMAIN
, LOC_CONST
,
6085 (cu
->language
== language_cplus
6086 || cu
->language
== language_java
)
6087 ? &objfile
->global_psymbols
6088 : &objfile
->static_psymbols
,
6089 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
6095 if (built_actual_name
)
6096 xfree (actual_name
);
6099 /* Read a partial die corresponding to a namespace; also, add a symbol
6100 corresponding to that namespace to the symbol table. NAMESPACE is
6101 the name of the enclosing namespace. */
6104 add_partial_namespace (struct partial_die_info
*pdi
,
6105 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6106 int need_pc
, struct dwarf2_cu
*cu
)
6108 /* Add a symbol for the namespace. */
6110 add_partial_symbol (pdi
, cu
);
6112 /* Now scan partial symbols in that namespace. */
6114 if (pdi
->has_children
)
6115 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
6118 /* Read a partial die corresponding to a Fortran module. */
6121 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
6122 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
6124 /* Now scan partial symbols in that module. */
6126 if (pdi
->has_children
)
6127 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
6130 /* Read a partial die corresponding to a subprogram and create a partial
6131 symbol for that subprogram. When the CU language allows it, this
6132 routine also defines a partial symbol for each nested subprogram
6133 that this subprogram contains.
6135 DIE my also be a lexical block, in which case we simply search
6136 recursively for suprograms defined inside that lexical block.
6137 Again, this is only performed when the CU language allows this
6138 type of definitions. */
6141 add_partial_subprogram (struct partial_die_info
*pdi
,
6142 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6143 int need_pc
, struct dwarf2_cu
*cu
)
6145 if (pdi
->tag
== DW_TAG_subprogram
)
6147 if (pdi
->has_pc_info
)
6149 if (pdi
->lowpc
< *lowpc
)
6150 *lowpc
= pdi
->lowpc
;
6151 if (pdi
->highpc
> *highpc
)
6152 *highpc
= pdi
->highpc
;
6156 struct objfile
*objfile
= cu
->objfile
;
6158 baseaddr
= ANOFFSET (objfile
->section_offsets
,
6159 SECT_OFF_TEXT (objfile
));
6160 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6161 pdi
->lowpc
+ baseaddr
,
6162 pdi
->highpc
- 1 + baseaddr
,
6163 cu
->per_cu
->v
.psymtab
);
6167 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
6169 if (!pdi
->is_declaration
)
6170 /* Ignore subprogram DIEs that do not have a name, they are
6171 illegal. Do not emit a complaint at this point, we will
6172 do so when we convert this psymtab into a symtab. */
6174 add_partial_symbol (pdi
, cu
);
6178 if (! pdi
->has_children
)
6181 if (cu
->language
== language_ada
)
6183 pdi
= pdi
->die_child
;
6186 fixup_partial_die (pdi
, cu
);
6187 if (pdi
->tag
== DW_TAG_subprogram
6188 || pdi
->tag
== DW_TAG_lexical_block
)
6189 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
6190 pdi
= pdi
->die_sibling
;
6195 /* Read a partial die corresponding to an enumeration type. */
6198 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
6199 struct dwarf2_cu
*cu
)
6201 struct partial_die_info
*pdi
;
6203 if (enum_pdi
->name
!= NULL
)
6204 add_partial_symbol (enum_pdi
, cu
);
6206 pdi
= enum_pdi
->die_child
;
6209 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
6210 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
6212 add_partial_symbol (pdi
, cu
);
6213 pdi
= pdi
->die_sibling
;
6217 /* Return the initial uleb128 in the die at INFO_PTR. */
6220 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
6222 unsigned int bytes_read
;
6224 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6227 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
6228 Return the corresponding abbrev, or NULL if the number is zero (indicating
6229 an empty DIE). In either case *BYTES_READ will be set to the length of
6230 the initial number. */
6232 static struct abbrev_info
*
6233 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
6234 struct dwarf2_cu
*cu
)
6236 bfd
*abfd
= cu
->objfile
->obfd
;
6237 unsigned int abbrev_number
;
6238 struct abbrev_info
*abbrev
;
6240 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
6242 if (abbrev_number
== 0)
6245 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
6248 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
6249 abbrev_number
, bfd_get_filename (abfd
));
6255 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6256 Returns a pointer to the end of a series of DIEs, terminated by an empty
6257 DIE. Any children of the skipped DIEs will also be skipped. */
6260 skip_children (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
)
6262 struct dwarf2_cu
*cu
= reader
->cu
;
6263 struct abbrev_info
*abbrev
;
6264 unsigned int bytes_read
;
6268 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
6270 return info_ptr
+ bytes_read
;
6272 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
6276 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6277 INFO_PTR should point just after the initial uleb128 of a DIE, and the
6278 abbrev corresponding to that skipped uleb128 should be passed in
6279 ABBREV. Returns a pointer to this DIE's sibling, skipping any
6283 skip_one_die (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
,
6284 struct abbrev_info
*abbrev
)
6286 unsigned int bytes_read
;
6287 struct attribute attr
;
6288 bfd
*abfd
= reader
->abfd
;
6289 struct dwarf2_cu
*cu
= reader
->cu
;
6290 gdb_byte
*buffer
= reader
->buffer
;
6291 const gdb_byte
*buffer_end
= reader
->buffer_end
;
6292 gdb_byte
*start_info_ptr
= info_ptr
;
6293 unsigned int form
, i
;
6295 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
6297 /* The only abbrev we care about is DW_AT_sibling. */
6298 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
6300 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
6301 if (attr
.form
== DW_FORM_ref_addr
)
6302 complaint (&symfile_complaints
,
6303 _("ignoring absolute DW_AT_sibling"));
6305 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
6308 /* If it isn't DW_AT_sibling, skip this attribute. */
6309 form
= abbrev
->attrs
[i
].form
;
6313 case DW_FORM_ref_addr
:
6314 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
6315 and later it is offset sized. */
6316 if (cu
->header
.version
== 2)
6317 info_ptr
+= cu
->header
.addr_size
;
6319 info_ptr
+= cu
->header
.offset_size
;
6321 case DW_FORM_GNU_ref_alt
:
6322 info_ptr
+= cu
->header
.offset_size
;
6325 info_ptr
+= cu
->header
.addr_size
;
6332 case DW_FORM_flag_present
:
6344 case DW_FORM_ref_sig8
:
6347 case DW_FORM_string
:
6348 read_direct_string (abfd
, info_ptr
, &bytes_read
);
6349 info_ptr
+= bytes_read
;
6351 case DW_FORM_sec_offset
:
6353 case DW_FORM_GNU_strp_alt
:
6354 info_ptr
+= cu
->header
.offset_size
;
6356 case DW_FORM_exprloc
:
6358 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6359 info_ptr
+= bytes_read
;
6361 case DW_FORM_block1
:
6362 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
6364 case DW_FORM_block2
:
6365 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
6367 case DW_FORM_block4
:
6368 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
6372 case DW_FORM_ref_udata
:
6373 case DW_FORM_GNU_addr_index
:
6374 case DW_FORM_GNU_str_index
:
6375 info_ptr
= (gdb_byte
*) safe_skip_leb128 (info_ptr
, buffer_end
);
6377 case DW_FORM_indirect
:
6378 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6379 info_ptr
+= bytes_read
;
6380 /* We need to continue parsing from here, so just go back to
6382 goto skip_attribute
;
6385 error (_("Dwarf Error: Cannot handle %s "
6386 "in DWARF reader [in module %s]"),
6387 dwarf_form_name (form
),
6388 bfd_get_filename (abfd
));
6392 if (abbrev
->has_children
)
6393 return skip_children (reader
, info_ptr
);
6398 /* Locate ORIG_PDI's sibling.
6399 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
6402 locate_pdi_sibling (const struct die_reader_specs
*reader
,
6403 struct partial_die_info
*orig_pdi
,
6406 /* Do we know the sibling already? */
6408 if (orig_pdi
->sibling
)
6409 return orig_pdi
->sibling
;
6411 /* Are there any children to deal with? */
6413 if (!orig_pdi
->has_children
)
6416 /* Skip the children the long way. */
6418 return skip_children (reader
, info_ptr
);
6421 /* Expand this partial symbol table into a full symbol table. PST is
6425 dwarf2_psymtab_to_symtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
6429 warning (_("bug: psymtab for %s is already read in."),
6436 printf_filtered (_("Reading in symbols for %s..."),
6438 gdb_flush (gdb_stdout
);
6441 /* Restore our global data. */
6442 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
6444 /* If this psymtab is constructed from a debug-only objfile, the
6445 has_section_at_zero flag will not necessarily be correct. We
6446 can get the correct value for this flag by looking at the data
6447 associated with the (presumably stripped) associated objfile. */
6448 if (objfile
->separate_debug_objfile_backlink
)
6450 struct dwarf2_per_objfile
*dpo_backlink
6451 = objfile_data (objfile
->separate_debug_objfile_backlink
,
6452 dwarf2_objfile_data_key
);
6454 dwarf2_per_objfile
->has_section_at_zero
6455 = dpo_backlink
->has_section_at_zero
;
6458 dwarf2_per_objfile
->reading_partial_symbols
= 0;
6460 psymtab_to_symtab_1 (pst
);
6462 /* Finish up the debug error message. */
6464 printf_filtered (_("done.\n"));
6467 process_cu_includes ();
6470 /* Reading in full CUs. */
6472 /* Add PER_CU to the queue. */
6475 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6476 enum language pretend_language
)
6478 struct dwarf2_queue_item
*item
;
6481 item
= xmalloc (sizeof (*item
));
6482 item
->per_cu
= per_cu
;
6483 item
->pretend_language
= pretend_language
;
6486 if (dwarf2_queue
== NULL
)
6487 dwarf2_queue
= item
;
6489 dwarf2_queue_tail
->next
= item
;
6491 dwarf2_queue_tail
= item
;
6494 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
6495 unit and add it to our queue.
6496 The result is non-zero if PER_CU was queued, otherwise the result is zero
6497 meaning either PER_CU is already queued or it is already loaded. */
6500 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
6501 struct dwarf2_per_cu_data
*per_cu
,
6502 enum language pretend_language
)
6504 /* We may arrive here during partial symbol reading, if we need full
6505 DIEs to process an unusual case (e.g. template arguments). Do
6506 not queue PER_CU, just tell our caller to load its DIEs. */
6507 if (dwarf2_per_objfile
->reading_partial_symbols
)
6509 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
6514 /* Mark the dependence relation so that we don't flush PER_CU
6516 dwarf2_add_dependence (this_cu
, per_cu
);
6518 /* If it's already on the queue, we have nothing to do. */
6522 /* If the compilation unit is already loaded, just mark it as
6524 if (per_cu
->cu
!= NULL
)
6526 per_cu
->cu
->last_used
= 0;
6530 /* Add it to the queue. */
6531 queue_comp_unit (per_cu
, pretend_language
);
6536 /* Process the queue. */
6539 process_queue (void)
6541 struct dwarf2_queue_item
*item
, *next_item
;
6543 if (dwarf2_read_debug
)
6545 fprintf_unfiltered (gdb_stdlog
,
6546 "Expanding one or more symtabs of objfile %s ...\n",
6547 dwarf2_per_objfile
->objfile
->name
);
6550 /* The queue starts out with one item, but following a DIE reference
6551 may load a new CU, adding it to the end of the queue. */
6552 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
6554 if (dwarf2_per_objfile
->using_index
6555 ? !item
->per_cu
->v
.quick
->symtab
6556 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
6558 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
6560 if (dwarf2_read_debug
)
6562 fprintf_unfiltered (gdb_stdlog
,
6563 "Expanding symtab of %s at offset 0x%x\n",
6564 per_cu
->is_debug_types
? "TU" : "CU",
6565 per_cu
->offset
.sect_off
);
6568 if (per_cu
->is_debug_types
)
6569 process_full_type_unit (per_cu
, item
->pretend_language
);
6571 process_full_comp_unit (per_cu
, item
->pretend_language
);
6573 if (dwarf2_read_debug
)
6575 fprintf_unfiltered (gdb_stdlog
,
6576 "Done expanding %s at offset 0x%x\n",
6577 per_cu
->is_debug_types
? "TU" : "CU",
6578 per_cu
->offset
.sect_off
);
6582 item
->per_cu
->queued
= 0;
6583 next_item
= item
->next
;
6587 dwarf2_queue_tail
= NULL
;
6589 if (dwarf2_read_debug
)
6591 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
6592 dwarf2_per_objfile
->objfile
->name
);
6596 /* Free all allocated queue entries. This function only releases anything if
6597 an error was thrown; if the queue was processed then it would have been
6598 freed as we went along. */
6601 dwarf2_release_queue (void *dummy
)
6603 struct dwarf2_queue_item
*item
, *last
;
6605 item
= dwarf2_queue
;
6608 /* Anything still marked queued is likely to be in an
6609 inconsistent state, so discard it. */
6610 if (item
->per_cu
->queued
)
6612 if (item
->per_cu
->cu
!= NULL
)
6613 free_one_cached_comp_unit (item
->per_cu
);
6614 item
->per_cu
->queued
= 0;
6622 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
6625 /* Read in full symbols for PST, and anything it depends on. */
6628 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
6630 struct dwarf2_per_cu_data
*per_cu
;
6636 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
6637 if (!pst
->dependencies
[i
]->readin
6638 && pst
->dependencies
[i
]->user
== NULL
)
6640 /* Inform about additional files that need to be read in. */
6643 /* FIXME: i18n: Need to make this a single string. */
6644 fputs_filtered (" ", gdb_stdout
);
6646 fputs_filtered ("and ", gdb_stdout
);
6648 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
6649 wrap_here (""); /* Flush output. */
6650 gdb_flush (gdb_stdout
);
6652 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
6655 per_cu
= pst
->read_symtab_private
;
6659 /* It's an include file, no symbols to read for it.
6660 Everything is in the parent symtab. */
6665 dw2_do_instantiate_symtab (per_cu
);
6668 /* Trivial hash function for die_info: the hash value of a DIE
6669 is its offset in .debug_info for this objfile. */
6672 die_hash (const void *item
)
6674 const struct die_info
*die
= item
;
6676 return die
->offset
.sect_off
;
6679 /* Trivial comparison function for die_info structures: two DIEs
6680 are equal if they have the same offset. */
6683 die_eq (const void *item_lhs
, const void *item_rhs
)
6685 const struct die_info
*die_lhs
= item_lhs
;
6686 const struct die_info
*die_rhs
= item_rhs
;
6688 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
6691 /* die_reader_func for load_full_comp_unit.
6692 This is identical to read_signatured_type_reader,
6693 but is kept separate for now. */
6696 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
6698 struct die_info
*comp_unit_die
,
6702 struct dwarf2_cu
*cu
= reader
->cu
;
6703 enum language
*language_ptr
= data
;
6705 gdb_assert (cu
->die_hash
== NULL
);
6707 htab_create_alloc_ex (cu
->header
.length
/ 12,
6711 &cu
->comp_unit_obstack
,
6712 hashtab_obstack_allocate
,
6713 dummy_obstack_deallocate
);
6716 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
6717 &info_ptr
, comp_unit_die
);
6718 cu
->dies
= comp_unit_die
;
6719 /* comp_unit_die is not stored in die_hash, no need. */
6721 /* We try not to read any attributes in this function, because not
6722 all CUs needed for references have been loaded yet, and symbol
6723 table processing isn't initialized. But we have to set the CU language,
6724 or we won't be able to build types correctly.
6725 Similarly, if we do not read the producer, we can not apply
6726 producer-specific interpretation. */
6727 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
6730 /* Load the DIEs associated with PER_CU into memory. */
6733 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6734 enum language pretend_language
)
6736 gdb_assert (! this_cu
->is_debug_types
);
6738 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
6739 load_full_comp_unit_reader
, &pretend_language
);
6742 /* Add a DIE to the delayed physname list. */
6745 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
6746 const char *name
, struct die_info
*die
,
6747 struct dwarf2_cu
*cu
)
6749 struct delayed_method_info mi
;
6751 mi
.fnfield_index
= fnfield_index
;
6755 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
6758 /* A cleanup for freeing the delayed method list. */
6761 free_delayed_list (void *ptr
)
6763 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
6764 if (cu
->method_list
!= NULL
)
6766 VEC_free (delayed_method_info
, cu
->method_list
);
6767 cu
->method_list
= NULL
;
6771 /* Compute the physnames of any methods on the CU's method list.
6773 The computation of method physnames is delayed in order to avoid the
6774 (bad) condition that one of the method's formal parameters is of an as yet
6778 compute_delayed_physnames (struct dwarf2_cu
*cu
)
6781 struct delayed_method_info
*mi
;
6782 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
6784 const char *physname
;
6785 struct fn_fieldlist
*fn_flp
6786 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
6787 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
6788 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
6792 /* Go objects should be embedded in a DW_TAG_module DIE,
6793 and it's not clear if/how imported objects will appear.
6794 To keep Go support simple until that's worked out,
6795 go back through what we've read and create something usable.
6796 We could do this while processing each DIE, and feels kinda cleaner,
6797 but that way is more invasive.
6798 This is to, for example, allow the user to type "p var" or "b main"
6799 without having to specify the package name, and allow lookups
6800 of module.object to work in contexts that use the expression
6804 fixup_go_packaging (struct dwarf2_cu
*cu
)
6806 char *package_name
= NULL
;
6807 struct pending
*list
;
6810 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
6812 for (i
= 0; i
< list
->nsyms
; ++i
)
6814 struct symbol
*sym
= list
->symbol
[i
];
6816 if (SYMBOL_LANGUAGE (sym
) == language_go
6817 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
6819 char *this_package_name
= go_symbol_package_name (sym
);
6821 if (this_package_name
== NULL
)
6823 if (package_name
== NULL
)
6824 package_name
= this_package_name
;
6827 if (strcmp (package_name
, this_package_name
) != 0)
6828 complaint (&symfile_complaints
,
6829 _("Symtab %s has objects from two different Go packages: %s and %s"),
6830 (SYMBOL_SYMTAB (sym
)
6831 ? SYMBOL_SYMTAB (sym
)->filename
6832 : cu
->objfile
->name
),
6833 this_package_name
, package_name
);
6834 xfree (this_package_name
);
6840 if (package_name
!= NULL
)
6842 struct objfile
*objfile
= cu
->objfile
;
6843 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
6844 package_name
, objfile
);
6847 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
6849 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
6850 SYMBOL_SET_LANGUAGE (sym
, language_go
);
6851 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
6852 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
6853 e.g., "main" finds the "main" module and not C's main(). */
6854 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
6855 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6856 SYMBOL_TYPE (sym
) = type
;
6858 add_symbol_to_list (sym
, &global_symbols
);
6860 xfree (package_name
);
6864 static void compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
);
6866 /* Return the symtab for PER_CU. This works properly regardless of
6867 whether we're using the index or psymtabs. */
6869 static struct symtab
*
6870 get_symtab (struct dwarf2_per_cu_data
*per_cu
)
6872 return (dwarf2_per_objfile
->using_index
6873 ? per_cu
->v
.quick
->symtab
6874 : per_cu
->v
.psymtab
->symtab
);
6877 /* A helper function for computing the list of all symbol tables
6878 included by PER_CU. */
6881 recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr
) **result
,
6882 htab_t all_children
,
6883 struct dwarf2_per_cu_data
*per_cu
)
6887 struct dwarf2_per_cu_data
*iter
;
6889 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
6892 /* This inclusion and its children have been processed. */
6897 /* Only add a CU if it has a symbol table. */
6898 if (get_symtab (per_cu
) != NULL
)
6899 VEC_safe_push (dwarf2_per_cu_ptr
, *result
, per_cu
);
6902 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
, ix
, iter
);
6904 recursively_compute_inclusions (result
, all_children
, iter
);
6907 /* Compute the symtab 'includes' fields for the symtab related to
6911 compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
6913 gdb_assert (! per_cu
->is_debug_types
);
6915 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
))
6918 struct dwarf2_per_cu_data
*iter
;
6919 VEC (dwarf2_per_cu_ptr
) *result_children
= NULL
;
6920 htab_t all_children
;
6921 struct symtab
*symtab
= get_symtab (per_cu
);
6923 /* If we don't have a symtab, we can just skip this case. */
6927 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
6928 NULL
, xcalloc
, xfree
);
6931 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
,
6934 recursively_compute_inclusions (&result_children
, all_children
, iter
);
6936 /* Now we have a transitive closure of all the included CUs, so
6937 we can convert it to a list of symtabs. */
6938 len
= VEC_length (dwarf2_per_cu_ptr
, result_children
);
6940 = obstack_alloc (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
6941 (len
+ 1) * sizeof (struct symtab
*));
6943 VEC_iterate (dwarf2_per_cu_ptr
, result_children
, ix
, iter
);
6945 symtab
->includes
[ix
] = get_symtab (iter
);
6946 symtab
->includes
[len
] = NULL
;
6948 VEC_free (dwarf2_per_cu_ptr
, result_children
);
6949 htab_delete (all_children
);
6953 /* Compute the 'includes' field for the symtabs of all the CUs we just
6957 process_cu_includes (void)
6960 struct dwarf2_per_cu_data
*iter
;
6963 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
6967 if (! iter
->is_debug_types
)
6968 compute_symtab_includes (iter
);
6971 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
6974 /* Generate full symbol information for PER_CU, whose DIEs have
6975 already been loaded into memory. */
6978 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6979 enum language pretend_language
)
6981 struct dwarf2_cu
*cu
= per_cu
->cu
;
6982 struct objfile
*objfile
= per_cu
->objfile
;
6983 CORE_ADDR lowpc
, highpc
;
6984 struct symtab
*symtab
;
6985 struct cleanup
*back_to
, *delayed_list_cleanup
;
6987 struct block
*static_block
;
6989 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6992 back_to
= make_cleanup (really_free_pendings
, NULL
);
6993 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
6995 cu
->list_in_scope
= &file_symbols
;
6997 cu
->language
= pretend_language
;
6998 cu
->language_defn
= language_def (cu
->language
);
7000 /* Do line number decoding in read_file_scope () */
7001 process_die (cu
->dies
, cu
);
7003 /* For now fudge the Go package. */
7004 if (cu
->language
== language_go
)
7005 fixup_go_packaging (cu
);
7007 /* Now that we have processed all the DIEs in the CU, all the types
7008 should be complete, and it should now be safe to compute all of the
7010 compute_delayed_physnames (cu
);
7011 do_cleanups (delayed_list_cleanup
);
7013 /* Some compilers don't define a DW_AT_high_pc attribute for the
7014 compilation unit. If the DW_AT_high_pc is missing, synthesize
7015 it, by scanning the DIE's below the compilation unit. */
7016 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
7019 = end_symtab_get_static_block (highpc
+ baseaddr
, objfile
, 0,
7020 per_cu
->s
.imported_symtabs
!= NULL
);
7022 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
7023 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
7024 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
7025 addrmap to help ensure it has an accurate map of pc values belonging to
7027 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
7029 symtab
= end_symtab_from_static_block (static_block
, objfile
,
7030 SECT_OFF_TEXT (objfile
), 0);
7034 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
7036 /* Set symtab language to language from DW_AT_language. If the
7037 compilation is from a C file generated by language preprocessors, do
7038 not set the language if it was already deduced by start_subfile. */
7039 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
7040 symtab
->language
= cu
->language
;
7042 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
7043 produce DW_AT_location with location lists but it can be possibly
7044 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
7045 there were bugs in prologue debug info, fixed later in GCC-4.5
7046 by "unwind info for epilogues" patch (which is not directly related).
7048 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
7049 needed, it would be wrong due to missing DW_AT_producer there.
7051 Still one can confuse GDB by using non-standard GCC compilation
7052 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
7054 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
7055 symtab
->locations_valid
= 1;
7057 if (gcc_4_minor
>= 5)
7058 symtab
->epilogue_unwind_valid
= 1;
7060 symtab
->call_site_htab
= cu
->call_site_htab
;
7063 if (dwarf2_per_objfile
->using_index
)
7064 per_cu
->v
.quick
->symtab
= symtab
;
7067 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
7068 pst
->symtab
= symtab
;
7072 /* Push it for inclusion processing later. */
7073 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
7075 do_cleanups (back_to
);
7078 /* Generate full symbol information for type unit PER_CU, whose DIEs have
7079 already been loaded into memory. */
7082 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
7083 enum language pretend_language
)
7085 struct dwarf2_cu
*cu
= per_cu
->cu
;
7086 struct objfile
*objfile
= per_cu
->objfile
;
7087 struct symtab
*symtab
;
7088 struct cleanup
*back_to
, *delayed_list_cleanup
;
7091 back_to
= make_cleanup (really_free_pendings
, NULL
);
7092 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
7094 cu
->list_in_scope
= &file_symbols
;
7096 cu
->language
= pretend_language
;
7097 cu
->language_defn
= language_def (cu
->language
);
7099 /* The symbol tables are set up in read_type_unit_scope. */
7100 process_die (cu
->dies
, cu
);
7102 /* For now fudge the Go package. */
7103 if (cu
->language
== language_go
)
7104 fixup_go_packaging (cu
);
7106 /* Now that we have processed all the DIEs in the CU, all the types
7107 should be complete, and it should now be safe to compute all of the
7109 compute_delayed_physnames (cu
);
7110 do_cleanups (delayed_list_cleanup
);
7112 /* TUs share symbol tables.
7113 If this is the first TU to use this symtab, complete the construction
7114 of it with end_expandable_symtab. Otherwise, complete the addition of
7115 this TU's symbols to the existing symtab. */
7116 if (per_cu
->s
.type_unit_group
->primary_symtab
== NULL
)
7118 symtab
= end_expandable_symtab (0, objfile
, SECT_OFF_TEXT (objfile
));
7119 per_cu
->s
.type_unit_group
->primary_symtab
= symtab
;
7123 /* Set symtab language to language from DW_AT_language. If the
7124 compilation is from a C file generated by language preprocessors,
7125 do not set the language if it was already deduced by
7127 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
7128 symtab
->language
= cu
->language
;
7133 augment_type_symtab (objfile
,
7134 per_cu
->s
.type_unit_group
->primary_symtab
);
7135 symtab
= per_cu
->s
.type_unit_group
->primary_symtab
;
7138 if (dwarf2_per_objfile
->using_index
)
7139 per_cu
->v
.quick
->symtab
= symtab
;
7142 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
7143 pst
->symtab
= symtab
;
7147 do_cleanups (back_to
);
7150 /* Process an imported unit DIE. */
7153 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7155 struct attribute
*attr
;
7157 /* For now we don't handle imported units in type units. */
7158 if (cu
->per_cu
->is_debug_types
)
7160 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7161 " supported in type units [in module %s]"),
7165 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7168 struct dwarf2_per_cu_data
*per_cu
;
7169 struct symtab
*imported_symtab
;
7173 offset
= dwarf2_get_ref_die_offset (attr
);
7174 is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
7175 per_cu
= dwarf2_find_containing_comp_unit (offset
, is_dwz
, cu
->objfile
);
7177 /* Queue the unit, if needed. */
7178 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
7179 load_full_comp_unit (per_cu
, cu
->language
);
7181 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
,
7186 /* Process a die and its children. */
7189 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7193 case DW_TAG_padding
:
7195 case DW_TAG_compile_unit
:
7196 case DW_TAG_partial_unit
:
7197 read_file_scope (die
, cu
);
7199 case DW_TAG_type_unit
:
7200 read_type_unit_scope (die
, cu
);
7202 case DW_TAG_subprogram
:
7203 case DW_TAG_inlined_subroutine
:
7204 read_func_scope (die
, cu
);
7206 case DW_TAG_lexical_block
:
7207 case DW_TAG_try_block
:
7208 case DW_TAG_catch_block
:
7209 read_lexical_block_scope (die
, cu
);
7211 case DW_TAG_GNU_call_site
:
7212 read_call_site_scope (die
, cu
);
7214 case DW_TAG_class_type
:
7215 case DW_TAG_interface_type
:
7216 case DW_TAG_structure_type
:
7217 case DW_TAG_union_type
:
7218 process_structure_scope (die
, cu
);
7220 case DW_TAG_enumeration_type
:
7221 process_enumeration_scope (die
, cu
);
7224 /* These dies have a type, but processing them does not create
7225 a symbol or recurse to process the children. Therefore we can
7226 read them on-demand through read_type_die. */
7227 case DW_TAG_subroutine_type
:
7228 case DW_TAG_set_type
:
7229 case DW_TAG_array_type
:
7230 case DW_TAG_pointer_type
:
7231 case DW_TAG_ptr_to_member_type
:
7232 case DW_TAG_reference_type
:
7233 case DW_TAG_string_type
:
7236 case DW_TAG_base_type
:
7237 case DW_TAG_subrange_type
:
7238 case DW_TAG_typedef
:
7239 /* Add a typedef symbol for the type definition, if it has a
7241 new_symbol (die
, read_type_die (die
, cu
), cu
);
7243 case DW_TAG_common_block
:
7244 read_common_block (die
, cu
);
7246 case DW_TAG_common_inclusion
:
7248 case DW_TAG_namespace
:
7249 processing_has_namespace_info
= 1;
7250 read_namespace (die
, cu
);
7253 processing_has_namespace_info
= 1;
7254 read_module (die
, cu
);
7256 case DW_TAG_imported_declaration
:
7257 case DW_TAG_imported_module
:
7258 processing_has_namespace_info
= 1;
7259 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
7260 || cu
->language
!= language_fortran
))
7261 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
7262 dwarf_tag_name (die
->tag
));
7263 read_import_statement (die
, cu
);
7266 case DW_TAG_imported_unit
:
7267 process_imported_unit_die (die
, cu
);
7271 new_symbol (die
, NULL
, cu
);
7276 /* A helper function for dwarf2_compute_name which determines whether DIE
7277 needs to have the name of the scope prepended to the name listed in the
7281 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7283 struct attribute
*attr
;
7287 case DW_TAG_namespace
:
7288 case DW_TAG_typedef
:
7289 case DW_TAG_class_type
:
7290 case DW_TAG_interface_type
:
7291 case DW_TAG_structure_type
:
7292 case DW_TAG_union_type
:
7293 case DW_TAG_enumeration_type
:
7294 case DW_TAG_enumerator
:
7295 case DW_TAG_subprogram
:
7299 case DW_TAG_variable
:
7300 case DW_TAG_constant
:
7301 /* We only need to prefix "globally" visible variables. These include
7302 any variable marked with DW_AT_external or any variable that
7303 lives in a namespace. [Variables in anonymous namespaces
7304 require prefixing, but they are not DW_AT_external.] */
7306 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
7308 struct dwarf2_cu
*spec_cu
= cu
;
7310 return die_needs_namespace (die_specification (die
, &spec_cu
),
7314 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
7315 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
7316 && die
->parent
->tag
!= DW_TAG_module
)
7318 /* A variable in a lexical block of some kind does not need a
7319 namespace, even though in C++ such variables may be external
7320 and have a mangled name. */
7321 if (die
->parent
->tag
== DW_TAG_lexical_block
7322 || die
->parent
->tag
== DW_TAG_try_block
7323 || die
->parent
->tag
== DW_TAG_catch_block
7324 || die
->parent
->tag
== DW_TAG_subprogram
)
7333 /* Retrieve the last character from a mem_file. */
7336 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
7338 char *last_char_p
= (char *) object
;
7341 *last_char_p
= buffer
[length
- 1];
7344 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
7345 compute the physname for the object, which include a method's:
7346 - formal parameters (C++/Java),
7347 - receiver type (Go),
7348 - return type (Java).
7350 The term "physname" is a bit confusing.
7351 For C++, for example, it is the demangled name.
7352 For Go, for example, it's the mangled name.
7354 For Ada, return the DIE's linkage name rather than the fully qualified
7355 name. PHYSNAME is ignored..
7357 The result is allocated on the objfile_obstack and canonicalized. */
7360 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
7363 struct objfile
*objfile
= cu
->objfile
;
7366 name
= dwarf2_name (die
, cu
);
7368 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
7369 compute it by typename_concat inside GDB. */
7370 if (cu
->language
== language_ada
7371 || (cu
->language
== language_fortran
&& physname
))
7373 /* For Ada unit, we prefer the linkage name over the name, as
7374 the former contains the exported name, which the user expects
7375 to be able to reference. Ideally, we want the user to be able
7376 to reference this entity using either natural or linkage name,
7377 but we haven't started looking at this enhancement yet. */
7378 struct attribute
*attr
;
7380 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
7382 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7383 if (attr
&& DW_STRING (attr
))
7384 return DW_STRING (attr
);
7387 /* These are the only languages we know how to qualify names in. */
7389 && (cu
->language
== language_cplus
|| cu
->language
== language_java
7390 || cu
->language
== language_fortran
))
7392 if (die_needs_namespace (die
, cu
))
7396 struct ui_file
*buf
;
7398 prefix
= determine_prefix (die
, cu
);
7399 buf
= mem_fileopen ();
7400 if (*prefix
!= '\0')
7402 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
7405 fputs_unfiltered (prefixed_name
, buf
);
7406 xfree (prefixed_name
);
7409 fputs_unfiltered (name
, buf
);
7411 /* Template parameters may be specified in the DIE's DW_AT_name, or
7412 as children with DW_TAG_template_type_param or
7413 DW_TAG_value_type_param. If the latter, add them to the name
7414 here. If the name already has template parameters, then
7415 skip this step; some versions of GCC emit both, and
7416 it is more efficient to use the pre-computed name.
7418 Something to keep in mind about this process: it is very
7419 unlikely, or in some cases downright impossible, to produce
7420 something that will match the mangled name of a function.
7421 If the definition of the function has the same debug info,
7422 we should be able to match up with it anyway. But fallbacks
7423 using the minimal symbol, for instance to find a method
7424 implemented in a stripped copy of libstdc++, will not work.
7425 If we do not have debug info for the definition, we will have to
7426 match them up some other way.
7428 When we do name matching there is a related problem with function
7429 templates; two instantiated function templates are allowed to
7430 differ only by their return types, which we do not add here. */
7432 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
7434 struct attribute
*attr
;
7435 struct die_info
*child
;
7438 die
->building_fullname
= 1;
7440 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
7445 struct dwarf2_locexpr_baton
*baton
;
7448 if (child
->tag
!= DW_TAG_template_type_param
7449 && child
->tag
!= DW_TAG_template_value_param
)
7454 fputs_unfiltered ("<", buf
);
7458 fputs_unfiltered (", ", buf
);
7460 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
7463 complaint (&symfile_complaints
,
7464 _("template parameter missing DW_AT_type"));
7465 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
7468 type
= die_type (child
, cu
);
7470 if (child
->tag
== DW_TAG_template_type_param
)
7472 c_print_type (type
, "", buf
, -1, 0, &type_print_raw_options
);
7476 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
7479 complaint (&symfile_complaints
,
7480 _("template parameter missing "
7481 "DW_AT_const_value"));
7482 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
7486 dwarf2_const_value_attr (attr
, type
, name
,
7487 &cu
->comp_unit_obstack
, cu
,
7488 &value
, &bytes
, &baton
);
7490 if (TYPE_NOSIGN (type
))
7491 /* GDB prints characters as NUMBER 'CHAR'. If that's
7492 changed, this can use value_print instead. */
7493 c_printchar (value
, type
, buf
);
7496 struct value_print_options opts
;
7499 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
7503 else if (bytes
!= NULL
)
7505 v
= allocate_value (type
);
7506 memcpy (value_contents_writeable (v
), bytes
,
7507 TYPE_LENGTH (type
));
7510 v
= value_from_longest (type
, value
);
7512 /* Specify decimal so that we do not depend on
7514 get_formatted_print_options (&opts
, 'd');
7516 value_print (v
, buf
, &opts
);
7522 die
->building_fullname
= 0;
7526 /* Close the argument list, with a space if necessary
7527 (nested templates). */
7528 char last_char
= '\0';
7529 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
7530 if (last_char
== '>')
7531 fputs_unfiltered (" >", buf
);
7533 fputs_unfiltered (">", buf
);
7537 /* For Java and C++ methods, append formal parameter type
7538 information, if PHYSNAME. */
7540 if (physname
&& die
->tag
== DW_TAG_subprogram
7541 && (cu
->language
== language_cplus
7542 || cu
->language
== language_java
))
7544 struct type
*type
= read_type_die (die
, cu
);
7546 c_type_print_args (type
, buf
, 1, cu
->language
,
7547 &type_print_raw_options
);
7549 if (cu
->language
== language_java
)
7551 /* For java, we must append the return type to method
7553 if (die
->tag
== DW_TAG_subprogram
)
7554 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
7555 0, 0, &type_print_raw_options
);
7557 else if (cu
->language
== language_cplus
)
7559 /* Assume that an artificial first parameter is
7560 "this", but do not crash if it is not. RealView
7561 marks unnamed (and thus unused) parameters as
7562 artificial; there is no way to differentiate
7564 if (TYPE_NFIELDS (type
) > 0
7565 && TYPE_FIELD_ARTIFICIAL (type
, 0)
7566 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
7567 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
7569 fputs_unfiltered (" const", buf
);
7573 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
7575 ui_file_delete (buf
);
7577 if (cu
->language
== language_cplus
)
7580 = dwarf2_canonicalize_name (name
, cu
,
7581 &objfile
->objfile_obstack
);
7592 /* Return the fully qualified name of DIE, based on its DW_AT_name.
7593 If scope qualifiers are appropriate they will be added. The result
7594 will be allocated on the objfile_obstack, or NULL if the DIE does
7595 not have a name. NAME may either be from a previous call to
7596 dwarf2_name or NULL.
7598 The output string will be canonicalized (if C++/Java). */
7601 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7603 return dwarf2_compute_name (name
, die
, cu
, 0);
7606 /* Construct a physname for the given DIE in CU. NAME may either be
7607 from a previous call to dwarf2_name or NULL. The result will be
7608 allocated on the objfile_objstack or NULL if the DIE does not have a
7611 The output string will be canonicalized (if C++/Java). */
7614 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7616 struct objfile
*objfile
= cu
->objfile
;
7617 struct attribute
*attr
;
7618 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
7619 struct cleanup
*back_to
;
7622 /* In this case dwarf2_compute_name is just a shortcut not building anything
7624 if (!die_needs_namespace (die
, cu
))
7625 return dwarf2_compute_name (name
, die
, cu
, 1);
7627 back_to
= make_cleanup (null_cleanup
, NULL
);
7629 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
7631 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7633 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
7635 if (attr
&& DW_STRING (attr
))
7639 mangled
= DW_STRING (attr
);
7641 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
7642 type. It is easier for GDB users to search for such functions as
7643 `name(params)' than `long name(params)'. In such case the minimal
7644 symbol names do not match the full symbol names but for template
7645 functions there is never a need to look up their definition from their
7646 declaration so the only disadvantage remains the minimal symbol
7647 variant `long name(params)' does not have the proper inferior type.
7650 if (cu
->language
== language_go
)
7652 /* This is a lie, but we already lie to the caller new_symbol_full.
7653 new_symbol_full assumes we return the mangled name.
7654 This just undoes that lie until things are cleaned up. */
7659 demangled
= cplus_demangle (mangled
,
7660 (DMGL_PARAMS
| DMGL_ANSI
7661 | (cu
->language
== language_java
7662 ? DMGL_JAVA
| DMGL_RET_POSTFIX
7667 make_cleanup (xfree
, demangled
);
7677 if (canon
== NULL
|| check_physname
)
7679 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
7681 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
7683 /* It may not mean a bug in GDB. The compiler could also
7684 compute DW_AT_linkage_name incorrectly. But in such case
7685 GDB would need to be bug-to-bug compatible. */
7687 complaint (&symfile_complaints
,
7688 _("Computed physname <%s> does not match demangled <%s> "
7689 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
7690 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
7692 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
7693 is available here - over computed PHYSNAME. It is safer
7694 against both buggy GDB and buggy compilers. */
7708 retval
= obsavestring (retval
, strlen (retval
),
7709 &objfile
->objfile_obstack
);
7711 do_cleanups (back_to
);
7715 /* Read the import statement specified by the given die and record it. */
7718 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
7720 struct objfile
*objfile
= cu
->objfile
;
7721 struct attribute
*import_attr
;
7722 struct die_info
*imported_die
, *child_die
;
7723 struct dwarf2_cu
*imported_cu
;
7724 const char *imported_name
;
7725 const char *imported_name_prefix
;
7726 const char *canonical_name
;
7727 const char *import_alias
;
7728 const char *imported_declaration
= NULL
;
7729 const char *import_prefix
;
7730 VEC (const_char_ptr
) *excludes
= NULL
;
7731 struct cleanup
*cleanups
;
7735 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7736 if (import_attr
== NULL
)
7738 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7739 dwarf_tag_name (die
->tag
));
7744 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
7745 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7746 if (imported_name
== NULL
)
7748 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
7750 The import in the following code:
7764 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
7765 <52> DW_AT_decl_file : 1
7766 <53> DW_AT_decl_line : 6
7767 <54> DW_AT_import : <0x75>
7768 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
7770 <5b> DW_AT_decl_file : 1
7771 <5c> DW_AT_decl_line : 2
7772 <5d> DW_AT_type : <0x6e>
7774 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
7775 <76> DW_AT_byte_size : 4
7776 <77> DW_AT_encoding : 5 (signed)
7778 imports the wrong die ( 0x75 instead of 0x58 ).
7779 This case will be ignored until the gcc bug is fixed. */
7783 /* Figure out the local name after import. */
7784 import_alias
= dwarf2_name (die
, cu
);
7786 /* Figure out where the statement is being imported to. */
7787 import_prefix
= determine_prefix (die
, cu
);
7789 /* Figure out what the scope of the imported die is and prepend it
7790 to the name of the imported die. */
7791 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
7793 if (imported_die
->tag
!= DW_TAG_namespace
7794 && imported_die
->tag
!= DW_TAG_module
)
7796 imported_declaration
= imported_name
;
7797 canonical_name
= imported_name_prefix
;
7799 else if (strlen (imported_name_prefix
) > 0)
7801 temp
= alloca (strlen (imported_name_prefix
)
7802 + 2 + strlen (imported_name
) + 1);
7803 strcpy (temp
, imported_name_prefix
);
7804 strcat (temp
, "::");
7805 strcat (temp
, imported_name
);
7806 canonical_name
= temp
;
7809 canonical_name
= imported_name
;
7811 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
7813 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
7814 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7815 child_die
= sibling_die (child_die
))
7817 /* DWARF-4: A Fortran use statement with a “rename list” may be
7818 represented by an imported module entry with an import attribute
7819 referring to the module and owned entries corresponding to those
7820 entities that are renamed as part of being imported. */
7822 if (child_die
->tag
!= DW_TAG_imported_declaration
)
7824 complaint (&symfile_complaints
,
7825 _("child DW_TAG_imported_declaration expected "
7826 "- DIE at 0x%x [in module %s]"),
7827 child_die
->offset
.sect_off
, objfile
->name
);
7831 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
7832 if (import_attr
== NULL
)
7834 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7835 dwarf_tag_name (child_die
->tag
));
7840 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
7842 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7843 if (imported_name
== NULL
)
7845 complaint (&symfile_complaints
,
7846 _("child DW_TAG_imported_declaration has unknown "
7847 "imported name - DIE at 0x%x [in module %s]"),
7848 child_die
->offset
.sect_off
, objfile
->name
);
7852 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
7854 process_die (child_die
, cu
);
7857 cp_add_using_directive (import_prefix
,
7860 imported_declaration
,
7862 &objfile
->objfile_obstack
);
7864 do_cleanups (cleanups
);
7867 /* Cleanup function for handle_DW_AT_stmt_list. */
7870 free_cu_line_header (void *arg
)
7872 struct dwarf2_cu
*cu
= arg
;
7874 free_line_header (cu
->line_header
);
7875 cu
->line_header
= NULL
;
7878 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
7879 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
7880 this, it was first present in GCC release 4.3.0. */
7883 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
7885 if (!cu
->checked_producer
)
7886 check_producer (cu
);
7888 return cu
->producer_is_gcc_lt_4_3
;
7892 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
7893 char **name
, char **comp_dir
)
7895 struct attribute
*attr
;
7900 /* Find the filename. Do not use dwarf2_name here, since the filename
7901 is not a source language identifier. */
7902 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7905 *name
= DW_STRING (attr
);
7908 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
7910 *comp_dir
= DW_STRING (attr
);
7911 else if (producer_is_gcc_lt_4_3 (cu
) && *name
!= NULL
7912 && IS_ABSOLUTE_PATH (*name
))
7914 *comp_dir
= ldirname (*name
);
7915 if (*comp_dir
!= NULL
)
7916 make_cleanup (xfree
, *comp_dir
);
7918 if (*comp_dir
!= NULL
)
7920 /* Irix 6.2 native cc prepends <machine>.: to the compilation
7921 directory, get rid of it. */
7922 char *cp
= strchr (*comp_dir
, ':');
7924 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
7929 *name
= "<unknown>";
7932 /* Handle DW_AT_stmt_list for a compilation unit.
7933 DIE is the DW_TAG_compile_unit die for CU.
7934 COMP_DIR is the compilation directory.
7935 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
7938 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
7939 const char *comp_dir
)
7941 struct attribute
*attr
;
7943 gdb_assert (! cu
->per_cu
->is_debug_types
);
7945 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7948 unsigned int line_offset
= DW_UNSND (attr
);
7949 struct line_header
*line_header
7950 = dwarf_decode_line_header (line_offset
, cu
);
7954 cu
->line_header
= line_header
;
7955 make_cleanup (free_cu_line_header
, cu
);
7956 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, 1);
7961 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
7964 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7966 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7967 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7968 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
7969 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
7970 struct attribute
*attr
;
7972 char *comp_dir
= NULL
;
7973 struct die_info
*child_die
;
7974 bfd
*abfd
= objfile
->obfd
;
7977 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7979 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
7981 /* If we didn't find a lowpc, set it to highpc to avoid complaints
7982 from finish_block. */
7983 if (lowpc
== ((CORE_ADDR
) -1))
7988 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
7990 prepare_one_comp_unit (cu
, die
, cu
->language
);
7992 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
7993 standardised yet. As a workaround for the language detection we fall
7994 back to the DW_AT_producer string. */
7995 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
7996 cu
->language
= language_opencl
;
7998 /* Similar hack for Go. */
7999 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
8000 set_cu_language (DW_LANG_Go
, cu
);
8002 dwarf2_start_symtab (cu
, name
, comp_dir
, lowpc
);
8004 /* Decode line number information if present. We do this before
8005 processing child DIEs, so that the line header table is available
8006 for DW_AT_decl_file. */
8007 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
8009 /* Process all dies in compilation unit. */
8010 if (die
->child
!= NULL
)
8012 child_die
= die
->child
;
8013 while (child_die
&& child_die
->tag
)
8015 process_die (child_die
, cu
);
8016 child_die
= sibling_die (child_die
);
8020 /* Decode macro information, if present. Dwarf 2 macro information
8021 refers to information in the line number info statement program
8022 header, so we can only read it if we've read the header
8024 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
8025 if (attr
&& cu
->line_header
)
8027 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
8028 complaint (&symfile_complaints
,
8029 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
8031 dwarf_decode_macros (cu
, DW_UNSND (attr
), comp_dir
, 1);
8035 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
8036 if (attr
&& cu
->line_header
)
8038 unsigned int macro_offset
= DW_UNSND (attr
);
8040 dwarf_decode_macros (cu
, macro_offset
, comp_dir
, 0);
8044 do_cleanups (back_to
);
8047 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
8048 Create the set of symtabs used by this TU, or if this TU is sharing
8049 symtabs with another TU and the symtabs have already been created
8050 then restore those symtabs in the line header.
8051 We don't need the pc/line-number mapping for type units. */
8054 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
8056 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8057 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8058 struct type_unit_group
*tu_group
;
8060 struct line_header
*lh
;
8061 struct attribute
*attr
;
8062 unsigned int i
, line_offset
;
8064 gdb_assert (per_cu
->is_debug_types
);
8066 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
8068 /* If we're using .gdb_index (includes -readnow) then
8069 per_cu->s.type_unit_group may not have been set up yet. */
8070 if (per_cu
->s
.type_unit_group
== NULL
)
8071 per_cu
->s
.type_unit_group
= get_type_unit_group (cu
, attr
);
8072 tu_group
= per_cu
->s
.type_unit_group
;
8074 /* If we've already processed this stmt_list there's no real need to
8075 do it again, we could fake it and just recreate the part we need
8076 (file name,index -> symtab mapping). If data shows this optimization
8077 is useful we can do it then. */
8078 first_time
= tu_group
->primary_symtab
== NULL
;
8080 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
8085 line_offset
= DW_UNSND (attr
);
8086 lh
= dwarf_decode_line_header (line_offset
, cu
);
8091 dwarf2_start_symtab (cu
, "", NULL
, 0);
8094 gdb_assert (tu_group
->symtabs
== NULL
);
8097 /* Note: The primary symtab will get allocated at the end. */
8101 cu
->line_header
= lh
;
8102 make_cleanup (free_cu_line_header
, cu
);
8106 dwarf2_start_symtab (cu
, "", NULL
, 0);
8108 tu_group
->num_symtabs
= lh
->num_file_names
;
8109 tu_group
->symtabs
= XNEWVEC (struct symtab
*, lh
->num_file_names
);
8111 for (i
= 0; i
< lh
->num_file_names
; ++i
)
8114 struct file_entry
*fe
= &lh
->file_names
[i
];
8117 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8118 dwarf2_start_subfile (fe
->name
, dir
, NULL
);
8120 /* Note: We don't have to watch for the main subfile here, type units
8121 don't have DW_AT_name. */
8123 if (current_subfile
->symtab
== NULL
)
8125 /* NOTE: start_subfile will recognize when it's been passed
8126 a file it has already seen. So we can't assume there's a
8127 simple mapping from lh->file_names to subfiles,
8128 lh->file_names may contain dups. */
8129 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
8133 fe
->symtab
= current_subfile
->symtab
;
8134 tu_group
->symtabs
[i
] = fe
->symtab
;
8141 for (i
= 0; i
< lh
->num_file_names
; ++i
)
8143 struct file_entry
*fe
= &lh
->file_names
[i
];
8145 fe
->symtab
= tu_group
->symtabs
[i
];
8149 /* The main symtab is allocated last. Type units don't have DW_AT_name
8150 so they don't have a "real" (so to speak) symtab anyway.
8151 There is later code that will assign the main symtab to all symbols
8152 that don't have one. We need to handle the case of a symbol with a
8153 missing symtab (DW_AT_decl_file) anyway. */
8156 /* Process DW_TAG_type_unit.
8157 For TUs we want to skip the first top level sibling if it's not the
8158 actual type being defined by this TU. In this case the first top
8159 level sibling is there to provide context only. */
8162 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8164 struct die_info
*child_die
;
8166 prepare_one_comp_unit (cu
, die
, language_minimal
);
8168 /* Initialize (or reinitialize) the machinery for building symtabs.
8169 We do this before processing child DIEs, so that the line header table
8170 is available for DW_AT_decl_file. */
8171 setup_type_unit_groups (die
, cu
);
8173 if (die
->child
!= NULL
)
8175 child_die
= die
->child
;
8176 while (child_die
&& child_die
->tag
)
8178 process_die (child_die
, cu
);
8179 child_die
= sibling_die (child_die
);
8186 http://gcc.gnu.org/wiki/DebugFission
8187 http://gcc.gnu.org/wiki/DebugFissionDWP
8189 To simplify handling of both DWO files ("object" files with the DWARF info)
8190 and DWP files (a file with the DWOs packaged up into one file), we treat
8191 DWP files as having a collection of virtual DWO files. */
8194 hash_dwo_file (const void *item
)
8196 const struct dwo_file
*dwo_file
= item
;
8198 return htab_hash_string (dwo_file
->name
);
8202 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
8204 const struct dwo_file
*lhs
= item_lhs
;
8205 const struct dwo_file
*rhs
= item_rhs
;
8207 return strcmp (lhs
->name
, rhs
->name
) == 0;
8210 /* Allocate a hash table for DWO files. */
8213 allocate_dwo_file_hash_table (void)
8215 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8217 return htab_create_alloc_ex (41,
8221 &objfile
->objfile_obstack
,
8222 hashtab_obstack_allocate
,
8223 dummy_obstack_deallocate
);
8226 /* Lookup DWO file DWO_NAME. */
8229 lookup_dwo_file_slot (const char *dwo_name
)
8231 struct dwo_file find_entry
;
8234 if (dwarf2_per_objfile
->dwo_files
== NULL
)
8235 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
8237 memset (&find_entry
, 0, sizeof (find_entry
));
8238 find_entry
.name
= dwo_name
;
8239 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
8245 hash_dwo_unit (const void *item
)
8247 const struct dwo_unit
*dwo_unit
= item
;
8249 /* This drops the top 32 bits of the id, but is ok for a hash. */
8250 return dwo_unit
->signature
;
8254 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
8256 const struct dwo_unit
*lhs
= item_lhs
;
8257 const struct dwo_unit
*rhs
= item_rhs
;
8259 /* The signature is assumed to be unique within the DWO file.
8260 So while object file CU dwo_id's always have the value zero,
8261 that's OK, assuming each object file DWO file has only one CU,
8262 and that's the rule for now. */
8263 return lhs
->signature
== rhs
->signature
;
8266 /* Allocate a hash table for DWO CUs,TUs.
8267 There is one of these tables for each of CUs,TUs for each DWO file. */
8270 allocate_dwo_unit_table (struct objfile
*objfile
)
8272 /* Start out with a pretty small number.
8273 Generally DWO files contain only one CU and maybe some TUs. */
8274 return htab_create_alloc_ex (3,
8278 &objfile
->objfile_obstack
,
8279 hashtab_obstack_allocate
,
8280 dummy_obstack_deallocate
);
8283 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
8285 struct create_dwo_info_table_data
8287 struct dwo_file
*dwo_file
;
8291 /* die_reader_func for create_dwo_debug_info_hash_table. */
8294 create_dwo_debug_info_hash_table_reader (const struct die_reader_specs
*reader
,
8296 struct die_info
*comp_unit_die
,
8300 struct dwarf2_cu
*cu
= reader
->cu
;
8301 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8302 sect_offset offset
= cu
->per_cu
->offset
;
8303 struct dwarf2_section_info
*section
= cu
->per_cu
->info_or_types_section
;
8304 struct create_dwo_info_table_data
*data
= datap
;
8305 struct dwo_file
*dwo_file
= data
->dwo_file
;
8306 htab_t cu_htab
= data
->cu_htab
;
8308 struct attribute
*attr
;
8309 struct dwo_unit
*dwo_unit
;
8311 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
8314 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
8315 " its dwo_id [in module %s]"),
8316 offset
.sect_off
, dwo_file
->name
);
8320 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
8321 dwo_unit
->dwo_file
= dwo_file
;
8322 dwo_unit
->signature
= DW_UNSND (attr
);
8323 dwo_unit
->info_or_types_section
= section
;
8324 dwo_unit
->offset
= offset
;
8325 dwo_unit
->length
= cu
->per_cu
->length
;
8327 slot
= htab_find_slot (cu_htab
, dwo_unit
, INSERT
);
8328 gdb_assert (slot
!= NULL
);
8331 const struct dwo_unit
*dup_dwo_unit
= *slot
;
8333 complaint (&symfile_complaints
,
8334 _("debug entry at offset 0x%x is duplicate to the entry at"
8335 " offset 0x%x, dwo_id 0x%s [in module %s]"),
8336 offset
.sect_off
, dup_dwo_unit
->offset
.sect_off
,
8337 phex (dwo_unit
->signature
, sizeof (dwo_unit
->signature
)),
8343 if (dwarf2_read_debug
)
8344 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id 0x%s\n",
8346 phex (dwo_unit
->signature
,
8347 sizeof (dwo_unit
->signature
)));
8350 /* Create a hash table to map DWO IDs to their CU entry in
8351 .debug_info.dwo in DWO_FILE.
8352 Note: This function processes DWO files only, not DWP files. */
8355 create_dwo_debug_info_hash_table (struct dwo_file
*dwo_file
)
8357 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8358 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
8361 gdb_byte
*info_ptr
, *end_ptr
;
8362 struct create_dwo_info_table_data create_dwo_info_table_data
;
8364 dwarf2_read_section (objfile
, section
);
8365 info_ptr
= section
->buffer
;
8367 if (info_ptr
== NULL
)
8370 /* We can't set abfd until now because the section may be empty or
8371 not present, in which case section->asection will be NULL. */
8372 abfd
= section
->asection
->owner
;
8374 if (dwarf2_read_debug
)
8375 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_info.dwo for %s:\n",
8376 bfd_get_filename (abfd
));
8378 cu_htab
= allocate_dwo_unit_table (objfile
);
8380 create_dwo_info_table_data
.dwo_file
= dwo_file
;
8381 create_dwo_info_table_data
.cu_htab
= cu_htab
;
8383 end_ptr
= info_ptr
+ section
->size
;
8384 while (info_ptr
< end_ptr
)
8386 struct dwarf2_per_cu_data per_cu
;
8388 memset (&per_cu
, 0, sizeof (per_cu
));
8389 per_cu
.objfile
= objfile
;
8390 per_cu
.is_debug_types
= 0;
8391 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
8392 per_cu
.info_or_types_section
= section
;
8394 init_cutu_and_read_dies_no_follow (&per_cu
,
8395 &dwo_file
->sections
.abbrev
,
8397 create_dwo_debug_info_hash_table_reader
,
8398 &create_dwo_info_table_data
);
8400 info_ptr
+= per_cu
.length
;
8406 /* DWP file .debug_{cu,tu}_index section format:
8407 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
8409 Both index sections have the same format, and serve to map a 64-bit
8410 signature to a set of section numbers. Each section begins with a header,
8411 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
8412 indexes, and a pool of 32-bit section numbers. The index sections will be
8413 aligned at 8-byte boundaries in the file.
8415 The index section header contains two unsigned 32-bit values (using the
8416 byte order of the application binary):
8418 N, the number of compilation units or type units in the index
8419 M, the number of slots in the hash table
8421 (We assume that N and M will not exceed 2^32 - 1.)
8423 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
8425 The hash table begins at offset 8 in the section, and consists of an array
8426 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
8427 order of the application binary). Unused slots in the hash table are 0.
8428 (We rely on the extreme unlikeliness of a signature being exactly 0.)
8430 The parallel table begins immediately after the hash table
8431 (at offset 8 + 8 * M from the beginning of the section), and consists of an
8432 array of 32-bit indexes (using the byte order of the application binary),
8433 corresponding 1-1 with slots in the hash table. Each entry in the parallel
8434 table contains a 32-bit index into the pool of section numbers. For unused
8435 hash table slots, the corresponding entry in the parallel table will be 0.
8437 Given a 64-bit compilation unit signature or a type signature S, an entry
8438 in the hash table is located as follows:
8440 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
8441 the low-order k bits all set to 1.
8443 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
8445 3) If the hash table entry at index H matches the signature, use that
8446 entry. If the hash table entry at index H is unused (all zeroes),
8447 terminate the search: the signature is not present in the table.
8449 4) Let H = (H + H') modulo M. Repeat at Step 3.
8451 Because M > N and H' and M are relatively prime, the search is guaranteed
8452 to stop at an unused slot or find the match.
8454 The pool of section numbers begins immediately following the hash table
8455 (at offset 8 + 12 * M from the beginning of the section). The pool of
8456 section numbers consists of an array of 32-bit words (using the byte order
8457 of the application binary). Each item in the array is indexed starting
8458 from 0. The hash table entry provides the index of the first section
8459 number in the set. Additional section numbers in the set follow, and the
8460 set is terminated by a 0 entry (section number 0 is not used in ELF).
8462 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
8463 section must be the first entry in the set, and the .debug_abbrev.dwo must
8464 be the second entry. Other members of the set may follow in any order. */
8466 /* Create a hash table to map DWO IDs to their CU/TU entry in
8467 .debug_{info,types}.dwo in DWP_FILE.
8468 Returns NULL if there isn't one.
8469 Note: This function processes DWP files only, not DWO files. */
8471 static struct dwp_hash_table
*
8472 create_dwp_hash_table (struct dwp_file
*dwp_file
, int is_debug_types
)
8474 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8475 bfd
*dbfd
= dwp_file
->dbfd
;
8476 char *index_ptr
, *index_end
;
8477 struct dwarf2_section_info
*index
;
8478 uint32_t version
, nr_units
, nr_slots
;
8479 struct dwp_hash_table
*htab
;
8482 index
= &dwp_file
->sections
.tu_index
;
8484 index
= &dwp_file
->sections
.cu_index
;
8486 if (dwarf2_section_empty_p (index
))
8488 dwarf2_read_section (objfile
, index
);
8490 index_ptr
= index
->buffer
;
8491 index_end
= index_ptr
+ index
->size
;
8493 version
= read_4_bytes (dbfd
, index_ptr
);
8494 index_ptr
+= 8; /* Skip the unused word. */
8495 nr_units
= read_4_bytes (dbfd
, index_ptr
);
8497 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
8502 error (_("Dwarf Error: unsupported DWP file version (%u)"
8504 version
, dwp_file
->name
);
8506 if (nr_slots
!= (nr_slots
& -nr_slots
))
8508 error (_("Dwarf Error: number of slots in DWP hash table (%u)"
8509 " is not power of 2 [in module %s]"),
8510 nr_slots
, dwp_file
->name
);
8513 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
8514 htab
->nr_units
= nr_units
;
8515 htab
->nr_slots
= nr_slots
;
8516 htab
->hash_table
= index_ptr
;
8517 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
8518 htab
->section_pool
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
8523 /* Update SECTIONS with the data from SECTP.
8525 This function is like the other "locate" section routines that are
8526 passed to bfd_map_over_sections, but in this context the sections to
8527 read comes from the DWP hash table, not the full ELF section table.
8529 The result is non-zero for success, or zero if an error was found. */
8532 locate_virtual_dwo_sections (asection
*sectp
,
8533 struct virtual_dwo_sections
*sections
)
8535 const struct dwop_section_names
*names
= &dwop_section_names
;
8537 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
8539 /* There can be only one. */
8540 if (sections
->abbrev
.asection
!= NULL
)
8542 sections
->abbrev
.asection
= sectp
;
8543 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
8545 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
8546 || section_is_p (sectp
->name
, &names
->types_dwo
))
8548 /* There can be only one. */
8549 if (sections
->info_or_types
.asection
!= NULL
)
8551 sections
->info_or_types
.asection
= sectp
;
8552 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
8554 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
8556 /* There can be only one. */
8557 if (sections
->line
.asection
!= NULL
)
8559 sections
->line
.asection
= sectp
;
8560 sections
->line
.size
= bfd_get_section_size (sectp
);
8562 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
8564 /* There can be only one. */
8565 if (sections
->loc
.asection
!= NULL
)
8567 sections
->loc
.asection
= sectp
;
8568 sections
->loc
.size
= bfd_get_section_size (sectp
);
8570 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
8572 /* There can be only one. */
8573 if (sections
->macinfo
.asection
!= NULL
)
8575 sections
->macinfo
.asection
= sectp
;
8576 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
8578 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
8580 /* There can be only one. */
8581 if (sections
->macro
.asection
!= NULL
)
8583 sections
->macro
.asection
= sectp
;
8584 sections
->macro
.size
= bfd_get_section_size (sectp
);
8586 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
8588 /* There can be only one. */
8589 if (sections
->str_offsets
.asection
!= NULL
)
8591 sections
->str_offsets
.asection
= sectp
;
8592 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
8596 /* No other kind of section is valid. */
8603 /* Create a dwo_unit object for the DWO with signature SIGNATURE.
8604 HTAB is the hash table from the DWP file.
8605 SECTION_INDEX is the index of the DWO in HTAB. */
8607 static struct dwo_unit
*
8608 create_dwo_in_dwp (struct dwp_file
*dwp_file
,
8609 const struct dwp_hash_table
*htab
,
8610 uint32_t section_index
,
8611 ULONGEST signature
, int is_debug_types
)
8613 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8614 bfd
*dbfd
= dwp_file
->dbfd
;
8615 const char *kind
= is_debug_types
? "TU" : "CU";
8616 struct dwo_file
*dwo_file
;
8617 struct dwo_unit
*dwo_unit
;
8618 struct virtual_dwo_sections sections
;
8619 void **dwo_file_slot
;
8620 char *virtual_dwo_name
;
8621 struct dwarf2_section_info
*cutu
;
8622 struct cleanup
*cleanups
;
8625 if (dwarf2_read_debug
)
8627 fprintf_unfiltered (gdb_stdlog
, "Reading %s %u/0x%s in DWP file: %s\n",
8629 section_index
, phex (signature
, sizeof (signature
)),
8633 /* Fetch the sections of this DWO.
8634 Put a limit on the number of sections we look for so that bad data
8635 doesn't cause us to loop forever. */
8637 #define MAX_NR_DWO_SECTIONS \
8638 (1 /* .debug_info or .debug_types */ \
8639 + 1 /* .debug_abbrev */ \
8640 + 1 /* .debug_line */ \
8641 + 1 /* .debug_loc */ \
8642 + 1 /* .debug_str_offsets */ \
8643 + 1 /* .debug_macro */ \
8644 + 1 /* .debug_macinfo */ \
8645 + 1 /* trailing zero */)
8647 memset (§ions
, 0, sizeof (sections
));
8648 cleanups
= make_cleanup (null_cleanup
, 0);
8650 for (i
= 0; i
< MAX_NR_DWO_SECTIONS
; ++i
)
8653 uint32_t section_nr
=
8656 + (section_index
+ i
) * sizeof (uint32_t));
8658 if (section_nr
== 0)
8660 if (section_nr
>= dwp_file
->num_sections
)
8662 error (_("Dwarf Error: bad DWP hash table, section number too large"
8667 sectp
= dwp_file
->elf_sections
[section_nr
];
8668 if (! locate_virtual_dwo_sections (sectp
, §ions
))
8670 error (_("Dwarf Error: bad DWP hash table, invalid section found"
8677 || sections
.info_or_types
.asection
== NULL
8678 || sections
.abbrev
.asection
== NULL
)
8680 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
8684 if (i
== MAX_NR_DWO_SECTIONS
)
8686 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
8691 /* It's easier for the rest of the code if we fake a struct dwo_file and
8692 have dwo_unit "live" in that. At least for now.
8694 The DWP file can be made up of a random collection of CUs and TUs.
8695 However, for each CU + set of TUs that came from the same original DWO
8696 file, we want to combine them back into a virtual DWO file to save space
8697 (fewer struct dwo_file objects to allocated). Remember that for really
8698 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
8701 xstrprintf ("virtual-dwo/%d-%d-%d-%d",
8702 sections
.abbrev
.asection
? sections
.abbrev
.asection
->id
: 0,
8703 sections
.line
.asection
? sections
.line
.asection
->id
: 0,
8704 sections
.loc
.asection
? sections
.loc
.asection
->id
: 0,
8705 (sections
.str_offsets
.asection
8706 ? sections
.str_offsets
.asection
->id
8708 make_cleanup (xfree
, virtual_dwo_name
);
8709 /* Can we use an existing virtual DWO file? */
8710 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
);
8711 /* Create one if necessary. */
8712 if (*dwo_file_slot
== NULL
)
8714 if (dwarf2_read_debug
)
8716 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
8719 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
8720 dwo_file
->name
= obstack_copy0 (&objfile
->objfile_obstack
,
8722 strlen (virtual_dwo_name
));
8723 dwo_file
->sections
.abbrev
= sections
.abbrev
;
8724 dwo_file
->sections
.line
= sections
.line
;
8725 dwo_file
->sections
.loc
= sections
.loc
;
8726 dwo_file
->sections
.macinfo
= sections
.macinfo
;
8727 dwo_file
->sections
.macro
= sections
.macro
;
8728 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
8729 /* The "str" section is global to the entire DWP file. */
8730 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
8731 /* The info or types section is assigned later to dwo_unit,
8732 there's no need to record it in dwo_file.
8733 Also, we can't simply record type sections in dwo_file because
8734 we record a pointer into the vector in dwo_unit. As we collect more
8735 types we'll grow the vector and eventually have to reallocate space
8736 for it, invalidating all the pointers into the current copy. */
8737 *dwo_file_slot
= dwo_file
;
8741 if (dwarf2_read_debug
)
8743 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
8746 dwo_file
= *dwo_file_slot
;
8748 do_cleanups (cleanups
);
8750 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
8751 dwo_unit
->dwo_file
= dwo_file
;
8752 dwo_unit
->signature
= signature
;
8753 dwo_unit
->info_or_types_section
=
8754 obstack_alloc (&objfile
->objfile_obstack
,
8755 sizeof (struct dwarf2_section_info
));
8756 *dwo_unit
->info_or_types_section
= sections
.info_or_types
;
8757 /* offset, length, type_offset_in_tu are set later. */
8762 /* Lookup the DWO with SIGNATURE in DWP_FILE. */
8764 static struct dwo_unit
*
8765 lookup_dwo_in_dwp (struct dwp_file
*dwp_file
,
8766 const struct dwp_hash_table
*htab
,
8767 ULONGEST signature
, int is_debug_types
)
8769 bfd
*dbfd
= dwp_file
->dbfd
;
8770 uint32_t mask
= htab
->nr_slots
- 1;
8771 uint32_t hash
= signature
& mask
;
8772 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
8775 struct dwo_unit find_dwo_cu
, *dwo_cu
;
8777 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
8778 find_dwo_cu
.signature
= signature
;
8779 slot
= htab_find_slot (dwp_file
->loaded_cutus
, &find_dwo_cu
, INSERT
);
8784 /* Use a for loop so that we don't loop forever on bad debug info. */
8785 for (i
= 0; i
< htab
->nr_slots
; ++i
)
8787 ULONGEST signature_in_table
;
8789 signature_in_table
=
8790 read_8_bytes (dbfd
, htab
->hash_table
+ hash
* sizeof (uint64_t));
8791 if (signature_in_table
== signature
)
8793 uint32_t section_index
=
8794 read_4_bytes (dbfd
, htab
->unit_table
+ hash
* sizeof (uint32_t));
8796 *slot
= create_dwo_in_dwp (dwp_file
, htab
, section_index
,
8797 signature
, is_debug_types
);
8800 if (signature_in_table
== 0)
8802 hash
= (hash
+ hash2
) & mask
;
8805 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
8810 /* Subroutine of open_dwop_file to simplify it.
8811 Open the file specified by FILE_NAME and hand it off to BFD for
8812 preliminary analysis. Return a newly initialized bfd *, which
8813 includes a canonicalized copy of FILE_NAME.
8814 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
8815 In case of trouble, return NULL.
8816 NOTE: This function is derived from symfile_bfd_open. */
8819 try_open_dwop_file (const char *file_name
, int is_dwp
)
8823 char *absolute_name
;
8825 flags
= OPF_TRY_CWD_FIRST
;
8827 flags
|= OPF_SEARCH_IN_PATH
;
8828 desc
= openp (debug_file_directory
, flags
, file_name
,
8829 O_RDONLY
| O_BINARY
, &absolute_name
);
8833 sym_bfd
= gdb_bfd_open (absolute_name
, gnutarget
, desc
);
8836 xfree (absolute_name
);
8839 xfree (absolute_name
);
8840 bfd_set_cacheable (sym_bfd
, 1);
8842 if (!bfd_check_format (sym_bfd
, bfd_object
))
8844 gdb_bfd_unref (sym_bfd
); /* This also closes desc. */
8851 /* Try to open DWO/DWP file FILE_NAME.
8852 COMP_DIR is the DW_AT_comp_dir attribute.
8853 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
8854 The result is the bfd handle of the file.
8855 If there is a problem finding or opening the file, return NULL.
8856 Upon success, the canonicalized path of the file is stored in the bfd,
8857 same as symfile_bfd_open. */
8860 open_dwop_file (const char *file_name
, const char *comp_dir
, int is_dwp
)
8864 if (IS_ABSOLUTE_PATH (file_name
))
8865 return try_open_dwop_file (file_name
, is_dwp
);
8867 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
8869 if (comp_dir
!= NULL
)
8871 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, file_name
, NULL
);
8873 /* NOTE: If comp_dir is a relative path, this will also try the
8874 search path, which seems useful. */
8875 abfd
= try_open_dwop_file (path_to_try
, is_dwp
);
8876 xfree (path_to_try
);
8881 /* That didn't work, try debug-file-directory, which, despite its name,
8882 is a list of paths. */
8884 if (*debug_file_directory
== '\0')
8887 return try_open_dwop_file (file_name
, is_dwp
);
8890 /* This function is mapped across the sections and remembers the offset and
8891 size of each of the DWO debugging sections we are interested in. */
8894 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
8896 struct dwo_sections
*dwo_sections
= dwo_sections_ptr
;
8897 const struct dwop_section_names
*names
= &dwop_section_names
;
8899 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
8901 dwo_sections
->abbrev
.asection
= sectp
;
8902 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
8904 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
8906 dwo_sections
->info
.asection
= sectp
;
8907 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
8909 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
8911 dwo_sections
->line
.asection
= sectp
;
8912 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
8914 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
8916 dwo_sections
->loc
.asection
= sectp
;
8917 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
8919 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
8921 dwo_sections
->macinfo
.asection
= sectp
;
8922 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
8924 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
8926 dwo_sections
->macro
.asection
= sectp
;
8927 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
8929 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
8931 dwo_sections
->str
.asection
= sectp
;
8932 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
8934 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
8936 dwo_sections
->str_offsets
.asection
= sectp
;
8937 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
8939 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
8941 struct dwarf2_section_info type_section
;
8943 memset (&type_section
, 0, sizeof (type_section
));
8944 type_section
.asection
= sectp
;
8945 type_section
.size
= bfd_get_section_size (sectp
);
8946 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
8951 /* Initialize the use of the DWO file specified by DWO_NAME.
8952 The result is NULL if DWO_NAME can't be found. */
8954 static struct dwo_file
*
8955 open_and_init_dwo_file (const char *dwo_name
, const char *comp_dir
)
8957 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8958 struct dwo_file
*dwo_file
;
8960 struct cleanup
*cleanups
;
8962 dbfd
= open_dwop_file (dwo_name
, comp_dir
, 0);
8965 if (dwarf2_read_debug
)
8966 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
8969 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
8970 dwo_file
->name
= obstack_copy0 (&objfile
->objfile_obstack
,
8971 dwo_name
, strlen (dwo_name
));
8972 dwo_file
->dbfd
= dbfd
;
8974 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
8976 bfd_map_over_sections (dbfd
, dwarf2_locate_dwo_sections
, &dwo_file
->sections
);
8978 dwo_file
->cus
= create_dwo_debug_info_hash_table (dwo_file
);
8980 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
8981 dwo_file
->sections
.types
);
8983 discard_cleanups (cleanups
);
8985 if (dwarf2_read_debug
)
8986 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
8991 /* This function is mapped across the sections and remembers the offset and
8992 size of each of the DWP debugging sections we are interested in. */
8995 dwarf2_locate_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
8997 struct dwp_file
*dwp_file
= dwp_file_ptr
;
8998 const struct dwop_section_names
*names
= &dwop_section_names
;
8999 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
9001 /* Record the ELF section number for later lookup: this is what the
9002 .debug_cu_index,.debug_tu_index tables use. */
9003 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
9004 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
9006 /* Look for specific sections that we need. */
9007 if (section_is_p (sectp
->name
, &names
->str_dwo
))
9009 dwp_file
->sections
.str
.asection
= sectp
;
9010 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
9012 else if (section_is_p (sectp
->name
, &names
->cu_index
))
9014 dwp_file
->sections
.cu_index
.asection
= sectp
;
9015 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
9017 else if (section_is_p (sectp
->name
, &names
->tu_index
))
9019 dwp_file
->sections
.tu_index
.asection
= sectp
;
9020 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
9024 /* Hash function for dwp_file loaded CUs/TUs. */
9027 hash_dwp_loaded_cutus (const void *item
)
9029 const struct dwo_unit
*dwo_unit
= item
;
9031 /* This drops the top 32 bits of the signature, but is ok for a hash. */
9032 return dwo_unit
->signature
;
9035 /* Equality function for dwp_file loaded CUs/TUs. */
9038 eq_dwp_loaded_cutus (const void *a
, const void *b
)
9040 const struct dwo_unit
*dua
= a
;
9041 const struct dwo_unit
*dub
= b
;
9043 return dua
->signature
== dub
->signature
;
9046 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
9049 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
9051 return htab_create_alloc_ex (3,
9052 hash_dwp_loaded_cutus
,
9053 eq_dwp_loaded_cutus
,
9055 &objfile
->objfile_obstack
,
9056 hashtab_obstack_allocate
,
9057 dummy_obstack_deallocate
);
9060 /* Initialize the use of the DWP file for the current objfile.
9061 By convention the name of the DWP file is ${objfile}.dwp.
9062 The result is NULL if it can't be found. */
9064 static struct dwp_file
*
9065 open_and_init_dwp_file (const char *comp_dir
)
9067 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9068 struct dwp_file
*dwp_file
;
9071 struct cleanup
*cleanups
;
9073 dwp_name
= xstrprintf ("%s.dwp", dwarf2_per_objfile
->objfile
->name
);
9074 cleanups
= make_cleanup (xfree
, dwp_name
);
9076 dbfd
= open_dwop_file (dwp_name
, comp_dir
, 1);
9079 if (dwarf2_read_debug
)
9080 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
);
9081 do_cleanups (cleanups
);
9084 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
9085 dwp_file
->name
= obstack_copy0 (&objfile
->objfile_obstack
,
9086 dwp_name
, strlen (dwp_name
));
9087 dwp_file
->dbfd
= dbfd
;
9088 do_cleanups (cleanups
);
9090 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwp_file
);
9092 /* +1: section 0 is unused */
9093 dwp_file
->num_sections
= bfd_count_sections (dbfd
) + 1;
9094 dwp_file
->elf_sections
=
9095 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
9096 dwp_file
->num_sections
, asection
*);
9098 bfd_map_over_sections (dbfd
, dwarf2_locate_dwp_sections
, dwp_file
);
9100 dwp_file
->cus
= create_dwp_hash_table (dwp_file
, 0);
9102 dwp_file
->tus
= create_dwp_hash_table (dwp_file
, 1);
9104 dwp_file
->loaded_cutus
= allocate_dwp_loaded_cutus_table (objfile
);
9106 discard_cleanups (cleanups
);
9108 if (dwarf2_read_debug
)
9110 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
9111 fprintf_unfiltered (gdb_stdlog
,
9112 " %u CUs, %u TUs\n",
9113 dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0,
9114 dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0);
9120 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
9121 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
9122 or in the DWP file for the objfile, referenced by THIS_UNIT.
9123 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
9124 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
9126 This is called, for example, when wanting to read a variable with a
9127 complex location. Therefore we don't want to do file i/o for every call.
9128 Therefore we don't want to look for a DWO file on every call.
9129 Therefore we first see if we've already seen SIGNATURE in a DWP file,
9130 then we check if we've already seen DWO_NAME, and only THEN do we check
9133 The result is a pointer to the dwo_unit object or NULL if we didn't find it
9134 (dwo_id mismatch or couldn't find the DWO/DWP file). */
9136 static struct dwo_unit
*
9137 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
9138 const char *dwo_name
, const char *comp_dir
,
9139 ULONGEST signature
, int is_debug_types
)
9141 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9142 const char *kind
= is_debug_types
? "TU" : "CU";
9143 void **dwo_file_slot
;
9144 struct dwo_file
*dwo_file
;
9145 struct dwp_file
*dwp_file
;
9147 /* Have we already read SIGNATURE from a DWP file? */
9149 if (! dwarf2_per_objfile
->dwp_checked
)
9151 dwarf2_per_objfile
->dwp_file
= open_and_init_dwp_file (comp_dir
);
9152 dwarf2_per_objfile
->dwp_checked
= 1;
9154 dwp_file
= dwarf2_per_objfile
->dwp_file
;
9156 if (dwp_file
!= NULL
)
9158 const struct dwp_hash_table
*dwp_htab
=
9159 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
9161 if (dwp_htab
!= NULL
)
9163 struct dwo_unit
*dwo_cutu
=
9164 lookup_dwo_in_dwp (dwp_file
, dwp_htab
, signature
, is_debug_types
);
9166 if (dwo_cutu
!= NULL
)
9168 if (dwarf2_read_debug
)
9170 fprintf_unfiltered (gdb_stdlog
,
9171 "Virtual DWO %s %s found: @%s\n",
9172 kind
, hex_string (signature
),
9173 host_address_to_string (dwo_cutu
));
9180 /* Have we already seen DWO_NAME? */
9182 dwo_file_slot
= lookup_dwo_file_slot (dwo_name
);
9183 if (*dwo_file_slot
== NULL
)
9185 /* Read in the file and build a table of the DWOs it contains. */
9186 *dwo_file_slot
= open_and_init_dwo_file (dwo_name
, comp_dir
);
9188 /* NOTE: This will be NULL if unable to open the file. */
9189 dwo_file
= *dwo_file_slot
;
9191 if (dwo_file
!= NULL
)
9193 htab_t htab
= is_debug_types
? dwo_file
->tus
: dwo_file
->cus
;
9197 struct dwo_unit find_dwo_cutu
, *dwo_cutu
;
9199 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
9200 find_dwo_cutu
.signature
= signature
;
9201 dwo_cutu
= htab_find (htab
, &find_dwo_cutu
);
9203 if (dwo_cutu
!= NULL
)
9205 if (dwarf2_read_debug
)
9207 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
9208 kind
, dwo_name
, hex_string (signature
),
9209 host_address_to_string (dwo_cutu
));
9216 /* We didn't find it. This could mean a dwo_id mismatch, or
9217 someone deleted the DWO/DWP file, or the search path isn't set up
9218 correctly to find the file. */
9220 if (dwarf2_read_debug
)
9222 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
9223 kind
, dwo_name
, hex_string (signature
));
9226 complaint (&symfile_complaints
,
9227 _("Could not find DWO CU referenced by CU at offset 0x%x"
9229 this_unit
->offset
.sect_off
, objfile
->name
);
9233 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
9234 See lookup_dwo_cutu_unit for details. */
9236 static struct dwo_unit
*
9237 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9238 const char *dwo_name
, const char *comp_dir
,
9241 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
9244 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
9245 See lookup_dwo_cutu_unit for details. */
9247 static struct dwo_unit
*
9248 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
9249 const char *dwo_name
, const char *comp_dir
)
9251 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
9254 /* Free all resources associated with DWO_FILE.
9255 Close the DWO file and munmap the sections.
9256 All memory should be on the objfile obstack. */
9259 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
9262 struct dwarf2_section_info
*section
;
9264 gdb_assert (dwo_file
->dbfd
!= objfile
->obfd
);
9265 gdb_bfd_unref (dwo_file
->dbfd
);
9267 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
9270 /* Wrapper for free_dwo_file for use in cleanups. */
9273 free_dwo_file_cleanup (void *arg
)
9275 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
9276 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9278 free_dwo_file (dwo_file
, objfile
);
9281 /* Traversal function for free_dwo_files. */
9284 free_dwo_file_from_slot (void **slot
, void *info
)
9286 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
9287 struct objfile
*objfile
= (struct objfile
*) info
;
9289 free_dwo_file (dwo_file
, objfile
);
9294 /* Free all resources associated with DWO_FILES. */
9297 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
9299 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
9302 /* Read in various DIEs. */
9304 /* qsort helper for inherit_abstract_dies. */
9307 unsigned_int_compar (const void *ap
, const void *bp
)
9309 unsigned int a
= *(unsigned int *) ap
;
9310 unsigned int b
= *(unsigned int *) bp
;
9312 return (a
> b
) - (b
> a
);
9315 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
9316 Inherit only the children of the DW_AT_abstract_origin DIE not being
9317 already referenced by DW_AT_abstract_origin from the children of the
9321 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
9323 struct die_info
*child_die
;
9324 unsigned die_children_count
;
9325 /* CU offsets which were referenced by children of the current DIE. */
9326 sect_offset
*offsets
;
9327 sect_offset
*offsets_end
, *offsetp
;
9328 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
9329 struct die_info
*origin_die
;
9330 /* Iterator of the ORIGIN_DIE children. */
9331 struct die_info
*origin_child_die
;
9332 struct cleanup
*cleanups
;
9333 struct attribute
*attr
;
9334 struct dwarf2_cu
*origin_cu
;
9335 struct pending
**origin_previous_list_in_scope
;
9337 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
9341 /* Note that following die references may follow to a die in a
9345 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
9347 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
9349 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
9350 origin_cu
->list_in_scope
= cu
->list_in_scope
;
9352 if (die
->tag
!= origin_die
->tag
9353 && !(die
->tag
== DW_TAG_inlined_subroutine
9354 && origin_die
->tag
== DW_TAG_subprogram
))
9355 complaint (&symfile_complaints
,
9356 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
9357 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
9359 child_die
= die
->child
;
9360 die_children_count
= 0;
9361 while (child_die
&& child_die
->tag
)
9363 child_die
= sibling_die (child_die
);
9364 die_children_count
++;
9366 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
9367 cleanups
= make_cleanup (xfree
, offsets
);
9369 offsets_end
= offsets
;
9370 child_die
= die
->child
;
9371 while (child_die
&& child_die
->tag
)
9373 /* For each CHILD_DIE, find the corresponding child of
9374 ORIGIN_DIE. If there is more than one layer of
9375 DW_AT_abstract_origin, follow them all; there shouldn't be,
9376 but GCC versions at least through 4.4 generate this (GCC PR
9378 struct die_info
*child_origin_die
= child_die
;
9379 struct dwarf2_cu
*child_origin_cu
= cu
;
9383 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
9387 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
9391 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
9392 counterpart may exist. */
9393 if (child_origin_die
!= child_die
)
9395 if (child_die
->tag
!= child_origin_die
->tag
9396 && !(child_die
->tag
== DW_TAG_inlined_subroutine
9397 && child_origin_die
->tag
== DW_TAG_subprogram
))
9398 complaint (&symfile_complaints
,
9399 _("Child DIE 0x%x and its abstract origin 0x%x have "
9400 "different tags"), child_die
->offset
.sect_off
,
9401 child_origin_die
->offset
.sect_off
);
9402 if (child_origin_die
->parent
!= origin_die
)
9403 complaint (&symfile_complaints
,
9404 _("Child DIE 0x%x and its abstract origin 0x%x have "
9405 "different parents"), child_die
->offset
.sect_off
,
9406 child_origin_die
->offset
.sect_off
);
9408 *offsets_end
++ = child_origin_die
->offset
;
9410 child_die
= sibling_die (child_die
);
9412 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
9413 unsigned_int_compar
);
9414 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
9415 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
9416 complaint (&symfile_complaints
,
9417 _("Multiple children of DIE 0x%x refer "
9418 "to DIE 0x%x as their abstract origin"),
9419 die
->offset
.sect_off
, offsetp
->sect_off
);
9422 origin_child_die
= origin_die
->child
;
9423 while (origin_child_die
&& origin_child_die
->tag
)
9425 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
9426 while (offsetp
< offsets_end
9427 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
9429 if (offsetp
>= offsets_end
9430 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
9432 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
9433 process_die (origin_child_die
, origin_cu
);
9435 origin_child_die
= sibling_die (origin_child_die
);
9437 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
9439 do_cleanups (cleanups
);
9443 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9445 struct objfile
*objfile
= cu
->objfile
;
9446 struct context_stack
*new;
9449 struct die_info
*child_die
;
9450 struct attribute
*attr
, *call_line
, *call_file
;
9453 struct block
*block
;
9454 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
9455 VEC (symbolp
) *template_args
= NULL
;
9456 struct template_symbol
*templ_func
= NULL
;
9460 /* If we do not have call site information, we can't show the
9461 caller of this inlined function. That's too confusing, so
9462 only use the scope for local variables. */
9463 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
9464 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
9465 if (call_line
== NULL
|| call_file
== NULL
)
9467 read_lexical_block_scope (die
, cu
);
9472 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9474 name
= dwarf2_name (die
, cu
);
9476 /* Ignore functions with missing or empty names. These are actually
9477 illegal according to the DWARF standard. */
9480 complaint (&symfile_complaints
,
9481 _("missing name for subprogram DIE at %d"),
9482 die
->offset
.sect_off
);
9486 /* Ignore functions with missing or invalid low and high pc attributes. */
9487 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
9489 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9490 if (!attr
|| !DW_UNSND (attr
))
9491 complaint (&symfile_complaints
,
9492 _("cannot get low and high bounds "
9493 "for subprogram DIE at %d"),
9494 die
->offset
.sect_off
);
9501 /* If we have any template arguments, then we must allocate a
9502 different sort of symbol. */
9503 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
9505 if (child_die
->tag
== DW_TAG_template_type_param
9506 || child_die
->tag
== DW_TAG_template_value_param
)
9508 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
9509 struct template_symbol
);
9510 templ_func
->base
.is_cplus_template_function
= 1;
9515 new = push_context (0, lowpc
);
9516 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
9517 (struct symbol
*) templ_func
);
9519 /* If there is a location expression for DW_AT_frame_base, record
9521 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
9523 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
9524 expression is being recorded directly in the function's symbol
9525 and not in a separate frame-base object. I guess this hack is
9526 to avoid adding some sort of frame-base adjunct/annex to the
9527 function's symbol :-(. The problem with doing this is that it
9528 results in a function symbol with a location expression that
9529 has nothing to do with the location of the function, ouch! The
9530 relationship should be: a function's symbol has-a frame base; a
9531 frame-base has-a location expression. */
9532 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
9534 cu
->list_in_scope
= &local_symbols
;
9536 if (die
->child
!= NULL
)
9538 child_die
= die
->child
;
9539 while (child_die
&& child_die
->tag
)
9541 if (child_die
->tag
== DW_TAG_template_type_param
9542 || child_die
->tag
== DW_TAG_template_value_param
)
9544 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
9547 VEC_safe_push (symbolp
, template_args
, arg
);
9550 process_die (child_die
, cu
);
9551 child_die
= sibling_die (child_die
);
9555 inherit_abstract_dies (die
, cu
);
9557 /* If we have a DW_AT_specification, we might need to import using
9558 directives from the context of the specification DIE. See the
9559 comment in determine_prefix. */
9560 if (cu
->language
== language_cplus
9561 && dwarf2_attr (die
, DW_AT_specification
, cu
))
9563 struct dwarf2_cu
*spec_cu
= cu
;
9564 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
9568 child_die
= spec_die
->child
;
9569 while (child_die
&& child_die
->tag
)
9571 if (child_die
->tag
== DW_TAG_imported_module
)
9572 process_die (child_die
, spec_cu
);
9573 child_die
= sibling_die (child_die
);
9576 /* In some cases, GCC generates specification DIEs that
9577 themselves contain DW_AT_specification attributes. */
9578 spec_die
= die_specification (spec_die
, &spec_cu
);
9582 new = pop_context ();
9583 /* Make a block for the local symbols within. */
9584 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
9585 lowpc
, highpc
, objfile
);
9587 /* For C++, set the block's scope. */
9588 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
9589 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
9590 determine_prefix (die
, cu
),
9591 processing_has_namespace_info
);
9593 /* If we have address ranges, record them. */
9594 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
9596 /* Attach template arguments to function. */
9597 if (! VEC_empty (symbolp
, template_args
))
9599 gdb_assert (templ_func
!= NULL
);
9601 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
9602 templ_func
->template_arguments
9603 = obstack_alloc (&objfile
->objfile_obstack
,
9604 (templ_func
->n_template_arguments
9605 * sizeof (struct symbol
*)));
9606 memcpy (templ_func
->template_arguments
,
9607 VEC_address (symbolp
, template_args
),
9608 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
9609 VEC_free (symbolp
, template_args
);
9612 /* In C++, we can have functions nested inside functions (e.g., when
9613 a function declares a class that has methods). This means that
9614 when we finish processing a function scope, we may need to go
9615 back to building a containing block's symbol lists. */
9616 local_symbols
= new->locals
;
9617 using_directives
= new->using_directives
;
9619 /* If we've finished processing a top-level function, subsequent
9620 symbols go in the file symbol list. */
9621 if (outermost_context_p ())
9622 cu
->list_in_scope
= &file_symbols
;
9625 /* Process all the DIES contained within a lexical block scope. Start
9626 a new scope, process the dies, and then close the scope. */
9629 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9631 struct objfile
*objfile
= cu
->objfile
;
9632 struct context_stack
*new;
9633 CORE_ADDR lowpc
, highpc
;
9634 struct die_info
*child_die
;
9637 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9639 /* Ignore blocks with missing or invalid low and high pc attributes. */
9640 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
9641 as multiple lexical blocks? Handling children in a sane way would
9642 be nasty. Might be easier to properly extend generic blocks to
9644 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
9649 push_context (0, lowpc
);
9650 if (die
->child
!= NULL
)
9652 child_die
= die
->child
;
9653 while (child_die
&& child_die
->tag
)
9655 process_die (child_die
, cu
);
9656 child_die
= sibling_die (child_die
);
9659 new = pop_context ();
9661 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
9664 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
9667 /* Note that recording ranges after traversing children, as we
9668 do here, means that recording a parent's ranges entails
9669 walking across all its children's ranges as they appear in
9670 the address map, which is quadratic behavior.
9672 It would be nicer to record the parent's ranges before
9673 traversing its children, simply overriding whatever you find
9674 there. But since we don't even decide whether to create a
9675 block until after we've traversed its children, that's hard
9677 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
9679 local_symbols
= new->locals
;
9680 using_directives
= new->using_directives
;
9683 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
9686 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9688 struct objfile
*objfile
= cu
->objfile
;
9689 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9690 CORE_ADDR pc
, baseaddr
;
9691 struct attribute
*attr
;
9692 struct call_site
*call_site
, call_site_local
;
9695 struct die_info
*child_die
;
9697 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9699 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
9702 complaint (&symfile_complaints
,
9703 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
9704 "DIE 0x%x [in module %s]"),
9705 die
->offset
.sect_off
, objfile
->name
);
9708 pc
= DW_ADDR (attr
) + baseaddr
;
9710 if (cu
->call_site_htab
== NULL
)
9711 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
9712 NULL
, &objfile
->objfile_obstack
,
9713 hashtab_obstack_allocate
, NULL
);
9714 call_site_local
.pc
= pc
;
9715 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
9718 complaint (&symfile_complaints
,
9719 _("Duplicate PC %s for DW_TAG_GNU_call_site "
9720 "DIE 0x%x [in module %s]"),
9721 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
9725 /* Count parameters at the caller. */
9728 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
9729 child_die
= sibling_die (child_die
))
9731 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
9733 complaint (&symfile_complaints
,
9734 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
9735 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9736 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
9743 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
9744 (sizeof (*call_site
)
9745 + (sizeof (*call_site
->parameter
)
9748 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
9751 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
9753 struct die_info
*func_die
;
9755 /* Skip also over DW_TAG_inlined_subroutine. */
9756 for (func_die
= die
->parent
;
9757 func_die
&& func_die
->tag
!= DW_TAG_subprogram
9758 && func_die
->tag
!= DW_TAG_subroutine_type
;
9759 func_die
= func_die
->parent
);
9761 /* DW_AT_GNU_all_call_sites is a superset
9762 of DW_AT_GNU_all_tail_call_sites. */
9764 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
9765 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
9767 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
9768 not complete. But keep CALL_SITE for look ups via call_site_htab,
9769 both the initial caller containing the real return address PC and
9770 the final callee containing the current PC of a chain of tail
9771 calls do not need to have the tail call list complete. But any
9772 function candidate for a virtual tail call frame searched via
9773 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
9774 determined unambiguously. */
9778 struct type
*func_type
= NULL
;
9781 func_type
= get_die_type (func_die
, cu
);
9782 if (func_type
!= NULL
)
9784 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
9786 /* Enlist this call site to the function. */
9787 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
9788 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
9791 complaint (&symfile_complaints
,
9792 _("Cannot find function owning DW_TAG_GNU_call_site "
9793 "DIE 0x%x [in module %s]"),
9794 die
->offset
.sect_off
, objfile
->name
);
9798 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
9800 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
9801 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
9802 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
9803 /* Keep NULL DWARF_BLOCK. */;
9804 else if (attr_form_is_block (attr
))
9806 struct dwarf2_locexpr_baton
*dlbaton
;
9808 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
9809 dlbaton
->data
= DW_BLOCK (attr
)->data
;
9810 dlbaton
->size
= DW_BLOCK (attr
)->size
;
9811 dlbaton
->per_cu
= cu
->per_cu
;
9813 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
9815 else if (is_ref_attr (attr
))
9817 struct dwarf2_cu
*target_cu
= cu
;
9818 struct die_info
*target_die
;
9820 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
9821 gdb_assert (target_cu
->objfile
== objfile
);
9822 if (die_is_declaration (target_die
, target_cu
))
9824 const char *target_physname
;
9826 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
9827 if (target_physname
== NULL
)
9828 complaint (&symfile_complaints
,
9829 _("DW_AT_GNU_call_site_target target DIE has invalid "
9830 "physname, for referencing DIE 0x%x [in module %s]"),
9831 die
->offset
.sect_off
, objfile
->name
);
9833 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
9839 /* DW_AT_entry_pc should be preferred. */
9840 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
9841 complaint (&symfile_complaints
,
9842 _("DW_AT_GNU_call_site_target target DIE has invalid "
9843 "low pc, for referencing DIE 0x%x [in module %s]"),
9844 die
->offset
.sect_off
, objfile
->name
);
9846 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
9850 complaint (&symfile_complaints
,
9851 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
9852 "block nor reference, for DIE 0x%x [in module %s]"),
9853 die
->offset
.sect_off
, objfile
->name
);
9855 call_site
->per_cu
= cu
->per_cu
;
9857 for (child_die
= die
->child
;
9858 child_die
&& child_die
->tag
;
9859 child_die
= sibling_die (child_die
))
9861 struct call_site_parameter
*parameter
;
9862 struct attribute
*loc
, *origin
;
9864 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
9866 /* Already printed the complaint above. */
9870 gdb_assert (call_site
->parameter_count
< nparams
);
9871 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
9873 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
9874 specifies DW_TAG_formal_parameter. Value of the data assumed for the
9875 register is contained in DW_AT_GNU_call_site_value. */
9877 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
9878 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
9879 if (loc
== NULL
&& origin
!= NULL
&& is_ref_attr (origin
))
9883 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
9884 offset
= dwarf2_get_ref_die_offset (origin
);
9885 if (!offset_in_cu_p (&cu
->header
, offset
))
9887 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
9888 binding can be done only inside one CU. Such referenced DIE
9889 therefore cannot be even moved to DW_TAG_partial_unit. */
9890 complaint (&symfile_complaints
,
9891 _("DW_AT_abstract_origin offset is not in CU for "
9892 "DW_TAG_GNU_call_site child DIE 0x%x "
9894 child_die
->offset
.sect_off
, objfile
->name
);
9897 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
9898 - cu
->header
.offset
.sect_off
);
9900 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
9902 complaint (&symfile_complaints
,
9903 _("No DW_FORM_block* DW_AT_location for "
9904 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9905 child_die
->offset
.sect_off
, objfile
->name
);
9910 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
9911 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
9912 if (parameter
->u
.dwarf_reg
!= -1)
9913 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
9914 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
9915 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
9916 ¶meter
->u
.fb_offset
))
9917 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
9920 complaint (&symfile_complaints
,
9921 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
9922 "for DW_FORM_block* DW_AT_location is supported for "
9923 "DW_TAG_GNU_call_site child DIE 0x%x "
9925 child_die
->offset
.sect_off
, objfile
->name
);
9930 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
9931 if (!attr_form_is_block (attr
))
9933 complaint (&symfile_complaints
,
9934 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
9935 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9936 child_die
->offset
.sect_off
, objfile
->name
);
9939 parameter
->value
= DW_BLOCK (attr
)->data
;
9940 parameter
->value_size
= DW_BLOCK (attr
)->size
;
9942 /* Parameters are not pre-cleared by memset above. */
9943 parameter
->data_value
= NULL
;
9944 parameter
->data_value_size
= 0;
9945 call_site
->parameter_count
++;
9947 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
9950 if (!attr_form_is_block (attr
))
9951 complaint (&symfile_complaints
,
9952 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
9953 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9954 child_die
->offset
.sect_off
, objfile
->name
);
9957 parameter
->data_value
= DW_BLOCK (attr
)->data
;
9958 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
9964 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
9965 Return 1 if the attributes are present and valid, otherwise, return 0.
9966 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
9969 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
9970 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
9971 struct partial_symtab
*ranges_pst
)
9973 struct objfile
*objfile
= cu
->objfile
;
9974 struct comp_unit_head
*cu_header
= &cu
->header
;
9975 bfd
*obfd
= objfile
->obfd
;
9976 unsigned int addr_size
= cu_header
->addr_size
;
9977 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
9978 /* Base address selection entry. */
9989 found_base
= cu
->base_known
;
9990 base
= cu
->base_address
;
9992 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
9993 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
9995 complaint (&symfile_complaints
,
9996 _("Offset %d out of bounds for DW_AT_ranges attribute"),
10000 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
10002 /* Read in the largest possible address. */
10003 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
10004 if ((marker
& mask
) == mask
)
10006 /* If we found the largest possible address, then
10007 read the base address. */
10008 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
10009 buffer
+= 2 * addr_size
;
10010 offset
+= 2 * addr_size
;
10016 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10020 CORE_ADDR range_beginning
, range_end
;
10022 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
10023 buffer
+= addr_size
;
10024 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
10025 buffer
+= addr_size
;
10026 offset
+= 2 * addr_size
;
10028 /* An end of list marker is a pair of zero addresses. */
10029 if (range_beginning
== 0 && range_end
== 0)
10030 /* Found the end of list entry. */
10033 /* Each base address selection entry is a pair of 2 values.
10034 The first is the largest possible address, the second is
10035 the base address. Check for a base address here. */
10036 if ((range_beginning
& mask
) == mask
)
10038 /* If we found the largest possible address, then
10039 read the base address. */
10040 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
10047 /* We have no valid base address for the ranges
10049 complaint (&symfile_complaints
,
10050 _("Invalid .debug_ranges data (no base address)"));
10054 if (range_beginning
> range_end
)
10056 /* Inverted range entries are invalid. */
10057 complaint (&symfile_complaints
,
10058 _("Invalid .debug_ranges data (inverted range)"));
10062 /* Empty range entries have no effect. */
10063 if (range_beginning
== range_end
)
10066 range_beginning
+= base
;
10069 /* A not-uncommon case of bad debug info.
10070 Don't pollute the addrmap with bad data. */
10071 if (range_beginning
+ baseaddr
== 0
10072 && !dwarf2_per_objfile
->has_section_at_zero
)
10074 complaint (&symfile_complaints
,
10075 _(".debug_ranges entry has start address of zero"
10076 " [in module %s]"), objfile
->name
);
10080 if (ranges_pst
!= NULL
)
10081 addrmap_set_empty (objfile
->psymtabs_addrmap
,
10082 range_beginning
+ baseaddr
,
10083 range_end
- 1 + baseaddr
,
10086 /* FIXME: This is recording everything as a low-high
10087 segment of consecutive addresses. We should have a
10088 data structure for discontiguous block ranges
10092 low
= range_beginning
;
10098 if (range_beginning
< low
)
10099 low
= range_beginning
;
10100 if (range_end
> high
)
10106 /* If the first entry is an end-of-list marker, the range
10107 describes an empty scope, i.e. no instructions. */
10113 *high_return
= high
;
10117 /* Get low and high pc attributes from a die. Return 1 if the attributes
10118 are present and valid, otherwise, return 0. Return -1 if the range is
10119 discontinuous, i.e. derived from DW_AT_ranges information. */
10122 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
10123 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
10124 struct partial_symtab
*pst
)
10126 struct attribute
*attr
;
10127 struct attribute
*attr_high
;
10129 CORE_ADDR high
= 0;
10132 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
10135 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10138 low
= DW_ADDR (attr
);
10139 if (attr_high
->form
== DW_FORM_addr
10140 || attr_high
->form
== DW_FORM_GNU_addr_index
)
10141 high
= DW_ADDR (attr_high
);
10143 high
= low
+ DW_UNSND (attr_high
);
10146 /* Found high w/o low attribute. */
10149 /* Found consecutive range of addresses. */
10154 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
10157 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
10158 We take advantage of the fact that DW_AT_ranges does not appear
10159 in DW_TAG_compile_unit of DWO files. */
10160 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
10161 unsigned int ranges_offset
= (DW_UNSND (attr
)
10162 + (need_ranges_base
10166 /* Value of the DW_AT_ranges attribute is the offset in the
10167 .debug_ranges section. */
10168 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
10170 /* Found discontinuous range of addresses. */
10175 /* read_partial_die has also the strict LOW < HIGH requirement. */
10179 /* When using the GNU linker, .gnu.linkonce. sections are used to
10180 eliminate duplicate copies of functions and vtables and such.
10181 The linker will arbitrarily choose one and discard the others.
10182 The AT_*_pc values for such functions refer to local labels in
10183 these sections. If the section from that file was discarded, the
10184 labels are not in the output, so the relocs get a value of 0.
10185 If this is a discarded function, mark the pc bounds as invalid,
10186 so that GDB will ignore it. */
10187 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10196 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
10197 its low and high PC addresses. Do nothing if these addresses could not
10198 be determined. Otherwise, set LOWPC to the low address if it is smaller,
10199 and HIGHPC to the high address if greater than HIGHPC. */
10202 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
10203 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
10204 struct dwarf2_cu
*cu
)
10206 CORE_ADDR low
, high
;
10207 struct die_info
*child
= die
->child
;
10209 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
10211 *lowpc
= min (*lowpc
, low
);
10212 *highpc
= max (*highpc
, high
);
10215 /* If the language does not allow nested subprograms (either inside
10216 subprograms or lexical blocks), we're done. */
10217 if (cu
->language
!= language_ada
)
10220 /* Check all the children of the given DIE. If it contains nested
10221 subprograms, then check their pc bounds. Likewise, we need to
10222 check lexical blocks as well, as they may also contain subprogram
10224 while (child
&& child
->tag
)
10226 if (child
->tag
== DW_TAG_subprogram
10227 || child
->tag
== DW_TAG_lexical_block
)
10228 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
10229 child
= sibling_die (child
);
10233 /* Get the low and high pc's represented by the scope DIE, and store
10234 them in *LOWPC and *HIGHPC. If the correct values can't be
10235 determined, set *LOWPC to -1 and *HIGHPC to 0. */
10238 get_scope_pc_bounds (struct die_info
*die
,
10239 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
10240 struct dwarf2_cu
*cu
)
10242 CORE_ADDR best_low
= (CORE_ADDR
) -1;
10243 CORE_ADDR best_high
= (CORE_ADDR
) 0;
10244 CORE_ADDR current_low
, current_high
;
10246 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
10248 best_low
= current_low
;
10249 best_high
= current_high
;
10253 struct die_info
*child
= die
->child
;
10255 while (child
&& child
->tag
)
10257 switch (child
->tag
) {
10258 case DW_TAG_subprogram
:
10259 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
10261 case DW_TAG_namespace
:
10262 case DW_TAG_module
:
10263 /* FIXME: carlton/2004-01-16: Should we do this for
10264 DW_TAG_class_type/DW_TAG_structure_type, too? I think
10265 that current GCC's always emit the DIEs corresponding
10266 to definitions of methods of classes as children of a
10267 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
10268 the DIEs giving the declarations, which could be
10269 anywhere). But I don't see any reason why the
10270 standards says that they have to be there. */
10271 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
10273 if (current_low
!= ((CORE_ADDR
) -1))
10275 best_low
= min (best_low
, current_low
);
10276 best_high
= max (best_high
, current_high
);
10284 child
= sibling_die (child
);
10289 *highpc
= best_high
;
10292 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
10296 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
10297 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
10299 struct objfile
*objfile
= cu
->objfile
;
10300 struct attribute
*attr
;
10301 struct attribute
*attr_high
;
10303 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
10306 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10309 CORE_ADDR low
= DW_ADDR (attr
);
10311 if (attr_high
->form
== DW_FORM_addr
10312 || attr_high
->form
== DW_FORM_GNU_addr_index
)
10313 high
= DW_ADDR (attr_high
);
10315 high
= low
+ DW_UNSND (attr_high
);
10317 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
10321 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
10324 bfd
*obfd
= objfile
->obfd
;
10325 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
10326 We take advantage of the fact that DW_AT_ranges does not appear
10327 in DW_TAG_compile_unit of DWO files. */
10328 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
10330 /* The value of the DW_AT_ranges attribute is the offset of the
10331 address range list in the .debug_ranges section. */
10332 unsigned long offset
= (DW_UNSND (attr
)
10333 + (need_ranges_base
? cu
->ranges_base
: 0));
10334 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
10336 /* For some target architectures, but not others, the
10337 read_address function sign-extends the addresses it returns.
10338 To recognize base address selection entries, we need a
10340 unsigned int addr_size
= cu
->header
.addr_size
;
10341 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
10343 /* The base address, to which the next pair is relative. Note
10344 that this 'base' is a DWARF concept: most entries in a range
10345 list are relative, to reduce the number of relocs against the
10346 debugging information. This is separate from this function's
10347 'baseaddr' argument, which GDB uses to relocate debugging
10348 information from a shared library based on the address at
10349 which the library was loaded. */
10350 CORE_ADDR base
= cu
->base_address
;
10351 int base_known
= cu
->base_known
;
10353 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
10354 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
10356 complaint (&symfile_complaints
,
10357 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
10364 unsigned int bytes_read
;
10365 CORE_ADDR start
, end
;
10367 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
10368 buffer
+= bytes_read
;
10369 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
10370 buffer
+= bytes_read
;
10372 /* Did we find the end of the range list? */
10373 if (start
== 0 && end
== 0)
10376 /* Did we find a base address selection entry? */
10377 else if ((start
& base_select_mask
) == base_select_mask
)
10383 /* We found an ordinary address range. */
10388 complaint (&symfile_complaints
,
10389 _("Invalid .debug_ranges data "
10390 "(no base address)"));
10396 /* Inverted range entries are invalid. */
10397 complaint (&symfile_complaints
,
10398 _("Invalid .debug_ranges data "
10399 "(inverted range)"));
10403 /* Empty range entries have no effect. */
10407 start
+= base
+ baseaddr
;
10408 end
+= base
+ baseaddr
;
10410 /* A not-uncommon case of bad debug info.
10411 Don't pollute the addrmap with bad data. */
10412 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10414 complaint (&symfile_complaints
,
10415 _(".debug_ranges entry has start address of zero"
10416 " [in module %s]"), objfile
->name
);
10420 record_block_range (block
, start
, end
- 1);
10426 /* Check whether the producer field indicates either of GCC < 4.6, or the
10427 Intel C/C++ compiler, and cache the result in CU. */
10430 check_producer (struct dwarf2_cu
*cu
)
10433 int major
, minor
, release
;
10435 if (cu
->producer
== NULL
)
10437 /* For unknown compilers expect their behavior is DWARF version
10440 GCC started to support .debug_types sections by -gdwarf-4 since
10441 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
10442 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
10443 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
10444 interpreted incorrectly by GDB now - GCC PR debug/48229. */
10446 else if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) == 0)
10448 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
10450 cs
= &cu
->producer
[strlen ("GNU ")];
10451 while (*cs
&& !isdigit (*cs
))
10453 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
10455 /* Not recognized as GCC. */
10459 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
10460 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
10463 else if (strncmp (cu
->producer
, "Intel(R) C", strlen ("Intel(R) C")) == 0)
10464 cu
->producer_is_icc
= 1;
10467 /* For other non-GCC compilers, expect their behavior is DWARF version
10471 cu
->checked_producer
= 1;
10474 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
10475 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
10476 during 4.6.0 experimental. */
10479 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
10481 if (!cu
->checked_producer
)
10482 check_producer (cu
);
10484 return cu
->producer_is_gxx_lt_4_6
;
10487 /* Return the default accessibility type if it is not overriden by
10488 DW_AT_accessibility. */
10490 static enum dwarf_access_attribute
10491 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
10493 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
10495 /* The default DWARF 2 accessibility for members is public, the default
10496 accessibility for inheritance is private. */
10498 if (die
->tag
!= DW_TAG_inheritance
)
10499 return DW_ACCESS_public
;
10501 return DW_ACCESS_private
;
10505 /* DWARF 3+ defines the default accessibility a different way. The same
10506 rules apply now for DW_TAG_inheritance as for the members and it only
10507 depends on the container kind. */
10509 if (die
->parent
->tag
== DW_TAG_class_type
)
10510 return DW_ACCESS_private
;
10512 return DW_ACCESS_public
;
10516 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
10517 offset. If the attribute was not found return 0, otherwise return
10518 1. If it was found but could not properly be handled, set *OFFSET
10522 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
10525 struct attribute
*attr
;
10527 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
10532 /* Note that we do not check for a section offset first here.
10533 This is because DW_AT_data_member_location is new in DWARF 4,
10534 so if we see it, we can assume that a constant form is really
10535 a constant and not a section offset. */
10536 if (attr_form_is_constant (attr
))
10537 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
10538 else if (attr_form_is_section_offset (attr
))
10539 dwarf2_complex_location_expr_complaint ();
10540 else if (attr_form_is_block (attr
))
10541 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
10543 dwarf2_complex_location_expr_complaint ();
10551 /* Add an aggregate field to the field list. */
10554 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
10555 struct dwarf2_cu
*cu
)
10557 struct objfile
*objfile
= cu
->objfile
;
10558 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10559 struct nextfield
*new_field
;
10560 struct attribute
*attr
;
10562 char *fieldname
= "";
10564 /* Allocate a new field list entry and link it in. */
10565 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
10566 make_cleanup (xfree
, new_field
);
10567 memset (new_field
, 0, sizeof (struct nextfield
));
10569 if (die
->tag
== DW_TAG_inheritance
)
10571 new_field
->next
= fip
->baseclasses
;
10572 fip
->baseclasses
= new_field
;
10576 new_field
->next
= fip
->fields
;
10577 fip
->fields
= new_field
;
10581 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
10583 new_field
->accessibility
= DW_UNSND (attr
);
10585 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
10586 if (new_field
->accessibility
!= DW_ACCESS_public
)
10587 fip
->non_public_fields
= 1;
10589 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
10591 new_field
->virtuality
= DW_UNSND (attr
);
10593 new_field
->virtuality
= DW_VIRTUALITY_none
;
10595 fp
= &new_field
->field
;
10597 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
10601 /* Data member other than a C++ static data member. */
10603 /* Get type of field. */
10604 fp
->type
= die_type (die
, cu
);
10606 SET_FIELD_BITPOS (*fp
, 0);
10608 /* Get bit size of field (zero if none). */
10609 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
10612 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
10616 FIELD_BITSIZE (*fp
) = 0;
10619 /* Get bit offset of field. */
10620 if (handle_data_member_location (die
, cu
, &offset
))
10621 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
10622 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
10625 if (gdbarch_bits_big_endian (gdbarch
))
10627 /* For big endian bits, the DW_AT_bit_offset gives the
10628 additional bit offset from the MSB of the containing
10629 anonymous object to the MSB of the field. We don't
10630 have to do anything special since we don't need to
10631 know the size of the anonymous object. */
10632 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
10636 /* For little endian bits, compute the bit offset to the
10637 MSB of the anonymous object, subtract off the number of
10638 bits from the MSB of the field to the MSB of the
10639 object, and then subtract off the number of bits of
10640 the field itself. The result is the bit offset of
10641 the LSB of the field. */
10642 int anonymous_size
;
10643 int bit_offset
= DW_UNSND (attr
);
10645 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10648 /* The size of the anonymous object containing
10649 the bit field is explicit, so use the
10650 indicated size (in bytes). */
10651 anonymous_size
= DW_UNSND (attr
);
10655 /* The size of the anonymous object containing
10656 the bit field must be inferred from the type
10657 attribute of the data member containing the
10659 anonymous_size
= TYPE_LENGTH (fp
->type
);
10661 SET_FIELD_BITPOS (*fp
,
10662 (FIELD_BITPOS (*fp
)
10663 + anonymous_size
* bits_per_byte
10664 - bit_offset
- FIELD_BITSIZE (*fp
)));
10668 /* Get name of field. */
10669 fieldname
= dwarf2_name (die
, cu
);
10670 if (fieldname
== NULL
)
10673 /* The name is already allocated along with this objfile, so we don't
10674 need to duplicate it for the type. */
10675 fp
->name
= fieldname
;
10677 /* Change accessibility for artificial fields (e.g. virtual table
10678 pointer or virtual base class pointer) to private. */
10679 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
10681 FIELD_ARTIFICIAL (*fp
) = 1;
10682 new_field
->accessibility
= DW_ACCESS_private
;
10683 fip
->non_public_fields
= 1;
10686 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
10688 /* C++ static member. */
10690 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
10691 is a declaration, but all versions of G++ as of this writing
10692 (so through at least 3.2.1) incorrectly generate
10693 DW_TAG_variable tags. */
10695 const char *physname
;
10697 /* Get name of field. */
10698 fieldname
= dwarf2_name (die
, cu
);
10699 if (fieldname
== NULL
)
10702 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10704 /* Only create a symbol if this is an external value.
10705 new_symbol checks this and puts the value in the global symbol
10706 table, which we want. If it is not external, new_symbol
10707 will try to put the value in cu->list_in_scope which is wrong. */
10708 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
10710 /* A static const member, not much different than an enum as far as
10711 we're concerned, except that we can support more types. */
10712 new_symbol (die
, NULL
, cu
);
10715 /* Get physical name. */
10716 physname
= dwarf2_physname (fieldname
, die
, cu
);
10718 /* The name is already allocated along with this objfile, so we don't
10719 need to duplicate it for the type. */
10720 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
10721 FIELD_TYPE (*fp
) = die_type (die
, cu
);
10722 FIELD_NAME (*fp
) = fieldname
;
10724 else if (die
->tag
== DW_TAG_inheritance
)
10728 /* C++ base class field. */
10729 if (handle_data_member_location (die
, cu
, &offset
))
10730 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
10731 FIELD_BITSIZE (*fp
) = 0;
10732 FIELD_TYPE (*fp
) = die_type (die
, cu
);
10733 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
10734 fip
->nbaseclasses
++;
10738 /* Add a typedef defined in the scope of the FIP's class. */
10741 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
10742 struct dwarf2_cu
*cu
)
10744 struct objfile
*objfile
= cu
->objfile
;
10745 struct typedef_field_list
*new_field
;
10746 struct attribute
*attr
;
10747 struct typedef_field
*fp
;
10748 char *fieldname
= "";
10750 /* Allocate a new field list entry and link it in. */
10751 new_field
= xzalloc (sizeof (*new_field
));
10752 make_cleanup (xfree
, new_field
);
10754 gdb_assert (die
->tag
== DW_TAG_typedef
);
10756 fp
= &new_field
->field
;
10758 /* Get name of field. */
10759 fp
->name
= dwarf2_name (die
, cu
);
10760 if (fp
->name
== NULL
)
10763 fp
->type
= read_type_die (die
, cu
);
10765 new_field
->next
= fip
->typedef_field_list
;
10766 fip
->typedef_field_list
= new_field
;
10767 fip
->typedef_field_list_count
++;
10770 /* Create the vector of fields, and attach it to the type. */
10773 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
10774 struct dwarf2_cu
*cu
)
10776 int nfields
= fip
->nfields
;
10778 /* Record the field count, allocate space for the array of fields,
10779 and create blank accessibility bitfields if necessary. */
10780 TYPE_NFIELDS (type
) = nfields
;
10781 TYPE_FIELDS (type
) = (struct field
*)
10782 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
10783 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
10785 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
10787 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10789 TYPE_FIELD_PRIVATE_BITS (type
) =
10790 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
10791 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
10793 TYPE_FIELD_PROTECTED_BITS (type
) =
10794 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
10795 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
10797 TYPE_FIELD_IGNORE_BITS (type
) =
10798 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
10799 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
10802 /* If the type has baseclasses, allocate and clear a bit vector for
10803 TYPE_FIELD_VIRTUAL_BITS. */
10804 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
10806 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
10807 unsigned char *pointer
;
10809 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10810 pointer
= TYPE_ALLOC (type
, num_bytes
);
10811 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
10812 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
10813 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
10816 /* Copy the saved-up fields into the field vector. Start from the head of
10817 the list, adding to the tail of the field array, so that they end up in
10818 the same order in the array in which they were added to the list. */
10819 while (nfields
-- > 0)
10821 struct nextfield
*fieldp
;
10825 fieldp
= fip
->fields
;
10826 fip
->fields
= fieldp
->next
;
10830 fieldp
= fip
->baseclasses
;
10831 fip
->baseclasses
= fieldp
->next
;
10834 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
10835 switch (fieldp
->accessibility
)
10837 case DW_ACCESS_private
:
10838 if (cu
->language
!= language_ada
)
10839 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
10842 case DW_ACCESS_protected
:
10843 if (cu
->language
!= language_ada
)
10844 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
10847 case DW_ACCESS_public
:
10851 /* Unknown accessibility. Complain and treat it as public. */
10853 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
10854 fieldp
->accessibility
);
10858 if (nfields
< fip
->nbaseclasses
)
10860 switch (fieldp
->virtuality
)
10862 case DW_VIRTUALITY_virtual
:
10863 case DW_VIRTUALITY_pure_virtual
:
10864 if (cu
->language
== language_ada
)
10865 error (_("unexpected virtuality in component of Ada type"));
10866 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
10873 /* Return true if this member function is a constructor, false
10877 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
10879 const char *fieldname
;
10880 const char *typename
;
10883 if (die
->parent
== NULL
)
10886 if (die
->parent
->tag
!= DW_TAG_structure_type
10887 && die
->parent
->tag
!= DW_TAG_union_type
10888 && die
->parent
->tag
!= DW_TAG_class_type
)
10891 fieldname
= dwarf2_name (die
, cu
);
10892 typename
= dwarf2_name (die
->parent
, cu
);
10893 if (fieldname
== NULL
|| typename
== NULL
)
10896 len
= strlen (fieldname
);
10897 return (strncmp (fieldname
, typename
, len
) == 0
10898 && (typename
[len
] == '\0' || typename
[len
] == '<'));
10901 /* Add a member function to the proper fieldlist. */
10904 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
10905 struct type
*type
, struct dwarf2_cu
*cu
)
10907 struct objfile
*objfile
= cu
->objfile
;
10908 struct attribute
*attr
;
10909 struct fnfieldlist
*flp
;
10911 struct fn_field
*fnp
;
10913 struct nextfnfield
*new_fnfield
;
10914 struct type
*this_type
;
10915 enum dwarf_access_attribute accessibility
;
10917 if (cu
->language
== language_ada
)
10918 error (_("unexpected member function in Ada type"));
10920 /* Get name of member function. */
10921 fieldname
= dwarf2_name (die
, cu
);
10922 if (fieldname
== NULL
)
10925 /* Look up member function name in fieldlist. */
10926 for (i
= 0; i
< fip
->nfnfields
; i
++)
10928 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
10932 /* Create new list element if necessary. */
10933 if (i
< fip
->nfnfields
)
10934 flp
= &fip
->fnfieldlists
[i
];
10937 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
10939 fip
->fnfieldlists
= (struct fnfieldlist
*)
10940 xrealloc (fip
->fnfieldlists
,
10941 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
10942 * sizeof (struct fnfieldlist
));
10943 if (fip
->nfnfields
== 0)
10944 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
10946 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
10947 flp
->name
= fieldname
;
10950 i
= fip
->nfnfields
++;
10953 /* Create a new member function field and chain it to the field list
10955 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
10956 make_cleanup (xfree
, new_fnfield
);
10957 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
10958 new_fnfield
->next
= flp
->head
;
10959 flp
->head
= new_fnfield
;
10962 /* Fill in the member function field info. */
10963 fnp
= &new_fnfield
->fnfield
;
10965 /* Delay processing of the physname until later. */
10966 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
10968 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
10973 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
10974 fnp
->physname
= physname
? physname
: "";
10977 fnp
->type
= alloc_type (objfile
);
10978 this_type
= read_type_die (die
, cu
);
10979 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
10981 int nparams
= TYPE_NFIELDS (this_type
);
10983 /* TYPE is the domain of this method, and THIS_TYPE is the type
10984 of the method itself (TYPE_CODE_METHOD). */
10985 smash_to_method_type (fnp
->type
, type
,
10986 TYPE_TARGET_TYPE (this_type
),
10987 TYPE_FIELDS (this_type
),
10988 TYPE_NFIELDS (this_type
),
10989 TYPE_VARARGS (this_type
));
10991 /* Handle static member functions.
10992 Dwarf2 has no clean way to discern C++ static and non-static
10993 member functions. G++ helps GDB by marking the first
10994 parameter for non-static member functions (which is the this
10995 pointer) as artificial. We obtain this information from
10996 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
10997 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
10998 fnp
->voffset
= VOFFSET_STATIC
;
11001 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
11002 dwarf2_full_name (fieldname
, die
, cu
));
11004 /* Get fcontext from DW_AT_containing_type if present. */
11005 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
11006 fnp
->fcontext
= die_containing_type (die
, cu
);
11008 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
11009 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
11011 /* Get accessibility. */
11012 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
11014 accessibility
= DW_UNSND (attr
);
11016 accessibility
= dwarf2_default_access_attribute (die
, cu
);
11017 switch (accessibility
)
11019 case DW_ACCESS_private
:
11020 fnp
->is_private
= 1;
11022 case DW_ACCESS_protected
:
11023 fnp
->is_protected
= 1;
11027 /* Check for artificial methods. */
11028 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
11029 if (attr
&& DW_UNSND (attr
) != 0)
11030 fnp
->is_artificial
= 1;
11032 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
11034 /* Get index in virtual function table if it is a virtual member
11035 function. For older versions of GCC, this is an offset in the
11036 appropriate virtual table, as specified by DW_AT_containing_type.
11037 For everyone else, it is an expression to be evaluated relative
11038 to the object address. */
11040 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
11043 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
11045 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
11047 /* Old-style GCC. */
11048 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
11050 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
11051 || (DW_BLOCK (attr
)->size
> 1
11052 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
11053 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
11055 struct dwarf_block blk
;
11058 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
11060 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
11061 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
11062 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
11063 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
11064 dwarf2_complex_location_expr_complaint ();
11066 fnp
->voffset
/= cu
->header
.addr_size
;
11070 dwarf2_complex_location_expr_complaint ();
11072 if (!fnp
->fcontext
)
11073 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
11075 else if (attr_form_is_section_offset (attr
))
11077 dwarf2_complex_location_expr_complaint ();
11081 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
11087 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
11088 if (attr
&& DW_UNSND (attr
))
11090 /* GCC does this, as of 2008-08-25; PR debug/37237. */
11091 complaint (&symfile_complaints
,
11092 _("Member function \"%s\" (offset %d) is virtual "
11093 "but the vtable offset is not specified"),
11094 fieldname
, die
->offset
.sect_off
);
11095 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11096 TYPE_CPLUS_DYNAMIC (type
) = 1;
11101 /* Create the vector of member function fields, and attach it to the type. */
11104 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
11105 struct dwarf2_cu
*cu
)
11107 struct fnfieldlist
*flp
;
11110 if (cu
->language
== language_ada
)
11111 error (_("unexpected member functions in Ada type"));
11113 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11114 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
11115 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
11117 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
11119 struct nextfnfield
*nfp
= flp
->head
;
11120 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
11123 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
11124 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
11125 fn_flp
->fn_fields
= (struct fn_field
*)
11126 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
11127 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
11128 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
11131 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
11134 /* Returns non-zero if NAME is the name of a vtable member in CU's
11135 language, zero otherwise. */
11137 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
11139 static const char vptr
[] = "_vptr";
11140 static const char vtable
[] = "vtable";
11142 /* Look for the C++ and Java forms of the vtable. */
11143 if ((cu
->language
== language_java
11144 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
11145 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
11146 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
11152 /* GCC outputs unnamed structures that are really pointers to member
11153 functions, with the ABI-specified layout. If TYPE describes
11154 such a structure, smash it into a member function type.
11156 GCC shouldn't do this; it should just output pointer to member DIEs.
11157 This is GCC PR debug/28767. */
11160 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
11162 struct type
*pfn_type
, *domain_type
, *new_type
;
11164 /* Check for a structure with no name and two children. */
11165 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
11168 /* Check for __pfn and __delta members. */
11169 if (TYPE_FIELD_NAME (type
, 0) == NULL
11170 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
11171 || TYPE_FIELD_NAME (type
, 1) == NULL
11172 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
11175 /* Find the type of the method. */
11176 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
11177 if (pfn_type
== NULL
11178 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
11179 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
11182 /* Look for the "this" argument. */
11183 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
11184 if (TYPE_NFIELDS (pfn_type
) == 0
11185 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
11186 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
11189 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
11190 new_type
= alloc_type (objfile
);
11191 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
11192 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
11193 TYPE_VARARGS (pfn_type
));
11194 smash_to_methodptr_type (type
, new_type
);
11197 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
11201 producer_is_icc (struct dwarf2_cu
*cu
)
11203 if (!cu
->checked_producer
)
11204 check_producer (cu
);
11206 return cu
->producer_is_icc
;
11209 /* Called when we find the DIE that starts a structure or union scope
11210 (definition) to create a type for the structure or union. Fill in
11211 the type's name and general properties; the members will not be
11212 processed until process_structure_type.
11214 NOTE: we need to call these functions regardless of whether or not the
11215 DIE has a DW_AT_name attribute, since it might be an anonymous
11216 structure or union. This gets the type entered into our set of
11217 user defined types.
11219 However, if the structure is incomplete (an opaque struct/union)
11220 then suppress creating a symbol table entry for it since gdb only
11221 wants to find the one with the complete definition. Note that if
11222 it is complete, we just call new_symbol, which does it's own
11223 checking about whether the struct/union is anonymous or not (and
11224 suppresses creating a symbol table entry itself). */
11226 static struct type
*
11227 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11229 struct objfile
*objfile
= cu
->objfile
;
11231 struct attribute
*attr
;
11234 /* If the definition of this type lives in .debug_types, read that type.
11235 Don't follow DW_AT_specification though, that will take us back up
11236 the chain and we want to go down. */
11237 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
11240 struct dwarf2_cu
*type_cu
= cu
;
11241 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11243 /* We could just recurse on read_structure_type, but we need to call
11244 get_die_type to ensure only one type for this DIE is created.
11245 This is important, for example, because for c++ classes we need
11246 TYPE_NAME set which is only done by new_symbol. Blech. */
11247 type
= read_type_die (type_die
, type_cu
);
11249 /* TYPE_CU may not be the same as CU.
11250 Ensure TYPE is recorded in CU's type_hash table. */
11251 return set_die_type (die
, type
, cu
);
11254 type
= alloc_type (objfile
);
11255 INIT_CPLUS_SPECIFIC (type
);
11257 name
= dwarf2_name (die
, cu
);
11260 if (cu
->language
== language_cplus
11261 || cu
->language
== language_java
)
11263 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
11265 /* dwarf2_full_name might have already finished building the DIE's
11266 type. If so, there is no need to continue. */
11267 if (get_die_type (die
, cu
) != NULL
)
11268 return get_die_type (die
, cu
);
11270 TYPE_TAG_NAME (type
) = full_name
;
11271 if (die
->tag
== DW_TAG_structure_type
11272 || die
->tag
== DW_TAG_class_type
)
11273 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
11277 /* The name is already allocated along with this objfile, so
11278 we don't need to duplicate it for the type. */
11279 TYPE_TAG_NAME (type
) = (char *) name
;
11280 if (die
->tag
== DW_TAG_class_type
)
11281 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
11285 if (die
->tag
== DW_TAG_structure_type
)
11287 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
11289 else if (die
->tag
== DW_TAG_union_type
)
11291 TYPE_CODE (type
) = TYPE_CODE_UNION
;
11295 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
11298 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
11299 TYPE_DECLARED_CLASS (type
) = 1;
11301 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11304 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11308 TYPE_LENGTH (type
) = 0;
11311 if (producer_is_icc (cu
))
11313 /* ICC does not output the required DW_AT_declaration
11314 on incomplete types, but gives them a size of zero. */
11317 TYPE_STUB_SUPPORTED (type
) = 1;
11319 if (die_is_declaration (die
, cu
))
11320 TYPE_STUB (type
) = 1;
11321 else if (attr
== NULL
&& die
->child
== NULL
11322 && producer_is_realview (cu
->producer
))
11323 /* RealView does not output the required DW_AT_declaration
11324 on incomplete types. */
11325 TYPE_STUB (type
) = 1;
11327 /* We need to add the type field to the die immediately so we don't
11328 infinitely recurse when dealing with pointers to the structure
11329 type within the structure itself. */
11330 set_die_type (die
, type
, cu
);
11332 /* set_die_type should be already done. */
11333 set_descriptive_type (type
, die
, cu
);
11338 /* Finish creating a structure or union type, including filling in
11339 its members and creating a symbol for it. */
11342 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11344 struct objfile
*objfile
= cu
->objfile
;
11345 struct die_info
*child_die
= die
->child
;
11348 type
= get_die_type (die
, cu
);
11350 type
= read_structure_type (die
, cu
);
11352 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
11354 struct field_info fi
;
11355 struct die_info
*child_die
;
11356 VEC (symbolp
) *template_args
= NULL
;
11357 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
11359 memset (&fi
, 0, sizeof (struct field_info
));
11361 child_die
= die
->child
;
11363 while (child_die
&& child_die
->tag
)
11365 if (child_die
->tag
== DW_TAG_member
11366 || child_die
->tag
== DW_TAG_variable
)
11368 /* NOTE: carlton/2002-11-05: A C++ static data member
11369 should be a DW_TAG_member that is a declaration, but
11370 all versions of G++ as of this writing (so through at
11371 least 3.2.1) incorrectly generate DW_TAG_variable
11372 tags for them instead. */
11373 dwarf2_add_field (&fi
, child_die
, cu
);
11375 else if (child_die
->tag
== DW_TAG_subprogram
)
11377 /* C++ member function. */
11378 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
11380 else if (child_die
->tag
== DW_TAG_inheritance
)
11382 /* C++ base class field. */
11383 dwarf2_add_field (&fi
, child_die
, cu
);
11385 else if (child_die
->tag
== DW_TAG_typedef
)
11386 dwarf2_add_typedef (&fi
, child_die
, cu
);
11387 else if (child_die
->tag
== DW_TAG_template_type_param
11388 || child_die
->tag
== DW_TAG_template_value_param
)
11390 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
11393 VEC_safe_push (symbolp
, template_args
, arg
);
11396 child_die
= sibling_die (child_die
);
11399 /* Attach template arguments to type. */
11400 if (! VEC_empty (symbolp
, template_args
))
11402 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11403 TYPE_N_TEMPLATE_ARGUMENTS (type
)
11404 = VEC_length (symbolp
, template_args
);
11405 TYPE_TEMPLATE_ARGUMENTS (type
)
11406 = obstack_alloc (&objfile
->objfile_obstack
,
11407 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
11408 * sizeof (struct symbol
*)));
11409 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
11410 VEC_address (symbolp
, template_args
),
11411 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
11412 * sizeof (struct symbol
*)));
11413 VEC_free (symbolp
, template_args
);
11416 /* Attach fields and member functions to the type. */
11418 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
11421 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
11423 /* Get the type which refers to the base class (possibly this
11424 class itself) which contains the vtable pointer for the current
11425 class from the DW_AT_containing_type attribute. This use of
11426 DW_AT_containing_type is a GNU extension. */
11428 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
11430 struct type
*t
= die_containing_type (die
, cu
);
11432 TYPE_VPTR_BASETYPE (type
) = t
;
11437 /* Our own class provides vtbl ptr. */
11438 for (i
= TYPE_NFIELDS (t
) - 1;
11439 i
>= TYPE_N_BASECLASSES (t
);
11442 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
11444 if (is_vtable_name (fieldname
, cu
))
11446 TYPE_VPTR_FIELDNO (type
) = i
;
11451 /* Complain if virtual function table field not found. */
11452 if (i
< TYPE_N_BASECLASSES (t
))
11453 complaint (&symfile_complaints
,
11454 _("virtual function table pointer "
11455 "not found when defining class '%s'"),
11456 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
11461 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
11464 else if (cu
->producer
11465 && strncmp (cu
->producer
,
11466 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
11468 /* The IBM XLC compiler does not provide direct indication
11469 of the containing type, but the vtable pointer is
11470 always named __vfp. */
11474 for (i
= TYPE_NFIELDS (type
) - 1;
11475 i
>= TYPE_N_BASECLASSES (type
);
11478 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
11480 TYPE_VPTR_FIELDNO (type
) = i
;
11481 TYPE_VPTR_BASETYPE (type
) = type
;
11488 /* Copy fi.typedef_field_list linked list elements content into the
11489 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
11490 if (fi
.typedef_field_list
)
11492 int i
= fi
.typedef_field_list_count
;
11494 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11495 TYPE_TYPEDEF_FIELD_ARRAY (type
)
11496 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
11497 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
11499 /* Reverse the list order to keep the debug info elements order. */
11502 struct typedef_field
*dest
, *src
;
11504 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
11505 src
= &fi
.typedef_field_list
->field
;
11506 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
11511 do_cleanups (back_to
);
11513 if (HAVE_CPLUS_STRUCT (type
))
11514 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
11517 quirk_gcc_member_function_pointer (type
, objfile
);
11519 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
11520 snapshots) has been known to create a die giving a declaration
11521 for a class that has, as a child, a die giving a definition for a
11522 nested class. So we have to process our children even if the
11523 current die is a declaration. Normally, of course, a declaration
11524 won't have any children at all. */
11526 while (child_die
!= NULL
&& child_die
->tag
)
11528 if (child_die
->tag
== DW_TAG_member
11529 || child_die
->tag
== DW_TAG_variable
11530 || child_die
->tag
== DW_TAG_inheritance
11531 || child_die
->tag
== DW_TAG_template_value_param
11532 || child_die
->tag
== DW_TAG_template_type_param
)
11537 process_die (child_die
, cu
);
11539 child_die
= sibling_die (child_die
);
11542 /* Do not consider external references. According to the DWARF standard,
11543 these DIEs are identified by the fact that they have no byte_size
11544 attribute, and a declaration attribute. */
11545 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
11546 || !die_is_declaration (die
, cu
))
11547 new_symbol (die
, type
, cu
);
11550 /* Given a DW_AT_enumeration_type die, set its type. We do not
11551 complete the type's fields yet, or create any symbols. */
11553 static struct type
*
11554 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11556 struct objfile
*objfile
= cu
->objfile
;
11558 struct attribute
*attr
;
11561 /* If the definition of this type lives in .debug_types, read that type.
11562 Don't follow DW_AT_specification though, that will take us back up
11563 the chain and we want to go down. */
11564 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
11567 struct dwarf2_cu
*type_cu
= cu
;
11568 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11570 type
= read_type_die (type_die
, type_cu
);
11572 /* TYPE_CU may not be the same as CU.
11573 Ensure TYPE is recorded in CU's type_hash table. */
11574 return set_die_type (die
, type
, cu
);
11577 type
= alloc_type (objfile
);
11579 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
11580 name
= dwarf2_full_name (NULL
, die
, cu
);
11582 TYPE_TAG_NAME (type
) = (char *) name
;
11584 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11587 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11591 TYPE_LENGTH (type
) = 0;
11594 /* The enumeration DIE can be incomplete. In Ada, any type can be
11595 declared as private in the package spec, and then defined only
11596 inside the package body. Such types are known as Taft Amendment
11597 Types. When another package uses such a type, an incomplete DIE
11598 may be generated by the compiler. */
11599 if (die_is_declaration (die
, cu
))
11600 TYPE_STUB (type
) = 1;
11602 return set_die_type (die
, type
, cu
);
11605 /* Given a pointer to a die which begins an enumeration, process all
11606 the dies that define the members of the enumeration, and create the
11607 symbol for the enumeration type.
11609 NOTE: We reverse the order of the element list. */
11612 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11614 struct type
*this_type
;
11616 this_type
= get_die_type (die
, cu
);
11617 if (this_type
== NULL
)
11618 this_type
= read_enumeration_type (die
, cu
);
11620 if (die
->child
!= NULL
)
11622 struct die_info
*child_die
;
11623 struct symbol
*sym
;
11624 struct field
*fields
= NULL
;
11625 int num_fields
= 0;
11626 int unsigned_enum
= 1;
11631 child_die
= die
->child
;
11632 while (child_die
&& child_die
->tag
)
11634 if (child_die
->tag
!= DW_TAG_enumerator
)
11636 process_die (child_die
, cu
);
11640 name
= dwarf2_name (child_die
, cu
);
11643 sym
= new_symbol (child_die
, this_type
, cu
);
11644 if (SYMBOL_VALUE (sym
) < 0)
11649 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
11652 mask
|= SYMBOL_VALUE (sym
);
11654 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
11656 fields
= (struct field
*)
11658 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
11659 * sizeof (struct field
));
11662 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
11663 FIELD_TYPE (fields
[num_fields
]) = NULL
;
11664 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
11665 FIELD_BITSIZE (fields
[num_fields
]) = 0;
11671 child_die
= sibling_die (child_die
);
11676 TYPE_NFIELDS (this_type
) = num_fields
;
11677 TYPE_FIELDS (this_type
) = (struct field
*)
11678 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
11679 memcpy (TYPE_FIELDS (this_type
), fields
,
11680 sizeof (struct field
) * num_fields
);
11684 TYPE_UNSIGNED (this_type
) = 1;
11686 TYPE_FLAG_ENUM (this_type
) = 1;
11689 /* If we are reading an enum from a .debug_types unit, and the enum
11690 is a declaration, and the enum is not the signatured type in the
11691 unit, then we do not want to add a symbol for it. Adding a
11692 symbol would in some cases obscure the true definition of the
11693 enum, giving users an incomplete type when the definition is
11694 actually available. Note that we do not want to do this for all
11695 enums which are just declarations, because C++0x allows forward
11696 enum declarations. */
11697 if (cu
->per_cu
->is_debug_types
11698 && die_is_declaration (die
, cu
))
11700 struct signatured_type
*sig_type
;
11703 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
11704 cu
->per_cu
->info_or_types_section
,
11705 cu
->per_cu
->offset
);
11706 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
11707 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
11711 new_symbol (die
, this_type
, cu
);
11714 /* Extract all information from a DW_TAG_array_type DIE and put it in
11715 the DIE's type field. For now, this only handles one dimensional
11718 static struct type
*
11719 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11721 struct objfile
*objfile
= cu
->objfile
;
11722 struct die_info
*child_die
;
11724 struct type
*element_type
, *range_type
, *index_type
;
11725 struct type
**range_types
= NULL
;
11726 struct attribute
*attr
;
11728 struct cleanup
*back_to
;
11731 element_type
= die_type (die
, cu
);
11733 /* The die_type call above may have already set the type for this DIE. */
11734 type
= get_die_type (die
, cu
);
11738 /* Irix 6.2 native cc creates array types without children for
11739 arrays with unspecified length. */
11740 if (die
->child
== NULL
)
11742 index_type
= objfile_type (objfile
)->builtin_int
;
11743 range_type
= create_range_type (NULL
, index_type
, 0, -1);
11744 type
= create_array_type (NULL
, element_type
, range_type
);
11745 return set_die_type (die
, type
, cu
);
11748 back_to
= make_cleanup (null_cleanup
, NULL
);
11749 child_die
= die
->child
;
11750 while (child_die
&& child_die
->tag
)
11752 if (child_die
->tag
== DW_TAG_subrange_type
)
11754 struct type
*child_type
= read_type_die (child_die
, cu
);
11756 if (child_type
!= NULL
)
11758 /* The range type was succesfully read. Save it for the
11759 array type creation. */
11760 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
11762 range_types
= (struct type
**)
11763 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
11764 * sizeof (struct type
*));
11766 make_cleanup (free_current_contents
, &range_types
);
11768 range_types
[ndim
++] = child_type
;
11771 child_die
= sibling_die (child_die
);
11774 /* Dwarf2 dimensions are output from left to right, create the
11775 necessary array types in backwards order. */
11777 type
= element_type
;
11779 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
11784 type
= create_array_type (NULL
, type
, range_types
[i
++]);
11789 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
11792 /* Understand Dwarf2 support for vector types (like they occur on
11793 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
11794 array type. This is not part of the Dwarf2/3 standard yet, but a
11795 custom vendor extension. The main difference between a regular
11796 array and the vector variant is that vectors are passed by value
11798 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
11800 make_vector_type (type
);
11802 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
11803 implementation may choose to implement triple vectors using this
11805 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11808 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
11809 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11811 complaint (&symfile_complaints
,
11812 _("DW_AT_byte_size for array type smaller "
11813 "than the total size of elements"));
11816 name
= dwarf2_name (die
, cu
);
11818 TYPE_NAME (type
) = name
;
11820 /* Install the type in the die. */
11821 set_die_type (die
, type
, cu
);
11823 /* set_die_type should be already done. */
11824 set_descriptive_type (type
, die
, cu
);
11826 do_cleanups (back_to
);
11831 static enum dwarf_array_dim_ordering
11832 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
11834 struct attribute
*attr
;
11836 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
11838 if (attr
) return DW_SND (attr
);
11840 /* GNU F77 is a special case, as at 08/2004 array type info is the
11841 opposite order to the dwarf2 specification, but data is still
11842 laid out as per normal fortran.
11844 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
11845 version checking. */
11847 if (cu
->language
== language_fortran
11848 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
11850 return DW_ORD_row_major
;
11853 switch (cu
->language_defn
->la_array_ordering
)
11855 case array_column_major
:
11856 return DW_ORD_col_major
;
11857 case array_row_major
:
11859 return DW_ORD_row_major
;
11863 /* Extract all information from a DW_TAG_set_type DIE and put it in
11864 the DIE's type field. */
11866 static struct type
*
11867 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11869 struct type
*domain_type
, *set_type
;
11870 struct attribute
*attr
;
11872 domain_type
= die_type (die
, cu
);
11874 /* The die_type call above may have already set the type for this DIE. */
11875 set_type
= get_die_type (die
, cu
);
11879 set_type
= create_set_type (NULL
, domain_type
);
11881 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11883 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
11885 return set_die_type (die
, set_type
, cu
);
11888 /* A helper for read_common_block that creates a locexpr baton.
11889 SYM is the symbol which we are marking as computed.
11890 COMMON_DIE is the DIE for the common block.
11891 COMMON_LOC is the location expression attribute for the common
11893 MEMBER_LOC is the location expression attribute for the particular
11894 member of the common block that we are processing.
11895 CU is the CU from which the above come. */
11898 mark_common_block_symbol_computed (struct symbol
*sym
,
11899 struct die_info
*common_die
,
11900 struct attribute
*common_loc
,
11901 struct attribute
*member_loc
,
11902 struct dwarf2_cu
*cu
)
11904 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11905 struct dwarf2_locexpr_baton
*baton
;
11907 unsigned int cu_off
;
11908 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
11909 LONGEST offset
= 0;
11911 gdb_assert (common_loc
&& member_loc
);
11912 gdb_assert (attr_form_is_block (common_loc
));
11913 gdb_assert (attr_form_is_block (member_loc
)
11914 || attr_form_is_constant (member_loc
));
11916 baton
= obstack_alloc (&objfile
->objfile_obstack
,
11917 sizeof (struct dwarf2_locexpr_baton
));
11918 baton
->per_cu
= cu
->per_cu
;
11919 gdb_assert (baton
->per_cu
);
11921 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
11923 if (attr_form_is_constant (member_loc
))
11925 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
11926 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
11929 baton
->size
+= DW_BLOCK (member_loc
)->size
;
11931 ptr
= obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
11934 *ptr
++ = DW_OP_call4
;
11935 cu_off
= common_die
->offset
.sect_off
- cu
->per_cu
->offset
.sect_off
;
11936 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
11939 if (attr_form_is_constant (member_loc
))
11941 *ptr
++ = DW_OP_addr
;
11942 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
11943 ptr
+= cu
->header
.addr_size
;
11947 /* We have to copy the data here, because DW_OP_call4 will only
11948 use a DW_AT_location attribute. */
11949 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
11950 ptr
+= DW_BLOCK (member_loc
)->size
;
11953 *ptr
++ = DW_OP_plus
;
11954 gdb_assert (ptr
- baton
->data
== baton
->size
);
11956 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11957 SYMBOL_LOCATION_BATON (sym
) = baton
;
11958 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11961 /* Create appropriate locally-scoped variables for all the
11962 DW_TAG_common_block entries. Also create a struct common_block
11963 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
11964 is used to sepate the common blocks name namespace from regular
11968 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
11970 struct attribute
*attr
;
11972 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11975 /* Support the .debug_loc offsets. */
11976 if (attr_form_is_block (attr
))
11980 else if (attr_form_is_section_offset (attr
))
11982 dwarf2_complex_location_expr_complaint ();
11987 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
11988 "common block member");
11993 if (die
->child
!= NULL
)
11995 struct objfile
*objfile
= cu
->objfile
;
11996 struct die_info
*child_die
;
11997 size_t n_entries
= 0, size
;
11998 struct common_block
*common_block
;
11999 struct symbol
*sym
;
12001 for (child_die
= die
->child
;
12002 child_die
&& child_die
->tag
;
12003 child_die
= sibling_die (child_die
))
12006 size
= (sizeof (struct common_block
)
12007 + (n_entries
- 1) * sizeof (struct symbol
*));
12008 common_block
= obstack_alloc (&objfile
->objfile_obstack
, size
);
12009 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
12010 common_block
->n_entries
= 0;
12012 for (child_die
= die
->child
;
12013 child_die
&& child_die
->tag
;
12014 child_die
= sibling_die (child_die
))
12016 /* Create the symbol in the DW_TAG_common_block block in the current
12018 sym
= new_symbol (child_die
, NULL
, cu
);
12021 struct attribute
*member_loc
;
12023 common_block
->contents
[common_block
->n_entries
++] = sym
;
12025 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
12029 /* GDB has handled this for a long time, but it is
12030 not specified by DWARF. It seems to have been
12031 emitted by gfortran at least as recently as:
12032 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
12033 complaint (&symfile_complaints
,
12034 _("Variable in common block has "
12035 "DW_AT_data_member_location "
12036 "- DIE at 0x%x [in module %s]"),
12037 child_die
->offset
.sect_off
, cu
->objfile
->name
);
12039 if (attr_form_is_section_offset (member_loc
))
12040 dwarf2_complex_location_expr_complaint ();
12041 else if (attr_form_is_constant (member_loc
)
12042 || attr_form_is_block (member_loc
))
12045 mark_common_block_symbol_computed (sym
, die
, attr
,
12049 dwarf2_complex_location_expr_complaint ();
12054 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
12055 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
12059 /* Create a type for a C++ namespace. */
12061 static struct type
*
12062 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12064 struct objfile
*objfile
= cu
->objfile
;
12065 const char *previous_prefix
, *name
;
12069 /* For extensions, reuse the type of the original namespace. */
12070 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
12072 struct die_info
*ext_die
;
12073 struct dwarf2_cu
*ext_cu
= cu
;
12075 ext_die
= dwarf2_extension (die
, &ext_cu
);
12076 type
= read_type_die (ext_die
, ext_cu
);
12078 /* EXT_CU may not be the same as CU.
12079 Ensure TYPE is recorded in CU's type_hash table. */
12080 return set_die_type (die
, type
, cu
);
12083 name
= namespace_name (die
, &is_anonymous
, cu
);
12085 /* Now build the name of the current namespace. */
12087 previous_prefix
= determine_prefix (die
, cu
);
12088 if (previous_prefix
[0] != '\0')
12089 name
= typename_concat (&objfile
->objfile_obstack
,
12090 previous_prefix
, name
, 0, cu
);
12092 /* Create the type. */
12093 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
12095 TYPE_NAME (type
) = (char *) name
;
12096 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
12098 return set_die_type (die
, type
, cu
);
12101 /* Read a C++ namespace. */
12104 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
12106 struct objfile
*objfile
= cu
->objfile
;
12109 /* Add a symbol associated to this if we haven't seen the namespace
12110 before. Also, add a using directive if it's an anonymous
12113 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
12117 type
= read_type_die (die
, cu
);
12118 new_symbol (die
, type
, cu
);
12120 namespace_name (die
, &is_anonymous
, cu
);
12123 const char *previous_prefix
= determine_prefix (die
, cu
);
12125 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
12126 NULL
, NULL
, &objfile
->objfile_obstack
);
12130 if (die
->child
!= NULL
)
12132 struct die_info
*child_die
= die
->child
;
12134 while (child_die
&& child_die
->tag
)
12136 process_die (child_die
, cu
);
12137 child_die
= sibling_die (child_die
);
12142 /* Read a Fortran module as type. This DIE can be only a declaration used for
12143 imported module. Still we need that type as local Fortran "use ... only"
12144 declaration imports depend on the created type in determine_prefix. */
12146 static struct type
*
12147 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12149 struct objfile
*objfile
= cu
->objfile
;
12153 module_name
= dwarf2_name (die
, cu
);
12155 complaint (&symfile_complaints
,
12156 _("DW_TAG_module has no name, offset 0x%x"),
12157 die
->offset
.sect_off
);
12158 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
12160 /* determine_prefix uses TYPE_TAG_NAME. */
12161 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
12163 return set_die_type (die
, type
, cu
);
12166 /* Read a Fortran module. */
12169 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
12171 struct die_info
*child_die
= die
->child
;
12173 while (child_die
&& child_die
->tag
)
12175 process_die (child_die
, cu
);
12176 child_die
= sibling_die (child_die
);
12180 /* Return the name of the namespace represented by DIE. Set
12181 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
12184 static const char *
12185 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
12187 struct die_info
*current_die
;
12188 const char *name
= NULL
;
12190 /* Loop through the extensions until we find a name. */
12192 for (current_die
= die
;
12193 current_die
!= NULL
;
12194 current_die
= dwarf2_extension (die
, &cu
))
12196 name
= dwarf2_name (current_die
, cu
);
12201 /* Is it an anonymous namespace? */
12203 *is_anonymous
= (name
== NULL
);
12205 name
= CP_ANONYMOUS_NAMESPACE_STR
;
12210 /* Extract all information from a DW_TAG_pointer_type DIE and add to
12211 the user defined type vector. */
12213 static struct type
*
12214 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12216 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
12217 struct comp_unit_head
*cu_header
= &cu
->header
;
12219 struct attribute
*attr_byte_size
;
12220 struct attribute
*attr_address_class
;
12221 int byte_size
, addr_class
;
12222 struct type
*target_type
;
12224 target_type
= die_type (die
, cu
);
12226 /* The die_type call above may have already set the type for this DIE. */
12227 type
= get_die_type (die
, cu
);
12231 type
= lookup_pointer_type (target_type
);
12233 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12234 if (attr_byte_size
)
12235 byte_size
= DW_UNSND (attr_byte_size
);
12237 byte_size
= cu_header
->addr_size
;
12239 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
12240 if (attr_address_class
)
12241 addr_class
= DW_UNSND (attr_address_class
);
12243 addr_class
= DW_ADDR_none
;
12245 /* If the pointer size or address class is different than the
12246 default, create a type variant marked as such and set the
12247 length accordingly. */
12248 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
12250 if (gdbarch_address_class_type_flags_p (gdbarch
))
12254 type_flags
= gdbarch_address_class_type_flags
12255 (gdbarch
, byte_size
, addr_class
);
12256 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
12258 type
= make_type_with_address_space (type
, type_flags
);
12260 else if (TYPE_LENGTH (type
) != byte_size
)
12262 complaint (&symfile_complaints
,
12263 _("invalid pointer size %d"), byte_size
);
12267 /* Should we also complain about unhandled address classes? */
12271 TYPE_LENGTH (type
) = byte_size
;
12272 return set_die_type (die
, type
, cu
);
12275 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
12276 the user defined type vector. */
12278 static struct type
*
12279 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12282 struct type
*to_type
;
12283 struct type
*domain
;
12285 to_type
= die_type (die
, cu
);
12286 domain
= die_containing_type (die
, cu
);
12288 /* The calls above may have already set the type for this DIE. */
12289 type
= get_die_type (die
, cu
);
12293 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
12294 type
= lookup_methodptr_type (to_type
);
12296 type
= lookup_memberptr_type (to_type
, domain
);
12298 return set_die_type (die
, type
, cu
);
12301 /* Extract all information from a DW_TAG_reference_type DIE and add to
12302 the user defined type vector. */
12304 static struct type
*
12305 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12307 struct comp_unit_head
*cu_header
= &cu
->header
;
12308 struct type
*type
, *target_type
;
12309 struct attribute
*attr
;
12311 target_type
= die_type (die
, cu
);
12313 /* The die_type call above may have already set the type for this DIE. */
12314 type
= get_die_type (die
, cu
);
12318 type
= lookup_reference_type (target_type
);
12319 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12322 TYPE_LENGTH (type
) = DW_UNSND (attr
);
12326 TYPE_LENGTH (type
) = cu_header
->addr_size
;
12328 return set_die_type (die
, type
, cu
);
12331 static struct type
*
12332 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12334 struct type
*base_type
, *cv_type
;
12336 base_type
= die_type (die
, cu
);
12338 /* The die_type call above may have already set the type for this DIE. */
12339 cv_type
= get_die_type (die
, cu
);
12343 /* In case the const qualifier is applied to an array type, the element type
12344 is so qualified, not the array type (section 6.7.3 of C99). */
12345 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
12347 struct type
*el_type
, *inner_array
;
12349 base_type
= copy_type (base_type
);
12350 inner_array
= base_type
;
12352 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
12354 TYPE_TARGET_TYPE (inner_array
) =
12355 copy_type (TYPE_TARGET_TYPE (inner_array
));
12356 inner_array
= TYPE_TARGET_TYPE (inner_array
);
12359 el_type
= TYPE_TARGET_TYPE (inner_array
);
12360 TYPE_TARGET_TYPE (inner_array
) =
12361 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
12363 return set_die_type (die
, base_type
, cu
);
12366 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
12367 return set_die_type (die
, cv_type
, cu
);
12370 static struct type
*
12371 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12373 struct type
*base_type
, *cv_type
;
12375 base_type
= die_type (die
, cu
);
12377 /* The die_type call above may have already set the type for this DIE. */
12378 cv_type
= get_die_type (die
, cu
);
12382 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
12383 return set_die_type (die
, cv_type
, cu
);
12386 /* Extract all information from a DW_TAG_string_type DIE and add to
12387 the user defined type vector. It isn't really a user defined type,
12388 but it behaves like one, with other DIE's using an AT_user_def_type
12389 attribute to reference it. */
12391 static struct type
*
12392 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12394 struct objfile
*objfile
= cu
->objfile
;
12395 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12396 struct type
*type
, *range_type
, *index_type
, *char_type
;
12397 struct attribute
*attr
;
12398 unsigned int length
;
12400 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
12403 length
= DW_UNSND (attr
);
12407 /* Check for the DW_AT_byte_size attribute. */
12408 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12411 length
= DW_UNSND (attr
);
12419 index_type
= objfile_type (objfile
)->builtin_int
;
12420 range_type
= create_range_type (NULL
, index_type
, 1, length
);
12421 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
12422 type
= create_string_type (NULL
, char_type
, range_type
);
12424 return set_die_type (die
, type
, cu
);
12427 /* Handle DIES due to C code like:
12431 int (*funcp)(int a, long l);
12435 ('funcp' generates a DW_TAG_subroutine_type DIE). */
12437 static struct type
*
12438 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12440 struct objfile
*objfile
= cu
->objfile
;
12441 struct type
*type
; /* Type that this function returns. */
12442 struct type
*ftype
; /* Function that returns above type. */
12443 struct attribute
*attr
;
12445 type
= die_type (die
, cu
);
12447 /* The die_type call above may have already set the type for this DIE. */
12448 ftype
= get_die_type (die
, cu
);
12452 ftype
= lookup_function_type (type
);
12454 /* All functions in C++, Pascal and Java have prototypes. */
12455 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
12456 if ((attr
&& (DW_UNSND (attr
) != 0))
12457 || cu
->language
== language_cplus
12458 || cu
->language
== language_java
12459 || cu
->language
== language_pascal
)
12460 TYPE_PROTOTYPED (ftype
) = 1;
12461 else if (producer_is_realview (cu
->producer
))
12462 /* RealView does not emit DW_AT_prototyped. We can not
12463 distinguish prototyped and unprototyped functions; default to
12464 prototyped, since that is more common in modern code (and
12465 RealView warns about unprototyped functions). */
12466 TYPE_PROTOTYPED (ftype
) = 1;
12468 /* Store the calling convention in the type if it's available in
12469 the subroutine die. Otherwise set the calling convention to
12470 the default value DW_CC_normal. */
12471 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
12473 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
12474 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
12475 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
12477 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
12479 /* We need to add the subroutine type to the die immediately so
12480 we don't infinitely recurse when dealing with parameters
12481 declared as the same subroutine type. */
12482 set_die_type (die
, ftype
, cu
);
12484 if (die
->child
!= NULL
)
12486 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
12487 struct die_info
*child_die
;
12488 int nparams
, iparams
;
12490 /* Count the number of parameters.
12491 FIXME: GDB currently ignores vararg functions, but knows about
12492 vararg member functions. */
12494 child_die
= die
->child
;
12495 while (child_die
&& child_die
->tag
)
12497 if (child_die
->tag
== DW_TAG_formal_parameter
)
12499 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
12500 TYPE_VARARGS (ftype
) = 1;
12501 child_die
= sibling_die (child_die
);
12504 /* Allocate storage for parameters and fill them in. */
12505 TYPE_NFIELDS (ftype
) = nparams
;
12506 TYPE_FIELDS (ftype
) = (struct field
*)
12507 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
12509 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
12510 even if we error out during the parameters reading below. */
12511 for (iparams
= 0; iparams
< nparams
; iparams
++)
12512 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
12515 child_die
= die
->child
;
12516 while (child_die
&& child_die
->tag
)
12518 if (child_die
->tag
== DW_TAG_formal_parameter
)
12520 struct type
*arg_type
;
12522 /* DWARF version 2 has no clean way to discern C++
12523 static and non-static member functions. G++ helps
12524 GDB by marking the first parameter for non-static
12525 member functions (which is the this pointer) as
12526 artificial. We pass this information to
12527 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
12529 DWARF version 3 added DW_AT_object_pointer, which GCC
12530 4.5 does not yet generate. */
12531 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
12533 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
12536 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
12538 /* GCC/43521: In java, the formal parameter
12539 "this" is sometimes not marked with DW_AT_artificial. */
12540 if (cu
->language
== language_java
)
12542 const char *name
= dwarf2_name (child_die
, cu
);
12544 if (name
&& !strcmp (name
, "this"))
12545 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
12548 arg_type
= die_type (child_die
, cu
);
12550 /* RealView does not mark THIS as const, which the testsuite
12551 expects. GCC marks THIS as const in method definitions,
12552 but not in the class specifications (GCC PR 43053). */
12553 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
12554 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
12557 struct dwarf2_cu
*arg_cu
= cu
;
12558 const char *name
= dwarf2_name (child_die
, cu
);
12560 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
12563 /* If the compiler emits this, use it. */
12564 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
12567 else if (name
&& strcmp (name
, "this") == 0)
12568 /* Function definitions will have the argument names. */
12570 else if (name
== NULL
&& iparams
== 0)
12571 /* Declarations may not have the names, so like
12572 elsewhere in GDB, assume an artificial first
12573 argument is "this". */
12577 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
12581 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
12584 child_die
= sibling_die (child_die
);
12591 static struct type
*
12592 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
12594 struct objfile
*objfile
= cu
->objfile
;
12595 const char *name
= NULL
;
12596 struct type
*this_type
, *target_type
;
12598 name
= dwarf2_full_name (NULL
, die
, cu
);
12599 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
12600 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
12601 TYPE_NAME (this_type
) = (char *) name
;
12602 set_die_type (die
, this_type
, cu
);
12603 target_type
= die_type (die
, cu
);
12604 if (target_type
!= this_type
)
12605 TYPE_TARGET_TYPE (this_type
) = target_type
;
12608 /* Self-referential typedefs are, it seems, not allowed by the DWARF
12609 spec and cause infinite loops in GDB. */
12610 complaint (&symfile_complaints
,
12611 _("Self-referential DW_TAG_typedef "
12612 "- DIE at 0x%x [in module %s]"),
12613 die
->offset
.sect_off
, objfile
->name
);
12614 TYPE_TARGET_TYPE (this_type
) = NULL
;
12619 /* Find a representation of a given base type and install
12620 it in the TYPE field of the die. */
12622 static struct type
*
12623 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12625 struct objfile
*objfile
= cu
->objfile
;
12627 struct attribute
*attr
;
12628 int encoding
= 0, size
= 0;
12630 enum type_code code
= TYPE_CODE_INT
;
12631 int type_flags
= 0;
12632 struct type
*target_type
= NULL
;
12634 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
12637 encoding
= DW_UNSND (attr
);
12639 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12642 size
= DW_UNSND (attr
);
12644 name
= dwarf2_name (die
, cu
);
12647 complaint (&symfile_complaints
,
12648 _("DW_AT_name missing from DW_TAG_base_type"));
12653 case DW_ATE_address
:
12654 /* Turn DW_ATE_address into a void * pointer. */
12655 code
= TYPE_CODE_PTR
;
12656 type_flags
|= TYPE_FLAG_UNSIGNED
;
12657 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
12659 case DW_ATE_boolean
:
12660 code
= TYPE_CODE_BOOL
;
12661 type_flags
|= TYPE_FLAG_UNSIGNED
;
12663 case DW_ATE_complex_float
:
12664 code
= TYPE_CODE_COMPLEX
;
12665 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
12667 case DW_ATE_decimal_float
:
12668 code
= TYPE_CODE_DECFLOAT
;
12671 code
= TYPE_CODE_FLT
;
12673 case DW_ATE_signed
:
12675 case DW_ATE_unsigned
:
12676 type_flags
|= TYPE_FLAG_UNSIGNED
;
12677 if (cu
->language
== language_fortran
12679 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
12680 code
= TYPE_CODE_CHAR
;
12682 case DW_ATE_signed_char
:
12683 if (cu
->language
== language_ada
|| cu
->language
== language_m2
12684 || cu
->language
== language_pascal
12685 || cu
->language
== language_fortran
)
12686 code
= TYPE_CODE_CHAR
;
12688 case DW_ATE_unsigned_char
:
12689 if (cu
->language
== language_ada
|| cu
->language
== language_m2
12690 || cu
->language
== language_pascal
12691 || cu
->language
== language_fortran
)
12692 code
= TYPE_CODE_CHAR
;
12693 type_flags
|= TYPE_FLAG_UNSIGNED
;
12696 /* We just treat this as an integer and then recognize the
12697 type by name elsewhere. */
12701 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
12702 dwarf_type_encoding_name (encoding
));
12706 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
12707 TYPE_NAME (type
) = name
;
12708 TYPE_TARGET_TYPE (type
) = target_type
;
12710 if (name
&& strcmp (name
, "char") == 0)
12711 TYPE_NOSIGN (type
) = 1;
12713 return set_die_type (die
, type
, cu
);
12716 /* Read the given DW_AT_subrange DIE. */
12718 static struct type
*
12719 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12721 struct type
*base_type
;
12722 struct type
*range_type
;
12723 struct attribute
*attr
;
12725 int low_default_is_valid
;
12727 LONGEST negative_mask
;
12729 base_type
= die_type (die
, cu
);
12730 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
12731 check_typedef (base_type
);
12733 /* The die_type call above may have already set the type for this DIE. */
12734 range_type
= get_die_type (die
, cu
);
12738 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
12739 omitting DW_AT_lower_bound. */
12740 switch (cu
->language
)
12743 case language_cplus
:
12745 low_default_is_valid
= 1;
12747 case language_fortran
:
12749 low_default_is_valid
= 1;
12752 case language_java
:
12753 case language_objc
:
12755 low_default_is_valid
= (cu
->header
.version
>= 4);
12759 case language_pascal
:
12761 low_default_is_valid
= (cu
->header
.version
>= 4);
12765 low_default_is_valid
= 0;
12769 /* FIXME: For variable sized arrays either of these could be
12770 a variable rather than a constant value. We'll allow it,
12771 but we don't know how to handle it. */
12772 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
12774 low
= dwarf2_get_attr_constant_value (attr
, low
);
12775 else if (!low_default_is_valid
)
12776 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
12777 "- DIE at 0x%x [in module %s]"),
12778 die
->offset
.sect_off
, cu
->objfile
->name
);
12780 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
12783 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
12785 /* GCC encodes arrays with unspecified or dynamic length
12786 with a DW_FORM_block1 attribute or a reference attribute.
12787 FIXME: GDB does not yet know how to handle dynamic
12788 arrays properly, treat them as arrays with unspecified
12791 FIXME: jimb/2003-09-22: GDB does not really know
12792 how to handle arrays of unspecified length
12793 either; we just represent them as zero-length
12794 arrays. Choose an appropriate upper bound given
12795 the lower bound we've computed above. */
12799 high
= dwarf2_get_attr_constant_value (attr
, 1);
12803 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
12806 int count
= dwarf2_get_attr_constant_value (attr
, 1);
12807 high
= low
+ count
- 1;
12811 /* Unspecified array length. */
12816 /* Dwarf-2 specifications explicitly allows to create subrange types
12817 without specifying a base type.
12818 In that case, the base type must be set to the type of
12819 the lower bound, upper bound or count, in that order, if any of these
12820 three attributes references an object that has a type.
12821 If no base type is found, the Dwarf-2 specifications say that
12822 a signed integer type of size equal to the size of an address should
12824 For the following C code: `extern char gdb_int [];'
12825 GCC produces an empty range DIE.
12826 FIXME: muller/2010-05-28: Possible references to object for low bound,
12827 high bound or count are not yet handled by this code. */
12828 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
12830 struct objfile
*objfile
= cu
->objfile
;
12831 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12832 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
12833 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
12835 /* Test "int", "long int", and "long long int" objfile types,
12836 and select the first one having a size above or equal to the
12837 architecture address size. */
12838 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
12839 base_type
= int_type
;
12842 int_type
= objfile_type (objfile
)->builtin_long
;
12843 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
12844 base_type
= int_type
;
12847 int_type
= objfile_type (objfile
)->builtin_long_long
;
12848 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
12849 base_type
= int_type
;
12855 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
12856 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
12857 low
|= negative_mask
;
12858 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
12859 high
|= negative_mask
;
12861 range_type
= create_range_type (NULL
, base_type
, low
, high
);
12863 /* Mark arrays with dynamic length at least as an array of unspecified
12864 length. GDB could check the boundary but before it gets implemented at
12865 least allow accessing the array elements. */
12866 if (attr
&& attr_form_is_block (attr
))
12867 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
12869 /* Ada expects an empty array on no boundary attributes. */
12870 if (attr
== NULL
&& cu
->language
!= language_ada
)
12871 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
12873 name
= dwarf2_name (die
, cu
);
12875 TYPE_NAME (range_type
) = name
;
12877 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12879 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
12881 set_die_type (die
, range_type
, cu
);
12883 /* set_die_type should be already done. */
12884 set_descriptive_type (range_type
, die
, cu
);
12889 static struct type
*
12890 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12894 /* For now, we only support the C meaning of an unspecified type: void. */
12896 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
12897 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
12899 return set_die_type (die
, type
, cu
);
12902 /* Read a single die and all its descendents. Set the die's sibling
12903 field to NULL; set other fields in the die correctly, and set all
12904 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
12905 location of the info_ptr after reading all of those dies. PARENT
12906 is the parent of the die in question. */
12908 static struct die_info
*
12909 read_die_and_children (const struct die_reader_specs
*reader
,
12910 gdb_byte
*info_ptr
,
12911 gdb_byte
**new_info_ptr
,
12912 struct die_info
*parent
)
12914 struct die_info
*die
;
12918 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
12921 *new_info_ptr
= cur_ptr
;
12924 store_in_ref_table (die
, reader
->cu
);
12927 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
12931 *new_info_ptr
= cur_ptr
;
12934 die
->sibling
= NULL
;
12935 die
->parent
= parent
;
12939 /* Read a die, all of its descendents, and all of its siblings; set
12940 all of the fields of all of the dies correctly. Arguments are as
12941 in read_die_and_children. */
12943 static struct die_info
*
12944 read_die_and_siblings (const struct die_reader_specs
*reader
,
12945 gdb_byte
*info_ptr
,
12946 gdb_byte
**new_info_ptr
,
12947 struct die_info
*parent
)
12949 struct die_info
*first_die
, *last_sibling
;
12952 cur_ptr
= info_ptr
;
12953 first_die
= last_sibling
= NULL
;
12957 struct die_info
*die
12958 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
12962 *new_info_ptr
= cur_ptr
;
12969 last_sibling
->sibling
= die
;
12971 last_sibling
= die
;
12975 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
12977 The caller is responsible for filling in the extra attributes
12978 and updating (*DIEP)->num_attrs.
12979 Set DIEP to point to a newly allocated die with its information,
12980 except for its child, sibling, and parent fields.
12981 Set HAS_CHILDREN to tell whether the die has children or not. */
12984 read_full_die_1 (const struct die_reader_specs
*reader
,
12985 struct die_info
**diep
, gdb_byte
*info_ptr
,
12986 int *has_children
, int num_extra_attrs
)
12988 unsigned int abbrev_number
, bytes_read
, i
;
12989 sect_offset offset
;
12990 struct abbrev_info
*abbrev
;
12991 struct die_info
*die
;
12992 struct dwarf2_cu
*cu
= reader
->cu
;
12993 bfd
*abfd
= reader
->abfd
;
12995 offset
.sect_off
= info_ptr
- reader
->buffer
;
12996 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12997 info_ptr
+= bytes_read
;
12998 if (!abbrev_number
)
13005 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
13007 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
13009 bfd_get_filename (abfd
));
13011 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
13012 die
->offset
= offset
;
13013 die
->tag
= abbrev
->tag
;
13014 die
->abbrev
= abbrev_number
;
13016 /* Make the result usable.
13017 The caller needs to update num_attrs after adding the extra
13019 die
->num_attrs
= abbrev
->num_attrs
;
13021 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
13022 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
13026 *has_children
= abbrev
->has_children
;
13030 /* Read a die and all its attributes.
13031 Set DIEP to point to a newly allocated die with its information,
13032 except for its child, sibling, and parent fields.
13033 Set HAS_CHILDREN to tell whether the die has children or not. */
13036 read_full_die (const struct die_reader_specs
*reader
,
13037 struct die_info
**diep
, gdb_byte
*info_ptr
,
13040 return read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
13043 /* Abbreviation tables.
13045 In DWARF version 2, the description of the debugging information is
13046 stored in a separate .debug_abbrev section. Before we read any
13047 dies from a section we read in all abbreviations and install them
13048 in a hash table. */
13050 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
13052 static struct abbrev_info
*
13053 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
13055 struct abbrev_info
*abbrev
;
13057 abbrev
= (struct abbrev_info
*)
13058 obstack_alloc (&abbrev_table
->abbrev_obstack
, sizeof (struct abbrev_info
));
13059 memset (abbrev
, 0, sizeof (struct abbrev_info
));
13063 /* Add an abbreviation to the table. */
13066 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
13067 unsigned int abbrev_number
,
13068 struct abbrev_info
*abbrev
)
13070 unsigned int hash_number
;
13072 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
13073 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
13074 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
13077 /* Look up an abbrev in the table.
13078 Returns NULL if the abbrev is not found. */
13080 static struct abbrev_info
*
13081 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
13082 unsigned int abbrev_number
)
13084 unsigned int hash_number
;
13085 struct abbrev_info
*abbrev
;
13087 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
13088 abbrev
= abbrev_table
->abbrevs
[hash_number
];
13092 if (abbrev
->number
== abbrev_number
)
13094 abbrev
= abbrev
->next
;
13099 /* Read in an abbrev table. */
13101 static struct abbrev_table
*
13102 abbrev_table_read_table (struct dwarf2_section_info
*section
,
13103 sect_offset offset
)
13105 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13106 bfd
*abfd
= section
->asection
->owner
;
13107 struct abbrev_table
*abbrev_table
;
13108 gdb_byte
*abbrev_ptr
;
13109 struct abbrev_info
*cur_abbrev
;
13110 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
13111 unsigned int abbrev_form
;
13112 struct attr_abbrev
*cur_attrs
;
13113 unsigned int allocated_attrs
;
13115 abbrev_table
= XMALLOC (struct abbrev_table
);
13116 abbrev_table
->offset
= offset
;
13117 obstack_init (&abbrev_table
->abbrev_obstack
);
13118 abbrev_table
->abbrevs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
13120 * sizeof (struct abbrev_info
*)));
13121 memset (abbrev_table
->abbrevs
, 0,
13122 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
13124 dwarf2_read_section (objfile
, section
);
13125 abbrev_ptr
= section
->buffer
+ offset
.sect_off
;
13126 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13127 abbrev_ptr
+= bytes_read
;
13129 allocated_attrs
= ATTR_ALLOC_CHUNK
;
13130 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
13132 /* Loop until we reach an abbrev number of 0. */
13133 while (abbrev_number
)
13135 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
13137 /* read in abbrev header */
13138 cur_abbrev
->number
= abbrev_number
;
13139 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13140 abbrev_ptr
+= bytes_read
;
13141 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
13144 /* now read in declarations */
13145 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13146 abbrev_ptr
+= bytes_read
;
13147 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13148 abbrev_ptr
+= bytes_read
;
13149 while (abbrev_name
)
13151 if (cur_abbrev
->num_attrs
== allocated_attrs
)
13153 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
13155 = xrealloc (cur_attrs
, (allocated_attrs
13156 * sizeof (struct attr_abbrev
)));
13159 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
13160 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
13161 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13162 abbrev_ptr
+= bytes_read
;
13163 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13164 abbrev_ptr
+= bytes_read
;
13167 cur_abbrev
->attrs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
13168 (cur_abbrev
->num_attrs
13169 * sizeof (struct attr_abbrev
)));
13170 memcpy (cur_abbrev
->attrs
, cur_attrs
,
13171 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
13173 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
13175 /* Get next abbreviation.
13176 Under Irix6 the abbreviations for a compilation unit are not
13177 always properly terminated with an abbrev number of 0.
13178 Exit loop if we encounter an abbreviation which we have
13179 already read (which means we are about to read the abbreviations
13180 for the next compile unit) or if the end of the abbreviation
13181 table is reached. */
13182 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
13184 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13185 abbrev_ptr
+= bytes_read
;
13186 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
13191 return abbrev_table
;
13194 /* Free the resources held by ABBREV_TABLE. */
13197 abbrev_table_free (struct abbrev_table
*abbrev_table
)
13199 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
13200 xfree (abbrev_table
);
13203 /* Same as abbrev_table_free but as a cleanup.
13204 We pass in a pointer to the pointer to the table so that we can
13205 set the pointer to NULL when we're done. It also simplifies
13206 build_type_unit_groups. */
13209 abbrev_table_free_cleanup (void *table_ptr
)
13211 struct abbrev_table
**abbrev_table_ptr
= table_ptr
;
13213 if (*abbrev_table_ptr
!= NULL
)
13214 abbrev_table_free (*abbrev_table_ptr
);
13215 *abbrev_table_ptr
= NULL
;
13218 /* Read the abbrev table for CU from ABBREV_SECTION. */
13221 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
13222 struct dwarf2_section_info
*abbrev_section
)
13225 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_offset
);
13228 /* Release the memory used by the abbrev table for a compilation unit. */
13231 dwarf2_free_abbrev_table (void *ptr_to_cu
)
13233 struct dwarf2_cu
*cu
= ptr_to_cu
;
13235 abbrev_table_free (cu
->abbrev_table
);
13236 /* Set this to NULL so that we SEGV if we try to read it later,
13237 and also because free_comp_unit verifies this is NULL. */
13238 cu
->abbrev_table
= NULL
;
13241 /* Returns nonzero if TAG represents a type that we might generate a partial
13245 is_type_tag_for_partial (int tag
)
13250 /* Some types that would be reasonable to generate partial symbols for,
13251 that we don't at present. */
13252 case DW_TAG_array_type
:
13253 case DW_TAG_file_type
:
13254 case DW_TAG_ptr_to_member_type
:
13255 case DW_TAG_set_type
:
13256 case DW_TAG_string_type
:
13257 case DW_TAG_subroutine_type
:
13259 case DW_TAG_base_type
:
13260 case DW_TAG_class_type
:
13261 case DW_TAG_interface_type
:
13262 case DW_TAG_enumeration_type
:
13263 case DW_TAG_structure_type
:
13264 case DW_TAG_subrange_type
:
13265 case DW_TAG_typedef
:
13266 case DW_TAG_union_type
:
13273 /* Load all DIEs that are interesting for partial symbols into memory. */
13275 static struct partial_die_info
*
13276 load_partial_dies (const struct die_reader_specs
*reader
,
13277 gdb_byte
*info_ptr
, int building_psymtab
)
13279 struct dwarf2_cu
*cu
= reader
->cu
;
13280 struct objfile
*objfile
= cu
->objfile
;
13281 struct partial_die_info
*part_die
;
13282 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
13283 struct abbrev_info
*abbrev
;
13284 unsigned int bytes_read
;
13285 unsigned int load_all
= 0;
13286 int nesting_level
= 1;
13291 gdb_assert (cu
->per_cu
!= NULL
);
13292 if (cu
->per_cu
->load_all_dies
)
13296 = htab_create_alloc_ex (cu
->header
.length
/ 12,
13300 &cu
->comp_unit_obstack
,
13301 hashtab_obstack_allocate
,
13302 dummy_obstack_deallocate
);
13304 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
13305 sizeof (struct partial_die_info
));
13309 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
13311 /* A NULL abbrev means the end of a series of children. */
13312 if (abbrev
== NULL
)
13314 if (--nesting_level
== 0)
13316 /* PART_DIE was probably the last thing allocated on the
13317 comp_unit_obstack, so we could call obstack_free
13318 here. We don't do that because the waste is small,
13319 and will be cleaned up when we're done with this
13320 compilation unit. This way, we're also more robust
13321 against other users of the comp_unit_obstack. */
13324 info_ptr
+= bytes_read
;
13325 last_die
= parent_die
;
13326 parent_die
= parent_die
->die_parent
;
13330 /* Check for template arguments. We never save these; if
13331 they're seen, we just mark the parent, and go on our way. */
13332 if (parent_die
!= NULL
13333 && cu
->language
== language_cplus
13334 && (abbrev
->tag
== DW_TAG_template_type_param
13335 || abbrev
->tag
== DW_TAG_template_value_param
))
13337 parent_die
->has_template_arguments
= 1;
13341 /* We don't need a partial DIE for the template argument. */
13342 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
13347 /* We only recurse into c++ subprograms looking for template arguments.
13348 Skip their other children. */
13350 && cu
->language
== language_cplus
13351 && parent_die
!= NULL
13352 && parent_die
->tag
== DW_TAG_subprogram
)
13354 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
13358 /* Check whether this DIE is interesting enough to save. Normally
13359 we would not be interested in members here, but there may be
13360 later variables referencing them via DW_AT_specification (for
13361 static members). */
13363 && !is_type_tag_for_partial (abbrev
->tag
)
13364 && abbrev
->tag
!= DW_TAG_constant
13365 && abbrev
->tag
!= DW_TAG_enumerator
13366 && abbrev
->tag
!= DW_TAG_subprogram
13367 && abbrev
->tag
!= DW_TAG_lexical_block
13368 && abbrev
->tag
!= DW_TAG_variable
13369 && abbrev
->tag
!= DW_TAG_namespace
13370 && abbrev
->tag
!= DW_TAG_module
13371 && abbrev
->tag
!= DW_TAG_member
13372 && abbrev
->tag
!= DW_TAG_imported_unit
)
13374 /* Otherwise we skip to the next sibling, if any. */
13375 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
13379 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
13382 /* This two-pass algorithm for processing partial symbols has a
13383 high cost in cache pressure. Thus, handle some simple cases
13384 here which cover the majority of C partial symbols. DIEs
13385 which neither have specification tags in them, nor could have
13386 specification tags elsewhere pointing at them, can simply be
13387 processed and discarded.
13389 This segment is also optional; scan_partial_symbols and
13390 add_partial_symbol will handle these DIEs if we chain
13391 them in normally. When compilers which do not emit large
13392 quantities of duplicate debug information are more common,
13393 this code can probably be removed. */
13395 /* Any complete simple types at the top level (pretty much all
13396 of them, for a language without namespaces), can be processed
13398 if (parent_die
== NULL
13399 && part_die
->has_specification
== 0
13400 && part_die
->is_declaration
== 0
13401 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
13402 || part_die
->tag
== DW_TAG_base_type
13403 || part_die
->tag
== DW_TAG_subrange_type
))
13405 if (building_psymtab
&& part_die
->name
!= NULL
)
13406 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
13407 VAR_DOMAIN
, LOC_TYPEDEF
,
13408 &objfile
->static_psymbols
,
13409 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
13410 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
13414 /* The exception for DW_TAG_typedef with has_children above is
13415 a workaround of GCC PR debug/47510. In the case of this complaint
13416 type_name_no_tag_or_error will error on such types later.
13418 GDB skipped children of DW_TAG_typedef by the shortcut above and then
13419 it could not find the child DIEs referenced later, this is checked
13420 above. In correct DWARF DW_TAG_typedef should have no children. */
13422 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
13423 complaint (&symfile_complaints
,
13424 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
13425 "- DIE at 0x%x [in module %s]"),
13426 part_die
->offset
.sect_off
, objfile
->name
);
13428 /* If we're at the second level, and we're an enumerator, and
13429 our parent has no specification (meaning possibly lives in a
13430 namespace elsewhere), then we can add the partial symbol now
13431 instead of queueing it. */
13432 if (part_die
->tag
== DW_TAG_enumerator
13433 && parent_die
!= NULL
13434 && parent_die
->die_parent
== NULL
13435 && parent_die
->tag
== DW_TAG_enumeration_type
13436 && parent_die
->has_specification
== 0)
13438 if (part_die
->name
== NULL
)
13439 complaint (&symfile_complaints
,
13440 _("malformed enumerator DIE ignored"));
13441 else if (building_psymtab
)
13442 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
13443 VAR_DOMAIN
, LOC_CONST
,
13444 (cu
->language
== language_cplus
13445 || cu
->language
== language_java
)
13446 ? &objfile
->global_psymbols
13447 : &objfile
->static_psymbols
,
13448 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
13450 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
13454 /* We'll save this DIE so link it in. */
13455 part_die
->die_parent
= parent_die
;
13456 part_die
->die_sibling
= NULL
;
13457 part_die
->die_child
= NULL
;
13459 if (last_die
&& last_die
== parent_die
)
13460 last_die
->die_child
= part_die
;
13462 last_die
->die_sibling
= part_die
;
13464 last_die
= part_die
;
13466 if (first_die
== NULL
)
13467 first_die
= part_die
;
13469 /* Maybe add the DIE to the hash table. Not all DIEs that we
13470 find interesting need to be in the hash table, because we
13471 also have the parent/sibling/child chains; only those that we
13472 might refer to by offset later during partial symbol reading.
13474 For now this means things that might have be the target of a
13475 DW_AT_specification, DW_AT_abstract_origin, or
13476 DW_AT_extension. DW_AT_extension will refer only to
13477 namespaces; DW_AT_abstract_origin refers to functions (and
13478 many things under the function DIE, but we do not recurse
13479 into function DIEs during partial symbol reading) and
13480 possibly variables as well; DW_AT_specification refers to
13481 declarations. Declarations ought to have the DW_AT_declaration
13482 flag. It happens that GCC forgets to put it in sometimes, but
13483 only for functions, not for types.
13485 Adding more things than necessary to the hash table is harmless
13486 except for the performance cost. Adding too few will result in
13487 wasted time in find_partial_die, when we reread the compilation
13488 unit with load_all_dies set. */
13491 || abbrev
->tag
== DW_TAG_constant
13492 || abbrev
->tag
== DW_TAG_subprogram
13493 || abbrev
->tag
== DW_TAG_variable
13494 || abbrev
->tag
== DW_TAG_namespace
13495 || part_die
->is_declaration
)
13499 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
13500 part_die
->offset
.sect_off
, INSERT
);
13504 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
13505 sizeof (struct partial_die_info
));
13507 /* For some DIEs we want to follow their children (if any). For C
13508 we have no reason to follow the children of structures; for other
13509 languages we have to, so that we can get at method physnames
13510 to infer fully qualified class names, for DW_AT_specification,
13511 and for C++ template arguments. For C++, we also look one level
13512 inside functions to find template arguments (if the name of the
13513 function does not already contain the template arguments).
13515 For Ada, we need to scan the children of subprograms and lexical
13516 blocks as well because Ada allows the definition of nested
13517 entities that could be interesting for the debugger, such as
13518 nested subprograms for instance. */
13519 if (last_die
->has_children
13521 || last_die
->tag
== DW_TAG_namespace
13522 || last_die
->tag
== DW_TAG_module
13523 || last_die
->tag
== DW_TAG_enumeration_type
13524 || (cu
->language
== language_cplus
13525 && last_die
->tag
== DW_TAG_subprogram
13526 && (last_die
->name
== NULL
13527 || strchr (last_die
->name
, '<') == NULL
))
13528 || (cu
->language
!= language_c
13529 && (last_die
->tag
== DW_TAG_class_type
13530 || last_die
->tag
== DW_TAG_interface_type
13531 || last_die
->tag
== DW_TAG_structure_type
13532 || last_die
->tag
== DW_TAG_union_type
))
13533 || (cu
->language
== language_ada
13534 && (last_die
->tag
== DW_TAG_subprogram
13535 || last_die
->tag
== DW_TAG_lexical_block
))))
13538 parent_die
= last_die
;
13542 /* Otherwise we skip to the next sibling, if any. */
13543 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
13545 /* Back to the top, do it again. */
13549 /* Read a minimal amount of information into the minimal die structure. */
13552 read_partial_die (const struct die_reader_specs
*reader
,
13553 struct partial_die_info
*part_die
,
13554 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
13555 gdb_byte
*info_ptr
)
13557 struct dwarf2_cu
*cu
= reader
->cu
;
13558 struct objfile
*objfile
= cu
->objfile
;
13559 gdb_byte
*buffer
= reader
->buffer
;
13561 struct attribute attr
;
13562 int has_low_pc_attr
= 0;
13563 int has_high_pc_attr
= 0;
13564 int high_pc_relative
= 0;
13566 memset (part_die
, 0, sizeof (struct partial_die_info
));
13568 part_die
->offset
.sect_off
= info_ptr
- buffer
;
13570 info_ptr
+= abbrev_len
;
13572 if (abbrev
== NULL
)
13575 part_die
->tag
= abbrev
->tag
;
13576 part_die
->has_children
= abbrev
->has_children
;
13578 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
13580 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
13582 /* Store the data if it is of an attribute we want to keep in a
13583 partial symbol table. */
13587 switch (part_die
->tag
)
13589 case DW_TAG_compile_unit
:
13590 case DW_TAG_partial_unit
:
13591 case DW_TAG_type_unit
:
13592 /* Compilation units have a DW_AT_name that is a filename, not
13593 a source language identifier. */
13594 case DW_TAG_enumeration_type
:
13595 case DW_TAG_enumerator
:
13596 /* These tags always have simple identifiers already; no need
13597 to canonicalize them. */
13598 part_die
->name
= DW_STRING (&attr
);
13602 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
13603 &objfile
->objfile_obstack
);
13607 case DW_AT_linkage_name
:
13608 case DW_AT_MIPS_linkage_name
:
13609 /* Note that both forms of linkage name might appear. We
13610 assume they will be the same, and we only store the last
13612 if (cu
->language
== language_ada
)
13613 part_die
->name
= DW_STRING (&attr
);
13614 part_die
->linkage_name
= DW_STRING (&attr
);
13617 has_low_pc_attr
= 1;
13618 part_die
->lowpc
= DW_ADDR (&attr
);
13620 case DW_AT_high_pc
:
13621 has_high_pc_attr
= 1;
13622 if (attr
.form
== DW_FORM_addr
13623 || attr
.form
== DW_FORM_GNU_addr_index
)
13624 part_die
->highpc
= DW_ADDR (&attr
);
13627 high_pc_relative
= 1;
13628 part_die
->highpc
= DW_UNSND (&attr
);
13631 case DW_AT_location
:
13632 /* Support the .debug_loc offsets. */
13633 if (attr_form_is_block (&attr
))
13635 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
13637 else if (attr_form_is_section_offset (&attr
))
13639 dwarf2_complex_location_expr_complaint ();
13643 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
13644 "partial symbol information");
13647 case DW_AT_external
:
13648 part_die
->is_external
= DW_UNSND (&attr
);
13650 case DW_AT_declaration
:
13651 part_die
->is_declaration
= DW_UNSND (&attr
);
13654 part_die
->has_type
= 1;
13656 case DW_AT_abstract_origin
:
13657 case DW_AT_specification
:
13658 case DW_AT_extension
:
13659 part_die
->has_specification
= 1;
13660 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
13661 part_die
->spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
13662 || cu
->per_cu
->is_dwz
);
13664 case DW_AT_sibling
:
13665 /* Ignore absolute siblings, they might point outside of
13666 the current compile unit. */
13667 if (attr
.form
== DW_FORM_ref_addr
)
13668 complaint (&symfile_complaints
,
13669 _("ignoring absolute DW_AT_sibling"));
13671 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
13673 case DW_AT_byte_size
:
13674 part_die
->has_byte_size
= 1;
13676 case DW_AT_calling_convention
:
13677 /* DWARF doesn't provide a way to identify a program's source-level
13678 entry point. DW_AT_calling_convention attributes are only meant
13679 to describe functions' calling conventions.
13681 However, because it's a necessary piece of information in
13682 Fortran, and because DW_CC_program is the only piece of debugging
13683 information whose definition refers to a 'main program' at all,
13684 several compilers have begun marking Fortran main programs with
13685 DW_CC_program --- even when those functions use the standard
13686 calling conventions.
13688 So until DWARF specifies a way to provide this information and
13689 compilers pick up the new representation, we'll support this
13691 if (DW_UNSND (&attr
) == DW_CC_program
13692 && cu
->language
== language_fortran
)
13694 set_main_name (part_die
->name
);
13696 /* As this DIE has a static linkage the name would be difficult
13697 to look up later. */
13698 language_of_main
= language_fortran
;
13702 if (DW_UNSND (&attr
) == DW_INL_inlined
13703 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
13704 part_die
->may_be_inlined
= 1;
13708 if (part_die
->tag
== DW_TAG_imported_unit
)
13710 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
13711 part_die
->is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
13712 || cu
->per_cu
->is_dwz
);
13721 if (high_pc_relative
)
13722 part_die
->highpc
+= part_die
->lowpc
;
13724 if (has_low_pc_attr
&& has_high_pc_attr
)
13726 /* When using the GNU linker, .gnu.linkonce. sections are used to
13727 eliminate duplicate copies of functions and vtables and such.
13728 The linker will arbitrarily choose one and discard the others.
13729 The AT_*_pc values for such functions refer to local labels in
13730 these sections. If the section from that file was discarded, the
13731 labels are not in the output, so the relocs get a value of 0.
13732 If this is a discarded function, mark the pc bounds as invalid,
13733 so that GDB will ignore it. */
13734 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13736 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13738 complaint (&symfile_complaints
,
13739 _("DW_AT_low_pc %s is zero "
13740 "for DIE at 0x%x [in module %s]"),
13741 paddress (gdbarch
, part_die
->lowpc
),
13742 part_die
->offset
.sect_off
, objfile
->name
);
13744 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
13745 else if (part_die
->lowpc
>= part_die
->highpc
)
13747 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13749 complaint (&symfile_complaints
,
13750 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
13751 "for DIE at 0x%x [in module %s]"),
13752 paddress (gdbarch
, part_die
->lowpc
),
13753 paddress (gdbarch
, part_die
->highpc
),
13754 part_die
->offset
.sect_off
, objfile
->name
);
13757 part_die
->has_pc_info
= 1;
13763 /* Find a cached partial DIE at OFFSET in CU. */
13765 static struct partial_die_info
*
13766 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
13768 struct partial_die_info
*lookup_die
= NULL
;
13769 struct partial_die_info part_die
;
13771 part_die
.offset
= offset
;
13772 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
13778 /* Find a partial DIE at OFFSET, which may or may not be in CU,
13779 except in the case of .debug_types DIEs which do not reference
13780 outside their CU (they do however referencing other types via
13781 DW_FORM_ref_sig8). */
13783 static struct partial_die_info
*
13784 find_partial_die (sect_offset offset
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
13786 struct objfile
*objfile
= cu
->objfile
;
13787 struct dwarf2_per_cu_data
*per_cu
= NULL
;
13788 struct partial_die_info
*pd
= NULL
;
13790 if (offset_in_dwz
== cu
->per_cu
->is_dwz
13791 && offset_in_cu_p (&cu
->header
, offset
))
13793 pd
= find_partial_die_in_comp_unit (offset
, cu
);
13796 /* We missed recording what we needed.
13797 Load all dies and try again. */
13798 per_cu
= cu
->per_cu
;
13802 /* TUs don't reference other CUs/TUs (except via type signatures). */
13803 if (cu
->per_cu
->is_debug_types
)
13805 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
13806 " external reference to offset 0x%lx [in module %s].\n"),
13807 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
13808 bfd_get_filename (objfile
->obfd
));
13810 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
13813 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
13814 load_partial_comp_unit (per_cu
);
13816 per_cu
->cu
->last_used
= 0;
13817 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
13820 /* If we didn't find it, and not all dies have been loaded,
13821 load them all and try again. */
13823 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
13825 per_cu
->load_all_dies
= 1;
13827 /* This is nasty. When we reread the DIEs, somewhere up the call chain
13828 THIS_CU->cu may already be in use. So we can't just free it and
13829 replace its DIEs with the ones we read in. Instead, we leave those
13830 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
13831 and clobber THIS_CU->cu->partial_dies with the hash table for the new
13833 load_partial_comp_unit (per_cu
);
13835 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
13839 internal_error (__FILE__
, __LINE__
,
13840 _("could not find partial DIE 0x%x "
13841 "in cache [from module %s]\n"),
13842 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
13846 /* See if we can figure out if the class lives in a namespace. We do
13847 this by looking for a member function; its demangled name will
13848 contain namespace info, if there is any. */
13851 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
13852 struct dwarf2_cu
*cu
)
13854 /* NOTE: carlton/2003-10-07: Getting the info this way changes
13855 what template types look like, because the demangler
13856 frequently doesn't give the same name as the debug info. We
13857 could fix this by only using the demangled name to get the
13858 prefix (but see comment in read_structure_type). */
13860 struct partial_die_info
*real_pdi
;
13861 struct partial_die_info
*child_pdi
;
13863 /* If this DIE (this DIE's specification, if any) has a parent, then
13864 we should not do this. We'll prepend the parent's fully qualified
13865 name when we create the partial symbol. */
13867 real_pdi
= struct_pdi
;
13868 while (real_pdi
->has_specification
)
13869 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
13870 real_pdi
->spec_is_dwz
, cu
);
13872 if (real_pdi
->die_parent
!= NULL
)
13875 for (child_pdi
= struct_pdi
->die_child
;
13877 child_pdi
= child_pdi
->die_sibling
)
13879 if (child_pdi
->tag
== DW_TAG_subprogram
13880 && child_pdi
->linkage_name
!= NULL
)
13882 char *actual_class_name
13883 = language_class_name_from_physname (cu
->language_defn
,
13884 child_pdi
->linkage_name
);
13885 if (actual_class_name
!= NULL
)
13888 = obsavestring (actual_class_name
,
13889 strlen (actual_class_name
),
13890 &cu
->objfile
->objfile_obstack
);
13891 xfree (actual_class_name
);
13898 /* Adjust PART_DIE before generating a symbol for it. This function
13899 may set the is_external flag or change the DIE's name. */
13902 fixup_partial_die (struct partial_die_info
*part_die
,
13903 struct dwarf2_cu
*cu
)
13905 /* Once we've fixed up a die, there's no point in doing so again.
13906 This also avoids a memory leak if we were to call
13907 guess_partial_die_structure_name multiple times. */
13908 if (part_die
->fixup_called
)
13911 /* If we found a reference attribute and the DIE has no name, try
13912 to find a name in the referred to DIE. */
13914 if (part_die
->name
== NULL
&& part_die
->has_specification
)
13916 struct partial_die_info
*spec_die
;
13918 spec_die
= find_partial_die (part_die
->spec_offset
,
13919 part_die
->spec_is_dwz
, cu
);
13921 fixup_partial_die (spec_die
, cu
);
13923 if (spec_die
->name
)
13925 part_die
->name
= spec_die
->name
;
13927 /* Copy DW_AT_external attribute if it is set. */
13928 if (spec_die
->is_external
)
13929 part_die
->is_external
= spec_die
->is_external
;
13933 /* Set default names for some unnamed DIEs. */
13935 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
13936 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
13938 /* If there is no parent die to provide a namespace, and there are
13939 children, see if we can determine the namespace from their linkage
13941 if (cu
->language
== language_cplus
13942 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
13943 && part_die
->die_parent
== NULL
13944 && part_die
->has_children
13945 && (part_die
->tag
== DW_TAG_class_type
13946 || part_die
->tag
== DW_TAG_structure_type
13947 || part_die
->tag
== DW_TAG_union_type
))
13948 guess_partial_die_structure_name (part_die
, cu
);
13950 /* GCC might emit a nameless struct or union that has a linkage
13951 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
13952 if (part_die
->name
== NULL
13953 && (part_die
->tag
== DW_TAG_class_type
13954 || part_die
->tag
== DW_TAG_interface_type
13955 || part_die
->tag
== DW_TAG_structure_type
13956 || part_die
->tag
== DW_TAG_union_type
)
13957 && part_die
->linkage_name
!= NULL
)
13961 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
13966 /* Strip any leading namespaces/classes, keep only the base name.
13967 DW_AT_name for named DIEs does not contain the prefixes. */
13968 base
= strrchr (demangled
, ':');
13969 if (base
&& base
> demangled
&& base
[-1] == ':')
13974 part_die
->name
= obsavestring (base
, strlen (base
),
13975 &cu
->objfile
->objfile_obstack
);
13980 part_die
->fixup_called
= 1;
13983 /* Read an attribute value described by an attribute form. */
13986 read_attribute_value (const struct die_reader_specs
*reader
,
13987 struct attribute
*attr
, unsigned form
,
13988 gdb_byte
*info_ptr
)
13990 struct dwarf2_cu
*cu
= reader
->cu
;
13991 bfd
*abfd
= reader
->abfd
;
13992 struct comp_unit_head
*cu_header
= &cu
->header
;
13993 unsigned int bytes_read
;
13994 struct dwarf_block
*blk
;
13999 case DW_FORM_ref_addr
:
14000 if (cu
->header
.version
== 2)
14001 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
14003 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
14004 &cu
->header
, &bytes_read
);
14005 info_ptr
+= bytes_read
;
14007 case DW_FORM_GNU_ref_alt
:
14008 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
14009 info_ptr
+= bytes_read
;
14012 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
14013 info_ptr
+= bytes_read
;
14015 case DW_FORM_block2
:
14016 blk
= dwarf_alloc_block (cu
);
14017 blk
->size
= read_2_bytes (abfd
, info_ptr
);
14019 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
14020 info_ptr
+= blk
->size
;
14021 DW_BLOCK (attr
) = blk
;
14023 case DW_FORM_block4
:
14024 blk
= dwarf_alloc_block (cu
);
14025 blk
->size
= read_4_bytes (abfd
, info_ptr
);
14027 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
14028 info_ptr
+= blk
->size
;
14029 DW_BLOCK (attr
) = blk
;
14031 case DW_FORM_data2
:
14032 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
14035 case DW_FORM_data4
:
14036 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
14039 case DW_FORM_data8
:
14040 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
14043 case DW_FORM_sec_offset
:
14044 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
14045 info_ptr
+= bytes_read
;
14047 case DW_FORM_string
:
14048 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
14049 DW_STRING_IS_CANONICAL (attr
) = 0;
14050 info_ptr
+= bytes_read
;
14053 if (!cu
->per_cu
->is_dwz
)
14055 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
14057 DW_STRING_IS_CANONICAL (attr
) = 0;
14058 info_ptr
+= bytes_read
;
14062 case DW_FORM_GNU_strp_alt
:
14064 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
14065 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
14068 DW_STRING (attr
) = read_indirect_string_from_dwz (dwz
, str_offset
);
14069 DW_STRING_IS_CANONICAL (attr
) = 0;
14070 info_ptr
+= bytes_read
;
14073 case DW_FORM_exprloc
:
14074 case DW_FORM_block
:
14075 blk
= dwarf_alloc_block (cu
);
14076 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14077 info_ptr
+= bytes_read
;
14078 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
14079 info_ptr
+= blk
->size
;
14080 DW_BLOCK (attr
) = blk
;
14082 case DW_FORM_block1
:
14083 blk
= dwarf_alloc_block (cu
);
14084 blk
->size
= read_1_byte (abfd
, info_ptr
);
14086 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
14087 info_ptr
+= blk
->size
;
14088 DW_BLOCK (attr
) = blk
;
14090 case DW_FORM_data1
:
14091 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
14095 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
14098 case DW_FORM_flag_present
:
14099 DW_UNSND (attr
) = 1;
14101 case DW_FORM_sdata
:
14102 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
14103 info_ptr
+= bytes_read
;
14105 case DW_FORM_udata
:
14106 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14107 info_ptr
+= bytes_read
;
14110 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14111 + read_1_byte (abfd
, info_ptr
));
14115 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14116 + read_2_bytes (abfd
, info_ptr
));
14120 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14121 + read_4_bytes (abfd
, info_ptr
));
14125 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14126 + read_8_bytes (abfd
, info_ptr
));
14129 case DW_FORM_ref_sig8
:
14130 /* Convert the signature to something we can record in DW_UNSND
14132 NOTE: This is NULL if the type wasn't found. */
14133 DW_SIGNATURED_TYPE (attr
) =
14134 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
14137 case DW_FORM_ref_udata
:
14138 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14139 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
14140 info_ptr
+= bytes_read
;
14142 case DW_FORM_indirect
:
14143 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14144 info_ptr
+= bytes_read
;
14145 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
14147 case DW_FORM_GNU_addr_index
:
14148 if (reader
->dwo_file
== NULL
)
14150 /* For now flag a hard error.
14151 Later we can turn this into a complaint. */
14152 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
14153 dwarf_form_name (form
),
14154 bfd_get_filename (abfd
));
14156 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
14157 info_ptr
+= bytes_read
;
14159 case DW_FORM_GNU_str_index
:
14160 if (reader
->dwo_file
== NULL
)
14162 /* For now flag a hard error.
14163 Later we can turn this into a complaint if warranted. */
14164 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
14165 dwarf_form_name (form
),
14166 bfd_get_filename (abfd
));
14169 ULONGEST str_index
=
14170 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14172 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
14173 DW_STRING_IS_CANONICAL (attr
) = 0;
14174 info_ptr
+= bytes_read
;
14178 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
14179 dwarf_form_name (form
),
14180 bfd_get_filename (abfd
));
14184 if (cu
->per_cu
->is_dwz
&& is_ref_attr (attr
))
14185 attr
->form
= DW_FORM_GNU_ref_alt
;
14187 /* We have seen instances where the compiler tried to emit a byte
14188 size attribute of -1 which ended up being encoded as an unsigned
14189 0xffffffff. Although 0xffffffff is technically a valid size value,
14190 an object of this size seems pretty unlikely so we can relatively
14191 safely treat these cases as if the size attribute was invalid and
14192 treat them as zero by default. */
14193 if (attr
->name
== DW_AT_byte_size
14194 && form
== DW_FORM_data4
14195 && DW_UNSND (attr
) >= 0xffffffff)
14198 (&symfile_complaints
,
14199 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
14200 hex_string (DW_UNSND (attr
)));
14201 DW_UNSND (attr
) = 0;
14207 /* Read an attribute described by an abbreviated attribute. */
14210 read_attribute (const struct die_reader_specs
*reader
,
14211 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
14212 gdb_byte
*info_ptr
)
14214 attr
->name
= abbrev
->name
;
14215 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
14218 /* Read dwarf information from a buffer. */
14220 static unsigned int
14221 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
14223 return bfd_get_8 (abfd
, buf
);
14227 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
14229 return bfd_get_signed_8 (abfd
, buf
);
14232 static unsigned int
14233 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14235 return bfd_get_16 (abfd
, buf
);
14239 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14241 return bfd_get_signed_16 (abfd
, buf
);
14244 static unsigned int
14245 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14247 return bfd_get_32 (abfd
, buf
);
14251 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14253 return bfd_get_signed_32 (abfd
, buf
);
14257 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14259 return bfd_get_64 (abfd
, buf
);
14263 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
14264 unsigned int *bytes_read
)
14266 struct comp_unit_head
*cu_header
= &cu
->header
;
14267 CORE_ADDR retval
= 0;
14269 if (cu_header
->signed_addr_p
)
14271 switch (cu_header
->addr_size
)
14274 retval
= bfd_get_signed_16 (abfd
, buf
);
14277 retval
= bfd_get_signed_32 (abfd
, buf
);
14280 retval
= bfd_get_signed_64 (abfd
, buf
);
14283 internal_error (__FILE__
, __LINE__
,
14284 _("read_address: bad switch, signed [in module %s]"),
14285 bfd_get_filename (abfd
));
14290 switch (cu_header
->addr_size
)
14293 retval
= bfd_get_16 (abfd
, buf
);
14296 retval
= bfd_get_32 (abfd
, buf
);
14299 retval
= bfd_get_64 (abfd
, buf
);
14302 internal_error (__FILE__
, __LINE__
,
14303 _("read_address: bad switch, "
14304 "unsigned [in module %s]"),
14305 bfd_get_filename (abfd
));
14309 *bytes_read
= cu_header
->addr_size
;
14313 /* Read the initial length from a section. The (draft) DWARF 3
14314 specification allows the initial length to take up either 4 bytes
14315 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
14316 bytes describe the length and all offsets will be 8 bytes in length
14319 An older, non-standard 64-bit format is also handled by this
14320 function. The older format in question stores the initial length
14321 as an 8-byte quantity without an escape value. Lengths greater
14322 than 2^32 aren't very common which means that the initial 4 bytes
14323 is almost always zero. Since a length value of zero doesn't make
14324 sense for the 32-bit format, this initial zero can be considered to
14325 be an escape value which indicates the presence of the older 64-bit
14326 format. As written, the code can't detect (old format) lengths
14327 greater than 4GB. If it becomes necessary to handle lengths
14328 somewhat larger than 4GB, we could allow other small values (such
14329 as the non-sensical values of 1, 2, and 3) to also be used as
14330 escape values indicating the presence of the old format.
14332 The value returned via bytes_read should be used to increment the
14333 relevant pointer after calling read_initial_length().
14335 [ Note: read_initial_length() and read_offset() are based on the
14336 document entitled "DWARF Debugging Information Format", revision
14337 3, draft 8, dated November 19, 2001. This document was obtained
14340 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
14342 This document is only a draft and is subject to change. (So beware.)
14344 Details regarding the older, non-standard 64-bit format were
14345 determined empirically by examining 64-bit ELF files produced by
14346 the SGI toolchain on an IRIX 6.5 machine.
14348 - Kevin, July 16, 2002
14352 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
14354 LONGEST length
= bfd_get_32 (abfd
, buf
);
14356 if (length
== 0xffffffff)
14358 length
= bfd_get_64 (abfd
, buf
+ 4);
14361 else if (length
== 0)
14363 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
14364 length
= bfd_get_64 (abfd
, buf
);
14375 /* Cover function for read_initial_length.
14376 Returns the length of the object at BUF, and stores the size of the
14377 initial length in *BYTES_READ and stores the size that offsets will be in
14379 If the initial length size is not equivalent to that specified in
14380 CU_HEADER then issue a complaint.
14381 This is useful when reading non-comp-unit headers. */
14384 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
14385 const struct comp_unit_head
*cu_header
,
14386 unsigned int *bytes_read
,
14387 unsigned int *offset_size
)
14389 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
14391 gdb_assert (cu_header
->initial_length_size
== 4
14392 || cu_header
->initial_length_size
== 8
14393 || cu_header
->initial_length_size
== 12);
14395 if (cu_header
->initial_length_size
!= *bytes_read
)
14396 complaint (&symfile_complaints
,
14397 _("intermixed 32-bit and 64-bit DWARF sections"));
14399 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
14403 /* Read an offset from the data stream. The size of the offset is
14404 given by cu_header->offset_size. */
14407 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
14408 unsigned int *bytes_read
)
14410 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
14412 *bytes_read
= cu_header
->offset_size
;
14416 /* Read an offset from the data stream. */
14419 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
14421 LONGEST retval
= 0;
14423 switch (offset_size
)
14426 retval
= bfd_get_32 (abfd
, buf
);
14429 retval
= bfd_get_64 (abfd
, buf
);
14432 internal_error (__FILE__
, __LINE__
,
14433 _("read_offset_1: bad switch [in module %s]"),
14434 bfd_get_filename (abfd
));
14441 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
14443 /* If the size of a host char is 8 bits, we can return a pointer
14444 to the buffer, otherwise we have to copy the data to a buffer
14445 allocated on the temporary obstack. */
14446 gdb_assert (HOST_CHAR_BIT
== 8);
14451 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
14453 /* If the size of a host char is 8 bits, we can return a pointer
14454 to the string, otherwise we have to copy the string to a buffer
14455 allocated on the temporary obstack. */
14456 gdb_assert (HOST_CHAR_BIT
== 8);
14459 *bytes_read_ptr
= 1;
14462 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
14463 return (char *) buf
;
14467 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
14469 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
14470 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
14471 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
14472 bfd_get_filename (abfd
));
14473 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
14474 error (_("DW_FORM_strp pointing outside of "
14475 ".debug_str section [in module %s]"),
14476 bfd_get_filename (abfd
));
14477 gdb_assert (HOST_CHAR_BIT
== 8);
14478 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
14480 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
14483 /* Read a string at offset STR_OFFSET in the .debug_str section from
14484 the .dwz file DWZ. Throw an error if the offset is too large. If
14485 the string consists of a single NUL byte, return NULL; otherwise
14486 return a pointer to the string. */
14489 read_indirect_string_from_dwz (struct dwz_file
*dwz
, LONGEST str_offset
)
14491 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwz
->str
);
14493 if (dwz
->str
.buffer
== NULL
)
14494 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
14495 "section [in module %s]"),
14496 bfd_get_filename (dwz
->dwz_bfd
));
14497 if (str_offset
>= dwz
->str
.size
)
14498 error (_("DW_FORM_GNU_strp_alt pointing outside of "
14499 ".debug_str section [in module %s]"),
14500 bfd_get_filename (dwz
->dwz_bfd
));
14501 gdb_assert (HOST_CHAR_BIT
== 8);
14502 if (dwz
->str
.buffer
[str_offset
] == '\0')
14504 return (char *) (dwz
->str
.buffer
+ str_offset
);
14508 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
14509 const struct comp_unit_head
*cu_header
,
14510 unsigned int *bytes_read_ptr
)
14512 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
14514 return read_indirect_string_at_offset (abfd
, str_offset
);
14518 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
14521 unsigned int num_read
;
14523 unsigned char byte
;
14531 byte
= bfd_get_8 (abfd
, buf
);
14534 result
|= ((ULONGEST
) (byte
& 127) << shift
);
14535 if ((byte
& 128) == 0)
14541 *bytes_read_ptr
= num_read
;
14546 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
14549 int i
, shift
, num_read
;
14550 unsigned char byte
;
14558 byte
= bfd_get_8 (abfd
, buf
);
14561 result
|= ((LONGEST
) (byte
& 127) << shift
);
14563 if ((byte
& 128) == 0)
14568 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
14569 result
|= -(((LONGEST
) 1) << shift
);
14570 *bytes_read_ptr
= num_read
;
14574 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
14575 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
14576 ADDR_SIZE is the size of addresses from the CU header. */
14579 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
14581 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14582 bfd
*abfd
= objfile
->obfd
;
14583 const gdb_byte
*info_ptr
;
14585 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
14586 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
14587 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
14589 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
14590 error (_("DW_FORM_addr_index pointing outside of "
14591 ".debug_addr section [in module %s]"),
14593 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
14594 + addr_base
+ addr_index
* addr_size
);
14595 if (addr_size
== 4)
14596 return bfd_get_32 (abfd
, info_ptr
);
14598 return bfd_get_64 (abfd
, info_ptr
);
14601 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
14604 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
14606 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
14609 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
14612 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
14613 unsigned int *bytes_read
)
14615 bfd
*abfd
= cu
->objfile
->obfd
;
14616 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
14618 return read_addr_index (cu
, addr_index
);
14621 /* Data structure to pass results from dwarf2_read_addr_index_reader
14622 back to dwarf2_read_addr_index. */
14624 struct dwarf2_read_addr_index_data
14626 ULONGEST addr_base
;
14630 /* die_reader_func for dwarf2_read_addr_index. */
14633 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
14634 gdb_byte
*info_ptr
,
14635 struct die_info
*comp_unit_die
,
14639 struct dwarf2_cu
*cu
= reader
->cu
;
14640 struct dwarf2_read_addr_index_data
*aidata
=
14641 (struct dwarf2_read_addr_index_data
*) data
;
14643 aidata
->addr_base
= cu
->addr_base
;
14644 aidata
->addr_size
= cu
->header
.addr_size
;
14647 /* Given an index in .debug_addr, fetch the value.
14648 NOTE: This can be called during dwarf expression evaluation,
14649 long after the debug information has been read, and thus per_cu->cu
14650 may no longer exist. */
14653 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
14654 unsigned int addr_index
)
14656 struct objfile
*objfile
= per_cu
->objfile
;
14657 struct dwarf2_cu
*cu
= per_cu
->cu
;
14658 ULONGEST addr_base
;
14661 /* This is intended to be called from outside this file. */
14662 dw2_setup (objfile
);
14664 /* We need addr_base and addr_size.
14665 If we don't have PER_CU->cu, we have to get it.
14666 Nasty, but the alternative is storing the needed info in PER_CU,
14667 which at this point doesn't seem justified: it's not clear how frequently
14668 it would get used and it would increase the size of every PER_CU.
14669 Entry points like dwarf2_per_cu_addr_size do a similar thing
14670 so we're not in uncharted territory here.
14671 Alas we need to be a bit more complicated as addr_base is contained
14674 We don't need to read the entire CU(/TU).
14675 We just need the header and top level die.
14677 IWBN to use the aging mechanism to let us lazily later discard the CU.
14678 For now we skip this optimization. */
14682 addr_base
= cu
->addr_base
;
14683 addr_size
= cu
->header
.addr_size
;
14687 struct dwarf2_read_addr_index_data aidata
;
14689 /* Note: We can't use init_cutu_and_read_dies_simple here,
14690 we need addr_base. */
14691 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
14692 dwarf2_read_addr_index_reader
, &aidata
);
14693 addr_base
= aidata
.addr_base
;
14694 addr_size
= aidata
.addr_size
;
14697 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
14700 /* Given a DW_AT_str_index, fetch the string. */
14703 read_str_index (const struct die_reader_specs
*reader
,
14704 struct dwarf2_cu
*cu
, ULONGEST str_index
)
14706 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14707 const char *dwo_name
= objfile
->name
;
14708 bfd
*abfd
= objfile
->obfd
;
14709 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
14710 gdb_byte
*info_ptr
;
14711 ULONGEST str_offset
;
14713 dwarf2_read_section (objfile
, §ions
->str
);
14714 dwarf2_read_section (objfile
, §ions
->str_offsets
);
14715 if (sections
->str
.buffer
== NULL
)
14716 error (_("DW_FORM_str_index used without .debug_str.dwo section"
14717 " in CU at offset 0x%lx [in module %s]"),
14718 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14719 if (sections
->str_offsets
.buffer
== NULL
)
14720 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
14721 " in CU at offset 0x%lx [in module %s]"),
14722 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14723 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
14724 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
14725 " section in CU at offset 0x%lx [in module %s]"),
14726 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14727 info_ptr
= (sections
->str_offsets
.buffer
14728 + str_index
* cu
->header
.offset_size
);
14729 if (cu
->header
.offset_size
== 4)
14730 str_offset
= bfd_get_32 (abfd
, info_ptr
);
14732 str_offset
= bfd_get_64 (abfd
, info_ptr
);
14733 if (str_offset
>= sections
->str
.size
)
14734 error (_("Offset from DW_FORM_str_index pointing outside of"
14735 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
14736 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14737 return (char *) (sections
->str
.buffer
+ str_offset
);
14740 /* Return the length of an LEB128 number in BUF. */
14743 leb128_size (const gdb_byte
*buf
)
14745 const gdb_byte
*begin
= buf
;
14751 if ((byte
& 128) == 0)
14752 return buf
- begin
;
14757 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
14764 cu
->language
= language_c
;
14766 case DW_LANG_C_plus_plus
:
14767 cu
->language
= language_cplus
;
14770 cu
->language
= language_d
;
14772 case DW_LANG_Fortran77
:
14773 case DW_LANG_Fortran90
:
14774 case DW_LANG_Fortran95
:
14775 cu
->language
= language_fortran
;
14778 cu
->language
= language_go
;
14780 case DW_LANG_Mips_Assembler
:
14781 cu
->language
= language_asm
;
14784 cu
->language
= language_java
;
14786 case DW_LANG_Ada83
:
14787 case DW_LANG_Ada95
:
14788 cu
->language
= language_ada
;
14790 case DW_LANG_Modula2
:
14791 cu
->language
= language_m2
;
14793 case DW_LANG_Pascal83
:
14794 cu
->language
= language_pascal
;
14797 cu
->language
= language_objc
;
14799 case DW_LANG_Cobol74
:
14800 case DW_LANG_Cobol85
:
14802 cu
->language
= language_minimal
;
14805 cu
->language_defn
= language_def (cu
->language
);
14808 /* Return the named attribute or NULL if not there. */
14810 static struct attribute
*
14811 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
14816 struct attribute
*spec
= NULL
;
14818 for (i
= 0; i
< die
->num_attrs
; ++i
)
14820 if (die
->attrs
[i
].name
== name
)
14821 return &die
->attrs
[i
];
14822 if (die
->attrs
[i
].name
== DW_AT_specification
14823 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
14824 spec
= &die
->attrs
[i
];
14830 die
= follow_die_ref (die
, spec
, &cu
);
14836 /* Return the named attribute or NULL if not there,
14837 but do not follow DW_AT_specification, etc.
14838 This is for use in contexts where we're reading .debug_types dies.
14839 Following DW_AT_specification, DW_AT_abstract_origin will take us
14840 back up the chain, and we want to go down. */
14842 static struct attribute
*
14843 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
14847 for (i
= 0; i
< die
->num_attrs
; ++i
)
14848 if (die
->attrs
[i
].name
== name
)
14849 return &die
->attrs
[i
];
14854 /* Return non-zero iff the attribute NAME is defined for the given DIE,
14855 and holds a non-zero value. This function should only be used for
14856 DW_FORM_flag or DW_FORM_flag_present attributes. */
14859 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
14861 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
14863 return (attr
&& DW_UNSND (attr
));
14867 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
14869 /* A DIE is a declaration if it has a DW_AT_declaration attribute
14870 which value is non-zero. However, we have to be careful with
14871 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
14872 (via dwarf2_flag_true_p) follows this attribute. So we may
14873 end up accidently finding a declaration attribute that belongs
14874 to a different DIE referenced by the specification attribute,
14875 even though the given DIE does not have a declaration attribute. */
14876 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
14877 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
14880 /* Return the die giving the specification for DIE, if there is
14881 one. *SPEC_CU is the CU containing DIE on input, and the CU
14882 containing the return value on output. If there is no
14883 specification, but there is an abstract origin, that is
14886 static struct die_info
*
14887 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
14889 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
14892 if (spec_attr
== NULL
)
14893 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
14895 if (spec_attr
== NULL
)
14898 return follow_die_ref (die
, spec_attr
, spec_cu
);
14901 /* Free the line_header structure *LH, and any arrays and strings it
14903 NOTE: This is also used as a "cleanup" function. */
14906 free_line_header (struct line_header
*lh
)
14908 if (lh
->standard_opcode_lengths
)
14909 xfree (lh
->standard_opcode_lengths
);
14911 /* Remember that all the lh->file_names[i].name pointers are
14912 pointers into debug_line_buffer, and don't need to be freed. */
14913 if (lh
->file_names
)
14914 xfree (lh
->file_names
);
14916 /* Similarly for the include directory names. */
14917 if (lh
->include_dirs
)
14918 xfree (lh
->include_dirs
);
14923 /* Add an entry to LH's include directory table. */
14926 add_include_dir (struct line_header
*lh
, char *include_dir
)
14928 /* Grow the array if necessary. */
14929 if (lh
->include_dirs_size
== 0)
14931 lh
->include_dirs_size
= 1; /* for testing */
14932 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
14933 * sizeof (*lh
->include_dirs
));
14935 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
14937 lh
->include_dirs_size
*= 2;
14938 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
14939 (lh
->include_dirs_size
14940 * sizeof (*lh
->include_dirs
)));
14943 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
14946 /* Add an entry to LH's file name table. */
14949 add_file_name (struct line_header
*lh
,
14951 unsigned int dir_index
,
14952 unsigned int mod_time
,
14953 unsigned int length
)
14955 struct file_entry
*fe
;
14957 /* Grow the array if necessary. */
14958 if (lh
->file_names_size
== 0)
14960 lh
->file_names_size
= 1; /* for testing */
14961 lh
->file_names
= xmalloc (lh
->file_names_size
14962 * sizeof (*lh
->file_names
));
14964 else if (lh
->num_file_names
>= lh
->file_names_size
)
14966 lh
->file_names_size
*= 2;
14967 lh
->file_names
= xrealloc (lh
->file_names
,
14968 (lh
->file_names_size
14969 * sizeof (*lh
->file_names
)));
14972 fe
= &lh
->file_names
[lh
->num_file_names
++];
14974 fe
->dir_index
= dir_index
;
14975 fe
->mod_time
= mod_time
;
14976 fe
->length
= length
;
14977 fe
->included_p
= 0;
14981 /* A convenience function to find the proper .debug_line section for a
14984 static struct dwarf2_section_info
*
14985 get_debug_line_section (struct dwarf2_cu
*cu
)
14987 struct dwarf2_section_info
*section
;
14989 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
14991 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
14992 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
14993 else if (cu
->per_cu
->is_dwz
)
14995 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
14997 section
= &dwz
->line
;
15000 section
= &dwarf2_per_objfile
->line
;
15005 /* Read the statement program header starting at OFFSET in
15006 .debug_line, or .debug_line.dwo. Return a pointer
15007 to a struct line_header, allocated using xmalloc.
15009 NOTE: the strings in the include directory and file name tables of
15010 the returned object point into the dwarf line section buffer,
15011 and must not be freed. */
15013 static struct line_header
*
15014 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
15016 struct cleanup
*back_to
;
15017 struct line_header
*lh
;
15018 gdb_byte
*line_ptr
;
15019 unsigned int bytes_read
, offset_size
;
15021 char *cur_dir
, *cur_file
;
15022 struct dwarf2_section_info
*section
;
15025 section
= get_debug_line_section (cu
);
15026 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
15027 if (section
->buffer
== NULL
)
15029 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
15030 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
15032 complaint (&symfile_complaints
, _("missing .debug_line section"));
15036 /* We can't do this until we know the section is non-empty.
15037 Only then do we know we have such a section. */
15038 abfd
= section
->asection
->owner
;
15040 /* Make sure that at least there's room for the total_length field.
15041 That could be 12 bytes long, but we're just going to fudge that. */
15042 if (offset
+ 4 >= section
->size
)
15044 dwarf2_statement_list_fits_in_line_number_section_complaint ();
15048 lh
= xmalloc (sizeof (*lh
));
15049 memset (lh
, 0, sizeof (*lh
));
15050 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
15053 line_ptr
= section
->buffer
+ offset
;
15055 /* Read in the header. */
15057 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
15058 &bytes_read
, &offset_size
);
15059 line_ptr
+= bytes_read
;
15060 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
15062 dwarf2_statement_list_fits_in_line_number_section_complaint ();
15065 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
15066 lh
->version
= read_2_bytes (abfd
, line_ptr
);
15068 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
15069 line_ptr
+= offset_size
;
15070 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
15072 if (lh
->version
>= 4)
15074 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
15078 lh
->maximum_ops_per_instruction
= 1;
15080 if (lh
->maximum_ops_per_instruction
== 0)
15082 lh
->maximum_ops_per_instruction
= 1;
15083 complaint (&symfile_complaints
,
15084 _("invalid maximum_ops_per_instruction "
15085 "in `.debug_line' section"));
15088 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
15090 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
15092 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
15094 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
15096 lh
->standard_opcode_lengths
15097 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
15099 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
15100 for (i
= 1; i
< lh
->opcode_base
; ++i
)
15102 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
15106 /* Read directory table. */
15107 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
15109 line_ptr
+= bytes_read
;
15110 add_include_dir (lh
, cur_dir
);
15112 line_ptr
+= bytes_read
;
15114 /* Read file name table. */
15115 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
15117 unsigned int dir_index
, mod_time
, length
;
15119 line_ptr
+= bytes_read
;
15120 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15121 line_ptr
+= bytes_read
;
15122 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15123 line_ptr
+= bytes_read
;
15124 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15125 line_ptr
+= bytes_read
;
15127 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
15129 line_ptr
+= bytes_read
;
15130 lh
->statement_program_start
= line_ptr
;
15132 if (line_ptr
> (section
->buffer
+ section
->size
))
15133 complaint (&symfile_complaints
,
15134 _("line number info header doesn't "
15135 "fit in `.debug_line' section"));
15137 discard_cleanups (back_to
);
15141 /* Subroutine of dwarf_decode_lines to simplify it.
15142 Return the file name of the psymtab for included file FILE_INDEX
15143 in line header LH of PST.
15144 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
15145 If space for the result is malloc'd, it will be freed by a cleanup.
15146 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
15149 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
15150 const struct partial_symtab
*pst
,
15151 const char *comp_dir
)
15153 const struct file_entry fe
= lh
->file_names
[file_index
];
15154 char *include_name
= fe
.name
;
15155 char *include_name_to_compare
= include_name
;
15156 char *dir_name
= NULL
;
15157 const char *pst_filename
;
15158 char *copied_name
= NULL
;
15162 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
15164 if (!IS_ABSOLUTE_PATH (include_name
)
15165 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
15167 /* Avoid creating a duplicate psymtab for PST.
15168 We do this by comparing INCLUDE_NAME and PST_FILENAME.
15169 Before we do the comparison, however, we need to account
15170 for DIR_NAME and COMP_DIR.
15171 First prepend dir_name (if non-NULL). If we still don't
15172 have an absolute path prepend comp_dir (if non-NULL).
15173 However, the directory we record in the include-file's
15174 psymtab does not contain COMP_DIR (to match the
15175 corresponding symtab(s)).
15180 bash$ gcc -g ./hello.c
15181 include_name = "hello.c"
15183 DW_AT_comp_dir = comp_dir = "/tmp"
15184 DW_AT_name = "./hello.c" */
15186 if (dir_name
!= NULL
)
15188 include_name
= concat (dir_name
, SLASH_STRING
,
15189 include_name
, (char *)NULL
);
15190 include_name_to_compare
= include_name
;
15191 make_cleanup (xfree
, include_name
);
15193 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
15195 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
15196 include_name
, (char *)NULL
);
15200 pst_filename
= pst
->filename
;
15201 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
15203 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
15204 pst_filename
, (char *)NULL
);
15205 pst_filename
= copied_name
;
15208 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
15210 if (include_name_to_compare
!= include_name
)
15211 xfree (include_name_to_compare
);
15212 if (copied_name
!= NULL
)
15213 xfree (copied_name
);
15217 return include_name
;
15220 /* Ignore this record_line request. */
15223 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
15228 /* Subroutine of dwarf_decode_lines to simplify it.
15229 Process the line number information in LH. */
15232 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
15233 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
15235 gdb_byte
*line_ptr
, *extended_end
;
15236 gdb_byte
*line_end
;
15237 unsigned int bytes_read
, extended_len
;
15238 unsigned char op_code
, extended_op
, adj_opcode
;
15239 CORE_ADDR baseaddr
;
15240 struct objfile
*objfile
= cu
->objfile
;
15241 bfd
*abfd
= objfile
->obfd
;
15242 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15243 const int decode_for_pst_p
= (pst
!= NULL
);
15244 struct subfile
*last_subfile
= NULL
;
15245 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
15248 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15250 line_ptr
= lh
->statement_program_start
;
15251 line_end
= lh
->statement_program_end
;
15253 /* Read the statement sequences until there's nothing left. */
15254 while (line_ptr
< line_end
)
15256 /* state machine registers */
15257 CORE_ADDR address
= 0;
15258 unsigned int file
= 1;
15259 unsigned int line
= 1;
15260 unsigned int column
= 0;
15261 int is_stmt
= lh
->default_is_stmt
;
15262 int basic_block
= 0;
15263 int end_sequence
= 0;
15265 unsigned char op_index
= 0;
15267 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
15269 /* Start a subfile for the current file of the state machine. */
15270 /* lh->include_dirs and lh->file_names are 0-based, but the
15271 directory and file name numbers in the statement program
15273 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
15277 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15279 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
15282 /* Decode the table. */
15283 while (!end_sequence
)
15285 op_code
= read_1_byte (abfd
, line_ptr
);
15287 if (line_ptr
> line_end
)
15289 dwarf2_debug_line_missing_end_sequence_complaint ();
15293 if (op_code
>= lh
->opcode_base
)
15295 /* Special operand. */
15296 adj_opcode
= op_code
- lh
->opcode_base
;
15297 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
15298 / lh
->maximum_ops_per_instruction
)
15299 * lh
->minimum_instruction_length
);
15300 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
15301 % lh
->maximum_ops_per_instruction
);
15302 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
15303 if (lh
->num_file_names
< file
|| file
== 0)
15304 dwarf2_debug_line_missing_file_complaint ();
15305 /* For now we ignore lines not starting on an
15306 instruction boundary. */
15307 else if (op_index
== 0)
15309 lh
->file_names
[file
- 1].included_p
= 1;
15310 if (!decode_for_pst_p
&& is_stmt
)
15312 if (last_subfile
!= current_subfile
)
15314 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15316 (*p_record_line
) (last_subfile
, 0, addr
);
15317 last_subfile
= current_subfile
;
15319 /* Append row to matrix using current values. */
15320 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15321 (*p_record_line
) (current_subfile
, line
, addr
);
15326 else switch (op_code
)
15328 case DW_LNS_extended_op
:
15329 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
15331 line_ptr
+= bytes_read
;
15332 extended_end
= line_ptr
+ extended_len
;
15333 extended_op
= read_1_byte (abfd
, line_ptr
);
15335 switch (extended_op
)
15337 case DW_LNE_end_sequence
:
15338 p_record_line
= record_line
;
15341 case DW_LNE_set_address
:
15342 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
15344 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
15346 /* This line table is for a function which has been
15347 GCd by the linker. Ignore it. PR gdb/12528 */
15350 = line_ptr
- get_debug_line_section (cu
)->buffer
;
15352 complaint (&symfile_complaints
,
15353 _(".debug_line address at offset 0x%lx is 0 "
15355 line_offset
, objfile
->name
);
15356 p_record_line
= noop_record_line
;
15360 line_ptr
+= bytes_read
;
15361 address
+= baseaddr
;
15363 case DW_LNE_define_file
:
15366 unsigned int dir_index
, mod_time
, length
;
15368 cur_file
= read_direct_string (abfd
, line_ptr
,
15370 line_ptr
+= bytes_read
;
15372 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15373 line_ptr
+= bytes_read
;
15375 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15376 line_ptr
+= bytes_read
;
15378 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15379 line_ptr
+= bytes_read
;
15380 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
15383 case DW_LNE_set_discriminator
:
15384 /* The discriminator is not interesting to the debugger;
15386 line_ptr
= extended_end
;
15389 complaint (&symfile_complaints
,
15390 _("mangled .debug_line section"));
15393 /* Make sure that we parsed the extended op correctly. If e.g.
15394 we expected a different address size than the producer used,
15395 we may have read the wrong number of bytes. */
15396 if (line_ptr
!= extended_end
)
15398 complaint (&symfile_complaints
,
15399 _("mangled .debug_line section"));
15404 if (lh
->num_file_names
< file
|| file
== 0)
15405 dwarf2_debug_line_missing_file_complaint ();
15408 lh
->file_names
[file
- 1].included_p
= 1;
15409 if (!decode_for_pst_p
&& is_stmt
)
15411 if (last_subfile
!= current_subfile
)
15413 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15415 (*p_record_line
) (last_subfile
, 0, addr
);
15416 last_subfile
= current_subfile
;
15418 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15419 (*p_record_line
) (current_subfile
, line
, addr
);
15424 case DW_LNS_advance_pc
:
15427 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15429 address
+= (((op_index
+ adjust
)
15430 / lh
->maximum_ops_per_instruction
)
15431 * lh
->minimum_instruction_length
);
15432 op_index
= ((op_index
+ adjust
)
15433 % lh
->maximum_ops_per_instruction
);
15434 line_ptr
+= bytes_read
;
15437 case DW_LNS_advance_line
:
15438 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
15439 line_ptr
+= bytes_read
;
15441 case DW_LNS_set_file
:
15443 /* The arrays lh->include_dirs and lh->file_names are
15444 0-based, but the directory and file name numbers in
15445 the statement program are 1-based. */
15446 struct file_entry
*fe
;
15449 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15450 line_ptr
+= bytes_read
;
15451 if (lh
->num_file_names
< file
|| file
== 0)
15452 dwarf2_debug_line_missing_file_complaint ();
15455 fe
= &lh
->file_names
[file
- 1];
15457 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15458 if (!decode_for_pst_p
)
15460 last_subfile
= current_subfile
;
15461 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
15466 case DW_LNS_set_column
:
15467 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15468 line_ptr
+= bytes_read
;
15470 case DW_LNS_negate_stmt
:
15471 is_stmt
= (!is_stmt
);
15473 case DW_LNS_set_basic_block
:
15476 /* Add to the address register of the state machine the
15477 address increment value corresponding to special opcode
15478 255. I.e., this value is scaled by the minimum
15479 instruction length since special opcode 255 would have
15480 scaled the increment. */
15481 case DW_LNS_const_add_pc
:
15483 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
15485 address
+= (((op_index
+ adjust
)
15486 / lh
->maximum_ops_per_instruction
)
15487 * lh
->minimum_instruction_length
);
15488 op_index
= ((op_index
+ adjust
)
15489 % lh
->maximum_ops_per_instruction
);
15492 case DW_LNS_fixed_advance_pc
:
15493 address
+= read_2_bytes (abfd
, line_ptr
);
15499 /* Unknown standard opcode, ignore it. */
15502 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
15504 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15505 line_ptr
+= bytes_read
;
15510 if (lh
->num_file_names
< file
|| file
== 0)
15511 dwarf2_debug_line_missing_file_complaint ();
15514 lh
->file_names
[file
- 1].included_p
= 1;
15515 if (!decode_for_pst_p
)
15517 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15518 (*p_record_line
) (current_subfile
, 0, addr
);
15524 /* Decode the Line Number Program (LNP) for the given line_header
15525 structure and CU. The actual information extracted and the type
15526 of structures created from the LNP depends on the value of PST.
15528 1. If PST is NULL, then this procedure uses the data from the program
15529 to create all necessary symbol tables, and their linetables.
15531 2. If PST is not NULL, this procedure reads the program to determine
15532 the list of files included by the unit represented by PST, and
15533 builds all the associated partial symbol tables.
15535 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
15536 It is used for relative paths in the line table.
15537 NOTE: When processing partial symtabs (pst != NULL),
15538 comp_dir == pst->dirname.
15540 NOTE: It is important that psymtabs have the same file name (via strcmp)
15541 as the corresponding symtab. Since COMP_DIR is not used in the name of the
15542 symtab we don't use it in the name of the psymtabs we create.
15543 E.g. expand_line_sal requires this when finding psymtabs to expand.
15544 A good testcase for this is mb-inline.exp. */
15547 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
15548 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
15549 int want_line_info
)
15551 struct objfile
*objfile
= cu
->objfile
;
15552 const int decode_for_pst_p
= (pst
!= NULL
);
15553 struct subfile
*first_subfile
= current_subfile
;
15555 if (want_line_info
)
15556 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
15558 if (decode_for_pst_p
)
15562 /* Now that we're done scanning the Line Header Program, we can
15563 create the psymtab of each included file. */
15564 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
15565 if (lh
->file_names
[file_index
].included_p
== 1)
15567 char *include_name
=
15568 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
15569 if (include_name
!= NULL
)
15570 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
15575 /* Make sure a symtab is created for every file, even files
15576 which contain only variables (i.e. no code with associated
15580 for (i
= 0; i
< lh
->num_file_names
; i
++)
15583 struct file_entry
*fe
;
15585 fe
= &lh
->file_names
[i
];
15587 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15588 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
15590 /* Skip the main file; we don't need it, and it must be
15591 allocated last, so that it will show up before the
15592 non-primary symtabs in the objfile's symtab list. */
15593 if (current_subfile
== first_subfile
)
15596 if (current_subfile
->symtab
== NULL
)
15597 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
15599 fe
->symtab
= current_subfile
->symtab
;
15604 /* Start a subfile for DWARF. FILENAME is the name of the file and
15605 DIRNAME the name of the source directory which contains FILENAME
15606 or NULL if not known. COMP_DIR is the compilation directory for the
15607 linetable's compilation unit or NULL if not known.
15608 This routine tries to keep line numbers from identical absolute and
15609 relative file names in a common subfile.
15611 Using the `list' example from the GDB testsuite, which resides in
15612 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
15613 of /srcdir/list0.c yields the following debugging information for list0.c:
15615 DW_AT_name: /srcdir/list0.c
15616 DW_AT_comp_dir: /compdir
15617 files.files[0].name: list0.h
15618 files.files[0].dir: /srcdir
15619 files.files[1].name: list0.c
15620 files.files[1].dir: /srcdir
15622 The line number information for list0.c has to end up in a single
15623 subfile, so that `break /srcdir/list0.c:1' works as expected.
15624 start_subfile will ensure that this happens provided that we pass the
15625 concatenation of files.files[1].dir and files.files[1].name as the
15629 dwarf2_start_subfile (char *filename
, const char *dirname
,
15630 const char *comp_dir
)
15634 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
15635 `start_symtab' will always pass the contents of DW_AT_comp_dir as
15636 second argument to start_subfile. To be consistent, we do the
15637 same here. In order not to lose the line information directory,
15638 we concatenate it to the filename when it makes sense.
15639 Note that the Dwarf3 standard says (speaking of filenames in line
15640 information): ``The directory index is ignored for file names
15641 that represent full path names''. Thus ignoring dirname in the
15642 `else' branch below isn't an issue. */
15644 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
15645 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
15647 fullname
= filename
;
15649 start_subfile (fullname
, comp_dir
);
15651 if (fullname
!= filename
)
15655 /* Start a symtab for DWARF.
15656 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
15659 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
15660 char *name
, char *comp_dir
, CORE_ADDR low_pc
)
15662 start_symtab (name
, comp_dir
, low_pc
);
15663 record_debugformat ("DWARF 2");
15664 record_producer (cu
->producer
);
15666 /* We assume that we're processing GCC output. */
15667 processing_gcc_compilation
= 2;
15669 processing_has_namespace_info
= 0;
15673 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
15674 struct dwarf2_cu
*cu
)
15676 struct objfile
*objfile
= cu
->objfile
;
15677 struct comp_unit_head
*cu_header
= &cu
->header
;
15679 /* NOTE drow/2003-01-30: There used to be a comment and some special
15680 code here to turn a symbol with DW_AT_external and a
15681 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
15682 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
15683 with some versions of binutils) where shared libraries could have
15684 relocations against symbols in their debug information - the
15685 minimal symbol would have the right address, but the debug info
15686 would not. It's no longer necessary, because we will explicitly
15687 apply relocations when we read in the debug information now. */
15689 /* A DW_AT_location attribute with no contents indicates that a
15690 variable has been optimized away. */
15691 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
15693 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
15697 /* Handle one degenerate form of location expression specially, to
15698 preserve GDB's previous behavior when section offsets are
15699 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
15700 then mark this symbol as LOC_STATIC. */
15702 if (attr_form_is_block (attr
)
15703 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
15704 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
15705 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
15706 && (DW_BLOCK (attr
)->size
15707 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
15709 unsigned int dummy
;
15711 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
15712 SYMBOL_VALUE_ADDRESS (sym
) =
15713 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
15715 SYMBOL_VALUE_ADDRESS (sym
) =
15716 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
15717 SYMBOL_CLASS (sym
) = LOC_STATIC
;
15718 fixup_symbol_section (sym
, objfile
);
15719 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
15720 SYMBOL_SECTION (sym
));
15724 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
15725 expression evaluator, and use LOC_COMPUTED only when necessary
15726 (i.e. when the value of a register or memory location is
15727 referenced, or a thread-local block, etc.). Then again, it might
15728 not be worthwhile. I'm assuming that it isn't unless performance
15729 or memory numbers show me otherwise. */
15731 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
15732 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
15734 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
15735 cu
->has_loclist
= 1;
15738 /* Given a pointer to a DWARF information entry, figure out if we need
15739 to make a symbol table entry for it, and if so, create a new entry
15740 and return a pointer to it.
15741 If TYPE is NULL, determine symbol type from the die, otherwise
15742 used the passed type.
15743 If SPACE is not NULL, use it to hold the new symbol. If it is
15744 NULL, allocate a new symbol on the objfile's obstack. */
15746 static struct symbol
*
15747 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
15748 struct symbol
*space
)
15750 struct objfile
*objfile
= cu
->objfile
;
15751 struct symbol
*sym
= NULL
;
15753 struct attribute
*attr
= NULL
;
15754 struct attribute
*attr2
= NULL
;
15755 CORE_ADDR baseaddr
;
15756 struct pending
**list_to_add
= NULL
;
15758 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
15760 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15762 name
= dwarf2_name (die
, cu
);
15765 const char *linkagename
;
15766 int suppress_add
= 0;
15771 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
15772 OBJSTAT (objfile
, n_syms
++);
15774 /* Cache this symbol's name and the name's demangled form (if any). */
15775 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
15776 linkagename
= dwarf2_physname (name
, die
, cu
);
15777 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
15779 /* Fortran does not have mangling standard and the mangling does differ
15780 between gfortran, iFort etc. */
15781 if (cu
->language
== language_fortran
15782 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
15783 symbol_set_demangled_name (&(sym
->ginfo
),
15784 (char *) dwarf2_full_name (name
, die
, cu
),
15787 /* Default assumptions.
15788 Use the passed type or decode it from the die. */
15789 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
15790 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
15792 SYMBOL_TYPE (sym
) = type
;
15794 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
15795 attr
= dwarf2_attr (die
,
15796 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
15800 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
15803 attr
= dwarf2_attr (die
,
15804 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
15808 int file_index
= DW_UNSND (attr
);
15810 if (cu
->line_header
== NULL
15811 || file_index
> cu
->line_header
->num_file_names
)
15812 complaint (&symfile_complaints
,
15813 _("file index out of range"));
15814 else if (file_index
> 0)
15816 struct file_entry
*fe
;
15818 fe
= &cu
->line_header
->file_names
[file_index
- 1];
15819 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
15826 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
15829 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
15831 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
15832 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
15833 SYMBOL_CLASS (sym
) = LOC_LABEL
;
15834 add_symbol_to_list (sym
, cu
->list_in_scope
);
15836 case DW_TAG_subprogram
:
15837 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
15839 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
15840 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15841 if ((attr2
&& (DW_UNSND (attr2
) != 0))
15842 || cu
->language
== language_ada
)
15844 /* Subprograms marked external are stored as a global symbol.
15845 Ada subprograms, whether marked external or not, are always
15846 stored as a global symbol, because we want to be able to
15847 access them globally. For instance, we want to be able
15848 to break on a nested subprogram without having to
15849 specify the context. */
15850 list_to_add
= &global_symbols
;
15854 list_to_add
= cu
->list_in_scope
;
15857 case DW_TAG_inlined_subroutine
:
15858 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
15860 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
15861 SYMBOL_INLINED (sym
) = 1;
15862 list_to_add
= cu
->list_in_scope
;
15864 case DW_TAG_template_value_param
:
15866 /* Fall through. */
15867 case DW_TAG_constant
:
15868 case DW_TAG_variable
:
15869 case DW_TAG_member
:
15870 /* Compilation with minimal debug info may result in
15871 variables with missing type entries. Change the
15872 misleading `void' type to something sensible. */
15873 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
15875 = objfile_type (objfile
)->nodebug_data_symbol
;
15877 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15878 /* In the case of DW_TAG_member, we should only be called for
15879 static const members. */
15880 if (die
->tag
== DW_TAG_member
)
15882 /* dwarf2_add_field uses die_is_declaration,
15883 so we do the same. */
15884 gdb_assert (die_is_declaration (die
, cu
));
15889 dwarf2_const_value (attr
, sym
, cu
);
15890 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15893 if (attr2
&& (DW_UNSND (attr2
) != 0))
15894 list_to_add
= &global_symbols
;
15896 list_to_add
= cu
->list_in_scope
;
15900 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15903 var_decode_location (attr
, sym
, cu
);
15904 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15906 /* Fortran explicitly imports any global symbols to the local
15907 scope by DW_TAG_common_block. */
15908 if (cu
->language
== language_fortran
&& die
->parent
15909 && die
->parent
->tag
== DW_TAG_common_block
)
15912 if (SYMBOL_CLASS (sym
) == LOC_STATIC
15913 && SYMBOL_VALUE_ADDRESS (sym
) == 0
15914 && !dwarf2_per_objfile
->has_section_at_zero
)
15916 /* When a static variable is eliminated by the linker,
15917 the corresponding debug information is not stripped
15918 out, but the variable address is set to null;
15919 do not add such variables into symbol table. */
15921 else if (attr2
&& (DW_UNSND (attr2
) != 0))
15923 /* Workaround gfortran PR debug/40040 - it uses
15924 DW_AT_location for variables in -fPIC libraries which may
15925 get overriden by other libraries/executable and get
15926 a different address. Resolve it by the minimal symbol
15927 which may come from inferior's executable using copy
15928 relocation. Make this workaround only for gfortran as for
15929 other compilers GDB cannot guess the minimal symbol
15930 Fortran mangling kind. */
15931 if (cu
->language
== language_fortran
&& die
->parent
15932 && die
->parent
->tag
== DW_TAG_module
15934 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
15935 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
15937 /* A variable with DW_AT_external is never static,
15938 but it may be block-scoped. */
15939 list_to_add
= (cu
->list_in_scope
== &file_symbols
15940 ? &global_symbols
: cu
->list_in_scope
);
15943 list_to_add
= cu
->list_in_scope
;
15947 /* We do not know the address of this symbol.
15948 If it is an external symbol and we have type information
15949 for it, enter the symbol as a LOC_UNRESOLVED symbol.
15950 The address of the variable will then be determined from
15951 the minimal symbol table whenever the variable is
15953 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15955 /* Fortran explicitly imports any global symbols to the local
15956 scope by DW_TAG_common_block. */
15957 if (cu
->language
== language_fortran
&& die
->parent
15958 && die
->parent
->tag
== DW_TAG_common_block
)
15960 /* SYMBOL_CLASS doesn't matter here because
15961 read_common_block is going to reset it. */
15963 list_to_add
= cu
->list_in_scope
;
15965 else if (attr2
&& (DW_UNSND (attr2
) != 0)
15966 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
15968 /* A variable with DW_AT_external is never static, but it
15969 may be block-scoped. */
15970 list_to_add
= (cu
->list_in_scope
== &file_symbols
15971 ? &global_symbols
: cu
->list_in_scope
);
15973 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
15975 else if (!die_is_declaration (die
, cu
))
15977 /* Use the default LOC_OPTIMIZED_OUT class. */
15978 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
15980 list_to_add
= cu
->list_in_scope
;
15984 case DW_TAG_formal_parameter
:
15985 /* If we are inside a function, mark this as an argument. If
15986 not, we might be looking at an argument to an inlined function
15987 when we do not have enough information to show inlined frames;
15988 pretend it's a local variable in that case so that the user can
15990 if (context_stack_depth
> 0
15991 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
15992 SYMBOL_IS_ARGUMENT (sym
) = 1;
15993 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15996 var_decode_location (attr
, sym
, cu
);
15998 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
16001 dwarf2_const_value (attr
, sym
, cu
);
16004 list_to_add
= cu
->list_in_scope
;
16006 case DW_TAG_unspecified_parameters
:
16007 /* From varargs functions; gdb doesn't seem to have any
16008 interest in this information, so just ignore it for now.
16011 case DW_TAG_template_type_param
:
16013 /* Fall through. */
16014 case DW_TAG_class_type
:
16015 case DW_TAG_interface_type
:
16016 case DW_TAG_structure_type
:
16017 case DW_TAG_union_type
:
16018 case DW_TAG_set_type
:
16019 case DW_TAG_enumeration_type
:
16020 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
16021 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
16024 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
16025 really ever be static objects: otherwise, if you try
16026 to, say, break of a class's method and you're in a file
16027 which doesn't mention that class, it won't work unless
16028 the check for all static symbols in lookup_symbol_aux
16029 saves you. See the OtherFileClass tests in
16030 gdb.c++/namespace.exp. */
16034 list_to_add
= (cu
->list_in_scope
== &file_symbols
16035 && (cu
->language
== language_cplus
16036 || cu
->language
== language_java
)
16037 ? &global_symbols
: cu
->list_in_scope
);
16039 /* The semantics of C++ state that "struct foo {
16040 ... }" also defines a typedef for "foo". A Java
16041 class declaration also defines a typedef for the
16043 if (cu
->language
== language_cplus
16044 || cu
->language
== language_java
16045 || cu
->language
== language_ada
)
16047 /* The symbol's name is already allocated along
16048 with this objfile, so we don't need to
16049 duplicate it for the type. */
16050 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
16051 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
16056 case DW_TAG_typedef
:
16057 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
16058 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
16059 list_to_add
= cu
->list_in_scope
;
16061 case DW_TAG_base_type
:
16062 case DW_TAG_subrange_type
:
16063 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
16064 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
16065 list_to_add
= cu
->list_in_scope
;
16067 case DW_TAG_enumerator
:
16068 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
16071 dwarf2_const_value (attr
, sym
, cu
);
16074 /* NOTE: carlton/2003-11-10: See comment above in the
16075 DW_TAG_class_type, etc. block. */
16077 list_to_add
= (cu
->list_in_scope
== &file_symbols
16078 && (cu
->language
== language_cplus
16079 || cu
->language
== language_java
)
16080 ? &global_symbols
: cu
->list_in_scope
);
16083 case DW_TAG_namespace
:
16084 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
16085 list_to_add
= &global_symbols
;
16087 case DW_TAG_common_block
:
16088 SYMBOL_CLASS (sym
) = LOC_STATIC
;
16089 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
16090 add_symbol_to_list (sym
, cu
->list_in_scope
);
16093 /* Not a tag we recognize. Hopefully we aren't processing
16094 trash data, but since we must specifically ignore things
16095 we don't recognize, there is nothing else we should do at
16097 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
16098 dwarf_tag_name (die
->tag
));
16104 sym
->hash_next
= objfile
->template_symbols
;
16105 objfile
->template_symbols
= sym
;
16106 list_to_add
= NULL
;
16109 if (list_to_add
!= NULL
)
16110 add_symbol_to_list (sym
, list_to_add
);
16112 /* For the benefit of old versions of GCC, check for anonymous
16113 namespaces based on the demangled name. */
16114 if (!processing_has_namespace_info
16115 && cu
->language
== language_cplus
)
16116 cp_scan_for_anonymous_namespaces (sym
, objfile
);
16121 /* A wrapper for new_symbol_full that always allocates a new symbol. */
16123 static struct symbol
*
16124 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
16126 return new_symbol_full (die
, type
, cu
, NULL
);
16129 /* Given an attr with a DW_FORM_dataN value in host byte order,
16130 zero-extend it as appropriate for the symbol's type. The DWARF
16131 standard (v4) is not entirely clear about the meaning of using
16132 DW_FORM_dataN for a constant with a signed type, where the type is
16133 wider than the data. The conclusion of a discussion on the DWARF
16134 list was that this is unspecified. We choose to always zero-extend
16135 because that is the interpretation long in use by GCC. */
16138 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
16139 const char *name
, struct obstack
*obstack
,
16140 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
16142 struct objfile
*objfile
= cu
->objfile
;
16143 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
16144 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
16145 LONGEST l
= DW_UNSND (attr
);
16147 if (bits
< sizeof (*value
) * 8)
16149 l
&= ((LONGEST
) 1 << bits
) - 1;
16152 else if (bits
== sizeof (*value
) * 8)
16156 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
16157 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
16164 /* Read a constant value from an attribute. Either set *VALUE, or if
16165 the value does not fit in *VALUE, set *BYTES - either already
16166 allocated on the objfile obstack, or newly allocated on OBSTACK,
16167 or, set *BATON, if we translated the constant to a location
16171 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
16172 const char *name
, struct obstack
*obstack
,
16173 struct dwarf2_cu
*cu
,
16174 LONGEST
*value
, gdb_byte
**bytes
,
16175 struct dwarf2_locexpr_baton
**baton
)
16177 struct objfile
*objfile
= cu
->objfile
;
16178 struct comp_unit_head
*cu_header
= &cu
->header
;
16179 struct dwarf_block
*blk
;
16180 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
16181 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
16187 switch (attr
->form
)
16190 case DW_FORM_GNU_addr_index
:
16194 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
16195 dwarf2_const_value_length_mismatch_complaint (name
,
16196 cu_header
->addr_size
,
16197 TYPE_LENGTH (type
));
16198 /* Symbols of this form are reasonably rare, so we just
16199 piggyback on the existing location code rather than writing
16200 a new implementation of symbol_computed_ops. */
16201 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
16202 sizeof (struct dwarf2_locexpr_baton
));
16203 (*baton
)->per_cu
= cu
->per_cu
;
16204 gdb_assert ((*baton
)->per_cu
);
16206 (*baton
)->size
= 2 + cu_header
->addr_size
;
16207 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
16208 (*baton
)->data
= data
;
16210 data
[0] = DW_OP_addr
;
16211 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
16212 byte_order
, DW_ADDR (attr
));
16213 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
16216 case DW_FORM_string
:
16218 case DW_FORM_GNU_str_index
:
16219 case DW_FORM_GNU_strp_alt
:
16220 /* DW_STRING is already allocated on the objfile obstack, point
16222 *bytes
= (gdb_byte
*) DW_STRING (attr
);
16224 case DW_FORM_block1
:
16225 case DW_FORM_block2
:
16226 case DW_FORM_block4
:
16227 case DW_FORM_block
:
16228 case DW_FORM_exprloc
:
16229 blk
= DW_BLOCK (attr
);
16230 if (TYPE_LENGTH (type
) != blk
->size
)
16231 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
16232 TYPE_LENGTH (type
));
16233 *bytes
= blk
->data
;
16236 /* The DW_AT_const_value attributes are supposed to carry the
16237 symbol's value "represented as it would be on the target
16238 architecture." By the time we get here, it's already been
16239 converted to host endianness, so we just need to sign- or
16240 zero-extend it as appropriate. */
16241 case DW_FORM_data1
:
16242 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16243 obstack
, cu
, value
, 8);
16245 case DW_FORM_data2
:
16246 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16247 obstack
, cu
, value
, 16);
16249 case DW_FORM_data4
:
16250 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16251 obstack
, cu
, value
, 32);
16253 case DW_FORM_data8
:
16254 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16255 obstack
, cu
, value
, 64);
16258 case DW_FORM_sdata
:
16259 *value
= DW_SND (attr
);
16262 case DW_FORM_udata
:
16263 *value
= DW_UNSND (attr
);
16267 complaint (&symfile_complaints
,
16268 _("unsupported const value attribute form: '%s'"),
16269 dwarf_form_name (attr
->form
));
16276 /* Copy constant value from an attribute to a symbol. */
16279 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
16280 struct dwarf2_cu
*cu
)
16282 struct objfile
*objfile
= cu
->objfile
;
16283 struct comp_unit_head
*cu_header
= &cu
->header
;
16286 struct dwarf2_locexpr_baton
*baton
;
16288 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
16289 SYMBOL_PRINT_NAME (sym
),
16290 &objfile
->objfile_obstack
, cu
,
16291 &value
, &bytes
, &baton
);
16295 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
16296 SYMBOL_LOCATION_BATON (sym
) = baton
;
16297 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
16299 else if (bytes
!= NULL
)
16301 SYMBOL_VALUE_BYTES (sym
) = bytes
;
16302 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
16306 SYMBOL_VALUE (sym
) = value
;
16307 SYMBOL_CLASS (sym
) = LOC_CONST
;
16311 /* Return the type of the die in question using its DW_AT_type attribute. */
16313 static struct type
*
16314 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16316 struct attribute
*type_attr
;
16318 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16321 /* A missing DW_AT_type represents a void type. */
16322 return objfile_type (cu
->objfile
)->builtin_void
;
16325 return lookup_die_type (die
, type_attr
, cu
);
16328 /* True iff CU's producer generates GNAT Ada auxiliary information
16329 that allows to find parallel types through that information instead
16330 of having to do expensive parallel lookups by type name. */
16333 need_gnat_info (struct dwarf2_cu
*cu
)
16335 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
16336 of GNAT produces this auxiliary information, without any indication
16337 that it is produced. Part of enhancing the FSF version of GNAT
16338 to produce that information will be to put in place an indicator
16339 that we can use in order to determine whether the descriptive type
16340 info is available or not. One suggestion that has been made is
16341 to use a new attribute, attached to the CU die. For now, assume
16342 that the descriptive type info is not available. */
16346 /* Return the auxiliary type of the die in question using its
16347 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
16348 attribute is not present. */
16350 static struct type
*
16351 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16353 struct attribute
*type_attr
;
16355 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
16359 return lookup_die_type (die
, type_attr
, cu
);
16362 /* If DIE has a descriptive_type attribute, then set the TYPE's
16363 descriptive type accordingly. */
16366 set_descriptive_type (struct type
*type
, struct die_info
*die
,
16367 struct dwarf2_cu
*cu
)
16369 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
16371 if (descriptive_type
)
16373 ALLOCATE_GNAT_AUX_TYPE (type
);
16374 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
16378 /* Return the containing type of the die in question using its
16379 DW_AT_containing_type attribute. */
16381 static struct type
*
16382 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16384 struct attribute
*type_attr
;
16386 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
16388 error (_("Dwarf Error: Problem turning containing type into gdb type "
16389 "[in module %s]"), cu
->objfile
->name
);
16391 return lookup_die_type (die
, type_attr
, cu
);
16394 /* Look up the type of DIE in CU using its type attribute ATTR.
16395 If there is no type substitute an error marker. */
16397 static struct type
*
16398 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
16399 struct dwarf2_cu
*cu
)
16401 struct objfile
*objfile
= cu
->objfile
;
16402 struct type
*this_type
;
16404 /* First see if we have it cached. */
16406 if (attr
->form
== DW_FORM_GNU_ref_alt
)
16408 struct dwarf2_per_cu_data
*per_cu
;
16409 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
16411 per_cu
= dwarf2_find_containing_comp_unit (offset
, 1, cu
->objfile
);
16412 this_type
= get_die_type_at_offset (offset
, per_cu
);
16414 else if (is_ref_attr (attr
))
16416 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
16418 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
16420 else if (attr
->form
== DW_FORM_ref_sig8
)
16422 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
16424 /* sig_type will be NULL if the signatured type is missing from
16426 if (sig_type
== NULL
)
16427 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
16428 "at 0x%x [in module %s]"),
16429 die
->offset
.sect_off
, objfile
->name
);
16431 gdb_assert (sig_type
->per_cu
.is_debug_types
);
16432 /* If we haven't filled in type_offset_in_section yet, then we
16433 haven't read the type in yet. */
16435 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
16438 get_die_type_at_offset (sig_type
->type_offset_in_section
,
16439 &sig_type
->per_cu
);
16444 dump_die_for_error (die
);
16445 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
16446 dwarf_attr_name (attr
->name
), objfile
->name
);
16449 /* If not cached we need to read it in. */
16451 if (this_type
== NULL
)
16453 struct die_info
*type_die
;
16454 struct dwarf2_cu
*type_cu
= cu
;
16456 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
16457 /* If we found the type now, it's probably because the type came
16458 from an inter-CU reference and the type's CU got expanded before
16460 this_type
= get_die_type (type_die
, type_cu
);
16461 if (this_type
== NULL
)
16462 this_type
= read_type_die_1 (type_die
, type_cu
);
16465 /* If we still don't have a type use an error marker. */
16467 if (this_type
== NULL
)
16469 char *message
, *saved
;
16471 /* read_type_die already issued a complaint. */
16472 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
16474 cu
->header
.offset
.sect_off
,
16475 die
->offset
.sect_off
);
16476 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
16477 message
, strlen (message
));
16480 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
16486 /* Return the type in DIE, CU.
16487 Returns NULL for invalid types.
16489 This first does a lookup in the appropriate type_hash table,
16490 and only reads the die in if necessary.
16492 NOTE: This can be called when reading in partial or full symbols. */
16494 static struct type
*
16495 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
16497 struct type
*this_type
;
16499 this_type
= get_die_type (die
, cu
);
16503 return read_type_die_1 (die
, cu
);
16506 /* Read the type in DIE, CU.
16507 Returns NULL for invalid types. */
16509 static struct type
*
16510 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
16512 struct type
*this_type
= NULL
;
16516 case DW_TAG_class_type
:
16517 case DW_TAG_interface_type
:
16518 case DW_TAG_structure_type
:
16519 case DW_TAG_union_type
:
16520 this_type
= read_structure_type (die
, cu
);
16522 case DW_TAG_enumeration_type
:
16523 this_type
= read_enumeration_type (die
, cu
);
16525 case DW_TAG_subprogram
:
16526 case DW_TAG_subroutine_type
:
16527 case DW_TAG_inlined_subroutine
:
16528 this_type
= read_subroutine_type (die
, cu
);
16530 case DW_TAG_array_type
:
16531 this_type
= read_array_type (die
, cu
);
16533 case DW_TAG_set_type
:
16534 this_type
= read_set_type (die
, cu
);
16536 case DW_TAG_pointer_type
:
16537 this_type
= read_tag_pointer_type (die
, cu
);
16539 case DW_TAG_ptr_to_member_type
:
16540 this_type
= read_tag_ptr_to_member_type (die
, cu
);
16542 case DW_TAG_reference_type
:
16543 this_type
= read_tag_reference_type (die
, cu
);
16545 case DW_TAG_const_type
:
16546 this_type
= read_tag_const_type (die
, cu
);
16548 case DW_TAG_volatile_type
:
16549 this_type
= read_tag_volatile_type (die
, cu
);
16551 case DW_TAG_string_type
:
16552 this_type
= read_tag_string_type (die
, cu
);
16554 case DW_TAG_typedef
:
16555 this_type
= read_typedef (die
, cu
);
16557 case DW_TAG_subrange_type
:
16558 this_type
= read_subrange_type (die
, cu
);
16560 case DW_TAG_base_type
:
16561 this_type
= read_base_type (die
, cu
);
16563 case DW_TAG_unspecified_type
:
16564 this_type
= read_unspecified_type (die
, cu
);
16566 case DW_TAG_namespace
:
16567 this_type
= read_namespace_type (die
, cu
);
16569 case DW_TAG_module
:
16570 this_type
= read_module_type (die
, cu
);
16573 complaint (&symfile_complaints
,
16574 _("unexpected tag in read_type_die: '%s'"),
16575 dwarf_tag_name (die
->tag
));
16582 /* See if we can figure out if the class lives in a namespace. We do
16583 this by looking for a member function; its demangled name will
16584 contain namespace info, if there is any.
16585 Return the computed name or NULL.
16586 Space for the result is allocated on the objfile's obstack.
16587 This is the full-die version of guess_partial_die_structure_name.
16588 In this case we know DIE has no useful parent. */
16591 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
16593 struct die_info
*spec_die
;
16594 struct dwarf2_cu
*spec_cu
;
16595 struct die_info
*child
;
16598 spec_die
= die_specification (die
, &spec_cu
);
16599 if (spec_die
!= NULL
)
16605 for (child
= die
->child
;
16607 child
= child
->sibling
)
16609 if (child
->tag
== DW_TAG_subprogram
)
16611 struct attribute
*attr
;
16613 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
16615 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
16619 = language_class_name_from_physname (cu
->language_defn
,
16623 if (actual_name
!= NULL
)
16625 char *die_name
= dwarf2_name (die
, cu
);
16627 if (die_name
!= NULL
16628 && strcmp (die_name
, actual_name
) != 0)
16630 /* Strip off the class name from the full name.
16631 We want the prefix. */
16632 int die_name_len
= strlen (die_name
);
16633 int actual_name_len
= strlen (actual_name
);
16635 /* Test for '::' as a sanity check. */
16636 if (actual_name_len
> die_name_len
+ 2
16637 && actual_name
[actual_name_len
16638 - die_name_len
- 1] == ':')
16640 obsavestring (actual_name
,
16641 actual_name_len
- die_name_len
- 2,
16642 &cu
->objfile
->objfile_obstack
);
16645 xfree (actual_name
);
16654 /* GCC might emit a nameless typedef that has a linkage name. Determine the
16655 prefix part in such case. See
16656 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16659 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
16661 struct attribute
*attr
;
16664 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
16665 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
16668 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
16669 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
16672 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
16674 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
16675 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
16678 /* dwarf2_name had to be already called. */
16679 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
16681 /* Strip the base name, keep any leading namespaces/classes. */
16682 base
= strrchr (DW_STRING (attr
), ':');
16683 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
16686 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
16687 &cu
->objfile
->objfile_obstack
);
16690 /* Return the name of the namespace/class that DIE is defined within,
16691 or "" if we can't tell. The caller should not xfree the result.
16693 For example, if we're within the method foo() in the following
16703 then determine_prefix on foo's die will return "N::C". */
16705 static const char *
16706 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
16708 struct die_info
*parent
, *spec_die
;
16709 struct dwarf2_cu
*spec_cu
;
16710 struct type
*parent_type
;
16713 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
16714 && cu
->language
!= language_fortran
)
16717 retval
= anonymous_struct_prefix (die
, cu
);
16721 /* We have to be careful in the presence of DW_AT_specification.
16722 For example, with GCC 3.4, given the code
16726 // Definition of N::foo.
16730 then we'll have a tree of DIEs like this:
16732 1: DW_TAG_compile_unit
16733 2: DW_TAG_namespace // N
16734 3: DW_TAG_subprogram // declaration of N::foo
16735 4: DW_TAG_subprogram // definition of N::foo
16736 DW_AT_specification // refers to die #3
16738 Thus, when processing die #4, we have to pretend that we're in
16739 the context of its DW_AT_specification, namely the contex of die
16742 spec_die
= die_specification (die
, &spec_cu
);
16743 if (spec_die
== NULL
)
16744 parent
= die
->parent
;
16747 parent
= spec_die
->parent
;
16751 if (parent
== NULL
)
16753 else if (parent
->building_fullname
)
16756 const char *parent_name
;
16758 /* It has been seen on RealView 2.2 built binaries,
16759 DW_TAG_template_type_param types actually _defined_ as
16760 children of the parent class:
16763 template class <class Enum> Class{};
16764 Class<enum E> class_e;
16766 1: DW_TAG_class_type (Class)
16767 2: DW_TAG_enumeration_type (E)
16768 3: DW_TAG_enumerator (enum1:0)
16769 3: DW_TAG_enumerator (enum2:1)
16771 2: DW_TAG_template_type_param
16772 DW_AT_type DW_FORM_ref_udata (E)
16774 Besides being broken debug info, it can put GDB into an
16775 infinite loop. Consider:
16777 When we're building the full name for Class<E>, we'll start
16778 at Class, and go look over its template type parameters,
16779 finding E. We'll then try to build the full name of E, and
16780 reach here. We're now trying to build the full name of E,
16781 and look over the parent DIE for containing scope. In the
16782 broken case, if we followed the parent DIE of E, we'd again
16783 find Class, and once again go look at its template type
16784 arguments, etc., etc. Simply don't consider such parent die
16785 as source-level parent of this die (it can't be, the language
16786 doesn't allow it), and break the loop here. */
16787 name
= dwarf2_name (die
, cu
);
16788 parent_name
= dwarf2_name (parent
, cu
);
16789 complaint (&symfile_complaints
,
16790 _("template param type '%s' defined within parent '%s'"),
16791 name
? name
: "<unknown>",
16792 parent_name
? parent_name
: "<unknown>");
16796 switch (parent
->tag
)
16798 case DW_TAG_namespace
:
16799 parent_type
= read_type_die (parent
, cu
);
16800 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
16801 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
16802 Work around this problem here. */
16803 if (cu
->language
== language_cplus
16804 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
16806 /* We give a name to even anonymous namespaces. */
16807 return TYPE_TAG_NAME (parent_type
);
16808 case DW_TAG_class_type
:
16809 case DW_TAG_interface_type
:
16810 case DW_TAG_structure_type
:
16811 case DW_TAG_union_type
:
16812 case DW_TAG_module
:
16813 parent_type
= read_type_die (parent
, cu
);
16814 if (TYPE_TAG_NAME (parent_type
) != NULL
)
16815 return TYPE_TAG_NAME (parent_type
);
16817 /* An anonymous structure is only allowed non-static data
16818 members; no typedefs, no member functions, et cetera.
16819 So it does not need a prefix. */
16821 case DW_TAG_compile_unit
:
16822 case DW_TAG_partial_unit
:
16823 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
16824 if (cu
->language
== language_cplus
16825 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
16826 && die
->child
!= NULL
16827 && (die
->tag
== DW_TAG_class_type
16828 || die
->tag
== DW_TAG_structure_type
16829 || die
->tag
== DW_TAG_union_type
))
16831 char *name
= guess_full_die_structure_name (die
, cu
);
16837 return determine_prefix (parent
, cu
);
16841 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
16842 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
16843 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
16844 an obconcat, otherwise allocate storage for the result. The CU argument is
16845 used to determine the language and hence, the appropriate separator. */
16847 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
16850 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
16851 int physname
, struct dwarf2_cu
*cu
)
16853 const char *lead
= "";
16856 if (suffix
== NULL
|| suffix
[0] == '\0'
16857 || prefix
== NULL
|| prefix
[0] == '\0')
16859 else if (cu
->language
== language_java
)
16861 else if (cu
->language
== language_fortran
&& physname
)
16863 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
16864 DW_AT_MIPS_linkage_name is preferred and used instead. */
16872 if (prefix
== NULL
)
16874 if (suffix
== NULL
)
16880 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
16882 strcpy (retval
, lead
);
16883 strcat (retval
, prefix
);
16884 strcat (retval
, sep
);
16885 strcat (retval
, suffix
);
16890 /* We have an obstack. */
16891 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
16895 /* Return sibling of die, NULL if no sibling. */
16897 static struct die_info
*
16898 sibling_die (struct die_info
*die
)
16900 return die
->sibling
;
16903 /* Get name of a die, return NULL if not found. */
16906 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
16907 struct obstack
*obstack
)
16909 if (name
&& cu
->language
== language_cplus
)
16911 char *canon_name
= cp_canonicalize_string (name
);
16913 if (canon_name
!= NULL
)
16915 if (strcmp (canon_name
, name
) != 0)
16916 name
= obsavestring (canon_name
, strlen (canon_name
),
16918 xfree (canon_name
);
16925 /* Get name of a die, return NULL if not found. */
16928 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
16930 struct attribute
*attr
;
16932 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
16933 if ((!attr
|| !DW_STRING (attr
))
16934 && die
->tag
!= DW_TAG_class_type
16935 && die
->tag
!= DW_TAG_interface_type
16936 && die
->tag
!= DW_TAG_structure_type
16937 && die
->tag
!= DW_TAG_union_type
)
16942 case DW_TAG_compile_unit
:
16943 case DW_TAG_partial_unit
:
16944 /* Compilation units have a DW_AT_name that is a filename, not
16945 a source language identifier. */
16946 case DW_TAG_enumeration_type
:
16947 case DW_TAG_enumerator
:
16948 /* These tags always have simple identifiers already; no need
16949 to canonicalize them. */
16950 return DW_STRING (attr
);
16952 case DW_TAG_subprogram
:
16953 /* Java constructors will all be named "<init>", so return
16954 the class name when we see this special case. */
16955 if (cu
->language
== language_java
16956 && DW_STRING (attr
) != NULL
16957 && strcmp (DW_STRING (attr
), "<init>") == 0)
16959 struct dwarf2_cu
*spec_cu
= cu
;
16960 struct die_info
*spec_die
;
16962 /* GCJ will output '<init>' for Java constructor names.
16963 For this special case, return the name of the parent class. */
16965 /* GCJ may output suprogram DIEs with AT_specification set.
16966 If so, use the name of the specified DIE. */
16967 spec_die
= die_specification (die
, &spec_cu
);
16968 if (spec_die
!= NULL
)
16969 return dwarf2_name (spec_die
, spec_cu
);
16974 if (die
->tag
== DW_TAG_class_type
)
16975 return dwarf2_name (die
, cu
);
16977 while (die
->tag
!= DW_TAG_compile_unit
16978 && die
->tag
!= DW_TAG_partial_unit
);
16982 case DW_TAG_class_type
:
16983 case DW_TAG_interface_type
:
16984 case DW_TAG_structure_type
:
16985 case DW_TAG_union_type
:
16986 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
16987 structures or unions. These were of the form "._%d" in GCC 4.1,
16988 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
16989 and GCC 4.4. We work around this problem by ignoring these. */
16990 if (attr
&& DW_STRING (attr
)
16991 && (strncmp (DW_STRING (attr
), "._", 2) == 0
16992 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
16995 /* GCC might emit a nameless typedef that has a linkage name. See
16996 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16997 if (!attr
|| DW_STRING (attr
) == NULL
)
16999 char *demangled
= NULL
;
17001 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
17003 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
17005 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
17008 /* Avoid demangling DW_STRING (attr) the second time on a second
17009 call for the same DIE. */
17010 if (!DW_STRING_IS_CANONICAL (attr
))
17011 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
17017 /* FIXME: we already did this for the partial symbol... */
17018 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
17019 &cu
->objfile
->objfile_obstack
);
17020 DW_STRING_IS_CANONICAL (attr
) = 1;
17023 /* Strip any leading namespaces/classes, keep only the base name.
17024 DW_AT_name for named DIEs does not contain the prefixes. */
17025 base
= strrchr (DW_STRING (attr
), ':');
17026 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
17029 return DW_STRING (attr
);
17038 if (!DW_STRING_IS_CANONICAL (attr
))
17041 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
17042 &cu
->objfile
->objfile_obstack
);
17043 DW_STRING_IS_CANONICAL (attr
) = 1;
17045 return DW_STRING (attr
);
17048 /* Return the die that this die in an extension of, or NULL if there
17049 is none. *EXT_CU is the CU containing DIE on input, and the CU
17050 containing the return value on output. */
17052 static struct die_info
*
17053 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
17055 struct attribute
*attr
;
17057 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
17061 return follow_die_ref (die
, attr
, ext_cu
);
17064 /* Convert a DIE tag into its string name. */
17066 static const char *
17067 dwarf_tag_name (unsigned tag
)
17069 const char *name
= get_DW_TAG_name (tag
);
17072 return "DW_TAG_<unknown>";
17077 /* Convert a DWARF attribute code into its string name. */
17079 static const char *
17080 dwarf_attr_name (unsigned attr
)
17084 #ifdef MIPS /* collides with DW_AT_HP_block_index */
17085 if (attr
== DW_AT_MIPS_fde
)
17086 return "DW_AT_MIPS_fde";
17088 if (attr
== DW_AT_HP_block_index
)
17089 return "DW_AT_HP_block_index";
17092 name
= get_DW_AT_name (attr
);
17095 return "DW_AT_<unknown>";
17100 /* Convert a DWARF value form code into its string name. */
17102 static const char *
17103 dwarf_form_name (unsigned form
)
17105 const char *name
= get_DW_FORM_name (form
);
17108 return "DW_FORM_<unknown>";
17114 dwarf_bool_name (unsigned mybool
)
17122 /* Convert a DWARF type code into its string name. */
17124 static const char *
17125 dwarf_type_encoding_name (unsigned enc
)
17127 const char *name
= get_DW_ATE_name (enc
);
17130 return "DW_ATE_<unknown>";
17136 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
17140 print_spaces (indent
, f
);
17141 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
17142 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
17144 if (die
->parent
!= NULL
)
17146 print_spaces (indent
, f
);
17147 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
17148 die
->parent
->offset
.sect_off
);
17151 print_spaces (indent
, f
);
17152 fprintf_unfiltered (f
, " has children: %s\n",
17153 dwarf_bool_name (die
->child
!= NULL
));
17155 print_spaces (indent
, f
);
17156 fprintf_unfiltered (f
, " attributes:\n");
17158 for (i
= 0; i
< die
->num_attrs
; ++i
)
17160 print_spaces (indent
, f
);
17161 fprintf_unfiltered (f
, " %s (%s) ",
17162 dwarf_attr_name (die
->attrs
[i
].name
),
17163 dwarf_form_name (die
->attrs
[i
].form
));
17165 switch (die
->attrs
[i
].form
)
17168 case DW_FORM_GNU_addr_index
:
17169 fprintf_unfiltered (f
, "address: ");
17170 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
17172 case DW_FORM_block2
:
17173 case DW_FORM_block4
:
17174 case DW_FORM_block
:
17175 case DW_FORM_block1
:
17176 fprintf_unfiltered (f
, "block: size %s",
17177 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
17179 case DW_FORM_exprloc
:
17180 fprintf_unfiltered (f
, "expression: size %s",
17181 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
17183 case DW_FORM_ref_addr
:
17184 fprintf_unfiltered (f
, "ref address: ");
17185 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
17187 case DW_FORM_GNU_ref_alt
:
17188 fprintf_unfiltered (f
, "alt ref address: ");
17189 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
17195 case DW_FORM_ref_udata
:
17196 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
17197 (long) (DW_UNSND (&die
->attrs
[i
])));
17199 case DW_FORM_data1
:
17200 case DW_FORM_data2
:
17201 case DW_FORM_data4
:
17202 case DW_FORM_data8
:
17203 case DW_FORM_udata
:
17204 case DW_FORM_sdata
:
17205 fprintf_unfiltered (f
, "constant: %s",
17206 pulongest (DW_UNSND (&die
->attrs
[i
])));
17208 case DW_FORM_sec_offset
:
17209 fprintf_unfiltered (f
, "section offset: %s",
17210 pulongest (DW_UNSND (&die
->attrs
[i
])));
17212 case DW_FORM_ref_sig8
:
17213 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
17214 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
17215 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
17217 fprintf_unfiltered (f
, "signatured type, offset: unknown");
17219 case DW_FORM_string
:
17221 case DW_FORM_GNU_str_index
:
17222 case DW_FORM_GNU_strp_alt
:
17223 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
17224 DW_STRING (&die
->attrs
[i
])
17225 ? DW_STRING (&die
->attrs
[i
]) : "",
17226 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
17229 if (DW_UNSND (&die
->attrs
[i
]))
17230 fprintf_unfiltered (f
, "flag: TRUE");
17232 fprintf_unfiltered (f
, "flag: FALSE");
17234 case DW_FORM_flag_present
:
17235 fprintf_unfiltered (f
, "flag: TRUE");
17237 case DW_FORM_indirect
:
17238 /* The reader will have reduced the indirect form to
17239 the "base form" so this form should not occur. */
17240 fprintf_unfiltered (f
,
17241 "unexpected attribute form: DW_FORM_indirect");
17244 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
17245 die
->attrs
[i
].form
);
17248 fprintf_unfiltered (f
, "\n");
17253 dump_die_for_error (struct die_info
*die
)
17255 dump_die_shallow (gdb_stderr
, 0, die
);
17259 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
17261 int indent
= level
* 4;
17263 gdb_assert (die
!= NULL
);
17265 if (level
>= max_level
)
17268 dump_die_shallow (f
, indent
, die
);
17270 if (die
->child
!= NULL
)
17272 print_spaces (indent
, f
);
17273 fprintf_unfiltered (f
, " Children:");
17274 if (level
+ 1 < max_level
)
17276 fprintf_unfiltered (f
, "\n");
17277 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
17281 fprintf_unfiltered (f
,
17282 " [not printed, max nesting level reached]\n");
17286 if (die
->sibling
!= NULL
&& level
> 0)
17288 dump_die_1 (f
, level
, max_level
, die
->sibling
);
17292 /* This is called from the pdie macro in gdbinit.in.
17293 It's not static so gcc will keep a copy callable from gdb. */
17296 dump_die (struct die_info
*die
, int max_level
)
17298 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
17302 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
17306 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
17312 /* DW_ADDR is always stored already as sect_offset; despite for the forms
17313 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
17316 is_ref_attr (struct attribute
*attr
)
17318 switch (attr
->form
)
17320 case DW_FORM_ref_addr
:
17325 case DW_FORM_ref_udata
:
17326 case DW_FORM_GNU_ref_alt
:
17333 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
17337 dwarf2_get_ref_die_offset (struct attribute
*attr
)
17339 sect_offset retval
= { DW_UNSND (attr
) };
17341 if (is_ref_attr (attr
))
17344 retval
.sect_off
= 0;
17345 complaint (&symfile_complaints
,
17346 _("unsupported die ref attribute form: '%s'"),
17347 dwarf_form_name (attr
->form
));
17351 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
17352 * the value held by the attribute is not constant. */
17355 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
17357 if (attr
->form
== DW_FORM_sdata
)
17358 return DW_SND (attr
);
17359 else if (attr
->form
== DW_FORM_udata
17360 || attr
->form
== DW_FORM_data1
17361 || attr
->form
== DW_FORM_data2
17362 || attr
->form
== DW_FORM_data4
17363 || attr
->form
== DW_FORM_data8
)
17364 return DW_UNSND (attr
);
17367 complaint (&symfile_complaints
,
17368 _("Attribute value is not a constant (%s)"),
17369 dwarf_form_name (attr
->form
));
17370 return default_value
;
17374 /* Follow reference or signature attribute ATTR of SRC_DIE.
17375 On entry *REF_CU is the CU of SRC_DIE.
17376 On exit *REF_CU is the CU of the result. */
17378 static struct die_info
*
17379 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
17380 struct dwarf2_cu
**ref_cu
)
17382 struct die_info
*die
;
17384 if (is_ref_attr (attr
))
17385 die
= follow_die_ref (src_die
, attr
, ref_cu
);
17386 else if (attr
->form
== DW_FORM_ref_sig8
)
17387 die
= follow_die_sig (src_die
, attr
, ref_cu
);
17390 dump_die_for_error (src_die
);
17391 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
17392 (*ref_cu
)->objfile
->name
);
17398 /* Follow reference OFFSET.
17399 On entry *REF_CU is the CU of the source die referencing OFFSET.
17400 On exit *REF_CU is the CU of the result.
17401 Returns NULL if OFFSET is invalid. */
17403 static struct die_info
*
17404 follow_die_offset (sect_offset offset
, int offset_in_dwz
,
17405 struct dwarf2_cu
**ref_cu
)
17407 struct die_info temp_die
;
17408 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
17410 gdb_assert (cu
->per_cu
!= NULL
);
17414 if (cu
->per_cu
->is_debug_types
)
17416 /* .debug_types CUs cannot reference anything outside their CU.
17417 If they need to, they have to reference a signatured type via
17418 DW_FORM_ref_sig8. */
17419 if (! offset_in_cu_p (&cu
->header
, offset
))
17422 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
17423 || ! offset_in_cu_p (&cu
->header
, offset
))
17425 struct dwarf2_per_cu_data
*per_cu
;
17427 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
17430 /* If necessary, add it to the queue and load its DIEs. */
17431 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
17432 load_full_comp_unit (per_cu
, cu
->language
);
17434 target_cu
= per_cu
->cu
;
17436 else if (cu
->dies
== NULL
)
17438 /* We're loading full DIEs during partial symbol reading. */
17439 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
17440 load_full_comp_unit (cu
->per_cu
, language_minimal
);
17443 *ref_cu
= target_cu
;
17444 temp_die
.offset
= offset
;
17445 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
17448 /* Follow reference attribute ATTR of SRC_DIE.
17449 On entry *REF_CU is the CU of SRC_DIE.
17450 On exit *REF_CU is the CU of the result. */
17452 static struct die_info
*
17453 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
17454 struct dwarf2_cu
**ref_cu
)
17456 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
17457 struct dwarf2_cu
*cu
= *ref_cu
;
17458 struct die_info
*die
;
17460 die
= follow_die_offset (offset
,
17461 (attr
->form
== DW_FORM_GNU_ref_alt
17462 || cu
->per_cu
->is_dwz
),
17465 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
17466 "at 0x%x [in module %s]"),
17467 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
17472 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
17473 Returned value is intended for DW_OP_call*. Returned
17474 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
17476 struct dwarf2_locexpr_baton
17477 dwarf2_fetch_die_loc_sect_off (sect_offset offset
,
17478 struct dwarf2_per_cu_data
*per_cu
,
17479 CORE_ADDR (*get_frame_pc
) (void *baton
),
17482 struct dwarf2_cu
*cu
;
17483 struct die_info
*die
;
17484 struct attribute
*attr
;
17485 struct dwarf2_locexpr_baton retval
;
17487 dw2_setup (per_cu
->objfile
);
17489 if (per_cu
->cu
== NULL
)
17493 die
= follow_die_offset (offset
, per_cu
->is_dwz
, &cu
);
17495 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
17496 offset
.sect_off
, per_cu
->objfile
->name
);
17498 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17501 /* DWARF: "If there is no such attribute, then there is no effect.".
17502 DATA is ignored if SIZE is 0. */
17504 retval
.data
= NULL
;
17507 else if (attr_form_is_section_offset (attr
))
17509 struct dwarf2_loclist_baton loclist_baton
;
17510 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
17513 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
17515 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
17517 retval
.size
= size
;
17521 if (!attr_form_is_block (attr
))
17522 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
17523 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
17524 offset
.sect_off
, per_cu
->objfile
->name
);
17526 retval
.data
= DW_BLOCK (attr
)->data
;
17527 retval
.size
= DW_BLOCK (attr
)->size
;
17529 retval
.per_cu
= cu
->per_cu
;
17531 age_cached_comp_units ();
17536 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
17539 struct dwarf2_locexpr_baton
17540 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
17541 struct dwarf2_per_cu_data
*per_cu
,
17542 CORE_ADDR (*get_frame_pc
) (void *baton
),
17545 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
17547 return dwarf2_fetch_die_loc_sect_off (offset
, per_cu
, get_frame_pc
, baton
);
17550 /* Return the type of the DIE at DIE_OFFSET in the CU named by
17554 dwarf2_get_die_type (cu_offset die_offset
,
17555 struct dwarf2_per_cu_data
*per_cu
)
17557 sect_offset die_offset_sect
;
17559 dw2_setup (per_cu
->objfile
);
17561 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
17562 return get_die_type_at_offset (die_offset_sect
, per_cu
);
17565 /* Follow the signature attribute ATTR in SRC_DIE.
17566 On entry *REF_CU is the CU of SRC_DIE.
17567 On exit *REF_CU is the CU of the result. */
17569 static struct die_info
*
17570 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
17571 struct dwarf2_cu
**ref_cu
)
17573 struct objfile
*objfile
= (*ref_cu
)->objfile
;
17574 struct die_info temp_die
;
17575 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
17576 struct dwarf2_cu
*sig_cu
;
17577 struct die_info
*die
;
17579 /* sig_type will be NULL if the signatured type is missing from
17581 if (sig_type
== NULL
)
17582 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
17583 "at 0x%x [in module %s]"),
17584 src_die
->offset
.sect_off
, objfile
->name
);
17586 /* If necessary, add it to the queue and load its DIEs. */
17588 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
17589 read_signatured_type (sig_type
);
17591 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
17593 sig_cu
= sig_type
->per_cu
.cu
;
17594 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
17595 temp_die
.offset
= sig_type
->type_offset_in_section
;
17596 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
17597 temp_die
.offset
.sect_off
);
17604 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
17605 "from DIE at 0x%x [in module %s]"),
17606 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
17609 /* Given an offset of a signatured type, return its signatured_type. */
17611 static struct signatured_type
*
17612 lookup_signatured_type_at_offset (struct objfile
*objfile
,
17613 struct dwarf2_section_info
*section
,
17614 sect_offset offset
)
17616 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
17617 unsigned int length
, initial_length_size
;
17618 unsigned int sig_offset
;
17619 struct signatured_type find_entry
, *sig_type
;
17621 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
17622 sig_offset
= (initial_length_size
17624 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
17625 + 1 /*address_size*/);
17626 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
17627 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
17629 /* This is only used to lookup previously recorded types.
17630 If we didn't find it, it's our bug. */
17631 gdb_assert (sig_type
!= NULL
);
17632 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
17637 /* Load the DIEs associated with type unit PER_CU into memory. */
17640 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
17642 struct signatured_type
*sig_type
;
17644 /* Caller is responsible for ensuring type_unit_groups don't get here. */
17645 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
17647 /* We have the per_cu, but we need the signatured_type.
17648 Fortunately this is an easy translation. */
17649 gdb_assert (per_cu
->is_debug_types
);
17650 sig_type
= (struct signatured_type
*) per_cu
;
17652 gdb_assert (per_cu
->cu
== NULL
);
17654 read_signatured_type (sig_type
);
17656 gdb_assert (per_cu
->cu
!= NULL
);
17659 /* die_reader_func for read_signatured_type.
17660 This is identical to load_full_comp_unit_reader,
17661 but is kept separate for now. */
17664 read_signatured_type_reader (const struct die_reader_specs
*reader
,
17665 gdb_byte
*info_ptr
,
17666 struct die_info
*comp_unit_die
,
17670 struct dwarf2_cu
*cu
= reader
->cu
;
17672 gdb_assert (cu
->die_hash
== NULL
);
17674 htab_create_alloc_ex (cu
->header
.length
/ 12,
17678 &cu
->comp_unit_obstack
,
17679 hashtab_obstack_allocate
,
17680 dummy_obstack_deallocate
);
17683 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
17684 &info_ptr
, comp_unit_die
);
17685 cu
->dies
= comp_unit_die
;
17686 /* comp_unit_die is not stored in die_hash, no need. */
17688 /* We try not to read any attributes in this function, because not
17689 all CUs needed for references have been loaded yet, and symbol
17690 table processing isn't initialized. But we have to set the CU language,
17691 or we won't be able to build types correctly.
17692 Similarly, if we do not read the producer, we can not apply
17693 producer-specific interpretation. */
17694 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
17697 /* Read in a signatured type and build its CU and DIEs.
17698 If the type is a stub for the real type in a DWO file,
17699 read in the real type from the DWO file as well. */
17702 read_signatured_type (struct signatured_type
*sig_type
)
17704 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
17706 gdb_assert (per_cu
->is_debug_types
);
17707 gdb_assert (per_cu
->cu
== NULL
);
17709 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
17710 read_signatured_type_reader
, NULL
);
17713 /* Decode simple location descriptions.
17714 Given a pointer to a dwarf block that defines a location, compute
17715 the location and return the value.
17717 NOTE drow/2003-11-18: This function is called in two situations
17718 now: for the address of static or global variables (partial symbols
17719 only) and for offsets into structures which are expected to be
17720 (more or less) constant. The partial symbol case should go away,
17721 and only the constant case should remain. That will let this
17722 function complain more accurately. A few special modes are allowed
17723 without complaint for global variables (for instance, global
17724 register values and thread-local values).
17726 A location description containing no operations indicates that the
17727 object is optimized out. The return value is 0 for that case.
17728 FIXME drow/2003-11-16: No callers check for this case any more; soon all
17729 callers will only want a very basic result and this can become a
17732 Note that stack[0] is unused except as a default error return. */
17735 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
17737 struct objfile
*objfile
= cu
->objfile
;
17739 size_t size
= blk
->size
;
17740 gdb_byte
*data
= blk
->data
;
17741 CORE_ADDR stack
[64];
17743 unsigned int bytes_read
, unsnd
;
17749 stack
[++stacki
] = 0;
17788 stack
[++stacki
] = op
- DW_OP_lit0
;
17823 stack
[++stacki
] = op
- DW_OP_reg0
;
17825 dwarf2_complex_location_expr_complaint ();
17829 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
17831 stack
[++stacki
] = unsnd
;
17833 dwarf2_complex_location_expr_complaint ();
17837 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
17842 case DW_OP_const1u
:
17843 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
17847 case DW_OP_const1s
:
17848 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
17852 case DW_OP_const2u
:
17853 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
17857 case DW_OP_const2s
:
17858 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
17862 case DW_OP_const4u
:
17863 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
17867 case DW_OP_const4s
:
17868 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
17872 case DW_OP_const8u
:
17873 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
17878 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
17884 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
17889 stack
[stacki
+ 1] = stack
[stacki
];
17894 stack
[stacki
- 1] += stack
[stacki
];
17898 case DW_OP_plus_uconst
:
17899 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
17905 stack
[stacki
- 1] -= stack
[stacki
];
17910 /* If we're not the last op, then we definitely can't encode
17911 this using GDB's address_class enum. This is valid for partial
17912 global symbols, although the variable's address will be bogus
17915 dwarf2_complex_location_expr_complaint ();
17918 case DW_OP_GNU_push_tls_address
:
17919 /* The top of the stack has the offset from the beginning
17920 of the thread control block at which the variable is located. */
17921 /* Nothing should follow this operator, so the top of stack would
17923 /* This is valid for partial global symbols, but the variable's
17924 address will be bogus in the psymtab. Make it always at least
17925 non-zero to not look as a variable garbage collected by linker
17926 which have DW_OP_addr 0. */
17928 dwarf2_complex_location_expr_complaint ();
17932 case DW_OP_GNU_uninit
:
17935 case DW_OP_GNU_addr_index
:
17936 case DW_OP_GNU_const_index
:
17937 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
17944 const char *name
= get_DW_OP_name (op
);
17947 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
17950 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
17954 return (stack
[stacki
]);
17957 /* Enforce maximum stack depth of SIZE-1 to avoid writing
17958 outside of the allocated space. Also enforce minimum>0. */
17959 if (stacki
>= ARRAY_SIZE (stack
) - 1)
17961 complaint (&symfile_complaints
,
17962 _("location description stack overflow"));
17968 complaint (&symfile_complaints
,
17969 _("location description stack underflow"));
17973 return (stack
[stacki
]);
17976 /* memory allocation interface */
17978 static struct dwarf_block
*
17979 dwarf_alloc_block (struct dwarf2_cu
*cu
)
17981 struct dwarf_block
*blk
;
17983 blk
= (struct dwarf_block
*)
17984 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
17988 static struct die_info
*
17989 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
17991 struct die_info
*die
;
17992 size_t size
= sizeof (struct die_info
);
17995 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
17997 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
17998 memset (die
, 0, sizeof (struct die_info
));
18003 /* Macro support. */
18005 /* Return the full name of file number I in *LH's file name table.
18006 Use COMP_DIR as the name of the current directory of the
18007 compilation. The result is allocated using xmalloc; the caller is
18008 responsible for freeing it. */
18010 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
18012 /* Is the file number a valid index into the line header's file name
18013 table? Remember that file numbers start with one, not zero. */
18014 if (1 <= file
&& file
<= lh
->num_file_names
)
18016 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
18018 if (IS_ABSOLUTE_PATH (fe
->name
))
18019 return xstrdup (fe
->name
);
18027 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
18033 dir_len
= strlen (dir
);
18034 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
18035 strcpy (full_name
, dir
);
18036 full_name
[dir_len
] = '/';
18037 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
18041 return xstrdup (fe
->name
);
18046 /* The compiler produced a bogus file number. We can at least
18047 record the macro definitions made in the file, even if we
18048 won't be able to find the file by name. */
18049 char fake_name
[80];
18051 xsnprintf (fake_name
, sizeof (fake_name
),
18052 "<bad macro file number %d>", file
);
18054 complaint (&symfile_complaints
,
18055 _("bad file number in macro information (%d)"),
18058 return xstrdup (fake_name
);
18063 static struct macro_source_file
*
18064 macro_start_file (int file
, int line
,
18065 struct macro_source_file
*current_file
,
18066 const char *comp_dir
,
18067 struct line_header
*lh
, struct objfile
*objfile
)
18069 /* The full name of this source file. */
18070 char *full_name
= file_full_name (file
, lh
, comp_dir
);
18072 /* We don't create a macro table for this compilation unit
18073 at all until we actually get a filename. */
18074 if (! pending_macros
)
18075 pending_macros
= new_macro_table (&objfile
->per_bfd
->storage_obstack
,
18076 objfile
->per_bfd
->macro_cache
);
18078 if (! current_file
)
18080 /* If we have no current file, then this must be the start_file
18081 directive for the compilation unit's main source file. */
18082 current_file
= macro_set_main (pending_macros
, full_name
);
18083 macro_define_special (pending_macros
);
18086 current_file
= macro_include (current_file
, line
, full_name
);
18090 return current_file
;
18094 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
18095 followed by a null byte. */
18097 copy_string (const char *buf
, int len
)
18099 char *s
= xmalloc (len
+ 1);
18101 memcpy (s
, buf
, len
);
18107 static const char *
18108 consume_improper_spaces (const char *p
, const char *body
)
18112 complaint (&symfile_complaints
,
18113 _("macro definition contains spaces "
18114 "in formal argument list:\n`%s'"),
18126 parse_macro_definition (struct macro_source_file
*file
, int line
,
18131 /* The body string takes one of two forms. For object-like macro
18132 definitions, it should be:
18134 <macro name> " " <definition>
18136 For function-like macro definitions, it should be:
18138 <macro name> "() " <definition>
18140 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
18142 Spaces may appear only where explicitly indicated, and in the
18145 The Dwarf 2 spec says that an object-like macro's name is always
18146 followed by a space, but versions of GCC around March 2002 omit
18147 the space when the macro's definition is the empty string.
18149 The Dwarf 2 spec says that there should be no spaces between the
18150 formal arguments in a function-like macro's formal argument list,
18151 but versions of GCC around March 2002 include spaces after the
18155 /* Find the extent of the macro name. The macro name is terminated
18156 by either a space or null character (for an object-like macro) or
18157 an opening paren (for a function-like macro). */
18158 for (p
= body
; *p
; p
++)
18159 if (*p
== ' ' || *p
== '(')
18162 if (*p
== ' ' || *p
== '\0')
18164 /* It's an object-like macro. */
18165 int name_len
= p
- body
;
18166 char *name
= copy_string (body
, name_len
);
18167 const char *replacement
;
18170 replacement
= body
+ name_len
+ 1;
18173 dwarf2_macro_malformed_definition_complaint (body
);
18174 replacement
= body
+ name_len
;
18177 macro_define_object (file
, line
, name
, replacement
);
18181 else if (*p
== '(')
18183 /* It's a function-like macro. */
18184 char *name
= copy_string (body
, p
- body
);
18187 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
18191 p
= consume_improper_spaces (p
, body
);
18193 /* Parse the formal argument list. */
18194 while (*p
&& *p
!= ')')
18196 /* Find the extent of the current argument name. */
18197 const char *arg_start
= p
;
18199 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
18202 if (! *p
|| p
== arg_start
)
18203 dwarf2_macro_malformed_definition_complaint (body
);
18206 /* Make sure argv has room for the new argument. */
18207 if (argc
>= argv_size
)
18210 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
18213 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
18216 p
= consume_improper_spaces (p
, body
);
18218 /* Consume the comma, if present. */
18223 p
= consume_improper_spaces (p
, body
);
18232 /* Perfectly formed definition, no complaints. */
18233 macro_define_function (file
, line
, name
,
18234 argc
, (const char **) argv
,
18236 else if (*p
== '\0')
18238 /* Complain, but do define it. */
18239 dwarf2_macro_malformed_definition_complaint (body
);
18240 macro_define_function (file
, line
, name
,
18241 argc
, (const char **) argv
,
18245 /* Just complain. */
18246 dwarf2_macro_malformed_definition_complaint (body
);
18249 /* Just complain. */
18250 dwarf2_macro_malformed_definition_complaint (body
);
18256 for (i
= 0; i
< argc
; i
++)
18262 dwarf2_macro_malformed_definition_complaint (body
);
18265 /* Skip some bytes from BYTES according to the form given in FORM.
18266 Returns the new pointer. */
18269 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
, gdb_byte
*buffer_end
,
18270 enum dwarf_form form
,
18271 unsigned int offset_size
,
18272 struct dwarf2_section_info
*section
)
18274 unsigned int bytes_read
;
18278 case DW_FORM_data1
:
18283 case DW_FORM_data2
:
18287 case DW_FORM_data4
:
18291 case DW_FORM_data8
:
18295 case DW_FORM_string
:
18296 read_direct_string (abfd
, bytes
, &bytes_read
);
18297 bytes
+= bytes_read
;
18300 case DW_FORM_sec_offset
:
18302 case DW_FORM_GNU_strp_alt
:
18303 bytes
+= offset_size
;
18306 case DW_FORM_block
:
18307 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
18308 bytes
+= bytes_read
;
18311 case DW_FORM_block1
:
18312 bytes
+= 1 + read_1_byte (abfd
, bytes
);
18314 case DW_FORM_block2
:
18315 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
18317 case DW_FORM_block4
:
18318 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
18321 case DW_FORM_sdata
:
18322 case DW_FORM_udata
:
18323 case DW_FORM_GNU_addr_index
:
18324 case DW_FORM_GNU_str_index
:
18325 bytes
= (gdb_byte
*) gdb_skip_leb128 (bytes
, buffer_end
);
18328 dwarf2_section_buffer_overflow_complaint (section
);
18336 complaint (&symfile_complaints
,
18337 _("invalid form 0x%x in `%s'"),
18339 section
->asection
->name
);
18347 /* A helper for dwarf_decode_macros that handles skipping an unknown
18348 opcode. Returns an updated pointer to the macro data buffer; or,
18349 on error, issues a complaint and returns NULL. */
18352 skip_unknown_opcode (unsigned int opcode
,
18353 gdb_byte
**opcode_definitions
,
18354 gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
18356 unsigned int offset_size
,
18357 struct dwarf2_section_info
*section
)
18359 unsigned int bytes_read
, i
;
18363 if (opcode_definitions
[opcode
] == NULL
)
18365 complaint (&symfile_complaints
,
18366 _("unrecognized DW_MACFINO opcode 0x%x"),
18371 defn
= opcode_definitions
[opcode
];
18372 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
18373 defn
+= bytes_read
;
18375 for (i
= 0; i
< arg
; ++i
)
18377 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
, defn
[i
], offset_size
,
18379 if (mac_ptr
== NULL
)
18381 /* skip_form_bytes already issued the complaint. */
18389 /* A helper function which parses the header of a macro section.
18390 If the macro section is the extended (for now called "GNU") type,
18391 then this updates *OFFSET_SIZE. Returns a pointer to just after
18392 the header, or issues a complaint and returns NULL on error. */
18395 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
18398 unsigned int *offset_size
,
18399 int section_is_gnu
)
18401 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
18403 if (section_is_gnu
)
18405 unsigned int version
, flags
;
18407 version
= read_2_bytes (abfd
, mac_ptr
);
18410 complaint (&symfile_complaints
,
18411 _("unrecognized version `%d' in .debug_macro section"),
18417 flags
= read_1_byte (abfd
, mac_ptr
);
18419 *offset_size
= (flags
& 1) ? 8 : 4;
18421 if ((flags
& 2) != 0)
18422 /* We don't need the line table offset. */
18423 mac_ptr
+= *offset_size
;
18425 /* Vendor opcode descriptions. */
18426 if ((flags
& 4) != 0)
18428 unsigned int i
, count
;
18430 count
= read_1_byte (abfd
, mac_ptr
);
18432 for (i
= 0; i
< count
; ++i
)
18434 unsigned int opcode
, bytes_read
;
18437 opcode
= read_1_byte (abfd
, mac_ptr
);
18439 opcode_definitions
[opcode
] = mac_ptr
;
18440 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18441 mac_ptr
+= bytes_read
;
18450 /* A helper for dwarf_decode_macros that handles the GNU extensions,
18451 including DW_MACRO_GNU_transparent_include. */
18454 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
18455 struct macro_source_file
*current_file
,
18456 struct line_header
*lh
, char *comp_dir
,
18457 struct dwarf2_section_info
*section
,
18458 int section_is_gnu
, int section_is_dwz
,
18459 unsigned int offset_size
,
18460 struct objfile
*objfile
,
18461 htab_t include_hash
)
18463 enum dwarf_macro_record_type macinfo_type
;
18464 int at_commandline
;
18465 gdb_byte
*opcode_definitions
[256];
18467 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
18468 &offset_size
, section_is_gnu
);
18469 if (mac_ptr
== NULL
)
18471 /* We already issued a complaint. */
18475 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
18476 GDB is still reading the definitions from command line. First
18477 DW_MACINFO_start_file will need to be ignored as it was already executed
18478 to create CURRENT_FILE for the main source holding also the command line
18479 definitions. On first met DW_MACINFO_start_file this flag is reset to
18480 normally execute all the remaining DW_MACINFO_start_file macinfos. */
18482 at_commandline
= 1;
18486 /* Do we at least have room for a macinfo type byte? */
18487 if (mac_ptr
>= mac_end
)
18489 dwarf2_section_buffer_overflow_complaint (section
);
18493 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
18496 /* Note that we rely on the fact that the corresponding GNU and
18497 DWARF constants are the same. */
18498 switch (macinfo_type
)
18500 /* A zero macinfo type indicates the end of the macro
18505 case DW_MACRO_GNU_define
:
18506 case DW_MACRO_GNU_undef
:
18507 case DW_MACRO_GNU_define_indirect
:
18508 case DW_MACRO_GNU_undef_indirect
:
18509 case DW_MACRO_GNU_define_indirect_alt
:
18510 case DW_MACRO_GNU_undef_indirect_alt
:
18512 unsigned int bytes_read
;
18517 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18518 mac_ptr
+= bytes_read
;
18520 if (macinfo_type
== DW_MACRO_GNU_define
18521 || macinfo_type
== DW_MACRO_GNU_undef
)
18523 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18524 mac_ptr
+= bytes_read
;
18528 LONGEST str_offset
;
18530 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
18531 mac_ptr
+= offset_size
;
18533 if (macinfo_type
== DW_MACRO_GNU_define_indirect_alt
18534 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
18537 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
18539 body
= read_indirect_string_from_dwz (dwz
, str_offset
);
18542 body
= read_indirect_string_at_offset (abfd
, str_offset
);
18545 is_define
= (macinfo_type
== DW_MACRO_GNU_define
18546 || macinfo_type
== DW_MACRO_GNU_define_indirect
18547 || macinfo_type
== DW_MACRO_GNU_define_indirect_alt
);
18548 if (! current_file
)
18550 /* DWARF violation as no main source is present. */
18551 complaint (&symfile_complaints
,
18552 _("debug info with no main source gives macro %s "
18554 is_define
? _("definition") : _("undefinition"),
18558 if ((line
== 0 && !at_commandline
)
18559 || (line
!= 0 && at_commandline
))
18560 complaint (&symfile_complaints
,
18561 _("debug info gives %s macro %s with %s line %d: %s"),
18562 at_commandline
? _("command-line") : _("in-file"),
18563 is_define
? _("definition") : _("undefinition"),
18564 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
18567 parse_macro_definition (current_file
, line
, body
);
18570 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
18571 || macinfo_type
== DW_MACRO_GNU_undef_indirect
18572 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
);
18573 macro_undef (current_file
, line
, body
);
18578 case DW_MACRO_GNU_start_file
:
18580 unsigned int bytes_read
;
18583 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18584 mac_ptr
+= bytes_read
;
18585 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18586 mac_ptr
+= bytes_read
;
18588 if ((line
== 0 && !at_commandline
)
18589 || (line
!= 0 && at_commandline
))
18590 complaint (&symfile_complaints
,
18591 _("debug info gives source %d included "
18592 "from %s at %s line %d"),
18593 file
, at_commandline
? _("command-line") : _("file"),
18594 line
== 0 ? _("zero") : _("non-zero"), line
);
18596 if (at_commandline
)
18598 /* This DW_MACRO_GNU_start_file was executed in the
18600 at_commandline
= 0;
18603 current_file
= macro_start_file (file
, line
,
18604 current_file
, comp_dir
,
18609 case DW_MACRO_GNU_end_file
:
18610 if (! current_file
)
18611 complaint (&symfile_complaints
,
18612 _("macro debug info has an unmatched "
18613 "`close_file' directive"));
18616 current_file
= current_file
->included_by
;
18617 if (! current_file
)
18619 enum dwarf_macro_record_type next_type
;
18621 /* GCC circa March 2002 doesn't produce the zero
18622 type byte marking the end of the compilation
18623 unit. Complain if it's not there, but exit no
18626 /* Do we at least have room for a macinfo type byte? */
18627 if (mac_ptr
>= mac_end
)
18629 dwarf2_section_buffer_overflow_complaint (section
);
18633 /* We don't increment mac_ptr here, so this is just
18635 next_type
= read_1_byte (abfd
, mac_ptr
);
18636 if (next_type
!= 0)
18637 complaint (&symfile_complaints
,
18638 _("no terminating 0-type entry for "
18639 "macros in `.debug_macinfo' section"));
18646 case DW_MACRO_GNU_transparent_include
:
18647 case DW_MACRO_GNU_transparent_include_alt
:
18651 bfd
*include_bfd
= abfd
;
18652 struct dwarf2_section_info
*include_section
= section
;
18653 struct dwarf2_section_info alt_section
;
18654 gdb_byte
*include_mac_end
= mac_end
;
18655 int is_dwz
= section_is_dwz
;
18656 gdb_byte
*new_mac_ptr
;
18658 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
18659 mac_ptr
+= offset_size
;
18661 if (macinfo_type
== DW_MACRO_GNU_transparent_include_alt
)
18663 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
18665 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
18668 include_bfd
= dwz
->macro
.asection
->owner
;
18669 include_section
= &dwz
->macro
;
18670 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
18674 new_mac_ptr
= include_section
->buffer
+ offset
;
18675 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
18679 /* This has actually happened; see
18680 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
18681 complaint (&symfile_complaints
,
18682 _("recursive DW_MACRO_GNU_transparent_include in "
18683 ".debug_macro section"));
18687 *slot
= new_mac_ptr
;
18689 dwarf_decode_macro_bytes (include_bfd
, new_mac_ptr
,
18690 include_mac_end
, current_file
,
18692 section
, section_is_gnu
, is_dwz
,
18693 offset_size
, objfile
, include_hash
);
18695 htab_remove_elt (include_hash
, new_mac_ptr
);
18700 case DW_MACINFO_vendor_ext
:
18701 if (!section_is_gnu
)
18703 unsigned int bytes_read
;
18706 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18707 mac_ptr
+= bytes_read
;
18708 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18709 mac_ptr
+= bytes_read
;
18711 /* We don't recognize any vendor extensions. */
18717 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
18718 mac_ptr
, mac_end
, abfd
, offset_size
,
18720 if (mac_ptr
== NULL
)
18724 } while (macinfo_type
!= 0);
18728 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
18729 char *comp_dir
, int section_is_gnu
)
18731 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18732 struct line_header
*lh
= cu
->line_header
;
18734 gdb_byte
*mac_ptr
, *mac_end
;
18735 struct macro_source_file
*current_file
= 0;
18736 enum dwarf_macro_record_type macinfo_type
;
18737 unsigned int offset_size
= cu
->header
.offset_size
;
18738 gdb_byte
*opcode_definitions
[256];
18739 struct cleanup
*cleanup
;
18740 htab_t include_hash
;
18742 struct dwarf2_section_info
*section
;
18743 const char *section_name
;
18745 if (cu
->dwo_unit
!= NULL
)
18747 if (section_is_gnu
)
18749 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
18750 section_name
= ".debug_macro.dwo";
18754 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
18755 section_name
= ".debug_macinfo.dwo";
18760 if (section_is_gnu
)
18762 section
= &dwarf2_per_objfile
->macro
;
18763 section_name
= ".debug_macro";
18767 section
= &dwarf2_per_objfile
->macinfo
;
18768 section_name
= ".debug_macinfo";
18772 dwarf2_read_section (objfile
, section
);
18773 if (section
->buffer
== NULL
)
18775 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
18778 abfd
= section
->asection
->owner
;
18780 /* First pass: Find the name of the base filename.
18781 This filename is needed in order to process all macros whose definition
18782 (or undefinition) comes from the command line. These macros are defined
18783 before the first DW_MACINFO_start_file entry, and yet still need to be
18784 associated to the base file.
18786 To determine the base file name, we scan the macro definitions until we
18787 reach the first DW_MACINFO_start_file entry. We then initialize
18788 CURRENT_FILE accordingly so that any macro definition found before the
18789 first DW_MACINFO_start_file can still be associated to the base file. */
18791 mac_ptr
= section
->buffer
+ offset
;
18792 mac_end
= section
->buffer
+ section
->size
;
18794 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
18795 &offset_size
, section_is_gnu
);
18796 if (mac_ptr
== NULL
)
18798 /* We already issued a complaint. */
18804 /* Do we at least have room for a macinfo type byte? */
18805 if (mac_ptr
>= mac_end
)
18807 /* Complaint is printed during the second pass as GDB will probably
18808 stop the first pass earlier upon finding
18809 DW_MACINFO_start_file. */
18813 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
18816 /* Note that we rely on the fact that the corresponding GNU and
18817 DWARF constants are the same. */
18818 switch (macinfo_type
)
18820 /* A zero macinfo type indicates the end of the macro
18825 case DW_MACRO_GNU_define
:
18826 case DW_MACRO_GNU_undef
:
18827 /* Only skip the data by MAC_PTR. */
18829 unsigned int bytes_read
;
18831 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18832 mac_ptr
+= bytes_read
;
18833 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18834 mac_ptr
+= bytes_read
;
18838 case DW_MACRO_GNU_start_file
:
18840 unsigned int bytes_read
;
18843 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18844 mac_ptr
+= bytes_read
;
18845 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18846 mac_ptr
+= bytes_read
;
18848 current_file
= macro_start_file (file
, line
, current_file
,
18849 comp_dir
, lh
, objfile
);
18853 case DW_MACRO_GNU_end_file
:
18854 /* No data to skip by MAC_PTR. */
18857 case DW_MACRO_GNU_define_indirect
:
18858 case DW_MACRO_GNU_undef_indirect
:
18859 case DW_MACRO_GNU_define_indirect_alt
:
18860 case DW_MACRO_GNU_undef_indirect_alt
:
18862 unsigned int bytes_read
;
18864 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18865 mac_ptr
+= bytes_read
;
18866 mac_ptr
+= offset_size
;
18870 case DW_MACRO_GNU_transparent_include
:
18871 case DW_MACRO_GNU_transparent_include_alt
:
18872 /* Note that, according to the spec, a transparent include
18873 chain cannot call DW_MACRO_GNU_start_file. So, we can just
18874 skip this opcode. */
18875 mac_ptr
+= offset_size
;
18878 case DW_MACINFO_vendor_ext
:
18879 /* Only skip the data by MAC_PTR. */
18880 if (!section_is_gnu
)
18882 unsigned int bytes_read
;
18884 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18885 mac_ptr
+= bytes_read
;
18886 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18887 mac_ptr
+= bytes_read
;
18892 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
18893 mac_ptr
, mac_end
, abfd
, offset_size
,
18895 if (mac_ptr
== NULL
)
18899 } while (macinfo_type
!= 0 && current_file
== NULL
);
18901 /* Second pass: Process all entries.
18903 Use the AT_COMMAND_LINE flag to determine whether we are still processing
18904 command-line macro definitions/undefinitions. This flag is unset when we
18905 reach the first DW_MACINFO_start_file entry. */
18907 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
18908 NULL
, xcalloc
, xfree
);
18909 cleanup
= make_cleanup_htab_delete (include_hash
);
18910 mac_ptr
= section
->buffer
+ offset
;
18911 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
18913 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
18914 current_file
, lh
, comp_dir
, section
,
18916 offset_size
, objfile
, include_hash
);
18917 do_cleanups (cleanup
);
18920 /* Check if the attribute's form is a DW_FORM_block*
18921 if so return true else false. */
18924 attr_form_is_block (struct attribute
*attr
)
18926 return (attr
== NULL
? 0 :
18927 attr
->form
== DW_FORM_block1
18928 || attr
->form
== DW_FORM_block2
18929 || attr
->form
== DW_FORM_block4
18930 || attr
->form
== DW_FORM_block
18931 || attr
->form
== DW_FORM_exprloc
);
18934 /* Return non-zero if ATTR's value is a section offset --- classes
18935 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
18936 You may use DW_UNSND (attr) to retrieve such offsets.
18938 Section 7.5.4, "Attribute Encodings", explains that no attribute
18939 may have a value that belongs to more than one of these classes; it
18940 would be ambiguous if we did, because we use the same forms for all
18944 attr_form_is_section_offset (struct attribute
*attr
)
18946 return (attr
->form
== DW_FORM_data4
18947 || attr
->form
== DW_FORM_data8
18948 || attr
->form
== DW_FORM_sec_offset
);
18951 /* Return non-zero if ATTR's value falls in the 'constant' class, or
18952 zero otherwise. When this function returns true, you can apply
18953 dwarf2_get_attr_constant_value to it.
18955 However, note that for some attributes you must check
18956 attr_form_is_section_offset before using this test. DW_FORM_data4
18957 and DW_FORM_data8 are members of both the constant class, and of
18958 the classes that contain offsets into other debug sections
18959 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
18960 that, if an attribute's can be either a constant or one of the
18961 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
18962 taken as section offsets, not constants. */
18965 attr_form_is_constant (struct attribute
*attr
)
18967 switch (attr
->form
)
18969 case DW_FORM_sdata
:
18970 case DW_FORM_udata
:
18971 case DW_FORM_data1
:
18972 case DW_FORM_data2
:
18973 case DW_FORM_data4
:
18974 case DW_FORM_data8
:
18981 /* Return the .debug_loc section to use for CU.
18982 For DWO files use .debug_loc.dwo. */
18984 static struct dwarf2_section_info
*
18985 cu_debug_loc_section (struct dwarf2_cu
*cu
)
18988 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
18989 return &dwarf2_per_objfile
->loc
;
18992 /* A helper function that fills in a dwarf2_loclist_baton. */
18995 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
18996 struct dwarf2_loclist_baton
*baton
,
18997 struct attribute
*attr
)
18999 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19001 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
19003 baton
->per_cu
= cu
->per_cu
;
19004 gdb_assert (baton
->per_cu
);
19005 /* We don't know how long the location list is, but make sure we
19006 don't run off the edge of the section. */
19007 baton
->size
= section
->size
- DW_UNSND (attr
);
19008 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
19009 baton
->base_address
= cu
->base_address
;
19010 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
19014 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
19015 struct dwarf2_cu
*cu
)
19017 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19018 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19020 if (attr_form_is_section_offset (attr
)
19021 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
19022 the section. If so, fall through to the complaint in the
19024 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
19026 struct dwarf2_loclist_baton
*baton
;
19028 baton
= obstack_alloc (&objfile
->objfile_obstack
,
19029 sizeof (struct dwarf2_loclist_baton
));
19031 fill_in_loclist_baton (cu
, baton
, attr
);
19033 if (cu
->base_known
== 0)
19034 complaint (&symfile_complaints
,
19035 _("Location list used without "
19036 "specifying the CU base address."));
19038 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
19039 SYMBOL_LOCATION_BATON (sym
) = baton
;
19043 struct dwarf2_locexpr_baton
*baton
;
19045 baton
= obstack_alloc (&objfile
->objfile_obstack
,
19046 sizeof (struct dwarf2_locexpr_baton
));
19047 baton
->per_cu
= cu
->per_cu
;
19048 gdb_assert (baton
->per_cu
);
19050 if (attr_form_is_block (attr
))
19052 /* Note that we're just copying the block's data pointer
19053 here, not the actual data. We're still pointing into the
19054 info_buffer for SYM's objfile; right now we never release
19055 that buffer, but when we do clean up properly this may
19057 baton
->size
= DW_BLOCK (attr
)->size
;
19058 baton
->data
= DW_BLOCK (attr
)->data
;
19062 dwarf2_invalid_attrib_class_complaint ("location description",
19063 SYMBOL_NATURAL_NAME (sym
));
19067 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
19068 SYMBOL_LOCATION_BATON (sym
) = baton
;
19072 /* Return the OBJFILE associated with the compilation unit CU. If CU
19073 came from a separate debuginfo file, then the master objfile is
19077 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
19079 struct objfile
*objfile
= per_cu
->objfile
;
19081 /* Return the master objfile, so that we can report and look up the
19082 correct file containing this variable. */
19083 if (objfile
->separate_debug_objfile_backlink
)
19084 objfile
= objfile
->separate_debug_objfile_backlink
;
19089 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
19090 (CU_HEADERP is unused in such case) or prepare a temporary copy at
19091 CU_HEADERP first. */
19093 static const struct comp_unit_head
*
19094 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
19095 struct dwarf2_per_cu_data
*per_cu
)
19097 gdb_byte
*info_ptr
;
19100 return &per_cu
->cu
->header
;
19102 info_ptr
= per_cu
->info_or_types_section
->buffer
+ per_cu
->offset
.sect_off
;
19104 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
19105 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->objfile
->obfd
);
19110 /* Return the address size given in the compilation unit header for CU. */
19113 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
19115 struct comp_unit_head cu_header_local
;
19116 const struct comp_unit_head
*cu_headerp
;
19118 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
19120 return cu_headerp
->addr_size
;
19123 /* Return the offset size given in the compilation unit header for CU. */
19126 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
19128 struct comp_unit_head cu_header_local
;
19129 const struct comp_unit_head
*cu_headerp
;
19131 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
19133 return cu_headerp
->offset_size
;
19136 /* See its dwarf2loc.h declaration. */
19139 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
19141 struct comp_unit_head cu_header_local
;
19142 const struct comp_unit_head
*cu_headerp
;
19144 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
19146 if (cu_headerp
->version
== 2)
19147 return cu_headerp
->addr_size
;
19149 return cu_headerp
->offset_size
;
19152 /* Return the text offset of the CU. The returned offset comes from
19153 this CU's objfile. If this objfile came from a separate debuginfo
19154 file, then the offset may be different from the corresponding
19155 offset in the parent objfile. */
19158 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
19160 struct objfile
*objfile
= per_cu
->objfile
;
19162 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
19165 /* Locate the .debug_info compilation unit from CU's objfile which contains
19166 the DIE at OFFSET. Raises an error on failure. */
19168 static struct dwarf2_per_cu_data
*
19169 dwarf2_find_containing_comp_unit (sect_offset offset
,
19170 unsigned int offset_in_dwz
,
19171 struct objfile
*objfile
)
19173 struct dwarf2_per_cu_data
*this_cu
;
19175 const sect_offset
*cu_off
;
19178 high
= dwarf2_per_objfile
->n_comp_units
- 1;
19181 struct dwarf2_per_cu_data
*mid_cu
;
19182 int mid
= low
+ (high
- low
) / 2;
19184 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
19185 cu_off
= &mid_cu
->offset
;
19186 if (mid_cu
->is_dwz
> offset_in_dwz
19187 || (mid_cu
->is_dwz
== offset_in_dwz
19188 && cu_off
->sect_off
>= offset
.sect_off
))
19193 gdb_assert (low
== high
);
19194 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
19195 cu_off
= &this_cu
->offset
;
19196 if (this_cu
->is_dwz
!= offset_in_dwz
|| cu_off
->sect_off
> offset
.sect_off
)
19198 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
19199 error (_("Dwarf Error: could not find partial DIE containing "
19200 "offset 0x%lx [in module %s]"),
19201 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
19203 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
19204 <= offset
.sect_off
);
19205 return dwarf2_per_objfile
->all_comp_units
[low
-1];
19209 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
19210 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
19211 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
19212 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
19213 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
19218 /* Initialize dwarf2_cu CU, owned by PER_CU. */
19221 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
19223 memset (cu
, 0, sizeof (*cu
));
19225 cu
->per_cu
= per_cu
;
19226 cu
->objfile
= per_cu
->objfile
;
19227 obstack_init (&cu
->comp_unit_obstack
);
19230 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
19233 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
19234 enum language pretend_language
)
19236 struct attribute
*attr
;
19238 /* Set the language we're debugging. */
19239 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
19241 set_cu_language (DW_UNSND (attr
), cu
);
19244 cu
->language
= pretend_language
;
19245 cu
->language_defn
= language_def (cu
->language
);
19248 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
19250 cu
->producer
= DW_STRING (attr
);
19253 /* Release one cached compilation unit, CU. We unlink it from the tree
19254 of compilation units, but we don't remove it from the read_in_chain;
19255 the caller is responsible for that.
19256 NOTE: DATA is a void * because this function is also used as a
19257 cleanup routine. */
19260 free_heap_comp_unit (void *data
)
19262 struct dwarf2_cu
*cu
= data
;
19264 gdb_assert (cu
->per_cu
!= NULL
);
19265 cu
->per_cu
->cu
= NULL
;
19268 obstack_free (&cu
->comp_unit_obstack
, NULL
);
19273 /* This cleanup function is passed the address of a dwarf2_cu on the stack
19274 when we're finished with it. We can't free the pointer itself, but be
19275 sure to unlink it from the cache. Also release any associated storage. */
19278 free_stack_comp_unit (void *data
)
19280 struct dwarf2_cu
*cu
= data
;
19282 gdb_assert (cu
->per_cu
!= NULL
);
19283 cu
->per_cu
->cu
= NULL
;
19286 obstack_free (&cu
->comp_unit_obstack
, NULL
);
19287 cu
->partial_dies
= NULL
;
19290 /* Free all cached compilation units. */
19293 free_cached_comp_units (void *data
)
19295 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
19297 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19298 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
19299 while (per_cu
!= NULL
)
19301 struct dwarf2_per_cu_data
*next_cu
;
19303 next_cu
= per_cu
->cu
->read_in_chain
;
19305 free_heap_comp_unit (per_cu
->cu
);
19306 *last_chain
= next_cu
;
19312 /* Increase the age counter on each cached compilation unit, and free
19313 any that are too old. */
19316 age_cached_comp_units (void)
19318 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
19320 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
19321 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19322 while (per_cu
!= NULL
)
19324 per_cu
->cu
->last_used
++;
19325 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
19326 dwarf2_mark (per_cu
->cu
);
19327 per_cu
= per_cu
->cu
->read_in_chain
;
19330 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19331 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
19332 while (per_cu
!= NULL
)
19334 struct dwarf2_per_cu_data
*next_cu
;
19336 next_cu
= per_cu
->cu
->read_in_chain
;
19338 if (!per_cu
->cu
->mark
)
19340 free_heap_comp_unit (per_cu
->cu
);
19341 *last_chain
= next_cu
;
19344 last_chain
= &per_cu
->cu
->read_in_chain
;
19350 /* Remove a single compilation unit from the cache. */
19353 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
19355 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
19357 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19358 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
19359 while (per_cu
!= NULL
)
19361 struct dwarf2_per_cu_data
*next_cu
;
19363 next_cu
= per_cu
->cu
->read_in_chain
;
19365 if (per_cu
== target_per_cu
)
19367 free_heap_comp_unit (per_cu
->cu
);
19369 *last_chain
= next_cu
;
19373 last_chain
= &per_cu
->cu
->read_in_chain
;
19379 /* Release all extra memory associated with OBJFILE. */
19382 dwarf2_free_objfile (struct objfile
*objfile
)
19384 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
19386 if (dwarf2_per_objfile
== NULL
)
19389 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
19390 free_cached_comp_units (NULL
);
19392 if (dwarf2_per_objfile
->quick_file_names_table
)
19393 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
19395 /* Everything else should be on the objfile obstack. */
19398 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
19399 We store these in a hash table separate from the DIEs, and preserve them
19400 when the DIEs are flushed out of cache.
19402 The CU "per_cu" pointer is needed because offset alone is not enough to
19403 uniquely identify the type. A file may have multiple .debug_types sections,
19404 or the type may come from a DWO file. We have to use something in
19405 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
19406 routine, get_die_type_at_offset, from outside this file, and thus won't
19407 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
19410 struct dwarf2_per_cu_offset_and_type
19412 const struct dwarf2_per_cu_data
*per_cu
;
19413 sect_offset offset
;
19417 /* Hash function for a dwarf2_per_cu_offset_and_type. */
19420 per_cu_offset_and_type_hash (const void *item
)
19422 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
19424 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
19427 /* Equality function for a dwarf2_per_cu_offset_and_type. */
19430 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
19432 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
19433 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
19435 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
19436 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
19439 /* Set the type associated with DIE to TYPE. Save it in CU's hash
19440 table if necessary. For convenience, return TYPE.
19442 The DIEs reading must have careful ordering to:
19443 * Not cause infite loops trying to read in DIEs as a prerequisite for
19444 reading current DIE.
19445 * Not trying to dereference contents of still incompletely read in types
19446 while reading in other DIEs.
19447 * Enable referencing still incompletely read in types just by a pointer to
19448 the type without accessing its fields.
19450 Therefore caller should follow these rules:
19451 * Try to fetch any prerequisite types we may need to build this DIE type
19452 before building the type and calling set_die_type.
19453 * After building type call set_die_type for current DIE as soon as
19454 possible before fetching more types to complete the current type.
19455 * Make the type as complete as possible before fetching more types. */
19457 static struct type
*
19458 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
19460 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
19461 struct objfile
*objfile
= cu
->objfile
;
19463 /* For Ada types, make sure that the gnat-specific data is always
19464 initialized (if not already set). There are a few types where
19465 we should not be doing so, because the type-specific area is
19466 already used to hold some other piece of info (eg: TYPE_CODE_FLT
19467 where the type-specific area is used to store the floatformat).
19468 But this is not a problem, because the gnat-specific information
19469 is actually not needed for these types. */
19470 if (need_gnat_info (cu
)
19471 && TYPE_CODE (type
) != TYPE_CODE_FUNC
19472 && TYPE_CODE (type
) != TYPE_CODE_FLT
19473 && !HAVE_GNAT_AUX_INFO (type
))
19474 INIT_GNAT_SPECIFIC (type
);
19476 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
19478 dwarf2_per_objfile
->die_type_hash
=
19479 htab_create_alloc_ex (127,
19480 per_cu_offset_and_type_hash
,
19481 per_cu_offset_and_type_eq
,
19483 &objfile
->objfile_obstack
,
19484 hashtab_obstack_allocate
,
19485 dummy_obstack_deallocate
);
19488 ofs
.per_cu
= cu
->per_cu
;
19489 ofs
.offset
= die
->offset
;
19491 slot
= (struct dwarf2_per_cu_offset_and_type
**)
19492 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
19494 complaint (&symfile_complaints
,
19495 _("A problem internal to GDB: DIE 0x%x has type already set"),
19496 die
->offset
.sect_off
);
19497 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
19502 /* Look up the type for the die at OFFSET in the appropriate type_hash
19503 table, or return NULL if the die does not have a saved type. */
19505 static struct type
*
19506 get_die_type_at_offset (sect_offset offset
,
19507 struct dwarf2_per_cu_data
*per_cu
)
19509 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
19511 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
19514 ofs
.per_cu
= per_cu
;
19515 ofs
.offset
= offset
;
19516 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
19523 /* Look up the type for DIE in the appropriate type_hash table,
19524 or return NULL if DIE does not have a saved type. */
19526 static struct type
*
19527 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19529 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
19532 /* Add a dependence relationship from CU to REF_PER_CU. */
19535 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
19536 struct dwarf2_per_cu_data
*ref_per_cu
)
19540 if (cu
->dependencies
== NULL
)
19542 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
19543 NULL
, &cu
->comp_unit_obstack
,
19544 hashtab_obstack_allocate
,
19545 dummy_obstack_deallocate
);
19547 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
19549 *slot
= ref_per_cu
;
19552 /* Subroutine of dwarf2_mark to pass to htab_traverse.
19553 Set the mark field in every compilation unit in the
19554 cache that we must keep because we are keeping CU. */
19557 dwarf2_mark_helper (void **slot
, void *data
)
19559 struct dwarf2_per_cu_data
*per_cu
;
19561 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
19563 /* cu->dependencies references may not yet have been ever read if QUIT aborts
19564 reading of the chain. As such dependencies remain valid it is not much
19565 useful to track and undo them during QUIT cleanups. */
19566 if (per_cu
->cu
== NULL
)
19569 if (per_cu
->cu
->mark
)
19571 per_cu
->cu
->mark
= 1;
19573 if (per_cu
->cu
->dependencies
!= NULL
)
19574 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
19579 /* Set the mark field in CU and in every other compilation unit in the
19580 cache that we must keep because we are keeping CU. */
19583 dwarf2_mark (struct dwarf2_cu
*cu
)
19588 if (cu
->dependencies
!= NULL
)
19589 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
19593 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
19597 per_cu
->cu
->mark
= 0;
19598 per_cu
= per_cu
->cu
->read_in_chain
;
19602 /* Trivial hash function for partial_die_info: the hash value of a DIE
19603 is its offset in .debug_info for this objfile. */
19606 partial_die_hash (const void *item
)
19608 const struct partial_die_info
*part_die
= item
;
19610 return part_die
->offset
.sect_off
;
19613 /* Trivial comparison function for partial_die_info structures: two DIEs
19614 are equal if they have the same offset. */
19617 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
19619 const struct partial_die_info
*part_die_lhs
= item_lhs
;
19620 const struct partial_die_info
*part_die_rhs
= item_rhs
;
19622 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
19625 static struct cmd_list_element
*set_dwarf2_cmdlist
;
19626 static struct cmd_list_element
*show_dwarf2_cmdlist
;
19629 set_dwarf2_cmd (char *args
, int from_tty
)
19631 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
19635 show_dwarf2_cmd (char *args
, int from_tty
)
19637 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
19640 /* Free data associated with OBJFILE, if necessary. */
19643 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
19645 struct dwarf2_per_objfile
*data
= d
;
19648 for (ix
= 0; ix
< dwarf2_per_objfile
->n_comp_units
; ++ix
)
19649 VEC_free (dwarf2_per_cu_ptr
,
19650 dwarf2_per_objfile
->all_comp_units
[ix
]->s
.imported_symtabs
);
19652 VEC_free (dwarf2_section_info_def
, data
->types
);
19654 if (data
->dwo_files
)
19655 free_dwo_files (data
->dwo_files
, objfile
);
19657 if (data
->dwz_file
&& data
->dwz_file
->dwz_bfd
)
19658 gdb_bfd_unref (data
->dwz_file
->dwz_bfd
);
19662 /* The "save gdb-index" command. */
19664 /* The contents of the hash table we create when building the string
19666 struct strtab_entry
19668 offset_type offset
;
19672 /* Hash function for a strtab_entry.
19674 Function is used only during write_hash_table so no index format backward
19675 compatibility is needed. */
19678 hash_strtab_entry (const void *e
)
19680 const struct strtab_entry
*entry
= e
;
19681 return mapped_index_string_hash (INT_MAX
, entry
->str
);
19684 /* Equality function for a strtab_entry. */
19687 eq_strtab_entry (const void *a
, const void *b
)
19689 const struct strtab_entry
*ea
= a
;
19690 const struct strtab_entry
*eb
= b
;
19691 return !strcmp (ea
->str
, eb
->str
);
19694 /* Create a strtab_entry hash table. */
19697 create_strtab (void)
19699 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
19700 xfree
, xcalloc
, xfree
);
19703 /* Add a string to the constant pool. Return the string's offset in
19707 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
19710 struct strtab_entry entry
;
19711 struct strtab_entry
*result
;
19714 slot
= htab_find_slot (table
, &entry
, INSERT
);
19719 result
= XNEW (struct strtab_entry
);
19720 result
->offset
= obstack_object_size (cpool
);
19722 obstack_grow_str0 (cpool
, str
);
19725 return result
->offset
;
19728 /* An entry in the symbol table. */
19729 struct symtab_index_entry
19731 /* The name of the symbol. */
19733 /* The offset of the name in the constant pool. */
19734 offset_type index_offset
;
19735 /* A sorted vector of the indices of all the CUs that hold an object
19737 VEC (offset_type
) *cu_indices
;
19740 /* The symbol table. This is a power-of-2-sized hash table. */
19741 struct mapped_symtab
19743 offset_type n_elements
;
19745 struct symtab_index_entry
**data
;
19748 /* Hash function for a symtab_index_entry. */
19751 hash_symtab_entry (const void *e
)
19753 const struct symtab_index_entry
*entry
= e
;
19754 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
19755 sizeof (offset_type
) * VEC_length (offset_type
,
19756 entry
->cu_indices
),
19760 /* Equality function for a symtab_index_entry. */
19763 eq_symtab_entry (const void *a
, const void *b
)
19765 const struct symtab_index_entry
*ea
= a
;
19766 const struct symtab_index_entry
*eb
= b
;
19767 int len
= VEC_length (offset_type
, ea
->cu_indices
);
19768 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
19770 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
19771 VEC_address (offset_type
, eb
->cu_indices
),
19772 sizeof (offset_type
) * len
);
19775 /* Destroy a symtab_index_entry. */
19778 delete_symtab_entry (void *p
)
19780 struct symtab_index_entry
*entry
= p
;
19781 VEC_free (offset_type
, entry
->cu_indices
);
19785 /* Create a hash table holding symtab_index_entry objects. */
19788 create_symbol_hash_table (void)
19790 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
19791 delete_symtab_entry
, xcalloc
, xfree
);
19794 /* Create a new mapped symtab object. */
19796 static struct mapped_symtab
*
19797 create_mapped_symtab (void)
19799 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
19800 symtab
->n_elements
= 0;
19801 symtab
->size
= 1024;
19802 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
19806 /* Destroy a mapped_symtab. */
19809 cleanup_mapped_symtab (void *p
)
19811 struct mapped_symtab
*symtab
= p
;
19812 /* The contents of the array are freed when the other hash table is
19814 xfree (symtab
->data
);
19818 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
19821 Function is used only during write_hash_table so no index format backward
19822 compatibility is needed. */
19824 static struct symtab_index_entry
**
19825 find_slot (struct mapped_symtab
*symtab
, const char *name
)
19827 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
19829 index
= hash
& (symtab
->size
- 1);
19830 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
19834 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
19835 return &symtab
->data
[index
];
19836 index
= (index
+ step
) & (symtab
->size
- 1);
19840 /* Expand SYMTAB's hash table. */
19843 hash_expand (struct mapped_symtab
*symtab
)
19845 offset_type old_size
= symtab
->size
;
19847 struct symtab_index_entry
**old_entries
= symtab
->data
;
19850 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
19852 for (i
= 0; i
< old_size
; ++i
)
19854 if (old_entries
[i
])
19856 struct symtab_index_entry
**slot
= find_slot (symtab
,
19857 old_entries
[i
]->name
);
19858 *slot
= old_entries
[i
];
19862 xfree (old_entries
);
19865 /* Add an entry to SYMTAB. NAME is the name of the symbol.
19866 CU_INDEX is the index of the CU in which the symbol appears.
19867 IS_STATIC is one if the symbol is static, otherwise zero (global). */
19870 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
19871 int is_static
, gdb_index_symbol_kind kind
,
19872 offset_type cu_index
)
19874 struct symtab_index_entry
**slot
;
19875 offset_type cu_index_and_attrs
;
19877 ++symtab
->n_elements
;
19878 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
19879 hash_expand (symtab
);
19881 slot
= find_slot (symtab
, name
);
19884 *slot
= XNEW (struct symtab_index_entry
);
19885 (*slot
)->name
= name
;
19886 /* index_offset is set later. */
19887 (*slot
)->cu_indices
= NULL
;
19890 cu_index_and_attrs
= 0;
19891 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
19892 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
19893 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
19895 /* We don't want to record an index value twice as we want to avoid the
19897 We process all global symbols and then all static symbols
19898 (which would allow us to avoid the duplication by only having to check
19899 the last entry pushed), but a symbol could have multiple kinds in one CU.
19900 To keep things simple we don't worry about the duplication here and
19901 sort and uniqufy the list after we've processed all symbols. */
19902 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
19905 /* qsort helper routine for uniquify_cu_indices. */
19908 offset_type_compare (const void *ap
, const void *bp
)
19910 offset_type a
= *(offset_type
*) ap
;
19911 offset_type b
= *(offset_type
*) bp
;
19913 return (a
> b
) - (b
> a
);
19916 /* Sort and remove duplicates of all symbols' cu_indices lists. */
19919 uniquify_cu_indices (struct mapped_symtab
*symtab
)
19923 for (i
= 0; i
< symtab
->size
; ++i
)
19925 struct symtab_index_entry
*entry
= symtab
->data
[i
];
19928 && entry
->cu_indices
!= NULL
)
19930 unsigned int next_to_insert
, next_to_check
;
19931 offset_type last_value
;
19933 qsort (VEC_address (offset_type
, entry
->cu_indices
),
19934 VEC_length (offset_type
, entry
->cu_indices
),
19935 sizeof (offset_type
), offset_type_compare
);
19937 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
19938 next_to_insert
= 1;
19939 for (next_to_check
= 1;
19940 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
19943 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
19946 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
19948 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
19953 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
19958 /* Add a vector of indices to the constant pool. */
19961 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
19962 struct symtab_index_entry
*entry
)
19966 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
19969 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
19970 offset_type val
= MAYBE_SWAP (len
);
19975 entry
->index_offset
= obstack_object_size (cpool
);
19977 obstack_grow (cpool
, &val
, sizeof (val
));
19979 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
19982 val
= MAYBE_SWAP (iter
);
19983 obstack_grow (cpool
, &val
, sizeof (val
));
19988 struct symtab_index_entry
*old_entry
= *slot
;
19989 entry
->index_offset
= old_entry
->index_offset
;
19992 return entry
->index_offset
;
19995 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
19996 constant pool entries going into the obstack CPOOL. */
19999 write_hash_table (struct mapped_symtab
*symtab
,
20000 struct obstack
*output
, struct obstack
*cpool
)
20003 htab_t symbol_hash_table
;
20006 symbol_hash_table
= create_symbol_hash_table ();
20007 str_table
= create_strtab ();
20009 /* We add all the index vectors to the constant pool first, to
20010 ensure alignment is ok. */
20011 for (i
= 0; i
< symtab
->size
; ++i
)
20013 if (symtab
->data
[i
])
20014 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
20017 /* Now write out the hash table. */
20018 for (i
= 0; i
< symtab
->size
; ++i
)
20020 offset_type str_off
, vec_off
;
20022 if (symtab
->data
[i
])
20024 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
20025 vec_off
= symtab
->data
[i
]->index_offset
;
20029 /* While 0 is a valid constant pool index, it is not valid
20030 to have 0 for both offsets. */
20035 str_off
= MAYBE_SWAP (str_off
);
20036 vec_off
= MAYBE_SWAP (vec_off
);
20038 obstack_grow (output
, &str_off
, sizeof (str_off
));
20039 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
20042 htab_delete (str_table
);
20043 htab_delete (symbol_hash_table
);
20046 /* Struct to map psymtab to CU index in the index file. */
20047 struct psymtab_cu_index_map
20049 struct partial_symtab
*psymtab
;
20050 unsigned int cu_index
;
20054 hash_psymtab_cu_index (const void *item
)
20056 const struct psymtab_cu_index_map
*map
= item
;
20058 return htab_hash_pointer (map
->psymtab
);
20062 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
20064 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
20065 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
20067 return lhs
->psymtab
== rhs
->psymtab
;
20070 /* Helper struct for building the address table. */
20071 struct addrmap_index_data
20073 struct objfile
*objfile
;
20074 struct obstack
*addr_obstack
;
20075 htab_t cu_index_htab
;
20077 /* Non-zero if the previous_* fields are valid.
20078 We can't write an entry until we see the next entry (since it is only then
20079 that we know the end of the entry). */
20080 int previous_valid
;
20081 /* Index of the CU in the table of all CUs in the index file. */
20082 unsigned int previous_cu_index
;
20083 /* Start address of the CU. */
20084 CORE_ADDR previous_cu_start
;
20087 /* Write an address entry to OBSTACK. */
20090 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
20091 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
20093 offset_type cu_index_to_write
;
20095 CORE_ADDR baseaddr
;
20097 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
20099 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
20100 obstack_grow (obstack
, addr
, 8);
20101 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
20102 obstack_grow (obstack
, addr
, 8);
20103 cu_index_to_write
= MAYBE_SWAP (cu_index
);
20104 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
20107 /* Worker function for traversing an addrmap to build the address table. */
20110 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
20112 struct addrmap_index_data
*data
= datap
;
20113 struct partial_symtab
*pst
= obj
;
20115 if (data
->previous_valid
)
20116 add_address_entry (data
->objfile
, data
->addr_obstack
,
20117 data
->previous_cu_start
, start_addr
,
20118 data
->previous_cu_index
);
20120 data
->previous_cu_start
= start_addr
;
20123 struct psymtab_cu_index_map find_map
, *map
;
20124 find_map
.psymtab
= pst
;
20125 map
= htab_find (data
->cu_index_htab
, &find_map
);
20126 gdb_assert (map
!= NULL
);
20127 data
->previous_cu_index
= map
->cu_index
;
20128 data
->previous_valid
= 1;
20131 data
->previous_valid
= 0;
20136 /* Write OBJFILE's address map to OBSTACK.
20137 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
20138 in the index file. */
20141 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
20142 htab_t cu_index_htab
)
20144 struct addrmap_index_data addrmap_index_data
;
20146 /* When writing the address table, we have to cope with the fact that
20147 the addrmap iterator only provides the start of a region; we have to
20148 wait until the next invocation to get the start of the next region. */
20150 addrmap_index_data
.objfile
= objfile
;
20151 addrmap_index_data
.addr_obstack
= obstack
;
20152 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
20153 addrmap_index_data
.previous_valid
= 0;
20155 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
20156 &addrmap_index_data
);
20158 /* It's highly unlikely the last entry (end address = 0xff...ff)
20159 is valid, but we should still handle it.
20160 The end address is recorded as the start of the next region, but that
20161 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
20163 if (addrmap_index_data
.previous_valid
)
20164 add_address_entry (objfile
, obstack
,
20165 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
20166 addrmap_index_data
.previous_cu_index
);
20169 /* Return the symbol kind of PSYM. */
20171 static gdb_index_symbol_kind
20172 symbol_kind (struct partial_symbol
*psym
)
20174 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
20175 enum address_class aclass
= PSYMBOL_CLASS (psym
);
20183 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
20185 return GDB_INDEX_SYMBOL_KIND_TYPE
;
20187 case LOC_CONST_BYTES
:
20188 case LOC_OPTIMIZED_OUT
:
20190 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
20192 /* Note: It's currently impossible to recognize psyms as enum values
20193 short of reading the type info. For now punt. */
20194 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
20196 /* There are other LOC_FOO values that one might want to classify
20197 as variables, but dwarf2read.c doesn't currently use them. */
20198 return GDB_INDEX_SYMBOL_KIND_OTHER
;
20200 case STRUCT_DOMAIN
:
20201 return GDB_INDEX_SYMBOL_KIND_TYPE
;
20203 return GDB_INDEX_SYMBOL_KIND_OTHER
;
20207 /* Add a list of partial symbols to SYMTAB. */
20210 write_psymbols (struct mapped_symtab
*symtab
,
20212 struct partial_symbol
**psymp
,
20214 offset_type cu_index
,
20217 for (; count
-- > 0; ++psymp
)
20219 struct partial_symbol
*psym
= *psymp
;
20222 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
20223 error (_("Ada is not currently supported by the index"));
20225 /* Only add a given psymbol once. */
20226 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
20229 gdb_index_symbol_kind kind
= symbol_kind (psym
);
20232 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
20233 is_static
, kind
, cu_index
);
20238 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
20239 exception if there is an error. */
20242 write_obstack (FILE *file
, struct obstack
*obstack
)
20244 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
20246 != obstack_object_size (obstack
))
20247 error (_("couldn't data write to file"));
20250 /* Unlink a file if the argument is not NULL. */
20253 unlink_if_set (void *p
)
20255 char **filename
= p
;
20257 unlink (*filename
);
20260 /* A helper struct used when iterating over debug_types. */
20261 struct signatured_type_index_data
20263 struct objfile
*objfile
;
20264 struct mapped_symtab
*symtab
;
20265 struct obstack
*types_list
;
20270 /* A helper function that writes a single signatured_type to an
20274 write_one_signatured_type (void **slot
, void *d
)
20276 struct signatured_type_index_data
*info
= d
;
20277 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
20278 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
20279 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
20282 write_psymbols (info
->symtab
,
20284 info
->objfile
->global_psymbols
.list
20285 + psymtab
->globals_offset
,
20286 psymtab
->n_global_syms
, info
->cu_index
,
20288 write_psymbols (info
->symtab
,
20290 info
->objfile
->static_psymbols
.list
20291 + psymtab
->statics_offset
,
20292 psymtab
->n_static_syms
, info
->cu_index
,
20295 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
20296 entry
->per_cu
.offset
.sect_off
);
20297 obstack_grow (info
->types_list
, val
, 8);
20298 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
20299 entry
->type_offset_in_tu
.cu_off
);
20300 obstack_grow (info
->types_list
, val
, 8);
20301 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
20302 obstack_grow (info
->types_list
, val
, 8);
20309 /* Recurse into all "included" dependencies and write their symbols as
20310 if they appeared in this psymtab. */
20313 recursively_write_psymbols (struct objfile
*objfile
,
20314 struct partial_symtab
*psymtab
,
20315 struct mapped_symtab
*symtab
,
20317 offset_type cu_index
)
20321 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
20322 if (psymtab
->dependencies
[i
]->user
!= NULL
)
20323 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
20324 symtab
, psyms_seen
, cu_index
);
20326 write_psymbols (symtab
,
20328 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
20329 psymtab
->n_global_syms
, cu_index
,
20331 write_psymbols (symtab
,
20333 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
20334 psymtab
->n_static_syms
, cu_index
,
20338 /* Create an index file for OBJFILE in the directory DIR. */
20341 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
20343 struct cleanup
*cleanup
;
20344 char *filename
, *cleanup_filename
;
20345 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
20346 struct obstack cu_list
, types_cu_list
;
20349 struct mapped_symtab
*symtab
;
20350 offset_type val
, size_of_contents
, total_len
;
20353 htab_t cu_index_htab
;
20354 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
20356 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
20359 if (dwarf2_per_objfile
->using_index
)
20360 error (_("Cannot use an index to create the index"));
20362 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
20363 error (_("Cannot make an index when the file has multiple .debug_types sections"));
20365 if (stat (objfile
->name
, &st
) < 0)
20366 perror_with_name (objfile
->name
);
20368 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
20369 INDEX_SUFFIX
, (char *) NULL
);
20370 cleanup
= make_cleanup (xfree
, filename
);
20372 out_file
= fopen (filename
, "wb");
20374 error (_("Can't open `%s' for writing"), filename
);
20376 cleanup_filename
= filename
;
20377 make_cleanup (unlink_if_set
, &cleanup_filename
);
20379 symtab
= create_mapped_symtab ();
20380 make_cleanup (cleanup_mapped_symtab
, symtab
);
20382 obstack_init (&addr_obstack
);
20383 make_cleanup_obstack_free (&addr_obstack
);
20385 obstack_init (&cu_list
);
20386 make_cleanup_obstack_free (&cu_list
);
20388 obstack_init (&types_cu_list
);
20389 make_cleanup_obstack_free (&types_cu_list
);
20391 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
20392 NULL
, xcalloc
, xfree
);
20393 make_cleanup_htab_delete (psyms_seen
);
20395 /* While we're scanning CU's create a table that maps a psymtab pointer
20396 (which is what addrmap records) to its index (which is what is recorded
20397 in the index file). This will later be needed to write the address
20399 cu_index_htab
= htab_create_alloc (100,
20400 hash_psymtab_cu_index
,
20401 eq_psymtab_cu_index
,
20402 NULL
, xcalloc
, xfree
);
20403 make_cleanup_htab_delete (cu_index_htab
);
20404 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
20405 xmalloc (sizeof (struct psymtab_cu_index_map
)
20406 * dwarf2_per_objfile
->n_comp_units
);
20407 make_cleanup (xfree
, psymtab_cu_index_map
);
20409 /* The CU list is already sorted, so we don't need to do additional
20410 work here. Also, the debug_types entries do not appear in
20411 all_comp_units, but only in their own hash table. */
20412 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
20414 struct dwarf2_per_cu_data
*per_cu
20415 = dwarf2_per_objfile
->all_comp_units
[i
];
20416 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
20418 struct psymtab_cu_index_map
*map
;
20421 if (psymtab
->user
== NULL
)
20422 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
20424 map
= &psymtab_cu_index_map
[i
];
20425 map
->psymtab
= psymtab
;
20427 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
20428 gdb_assert (slot
!= NULL
);
20429 gdb_assert (*slot
== NULL
);
20432 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
20433 per_cu
->offset
.sect_off
);
20434 obstack_grow (&cu_list
, val
, 8);
20435 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
20436 obstack_grow (&cu_list
, val
, 8);
20439 /* Dump the address map. */
20440 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
20442 /* Write out the .debug_type entries, if any. */
20443 if (dwarf2_per_objfile
->signatured_types
)
20445 struct signatured_type_index_data sig_data
;
20447 sig_data
.objfile
= objfile
;
20448 sig_data
.symtab
= symtab
;
20449 sig_data
.types_list
= &types_cu_list
;
20450 sig_data
.psyms_seen
= psyms_seen
;
20451 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
20452 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
20453 write_one_signatured_type
, &sig_data
);
20456 /* Now that we've processed all symbols we can shrink their cu_indices
20458 uniquify_cu_indices (symtab
);
20460 obstack_init (&constant_pool
);
20461 make_cleanup_obstack_free (&constant_pool
);
20462 obstack_init (&symtab_obstack
);
20463 make_cleanup_obstack_free (&symtab_obstack
);
20464 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
20466 obstack_init (&contents
);
20467 make_cleanup_obstack_free (&contents
);
20468 size_of_contents
= 6 * sizeof (offset_type
);
20469 total_len
= size_of_contents
;
20471 /* The version number. */
20472 val
= MAYBE_SWAP (7);
20473 obstack_grow (&contents
, &val
, sizeof (val
));
20475 /* The offset of the CU list from the start of the file. */
20476 val
= MAYBE_SWAP (total_len
);
20477 obstack_grow (&contents
, &val
, sizeof (val
));
20478 total_len
+= obstack_object_size (&cu_list
);
20480 /* The offset of the types CU list from the start of the file. */
20481 val
= MAYBE_SWAP (total_len
);
20482 obstack_grow (&contents
, &val
, sizeof (val
));
20483 total_len
+= obstack_object_size (&types_cu_list
);
20485 /* The offset of the address table from the start of the file. */
20486 val
= MAYBE_SWAP (total_len
);
20487 obstack_grow (&contents
, &val
, sizeof (val
));
20488 total_len
+= obstack_object_size (&addr_obstack
);
20490 /* The offset of the symbol table from the start of the file. */
20491 val
= MAYBE_SWAP (total_len
);
20492 obstack_grow (&contents
, &val
, sizeof (val
));
20493 total_len
+= obstack_object_size (&symtab_obstack
);
20495 /* The offset of the constant pool from the start of the file. */
20496 val
= MAYBE_SWAP (total_len
);
20497 obstack_grow (&contents
, &val
, sizeof (val
));
20498 total_len
+= obstack_object_size (&constant_pool
);
20500 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
20502 write_obstack (out_file
, &contents
);
20503 write_obstack (out_file
, &cu_list
);
20504 write_obstack (out_file
, &types_cu_list
);
20505 write_obstack (out_file
, &addr_obstack
);
20506 write_obstack (out_file
, &symtab_obstack
);
20507 write_obstack (out_file
, &constant_pool
);
20511 /* We want to keep the file, so we set cleanup_filename to NULL
20512 here. See unlink_if_set. */
20513 cleanup_filename
= NULL
;
20515 do_cleanups (cleanup
);
20518 /* Implementation of the `save gdb-index' command.
20520 Note that the file format used by this command is documented in the
20521 GDB manual. Any changes here must be documented there. */
20524 save_gdb_index_command (char *arg
, int from_tty
)
20526 struct objfile
*objfile
;
20529 error (_("usage: save gdb-index DIRECTORY"));
20531 ALL_OBJFILES (objfile
)
20535 /* If the objfile does not correspond to an actual file, skip it. */
20536 if (stat (objfile
->name
, &st
) < 0)
20539 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
20540 if (dwarf2_per_objfile
)
20542 volatile struct gdb_exception except
;
20544 TRY_CATCH (except
, RETURN_MASK_ERROR
)
20546 write_psymtabs_to_index (objfile
, arg
);
20548 if (except
.reason
< 0)
20549 exception_fprintf (gdb_stderr
, except
,
20550 _("Error while writing index for `%s': "),
20558 int dwarf2_always_disassemble
;
20561 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
20562 struct cmd_list_element
*c
, const char *value
)
20564 fprintf_filtered (file
,
20565 _("Whether to always disassemble "
20566 "DWARF expressions is %s.\n"),
20571 show_check_physname (struct ui_file
*file
, int from_tty
,
20572 struct cmd_list_element
*c
, const char *value
)
20574 fprintf_filtered (file
,
20575 _("Whether to check \"physname\" is %s.\n"),
20579 void _initialize_dwarf2_read (void);
20582 _initialize_dwarf2_read (void)
20584 struct cmd_list_element
*c
;
20586 dwarf2_objfile_data_key
20587 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
20589 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
20590 Set DWARF 2 specific variables.\n\
20591 Configure DWARF 2 variables such as the cache size"),
20592 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
20593 0/*allow-unknown*/, &maintenance_set_cmdlist
);
20595 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
20596 Show DWARF 2 specific variables\n\
20597 Show DWARF 2 variables such as the cache size"),
20598 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
20599 0/*allow-unknown*/, &maintenance_show_cmdlist
);
20601 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
20602 &dwarf2_max_cache_age
, _("\
20603 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
20604 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
20605 A higher limit means that cached compilation units will be stored\n\
20606 in memory longer, and more total memory will be used. Zero disables\n\
20607 caching, which can slow down startup."),
20609 show_dwarf2_max_cache_age
,
20610 &set_dwarf2_cmdlist
,
20611 &show_dwarf2_cmdlist
);
20613 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
20614 &dwarf2_always_disassemble
, _("\
20615 Set whether `info address' always disassembles DWARF expressions."), _("\
20616 Show whether `info address' always disassembles DWARF expressions."), _("\
20617 When enabled, DWARF expressions are always printed in an assembly-like\n\
20618 syntax. When disabled, expressions will be printed in a more\n\
20619 conversational style, when possible."),
20621 show_dwarf2_always_disassemble
,
20622 &set_dwarf2_cmdlist
,
20623 &show_dwarf2_cmdlist
);
20625 add_setshow_boolean_cmd ("dwarf2-read", no_class
, &dwarf2_read_debug
, _("\
20626 Set debugging of the dwarf2 reader."), _("\
20627 Show debugging of the dwarf2 reader."), _("\
20628 When enabled, debugging messages are printed during dwarf2 reading\n\
20629 and symtab expansion."),
20632 &setdebuglist
, &showdebuglist
);
20634 add_setshow_zuinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
20635 Set debugging of the dwarf2 DIE reader."), _("\
20636 Show debugging of the dwarf2 DIE reader."), _("\
20637 When enabled (non-zero), DIEs are dumped after they are read in.\n\
20638 The value is the maximum depth to print."),
20641 &setdebuglist
, &showdebuglist
);
20643 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
20644 Set cross-checking of \"physname\" code against demangler."), _("\
20645 Show cross-checking of \"physname\" code against demangler."), _("\
20646 When enabled, GDB's internal \"physname\" code is checked against\n\
20648 NULL
, show_check_physname
,
20649 &setdebuglist
, &showdebuglist
);
20651 add_setshow_boolean_cmd ("use-deprecated-index-sections",
20652 no_class
, &use_deprecated_index_sections
, _("\
20653 Set whether to use deprecated gdb_index sections."), _("\
20654 Show whether to use deprecated gdb_index sections."), _("\
20655 When enabled, deprecated .gdb_index sections are used anyway.\n\
20656 Normally they are ignored either because of a missing feature or\n\
20657 performance issue.\n\
20658 Warning: This option must be enabled before gdb reads the file."),
20661 &setlist
, &showlist
);
20663 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
20665 Save a gdb-index file.\n\
20666 Usage: save gdb-index DIRECTORY"),
20668 set_cmd_completer (c
, filename_completer
);