1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992-2024 Free Software Foundation, Inc.
3 Contributed by Gary Funck (gary@intrepid.com).
4 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
5 Extensively modified by Jason Merrill (jason@cygnus.com).
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
23 /* TODO: Emit .debug_line header even when there are no functions, since
24 the file numbers are used by .debug_info. Alternately, leave
25 out locations for types and decls.
26 Avoid talking about ctors and op= for PODs.
27 Factor out common prologue sequences into multiple CIEs. */
29 /* The first part of this file deals with the DWARF 2 frame unwind
30 information, which is also used by the GCC efficient exception handling
31 mechanism. The second part, controlled only by an #ifdef
32 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
35 /* DWARF2 Abbreviation Glossary:
37 CFA = Canonical Frame Address
38 a fixed address on the stack which identifies a call frame.
39 We define it to be the value of SP just before the call insn.
40 The CFA register and offset, which may change during the course
41 of the function, are used to calculate its value at runtime.
43 CFI = Call Frame Instruction
44 an instruction for the DWARF2 abstract machine
46 CIE = Common Information Entry
47 information describing information common to one or more FDEs
49 DIE = Debugging Information Entry
51 FDE = Frame Description Entry
52 information describing the stack call frame, in particular,
53 how to restore registers
55 DW_CFA_... = DWARF2 CFA call frame instruction
56 DW_TAG_... = DWARF2 DIE tag */
60 #include "coretypes.h"
67 #include "stringpool.h"
68 #include "insn-config.h"
71 #include "diagnostic.h"
72 #include "fold-const.h"
73 #include "stor-layout.h"
81 #include "dwarf2out.h"
82 #include "dwarf2ctf.h"
83 #include "dwarf2codeview.h"
84 #include "dwarf2asm.h"
87 #include "tree-pretty-print.h"
88 #include "print-rtl.h"
90 #include "common/common-target.h"
91 #include "langhooks.h"
96 #include "gdb/gdb-index.h"
98 #include "stringpool.h"
100 #include "file-prefix-map.h" /* remap_debug_filename() */
102 static void dwarf2out_source_line (unsigned int, unsigned int, const char *,
104 static rtx_insn
*last_var_location_insn
;
105 static rtx_insn
*cached_next_real_insn
;
106 static void dwarf2out_decl (tree
);
107 static bool is_redundant_typedef (const_tree
);
109 #ifndef XCOFF_DEBUGGING_INFO
110 #define XCOFF_DEBUGGING_INFO 0
113 #ifndef HAVE_XCOFF_DWARF_EXTRAS
114 #define HAVE_XCOFF_DWARF_EXTRAS 0
117 #ifdef VMS_DEBUGGING_INFO
118 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
120 /* Define this macro to be a nonzero value if the directory specifications
121 which are output in the debug info should end with a separator. */
122 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
123 /* Define this macro to evaluate to a nonzero value if GCC should refrain
124 from generating indirect strings in DWARF2 debug information, for instance
125 if your target is stuck with an old version of GDB that is unable to
126 process them properly or uses VMS Debug. */
127 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
129 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
130 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
133 /* ??? Poison these here until it can be done generically. They've been
134 totally replaced in this file; make sure it stays that way. */
135 #undef DWARF2_UNWIND_INFO
136 #undef DWARF2_FRAME_INFO
137 #if (GCC_VERSION >= 3000)
138 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
141 /* The size of the target's pointer type. */
143 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
146 /* Array of RTXes referenced by the debugging information, which therefore
147 must be kept around forever. */
148 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
150 /* A pointer to the base of a list of incomplete types which might be
151 completed at some later time. incomplete_types_list needs to be a
152 vec<tree, va_gc> *because we want to tell the garbage collector about
154 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
156 /* Pointers to various DWARF2 sections. */
157 static GTY(()) section
*debug_info_section
;
158 static GTY(()) section
*debug_skeleton_info_section
;
159 static GTY(()) section
*debug_abbrev_section
;
160 static GTY(()) section
*debug_skeleton_abbrev_section
;
161 static GTY(()) section
*debug_aranges_section
;
162 static GTY(()) section
*debug_addr_section
;
163 static GTY(()) section
*debug_macinfo_section
;
164 static const char *debug_macinfo_section_name
;
165 static unsigned macinfo_label_base
= 1;
166 static GTY(()) section
*debug_line_section
;
167 static GTY(()) section
*debug_skeleton_line_section
;
168 static GTY(()) section
*debug_loc_section
;
169 static GTY(()) section
*debug_pubnames_section
;
170 static GTY(()) section
*debug_pubtypes_section
;
171 static GTY(()) section
*debug_str_section
;
172 static GTY(()) section
*debug_line_str_section
;
173 static GTY(()) section
*debug_str_dwo_section
;
174 static GTY(()) section
*debug_str_offsets_section
;
175 static GTY(()) section
*debug_ranges_section
;
176 static GTY(()) section
*debug_ranges_dwo_section
;
177 static GTY(()) section
*debug_frame_section
;
179 /* Maximum size (in bytes) of an artificially generated label. */
180 #define MAX_ARTIFICIAL_LABEL_BYTES 40
182 /* According to the (draft) DWARF 3 specification, the initial length
183 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
184 bytes are 0xffffffff, followed by the length stored in the next 8
187 However, the SGI/MIPS ABI uses an initial length which is equal to
188 dwarf_offset_size. It is defined (elsewhere) accordingly. */
190 #ifndef DWARF_INITIAL_LENGTH_SIZE
191 #define DWARF_INITIAL_LENGTH_SIZE (dwarf_offset_size == 4 ? 4 : 12)
194 #ifndef DWARF_INITIAL_LENGTH_SIZE_STR
195 #define DWARF_INITIAL_LENGTH_SIZE_STR (dwarf_offset_size == 4 ? "-4" : "-12")
198 /* Round SIZE up to the nearest BOUNDARY. */
199 #define DWARF_ROUND(SIZE,BOUNDARY) \
200 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
202 /* CIE identifier. */
203 #if HOST_BITS_PER_WIDE_INT >= 64
204 #define DWARF_CIE_ID \
205 (unsigned HOST_WIDE_INT) (dwarf_offset_size == 4 ? DW_CIE_ID : DW64_CIE_ID)
207 #define DWARF_CIE_ID DW_CIE_ID
211 /* A vector for a table that contains frame description
212 information for each routine. */
213 #define NOT_INDEXED (-1U)
214 #define NO_INDEX_ASSIGNED (-2U)
216 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
218 struct GTY((for_user
)) indirect_string_node
{
220 unsigned int refcount
;
221 enum dwarf_form form
;
226 struct indirect_string_hasher
: ggc_ptr_hash
<indirect_string_node
>
228 typedef const char *compare_type
;
230 static hashval_t
hash (indirect_string_node
*);
231 static bool equal (indirect_string_node
*, const char *);
234 static GTY (()) hash_table
<indirect_string_hasher
> *debug_str_hash
;
236 static GTY (()) hash_table
<indirect_string_hasher
> *debug_line_str_hash
;
238 /* With split_debug_info, both the comp_dir and dwo_name go in the
239 main object file, rather than the dwo, similar to the force_direct
240 parameter elsewhere but with additional complications:
242 1) The string is needed in both the main object file and the dwo.
243 That is, the comp_dir and dwo_name will appear in both places.
245 2) Strings can use four forms: DW_FORM_string, DW_FORM_strp,
246 DW_FORM_line_strp or DW_FORM_strx/GNU_str_index.
248 3) GCC chooses the form to use late, depending on the size and
251 Rather than forcing the all debug string handling functions and
252 callers to deal with these complications, simply use a separate,
253 special-cased string table for any attribute that should go in the
254 main object file. This limits the complexity to just the places
257 static GTY (()) hash_table
<indirect_string_hasher
> *skeleton_debug_str_hash
;
259 static GTY(()) int dw2_string_counter
;
261 /* True if the compilation unit places functions in more than one section. */
262 static GTY(()) bool have_multiple_function_sections
= false;
264 /* The default cold text section. */
265 static GTY(()) section
*cold_text_section
;
267 /* True if currently in text section. */
268 static GTY(()) bool in_text_section_p
= false;
270 /* Last debug-on location in corresponding section. */
271 static GTY(()) const char *last_text_label
;
272 static GTY(()) const char *last_cold_label
;
274 /* Mark debug-on/off locations per section.
275 NULL means the section is not used at all. */
276 static GTY(()) vec
<const char *, va_gc
> *switch_text_ranges
;
277 static GTY(()) vec
<const char *, va_gc
> *switch_cold_ranges
;
279 /* The DIE for C++14 'auto' in a function return type. */
280 static GTY(()) dw_die_ref auto_die
;
282 /* The DIE for C++14 'decltype(auto)' in a function return type. */
283 static GTY(()) dw_die_ref decltype_auto_die
;
285 /* Forward declarations for functions defined in this file. */
287 static void output_call_frame_info (int);
289 /* Personality decl of current unit. Used only when assembler does not support
291 static GTY(()) rtx current_unit_personality
;
293 /* Whether an eh_frame section is required. */
294 static GTY(()) bool do_eh_frame
= false;
296 /* .debug_rnglists next index. */
297 static unsigned int rnglist_idx
;
299 /* Data and reference forms for relocatable data. */
300 #define DW_FORM_data (dwarf_offset_size == 8 ? DW_FORM_data8 : DW_FORM_data4)
301 #define DW_FORM_ref (dwarf_offset_size == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
303 #ifndef DEBUG_FRAME_SECTION
304 #define DEBUG_FRAME_SECTION ".debug_frame"
307 #ifndef FUNC_BEGIN_LABEL
308 #define FUNC_BEGIN_LABEL "LFB"
311 #ifndef FUNC_SECOND_SECT_LABEL
312 #define FUNC_SECOND_SECT_LABEL "LFSB"
315 #ifndef FUNC_END_LABEL
316 #define FUNC_END_LABEL "LFE"
319 #ifndef PROLOGUE_END_LABEL
320 #define PROLOGUE_END_LABEL "LPE"
323 #ifndef EPILOGUE_BEGIN_LABEL
324 #define EPILOGUE_BEGIN_LABEL "LEB"
327 #ifndef FRAME_BEGIN_LABEL
328 #define FRAME_BEGIN_LABEL "Lframe"
330 #define CIE_AFTER_SIZE_LABEL "LSCIE"
331 #define CIE_END_LABEL "LECIE"
332 #define FDE_LABEL "LSFDE"
333 #define FDE_AFTER_SIZE_LABEL "LASFDE"
334 #define FDE_END_LABEL "LEFDE"
335 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
336 #define LINE_NUMBER_END_LABEL "LELT"
337 #define LN_PROLOG_AS_LABEL "LASLTP"
338 #define LN_PROLOG_END_LABEL "LELTP"
339 #define DIE_LABEL_PREFIX "DW"
341 /* Match the base name of a file to the base name of a compilation unit. */
344 matches_main_base (const char *path
)
346 /* Cache the last query. */
347 static const char *last_path
= NULL
;
348 static bool last_match
= false;
349 if (path
!= last_path
)
352 int length
= base_of_path (path
, &base
);
354 last_match
= (length
== main_input_baselength
355 && memcmp (base
, main_input_basename
, length
) == 0);
360 #ifdef DEBUG_DEBUG_STRUCT
363 dump_struct_debug (tree type
, enum debug_info_usage usage
,
364 enum debug_struct_file criterion
, int generic
,
365 bool matches
, bool result
)
367 /* Find the type name. */
368 tree type_decl
= TYPE_STUB_DECL (type
);
370 const char *name
= 0;
371 if (TREE_CODE (t
) == TYPE_DECL
)
374 name
= IDENTIFIER_POINTER (t
);
376 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
378 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
379 matches
? "bas" : "hdr",
380 generic
? "gen" : "ord",
381 usage
== DINFO_USAGE_DFN
? ";" :
382 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
384 (void*) type_decl
, name
);
387 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
388 dump_struct_debug (type, usage, criterion, generic, matches, result)
392 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
397 /* Get the number of HOST_WIDE_INTs needed to represent the precision
401 get_full_len (const dw_wide_int
&op
)
403 return CEIL (op
.get_precision (), HOST_BITS_PER_WIDE_INT
);
407 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
409 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
412 enum debug_struct_file criterion
;
414 bool generic
= lang_hooks
.types
.generic_p (type
);
417 criterion
= debug_struct_generic
[usage
];
419 criterion
= debug_struct_ordinary
[usage
];
421 if (criterion
== DINFO_STRUCT_FILE_NONE
)
422 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
423 if (criterion
== DINFO_STRUCT_FILE_ANY
)
424 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
426 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
428 if (type_decl
!= NULL
)
430 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
431 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
433 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
434 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
437 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
440 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
441 switch to the data section instead, and write out a synthetic start label
442 for collect2 the first time around. */
445 switch_to_eh_frame_section (bool back ATTRIBUTE_UNUSED
)
447 if (eh_frame_section
== 0)
451 if (EH_TABLES_CAN_BE_READ_ONLY
)
457 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
459 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
461 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
464 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
465 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
466 && (per_encoding
& 0x70) != DW_EH_PE_absptr
467 && (per_encoding
& 0x70) != DW_EH_PE_aligned
468 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
469 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
470 ? 0 : SECTION_WRITE
);
473 flags
= SECTION_WRITE
;
475 #ifdef EH_FRAME_SECTION_NAME
476 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
478 eh_frame_section
= ((flags
== SECTION_WRITE
)
479 ? data_section
: readonly_data_section
);
480 #endif /* EH_FRAME_SECTION_NAME */
483 switch_to_section (eh_frame_section
);
485 #ifdef EH_FRAME_THROUGH_COLLECT2
486 /* We have no special eh_frame section. Emit special labels to guide
490 tree label
= get_file_function_name ("F");
491 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
492 targetm
.asm_out
.globalize_label (asm_out_file
,
493 IDENTIFIER_POINTER (label
));
494 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
499 /* Switch [BACK] to the eh or debug frame table section, depending on
503 switch_to_frame_table_section (int for_eh
, bool back
)
506 switch_to_eh_frame_section (back
);
509 if (!debug_frame_section
)
510 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
511 SECTION_DEBUG
, NULL
);
512 switch_to_section (debug_frame_section
);
516 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
518 enum dw_cfi_oprnd_type
519 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
524 case DW_CFA_GNU_window_save
:
525 case DW_CFA_remember_state
:
526 case DW_CFA_restore_state
:
527 return dw_cfi_oprnd_unused
;
530 case DW_CFA_advance_loc1
:
531 case DW_CFA_advance_loc2
:
532 case DW_CFA_advance_loc4
:
533 case DW_CFA_MIPS_advance_loc8
:
534 return dw_cfi_oprnd_addr
;
537 case DW_CFA_offset_extended
:
539 case DW_CFA_offset_extended_sf
:
540 case DW_CFA_def_cfa_sf
:
542 case DW_CFA_restore_extended
:
543 case DW_CFA_undefined
:
544 case DW_CFA_same_value
:
545 case DW_CFA_def_cfa_register
:
546 case DW_CFA_register
:
547 case DW_CFA_expression
:
548 case DW_CFA_val_expression
:
549 return dw_cfi_oprnd_reg_num
;
551 case DW_CFA_def_cfa_offset
:
552 case DW_CFA_GNU_args_size
:
553 case DW_CFA_def_cfa_offset_sf
:
554 return dw_cfi_oprnd_offset
;
556 case DW_CFA_def_cfa_expression
:
557 return dw_cfi_oprnd_loc
;
564 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
566 enum dw_cfi_oprnd_type
567 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
572 case DW_CFA_def_cfa_sf
:
574 case DW_CFA_offset_extended_sf
:
575 case DW_CFA_offset_extended
:
576 return dw_cfi_oprnd_offset
;
578 case DW_CFA_register
:
579 return dw_cfi_oprnd_reg_num
;
581 case DW_CFA_expression
:
582 case DW_CFA_val_expression
:
583 return dw_cfi_oprnd_loc
;
585 case DW_CFA_def_cfa_expression
:
586 return dw_cfi_oprnd_cfa_loc
;
589 return dw_cfi_oprnd_unused
;
593 /* Output one FDE. */
596 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
597 char *section_start_label
, int fde_encoding
, char *augmentation
,
598 bool any_lsda_needed
, int lsda_encoding
)
600 const char *begin
, *end
;
601 static unsigned int j
;
602 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
604 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
606 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
608 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
609 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
610 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
612 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4 && !for_eh
)
613 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
614 " indicating 64-bit DWARF extension");
615 dw2_asm_output_delta (for_eh
? 4 : dwarf_offset_size
, l2
, l1
,
618 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
621 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
623 dw2_asm_output_offset (dwarf_offset_size
, section_start_label
,
624 debug_frame_section
, "FDE CIE offset");
626 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
627 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
631 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
632 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
633 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
634 "FDE initial location");
635 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
636 end
, begin
, "FDE address range");
640 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
641 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
648 int size
= size_of_encoded_value (lsda_encoding
);
650 if (lsda_encoding
== DW_EH_PE_aligned
)
652 int offset
= ( 4 /* Length */
654 + 2 * size_of_encoded_value (fde_encoding
)
655 + 1 /* Augmentation size */ );
656 int pad
= -offset
& (PTR_SIZE
- 1);
659 gcc_assert (size_of_uleb128 (size
) == 1);
662 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
664 if (fde
->uses_eh_lsda
)
666 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
667 fde
->funcdef_number
);
668 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
669 gen_rtx_SYMBOL_REF (Pmode
, l1
),
671 "Language Specific Data Area");
675 if (lsda_encoding
== DW_EH_PE_aligned
)
676 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
677 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
678 "Language Specific Data Area (none)");
682 dw2_asm_output_data_uleb128 (0, "Augmentation size");
685 /* Loop through the Call Frame Instructions associated with this FDE. */
686 fde
->dw_fde_current_label
= begin
;
688 size_t from
, until
, i
;
691 until
= vec_safe_length (fde
->dw_fde_cfi
);
693 if (fde
->dw_fde_second_begin
== NULL
)
696 until
= fde
->dw_fde_switch_cfi_index
;
698 from
= fde
->dw_fde_switch_cfi_index
;
700 for (i
= from
; i
< until
; i
++)
701 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
704 /* If we are to emit a ref/link from function bodies to their frame tables,
705 do it now. This is typically performed to make sure that tables
706 associated with functions are dragged with them and not discarded in
707 garbage collecting links. We need to do this on a per function basis to
708 cope with -ffunction-sections. */
710 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
711 /* Switch to the function section, emit the ref to the tables, and
712 switch *back* into the table section. */
713 switch_to_section (function_section (fde
->decl
));
714 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
715 switch_to_frame_table_section (for_eh
, true);
718 /* Pad the FDE out to an address sized boundary. */
719 ASM_OUTPUT_ALIGN (asm_out_file
,
720 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
721 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
726 /* Return true if frame description entry FDE is needed for EH. */
729 fde_needed_for_eh_p (dw_fde_ref fde
)
731 if (flag_asynchronous_unwind_tables
)
734 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
737 if (fde
->uses_eh_lsda
)
740 /* If exceptions are enabled, we have collected nothrow info. */
741 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
747 /* Output the call frame information used to record information
748 that relates to calculating the frame pointer, and records the
749 location of saved registers. */
752 output_call_frame_info (int for_eh
)
757 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
758 char section_start_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
759 bool any_lsda_needed
= false;
760 char augmentation
[6];
761 int augmentation_size
;
762 int fde_encoding
= DW_EH_PE_absptr
;
763 int per_encoding
= DW_EH_PE_absptr
;
764 int lsda_encoding
= DW_EH_PE_absptr
;
766 rtx personality
= NULL
;
769 /* Don't emit a CIE if there won't be any FDEs. */
773 /* Nothing to do if the assembler's doing it all. */
774 if (dwarf2out_do_cfi_asm ())
777 /* If we don't have any functions we'll want to unwind out of, don't emit
778 any EH unwind information. If we make FDEs linkonce, we may have to
779 emit an empty label for an FDE that wouldn't otherwise be emitted. We
780 want to avoid having an FDE kept around when the function it refers to
781 is discarded. Example where this matters: a primary function template
782 in C++ requires EH information, an explicit specialization doesn't. */
785 bool any_eh_needed
= false;
787 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
789 if (fde
->uses_eh_lsda
)
790 any_eh_needed
= any_lsda_needed
= true;
791 else if (fde_needed_for_eh_p (fde
))
792 any_eh_needed
= true;
793 else if (TARGET_USES_WEAK_UNWIND_INFO
)
794 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
801 /* We're going to be generating comments, so turn on app. */
805 /* Switch to the proper frame section, first time. */
806 switch_to_frame_table_section (for_eh
, false);
808 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
809 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
811 /* Output the CIE. */
812 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
813 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
814 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
816 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4 && !for_eh
)
817 dw2_asm_output_data (4, 0xffffffff,
818 "Initial length escape value indicating 64-bit DWARF extension");
819 dw2_asm_output_delta (for_eh
? 4 : dwarf_offset_size
, l2
, l1
,
820 "Length of Common Information Entry");
822 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
824 /* Now that the CIE pointer is PC-relative for EH,
825 use 0 to identify the CIE. */
826 dw2_asm_output_data ((for_eh
? 4 : dwarf_offset_size
),
827 (for_eh
? 0 : DWARF_CIE_ID
),
828 "CIE Identifier Tag");
830 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
831 use CIE version 1, unless that would produce incorrect results
832 due to overflowing the return register column. */
833 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
835 if (return_reg
>= 256 || dwarf_version
> 2)
837 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
840 augmentation_size
= 0;
842 personality
= current_unit_personality
;
848 z Indicates that a uleb128 is present to size the
849 augmentation section.
850 L Indicates the encoding (and thus presence) of
851 an LSDA pointer in the FDE augmentation.
852 R Indicates a non-default pointer encoding for
854 P Indicates the presence of an encoding + language
855 personality routine in the CIE augmentation. */
857 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
858 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
859 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
861 p
= augmentation
+ 1;
865 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
866 assemble_external_libcall (personality
);
871 augmentation_size
+= 1;
873 if (fde_encoding
!= DW_EH_PE_absptr
)
876 augmentation_size
+= 1;
878 if (p
> augmentation
+ 1)
880 augmentation
[0] = 'z';
884 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
885 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
887 int offset
= ( 4 /* Length */
889 + 1 /* CIE version */
890 + strlen (augmentation
) + 1 /* Augmentation */
891 + size_of_uleb128 (1) /* Code alignment */
892 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
894 + 1 /* Augmentation size */
895 + 1 /* Personality encoding */ );
896 int pad
= -offset
& (PTR_SIZE
- 1);
898 augmentation_size
+= pad
;
900 /* Augmentations should be small, so there's scarce need to
901 iterate for a solution. Die if we exceed one uleb128 byte. */
902 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
906 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
907 if (dw_cie_version
>= 4)
909 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
910 dw2_asm_output_data (1, 0, "CIE Segment Size");
912 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
913 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
914 "CIE Data Alignment Factor");
916 if (dw_cie_version
== 1)
917 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
919 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
923 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
926 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
927 eh_data_format_name (per_encoding
));
928 dw2_asm_output_encoded_addr_rtx (per_encoding
,
934 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
935 eh_data_format_name (lsda_encoding
));
937 if (fde_encoding
!= DW_EH_PE_absptr
)
938 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
939 eh_data_format_name (fde_encoding
));
942 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
943 output_cfi (cfi
, NULL
, for_eh
);
945 /* Pad the CIE out to an address sized boundary. */
946 ASM_OUTPUT_ALIGN (asm_out_file
,
947 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
948 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
950 /* Loop through all of the FDE's. */
951 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
955 /* Don't emit EH unwind info for leaf functions that don't need it. */
956 if (for_eh
&& !fde_needed_for_eh_p (fde
))
959 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
960 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
961 augmentation
, any_lsda_needed
, lsda_encoding
);
964 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
965 dw2_asm_output_data (4, 0, "End of Table");
967 /* Turn off app to make assembly quicker. */
972 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
975 dwarf2out_do_cfi_startproc (bool second
)
980 fprintf (asm_out_file
, "\t.cfi_startproc\n");
982 targetm
.asm_out
.post_cfi_startproc (asm_out_file
, current_function_decl
);
984 /* .cfi_personality and .cfi_lsda are only relevant to DWARF2
986 if (targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
)
989 rtx personality
= get_personality_function (current_function_decl
);
993 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
996 /* ??? The GAS support isn't entirely consistent. We have to
997 handle indirect support ourselves, but PC-relative is done
998 in the assembler. Further, the assembler can't handle any
999 of the weirder relocation types. */
1000 if (enc
& DW_EH_PE_indirect
)
1002 if (targetm
.asm_out
.make_eh_symbol_indirect
!= NULL
)
1003 ref
= targetm
.asm_out
.make_eh_symbol_indirect (ref
, true);
1005 ref
= dw2_force_const_mem (ref
, true);
1008 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
1009 output_addr_const (asm_out_file
, ref
);
1010 fputc ('\n', asm_out_file
);
1013 if (crtl
->uses_eh_lsda
)
1015 char lab
[MAX_ARTIFICIAL_LABEL_BYTES
];
1017 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1018 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
1019 current_function_funcdef_no
);
1020 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
1021 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
1023 if (enc
& DW_EH_PE_indirect
)
1025 if (targetm
.asm_out
.make_eh_symbol_indirect
!= NULL
)
1026 ref
= targetm
.asm_out
.make_eh_symbol_indirect (ref
, true);
1028 ref
= dw2_force_const_mem (ref
, true);
1031 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
1032 output_addr_const (asm_out_file
, ref
);
1033 fputc ('\n', asm_out_file
);
1037 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
1038 this allocation may be done before pass_final. */
1041 dwarf2out_alloc_current_fde (void)
1045 fde
= ggc_cleared_alloc
<dw_fde_node
> ();
1046 fde
->decl
= current_function_decl
;
1047 fde
->funcdef_number
= current_function_funcdef_no
;
1048 fde
->fde_index
= vec_safe_length (fde_vec
);
1049 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
1050 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
1051 fde
->nothrow
= crtl
->nothrow
;
1052 fde
->drap_reg
= INVALID_REGNUM
;
1053 fde
->vdrap_reg
= INVALID_REGNUM
;
1055 /* Record the FDE associated with this function. */
1057 vec_safe_push (fde_vec
, fde
);
1062 /* Output a marker (i.e. a label) for the beginning of a function, before
1066 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1067 unsigned int column ATTRIBUTE_UNUSED
,
1068 const char *file ATTRIBUTE_UNUSED
)
1070 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1076 current_function_func_begin_label
= NULL
;
1078 do_frame
= dwarf2out_do_frame ();
1080 /* ??? current_function_func_begin_label is also used by except.cc for
1081 call-site information. We must emit this label if it might be used. */
1083 && (!flag_exceptions
1084 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1087 fnsec
= function_section (current_function_decl
);
1088 switch_to_section (fnsec
);
1089 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1090 current_function_funcdef_no
);
1091 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1092 current_function_funcdef_no
);
1093 dup_label
= xstrdup (label
);
1094 current_function_func_begin_label
= dup_label
;
1096 /* We can elide FDE allocation if we're not emitting frame unwind info. */
1100 /* Unlike the debug version, the EH version of frame unwind info is a per-
1101 function setting so we need to record whether we need it for the unit. */
1102 do_eh_frame
|= dwarf2out_do_eh_frame ();
1104 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1105 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1106 would include pass_dwarf2_frame. If we've not created the FDE yet,
1110 fde
= dwarf2out_alloc_current_fde ();
1112 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1113 fde
->dw_fde_begin
= dup_label
;
1114 fde
->dw_fde_current_label
= dup_label
;
1115 fde
->in_std_section
= (fnsec
== text_section
1116 || (cold_text_section
&& fnsec
== cold_text_section
));
1117 fde
->ignored_debug
= DECL_IGNORED_P (current_function_decl
);
1118 in_text_section_p
= fnsec
== text_section
;
1120 /* We only want to output line number information for the genuine dwarf2
1121 prologue case, not the eh frame case. */
1122 #ifdef DWARF2_DEBUGGING_INFO
1124 dwarf2out_source_line (line
, column
, file
, 0, true);
1127 if (dwarf2out_do_cfi_asm ())
1128 dwarf2out_do_cfi_startproc (false);
1131 rtx personality
= get_personality_function (current_function_decl
);
1132 if (!current_unit_personality
)
1133 current_unit_personality
= personality
;
1135 /* We cannot keep a current personality per function as without CFI
1136 asm, at the point where we emit the CFI data, there is no current
1137 function anymore. */
1138 if (personality
&& current_unit_personality
!= personality
)
1139 sorry ("multiple EH personalities are supported only with assemblers "
1140 "supporting %<.cfi_personality%> directive");
1144 /* Output a marker (i.e. a label) for the end of the generated code
1145 for a function prologue. This gets called *after* the prologue code has
1149 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1150 const char *file ATTRIBUTE_UNUSED
)
1152 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1154 /* Output a label to mark the endpoint of the code generated for this
1156 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1157 current_function_funcdef_no
);
1158 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1159 current_function_funcdef_no
);
1160 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1163 /* Output a marker (i.e. a label) for the beginning of the generated code
1164 for a function epilogue. This gets called *before* the prologue code has
1168 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1169 const char *file ATTRIBUTE_UNUSED
)
1171 dw_fde_ref fde
= cfun
->fde
;
1172 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1174 if (fde
->dw_fde_vms_begin_epilogue
)
1177 /* Output a label to mark the endpoint of the code generated for this
1179 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1180 current_function_funcdef_no
);
1181 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1182 current_function_funcdef_no
);
1183 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1186 /* Mark the ranges of non-debug subsections in the std text sections. */
1189 mark_ignored_debug_section (dw_fde_ref fde
, bool second
)
1192 const char *begin_label
, *end_label
;
1193 const char **last_end_label
;
1194 vec
<const char *, va_gc
> **switch_ranges
;
1198 std_section
= fde
->second_in_std_section
;
1199 begin_label
= fde
->dw_fde_second_begin
;
1200 end_label
= fde
->dw_fde_second_end
;
1204 std_section
= fde
->in_std_section
;
1205 begin_label
= fde
->dw_fde_begin
;
1206 end_label
= fde
->dw_fde_end
;
1212 if (in_text_section_p
)
1214 last_end_label
= &last_text_label
;
1215 switch_ranges
= &switch_text_ranges
;
1219 last_end_label
= &last_cold_label
;
1220 switch_ranges
= &switch_cold_ranges
;
1223 if (fde
->ignored_debug
)
1225 if (*switch_ranges
&& !(vec_safe_length (*switch_ranges
) & 1))
1226 vec_safe_push (*switch_ranges
, *last_end_label
);
1230 *last_end_label
= end_label
;
1232 if (!*switch_ranges
)
1233 vec_alloc (*switch_ranges
, 16);
1234 else if (vec_safe_length (*switch_ranges
) & 1)
1235 vec_safe_push (*switch_ranges
, begin_label
);
1239 /* Output a marker (i.e. a label) for the absolute end of the generated code
1240 for a function definition. This gets called *after* the epilogue code has
1244 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1245 const char *file ATTRIBUTE_UNUSED
)
1248 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1250 last_var_location_insn
= NULL
;
1251 cached_next_real_insn
= NULL
;
1253 if (dwarf2out_do_cfi_asm ())
1254 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1256 /* Output a label to mark the endpoint of the code generated for this
1258 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1259 current_function_funcdef_no
);
1260 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1262 gcc_assert (fde
!= NULL
);
1263 if (fde
->dw_fde_second_begin
== NULL
)
1264 fde
->dw_fde_end
= xstrdup (label
);
1266 mark_ignored_debug_section (fde
, fde
->dw_fde_second_begin
!= NULL
);
1270 dwarf2out_frame_finish (void)
1272 /* Output call frame information. */
1273 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1274 output_call_frame_info (0);
1276 /* Output another copy for the unwinder. */
1278 output_call_frame_info (1);
1281 static void var_location_switch_text_section (void);
1282 static void set_cur_line_info_table (section
*);
1285 dwarf2out_switch_text_section (void)
1287 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1289 dw_fde_ref fde
= cfun
->fde
;
1291 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1293 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_SECOND_SECT_LABEL
,
1294 current_function_funcdef_no
);
1296 fde
->dw_fde_second_begin
= ggc_strdup (label
);
1297 if (!in_cold_section_p
)
1299 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1300 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1304 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1305 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1307 have_multiple_function_sections
= true;
1309 if (dwarf2out_do_cfi_asm ())
1310 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1312 mark_ignored_debug_section (fde
, false);
1314 /* Now do the real section switch. */
1315 sect
= current_function_section ();
1316 switch_to_section (sect
);
1318 fde
->second_in_std_section
1319 = (sect
== text_section
1320 || (cold_text_section
&& sect
== cold_text_section
));
1321 in_text_section_p
= sect
== text_section
;
1323 if (dwarf2out_do_cfi_asm ())
1324 dwarf2out_do_cfi_startproc (true);
1326 var_location_switch_text_section ();
1328 if (cold_text_section
!= NULL
)
1329 set_cur_line_info_table (sect
);
1332 /* And now, the subset of the debugging information support code necessary
1333 for emitting location expressions. */
1335 /* Describe an entry into the .debug_addr section. */
1339 ate_kind_rtx_dtprel
,
1343 struct GTY((for_user
)) addr_table_entry
{
1345 unsigned int refcount
;
1347 union addr_table_entry_struct_union
1349 rtx
GTY ((tag ("0"))) rtl
;
1350 char * GTY ((tag ("1"))) label
;
1352 GTY ((desc ("%1.kind"))) addr
;
1355 typedef unsigned int var_loc_view
;
1357 /* Location lists are ranges + location descriptions for that range,
1358 so you can track variables that are in different places over
1359 their entire life. */
1360 typedef struct GTY(()) dw_loc_list_struct
{
1361 dw_loc_list_ref dw_loc_next
;
1362 const char *begin
; /* Label and addr_entry for start of range */
1363 addr_table_entry
*begin_entry
;
1364 const char *end
; /* Label for end of range */
1365 addr_table_entry
*end_entry
;
1366 char *ll_symbol
; /* Label for beginning of location list.
1367 Only on head of list. */
1368 char *vl_symbol
; /* Label for beginning of view list. Ditto. */
1369 const char *section
; /* Section this loclist is relative to */
1370 dw_loc_descr_ref expr
;
1371 var_loc_view vbegin
, vend
;
1373 /* True if all addresses in this and subsequent lists are known to be
1376 /* True if this list has been replaced by dw_loc_next. */
1378 /* True if it has been emitted into .debug_loc* / .debug_loclists*
1380 unsigned char emitted
: 1;
1381 /* True if hash field is index rather than hash value. */
1382 unsigned char num_assigned
: 1;
1383 /* True if .debug_loclists.dwo offset has been emitted for it already. */
1384 unsigned char offset_emitted
: 1;
1385 /* True if note_variable_value_in_expr has been called on it. */
1386 unsigned char noted_variable_value
: 1;
1387 /* True if the range should be emitted even if begin and end
1392 static dw_loc_descr_ref
int_loc_descriptor (poly_int64
);
1393 static dw_loc_descr_ref
uint_loc_descriptor (unsigned HOST_WIDE_INT
);
1395 /* Convert a DWARF stack opcode into its string name. */
1398 dwarf_stack_op_name (unsigned int op
)
1400 const char *name
= get_DW_OP_name (op
);
1405 return "OP_<unknown>";
1408 /* Return TRUE iff we're to output location view lists as a separate
1409 attribute next to the location lists, as an extension compatible
1410 with DWARF 2 and above. */
1413 dwarf2out_locviews_in_attribute ()
1415 return debug_variable_location_views
== 1;
1418 /* Return TRUE iff we're to output location view lists as part of the
1419 location lists, as proposed for standardization after DWARF 5. */
1422 dwarf2out_locviews_in_loclist ()
1424 #ifndef DW_LLE_view_pair
1427 return debug_variable_location_views
== -1;
1431 /* Return a pointer to a newly allocated location description. Location
1432 descriptions are simple expression terms that can be strung
1433 together to form more complicated location (address) descriptions. */
1435 static inline dw_loc_descr_ref
1436 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1437 unsigned HOST_WIDE_INT oprnd2
)
1439 dw_loc_descr_ref descr
= ggc_cleared_alloc
<dw_loc_descr_node
> ();
1441 descr
->dw_loc_opc
= op
;
1442 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1443 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1444 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1445 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1446 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1447 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1452 /* Add a location description term to a location description expression. */
1455 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1457 dw_loc_descr_ref
*d
;
1459 /* Find the end of the chain. */
1460 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1466 /* Compare two location operands for exact equality. */
1469 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1471 if (a
->val_class
!= b
->val_class
)
1473 switch (a
->val_class
)
1475 case dw_val_class_none
:
1477 case dw_val_class_addr
:
1478 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1480 case dw_val_class_offset
:
1481 case dw_val_class_unsigned_const
:
1482 case dw_val_class_const
:
1483 case dw_val_class_unsigned_const_implicit
:
1484 case dw_val_class_const_implicit
:
1485 case dw_val_class_range_list
:
1486 /* These are all HOST_WIDE_INT, signed or unsigned. */
1487 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1489 case dw_val_class_loc
:
1490 return a
->v
.val_loc
== b
->v
.val_loc
;
1491 case dw_val_class_loc_list
:
1492 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1493 case dw_val_class_view_list
:
1494 return a
->v
.val_view_list
== b
->v
.val_view_list
;
1495 case dw_val_class_die_ref
:
1496 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1497 case dw_val_class_fde_ref
:
1498 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1499 case dw_val_class_symview
:
1500 return strcmp (a
->v
.val_symbolic_view
, b
->v
.val_symbolic_view
) == 0;
1501 case dw_val_class_lbl_id
:
1502 case dw_val_class_lineptr
:
1503 case dw_val_class_macptr
:
1504 case dw_val_class_loclistsptr
:
1505 case dw_val_class_high_pc
:
1506 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1507 case dw_val_class_str
:
1508 return a
->v
.val_str
== b
->v
.val_str
;
1509 case dw_val_class_flag
:
1510 return a
->v
.val_flag
== b
->v
.val_flag
;
1511 case dw_val_class_file
:
1512 case dw_val_class_file_implicit
:
1513 return a
->v
.val_file
== b
->v
.val_file
;
1514 case dw_val_class_decl_ref
:
1515 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1517 case dw_val_class_const_double
:
1518 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1519 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1521 case dw_val_class_wide_int
:
1522 return *a
->v
.val_wide
== *b
->v
.val_wide
;
1524 case dw_val_class_vec
:
1526 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1527 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1529 return (a_len
== b_len
1530 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1533 case dw_val_class_data8
:
1534 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1536 case dw_val_class_vms_delta
:
1537 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1538 && !strcmp (a
->v
.val_vms_delta
.lbl2
, b
->v
.val_vms_delta
.lbl2
));
1540 case dw_val_class_discr_value
:
1541 return (a
->v
.val_discr_value
.pos
== b
->v
.val_discr_value
.pos
1542 && a
->v
.val_discr_value
.v
.uval
== b
->v
.val_discr_value
.v
.uval
);
1543 case dw_val_class_discr_list
:
1544 /* It makes no sense comparing two discriminant value lists. */
1550 /* Compare two location atoms for exact equality. */
1553 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1555 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1558 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1559 address size, but since we always allocate cleared storage it
1560 should be zero for other types of locations. */
1561 if (a
->dtprel
!= b
->dtprel
)
1564 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1565 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1568 /* Compare two complete location expressions for exact equality. */
1571 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1577 if (a
== NULL
|| b
== NULL
)
1579 if (!loc_descr_equal_p_1 (a
, b
))
1588 /* Add a constant POLY_OFFSET to a location expression. */
1591 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, poly_int64 poly_offset
)
1593 dw_loc_descr_ref loc
;
1596 gcc_assert (*list_head
!= NULL
);
1598 if (known_eq (poly_offset
, 0))
1601 /* Find the end of the chain. */
1602 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1605 HOST_WIDE_INT offset
;
1606 if (!poly_offset
.is_constant (&offset
))
1608 loc
->dw_loc_next
= int_loc_descriptor (poly_offset
);
1609 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_plus
, 0, 0));
1614 if (loc
->dw_loc_opc
== DW_OP_fbreg
1615 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1616 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1617 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1618 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1620 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1621 offset. Don't optimize if an signed integer overflow would happen. */
1623 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1624 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1627 else if (offset
> 0)
1628 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1633 = uint_loc_descriptor (-(unsigned HOST_WIDE_INT
) offset
);
1634 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1638 /* Return a pointer to a newly allocated location description for
1641 static inline dw_loc_descr_ref
1642 new_reg_loc_descr (unsigned int reg
, poly_int64 offset
)
1644 HOST_WIDE_INT const_offset
;
1645 if (offset
.is_constant (&const_offset
))
1648 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1651 return new_loc_descr (DW_OP_bregx
, reg
, const_offset
);
1655 dw_loc_descr_ref ret
= new_reg_loc_descr (reg
, 0);
1656 loc_descr_plus_const (&ret
, offset
);
1661 /* Add a constant OFFSET to a location list. */
1664 loc_list_plus_const (dw_loc_list_ref list_head
, poly_int64 offset
)
1667 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1668 loc_descr_plus_const (&d
->expr
, offset
);
1671 #define DWARF_REF_SIZE \
1672 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : dwarf_offset_size)
1674 /* The number of bits that can be encoded by largest DW_FORM_dataN.
1675 In DWARF4 and earlier it is DW_FORM_data8 with 64 bits, in DWARF5
1676 DW_FORM_data16 with 128 bits. */
1677 #define DWARF_LARGEST_DATA_FORM_BITS \
1678 (dwarf_version >= 5 ? 128 : 64)
1680 /* Utility inline function for construction of ops that were GNU extension
1682 static inline enum dwarf_location_atom
1683 dwarf_OP (enum dwarf_location_atom op
)
1687 case DW_OP_implicit_pointer
:
1688 if (dwarf_version
< 5)
1689 return DW_OP_GNU_implicit_pointer
;
1692 case DW_OP_entry_value
:
1693 if (dwarf_version
< 5)
1694 return DW_OP_GNU_entry_value
;
1697 case DW_OP_const_type
:
1698 if (dwarf_version
< 5)
1699 return DW_OP_GNU_const_type
;
1702 case DW_OP_regval_type
:
1703 if (dwarf_version
< 5)
1704 return DW_OP_GNU_regval_type
;
1707 case DW_OP_deref_type
:
1708 if (dwarf_version
< 5)
1709 return DW_OP_GNU_deref_type
;
1713 if (dwarf_version
< 5)
1714 return DW_OP_GNU_convert
;
1717 case DW_OP_reinterpret
:
1718 if (dwarf_version
< 5)
1719 return DW_OP_GNU_reinterpret
;
1723 if (dwarf_version
< 5)
1724 return DW_OP_GNU_addr_index
;
1728 if (dwarf_version
< 5)
1729 return DW_OP_GNU_const_index
;
1738 /* Similarly for attributes. */
1739 static inline enum dwarf_attribute
1740 dwarf_AT (enum dwarf_attribute at
)
1744 case DW_AT_call_return_pc
:
1745 if (dwarf_version
< 5)
1746 return DW_AT_low_pc
;
1749 case DW_AT_call_tail_call
:
1750 if (dwarf_version
< 5)
1751 return DW_AT_GNU_tail_call
;
1754 case DW_AT_call_origin
:
1755 if (dwarf_version
< 5)
1756 return DW_AT_abstract_origin
;
1759 case DW_AT_call_target
:
1760 if (dwarf_version
< 5)
1761 return DW_AT_GNU_call_site_target
;
1764 case DW_AT_call_target_clobbered
:
1765 if (dwarf_version
< 5)
1766 return DW_AT_GNU_call_site_target_clobbered
;
1769 case DW_AT_call_parameter
:
1770 if (dwarf_version
< 5)
1771 return DW_AT_abstract_origin
;
1774 case DW_AT_call_value
:
1775 if (dwarf_version
< 5)
1776 return DW_AT_GNU_call_site_value
;
1779 case DW_AT_call_data_value
:
1780 if (dwarf_version
< 5)
1781 return DW_AT_GNU_call_site_data_value
;
1784 case DW_AT_call_all_calls
:
1785 if (dwarf_version
< 5)
1786 return DW_AT_GNU_all_call_sites
;
1789 case DW_AT_call_all_tail_calls
:
1790 if (dwarf_version
< 5)
1791 return DW_AT_GNU_all_tail_call_sites
;
1794 case DW_AT_dwo_name
:
1795 if (dwarf_version
< 5)
1796 return DW_AT_GNU_dwo_name
;
1799 case DW_AT_addr_base
:
1800 if (dwarf_version
< 5)
1801 return DW_AT_GNU_addr_base
;
1810 /* And similarly for tags. */
1811 static inline enum dwarf_tag
1812 dwarf_TAG (enum dwarf_tag tag
)
1816 case DW_TAG_call_site
:
1817 if (dwarf_version
< 5)
1818 return DW_TAG_GNU_call_site
;
1821 case DW_TAG_call_site_parameter
:
1822 if (dwarf_version
< 5)
1823 return DW_TAG_GNU_call_site_parameter
;
1832 /* And similarly for forms. */
1833 static inline enum dwarf_form
1834 dwarf_FORM (enum dwarf_form form
)
1839 if (dwarf_version
< 5)
1840 return DW_FORM_GNU_addr_index
;
1844 if (dwarf_version
< 5)
1845 return DW_FORM_GNU_str_index
;
1854 static unsigned long int get_base_type_offset (dw_die_ref
);
1856 /* Return the size of a location descriptor. */
1858 static unsigned long
1859 size_of_loc_descr (dw_loc_descr_ref loc
)
1861 unsigned long size
= 1;
1863 switch (loc
->dw_loc_opc
)
1866 size
+= DWARF2_ADDR_SIZE
;
1868 case DW_OP_GNU_addr_index
:
1870 case DW_OP_GNU_const_index
:
1872 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1873 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1892 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1895 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1900 case DW_OP_plus_uconst
:
1901 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1939 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1942 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1945 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1948 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1949 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1952 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1954 case DW_OP_bit_piece
:
1955 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1956 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1958 case DW_OP_deref_size
:
1959 case DW_OP_xderef_size
:
1968 case DW_OP_call_ref
:
1969 case DW_OP_GNU_variable_value
:
1970 size
+= DWARF_REF_SIZE
;
1972 case DW_OP_implicit_value
:
1973 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1974 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1976 case DW_OP_implicit_pointer
:
1977 case DW_OP_GNU_implicit_pointer
:
1978 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1980 case DW_OP_entry_value
:
1981 case DW_OP_GNU_entry_value
:
1983 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1984 size
+= size_of_uleb128 (op_size
) + op_size
;
1987 case DW_OP_const_type
:
1988 case DW_OP_GNU_const_type
:
1991 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1992 size
+= size_of_uleb128 (o
) + 1;
1993 switch (loc
->dw_loc_oprnd2
.val_class
)
1995 case dw_val_class_vec
:
1996 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1997 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1999 case dw_val_class_const
:
2000 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
2002 case dw_val_class_const_double
:
2003 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
2005 case dw_val_class_wide_int
:
2006 size
+= (get_full_len (*loc
->dw_loc_oprnd2
.v
.val_wide
)
2007 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
2014 case DW_OP_regval_type
:
2015 case DW_OP_GNU_regval_type
:
2018 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
2019 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
2020 + size_of_uleb128 (o
);
2023 case DW_OP_deref_type
:
2024 case DW_OP_GNU_deref_type
:
2027 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
2028 size
+= 1 + size_of_uleb128 (o
);
2032 case DW_OP_reinterpret
:
2033 case DW_OP_GNU_convert
:
2034 case DW_OP_GNU_reinterpret
:
2035 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2036 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2040 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
2041 size
+= size_of_uleb128 (o
);
2044 case DW_OP_GNU_parameter_ref
:
2054 /* Return the size of a series of location descriptors. */
2057 size_of_locs (dw_loc_descr_ref loc
)
2062 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
2063 field, to avoid writing to a PCH file. */
2064 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
2066 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
2068 size
+= size_of_loc_descr (l
);
2073 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
2075 l
->dw_loc_addr
= size
;
2076 size
+= size_of_loc_descr (l
);
2082 /* Return the size of the value in a DW_AT_discr_value attribute. */
2085 size_of_discr_value (dw_discr_value
*discr_value
)
2087 if (discr_value
->pos
)
2088 return size_of_uleb128 (discr_value
->v
.uval
);
2090 return size_of_sleb128 (discr_value
->v
.sval
);
2093 /* Return the size of the value in a DW_AT_discr_list attribute. */
2096 size_of_discr_list (dw_discr_list_ref discr_list
)
2100 for (dw_discr_list_ref list
= discr_list
;
2102 list
= list
->dw_discr_next
)
2104 /* One byte for the discriminant value descriptor, and then one or two
2105 LEB128 numbers, depending on whether it's a single case label or a
2108 size
+= size_of_discr_value (&list
->dw_discr_lower_bound
);
2109 if (list
->dw_discr_range
!= 0)
2110 size
+= size_of_discr_value (&list
->dw_discr_upper_bound
);
2115 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
2116 static void get_ref_die_offset_label (char *, dw_die_ref
);
2117 static unsigned long int get_ref_die_offset (dw_die_ref
);
2119 /* Output location description stack opcode's operands (if any).
2120 The for_eh_or_skip parameter controls whether register numbers are
2121 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2122 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2123 info). This should be suppressed for the cases that have not been converted
2124 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2127 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2129 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2130 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2132 switch (loc
->dw_loc_opc
)
2134 #ifdef DWARF2_DEBUGGING_INFO
2137 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
2142 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
2143 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
2145 fputc ('\n', asm_out_file
);
2150 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
2155 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
2156 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
2158 fputc ('\n', asm_out_file
);
2163 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2164 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
2171 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2172 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2174 dw2_asm_output_data (2, offset
, NULL
);
2177 case DW_OP_implicit_value
:
2178 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2179 switch (val2
->val_class
)
2181 case dw_val_class_const
:
2182 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
2184 case dw_val_class_vec
:
2186 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2187 unsigned int len
= val2
->v
.val_vec
.length
;
2191 if (elt_size
> sizeof (HOST_WIDE_INT
))
2196 for (i
= 0, p
= (unsigned char *) val2
->v
.val_vec
.array
;
2199 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2200 "fp or vector constant word %u", i
);
2203 case dw_val_class_const_double
:
2205 unsigned HOST_WIDE_INT first
, second
;
2207 if (WORDS_BIG_ENDIAN
)
2209 first
= val2
->v
.val_double
.high
;
2210 second
= val2
->v
.val_double
.low
;
2214 first
= val2
->v
.val_double
.low
;
2215 second
= val2
->v
.val_double
.high
;
2217 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2219 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2223 case dw_val_class_wide_int
:
2226 int len
= get_full_len (*val2
->v
.val_wide
);
2227 if (WORDS_BIG_ENDIAN
)
2228 for (i
= len
- 1; i
>= 0; --i
)
2229 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2230 val2
->v
.val_wide
->elt (i
), NULL
);
2232 for (i
= 0; i
< len
; ++i
)
2233 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2234 val2
->v
.val_wide
->elt (i
), NULL
);
2237 case dw_val_class_addr
:
2238 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
2239 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
2254 case DW_OP_implicit_value
:
2255 /* We currently don't make any attempt to make sure these are
2256 aligned properly like we do for the main unwind info, so
2257 don't support emitting things larger than a byte if we're
2258 only doing unwinding. */
2263 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2266 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2269 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2272 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2274 case DW_OP_plus_uconst
:
2275 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2309 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2313 unsigned r
= val1
->v
.val_unsigned
;
2314 if (for_eh_or_skip
>= 0)
2315 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2316 gcc_assert (size_of_uleb128 (r
)
2317 == size_of_uleb128 (val1
->v
.val_unsigned
));
2318 dw2_asm_output_data_uleb128 (r
, NULL
);
2322 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2326 unsigned r
= val1
->v
.val_unsigned
;
2327 if (for_eh_or_skip
>= 0)
2328 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2329 gcc_assert (size_of_uleb128 (r
)
2330 == size_of_uleb128 (val1
->v
.val_unsigned
));
2331 dw2_asm_output_data_uleb128 (r
, NULL
);
2332 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2336 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2338 case DW_OP_bit_piece
:
2339 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2340 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
2342 case DW_OP_deref_size
:
2343 case DW_OP_xderef_size
:
2344 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2350 if (targetm
.asm_out
.output_dwarf_dtprel
)
2352 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
2355 fputc ('\n', asm_out_file
);
2362 #ifdef DWARF2_DEBUGGING_INFO
2363 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2370 case DW_OP_GNU_addr_index
:
2372 case DW_OP_GNU_const_index
:
2374 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
2375 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
2376 "(index into .debug_addr)");
2382 unsigned long die_offset
2383 = get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2384 /* Make sure the offset has been computed and that we can encode it as
2386 gcc_assert (die_offset
> 0
2387 && die_offset
<= (loc
->dw_loc_opc
== DW_OP_call2
2390 dw2_asm_output_data ((loc
->dw_loc_opc
== DW_OP_call2
) ? 2 : 4,
2395 case DW_OP_call_ref
:
2396 case DW_OP_GNU_variable_value
:
2398 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2399 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2400 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2401 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2402 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2406 case DW_OP_implicit_pointer
:
2407 case DW_OP_GNU_implicit_pointer
:
2409 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2410 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2411 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2412 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2413 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2414 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2418 case DW_OP_entry_value
:
2419 case DW_OP_GNU_entry_value
:
2420 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
2421 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
2424 case DW_OP_const_type
:
2425 case DW_OP_GNU_const_type
:
2427 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
2429 dw2_asm_output_data_uleb128 (o
, NULL
);
2430 switch (val2
->val_class
)
2432 case dw_val_class_const
:
2433 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2434 dw2_asm_output_data (1, l
, NULL
);
2435 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
2437 case dw_val_class_vec
:
2439 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2440 unsigned int len
= val2
->v
.val_vec
.length
;
2445 dw2_asm_output_data (1, l
, NULL
);
2446 if (elt_size
> sizeof (HOST_WIDE_INT
))
2451 for (i
= 0, p
= (unsigned char *) val2
->v
.val_vec
.array
;
2454 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2455 "fp or vector constant word %u", i
);
2458 case dw_val_class_const_double
:
2460 unsigned HOST_WIDE_INT first
, second
;
2461 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2463 dw2_asm_output_data (1, 2 * l
, NULL
);
2464 if (WORDS_BIG_ENDIAN
)
2466 first
= val2
->v
.val_double
.high
;
2467 second
= val2
->v
.val_double
.low
;
2471 first
= val2
->v
.val_double
.low
;
2472 second
= val2
->v
.val_double
.high
;
2474 dw2_asm_output_data (l
, first
, NULL
);
2475 dw2_asm_output_data (l
, second
, NULL
);
2478 case dw_val_class_wide_int
:
2481 int len
= get_full_len (*val2
->v
.val_wide
);
2482 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2484 dw2_asm_output_data (1, len
* l
, NULL
);
2485 if (WORDS_BIG_ENDIAN
)
2486 for (i
= len
- 1; i
>= 0; --i
)
2487 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2489 for (i
= 0; i
< len
; ++i
)
2490 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2498 case DW_OP_regval_type
:
2499 case DW_OP_GNU_regval_type
:
2501 unsigned r
= val1
->v
.val_unsigned
;
2502 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2504 if (for_eh_or_skip
>= 0)
2506 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2507 gcc_assert (size_of_uleb128 (r
)
2508 == size_of_uleb128 (val1
->v
.val_unsigned
));
2510 dw2_asm_output_data_uleb128 (r
, NULL
);
2511 dw2_asm_output_data_uleb128 (o
, NULL
);
2514 case DW_OP_deref_type
:
2515 case DW_OP_GNU_deref_type
:
2517 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2519 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2520 dw2_asm_output_data_uleb128 (o
, NULL
);
2524 case DW_OP_reinterpret
:
2525 case DW_OP_GNU_convert
:
2526 case DW_OP_GNU_reinterpret
:
2527 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2528 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2531 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2533 dw2_asm_output_data_uleb128 (o
, NULL
);
2537 case DW_OP_GNU_parameter_ref
:
2540 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2541 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2542 dw2_asm_output_data (4, o
, NULL
);
2547 /* Other codes have no operands. */
2552 /* Output a sequence of location operations.
2553 The for_eh_or_skip parameter controls whether register numbers are
2554 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2555 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2556 info). This should be suppressed for the cases that have not been converted
2557 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2560 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2562 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2564 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2565 /* Output the opcode. */
2566 if (for_eh_or_skip
>= 0
2567 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2569 unsigned r
= (opc
- DW_OP_breg0
);
2570 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2571 gcc_assert (r
<= 31);
2572 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2574 else if (for_eh_or_skip
>= 0
2575 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2577 unsigned r
= (opc
- DW_OP_reg0
);
2578 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2579 gcc_assert (r
<= 31);
2580 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2583 dw2_asm_output_data (1, opc
,
2584 "%s", dwarf_stack_op_name (opc
));
2586 /* Output the operand(s) (if any). */
2587 output_loc_operands (loc
, for_eh_or_skip
);
2591 /* Output location description stack opcode's operands (if any).
2592 The output is single bytes on a line, suitable for .cfi_escape. */
2595 output_loc_operands_raw (dw_loc_descr_ref loc
)
2597 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2598 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2600 switch (loc
->dw_loc_opc
)
2603 case DW_OP_GNU_addr_index
:
2605 case DW_OP_GNU_const_index
:
2607 case DW_OP_implicit_value
:
2608 /* We cannot output addresses in .cfi_escape, only bytes. */
2614 case DW_OP_deref_size
:
2615 case DW_OP_xderef_size
:
2616 fputc (',', asm_out_file
);
2617 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2622 fputc (',', asm_out_file
);
2623 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2628 fputc (',', asm_out_file
);
2629 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2634 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2635 fputc (',', asm_out_file
);
2636 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2644 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2645 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2647 fputc (',', asm_out_file
);
2648 dw2_asm_output_data_raw (2, offset
);
2654 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2655 gcc_assert (size_of_uleb128 (r
)
2656 == size_of_uleb128 (val1
->v
.val_unsigned
));
2657 fputc (',', asm_out_file
);
2658 dw2_asm_output_data_uleb128_raw (r
);
2663 case DW_OP_plus_uconst
:
2665 fputc (',', asm_out_file
);
2666 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2669 case DW_OP_bit_piece
:
2670 fputc (',', asm_out_file
);
2671 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2672 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2709 fputc (',', asm_out_file
);
2710 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2715 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2716 gcc_assert (size_of_uleb128 (r
)
2717 == size_of_uleb128 (val1
->v
.val_unsigned
));
2718 fputc (',', asm_out_file
);
2719 dw2_asm_output_data_uleb128_raw (r
);
2720 fputc (',', asm_out_file
);
2721 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2725 case DW_OP_implicit_pointer
:
2726 case DW_OP_entry_value
:
2727 case DW_OP_const_type
:
2728 case DW_OP_regval_type
:
2729 case DW_OP_deref_type
:
2731 case DW_OP_reinterpret
:
2732 case DW_OP_GNU_implicit_pointer
:
2733 case DW_OP_GNU_entry_value
:
2734 case DW_OP_GNU_const_type
:
2735 case DW_OP_GNU_regval_type
:
2736 case DW_OP_GNU_deref_type
:
2737 case DW_OP_GNU_convert
:
2738 case DW_OP_GNU_reinterpret
:
2739 case DW_OP_GNU_parameter_ref
:
2744 /* Other codes have no operands. */
2750 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2754 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2755 /* Output the opcode. */
2756 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2758 unsigned r
= (opc
- DW_OP_breg0
);
2759 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2760 gcc_assert (r
<= 31);
2761 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2763 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2765 unsigned r
= (opc
- DW_OP_reg0
);
2766 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2767 gcc_assert (r
<= 31);
2768 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2770 /* Output the opcode. */
2771 fprintf (asm_out_file
, "%#x", opc
);
2772 output_loc_operands_raw (loc
);
2774 if (!loc
->dw_loc_next
)
2776 loc
= loc
->dw_loc_next
;
2778 fputc (',', asm_out_file
);
2783 build_breg_loc (struct dw_loc_descr_node
**head
, unsigned int regno
)
2786 add_loc_descr (head
, new_loc_descr ((enum dwarf_location_atom
)
2787 (DW_OP_breg0
+ regno
), 0, 0));
2789 add_loc_descr (head
, new_loc_descr (DW_OP_bregx
, regno
, 0));
2792 /* Build a dwarf location for a cfa_reg spanning multiple
2793 consecutive registers. */
2795 struct dw_loc_descr_node
*
2796 build_span_loc (struct cfa_reg reg
)
2798 struct dw_loc_descr_node
*head
= NULL
;
2800 gcc_assert (reg
.span_width
> 0);
2801 gcc_assert (reg
.span
> 1);
2803 /* Start from the highest number register as it goes in the upper bits. */
2804 unsigned int regno
= reg
.reg
+ reg
.span
- 1;
2805 build_breg_loc (&head
, regno
);
2807 /* Deal with the remaining registers in the span. */
2808 for (int i
= reg
.span
- 2; i
>= 0; i
--)
2810 add_loc_descr (&head
, int_loc_descriptor (reg
.span_width
* 8));
2811 add_loc_descr (&head
, new_loc_descr (DW_OP_shl
, 0, 0));
2813 build_breg_loc (&head
, regno
);
2814 add_loc_descr (&head
, new_loc_descr (DW_OP_plus
, 0, 0));
2819 /* This function builds a dwarf location descriptor sequence from a
2820 dw_cfa_location, adding the given OFFSET to the result of the
2823 struct dw_loc_descr_node
*
2824 build_cfa_loc (dw_cfa_location
*cfa
, poly_int64 offset
)
2826 struct dw_loc_descr_node
*head
, *tmp
;
2828 offset
+= cfa
->offset
;
2830 if (cfa
->reg
.span
> 1)
2832 head
= build_span_loc (cfa
->reg
);
2834 if (maybe_ne (offset
, 0))
2835 loc_descr_plus_const (&head
, offset
);
2837 else if (cfa
->indirect
)
2839 head
= new_reg_loc_descr (cfa
->reg
.reg
, cfa
->base_offset
);
2840 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2841 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2842 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2843 add_loc_descr (&head
, tmp
);
2844 loc_descr_plus_const (&head
, offset
);
2847 head
= new_reg_loc_descr (cfa
->reg
.reg
, offset
);
2852 /* This function builds a dwarf location descriptor sequence for
2853 the address at OFFSET from the CFA when stack is aligned to
2856 struct dw_loc_descr_node
*
2857 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2858 poly_int64 offset
, HOST_WIDE_INT alignment
)
2860 struct dw_loc_descr_node
*head
;
2861 unsigned int dwarf_fp
2862 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2864 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2865 if (cfa
->reg
.reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2867 head
= new_reg_loc_descr (dwarf_fp
, 0);
2868 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2869 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2870 loc_descr_plus_const (&head
, offset
);
2873 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2877 /* And now, the support for symbolic debugging information. */
2879 /* .debug_str support. */
2881 static void dwarf2out_init (const char *);
2882 static void dwarf2out_finish (const char *);
2883 static void dwarf2out_early_finish (const char *);
2884 static void dwarf2out_assembly_start (void);
2885 static void dwarf2out_define (unsigned int, const char *);
2886 static void dwarf2out_undef (unsigned int, const char *);
2887 static void dwarf2out_start_source_file (unsigned, const char *);
2888 static void dwarf2out_end_source_file (unsigned);
2889 static void dwarf2out_function_decl (tree
);
2890 static void dwarf2out_begin_block (unsigned, unsigned);
2891 static void dwarf2out_end_block (unsigned, unsigned);
2892 static bool dwarf2out_ignore_block (const_tree
);
2893 static void dwarf2out_set_ignored_loc (unsigned, unsigned, const char *);
2894 static void dwarf2out_early_global_decl (tree
);
2895 static void dwarf2out_late_global_decl (tree
);
2896 static void dwarf2out_type_decl (tree
, int);
2897 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool, bool);
2898 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2900 static void dwarf2out_abstract_function (tree
);
2901 static void dwarf2out_var_location (rtx_insn
*);
2902 static void dwarf2out_inline_entry (tree
);
2903 static void dwarf2out_size_function (tree
);
2904 static void dwarf2out_begin_function (tree
);
2905 static void dwarf2out_end_function (unsigned int);
2906 static void dwarf2out_register_main_translation_unit (tree unit
);
2907 static void dwarf2out_set_name (tree
, tree
);
2908 static void dwarf2out_register_external_die (tree decl
, const char *sym
,
2909 unsigned HOST_WIDE_INT off
);
2910 static bool dwarf2out_die_ref_for_decl (tree decl
, const char **sym
,
2911 unsigned HOST_WIDE_INT
*off
);
2913 /* The debug hooks structure. */
2915 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2919 dwarf2out_early_finish
,
2920 dwarf2out_assembly_start
,
2923 dwarf2out_start_source_file
,
2924 dwarf2out_end_source_file
,
2925 dwarf2out_begin_block
,
2926 dwarf2out_end_block
,
2927 dwarf2out_ignore_block
,
2928 dwarf2out_source_line
,
2929 dwarf2out_set_ignored_loc
,
2930 dwarf2out_begin_prologue
,
2931 #if VMS_DEBUGGING_INFO
2932 dwarf2out_vms_end_prologue
,
2933 dwarf2out_vms_begin_epilogue
,
2935 debug_nothing_int_charstar
,
2936 debug_nothing_int_charstar
,
2938 dwarf2out_end_epilogue
,
2939 dwarf2out_begin_function
,
2940 dwarf2out_end_function
, /* end_function */
2941 dwarf2out_register_main_translation_unit
,
2942 dwarf2out_function_decl
, /* function_decl */
2943 dwarf2out_early_global_decl
,
2944 dwarf2out_late_global_decl
,
2945 dwarf2out_type_decl
, /* type_decl */
2946 dwarf2out_imported_module_or_decl
,
2947 dwarf2out_die_ref_for_decl
,
2948 dwarf2out_register_external_die
,
2949 debug_nothing_tree
, /* deferred_inline_function */
2950 /* The DWARF 2 backend tries to reduce debugging bloat by not
2951 emitting the abstract description of inline functions until
2952 something tries to reference them. */
2953 dwarf2out_abstract_function
, /* outlining_inline_function */
2954 debug_nothing_rtx_code_label
, /* label */
2955 debug_nothing_int
, /* handle_pch */
2956 dwarf2out_var_location
,
2957 dwarf2out_inline_entry
, /* inline_entry */
2958 dwarf2out_size_function
, /* size_function */
2959 dwarf2out_switch_text_section
,
2961 1, /* start_end_main_source_file */
2962 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2965 const struct gcc_debug_hooks dwarf2_lineno_debug_hooks
=
2968 debug_nothing_charstar
,
2969 debug_nothing_charstar
,
2970 dwarf2out_assembly_start
,
2971 debug_nothing_int_charstar
,
2972 debug_nothing_int_charstar
,
2973 debug_nothing_int_charstar
,
2975 debug_nothing_int_int
, /* begin_block */
2976 debug_nothing_int_int
, /* end_block */
2977 debug_true_const_tree
, /* ignore_block */
2978 dwarf2out_source_line
, /* source_line */
2979 debug_nothing_int_int_charstar
, /* set_ignored_loc */
2980 debug_nothing_int_int_charstar
, /* begin_prologue */
2981 debug_nothing_int_charstar
, /* end_prologue */
2982 debug_nothing_int_charstar
, /* begin_epilogue */
2983 debug_nothing_int_charstar
, /* end_epilogue */
2984 debug_nothing_tree
, /* begin_function */
2985 debug_nothing_int
, /* end_function */
2986 debug_nothing_tree
, /* register_main_translation_unit */
2987 debug_nothing_tree
, /* function_decl */
2988 debug_nothing_tree
, /* early_global_decl */
2989 debug_nothing_tree
, /* late_global_decl */
2990 debug_nothing_tree_int
, /* type_decl */
2991 debug_nothing_tree_tree_tree_bool_bool
,/* imported_module_or_decl */
2992 debug_false_tree_charstarstar_uhwistar
,/* die_ref_for_decl */
2993 debug_nothing_tree_charstar_uhwi
, /* register_external_die */
2994 debug_nothing_tree
, /* deferred_inline_function */
2995 debug_nothing_tree
, /* outlining_inline_function */
2996 debug_nothing_rtx_code_label
, /* label */
2997 debug_nothing_int
, /* handle_pch */
2998 debug_nothing_rtx_insn
, /* var_location */
2999 debug_nothing_tree
, /* inline_entry */
3000 debug_nothing_tree
, /* size_function */
3001 debug_nothing_void
, /* switch_text_section */
3002 debug_nothing_tree_tree
, /* set_name */
3003 0, /* start_end_main_source_file */
3004 TYPE_SYMTAB_IS_ADDRESS
/* tree_type_symtab_field */
3007 /* NOTE: In the comments in this file, many references are made to
3008 "Debugging Information Entries". This term is abbreviated as `DIE'
3009 throughout the remainder of this file. */
3011 /* An internal representation of the DWARF output is built, and then
3012 walked to generate the DWARF debugging info. The walk of the internal
3013 representation is done after the entire program has been compiled.
3014 The types below are used to describe the internal representation. */
3016 /* Whether to put type DIEs into their own section .debug_types instead
3017 of making them part of the .debug_info section. Only supported for
3018 Dwarf V4 or higher and the user didn't disable them through
3019 -fno-debug-types-section. It is more efficient to put them in a
3020 separate comdat sections since the linker will then be able to
3021 remove duplicates. But not all tools support .debug_types sections
3022 yet. For Dwarf V5 or higher .debug_types doesn't exist any more,
3023 it is DW_UT_type unit type in .debug_info section. For late LTO
3024 debug there should be almost no types emitted so avoid enabling
3025 -fdebug-types-section there. */
3027 #define use_debug_types (dwarf_version >= 4 \
3028 && flag_debug_types_section \
3031 /* Various DIE's use offsets relative to the beginning of the
3032 .debug_info section to refer to each other. */
3034 typedef long int dw_offset
;
3036 struct comdat_type_node
;
3038 /* The entries in the line_info table more-or-less mirror the opcodes
3039 that are used in the real dwarf line table. Arrays of these entries
3040 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
3043 enum dw_line_info_opcode
{
3044 /* Emit DW_LNE_set_address; the operand is the label index. */
3047 /* Emit a row to the matrix with the given line. This may be done
3048 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
3052 /* Emit a DW_LNS_set_file. */
3055 /* Emit a DW_LNS_set_column. */
3058 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
3061 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
3062 LI_set_prologue_end
,
3063 LI_set_epilogue_begin
,
3065 /* Emit a DW_LNE_set_discriminator. */
3066 LI_set_discriminator
,
3068 /* Output a Fixed Advance PC; the target PC is the label index; the
3069 base PC is the previous LI_adv_address or LI_set_address entry.
3070 We only use this when emitting debug views without assembler
3071 support, at explicit user request. Ideally, we should only use
3072 it when the offset might be zero but we can't tell: it's the only
3073 way to maybe change the PC without resetting the view number. */
3077 typedef struct GTY(()) dw_line_info_struct
{
3078 enum dw_line_info_opcode opcode
;
3080 } dw_line_info_entry
;
3083 struct GTY(()) dw_line_info_table
{
3084 /* The label that marks the end of this section. */
3085 const char *end_label
;
3087 /* The values for the last row of the matrix, as collected in the table.
3088 These are used to minimize the changes to the next row. */
3089 unsigned int file_num
;
3090 unsigned int line_num
;
3091 unsigned int column_num
;
3096 /* This denotes the NEXT view number.
3098 If it is 0, it is known that the NEXT view will be the first view
3101 If it is -1, we're forcing the view number to be reset, e.g. at a
3104 The meaning of other nonzero values depends on whether we're
3105 computing views internally or leaving it for the assembler to do
3106 so. If we're emitting them internally, view denotes the view
3107 number since the last known advance of PC. If we're leaving it
3108 for the assembler, it denotes the LVU label number that we're
3109 going to ask the assembler to assign. */
3112 /* This counts the number of symbolic views emitted in this table
3113 since the latest view reset. Its max value, over all tables,
3114 sets symview_upper_bound. */
3115 var_loc_view symviews_since_reset
;
3117 #define FORCE_RESET_NEXT_VIEW(x) ((x) = (var_loc_view)-1)
3118 #define RESET_NEXT_VIEW(x) ((x) = (var_loc_view)0)
3119 #define FORCE_RESETTING_VIEW_P(x) ((x) == (var_loc_view)-1)
3120 #define RESETTING_VIEW_P(x) ((x) == (var_loc_view)0 || FORCE_RESETTING_VIEW_P (x))
3122 vec
<dw_line_info_entry
, va_gc
> *entries
;
3125 /* This is an upper bound for view numbers that the assembler may
3126 assign to symbolic views output in this translation. It is used to
3127 decide how big a field to use to represent view numbers in
3128 symview-classed attributes. */
3130 static var_loc_view symview_upper_bound
;
3132 /* If we're keep track of location views and their reset points, and
3133 INSN is a reset point (i.e., it necessarily advances the PC), mark
3134 the next view in TABLE as reset. */
3137 maybe_reset_location_view (rtx_insn
*insn
, dw_line_info_table
*table
)
3139 if (!debug_internal_reset_location_views
)
3142 /* Maybe turn (part of?) this test into a default target hook. */
3145 if (targetm
.reset_location_view
)
3146 reset
= targetm
.reset_location_view (insn
);
3150 else if (JUMP_TABLE_DATA_P (insn
))
3152 else if (GET_CODE (insn
) == USE
3153 || GET_CODE (insn
) == CLOBBER
3154 || GET_CODE (insn
) == ASM_INPUT
3155 || asm_noperands (insn
) >= 0)
3157 else if (get_attr_min_length (insn
) > 0)
3160 if (reset
> 0 && !RESETTING_VIEW_P (table
->view
))
3161 RESET_NEXT_VIEW (table
->view
);
3164 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
3165 The children of each node form a circular list linked by
3166 die_sib. die_child points to the node *before* the "first" child node. */
3168 typedef struct GTY((chain_circular ("%h.die_sib"), for_user
)) die_struct
{
3169 union die_symbol_or_type_node
3171 const char * GTY ((tag ("0"))) die_symbol
;
3172 comdat_type_node
*GTY ((tag ("1"))) die_type_node
;
3174 GTY ((desc ("%0.comdat_type_p"))) die_id
;
3175 vec
<dw_attr_node
, va_gc
> *die_attr
;
3176 dw_die_ref die_parent
;
3177 dw_die_ref die_child
;
3179 dw_die_ref die_definition
; /* ref from a specification to its definition */
3180 dw_offset die_offset
;
3181 unsigned long die_abbrev
;
3183 unsigned int decl_id
;
3184 enum dwarf_tag die_tag
;
3185 /* Die is used and must not be pruned as unused. */
3186 BOOL_BITFIELD die_perennial_p
: 1;
3187 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
3188 /* For an external ref to die_symbol if die_offset contains an extra
3189 offset to that symbol. */
3190 BOOL_BITFIELD with_offset
: 1;
3191 /* Whether this DIE was removed from the DIE tree, for example via
3192 prune_unused_types. We don't consider those present from the
3193 DIE lookup routines. */
3194 BOOL_BITFIELD removed
: 1;
3195 /* Lots of spare bits. */
3199 /* Set to TRUE while dwarf2out_early_global_decl is running. */
3200 static bool early_dwarf
;
3201 static bool early_dwarf_finished
;
3202 class set_early_dwarf
{
3205 set_early_dwarf () : saved(early_dwarf
)
3207 gcc_assert (! early_dwarf_finished
);
3210 ~set_early_dwarf () { early_dwarf
= saved
; }
3213 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
3214 #define FOR_EACH_CHILD(die, c, expr) do { \
3215 c = die->die_child; \
3219 } while (c != die->die_child); \
3222 /* The pubname structure */
3224 typedef struct GTY(()) pubname_struct
{
3231 struct GTY(()) dw_ranges
{
3233 /* If this is positive, it's a block number, otherwise it's a
3234 bitwise-negated index into dw_ranges_by_label. */
3236 /* If idx is equal to DW_RANGES_IDX_SKELETON, it should be emitted
3237 into .debug_rnglists section rather than .debug_rnglists.dwo
3238 for -gsplit-dwarf and DWARF >= 5. */
3239 #define DW_RANGES_IDX_SKELETON ((1U << 31) - 1)
3240 /* Index for the range list for DW_FORM_rnglistx. */
3241 unsigned int idx
: 31;
3242 /* True if this range might be possibly in a different section
3243 from previous entry. */
3244 unsigned int maybe_new_sec
: 1;
3245 addr_table_entry
*begin_entry
;
3246 addr_table_entry
*end_entry
;
3249 /* A structure to hold a macinfo entry. */
3251 typedef struct GTY(()) macinfo_struct
{
3253 unsigned HOST_WIDE_INT lineno
;
3259 struct GTY(()) dw_ranges_by_label
{
3264 /* The comdat type node structure. */
3265 struct GTY(()) comdat_type_node
3267 dw_die_ref root_die
;
3268 dw_die_ref type_die
;
3269 dw_die_ref skeleton_die
;
3270 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
3271 comdat_type_node
*next
;
3274 /* A list of DIEs for which we can't determine ancestry (parent_die
3275 field) just yet. Later in dwarf2out_finish we will fill in the
3277 typedef struct GTY(()) limbo_die_struct
{
3279 /* The tree for which this DIE was created. We use this to
3280 determine ancestry later. */
3282 struct limbo_die_struct
*next
;
3286 typedef struct skeleton_chain_struct
3290 struct skeleton_chain_struct
*parent
;
3292 skeleton_chain_node
;
3294 /* Define a macro which returns nonzero for a TYPE_DECL which was
3295 implicitly generated for a type.
3297 Note that, unlike the C front-end (which generates a NULL named
3298 TYPE_DECL node for each complete tagged type, each array type,
3299 and each function type node created) the C++ front-end generates
3300 a _named_ TYPE_DECL node for each tagged type node created.
3301 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3302 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
3303 front-end, but for each type, tagged or not. */
3305 #define TYPE_DECL_IS_STUB(decl) \
3306 (DECL_NAME (decl) == NULL_TREE \
3307 || (DECL_ARTIFICIAL (decl) \
3308 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3309 /* This is necessary for stub decls that \
3310 appear in nested inline functions. */ \
3311 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3312 && (decl_ultimate_origin (decl) \
3313 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3315 /* Information concerning the compilation unit's programming
3316 language, and compiler version. */
3318 /* Fixed size portion of the DWARF compilation unit header. */
3319 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3320 (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size \
3321 + (dwarf_version >= 5 ? 4 : 3))
3323 /* Fixed size portion of the DWARF comdat type unit header. */
3324 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
3325 (DWARF_COMPILE_UNIT_HEADER_SIZE \
3326 + DWARF_TYPE_SIGNATURE_SIZE + dwarf_offset_size)
3328 /* Fixed size portion of the DWARF skeleton compilation unit header. */
3329 #define DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE \
3330 (DWARF_COMPILE_UNIT_HEADER_SIZE + (dwarf_version >= 5 ? 8 : 0))
3332 /* Fixed size portion of public names info. */
3333 #define DWARF_PUBNAMES_HEADER_SIZE (2 * dwarf_offset_size + 2)
3335 /* Fixed size portion of the address range info. */
3336 #define DWARF_ARANGES_HEADER_SIZE \
3337 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size + 4, \
3338 DWARF2_ADDR_SIZE * 2) \
3339 - DWARF_INITIAL_LENGTH_SIZE)
3341 /* Size of padding portion in the address range info. It must be
3342 aligned to twice the pointer size. */
3343 #define DWARF_ARANGES_PAD_SIZE \
3344 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size + 4, \
3345 DWARF2_ADDR_SIZE * 2) \
3346 - (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size + 4))
3348 /* Use assembler line directives if available. */
3349 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3350 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3351 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3353 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3357 /* Use assembler views in line directives if available. */
3358 #ifndef DWARF2_ASM_VIEW_DEBUG_INFO
3359 #ifdef HAVE_AS_DWARF2_DEBUG_VIEW
3360 #define DWARF2_ASM_VIEW_DEBUG_INFO 1
3362 #define DWARF2_ASM_VIEW_DEBUG_INFO 0
3366 /* Return true if GCC configure detected assembler support for .loc. */
3369 dwarf2out_default_as_loc_support (void)
3371 return DWARF2_ASM_LINE_DEBUG_INFO
;
3372 #if (GCC_VERSION >= 3000)
3373 # undef DWARF2_ASM_LINE_DEBUG_INFO
3374 # pragma GCC poison DWARF2_ASM_LINE_DEBUG_INFO
3378 /* Return true if GCC configure detected assembler support for views
3379 in .loc directives. */
3382 dwarf2out_default_as_locview_support (void)
3384 return DWARF2_ASM_VIEW_DEBUG_INFO
;
3385 #if (GCC_VERSION >= 3000)
3386 # undef DWARF2_ASM_VIEW_DEBUG_INFO
3387 # pragma GCC poison DWARF2_ASM_VIEW_DEBUG_INFO
3391 /* A bit is set in ZERO_VIEW_P if we are using the assembler-supported
3392 view computation, and it refers to a view identifier for which we
3393 will not emit a label because it is known to map to a view number
3394 zero. We won't allocate the bitmap if we're not using assembler
3395 support for location views, but we have to make the variable
3396 visible for GGC and for code that will be optimized out for lack of
3397 support but that's still parsed and compiled. We could abstract it
3398 out with macros, but it's not worth it. */
3399 static GTY(()) bitmap zero_view_p
;
3401 /* Evaluate to TRUE iff N is known to identify the first location view
3402 at its PC. When not using assembler location view computation,
3403 that must be view number zero. Otherwise, ZERO_VIEW_P is allocated
3404 and views label numbers recorded in it are the ones known to be
3406 #define ZERO_VIEW_P(N) ((N) == (var_loc_view)0 \
3407 || (N) == (var_loc_view)-1 \
3409 && bitmap_bit_p (zero_view_p, (N))))
3411 /* Return true iff we're to emit .loc directives for the assembler to
3412 generate line number sections.
3414 When we're not emitting views, all we need from the assembler is
3415 support for .loc directives.
3417 If we are emitting views, we can only use the assembler's .loc
3418 support if it also supports views.
3420 When the compiler is emitting the line number programs and
3421 computing view numbers itself, it resets view numbers at known PC
3422 changes and counts from that, and then it emits view numbers as
3423 literal constants in locviewlists. There are cases in which the
3424 compiler is not sure about PC changes, e.g. when extra alignment is
3425 requested for a label. In these cases, the compiler may not reset
3426 the view counter, and the potential PC advance in the line number
3427 program will use an opcode that does not reset the view counter
3428 even if the PC actually changes, so that compiler and debug info
3429 consumer can keep view numbers in sync.
3431 When the compiler defers view computation to the assembler, it
3432 emits symbolic view numbers in locviewlists, with the exception of
3433 views known to be zero (forced resets, or reset after
3434 compiler-visible PC changes): instead of emitting symbols for
3435 these, we emit literal zero and assert the assembler agrees with
3436 the compiler's assessment. We could use symbolic views everywhere,
3437 instead of special-casing zero views, but then we'd be unable to
3438 optimize out locviewlists that contain only zeros. */
3441 output_asm_line_debug_info (void)
3443 return (dwarf2out_as_loc_support
3444 && (dwarf2out_as_locview_support
3445 || !debug_variable_location_views
));
3448 static bool asm_outputs_debug_line_str (void);
3450 /* Minimum line offset in a special line info. opcode.
3451 This value was chosen to give a reasonable range of values. */
3452 #define DWARF_LINE_BASE -10
3454 /* First special line opcode - leave room for the standard opcodes. */
3455 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
3457 /* Range of line offsets in a special line info. opcode. */
3458 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3460 /* Flag that indicates the initial value of the is_stmt_start flag.
3461 In the present implementation, we do not mark any lines as
3462 the beginning of a source statement, because that information
3463 is not made available by the GCC front-end. */
3464 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3466 /* Maximum number of operations per instruction bundle. */
3467 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
3468 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
3471 /* This location is used by calc_die_sizes() to keep track
3472 the offset of each DIE within the .debug_info section. */
3473 static unsigned long next_die_offset
;
3475 /* Record the root of the DIE's built for the current compilation unit. */
3476 static GTY(()) dw_die_ref single_comp_unit_die
;
3478 /* A list of type DIEs that have been separated into comdat sections. */
3479 static GTY(()) comdat_type_node
*comdat_type_list
;
3481 /* A list of CU DIEs that have been separated. */
3482 static GTY(()) limbo_die_node
*cu_die_list
;
3484 /* A list of DIEs with a NULL parent waiting to be relocated. */
3485 static GTY(()) limbo_die_node
*limbo_die_list
;
3487 /* A list of DIEs for which we may have to generate
3488 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
3489 static GTY(()) limbo_die_node
*deferred_asm_name
;
3491 struct dwarf_file_hasher
: ggc_ptr_hash
<dwarf_file_data
>
3493 typedef const char *compare_type
;
3495 static hashval_t
hash (dwarf_file_data
*);
3496 static bool equal (dwarf_file_data
*, const char *);
3499 /* Filenames referenced by this compilation unit. */
3500 static GTY(()) hash_table
<dwarf_file_hasher
> *file_table
;
3502 struct decl_die_hasher
: ggc_ptr_hash
<die_node
>
3504 typedef tree compare_type
;
3506 static hashval_t
hash (die_node
*);
3507 static bool equal (die_node
*, tree
);
3509 /* A hash table of references to DIE's that describe declarations.
3510 The key is a DECL_UID() which is a unique number identifying each decl. */
3511 static GTY (()) hash_table
<decl_die_hasher
> *decl_die_table
;
3513 struct GTY ((for_user
)) variable_value_struct
{
3514 unsigned int decl_id
;
3515 vec
<dw_die_ref
, va_gc
> *dies
;
3518 struct variable_value_hasher
: ggc_ptr_hash
<variable_value_struct
>
3520 typedef tree compare_type
;
3522 static hashval_t
hash (variable_value_struct
*);
3523 static bool equal (variable_value_struct
*, tree
);
3525 /* A hash table of DIEs that contain DW_OP_GNU_variable_value with
3526 dw_val_class_decl_ref class, indexed by FUNCTION_DECLs which is
3527 DECL_CONTEXT of the referenced VAR_DECLs. */
3528 static GTY (()) hash_table
<variable_value_hasher
> *variable_value_hash
;
3530 struct block_die_hasher
: ggc_ptr_hash
<die_struct
>
3532 static hashval_t
hash (die_struct
*);
3533 static bool equal (die_struct
*, die_struct
*);
3536 /* A hash table of references to DIE's that describe COMMON blocks.
3537 The key is DECL_UID() ^ die_parent. */
3538 static GTY (()) hash_table
<block_die_hasher
> *common_block_die_table
;
3540 typedef struct GTY(()) die_arg_entry_struct
{
3546 /* Node of the variable location list. */
3547 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
3548 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
3549 EXPR_LIST chain. For small bitsizes, bitsize is encoded
3550 in mode of the EXPR_LIST node and first EXPR_LIST operand
3551 is either NOTE_INSN_VAR_LOCATION for a piece with a known
3552 location or NULL for padding. For larger bitsizes,
3553 mode is 0 and first operand is a CONCAT with bitsize
3554 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
3555 NULL as second operand. */
3557 const char * GTY (()) label
;
3558 struct var_loc_node
* GTY (()) next
;
3562 /* Variable location list. */
3563 struct GTY ((for_user
)) var_loc_list_def
{
3564 struct var_loc_node
* GTY (()) first
;
3566 /* Pointer to the last but one or last element of the
3567 chained list. If the list is empty, both first and
3568 last are NULL, if the list contains just one node
3569 or the last node certainly is not redundant, it points
3570 to the last node, otherwise points to the last but one.
3571 Do not mark it for GC because it is marked through the chain. */
3572 struct var_loc_node
* GTY ((skip ("%h"))) last
;
3574 /* Pointer to the last element before section switch,
3575 if NULL, either sections weren't switched or first
3576 is after section switch. */
3577 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
3579 /* DECL_UID of the variable decl. */
3580 unsigned int decl_id
;
3582 typedef struct var_loc_list_def var_loc_list
;
3584 /* Call argument location list. */
3585 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
3586 rtx
GTY (()) call_arg_loc_note
;
3587 const char * GTY (()) label
;
3588 tree
GTY (()) block
;
3590 rtx
GTY (()) symbol_ref
;
3591 struct call_arg_loc_node
* GTY (()) next
;
3595 struct decl_loc_hasher
: ggc_ptr_hash
<var_loc_list
>
3597 typedef const_tree compare_type
;
3599 static hashval_t
hash (var_loc_list
*);
3600 static bool equal (var_loc_list
*, const_tree
);
3603 /* Table of decl location linked lists. */
3604 static GTY (()) hash_table
<decl_loc_hasher
> *decl_loc_table
;
3606 /* Head and tail of call_arg_loc chain. */
3607 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
3608 static struct call_arg_loc_node
*call_arg_loc_last
;
3610 /* Number of call sites in the current function. */
3611 static int call_site_count
= -1;
3612 /* Number of tail call sites in the current function. */
3613 static int tail_call_site_count
= -1;
3615 /* A cached location list. */
3616 struct GTY ((for_user
)) cached_dw_loc_list_def
{
3617 /* The DECL_UID of the decl that this entry describes. */
3618 unsigned int decl_id
;
3620 /* The cached location list. */
3621 dw_loc_list_ref loc_list
;
3623 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
3625 struct dw_loc_list_hasher
: ggc_ptr_hash
<cached_dw_loc_list
>
3628 typedef const_tree compare_type
;
3630 static hashval_t
hash (cached_dw_loc_list
*);
3631 static bool equal (cached_dw_loc_list
*, const_tree
);
3634 /* Table of cached location lists. */
3635 static GTY (()) hash_table
<dw_loc_list_hasher
> *cached_dw_loc_list_table
;
3637 /* A vector of references to DIE's that are uniquely identified by their tag,
3638 presence/absence of children DIE's, and list of attribute/value pairs. */
3639 static GTY(()) vec
<dw_die_ref
, va_gc
> *abbrev_die_table
;
3641 /* A hash map to remember the stack usage for DWARF procedures. The value
3642 stored is the stack size difference between before the DWARF procedure
3643 invokation and after it returned. In other words, for a DWARF procedure
3644 that consumes N stack slots and that pushes M ones, this stores M - N. */
3645 static hash_map
<dw_die_ref
, int> *dwarf_proc_stack_usage_map
;
3647 /* A global counter for generating labels for line number data. */
3648 static unsigned int line_info_label_num
;
3650 /* The current table to which we should emit line number information
3651 for the current function. This will be set up at the beginning of
3652 assembly for the function. */
3653 static GTY(()) dw_line_info_table
*cur_line_info_table
;
3655 /* The two default tables of line number info. */
3656 static GTY(()) dw_line_info_table
*text_section_line_info
;
3657 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
3659 /* The set of all non-default tables of line number info. */
3660 static GTY(()) vec
<dw_line_info_table
*, va_gc
> *separate_line_info
;
3662 /* A flag to tell pubnames/types export if there is an info section to
3664 static bool info_section_emitted
;
3666 /* A pointer to the base of a table that contains a list of publicly
3667 accessible names. */
3668 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
3670 /* A pointer to the base of a table that contains a list of publicly
3671 accessible types. */
3672 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
3674 /* A pointer to the base of a table that contains a list of macro
3675 defines/undefines (and file start/end markers). */
3676 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
3678 /* True if .debug_macinfo or .debug_macros section is going to be
3680 #define have_macinfo \
3681 ((!XCOFF_DEBUGGING_INFO || HAVE_XCOFF_DWARF_EXTRAS) \
3682 && debug_info_level >= DINFO_LEVEL_VERBOSE \
3683 && !macinfo_table->is_empty ())
3685 /* Vector of dies for which we should generate .debug_ranges info. */
3686 static GTY (()) vec
<dw_ranges
, va_gc
> *ranges_table
;
3688 /* Vector of pairs of labels referenced in ranges_table. */
3689 static GTY (()) vec
<dw_ranges_by_label
, va_gc
> *ranges_by_label
;
3691 /* Whether we have location lists that need outputting */
3692 static GTY(()) bool have_location_lists
;
3694 /* Unique label counter. */
3695 static GTY(()) unsigned int loclabel_num
;
3697 /* Unique label counter for point-of-call tables. */
3698 static GTY(()) unsigned int poc_label_num
;
3700 /* The last file entry emitted by maybe_emit_file(). */
3701 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
3703 /* Number of internal labels generated by gen_internal_sym(). */
3704 static GTY(()) int label_num
;
3706 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
3708 /* Instances of generic types for which we need to generate debug
3709 info that describe their generic parameters and arguments. That
3710 generation needs to happen once all types are properly laid out so
3711 we do it at the end of compilation. */
3712 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
3714 /* Offset from the "steady-state frame pointer" to the frame base,
3715 within the current function. */
3716 static poly_int64 frame_pointer_fb_offset
;
3717 static bool frame_pointer_fb_offset_valid
;
3719 static vec
<dw_die_ref
> base_types
;
3721 /* Flags to represent a set of attribute classes for attributes that represent
3722 a scalar value (bounds, pointers, ...). */
3725 dw_scalar_form_constant
= 0x01,
3726 dw_scalar_form_exprloc
= 0x02,
3727 dw_scalar_form_reference
= 0x04
3730 /* Forward declarations for functions defined in this file. */
3732 static bool is_pseudo_reg (const_rtx
);
3733 static tree
type_main_variant (tree
);
3734 static bool is_tagged_type (const_tree
);
3735 static const char *dwarf_tag_name (unsigned);
3736 static const char *dwarf_attr_name (unsigned);
3737 static const char *dwarf_form_name (unsigned);
3738 static tree
decl_ultimate_origin (const_tree
);
3739 static tree
decl_class_context (tree
);
3740 static void add_dwarf_attr (dw_die_ref
, dw_attr_node
*);
3741 static inline unsigned int AT_index (dw_attr_node
*);
3742 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3743 static inline unsigned AT_flag (dw_attr_node
*);
3744 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3745 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3746 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
3747 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
3748 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3749 unsigned int, unsigned char *);
3750 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
3751 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3752 static inline const char *AT_string (dw_attr_node
*);
3753 static enum dwarf_form
AT_string_form (dw_attr_node
*);
3754 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3755 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3756 static inline dw_die_ref
AT_ref (dw_attr_node
*);
3757 static inline int AT_ref_external (dw_attr_node
*);
3758 static inline void set_AT_ref_external (dw_attr_node
*, int);
3759 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3760 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3762 static inline dw_loc_list_ref
AT_loc_list (dw_attr_node
*);
3763 static void add_AT_view_list (dw_die_ref
, enum dwarf_attribute
);
3764 static inline dw_loc_list_ref
AT_loc_list (dw_attr_node
*);
3765 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
3766 static void remove_addr_table_entry (addr_table_entry
*);
3767 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
3768 static inline rtx
AT_addr (dw_attr_node
*);
3769 static void add_AT_symview (dw_die_ref
, enum dwarf_attribute
, const char *);
3770 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3771 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3772 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3773 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3774 unsigned long, bool);
3775 static inline const char *AT_lbl (dw_attr_node
*);
3776 static const char *get_AT_low_pc (dw_die_ref
);
3777 static bool is_c (void);
3778 static bool is_cxx (void);
3779 static bool is_cxx (const_tree
);
3780 static bool is_fortran (void);
3781 static bool is_ada (void);
3782 static bool remove_AT (dw_die_ref
, enum dwarf_attribute
);
3783 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3784 static void add_child_die (dw_die_ref
, dw_die_ref
);
3785 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3786 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3787 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3788 static void equate_type_number_to_die (tree
, dw_die_ref
);
3789 static var_loc_list
*lookup_decl_loc (const_tree
);
3790 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3791 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *, var_loc_view
);
3792 static void print_spaces (FILE *);
3793 static void print_die (dw_die_ref
, FILE *);
3794 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3795 static void attr_checksum (dw_attr_node
*, struct md5_ctx
*, int *);
3796 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3797 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3798 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3799 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3800 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_node
*,
3801 struct md5_ctx
*, int *);
3802 struct checksum_attributes
;
3803 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3804 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3805 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3806 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3807 static bool same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3808 static bool same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3809 static bool same_attr_p (dw_attr_node
*, dw_attr_node
*, int *);
3810 static bool same_die_p (dw_die_ref
, dw_die_ref
, int *);
3811 static bool is_type_die (dw_die_ref
);
3812 static inline bool is_template_instantiation (dw_die_ref
);
3813 static bool is_declaration_die (dw_die_ref
);
3814 static bool should_move_die_to_comdat (dw_die_ref
);
3815 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3816 static dw_die_ref
clone_die (dw_die_ref
);
3817 static dw_die_ref
clone_tree (dw_die_ref
);
3818 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3819 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3820 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3821 static dw_die_ref
generate_skeleton (dw_die_ref
);
3822 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3825 static void break_out_comdat_types (dw_die_ref
);
3826 static void copy_decls_for_unworthy_types (dw_die_ref
);
3828 static void add_sibling_attributes (dw_die_ref
);
3829 static void output_location_lists (dw_die_ref
);
3830 static int constant_size (unsigned HOST_WIDE_INT
);
3831 static unsigned long size_of_die (dw_die_ref
);
3832 static void calc_die_sizes (dw_die_ref
);
3833 static void calc_base_type_die_sizes (void);
3834 static void mark_dies (dw_die_ref
);
3835 static void unmark_dies (dw_die_ref
);
3836 static void unmark_all_dies (dw_die_ref
);
3837 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3838 static unsigned long size_of_aranges (void);
3839 static enum dwarf_form
value_format (dw_attr_node
*);
3840 static void output_value_format (dw_attr_node
*);
3841 static void output_abbrev_section (void);
3842 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3843 static void output_die (dw_die_ref
);
3844 static void output_compilation_unit_header (enum dwarf_unit_type
);
3845 static void output_comp_unit (dw_die_ref
, int, const unsigned char *);
3846 static void output_comdat_type_unit (comdat_type_node
*, bool);
3847 static const char *dwarf2_name (tree
, int);
3848 static void add_pubname (tree
, dw_die_ref
);
3849 static void add_enumerator_pubname (const char *, dw_die_ref
);
3850 static void add_pubname_string (const char *, dw_die_ref
);
3851 static void add_pubtype (tree
, dw_die_ref
);
3852 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3853 static void output_aranges (void);
3854 static unsigned int add_ranges (const_tree
, bool = false);
3855 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3857 static void output_ranges (void);
3858 static dw_line_info_table
*new_line_info_table (void);
3859 static void output_line_info (bool);
3860 static void output_file_names (void);
3861 static bool is_base_type (tree
);
3862 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, tree
, dw_die_ref
);
3863 static int decl_quals (const_tree
);
3864 static dw_die_ref
modified_type_die (tree
, int, bool, dw_die_ref
);
3865 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3866 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3867 static unsigned int debugger_reg_number (const_rtx
);
3868 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3869 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3870 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3871 enum var_init_status
);
3872 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3873 enum var_init_status
);
3874 static dw_loc_descr_ref
based_loc_descr (rtx
, poly_int64
,
3875 enum var_init_status
);
3876 static bool is_based_loc (const_rtx
);
3877 static bool resolve_one_addr (rtx
*);
3878 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3879 enum var_init_status
);
3880 static dw_loc_descr_ref
loc_descriptor (rtx
, machine_mode mode
,
3881 enum var_init_status
);
3882 struct loc_descr_context
;
3883 static void add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
);
3884 static void add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
);
3885 static dw_loc_list_ref
loc_list_from_tree (tree
, int,
3886 struct loc_descr_context
*);
3887 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int,
3888 struct loc_descr_context
*);
3889 static tree
field_type (const_tree
);
3890 static unsigned int simple_type_align_in_bits (const_tree
);
3891 static unsigned int simple_decl_align_in_bits (const_tree
);
3892 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3894 static dw_loc_descr_ref
field_byte_offset (const_tree
, struct vlr_context
*,
3896 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3898 static void add_data_member_location_attribute (dw_die_ref
, tree
,
3899 struct vlr_context
*);
3900 static bool add_const_value_attribute (dw_die_ref
, machine_mode
, rtx
);
3901 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3902 static void insert_wide_int (const wide_int_ref
&, unsigned char *, int);
3903 static unsigned insert_float (const_rtx
, unsigned char *);
3904 static rtx
rtl_for_decl_location (tree
);
3905 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool);
3906 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3907 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3908 static void add_desc_attribute (dw_die_ref
, tree
);
3909 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3910 static void add_comp_dir_attribute (dw_die_ref
);
3911 static void add_scalar_info (dw_die_ref
, enum dwarf_attribute
, tree
, int,
3912 struct loc_descr_context
*);
3913 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
,
3914 struct loc_descr_context
*);
3915 static void add_subscript_info (dw_die_ref
, tree
, bool);
3916 static void add_byte_size_attribute (dw_die_ref
, tree
);
3917 static void add_alignment_attribute (dw_die_ref
, tree
);
3918 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3919 static void add_bit_size_attribute (dw_die_ref
, tree
);
3920 static void add_prototyped_attribute (dw_die_ref
, tree
);
3921 static void add_abstract_origin_attribute (dw_die_ref
, tree
);
3922 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3923 static void add_src_coords_attributes (dw_die_ref
, tree
);
3924 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
, bool = false);
3925 static void add_discr_value (dw_die_ref
, dw_discr_value
*);
3926 static void add_discr_list (dw_die_ref
, dw_discr_list_ref
);
3927 static inline dw_discr_list_ref
AT_discr_list (dw_attr_node
*);
3928 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3929 static inline bool local_scope_p (dw_die_ref
);
3930 static inline bool class_scope_p (dw_die_ref
);
3931 static inline bool class_or_namespace_scope_p (dw_die_ref
);
3932 static void add_type_attribute (dw_die_ref
, tree
, int, bool, dw_die_ref
);
3933 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3934 static const char *type_tag (const_tree
);
3935 static tree
member_declared_type (const_tree
);
3937 static const char *decl_start_label (tree
);
3939 static void gen_array_type_die (tree
, dw_die_ref
);
3940 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3942 static void gen_entry_point_die (tree
, dw_die_ref
);
3944 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
, bool);
3945 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3946 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3947 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3948 static void gen_formal_types_die (tree
, dw_die_ref
);
3949 static void gen_subprogram_die (tree
, dw_die_ref
);
3950 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3951 static void gen_const_die (tree
, dw_die_ref
);
3952 static void gen_label_die (tree
, dw_die_ref
);
3953 static void gen_lexical_block_die (tree
, dw_die_ref
);
3954 static void gen_inlined_subroutine_die (tree
, dw_die_ref
);
3955 static void gen_field_die (tree
, struct vlr_context
*, dw_die_ref
);
3956 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3957 static dw_die_ref
gen_compile_unit_die (const char *);
3958 static void gen_inheritance_die (tree
, tree
, tree
, dw_die_ref
);
3959 static void gen_member_die (tree
, dw_die_ref
);
3960 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3961 enum debug_info_usage
);
3962 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3963 static void gen_typedef_die (tree
, dw_die_ref
);
3964 static void gen_type_die (tree
, dw_die_ref
, bool = false);
3965 static void gen_block_die (tree
, dw_die_ref
);
3966 static void decls_for_scope (tree
, dw_die_ref
, bool = true);
3967 static bool is_naming_typedef_decl (const_tree
);
3968 static inline dw_die_ref
get_context_die (tree
);
3969 static void gen_namespace_die (tree
, dw_die_ref
);
3970 static dw_die_ref
gen_namelist_decl (tree
, dw_die_ref
, tree
);
3971 static dw_die_ref
gen_decl_die (tree
, tree
, struct vlr_context
*, dw_die_ref
);
3972 static dw_die_ref
force_decl_die (tree
);
3973 static dw_die_ref
force_type_die (tree
);
3974 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3975 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3976 static struct dwarf_file_data
* lookup_filename (const char *);
3977 static void retry_incomplete_types (void);
3978 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3979 static void gen_generic_params_dies (tree
);
3980 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
,
3982 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
,
3984 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3985 static int file_info_cmp (const void *, const void *);
3986 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *, var_loc_view
,
3987 const char *, var_loc_view
, const char *);
3988 static void output_loc_list (dw_loc_list_ref
);
3989 static char *gen_internal_sym (const char *);
3990 static bool want_pubnames (void);
3992 static void prune_unmark_dies (dw_die_ref
);
3993 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3994 static void prune_unused_types_mark (dw_die_ref
, int);
3995 static void prune_unused_types_walk (dw_die_ref
);
3996 static void prune_unused_types_walk_attribs (dw_die_ref
);
3997 static void prune_unused_types_prune (dw_die_ref
);
3998 static void prune_unused_types (void);
3999 static int maybe_emit_file (struct dwarf_file_data
*fd
);
4000 static inline const char *AT_vms_delta1 (dw_attr_node
*);
4001 static inline const char *AT_vms_delta2 (dw_attr_node
*);
4002 #if VMS_DEBUGGING_INFO
4003 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
4004 const char *, const char *);
4006 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
4007 static void gen_remaining_tmpl_value_param_die_attribute (void);
4008 static bool generic_type_p (tree
);
4009 static void schedule_generic_params_dies_gen (tree t
);
4010 static void gen_scheduled_generic_parms_dies (void);
4011 static void resolve_variable_values (void);
4013 static const char *comp_dir_string (void);
4015 static void hash_loc_operands (dw_loc_descr_ref
, inchash::hash
&);
4017 /* enum for tracking thread-local variables whose address is really an offset
4018 relative to the TLS pointer, which will need link-time relocation, but will
4019 not need relocation by the DWARF consumer. */
4027 /* Return the operator to use for an address of a variable. For dtprel_true, we
4028 use DW_OP_const*. For regular variables, which need both link-time
4029 relocation and consumer-level relocation (e.g., to account for shared objects
4030 loaded at a random address), we use DW_OP_addr*. */
4032 static inline enum dwarf_location_atom
4033 dw_addr_op (enum dtprel_bool dtprel
)
4035 if (dtprel
== dtprel_true
)
4036 return (dwarf_split_debug_info
? dwarf_OP (DW_OP_constx
)
4037 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
4039 return dwarf_split_debug_info
? dwarf_OP (DW_OP_addrx
) : DW_OP_addr
;
4042 /* Return a pointer to a newly allocated address location description. If
4043 dwarf_split_debug_info is true, then record the address with the appropriate
4045 static inline dw_loc_descr_ref
4046 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
4048 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
4050 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
4051 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
4052 ref
->dtprel
= dtprel
;
4053 if (dwarf_split_debug_info
)
4054 ref
->dw_loc_oprnd1
.val_entry
4055 = add_addr_table_entry (addr
,
4056 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
4058 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
4063 /* Section names used to hold DWARF debugging information. */
4065 #ifndef DEBUG_INFO_SECTION
4066 #define DEBUG_INFO_SECTION ".debug_info"
4068 #ifndef DEBUG_DWO_INFO_SECTION
4069 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
4071 #ifndef DEBUG_LTO_INFO_SECTION
4072 #define DEBUG_LTO_INFO_SECTION ".gnu.debuglto_.debug_info"
4074 #ifndef DEBUG_LTO_DWO_INFO_SECTION
4075 #define DEBUG_LTO_DWO_INFO_SECTION ".gnu.debuglto_.debug_info.dwo"
4077 #ifndef DEBUG_ABBREV_SECTION
4078 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4080 #ifndef DEBUG_LTO_ABBREV_SECTION
4081 #define DEBUG_LTO_ABBREV_SECTION ".gnu.debuglto_.debug_abbrev"
4083 #ifndef DEBUG_DWO_ABBREV_SECTION
4084 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
4086 #ifndef DEBUG_LTO_DWO_ABBREV_SECTION
4087 #define DEBUG_LTO_DWO_ABBREV_SECTION ".gnu.debuglto_.debug_abbrev.dwo"
4089 #ifndef DEBUG_ARANGES_SECTION
4090 #define DEBUG_ARANGES_SECTION ".debug_aranges"
4092 #ifndef DEBUG_ADDR_SECTION
4093 #define DEBUG_ADDR_SECTION ".debug_addr"
4095 #ifndef DEBUG_MACINFO_SECTION
4096 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4098 #ifndef DEBUG_LTO_MACINFO_SECTION
4099 #define DEBUG_LTO_MACINFO_SECTION ".gnu.debuglto_.debug_macinfo"
4101 #ifndef DEBUG_DWO_MACINFO_SECTION
4102 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
4104 #ifndef DEBUG_LTO_DWO_MACINFO_SECTION
4105 #define DEBUG_LTO_DWO_MACINFO_SECTION ".gnu.debuglto_.debug_macinfo.dwo"
4107 #ifndef DEBUG_MACRO_SECTION
4108 #define DEBUG_MACRO_SECTION ".debug_macro"
4110 #ifndef DEBUG_LTO_MACRO_SECTION
4111 #define DEBUG_LTO_MACRO_SECTION ".gnu.debuglto_.debug_macro"
4113 #ifndef DEBUG_DWO_MACRO_SECTION
4114 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
4116 #ifndef DEBUG_LTO_DWO_MACRO_SECTION
4117 #define DEBUG_LTO_DWO_MACRO_SECTION ".gnu.debuglto_.debug_macro.dwo"
4119 #ifndef DEBUG_LINE_SECTION
4120 #define DEBUG_LINE_SECTION ".debug_line"
4122 #ifndef DEBUG_LTO_LINE_SECTION
4123 #define DEBUG_LTO_LINE_SECTION ".gnu.debuglto_.debug_line"
4125 #ifndef DEBUG_DWO_LINE_SECTION
4126 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
4128 #ifndef DEBUG_LTO_DWO_LINE_SECTION
4129 #define DEBUG_LTO_DWO_LINE_SECTION ".gnu.debuglto_.debug_line.dwo"
4131 #ifndef DEBUG_LOC_SECTION
4132 #define DEBUG_LOC_SECTION ".debug_loc"
4134 #ifndef DEBUG_DWO_LOC_SECTION
4135 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
4137 #ifndef DEBUG_LOCLISTS_SECTION
4138 #define DEBUG_LOCLISTS_SECTION ".debug_loclists"
4140 #ifndef DEBUG_DWO_LOCLISTS_SECTION
4141 #define DEBUG_DWO_LOCLISTS_SECTION ".debug_loclists.dwo"
4143 #ifndef DEBUG_PUBNAMES_SECTION
4144 #define DEBUG_PUBNAMES_SECTION \
4145 ((debug_generate_pub_sections == 2) \
4146 ? ".debug_gnu_pubnames" : ".debug_pubnames")
4148 #ifndef DEBUG_PUBTYPES_SECTION
4149 #define DEBUG_PUBTYPES_SECTION \
4150 ((debug_generate_pub_sections == 2) \
4151 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
4153 #ifndef DEBUG_STR_OFFSETS_SECTION
4154 #define DEBUG_STR_OFFSETS_SECTION ".debug_str_offsets"
4156 #ifndef DEBUG_DWO_STR_OFFSETS_SECTION
4157 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
4159 #ifndef DEBUG_LTO_DWO_STR_OFFSETS_SECTION
4160 #define DEBUG_LTO_DWO_STR_OFFSETS_SECTION ".gnu.debuglto_.debug_str_offsets.dwo"
4162 #ifndef DEBUG_STR_SECTION
4163 #define DEBUG_STR_SECTION ".debug_str"
4165 #ifndef DEBUG_LTO_STR_SECTION
4166 #define DEBUG_LTO_STR_SECTION ".gnu.debuglto_.debug_str"
4168 #ifndef DEBUG_STR_DWO_SECTION
4169 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
4171 #ifndef DEBUG_LTO_STR_DWO_SECTION
4172 #define DEBUG_LTO_STR_DWO_SECTION ".gnu.debuglto_.debug_str.dwo"
4174 #ifndef DEBUG_RANGES_SECTION
4175 #define DEBUG_RANGES_SECTION ".debug_ranges"
4177 #ifndef DEBUG_RNGLISTS_SECTION
4178 #define DEBUG_RNGLISTS_SECTION ".debug_rnglists"
4180 #ifndef DEBUG_DWO_RNGLISTS_SECTION
4181 #define DEBUG_DWO_RNGLISTS_SECTION ".debug_rnglists.dwo"
4183 #ifndef DEBUG_LINE_STR_SECTION
4184 #define DEBUG_LINE_STR_SECTION ".debug_line_str"
4186 #ifndef DEBUG_LTO_LINE_STR_SECTION
4187 #define DEBUG_LTO_LINE_STR_SECTION ".gnu.debuglto_.debug_line_str"
4190 /* Section flags for .debug_str section. */
4191 #define DEBUG_STR_SECTION_FLAGS \
4192 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
4193 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4196 /* Section flags for .debug_str.dwo section. */
4197 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
4199 /* Attribute used to refer to the macro section. */
4200 #define DEBUG_MACRO_ATTRIBUTE (dwarf_version >= 5 ? DW_AT_macros \
4201 : dwarf_strict ? DW_AT_macro_info : DW_AT_GNU_macros)
4203 /* Labels we insert at beginning sections we can reference instead of
4204 the section names themselves. */
4206 #ifndef TEXT_SECTION_LABEL
4207 #define TEXT_SECTION_LABEL "Ltext"
4209 #ifndef COLD_TEXT_SECTION_LABEL
4210 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
4212 #ifndef DEBUG_LINE_SECTION_LABEL
4213 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4215 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
4216 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
4218 #ifndef DEBUG_INFO_SECTION_LABEL
4219 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4221 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
4222 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
4224 #ifndef DEBUG_ABBREV_SECTION_LABEL
4225 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4227 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
4228 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
4230 #ifndef DEBUG_ADDR_SECTION_LABEL
4231 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
4233 #ifndef DEBUG_LOC_SECTION_LABEL
4234 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4236 #ifndef DEBUG_RANGES_SECTION_LABEL
4237 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4239 #ifndef DEBUG_MACINFO_SECTION_LABEL
4240 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4242 #ifndef DEBUG_MACRO_SECTION_LABEL
4243 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
4245 #define SKELETON_COMP_DIE_ABBREV 1
4246 #define SKELETON_TYPE_DIE_ABBREV 2
4248 /* Definitions of defaults for formats and names of various special
4249 (artificial) labels which may be generated within this file (when the -g
4250 options is used and DWARF2_DEBUGGING_INFO is in effect.
4251 If necessary, these may be overridden from within the tm.h file, but
4252 typically, overriding these defaults is unnecessary. */
4254 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4255 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4256 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4257 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4258 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4259 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4260 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4261 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4262 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4263 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4264 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4265 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4266 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4267 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
4268 static char ranges_base_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
4270 #ifndef TEXT_END_LABEL
4271 #define TEXT_END_LABEL "Letext"
4273 #ifndef COLD_END_LABEL
4274 #define COLD_END_LABEL "Letext_cold"
4276 #ifndef BLOCK_BEGIN_LABEL
4277 #define BLOCK_BEGIN_LABEL "LBB"
4279 #ifndef BLOCK_INLINE_ENTRY_LABEL
4280 #define BLOCK_INLINE_ENTRY_LABEL "LBI"
4282 #ifndef BLOCK_END_LABEL
4283 #define BLOCK_END_LABEL "LBE"
4285 #ifndef LINE_CODE_LABEL
4286 #define LINE_CODE_LABEL "LM"
4290 /* Return the root of the DIE's built for the current compilation unit. */
4292 comp_unit_die (void)
4294 if (!single_comp_unit_die
)
4295 single_comp_unit_die
= gen_compile_unit_die (NULL
);
4296 return single_comp_unit_die
;
4299 /* We allow a language front-end to designate a function that is to be
4300 called to "demangle" any name before it is put into a DIE. */
4302 static const char *(*demangle_name_func
) (const char *);
4305 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
4307 demangle_name_func
= func
;
4310 /* Test if rtl node points to a pseudo register. */
4313 is_pseudo_reg (const_rtx rtl
)
4315 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
4316 || (GET_CODE (rtl
) == SUBREG
4317 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
4320 /* Return a reference to a type, with its const and volatile qualifiers
4324 type_main_variant (tree type
)
4326 type
= TYPE_MAIN_VARIANT (type
);
4328 /* ??? There really should be only one main variant among any group of
4329 variants of a given type (and all of the MAIN_VARIANT values for all
4330 members of the group should point to that one type) but sometimes the C
4331 front-end messes this up for array types, so we work around that bug
4333 if (TREE_CODE (type
) == ARRAY_TYPE
)
4334 while (type
!= TYPE_MAIN_VARIANT (type
))
4335 type
= TYPE_MAIN_VARIANT (type
);
4340 /* Return true if the given type node represents a tagged type. */
4343 is_tagged_type (const_tree type
)
4345 enum tree_code code
= TREE_CODE (type
);
4347 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
4348 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
4351 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
4354 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
4356 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
4359 /* Return die_offset of a DIE reference to a base type. */
4361 static unsigned long int
4362 get_base_type_offset (dw_die_ref ref
)
4364 if (ref
->die_offset
)
4365 return ref
->die_offset
;
4366 if (comp_unit_die ()->die_abbrev
)
4368 calc_base_type_die_sizes ();
4369 gcc_assert (ref
->die_offset
);
4371 return ref
->die_offset
;
4374 /* Return die_offset of a DIE reference other than base type. */
4376 static unsigned long int
4377 get_ref_die_offset (dw_die_ref ref
)
4379 gcc_assert (ref
->die_offset
);
4380 return ref
->die_offset
;
4383 /* Convert a DIE tag into its string name. */
4386 dwarf_tag_name (unsigned int tag
)
4388 const char *name
= get_DW_TAG_name (tag
);
4393 return "DW_TAG_<unknown>";
4396 /* Convert a DWARF attribute code into its string name. */
4399 dwarf_attr_name (unsigned int attr
)
4405 #if VMS_DEBUGGING_INFO
4406 case DW_AT_HP_prologue
:
4407 return "DW_AT_HP_prologue";
4409 case DW_AT_MIPS_loop_unroll_factor
:
4410 return "DW_AT_MIPS_loop_unroll_factor";
4413 #if VMS_DEBUGGING_INFO
4414 case DW_AT_HP_epilogue
:
4415 return "DW_AT_HP_epilogue";
4417 case DW_AT_MIPS_stride
:
4418 return "DW_AT_MIPS_stride";
4422 name
= get_DW_AT_name (attr
);
4427 return "DW_AT_<unknown>";
4430 /* Convert a DWARF value form code into its string name. */
4433 dwarf_form_name (unsigned int form
)
4435 const char *name
= get_DW_FORM_name (form
);
4440 return "DW_FORM_<unknown>";
4443 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4444 instance of an inlined instance of a decl which is local to an inline
4445 function, so we have to trace all of the way back through the origin chain
4446 to find out what sort of node actually served as the original seed for the
4450 decl_ultimate_origin (const_tree decl
)
4452 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
4455 /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
4456 we're trying to output the abstract instance of this function. */
4457 if (DECL_ABSTRACT_P (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4460 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4461 most distant ancestor, this should never happen. */
4462 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
4464 return DECL_ABSTRACT_ORIGIN (decl
);
4467 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4468 of a virtual function may refer to a base class, so we check the 'this'
4472 decl_class_context (tree decl
)
4474 tree context
= NULL_TREE
;
4476 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4477 context
= DECL_CONTEXT (decl
);
4479 context
= TYPE_MAIN_VARIANT
4480 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4482 if (context
&& !TYPE_P (context
))
4483 context
= NULL_TREE
;
4488 /* Add an attribute/value pair to a DIE. */
4491 add_dwarf_attr (dw_die_ref die
, dw_attr_node
*attr
)
4493 /* Maybe this should be an assert? */
4499 /* Check we do not add duplicate attrs. Can't use get_AT here
4500 because that recurses to the specification/abstract origin DIE. */
4503 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4504 gcc_assert (a
->dw_attr
!= attr
->dw_attr
);
4507 vec_safe_reserve (die
->die_attr
, 1);
4508 vec_safe_push (die
->die_attr
, *attr
);
4512 AT_class (dw_attr_node
*a
)
4514 return a
->dw_attr_val
.val_class
;
4517 /* Return the index for any attribute that will be referenced with a
4518 DW_FORM_addrx/GNU_addr_index or DW_FORM_strx/GNU_str_index. String
4519 indices are stored in dw_attr_val.v.val_str for reference counting
4522 static inline unsigned int
4523 AT_index (dw_attr_node
*a
)
4525 if (AT_class (a
) == dw_val_class_str
)
4526 return a
->dw_attr_val
.v
.val_str
->index
;
4527 else if (a
->dw_attr_val
.val_entry
!= NULL
)
4528 return a
->dw_attr_val
.val_entry
->index
;
4532 /* Add a flag value attribute to a DIE. */
4535 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
4539 attr
.dw_attr
= attr_kind
;
4540 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
4541 attr
.dw_attr_val
.val_entry
= NULL
;
4542 attr
.dw_attr_val
.v
.val_flag
= flag
;
4543 add_dwarf_attr (die
, &attr
);
4546 static inline unsigned
4547 AT_flag (dw_attr_node
*a
)
4549 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
4550 return a
->dw_attr_val
.v
.val_flag
;
4553 /* Add a signed integer attribute value to a DIE. */
4556 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
4560 attr
.dw_attr
= attr_kind
;
4561 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
4562 attr
.dw_attr_val
.val_entry
= NULL
;
4563 attr
.dw_attr_val
.v
.val_int
= int_val
;
4564 add_dwarf_attr (die
, &attr
);
4568 AT_int (dw_attr_node
*a
)
4570 gcc_assert (a
&& (AT_class (a
) == dw_val_class_const
4571 || AT_class (a
) == dw_val_class_const_implicit
));
4572 return a
->dw_attr_val
.v
.val_int
;
4575 /* Add an unsigned integer attribute value to a DIE. */
4578 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4579 unsigned HOST_WIDE_INT unsigned_val
)
4583 attr
.dw_attr
= attr_kind
;
4584 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4585 attr
.dw_attr_val
.val_entry
= NULL
;
4586 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4587 add_dwarf_attr (die
, &attr
);
4590 unsigned HOST_WIDE_INT
4591 AT_unsigned (dw_attr_node
*a
)
4593 gcc_assert (a
&& (AT_class (a
) == dw_val_class_unsigned_const
4594 || AT_class (a
) == dw_val_class_unsigned_const_implicit
));
4595 return a
->dw_attr_val
.v
.val_unsigned
;
4599 alloc_dw_wide_int (const wide_int_ref
&w
)
4602 = (dw_wide_int
*) ggc_internal_alloc (sizeof (dw_wide_int
)
4603 + ((w
.get_len () - 1)
4604 * sizeof (HOST_WIDE_INT
)));
4605 p
->precision
= w
.get_precision ();
4606 p
->len
= w
.get_len ();
4607 memcpy (p
->val
, w
.get_val (), p
->len
* sizeof (HOST_WIDE_INT
));
4611 /* Add an unsigned wide integer attribute value to a DIE. */
4614 add_AT_wide (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4615 const wide_int_ref
&w
)
4619 attr
.dw_attr
= attr_kind
;
4620 attr
.dw_attr_val
.val_class
= dw_val_class_wide_int
;
4621 attr
.dw_attr_val
.val_entry
= NULL
;
4622 attr
.dw_attr_val
.v
.val_wide
= alloc_dw_wide_int (w
);
4623 add_dwarf_attr (die
, &attr
);
4626 /* Add an unsigned double integer attribute value to a DIE. */
4629 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4630 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
4634 attr
.dw_attr
= attr_kind
;
4635 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
4636 attr
.dw_attr_val
.val_entry
= NULL
;
4637 attr
.dw_attr_val
.v
.val_double
.high
= high
;
4638 attr
.dw_attr_val
.v
.val_double
.low
= low
;
4639 add_dwarf_attr (die
, &attr
);
4642 /* Add a floating point attribute value to a DIE and return it. */
4645 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4646 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
4650 attr
.dw_attr
= attr_kind
;
4651 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
4652 attr
.dw_attr_val
.val_entry
= NULL
;
4653 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
4654 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
4655 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
4656 add_dwarf_attr (die
, &attr
);
4659 /* Add an 8-byte data attribute value to a DIE. */
4662 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4663 unsigned char data8
[8])
4667 attr
.dw_attr
= attr_kind
;
4668 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
4669 attr
.dw_attr_val
.val_entry
= NULL
;
4670 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
4671 add_dwarf_attr (die
, &attr
);
4674 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
4675 dwarf_split_debug_info, address attributes in dies destined for the
4676 final executable have force_direct set to avoid using indexed
4680 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
4686 lbl_id
= xstrdup (lbl_low
);
4687 attr
.dw_attr
= DW_AT_low_pc
;
4688 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4689 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4690 if (dwarf_split_debug_info
&& !force_direct
)
4691 attr
.dw_attr_val
.val_entry
4692 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4694 attr
.dw_attr_val
.val_entry
= NULL
;
4695 add_dwarf_attr (die
, &attr
);
4697 attr
.dw_attr
= DW_AT_high_pc
;
4698 if (dwarf_version
< 4)
4699 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4701 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
4702 lbl_id
= xstrdup (lbl_high
);
4703 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4704 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
4705 && dwarf_split_debug_info
&& !force_direct
)
4706 attr
.dw_attr_val
.val_entry
4707 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4709 attr
.dw_attr_val
.val_entry
= NULL
;
4710 add_dwarf_attr (die
, &attr
);
4713 /* Hash and equality functions for debug_str_hash. */
4716 indirect_string_hasher::hash (indirect_string_node
*x
)
4718 return htab_hash_string (x
->str
);
4722 indirect_string_hasher::equal (indirect_string_node
*x1
, const char *x2
)
4724 return strcmp (x1
->str
, x2
) == 0;
4727 /* Add STR to the given string hash table. */
4729 static struct indirect_string_node
*
4730 find_AT_string_in_table (const char *str
,
4731 hash_table
<indirect_string_hasher
> *table
,
4732 enum insert_option insert
= INSERT
)
4734 struct indirect_string_node
*node
;
4736 indirect_string_node
**slot
4737 = table
->find_slot_with_hash (str
, htab_hash_string (str
), insert
);
4740 node
= ggc_cleared_alloc
<indirect_string_node
> ();
4741 node
->str
= ggc_strdup (str
);
4751 /* Add STR to the indirect string hash table. */
4753 static struct indirect_string_node
*
4754 find_AT_string (const char *str
, enum insert_option insert
= INSERT
)
4756 if (! debug_str_hash
)
4757 debug_str_hash
= hash_table
<indirect_string_hasher
>::create_ggc (10);
4759 return find_AT_string_in_table (str
, debug_str_hash
, insert
);
4762 /* Add a string attribute value to a DIE. */
4765 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4768 struct indirect_string_node
*node
;
4770 node
= find_AT_string (str
);
4772 attr
.dw_attr
= attr_kind
;
4773 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4774 attr
.dw_attr_val
.val_entry
= NULL
;
4775 attr
.dw_attr_val
.v
.val_str
= node
;
4776 add_dwarf_attr (die
, &attr
);
4779 static inline const char *
4780 AT_string (dw_attr_node
*a
)
4782 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4783 return a
->dw_attr_val
.v
.val_str
->str
;
4786 /* Call this function directly to bypass AT_string_form's logic to put
4787 the string inline in the die. */
4790 set_indirect_string (struct indirect_string_node
*node
)
4792 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4793 /* Already indirect is a no op. */
4794 if (node
->form
== DW_FORM_strp
4795 || node
->form
== DW_FORM_line_strp
4796 || node
->form
== dwarf_FORM (DW_FORM_strx
))
4798 gcc_assert (node
->label
);
4801 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4802 ++dw2_string_counter
;
4803 node
->label
= xstrdup (label
);
4805 if (!dwarf_split_debug_info
)
4807 node
->form
= DW_FORM_strp
;
4808 node
->index
= NOT_INDEXED
;
4812 node
->form
= dwarf_FORM (DW_FORM_strx
);
4813 node
->index
= NO_INDEX_ASSIGNED
;
4817 /* A helper function for dwarf2out_finish, called to reset indirect
4818 string decisions done for early LTO dwarf output before fat object
4822 reset_indirect_string (indirect_string_node
**h
, void *)
4824 struct indirect_string_node
*node
= *h
;
4825 if (node
->form
== DW_FORM_strp
4826 || node
->form
== DW_FORM_line_strp
4827 || node
->form
== dwarf_FORM (DW_FORM_strx
))
4831 node
->form
= (dwarf_form
) 0;
4837 /* Add a string representing a file or filepath attribute value to a DIE. */
4840 add_filepath_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4843 if (! asm_outputs_debug_line_str ())
4844 add_AT_string (die
, attr_kind
, str
);
4848 struct indirect_string_node
*node
;
4850 if (!debug_line_str_hash
)
4852 = hash_table
<indirect_string_hasher
>::create_ggc (10);
4854 node
= find_AT_string_in_table (str
, debug_line_str_hash
);
4855 set_indirect_string (node
);
4856 node
->form
= DW_FORM_line_strp
;
4858 attr
.dw_attr
= attr_kind
;
4859 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4860 attr
.dw_attr_val
.val_entry
= NULL
;
4861 attr
.dw_attr_val
.v
.val_str
= node
;
4862 add_dwarf_attr (die
, &attr
);
4866 /* Find out whether a string should be output inline in DIE
4867 or out-of-line in .debug_str section. */
4869 static enum dwarf_form
4870 find_string_form (struct indirect_string_node
*node
)
4877 len
= strlen (node
->str
) + 1;
4879 /* If the string is shorter or equal to the size of the reference, it is
4880 always better to put it inline. */
4881 if (len
<= (unsigned) dwarf_offset_size
|| node
->refcount
== 0)
4882 return node
->form
= DW_FORM_string
;
4884 /* If we cannot expect the linker to merge strings in .debug_str
4885 section, only put it into .debug_str if it is worth even in this
4887 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4888 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4889 && (len
- dwarf_offset_size
) * node
->refcount
<= len
))
4890 return node
->form
= DW_FORM_string
;
4892 set_indirect_string (node
);
4897 /* Find out whether the string referenced from the attribute should be
4898 output inline in DIE or out-of-line in .debug_str section. */
4900 static enum dwarf_form
4901 AT_string_form (dw_attr_node
*a
)
4903 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4904 return find_string_form (a
->dw_attr_val
.v
.val_str
);
4907 /* Add a DIE reference attribute value to a DIE. */
4910 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4913 gcc_checking_assert (targ_die
!= NULL
);
4914 gcc_assert (targ_die
!= die
4915 || (attr_kind
!= DW_AT_abstract_origin
4916 && attr_kind
!= DW_AT_specification
));
4918 /* With LTO we can end up trying to reference something we didn't create
4919 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4920 if (targ_die
== NULL
)
4923 attr
.dw_attr
= attr_kind
;
4924 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4925 attr
.dw_attr_val
.val_entry
= NULL
;
4926 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4927 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4928 add_dwarf_attr (die
, &attr
);
4931 /* Change DIE reference REF to point to NEW_DIE instead. */
4934 change_AT_die_ref (dw_attr_node
*ref
, dw_die_ref new_die
)
4936 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4937 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4938 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4941 /* Add an AT_specification attribute to a DIE, and also make the back
4942 pointer from the specification to the definition. */
4945 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4947 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4948 gcc_assert (!targ_die
->die_definition
);
4949 targ_die
->die_definition
= die
;
4952 static inline dw_die_ref
4953 AT_ref (dw_attr_node
*a
)
4955 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4956 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4960 AT_ref_external (dw_attr_node
*a
)
4962 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4963 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4969 set_AT_ref_external (dw_attr_node
*a
, int i
)
4971 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4972 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4975 /* Add a location description attribute value to a DIE. */
4978 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4982 attr
.dw_attr
= attr_kind
;
4983 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4984 attr
.dw_attr_val
.val_entry
= NULL
;
4985 attr
.dw_attr_val
.v
.val_loc
= loc
;
4986 add_dwarf_attr (die
, &attr
);
4990 AT_loc (dw_attr_node
*a
)
4992 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4993 return a
->dw_attr_val
.v
.val_loc
;
4997 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
5001 if (XCOFF_DEBUGGING_INFO
&& !HAVE_XCOFF_DWARF_EXTRAS
)
5004 attr
.dw_attr
= attr_kind
;
5005 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
5006 attr
.dw_attr_val
.val_entry
= NULL
;
5007 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
5008 add_dwarf_attr (die
, &attr
);
5009 have_location_lists
= true;
5012 static inline dw_loc_list_ref
5013 AT_loc_list (dw_attr_node
*a
)
5015 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
5016 return a
->dw_attr_val
.v
.val_loc_list
;
5019 /* Add a view list attribute to DIE. It must have a DW_AT_location
5020 attribute, because the view list complements the location list. */
5023 add_AT_view_list (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5027 if (XCOFF_DEBUGGING_INFO
&& !HAVE_XCOFF_DWARF_EXTRAS
)
5030 attr
.dw_attr
= attr_kind
;
5031 attr
.dw_attr_val
.val_class
= dw_val_class_view_list
;
5032 attr
.dw_attr_val
.val_entry
= NULL
;
5033 attr
.dw_attr_val
.v
.val_view_list
= die
;
5034 add_dwarf_attr (die
, &attr
);
5035 gcc_checking_assert (get_AT (die
, DW_AT_location
));
5036 gcc_assert (have_location_lists
);
5039 /* Return a pointer to the location list referenced by the attribute.
5040 If the named attribute is a view list, look up the corresponding
5041 DW_AT_location attribute and return its location list. */
5043 static inline dw_loc_list_ref
*
5044 AT_loc_list_ptr (dw_attr_node
*a
)
5047 switch (AT_class (a
))
5049 case dw_val_class_loc_list
:
5050 return &a
->dw_attr_val
.v
.val_loc_list
;
5051 case dw_val_class_view_list
:
5054 l
= get_AT (a
->dw_attr_val
.v
.val_view_list
, DW_AT_location
);
5057 gcc_checking_assert (l
+ 1 == a
);
5058 return AT_loc_list_ptr (l
);
5065 /* Return the location attribute value associated with a view list
5068 static inline dw_val_node
*
5069 view_list_to_loc_list_val_node (dw_val_node
*val
)
5071 gcc_assert (val
->val_class
== dw_val_class_view_list
);
5072 dw_attr_node
*loc
= get_AT (val
->v
.val_view_list
, DW_AT_location
);
5075 gcc_checking_assert (&(loc
+ 1)->dw_attr_val
== val
);
5076 gcc_assert (AT_class (loc
) == dw_val_class_loc_list
);
5077 return &loc
->dw_attr_val
;
5080 struct addr_hasher
: ggc_ptr_hash
<addr_table_entry
>
5082 static hashval_t
hash (addr_table_entry
*);
5083 static bool equal (addr_table_entry
*, addr_table_entry
*);
5086 /* Table of entries into the .debug_addr section. */
5088 static GTY (()) hash_table
<addr_hasher
> *addr_index_table
;
5090 /* Hash an address_table_entry. */
5093 addr_hasher::hash (addr_table_entry
*a
)
5095 inchash::hash hstate
;
5101 case ate_kind_rtx_dtprel
:
5104 case ate_kind_label
:
5105 return htab_hash_string (a
->addr
.label
);
5109 inchash::add_rtx (a
->addr
.rtl
, hstate
);
5110 return hstate
.end ();
5113 /* Determine equality for two address_table_entries. */
5116 addr_hasher::equal (addr_table_entry
*a1
, addr_table_entry
*a2
)
5118 if (a1
->kind
!= a2
->kind
)
5123 case ate_kind_rtx_dtprel
:
5124 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
5125 case ate_kind_label
:
5126 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
5132 /* Initialize an addr_table_entry. */
5135 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
5141 case ate_kind_rtx_dtprel
:
5142 e
->addr
.rtl
= (rtx
) addr
;
5144 case ate_kind_label
:
5145 e
->addr
.label
= (char *) addr
;
5149 e
->index
= NO_INDEX_ASSIGNED
;
5152 /* Add attr to the address table entry to the table. Defer setting an
5153 index until output time. */
5155 static addr_table_entry
*
5156 add_addr_table_entry (void *addr
, enum ate_kind kind
)
5158 addr_table_entry
*node
;
5159 addr_table_entry finder
;
5161 gcc_assert (dwarf_split_debug_info
);
5162 if (! addr_index_table
)
5163 addr_index_table
= hash_table
<addr_hasher
>::create_ggc (10);
5164 init_addr_table_entry (&finder
, kind
, addr
);
5165 addr_table_entry
**slot
= addr_index_table
->find_slot (&finder
, INSERT
);
5167 if (*slot
== HTAB_EMPTY_ENTRY
)
5169 node
= ggc_cleared_alloc
<addr_table_entry
> ();
5170 init_addr_table_entry (node
, kind
, addr
);
5180 /* Remove an entry from the addr table by decrementing its refcount.
5181 Strictly, decrementing the refcount would be enough, but the
5182 assertion that the entry is actually in the table has found
5186 remove_addr_table_entry (addr_table_entry
*entry
)
5188 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
5189 /* After an index is assigned, the table is frozen. */
5190 gcc_assert (entry
->refcount
> 0 && entry
->index
== NO_INDEX_ASSIGNED
);
5194 /* Given a location list, remove all addresses it refers to from the
5198 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
5200 for (; descr
; descr
= descr
->dw_loc_next
)
5201 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
5203 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
5204 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
5208 /* A helper function for dwarf2out_finish called through
5209 htab_traverse. Assign an addr_table_entry its index. All entries
5210 must be collected into the table when this function is called,
5211 because the indexing code relies on htab_traverse to traverse nodes
5212 in the same order for each run. */
5215 index_addr_table_entry (addr_table_entry
**h
, unsigned int *index
)
5217 addr_table_entry
*node
= *h
;
5219 /* Don't index unreferenced nodes. */
5220 if (node
->refcount
== 0)
5223 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
5224 node
->index
= *index
;
5230 /* Return the tag of a given DIE. */
5233 dw_get_die_tag (dw_die_ref die
)
5235 return die
->die_tag
;
5238 /* Return a reference to the children list of a given DIE. */
5241 dw_get_die_child (dw_die_ref die
)
5243 return die
->die_child
;
5246 /* Return a reference to the sibling of a given DIE. */
5249 dw_get_die_sib (dw_die_ref die
)
5251 return die
->die_sib
;
5254 /* Add an address constant attribute value to a DIE. When using
5255 dwarf_split_debug_info, address attributes in dies destined for the
5256 final executable should be direct references--setting the parameter
5257 force_direct ensures this behavior. */
5260 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
5265 attr
.dw_attr
= attr_kind
;
5266 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
5267 attr
.dw_attr_val
.v
.val_addr
= addr
;
5268 if (dwarf_split_debug_info
&& !force_direct
)
5269 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
5271 attr
.dw_attr_val
.val_entry
= NULL
;
5272 add_dwarf_attr (die
, &attr
);
5275 /* Get the RTX from to an address DIE attribute. */
5278 AT_addr (dw_attr_node
*a
)
5280 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
5281 return a
->dw_attr_val
.v
.val_addr
;
5284 /* Add a file attribute value to a DIE. */
5287 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5288 struct dwarf_file_data
*fd
)
5292 attr
.dw_attr
= attr_kind
;
5293 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
5294 attr
.dw_attr_val
.val_entry
= NULL
;
5295 attr
.dw_attr_val
.v
.val_file
= fd
;
5296 add_dwarf_attr (die
, &attr
);
5299 /* Get the dwarf_file_data from a file DIE attribute. */
5301 static inline struct dwarf_file_data
*
5302 AT_file (dw_attr_node
*a
)
5304 gcc_assert (a
&& (AT_class (a
) == dw_val_class_file
5305 || AT_class (a
) == dw_val_class_file_implicit
));
5306 return a
->dw_attr_val
.v
.val_file
;
5309 #if VMS_DEBUGGING_INFO
5310 /* Add a vms delta attribute value to a DIE. */
5313 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5314 const char *lbl1
, const char *lbl2
)
5318 attr
.dw_attr
= attr_kind
;
5319 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
5320 attr
.dw_attr_val
.val_entry
= NULL
;
5321 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
5322 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
5323 add_dwarf_attr (die
, &attr
);
5327 /* Add a symbolic view identifier attribute value to a DIE. */
5330 add_AT_symview (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5331 const char *view_label
)
5335 attr
.dw_attr
= attr_kind
;
5336 attr
.dw_attr_val
.val_class
= dw_val_class_symview
;
5337 attr
.dw_attr_val
.val_entry
= NULL
;
5338 attr
.dw_attr_val
.v
.val_symbolic_view
= xstrdup (view_label
);
5339 add_dwarf_attr (die
, &attr
);
5342 /* Add a label identifier attribute value to a DIE. */
5345 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5350 attr
.dw_attr
= attr_kind
;
5351 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
5352 attr
.dw_attr_val
.val_entry
= NULL
;
5353 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
5354 if (dwarf_split_debug_info
)
5355 attr
.dw_attr_val
.val_entry
5356 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
5358 add_dwarf_attr (die
, &attr
);
5361 /* Add a section offset attribute value to a DIE, an offset into the
5362 debug_line section. */
5365 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5370 attr
.dw_attr
= attr_kind
;
5371 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
5372 attr
.dw_attr_val
.val_entry
= NULL
;
5373 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
5374 add_dwarf_attr (die
, &attr
);
5377 /* Add a section offset attribute value to a DIE, an offset into the
5378 debug_macinfo section. */
5381 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5386 attr
.dw_attr
= attr_kind
;
5387 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
5388 attr
.dw_attr_val
.val_entry
= NULL
;
5389 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
5390 add_dwarf_attr (die
, &attr
);
5393 /* Add a range_list attribute value to a DIE. When using
5394 dwarf_split_debug_info, address attributes in dies destined for the
5395 final executable should be direct references--setting the parameter
5396 force_direct ensures this behavior. */
5398 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
5399 #define RELOCATED_OFFSET (NULL)
5402 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5403 long unsigned int offset
, bool force_direct
)
5407 attr
.dw_attr
= attr_kind
;
5408 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
5409 /* For the range_list attribute, use val_entry to store whether the
5410 offset should follow split-debug-info or normal semantics. This
5411 value is read in output_range_list_offset. */
5412 if (dwarf_split_debug_info
&& !force_direct
)
5413 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
5415 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
5416 attr
.dw_attr_val
.v
.val_offset
= offset
;
5417 add_dwarf_attr (die
, &attr
);
5420 /* Return the start label of a delta attribute. */
5422 static inline const char *
5423 AT_vms_delta1 (dw_attr_node
*a
)
5425 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
5426 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
5429 /* Return the end label of a delta attribute. */
5431 static inline const char *
5432 AT_vms_delta2 (dw_attr_node
*a
)
5434 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
5435 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
5438 static inline const char *
5439 AT_lbl (dw_attr_node
*a
)
5441 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
5442 || AT_class (a
) == dw_val_class_lineptr
5443 || AT_class (a
) == dw_val_class_macptr
5444 || AT_class (a
) == dw_val_class_loclistsptr
5445 || AT_class (a
) == dw_val_class_high_pc
));
5446 return a
->dw_attr_val
.v
.val_lbl_id
;
5449 /* Get the attribute of type attr_kind. */
5452 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5456 dw_die_ref spec
= NULL
;
5461 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5462 if (a
->dw_attr
== attr_kind
)
5464 else if (a
->dw_attr
== DW_AT_specification
5465 || a
->dw_attr
== DW_AT_abstract_origin
)
5469 return get_AT (spec
, attr_kind
);
5474 /* Returns the parent of the declaration of DIE. */
5477 get_die_parent (dw_die_ref die
)
5484 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
5485 || (t
= get_AT_ref (die
, DW_AT_specification
)))
5488 return die
->die_parent
;
5491 /* Return the "low pc" attribute value, typically associated with a subprogram
5492 DIE. Return null if the "low pc" attribute is either not present, or if it
5493 cannot be represented as an assembler label identifier. */
5495 static inline const char *
5496 get_AT_low_pc (dw_die_ref die
)
5498 dw_attr_node
*a
= get_AT (die
, DW_AT_low_pc
);
5500 return a
? AT_lbl (a
) : NULL
;
5503 /* Return the value of the string attribute designated by ATTR_KIND, or
5504 NULL if it is not present. */
5507 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5509 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5511 return a
? AT_string (a
) : NULL
;
5514 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5515 if it is not present. */
5518 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5520 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5522 return a
? AT_flag (a
) : 0;
5525 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5526 if it is not present. */
5529 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5531 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5533 return a
? AT_unsigned (a
) : 0;
5537 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5539 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5541 return a
? AT_ref (a
) : NULL
;
5544 struct dwarf_file_data
*
5545 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5547 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5549 return a
? AT_file (a
) : NULL
;
5552 /* Return TRUE if the language is C. */
5557 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5559 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
|| lang
== DW_LANG_C99
5560 || lang
== DW_LANG_C11
|| lang
== DW_LANG_ObjC
);
5565 /* Return TRUE if the language is C++. */
5570 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5572 return (lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
5573 || lang
== DW_LANG_C_plus_plus_11
|| lang
== DW_LANG_C_plus_plus_14
);
5576 /* Return TRUE if DECL was created by the C++ frontend. */
5579 is_cxx (const_tree decl
)
5583 const_tree context
= get_ultimate_context (decl
);
5584 if (context
&& TRANSLATION_UNIT_LANGUAGE (context
))
5585 return startswith (TRANSLATION_UNIT_LANGUAGE (context
), "GNU C++");
5590 /* Return TRUE if the language is Fortran. */
5595 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5597 return (lang
== DW_LANG_Fortran77
5598 || lang
== DW_LANG_Fortran90
5599 || lang
== DW_LANG_Fortran95
5600 || lang
== DW_LANG_Fortran03
5601 || lang
== DW_LANG_Fortran08
);
5605 is_fortran (const_tree decl
)
5609 const_tree context
= get_ultimate_context (decl
);
5610 if (context
&& TRANSLATION_UNIT_LANGUAGE (context
))
5611 return (strncmp (TRANSLATION_UNIT_LANGUAGE (context
),
5612 "GNU Fortran", 11) == 0
5613 || strcmp (TRANSLATION_UNIT_LANGUAGE (context
),
5616 return is_fortran ();
5619 /* Return TRUE if the language is Rust.
5620 Note, returns FALSE for dwarf_version < 5 && dwarf_strict. */
5625 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5627 return lang
== DW_LANG_Rust
;
5630 /* Return TRUE if the language is Ada. */
5635 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5637 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
5640 /* Return TRUE if the language is D. */
5645 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5647 return lang
== DW_LANG_D
;
5650 /* Remove the specified attribute if present. Return TRUE if removal
5654 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5662 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5663 if (a
->dw_attr
== attr_kind
)
5665 if (AT_class (a
) == dw_val_class_str
)
5666 if (a
->dw_attr_val
.v
.val_str
->refcount
)
5667 a
->dw_attr_val
.v
.val_str
->refcount
--;
5669 /* vec::ordered_remove should help reduce the number of abbrevs
5671 die
->die_attr
->ordered_remove (ix
);
5677 /* Remove CHILD from its parent. PREV must have the property that
5678 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
5681 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
5683 gcc_assert (child
->die_parent
== prev
->die_parent
);
5684 gcc_assert (prev
->die_sib
== child
);
5687 gcc_assert (child
->die_parent
->die_child
== child
);
5691 prev
->die_sib
= child
->die_sib
;
5692 if (child
->die_parent
->die_child
== child
)
5693 child
->die_parent
->die_child
= prev
;
5694 child
->die_sib
= NULL
;
5697 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
5698 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
5701 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
5703 dw_die_ref parent
= old_child
->die_parent
;
5705 gcc_assert (parent
== prev
->die_parent
);
5706 gcc_assert (prev
->die_sib
== old_child
);
5708 new_child
->die_parent
= parent
;
5709 if (prev
== old_child
)
5711 gcc_assert (parent
->die_child
== old_child
);
5712 new_child
->die_sib
= new_child
;
5716 prev
->die_sib
= new_child
;
5717 new_child
->die_sib
= old_child
->die_sib
;
5719 if (old_child
->die_parent
->die_child
== old_child
)
5720 old_child
->die_parent
->die_child
= new_child
;
5721 old_child
->die_sib
= NULL
;
5724 /* Move all children from OLD_PARENT to NEW_PARENT. */
5727 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
5730 new_parent
->die_child
= old_parent
->die_child
;
5731 old_parent
->die_child
= NULL
;
5732 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
5735 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
5739 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
5745 dw_die_ref prev
= c
;
5747 while (c
->die_tag
== tag
)
5749 remove_child_with_prev (c
, prev
);
5750 c
->die_parent
= NULL
;
5751 /* Might have removed every child. */
5752 if (die
->die_child
== NULL
)
5756 } while (c
!= die
->die_child
);
5759 /* Add a CHILD_DIE as the last child of DIE. */
5762 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
5764 /* FIXME this should probably be an assert. */
5765 if (! die
|| ! child_die
)
5767 gcc_assert (die
!= child_die
);
5769 child_die
->die_parent
= die
;
5772 child_die
->die_sib
= die
->die_child
->die_sib
;
5773 die
->die_child
->die_sib
= child_die
;
5776 child_die
->die_sib
= child_die
;
5777 die
->die_child
= child_die
;
5780 /* Like add_child_die, but put CHILD_DIE after AFTER_DIE. */
5783 add_child_die_after (dw_die_ref die
, dw_die_ref child_die
,
5784 dw_die_ref after_die
)
5790 && die
!= child_die
);
5792 child_die
->die_parent
= die
;
5793 child_die
->die_sib
= after_die
->die_sib
;
5794 after_die
->die_sib
= child_die
;
5795 if (die
->die_child
== after_die
)
5796 die
->die_child
= child_die
;
5799 /* Unassociate CHILD from its parent, and make its parent be
5803 reparent_child (dw_die_ref child
, dw_die_ref new_parent
)
5805 for (dw_die_ref p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
5806 if (p
->die_sib
== child
)
5808 remove_child_with_prev (child
, p
);
5811 add_child_die (new_parent
, child
);
5814 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5815 is the specification, to the end of PARENT's list of children.
5816 This is done by removing and re-adding it. */
5819 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
5821 /* We want the declaration DIE from inside the class, not the
5822 specification DIE at toplevel. */
5823 if (child
->die_parent
!= parent
)
5825 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5831 gcc_assert (child
->die_parent
== parent
5832 || (child
->die_parent
5833 == get_AT_ref (parent
, DW_AT_specification
)));
5835 reparent_child (child
, parent
);
5838 /* Create and return a new die with TAG_VALUE as tag. */
5841 new_die_raw (enum dwarf_tag tag_value
)
5843 dw_die_ref die
= ggc_cleared_alloc
<die_node
> ();
5844 die
->die_tag
= tag_value
;
5848 /* Create and return a new die with a parent of PARENT_DIE. If
5849 PARENT_DIE is NULL, the new DIE is placed in limbo and an
5850 associated tree T must be supplied to determine parenthood
5853 static inline dw_die_ref
5854 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
5856 dw_die_ref die
= new_die_raw (tag_value
);
5858 if (parent_die
!= NULL
)
5859 add_child_die (parent_die
, die
);
5862 limbo_die_node
*limbo_node
;
5864 /* No DIEs created after early dwarf should end up in limbo,
5865 because the limbo list should not persist past LTO
5867 if (tag_value
!= DW_TAG_compile_unit
5868 /* These are allowed because they're generated while
5869 breaking out COMDAT units late. */
5870 && tag_value
!= DW_TAG_type_unit
5871 && tag_value
!= DW_TAG_skeleton_unit
5873 /* Allow nested functions to live in limbo because they will
5874 only temporarily live there, as decls_for_scope will fix
5876 && (TREE_CODE (t
) != FUNCTION_DECL
5877 || !decl_function_context (t
))
5878 /* Same as nested functions above but for types. Types that
5879 are local to a function will be fixed in
5881 && (!RECORD_OR_UNION_TYPE_P (t
)
5882 || !TYPE_CONTEXT (t
)
5883 || TREE_CODE (TYPE_CONTEXT (t
)) != FUNCTION_DECL
)
5884 /* FIXME debug-early: Allow late limbo DIE creation for LTO,
5885 especially in the ltrans stage, but once we implement LTO
5886 dwarf streaming, we should remove this exception. */
5889 fprintf (stderr
, "symbol ended up in limbo too late:");
5890 debug_generic_stmt (t
);
5894 limbo_node
= ggc_cleared_alloc
<limbo_die_node
> ();
5895 limbo_node
->die
= die
;
5896 limbo_node
->created_for
= t
;
5897 limbo_node
->next
= limbo_die_list
;
5898 limbo_die_list
= limbo_node
;
5904 /* Return the DIE associated with the given type specifier. */
5907 lookup_type_die (tree type
)
5909 dw_die_ref die
= TYPE_SYMTAB_DIE (type
);
5910 if (die
&& die
->removed
)
5912 TYPE_SYMTAB_DIE (type
) = NULL
;
5913 TREE_ASM_WRITTEN (type
) = 0;
5919 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
5920 anonymous type named by the typedef TYPE_DIE, return the DIE of the
5921 anonymous type instead the one of the naming typedef. */
5923 static inline dw_die_ref
5924 strip_naming_typedef (tree type
, dw_die_ref type_die
)
5927 && TREE_CODE (type
) == RECORD_TYPE
5929 && type_die
->die_tag
== DW_TAG_typedef
5930 && is_naming_typedef_decl (TYPE_NAME (type
)))
5931 type_die
= get_AT_ref (type_die
, DW_AT_type
);
5935 /* Like lookup_type_die, but if type is an anonymous type named by a
5936 typedef[1], return the DIE of the anonymous type instead the one of
5937 the naming typedef. This is because in gen_typedef_die, we did
5938 equate the anonymous struct named by the typedef with the DIE of
5939 the naming typedef. So by default, lookup_type_die on an anonymous
5940 struct yields the DIE of the naming typedef.
5942 [1]: Read the comment of is_naming_typedef_decl to learn about what
5943 a naming typedef is. */
5945 static inline dw_die_ref
5946 lookup_type_die_strip_naming_typedef (tree type
)
5948 dw_die_ref die
= lookup_type_die (type
);
5949 return strip_naming_typedef (type
, die
);
5952 /* Equate a DIE to a given type specifier. */
5955 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5957 TYPE_SYMTAB_DIE (type
) = type_die
;
5960 static dw_die_ref
maybe_create_die_with_external_ref (tree
);
5961 struct GTY(()) sym_off_pair
5963 const char * GTY((skip
)) sym
;
5964 unsigned HOST_WIDE_INT off
;
5966 static GTY(()) hash_map
<tree
, sym_off_pair
> *external_die_map
;
5968 /* Returns a hash value for X (which really is a die_struct). */
5971 decl_die_hasher::hash (die_node
*x
)
5973 return (hashval_t
) x
->decl_id
;
5976 /* Return true if decl_id of die_struct X is the same as UID of decl *Y. */
5979 decl_die_hasher::equal (die_node
*x
, tree y
)
5981 return (x
->decl_id
== DECL_UID (y
));
5984 /* Return the DIE associated with a given declaration. */
5987 lookup_decl_die (tree decl
)
5989 dw_die_ref
*die
= decl_die_table
->find_slot_with_hash (decl
, DECL_UID (decl
),
5994 return maybe_create_die_with_external_ref (decl
);
5997 if ((*die
)->removed
)
5999 decl_die_table
->clear_slot (die
);
6006 /* Return the DIE associated with BLOCK. */
6008 static inline dw_die_ref
6009 lookup_block_die (tree block
)
6011 dw_die_ref die
= BLOCK_DIE (block
);
6012 if (!die
&& in_lto_p
)
6013 return maybe_create_die_with_external_ref (block
);
6017 /* Associate DIE with BLOCK. */
6020 equate_block_to_die (tree block
, dw_die_ref die
)
6022 BLOCK_DIE (block
) = die
;
6027 /* For DECL which might have early dwarf output query a SYMBOL + OFFSET
6028 style reference. Return true if we found one refering to a DIE for
6029 DECL, otherwise return false. */
6032 dwarf2out_die_ref_for_decl (tree decl
, const char **sym
,
6033 unsigned HOST_WIDE_INT
*off
)
6039 /* During WPA stage and incremental linking we use a hash-map
6040 to store the decl <-> label + offset map. */
6041 if (!external_die_map
)
6043 sym_off_pair
*desc
= external_die_map
->get (decl
);
6051 if (TREE_CODE (decl
) == BLOCK
)
6052 die
= lookup_block_die (decl
);
6054 die
= lookup_decl_die (decl
);
6058 /* Similar to get_ref_die_offset_label, but using the "correct"
6060 *off
= die
->die_offset
;
6061 while (die
->die_parent
)
6062 die
= die
->die_parent
;
6063 /* For the containing CU DIE we compute a die_symbol in
6064 compute_comp_unit_symbol. */
6065 if (die
->die_tag
== DW_TAG_compile_unit
)
6067 gcc_assert (die
->die_id
.die_symbol
!= NULL
);
6068 *sym
= die
->die_id
.die_symbol
;
6071 /* While we can gracefully handle running into say a type unit
6072 we don't really want and consider this a bug. */
6078 /* Add a reference of kind ATTR_KIND to a DIE at SYMBOL + OFFSET to DIE. */
6081 add_AT_external_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
,
6082 const char *symbol
, HOST_WIDE_INT offset
)
6084 /* Create a fake DIE that contains the reference. Don't use
6085 new_die because we don't want to end up in the limbo list. */
6086 /* ??? We probably want to share these, thus put a ref to the DIE
6087 we create here to the external_die_map entry. */
6088 dw_die_ref ref
= new_die_raw (die
->die_tag
);
6089 ref
->die_id
.die_symbol
= symbol
;
6090 ref
->die_offset
= offset
;
6091 ref
->with_offset
= 1;
6092 add_AT_die_ref (die
, attr_kind
, ref
);
6095 /* Create a DIE for DECL if required and add a reference to a DIE
6096 at SYMBOL + OFFSET which contains attributes dumped early. */
6099 dwarf2out_register_external_die (tree decl
, const char *sym
,
6100 unsigned HOST_WIDE_INT off
)
6102 if (debug_info_level
== DINFO_LEVEL_NONE
)
6105 if (!external_die_map
)
6106 external_die_map
= hash_map
<tree
, sym_off_pair
>::create_ggc (1000);
6107 gcc_checking_assert (!external_die_map
->get (decl
));
6108 sym_off_pair p
= { IDENTIFIER_POINTER (get_identifier (sym
)), off
};
6109 external_die_map
->put (decl
, p
);
6112 /* If we have a registered external DIE for DECL return a new DIE for
6113 the concrete instance with an appropriate abstract origin. */
6116 maybe_create_die_with_external_ref (tree decl
)
6118 if (!external_die_map
)
6120 sym_off_pair
*desc
= external_die_map
->get (decl
);
6124 const char *sym
= desc
->sym
;
6125 unsigned HOST_WIDE_INT off
= desc
->off
;
6126 external_die_map
->remove (decl
);
6129 dw_die_ref die
= (TREE_CODE (decl
) == BLOCK
6130 ? lookup_block_die (decl
) : lookup_decl_die (decl
));
6135 dw_die_ref parent
= NULL
;
6136 /* Need to lookup a DIE for the decls context - the containing
6137 function or translation unit. */
6138 if (TREE_CODE (decl
) == BLOCK
)
6140 ctx
= BLOCK_SUPERCONTEXT (decl
);
6141 /* ??? We do not output DIEs for all scopes thus skip as
6142 many DIEs as needed. */
6143 while (TREE_CODE (ctx
) == BLOCK
6144 && !lookup_block_die (ctx
))
6145 ctx
= BLOCK_SUPERCONTEXT (ctx
);
6148 ctx
= DECL_CONTEXT (decl
);
6149 /* Peel types in the context stack. */
6150 while (ctx
&& TYPE_P (ctx
))
6151 ctx
= TYPE_CONTEXT (ctx
);
6152 /* Likewise namespaces in case we do not want to emit DIEs for them. */
6153 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
6154 while (ctx
&& TREE_CODE (ctx
) == NAMESPACE_DECL
)
6155 ctx
= DECL_CONTEXT (ctx
);
6158 if (TREE_CODE (ctx
) == BLOCK
)
6159 parent
= lookup_block_die (ctx
);
6160 else if (TREE_CODE (ctx
) == TRANSLATION_UNIT_DECL
6161 /* Keep the 1:1 association during WPA. */
6163 && flag_incremental_link
!= INCREMENTAL_LINK_LTO
)
6164 /* Otherwise all late annotations go to the main CU which
6165 imports the original CUs. */
6166 parent
= comp_unit_die ();
6167 else if (TREE_CODE (ctx
) == FUNCTION_DECL
6168 && TREE_CODE (decl
) != FUNCTION_DECL
6169 && TREE_CODE (decl
) != PARM_DECL
6170 && TREE_CODE (decl
) != RESULT_DECL
6171 && TREE_CODE (decl
) != BLOCK
)
6172 /* Leave function local entities parent determination to when
6173 we process scope vars. */
6176 parent
= lookup_decl_die (ctx
);
6179 /* In some cases the FEs fail to set DECL_CONTEXT properly.
6180 Handle this case gracefully by globalizing stuff. */
6181 parent
= comp_unit_die ();
6182 /* Create a DIE "stub". */
6183 switch (TREE_CODE (decl
))
6185 case TRANSLATION_UNIT_DECL
:
6187 die
= comp_unit_die ();
6188 /* We re-target all CU decls to the LTRANS CU DIE, so no need
6189 to create a DIE for the original CUs. */
6192 case NAMESPACE_DECL
:
6193 if (is_fortran (decl
))
6194 die
= new_die (DW_TAG_module
, parent
, decl
);
6196 die
= new_die (DW_TAG_namespace
, parent
, decl
);
6199 die
= new_die (DW_TAG_subprogram
, parent
, decl
);
6202 die
= new_die (DW_TAG_variable
, parent
, decl
);
6205 die
= new_die (DW_TAG_variable
, parent
, decl
);
6208 die
= new_die (DW_TAG_formal_parameter
, parent
, decl
);
6211 die
= new_die (DW_TAG_constant
, parent
, decl
);
6214 die
= new_die (DW_TAG_label
, parent
, decl
);
6217 die
= new_die (DW_TAG_lexical_block
, parent
, decl
);
6222 if (TREE_CODE (decl
) == BLOCK
)
6223 equate_block_to_die (decl
, die
);
6225 equate_decl_number_to_die (decl
, die
);
6227 add_desc_attribute (die
, decl
);
6229 /* Add a reference to the DIE providing early debug at $sym + off. */
6230 add_AT_external_die_ref (die
, DW_AT_abstract_origin
, sym
, off
);
6235 /* Returns a hash value for X (which really is a var_loc_list). */
6238 decl_loc_hasher::hash (var_loc_list
*x
)
6240 return (hashval_t
) x
->decl_id
;
6243 /* Return true if decl_id of var_loc_list X is the same as
6247 decl_loc_hasher::equal (var_loc_list
*x
, const_tree y
)
6249 return (x
->decl_id
== DECL_UID (y
));
6252 /* Return the var_loc list associated with a given declaration. */
6254 static inline var_loc_list
*
6255 lookup_decl_loc (const_tree decl
)
6257 if (!decl_loc_table
)
6259 return decl_loc_table
->find_with_hash (decl
, DECL_UID (decl
));
6262 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
6265 dw_loc_list_hasher::hash (cached_dw_loc_list
*x
)
6267 return (hashval_t
) x
->decl_id
;
6270 /* Return true if decl_id of cached_dw_loc_list X is the same as
6274 dw_loc_list_hasher::equal (cached_dw_loc_list
*x
, const_tree y
)
6276 return (x
->decl_id
== DECL_UID (y
));
6279 /* Equate a DIE to a particular declaration. */
6282 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
6284 unsigned int decl_id
= DECL_UID (decl
);
6286 *decl_die_table
->find_slot_with_hash (decl
, decl_id
, INSERT
) = decl_die
;
6287 decl_die
->decl_id
= decl_id
;
6290 /* Return how many bits covers PIECE EXPR_LIST. */
6292 static HOST_WIDE_INT
6293 decl_piece_bitsize (rtx piece
)
6295 int ret
= (int) GET_MODE (piece
);
6298 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
6299 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
6300 return INTVAL (XEXP (XEXP (piece
, 0), 0));
6303 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
6306 decl_piece_varloc_ptr (rtx piece
)
6308 if ((int) GET_MODE (piece
))
6309 return &XEXP (piece
, 0);
6311 return &XEXP (XEXP (piece
, 0), 1);
6314 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
6315 Next is the chain of following piece nodes. */
6317 static rtx_expr_list
*
6318 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
6320 if (bitsize
> 0 && bitsize
<= (int) MAX_MACHINE_MODE
)
6321 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
6323 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
6328 /* Return rtx that should be stored into loc field for
6329 LOC_NOTE and BITPOS/BITSIZE. */
6332 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
6333 HOST_WIDE_INT bitsize
)
6337 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
6339 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
6344 /* This function either modifies location piece list *DEST in
6345 place (if SRC and INNER is NULL), or copies location piece list
6346 *SRC to *DEST while modifying it. Location BITPOS is modified
6347 to contain LOC_NOTE, any pieces overlapping it are removed resp.
6348 not copied and if needed some padding around it is added.
6349 When modifying in place, DEST should point to EXPR_LIST where
6350 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
6351 to the start of the whole list and INNER points to the EXPR_LIST
6352 where earlier pieces cover PIECE_BITPOS bits. */
6355 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
6356 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
6357 HOST_WIDE_INT bitsize
, rtx loc_note
)
6360 bool copy
= inner
!= NULL
;
6364 /* First copy all nodes preceding the current bitpos. */
6365 while (src
!= inner
)
6367 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
6368 decl_piece_bitsize (*src
), NULL_RTX
);
6369 dest
= &XEXP (*dest
, 1);
6370 src
= &XEXP (*src
, 1);
6373 /* Add padding if needed. */
6374 if (bitpos
!= piece_bitpos
)
6376 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
6377 copy
? NULL_RTX
: *dest
);
6378 dest
= &XEXP (*dest
, 1);
6380 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
6383 /* A piece with correct bitpos and bitsize already exist,
6384 just update the location for it and return. */
6385 *decl_piece_varloc_ptr (*dest
) = loc_note
;
6388 /* Add the piece that changed. */
6389 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
6390 dest
= &XEXP (*dest
, 1);
6391 /* Skip over pieces that overlap it. */
6392 diff
= bitpos
- piece_bitpos
+ bitsize
;
6395 while (diff
> 0 && *src
)
6398 diff
-= decl_piece_bitsize (piece
);
6400 src
= &XEXP (piece
, 1);
6403 *src
= XEXP (piece
, 1);
6404 free_EXPR_LIST_node (piece
);
6407 /* Add padding if needed. */
6408 if (diff
< 0 && *src
)
6412 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
6413 dest
= &XEXP (*dest
, 1);
6417 /* Finally copy all nodes following it. */
6420 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
6421 decl_piece_bitsize (*src
), NULL_RTX
);
6422 dest
= &XEXP (*dest
, 1);
6423 src
= &XEXP (*src
, 1);
6427 /* Add a variable location node to the linked list for DECL. */
6429 static struct var_loc_node
*
6430 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
, var_loc_view view
)
6432 unsigned int decl_id
;
6434 struct var_loc_node
*loc
= NULL
;
6435 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
6437 if (VAR_P (decl
) && DECL_HAS_DEBUG_EXPR_P (decl
))
6439 tree realdecl
= DECL_DEBUG_EXPR (decl
);
6440 if (handled_component_p (realdecl
)
6441 || (TREE_CODE (realdecl
) == MEM_REF
6442 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
6445 tree innerdecl
= get_ref_base_and_extent_hwi (realdecl
, &bitpos
,
6446 &bitsize
, &reverse
);
6448 || !DECL_P (innerdecl
)
6449 || DECL_IGNORED_P (innerdecl
)
6450 || TREE_STATIC (innerdecl
)
6452 || bitpos
+ bitsize
> 256)
6458 decl_id
= DECL_UID (decl
);
6460 = decl_loc_table
->find_slot_with_hash (decl
, decl_id
, INSERT
);
6463 temp
= ggc_cleared_alloc
<var_loc_list
> ();
6464 temp
->decl_id
= decl_id
;
6470 /* For PARM_DECLs try to keep around the original incoming value,
6471 even if that means we'll emit a zero-range .debug_loc entry. */
6473 && temp
->first
== temp
->last
6474 && TREE_CODE (decl
) == PARM_DECL
6475 && NOTE_P (temp
->first
->loc
)
6476 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
6477 && DECL_INCOMING_RTL (decl
)
6478 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
6479 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
6480 == GET_CODE (DECL_INCOMING_RTL (decl
))
6481 && prev_real_insn (as_a
<rtx_insn
*> (temp
->first
->loc
)) == NULL_RTX
6483 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
6484 NOTE_VAR_LOCATION_LOC (loc_note
))
6485 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
6486 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
6488 loc
= ggc_cleared_alloc
<var_loc_node
> ();
6489 temp
->first
->next
= loc
;
6491 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
6493 else if (temp
->last
)
6495 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
6496 rtx
*piece_loc
= NULL
, last_loc_note
;
6497 HOST_WIDE_INT piece_bitpos
= 0;
6501 gcc_assert (last
->next
== NULL
);
6503 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
6505 piece_loc
= &last
->loc
;
6508 HOST_WIDE_INT cur_bitsize
= decl_piece_bitsize (*piece_loc
);
6509 if (piece_bitpos
+ cur_bitsize
> bitpos
)
6511 piece_bitpos
+= cur_bitsize
;
6512 piece_loc
= &XEXP (*piece_loc
, 1);
6516 /* TEMP->LAST here is either pointer to the last but one or
6517 last element in the chained list, LAST is pointer to the
6519 if (label
&& strcmp (last
->label
, label
) == 0 && last
->view
== view
)
6521 /* For SRA optimized variables if there weren't any real
6522 insns since last note, just modify the last node. */
6523 if (piece_loc
!= NULL
)
6525 adjust_piece_list (piece_loc
, NULL
, NULL
,
6526 bitpos
, piece_bitpos
, bitsize
, loc_note
);
6529 /* If the last note doesn't cover any instructions, remove it. */
6530 if (temp
->last
!= last
)
6532 temp
->last
->next
= NULL
;
6535 gcc_assert (strcmp (last
->label
, label
) != 0 || last
->view
!= view
);
6539 gcc_assert (temp
->first
== temp
->last
6540 || (temp
->first
->next
== temp
->last
6541 && TREE_CODE (decl
) == PARM_DECL
));
6542 memset (temp
->last
, '\0', sizeof (*temp
->last
));
6543 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
6547 if (bitsize
== -1 && NOTE_P (last
->loc
))
6548 last_loc_note
= last
->loc
;
6549 else if (piece_loc
!= NULL
6550 && *piece_loc
!= NULL_RTX
6551 && piece_bitpos
== bitpos
6552 && decl_piece_bitsize (*piece_loc
) == bitsize
)
6553 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
6555 last_loc_note
= NULL_RTX
;
6556 /* If the current location is the same as the end of the list,
6557 and either both or neither of the locations is uninitialized,
6558 we have nothing to do. */
6559 if (last_loc_note
== NULL_RTX
6560 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
6561 NOTE_VAR_LOCATION_LOC (loc_note
)))
6562 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
6563 != NOTE_VAR_LOCATION_STATUS (loc_note
))
6564 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
6565 == VAR_INIT_STATUS_UNINITIALIZED
)
6566 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
6567 == VAR_INIT_STATUS_UNINITIALIZED
))))
6569 /* Add LOC to the end of list and update LAST. If the last
6570 element of the list has been removed above, reuse its
6571 memory for the new node, otherwise allocate a new one. */
6575 memset (loc
, '\0', sizeof (*loc
));
6578 loc
= ggc_cleared_alloc
<var_loc_node
> ();
6579 if (bitsize
== -1 || piece_loc
== NULL
)
6580 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
6582 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
6583 bitpos
, piece_bitpos
, bitsize
, loc_note
);
6585 /* Ensure TEMP->LAST will point either to the new last but one
6586 element of the chain, or to the last element in it. */
6587 if (last
!= temp
->last
)
6595 loc
= ggc_cleared_alloc
<var_loc_node
> ();
6598 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
6603 /* Keep track of the number of spaces used to indent the
6604 output of the debugging routines that print the structure of
6605 the DIE internal representation. */
6606 static int print_indent
;
6608 /* Indent the line the number of spaces given by print_indent. */
6611 print_spaces (FILE *outfile
)
6613 fprintf (outfile
, "%*s", print_indent
, "");
6616 /* Print a type signature in hex. */
6619 print_signature (FILE *outfile
, char *sig
)
6623 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
6624 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
6628 print_discr_value (FILE *outfile
, dw_discr_value
*discr_value
)
6630 if (discr_value
->pos
)
6631 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, discr_value
->v
.sval
);
6633 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, discr_value
->v
.uval
);
6636 static void print_loc_descr (dw_loc_descr_ref
, FILE *);
6638 /* Print the value associated to the VAL DWARF value node to OUTFILE. If
6639 RECURSE, output location descriptor operations. */
6642 print_dw_val (dw_val_node
*val
, bool recurse
, FILE *outfile
)
6644 switch (val
->val_class
)
6646 case dw_val_class_addr
:
6647 fprintf (outfile
, "address");
6649 case dw_val_class_offset
:
6650 fprintf (outfile
, "offset");
6652 case dw_val_class_loc
:
6653 fprintf (outfile
, "location descriptor");
6654 if (val
->v
.val_loc
== NULL
)
6655 fprintf (outfile
, " -> <null>");
6658 fprintf (outfile
, ":\n");
6660 print_loc_descr (val
->v
.val_loc
, outfile
);
6665 if (flag_dump_noaddr
|| flag_dump_unnumbered
)
6666 fprintf (outfile
, " #");
6668 fprintf (outfile
, " (%p)", (void *) val
->v
.val_loc
);
6671 case dw_val_class_loc_list
:
6672 fprintf (outfile
, "location list -> label:%s",
6673 val
->v
.val_loc_list
->ll_symbol
);
6675 case dw_val_class_view_list
:
6676 val
= view_list_to_loc_list_val_node (val
);
6677 fprintf (outfile
, "location list with views -> labels:%s and %s",
6678 val
->v
.val_loc_list
->ll_symbol
,
6679 val
->v
.val_loc_list
->vl_symbol
);
6681 case dw_val_class_range_list
:
6682 fprintf (outfile
, "range list");
6684 case dw_val_class_const
:
6685 case dw_val_class_const_implicit
:
6686 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, val
->v
.val_int
);
6688 case dw_val_class_unsigned_const
:
6689 case dw_val_class_unsigned_const_implicit
:
6690 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, val
->v
.val_unsigned
);
6692 case dw_val_class_const_double
:
6693 fprintf (outfile
, "constant (" HOST_WIDE_INT_PRINT_DEC
","\
6694 HOST_WIDE_INT_PRINT_UNSIGNED
")",
6695 val
->v
.val_double
.high
,
6696 val
->v
.val_double
.low
);
6698 case dw_val_class_wide_int
:
6700 int i
= val
->v
.val_wide
->get_len ();
6701 fprintf (outfile
, "constant (");
6703 if (val
->v
.val_wide
->elt (i
- 1) == 0)
6704 fprintf (outfile
, "0x");
6705 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
,
6706 val
->v
.val_wide
->elt (--i
));
6708 fprintf (outfile
, HOST_WIDE_INT_PRINT_PADDED_HEX
,
6709 val
->v
.val_wide
->elt (i
));
6710 fprintf (outfile
, ")");
6713 case dw_val_class_vec
:
6714 fprintf (outfile
, "floating-point or vector constant");
6716 case dw_val_class_flag
:
6717 fprintf (outfile
, "%u", val
->v
.val_flag
);
6719 case dw_val_class_die_ref
:
6720 if (val
->v
.val_die_ref
.die
!= NULL
)
6722 dw_die_ref die
= val
->v
.val_die_ref
.die
;
6724 if (die
->comdat_type_p
)
6726 fprintf (outfile
, "die -> signature: ");
6727 print_signature (outfile
,
6728 die
->die_id
.die_type_node
->signature
);
6730 else if (die
->die_id
.die_symbol
)
6732 fprintf (outfile
, "die -> label: %s", die
->die_id
.die_symbol
);
6733 if (die
->with_offset
)
6734 fprintf (outfile
, " + %ld", die
->die_offset
);
6737 fprintf (outfile
, "die -> %ld", die
->die_offset
);
6738 if (flag_dump_noaddr
|| flag_dump_unnumbered
)
6739 fprintf (outfile
, " #");
6741 fprintf (outfile
, " (%p)", (void *) die
);
6744 fprintf (outfile
, "die -> <null>");
6746 case dw_val_class_vms_delta
:
6747 fprintf (outfile
, "delta: @slotcount(%s-%s)",
6748 val
->v
.val_vms_delta
.lbl2
, val
->v
.val_vms_delta
.lbl1
);
6750 case dw_val_class_symview
:
6751 fprintf (outfile
, "view: %s", val
->v
.val_symbolic_view
);
6753 case dw_val_class_lbl_id
:
6754 case dw_val_class_lineptr
:
6755 case dw_val_class_macptr
:
6756 case dw_val_class_loclistsptr
:
6757 case dw_val_class_high_pc
:
6758 fprintf (outfile
, "label: %s", val
->v
.val_lbl_id
);
6760 case dw_val_class_str
:
6761 if (val
->v
.val_str
->str
!= NULL
)
6762 fprintf (outfile
, "\"%s\"", val
->v
.val_str
->str
);
6764 fprintf (outfile
, "<null>");
6766 case dw_val_class_file
:
6767 case dw_val_class_file_implicit
:
6768 fprintf (outfile
, "\"%s\" (%d)", val
->v
.val_file
->filename
,
6769 val
->v
.val_file
->emitted_number
);
6771 case dw_val_class_data8
:
6775 for (i
= 0; i
< 8; i
++)
6776 fprintf (outfile
, "%02x", val
->v
.val_data8
[i
]);
6779 case dw_val_class_discr_value
:
6780 print_discr_value (outfile
, &val
->v
.val_discr_value
);
6782 case dw_val_class_discr_list
:
6783 for (dw_discr_list_ref node
= val
->v
.val_discr_list
;
6785 node
= node
->dw_discr_next
)
6787 if (node
->dw_discr_range
)
6789 fprintf (outfile
, " .. ");
6790 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
6791 print_discr_value (outfile
, &node
->dw_discr_upper_bound
);
6794 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
6796 if (node
->dw_discr_next
!= NULL
)
6797 fprintf (outfile
, " | ");
6804 /* Likewise, for a DIE attribute. */
6807 print_attribute (dw_attr_node
*a
, bool recurse
, FILE *outfile
)
6809 print_dw_val (&a
->dw_attr_val
, recurse
, outfile
);
6813 /* Print the list of operands in the LOC location description to OUTFILE. This
6814 routine is a debugging aid only. */
6817 print_loc_descr (dw_loc_descr_ref loc
, FILE *outfile
)
6819 dw_loc_descr_ref l
= loc
;
6823 print_spaces (outfile
);
6824 fprintf (outfile
, "<null>\n");
6828 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
6830 print_spaces (outfile
);
6831 if (flag_dump_noaddr
|| flag_dump_unnumbered
)
6832 fprintf (outfile
, "#");
6834 fprintf (outfile
, "(%p)", (void *) l
);
6835 fprintf (outfile
, " %s",
6836 dwarf_stack_op_name (l
->dw_loc_opc
));
6837 if (l
->dw_loc_oprnd1
.val_class
!= dw_val_class_none
)
6839 fprintf (outfile
, " ");
6840 print_dw_val (&l
->dw_loc_oprnd1
, false, outfile
);
6842 if (l
->dw_loc_oprnd2
.val_class
!= dw_val_class_none
)
6844 fprintf (outfile
, ", ");
6845 print_dw_val (&l
->dw_loc_oprnd2
, false, outfile
);
6847 fprintf (outfile
, "\n");
6851 /* Print the information associated with a given DIE, and its children.
6852 This routine is a debugging aid only. */
6855 print_die (dw_die_ref die
, FILE *outfile
)
6861 print_spaces (outfile
);
6862 fprintf (outfile
, "DIE %4ld: %s ",
6863 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
6864 if (flag_dump_noaddr
|| flag_dump_unnumbered
)
6865 fprintf (outfile
, "#\n");
6867 fprintf (outfile
, "(%p)\n", (void*) die
);
6868 print_spaces (outfile
);
6869 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
6870 fprintf (outfile
, " offset: %ld", die
->die_offset
);
6871 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
6873 if (die
->comdat_type_p
)
6875 print_spaces (outfile
);
6876 fprintf (outfile
, " signature: ");
6877 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
6878 fprintf (outfile
, "\n");
6881 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6883 print_spaces (outfile
);
6884 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
6886 print_attribute (a
, true, outfile
);
6887 fprintf (outfile
, "\n");
6890 if (die
->die_child
!= NULL
)
6893 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
6896 if (print_indent
== 0)
6897 fprintf (outfile
, "\n");
6900 /* Print the list of operations in the LOC location description. */
6903 debug_dwarf_loc_descr (dw_loc_descr_ref loc
)
6905 print_loc_descr (loc
, stderr
);
6908 /* Print the information collected for a given DIE. */
6911 debug_dwarf_die (dw_die_ref die
)
6913 print_die (die
, stderr
);
6917 debug (die_struct
&ref
)
6919 print_die (&ref
, stderr
);
6923 debug (die_struct
*ptr
)
6928 fprintf (stderr
, "<nil>\n");
6932 /* Print all DWARF information collected for the compilation unit.
6933 This routine is a debugging aid only. */
6939 print_die (comp_unit_die (), stderr
);
6942 /* Verify the DIE tree structure. */
6945 verify_die (dw_die_ref die
)
6947 gcc_assert (!die
->die_mark
);
6948 if (die
->die_parent
== NULL
6949 && die
->die_sib
== NULL
)
6951 /* Verify the die_sib list is cyclic. */
6958 while (x
&& !x
->die_mark
);
6959 gcc_assert (x
== die
);
6963 /* Verify all dies have the same parent. */
6964 gcc_assert (x
->die_parent
== die
->die_parent
);
6967 /* Verify the child has the proper parent and recurse. */
6968 gcc_assert (x
->die_child
->die_parent
== x
);
6969 verify_die (x
->die_child
);
6974 while (x
&& x
->die_mark
);
6977 /* Sanity checks on DIEs. */
6980 check_die (dw_die_ref die
)
6984 bool inline_found
= false;
6985 int n_location
= 0, n_low_pc
= 0, n_high_pc
= 0, n_artificial
= 0;
6986 int n_decl_line
= 0, n_decl_column
= 0, n_decl_file
= 0;
6987 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6992 if (a
->dw_attr_val
.v
.val_unsigned
)
6993 inline_found
= true;
6995 case DW_AT_location
:
7004 case DW_AT_artificial
:
7007 case DW_AT_decl_column
:
7010 case DW_AT_decl_line
:
7013 case DW_AT_decl_file
:
7020 if (n_location
> 1 || n_low_pc
> 1 || n_high_pc
> 1 || n_artificial
> 1
7021 || n_decl_column
> 1 || n_decl_line
> 1 || n_decl_file
> 1)
7023 fprintf (stderr
, "Duplicate attributes in DIE:\n");
7024 debug_dwarf_die (die
);
7029 /* A debugging information entry that is a member of an abstract
7030 instance tree [that has DW_AT_inline] should not contain any
7031 attributes which describe aspects of the subroutine which vary
7032 between distinct inlined expansions or distinct out-of-line
7034 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7035 gcc_assert (a
->dw_attr
!= DW_AT_low_pc
7036 && a
->dw_attr
!= DW_AT_high_pc
7037 && a
->dw_attr
!= DW_AT_location
7038 && a
->dw_attr
!= DW_AT_frame_base
7039 && a
->dw_attr
!= DW_AT_call_all_calls
7040 && a
->dw_attr
!= DW_AT_GNU_all_call_sites
);
7044 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
7045 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
7046 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
7048 /* Calculate the checksum of a location expression. */
7051 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
7054 inchash::hash hstate
;
7057 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
7059 hash_loc_operands (loc
, hstate
);
7060 hash
= hstate
.end();
7064 /* Calculate the checksum of an attribute. */
7067 attr_checksum (dw_attr_node
*at
, struct md5_ctx
*ctx
, int *mark
)
7069 dw_loc_descr_ref loc
;
7072 CHECKSUM (at
->dw_attr
);
7074 /* We don't care that this was compiled with a different compiler
7075 snapshot; if the output is the same, that's what matters. */
7076 if (at
->dw_attr
== DW_AT_producer
)
7079 switch (AT_class (at
))
7081 case dw_val_class_const
:
7082 case dw_val_class_const_implicit
:
7083 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
7085 case dw_val_class_unsigned_const
:
7086 case dw_val_class_unsigned_const_implicit
:
7087 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
7089 case dw_val_class_const_double
:
7090 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
7092 case dw_val_class_wide_int
:
7093 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
7094 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
7095 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
7097 case dw_val_class_vec
:
7098 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
7099 (at
->dw_attr_val
.v
.val_vec
.length
7100 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
7102 case dw_val_class_flag
:
7103 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
7105 case dw_val_class_str
:
7106 CHECKSUM_STRING (AT_string (at
));
7109 case dw_val_class_addr
:
7111 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
7112 CHECKSUM_STRING (XSTR (r
, 0));
7115 case dw_val_class_offset
:
7116 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
7119 case dw_val_class_loc
:
7120 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
7121 loc_checksum (loc
, ctx
);
7124 case dw_val_class_die_ref
:
7125 die_checksum (AT_ref (at
), ctx
, mark
);
7128 case dw_val_class_fde_ref
:
7129 case dw_val_class_vms_delta
:
7130 case dw_val_class_symview
:
7131 case dw_val_class_lbl_id
:
7132 case dw_val_class_lineptr
:
7133 case dw_val_class_macptr
:
7134 case dw_val_class_loclistsptr
:
7135 case dw_val_class_high_pc
:
7138 case dw_val_class_file
:
7139 case dw_val_class_file_implicit
:
7140 CHECKSUM_STRING (AT_file (at
)->filename
);
7143 case dw_val_class_data8
:
7144 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
7152 /* Calculate the checksum of a DIE. */
7155 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
7161 /* To avoid infinite recursion. */
7164 CHECKSUM (die
->die_mark
);
7167 die
->die_mark
= ++(*mark
);
7169 CHECKSUM (die
->die_tag
);
7171 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7172 attr_checksum (a
, ctx
, mark
);
7174 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
7178 #undef CHECKSUM_BLOCK
7179 #undef CHECKSUM_STRING
7181 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
7182 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
7183 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
7184 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
7185 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
7186 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
7187 #define CHECKSUM_ATTR(FOO) \
7188 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
7190 /* Calculate the checksum of a number in signed LEB128 format. */
7193 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
7200 byte
= (value
& 0x7f);
7202 more
= !((value
== 0 && (byte
& 0x40) == 0)
7203 || (value
== -1 && (byte
& 0x40) != 0));
7212 /* Calculate the checksum of a number in unsigned LEB128 format. */
7215 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
7219 unsigned char byte
= (value
& 0x7f);
7222 /* More bytes to follow. */
7230 /* Checksum the context of the DIE. This adds the names of any
7231 surrounding namespaces or structures to the checksum. */
7234 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
7238 int tag
= die
->die_tag
;
7240 if (tag
!= DW_TAG_namespace
7241 && tag
!= DW_TAG_structure_type
7242 && tag
!= DW_TAG_class_type
)
7245 name
= get_AT_string (die
, DW_AT_name
);
7247 spec
= get_AT_ref (die
, DW_AT_specification
);
7251 if (die
->die_parent
!= NULL
)
7252 checksum_die_context (die
->die_parent
, ctx
);
7254 CHECKSUM_ULEB128 ('C');
7255 CHECKSUM_ULEB128 (tag
);
7257 CHECKSUM_STRING (name
);
7260 /* Calculate the checksum of a location expression. */
7263 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
7265 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
7266 were emitted as a DW_FORM_sdata instead of a location expression. */
7267 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
7269 CHECKSUM_ULEB128 (DW_FORM_sdata
);
7270 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
7274 /* Otherwise, just checksum the raw location expression. */
7277 inchash::hash hstate
;
7280 CHECKSUM_ULEB128 (loc
->dtprel
);
7281 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
7282 hash_loc_operands (loc
, hstate
);
7283 hash
= hstate
.end ();
7285 loc
= loc
->dw_loc_next
;
7289 /* Calculate the checksum of an attribute. */
7292 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_node
*at
,
7293 struct md5_ctx
*ctx
, int *mark
)
7295 dw_loc_descr_ref loc
;
7298 if (AT_class (at
) == dw_val_class_die_ref
)
7300 dw_die_ref target_die
= AT_ref (at
);
7302 /* For pointer and reference types, we checksum only the (qualified)
7303 name of the target type (if there is a name). For friend entries,
7304 we checksum only the (qualified) name of the target type or function.
7305 This allows the checksum to remain the same whether the target type
7306 is complete or not. */
7307 if ((at
->dw_attr
== DW_AT_type
7308 && (tag
== DW_TAG_pointer_type
7309 || tag
== DW_TAG_reference_type
7310 || tag
== DW_TAG_rvalue_reference_type
7311 || tag
== DW_TAG_ptr_to_member_type
))
7312 || (at
->dw_attr
== DW_AT_friend
7313 && tag
== DW_TAG_friend
))
7315 dw_attr_node
*name_attr
= get_AT (target_die
, DW_AT_name
);
7317 if (name_attr
!= NULL
)
7319 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
7323 CHECKSUM_ULEB128 ('N');
7324 CHECKSUM_ULEB128 (at
->dw_attr
);
7325 if (decl
->die_parent
!= NULL
)
7326 checksum_die_context (decl
->die_parent
, ctx
);
7327 CHECKSUM_ULEB128 ('E');
7328 CHECKSUM_STRING (AT_string (name_attr
));
7333 /* For all other references to another DIE, we check to see if the
7334 target DIE has already been visited. If it has, we emit a
7335 backward reference; if not, we descend recursively. */
7336 if (target_die
->die_mark
> 0)
7338 CHECKSUM_ULEB128 ('R');
7339 CHECKSUM_ULEB128 (at
->dw_attr
);
7340 CHECKSUM_ULEB128 (target_die
->die_mark
);
7344 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
7348 target_die
->die_mark
= ++(*mark
);
7349 CHECKSUM_ULEB128 ('T');
7350 CHECKSUM_ULEB128 (at
->dw_attr
);
7351 if (decl
->die_parent
!= NULL
)
7352 checksum_die_context (decl
->die_parent
, ctx
);
7353 die_checksum_ordered (target_die
, ctx
, mark
);
7358 CHECKSUM_ULEB128 ('A');
7359 CHECKSUM_ULEB128 (at
->dw_attr
);
7361 switch (AT_class (at
))
7363 case dw_val_class_const
:
7364 case dw_val_class_const_implicit
:
7365 CHECKSUM_ULEB128 (DW_FORM_sdata
);
7366 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
7369 case dw_val_class_unsigned_const
:
7370 case dw_val_class_unsigned_const_implicit
:
7371 CHECKSUM_ULEB128 (DW_FORM_sdata
);
7372 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
7375 case dw_val_class_const_double
:
7376 CHECKSUM_ULEB128 (DW_FORM_block
);
7377 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
7378 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
7381 case dw_val_class_wide_int
:
7382 CHECKSUM_ULEB128 (DW_FORM_block
);
7383 CHECKSUM_ULEB128 (get_full_len (*at
->dw_attr_val
.v
.val_wide
)
7384 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
7385 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
7386 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
7387 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
7390 case dw_val_class_vec
:
7391 CHECKSUM_ULEB128 (DW_FORM_block
);
7392 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
7393 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
7394 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
7395 (at
->dw_attr_val
.v
.val_vec
.length
7396 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
7399 case dw_val_class_flag
:
7400 CHECKSUM_ULEB128 (DW_FORM_flag
);
7401 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
7404 case dw_val_class_str
:
7405 CHECKSUM_ULEB128 (DW_FORM_string
);
7406 CHECKSUM_STRING (AT_string (at
));
7409 case dw_val_class_addr
:
7411 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
7412 CHECKSUM_ULEB128 (DW_FORM_string
);
7413 CHECKSUM_STRING (XSTR (r
, 0));
7416 case dw_val_class_offset
:
7417 CHECKSUM_ULEB128 (DW_FORM_sdata
);
7418 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
7421 case dw_val_class_loc
:
7422 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
7423 loc_checksum_ordered (loc
, ctx
);
7426 case dw_val_class_fde_ref
:
7427 case dw_val_class_symview
:
7428 case dw_val_class_lbl_id
:
7429 case dw_val_class_lineptr
:
7430 case dw_val_class_macptr
:
7431 case dw_val_class_loclistsptr
:
7432 case dw_val_class_high_pc
:
7435 case dw_val_class_file
:
7436 case dw_val_class_file_implicit
:
7437 CHECKSUM_ULEB128 (DW_FORM_string
);
7438 CHECKSUM_STRING (AT_file (at
)->filename
);
7441 case dw_val_class_data8
:
7442 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
7450 struct checksum_attributes
7452 dw_attr_node
*at_name
;
7453 dw_attr_node
*at_type
;
7454 dw_attr_node
*at_friend
;
7455 dw_attr_node
*at_accessibility
;
7456 dw_attr_node
*at_address_class
;
7457 dw_attr_node
*at_alignment
;
7458 dw_attr_node
*at_allocated
;
7459 dw_attr_node
*at_artificial
;
7460 dw_attr_node
*at_associated
;
7461 dw_attr_node
*at_binary_scale
;
7462 dw_attr_node
*at_bit_offset
;
7463 dw_attr_node
*at_bit_size
;
7464 dw_attr_node
*at_bit_stride
;
7465 dw_attr_node
*at_byte_size
;
7466 dw_attr_node
*at_byte_stride
;
7467 dw_attr_node
*at_const_value
;
7468 dw_attr_node
*at_containing_type
;
7469 dw_attr_node
*at_count
;
7470 dw_attr_node
*at_data_location
;
7471 dw_attr_node
*at_data_member_location
;
7472 dw_attr_node
*at_decimal_scale
;
7473 dw_attr_node
*at_decimal_sign
;
7474 dw_attr_node
*at_default_value
;
7475 dw_attr_node
*at_digit_count
;
7476 dw_attr_node
*at_discr
;
7477 dw_attr_node
*at_discr_list
;
7478 dw_attr_node
*at_discr_value
;
7479 dw_attr_node
*at_encoding
;
7480 dw_attr_node
*at_endianity
;
7481 dw_attr_node
*at_explicit
;
7482 dw_attr_node
*at_is_optional
;
7483 dw_attr_node
*at_location
;
7484 dw_attr_node
*at_lower_bound
;
7485 dw_attr_node
*at_mutable
;
7486 dw_attr_node
*at_ordering
;
7487 dw_attr_node
*at_picture_string
;
7488 dw_attr_node
*at_prototyped
;
7489 dw_attr_node
*at_small
;
7490 dw_attr_node
*at_segment
;
7491 dw_attr_node
*at_string_length
;
7492 dw_attr_node
*at_string_length_bit_size
;
7493 dw_attr_node
*at_string_length_byte_size
;
7494 dw_attr_node
*at_threads_scaled
;
7495 dw_attr_node
*at_upper_bound
;
7496 dw_attr_node
*at_use_location
;
7497 dw_attr_node
*at_use_UTF8
;
7498 dw_attr_node
*at_variable_parameter
;
7499 dw_attr_node
*at_virtuality
;
7500 dw_attr_node
*at_visibility
;
7501 dw_attr_node
*at_vtable_elem_location
;
7504 /* Collect the attributes that we will want to use for the checksum. */
7507 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
7512 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7523 attrs
->at_friend
= a
;
7525 case DW_AT_accessibility
:
7526 attrs
->at_accessibility
= a
;
7528 case DW_AT_address_class
:
7529 attrs
->at_address_class
= a
;
7531 case DW_AT_alignment
:
7532 attrs
->at_alignment
= a
;
7534 case DW_AT_allocated
:
7535 attrs
->at_allocated
= a
;
7537 case DW_AT_artificial
:
7538 attrs
->at_artificial
= a
;
7540 case DW_AT_associated
:
7541 attrs
->at_associated
= a
;
7543 case DW_AT_binary_scale
:
7544 attrs
->at_binary_scale
= a
;
7546 case DW_AT_bit_offset
:
7547 attrs
->at_bit_offset
= a
;
7549 case DW_AT_bit_size
:
7550 attrs
->at_bit_size
= a
;
7552 case DW_AT_bit_stride
:
7553 attrs
->at_bit_stride
= a
;
7555 case DW_AT_byte_size
:
7556 attrs
->at_byte_size
= a
;
7558 case DW_AT_byte_stride
:
7559 attrs
->at_byte_stride
= a
;
7561 case DW_AT_const_value
:
7562 attrs
->at_const_value
= a
;
7564 case DW_AT_containing_type
:
7565 attrs
->at_containing_type
= a
;
7568 attrs
->at_count
= a
;
7570 case DW_AT_data_location
:
7571 attrs
->at_data_location
= a
;
7573 case DW_AT_data_member_location
:
7574 attrs
->at_data_member_location
= a
;
7576 case DW_AT_decimal_scale
:
7577 attrs
->at_decimal_scale
= a
;
7579 case DW_AT_decimal_sign
:
7580 attrs
->at_decimal_sign
= a
;
7582 case DW_AT_default_value
:
7583 attrs
->at_default_value
= a
;
7585 case DW_AT_digit_count
:
7586 attrs
->at_digit_count
= a
;
7589 attrs
->at_discr
= a
;
7591 case DW_AT_discr_list
:
7592 attrs
->at_discr_list
= a
;
7594 case DW_AT_discr_value
:
7595 attrs
->at_discr_value
= a
;
7597 case DW_AT_encoding
:
7598 attrs
->at_encoding
= a
;
7600 case DW_AT_endianity
:
7601 attrs
->at_endianity
= a
;
7603 case DW_AT_explicit
:
7604 attrs
->at_explicit
= a
;
7606 case DW_AT_is_optional
:
7607 attrs
->at_is_optional
= a
;
7609 case DW_AT_location
:
7610 attrs
->at_location
= a
;
7612 case DW_AT_lower_bound
:
7613 attrs
->at_lower_bound
= a
;
7616 attrs
->at_mutable
= a
;
7618 case DW_AT_ordering
:
7619 attrs
->at_ordering
= a
;
7621 case DW_AT_picture_string
:
7622 attrs
->at_picture_string
= a
;
7624 case DW_AT_prototyped
:
7625 attrs
->at_prototyped
= a
;
7628 attrs
->at_small
= a
;
7631 attrs
->at_segment
= a
;
7633 case DW_AT_string_length
:
7634 attrs
->at_string_length
= a
;
7636 case DW_AT_string_length_bit_size
:
7637 attrs
->at_string_length_bit_size
= a
;
7639 case DW_AT_string_length_byte_size
:
7640 attrs
->at_string_length_byte_size
= a
;
7642 case DW_AT_threads_scaled
:
7643 attrs
->at_threads_scaled
= a
;
7645 case DW_AT_upper_bound
:
7646 attrs
->at_upper_bound
= a
;
7648 case DW_AT_use_location
:
7649 attrs
->at_use_location
= a
;
7651 case DW_AT_use_UTF8
:
7652 attrs
->at_use_UTF8
= a
;
7654 case DW_AT_variable_parameter
:
7655 attrs
->at_variable_parameter
= a
;
7657 case DW_AT_virtuality
:
7658 attrs
->at_virtuality
= a
;
7660 case DW_AT_visibility
:
7661 attrs
->at_visibility
= a
;
7663 case DW_AT_vtable_elem_location
:
7664 attrs
->at_vtable_elem_location
= a
;
7672 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
7675 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
7679 struct checksum_attributes attrs
;
7681 CHECKSUM_ULEB128 ('D');
7682 CHECKSUM_ULEB128 (die
->die_tag
);
7684 memset (&attrs
, 0, sizeof (attrs
));
7686 decl
= get_AT_ref (die
, DW_AT_specification
);
7688 collect_checksum_attributes (&attrs
, decl
);
7689 collect_checksum_attributes (&attrs
, die
);
7691 CHECKSUM_ATTR (attrs
.at_name
);
7692 CHECKSUM_ATTR (attrs
.at_accessibility
);
7693 CHECKSUM_ATTR (attrs
.at_address_class
);
7694 CHECKSUM_ATTR (attrs
.at_allocated
);
7695 CHECKSUM_ATTR (attrs
.at_artificial
);
7696 CHECKSUM_ATTR (attrs
.at_associated
);
7697 CHECKSUM_ATTR (attrs
.at_binary_scale
);
7698 CHECKSUM_ATTR (attrs
.at_bit_offset
);
7699 CHECKSUM_ATTR (attrs
.at_bit_size
);
7700 CHECKSUM_ATTR (attrs
.at_bit_stride
);
7701 CHECKSUM_ATTR (attrs
.at_byte_size
);
7702 CHECKSUM_ATTR (attrs
.at_byte_stride
);
7703 CHECKSUM_ATTR (attrs
.at_const_value
);
7704 CHECKSUM_ATTR (attrs
.at_containing_type
);
7705 CHECKSUM_ATTR (attrs
.at_count
);
7706 CHECKSUM_ATTR (attrs
.at_data_location
);
7707 CHECKSUM_ATTR (attrs
.at_data_member_location
);
7708 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
7709 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
7710 CHECKSUM_ATTR (attrs
.at_default_value
);
7711 CHECKSUM_ATTR (attrs
.at_digit_count
);
7712 CHECKSUM_ATTR (attrs
.at_discr
);
7713 CHECKSUM_ATTR (attrs
.at_discr_list
);
7714 CHECKSUM_ATTR (attrs
.at_discr_value
);
7715 CHECKSUM_ATTR (attrs
.at_encoding
);
7716 CHECKSUM_ATTR (attrs
.at_endianity
);
7717 CHECKSUM_ATTR (attrs
.at_explicit
);
7718 CHECKSUM_ATTR (attrs
.at_is_optional
);
7719 CHECKSUM_ATTR (attrs
.at_location
);
7720 CHECKSUM_ATTR (attrs
.at_lower_bound
);
7721 CHECKSUM_ATTR (attrs
.at_mutable
);
7722 CHECKSUM_ATTR (attrs
.at_ordering
);
7723 CHECKSUM_ATTR (attrs
.at_picture_string
);
7724 CHECKSUM_ATTR (attrs
.at_prototyped
);
7725 CHECKSUM_ATTR (attrs
.at_small
);
7726 CHECKSUM_ATTR (attrs
.at_segment
);
7727 CHECKSUM_ATTR (attrs
.at_string_length
);
7728 CHECKSUM_ATTR (attrs
.at_string_length_bit_size
);
7729 CHECKSUM_ATTR (attrs
.at_string_length_byte_size
);
7730 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
7731 CHECKSUM_ATTR (attrs
.at_upper_bound
);
7732 CHECKSUM_ATTR (attrs
.at_use_location
);
7733 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
7734 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
7735 CHECKSUM_ATTR (attrs
.at_virtuality
);
7736 CHECKSUM_ATTR (attrs
.at_visibility
);
7737 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
7738 CHECKSUM_ATTR (attrs
.at_type
);
7739 CHECKSUM_ATTR (attrs
.at_friend
);
7740 CHECKSUM_ATTR (attrs
.at_alignment
);
7742 /* Checksum the child DIEs. */
7745 dw_attr_node
*name_attr
;
7748 name_attr
= get_AT (c
, DW_AT_name
);
7749 if (is_template_instantiation (c
))
7751 /* Ignore instantiations of member type and function templates. */
7753 else if (name_attr
!= NULL
7754 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
7756 /* Use a shallow checksum for named nested types and member
7758 CHECKSUM_ULEB128 ('S');
7759 CHECKSUM_ULEB128 (c
->die_tag
);
7760 CHECKSUM_STRING (AT_string (name_attr
));
7764 /* Use a deep checksum for other children. */
7765 /* Mark this DIE so it gets processed when unmarking. */
7766 if (c
->die_mark
== 0)
7768 die_checksum_ordered (c
, ctx
, mark
);
7770 } while (c
!= die
->die_child
);
7772 CHECKSUM_ULEB128 (0);
7775 /* Add a type name and tag to a hash. */
7777 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
7779 CHECKSUM_ULEB128 (tag
);
7780 CHECKSUM_STRING (name
);
7784 #undef CHECKSUM_STRING
7785 #undef CHECKSUM_ATTR
7786 #undef CHECKSUM_LEB128
7787 #undef CHECKSUM_ULEB128
7789 /* Generate the type signature for DIE. This is computed by generating an
7790 MD5 checksum over the DIE's tag, its relevant attributes, and its
7791 children. Attributes that are references to other DIEs are processed
7792 by recursion, using the MARK field to prevent infinite recursion.
7793 If the DIE is nested inside a namespace or another type, we also
7794 need to include that context in the signature. The lower 64 bits
7795 of the resulting MD5 checksum comprise the signature. */
7798 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
7802 unsigned char checksum
[16];
7807 name
= get_AT_string (die
, DW_AT_name
);
7808 decl
= get_AT_ref (die
, DW_AT_specification
);
7809 parent
= get_die_parent (die
);
7811 /* First, compute a signature for just the type name (and its surrounding
7812 context, if any. This is stored in the type unit DIE for link-time
7813 ODR (one-definition rule) checking. */
7815 if (is_cxx () && name
!= NULL
)
7817 md5_init_ctx (&ctx
);
7819 /* Checksum the names of surrounding namespaces and structures. */
7821 checksum_die_context (parent
, &ctx
);
7823 /* Checksum the current DIE. */
7824 die_odr_checksum (die
->die_tag
, name
, &ctx
);
7825 md5_finish_ctx (&ctx
, checksum
);
7827 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
7830 /* Next, compute the complete type signature. */
7832 md5_init_ctx (&ctx
);
7834 die
->die_mark
= mark
;
7836 /* Checksum the names of surrounding namespaces and structures. */
7838 checksum_die_context (parent
, &ctx
);
7840 /* Checksum the DIE and its children. */
7841 die_checksum_ordered (die
, &ctx
, &mark
);
7842 unmark_all_dies (die
);
7843 md5_finish_ctx (&ctx
, checksum
);
7845 /* Store the signature in the type node and link the type DIE and the
7846 type node together. */
7847 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
7848 DWARF_TYPE_SIGNATURE_SIZE
);
7849 die
->comdat_type_p
= true;
7850 die
->die_id
.die_type_node
= type_node
;
7851 type_node
->type_die
= die
;
7853 /* If the DIE is a specification, link its declaration to the type node
7857 decl
->comdat_type_p
= true;
7858 decl
->die_id
.die_type_node
= type_node
;
7862 /* Do the location expressions look same? */
7864 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
7866 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
7867 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
7868 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
7871 /* Do the values look the same? */
7873 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
7875 dw_loc_descr_ref loc1
, loc2
;
7878 if (v1
->val_class
!= v2
->val_class
)
7881 switch (v1
->val_class
)
7883 case dw_val_class_const
:
7884 case dw_val_class_const_implicit
:
7885 return v1
->v
.val_int
== v2
->v
.val_int
;
7886 case dw_val_class_unsigned_const
:
7887 case dw_val_class_unsigned_const_implicit
:
7888 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
7889 case dw_val_class_const_double
:
7890 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
7891 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
7892 case dw_val_class_wide_int
:
7893 return *v1
->v
.val_wide
== *v2
->v
.val_wide
;
7894 case dw_val_class_vec
:
7895 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
7896 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
7898 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
7899 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
7902 case dw_val_class_flag
:
7903 return v1
->v
.val_flag
== v2
->v
.val_flag
;
7904 case dw_val_class_str
:
7905 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
7907 case dw_val_class_addr
:
7908 r1
= v1
->v
.val_addr
;
7909 r2
= v2
->v
.val_addr
;
7910 if (GET_CODE (r1
) != GET_CODE (r2
))
7912 return !rtx_equal_p (r1
, r2
);
7914 case dw_val_class_offset
:
7915 return v1
->v
.val_offset
== v2
->v
.val_offset
;
7917 case dw_val_class_loc
:
7918 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
7920 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
7921 if (!same_loc_p (loc1
, loc2
, mark
))
7923 return !loc1
&& !loc2
;
7925 case dw_val_class_die_ref
:
7926 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
7928 case dw_val_class_symview
:
7929 return strcmp (v1
->v
.val_symbolic_view
, v2
->v
.val_symbolic_view
) == 0;
7931 case dw_val_class_fde_ref
:
7932 case dw_val_class_vms_delta
:
7933 case dw_val_class_lbl_id
:
7934 case dw_val_class_lineptr
:
7935 case dw_val_class_macptr
:
7936 case dw_val_class_loclistsptr
:
7937 case dw_val_class_high_pc
:
7940 case dw_val_class_file
:
7941 case dw_val_class_file_implicit
:
7942 return v1
->v
.val_file
== v2
->v
.val_file
;
7944 case dw_val_class_data8
:
7945 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
7952 /* Do the attributes look the same? */
7955 same_attr_p (dw_attr_node
*at1
, dw_attr_node
*at2
, int *mark
)
7957 if (at1
->dw_attr
!= at2
->dw_attr
)
7960 /* We don't care that this was compiled with a different compiler
7961 snapshot; if the output is the same, that's what matters. */
7962 if (at1
->dw_attr
== DW_AT_producer
)
7965 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
7968 /* Do the dies look the same? */
7971 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
7977 /* To avoid infinite recursion. */
7979 return die1
->die_mark
== die2
->die_mark
;
7980 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
7982 if (die1
->die_tag
!= die2
->die_tag
)
7985 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
7988 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
7989 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
7992 c1
= die1
->die_child
;
7993 c2
= die2
->die_child
;
8002 if (!same_die_p (c1
, c2
, mark
))
8006 if (c1
== die1
->die_child
)
8008 if (c2
== die2
->die_child
)
8018 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
8019 children, and set die_symbol. */
8022 compute_comp_unit_symbol (dw_die_ref unit_die
)
8024 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
8025 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
8026 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
8029 unsigned char checksum
[16];
8032 /* Compute the checksum of the DIE, then append part of it as hex digits to
8033 the name filename of the unit. */
8035 md5_init_ctx (&ctx
);
8037 die_checksum (unit_die
, &ctx
, &mark
);
8038 unmark_all_dies (unit_die
);
8039 md5_finish_ctx (&ctx
, checksum
);
8041 /* When we this for comp_unit_die () we have a DW_AT_name that might
8042 not start with a letter but with anything valid for filenames and
8043 clean_symbol_name doesn't fix that up. Prepend 'g' if the first
8044 character is not a letter. */
8045 sprintf (name
, "%s%s.", ISALPHA (*base
) ? "" : "g", base
);
8046 clean_symbol_name (name
);
8048 p
= name
+ strlen (name
);
8049 for (i
= 0; i
< 4; i
++)
8051 sprintf (p
, "%.2x", checksum
[i
]);
8055 unit_die
->die_id
.die_symbol
= xstrdup (name
);
8058 /* Returns true if DIE represents a type, in the sense of TYPE_P. */
8061 is_type_die (dw_die_ref die
)
8063 switch (die
->die_tag
)
8065 case DW_TAG_array_type
:
8066 case DW_TAG_class_type
:
8067 case DW_TAG_interface_type
:
8068 case DW_TAG_enumeration_type
:
8069 case DW_TAG_pointer_type
:
8070 case DW_TAG_reference_type
:
8071 case DW_TAG_rvalue_reference_type
:
8072 case DW_TAG_string_type
:
8073 case DW_TAG_structure_type
:
8074 case DW_TAG_subroutine_type
:
8075 case DW_TAG_union_type
:
8076 case DW_TAG_ptr_to_member_type
:
8077 case DW_TAG_set_type
:
8078 case DW_TAG_subrange_type
:
8079 case DW_TAG_base_type
:
8080 case DW_TAG_const_type
:
8081 case DW_TAG_file_type
:
8082 case DW_TAG_packed_type
:
8083 case DW_TAG_volatile_type
:
8084 case DW_TAG_typedef
:
8091 /* Returns true iff C is a compile-unit DIE. */
8094 is_cu_die (dw_die_ref c
)
8096 return c
&& (c
->die_tag
== DW_TAG_compile_unit
8097 || c
->die_tag
== DW_TAG_skeleton_unit
);
8100 /* Returns true iff C is a unit DIE of some sort. */
8103 is_unit_die (dw_die_ref c
)
8105 return c
&& (c
->die_tag
== DW_TAG_compile_unit
8106 || c
->die_tag
== DW_TAG_partial_unit
8107 || c
->die_tag
== DW_TAG_type_unit
8108 || c
->die_tag
== DW_TAG_skeleton_unit
);
8111 /* Returns true iff C is a namespace DIE. */
8114 is_namespace_die (dw_die_ref c
)
8116 return c
&& c
->die_tag
== DW_TAG_namespace
;
8119 /* Return true if this DIE is a template parameter. */
8122 is_template_parameter (dw_die_ref die
)
8124 switch (die
->die_tag
)
8126 case DW_TAG_template_type_param
:
8127 case DW_TAG_template_value_param
:
8128 case DW_TAG_GNU_template_template_param
:
8129 case DW_TAG_GNU_template_parameter_pack
:
8136 /* Return true if this DIE represents a template instantiation. */
8139 is_template_instantiation (dw_die_ref die
)
8143 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
8145 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
8150 gen_internal_sym (const char *prefix
)
8152 char buf
[MAX_ARTIFICIAL_LABEL_BYTES
];
8154 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
8155 return xstrdup (buf
);
8158 /* Return true if this DIE is a declaration. */
8161 is_declaration_die (dw_die_ref die
)
8166 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8167 if (a
->dw_attr
== DW_AT_declaration
)
8173 /* Return true if this DIE is nested inside a subprogram. */
8176 is_nested_in_subprogram (dw_die_ref die
)
8178 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
8182 return local_scope_p (decl
);
8185 /* Return true if this DIE contains a defining declaration of a
8189 contains_subprogram_definition (dw_die_ref die
)
8193 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
8195 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
8199 /* Return true if this is a type DIE that should be moved to a
8200 COMDAT .debug_types section or .debug_info section with DW_UT_*type
8204 should_move_die_to_comdat (dw_die_ref die
)
8206 switch (die
->die_tag
)
8208 case DW_TAG_class_type
:
8209 case DW_TAG_structure_type
:
8210 case DW_TAG_enumeration_type
:
8211 case DW_TAG_union_type
:
8212 /* Don't move declarations, inlined instances, types nested in a
8213 subprogram, or types that contain subprogram definitions. */
8214 if (is_declaration_die (die
)
8215 || get_AT (die
, DW_AT_abstract_origin
)
8216 || is_nested_in_subprogram (die
)
8217 || contains_subprogram_definition (die
))
8219 if (die
->die_tag
!= DW_TAG_enumeration_type
)
8221 /* Don't move non-constant size aggregates. */
8222 dw_attr_node
*sz
= get_AT (die
, DW_AT_byte_size
);
8224 || (AT_class (sz
) != dw_val_class_unsigned_const
8225 && AT_class (sz
) != dw_val_class_unsigned_const_implicit
))
8229 case DW_TAG_array_type
:
8230 case DW_TAG_interface_type
:
8231 case DW_TAG_pointer_type
:
8232 case DW_TAG_reference_type
:
8233 case DW_TAG_rvalue_reference_type
:
8234 case DW_TAG_string_type
:
8235 case DW_TAG_subroutine_type
:
8236 case DW_TAG_ptr_to_member_type
:
8237 case DW_TAG_set_type
:
8238 case DW_TAG_subrange_type
:
8239 case DW_TAG_base_type
:
8240 case DW_TAG_const_type
:
8241 case DW_TAG_file_type
:
8242 case DW_TAG_packed_type
:
8243 case DW_TAG_volatile_type
:
8244 case DW_TAG_typedef
:
8250 /* Make a clone of DIE. */
8253 clone_die (dw_die_ref die
)
8255 dw_die_ref clone
= new_die_raw (die
->die_tag
);
8259 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8260 add_dwarf_attr (clone
, a
);
8265 /* Make a clone of the tree rooted at DIE. */
8268 clone_tree (dw_die_ref die
)
8271 dw_die_ref clone
= clone_die (die
);
8273 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
8278 /* Make a clone of DIE as a declaration. */
8281 clone_as_declaration (dw_die_ref die
)
8288 /* If the DIE is already a declaration, just clone it. */
8289 if (is_declaration_die (die
))
8290 return clone_die (die
);
8292 /* If the DIE is a specification, just clone its declaration DIE. */
8293 decl
= get_AT_ref (die
, DW_AT_specification
);
8296 clone
= clone_die (decl
);
8297 if (die
->comdat_type_p
)
8298 add_AT_die_ref (clone
, DW_AT_signature
, die
);
8302 clone
= new_die_raw (die
->die_tag
);
8304 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8306 /* We don't want to copy over all attributes.
8307 For example we don't want DW_AT_byte_size because otherwise we will no
8308 longer have a declaration and GDB will treat it as a definition. */
8312 case DW_AT_abstract_origin
:
8313 case DW_AT_artificial
:
8314 case DW_AT_containing_type
:
8315 case DW_AT_external
:
8318 case DW_AT_virtuality
:
8319 case DW_AT_linkage_name
:
8320 case DW_AT_MIPS_linkage_name
:
8321 add_dwarf_attr (clone
, a
);
8323 case DW_AT_byte_size
:
8324 case DW_AT_alignment
:
8330 if (die
->comdat_type_p
)
8331 add_AT_die_ref (clone
, DW_AT_signature
, die
);
8333 add_AT_flag (clone
, DW_AT_declaration
, 1);
8338 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
8340 struct decl_table_entry
8346 /* Helpers to manipulate hash table of copied declarations. */
8348 /* Hashtable helpers. */
8350 struct decl_table_entry_hasher
: free_ptr_hash
<decl_table_entry
>
8352 typedef die_struct
*compare_type
;
8353 static inline hashval_t
hash (const decl_table_entry
*);
8354 static inline bool equal (const decl_table_entry
*, const die_struct
*);
8358 decl_table_entry_hasher::hash (const decl_table_entry
*entry
)
8360 return htab_hash_pointer (entry
->orig
);
8364 decl_table_entry_hasher::equal (const decl_table_entry
*entry1
,
8365 const die_struct
*entry2
)
8367 return entry1
->orig
== entry2
;
8370 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
8372 /* Copy DIE and its ancestors, up to, but not including, the compile unit
8373 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
8374 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
8375 to check if the ancestor has already been copied into UNIT. */
8378 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
,
8379 decl_hash_type
*decl_table
)
8381 dw_die_ref parent
= die
->die_parent
;
8382 dw_die_ref new_parent
= unit
;
8384 decl_table_entry
**slot
= NULL
;
8385 struct decl_table_entry
*entry
= NULL
;
8387 /* If DIE refers to a stub unfold that so we get the appropriate
8388 DIE registered as orig in decl_table. */
8389 if (dw_die_ref c
= get_AT_ref (die
, DW_AT_signature
))
8394 /* Check if the entry has already been copied to UNIT. */
8395 slot
= decl_table
->find_slot_with_hash (die
, htab_hash_pointer (die
),
8397 if (*slot
!= HTAB_EMPTY_ENTRY
)
8403 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
8404 entry
= XCNEW (struct decl_table_entry
);
8412 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
8415 if (!is_unit_die (parent
))
8416 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
8419 copy
= clone_as_declaration (die
);
8420 add_child_die (new_parent
, copy
);
8424 /* Record the pointer to the copy. */
8430 /* Copy the declaration context to the new type unit DIE. This includes
8431 any surrounding namespace or type declarations. If the DIE has an
8432 AT_specification attribute, it also includes attributes and children
8433 attached to the specification, and returns a pointer to the original
8434 parent of the declaration DIE. Returns NULL otherwise. */
8437 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
8440 dw_die_ref new_decl
;
8441 dw_die_ref orig_parent
= NULL
;
8443 decl
= get_AT_ref (die
, DW_AT_specification
);
8452 /* The original DIE will be changed to a declaration, and must
8453 be moved to be a child of the original declaration DIE. */
8454 orig_parent
= decl
->die_parent
;
8456 /* Copy the type node pointer from the new DIE to the original
8457 declaration DIE so we can forward references later. */
8458 decl
->comdat_type_p
= true;
8459 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
8461 remove_AT (die
, DW_AT_specification
);
8463 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
8465 if (a
->dw_attr
!= DW_AT_name
8466 && a
->dw_attr
!= DW_AT_declaration
8467 && a
->dw_attr
!= DW_AT_external
)
8468 add_dwarf_attr (die
, a
);
8471 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
8474 if (decl
->die_parent
!= NULL
8475 && !is_unit_die (decl
->die_parent
))
8477 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
8478 if (new_decl
!= NULL
)
8480 remove_AT (new_decl
, DW_AT_signature
);
8481 add_AT_specification (die
, new_decl
);
8488 /* Generate the skeleton ancestor tree for the given NODE, then clone
8489 the DIE and add the clone into the tree. */
8492 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
8494 if (node
->new_die
!= NULL
)
8497 node
->new_die
= clone_as_declaration (node
->old_die
);
8499 if (node
->parent
!= NULL
)
8501 generate_skeleton_ancestor_tree (node
->parent
);
8502 add_child_die (node
->parent
->new_die
, node
->new_die
);
8506 /* Generate a skeleton tree of DIEs containing any declarations that are
8507 found in the original tree. We traverse the tree looking for declaration
8508 DIEs, and construct the skeleton from the bottom up whenever we find one. */
8511 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
8513 skeleton_chain_node node
;
8516 dw_die_ref prev
= NULL
;
8517 dw_die_ref next
= NULL
;
8519 node
.parent
= parent
;
8521 first
= c
= parent
->old_die
->die_child
;
8525 if (prev
== NULL
|| prev
->die_sib
== c
)
8528 next
= (c
== first
? NULL
: c
->die_sib
);
8530 node
.new_die
= NULL
;
8531 if (is_declaration_die (c
))
8533 if (is_template_instantiation (c
))
8535 /* Instantiated templates do not need to be cloned into the
8536 type unit. Just move the DIE and its children back to
8537 the skeleton tree (in the main CU). */
8538 remove_child_with_prev (c
, prev
);
8539 add_child_die (parent
->new_die
, c
);
8542 else if (c
->comdat_type_p
)
8544 /* This is the skeleton of earlier break_out_comdat_types
8545 type. Clone the existing DIE, but keep the children
8546 under the original (which is in the main CU). */
8547 dw_die_ref clone
= clone_die (c
);
8549 replace_child (c
, clone
, prev
);
8550 generate_skeleton_ancestor_tree (parent
);
8551 add_child_die (parent
->new_die
, c
);
8557 /* Clone the existing DIE, move the original to the skeleton
8558 tree (which is in the main CU), and put the clone, with
8559 all the original's children, where the original came from
8560 (which is about to be moved to the type unit). */
8561 dw_die_ref clone
= clone_die (c
);
8562 move_all_children (c
, clone
);
8564 /* If the original has a DW_AT_object_pointer attribute,
8565 it would now point to a child DIE just moved to the
8566 cloned tree, so we need to remove that attribute from
8568 remove_AT (c
, DW_AT_object_pointer
);
8570 replace_child (c
, clone
, prev
);
8571 generate_skeleton_ancestor_tree (parent
);
8572 add_child_die (parent
->new_die
, c
);
8573 node
.old_die
= clone
;
8578 generate_skeleton_bottom_up (&node
);
8579 } while (next
!= NULL
);
8582 /* Wrapper function for generate_skeleton_bottom_up. */
8585 generate_skeleton (dw_die_ref die
)
8587 skeleton_chain_node node
;
8590 node
.new_die
= NULL
;
8593 /* If this type definition is nested inside another type,
8594 and is not an instantiation of a template, always leave
8595 at least a declaration in its place. */
8596 if (die
->die_parent
!= NULL
8597 && is_type_die (die
->die_parent
)
8598 && !is_template_instantiation (die
))
8599 node
.new_die
= clone_as_declaration (die
);
8601 generate_skeleton_bottom_up (&node
);
8602 return node
.new_die
;
8605 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
8606 declaration. The original DIE is moved to a new compile unit so that
8607 existing references to it follow it to the new location. If any of the
8608 original DIE's descendants is a declaration, we need to replace the
8609 original DIE with a skeleton tree and move the declarations back into the
8613 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
8616 dw_die_ref skeleton
, orig_parent
;
8618 /* Copy the declaration context to the type unit DIE. If the returned
8619 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
8621 orig_parent
= copy_declaration_context (unit
, child
);
8623 skeleton
= generate_skeleton (child
);
8624 if (skeleton
== NULL
)
8625 remove_child_with_prev (child
, prev
);
8628 skeleton
->comdat_type_p
= true;
8629 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
8631 /* If the original DIE was a specification, we need to put
8632 the skeleton under the parent DIE of the declaration.
8633 This leaves the original declaration in the tree, but
8634 it will be pruned later since there are no longer any
8635 references to it. */
8636 if (orig_parent
!= NULL
)
8638 remove_child_with_prev (child
, prev
);
8639 add_child_die (orig_parent
, skeleton
);
8642 replace_child (child
, skeleton
, prev
);
8649 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
8650 comdat_type_node
*type_node
,
8651 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
);
8653 /* Helper for copy_dwarf_procs_ref_in_dies. Make a copy of the DIE DWARF
8654 procedure, put it under TYPE_NODE and return the copy. Continue looking for
8655 DWARF procedure references in the DW_AT_location attribute. */
8658 copy_dwarf_procedure (dw_die_ref die
,
8659 comdat_type_node
*type_node
,
8660 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8662 gcc_assert (die
->die_tag
== DW_TAG_dwarf_procedure
);
8664 /* DWARF procedures are not supposed to have children... */
8665 gcc_assert (die
->die_child
== NULL
);
8667 /* ... and they are supposed to have only one attribute: DW_AT_location. */
8668 gcc_assert (vec_safe_length (die
->die_attr
) == 1
8669 && ((*die
->die_attr
)[0].dw_attr
== DW_AT_location
));
8671 /* Do not copy more than once DWARF procedures. */
8673 dw_die_ref
&die_copy
= copied_dwarf_procs
.get_or_insert (die
, &existed
);
8677 die_copy
= clone_die (die
);
8678 add_child_die (type_node
->root_die
, die_copy
);
8679 copy_dwarf_procs_ref_in_attrs (die_copy
, type_node
, copied_dwarf_procs
);
8683 /* Helper for copy_dwarf_procs_ref_in_dies. Look for references to DWARF
8684 procedures in DIE's attributes. */
8687 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
8688 comdat_type_node
*type_node
,
8689 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8694 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, i
, a
)
8696 dw_loc_descr_ref loc
;
8698 if (a
->dw_attr_val
.val_class
!= dw_val_class_loc
)
8701 for (loc
= a
->dw_attr_val
.v
.val_loc
; loc
!= NULL
; loc
= loc
->dw_loc_next
)
8703 switch (loc
->dw_loc_opc
)
8707 case DW_OP_call_ref
:
8708 gcc_assert (loc
->dw_loc_oprnd1
.val_class
8709 == dw_val_class_die_ref
);
8710 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
8711 = copy_dwarf_procedure (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
,
8713 copied_dwarf_procs
);
8722 /* Copy DWARF procedures that are referenced by the DIE tree to TREE_NODE and
8723 rewrite references to point to the copies.
8725 References are looked for in DIE's attributes and recursively in all its
8726 children attributes that are location descriptions. COPIED_DWARF_PROCS is a
8727 mapping from old DWARF procedures to their copy. It is used not to copy
8728 twice the same DWARF procedure under TYPE_NODE. */
8731 copy_dwarf_procs_ref_in_dies (dw_die_ref die
,
8732 comdat_type_node
*type_node
,
8733 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8737 copy_dwarf_procs_ref_in_attrs (die
, type_node
, copied_dwarf_procs
);
8738 FOR_EACH_CHILD (die
, c
, copy_dwarf_procs_ref_in_dies (c
,
8740 copied_dwarf_procs
));
8743 /* Traverse the DIE and set up additional .debug_types or .debug_info
8744 DW_UT_*type sections for each type worthy of being placed in a COMDAT
8748 break_out_comdat_types (dw_die_ref die
)
8752 dw_die_ref prev
= NULL
;
8753 dw_die_ref next
= NULL
;
8754 dw_die_ref unit
= NULL
;
8756 first
= c
= die
->die_child
;
8760 if (prev
== NULL
|| prev
->die_sib
== c
)
8763 next
= (c
== first
? NULL
: c
->die_sib
);
8764 if (should_move_die_to_comdat (c
))
8766 dw_die_ref replacement
;
8767 comdat_type_node
*type_node
;
8769 /* Break out nested types into their own type units. */
8770 break_out_comdat_types (c
);
8772 /* Create a new type unit DIE as the root for the new tree. */
8773 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8774 add_AT_unsigned (unit
, DW_AT_language
,
8775 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
8777 /* Add the new unit's type DIE into the comdat type list. */
8778 type_node
= ggc_cleared_alloc
<comdat_type_node
> ();
8779 type_node
->root_die
= unit
;
8780 type_node
->next
= comdat_type_list
;
8781 comdat_type_list
= type_node
;
8783 /* Generate the type signature. */
8784 generate_type_signature (c
, type_node
);
8786 /* Copy the declaration context, attributes, and children of the
8787 declaration into the new type unit DIE, then remove this DIE
8788 from the main CU (or replace it with a skeleton if necessary). */
8789 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
8790 type_node
->skeleton_die
= replacement
;
8792 /* Add the DIE to the new compunit. */
8793 add_child_die (unit
, c
);
8795 /* Types can reference DWARF procedures for type size or data location
8796 expressions. Calls in DWARF expressions cannot target procedures
8797 that are not in the same section. So we must copy DWARF procedures
8798 along with this type and then rewrite references to them. */
8799 hash_map
<dw_die_ref
, dw_die_ref
> copied_dwarf_procs
;
8800 copy_dwarf_procs_ref_in_dies (c
, type_node
, copied_dwarf_procs
);
8802 if (replacement
!= NULL
)
8805 else if (c
->die_tag
== DW_TAG_namespace
8806 || c
->die_tag
== DW_TAG_class_type
8807 || c
->die_tag
== DW_TAG_structure_type
8808 || c
->die_tag
== DW_TAG_union_type
)
8810 /* Look for nested types that can be broken out. */
8811 break_out_comdat_types (c
);
8813 } while (next
!= NULL
);
8816 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
8817 Enter all the cloned children into the hash table decl_table. */
8820 clone_tree_partial (dw_die_ref die
, decl_hash_type
*decl_table
)
8824 struct decl_table_entry
*entry
;
8825 decl_table_entry
**slot
;
8827 if (die
->die_tag
== DW_TAG_subprogram
)
8828 clone
= clone_as_declaration (die
);
8830 clone
= clone_die (die
);
8832 slot
= decl_table
->find_slot_with_hash (die
,
8833 htab_hash_pointer (die
), INSERT
);
8835 /* Assert that DIE isn't in the hash table yet. If it would be there
8836 before, the ancestors would be necessarily there as well, therefore
8837 clone_tree_partial wouldn't be called. */
8838 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
8840 entry
= XCNEW (struct decl_table_entry
);
8842 entry
->copy
= clone
;
8845 if (die
->die_tag
!= DW_TAG_subprogram
)
8846 FOR_EACH_CHILD (die
, c
,
8847 add_child_die (clone
, clone_tree_partial (c
, decl_table
)));
8852 /* Walk the DIE and its children, looking for references to incomplete
8853 or trivial types that are unmarked (i.e., that are not in the current
8857 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type
*decl_table
)
8863 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8865 if (AT_class (a
) == dw_val_class_die_ref
)
8867 dw_die_ref targ
= AT_ref (a
);
8868 decl_table_entry
**slot
;
8869 struct decl_table_entry
*entry
;
8871 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
8874 slot
= decl_table
->find_slot_with_hash (targ
,
8875 htab_hash_pointer (targ
),
8878 if (*slot
!= HTAB_EMPTY_ENTRY
)
8880 /* TARG has already been copied, so we just need to
8881 modify the reference to point to the copy. */
8883 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
8887 dw_die_ref parent
= unit
;
8888 dw_die_ref copy
= clone_die (targ
);
8890 /* Record in DECL_TABLE that TARG has been copied.
8891 Need to do this now, before the recursive call,
8892 because DECL_TABLE may be expanded and SLOT
8893 would no longer be a valid pointer. */
8894 entry
= XCNEW (struct decl_table_entry
);
8899 /* If TARG is not a declaration DIE, we need to copy its
8901 if (!is_declaration_die (targ
))
8905 add_child_die (copy
,
8906 clone_tree_partial (c
, decl_table
)));
8909 /* Make sure the cloned tree is marked as part of the
8913 /* If TARG has surrounding context, copy its ancestor tree
8914 into the new type unit. */
8915 if (targ
->die_parent
!= NULL
8916 && !is_unit_die (targ
->die_parent
))
8917 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
8920 add_child_die (parent
, copy
);
8921 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
8923 /* Make sure the newly-copied DIE is walked. If it was
8924 installed in a previously-added context, it won't
8925 get visited otherwise. */
8928 /* Find the highest point of the newly-added tree,
8929 mark each node along the way, and walk from there. */
8930 parent
->die_mark
= 1;
8931 while (parent
->die_parent
8932 && parent
->die_parent
->die_mark
== 0)
8934 parent
= parent
->die_parent
;
8935 parent
->die_mark
= 1;
8937 copy_decls_walk (unit
, parent
, decl_table
);
8943 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
8946 /* Collect skeleton dies in DIE created by break_out_comdat_types already
8947 and record them in DECL_TABLE. */
8950 collect_skeleton_dies (dw_die_ref die
, decl_hash_type
*decl_table
)
8954 if (dw_attr_node
*a
= get_AT (die
, DW_AT_signature
))
8956 dw_die_ref targ
= AT_ref (a
);
8957 gcc_assert (targ
->die_mark
== 0 && targ
->comdat_type_p
);
8958 decl_table_entry
**slot
8959 = decl_table
->find_slot_with_hash (targ
,
8960 htab_hash_pointer (targ
),
8962 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
8963 /* Record in DECL_TABLE that TARG has been already copied
8964 by remove_child_or_replace_with_skeleton. */
8965 decl_table_entry
*entry
= XCNEW (struct decl_table_entry
);
8970 FOR_EACH_CHILD (die
, c
, collect_skeleton_dies (c
, decl_table
));
8973 /* Copy declarations for "unworthy" types into the new comdat section.
8974 Incomplete types, modified types, and certain other types aren't broken
8975 out into comdat sections of their own, so they don't have a signature,
8976 and we need to copy the declaration into the same section so that we
8977 don't have an external reference. */
8980 copy_decls_for_unworthy_types (dw_die_ref unit
)
8983 decl_hash_type
decl_table (10);
8984 collect_skeleton_dies (unit
, &decl_table
);
8985 copy_decls_walk (unit
, unit
, &decl_table
);
8989 /* Traverse the DIE and add a sibling attribute if it may have the
8990 effect of speeding up access to siblings. To save some space,
8991 avoid generating sibling attributes for DIE's without children. */
8994 add_sibling_attributes (dw_die_ref die
)
8998 if (! die
->die_child
)
9001 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
9002 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
9004 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
9007 /* Output all location lists for the DIE and its children. */
9010 output_location_lists (dw_die_ref die
)
9016 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9017 if (AT_class (a
) == dw_val_class_loc_list
)
9018 output_loc_list (AT_loc_list (a
));
9020 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
9023 /* During assign_location_list_indexes and output_loclists_offset the
9024 current index, after it the number of assigned indexes (i.e. how
9025 large the .debug_loclists* offset table should be). */
9026 static unsigned int loc_list_idx
;
9028 /* Output all location list offsets for the DIE and its children. */
9031 output_loclists_offsets (dw_die_ref die
)
9037 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9038 if (AT_class (a
) == dw_val_class_loc_list
)
9040 dw_loc_list_ref l
= AT_loc_list (a
);
9041 if (l
->offset_emitted
)
9043 dw2_asm_output_delta (dwarf_offset_size
, l
->ll_symbol
,
9044 loc_section_label
, NULL
);
9045 gcc_assert (l
->hash
== loc_list_idx
);
9047 l
->offset_emitted
= true;
9050 FOR_EACH_CHILD (die
, c
, output_loclists_offsets (c
));
9053 /* Recursively set indexes of location lists. */
9056 assign_location_list_indexes (dw_die_ref die
)
9062 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9063 if (AT_class (a
) == dw_val_class_loc_list
)
9065 dw_loc_list_ref list
= AT_loc_list (a
);
9066 if (!list
->num_assigned
)
9068 list
->num_assigned
= true;
9069 list
->hash
= loc_list_idx
++;
9073 FOR_EACH_CHILD (die
, c
, assign_location_list_indexes (c
));
9076 /* We want to limit the number of external references, because they are
9077 larger than local references: a relocation takes multiple words, and
9078 even a sig8 reference is always eight bytes, whereas a local reference
9079 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
9080 So if we encounter multiple external references to the same type DIE, we
9081 make a local typedef stub for it and redirect all references there.
9083 This is the element of the hash table for keeping track of these
9093 /* Hashtable helpers. */
9095 struct external_ref_hasher
: free_ptr_hash
<external_ref
>
9097 static inline hashval_t
hash (const external_ref
*);
9098 static inline bool equal (const external_ref
*, const external_ref
*);
9102 external_ref_hasher::hash (const external_ref
*r
)
9104 dw_die_ref die
= r
->type
;
9107 /* We can't use the address of the DIE for hashing, because
9108 that will make the order of the stub DIEs non-deterministic. */
9109 if (! die
->comdat_type_p
)
9110 /* We have a symbol; use it to compute a hash. */
9111 h
= htab_hash_string (die
->die_id
.die_symbol
);
9114 /* We have a type signature; use a subset of the bits as the hash.
9115 The 8-byte signature is at least as large as hashval_t. */
9116 comdat_type_node
*type_node
= die
->die_id
.die_type_node
;
9117 memcpy (&h
, type_node
->signature
, sizeof (h
));
9123 external_ref_hasher::equal (const external_ref
*r1
, const external_ref
*r2
)
9125 return r1
->type
== r2
->type
;
9128 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
9130 /* Return a pointer to the external_ref for references to DIE. */
9132 static struct external_ref
*
9133 lookup_external_ref (external_ref_hash_type
*map
, dw_die_ref die
)
9135 struct external_ref ref
, *ref_p
;
9136 external_ref
**slot
;
9139 slot
= map
->find_slot (&ref
, INSERT
);
9140 if (*slot
!= HTAB_EMPTY_ENTRY
)
9143 ref_p
= XCNEW (struct external_ref
);
9149 /* Subroutine of optimize_external_refs, below.
9151 If we see a type skeleton, record it as our stub. If we see external
9152 references, remember how many we've seen. */
9155 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type
*map
)
9160 struct external_ref
*ref_p
;
9162 if (is_type_die (die
)
9163 && (c
= get_AT_ref (die
, DW_AT_signature
)))
9165 /* This is a local skeleton; use it for local references. */
9166 ref_p
= lookup_external_ref (map
, c
);
9170 /* Scan the DIE references, and remember any that refer to DIEs from
9171 other CUs (i.e. those which are not marked). */
9172 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9173 if (AT_class (a
) == dw_val_class_die_ref
9174 && (c
= AT_ref (a
))->die_mark
== 0
9177 ref_p
= lookup_external_ref (map
, c
);
9181 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
9184 /* htab_traverse callback function for optimize_external_refs, below. SLOT
9185 points to an external_ref, DATA is the CU we're processing. If we don't
9186 already have a local stub, and we have multiple refs, build a stub. */
9189 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
9191 struct external_ref
*ref_p
= *slot
;
9193 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
9195 /* We have multiple references to this type, so build a small stub.
9196 Both of these forms are a bit dodgy from the perspective of the
9197 DWARF standard, since technically they should have names. */
9198 dw_die_ref cu
= data
;
9199 dw_die_ref type
= ref_p
->type
;
9200 dw_die_ref stub
= NULL
;
9202 if (type
->comdat_type_p
)
9204 /* If we refer to this type via sig8, use AT_signature. */
9205 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
9206 add_AT_die_ref (stub
, DW_AT_signature
, type
);
9210 /* Otherwise, use a typedef with no name. */
9211 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
9212 add_AT_die_ref (stub
, DW_AT_type
, type
);
9221 /* DIE is a unit; look through all the DIE references to see if there are
9222 any external references to types, and if so, create local stubs for
9223 them which will be applied in build_abbrev_table. This is useful because
9224 references to local DIEs are smaller. */
9226 static external_ref_hash_type
*
9227 optimize_external_refs (dw_die_ref die
)
9229 external_ref_hash_type
*map
= new external_ref_hash_type (10);
9230 optimize_external_refs_1 (die
, map
);
9231 map
->traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
9235 /* The following 3 variables are temporaries that are computed only during the
9236 build_abbrev_table call and used and released during the following
9237 optimize_abbrev_table call. */
9239 /* First abbrev_id that can be optimized based on usage. */
9240 static unsigned int abbrev_opt_start
;
9242 /* Maximum abbrev_id of a base type plus one (we can't optimize DIEs with
9243 abbrev_id smaller than this, because they must be already sized
9244 during build_abbrev_table). */
9245 static unsigned int abbrev_opt_base_type_end
;
9247 /* Vector of usage counts during build_abbrev_table. Indexed by
9248 abbrev_id - abbrev_opt_start. */
9249 static vec
<unsigned int> abbrev_usage_count
;
9251 /* Vector of all DIEs added with die_abbrev >= abbrev_opt_start. */
9252 static vec
<dw_die_ref
> sorted_abbrev_dies
;
9254 /* The format of each DIE (and its attribute value pairs) is encoded in an
9255 abbreviation table. This routine builds the abbreviation table and assigns
9256 a unique abbreviation id for each abbreviation entry. The children of each
9257 die are visited recursively. */
9260 build_abbrev_table (dw_die_ref die
, external_ref_hash_type
*extern_map
)
9262 unsigned int abbrev_id
= 0;
9268 /* Scan the DIE references, and replace any that refer to
9269 DIEs from other CUs (i.e. those which are not marked) with
9270 the local stubs we built in optimize_external_refs. */
9271 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9272 if (AT_class (a
) == dw_val_class_die_ref
9273 && (c
= AT_ref (a
))->die_mark
== 0)
9275 struct external_ref
*ref_p
;
9276 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
9279 && (ref_p
= lookup_external_ref (extern_map
, c
))
9280 && ref_p
->stub
&& ref_p
->stub
!= die
)
9282 gcc_assert (a
->dw_attr
!= DW_AT_signature
);
9283 change_AT_die_ref (a
, ref_p
->stub
);
9286 /* We aren't changing this reference, so mark it external. */
9287 set_AT_ref_external (a
, 1);
9290 FOR_EACH_VEC_SAFE_ELT (abbrev_die_table
, abbrev_id
, abbrev
)
9292 dw_attr_node
*die_a
, *abbrev_a
;
9298 if (abbrev
->die_tag
!= die
->die_tag
)
9300 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
9303 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
9306 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
9308 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
9309 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
9310 || (value_format (abbrev_a
) != value_format (die_a
)))
9320 if (abbrev_id
>= vec_safe_length (abbrev_die_table
))
9322 vec_safe_push (abbrev_die_table
, die
);
9323 if (abbrev_opt_start
)
9324 abbrev_usage_count
.safe_push (0);
9326 if (abbrev_opt_start
&& abbrev_id
>= abbrev_opt_start
)
9328 abbrev_usage_count
[abbrev_id
- abbrev_opt_start
]++;
9329 sorted_abbrev_dies
.safe_push (die
);
9332 die
->die_abbrev
= abbrev_id
;
9333 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
9336 /* Callback function for sorted_abbrev_dies vector sorting. We sort
9337 by die_abbrev's usage count, from the most commonly used
9338 abbreviation to the least. */
9341 die_abbrev_cmp (const void *p1
, const void *p2
)
9343 dw_die_ref die1
= *(const dw_die_ref
*) p1
;
9344 dw_die_ref die2
= *(const dw_die_ref
*) p2
;
9346 gcc_checking_assert (die1
->die_abbrev
>= abbrev_opt_start
);
9347 gcc_checking_assert (die2
->die_abbrev
>= abbrev_opt_start
);
9349 if (die1
->die_abbrev
>= abbrev_opt_base_type_end
9350 && die2
->die_abbrev
>= abbrev_opt_base_type_end
)
9352 if (abbrev_usage_count
[die1
->die_abbrev
- abbrev_opt_start
]
9353 > abbrev_usage_count
[die2
->die_abbrev
- abbrev_opt_start
])
9355 if (abbrev_usage_count
[die1
->die_abbrev
- abbrev_opt_start
]
9356 < abbrev_usage_count
[die2
->die_abbrev
- abbrev_opt_start
])
9360 /* Stabilize the sort. */
9361 if (die1
->die_abbrev
< die2
->die_abbrev
)
9363 if (die1
->die_abbrev
> die2
->die_abbrev
)
9369 /* Convert dw_val_class_const and dw_val_class_unsigned_const class attributes
9370 of DIEs in between sorted_abbrev_dies[first_id] and abbrev_dies[end_id - 1]
9371 into dw_val_class_const_implicit or
9372 dw_val_class_unsigned_const_implicit. */
9375 optimize_implicit_const (unsigned int first_id
, unsigned int end
,
9376 vec
<bool> &implicit_consts
)
9378 /* It never makes sense if there is just one DIE using the abbreviation. */
9379 if (end
< first_id
+ 2)
9384 dw_die_ref die
= sorted_abbrev_dies
[first_id
];
9385 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9386 if (implicit_consts
[ix
])
9388 enum dw_val_class new_class
= dw_val_class_none
;
9389 switch (AT_class (a
))
9391 case dw_val_class_unsigned_const
:
9392 if ((HOST_WIDE_INT
) AT_unsigned (a
) < 0)
9395 /* The .debug_abbrev section will grow by
9396 size_of_sleb128 (AT_unsigned (a)) and we avoid the constants
9397 in all the DIEs using that abbreviation. */
9398 if (constant_size (AT_unsigned (a
)) * (end
- first_id
)
9399 <= (unsigned) size_of_sleb128 (AT_unsigned (a
)))
9402 new_class
= dw_val_class_unsigned_const_implicit
;
9405 case dw_val_class_const
:
9406 new_class
= dw_val_class_const_implicit
;
9409 case dw_val_class_file
:
9410 new_class
= dw_val_class_file_implicit
;
9416 for (i
= first_id
; i
< end
; i
++)
9417 (*sorted_abbrev_dies
[i
]->die_attr
)[ix
].dw_attr_val
.val_class
9422 /* Attempt to optimize abbreviation table from abbrev_opt_start
9423 abbreviation above. */
9426 optimize_abbrev_table (void)
9428 if (abbrev_opt_start
9429 && vec_safe_length (abbrev_die_table
) > abbrev_opt_start
9430 && (dwarf_version
>= 5 || vec_safe_length (abbrev_die_table
) > 127))
9432 auto_vec
<bool, 32> implicit_consts
;
9433 sorted_abbrev_dies
.qsort (die_abbrev_cmp
);
9435 unsigned int abbrev_id
= abbrev_opt_start
- 1;
9436 unsigned int first_id
= ~0U;
9437 unsigned int last_abbrev_id
= 0;
9440 if (abbrev_opt_base_type_end
> abbrev_opt_start
)
9441 abbrev_id
= abbrev_opt_base_type_end
- 1;
9442 /* Reassign abbreviation ids from abbrev_opt_start above, so that
9443 most commonly used abbreviations come first. */
9444 FOR_EACH_VEC_ELT (sorted_abbrev_dies
, i
, die
)
9449 /* If calc_base_type_die_sizes has been called, the CU and
9450 base types after it can't be optimized, because we've already
9451 calculated their DIE offsets. We've sorted them first. */
9452 if (die
->die_abbrev
< abbrev_opt_base_type_end
)
9454 if (die
->die_abbrev
!= last_abbrev_id
)
9456 last_abbrev_id
= die
->die_abbrev
;
9457 if (dwarf_version
>= 5 && first_id
!= ~0U)
9458 optimize_implicit_const (first_id
, i
, implicit_consts
);
9460 (*abbrev_die_table
)[abbrev_id
] = die
;
9461 if (dwarf_version
>= 5)
9464 implicit_consts
.truncate (0);
9466 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9467 switch (AT_class (a
))
9469 case dw_val_class_const
:
9470 case dw_val_class_unsigned_const
:
9471 case dw_val_class_file
:
9472 implicit_consts
.safe_push (true);
9475 implicit_consts
.safe_push (false);
9480 else if (dwarf_version
>= 5)
9482 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9483 if (!implicit_consts
[ix
])
9487 dw_attr_node
*other_a
9488 = &(*(*abbrev_die_table
)[abbrev_id
]->die_attr
)[ix
];
9489 if (!dw_val_equal_p (&a
->dw_attr_val
,
9490 &other_a
->dw_attr_val
))
9491 implicit_consts
[ix
] = false;
9494 die
->die_abbrev
= abbrev_id
;
9496 gcc_assert (abbrev_id
== vec_safe_length (abbrev_die_table
) - 1);
9497 if (dwarf_version
>= 5 && first_id
!= ~0U)
9498 optimize_implicit_const (first_id
, i
, implicit_consts
);
9501 abbrev_opt_start
= 0;
9502 abbrev_opt_base_type_end
= 0;
9503 abbrev_usage_count
.release ();
9504 sorted_abbrev_dies
.release ();
9507 /* Return the power-of-two number of bytes necessary to represent VALUE. */
9510 constant_size (unsigned HOST_WIDE_INT value
)
9517 log
= floor_log2 (value
);
9520 log
= 1 << (floor_log2 (log
) + 1);
9525 /* Return the size of a DIE as it is represented in the
9526 .debug_info section. */
9528 static unsigned long
9529 size_of_die (dw_die_ref die
)
9531 unsigned long size
= 0;
9534 enum dwarf_form form
;
9536 size
+= size_of_uleb128 (die
->die_abbrev
);
9537 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9539 switch (AT_class (a
))
9541 case dw_val_class_addr
:
9542 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
9544 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
9545 size
+= size_of_uleb128 (AT_index (a
));
9548 size
+= DWARF2_ADDR_SIZE
;
9550 case dw_val_class_offset
:
9551 size
+= dwarf_offset_size
;
9553 case dw_val_class_loc
:
9555 unsigned long lsize
= size_of_locs (AT_loc (a
));
9558 if (dwarf_version
>= 4)
9559 size
+= size_of_uleb128 (lsize
);
9561 size
+= constant_size (lsize
);
9565 case dw_val_class_loc_list
:
9566 if (dwarf_split_debug_info
&& dwarf_version
>= 5)
9568 gcc_assert (AT_loc_list (a
)->num_assigned
);
9569 size
+= size_of_uleb128 (AT_loc_list (a
)->hash
);
9572 size
+= dwarf_offset_size
;
9574 case dw_val_class_view_list
:
9575 size
+= dwarf_offset_size
;
9577 case dw_val_class_range_list
:
9578 if (value_format (a
) == DW_FORM_rnglistx
)
9580 gcc_assert (rnglist_idx
);
9581 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
9582 size
+= size_of_uleb128 (r
->idx
);
9585 size
+= dwarf_offset_size
;
9587 case dw_val_class_const
:
9588 size
+= size_of_sleb128 (AT_int (a
));
9590 case dw_val_class_unsigned_const
:
9592 int csize
= constant_size (AT_unsigned (a
));
9593 if (dwarf_version
== 3
9594 && a
->dw_attr
== DW_AT_data_member_location
9596 size
+= size_of_uleb128 (AT_unsigned (a
));
9601 case dw_val_class_symview
:
9602 if (symview_upper_bound
<= 0xff)
9604 else if (symview_upper_bound
<= 0xffff)
9606 else if (symview_upper_bound
<= 0xffffffff)
9611 case dw_val_class_const_implicit
:
9612 case dw_val_class_unsigned_const_implicit
:
9613 case dw_val_class_file_implicit
:
9614 /* These occupy no size in the DIE, just an extra sleb128 in
9617 case dw_val_class_const_double
:
9618 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
9619 if (HOST_BITS_PER_WIDE_INT
>= DWARF_LARGEST_DATA_FORM_BITS
)
9622 case dw_val_class_wide_int
:
9623 size
+= (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
9624 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
9625 if (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
9626 * HOST_BITS_PER_WIDE_INT
> DWARF_LARGEST_DATA_FORM_BITS
)
9629 case dw_val_class_vec
:
9630 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
9631 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
9632 + a
->dw_attr_val
.v
.val_vec
.length
9633 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
9635 case dw_val_class_flag
:
9636 if (dwarf_version
>= 4)
9637 /* Currently all add_AT_flag calls pass in 1 as last argument,
9638 so DW_FORM_flag_present can be used. If that ever changes,
9639 we'll need to use DW_FORM_flag and have some optimization
9640 in build_abbrev_table that will change those to
9641 DW_FORM_flag_present if it is set to 1 in all DIEs using
9642 the same abbrev entry. */
9643 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
9647 case dw_val_class_die_ref
:
9648 if (AT_ref_external (a
))
9650 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
9651 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
9652 is sized by target address length, whereas in DWARF3
9653 it's always sized as an offset. */
9654 if (AT_ref (a
)->comdat_type_p
)
9655 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
9656 else if (dwarf_version
== 2)
9657 size
+= DWARF2_ADDR_SIZE
;
9659 size
+= dwarf_offset_size
;
9662 size
+= dwarf_offset_size
;
9664 case dw_val_class_fde_ref
:
9665 size
+= dwarf_offset_size
;
9667 case dw_val_class_lbl_id
:
9668 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
9670 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
9671 size
+= size_of_uleb128 (AT_index (a
));
9674 size
+= DWARF2_ADDR_SIZE
;
9676 case dw_val_class_lineptr
:
9677 case dw_val_class_macptr
:
9678 case dw_val_class_loclistsptr
:
9679 size
+= dwarf_offset_size
;
9681 case dw_val_class_str
:
9682 form
= AT_string_form (a
);
9683 if (form
== DW_FORM_strp
|| form
== DW_FORM_line_strp
)
9684 size
+= dwarf_offset_size
;
9685 else if (form
== dwarf_FORM (DW_FORM_strx
))
9686 size
+= size_of_uleb128 (AT_index (a
));
9688 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
9690 case dw_val_class_file
:
9691 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
9693 case dw_val_class_data8
:
9696 case dw_val_class_vms_delta
:
9697 size
+= dwarf_offset_size
;
9699 case dw_val_class_high_pc
:
9700 size
+= DWARF2_ADDR_SIZE
;
9702 case dw_val_class_discr_value
:
9703 size
+= size_of_discr_value (&a
->dw_attr_val
.v
.val_discr_value
);
9705 case dw_val_class_discr_list
:
9707 unsigned block_size
= size_of_discr_list (AT_discr_list (a
));
9709 /* This is a block, so we have the block length and then its
9711 size
+= constant_size (block_size
) + block_size
;
9722 /* Size the debugging information associated with a given DIE. Visits the
9723 DIE's children recursively. Updates the global variable next_die_offset, on
9724 each time through. Uses the current value of next_die_offset to update the
9725 die_offset field in each DIE. */
9728 calc_die_sizes (dw_die_ref die
)
9732 gcc_assert (die
->die_offset
== 0
9733 || (unsigned long int) die
->die_offset
== next_die_offset
);
9734 die
->die_offset
= next_die_offset
;
9735 next_die_offset
+= size_of_die (die
);
9737 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
9739 if (die
->die_child
!= NULL
)
9740 /* Count the null byte used to terminate sibling lists. */
9741 next_die_offset
+= 1;
9744 /* Size just the base type children at the start of the CU.
9745 This is needed because build_abbrev needs to size locs
9746 and sizing of type based stack ops needs to know die_offset
9747 values for the base types. */
9750 calc_base_type_die_sizes (void)
9752 unsigned long die_offset
= (dwarf_split_debug_info
9753 ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
9754 : DWARF_COMPILE_UNIT_HEADER_SIZE
);
9756 dw_die_ref base_type
;
9757 #if ENABLE_ASSERT_CHECKING
9758 dw_die_ref prev
= comp_unit_die ()->die_child
;
9761 die_offset
+= size_of_die (comp_unit_die ());
9762 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
9764 #if ENABLE_ASSERT_CHECKING
9765 gcc_assert (base_type
->die_offset
== 0
9766 && prev
->die_sib
== base_type
9767 && base_type
->die_child
== NULL
9768 && base_type
->die_abbrev
);
9771 if (abbrev_opt_start
9772 && base_type
->die_abbrev
>= abbrev_opt_base_type_end
)
9773 abbrev_opt_base_type_end
= base_type
->die_abbrev
+ 1;
9774 base_type
->die_offset
= die_offset
;
9775 die_offset
+= size_of_die (base_type
);
9779 /* Set the marks for a die and its children. We do this so
9780 that we know whether or not a reference needs to use FORM_ref_addr; only
9781 DIEs in the same CU will be marked. We used to clear out the offset
9782 and use that as the flag, but ran into ordering problems. */
9785 mark_dies (dw_die_ref die
)
9789 gcc_assert (!die
->die_mark
);
9792 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
9795 /* Clear the marks for a die and its children. */
9798 unmark_dies (dw_die_ref die
)
9802 if (! use_debug_types
)
9803 gcc_assert (die
->die_mark
);
9806 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
9809 /* Clear the marks for a die, its children and referred dies. */
9812 unmark_all_dies (dw_die_ref die
)
9822 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
9824 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9825 if (AT_class (a
) == dw_val_class_die_ref
)
9826 unmark_all_dies (AT_ref (a
));
9829 /* Calculate if the entry should appear in the final output file. It may be
9830 from a pruned a type. */
9833 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
9835 /* By limiting gnu pubnames to definitions only, gold can generate a
9836 gdb index without entries for declarations, which don't include
9837 enough information to be useful. */
9838 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
9841 if (table
== pubname_table
)
9843 /* Enumerator names are part of the pubname table, but the
9844 parent DW_TAG_enumeration_type die may have been pruned.
9845 Don't output them if that is the case. */
9846 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
9847 (p
->die
->die_parent
== NULL
9848 || !p
->die
->die_parent
->die_perennial_p
))
9851 /* Everything else in the pubname table is included. */
9855 /* The pubtypes table shouldn't include types that have been
9857 return (p
->die
->die_offset
!= 0
9858 || !flag_eliminate_unused_debug_types
);
9861 /* Return the size of the .debug_pubnames or .debug_pubtypes table
9862 generated for the compilation unit. */
9864 static unsigned long
9865 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9870 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
9872 size
= DWARF_PUBNAMES_HEADER_SIZE
;
9873 FOR_EACH_VEC_ELT (*names
, i
, p
)
9874 if (include_pubname_in_output (names
, p
))
9875 size
+= strlen (p
->name
) + dwarf_offset_size
+ 1 + space_for_flags
;
9877 size
+= dwarf_offset_size
;
9881 /* Return the size of the information in the .debug_aranges section. */
9883 static unsigned long
9884 size_of_aranges (void)
9888 size
= DWARF_ARANGES_HEADER_SIZE
;
9890 /* Count the address/length pair for this compilation unit. */
9891 if (switch_text_ranges
)
9892 size
+= 2 * DWARF2_ADDR_SIZE
9893 * (vec_safe_length (switch_text_ranges
) / 2 + 1);
9894 if (switch_cold_ranges
)
9895 size
+= 2 * DWARF2_ADDR_SIZE
9896 * (vec_safe_length (switch_cold_ranges
) / 2 + 1);
9897 if (have_multiple_function_sections
)
9902 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9904 if (fde
->ignored_debug
)
9906 if (!fde
->in_std_section
)
9907 size
+= 2 * DWARF2_ADDR_SIZE
;
9908 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9909 size
+= 2 * DWARF2_ADDR_SIZE
;
9913 /* Count the two zero words used to terminated the address range table. */
9914 size
+= 2 * DWARF2_ADDR_SIZE
;
9918 /* Select the encoding of an attribute value. */
9920 static enum dwarf_form
9921 value_format (dw_attr_node
*a
)
9923 switch (AT_class (a
))
9925 case dw_val_class_addr
:
9926 /* Only very few attributes allow DW_FORM_addr. */
9931 case DW_AT_entry_pc
:
9932 case DW_AT_trampoline
:
9933 return (AT_index (a
) == NOT_INDEXED
9934 ? DW_FORM_addr
: dwarf_FORM (DW_FORM_addrx
));
9938 switch (DWARF2_ADDR_SIZE
)
9941 return DW_FORM_data1
;
9943 return DW_FORM_data2
;
9945 return DW_FORM_data4
;
9947 return DW_FORM_data8
;
9951 case dw_val_class_loc_list
:
9952 if (dwarf_split_debug_info
9953 && dwarf_version
>= 5
9954 && AT_loc_list (a
)->num_assigned
)
9955 return DW_FORM_loclistx
;
9957 case dw_val_class_view_list
:
9958 case dw_val_class_range_list
:
9959 /* For range lists in DWARF 5, use DW_FORM_rnglistx from .debug_info.dwo
9960 but in .debug_info use DW_FORM_sec_offset, which is shorter if we
9961 care about sizes of .debug* sections in shared libraries and
9962 executables and don't take into account relocations that affect just
9963 relocatable objects - for DW_FORM_rnglistx we'd have to emit offset
9964 table in the .debug_rnglists section. */
9965 if (dwarf_split_debug_info
9966 && dwarf_version
>= 5
9967 && AT_class (a
) == dw_val_class_range_list
9969 && a
->dw_attr_val
.val_entry
!= RELOCATED_OFFSET
)
9970 return DW_FORM_rnglistx
;
9971 if (dwarf_version
>= 4)
9972 return DW_FORM_sec_offset
;
9974 case dw_val_class_vms_delta
:
9975 case dw_val_class_offset
:
9976 switch (dwarf_offset_size
)
9979 return DW_FORM_data4
;
9981 return DW_FORM_data8
;
9985 case dw_val_class_loc
:
9986 if (dwarf_version
>= 4)
9987 return DW_FORM_exprloc
;
9988 switch (constant_size (size_of_locs (AT_loc (a
))))
9991 return DW_FORM_block1
;
9993 return DW_FORM_block2
;
9995 return DW_FORM_block4
;
9999 case dw_val_class_const
:
10000 return DW_FORM_sdata
;
10001 case dw_val_class_unsigned_const
:
10002 switch (constant_size (AT_unsigned (a
)))
10005 return DW_FORM_data1
;
10007 return DW_FORM_data2
;
10009 /* In DWARF3 DW_AT_data_member_location with
10010 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
10011 constant, so we need to use DW_FORM_udata if we need
10012 a large constant. */
10013 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
10014 return DW_FORM_udata
;
10015 return DW_FORM_data4
;
10017 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
10018 return DW_FORM_udata
;
10019 return DW_FORM_data8
;
10021 gcc_unreachable ();
10023 case dw_val_class_const_implicit
:
10024 case dw_val_class_unsigned_const_implicit
:
10025 case dw_val_class_file_implicit
:
10026 return DW_FORM_implicit_const
;
10027 case dw_val_class_const_double
:
10028 switch (HOST_BITS_PER_WIDE_INT
)
10031 return DW_FORM_data2
;
10033 return DW_FORM_data4
;
10035 return DW_FORM_data8
;
10037 if (dwarf_version
>= 5)
10038 return DW_FORM_data16
;
10041 return DW_FORM_block1
;
10043 case dw_val_class_wide_int
:
10044 switch (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
)
10047 return DW_FORM_data1
;
10049 return DW_FORM_data2
;
10051 return DW_FORM_data4
;
10053 return DW_FORM_data8
;
10055 if (dwarf_version
>= 5)
10056 return DW_FORM_data16
;
10059 return DW_FORM_block1
;
10061 case dw_val_class_symview
:
10062 /* ??? We might use uleb128, but then we'd have to compute
10063 .debug_info offsets in the assembler. */
10064 if (symview_upper_bound
<= 0xff)
10065 return DW_FORM_data1
;
10066 else if (symview_upper_bound
<= 0xffff)
10067 return DW_FORM_data2
;
10068 else if (symview_upper_bound
<= 0xffffffff)
10069 return DW_FORM_data4
;
10071 return DW_FORM_data8
;
10072 case dw_val_class_vec
:
10073 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
10074 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
10077 return DW_FORM_block1
;
10079 return DW_FORM_block2
;
10081 return DW_FORM_block4
;
10083 gcc_unreachable ();
10085 case dw_val_class_flag
:
10086 if (dwarf_version
>= 4)
10088 /* Currently all add_AT_flag calls pass in 1 as last argument,
10089 so DW_FORM_flag_present can be used. If that ever changes,
10090 we'll need to use DW_FORM_flag and have some optimization
10091 in build_abbrev_table that will change those to
10092 DW_FORM_flag_present if it is set to 1 in all DIEs using
10093 the same abbrev entry. */
10094 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
10095 return DW_FORM_flag_present
;
10097 return DW_FORM_flag
;
10098 case dw_val_class_die_ref
:
10099 if (AT_ref_external (a
))
10101 if (AT_ref (a
)->comdat_type_p
)
10102 return DW_FORM_ref_sig8
;
10104 return DW_FORM_ref_addr
;
10107 return DW_FORM_ref
;
10108 case dw_val_class_fde_ref
:
10109 return DW_FORM_data
;
10110 case dw_val_class_lbl_id
:
10111 return (AT_index (a
) == NOT_INDEXED
10112 ? DW_FORM_addr
: dwarf_FORM (DW_FORM_addrx
));
10113 case dw_val_class_lineptr
:
10114 case dw_val_class_macptr
:
10115 case dw_val_class_loclistsptr
:
10116 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
10117 case dw_val_class_str
:
10118 return AT_string_form (a
);
10119 case dw_val_class_file
:
10120 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
10123 return DW_FORM_data1
;
10125 return DW_FORM_data2
;
10127 return DW_FORM_data4
;
10129 gcc_unreachable ();
10132 case dw_val_class_data8
:
10133 return DW_FORM_data8
;
10135 case dw_val_class_high_pc
:
10136 switch (DWARF2_ADDR_SIZE
)
10139 return DW_FORM_data1
;
10141 return DW_FORM_data2
;
10143 return DW_FORM_data4
;
10145 return DW_FORM_data8
;
10147 gcc_unreachable ();
10150 case dw_val_class_discr_value
:
10151 return (a
->dw_attr_val
.v
.val_discr_value
.pos
10154 case dw_val_class_discr_list
:
10155 switch (constant_size (size_of_discr_list (AT_discr_list (a
))))
10158 return DW_FORM_block1
;
10160 return DW_FORM_block2
;
10162 return DW_FORM_block4
;
10164 gcc_unreachable ();
10168 gcc_unreachable ();
10172 /* Output the encoding of an attribute value. */
10175 output_value_format (dw_attr_node
*a
)
10177 enum dwarf_form form
= value_format (a
);
10179 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
10182 /* Given a die and id, produce the appropriate abbreviations. */
10185 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
10188 dw_attr_node
*a_attr
;
10190 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
10191 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
10192 dwarf_tag_name (abbrev
->die_tag
));
10194 if (abbrev
->die_child
!= NULL
)
10195 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
10197 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
10199 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
10201 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
10202 dwarf_attr_name (a_attr
->dw_attr
));
10203 output_value_format (a_attr
);
10204 if (value_format (a_attr
) == DW_FORM_implicit_const
)
10206 if (AT_class (a_attr
) == dw_val_class_file_implicit
)
10208 int f
= maybe_emit_file (a_attr
->dw_attr_val
.v
.val_file
);
10209 const char *filename
= a_attr
->dw_attr_val
.v
.val_file
->filename
;
10210 dw2_asm_output_data_sleb128 (f
, "(%s)", filename
);
10213 dw2_asm_output_data_sleb128 (a_attr
->dw_attr_val
.v
.val_int
, NULL
);
10217 dw2_asm_output_data (1, 0, NULL
);
10218 dw2_asm_output_data (1, 0, NULL
);
10222 /* Output the .debug_abbrev section which defines the DIE abbreviation
10226 output_abbrev_section (void)
10228 unsigned int abbrev_id
;
10231 FOR_EACH_VEC_SAFE_ELT (abbrev_die_table
, abbrev_id
, abbrev
)
10232 if (abbrev_id
!= 0)
10233 output_die_abbrevs (abbrev_id
, abbrev
);
10235 /* Terminate the table. */
10236 dw2_asm_output_data (1, 0, NULL
);
10239 /* Return a new location list, given the begin and end range, and the
10242 static inline dw_loc_list_ref
10243 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, var_loc_view vbegin
,
10244 const char *end
, var_loc_view vend
,
10245 const char *section
)
10247 dw_loc_list_ref retlist
= ggc_cleared_alloc
<dw_loc_list_node
> ();
10249 retlist
->begin
= begin
;
10250 retlist
->begin_entry
= NULL
;
10251 retlist
->end
= end
;
10252 retlist
->end_entry
= NULL
;
10253 retlist
->expr
= expr
;
10254 retlist
->section
= section
;
10255 retlist
->vbegin
= vbegin
;
10256 retlist
->vend
= vend
;
10261 /* Return true iff there's any nonzero view number in the loc list.
10263 ??? When views are not enabled, we'll often extend a single range
10264 to the entire function, so that we emit a single location
10265 expression rather than a location list. With views, even with a
10266 single range, we'll output a list if start or end have a nonzero
10267 view. If we change this, we may want to stop splitting a single
10268 range in dw_loc_list just because of a nonzero view, even if it
10269 straddles across hot/cold partitions. */
10272 loc_list_has_views (dw_loc_list_ref list
)
10274 if (!debug_variable_location_views
)
10277 for (dw_loc_list_ref loc
= list
;
10278 loc
!= NULL
; loc
= loc
->dw_loc_next
)
10279 if (!ZERO_VIEW_P (loc
->vbegin
) || !ZERO_VIEW_P (loc
->vend
))
10285 /* Generate a new internal symbol for this location list node, if it
10286 hasn't got one yet. */
10289 gen_llsym (dw_loc_list_ref list
)
10291 gcc_assert (!list
->ll_symbol
);
10292 list
->ll_symbol
= gen_internal_sym ("LLST");
10294 if (!loc_list_has_views (list
))
10297 if (dwarf2out_locviews_in_attribute ())
10299 /* Use the same label_num for the view list. */
10301 list
->vl_symbol
= gen_internal_sym ("LVUS");
10304 list
->vl_symbol
= list
->ll_symbol
;
10307 /* Generate a symbol for the list, but only if we really want to emit
10311 maybe_gen_llsym (dw_loc_list_ref list
)
10313 if (!list
|| (!list
->dw_loc_next
&& !loc_list_has_views (list
)))
10319 /* Determine whether or not to skip loc_list entry CURR. If SIZEP is
10320 NULL, don't consider size of the location expression. If we're not
10321 to skip it, and SIZEP is non-null, store the size of CURR->expr's
10322 representation in *SIZEP. */
10325 skip_loc_list_entry (dw_loc_list_ref curr
, unsigned long *sizep
= NULL
)
10327 /* Don't output an entry that starts and ends at the same address. */
10328 if (strcmp (curr
->begin
, curr
->end
) == 0
10329 && curr
->vbegin
== curr
->vend
&& !curr
->force
)
10335 unsigned long size
= size_of_locs (curr
->expr
);
10337 /* If the expression is too large, drop it on the floor. We could
10338 perhaps put it into DW_TAG_dwarf_procedure and refer to that
10339 in the expression, but >= 64KB expressions for a single value
10340 in a single range are unlikely very useful. */
10341 if (dwarf_version
< 5 && size
> 0xffff)
10349 /* Output a view pair loclist entry for CURR, if it requires one. */
10352 dwarf2out_maybe_output_loclist_view_pair (dw_loc_list_ref curr
)
10354 if (!dwarf2out_locviews_in_loclist ())
10357 if (ZERO_VIEW_P (curr
->vbegin
) && ZERO_VIEW_P (curr
->vend
))
10360 #ifdef DW_LLE_view_pair
10361 dw2_asm_output_data (1, DW_LLE_view_pair
, "DW_LLE_view_pair");
10363 if (dwarf2out_as_locview_support
)
10365 if (ZERO_VIEW_P (curr
->vbegin
))
10366 dw2_asm_output_data_uleb128 (0, "Location view begin");
10369 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10370 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", curr
->vbegin
);
10371 dw2_asm_output_symname_uleb128 (label
, "Location view begin");
10374 if (ZERO_VIEW_P (curr
->vend
))
10375 dw2_asm_output_data_uleb128 (0, "Location view end");
10378 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10379 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", curr
->vend
);
10380 dw2_asm_output_symname_uleb128 (label
, "Location view end");
10385 dw2_asm_output_data_uleb128 (curr
->vbegin
, "Location view begin");
10386 dw2_asm_output_data_uleb128 (curr
->vend
, "Location view end");
10388 #endif /* DW_LLE_view_pair */
10393 /* Output the location list given to us. */
10396 output_loc_list (dw_loc_list_ref list_head
)
10398 int vcount
= 0, lcount
= 0;
10400 if (list_head
->emitted
)
10402 list_head
->emitted
= true;
10404 if (list_head
->vl_symbol
&& dwarf2out_locviews_in_attribute ())
10406 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->vl_symbol
);
10408 for (dw_loc_list_ref curr
= list_head
; curr
!= NULL
;
10409 curr
= curr
->dw_loc_next
)
10411 unsigned long size
;
10413 if (skip_loc_list_entry (curr
, &size
))
10418 /* ?? dwarf_split_debug_info? */
10419 if (dwarf2out_as_locview_support
)
10421 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10423 if (!ZERO_VIEW_P (curr
->vbegin
))
10425 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", curr
->vbegin
);
10426 dw2_asm_output_symname_uleb128 (label
,
10427 "View list begin (%s)",
10428 list_head
->vl_symbol
);
10431 dw2_asm_output_data_uleb128 (0,
10432 "View list begin (%s)",
10433 list_head
->vl_symbol
);
10435 if (!ZERO_VIEW_P (curr
->vend
))
10437 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", curr
->vend
);
10438 dw2_asm_output_symname_uleb128 (label
,
10439 "View list end (%s)",
10440 list_head
->vl_symbol
);
10443 dw2_asm_output_data_uleb128 (0,
10444 "View list end (%s)",
10445 list_head
->vl_symbol
);
10449 dw2_asm_output_data_uleb128 (curr
->vbegin
,
10450 "View list begin (%s)",
10451 list_head
->vl_symbol
);
10452 dw2_asm_output_data_uleb128 (curr
->vend
,
10453 "View list end (%s)",
10454 list_head
->vl_symbol
);
10459 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
10461 const char *last_section
= NULL
;
10462 const char *base_label
= NULL
;
10464 /* Walk the location list, and output each range + expression. */
10465 for (dw_loc_list_ref curr
= list_head
; curr
!= NULL
;
10466 curr
= curr
->dw_loc_next
)
10468 unsigned long size
;
10470 /* Skip this entry? If we skip it here, we must skip it in the
10471 view list above as well. */
10472 if (skip_loc_list_entry (curr
, &size
))
10477 if (dwarf_version
>= 5)
10479 if (dwarf_split_debug_info
&& HAVE_AS_LEB128
)
10481 dwarf2out_maybe_output_loclist_view_pair (curr
);
10482 /* For -gsplit-dwarf, emit DW_LLE_startx_length, which has
10483 uleb128 index into .debug_addr and uleb128 length. */
10484 dw2_asm_output_data (1, DW_LLE_startx_length
,
10485 "DW_LLE_startx_length (%s)",
10486 list_head
->ll_symbol
);
10487 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
10488 "Location list range start index "
10489 "(%s)", curr
->begin
);
10490 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->begin
,
10491 "Location list length (%s)",
10492 list_head
->ll_symbol
);
10494 else if (dwarf_split_debug_info
)
10496 dwarf2out_maybe_output_loclist_view_pair (curr
);
10497 /* For -gsplit-dwarf without usable .uleb128 support, emit
10498 DW_LLE_startx_endx, which has two uleb128 indexes into
10500 dw2_asm_output_data (1, DW_LLE_startx_endx
,
10501 "DW_LLE_startx_endx (%s)",
10502 list_head
->ll_symbol
);
10503 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
10504 "Location list range start index "
10505 "(%s)", curr
->begin
);
10506 dw2_asm_output_data_uleb128 (curr
->end_entry
->index
,
10507 "Location list range end index "
10508 "(%s)", curr
->end
);
10510 else if (!have_multiple_function_sections
&& HAVE_AS_LEB128
)
10512 dwarf2out_maybe_output_loclist_view_pair (curr
);
10513 /* If all code is in .text section, the base address is
10514 already provided by the CU attributes. Use
10515 DW_LLE_offset_pair where both addresses are uleb128 encoded
10516 offsets against that base. */
10517 dw2_asm_output_data (1, DW_LLE_offset_pair
,
10518 "DW_LLE_offset_pair (%s)",
10519 list_head
->ll_symbol
);
10520 dw2_asm_output_delta_uleb128 (curr
->begin
, curr
->section
,
10521 "Location list begin address (%s)",
10522 list_head
->ll_symbol
);
10523 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->section
,
10524 "Location list end address (%s)",
10525 list_head
->ll_symbol
);
10527 else if (HAVE_AS_LEB128
)
10529 /* Otherwise, find out how many consecutive entries could share
10530 the same base entry. If just one, emit DW_LLE_start_length,
10531 otherwise emit DW_LLE_base_address for the base address
10532 followed by a series of DW_LLE_offset_pair. */
10533 if (last_section
== NULL
|| curr
->section
!= last_section
)
10535 dw_loc_list_ref curr2
;
10536 for (curr2
= curr
->dw_loc_next
; curr2
!= NULL
;
10537 curr2
= curr2
->dw_loc_next
)
10539 if (strcmp (curr2
->begin
, curr2
->end
) == 0
10544 if (curr2
== NULL
|| curr
->section
!= curr2
->section
)
10545 last_section
= NULL
;
10548 last_section
= curr
->section
;
10549 base_label
= curr
->begin
;
10550 dw2_asm_output_data (1, DW_LLE_base_address
,
10551 "DW_LLE_base_address (%s)",
10552 list_head
->ll_symbol
);
10553 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, base_label
,
10554 "Base address (%s)",
10555 list_head
->ll_symbol
);
10558 /* Only one entry with the same base address. Use
10559 DW_LLE_start_length with absolute address and uleb128
10561 if (last_section
== NULL
)
10563 dwarf2out_maybe_output_loclist_view_pair (curr
);
10564 dw2_asm_output_data (1, DW_LLE_start_length
,
10565 "DW_LLE_start_length (%s)",
10566 list_head
->ll_symbol
);
10567 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
10568 "Location list begin address (%s)",
10569 list_head
->ll_symbol
);
10570 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->begin
,
10571 "Location list length "
10572 "(%s)", list_head
->ll_symbol
);
10574 /* Otherwise emit DW_LLE_offset_pair, relative to above emitted
10575 DW_LLE_base_address. */
10578 dwarf2out_maybe_output_loclist_view_pair (curr
);
10579 dw2_asm_output_data (1, DW_LLE_offset_pair
,
10580 "DW_LLE_offset_pair (%s)",
10581 list_head
->ll_symbol
);
10582 dw2_asm_output_delta_uleb128 (curr
->begin
, base_label
,
10583 "Location list begin address "
10584 "(%s)", list_head
->ll_symbol
);
10585 dw2_asm_output_delta_uleb128 (curr
->end
, base_label
,
10586 "Location list end address "
10587 "(%s)", list_head
->ll_symbol
);
10590 /* The assembler does not support .uleb128 directive. Emit
10591 DW_LLE_start_end with a pair of absolute addresses. */
10594 dwarf2out_maybe_output_loclist_view_pair (curr
);
10595 dw2_asm_output_data (1, DW_LLE_start_end
,
10596 "DW_LLE_start_end (%s)",
10597 list_head
->ll_symbol
);
10598 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
10599 "Location list begin address (%s)",
10600 list_head
->ll_symbol
);
10601 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
10602 "Location list end address (%s)",
10603 list_head
->ll_symbol
);
10606 else if (dwarf_split_debug_info
)
10608 /* For -gsplit-dwarf -gdwarf-{2,3,4} emit index into .debug_addr
10609 and 4 byte length. */
10610 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
10611 "Location list start/length entry (%s)",
10612 list_head
->ll_symbol
);
10613 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
10614 "Location list range start index (%s)",
10616 /* The length field is 4 bytes. If we ever need to support
10617 an 8-byte length, we can add a new DW_LLE code or fall back
10618 to DW_LLE_GNU_start_end_entry. */
10619 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
10620 "Location list range length (%s)",
10621 list_head
->ll_symbol
);
10623 else if (!have_multiple_function_sections
)
10625 /* Pair of relative addresses against start of text section. */
10626 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
10627 "Location list begin address (%s)",
10628 list_head
->ll_symbol
);
10629 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
10630 "Location list end address (%s)",
10631 list_head
->ll_symbol
);
10635 /* Pair of absolute addresses. */
10636 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
10637 "Location list begin address (%s)",
10638 list_head
->ll_symbol
);
10639 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
10640 "Location list end address (%s)",
10641 list_head
->ll_symbol
);
10644 /* Output the block length for this list of location operations. */
10645 if (dwarf_version
>= 5)
10646 dw2_asm_output_data_uleb128 (size
, "Location expression size");
10649 gcc_assert (size
<= 0xffff);
10650 dw2_asm_output_data (2, size
, "Location expression size");
10653 output_loc_sequence (curr
->expr
, -1);
10656 /* And finally list termination. */
10657 if (dwarf_version
>= 5)
10658 dw2_asm_output_data (1, DW_LLE_end_of_list
,
10659 "DW_LLE_end_of_list (%s)", list_head
->ll_symbol
);
10660 else if (dwarf_split_debug_info
)
10661 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
10662 "Location list terminator (%s)",
10663 list_head
->ll_symbol
);
10666 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
10667 "Location list terminator begin (%s)",
10668 list_head
->ll_symbol
);
10669 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
10670 "Location list terminator end (%s)",
10671 list_head
->ll_symbol
);
10674 gcc_assert (!list_head
->vl_symbol
10675 || vcount
== lcount
* (dwarf2out_locviews_in_attribute () ? 1 : 0));
10678 /* Output a range_list offset into the .debug_ranges or .debug_rnglists
10679 section. Emit a relocated reference if val_entry is NULL, otherwise,
10680 emit an indirect reference. */
10683 output_range_list_offset (dw_attr_node
*a
)
10685 const char *name
= dwarf_attr_name (a
->dw_attr
);
10687 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
10689 if (dwarf_version
>= 5)
10691 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
10692 dw2_asm_output_offset (dwarf_offset_size
, r
->label
,
10693 debug_ranges_section
, "%s", name
);
10697 char *p
= strchr (ranges_section_label
, '\0');
10698 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
10699 a
->dw_attr_val
.v
.val_offset
* 2 * DWARF2_ADDR_SIZE
);
10700 dw2_asm_output_offset (dwarf_offset_size
, ranges_section_label
,
10701 debug_ranges_section
, "%s", name
);
10705 else if (dwarf_version
>= 5)
10707 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
10708 gcc_assert (rnglist_idx
);
10709 dw2_asm_output_data_uleb128 (r
->idx
, "%s", name
);
10712 dw2_asm_output_data (dwarf_offset_size
,
10713 a
->dw_attr_val
.v
.val_offset
* 2 * DWARF2_ADDR_SIZE
,
10714 "%s (offset from %s)", name
, ranges_section_label
);
10717 /* Output the offset into the debug_loc section. */
10720 output_loc_list_offset (dw_attr_node
*a
)
10722 char *sym
= AT_loc_list (a
)->ll_symbol
;
10725 if (!dwarf_split_debug_info
)
10726 dw2_asm_output_offset (dwarf_offset_size
, sym
, debug_loc_section
,
10727 "%s", dwarf_attr_name (a
->dw_attr
));
10728 else if (dwarf_version
>= 5)
10730 gcc_assert (AT_loc_list (a
)->num_assigned
);
10731 dw2_asm_output_data_uleb128 (AT_loc_list (a
)->hash
, "%s (%s)",
10732 dwarf_attr_name (a
->dw_attr
),
10736 dw2_asm_output_delta (dwarf_offset_size
, sym
, loc_section_label
,
10737 "%s", dwarf_attr_name (a
->dw_attr
));
10740 /* Output the offset into the debug_loc section. */
10743 output_view_list_offset (dw_attr_node
*a
)
10745 char *sym
= (*AT_loc_list_ptr (a
))->vl_symbol
;
10748 if (dwarf_split_debug_info
)
10749 dw2_asm_output_delta (dwarf_offset_size
, sym
, loc_section_label
,
10750 "%s", dwarf_attr_name (a
->dw_attr
));
10752 dw2_asm_output_offset (dwarf_offset_size
, sym
, debug_loc_section
,
10753 "%s", dwarf_attr_name (a
->dw_attr
));
10756 /* Output an attribute's index or value appropriately. */
10759 output_attr_index_or_value (dw_attr_node
*a
)
10761 const char *name
= dwarf_attr_name (a
->dw_attr
);
10763 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
10765 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
10768 switch (AT_class (a
))
10770 case dw_val_class_addr
:
10771 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
10773 case dw_val_class_high_pc
:
10774 case dw_val_class_lbl_id
:
10775 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
10778 gcc_unreachable ();
10782 /* Output a type signature. */
10785 output_signature (const char *sig
, const char *name
)
10789 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
10790 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
10793 /* Output a discriminant value. */
10796 output_discr_value (dw_discr_value
*discr_value
, const char *name
)
10798 if (discr_value
->pos
)
10799 dw2_asm_output_data_uleb128 (discr_value
->v
.uval
, "%s", name
);
10801 dw2_asm_output_data_sleb128 (discr_value
->v
.sval
, "%s", name
);
10804 /* Output the DIE and its attributes. Called recursively to generate
10805 the definitions of each child DIE. */
10808 output_die (dw_die_ref die
)
10812 unsigned long size
;
10815 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
10816 (unsigned long)die
->die_offset
,
10817 dwarf_tag_name (die
->die_tag
));
10819 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
10821 const char *name
= dwarf_attr_name (a
->dw_attr
);
10823 switch (AT_class (a
))
10825 case dw_val_class_addr
:
10826 output_attr_index_or_value (a
);
10829 case dw_val_class_offset
:
10830 dw2_asm_output_data (dwarf_offset_size
, a
->dw_attr_val
.v
.val_offset
,
10834 case dw_val_class_range_list
:
10835 output_range_list_offset (a
);
10838 case dw_val_class_loc
:
10839 size
= size_of_locs (AT_loc (a
));
10841 /* Output the block length for this list of location operations. */
10842 if (dwarf_version
>= 4)
10843 dw2_asm_output_data_uleb128 (size
, "%s", name
);
10845 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
10847 output_loc_sequence (AT_loc (a
), -1);
10850 case dw_val_class_const
:
10851 /* ??? It would be slightly more efficient to use a scheme like is
10852 used for unsigned constants below, but gdb 4.x does not sign
10853 extend. Gdb 5.x does sign extend. */
10854 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
10857 case dw_val_class_unsigned_const
:
10859 int csize
= constant_size (AT_unsigned (a
));
10860 if (dwarf_version
== 3
10861 && a
->dw_attr
== DW_AT_data_member_location
10863 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
10865 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
10869 case dw_val_class_symview
:
10872 if (symview_upper_bound
<= 0xff)
10874 else if (symview_upper_bound
<= 0xffff)
10876 else if (symview_upper_bound
<= 0xffffffff)
10880 dw2_asm_output_addr (vsize
, a
->dw_attr_val
.v
.val_symbolic_view
,
10885 case dw_val_class_const_implicit
:
10886 if (flag_debug_asm
)
10887 fprintf (asm_out_file
, "\t\t\t%s %s ("
10888 HOST_WIDE_INT_PRINT_DEC
")\n",
10889 ASM_COMMENT_START
, name
, AT_int (a
));
10892 case dw_val_class_unsigned_const_implicit
:
10893 if (flag_debug_asm
)
10894 fprintf (asm_out_file
, "\t\t\t%s %s ("
10895 HOST_WIDE_INT_PRINT_HEX
")\n",
10896 ASM_COMMENT_START
, name
, AT_unsigned (a
));
10899 case dw_val_class_const_double
:
10901 unsigned HOST_WIDE_INT first
, second
;
10903 if (HOST_BITS_PER_WIDE_INT
>= DWARF_LARGEST_DATA_FORM_BITS
)
10904 dw2_asm_output_data (1,
10905 HOST_BITS_PER_DOUBLE_INT
10906 / HOST_BITS_PER_CHAR
,
10909 if (WORDS_BIG_ENDIAN
)
10911 first
= a
->dw_attr_val
.v
.val_double
.high
;
10912 second
= a
->dw_attr_val
.v
.val_double
.low
;
10916 first
= a
->dw_attr_val
.v
.val_double
.low
;
10917 second
= a
->dw_attr_val
.v
.val_double
.high
;
10920 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
10921 first
, "%s", name
);
10922 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
10927 case dw_val_class_wide_int
:
10930 int len
= get_full_len (*a
->dw_attr_val
.v
.val_wide
);
10931 int l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
10932 if (len
* HOST_BITS_PER_WIDE_INT
> DWARF_LARGEST_DATA_FORM_BITS
)
10933 dw2_asm_output_data (1, get_full_len (*a
->dw_attr_val
.v
.val_wide
)
10936 if (WORDS_BIG_ENDIAN
)
10937 for (i
= len
- 1; i
>= 0; --i
)
10939 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
10944 for (i
= 0; i
< len
; ++i
)
10946 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
10953 case dw_val_class_vec
:
10955 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
10956 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
10960 dw2_asm_output_data (constant_size (len
* elt_size
),
10961 len
* elt_size
, "%s", name
);
10962 if (elt_size
> sizeof (HOST_WIDE_INT
))
10967 for (i
= 0, p
= (unsigned char *) a
->dw_attr_val
.v
.val_vec
.array
;
10969 i
++, p
+= elt_size
)
10970 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
10971 "fp or vector constant word %u", i
);
10975 case dw_val_class_flag
:
10976 if (dwarf_version
>= 4)
10978 /* Currently all add_AT_flag calls pass in 1 as last argument,
10979 so DW_FORM_flag_present can be used. If that ever changes,
10980 we'll need to use DW_FORM_flag and have some optimization
10981 in build_abbrev_table that will change those to
10982 DW_FORM_flag_present if it is set to 1 in all DIEs using
10983 the same abbrev entry. */
10984 gcc_assert (AT_flag (a
) == 1);
10985 if (flag_debug_asm
)
10986 fprintf (asm_out_file
, "\t\t\t%s %s\n",
10987 ASM_COMMENT_START
, name
);
10990 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
10993 case dw_val_class_loc_list
:
10994 output_loc_list_offset (a
);
10997 case dw_val_class_view_list
:
10998 output_view_list_offset (a
);
11001 case dw_val_class_die_ref
:
11002 if (AT_ref_external (a
))
11004 if (AT_ref (a
)->comdat_type_p
)
11006 comdat_type_node
*type_node
11007 = AT_ref (a
)->die_id
.die_type_node
;
11009 gcc_assert (type_node
);
11010 output_signature (type_node
->signature
, name
);
11014 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
11018 /* In DWARF2, DW_FORM_ref_addr is sized by target address
11019 length, whereas in DWARF3 it's always sized as an
11021 if (dwarf_version
== 2)
11022 size
= DWARF2_ADDR_SIZE
;
11024 size
= dwarf_offset_size
;
11025 /* ??? We cannot unconditionally output die_offset if
11026 non-zero - others might create references to those
11028 And we do not clear its DIE offset after outputting it
11029 (and the label refers to the actual DIEs, not the
11030 DWARF CU unit header which is when using label + offset
11031 would be the correct thing to do).
11032 ??? This is the reason for the with_offset flag. */
11033 if (AT_ref (a
)->with_offset
)
11034 dw2_asm_output_offset (size
, sym
, AT_ref (a
)->die_offset
,
11035 debug_info_section
, "%s", name
);
11037 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
11043 gcc_assert (AT_ref (a
)->die_offset
);
11044 dw2_asm_output_data (dwarf_offset_size
, AT_ref (a
)->die_offset
,
11049 case dw_val_class_fde_ref
:
11051 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
11053 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
11054 a
->dw_attr_val
.v
.val_fde_index
* 2);
11055 dw2_asm_output_offset (dwarf_offset_size
, l1
, debug_frame_section
,
11060 case dw_val_class_vms_delta
:
11061 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
11062 dw2_asm_output_vms_delta (dwarf_offset_size
,
11063 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
11066 dw2_asm_output_delta (dwarf_offset_size
,
11067 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
11072 case dw_val_class_lbl_id
:
11073 output_attr_index_or_value (a
);
11076 case dw_val_class_lineptr
:
11077 dw2_asm_output_offset (dwarf_offset_size
, AT_lbl (a
),
11078 debug_line_section
, "%s", name
);
11081 case dw_val_class_macptr
:
11082 dw2_asm_output_offset (dwarf_offset_size
, AT_lbl (a
),
11083 debug_macinfo_section
, "%s", name
);
11086 case dw_val_class_loclistsptr
:
11087 dw2_asm_output_offset (dwarf_offset_size
, AT_lbl (a
),
11088 debug_loc_section
, "%s", name
);
11091 case dw_val_class_str
:
11092 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
11093 dw2_asm_output_offset (dwarf_offset_size
,
11094 a
->dw_attr_val
.v
.val_str
->label
,
11096 "%s: \"%s\"", name
, AT_string (a
));
11097 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_line_strp
)
11098 dw2_asm_output_offset (dwarf_offset_size
,
11099 a
->dw_attr_val
.v
.val_str
->label
,
11100 debug_line_str_section
,
11101 "%s: \"%s\"", name
, AT_string (a
));
11102 else if (a
->dw_attr_val
.v
.val_str
->form
== dwarf_FORM (DW_FORM_strx
))
11103 dw2_asm_output_data_uleb128 (AT_index (a
),
11104 "%s: \"%s\"", name
, AT_string (a
));
11106 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
11109 case dw_val_class_file
:
11111 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
11113 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
11114 a
->dw_attr_val
.v
.val_file
->filename
);
11118 case dw_val_class_file_implicit
:
11119 if (flag_debug_asm
)
11120 fprintf (asm_out_file
, "\t\t\t%s %s (%d, %s)\n",
11121 ASM_COMMENT_START
, name
,
11122 maybe_emit_file (a
->dw_attr_val
.v
.val_file
),
11123 a
->dw_attr_val
.v
.val_file
->filename
);
11126 case dw_val_class_data8
:
11130 for (i
= 0; i
< 8; i
++)
11131 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
11132 i
== 0 ? "%s" : NULL
, name
);
11136 case dw_val_class_high_pc
:
11137 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
11138 get_AT_low_pc (die
), "DW_AT_high_pc");
11141 case dw_val_class_discr_value
:
11142 output_discr_value (&a
->dw_attr_val
.v
.val_discr_value
, name
);
11145 case dw_val_class_discr_list
:
11147 dw_discr_list_ref list
= AT_discr_list (a
);
11148 const int size
= size_of_discr_list (list
);
11150 /* This is a block, so output its length first. */
11151 dw2_asm_output_data (constant_size (size
), size
,
11152 "%s: block size", name
);
11154 for (; list
!= NULL
; list
= list
->dw_discr_next
)
11156 /* One byte for the discriminant value descriptor, and then as
11157 many LEB128 numbers as required. */
11158 if (list
->dw_discr_range
)
11159 dw2_asm_output_data (1, DW_DSC_range
,
11160 "%s: DW_DSC_range", name
);
11162 dw2_asm_output_data (1, DW_DSC_label
,
11163 "%s: DW_DSC_label", name
);
11165 output_discr_value (&list
->dw_discr_lower_bound
, name
);
11166 if (list
->dw_discr_range
)
11167 output_discr_value (&list
->dw_discr_upper_bound
, name
);
11173 gcc_unreachable ();
11177 FOR_EACH_CHILD (die
, c
, output_die (c
));
11179 /* Add null byte to terminate sibling list. */
11180 if (die
->die_child
!= NULL
)
11181 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11182 (unsigned long) die
->die_offset
);
11185 /* Output the dwarf version number. */
11188 output_dwarf_version ()
11190 /* ??? For now, if -gdwarf-6 is specified, we output version 5 with
11191 views in loclist. That will change eventually. */
11192 if (dwarf_version
== 6)
11197 warning (0, "%<-gdwarf-6%> is output as version 5 with "
11198 "incompatibilities");
11201 dw2_asm_output_data (2, 5, "DWARF version number");
11204 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
11207 /* Output the compilation unit that appears at the beginning of the
11208 .debug_info section, and precedes the DIE descriptions. */
11211 output_compilation_unit_header (enum dwarf_unit_type ut
)
11213 if (!XCOFF_DEBUGGING_INFO
)
11215 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
11216 dw2_asm_output_data (4, 0xffffffff,
11217 "Initial length escape value indicating 64-bit DWARF extension");
11218 dw2_asm_output_data (dwarf_offset_size
,
11219 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
11220 "Length of Compilation Unit Info");
11223 output_dwarf_version ();
11224 if (dwarf_version
>= 5)
11229 case DW_UT_compile
: name
= "DW_UT_compile"; break;
11230 case DW_UT_type
: name
= "DW_UT_type"; break;
11231 case DW_UT_split_compile
: name
= "DW_UT_split_compile"; break;
11232 case DW_UT_split_type
: name
= "DW_UT_split_type"; break;
11233 default: gcc_unreachable ();
11235 dw2_asm_output_data (1, ut
, "%s", name
);
11236 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
11238 dw2_asm_output_offset (dwarf_offset_size
, abbrev_section_label
,
11239 debug_abbrev_section
,
11240 "Offset Into Abbrev. Section");
11241 if (dwarf_version
< 5)
11242 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
11245 /* Output the compilation unit DIE and its children. */
11248 output_comp_unit (dw_die_ref die
, int output_if_empty
,
11249 const unsigned char *dwo_id
)
11251 const char *secname
, *oldsym
;
11254 /* Unless we are outputting main CU, we may throw away empty ones. */
11255 if (!output_if_empty
&& die
->die_child
== NULL
)
11258 /* Even if there are no children of this DIE, we must output the information
11259 about the compilation unit. Otherwise, on an empty translation unit, we
11260 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
11261 will then complain when examining the file. First mark all the DIEs in
11262 this CU so we know which get local refs. */
11265 external_ref_hash_type
*extern_map
= optimize_external_refs (die
);
11267 /* For now, optimize only the main CU, in order to optimize the rest
11268 we'd need to see all of them earlier. Leave the rest for post-linking
11270 if (die
== comp_unit_die ())
11271 abbrev_opt_start
= vec_safe_length (abbrev_die_table
);
11273 build_abbrev_table (die
, extern_map
);
11275 optimize_abbrev_table ();
11279 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11280 next_die_offset
= (dwo_id
11281 ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
11282 : DWARF_COMPILE_UNIT_HEADER_SIZE
);
11283 calc_die_sizes (die
);
11285 oldsym
= die
->die_id
.die_symbol
;
11286 if (oldsym
&& die
->comdat_type_p
)
11288 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
11290 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
11292 die
->die_id
.die_symbol
= NULL
;
11293 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
11297 switch_to_section (debug_info_section
);
11298 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
11299 info_section_emitted
= true;
11302 /* For LTO cross unit DIE refs we want a symbol on the start of the
11303 debuginfo section, not on the CU DIE. */
11304 if ((flag_generate_lto
|| flag_generate_offload
) && oldsym
)
11306 /* ??? No way to get visibility assembled without a decl. */
11307 tree decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
,
11308 get_identifier (oldsym
), char_type_node
);
11309 TREE_PUBLIC (decl
) = true;
11310 TREE_STATIC (decl
) = true;
11311 DECL_ARTIFICIAL (decl
) = true;
11312 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
11313 DECL_VISIBILITY_SPECIFIED (decl
) = true;
11314 targetm
.asm_out
.assemble_visibility (decl
, VISIBILITY_HIDDEN
);
11315 #ifdef ASM_WEAKEN_LABEL
11316 /* We prefer a .weak because that handles duplicates from duplicate
11317 archive members in a graceful way. */
11318 ASM_WEAKEN_LABEL (asm_out_file
, oldsym
);
11320 targetm
.asm_out
.globalize_label (asm_out_file
, oldsym
);
11322 ASM_OUTPUT_LABEL (asm_out_file
, oldsym
);
11325 /* Output debugging information. */
11326 output_compilation_unit_header (dwo_id
11327 ? DW_UT_split_compile
: DW_UT_compile
);
11328 if (dwarf_version
>= 5)
11330 if (dwo_id
!= NULL
)
11331 for (int i
= 0; i
< 8; i
++)
11332 dw2_asm_output_data (1, dwo_id
[i
], i
== 0 ? "DWO id" : NULL
);
11336 /* Leave the marks on the main CU, so we can check them in
11337 output_pubnames. */
11341 die
->die_id
.die_symbol
= oldsym
;
11345 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
11346 and .debug_pubtypes. This is configured per-target, but can be
11347 overridden by the -gpubnames or -gno-pubnames options. */
11350 want_pubnames (void)
11352 if (debug_info_level
<= DINFO_LEVEL_TERSE
11353 /* Names and types go to the early debug part only. */
11356 if (debug_generate_pub_sections
!= -1)
11357 return debug_generate_pub_sections
;
11358 return targetm
.want_debug_pub_sections
;
11361 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
11364 add_AT_pubnames (dw_die_ref die
)
11366 if (want_pubnames ())
11367 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
11370 /* Add a string attribute value to a skeleton DIE. */
11373 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
11377 struct indirect_string_node
*node
;
11379 if (! skeleton_debug_str_hash
)
11380 skeleton_debug_str_hash
11381 = hash_table
<indirect_string_hasher
>::create_ggc (10);
11383 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
11384 find_string_form (node
);
11385 if (node
->form
== dwarf_FORM (DW_FORM_strx
))
11386 node
->form
= DW_FORM_strp
;
11388 attr
.dw_attr
= attr_kind
;
11389 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
11390 attr
.dw_attr_val
.val_entry
= NULL
;
11391 attr
.dw_attr_val
.v
.val_str
= node
;
11392 add_dwarf_attr (die
, &attr
);
11395 /* Helper function to generate top-level dies for skeleton debug_info and
11399 add_top_level_skeleton_die_attrs (dw_die_ref die
)
11401 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
11402 const char *comp_dir
= comp_dir_string ();
11404 add_skeleton_AT_string (die
, dwarf_AT (DW_AT_dwo_name
), dwo_file_name
);
11405 if (comp_dir
!= NULL
)
11406 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
11407 add_AT_pubnames (die
);
11408 if (addr_index_table
!= NULL
&& addr_index_table
->size () > 0)
11409 add_AT_lineptr (die
, dwarf_AT (DW_AT_addr_base
), debug_addr_section_label
);
11412 /* Output skeleton debug sections that point to the dwo file. */
11415 output_skeleton_debug_sections (dw_die_ref comp_unit
,
11416 const unsigned char *dwo_id
)
11418 /* These attributes will be found in the full debug_info section. */
11419 remove_AT (comp_unit
, DW_AT_producer
);
11420 remove_AT (comp_unit
, DW_AT_language
);
11422 switch_to_section (debug_skeleton_info_section
);
11423 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
11425 /* Produce the skeleton compilation-unit header. This one differs enough from
11426 a normal CU header that it's better not to call output_compilation_unit
11428 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
11429 dw2_asm_output_data (4, 0xffffffff,
11430 "Initial length escape value indicating 64-bit "
11431 "DWARF extension");
11433 dw2_asm_output_data (dwarf_offset_size
,
11434 DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
11435 - DWARF_INITIAL_LENGTH_SIZE
11436 + size_of_die (comp_unit
),
11437 "Length of Compilation Unit Info");
11438 output_dwarf_version ();
11439 if (dwarf_version
>= 5)
11441 dw2_asm_output_data (1, DW_UT_skeleton
, "DW_UT_skeleton");
11442 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
11444 dw2_asm_output_offset (dwarf_offset_size
, debug_skeleton_abbrev_section_label
,
11445 debug_skeleton_abbrev_section
,
11446 "Offset Into Abbrev. Section");
11447 if (dwarf_version
< 5)
11448 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
11450 for (int i
= 0; i
< 8; i
++)
11451 dw2_asm_output_data (1, dwo_id
[i
], i
== 0 ? "DWO id" : NULL
);
11453 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
11454 output_die (comp_unit
);
11456 /* Build the skeleton debug_abbrev section. */
11457 switch_to_section (debug_skeleton_abbrev_section
);
11458 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
11460 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
11462 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
11465 /* Output a comdat type unit DIE and its children. */
11468 output_comdat_type_unit (comdat_type_node
*node
,
11469 bool early_lto_debug ATTRIBUTE_UNUSED
)
11471 const char *secname
;
11474 #if defined (OBJECT_FORMAT_ELF)
11478 /* First mark all the DIEs in this CU so we know which get local refs. */
11479 mark_dies (node
->root_die
);
11481 external_ref_hash_type
*extern_map
= optimize_external_refs (node
->root_die
);
11483 build_abbrev_table (node
->root_die
, extern_map
);
11488 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11489 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
11490 calc_die_sizes (node
->root_die
);
11492 #if defined (OBJECT_FORMAT_ELF)
11493 if (dwarf_version
>= 5)
11495 if (!dwarf_split_debug_info
)
11496 secname
= early_lto_debug
? DEBUG_LTO_INFO_SECTION
: DEBUG_INFO_SECTION
;
11498 secname
= (early_lto_debug
11499 ? DEBUG_LTO_DWO_INFO_SECTION
: DEBUG_DWO_INFO_SECTION
);
11501 else if (!dwarf_split_debug_info
)
11502 secname
= early_lto_debug
? ".gnu.debuglto_.debug_types" : ".debug_types";
11504 secname
= (early_lto_debug
11505 ? ".gnu.debuglto_.debug_types.dwo" : ".debug_types.dwo");
11507 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
11508 sprintf (tmp
, dwarf_version
>= 5 ? "wi." : "wt.");
11509 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
11510 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
11511 comdat_key
= get_identifier (tmp
);
11512 targetm
.asm_out
.named_section (secname
,
11513 SECTION_DEBUG
| SECTION_LINKONCE
,
11516 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
11517 sprintf (tmp
, (dwarf_version
>= 5
11518 ? ".gnu.linkonce.wi." : ".gnu.linkonce.wt."));
11519 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
11520 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
11522 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
11525 /* Output debugging information. */
11526 output_compilation_unit_header (dwarf_split_debug_info
11527 ? DW_UT_split_type
: DW_UT_type
);
11528 output_signature (node
->signature
, "Type Signature");
11529 dw2_asm_output_data (dwarf_offset_size
, node
->type_die
->die_offset
,
11530 "Offset to Type DIE");
11531 output_die (node
->root_die
);
11533 unmark_dies (node
->root_die
);
11536 /* Return the DWARF2/3 pubname associated with a decl. */
11538 static const char *
11539 dwarf2_name (tree decl
, int scope
)
11541 if (DECL_NAMELESS (decl
))
11543 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
11546 /* Add a new entry to .debug_pubnames if appropriate. */
11549 add_pubname_string (const char *str
, dw_die_ref die
)
11554 e
.name
= xstrdup (str
);
11555 vec_safe_push (pubname_table
, e
);
11559 add_pubname (tree decl
, dw_die_ref die
)
11561 if (!want_pubnames ())
11564 /* Don't add items to the table when we expect that the consumer will have
11565 just read the enclosing die. For example, if the consumer is looking at a
11566 class_member, it will either be inside the class already, or will have just
11567 looked up the class to find the member. Either way, searching the class is
11568 faster than searching the index. */
11569 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
11570 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
11572 const char *name
= dwarf2_name (decl
, 1);
11575 add_pubname_string (name
, die
);
11579 /* Add an enumerator to the pubnames section. */
11582 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
11586 gcc_assert (scope_name
);
11587 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
11589 vec_safe_push (pubname_table
, e
);
11592 /* Add a new entry to .debug_pubtypes if appropriate. */
11595 add_pubtype (tree decl
, dw_die_ref die
)
11599 if (!want_pubnames ())
11602 if ((TREE_PUBLIC (decl
)
11603 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
11604 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
11607 const char *scope_name
= "";
11608 const char *sep
= is_cxx () ? "::" : ".";
11611 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
11612 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
11614 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
11615 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
11616 scope_name
= concat (scope_name
, sep
, NULL
);
11622 name
= type_tag (decl
);
11624 name
= lang_hooks
.dwarf_name (decl
, 1);
11626 /* If we don't have a name for the type, there's no point in adding
11627 it to the table. */
11628 if (name
!= NULL
&& name
[0] != '\0')
11631 e
.name
= concat (scope_name
, name
, NULL
);
11632 vec_safe_push (pubtype_table
, e
);
11635 /* Although it might be more consistent to add the pubinfo for the
11636 enumerators as their dies are created, they should only be added if the
11637 enum type meets the criteria above. So rather than re-check the parent
11638 enum type whenever an enumerator die is created, just output them all
11639 here. This isn't protected by the name conditional because anonymous
11640 enums don't have names. */
11641 if (die
->die_tag
== DW_TAG_enumeration_type
)
11645 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
11650 /* Output a single entry in the pubnames table. */
11653 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
11655 dw_die_ref die
= entry
->die
;
11656 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
11658 dw2_asm_output_data (dwarf_offset_size
, die_offset
, "DIE offset");
11660 if (debug_generate_pub_sections
== 2)
11662 /* This logic follows gdb's method for determining the value of the flag
11664 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
11665 switch (die
->die_tag
)
11667 case DW_TAG_typedef
:
11668 case DW_TAG_base_type
:
11669 case DW_TAG_subrange_type
:
11670 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
11671 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
11673 case DW_TAG_enumerator
:
11674 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
11675 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
11677 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
11679 case DW_TAG_subprogram
:
11680 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
11681 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
11683 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
11685 case DW_TAG_constant
:
11686 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
11687 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
11688 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
11690 case DW_TAG_variable
:
11691 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
11692 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
11693 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
11695 case DW_TAG_namespace
:
11696 case DW_TAG_imported_declaration
:
11697 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
11699 case DW_TAG_class_type
:
11700 case DW_TAG_interface_type
:
11701 case DW_TAG_structure_type
:
11702 case DW_TAG_union_type
:
11703 case DW_TAG_enumeration_type
:
11704 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
11706 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
11709 /* An unusual tag. Leave the flag-byte empty. */
11712 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
11713 "GDB-index flags");
11716 dw2_asm_output_nstring (entry
->name
, -1, "external name");
11720 /* Output the public names table used to speed up access to externally
11721 visible names; or the public types table used to find type definitions. */
11724 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
11727 unsigned long pubnames_length
= size_of_pubnames (names
);
11728 pubname_entry
*pub
;
11730 if (!XCOFF_DEBUGGING_INFO
)
11732 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
11733 dw2_asm_output_data (4, 0xffffffff,
11734 "Initial length escape value indicating 64-bit DWARF extension");
11735 dw2_asm_output_data (dwarf_offset_size
, pubnames_length
,
11736 "Pub Info Length");
11739 /* Version number for pubnames/pubtypes is independent of dwarf version. */
11740 dw2_asm_output_data (2, 2, "DWARF pubnames/pubtypes version");
11742 if (dwarf_split_debug_info
)
11743 dw2_asm_output_offset (dwarf_offset_size
, debug_skeleton_info_section_label
,
11744 debug_skeleton_info_section
,
11745 "Offset of Compilation Unit Info");
11747 dw2_asm_output_offset (dwarf_offset_size
, debug_info_section_label
,
11748 debug_info_section
,
11749 "Offset of Compilation Unit Info");
11750 dw2_asm_output_data (dwarf_offset_size
, next_die_offset
,
11751 "Compilation Unit Length");
11753 FOR_EACH_VEC_ELT (*names
, i
, pub
)
11755 if (include_pubname_in_output (names
, pub
))
11757 dw_offset die_offset
= pub
->die
->die_offset
;
11759 /* We shouldn't see pubnames for DIEs outside of the main CU. */
11760 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
11761 gcc_assert (pub
->die
->die_mark
);
11763 /* If we're putting types in their own .debug_types sections,
11764 the .debug_pubtypes table will still point to the compile
11765 unit (not the type unit), so we want to use the offset of
11766 the skeleton DIE (if there is one). */
11767 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
11769 comdat_type_node
*type_node
= pub
->die
->die_id
.die_type_node
;
11771 if (type_node
!= NULL
)
11772 die_offset
= (type_node
->skeleton_die
!= NULL
11773 ? type_node
->skeleton_die
->die_offset
11774 : comp_unit_die ()->die_offset
);
11777 output_pubname (die_offset
, pub
);
11781 dw2_asm_output_data (dwarf_offset_size
, 0, NULL
);
11784 /* Output public names and types tables if necessary. */
11787 output_pubtables (void)
11789 if (!want_pubnames () || !info_section_emitted
)
11792 switch_to_section (debug_pubnames_section
);
11793 output_pubnames (pubname_table
);
11794 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
11795 It shouldn't hurt to emit it always, since pure DWARF2 consumers
11796 simply won't look for the section. */
11797 switch_to_section (debug_pubtypes_section
);
11798 output_pubnames (pubtype_table
);
11802 /* Output the information that goes into the .debug_aranges table.
11803 Namely, define the beginning and ending address range of the
11804 text section generated for this compilation unit. */
11807 output_aranges (void)
11810 unsigned long aranges_length
= size_of_aranges ();
11812 if (!XCOFF_DEBUGGING_INFO
)
11814 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
11815 dw2_asm_output_data (4, 0xffffffff,
11816 "Initial length escape value indicating 64-bit DWARF extension");
11817 dw2_asm_output_data (dwarf_offset_size
, aranges_length
,
11818 "Length of Address Ranges Info");
11821 /* Version number for aranges is still 2, even up to DWARF5. */
11822 dw2_asm_output_data (2, 2, "DWARF aranges version");
11823 if (dwarf_split_debug_info
)
11824 dw2_asm_output_offset (dwarf_offset_size
, debug_skeleton_info_section_label
,
11825 debug_skeleton_info_section
,
11826 "Offset of Compilation Unit Info");
11828 dw2_asm_output_offset (dwarf_offset_size
, debug_info_section_label
,
11829 debug_info_section
,
11830 "Offset of Compilation Unit Info");
11831 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
11832 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
11834 /* We need to align to twice the pointer size here. */
11835 if (DWARF_ARANGES_PAD_SIZE
)
11837 /* Pad using a 2 byte words so that padding is correct for any
11839 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
11840 2 * DWARF2_ADDR_SIZE
);
11841 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
11842 dw2_asm_output_data (2, 0, NULL
);
11845 /* It is necessary not to output these entries if the sections were
11846 not used; if the sections were not used, the length will be 0 and
11847 the address may end up as 0 if the section is discarded by ld
11848 --gc-sections, leaving an invalid (0, 0) entry that can be
11849 confused with the terminator. */
11850 if (switch_text_ranges
)
11852 const char *prev_loc
= text_section_label
;
11856 FOR_EACH_VEC_ELT (*switch_text_ranges
, idx
, loc
)
11859 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, prev_loc
, "Address");
11860 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, loc
, prev_loc
, "Length");
11868 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, prev_loc
, "Address");
11869 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
11870 prev_loc
, "Length");
11874 if (switch_cold_ranges
)
11876 const char *prev_loc
= cold_text_section_label
;
11880 FOR_EACH_VEC_ELT (*switch_cold_ranges
, idx
, loc
)
11883 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, prev_loc
, "Address");
11884 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, loc
, prev_loc
, "Length");
11892 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, prev_loc
, "Address");
11893 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
11894 prev_loc
, "Length");
11898 if (have_multiple_function_sections
)
11903 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
11905 if (fde
->ignored_debug
)
11907 if (!fde
->in_std_section
)
11909 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
11911 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
11912 fde
->dw_fde_begin
, "Length");
11914 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
11916 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
11918 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
11919 fde
->dw_fde_second_begin
, "Length");
11924 /* Output the terminator words. */
11925 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11926 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11929 /* Add a new entry to .debug_ranges. Return its index into
11930 ranges_table vector. */
11932 static unsigned int
11933 add_ranges_num (int num
, bool maybe_new_sec
)
11935 dw_ranges r
= { NULL
, num
, 0, maybe_new_sec
, NULL
, NULL
};
11936 vec_safe_push (ranges_table
, r
);
11937 return vec_safe_length (ranges_table
) - 1;
11940 /* Add a new entry to .debug_ranges corresponding to a block, or a
11941 range terminator if BLOCK is NULL. MAYBE_NEW_SEC is true if
11942 this entry might be in a different section from previous range. */
11944 static unsigned int
11945 add_ranges (const_tree block
, bool maybe_new_sec
)
11947 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0, maybe_new_sec
);
11950 /* Note that (*rnglist_table)[offset] is either a head of a rnglist
11951 chain, or middle entry of a chain that will be directly referred to. */
11954 note_rnglist_head (unsigned int offset
)
11956 if (dwarf_version
< 5 || (*ranges_table
)[offset
].label
)
11958 (*ranges_table
)[offset
].label
= gen_internal_sym ("LLRL");
11961 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
11962 When using dwarf_split_debug_info, address attributes in dies destined
11963 for the final executable should be direct references--setting the
11964 parameter force_direct ensures this behavior. */
11967 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
11968 bool *added
, bool force_direct
)
11970 unsigned int in_use
= vec_safe_length (ranges_by_label
);
11971 unsigned int offset
;
11972 dw_ranges_by_label rbl
= { begin
, end
};
11973 vec_safe_push (ranges_by_label
, rbl
);
11974 offset
= add_ranges_num (-(int)in_use
- 1, true);
11977 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
11979 note_rnglist_head (offset
);
11980 if (dwarf_split_debug_info
&& force_direct
)
11981 (*ranges_table
)[offset
].idx
= DW_RANGES_IDX_SKELETON
;
11985 /* Emit .debug_ranges section. */
11988 output_ranges (void)
11991 static const char *const start_fmt
= "Offset %#x";
11992 const char *fmt
= start_fmt
;
11995 switch_to_section (debug_ranges_section
);
11996 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
11997 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11999 int block_num
= r
->num
;
12003 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
12004 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
12006 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
12007 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
12009 /* If all code is in the text section, then the compilation
12010 unit base address defaults to DW_AT_low_pc, which is the
12011 base of the text section. */
12012 if (!have_multiple_function_sections
)
12014 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
12015 text_section_label
,
12016 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
12017 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
12018 text_section_label
, NULL
);
12021 /* Otherwise, the compilation unit base address is zero,
12022 which allows us to use absolute addresses, and not worry
12023 about whether the target supports cross-section
12027 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
12028 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
12029 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
12035 /* Negative block_num stands for an index into ranges_by_label. */
12036 else if (block_num
< 0)
12038 int lab_idx
= - block_num
- 1;
12040 if (!have_multiple_function_sections
)
12042 gcc_unreachable ();
12044 /* If we ever use add_ranges_by_labels () for a single
12045 function section, all we have to do is to take out
12046 the #if 0 above. */
12047 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
12048 (*ranges_by_label
)[lab_idx
].begin
,
12049 text_section_label
,
12050 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
12051 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
12052 (*ranges_by_label
)[lab_idx
].end
,
12053 text_section_label
, NULL
);
12058 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
12059 (*ranges_by_label
)[lab_idx
].begin
,
12060 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
12061 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
12062 (*ranges_by_label
)[lab_idx
].end
,
12068 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
12069 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
12075 /* Non-zero if .debug_line_str should be used for .debug_line section
12076 strings or strings that are likely shareable with those. */
12077 #define DWARF5_USE_DEBUG_LINE_STR \
12078 (!DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET \
12079 && (DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) != 0 \
12080 /* FIXME: there is no .debug_line_str.dwo section, \
12081 for -gsplit-dwarf we should use DW_FORM_strx instead. */ \
12082 && !dwarf_split_debug_info)
12085 /* Returns TRUE if we are outputting DWARF5 and the assembler supports
12086 DWARF5 .debug_line tables using .debug_line_str or we generate
12087 it ourselves, except for split-dwarf which doesn't have a
12088 .debug_line_str. */
12090 asm_outputs_debug_line_str (void)
12092 if (dwarf_version
>= 5
12093 && ! output_asm_line_debug_info ()
12094 && DWARF5_USE_DEBUG_LINE_STR
)
12098 #if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG)
12099 return !dwarf_split_debug_info
&& dwarf_version
>= 5;
12106 /* Return true if it is beneficial to use DW_RLE_base_address{,x}.
12107 I is index of the following range. */
12110 use_distinct_base_address_for_range (unsigned int i
)
12112 if (i
>= vec_safe_length (ranges_table
))
12115 dw_ranges
*r2
= &(*ranges_table
)[i
];
12116 /* Use DW_RLE_base_address{,x} if there is a next range in the
12117 range list and is guaranteed to be in the same section. */
12118 return r2
->num
!= 0 && r2
->label
== NULL
&& !r2
->maybe_new_sec
;
12121 /* Assign .debug_rnglists indexes and unique indexes into the debug_addr
12122 section when needed. */
12125 index_rnglists (void)
12131 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
12133 if (r
->label
&& r
->idx
!= DW_RANGES_IDX_SKELETON
)
12134 r
->idx
= rnglist_idx
++;
12136 int block_num
= r
->num
;
12137 if ((HAVE_AS_LEB128
|| block_num
< 0)
12138 && !have_multiple_function_sections
)
12140 if (HAVE_AS_LEB128
&& (r
->label
|| r
->maybe_new_sec
))
12144 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
12145 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
12147 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
12148 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
12150 if (HAVE_AS_LEB128
)
12152 if (!base
&& use_distinct_base_address_for_range (i
+ 1))
12154 r
->begin_entry
= add_addr_table_entry (xstrdup (blabel
),
12159 /* If we have a base, no need for further
12160 begin_entry/end_entry, as DW_RLE_offset_pair will be
12164 = add_addr_table_entry (xstrdup (blabel
), ate_kind_label
);
12165 /* No need for end_entry, DW_RLE_start{,x}_length will use
12166 length as opposed to a pair of addresses. */
12171 = add_addr_table_entry (xstrdup (blabel
), ate_kind_label
);
12173 = add_addr_table_entry (xstrdup (elabel
), ate_kind_label
);
12177 /* Negative block_num stands for an index into ranges_by_label. */
12178 else if (block_num
< 0)
12180 int lab_idx
= - block_num
- 1;
12181 const char *blabel
= (*ranges_by_label
)[lab_idx
].begin
;
12182 const char *elabel
= (*ranges_by_label
)[lab_idx
].end
;
12185 = add_addr_table_entry (xstrdup (blabel
), ate_kind_label
);
12186 if (!HAVE_AS_LEB128
)
12188 = add_addr_table_entry (xstrdup (elabel
), ate_kind_label
);
12193 /* Emit .debug_rnglists or (when DWO is true) .debug_rnglists.dwo section. */
12196 output_rnglists (unsigned generation
, bool dwo
)
12200 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
12201 char l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
12202 char basebuf
[MAX_ARTIFICIAL_LABEL_BYTES
];
12205 switch_to_section (debug_ranges_dwo_section
);
12208 switch_to_section (debug_ranges_section
);
12209 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
12211 /* There are up to 4 unique ranges labels per generation.
12212 See also init_sections_and_labels. */
12213 ASM_GENERATE_INTERNAL_LABEL (l1
, DEBUG_RANGES_SECTION_LABEL
,
12214 2 + 2 * dwo
+ generation
* 6);
12215 ASM_GENERATE_INTERNAL_LABEL (l2
, DEBUG_RANGES_SECTION_LABEL
,
12216 3 + 2 * dwo
+ generation
* 6);
12217 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
12218 dw2_asm_output_data (4, 0xffffffff,
12219 "Initial length escape value indicating "
12220 "64-bit DWARF extension");
12221 dw2_asm_output_delta (dwarf_offset_size
, l2
, l1
,
12222 "Length of Range Lists");
12223 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
12224 output_dwarf_version ();
12225 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
12226 dw2_asm_output_data (1, 0, "Segment Size");
12227 /* Emit the offset table only for -gsplit-dwarf. If we don't care
12228 about relocation sizes and primarily care about the size of .debug*
12229 sections in linked shared libraries and executables, then
12230 the offset table plus corresponding DW_FORM_rnglistx uleb128 indexes
12231 into it are usually larger than just DW_FORM_sec_offset offsets
12232 into the .debug_rnglists section. */
12233 dw2_asm_output_data (4, dwo
? rnglist_idx
: 0,
12234 "Offset Entry Count");
12237 ASM_OUTPUT_LABEL (asm_out_file
, ranges_base_label
);
12238 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
12239 if (r
->label
&& r
->idx
!= DW_RANGES_IDX_SKELETON
)
12240 dw2_asm_output_delta (dwarf_offset_size
, r
->label
,
12241 ranges_base_label
, NULL
);
12244 const char *lab
= "";
12245 const char *base
= NULL
;
12246 bool skipping
= false;
12248 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
12250 int block_num
= r
->num
;
12254 if (dwarf_split_debug_info
12255 && (r
->idx
== DW_RANGES_IDX_SKELETON
) == dwo
)
12261 ASM_OUTPUT_LABEL (asm_out_file
, r
->label
);
12266 if (block_num
== 0)
12270 if (HAVE_AS_LEB128
&& (r
->label
|| r
->maybe_new_sec
))
12274 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
12275 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
12277 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
12278 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
12280 if (HAVE_AS_LEB128
)
12282 /* If all code is in the text section, then the compilation
12283 unit base address defaults to DW_AT_low_pc, which is the
12284 base of the text section. */
12285 if (!have_multiple_function_sections
)
12287 dw2_asm_output_data (1, DW_RLE_offset_pair
,
12288 "DW_RLE_offset_pair (%s)", lab
);
12289 dw2_asm_output_delta_uleb128 (blabel
, text_section_label
,
12290 "Range begin address (%s)", lab
);
12291 dw2_asm_output_delta_uleb128 (elabel
, text_section_label
,
12292 "Range end address (%s)", lab
);
12295 if (base
== NULL
&& use_distinct_base_address_for_range (i
+ 1))
12297 if (dwarf_split_debug_info
)
12299 dw2_asm_output_data (1, DW_RLE_base_addressx
,
12300 "DW_RLE_base_addressx (%s)", lab
);
12301 dw2_asm_output_data_uleb128 (r
->begin_entry
->index
,
12302 "Base address index (%s)",
12307 dw2_asm_output_data (1, DW_RLE_base_address
,
12308 "DW_RLE_base_address (%s)", lab
);
12309 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
12310 "Base address (%s)", lab
);
12312 strcpy (basebuf
, blabel
);
12317 dw2_asm_output_data (1, DW_RLE_offset_pair
,
12318 "DW_RLE_offset_pair (%s)", lab
);
12319 dw2_asm_output_delta_uleb128 (blabel
, base
,
12320 "Range begin address (%s)", lab
);
12321 dw2_asm_output_delta_uleb128 (elabel
, base
,
12322 "Range end address (%s)", lab
);
12325 if (dwarf_split_debug_info
)
12327 dw2_asm_output_data (1, DW_RLE_startx_length
,
12328 "DW_RLE_startx_length (%s)", lab
);
12329 dw2_asm_output_data_uleb128 (r
->begin_entry
->index
,
12330 "Range begin address index "
12335 dw2_asm_output_data (1, DW_RLE_start_length
,
12336 "DW_RLE_start_length (%s)", lab
);
12337 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
12338 "Range begin address (%s)", lab
);
12340 dw2_asm_output_delta_uleb128 (elabel
, blabel
,
12341 "Range length (%s)", lab
);
12343 else if (dwarf_split_debug_info
)
12345 dw2_asm_output_data (1, DW_RLE_startx_endx
,
12346 "DW_RLE_startx_endx (%s)", lab
);
12347 dw2_asm_output_data_uleb128 (r
->begin_entry
->index
,
12348 "Range begin address index "
12350 dw2_asm_output_data_uleb128 (r
->end_entry
->index
,
12351 "Range end address index "
12356 dw2_asm_output_data (1, DW_RLE_start_end
,
12357 "DW_RLE_start_end (%s)", lab
);
12358 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
12359 "Range begin address (%s)", lab
);
12360 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
,
12361 "Range end address (%s)", lab
);
12365 /* Negative block_num stands for an index into ranges_by_label. */
12366 else if (block_num
< 0)
12368 int lab_idx
= - block_num
- 1;
12369 const char *blabel
= (*ranges_by_label
)[lab_idx
].begin
;
12370 const char *elabel
= (*ranges_by_label
)[lab_idx
].end
;
12372 if (!have_multiple_function_sections
)
12373 gcc_unreachable ();
12374 if (HAVE_AS_LEB128
)
12376 if (dwarf_split_debug_info
)
12378 dw2_asm_output_data (1, DW_RLE_startx_length
,
12379 "DW_RLE_startx_length (%s)", lab
);
12380 dw2_asm_output_data_uleb128 (r
->begin_entry
->index
,
12381 "Range begin address index "
12386 dw2_asm_output_data (1, DW_RLE_start_length
,
12387 "DW_RLE_start_length (%s)", lab
);
12388 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
12389 "Range begin address (%s)", lab
);
12391 dw2_asm_output_delta_uleb128 (elabel
, blabel
,
12392 "Range length (%s)", lab
);
12394 else if (dwarf_split_debug_info
)
12396 dw2_asm_output_data (1, DW_RLE_startx_endx
,
12397 "DW_RLE_startx_endx (%s)", lab
);
12398 dw2_asm_output_data_uleb128 (r
->begin_entry
->index
,
12399 "Range begin address index "
12401 dw2_asm_output_data_uleb128 (r
->end_entry
->index
,
12402 "Range end address index "
12407 dw2_asm_output_data (1, DW_RLE_start_end
,
12408 "DW_RLE_start_end (%s)", lab
);
12409 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
12410 "Range begin address (%s)", lab
);
12411 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
,
12412 "Range end address (%s)", lab
);
12416 dw2_asm_output_data (1, DW_RLE_end_of_list
,
12417 "DW_RLE_end_of_list (%s)", lab
);
12419 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
12423 /* Data structure containing information about input files. */
12426 const char *path
; /* Complete file name. */
12427 const char *fname
; /* File name part. */
12428 int length
; /* Length of entire string. */
12429 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
12430 int dir_idx
; /* Index in directory table. */
12433 /* Data structure containing information about directories with source
12437 const char *path
; /* Path including directory name. */
12438 int length
; /* Path length. */
12439 int prefix
; /* Index of directory entry which is a prefix. */
12440 int count
; /* Number of files in this directory. */
12441 int dir_idx
; /* Index of directory used as base. */
12444 /* Callback function for file_info comparison. We sort by looking at
12445 the directories in the path. */
12448 file_info_cmp (const void *p1
, const void *p2
)
12450 const struct file_info
*const s1
= (const struct file_info
*) p1
;
12451 const struct file_info
*const s2
= (const struct file_info
*) p2
;
12452 const unsigned char *cp1
;
12453 const unsigned char *cp2
;
12455 /* Take care of file names without directories. We need to make sure that
12456 we return consistent values to qsort since some will get confused if
12457 we return the same value when identical operands are passed in opposite
12458 orders. So if neither has a directory, return 0 and otherwise return
12459 1 or -1 depending on which one has the directory. We want the one with
12460 the directory to sort after the one without, so all no directory files
12461 are at the start (normally only the compilation unit file). */
12462 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
12463 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
12465 cp1
= (const unsigned char *) s1
->path
;
12466 cp2
= (const unsigned char *) s2
->path
;
12472 /* Reached the end of the first path? If so, handle like above,
12473 but now we want longer directory prefixes before shorter ones. */
12474 if ((cp1
== (const unsigned char *) s1
->fname
)
12475 || (cp2
== (const unsigned char *) s2
->fname
))
12476 return ((cp1
== (const unsigned char *) s1
->fname
)
12477 - (cp2
== (const unsigned char *) s2
->fname
));
12479 /* Character of current path component the same? */
12480 else if (*cp1
!= *cp2
)
12481 return *cp1
- *cp2
;
12485 struct file_name_acquire_data
12487 struct file_info
*files
;
12492 /* Traversal function for the hash table. */
12495 file_name_acquire (dwarf_file_data
**slot
, file_name_acquire_data
*fnad
)
12497 struct dwarf_file_data
*d
= *slot
;
12498 struct file_info
*fi
;
12501 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
12503 if (! d
->emitted_number
)
12506 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
12508 fi
= fnad
->files
+ fnad
->used_files
++;
12512 /* Skip all leading "./". */
12513 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
12516 /* Create a new array entry. */
12518 fi
->length
= strlen (f
);
12521 /* Search for the file name part. */
12522 f
= strrchr (f
, DIR_SEPARATOR
);
12523 #if defined (DIR_SEPARATOR_2)
12525 const char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
12529 if (f
== NULL
|| f
< g
)
12535 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
12539 /* Helper function for output_file_names. Emit a FORM encoded
12540 string STR, with assembly comment start ENTRY_KIND and
12544 output_line_string (enum dwarf_form form
, const char *str
,
12545 const char *entry_kind
, unsigned int idx
)
12549 case DW_FORM_string
:
12550 dw2_asm_output_nstring (str
, -1, "%s: %#x", entry_kind
, idx
);
12552 case DW_FORM_line_strp
:
12553 if (!debug_line_str_hash
)
12554 debug_line_str_hash
12555 = hash_table
<indirect_string_hasher
>::create_ggc (10);
12557 struct indirect_string_node
*node
;
12558 node
= find_AT_string_in_table (str
, debug_line_str_hash
);
12559 set_indirect_string (node
);
12561 dw2_asm_output_offset (dwarf_offset_size
, node
->label
,
12562 debug_line_str_section
, "%s: %#x: \"%s\"",
12563 entry_kind
, 0, node
->str
);
12566 gcc_unreachable ();
12570 /* Output the directory table and the file name table. We try to minimize
12571 the total amount of memory needed. A heuristic is used to avoid large
12572 slowdowns with many input files. */
12575 output_file_names (void)
12577 struct file_name_acquire_data fnad
;
12579 struct file_info
*files
;
12580 struct dir_info
*dirs
;
12588 if (!last_emitted_file
)
12590 if (dwarf_version
>= 5)
12592 const char *comp_dir
= comp_dir_string ();
12593 if (comp_dir
== NULL
)
12595 dw2_asm_output_data (1, 1, "Directory entry format count");
12596 enum dwarf_form str_form
= DW_FORM_string
;
12597 if (DWARF5_USE_DEBUG_LINE_STR
)
12598 str_form
= DW_FORM_line_strp
;
12599 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
12600 dw2_asm_output_data_uleb128 (str_form
, "%s",
12601 get_DW_FORM_name (str_form
));
12602 dw2_asm_output_data_uleb128 (1, "Directories count");
12603 if (str_form
== DW_FORM_string
)
12604 dw2_asm_output_nstring (comp_dir
, -1, "Directory Entry: %#x", 0);
12606 output_line_string (str_form
, comp_dir
, "Directory Entry", 0);
12607 const char *filename0
= get_AT_string (comp_unit_die (), DW_AT_name
);
12608 if (filename0
== NULL
)
12610 #ifdef VMS_DEBUGGING_INFO
12611 dw2_asm_output_data (1, 4, "File name entry format count");
12613 dw2_asm_output_data (1, 2, "File name entry format count");
12615 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
12616 dw2_asm_output_data_uleb128 (str_form
, "%s",
12617 get_DW_FORM_name (str_form
));
12618 dw2_asm_output_data_uleb128 (DW_LNCT_directory_index
,
12619 "DW_LNCT_directory_index");
12620 dw2_asm_output_data_uleb128 (DW_FORM_data1
, "%s",
12621 get_DW_FORM_name (DW_FORM_data1
));
12622 #ifdef VMS_DEBUGGING_INFO
12623 dw2_asm_output_data_uleb128 (DW_LNCT_timestamp
, "DW_LNCT_timestamp");
12624 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
12625 dw2_asm_output_data_uleb128 (DW_LNCT_size
, "DW_LNCT_size");
12626 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
12628 dw2_asm_output_data_uleb128 (1, "File names count");
12630 output_line_string (str_form
, filename0
, "File Entry", 0);
12631 dw2_asm_output_data (1, 0, NULL
);
12632 #ifdef VMS_DEBUGGING_INFO
12633 dw2_asm_output_data_uleb128 (0, NULL
);
12634 dw2_asm_output_data_uleb128 (0, NULL
);
12639 dw2_asm_output_data (1, 0, "End directory table");
12640 dw2_asm_output_data (1, 0, "End file name table");
12645 numfiles
= last_emitted_file
->emitted_number
;
12647 /* Allocate the various arrays we need. */
12648 files
= XALLOCAVEC (struct file_info
, numfiles
);
12649 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
12651 fnad
.files
= files
;
12652 fnad
.used_files
= 0;
12653 fnad
.max_files
= numfiles
;
12654 file_table
->traverse
<file_name_acquire_data
*, file_name_acquire
> (&fnad
);
12655 gcc_assert (fnad
.used_files
== fnad
.max_files
);
12657 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
12659 /* Find all the different directories used. */
12660 dirs
[0].path
= files
[0].path
;
12661 dirs
[0].length
= files
[0].fname
- files
[0].path
;
12662 dirs
[0].prefix
= -1;
12664 dirs
[0].dir_idx
= 0;
12665 files
[0].dir_idx
= 0;
12668 for (i
= 1; i
< numfiles
; i
++)
12669 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
12670 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
12671 dirs
[ndirs
- 1].length
) == 0)
12673 /* Same directory as last entry. */
12674 files
[i
].dir_idx
= ndirs
- 1;
12675 ++dirs
[ndirs
- 1].count
;
12681 /* This is a new directory. */
12682 dirs
[ndirs
].path
= files
[i
].path
;
12683 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
12684 dirs
[ndirs
].count
= 1;
12685 dirs
[ndirs
].dir_idx
= ndirs
;
12686 files
[i
].dir_idx
= ndirs
;
12688 /* Search for a prefix. */
12689 dirs
[ndirs
].prefix
= -1;
12690 for (j
= 0; j
< ndirs
; j
++)
12691 if (dirs
[j
].length
< dirs
[ndirs
].length
12692 && dirs
[j
].length
> 1
12693 && (dirs
[ndirs
].prefix
== -1
12694 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
12695 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
12696 dirs
[ndirs
].prefix
= j
;
12701 /* Now to the actual work. We have to find a subset of the directories which
12702 allow expressing the file name using references to the directory table
12703 with the least amount of characters. We do not do an exhaustive search
12704 where we would have to check out every combination of every single
12705 possible prefix. Instead we use a heuristic which provides nearly optimal
12706 results in most cases and never is much off. */
12707 saved
= XALLOCAVEC (int, ndirs
);
12708 savehere
= XALLOCAVEC (int, ndirs
);
12710 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
12711 for (i
= 0; i
< ndirs
; i
++)
12716 /* We can always save some space for the current directory. But this
12717 does not mean it will be enough to justify adding the directory. */
12718 savehere
[i
] = dirs
[i
].length
;
12719 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
12721 for (j
= i
+ 1; j
< ndirs
; j
++)
12724 if (saved
[j
] < dirs
[i
].length
)
12726 /* Determine whether the dirs[i] path is a prefix of the
12730 k
= dirs
[j
].prefix
;
12731 while (k
!= -1 && k
!= (int) i
)
12732 k
= dirs
[k
].prefix
;
12736 /* Yes it is. We can possibly save some memory by
12737 writing the filenames in dirs[j] relative to
12739 savehere
[j
] = dirs
[i
].length
;
12740 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
12745 /* Check whether we can save enough to justify adding the dirs[i]
12747 if (total
> dirs
[i
].length
+ 1)
12749 /* It's worthwhile adding. */
12750 for (j
= i
; j
< ndirs
; j
++)
12751 if (savehere
[j
] > 0)
12753 /* Remember how much we saved for this directory so far. */
12754 saved
[j
] = savehere
[j
];
12756 /* Remember the prefix directory. */
12757 dirs
[j
].dir_idx
= i
;
12762 /* Emit the directory name table. */
12763 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
12764 enum dwarf_form str_form
= DW_FORM_string
;
12765 enum dwarf_form idx_form
= DW_FORM_udata
;
12766 if (dwarf_version
>= 5)
12768 const char *comp_dir
= comp_dir_string ();
12769 if (comp_dir
== NULL
)
12771 dw2_asm_output_data (1, 1, "Directory entry format count");
12772 if (DWARF5_USE_DEBUG_LINE_STR
)
12773 str_form
= DW_FORM_line_strp
;
12774 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
12775 dw2_asm_output_data_uleb128 (str_form
, "%s",
12776 get_DW_FORM_name (str_form
));
12777 dw2_asm_output_data_uleb128 (ndirs
+ idx_offset
, "Directories count");
12778 if (str_form
== DW_FORM_string
)
12780 dw2_asm_output_nstring (comp_dir
, -1, "Directory Entry: %#x", 0);
12781 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
12782 dw2_asm_output_nstring (dirs
[i
].path
,
12784 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
12785 "Directory Entry: %#x", i
+ idx_offset
);
12789 output_line_string (str_form
, comp_dir
, "Directory Entry", 0);
12790 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
12793 = ggc_alloc_string (dirs
[i
].path
,
12795 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
);
12796 output_line_string (str_form
, str
, "Directory Entry",
12797 (unsigned) i
+ idx_offset
);
12803 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
12804 dw2_asm_output_nstring (dirs
[i
].path
,
12806 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
12807 "Directory Entry: %#x", i
+ idx_offset
);
12809 dw2_asm_output_data (1, 0, "End directory table");
12812 /* We have to emit them in the order of emitted_number since that's
12813 used in the debug info generation. To do this efficiently we
12814 generate a back-mapping of the indices first. */
12815 backmap
= XALLOCAVEC (int, numfiles
);
12816 for (i
= 0; i
< numfiles
; i
++)
12817 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
12819 if (dwarf_version
>= 5)
12821 const char *filename0
= get_AT_string (comp_unit_die (), DW_AT_name
);
12822 if (filename0
== NULL
)
12824 /* DW_LNCT_directory_index can use DW_FORM_udata, DW_FORM_data1 and
12825 DW_FORM_data2. Choose one based on the number of directories
12826 and how much space would they occupy in each encoding.
12827 If we have at most 256 directories, all indexes fit into
12828 a single byte, so DW_FORM_data1 is most compact (if there
12829 are at most 128 directories, DW_FORM_udata would be as
12830 compact as that, but not shorter and slower to decode). */
12831 if (ndirs
+ idx_offset
<= 256)
12832 idx_form
= DW_FORM_data1
;
12833 /* If there are more than 65536 directories, we have to use
12834 DW_FORM_udata, DW_FORM_data2 can't refer to them.
12835 Otherwise, compute what space would occupy if all the indexes
12836 used DW_FORM_udata - sum - and compare that to how large would
12837 be DW_FORM_data2 encoding, and pick the more efficient one. */
12838 else if (ndirs
+ idx_offset
<= 65536)
12840 unsigned HOST_WIDE_INT sum
= 1;
12841 for (i
= 0; i
< numfiles
; i
++)
12843 int file_idx
= backmap
[i
];
12844 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
12845 sum
+= size_of_uleb128 (dir_idx
);
12847 if (sum
>= HOST_WIDE_INT_UC (2) * (numfiles
+ 1))
12848 idx_form
= DW_FORM_data2
;
12850 #ifdef VMS_DEBUGGING_INFO
12851 dw2_asm_output_data (1, 4, "File name entry format count");
12853 dw2_asm_output_data (1, 2, "File name entry format count");
12855 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
12856 dw2_asm_output_data_uleb128 (str_form
, "%s",
12857 get_DW_FORM_name (str_form
));
12858 dw2_asm_output_data_uleb128 (DW_LNCT_directory_index
,
12859 "DW_LNCT_directory_index");
12860 dw2_asm_output_data_uleb128 (idx_form
, "%s",
12861 get_DW_FORM_name (idx_form
));
12862 #ifdef VMS_DEBUGGING_INFO
12863 dw2_asm_output_data_uleb128 (DW_LNCT_timestamp
, "DW_LNCT_timestamp");
12864 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
12865 dw2_asm_output_data_uleb128 (DW_LNCT_size
, "DW_LNCT_size");
12866 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
12868 dw2_asm_output_data_uleb128 (numfiles
+ 1, "File names count");
12870 output_line_string (str_form
, filename0
, "File Entry", 0);
12872 /* Include directory index. */
12873 if (idx_form
!= DW_FORM_udata
)
12874 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
12877 dw2_asm_output_data_uleb128 (0, NULL
);
12879 #ifdef VMS_DEBUGGING_INFO
12880 dw2_asm_output_data_uleb128 (0, NULL
);
12881 dw2_asm_output_data_uleb128 (0, NULL
);
12885 /* Now write all the file names. */
12886 for (i
= 0; i
< numfiles
; i
++)
12888 int file_idx
= backmap
[i
];
12889 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
12891 #ifdef VMS_DEBUGGING_INFO
12892 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
12894 /* Setting these fields can lead to debugger miscomparisons,
12895 but VMS Debug requires them to be set correctly. */
12900 int maxfilelen
= (strlen (files
[file_idx
].path
)
12901 + dirs
[dir_idx
].length
12902 + MAX_VMS_VERSION_LEN
+ 1);
12903 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
12905 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
12906 snprintf (filebuf
, maxfilelen
, "%s;%d",
12907 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
12909 output_line_string (str_form
, filebuf
, "File Entry", (unsigned) i
+ 1);
12911 /* Include directory index. */
12912 if (dwarf_version
>= 5 && idx_form
!= DW_FORM_udata
)
12913 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
12914 dir_idx
+ idx_offset
, NULL
);
12916 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
12918 /* Modification time. */
12919 dw2_asm_output_data_uleb128 ((vms_file_stats_name (files
[file_idx
].path
,
12920 &cdt
, 0, 0, 0) == 0)
12923 /* File length in bytes. */
12924 dw2_asm_output_data_uleb128 ((vms_file_stats_name (files
[file_idx
].path
,
12925 0, &siz
, 0, 0) == 0)
12928 output_line_string (str_form
,
12929 files
[file_idx
].path
+ dirs
[dir_idx
].length
,
12930 "File Entry", (unsigned) i
+ 1);
12932 /* Include directory index. */
12933 if (dwarf_version
>= 5 && idx_form
!= DW_FORM_udata
)
12934 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
12935 dir_idx
+ idx_offset
, NULL
);
12937 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
12939 if (dwarf_version
>= 5)
12942 /* Modification time. */
12943 dw2_asm_output_data_uleb128 (0, NULL
);
12945 /* File length in bytes. */
12946 dw2_asm_output_data_uleb128 (0, NULL
);
12947 #endif /* VMS_DEBUGGING_INFO */
12950 if (dwarf_version
< 5)
12951 dw2_asm_output_data (1, 0, "End file name table");
12955 /* Output one line number table into the .debug_line section. */
12958 output_one_line_info_table (dw_line_info_table
*table
)
12960 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
12961 unsigned int current_line
= 1;
12962 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
12963 dw_line_info_entry
*ent
, *prev_addr
= NULL
;
12969 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
12971 switch (ent
->opcode
)
12973 case LI_set_address
:
12974 /* ??? Unfortunately, we have little choice here currently, and
12975 must always use the most general form. GCC does not know the
12976 address delta itself, so we can't use DW_LNS_advance_pc. Many
12977 ports do have length attributes which will give an upper bound
12978 on the address range. We could perhaps use length attributes
12979 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
12980 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
12984 /* This can handle any delta. This takes
12985 4+DWARF2_ADDR_SIZE bytes. */
12986 dw2_asm_output_data (1, 0, "set address %s%s", line_label
,
12987 debug_variable_location_views
12988 ? ", reset view to 0" : "");
12989 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
12990 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
12991 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
12996 case LI_adv_address
:
12998 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
12999 char prev_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
13000 ASM_GENERATE_INTERNAL_LABEL (prev_label
, LINE_CODE_LABEL
, prev_addr
->val
);
13004 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
, "fixed advance PC, increment view to %i", view
);
13005 dw2_asm_output_delta (2, line_label
, prev_label
,
13006 "from %s to %s", prev_label
, line_label
);
13013 if (ent
->val
== current_line
)
13015 /* We still need to start a new row, so output a copy insn. */
13016 dw2_asm_output_data (1, DW_LNS_copy
,
13017 "copy line %u", current_line
);
13021 int line_offset
= ent
->val
- current_line
;
13022 int line_delta
= line_offset
- DWARF_LINE_BASE
;
13024 current_line
= ent
->val
;
13025 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
13027 /* This can handle deltas from -10 to 234, using the current
13028 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
13029 This takes 1 byte. */
13030 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
13031 "line %u", current_line
);
13035 /* This can handle any delta. This takes at least 4 bytes,
13036 depending on the value being encoded. */
13037 dw2_asm_output_data (1, DW_LNS_advance_line
,
13038 "advance to line %u", current_line
);
13039 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
13040 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
13046 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
13047 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
13050 case LI_set_column
:
13051 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
13052 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
13055 case LI_negate_stmt
:
13056 current_is_stmt
= !current_is_stmt
;
13057 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
13058 "is_stmt %d", current_is_stmt
);
13061 case LI_set_prologue_end
:
13062 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
13063 "set prologue end");
13066 case LI_set_epilogue_begin
:
13067 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
13068 "set epilogue begin");
13071 case LI_set_discriminator
:
13072 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
13073 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
13074 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
13075 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
13080 /* Emit debug info for the address of the end of the table. */
13081 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
13082 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
13083 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
13084 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
13086 dw2_asm_output_data (1, 0, "end sequence");
13087 dw2_asm_output_data_uleb128 (1, NULL
);
13088 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
13091 static unsigned int output_line_info_generation
;
13093 /* Output the source line number correspondence information. This
13094 information goes into the .debug_line section. */
13097 output_line_info (bool prologue_only
)
13099 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
13100 char p1
[MAX_ARTIFICIAL_LABEL_BYTES
], p2
[MAX_ARTIFICIAL_LABEL_BYTES
];
13101 bool saw_one
= false;
13104 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
,
13105 output_line_info_generation
);
13106 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
,
13107 output_line_info_generation
);
13108 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
,
13109 output_line_info_generation
);
13110 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
,
13111 output_line_info_generation
++);
13113 if (!XCOFF_DEBUGGING_INFO
)
13115 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
13116 dw2_asm_output_data (4, 0xffffffff,
13117 "Initial length escape value indicating 64-bit DWARF extension");
13118 dw2_asm_output_delta (dwarf_offset_size
, l2
, l1
,
13119 "Length of Source Line Info");
13122 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
13124 output_dwarf_version ();
13125 if (dwarf_version
>= 5)
13127 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
13128 dw2_asm_output_data (1, 0, "Segment Size");
13130 dw2_asm_output_delta (dwarf_offset_size
, p2
, p1
, "Prolog Length");
13131 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
13133 /* Define the architecture-dependent minimum instruction length (in bytes).
13134 In this implementation of DWARF, this field is used for information
13135 purposes only. Since GCC generates assembly language, we have no
13136 a priori knowledge of how many instruction bytes are generated for each
13137 source line, and therefore can use only the DW_LNE_set_address and
13138 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
13139 this as '1', which is "correct enough" for all architectures,
13140 and don't let the target override. */
13141 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
13143 if (dwarf_version
>= 4)
13144 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
13145 "Maximum Operations Per Instruction");
13146 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
13147 "Default is_stmt_start flag");
13148 dw2_asm_output_data (1, DWARF_LINE_BASE
,
13149 "Line Base Value (Special Opcodes)");
13150 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
13151 "Line Range Value (Special Opcodes)");
13152 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
13153 "Special Opcode Base");
13155 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
13160 case DW_LNS_advance_pc
:
13161 case DW_LNS_advance_line
:
13162 case DW_LNS_set_file
:
13163 case DW_LNS_set_column
:
13164 case DW_LNS_fixed_advance_pc
:
13165 case DW_LNS_set_isa
:
13173 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
13177 /* Write out the information about the files we use. */
13178 output_file_names ();
13179 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
13182 /* Output the marker for the end of the line number info. */
13183 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
13187 if (separate_line_info
)
13189 dw_line_info_table
*table
;
13192 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
13195 output_one_line_info_table (table
);
13199 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
13201 output_one_line_info_table (cold_text_section_line_info
);
13205 /* ??? Some Darwin linkers crash on a .debug_line section with no
13206 sequences. Further, merely a DW_LNE_end_sequence entry is not
13207 sufficient -- the address column must also be initialized.
13208 Make sure to output at least one set_address/end_sequence pair,
13209 choosing .text since that section is always present. */
13210 if (text_section_line_info
->in_use
|| !saw_one
)
13211 output_one_line_info_table (text_section_line_info
);
13213 /* Output the marker for the end of the line number info. */
13214 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
13217 /* Return true if DW_AT_endianity should be emitted according to REVERSE. */
13220 need_endianity_attribute_p (bool reverse
)
13222 return reverse
&& (dwarf_version
>= 3 || !dwarf_strict
);
13225 /* Given a pointer to a tree node for some base type, return a pointer to
13226 a DIE that describes the given type. REVERSE is true if the type is
13227 to be interpreted in the reverse storage order wrt the target order.
13229 This routine must only be called for GCC type nodes that correspond to
13230 Dwarf base (fundamental) types. */
13233 base_type_die (tree type
, bool reverse
)
13235 dw_die_ref base_type_result
;
13236 enum dwarf_type encoding
;
13237 bool fpt_used
= false;
13238 struct fixed_point_type_info fpt_info
;
13239 tree type_bias
= NULL_TREE
;
13241 /* If this is a subtype that should not be emitted as a subrange type,
13242 use the base type. See subrange_type_for_debug_p. */
13243 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
13244 type
= TREE_TYPE (type
);
13246 switch (TREE_CODE (type
))
13249 if ((dwarf_version
>= 4 || !dwarf_strict
)
13250 && TYPE_NAME (type
)
13251 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
13252 && DECL_IS_UNDECLARED_BUILTIN (TYPE_NAME (type
))
13253 && DECL_NAME (TYPE_NAME (type
)))
13255 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
13256 if (strcmp (name
, "char16_t") == 0
13257 || strcmp (name
, "char8_t") == 0
13258 || strcmp (name
, "char32_t") == 0)
13260 encoding
= DW_ATE_UTF
;
13264 if ((dwarf_version
>= 3 || !dwarf_strict
)
13265 && lang_hooks
.types
.get_fixed_point_type_info
)
13267 memset (&fpt_info
, 0, sizeof (fpt_info
));
13268 if (lang_hooks
.types
.get_fixed_point_type_info (type
, &fpt_info
))
13271 encoding
= ((TYPE_UNSIGNED (type
))
13272 ? DW_ATE_unsigned_fixed
13273 : DW_ATE_signed_fixed
);
13277 if (TYPE_STRING_FLAG (type
))
13279 if ((dwarf_version
>= 4 || !dwarf_strict
)
13281 && int_size_in_bytes (type
) == 4)
13282 encoding
= DW_ATE_UTF
;
13283 else if (TYPE_UNSIGNED (type
))
13284 encoding
= DW_ATE_unsigned_char
;
13286 encoding
= DW_ATE_signed_char
;
13288 else if (TYPE_UNSIGNED (type
))
13289 encoding
= DW_ATE_unsigned
;
13291 encoding
= DW_ATE_signed
;
13294 && lang_hooks
.types
.get_type_bias
)
13295 type_bias
= lang_hooks
.types
.get_type_bias (type
);
13299 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
13301 if (dwarf_version
>= 3 || !dwarf_strict
)
13302 encoding
= DW_ATE_decimal_float
;
13304 encoding
= DW_ATE_lo_user
;
13307 encoding
= DW_ATE_float
;
13310 case FIXED_POINT_TYPE
:
13311 if (!(dwarf_version
>= 3 || !dwarf_strict
))
13312 encoding
= DW_ATE_lo_user
;
13313 else if (TYPE_UNSIGNED (type
))
13314 encoding
= DW_ATE_unsigned_fixed
;
13316 encoding
= DW_ATE_signed_fixed
;
13319 /* Dwarf2 doesn't know anything about complex ints, so use
13320 a user defined type for it. */
13322 if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (type
)))
13323 encoding
= DW_ATE_complex_float
;
13325 encoding
= DW_ATE_lo_user
;
13329 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
13330 encoding
= DW_ATE_boolean
;
13334 /* C23 _BitInt(N). */
13335 if (TYPE_UNSIGNED (type
))
13336 encoding
= DW_ATE_unsigned
;
13338 encoding
= DW_ATE_signed
;
13342 /* No other TREE_CODEs are Dwarf fundamental types. */
13343 gcc_unreachable ();
13346 base_type_result
= new_die_raw (DW_TAG_base_type
);
13348 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
13349 int_size_in_bytes (type
));
13350 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
13351 if (TREE_CODE (type
) == BITINT_TYPE
)
13352 add_AT_unsigned (base_type_result
, DW_AT_bit_size
, TYPE_PRECISION (type
));
13354 if (need_endianity_attribute_p (reverse
))
13355 add_AT_unsigned (base_type_result
, DW_AT_endianity
,
13356 BYTES_BIG_ENDIAN
? DW_END_little
: DW_END_big
);
13358 add_alignment_attribute (base_type_result
, type
);
13362 switch (fpt_info
.scale_factor_kind
)
13364 case fixed_point_scale_factor_binary
:
13365 add_AT_int (base_type_result
, DW_AT_binary_scale
,
13366 fpt_info
.scale_factor
.binary
);
13369 case fixed_point_scale_factor_decimal
:
13370 add_AT_int (base_type_result
, DW_AT_decimal_scale
,
13371 fpt_info
.scale_factor
.decimal
);
13374 case fixed_point_scale_factor_arbitrary
:
13375 /* Arbitrary scale factors cannot be described in standard DWARF. */
13378 /* Describe the scale factor as a rational constant. */
13379 const dw_die_ref scale_factor
13380 = new_die (DW_TAG_constant
, comp_unit_die (), type
);
13382 add_scalar_info (scale_factor
, DW_AT_GNU_numerator
,
13383 fpt_info
.scale_factor
.arbitrary
.numerator
,
13384 dw_scalar_form_constant
, NULL
);
13385 add_scalar_info (scale_factor
, DW_AT_GNU_denominator
,
13386 fpt_info
.scale_factor
.arbitrary
.denominator
,
13387 dw_scalar_form_constant
, NULL
);
13389 add_AT_die_ref (base_type_result
, DW_AT_small
, scale_factor
);
13394 gcc_unreachable ();
13399 add_scalar_info (base_type_result
, DW_AT_GNU_bias
, type_bias
,
13400 dw_scalar_form_constant
13401 | dw_scalar_form_exprloc
13402 | dw_scalar_form_reference
,
13405 return base_type_result
;
13408 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
13409 named 'auto' in its type: return true for it, false otherwise. */
13412 is_cxx_auto (tree type
)
13416 tree name
= TYPE_IDENTIFIER (type
);
13417 if (name
== get_identifier ("auto")
13418 || name
== get_identifier ("decltype(auto)"))
13424 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if the
13425 given input type is a Dwarf "fundamental" type. Otherwise return null. */
13428 is_base_type (tree type
)
13430 switch (TREE_CODE (type
))
13434 case FIXED_POINT_TYPE
:
13445 case QUAL_UNION_TYPE
:
13446 case ENUMERAL_TYPE
:
13447 case FUNCTION_TYPE
:
13450 case REFERENCE_TYPE
:
13458 if (is_cxx_auto (type
))
13460 gcc_unreachable ();
13464 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
13465 node, return the size in bits for the type if it is a constant, or else
13466 return the alignment for the type if the type's size is not constant, or
13467 else return BITS_PER_WORD if the type actually turns out to be an
13468 ERROR_MARK node. */
13470 static inline unsigned HOST_WIDE_INT
13471 simple_type_size_in_bits (const_tree type
)
13473 if (TREE_CODE (type
) == ERROR_MARK
)
13474 return BITS_PER_WORD
;
13475 else if (TYPE_SIZE (type
) == NULL_TREE
)
13477 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
13478 return tree_to_uhwi (TYPE_SIZE (type
));
13480 return TYPE_ALIGN (type
);
13483 /* Similarly, but return an offset_int instead of UHWI. */
13485 static inline offset_int
13486 offset_int_type_size_in_bits (const_tree type
)
13488 if (TREE_CODE (type
) == ERROR_MARK
)
13489 return BITS_PER_WORD
;
13490 else if (TYPE_SIZE (type
) == NULL_TREE
)
13492 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
13493 return wi::to_offset (TYPE_SIZE (type
));
13495 return TYPE_ALIGN (type
);
13498 /* Given a pointer to a tree node for a subrange type, return a pointer
13499 to a DIE that describes the given type. */
13502 subrange_type_die (tree type
, tree low
, tree high
, tree bias
,
13503 dw_die_ref context_die
)
13505 dw_die_ref subrange_die
;
13506 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
13508 if (context_die
== NULL
)
13509 context_die
= comp_unit_die ();
13511 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
13513 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
13515 /* The size of the subrange type and its base type do not match,
13516 so we need to generate a size attribute for the subrange type. */
13517 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
13520 add_alignment_attribute (subrange_die
, type
);
13523 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
, NULL
);
13525 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
, NULL
);
13526 if (bias
&& !dwarf_strict
)
13527 add_scalar_info (subrange_die
, DW_AT_GNU_bias
, bias
,
13528 dw_scalar_form_constant
13529 | dw_scalar_form_exprloc
13530 | dw_scalar_form_reference
,
13533 return subrange_die
;
13536 /* Returns the (const and/or volatile) cv_qualifiers associated with
13537 the decl node. This will normally be augmented with the
13538 cv_qualifiers of the underlying type in add_type_attribute. */
13541 decl_quals (const_tree decl
)
13543 return ((TREE_READONLY (decl
)
13544 /* The C++ front-end correctly marks reference-typed
13545 variables as readonly, but from a language (and debug
13546 info) standpoint they are not const-qualified. */
13547 && TREE_CODE (TREE_TYPE (decl
)) != REFERENCE_TYPE
13548 ? TYPE_QUAL_CONST
: TYPE_UNQUALIFIED
)
13549 | (TREE_THIS_VOLATILE (decl
)
13550 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
));
13553 /* Determine the TYPE whose qualifiers match the largest strict subset
13554 of the given TYPE_QUALS, and return its qualifiers. Ignore all
13555 qualifiers outside QUAL_MASK. */
13558 get_nearest_type_subqualifiers (tree type
, int type_quals
, int qual_mask
)
13561 int best_rank
= 0, best_qual
= 0, max_rank
;
13563 type_quals
&= qual_mask
;
13564 max_rank
= popcount_hwi (type_quals
) - 1;
13566 for (t
= TYPE_MAIN_VARIANT (type
); t
&& best_rank
< max_rank
;
13567 t
= TYPE_NEXT_VARIANT (t
))
13569 int q
= TYPE_QUALS (t
) & qual_mask
;
13571 if ((q
& type_quals
) == q
&& q
!= type_quals
13572 && check_base_type (t
, type
))
13574 int rank
= popcount_hwi (q
);
13576 if (rank
> best_rank
)
13587 struct dwarf_qual_info_t
{ int q
; enum dwarf_tag t
; };
13588 static const dwarf_qual_info_t dwarf_qual_info
[] =
13590 { TYPE_QUAL_CONST
, DW_TAG_const_type
},
13591 { TYPE_QUAL_VOLATILE
, DW_TAG_volatile_type
},
13592 { TYPE_QUAL_RESTRICT
, DW_TAG_restrict_type
},
13593 { TYPE_QUAL_ATOMIC
, DW_TAG_atomic_type
}
13595 static const unsigned int dwarf_qual_info_size
= ARRAY_SIZE (dwarf_qual_info
);
13597 /* If DIE is a qualified DIE of some base DIE with the same parent,
13598 return the base DIE, otherwise return NULL. Set MASK to the
13599 qualifiers added compared to the returned DIE. */
13602 qualified_die_p (dw_die_ref die
, int *mask
, unsigned int depth
)
13605 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
13606 if (die
->die_tag
== dwarf_qual_info
[i
].t
)
13608 if (i
== dwarf_qual_info_size
)
13610 if (vec_safe_length (die
->die_attr
) != 1)
13612 dw_die_ref type
= get_AT_ref (die
, DW_AT_type
);
13613 if (type
== NULL
|| type
->die_parent
!= die
->die_parent
)
13615 *mask
|= dwarf_qual_info
[i
].q
;
13618 dw_die_ref ret
= qualified_die_p (type
, mask
, depth
- 1);
13625 /* If TYPE is long double or complex long double that
13626 should be emitted as artificial typedef to _Float128 or
13627 complex _Float128, return the type it should be emitted as.
13628 This is done in case the target already supports 16-byte
13629 composite floating point type (ibm_extended_format). */
13632 long_double_as_float128 (tree type
)
13634 if (type
!= long_double_type_node
13635 && type
!= complex_long_double_type_node
)
13638 machine_mode mode
, fmode
;
13639 if (TREE_CODE (type
) == COMPLEX_TYPE
)
13640 mode
= TYPE_MODE (TREE_TYPE (type
));
13642 mode
= TYPE_MODE (type
);
13643 if (known_eq (GET_MODE_SIZE (mode
), 16) && !MODE_COMPOSITE_P (mode
))
13644 FOR_EACH_MODE_IN_CLASS (fmode
, MODE_FLOAT
)
13645 if (known_eq (GET_MODE_SIZE (fmode
), 16)
13646 && MODE_COMPOSITE_P (fmode
))
13648 if (type
== long_double_type_node
)
13650 if (float128_type_node
13651 && (TYPE_MODE (float128_type_node
)
13652 == TYPE_MODE (type
)))
13653 return float128_type_node
;
13656 for (int i
= 0; i
< NUM_FLOATN_NX_TYPES
; i
++)
13657 if (COMPLEX_FLOATN_NX_TYPE_NODE (i
) != NULL_TREE
13658 && (TYPE_MODE (COMPLEX_FLOATN_NX_TYPE_NODE (i
))
13659 == TYPE_MODE (type
)))
13660 return COMPLEX_FLOATN_NX_TYPE_NODE (i
);
13666 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
13667 entry that chains the modifiers specified by CV_QUALS in front of the
13668 given type. REVERSE is true if the type is to be interpreted in the
13669 reverse storage order wrt the target order. */
13672 modified_type_die (tree type
, int cv_quals
, bool reverse
,
13673 dw_die_ref context_die
)
13675 enum tree_code code
= TREE_CODE (type
);
13676 dw_die_ref mod_type_die
;
13677 dw_die_ref sub_die
= NULL
;
13678 tree item_type
= NULL
;
13679 tree qualified_type
;
13680 tree name
, low
, high
;
13681 dw_die_ref mod_scope
;
13682 struct array_descr_info info
;
13683 /* Only these cv-qualifiers are currently handled. */
13684 const int cv_qual_mask
= (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
13685 | TYPE_QUAL_RESTRICT
| TYPE_QUAL_ATOMIC
|
13686 ENCODE_QUAL_ADDR_SPACE(~0U));
13687 /* DW_AT_endianity is specified only for base types in the standard. */
13688 const bool reverse_type
13689 = need_endianity_attribute_p (reverse
)
13690 && (is_base_type (type
)
13691 || (TREE_CODE (type
) == ENUMERAL_TYPE
&& !dwarf_strict
));
13693 if (code
== ERROR_MARK
)
13696 if (lang_hooks
.types
.get_debug_type
)
13698 tree debug_type
= lang_hooks
.types
.get_debug_type (type
);
13700 if (debug_type
!= NULL_TREE
&& debug_type
!= type
)
13701 return modified_type_die (debug_type
, cv_quals
, reverse
, context_die
);
13704 cv_quals
&= cv_qual_mask
;
13706 /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
13707 tag modifier (and not an attribute) old consumers won't be able
13709 if (dwarf_version
< 3)
13710 cv_quals
&= ~TYPE_QUAL_RESTRICT
;
13712 /* Likewise for DW_TAG_atomic_type for DWARFv5. */
13713 if (dwarf_version
< 5)
13714 cv_quals
&= ~TYPE_QUAL_ATOMIC
;
13716 /* See if we already have the appropriately qualified variant of
13718 qualified_type
= get_qualified_type (type
, cv_quals
);
13720 if (qualified_type
== sizetype
)
13722 /* Try not to expose the internal sizetype type's name. */
13723 if (TYPE_NAME (qualified_type
)
13724 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
13726 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
13728 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
13729 && (TYPE_PRECISION (t
)
13730 == TYPE_PRECISION (qualified_type
))
13731 && (TYPE_UNSIGNED (t
)
13732 == TYPE_UNSIGNED (qualified_type
)));
13733 qualified_type
= t
;
13735 else if (qualified_type
== sizetype
13736 && TREE_CODE (sizetype
) == TREE_CODE (size_type_node
)
13737 && TYPE_PRECISION (sizetype
) == TYPE_PRECISION (size_type_node
)
13738 && TYPE_UNSIGNED (sizetype
) == TYPE_UNSIGNED (size_type_node
))
13739 qualified_type
= size_type_node
;
13740 if (type
== sizetype
)
13741 type
= qualified_type
;
13744 /* If we do, then we can just use its DIE, if it exists. */
13745 if (qualified_type
)
13747 mod_type_die
= lookup_type_die (qualified_type
);
13749 /* DW_AT_endianity doesn't come from a qualifier on the type, so it is
13750 dealt with specially: the DIE with the attribute, if it exists, is
13751 placed immediately after the regular DIE for the same type. */
13754 || ((mod_type_die
= mod_type_die
->die_sib
) != NULL
13755 && get_AT_unsigned (mod_type_die
, DW_AT_endianity
))))
13756 return mod_type_die
;
13759 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
13761 /* Handle C typedef types. */
13763 && TREE_CODE (name
) == TYPE_DECL
13764 && DECL_ORIGINAL_TYPE (name
)
13765 && !DECL_ARTIFICIAL (name
))
13767 tree dtype
= TREE_TYPE (name
);
13769 /* Skip the typedef for base types with DW_AT_endianity, no big deal. */
13770 if (qualified_type
== dtype
&& !reverse_type
)
13772 tree origin
= decl_ultimate_origin (name
);
13774 /* Typedef variants that have an abstract origin don't get their own
13775 type DIE (see gen_typedef_die), so fall back on the ultimate
13776 abstract origin instead. */
13777 if (origin
!= NULL
&& origin
!= name
)
13778 return modified_type_die (TREE_TYPE (origin
), cv_quals
, reverse
,
13781 /* For a named type, use the typedef. */
13782 gen_type_die (qualified_type
, context_die
);
13783 return lookup_type_die (qualified_type
);
13787 int dquals
= TYPE_QUALS_NO_ADDR_SPACE (dtype
);
13788 dquals
&= cv_qual_mask
;
13789 if ((dquals
& ~cv_quals
) != TYPE_UNQUALIFIED
13790 || (cv_quals
== dquals
&& DECL_ORIGINAL_TYPE (name
) != type
))
13791 /* cv-unqualified version of named type. Just use
13792 the unnamed type to which it refers. */
13793 return modified_type_die (DECL_ORIGINAL_TYPE (name
), cv_quals
,
13794 reverse
, context_die
);
13795 /* Else cv-qualified version of named type; fall through. */
13799 mod_scope
= scope_die_for (type
, context_die
);
13803 int sub_quals
= 0, first_quals
= 0;
13805 dw_die_ref first
= NULL
, last
= NULL
;
13807 /* Determine a lesser qualified type that most closely matches
13808 this one. Then generate DW_TAG_* entries for the remaining
13810 sub_quals
= get_nearest_type_subqualifiers (type
, cv_quals
,
13812 if (sub_quals
&& use_debug_types
)
13814 bool needed
= false;
13815 /* If emitting type units, make sure the order of qualifiers
13816 is canonical. Thus, start from unqualified type if
13817 an earlier qualifier is missing in sub_quals, but some later
13818 one is present there. */
13819 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
13820 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
13822 else if (needed
&& (dwarf_qual_info
[i
].q
& cv_quals
))
13828 mod_type_die
= modified_type_die (type
, sub_quals
, reverse
, context_die
);
13829 if (mod_scope
&& mod_type_die
&& mod_type_die
->die_parent
== mod_scope
)
13831 /* As not all intermediate qualified DIEs have corresponding
13832 tree types, ensure that qualified DIEs in the same scope
13833 as their DW_AT_type are emitted after their DW_AT_type,
13834 only with other qualified DIEs for the same type possibly
13835 in between them. Determine the range of such qualified
13836 DIEs now (first being the base type, last being corresponding
13837 last qualified DIE for it). */
13838 unsigned int count
= 0;
13839 first
= qualified_die_p (mod_type_die
, &first_quals
,
13840 dwarf_qual_info_size
);
13842 first
= mod_type_die
;
13843 gcc_assert ((first_quals
& ~sub_quals
) == 0);
13844 for (count
= 0, last
= first
;
13845 count
< (1U << dwarf_qual_info_size
);
13846 count
++, last
= last
->die_sib
)
13849 if (last
== mod_scope
->die_child
)
13851 if (qualified_die_p (last
->die_sib
, &quals
, dwarf_qual_info_size
)
13857 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
13858 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
13861 if (first
&& first
!= last
)
13863 for (d
= first
->die_sib
; ; d
= d
->die_sib
)
13866 qualified_die_p (d
, &quals
, dwarf_qual_info_size
);
13867 if (quals
== (first_quals
| dwarf_qual_info
[i
].q
))
13883 d
= new_die_raw (dwarf_qual_info
[i
].t
);
13884 add_child_die_after (mod_scope
, d
, last
);
13888 d
= new_die (dwarf_qual_info
[i
].t
, mod_scope
, type
);
13890 add_AT_die_ref (d
, DW_AT_type
, mod_type_die
);
13892 first_quals
|= dwarf_qual_info
[i
].q
;
13895 else if (code
== POINTER_TYPE
|| code
== REFERENCE_TYPE
)
13897 dwarf_tag tag
= DW_TAG_pointer_type
;
13898 if (code
== REFERENCE_TYPE
)
13900 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
13901 tag
= DW_TAG_rvalue_reference_type
;
13903 tag
= DW_TAG_reference_type
;
13905 mod_type_die
= new_die (tag
, mod_scope
, type
);
13907 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
13908 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
13909 add_alignment_attribute (mod_type_die
, type
);
13910 item_type
= TREE_TYPE (type
);
13912 addr_space_t as
= TYPE_ADDR_SPACE (item_type
);
13913 if (!ADDR_SPACE_GENERIC_P (as
))
13915 int action
= targetm
.addr_space
.debug (as
);
13918 /* Positive values indicate an address_class. */
13919 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, action
);
13923 /* Negative values indicate an (inverted) segment base reg. */
13925 = one_reg_loc_descriptor (~action
, VAR_INIT_STATUS_INITIALIZED
);
13926 add_AT_loc (mod_type_die
, DW_AT_segment
, d
);
13930 else if (code
== ARRAY_TYPE
13931 || (lang_hooks
.types
.get_array_descr_info
13932 && lang_hooks
.types
.get_array_descr_info (type
, &info
)))
13934 gen_type_die (type
, context_die
);
13935 return lookup_type_die (type
);
13937 else if (code
== INTEGER_TYPE
13938 && TREE_TYPE (type
) != NULL_TREE
13939 && subrange_type_for_debug_p (type
, &low
, &high
))
13941 tree bias
= NULL_TREE
;
13942 if (lang_hooks
.types
.get_type_bias
)
13943 bias
= lang_hooks
.types
.get_type_bias (type
);
13944 mod_type_die
= subrange_type_die (type
, low
, high
, bias
, context_die
);
13945 item_type
= TREE_TYPE (type
);
13947 else if (is_base_type (type
))
13949 /* If a target supports long double as different floating point
13950 modes with the same 16-byte size, use normal DW_TAG_base_type
13951 only for the composite (ibm_extended_real_format) type and
13952 for the other for the time being emit instead a "_Float128"
13953 or "complex _Float128" DW_TAG_base_type and a "long double"
13954 or "complex long double" typedef to it. */
13955 if (tree other_type
= long_double_as_float128 (type
))
13957 dw_die_ref other_die
;
13958 if (TYPE_NAME (other_type
))
13960 = modified_type_die (other_type
, TYPE_UNQUALIFIED
, reverse
,
13964 other_die
= base_type_die (type
, reverse
);
13965 add_child_die (comp_unit_die (), other_die
);
13966 add_name_attribute (other_die
,
13967 TREE_CODE (type
) == COMPLEX_TYPE
13968 ? "complex _Float128" : "_Float128");
13970 mod_type_die
= new_die_raw (DW_TAG_typedef
);
13971 add_AT_die_ref (mod_type_die
, DW_AT_type
, other_die
);
13974 mod_type_die
= base_type_die (type
, reverse
);
13976 /* The DIE with DW_AT_endianity is placed right after the naked DIE. */
13979 dw_die_ref after_die
13980 = modified_type_die (type
, cv_quals
, false, context_die
);
13981 add_child_die_after (comp_unit_die (), mod_type_die
, after_die
);
13984 add_child_die (comp_unit_die (), mod_type_die
);
13986 add_pubtype (type
, mod_type_die
);
13990 /* The DIE with DW_AT_endianity is placed right after the naked DIE. */
13993 dw_die_ref after_die
13994 = modified_type_die (type
, cv_quals
, false, context_die
);
13995 gen_type_die (type
, context_die
, true);
13996 gcc_assert (after_die
->die_sib
13997 && get_AT_unsigned (after_die
->die_sib
, DW_AT_endianity
));
13998 return after_die
->die_sib
;
14001 gen_type_die (type
, context_die
);
14003 /* We have to get the type_main_variant here (and pass that to the
14004 `lookup_type_die' routine) because the ..._TYPE node we have
14005 might simply be a *copy* of some original type node (where the
14006 copy was created to help us keep track of typedef names) and
14007 that copy might have a different TYPE_UID from the original
14009 if (code
== FUNCTION_TYPE
|| code
== METHOD_TYPE
)
14011 /* For function/method types, can't just use type_main_variant here,
14012 because that can have different ref-qualifiers for C++,
14013 but try to canonicalize. */
14014 tree main
= TYPE_MAIN_VARIANT (type
);
14015 for (tree t
= main
; t
; t
= TYPE_NEXT_VARIANT (t
))
14016 if (TYPE_QUALS_NO_ADDR_SPACE (t
) == 0
14017 && check_base_type (t
, main
)
14018 && check_lang_type (t
, type
))
14019 return lookup_type_die (t
);
14020 return lookup_type_die (type
);
14022 /* Vectors have the debugging information in the type,
14023 not the main variant. */
14024 else if (code
== VECTOR_TYPE
)
14025 return lookup_type_die (type
);
14027 return lookup_type_die (type_main_variant (type
));
14030 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
14031 don't output a DW_TAG_typedef, since there isn't one in the
14032 user's program; just attach a DW_AT_name to the type.
14033 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
14034 if the base type already has the same name. */
14036 && ((TREE_CODE (name
) != TYPE_DECL
14037 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
14038 || (cv_quals
== TYPE_UNQUALIFIED
)))
14039 || (TREE_CODE (name
) == TYPE_DECL
14040 && TREE_TYPE (name
) == qualified_type
14041 && DECL_NAME (name
))))
14043 if (TREE_CODE (name
) == TYPE_DECL
)
14044 /* Could just call add_name_and_src_coords_attributes here,
14045 but since this is a builtin type it doesn't have any
14046 useful source coordinates anyway. */
14047 name
= DECL_NAME (name
);
14048 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
14050 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
14052 if (TREE_CODE (type
) == BITINT_TYPE
)
14054 char name_buf
[sizeof ("unsigned _BitInt(2147483647)")];
14055 snprintf (name_buf
, sizeof (name_buf
),
14056 "%s_BitInt(%d)", TYPE_UNSIGNED (type
) ? "unsigned " : "",
14057 TYPE_PRECISION (type
));
14058 add_name_attribute (mod_type_die
, name_buf
);
14062 /* This probably indicates a bug. */
14063 name
= TYPE_IDENTIFIER (type
);
14064 add_name_attribute (mod_type_die
,
14066 ? IDENTIFIER_POINTER (name
) : "__unknown__");
14070 if (qualified_type
&& !reverse_type
)
14071 equate_type_number_to_die (qualified_type
, mod_type_die
);
14074 /* We must do this after the equate_type_number_to_die call, in case
14075 this is a recursive type. This ensures that the modified_type_die
14076 recursion will terminate even if the type is recursive. Recursive
14077 types are possible in Ada. */
14078 sub_die
= modified_type_die (item_type
,
14079 TYPE_QUALS_NO_ADDR_SPACE (item_type
),
14083 if (sub_die
!= NULL
)
14084 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
14086 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
14087 if (TYPE_ARTIFICIAL (type
))
14088 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
14090 return mod_type_die
;
14093 /* Generate DIEs for the generic parameters of T.
14094 T must be either a generic type or a generic function.
14095 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
14098 gen_generic_params_dies (tree t
)
14102 dw_die_ref die
= NULL
;
14105 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
14109 die
= lookup_type_die (t
);
14110 else if (DECL_P (t
))
14111 die
= lookup_decl_die (t
);
14115 parms
= lang_hooks
.get_innermost_generic_parms (t
);
14117 /* T has no generic parameter. It means T is neither a generic type
14118 or function. End of story. */
14121 parms_num
= TREE_VEC_LENGTH (parms
);
14122 args
= lang_hooks
.get_innermost_generic_args (t
);
14123 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
14124 non_default
= int_cst_value (TREE_CHAIN (args
));
14126 non_default
= TREE_VEC_LENGTH (args
);
14127 for (i
= 0; i
< parms_num
; i
++)
14129 tree parm
, arg
, arg_pack_elems
;
14130 dw_die_ref parm_die
;
14132 parm
= TREE_VEC_ELT (parms
, i
);
14133 arg
= TREE_VEC_ELT (args
, i
);
14134 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
14135 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
14137 if (parm
&& TREE_VALUE (parm
) && arg
)
14139 /* If PARM represents a template parameter pack,
14140 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
14141 by DW_TAG_template_*_parameter DIEs for the argument
14142 pack elements of ARG. Note that ARG would then be
14143 an argument pack. */
14144 if (arg_pack_elems
)
14145 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
14149 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
14150 true /* emit name */, die
);
14151 if (i
>= non_default
)
14152 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
14157 /* Create and return a DIE for PARM which should be
14158 the representation of a generic type parameter.
14159 For instance, in the C++ front end, PARM would be a template parameter.
14160 ARG is the argument to PARM.
14161 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
14163 PARENT_DIE is the parent DIE which the new created DIE should be added to,
14164 as a child node. */
14167 generic_parameter_die (tree parm
, tree arg
,
14169 dw_die_ref parent_die
)
14171 dw_die_ref tmpl_die
= NULL
;
14172 const char *name
= NULL
;
14174 /* C++20 accepts class literals as template parameters, and var
14175 decls with initializers represent them. The VAR_DECLs would be
14176 rejected, but we can take the DECL_INITIAL constructor and
14177 attempt to expand it. */
14178 if (arg
&& VAR_P (arg
))
14179 arg
= DECL_INITIAL (arg
);
14181 if (!parm
|| !DECL_NAME (parm
) || !arg
)
14184 /* We support non-type generic parameters and arguments,
14185 type generic parameters and arguments, as well as
14186 generic generic parameters (a.k.a. template template parameters in C++)
14188 if (TREE_CODE (parm
) == PARM_DECL
)
14189 /* PARM is a nontype generic parameter */
14190 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
14191 else if (TREE_CODE (parm
) == TYPE_DECL
)
14192 /* PARM is a type generic parameter. */
14193 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
14194 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
14195 /* PARM is a generic generic parameter.
14196 Its DIE is a GNU extension. It shall have a
14197 DW_AT_name attribute to represent the name of the template template
14198 parameter, and a DW_AT_GNU_template_name attribute to represent the
14199 name of the template template argument. */
14200 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
14203 gcc_unreachable ();
14209 /* If PARM is a generic parameter pack, it means we are
14210 emitting debug info for a template argument pack element.
14211 In other terms, ARG is a template argument pack element.
14212 In that case, we don't emit any DW_AT_name attribute for
14216 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
14218 add_AT_string (tmpl_die
, DW_AT_name
, name
);
14221 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
14223 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
14224 TMPL_DIE should have a child DW_AT_type attribute that is set
14225 to the type of the argument to PARM, which is ARG.
14226 If PARM is a type generic parameter, TMPL_DIE should have a
14227 child DW_AT_type that is set to ARG. */
14228 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
14229 add_type_attribute (tmpl_die
, tmpl_type
,
14230 (TREE_THIS_VOLATILE (tmpl_type
)
14231 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
),
14232 false, parent_die
);
14236 /* So TMPL_DIE is a DIE representing a
14237 a generic generic template parameter, a.k.a template template
14238 parameter in C++ and arg is a template. */
14240 /* The DW_AT_GNU_template_name attribute of the DIE must be set
14241 to the name of the argument. */
14242 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
14244 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
14247 if (TREE_CODE (parm
) == PARM_DECL
)
14248 /* So PARM is a non-type generic parameter.
14249 DWARF3 5.6.8 says we must set a DW_AT_const_value child
14250 attribute of TMPL_DIE which value represents the value
14252 We must be careful here:
14253 The value of ARG might reference some function decls.
14254 We might currently be emitting debug info for a generic
14255 type and types are emitted before function decls, we don't
14256 know if the function decls referenced by ARG will actually be
14257 emitted after cgraph computations.
14258 So must defer the generation of the DW_AT_const_value to
14259 after cgraph is ready. */
14260 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
14266 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
14267 PARM_PACK must be a template parameter pack. The returned DIE
14268 will be child DIE of PARENT_DIE. */
14271 template_parameter_pack_die (tree parm_pack
,
14272 tree parm_pack_args
,
14273 dw_die_ref parent_die
)
14278 gcc_assert (parent_die
&& parm_pack
);
14280 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
14281 add_name_and_src_coords_attributes (die
, parm_pack
);
14282 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
14283 generic_parameter_die (parm_pack
,
14284 TREE_VEC_ELT (parm_pack_args
, j
),
14285 false /* Don't emit DW_AT_name */,
14290 /* Return the debugger register number described by a given RTL node. */
14292 static unsigned int
14293 debugger_reg_number (const_rtx rtl
)
14295 unsigned regno
= REGNO (rtl
);
14297 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
14299 #ifdef LEAF_REG_REMAP
14300 if (crtl
->uses_only_leaf_regs
)
14302 int leaf_reg
= LEAF_REG_REMAP (regno
);
14303 if (leaf_reg
!= -1)
14304 regno
= (unsigned) leaf_reg
;
14308 regno
= DEBUGGER_REGNO (regno
);
14309 gcc_assert (regno
!= INVALID_REGNUM
);
14313 /* Optionally add a DW_OP_piece term to a location description expression.
14314 DW_OP_piece is only added if the location description expression already
14315 doesn't end with DW_OP_piece. */
14318 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
14320 dw_loc_descr_ref loc
;
14322 if (*list_head
!= NULL
)
14324 /* Find the end of the chain. */
14325 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
14328 if (loc
->dw_loc_opc
!= DW_OP_piece
)
14329 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
14333 /* Return a location descriptor that designates a machine register or
14334 zero if there is none. */
14336 static dw_loc_descr_ref
14337 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
14341 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
14344 /* We only use "frame base" when we're sure we're talking about the
14345 post-prologue local stack frame. We do this by *not* running
14346 register elimination until this point, and recognizing the special
14347 argument pointer and soft frame pointer rtx's.
14348 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
14349 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
14351 ? lra_eliminate_regs (rtl
, VOIDmode
, NULL_RTX
)
14352 : eliminate_regs (rtl
, VOIDmode
, NULL_RTX
)) != rtl
)
14354 dw_loc_descr_ref result
= NULL
;
14356 if (dwarf_version
>= 4 || !dwarf_strict
)
14358 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
14361 add_loc_descr (&result
,
14362 new_loc_descr (DW_OP_stack_value
, 0, 0));
14367 regs
= targetm
.dwarf_register_span (rtl
);
14369 if (REG_NREGS (rtl
) > 1 || regs
)
14370 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
14373 unsigned int debugger_regnum
= debugger_reg_number (rtl
);
14374 if (debugger_regnum
== IGNORED_DWARF_REGNUM
)
14376 return one_reg_loc_descriptor (debugger_regnum
, initialized
);
14380 /* Return a location descriptor that designates a machine register for
14381 a given hard register number. */
14383 static dw_loc_descr_ref
14384 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
14386 dw_loc_descr_ref reg_loc_descr
;
14390 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
14392 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
14394 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14395 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14397 return reg_loc_descr
;
14400 /* Given an RTL of a register, return a location descriptor that
14401 designates a value that spans more than one register. */
14403 static dw_loc_descr_ref
14404 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
14405 enum var_init_status initialized
)
14408 dw_loc_descr_ref loc_result
= NULL
;
14410 /* Simple, contiguous registers. */
14411 if (regs
== NULL_RTX
)
14413 unsigned reg
= REGNO (rtl
);
14416 #ifdef LEAF_REG_REMAP
14417 if (crtl
->uses_only_leaf_regs
)
14419 int leaf_reg
= LEAF_REG_REMAP (reg
);
14420 if (leaf_reg
!= -1)
14421 reg
= (unsigned) leaf_reg
;
14425 gcc_assert ((unsigned) DEBUGGER_REGNO (reg
) == debugger_reg_number (rtl
));
14426 nregs
= REG_NREGS (rtl
);
14428 /* At present we only track constant-sized pieces. */
14429 if (!GET_MODE_SIZE (GET_MODE (rtl
)).is_constant (&size
))
14436 dw_loc_descr_ref t
;
14438 t
= one_reg_loc_descriptor (DEBUGGER_REGNO (reg
),
14439 VAR_INIT_STATUS_INITIALIZED
);
14440 add_loc_descr (&loc_result
, t
);
14441 add_loc_descr_op_piece (&loc_result
, size
);
14447 /* Now onto stupid register sets in non contiguous locations. */
14449 gcc_assert (GET_CODE (regs
) == PARALLEL
);
14451 /* At present we only track constant-sized pieces. */
14452 if (!GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0))).is_constant (&size
))
14456 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
14458 dw_loc_descr_ref t
;
14460 t
= one_reg_loc_descriptor (debugger_reg_number (XVECEXP (regs
, 0, i
)),
14461 VAR_INIT_STATUS_INITIALIZED
);
14462 add_loc_descr (&loc_result
, t
);
14463 add_loc_descr_op_piece (&loc_result
, size
);
14466 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14467 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14471 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
14473 /* Return a location descriptor that designates a constant i,
14474 as a compound operation from constant (i >> shift), constant shift
14477 static dw_loc_descr_ref
14478 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
14480 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
14481 add_loc_descr (&ret
, int_loc_descriptor (shift
));
14482 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
14486 /* Return a location descriptor that designates constant POLY_I. */
14488 static dw_loc_descr_ref
14489 int_loc_descriptor (poly_int64 poly_i
)
14491 enum dwarf_location_atom op
;
14494 if (!poly_i
.is_constant (&i
))
14496 /* Create location descriptions for the non-constant part and
14497 add any constant offset at the end. */
14498 dw_loc_descr_ref ret
= NULL
;
14499 HOST_WIDE_INT constant
= poly_i
.coeffs
[0];
14500 for (unsigned int j
= 1; j
< NUM_POLY_INT_COEFFS
; ++j
)
14502 HOST_WIDE_INT coeff
= poly_i
.coeffs
[j
];
14505 dw_loc_descr_ref start
= ret
;
14506 unsigned int factor
;
14508 unsigned int regno
= targetm
.dwarf_poly_indeterminate_value
14509 (j
, &factor
, &bias
);
14511 /* Add COEFF * ((REGNO / FACTOR) - BIAS) to the value:
14512 add COEFF * (REGNO / FACTOR) now and subtract
14513 COEFF * BIAS from the final constant part. */
14514 constant
-= coeff
* bias
;
14515 add_loc_descr (&ret
, new_reg_loc_descr (regno
, 0));
14516 if (coeff
% factor
== 0)
14520 int amount
= exact_log2 (factor
);
14521 gcc_assert (amount
>= 0);
14522 add_loc_descr (&ret
, int_loc_descriptor (amount
));
14523 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
14527 add_loc_descr (&ret
, int_loc_descriptor (coeff
));
14528 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14531 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
14534 loc_descr_plus_const (&ret
, constant
);
14538 /* Pick the smallest representation of a constant, rather than just
14539 defaulting to the LEB encoding. */
14542 int clz
= clz_hwi (i
);
14543 int ctz
= ctz_hwi (i
);
14545 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
14546 else if (i
<= 0xff)
14547 op
= DW_OP_const1u
;
14548 else if (i
<= 0xffff)
14549 op
= DW_OP_const2u
;
14550 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
14551 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
14552 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
14553 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
14554 while DW_OP_const4u is 5 bytes. */
14555 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
14556 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
14557 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
14558 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
14559 while DW_OP_const4u is 5 bytes. */
14560 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
14562 else if (DWARF2_ADDR_SIZE
== 4 && i
> 0x7fffffff
14563 && size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
)
14566 /* As i >= 2**31, the double cast above will yield a negative number.
14567 Since wrapping is defined in DWARF expressions we can output big
14568 positive integers as small negative ones, regardless of the size
14571 Here, since the evaluator will handle 32-bit values and since i >=
14572 2**31, we know it's going to be interpreted as a negative literal:
14573 store it this way if we can do better than 5 bytes this way. */
14574 return int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
);
14576 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
14577 op
= DW_OP_const4u
;
14579 /* Past this point, i >= 0x100000000 and thus DW_OP_constu will take at
14580 least 6 bytes: see if we can do better before falling back to it. */
14581 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
14582 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
14583 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes. */
14584 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
14585 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
14586 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
14587 >= HOST_BITS_PER_WIDE_INT
)
14588 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
14589 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes. */
14590 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
14591 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
14592 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
14593 && size_of_uleb128 (i
) > 6)
14594 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
14595 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
14602 op
= DW_OP_const1s
;
14603 else if (i
>= -0x8000)
14604 op
= DW_OP_const2s
;
14605 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
14607 if (size_of_int_loc_descriptor (i
) < 5)
14609 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
14610 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
14613 op
= DW_OP_const4s
;
14617 if (size_of_int_loc_descriptor (i
)
14618 < (unsigned long) 1 + size_of_sleb128 (i
))
14620 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
14621 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
14628 return new_loc_descr (op
, i
, 0);
14631 /* Likewise, for unsigned constants. */
14633 static dw_loc_descr_ref
14634 uint_loc_descriptor (unsigned HOST_WIDE_INT i
)
14636 const unsigned HOST_WIDE_INT max_int
= INTTYPE_MAXIMUM (HOST_WIDE_INT
);
14637 const unsigned HOST_WIDE_INT max_uint
14638 = INTTYPE_MAXIMUM (unsigned HOST_WIDE_INT
);
14640 /* If possible, use the clever signed constants handling. */
14642 return int_loc_descriptor ((HOST_WIDE_INT
) i
);
14644 /* Here, we are left with positive numbers that cannot be represented as
14645 HOST_WIDE_INT, i.e.:
14646 max (HOST_WIDE_INT) < i <= max (unsigned HOST_WIDE_INT)
14648 Using DW_OP_const4/8/./u operation to encode them consumes a lot of bytes
14649 whereas may be better to output a negative integer: thanks to integer
14650 wrapping, we know that:
14651 x = x - 2 ** DWARF2_ADDR_SIZE
14652 = x - 2 * (max (HOST_WIDE_INT) + 1)
14653 So numbers close to max (unsigned HOST_WIDE_INT) could be represented as
14654 small negative integers. Let's try that in cases it will clearly improve
14655 the encoding: there is no gain turning DW_OP_const4u into
14657 if (DWARF2_ADDR_SIZE
* 8 == HOST_BITS_PER_WIDE_INT
14658 && ((DWARF2_ADDR_SIZE
== 4 && i
> max_uint
- 0x8000)
14659 || (DWARF2_ADDR_SIZE
== 8 && i
> max_uint
- 0x80000000)))
14661 const unsigned HOST_WIDE_INT first_shift
= i
- max_int
- 1;
14663 /* Now, -1 < first_shift <= max (HOST_WIDE_INT)
14664 i.e. 0 <= first_shift <= max (HOST_WIDE_INT). */
14665 const HOST_WIDE_INT second_shift
14666 = (HOST_WIDE_INT
) first_shift
- (HOST_WIDE_INT
) max_int
- 1;
14668 /* So we finally have:
14669 -max (HOST_WIDE_INT) - 1 <= second_shift <= -1.
14670 i.e. min (HOST_WIDE_INT) <= second_shift < 0. */
14671 return int_loc_descriptor (second_shift
);
14674 /* Last chance: fallback to a simple constant operation. */
14675 return new_loc_descr
14676 ((HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
14682 /* Generate and return a location description that computes the unsigned
14683 comparison of the two stack top entries (a OP b where b is the top-most
14684 entry and a is the second one). The KIND of comparison can be LT_EXPR,
14685 LE_EXPR, GT_EXPR or GE_EXPR. */
14687 static dw_loc_descr_ref
14688 uint_comparison_loc_list (enum tree_code kind
)
14690 enum dwarf_location_atom op
, flip_op
;
14691 dw_loc_descr_ref ret
, bra_node
, jmp_node
, tmp
;
14708 gcc_unreachable ();
14711 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14712 jmp_node
= new_loc_descr (DW_OP_skip
, 0, 0);
14714 /* Until DWARFv4, operations all work on signed integers. It is nevertheless
14715 possible to perform unsigned comparisons: we just have to distinguish
14718 1. when a and b have the same sign (as signed integers); then we should
14719 return: a OP(signed) b;
14721 2. when a is a negative signed integer while b is a positive one, then a
14722 is a greater unsigned integer than b; likewise when a and b's roles
14725 So first, compare the sign of the two operands. */
14726 ret
= new_loc_descr (DW_OP_over
, 0, 0);
14727 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
14728 add_loc_descr (&ret
, new_loc_descr (DW_OP_xor
, 0, 0));
14729 /* If they have different signs (i.e. they have different sign bits), then
14730 the stack top value has now the sign bit set and thus it's smaller than
14732 add_loc_descr (&ret
, new_loc_descr (DW_OP_lit0
, 0, 0));
14733 add_loc_descr (&ret
, new_loc_descr (DW_OP_lt
, 0, 0));
14734 add_loc_descr (&ret
, bra_node
);
14736 /* We are in case 1. At this point, we know both operands have the same
14737 sign, to it's safe to use the built-in signed comparison. */
14738 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
14739 add_loc_descr (&ret
, jmp_node
);
14741 /* We are in case 2. Here, we know both operands do not have the same sign,
14742 so we have to flip the signed comparison. */
14743 flip_op
= (kind
== LT_EXPR
|| kind
== LE_EXPR
) ? DW_OP_gt
: DW_OP_lt
;
14744 tmp
= new_loc_descr (flip_op
, 0, 0);
14745 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14746 bra_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14747 add_loc_descr (&ret
, tmp
);
14749 /* This dummy operation is necessary to make the two branches join. */
14750 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
14751 jmp_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14752 jmp_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14753 add_loc_descr (&ret
, tmp
);
14758 /* Likewise, but takes the location description lists (might be destructive on
14759 them). Return NULL if either is NULL or if concatenation fails. */
14761 static dw_loc_list_ref
14762 loc_list_from_uint_comparison (dw_loc_list_ref left
, dw_loc_list_ref right
,
14763 enum tree_code kind
)
14765 if (left
== NULL
|| right
== NULL
)
14768 add_loc_list (&left
, right
);
14772 add_loc_descr_to_each (left
, uint_comparison_loc_list (kind
));
14776 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
14777 without actually allocating it. */
14779 static unsigned long
14780 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
14782 return size_of_int_loc_descriptor (i
>> shift
)
14783 + size_of_int_loc_descriptor (shift
)
14787 /* Return size_of_locs (int_loc_descriptor (i)) without
14788 actually allocating it. */
14790 static unsigned long
14791 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
14800 else if (i
<= 0xff)
14802 else if (i
<= 0xffff)
14806 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
14807 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
14808 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
14810 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
14811 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
14812 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
14814 else if (DWARF2_ADDR_SIZE
== 4 && i
> 0x7fffffff
14815 && size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
)
14817 return size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
);
14818 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
14820 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
14821 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
14822 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
14823 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
14825 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
14826 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
14827 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
14829 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
14830 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
14832 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
14841 else if (i
>= -0x8000)
14843 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
14845 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
14847 s
= size_of_int_loc_descriptor (-i
) + 1;
14855 unsigned long r
= 1 + size_of_sleb128 (i
);
14856 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
14858 s
= size_of_int_loc_descriptor (-i
) + 1;
14867 /* Return loc description representing "address" of integer value.
14868 This can appear only as toplevel expression. */
14870 static dw_loc_descr_ref
14871 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
14874 dw_loc_descr_ref loc_result
= NULL
;
14876 if (!(dwarf_version
>= 4 || !dwarf_strict
))
14879 litsize
= size_of_int_loc_descriptor (i
);
14880 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
14881 is more compact. For DW_OP_stack_value we need:
14882 litsize + 1 (DW_OP_stack_value)
14883 and for DW_OP_implicit_value:
14884 1 (DW_OP_implicit_value) + 1 (length) + size. */
14885 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
14887 loc_result
= int_loc_descriptor (i
);
14888 add_loc_descr (&loc_result
,
14889 new_loc_descr (DW_OP_stack_value
, 0, 0));
14893 loc_result
= new_loc_descr (DW_OP_implicit_value
,
14895 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
14896 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
14900 /* Return a location descriptor that designates a base+offset location. */
14902 static dw_loc_descr_ref
14903 based_loc_descr (rtx reg
, poly_int64 offset
,
14904 enum var_init_status initialized
)
14906 unsigned int regno
;
14907 dw_loc_descr_ref result
;
14908 dw_fde_ref fde
= cfun
->fde
;
14910 /* We only use "frame base" when we're sure we're talking about the
14911 post-prologue local stack frame. We do this by *not* running
14912 register elimination until this point, and recognizing the special
14913 argument pointer and soft frame pointer rtx's. */
14914 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
14916 rtx elim
= (ira_use_lra_p
14917 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
14918 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
14922 /* Allow hard frame pointer here even if frame pointer
14923 isn't used since hard frame pointer is encoded with
14924 DW_OP_fbreg which uses the DW_AT_frame_base attribute,
14925 not hard frame pointer directly. */
14926 elim
= strip_offset_and_add (elim
, &offset
);
14927 gcc_assert (elim
== hard_frame_pointer_rtx
14928 || elim
== stack_pointer_rtx
);
14930 /* If drap register is used to align stack, use frame
14931 pointer + offset to access stack variables. If stack
14932 is aligned without drap, use stack pointer + offset to
14933 access stack variables. */
14934 if (crtl
->stack_realign_tried
14935 && reg
== frame_pointer_rtx
)
14938 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
14939 ? HARD_FRAME_POINTER_REGNUM
14941 return new_reg_loc_descr (base_reg
, offset
);
14944 gcc_assert (frame_pointer_fb_offset_valid
);
14945 offset
+= frame_pointer_fb_offset
;
14946 HOST_WIDE_INT const_offset
;
14947 if (offset
.is_constant (&const_offset
))
14948 return new_loc_descr (DW_OP_fbreg
, const_offset
, 0);
14951 dw_loc_descr_ref ret
= new_loc_descr (DW_OP_fbreg
, 0, 0);
14952 loc_descr_plus_const (&ret
, offset
);
14958 regno
= REGNO (reg
);
14959 #ifdef LEAF_REG_REMAP
14960 if (crtl
->uses_only_leaf_regs
)
14962 int leaf_reg
= LEAF_REG_REMAP (regno
);
14963 if (leaf_reg
!= -1)
14964 regno
= (unsigned) leaf_reg
;
14967 regno
= DWARF_FRAME_REGNUM (regno
);
14969 HOST_WIDE_INT const_offset
;
14970 if (!optimize
&& fde
14971 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
)
14972 && offset
.is_constant (&const_offset
))
14974 /* Use cfa+offset to represent the location of arguments passed
14975 on the stack when drap is used to align stack.
14976 Only do this when not optimizing, for optimized code var-tracking
14977 is supposed to track where the arguments live and the register
14978 used as vdrap or drap in some spot might be used for something
14979 else in other part of the routine. */
14980 return new_loc_descr (DW_OP_fbreg
, const_offset
, 0);
14983 result
= new_reg_loc_descr (regno
, offset
);
14985 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14986 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14991 /* Return true if this RTL expression describes a base+offset calculation. */
14994 is_based_loc (const_rtx rtl
)
14996 return (GET_CODE (rtl
) == PLUS
14997 && ((REG_P (XEXP (rtl
, 0))
14998 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
14999 && CONST_INT_P (XEXP (rtl
, 1)))));
15002 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
15005 static dw_loc_descr_ref
15006 tls_mem_loc_descriptor (rtx mem
)
15009 dw_loc_descr_ref loc_result
;
15011 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
15014 base
= get_base_address (MEM_EXPR (mem
));
15017 || !DECL_THREAD_LOCAL_P (base
))
15020 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1, NULL
);
15021 if (loc_result
== NULL
)
15024 if (maybe_ne (MEM_OFFSET (mem
), 0))
15025 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
15030 /* Output debug info about reason why we failed to expand expression as dwarf
15034 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
15036 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
15038 fprintf (dump_file
, "Failed to expand as dwarf: ");
15040 print_generic_expr (dump_file
, expr
, dump_flags
);
15043 fprintf (dump_file
, "\n");
15044 print_rtl (dump_file
, rtl
);
15046 fprintf (dump_file
, "\nReason: %s\n", reason
);
15050 /* Helper function for const_ok_for_output. */
15053 const_ok_for_output_1 (rtx rtl
)
15055 if (targetm
.const_not_ok_for_debug_p (rtl
))
15057 if (GET_CODE (rtl
) != UNSPEC
)
15059 expansion_failed (NULL_TREE
, rtl
,
15060 "Expression rejected for debug by the backend.\n");
15064 /* If delegitimize_address couldn't do anything with the UNSPEC, and
15065 the target hook doesn't explicitly allow it in debug info, assume
15066 we can't express it in the debug info. */
15067 /* Don't complain about TLS UNSPECs, those are just too hard to
15068 delegitimize. Note this could be a non-decl SYMBOL_REF such as
15069 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
15070 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
15072 && (XVECLEN (rtl
, 0) == 0
15073 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
15074 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
))
15075 inform (current_function_decl
15076 ? DECL_SOURCE_LOCATION (current_function_decl
)
15077 : UNKNOWN_LOCATION
,
15078 #if NUM_UNSPEC_VALUES > 0
15079 "non-delegitimized UNSPEC %s (%d) found in variable location",
15080 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
15081 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
15083 "non-delegitimized UNSPEC %d found in variable location",
15086 expansion_failed (NULL_TREE
, rtl
,
15087 "UNSPEC hasn't been delegitimized.\n");
15091 if (CONST_POLY_INT_P (rtl
))
15094 /* FIXME: Refer to PR60655. It is possible for simplification
15095 of rtl expressions in var tracking to produce such expressions.
15096 We should really identify / validate expressions
15097 enclosed in CONST that can be handled by assemblers on various
15098 targets and only handle legitimate cases here. */
15099 switch (GET_CODE (rtl
))
15108 /* Make sure SYMBOL_REFs/UNSPECs are at most in one of the
15110 subrtx_var_iterator::array_type array
;
15111 bool first
= false;
15112 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 0), ALL
)
15113 if (SYMBOL_REF_P (*iter
)
15115 || GET_CODE (*iter
) == UNSPEC
)
15122 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 1), ALL
)
15123 if (SYMBOL_REF_P (*iter
)
15125 || GET_CODE (*iter
) == UNSPEC
)
15131 /* Disallow negation of SYMBOL_REFs or UNSPECs when they
15132 appear in the second operand of MINUS. */
15133 subrtx_var_iterator::array_type array
;
15134 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 1), ALL
)
15135 if (SYMBOL_REF_P (*iter
)
15137 || GET_CODE (*iter
) == UNSPEC
)
15145 if (CONSTANT_POOL_ADDRESS_P (rtl
))
15148 get_pool_constant_mark (rtl
, &marked
);
15149 /* If all references to this pool constant were optimized away,
15150 it was not output and thus we can't represent it. */
15153 expansion_failed (NULL_TREE
, rtl
,
15154 "Constant was removed from constant pool.\n");
15159 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
15162 /* Avoid references to external symbols in debug info, on several targets
15163 the linker might even refuse to link when linking a shared library,
15164 and in many other cases the relocations for .debug_info/.debug_loc are
15165 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
15166 to be defined within the same shared library or executable are fine. */
15167 if (SYMBOL_REF_EXTERNAL_P (rtl
))
15169 tree decl
= SYMBOL_REF_DECL (rtl
);
15171 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
15173 expansion_failed (NULL_TREE
, rtl
,
15174 "Symbol not defined in current TU.\n");
15182 /* Return true if constant RTL can be emitted in DW_OP_addr or
15183 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
15184 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
15187 const_ok_for_output (rtx rtl
)
15189 if (GET_CODE (rtl
) == SYMBOL_REF
)
15190 return const_ok_for_output_1 (rtl
);
15192 if (GET_CODE (rtl
) == CONST
)
15194 subrtx_var_iterator::array_type array
;
15195 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 0), ALL
)
15196 if (!const_ok_for_output_1 (*iter
))
15204 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
15205 if possible, NULL otherwise. */
15208 base_type_for_mode (machine_mode mode
, bool unsignedp
)
15210 dw_die_ref type_die
;
15211 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
15215 switch (TREE_CODE (type
))
15223 type_die
= lookup_type_die (type
);
15225 type_die
= modified_type_die (type
, TYPE_UNQUALIFIED
, false,
15227 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
15232 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
15233 type matching MODE, or, if MODE is narrower than or as wide as
15234 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
15237 static dw_loc_descr_ref
15238 convert_descriptor_to_mode (scalar_int_mode mode
, dw_loc_descr_ref op
)
15240 machine_mode outer_mode
= mode
;
15241 dw_die_ref type_die
;
15242 dw_loc_descr_ref cvt
;
15244 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
15246 add_loc_descr (&op
, new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0));
15249 type_die
= base_type_for_mode (outer_mode
, 1);
15250 if (type_die
== NULL
)
15252 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15253 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15254 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15255 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15256 add_loc_descr (&op
, cvt
);
15260 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
15262 static dw_loc_descr_ref
15263 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
15264 dw_loc_descr_ref op1
)
15266 dw_loc_descr_ref ret
= op0
;
15267 add_loc_descr (&ret
, op1
);
15268 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
15269 if (STORE_FLAG_VALUE
!= 1)
15271 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
15272 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
15277 /* Subroutine of scompare_loc_descriptor for the case in which we're
15278 comparing two scalar integer operands OP0 and OP1 that have mode OP_MODE,
15279 and in which OP_MODE is bigger than DWARF2_ADDR_SIZE. */
15281 static dw_loc_descr_ref
15282 scompare_loc_descriptor_wide (enum dwarf_location_atom op
,
15283 scalar_int_mode op_mode
,
15284 dw_loc_descr_ref op0
, dw_loc_descr_ref op1
)
15286 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
15287 dw_loc_descr_ref cvt
;
15289 if (type_die
== NULL
)
15291 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15292 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15293 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15294 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15295 add_loc_descr (&op0
, cvt
);
15296 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15297 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15298 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15299 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15300 add_loc_descr (&op1
, cvt
);
15301 return compare_loc_descriptor (op
, op0
, op1
);
15304 /* Subroutine of scompare_loc_descriptor for the case in which we're
15305 comparing two scalar integer operands OP0 and OP1 that have mode OP_MODE,
15306 and in which OP_MODE is smaller than DWARF2_ADDR_SIZE. */
15308 static dw_loc_descr_ref
15309 scompare_loc_descriptor_narrow (enum dwarf_location_atom op
, rtx rtl
,
15310 scalar_int_mode op_mode
,
15311 dw_loc_descr_ref op0
, dw_loc_descr_ref op1
)
15313 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
15314 /* For eq/ne, if the operands are known to be zero-extended,
15315 there is no need to do the fancy shifting up. */
15316 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
15318 dw_loc_descr_ref last0
, last1
;
15319 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
15321 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
15323 /* deref_size zero extends, and for constants we can check
15324 whether they are zero extended or not. */
15325 if (((last0
->dw_loc_opc
== DW_OP_deref_size
15326 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
15327 || (CONST_INT_P (XEXP (rtl
, 0))
15328 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
15329 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
15330 && ((last1
->dw_loc_opc
== DW_OP_deref_size
15331 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
15332 || (CONST_INT_P (XEXP (rtl
, 1))
15333 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
15334 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
15335 return compare_loc_descriptor (op
, op0
, op1
);
15337 /* EQ/NE comparison against constant in narrower type than
15338 DWARF2_ADDR_SIZE can be performed either as
15339 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
15342 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
15343 DW_OP_{eq,ne}. Pick whatever is shorter. */
15344 if (CONST_INT_P (XEXP (rtl
, 1))
15345 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
15346 && (size_of_int_loc_descriptor (shift
) + 1
15347 + size_of_int_loc_descriptor (UINTVAL (XEXP (rtl
, 1)) << shift
)
15348 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
15349 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
15350 & GET_MODE_MASK (op_mode
))))
15352 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
15353 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
15354 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
15355 & GET_MODE_MASK (op_mode
));
15356 return compare_loc_descriptor (op
, op0
, op1
);
15359 add_loc_descr (&op0
, int_loc_descriptor (shift
));
15360 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
15361 if (CONST_INT_P (XEXP (rtl
, 1)))
15362 op1
= int_loc_descriptor (UINTVAL (XEXP (rtl
, 1)) << shift
);
15365 add_loc_descr (&op1
, int_loc_descriptor (shift
));
15366 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
15368 return compare_loc_descriptor (op
, op0
, op1
);
15371 /* Return location descriptor for signed comparison OP RTL. */
15373 static dw_loc_descr_ref
15374 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
15375 machine_mode mem_mode
)
15377 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
15378 dw_loc_descr_ref op0
, op1
;
15380 if (op_mode
== VOIDmode
)
15381 op_mode
= GET_MODE (XEXP (rtl
, 1));
15382 if (op_mode
== VOIDmode
)
15385 scalar_int_mode int_op_mode
;
15387 && dwarf_version
< 5
15388 && (!is_a
<scalar_int_mode
> (op_mode
, &int_op_mode
)
15389 || GET_MODE_SIZE (int_op_mode
) > DWARF2_ADDR_SIZE
))
15392 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
15393 VAR_INIT_STATUS_INITIALIZED
);
15394 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
15395 VAR_INIT_STATUS_INITIALIZED
);
15397 if (op0
== NULL
|| op1
== NULL
)
15400 if (is_a
<scalar_int_mode
> (op_mode
, &int_op_mode
))
15402 if (GET_MODE_SIZE (int_op_mode
) < DWARF2_ADDR_SIZE
)
15403 return scompare_loc_descriptor_narrow (op
, rtl
, int_op_mode
, op0
, op1
);
15405 if (GET_MODE_SIZE (int_op_mode
) > DWARF2_ADDR_SIZE
)
15406 return scompare_loc_descriptor_wide (op
, int_op_mode
, op0
, op1
);
15408 return compare_loc_descriptor (op
, op0
, op1
);
15411 /* Return location descriptor for unsigned comparison OP RTL. */
15413 static dw_loc_descr_ref
15414 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
15415 machine_mode mem_mode
)
15417 dw_loc_descr_ref op0
, op1
;
15419 machine_mode test_op_mode
= GET_MODE (XEXP (rtl
, 0));
15420 if (test_op_mode
== VOIDmode
)
15421 test_op_mode
= GET_MODE (XEXP (rtl
, 1));
15423 scalar_int_mode op_mode
;
15424 if (!is_a
<scalar_int_mode
> (test_op_mode
, &op_mode
))
15428 && dwarf_version
< 5
15429 && GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
15432 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
15433 VAR_INIT_STATUS_INITIALIZED
);
15434 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
15435 VAR_INIT_STATUS_INITIALIZED
);
15437 if (op0
== NULL
|| op1
== NULL
)
15440 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
15442 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
15443 dw_loc_descr_ref last0
, last1
;
15444 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
15446 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
15448 if (CONST_INT_P (XEXP (rtl
, 0)))
15449 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
15450 /* deref_size zero extends, so no need to mask it again. */
15451 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
15452 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
15454 add_loc_descr (&op0
, int_loc_descriptor (mask
));
15455 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
15457 if (CONST_INT_P (XEXP (rtl
, 1)))
15458 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
15459 /* deref_size zero extends, so no need to mask it again. */
15460 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
15461 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
15463 add_loc_descr (&op1
, int_loc_descriptor (mask
));
15464 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
15467 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
15469 HOST_WIDE_INT bias
= 1;
15470 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
15471 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
15472 if (CONST_INT_P (XEXP (rtl
, 1)))
15473 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
15474 + INTVAL (XEXP (rtl
, 1)));
15476 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
15479 return compare_loc_descriptor (op
, op0
, op1
);
15482 /* Return location descriptor for {U,S}{MIN,MAX}. */
15484 static dw_loc_descr_ref
15485 minmax_loc_descriptor (rtx rtl
, machine_mode mode
,
15486 machine_mode mem_mode
)
15488 enum dwarf_location_atom op
;
15489 dw_loc_descr_ref op0
, op1
, ret
;
15490 dw_loc_descr_ref bra_node
, drop_node
;
15492 scalar_int_mode int_mode
;
15494 && dwarf_version
< 5
15495 && (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
15496 || GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
))
15499 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15500 VAR_INIT_STATUS_INITIALIZED
);
15501 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15502 VAR_INIT_STATUS_INITIALIZED
);
15504 if (op0
== NULL
|| op1
== NULL
)
15507 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
15508 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
15509 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
15510 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
15512 /* Checked by the caller. */
15513 int_mode
= as_a
<scalar_int_mode
> (mode
);
15514 if (GET_MODE_SIZE (int_mode
) < DWARF2_ADDR_SIZE
)
15516 HOST_WIDE_INT mask
= GET_MODE_MASK (int_mode
);
15517 add_loc_descr (&op0
, int_loc_descriptor (mask
));
15518 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
15519 add_loc_descr (&op1
, int_loc_descriptor (mask
));
15520 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
15522 else if (GET_MODE_SIZE (int_mode
) == DWARF2_ADDR_SIZE
)
15524 HOST_WIDE_INT bias
= 1;
15525 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
15526 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
15527 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
15530 else if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
15531 && GET_MODE_SIZE (int_mode
) < DWARF2_ADDR_SIZE
)
15533 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (int_mode
)) * BITS_PER_UNIT
;
15534 add_loc_descr (&op0
, int_loc_descriptor (shift
));
15535 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
15536 add_loc_descr (&op1
, int_loc_descriptor (shift
));
15537 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
15539 else if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
15540 && GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
15542 dw_die_ref type_die
= base_type_for_mode (int_mode
, 0);
15543 dw_loc_descr_ref cvt
;
15544 if (type_die
== NULL
)
15546 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15547 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15548 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15549 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15550 add_loc_descr (&op0
, cvt
);
15551 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15552 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15553 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15554 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15555 add_loc_descr (&op1
, cvt
);
15558 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
15563 add_loc_descr (&ret
, op1
);
15564 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
15565 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
15566 add_loc_descr (&ret
, bra_node
);
15567 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15568 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
15569 add_loc_descr (&ret
, drop_node
);
15570 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15571 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
15572 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
15573 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
15574 && GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
15575 ret
= convert_descriptor_to_mode (int_mode
, ret
);
15579 /* Helper function for mem_loc_descriptor. Perform OP binary op,
15580 but after converting arguments to type_die, afterwards
15581 convert back to unsigned. */
15583 static dw_loc_descr_ref
15584 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
15585 scalar_int_mode mode
, machine_mode mem_mode
)
15587 dw_loc_descr_ref cvt
, op0
, op1
;
15589 if (type_die
== NULL
)
15591 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15592 VAR_INIT_STATUS_INITIALIZED
);
15593 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15594 VAR_INIT_STATUS_INITIALIZED
);
15595 if (op0
== NULL
|| op1
== NULL
)
15597 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15598 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15599 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15600 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15601 add_loc_descr (&op0
, cvt
);
15602 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15603 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15604 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15605 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15606 add_loc_descr (&op1
, cvt
);
15607 add_loc_descr (&op0
, op1
);
15608 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
15609 return convert_descriptor_to_mode (mode
, op0
);
15612 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
15613 const0 is DW_OP_lit0 or corresponding typed constant,
15614 const1 is DW_OP_lit1 or corresponding typed constant
15615 and constMSB is constant with just the MSB bit set
15617 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
15618 L1: const0 DW_OP_swap
15619 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
15620 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
15625 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
15626 L1: const0 DW_OP_swap
15627 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
15628 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
15633 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
15634 L1: const1 DW_OP_swap
15635 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
15636 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
15640 static dw_loc_descr_ref
15641 clz_loc_descriptor (rtx rtl
, scalar_int_mode mode
,
15642 machine_mode mem_mode
)
15644 dw_loc_descr_ref op0
, ret
, tmp
;
15645 HOST_WIDE_INT valv
;
15646 dw_loc_descr_ref l1jump
, l1label
;
15647 dw_loc_descr_ref l2jump
, l2label
;
15648 dw_loc_descr_ref l3jump
, l3label
;
15649 dw_loc_descr_ref l4jump
, l4label
;
15652 if (GET_MODE (XEXP (rtl
, 0)) != mode
)
15655 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15656 VAR_INIT_STATUS_INITIALIZED
);
15660 if (GET_CODE (rtl
) == CLZ
)
15662 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
15663 valv
= GET_MODE_BITSIZE (mode
);
15665 else if (GET_CODE (rtl
) == FFS
)
15667 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
15668 valv
= GET_MODE_BITSIZE (mode
);
15669 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
15670 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
15671 add_loc_descr (&ret
, l1jump
);
15672 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
15673 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
15674 VAR_INIT_STATUS_INITIALIZED
);
15677 add_loc_descr (&ret
, tmp
);
15678 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
15679 add_loc_descr (&ret
, l4jump
);
15680 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
15681 ? const1_rtx
: const0_rtx
,
15683 VAR_INIT_STATUS_INITIALIZED
);
15684 if (l1label
== NULL
)
15686 add_loc_descr (&ret
, l1label
);
15687 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15688 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
15689 add_loc_descr (&ret
, l2label
);
15690 if (GET_CODE (rtl
) != CLZ
)
15692 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
15693 msb
= GEN_INT (HOST_WIDE_INT_1U
15694 << (GET_MODE_BITSIZE (mode
) - 1));
15696 msb
= immed_wide_int_const
15697 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode
) - 1,
15698 GET_MODE_PRECISION (mode
)), mode
);
15699 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
15700 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
15701 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
15702 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
15704 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
15705 VAR_INIT_STATUS_INITIALIZED
);
15708 add_loc_descr (&ret
, tmp
);
15709 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
15710 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
15711 add_loc_descr (&ret
, l3jump
);
15712 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
15713 VAR_INIT_STATUS_INITIALIZED
);
15716 add_loc_descr (&ret
, tmp
);
15717 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
15718 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
15719 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15720 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
15721 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15722 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
15723 add_loc_descr (&ret
, l2jump
);
15724 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
15725 add_loc_descr (&ret
, l3label
);
15726 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
15727 add_loc_descr (&ret
, l4label
);
15728 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15729 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
15730 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15731 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
15732 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15733 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
15734 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15735 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
15739 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
15740 const1 is DW_OP_lit1 or corresponding typed constant):
15742 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
15743 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
15747 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
15748 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
15751 static dw_loc_descr_ref
15752 popcount_loc_descriptor (rtx rtl
, scalar_int_mode mode
,
15753 machine_mode mem_mode
)
15755 dw_loc_descr_ref op0
, ret
, tmp
;
15756 dw_loc_descr_ref l1jump
, l1label
;
15757 dw_loc_descr_ref l2jump
, l2label
;
15759 if (GET_MODE (XEXP (rtl
, 0)) != mode
)
15762 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15763 VAR_INIT_STATUS_INITIALIZED
);
15767 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
15768 VAR_INIT_STATUS_INITIALIZED
);
15771 add_loc_descr (&ret
, tmp
);
15772 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15773 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
15774 add_loc_descr (&ret
, l1label
);
15775 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
15776 add_loc_descr (&ret
, l2jump
);
15777 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
15778 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
15779 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
15780 VAR_INIT_STATUS_INITIALIZED
);
15783 add_loc_descr (&ret
, tmp
);
15784 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
15785 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
15786 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
15787 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15788 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
15789 VAR_INIT_STATUS_INITIALIZED
);
15790 add_loc_descr (&ret
, tmp
);
15791 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
15792 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
15793 add_loc_descr (&ret
, l1jump
);
15794 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
15795 add_loc_descr (&ret
, l2label
);
15796 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15797 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
15798 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15799 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
15803 /* BSWAP (constS is initial shift count, either 56 or 24):
15805 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
15806 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
15807 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
15808 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
15809 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
15811 static dw_loc_descr_ref
15812 bswap_loc_descriptor (rtx rtl
, scalar_int_mode mode
,
15813 machine_mode mem_mode
)
15815 dw_loc_descr_ref op0
, ret
, tmp
;
15816 dw_loc_descr_ref l1jump
, l1label
;
15817 dw_loc_descr_ref l2jump
, l2label
;
15819 if (BITS_PER_UNIT
!= 8
15820 || (GET_MODE_BITSIZE (mode
) != 32
15821 && GET_MODE_BITSIZE (mode
) != 64))
15824 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15825 VAR_INIT_STATUS_INITIALIZED
);
15830 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
15832 VAR_INIT_STATUS_INITIALIZED
);
15835 add_loc_descr (&ret
, tmp
);
15836 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
15837 VAR_INIT_STATUS_INITIALIZED
);
15840 add_loc_descr (&ret
, tmp
);
15841 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
15842 add_loc_descr (&ret
, l1label
);
15843 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
15845 VAR_INIT_STATUS_INITIALIZED
);
15846 add_loc_descr (&ret
, tmp
);
15847 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
15848 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
15849 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
15850 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
15851 VAR_INIT_STATUS_INITIALIZED
);
15854 add_loc_descr (&ret
, tmp
);
15855 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
15856 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
15857 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
15858 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
15859 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15860 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
15861 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
15862 VAR_INIT_STATUS_INITIALIZED
);
15863 add_loc_descr (&ret
, tmp
);
15864 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
15865 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
15866 add_loc_descr (&ret
, l2jump
);
15867 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
15868 VAR_INIT_STATUS_INITIALIZED
);
15869 add_loc_descr (&ret
, tmp
);
15870 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
15871 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15872 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
15873 add_loc_descr (&ret
, l1jump
);
15874 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
15875 add_loc_descr (&ret
, l2label
);
15876 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15877 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
15878 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15879 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
15880 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15881 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
15885 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
15886 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
15887 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
15888 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
15890 ROTATERT is similar:
15891 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
15892 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
15893 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
15895 static dw_loc_descr_ref
15896 rotate_loc_descriptor (rtx rtl
, scalar_int_mode mode
,
15897 machine_mode mem_mode
)
15899 rtx rtlop1
= XEXP (rtl
, 1);
15900 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
15903 if (is_narrower_int_mode (GET_MODE (rtlop1
), mode
))
15904 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
15905 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15906 VAR_INIT_STATUS_INITIALIZED
);
15907 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
15908 VAR_INIT_STATUS_INITIALIZED
);
15909 if (op0
== NULL
|| op1
== NULL
)
15911 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
15912 for (i
= 0; i
< 2; i
++)
15914 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
15915 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
15917 VAR_INIT_STATUS_INITIALIZED
);
15918 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
15919 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
15921 : HOST_BITS_PER_WIDE_INT
== 64
15922 ? DW_OP_const8u
: DW_OP_constu
,
15923 GET_MODE_MASK (mode
), 0);
15926 if (mask
[i
] == NULL
)
15928 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
15931 add_loc_descr (&ret
, op1
);
15932 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
15933 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
15934 if (GET_CODE (rtl
) == ROTATERT
)
15936 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
15937 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
15938 GET_MODE_BITSIZE (mode
), 0));
15940 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
15941 if (mask
[0] != NULL
)
15942 add_loc_descr (&ret
, mask
[0]);
15943 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
15944 if (mask
[1] != NULL
)
15946 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15947 add_loc_descr (&ret
, mask
[1]);
15948 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15950 if (GET_CODE (rtl
) == ROTATE
)
15952 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
15953 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
15954 GET_MODE_BITSIZE (mode
), 0));
15956 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
15957 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
15961 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
15962 for DEBUG_PARAMETER_REF RTL. */
15964 static dw_loc_descr_ref
15965 parameter_ref_descriptor (rtx rtl
)
15967 dw_loc_descr_ref ret
;
15972 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
15973 /* With LTO during LTRANS we get the late DIE that refers to the early
15974 DIE, thus we add another indirection here. This seems to confuse
15975 gdb enough to make gcc.dg/guality/pr68860-1.c FAIL with LTO. */
15976 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
15977 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
15980 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15981 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
15982 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15986 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
15987 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
15992 /* The following routine converts the RTL for a variable or parameter
15993 (resident in memory) into an equivalent Dwarf representation of a
15994 mechanism for getting the address of that same variable onto the top of a
15995 hypothetical "address evaluation" stack.
15997 When creating memory location descriptors, we are effectively transforming
15998 the RTL for a memory-resident object into its Dwarf postfix expression
15999 equivalent. This routine recursively descends an RTL tree, turning
16000 it into Dwarf postfix code as it goes.
16002 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
16004 MEM_MODE is the mode of the memory reference, needed to handle some
16005 autoincrement addressing modes.
16007 Return 0 if we can't represent the location. */
16010 mem_loc_descriptor (rtx rtl
, machine_mode mode
,
16011 machine_mode mem_mode
,
16012 enum var_init_status initialized
)
16014 dw_loc_descr_ref mem_loc_result
= NULL
;
16015 enum dwarf_location_atom op
;
16016 dw_loc_descr_ref op0
, op1
;
16017 rtx inner
= NULL_RTX
;
16019 if (mode
== VOIDmode
)
16020 mode
= GET_MODE (rtl
);
16022 /* Note that for a dynamically sized array, the location we will generate a
16023 description of here will be the lowest numbered location which is
16024 actually within the array. That's *not* necessarily the same as the
16025 zeroth element of the array. */
16027 rtl
= targetm
.delegitimize_address (rtl
);
16029 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
16032 scalar_int_mode int_mode
= BImode
, inner_mode
, op1_mode
;
16033 switch (GET_CODE (rtl
))
16038 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
16041 /* The case of a subreg may arise when we have a local (register)
16042 variable or a formal (register) parameter which doesn't quite fill
16043 up an entire register. For now, just assume that it is
16044 legitimate to make the Dwarf info refer to the whole register which
16045 contains the given subreg. */
16046 if (!subreg_lowpart_p (rtl
))
16048 inner
= SUBREG_REG (rtl
);
16051 if (inner
== NULL_RTX
)
16052 inner
= XEXP (rtl
, 0);
16053 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
16054 && is_a
<scalar_int_mode
> (GET_MODE (inner
), &inner_mode
)
16055 && (GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
16056 #ifdef POINTERS_EXTEND_UNSIGNED
16057 || (int_mode
== Pmode
&& mem_mode
!= VOIDmode
)
16060 && GET_MODE_SIZE (inner_mode
) <= DWARF2_ADDR_SIZE
)
16062 mem_loc_result
= mem_loc_descriptor (inner
,
16064 mem_mode
, initialized
);
16067 if (dwarf_strict
&& dwarf_version
< 5)
16069 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
16070 && is_a
<scalar_int_mode
> (GET_MODE (inner
), &inner_mode
)
16071 ? GET_MODE_SIZE (int_mode
) <= GET_MODE_SIZE (inner_mode
)
16072 : known_eq (GET_MODE_SIZE (mode
), GET_MODE_SIZE (GET_MODE (inner
))))
16074 dw_die_ref type_die
;
16075 dw_loc_descr_ref cvt
;
16077 mem_loc_result
= mem_loc_descriptor (inner
,
16079 mem_mode
, initialized
);
16080 if (mem_loc_result
== NULL
)
16082 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
16083 if (type_die
== NULL
)
16085 mem_loc_result
= NULL
;
16088 if (maybe_ne (GET_MODE_SIZE (mode
), GET_MODE_SIZE (GET_MODE (inner
))))
16089 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
16091 cvt
= new_loc_descr (dwarf_OP (DW_OP_reinterpret
), 0, 0);
16092 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16093 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
16094 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16095 add_loc_descr (&mem_loc_result
, cvt
);
16096 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
16097 && GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
)
16099 /* Convert it to untyped afterwards. */
16100 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
16101 add_loc_descr (&mem_loc_result
, cvt
);
16107 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
16108 || (GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
16109 && rtl
!= arg_pointer_rtx
16110 && rtl
!= frame_pointer_rtx
16111 #ifdef POINTERS_EXTEND_UNSIGNED
16112 && (int_mode
!= Pmode
|| mem_mode
== VOIDmode
)
16116 dw_die_ref type_die
;
16117 unsigned int debugger_regnum
;
16119 if (dwarf_strict
&& dwarf_version
< 5)
16121 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
16123 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
16124 if (type_die
== NULL
)
16127 debugger_regnum
= debugger_reg_number (rtl
);
16128 if (debugger_regnum
== IGNORED_DWARF_REGNUM
)
16130 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_regval_type
),
16131 debugger_regnum
, 0);
16132 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
16133 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
16134 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
16137 /* Whenever a register number forms a part of the description of the
16138 method for calculating the (dynamic) address of a memory resident
16139 object, DWARF rules require the register number be referred to as
16140 a "base register". This distinction is not based in any way upon
16141 what category of register the hardware believes the given register
16142 belongs to. This is strictly DWARF terminology we're dealing with
16143 here. Note that in cases where the location of a memory-resident
16144 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
16145 OP_CONST (0)) the actual DWARF location descriptor that we generate
16146 may just be OP_BASEREG (basereg). This may look deceptively like
16147 the object in question was allocated to a register (rather than in
16148 memory) so DWARF consumers need to be aware of the subtle
16149 distinction between OP_REG and OP_BASEREG. */
16150 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
16151 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
16152 else if (stack_realign_drap
16154 && crtl
->args
.internal_arg_pointer
== rtl
16155 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
16157 /* If RTL is internal_arg_pointer, which has been optimized
16158 out, use DRAP instead. */
16159 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
16160 VAR_INIT_STATUS_INITIALIZED
);
16166 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
16167 || !is_a
<scalar_int_mode
> (GET_MODE (XEXP (rtl
, 0)), &inner_mode
))
16169 op0
= mem_loc_descriptor (XEXP (rtl
, 0), inner_mode
,
16170 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
16173 else if (GET_CODE (rtl
) == ZERO_EXTEND
16174 && GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
16175 && GET_MODE_BITSIZE (inner_mode
) < HOST_BITS_PER_WIDE_INT
16176 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
16177 to expand zero extend as two shifts instead of
16179 && GET_MODE_SIZE (inner_mode
) <= 4)
16181 mem_loc_result
= op0
;
16182 add_loc_descr (&mem_loc_result
,
16183 int_loc_descriptor (GET_MODE_MASK (inner_mode
)));
16184 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
16186 else if (GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
)
16188 int shift
= DWARF2_ADDR_SIZE
- GET_MODE_SIZE (inner_mode
);
16189 shift
*= BITS_PER_UNIT
;
16190 if (GET_CODE (rtl
) == SIGN_EXTEND
)
16194 mem_loc_result
= op0
;
16195 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
16196 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
16197 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
16198 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
16200 else if (!dwarf_strict
|| dwarf_version
>= 5)
16202 dw_die_ref type_die1
, type_die2
;
16203 dw_loc_descr_ref cvt
;
16205 type_die1
= base_type_for_mode (inner_mode
,
16206 GET_CODE (rtl
) == ZERO_EXTEND
);
16207 if (type_die1
== NULL
)
16209 type_die2
= base_type_for_mode (int_mode
, 1);
16210 if (type_die2
== NULL
)
16212 mem_loc_result
= op0
;
16213 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
16214 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16215 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
16216 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16217 add_loc_descr (&mem_loc_result
, cvt
);
16218 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
16219 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16220 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
16221 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16222 add_loc_descr (&mem_loc_result
, cvt
);
16228 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
16229 if (new_rtl
!= rtl
)
16231 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
16233 if (mem_loc_result
!= NULL
)
16234 return mem_loc_result
;
16237 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
16238 get_address_mode (rtl
), mode
,
16239 VAR_INIT_STATUS_INITIALIZED
);
16240 if (mem_loc_result
== NULL
)
16241 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
16242 if (mem_loc_result
!= NULL
)
16244 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
16245 || GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
16247 dw_die_ref type_die
;
16248 dw_loc_descr_ref deref
;
16249 HOST_WIDE_INT size
;
16251 if (dwarf_strict
&& dwarf_version
< 5)
16253 if (!GET_MODE_SIZE (mode
).is_constant (&size
))
16256 = base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
16257 if (type_die
== NULL
)
16259 deref
= new_loc_descr (dwarf_OP (DW_OP_deref_type
), size
, 0);
16260 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
16261 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
16262 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
16263 add_loc_descr (&mem_loc_result
, deref
);
16265 else if (GET_MODE_SIZE (int_mode
) == DWARF2_ADDR_SIZE
)
16266 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
16268 add_loc_descr (&mem_loc_result
,
16269 new_loc_descr (DW_OP_deref_size
,
16270 GET_MODE_SIZE (int_mode
), 0));
16275 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
16278 /* Some ports can transform a symbol ref into a label ref, because
16279 the symbol ref is too far away and has to be dumped into a constant
16284 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
16285 || (GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
16286 #ifdef POINTERS_EXTEND_UNSIGNED
16287 && (int_mode
!= Pmode
|| mem_mode
== VOIDmode
)
16292 if (GET_CODE (rtl
) == UNSPEC
)
16294 /* If delegitimize_address couldn't do anything with the UNSPEC, we
16295 can't express it in the debug info. This can happen e.g. with some
16296 TLS UNSPECs. Allow UNSPECs formerly from CONST that the backend
16298 bool not_ok
= false;
16299 subrtx_var_iterator::array_type array
;
16300 FOR_EACH_SUBRTX_VAR (iter
, array
, rtl
, ALL
)
16301 if (*iter
!= rtl
&& !CONSTANT_P (*iter
))
16310 FOR_EACH_SUBRTX_VAR (iter
, array
, rtl
, ALL
)
16311 if (!const_ok_for_output_1 (*iter
))
16320 rtl
= gen_rtx_CONST (GET_MODE (rtl
), rtl
);
16324 if (GET_CODE (rtl
) == SYMBOL_REF
16325 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
16327 dw_loc_descr_ref temp
;
16329 /* If this is not defined, we have no way to emit the data. */
16330 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
16333 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
16335 /* We check for DWARF 5 here because gdb did not implement
16336 DW_OP_form_tls_address until after 7.12. */
16337 mem_loc_result
= new_loc_descr ((dwarf_version
>= 5
16338 ? DW_OP_form_tls_address
16339 : DW_OP_GNU_push_tls_address
),
16341 add_loc_descr (&mem_loc_result
, temp
);
16346 if (!const_ok_for_output (rtl
))
16348 if (GET_CODE (rtl
) == CONST
)
16349 switch (GET_CODE (XEXP (rtl
, 0)))
16353 goto try_const_unop
;
16356 goto try_const_unop
;
16359 arg
= XEXP (XEXP (rtl
, 0), 0);
16360 if (!CONSTANT_P (arg
))
16361 arg
= gen_rtx_CONST (int_mode
, arg
);
16362 op0
= mem_loc_descriptor (arg
, int_mode
, mem_mode
,
16366 mem_loc_result
= op0
;
16367 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
16371 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), int_mode
,
16372 mem_mode
, initialized
);
16379 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
16380 vec_safe_push (used_rtx_array
, rtl
);
16386 case DEBUG_IMPLICIT_PTR
:
16387 expansion_failed (NULL_TREE
, rtl
,
16388 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
16392 if (dwarf_strict
&& dwarf_version
< 5)
16394 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
16396 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
16397 || GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
16398 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
16399 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
16402 unsigned int debugger_regnum
= debugger_reg_number (ENTRY_VALUE_EXP (rtl
));
16403 if (debugger_regnum
== IGNORED_DWARF_REGNUM
)
16405 op0
= one_reg_loc_descriptor (debugger_regnum
,
16406 VAR_INIT_STATUS_INITIALIZED
);
16409 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
16410 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
16412 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
16413 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
16414 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
16418 gcc_unreachable ();
16421 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_entry_value
), 0, 0);
16422 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
16423 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
16426 case DEBUG_PARAMETER_REF
:
16427 mem_loc_result
= parameter_ref_descriptor (rtl
);
16431 /* Extract the PLUS expression nested inside and fall into
16432 PLUS code below. */
16433 rtl
= XEXP (rtl
, 1);
16438 /* Turn these into a PLUS expression and fall into the PLUS code
16440 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
16441 gen_int_mode (GET_CODE (rtl
) == PRE_INC
16442 ? GET_MODE_UNIT_SIZE (mem_mode
)
16443 : -GET_MODE_UNIT_SIZE (mem_mode
),
16450 if (is_based_loc (rtl
)
16451 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
16452 && (GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
16453 || XEXP (rtl
, 0) == arg_pointer_rtx
16454 || XEXP (rtl
, 0) == frame_pointer_rtx
))
16455 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
16456 INTVAL (XEXP (rtl
, 1)),
16457 VAR_INIT_STATUS_INITIALIZED
);
16460 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
16461 VAR_INIT_STATUS_INITIALIZED
);
16462 if (mem_loc_result
== 0)
16465 if (CONST_INT_P (XEXP (rtl
, 1))
16466 && (GET_MODE_SIZE (as_a
<scalar_int_mode
> (mode
))
16467 <= DWARF2_ADDR_SIZE
))
16468 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
16471 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
16472 VAR_INIT_STATUS_INITIALIZED
);
16475 add_loc_descr (&mem_loc_result
, op1
);
16476 add_loc_descr (&mem_loc_result
,
16477 new_loc_descr (DW_OP_plus
, 0, 0));
16482 /* If a pseudo-reg is optimized away, it is possible for it to
16483 be replaced with a MEM containing a multiply or shift. */
16493 if ((!dwarf_strict
|| dwarf_version
>= 5)
16494 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
16495 && GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
16497 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
16498 base_type_for_mode (mode
, 0),
16499 int_mode
, mem_mode
);
16522 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
))
16524 op0
= mem_loc_descriptor (XEXP (rtl
, 0), int_mode
, mem_mode
,
16525 VAR_INIT_STATUS_INITIALIZED
);
16527 rtx rtlop1
= XEXP (rtl
, 1);
16528 if (is_a
<scalar_int_mode
> (GET_MODE (rtlop1
), &op1_mode
)
16529 && GET_MODE_BITSIZE (op1_mode
) < GET_MODE_BITSIZE (int_mode
))
16530 rtlop1
= gen_rtx_ZERO_EXTEND (int_mode
, rtlop1
);
16531 op1
= mem_loc_descriptor (rtlop1
, int_mode
, mem_mode
,
16532 VAR_INIT_STATUS_INITIALIZED
);
16535 if (op0
== 0 || op1
== 0)
16538 mem_loc_result
= op0
;
16539 add_loc_descr (&mem_loc_result
, op1
);
16540 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
16556 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
16557 VAR_INIT_STATUS_INITIALIZED
);
16558 if (XEXP (rtl
, 0) == XEXP (rtl
, 1))
16562 mem_loc_result
= op0
;
16563 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_dup
, 0, 0));
16564 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
16567 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
16568 VAR_INIT_STATUS_INITIALIZED
);
16570 if (op0
== 0 || op1
== 0)
16573 mem_loc_result
= op0
;
16574 add_loc_descr (&mem_loc_result
, op1
);
16575 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
16579 if ((!dwarf_strict
|| dwarf_version
>= 5)
16580 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
16581 && GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
16583 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
16584 base_type_for_mode (mode
, 0),
16585 int_mode
, mem_mode
);
16589 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
16590 VAR_INIT_STATUS_INITIALIZED
);
16591 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
16592 VAR_INIT_STATUS_INITIALIZED
);
16594 if (op0
== 0 || op1
== 0)
16597 mem_loc_result
= op0
;
16598 add_loc_descr (&mem_loc_result
, op1
);
16599 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
16600 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
16601 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
16602 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
16603 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
16607 if ((!dwarf_strict
|| dwarf_version
>= 5)
16608 && is_a
<scalar_int_mode
> (mode
, &int_mode
))
16610 /* We can use a signed divide if the sign bit is not set. */
16611 if (GET_MODE_SIZE (int_mode
) < DWARF2_ADDR_SIZE
)
16617 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
16618 base_type_for_mode (int_mode
, 1),
16619 int_mode
, mem_mode
);
16636 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
16637 VAR_INIT_STATUS_INITIALIZED
);
16642 mem_loc_result
= op0
;
16643 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
16647 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
16648 || GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
16649 #ifdef POINTERS_EXTEND_UNSIGNED
16650 || (int_mode
== Pmode
16651 && mem_mode
!= VOIDmode
16652 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
16656 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
16659 if ((!dwarf_strict
|| dwarf_version
>= 5)
16660 && (GET_MODE_BITSIZE (int_mode
) == HOST_BITS_PER_WIDE_INT
16661 || GET_MODE_BITSIZE (int_mode
) == HOST_BITS_PER_DOUBLE_INT
))
16663 dw_die_ref type_die
= base_type_for_mode (int_mode
, 1);
16664 scalar_int_mode amode
;
16665 if (type_die
== NULL
)
16667 if (INTVAL (rtl
) >= 0
16668 && (int_mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
, 0)
16670 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
16671 /* const DW_OP_convert <XXX> vs.
16672 DW_OP_const_type <XXX, 1, const>. */
16673 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
16674 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (int_mode
))
16676 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
16677 op0
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
16678 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16679 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
16680 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16681 add_loc_descr (&mem_loc_result
, op0
);
16682 return mem_loc_result
;
16684 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0,
16686 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16687 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
16688 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16689 if (GET_MODE_BITSIZE (int_mode
) == HOST_BITS_PER_WIDE_INT
)
16690 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
16693 mem_loc_result
->dw_loc_oprnd2
.val_class
16694 = dw_val_class_const_double
;
16695 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
16696 = double_int::from_shwi (INTVAL (rtl
));
16702 if (!dwarf_strict
|| dwarf_version
>= 5)
16704 dw_die_ref type_die
;
16706 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
16707 CONST_DOUBLE rtx could represent either a large integer
16708 or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
16709 the value is always a floating point constant.
16711 When it is an integer, a CONST_DOUBLE is used whenever
16712 the constant requires 2 HWIs to be adequately represented.
16713 We output CONST_DOUBLEs as blocks. */
16714 if (mode
== VOIDmode
16715 || (GET_MODE (rtl
) == VOIDmode
16716 && maybe_ne (GET_MODE_BITSIZE (mode
),
16717 HOST_BITS_PER_DOUBLE_INT
)))
16719 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
16720 if (type_die
== NULL
)
16722 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0, 0);
16723 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16724 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
16725 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16726 #if TARGET_SUPPORTS_WIDE_INT == 0
16727 if (!SCALAR_FLOAT_MODE_P (mode
))
16729 mem_loc_result
->dw_loc_oprnd2
.val_class
16730 = dw_val_class_const_double
;
16731 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
16732 = rtx_to_double_int (rtl
);
16737 scalar_float_mode float_mode
= as_a
<scalar_float_mode
> (mode
);
16738 unsigned int length
= GET_MODE_SIZE (float_mode
);
16739 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
16740 unsigned int elt_size
= insert_float (rtl
, array
);
16742 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
16743 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
16744 = length
/ elt_size
;
16745 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
16746 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
16751 case CONST_WIDE_INT
:
16752 if (!dwarf_strict
|| dwarf_version
>= 5)
16754 dw_die_ref type_die
;
16756 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
16757 if (type_die
== NULL
)
16759 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0, 0);
16760 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16761 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
16762 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16763 mem_loc_result
->dw_loc_oprnd2
.val_class
16764 = dw_val_class_wide_int
;
16765 mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
16766 = alloc_dw_wide_int (rtx_mode_t (rtl
, mode
));
16770 case CONST_POLY_INT
:
16771 mem_loc_result
= int_loc_descriptor (rtx_to_poly_int64 (rtl
));
16775 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
16779 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
16783 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
16787 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
16791 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
16795 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
16799 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
16803 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
16807 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
16811 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
16816 if (!SCALAR_INT_MODE_P (mode
))
16821 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
16826 if (CONST_INT_P (XEXP (rtl
, 1))
16827 && CONST_INT_P (XEXP (rtl
, 2))
16828 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
16829 && is_a
<scalar_int_mode
> (GET_MODE (XEXP (rtl
, 0)), &inner_mode
)
16830 && GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
16831 && GET_MODE_SIZE (inner_mode
) <= DWARF2_ADDR_SIZE
16832 && ((unsigned) INTVAL (XEXP (rtl
, 1))
16833 + (unsigned) INTVAL (XEXP (rtl
, 2))
16834 <= GET_MODE_BITSIZE (int_mode
)))
16837 op0
= mem_loc_descriptor (XEXP (rtl
, 0), inner_mode
,
16838 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
16841 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
16845 mem_loc_result
= op0
;
16846 size
= INTVAL (XEXP (rtl
, 1));
16847 shift
= INTVAL (XEXP (rtl
, 2));
16848 if (BITS_BIG_ENDIAN
)
16849 shift
= GET_MODE_BITSIZE (inner_mode
) - shift
- size
;
16850 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
16852 add_loc_descr (&mem_loc_result
,
16853 int_loc_descriptor (DWARF2_ADDR_SIZE
16855 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
16857 if (size
!= (int) DWARF2_ADDR_SIZE
)
16859 add_loc_descr (&mem_loc_result
,
16860 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
16861 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
16868 dw_loc_descr_ref op2
, bra_node
, drop_node
;
16869 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
16870 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
16871 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
16872 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
16873 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
16874 VAR_INIT_STATUS_INITIALIZED
);
16875 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
16876 VAR_INIT_STATUS_INITIALIZED
);
16877 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
16880 mem_loc_result
= op1
;
16881 add_loc_descr (&mem_loc_result
, op2
);
16882 add_loc_descr (&mem_loc_result
, op0
);
16883 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
16884 add_loc_descr (&mem_loc_result
, bra_node
);
16885 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
16886 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
16887 add_loc_descr (&mem_loc_result
, drop_node
);
16888 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
16889 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
16894 case FLOAT_TRUNCATE
:
16896 case UNSIGNED_FLOAT
:
16899 if (!dwarf_strict
|| dwarf_version
>= 5)
16901 dw_die_ref type_die
;
16902 dw_loc_descr_ref cvt
;
16904 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
16905 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
16908 if (is_a
<scalar_int_mode
> (GET_MODE (XEXP (rtl
, 0)), &int_mode
)
16909 && (GET_CODE (rtl
) == FLOAT
16910 || GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
))
16912 type_die
= base_type_for_mode (int_mode
,
16913 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
16914 if (type_die
== NULL
)
16916 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
16917 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16918 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
16919 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16920 add_loc_descr (&op0
, cvt
);
16922 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
16923 if (type_die
== NULL
)
16925 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
16926 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16927 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
16928 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16929 add_loc_descr (&op0
, cvt
);
16930 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
16931 && (GET_CODE (rtl
) == FIX
16932 || GET_MODE_SIZE (int_mode
) < DWARF2_ADDR_SIZE
))
16934 op0
= convert_descriptor_to_mode (int_mode
, op0
);
16938 mem_loc_result
= op0
;
16945 if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
16946 mem_loc_result
= clz_loc_descriptor (rtl
, int_mode
, mem_mode
);
16951 if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
16952 mem_loc_result
= popcount_loc_descriptor (rtl
, int_mode
, mem_mode
);
16956 if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
16957 mem_loc_result
= bswap_loc_descriptor (rtl
, int_mode
, mem_mode
);
16962 if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
16963 mem_loc_result
= rotate_loc_descriptor (rtl
, int_mode
, mem_mode
);
16967 /* In theory, we could implement the above. */
16968 /* DWARF cannot represent the unsigned compare operations
16993 case FRACT_CONVERT
:
16994 case UNSIGNED_FRACT_CONVERT
:
16996 case UNSIGNED_SAT_FRACT
:
17002 case VEC_DUPLICATE
:
17006 case STRICT_LOW_PART
:
17011 case SMUL_HIGHPART
:
17012 case UMUL_HIGHPART
:
17018 resolve_one_addr (&rtl
);
17021 /* RTL sequences inside PARALLEL record a series of DWARF operations for
17022 the expression. An UNSPEC rtx represents a raw DWARF operation,
17023 new_loc_descr is called for it to build the operation directly.
17024 Otherwise mem_loc_descriptor is called recursively. */
17028 dw_loc_descr_ref exp_result
= NULL
;
17030 for (; index
< XVECLEN (rtl
, 0); index
++)
17032 rtx elem
= XVECEXP (rtl
, 0, index
);
17033 if (GET_CODE (elem
) == UNSPEC
)
17035 /* Each DWARF operation UNSPEC contain two operands, if
17036 one operand is not used for the operation, const0_rtx is
17038 gcc_assert (XVECLEN (elem
, 0) == 2);
17040 HOST_WIDE_INT dw_op
= XINT (elem
, 1);
17041 HOST_WIDE_INT oprnd1
= INTVAL (XVECEXP (elem
, 0, 0));
17042 HOST_WIDE_INT oprnd2
= INTVAL (XVECEXP (elem
, 0, 1));
17044 = new_loc_descr ((enum dwarf_location_atom
) dw_op
, oprnd1
,
17049 = mem_loc_descriptor (elem
, mode
, mem_mode
,
17050 VAR_INIT_STATUS_INITIALIZED
);
17052 if (!mem_loc_result
)
17053 mem_loc_result
= exp_result
;
17055 add_loc_descr (&mem_loc_result
, exp_result
);
17064 print_rtl (stderr
, rtl
);
17065 gcc_unreachable ();
17070 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
17071 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
17073 return mem_loc_result
;
17076 /* Return a descriptor that describes the concatenation of two locations.
17077 This is typically a complex variable. */
17079 static dw_loc_descr_ref
17080 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
17082 /* At present we only track constant-sized pieces. */
17083 unsigned int size0
, size1
;
17084 if (!GET_MODE_SIZE (GET_MODE (x0
)).is_constant (&size0
)
17085 || !GET_MODE_SIZE (GET_MODE (x1
)).is_constant (&size1
))
17088 dw_loc_descr_ref cc_loc_result
= NULL
;
17089 dw_loc_descr_ref x0_ref
17090 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
17091 dw_loc_descr_ref x1_ref
17092 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
17094 if (x0_ref
== 0 || x1_ref
== 0)
17097 cc_loc_result
= x0_ref
;
17098 add_loc_descr_op_piece (&cc_loc_result
, size0
);
17100 add_loc_descr (&cc_loc_result
, x1_ref
);
17101 add_loc_descr_op_piece (&cc_loc_result
, size1
);
17103 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
17104 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
17106 return cc_loc_result
;
17109 /* Return a descriptor that describes the concatenation of N
17112 static dw_loc_descr_ref
17113 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
17116 dw_loc_descr_ref cc_loc_result
= NULL
;
17117 unsigned int n
= XVECLEN (concatn
, 0);
17120 for (i
= 0; i
< n
; ++i
)
17122 dw_loc_descr_ref ref
;
17123 rtx x
= XVECEXP (concatn
, 0, i
);
17125 /* At present we only track constant-sized pieces. */
17126 if (!GET_MODE_SIZE (GET_MODE (x
)).is_constant (&size
))
17129 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
17133 add_loc_descr (&cc_loc_result
, ref
);
17134 add_loc_descr_op_piece (&cc_loc_result
, size
);
17137 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
17138 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
17140 return cc_loc_result
;
17143 /* Helper function for loc_descriptor. Return DW_OP_implicit_pointer
17144 for DEBUG_IMPLICIT_PTR RTL. */
17146 static dw_loc_descr_ref
17147 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
17149 dw_loc_descr_ref ret
;
17152 if (dwarf_strict
&& dwarf_version
< 5)
17154 gcc_assert (VAR_P (DEBUG_IMPLICIT_PTR_DECL (rtl
))
17155 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
17156 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
17157 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
17158 ret
= new_loc_descr (dwarf_OP (DW_OP_implicit_pointer
), 0, offset
);
17159 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
17162 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
17163 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
17164 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
17168 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
17169 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
17174 /* Output a proper Dwarf location descriptor for a variable or parameter
17175 which is either allocated in a register or in a memory location. For a
17176 register, we just generate an OP_REG and the register number. For a
17177 memory location we provide a Dwarf postfix expression describing how to
17178 generate the (dynamic) address of the object onto the address stack.
17180 MODE is mode of the decl if this loc_descriptor is going to be used in
17181 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
17182 allowed, VOIDmode otherwise.
17184 If we don't know how to describe it, return 0. */
17186 static dw_loc_descr_ref
17187 loc_descriptor (rtx rtl
, machine_mode mode
,
17188 enum var_init_status initialized
)
17190 dw_loc_descr_ref loc_result
= NULL
;
17191 scalar_int_mode int_mode
;
17193 switch (GET_CODE (rtl
))
17196 /* The case of a subreg may arise when we have a local (register)
17197 variable or a formal (register) parameter which doesn't quite fill
17198 up an entire register. For now, just assume that it is
17199 legitimate to make the Dwarf info refer to the whole register which
17200 contains the given subreg. */
17201 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
17202 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
17203 GET_MODE (SUBREG_REG (rtl
)), initialized
);
17209 loc_result
= reg_loc_descriptor (rtl
, initialized
);
17213 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
17214 GET_MODE (rtl
), initialized
);
17215 if (loc_result
== NULL
)
17216 loc_result
= tls_mem_loc_descriptor (rtl
);
17217 if (loc_result
== NULL
)
17219 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
17220 if (new_rtl
!= rtl
)
17221 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
17226 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
17231 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
17236 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
17238 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
17239 if (GET_CODE (loc
) == EXPR_LIST
)
17240 loc
= XEXP (loc
, 0);
17241 loc_result
= loc_descriptor (loc
, mode
, initialized
);
17245 rtl
= XEXP (rtl
, 1);
17250 rtvec par_elems
= XVEC (rtl
, 0);
17251 int num_elem
= GET_NUM_ELEM (par_elems
);
17255 /* Create the first one, so we have something to add to. */
17256 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
17257 VOIDmode
, initialized
);
17258 if (loc_result
== NULL
)
17260 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
17261 /* At present we only track constant-sized pieces. */
17262 if (!GET_MODE_SIZE (mode
).is_constant (&size
))
17264 add_loc_descr_op_piece (&loc_result
, size
);
17265 for (i
= 1; i
< num_elem
; i
++)
17267 dw_loc_descr_ref temp
;
17269 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
17270 VOIDmode
, initialized
);
17273 add_loc_descr (&loc_result
, temp
);
17274 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
17275 /* At present we only track constant-sized pieces. */
17276 if (!GET_MODE_SIZE (mode
).is_constant (&size
))
17278 add_loc_descr_op_piece (&loc_result
, size
);
17284 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
17286 int_mode
= as_a
<scalar_int_mode
> (mode
);
17287 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (int_mode
),
17293 if (mode
== VOIDmode
)
17294 mode
= GET_MODE (rtl
);
17296 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
17298 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
17300 /* Note that a CONST_DOUBLE rtx could represent either an integer
17301 or a floating-point constant. A CONST_DOUBLE is used whenever
17302 the constant requires more than one word in order to be
17303 adequately represented. We output CONST_DOUBLEs as blocks. */
17304 scalar_mode smode
= as_a
<scalar_mode
> (mode
);
17305 loc_result
= new_loc_descr (DW_OP_implicit_value
,
17306 GET_MODE_SIZE (smode
), 0);
17307 #if TARGET_SUPPORTS_WIDE_INT == 0
17308 if (!SCALAR_FLOAT_MODE_P (smode
))
17310 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
17311 loc_result
->dw_loc_oprnd2
.v
.val_double
17312 = rtx_to_double_int (rtl
);
17317 unsigned int length
= GET_MODE_SIZE (smode
);
17318 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
17319 unsigned int elt_size
= insert_float (rtl
, array
);
17321 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
17322 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ elt_size
;
17323 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
17324 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
17329 case CONST_WIDE_INT
:
17330 if (mode
== VOIDmode
)
17331 mode
= GET_MODE (rtl
);
17333 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
17335 int_mode
= as_a
<scalar_int_mode
> (mode
);
17336 loc_result
= new_loc_descr (DW_OP_implicit_value
,
17337 GET_MODE_SIZE (int_mode
), 0);
17338 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_wide_int
;
17339 loc_result
->dw_loc_oprnd2
.v
.val_wide
17340 = alloc_dw_wide_int (rtx_mode_t (rtl
, int_mode
));
17345 if (mode
== VOIDmode
)
17346 mode
= GET_MODE (rtl
);
17348 if (mode
!= VOIDmode
17349 /* The combination of a length and byte elt_size doesn't extend
17350 naturally to boolean vectors, where several elements are packed
17351 into the same byte. */
17352 && GET_MODE_CLASS (mode
) != MODE_VECTOR_BOOL
17353 && (dwarf_version
>= 4 || !dwarf_strict
))
17355 unsigned int length
;
17356 if (!CONST_VECTOR_NUNITS (rtl
).is_constant (&length
))
17359 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
17360 unsigned char *array
17361 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
17364 machine_mode imode
= GET_MODE_INNER (mode
);
17366 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
17367 switch (GET_MODE_CLASS (mode
))
17369 case MODE_VECTOR_INT
:
17370 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
17372 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
17373 insert_wide_int (rtx_mode_t (elt
, imode
), p
, elt_size
);
17377 case MODE_VECTOR_FLOAT
:
17378 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
17380 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
17381 insert_float (elt
, p
);
17386 gcc_unreachable ();
17389 loc_result
= new_loc_descr (DW_OP_implicit_value
,
17390 length
* elt_size
, 0);
17391 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
17392 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
17393 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
17394 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
17399 if (mode
== VOIDmode
17400 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
17401 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
17402 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
17404 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
17409 if (!const_ok_for_output (rtl
))
17413 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
17414 && GET_MODE_SIZE (int_mode
) == DWARF2_ADDR_SIZE
17415 && (dwarf_version
>= 4 || !dwarf_strict
))
17417 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
17418 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
17419 vec_safe_push (used_rtx_array
, rtl
);
17423 case DEBUG_IMPLICIT_PTR
:
17424 loc_result
= implicit_ptr_descriptor (rtl
, 0);
17428 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
17429 && CONST_INT_P (XEXP (rtl
, 1)))
17432 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
17438 if ((is_a
<scalar_int_mode
> (mode
, &int_mode
)
17439 && GET_MODE (rtl
) == int_mode
17440 && GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
17441 && dwarf_version
>= 4)
17442 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
17444 /* Value expression. */
17445 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
17447 add_loc_descr (&loc_result
,
17448 new_loc_descr (DW_OP_stack_value
, 0, 0));
17456 /* We need to figure out what section we should use as the base for the
17457 address ranges where a given location is valid.
17458 1. If this particular DECL has a section associated with it, use that.
17459 2. If this function has a section associated with it, use that.
17460 3. Otherwise, use the text section.
17461 XXX: If you split a variable across multiple sections, we won't notice. */
17463 static const char *
17464 secname_for_decl (const_tree decl
)
17466 const char *secname
;
17468 if (VAR_OR_FUNCTION_DECL_P (decl
)
17469 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
) || TREE_STATIC (decl
))
17470 && DECL_SECTION_NAME (decl
))
17471 secname
= DECL_SECTION_NAME (decl
);
17472 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
17474 if (in_cold_section_p
)
17476 section
*sec
= current_function_section ();
17477 if (sec
->common
.flags
& SECTION_NAMED
)
17478 return sec
->named
.name
;
17480 secname
= DECL_SECTION_NAME (current_function_decl
);
17482 else if (cfun
&& in_cold_section_p
)
17483 secname
= crtl
->subsections
.cold_section_label
;
17485 secname
= text_section_label
;
17490 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
17493 decl_by_reference_p (tree decl
)
17495 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
17497 && DECL_BY_REFERENCE (decl
));
17500 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
17503 static dw_loc_descr_ref
17504 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
17505 enum var_init_status initialized
)
17507 int have_address
= 0;
17508 dw_loc_descr_ref descr
;
17511 if (want_address
!= 2)
17513 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
17515 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
17517 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
17518 if (GET_CODE (varloc
) == EXPR_LIST
)
17519 varloc
= XEXP (varloc
, 0);
17520 mode
= GET_MODE (varloc
);
17521 if (MEM_P (varloc
))
17523 rtx addr
= XEXP (varloc
, 0);
17524 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
17525 mode
, initialized
);
17530 rtx x
= avoid_constant_pool_reference (varloc
);
17532 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
17537 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
17544 if (GET_CODE (varloc
) == VAR_LOCATION
)
17545 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
17547 mode
= DECL_MODE (loc
);
17548 descr
= loc_descriptor (varloc
, mode
, initialized
);
17555 if (want_address
== 2 && !have_address
17556 && (dwarf_version
>= 4 || !dwarf_strict
))
17558 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
17560 expansion_failed (loc
, NULL_RTX
,
17561 "DWARF address size mismatch");
17564 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
17567 /* Show if we can't fill the request for an address. */
17568 if (want_address
&& !have_address
)
17570 expansion_failed (loc
, NULL_RTX
,
17571 "Want address and only have value");
17575 /* If we've got an address and don't want one, dereference. */
17576 if (!want_address
&& have_address
)
17578 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
17579 enum dwarf_location_atom op
;
17581 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
17583 expansion_failed (loc
, NULL_RTX
,
17584 "DWARF address size mismatch");
17587 else if (size
== DWARF2_ADDR_SIZE
)
17590 op
= DW_OP_deref_size
;
17592 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
17598 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
17599 if it is not possible. */
17601 static dw_loc_descr_ref
17602 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
17604 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
17605 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
17606 else if (dwarf_version
>= 3 || !dwarf_strict
)
17607 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
17612 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
17613 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
17615 static dw_loc_descr_ref
17616 dw_sra_loc_expr (tree decl
, rtx loc
)
17619 unsigned HOST_WIDE_INT padsize
= 0;
17620 dw_loc_descr_ref descr
, *descr_tail
;
17621 unsigned HOST_WIDE_INT decl_size
;
17623 enum var_init_status initialized
;
17625 if (DECL_SIZE (decl
) == NULL
17626 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
17629 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
17631 descr_tail
= &descr
;
17633 for (p
= loc
; p
; p
= XEXP (p
, 1))
17635 unsigned HOST_WIDE_INT bitsize
= decl_piece_bitsize (p
);
17636 rtx loc_note
= *decl_piece_varloc_ptr (p
);
17637 dw_loc_descr_ref cur_descr
;
17638 dw_loc_descr_ref
*tail
, last
= NULL
;
17639 unsigned HOST_WIDE_INT opsize
= 0;
17641 if (loc_note
== NULL_RTX
17642 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
17644 padsize
+= bitsize
;
17647 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
17648 varloc
= NOTE_VAR_LOCATION (loc_note
);
17649 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
17650 if (cur_descr
== NULL
)
17652 padsize
+= bitsize
;
17656 /* Check that cur_descr either doesn't use
17657 DW_OP_*piece operations, or their sum is equal
17658 to bitsize. Otherwise we can't embed it. */
17659 for (tail
= &cur_descr
; *tail
!= NULL
;
17660 tail
= &(*tail
)->dw_loc_next
)
17661 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
17663 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
17667 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
17669 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
17673 if (last
!= NULL
&& opsize
!= bitsize
)
17675 padsize
+= bitsize
;
17676 /* Discard the current piece of the descriptor and release any
17677 addr_table entries it uses. */
17678 remove_loc_list_addr_table_entries (cur_descr
);
17682 /* If there is a hole, add DW_OP_*piece after empty DWARF
17683 expression, which means that those bits are optimized out. */
17686 if (padsize
> decl_size
)
17688 remove_loc_list_addr_table_entries (cur_descr
);
17689 goto discard_descr
;
17691 decl_size
-= padsize
;
17692 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
17693 if (*descr_tail
== NULL
)
17695 remove_loc_list_addr_table_entries (cur_descr
);
17696 goto discard_descr
;
17698 descr_tail
= &(*descr_tail
)->dw_loc_next
;
17701 *descr_tail
= cur_descr
;
17703 if (bitsize
> decl_size
)
17704 goto discard_descr
;
17705 decl_size
-= bitsize
;
17708 HOST_WIDE_INT offset
= 0;
17709 if (GET_CODE (varloc
) == VAR_LOCATION
17710 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
17712 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
17713 if (GET_CODE (varloc
) == EXPR_LIST
)
17714 varloc
= XEXP (varloc
, 0);
17718 if (GET_CODE (varloc
) == CONST
17719 || GET_CODE (varloc
) == SIGN_EXTEND
17720 || GET_CODE (varloc
) == ZERO_EXTEND
)
17721 varloc
= XEXP (varloc
, 0);
17722 else if (GET_CODE (varloc
) == SUBREG
)
17723 varloc
= SUBREG_REG (varloc
);
17728 /* DW_OP_bit_size offset should be zero for register
17729 or implicit location descriptions and empty location
17730 descriptions, but for memory addresses needs big endian
17732 if (MEM_P (varloc
))
17734 unsigned HOST_WIDE_INT memsize
;
17735 if (!poly_uint64 (MEM_SIZE (varloc
)).is_constant (&memsize
))
17736 goto discard_descr
;
17737 memsize
*= BITS_PER_UNIT
;
17738 if (memsize
!= bitsize
)
17740 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
17741 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
17742 goto discard_descr
;
17743 if (memsize
< bitsize
)
17744 goto discard_descr
;
17745 if (BITS_BIG_ENDIAN
)
17746 offset
= memsize
- bitsize
;
17750 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
17751 if (*descr_tail
== NULL
)
17752 goto discard_descr
;
17753 descr_tail
= &(*descr_tail
)->dw_loc_next
;
17757 /* If there were any non-empty expressions, add padding till the end of
17759 if (descr
!= NULL
&& decl_size
!= 0)
17761 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
17762 if (*descr_tail
== NULL
)
17763 goto discard_descr
;
17768 /* Discard the descriptor and release any addr_table entries it uses. */
17769 remove_loc_list_addr_table_entries (descr
);
17773 /* Return the dwarf representation of the location list LOC_LIST of
17774 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
17777 static dw_loc_list_ref
17778 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
17780 const char *endname
, *secname
;
17781 var_loc_view endview
;
17783 enum var_init_status initialized
;
17784 struct var_loc_node
*node
;
17785 dw_loc_descr_ref descr
;
17786 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
17787 dw_loc_list_ref list
= NULL
;
17788 dw_loc_list_ref
*listp
= &list
;
17790 /* Now that we know what section we are using for a base,
17791 actually construct the list of locations.
17792 The first location information is what is passed to the
17793 function that creates the location list, and the remaining
17794 locations just get added on to that list.
17795 Note that we only know the start address for a location
17796 (IE location changes), so to build the range, we use
17797 the range [current location start, next location start].
17798 This means we have to special case the last node, and generate
17799 a range of [last location start, end of function label]. */
17801 if (cfun
&& crtl
->has_bb_partition
)
17803 bool save_in_cold_section_p
= in_cold_section_p
;
17804 in_cold_section_p
= first_function_block_is_cold
;
17805 if (loc_list
->last_before_switch
== NULL
)
17806 in_cold_section_p
= !in_cold_section_p
;
17807 secname
= secname_for_decl (decl
);
17808 in_cold_section_p
= save_in_cold_section_p
;
17811 secname
= secname_for_decl (decl
);
17813 for (node
= loc_list
->first
; node
; node
= node
->next
)
17815 bool range_across_switch
= false;
17816 if (GET_CODE (node
->loc
) == EXPR_LIST
17817 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
17819 if (GET_CODE (node
->loc
) == EXPR_LIST
)
17822 /* This requires DW_OP_{,bit_}piece, which is not usable
17823 inside DWARF expressions. */
17824 if (want_address
== 2)
17825 descr
= dw_sra_loc_expr (decl
, node
->loc
);
17829 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
17830 varloc
= NOTE_VAR_LOCATION (node
->loc
);
17831 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
17835 /* If section switch happens in between node->label
17836 and node->next->label (or end of function) and
17837 we can't emit it as a single entry list,
17838 emit two ranges, first one ending at the end
17839 of first partition and second one starting at the
17840 beginning of second partition. */
17841 if (node
== loc_list
->last_before_switch
17842 && (node
!= loc_list
->first
|| loc_list
->first
->next
17843 /* If we are to emit a view number, we will emit
17844 a loclist rather than a single location
17845 expression for the entire function (see
17846 loc_list_has_views), so we have to split the
17847 range that straddles across partitions. */
17848 || !ZERO_VIEW_P (node
->view
))
17849 && current_function_decl
)
17851 endname
= cfun
->fde
->dw_fde_end
;
17853 range_across_switch
= true;
17855 /* The variable has a location between NODE->LABEL and
17856 NODE->NEXT->LABEL. */
17857 else if (node
->next
)
17858 endname
= node
->next
->label
, endview
= node
->next
->view
;
17859 /* If the variable has a location at the last label
17860 it keeps its location until the end of function. */
17861 else if (!current_function_decl
)
17862 endname
= text_end_label
, endview
= 0;
17865 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
17866 current_function_funcdef_no
);
17867 endname
= ggc_strdup (label_id
);
17871 *listp
= new_loc_list (descr
, node
->label
, node
->view
,
17872 endname
, endview
, secname
);
17873 if (TREE_CODE (decl
) == PARM_DECL
17874 && node
== loc_list
->first
17875 && NOTE_P (node
->loc
)
17876 && strcmp (node
->label
, endname
) == 0)
17877 (*listp
)->force
= true;
17878 listp
= &(*listp
)->dw_loc_next
;
17883 && crtl
->has_bb_partition
17884 && node
== loc_list
->last_before_switch
)
17886 bool save_in_cold_section_p
= in_cold_section_p
;
17887 in_cold_section_p
= !first_function_block_is_cold
;
17888 secname
= secname_for_decl (decl
);
17889 in_cold_section_p
= save_in_cold_section_p
;
17892 if (range_across_switch
)
17894 if (GET_CODE (node
->loc
) == EXPR_LIST
)
17895 descr
= dw_sra_loc_expr (decl
, node
->loc
);
17898 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
17899 varloc
= NOTE_VAR_LOCATION (node
->loc
);
17900 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
17903 gcc_assert (descr
);
17904 /* The variable has a location between NODE->LABEL and
17905 NODE->NEXT->LABEL. */
17907 endname
= node
->next
->label
, endview
= node
->next
->view
;
17909 endname
= cfun
->fde
->dw_fde_second_end
, endview
= 0;
17910 *listp
= new_loc_list (descr
, cfun
->fde
->dw_fde_second_begin
, 0,
17911 endname
, endview
, secname
);
17912 listp
= &(*listp
)->dw_loc_next
;
17916 /* Try to avoid the overhead of a location list emitting a location
17917 expression instead, but only if we didn't have more than one
17918 location entry in the first place. If some entries were not
17919 representable, we don't want to pretend a single entry that was
17920 applies to the entire scope in which the variable is
17922 if (list
&& loc_list
->first
->next
)
17925 maybe_gen_llsym (list
);
17930 /* Return true if the loc_list has only single element and thus
17931 can be represented as location description. */
17934 single_element_loc_list_p (dw_loc_list_ref list
)
17936 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
17937 return !list
->ll_symbol
;
17940 /* Duplicate a single element of location list. */
17942 static inline dw_loc_descr_ref
17943 copy_loc_descr (dw_loc_descr_ref ref
)
17945 dw_loc_descr_ref copy
= ggc_alloc
<dw_loc_descr_node
> ();
17946 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
17950 /* To each location in list LIST append loc descr REF. */
17953 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
17955 dw_loc_descr_ref copy
;
17956 add_loc_descr (&list
->expr
, ref
);
17957 list
= list
->dw_loc_next
;
17960 copy
= copy_loc_descr (ref
);
17961 add_loc_descr (&list
->expr
, copy
);
17962 while (copy
->dw_loc_next
)
17963 copy
= copy
->dw_loc_next
= copy_loc_descr (copy
->dw_loc_next
);
17964 list
= list
->dw_loc_next
;
17968 /* To each location in list LIST prepend loc descr REF. */
17971 prepend_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
17973 dw_loc_descr_ref copy
;
17974 dw_loc_descr_ref ref_end
= list
->expr
;
17975 add_loc_descr (&ref
, list
->expr
);
17977 list
= list
->dw_loc_next
;
17980 dw_loc_descr_ref end
= list
->expr
;
17981 list
->expr
= copy
= copy_loc_descr (ref
);
17982 while (copy
->dw_loc_next
!= ref_end
)
17983 copy
= copy
->dw_loc_next
= copy_loc_descr (copy
->dw_loc_next
);
17984 copy
->dw_loc_next
= end
;
17985 list
= list
->dw_loc_next
;
17989 /* Given two lists RET and LIST
17990 produce location list that is result of adding expression in LIST
17991 to expression in RET on each position in program.
17992 Might be destructive on both RET and LIST.
17994 TODO: We handle only simple cases of RET or LIST having at most one
17995 element. General case would involve sorting the lists in program order
17996 and merging them that will need some additional work.
17997 Adding that will improve quality of debug info especially for SRA-ed
18001 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
18010 if (!list
->dw_loc_next
)
18012 add_loc_descr_to_each (*ret
, list
->expr
);
18015 if (!(*ret
)->dw_loc_next
)
18017 prepend_loc_descr_to_each (list
, (*ret
)->expr
);
18021 expansion_failed (NULL_TREE
, NULL_RTX
,
18022 "Don't know how to merge two non-trivial"
18023 " location lists.\n");
18028 /* LOC is constant expression. Try a luck, look it up in constant
18029 pool and return its loc_descr of its address. */
18031 static dw_loc_descr_ref
18032 cst_pool_loc_descr (tree loc
)
18034 /* Get an RTL for this, if something has been emitted. */
18035 rtx rtl
= lookup_constant_def (loc
);
18037 if (!rtl
|| !MEM_P (rtl
))
18042 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
18044 /* TODO: We might get more coverage if we was actually delaying expansion
18045 of all expressions till end of compilation when constant pools are fully
18047 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
18049 expansion_failed (loc
, NULL_RTX
,
18050 "CST value in contant pool but not marked.");
18053 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
18054 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
18057 /* Return dw_loc_list representing address of addr_expr LOC
18058 by looking for inner INDIRECT_REF expression and turning
18059 it into simple arithmetics.
18061 See loc_list_from_tree for the meaning of CONTEXT. */
18063 static dw_loc_list_ref
18064 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
,
18065 loc_descr_context
*context
)
18068 poly_int64 bitsize
, bitpos
, bytepos
;
18070 int unsignedp
, reversep
, volatilep
= 0;
18071 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
18073 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
18074 &bitsize
, &bitpos
, &offset
, &mode
,
18075 &unsignedp
, &reversep
, &volatilep
);
18077 if (!multiple_p (bitpos
, BITS_PER_UNIT
, &bytepos
))
18079 expansion_failed (loc
, NULL_RTX
, "bitfield access");
18082 if (!INDIRECT_REF_P (obj
))
18084 expansion_failed (obj
,
18085 NULL_RTX
, "no indirect ref in inner refrence");
18088 if (!offset
&& known_eq (bitpos
, 0))
18089 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1,
18092 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
18093 && (dwarf_version
>= 4 || !dwarf_strict
))
18095 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0, context
);
18100 /* Variable offset. */
18101 list_ret1
= loc_list_from_tree (offset
, 0, context
);
18102 if (list_ret1
== 0)
18104 add_loc_list (&list_ret
, list_ret1
);
18107 add_loc_descr_to_each (list_ret
,
18108 new_loc_descr (DW_OP_plus
, 0, 0));
18110 HOST_WIDE_INT value
;
18111 if (bytepos
.is_constant (&value
) && value
> 0)
18112 add_loc_descr_to_each (list_ret
,
18113 new_loc_descr (DW_OP_plus_uconst
, value
, 0));
18114 else if (maybe_ne (bytepos
, 0))
18115 loc_list_plus_const (list_ret
, bytepos
);
18116 add_loc_descr_to_each (list_ret
,
18117 new_loc_descr (DW_OP_stack_value
, 0, 0));
18122 /* Set LOC to the next operation that is not a DW_OP_nop operation. In the case
18123 all operations from LOC are nops, move to the last one. Insert in NOPS all
18124 operations that are skipped. */
18127 loc_descr_to_next_no_nop (dw_loc_descr_ref
&loc
,
18128 hash_set
<dw_loc_descr_ref
> &nops
)
18130 while (loc
->dw_loc_next
!= NULL
&& loc
->dw_loc_opc
== DW_OP_nop
)
18133 loc
= loc
->dw_loc_next
;
18137 /* Helper for loc_descr_without_nops: free the location description operation
18141 free_loc_descr (const dw_loc_descr_ref
&loc
, void *data ATTRIBUTE_UNUSED
)
18147 /* Remove all DW_OP_nop operations from LOC except, if it exists, the one that
18151 loc_descr_without_nops (dw_loc_descr_ref
&loc
)
18153 if (loc
->dw_loc_opc
== DW_OP_nop
&& loc
->dw_loc_next
== NULL
)
18156 /* Set of all DW_OP_nop operations we remove. */
18157 hash_set
<dw_loc_descr_ref
> nops
;
18159 /* First, strip all prefix NOP operations in order to keep the head of the
18160 operations list. */
18161 loc_descr_to_next_no_nop (loc
, nops
);
18163 for (dw_loc_descr_ref cur
= loc
; cur
!= NULL
;)
18165 /* For control flow operations: strip "prefix" nops in destination
18167 if (cur
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
)
18168 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd1
.v
.val_loc
, nops
);
18169 if (cur
->dw_loc_oprnd2
.val_class
== dw_val_class_loc
)
18170 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd2
.v
.val_loc
, nops
);
18172 /* Do the same for the operations that follow, then move to the next
18174 if (cur
->dw_loc_next
!= NULL
)
18175 loc_descr_to_next_no_nop (cur
->dw_loc_next
, nops
);
18176 cur
= cur
->dw_loc_next
;
18179 nops
.traverse
<void *, free_loc_descr
> (NULL
);
18183 struct dwarf_procedure_info
;
18185 /* Helper structure for location descriptions generation. */
18186 struct loc_descr_context
18188 /* The type that is implicitly referenced by DW_OP_push_object_address, or
18189 NULL_TREE if DW_OP_push_object_address in invalid for this location
18190 description. This is used when processing PLACEHOLDER_EXPR nodes. */
18192 /* The ..._DECL node that should be translated as a
18193 DW_OP_push_object_address operation. */
18195 /* Information about the DWARF procedure we are currently generating. NULL if
18196 we are not generating a DWARF procedure. */
18197 struct dwarf_procedure_info
*dpi
;
18198 /* True if integral PLACEHOLDER_EXPR stands for the first argument passed
18199 by consumer. Used for DW_TAG_generic_subrange attributes. */
18200 bool placeholder_arg
;
18201 /* True if PLACEHOLDER_EXPR has been seen. */
18202 bool placeholder_seen
;
18203 /* True if strict preservation of signedness has been requested. */
18204 bool strict_signedness
;
18207 /* DWARF procedures generation
18209 DWARF expressions (aka. location descriptions) are used to encode variable
18210 things such as sizes or offsets. Such computations can have redundant parts
18211 that can be factorized in order to reduce the size of the output debug
18212 information. This is the whole point of DWARF procedures.
18214 Thanks to stor-layout.cc, size and offset expressions in GENERIC trees are
18215 already factorized into functions ("size functions") in order to handle very
18216 big and complex types. Such functions are quite simple: they have integral
18217 arguments, they return an integral result and their body contains only a
18218 return statement with arithmetic expressions. This is the only kind of
18219 function we are interested in translating into DWARF procedures, here.
18221 DWARF expressions and DWARF procedure are executed using a stack, so we have
18222 to define some calling convention for them to interact. Let's say that:
18224 - Before calling a DWARF procedure, DWARF expressions must push on the stack
18225 all arguments in reverse order (right-to-left) so that when the DWARF
18226 procedure execution starts, the first argument is the top of the stack.
18228 - Then, when returning, the DWARF procedure must have consumed all arguments
18229 on the stack, must have pushed the result and touched nothing else.
18231 - Each integral argument and the result are integral types can be hold in a
18234 - We call "frame offset" the number of stack slots that are "under DWARF
18235 procedure control": it includes the arguments slots, the temporaries and
18236 the result slot. Thus, it is equal to the number of arguments when the
18237 procedure execution starts and must be equal to one (the result) when it
18240 /* Helper structure used when generating operations for a DWARF procedure. */
18241 struct dwarf_procedure_info
18243 /* The FUNCTION_DECL node corresponding to the DWARF procedure that is
18244 currently translated. */
18246 /* The number of arguments FNDECL takes. */
18247 unsigned args_count
;
18250 /* Return a pointer to a newly created DIE node for a DWARF procedure. Add
18251 LOCATION as its DW_AT_location attribute. If FNDECL is not NULL_TREE,
18252 equate it to this DIE. */
18255 new_dwarf_proc_die (dw_loc_descr_ref location
, tree fndecl
,
18256 dw_die_ref parent_die
)
18258 dw_die_ref dwarf_proc_die
;
18260 if ((dwarf_version
< 3 && dwarf_strict
)
18261 || location
== NULL
)
18264 dwarf_proc_die
= new_die (DW_TAG_dwarf_procedure
, parent_die
, fndecl
);
18266 equate_decl_number_to_die (fndecl
, dwarf_proc_die
);
18267 add_AT_loc (dwarf_proc_die
, DW_AT_location
, location
);
18268 return dwarf_proc_die
;
18271 /* Return whether TYPE is a supported type as a DWARF procedure argument
18272 type or return type (we handle only scalar types and pointer types that
18273 aren't wider than the DWARF expression evaluation stack). */
18276 is_handled_procedure_type (tree type
)
18278 return ((INTEGRAL_TYPE_P (type
)
18279 || TREE_CODE (type
) == OFFSET_TYPE
18280 || TREE_CODE (type
) == POINTER_TYPE
)
18281 && int_size_in_bytes (type
) <= DWARF2_ADDR_SIZE
);
18284 /* Helper for resolve_args_picking: do the same but stop when coming across
18285 visited nodes. For each node we visit, register in FRAME_OFFSETS the frame
18286 offset *before* evaluating the corresponding operation. */
18289 resolve_args_picking_1 (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
18290 struct dwarf_procedure_info
*dpi
,
18291 hash_map
<dw_loc_descr_ref
, unsigned> &frame_offsets
)
18293 /* The "frame_offset" identifier is already used to name a macro... */
18294 unsigned frame_offset_
= initial_frame_offset
;
18295 dw_loc_descr_ref l
;
18297 for (l
= loc
; l
!= NULL
;)
18300 unsigned &l_frame_offset
= frame_offsets
.get_or_insert (l
, &existed
);
18302 /* If we already met this node, there is nothing to compute anymore. */
18305 /* Make sure that the stack size is consistent wherever the execution
18306 flow comes from. */
18307 gcc_assert ((unsigned) l_frame_offset
== frame_offset_
);
18310 l_frame_offset
= frame_offset_
;
18312 /* If needed, relocate the picking offset with respect to the frame
18314 if (l
->frame_offset_rel
)
18316 unsigned HOST_WIDE_INT off
;
18317 switch (l
->dw_loc_opc
)
18320 off
= l
->dw_loc_oprnd1
.v
.val_unsigned
;
18329 gcc_unreachable ();
18331 /* frame_offset_ is the size of the current stack frame, including
18332 incoming arguments. Besides, the arguments are pushed
18333 right-to-left. Thus, in order to access the Nth argument from
18334 this operation node, the picking has to skip temporaries *plus*
18335 one stack slot per argument (0 for the first one, 1 for the second
18338 The targetted argument number (N) is already set as the operand,
18339 and the number of temporaries can be computed with:
18340 frame_offsets_ - dpi->args_count */
18341 off
+= frame_offset_
- dpi
->args_count
;
18343 /* DW_OP_pick handles only offsets from 0 to 255 (inclusive)... */
18349 l
->dw_loc_opc
= DW_OP_dup
;
18350 l
->dw_loc_oprnd1
.v
.val_unsigned
= 0;
18354 l
->dw_loc_opc
= DW_OP_over
;
18355 l
->dw_loc_oprnd1
.v
.val_unsigned
= 0;
18359 l
->dw_loc_opc
= DW_OP_pick
;
18360 l
->dw_loc_oprnd1
.v
.val_unsigned
= off
;
18364 /* Update frame_offset according to the effect the current operation has
18366 switch (l
->dw_loc_opc
)
18374 case DW_OP_plus_uconst
:
18410 case DW_OP_deref_size
:
18412 case DW_OP_bit_piece
:
18413 case DW_OP_implicit_value
:
18414 case DW_OP_stack_value
:
18415 case DW_OP_deref_type
:
18416 case DW_OP_convert
:
18417 case DW_OP_reinterpret
:
18418 case DW_OP_GNU_deref_type
:
18419 case DW_OP_GNU_convert
:
18420 case DW_OP_GNU_reinterpret
:
18424 case DW_OP_const1u
:
18425 case DW_OP_const1s
:
18426 case DW_OP_const2u
:
18427 case DW_OP_const2s
:
18428 case DW_OP_const4u
:
18429 case DW_OP_const4s
:
18430 case DW_OP_const8u
:
18431 case DW_OP_const8s
:
18502 case DW_OP_push_object_address
:
18503 case DW_OP_call_frame_cfa
:
18504 case DW_OP_GNU_variable_value
:
18505 case DW_OP_GNU_addr_index
:
18506 case DW_OP_GNU_const_index
:
18531 case DW_OP_xderef_size
:
18537 case DW_OP_call_ref
:
18539 dw_die_ref dwarf_proc
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
18540 int *stack_usage
= dwarf_proc_stack_usage_map
->get (dwarf_proc
);
18542 if (stack_usage
== NULL
)
18544 frame_offset_
+= *stack_usage
;
18548 case DW_OP_implicit_pointer
:
18549 case DW_OP_entry_value
:
18550 case DW_OP_const_type
:
18551 case DW_OP_regval_type
:
18552 case DW_OP_form_tls_address
:
18553 case DW_OP_GNU_push_tls_address
:
18554 case DW_OP_GNU_uninit
:
18555 case DW_OP_GNU_encoded_addr
:
18556 case DW_OP_GNU_implicit_pointer
:
18557 case DW_OP_GNU_entry_value
:
18558 case DW_OP_GNU_const_type
:
18559 case DW_OP_GNU_regval_type
:
18560 case DW_OP_GNU_parameter_ref
:
18561 /* loc_list_from_tree will probably not output these operations for
18562 size functions, so assume they will not appear here. */
18563 /* Fall through... */
18566 gcc_unreachable ();
18569 /* Now, follow the control flow (except subroutine calls). */
18570 switch (l
->dw_loc_opc
)
18573 if (!resolve_args_picking_1 (l
->dw_loc_next
, frame_offset_
, dpi
,
18576 /* Fall through. */
18579 l
= l
->dw_loc_oprnd1
.v
.val_loc
;
18582 case DW_OP_stack_value
:
18586 l
= l
->dw_loc_next
;
18594 /* Make a DFS over operations reachable through LOC (i.e. follow branch
18595 operations) in order to resolve the operand of DW_OP_pick operations that
18596 target DWARF procedure arguments (DPI). INITIAL_FRAME_OFFSET is the frame
18597 offset *before* LOC is executed. Return if all relocations were
18601 resolve_args_picking (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
18602 struct dwarf_procedure_info
*dpi
)
18604 /* Associate to all visited operations the frame offset *before* evaluating
18606 hash_map
<dw_loc_descr_ref
, unsigned> frame_offsets
;
18609 resolve_args_picking_1 (loc
, initial_frame_offset
, dpi
, frame_offsets
);
18612 /* Try to generate a DWARF procedure that computes the same result as FNDECL.
18613 Return NULL if it is not possible. */
18616 function_to_dwarf_procedure (tree fndecl
)
18618 struct dwarf_procedure_info dpi
;
18619 struct loc_descr_context ctx
= {
18620 NULL_TREE
, /* context_type */
18621 NULL_TREE
, /* base_decl */
18623 false, /* placeholder_arg */
18624 false, /* placeholder_seen */
18625 true /* strict_signedness */
18627 dw_die_ref dwarf_proc_die
;
18628 tree tree_body
= DECL_SAVED_TREE (fndecl
);
18629 dw_loc_descr_ref loc_body
, epilogue
;
18634 /* Do not generate multiple DWARF procedures for the same function
18636 dwarf_proc_die
= lookup_decl_die (fndecl
);
18637 if (dwarf_proc_die
!= NULL
)
18638 return dwarf_proc_die
;
18640 /* DWARF procedures are available starting with the DWARFv3 standard. */
18641 if (dwarf_version
< 3 && dwarf_strict
)
18644 /* We handle only functions for which we still have a body, that return a
18645 supported type and that takes arguments with supported types. Note that
18646 there is no point translating functions that return nothing. */
18647 if (tree_body
== NULL_TREE
18648 || DECL_RESULT (fndecl
) == NULL_TREE
18649 || !is_handled_procedure_type (TREE_TYPE (DECL_RESULT (fndecl
))))
18652 for (cursor
= DECL_ARGUMENTS (fndecl
);
18653 cursor
!= NULL_TREE
;
18654 cursor
= TREE_CHAIN (cursor
))
18655 if (!is_handled_procedure_type (TREE_TYPE (cursor
)))
18658 /* Match only "expr" in: RETURN_EXPR (MODIFY_EXPR (RESULT_DECL, expr)). */
18659 if (TREE_CODE (tree_body
) != RETURN_EXPR
)
18661 tree_body
= TREE_OPERAND (tree_body
, 0);
18662 if (TREE_CODE (tree_body
) != MODIFY_EXPR
18663 || TREE_OPERAND (tree_body
, 0) != DECL_RESULT (fndecl
))
18665 tree_body
= TREE_OPERAND (tree_body
, 1);
18667 /* Try to translate the body expression itself. Note that this will probably
18668 cause an infinite recursion if its call graph has a cycle. This is very
18669 unlikely for size functions, however, so don't bother with such things at
18671 dpi
.fndecl
= fndecl
;
18672 dpi
.args_count
= list_length (DECL_ARGUMENTS (fndecl
));
18673 loc_body
= loc_descriptor_from_tree (tree_body
, 0, &ctx
);
18677 /* After evaluating all operands in "loc_body", we should still have on the
18678 stack all arguments plus the desired function result (top of the stack).
18679 Generate code in order to keep only the result in our stack frame. */
18681 for (i
= 0; i
< dpi
.args_count
; ++i
)
18683 dw_loc_descr_ref op_couple
= new_loc_descr (DW_OP_swap
, 0, 0);
18684 op_couple
->dw_loc_next
= new_loc_descr (DW_OP_drop
, 0, 0);
18685 op_couple
->dw_loc_next
->dw_loc_next
= epilogue
;
18686 epilogue
= op_couple
;
18688 add_loc_descr (&loc_body
, epilogue
);
18689 if (!resolve_args_picking (loc_body
, dpi
.args_count
, &dpi
))
18692 /* Trailing nops from loc_descriptor_from_tree (if any) cannot be removed
18693 because they are considered useful. Now there is an epilogue, they are
18694 not anymore, so give it another try. */
18695 loc_descr_without_nops (loc_body
);
18697 /* fndecl may be used both as a regular DW_TAG_subprogram DIE and as
18698 a DW_TAG_dwarf_procedure, so we may have a conflict, here. It's unlikely,
18699 though, given that size functions do not come from source, so they should
18700 not have a dedicated DW_TAG_subprogram DIE. */
18702 = new_dwarf_proc_die (loc_body
, fndecl
,
18703 get_context_die (DECL_CONTEXT (fndecl
)));
18705 /* The called DWARF procedure consumes one stack slot per argument and
18706 returns one stack slot. */
18707 dwarf_proc_stack_usage_map
->put (dwarf_proc_die
, 1 - dpi
.args_count
);
18709 return dwarf_proc_die
;
18712 /* Helper function for loc_list_from_tree. Perform OP binary op,
18713 but after converting arguments to type_die, afterwards convert
18714 back to unsigned. */
18716 static dw_loc_list_ref
18717 typed_binop_from_tree (enum dwarf_location_atom op
, tree loc
,
18718 dw_die_ref type_die
, scalar_int_mode mode
,
18719 struct loc_descr_context
*context
)
18721 dw_loc_list_ref op0
, op1
;
18722 dw_loc_descr_ref cvt
, binop
;
18724 if (type_die
== NULL
)
18727 op0
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
18728 op1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
18729 if (op0
== NULL
|| op1
== NULL
)
18732 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
18733 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
18734 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
18735 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
18736 add_loc_descr_to_each (op0
, cvt
);
18738 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
18739 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
18740 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
18741 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
18742 add_loc_descr_to_each (op1
, cvt
);
18744 add_loc_list (&op0
, op1
);
18748 binop
= new_loc_descr (op
, 0, 0);
18749 convert_descriptor_to_mode (mode
, binop
);
18750 add_loc_descr_to_each (op0
, binop
);
18755 /* Generate Dwarf location list representing LOC.
18756 If WANT_ADDRESS is false, expression computing LOC will be computed
18757 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
18758 if WANT_ADDRESS is 2, expression computing address useable in location
18759 will be returned (i.e. DW_OP_reg can be used
18760 to refer to register values).
18762 CONTEXT provides information to customize the location descriptions
18763 generation. Its context_type field specifies what type is implicitly
18764 referenced by DW_OP_push_object_address. If it is NULL_TREE, this operation
18765 will not be generated.
18767 Its DPI field determines whether we are generating a DWARF expression for a
18768 DWARF procedure, so PARM_DECL references are processed specifically.
18770 If CONTEXT is NULL, the behavior is the same as if context_type, base_decl
18771 and dpi fields were null. */
18773 static dw_loc_list_ref
18774 loc_list_from_tree_1 (tree loc
, int want_address
,
18775 struct loc_descr_context
*context
)
18777 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
18778 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
18779 int have_address
= 0;
18780 enum dwarf_location_atom op
;
18782 /* ??? Most of the time we do not take proper care for sign/zero
18783 extending the values properly. Hopefully this won't be a real
18786 if (context
!= NULL
18787 && context
->base_decl
== loc
18788 && want_address
== 0)
18790 if (dwarf_version
>= 3 || !dwarf_strict
)
18791 return new_loc_list (new_loc_descr (DW_OP_push_object_address
, 0, 0),
18792 NULL
, 0, NULL
, 0, NULL
);
18797 switch (TREE_CODE (loc
))
18800 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
18803 case PLACEHOLDER_EXPR
:
18804 /* This case involves extracting fields from an object to determine the
18805 position of other fields. It is supposed to appear only as the first
18806 operand of COMPONENT_REF nodes and to reference precisely the type
18807 that the context allows or its enclosing type. */
18808 if (context
!= NULL
18809 && (TREE_TYPE (loc
) == context
->context_type
18810 || TREE_TYPE (loc
) == TYPE_CONTEXT (context
->context_type
))
18811 && want_address
>= 1)
18813 if (dwarf_version
>= 3 || !dwarf_strict
)
18815 ret
= new_loc_descr (DW_OP_push_object_address
, 0, 0);
18822 /* For DW_TAG_generic_subrange attributes, PLACEHOLDER_EXPR stands for
18823 the single argument passed by consumer. */
18824 else if (context
!= NULL
18825 && context
->placeholder_arg
18826 && INTEGRAL_TYPE_P (TREE_TYPE (loc
))
18827 && want_address
== 0)
18829 ret
= new_loc_descr (DW_OP_pick
, 0, 0);
18830 ret
->frame_offset_rel
= 1;
18831 context
->placeholder_seen
= true;
18835 expansion_failed (loc
, NULL_RTX
,
18836 "PLACEHOLDER_EXPR for an unexpected type");
18841 tree callee
= get_callee_fndecl (loc
);
18842 dw_die_ref dwarf_proc
;
18845 && is_handled_procedure_type (TREE_TYPE (TREE_TYPE (callee
)))
18846 && (dwarf_proc
= function_to_dwarf_procedure (callee
)))
18848 /* DWARF procedures are used for size functions, which are built
18849 when size expressions contain conditional constructs, so we
18850 request strict preservation of signedness for comparisons. */
18851 bool old_strict_signedness
;
18854 old_strict_signedness
= context
->strict_signedness
;
18855 context
->strict_signedness
= true;
18858 /* Evaluate arguments right-to-left so that the first argument
18859 will be the top-most one on the stack. */
18860 for (int i
= call_expr_nargs (loc
) - 1; i
>= 0; --i
)
18862 tree arg
= CALL_EXPR_ARG (loc
, i
);
18863 ret1
= loc_descriptor_from_tree (arg
, 0, context
);
18866 expansion_failed (arg
, NULL_RTX
, "CALL_EXPR argument");
18869 add_loc_descr (&ret
, ret1
);
18872 ret1
= new_loc_descr (DW_OP_call4
, 0, 0);
18873 ret1
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
18874 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.die
= dwarf_proc
;
18875 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
18876 add_loc_descr (&ret
, ret1
);
18878 context
->strict_signedness
= old_strict_signedness
;
18881 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR target");
18885 case PREINCREMENT_EXPR
:
18886 case PREDECREMENT_EXPR
:
18887 case POSTINCREMENT_EXPR
:
18888 case POSTDECREMENT_EXPR
:
18889 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
18890 /* There are no opcodes for these operations. */
18894 /* If we already want an address, see if there is INDIRECT_REF inside
18895 e.g. for &this->field. */
18898 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
18899 (loc
, want_address
== 2, context
);
18902 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
18903 && (ret
= cst_pool_loc_descr (loc
)))
18906 /* Otherwise, process the argument and look for the address. */
18907 if (!list_ret
&& !ret
)
18908 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 1, context
);
18912 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
18918 if (DECL_THREAD_LOCAL_P (loc
))
18921 enum dwarf_location_atom tls_op
;
18922 enum dtprel_bool dtprel
= dtprel_false
;
18924 if (targetm
.have_tls
)
18926 /* If this is not defined, we have no way to emit the
18928 if (!targetm
.asm_out
.output_dwarf_dtprel
)
18931 /* The way DW_OP_GNU_push_tls_address is specified, we
18932 can only look up addresses of objects in the current
18933 module. We used DW_OP_addr as first op, but that's
18934 wrong, because DW_OP_addr is relocated by the debug
18935 info consumer, while DW_OP_GNU_push_tls_address
18936 operand shouldn't be. */
18937 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
18939 dtprel
= dtprel_true
;
18940 /* We check for DWARF 5 here because gdb did not implement
18941 DW_OP_form_tls_address until after 7.12. */
18942 tls_op
= (dwarf_version
>= 5 ? DW_OP_form_tls_address
18943 : DW_OP_GNU_push_tls_address
);
18947 if (!targetm
.emutls
.debug_form_tls_address
18948 || !(dwarf_version
>= 3 || !dwarf_strict
))
18950 /* We stuffed the control variable into the DECL_VALUE_EXPR
18951 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
18952 no longer appear in gimple code. We used the control
18953 variable in specific so that we could pick it up here. */
18954 loc
= DECL_VALUE_EXPR (loc
);
18955 tls_op
= DW_OP_form_tls_address
;
18958 rtl
= rtl_for_decl_location (loc
);
18959 if (rtl
== NULL_RTX
)
18964 rtl
= XEXP (rtl
, 0);
18965 if (! CONSTANT_P (rtl
))
18968 ret
= new_addr_loc_descr (rtl
, dtprel
);
18969 ret1
= new_loc_descr (tls_op
, 0, 0);
18970 add_loc_descr (&ret
, ret1
);
18978 if (context
!= NULL
&& context
->dpi
!= NULL
18979 && DECL_CONTEXT (loc
) == context
->dpi
->fndecl
)
18981 /* We are generating code for a DWARF procedure and we want to access
18982 one of its arguments: find the appropriate argument offset and let
18983 the resolve_args_picking pass compute the offset that complies
18984 with the stack frame size. */
18988 for (cursor
= DECL_ARGUMENTS (context
->dpi
->fndecl
);
18989 cursor
!= NULL_TREE
&& cursor
!= loc
;
18990 cursor
= TREE_CHAIN (cursor
), ++i
)
18992 /* If we are translating a DWARF procedure, all referenced parameters
18993 must belong to the current function. */
18994 gcc_assert (cursor
!= NULL_TREE
);
18996 ret
= new_loc_descr (DW_OP_pick
, i
, 0);
18997 ret
->frame_offset_rel
= 1;
19003 if (DECL_HAS_VALUE_EXPR_P (loc
))
19005 tree value_expr
= DECL_VALUE_EXPR (loc
);
19007 /* Non-local frame structures are DECL_IGNORED_P variables so we need
19008 to wait until they get an RTX in order to reference them. */
19010 && TREE_CODE (value_expr
) == COMPONENT_REF
19011 && VAR_P (TREE_OPERAND (value_expr
, 0))
19012 && DECL_NONLOCAL_FRAME (TREE_OPERAND (value_expr
, 0)))
19015 return loc_list_from_tree_1 (value_expr
, want_address
, context
);
19020 case FUNCTION_DECL
:
19023 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
19025 if (loc_list
&& loc_list
->first
)
19027 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
19028 have_address
= want_address
!= 0;
19031 rtl
= rtl_for_decl_location (loc
);
19032 if (rtl
== NULL_RTX
)
19034 if (TREE_CODE (loc
) != FUNCTION_DECL
19036 && want_address
!= 1
19037 && ! DECL_IGNORED_P (loc
)
19038 && (INTEGRAL_TYPE_P (TREE_TYPE (loc
))
19039 || POINTER_TYPE_P (TREE_TYPE (loc
)))
19040 && TYPE_MODE (TREE_TYPE (loc
)) != BLKmode
19041 && (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (loc
)))
19042 <= DWARF2_ADDR_SIZE
))
19044 dw_die_ref ref
= lookup_decl_die (loc
);
19047 ret
= new_loc_descr (DW_OP_GNU_variable_value
, 0, 0);
19048 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
19049 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
19050 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
19052 else if (current_function_decl
19053 && DECL_CONTEXT (loc
) == current_function_decl
)
19055 ret
= new_loc_descr (DW_OP_GNU_variable_value
, 0, 0);
19056 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
19057 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= loc
;
19061 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
19064 else if (CONST_INT_P (rtl
))
19066 HOST_WIDE_INT val
= INTVAL (rtl
);
19067 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
19068 val
&= GET_MODE_MASK (DECL_MODE (loc
));
19069 ret
= int_loc_descriptor (val
);
19071 else if (GET_CODE (rtl
) == CONST_STRING
)
19073 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
19076 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
19077 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
19080 machine_mode mode
, mem_mode
;
19082 /* Certain constructs can only be represented at top-level. */
19083 if (want_address
== 2)
19085 ret
= loc_descriptor (rtl
, VOIDmode
,
19086 VAR_INIT_STATUS_INITIALIZED
);
19091 mode
= GET_MODE (rtl
);
19092 mem_mode
= VOIDmode
;
19096 mode
= get_address_mode (rtl
);
19097 rtl
= XEXP (rtl
, 0);
19100 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
19101 VAR_INIT_STATUS_INITIALIZED
);
19104 expansion_failed (loc
, rtl
,
19105 "failed to produce loc descriptor for rtl");
19111 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
19118 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
19122 case TARGET_MEM_REF
:
19124 case DEBUG_EXPR_DECL
:
19127 case COMPOUND_EXPR
:
19128 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), want_address
,
19132 case VIEW_CONVERT_EXPR
:
19135 case NON_LVALUE_EXPR
:
19136 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), want_address
,
19139 case COMPONENT_REF
:
19140 case BIT_FIELD_REF
:
19142 case ARRAY_RANGE_REF
:
19143 case REALPART_EXPR
:
19144 case IMAGPART_EXPR
:
19147 poly_int64 bitsize
, bitpos
, bytepos
;
19149 int unsignedp
, reversep
, volatilep
= 0;
19151 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
19152 &unsignedp
, &reversep
, &volatilep
);
19154 gcc_assert (obj
!= loc
);
19156 list_ret
= loc_list_from_tree_1 (obj
,
19158 && known_eq (bitpos
, 0)
19159 && !offset
? 2 : 1,
19161 /* TODO: We can extract value of the small expression via shifting even
19162 for nonzero bitpos. */
19165 if (!multiple_p (bitpos
, BITS_PER_UNIT
, &bytepos
)
19166 || !multiple_p (bitsize
, BITS_PER_UNIT
))
19168 expansion_failed (loc
, NULL_RTX
,
19169 "bitfield access");
19173 if (offset
!= NULL_TREE
)
19175 /* Variable offset. */
19176 list_ret1
= loc_list_from_tree_1 (offset
, 0, context
);
19177 if (list_ret1
== 0)
19179 add_loc_list (&list_ret
, list_ret1
);
19182 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
19185 HOST_WIDE_INT value
;
19186 if (bytepos
.is_constant (&value
) && value
> 0)
19187 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
,
19189 else if (maybe_ne (bytepos
, 0))
19190 loc_list_plus_const (list_ret
, bytepos
);
19197 if ((want_address
|| !tree_fits_shwi_p (loc
))
19198 && (ret
= cst_pool_loc_descr (loc
)))
19200 else if (want_address
== 2
19201 && tree_fits_shwi_p (loc
)
19202 && (ret
= address_of_int_loc_descriptor
19203 (int_size_in_bytes (TREE_TYPE (loc
)),
19204 tree_to_shwi (loc
))))
19206 else if (tree_fits_shwi_p (loc
))
19207 ret
= int_loc_descriptor (tree_to_shwi (loc
));
19208 else if (tree_fits_uhwi_p (loc
))
19209 ret
= uint_loc_descriptor (tree_to_uhwi (loc
));
19212 expansion_failed (loc
, NULL_RTX
,
19213 "Integer operand is not host integer");
19222 expansion_failed (loc
, NULL_RTX
,
19223 "constant address with a runtime component");
19227 if (!poly_int_tree_p (loc
, &value
))
19229 expansion_failed (loc
, NULL_RTX
, "constant too big");
19232 ret
= int_loc_descriptor (value
);
19240 if ((ret
= cst_pool_loc_descr (loc
)))
19242 else if (TREE_CODE (loc
) == CONSTRUCTOR
)
19244 tree type
= TREE_TYPE (loc
);
19245 unsigned HOST_WIDE_INT size
= int_size_in_bytes (type
);
19246 unsigned HOST_WIDE_INT offset
= 0;
19247 unsigned HOST_WIDE_INT cnt
;
19248 constructor_elt
*ce
;
19250 if (TREE_CODE (type
) == RECORD_TYPE
)
19252 /* This is very limited, but it's enough to output
19253 pointers to member functions, as long as the
19254 referenced function is defined in the current
19255 translation unit. */
19256 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (loc
), cnt
, ce
)
19258 tree val
= ce
->value
;
19260 tree field
= ce
->index
;
19265 if (!field
|| DECL_BIT_FIELD (field
))
19267 expansion_failed (loc
, NULL_RTX
,
19268 "bitfield in record type constructor");
19269 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
19274 HOST_WIDE_INT fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
19275 unsigned HOST_WIDE_INT pos
= int_byte_position (field
);
19276 gcc_assert (pos
+ fieldsize
<= size
);
19279 expansion_failed (loc
, NULL_RTX
,
19280 "out-of-order fields in record constructor");
19281 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
19287 ret1
= new_loc_descr (DW_OP_piece
, pos
- offset
, 0);
19288 add_loc_descr (&ret
, ret1
);
19291 if (val
&& fieldsize
!= 0)
19293 ret1
= loc_descriptor_from_tree (val
, want_address
, context
);
19296 expansion_failed (loc
, NULL_RTX
,
19297 "unsupported expression in field");
19298 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
19302 add_loc_descr (&ret
, ret1
);
19306 ret1
= new_loc_descr (DW_OP_piece
, fieldsize
, 0);
19307 add_loc_descr (&ret
, ret1
);
19308 offset
= pos
+ fieldsize
;
19312 if (offset
!= size
)
19314 ret1
= new_loc_descr (DW_OP_piece
, size
- offset
, 0);
19315 add_loc_descr (&ret
, ret1
);
19319 have_address
= !!want_address
;
19322 expansion_failed (loc
, NULL_RTX
,
19323 "constructor of non-record type");
19326 /* We can construct small constants here using int_loc_descriptor. */
19327 expansion_failed (loc
, NULL_RTX
,
19328 "constructor or constant not in constant pool");
19331 case TRUTH_AND_EXPR
:
19332 case TRUTH_ANDIF_EXPR
:
19337 case TRUTH_XOR_EXPR
:
19342 case TRUTH_OR_EXPR
:
19343 case TRUTH_ORIF_EXPR
:
19348 case EXACT_DIV_EXPR
:
19349 case FLOOR_DIV_EXPR
:
19350 case TRUNC_DIV_EXPR
:
19351 /* Turn a divide by a power of 2 into a shift when possible. */
19352 if (TYPE_UNSIGNED (TREE_TYPE (loc
))
19353 && tree_fits_uhwi_p (TREE_OPERAND (loc
, 1)))
19355 const int log2
= exact_log2 (tree_to_uhwi (TREE_OPERAND (loc
, 1)));
19359 = loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
19363 add_loc_descr_to_each (list_ret
, uint_loc_descriptor (log2
));
19364 add_loc_descr_to_each (list_ret
,
19365 new_loc_descr (DW_OP_shr
, 0, 0));
19372 case CEIL_DIV_EXPR
:
19373 case ROUND_DIV_EXPR
:
19374 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
19376 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (loc
));
19377 scalar_int_mode int_mode
;
19379 if ((dwarf_strict
&& dwarf_version
< 5)
19380 || !is_a
<scalar_int_mode
> (mode
, &int_mode
))
19383 /* We can use a signed divide if the sign bit is not set. */
19384 if (GET_MODE_SIZE (int_mode
) < DWARF2_ADDR_SIZE
)
19390 list_ret
= typed_binop_from_tree (DW_OP_div
, loc
,
19391 base_type_for_mode (int_mode
, 1),
19392 int_mode
, context
);
19402 case FLOOR_MOD_EXPR
:
19403 case CEIL_MOD_EXPR
:
19404 case ROUND_MOD_EXPR
:
19405 case TRUNC_MOD_EXPR
:
19406 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
19411 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
19412 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
19413 if (list_ret
== 0 || list_ret1
== 0)
19416 add_loc_list (&list_ret
, list_ret1
);
19419 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
19420 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
19421 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
19422 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
19423 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
19435 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
19438 case POINTER_PLUS_EXPR
:
19441 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
19443 /* Big unsigned numbers can fit in HOST_WIDE_INT but it may be
19444 smarter to encode their opposite. The DW_OP_plus_uconst operation
19445 takes 1 + X bytes, X being the size of the ULEB128 addend. On the
19446 other hand, a "<push literal>; DW_OP_minus" pattern takes 1 + Y
19447 bytes, Y being the size of the operation that pushes the opposite
19448 of the addend. So let's choose the smallest representation. */
19449 const tree tree_addend
= TREE_OPERAND (loc
, 1);
19450 offset_int wi_addend
;
19451 HOST_WIDE_INT shwi_addend
;
19452 dw_loc_descr_ref loc_naddend
;
19454 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
19458 /* Try to get the literal to push. It is the opposite of the addend,
19459 so as we rely on wrapping during DWARF evaluation, first decode
19460 the literal as a "DWARF-sized" signed number. */
19461 wi_addend
= wi::to_offset (tree_addend
);
19462 wi_addend
= wi::sext (wi_addend
, DWARF2_ADDR_SIZE
* 8);
19463 shwi_addend
= wi_addend
.to_shwi ();
19464 loc_naddend
= (shwi_addend
!= INTTYPE_MINIMUM (HOST_WIDE_INT
))
19465 ? int_loc_descriptor (-shwi_addend
)
19468 if (loc_naddend
!= NULL
19469 && ((unsigned) size_of_uleb128 (shwi_addend
)
19470 > size_of_loc_descr (loc_naddend
)))
19472 add_loc_descr_to_each (list_ret
, loc_naddend
);
19473 add_loc_descr_to_each (list_ret
,
19474 new_loc_descr (DW_OP_minus
, 0, 0));
19478 for (dw_loc_descr_ref loc_cur
= loc_naddend
; loc_cur
!= NULL
; )
19480 loc_naddend
= loc_cur
;
19481 loc_cur
= loc_cur
->dw_loc_next
;
19482 ggc_free (loc_naddend
);
19484 loc_list_plus_const (list_ret
, wi_addend
.to_shwi ());
19494 goto do_comp_binop
;
19498 goto do_comp_binop
;
19502 goto do_comp_binop
;
19506 goto do_comp_binop
;
19509 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
19511 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
19512 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
19513 list_ret
= loc_list_from_uint_comparison (list_ret
, list_ret1
,
19529 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
19530 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
19531 if (list_ret
== 0 || list_ret1
== 0)
19534 add_loc_list (&list_ret
, list_ret1
);
19537 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
19540 case TRUTH_NOT_EXPR
:
19541 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
19545 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_lit0
, 0, 0));
19546 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_eq
, 0, 0));
19562 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
19566 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
19572 const enum tree_code code
=
19573 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
19575 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
19576 build2 (code
, integer_type_node
,
19577 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
19578 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
19585 dw_loc_descr_ref lhs
19586 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
19587 dw_loc_list_ref rhs
19588 = loc_list_from_tree_1 (TREE_OPERAND (loc
, 2), 0, context
);
19589 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
19591 /* DW_OP_bra is branch-on-nonzero so avoid doing useless work. */
19592 if (TREE_CODE (TREE_OPERAND (loc
, 0)) == NE_EXPR
19593 && integer_zerop (TREE_OPERAND (TREE_OPERAND (loc
, 0), 1)))
19595 = loc_list_from_tree_1 (TREE_OPERAND (TREE_OPERAND (loc
, 0), 0),
19597 /* Likewise, swap the operands for a logically negated condition. */
19598 else if (TREE_CODE (TREE_OPERAND (loc
, 0)) == TRUTH_NOT_EXPR
)
19600 lhs
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 2), 0, context
);
19601 rhs
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
19603 = loc_list_from_tree_1 (TREE_OPERAND (TREE_OPERAND (loc
, 0), 0),
19607 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
19608 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
19611 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
19612 add_loc_descr_to_each (list_ret
, bra_node
);
19614 add_loc_list (&list_ret
, rhs
);
19615 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
19616 add_loc_descr_to_each (list_ret
, jump_node
);
19618 add_loc_descr_to_each (list_ret
, lhs
);
19619 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
19620 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
19622 /* ??? Need a node to point the skip at. Use a nop. */
19623 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
19624 add_loc_descr_to_each (list_ret
, tmp
);
19625 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
19626 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
19630 case FIX_TRUNC_EXPR
:
19633 case COMPOUND_LITERAL_EXPR
:
19634 return loc_list_from_tree_1 (COMPOUND_LITERAL_EXPR_DECL (loc
),
19638 /* Leave front-end specific codes as simply unknown. This comes
19639 up, for instance, with the C STMT_EXPR. */
19640 if ((unsigned int) TREE_CODE (loc
)
19641 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
19643 expansion_failed (loc
, NULL_RTX
,
19644 "language specific tree node");
19648 /* Otherwise this is a generic code; we should just lists all of
19649 these explicitly. We forgot one. */
19651 gcc_unreachable ();
19653 /* In a release build, we want to degrade gracefully: better to
19654 generate incomplete debugging information than to crash. */
19658 if (!ret
&& !list_ret
)
19661 if (want_address
== 2 && !have_address
19662 && (dwarf_version
>= 4 || !dwarf_strict
))
19664 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
19666 expansion_failed (loc
, NULL_RTX
,
19667 "DWARF address size mismatch");
19671 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
19673 add_loc_descr_to_each (list_ret
,
19674 new_loc_descr (DW_OP_stack_value
, 0, 0));
19677 /* Show if we can't fill the request for an address. */
19678 if (want_address
&& !have_address
)
19680 expansion_failed (loc
, NULL_RTX
,
19681 "Want address and only have value");
19685 gcc_assert (!ret
|| !list_ret
);
19687 /* If we've got an address and don't want one, dereference. */
19688 if (!want_address
&& have_address
)
19690 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
19691 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (loc
));
19692 scalar_int_mode int_mode
;
19693 dw_die_ref type_die
;
19694 dw_loc_descr_ref deref
;
19696 /* If the size is greater than DWARF2_ADDR_SIZE, bail out. */
19697 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
19699 expansion_failed (loc
, NULL_RTX
,
19700 "DWARF address size mismatch");
19704 /* If it is equal to DWARF2_ADDR_SIZE, extension does not matter. */
19705 else if (size
== DWARF2_ADDR_SIZE
)
19706 deref
= new_loc_descr (DW_OP_deref
, size
, 0);
19708 /* If it is lower than DWARF2_ADDR_SIZE, DW_OP_deref_size will zero-
19709 extend the value, which is really OK for unsigned types only. */
19710 else if (!(context
&& context
->strict_signedness
)
19711 || TYPE_UNSIGNED (TREE_TYPE (loc
))
19712 || (dwarf_strict
&& dwarf_version
< 5)
19713 || !is_a
<scalar_int_mode
> (mode
, &int_mode
)
19714 || !(type_die
= base_type_for_mode (mode
, false)))
19715 deref
= new_loc_descr (DW_OP_deref_size
, size
, 0);
19717 /* Use DW_OP_deref_type for signed integral types if possible, but
19718 convert back to the generic type to avoid type mismatches later. */
19721 deref
= new_loc_descr (dwarf_OP (DW_OP_deref_type
), size
, 0);
19722 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
19723 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
19724 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
19725 add_loc_descr (&deref
,
19726 new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0));
19730 add_loc_descr (&ret
, deref
);
19732 add_loc_descr_to_each (list_ret
, deref
);
19736 list_ret
= new_loc_list (ret
, NULL
, 0, NULL
, 0, NULL
);
19741 /* Likewise, but strip useless DW_OP_nop operations in the resulting
19744 static dw_loc_list_ref
19745 loc_list_from_tree (tree loc
, int want_address
,
19746 struct loc_descr_context
*context
)
19748 dw_loc_list_ref result
= loc_list_from_tree_1 (loc
, want_address
, context
);
19750 for (dw_loc_list_ref loc_cur
= result
;
19751 loc_cur
!= NULL
; loc_cur
= loc_cur
->dw_loc_next
)
19752 loc_descr_without_nops (loc_cur
->expr
);
19756 /* Same as above but return only single location expression. */
19757 static dw_loc_descr_ref
19758 loc_descriptor_from_tree (tree loc
, int want_address
,
19759 struct loc_descr_context
*context
)
19761 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
, context
);
19764 if (ret
->dw_loc_next
)
19766 expansion_failed (loc
, NULL_RTX
,
19767 "Location list where only loc descriptor needed");
19773 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
19774 pointer to the declared type for the relevant field variable, or return
19775 `integer_type_node' if the given node turns out to be an
19776 ERROR_MARK node. */
19779 field_type (const_tree decl
)
19783 if (TREE_CODE (decl
) == ERROR_MARK
)
19784 return integer_type_node
;
19786 type
= DECL_BIT_FIELD_TYPE (decl
);
19787 if (type
== NULL_TREE
)
19788 type
= TREE_TYPE (decl
);
19793 /* Given a pointer to a tree node, return the alignment in bits for
19794 it, or else return BITS_PER_WORD if the node actually turns out to
19795 be an ERROR_MARK node. */
19797 static inline unsigned
19798 simple_type_align_in_bits (const_tree type
)
19800 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
19803 static inline unsigned
19804 simple_decl_align_in_bits (const_tree decl
)
19806 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
19809 /* Return the result of rounding T up to ALIGN. */
19811 static inline offset_int
19812 round_up_to_align (const offset_int
&t
, unsigned int align
)
19814 return wi::udiv_trunc (t
+ align
- 1, align
) * align
;
19817 /* Helper structure for RECORD_TYPE processing. */
19820 /* Root RECORD_TYPE. It is needed to generate data member location
19821 descriptions in variable-length records (VLR), but also to cope with
19822 variants, which are composed of nested structures multiplexed with
19823 QUAL_UNION_TYPE nodes. Each time such a structure is passed to a
19824 function processing a FIELD_DECL, it is required to be non null. */
19827 /* When generating a variant part in a RECORD_TYPE (i.e. a nested
19828 QUAL_UNION_TYPE), this holds an expression that computes the offset for
19829 this variant part as part of the root record (in storage units). For
19830 regular records, it must be NULL_TREE. */
19831 tree variant_part_offset
;
19834 /* Given a pointer to a FIELD_DECL, compute the byte offset of the lowest
19835 addressed byte of the "containing object" for the given FIELD_DECL. If
19836 possible, return a native constant through CST_OFFSET (in which case NULL is
19837 returned); otherwise return a DWARF expression that computes the offset.
19839 Set *CST_OFFSET to 0 and return NULL if we are unable to determine what
19840 that offset is, either because the argument turns out to be a pointer to an
19841 ERROR_MARK node, or because the offset expression is too complex for us.
19843 CTX is required: see the comment for VLR_CONTEXT. */
19845 static dw_loc_descr_ref
19846 field_byte_offset (const_tree decl
, struct vlr_context
*ctx
,
19847 HOST_WIDE_INT
*cst_offset
)
19850 dw_loc_list_ref loc_result
;
19854 if (TREE_CODE (decl
) == ERROR_MARK
)
19857 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
19859 /* We cannot handle variable bit offsets at the moment, so abort if it's the
19861 if (TREE_CODE (DECL_FIELD_BIT_OFFSET (decl
)) != INTEGER_CST
)
19864 /* We used to handle only constant offsets in all cases. Now, we handle
19865 properly dynamic byte offsets only when PCC bitfield type doesn't
19867 if (PCC_BITFIELD_TYPE_MATTERS
19868 && DECL_BIT_FIELD_TYPE (decl
)
19869 && TREE_CODE (DECL_FIELD_OFFSET (decl
)) == INTEGER_CST
)
19871 offset_int object_offset_in_bits
;
19872 offset_int object_offset_in_bytes
;
19873 offset_int bitpos_int
;
19875 tree field_size_tree
;
19876 offset_int deepest_bitpos
;
19877 offset_int field_size_in_bits
;
19878 unsigned int type_align_in_bits
;
19879 unsigned int decl_align_in_bits
;
19880 offset_int type_size_in_bits
;
19882 bitpos_int
= wi::to_offset (bit_position (decl
));
19883 type
= field_type (decl
);
19884 type_size_in_bits
= offset_int_type_size_in_bits (type
);
19885 type_align_in_bits
= simple_type_align_in_bits (type
);
19887 field_size_tree
= DECL_SIZE (decl
);
19889 /* The size could be unspecified if there was an error, or for
19890 a flexible array member. */
19891 if (!field_size_tree
)
19892 field_size_tree
= bitsize_zero_node
;
19894 /* If the size of the field is not constant, use the type size. */
19895 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
19896 field_size_in_bits
= wi::to_offset (field_size_tree
);
19898 field_size_in_bits
= type_size_in_bits
;
19900 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
19902 /* The GCC front-end doesn't make any attempt to keep track of the
19903 starting bit offset (relative to the start of the containing
19904 structure type) of the hypothetical "containing object" for a
19905 bit-field. Thus, when computing the byte offset value for the
19906 start of the "containing object" of a bit-field, we must deduce
19907 this information on our own. This can be rather tricky to do in
19908 some cases. For example, handling the following structure type
19909 definition when compiling for an i386/i486 target (which only
19910 aligns long long's to 32-bit boundaries) can be very tricky:
19912 struct S { int field1; long long field2:31; };
19914 Fortunately, there is a simple rule-of-thumb which can be used
19915 in such cases. When compiling for an i386/i486, GCC will
19916 allocate 8 bytes for the structure shown above. It decides to
19917 do this based upon one simple rule for bit-field allocation.
19918 GCC allocates each "containing object" for each bit-field at
19919 the first (i.e. lowest addressed) legitimate alignment boundary
19920 (based upon the required minimum alignment for the declared
19921 type of the field) which it can possibly use, subject to the
19922 condition that there is still enough available space remaining
19923 in the containing object (when allocated at the selected point)
19924 to fully accommodate all of the bits of the bit-field itself.
19926 This simple rule makes it obvious why GCC allocates 8 bytes for
19927 each object of the structure type shown above. When looking
19928 for a place to allocate the "containing object" for `field2',
19929 the compiler simply tries to allocate a 64-bit "containing
19930 object" at each successive 32-bit boundary (starting at zero)
19931 until it finds a place to allocate that 64- bit field such that
19932 at least 31 contiguous (and previously unallocated) bits remain
19933 within that selected 64 bit field. (As it turns out, for the
19934 example above, the compiler finds it is OK to allocate the
19935 "containing object" 64-bit field at bit-offset zero within the
19938 Here we attempt to work backwards from the limited set of facts
19939 we're given, and we try to deduce from those facts, where GCC
19940 must have believed that the containing object started (within
19941 the structure type). The value we deduce is then used (by the
19942 callers of this routine) to generate DW_AT_location and
19943 DW_AT_bit_offset attributes for fields (both bit-fields and, in
19944 the case of DW_AT_location, regular fields as well). */
19946 /* Figure out the bit-distance from the start of the structure to
19947 the "deepest" bit of the bit-field. */
19948 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
19950 /* This is the tricky part. Use some fancy footwork to deduce
19951 where the lowest addressed bit of the containing object must
19953 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
19955 /* Round up to type_align by default. This works best for
19957 object_offset_in_bits
19958 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
19960 if (wi::gtu_p (object_offset_in_bits
, bitpos_int
))
19962 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
19964 /* Round up to decl_align instead. */
19965 object_offset_in_bits
19966 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
19969 object_offset_in_bytes
19970 = wi::lrshift (object_offset_in_bits
, LOG2_BITS_PER_UNIT
);
19971 if (ctx
->variant_part_offset
== NULL_TREE
)
19973 *cst_offset
= object_offset_in_bytes
.to_shwi ();
19976 tree_result
= wide_int_to_tree (sizetype
, object_offset_in_bytes
);
19979 tree_result
= byte_position (decl
);
19981 if (ctx
->variant_part_offset
!= NULL_TREE
)
19982 tree_result
= fold_build2 (PLUS_EXPR
, TREE_TYPE (tree_result
),
19983 ctx
->variant_part_offset
, tree_result
);
19985 /* If the byte offset is a constant, it's simplier to handle a native
19986 constant rather than a DWARF expression. */
19987 if (TREE_CODE (tree_result
) == INTEGER_CST
)
19989 *cst_offset
= wi::to_offset (tree_result
).to_shwi ();
19993 struct loc_descr_context loc_ctx
= {
19994 ctx
->struct_type
, /* context_type */
19995 NULL_TREE
, /* base_decl */
19997 false, /* placeholder_arg */
19998 false, /* placeholder_seen */
19999 false /* strict_signedness */
20001 loc_result
= loc_list_from_tree (tree_result
, 0, &loc_ctx
);
20003 /* We want a DWARF expression: abort if we only have a location list with
20004 multiple elements. */
20005 if (!loc_result
|| !single_element_loc_list_p (loc_result
))
20008 return loc_result
->expr
;
20011 /* The following routines define various Dwarf attributes and any data
20012 associated with them. */
20014 /* Add a location description attribute value to a DIE.
20016 This emits location attributes suitable for whole variables and
20017 whole parameters. Note that the location attributes for struct fields are
20018 generated by the routine `data_member_location_attribute' below. */
20021 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
20022 dw_loc_list_ref descr
)
20024 bool check_no_locviews
= true;
20027 if (single_element_loc_list_p (descr
))
20028 add_AT_loc (die
, attr_kind
, descr
->expr
);
20031 add_AT_loc_list (die
, attr_kind
, descr
);
20032 gcc_assert (descr
->ll_symbol
);
20033 if (attr_kind
== DW_AT_location
&& descr
->vl_symbol
20034 && dwarf2out_locviews_in_attribute ())
20036 add_AT_view_list (die
, DW_AT_GNU_locviews
);
20037 check_no_locviews
= false;
20041 if (check_no_locviews
)
20042 gcc_assert (!get_AT (die
, DW_AT_GNU_locviews
));
20045 /* Add DW_AT_accessibility attribute to DIE if needed. */
20048 add_accessibility_attribute (dw_die_ref die
, tree decl
)
20050 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
20051 children, otherwise the default is DW_ACCESS_public. In DWARF2
20052 the default has always been DW_ACCESS_public. */
20053 if (TREE_PROTECTED (decl
))
20054 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
20055 else if (TREE_PRIVATE (decl
))
20057 if (dwarf_version
== 2
20058 || die
->die_parent
== NULL
20059 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
20060 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
20062 else if (dwarf_version
> 2
20064 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
20065 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
20068 /* Attach the specialized form of location attribute used for data members of
20069 struct and union types. In the special case of a FIELD_DECL node which
20070 represents a bit-field, the "offset" part of this special location
20071 descriptor must indicate the distance in bytes from the lowest-addressed
20072 byte of the containing struct or union type to the lowest-addressed byte of
20073 the "containing object" for the bit-field. (See the `field_byte_offset'
20076 For any given bit-field, the "containing object" is a hypothetical object
20077 (of some integral or enum type) within which the given bit-field lives. The
20078 type of this hypothetical "containing object" is always the same as the
20079 declared type of the individual bit-field itself (for GCC anyway... the
20080 DWARF spec doesn't actually mandate this). Note that it is the size (in
20081 bytes) of the hypothetical "containing object" which will be given in the
20082 DW_AT_byte_size attribute for this bit-field. (See the
20083 `byte_size_attribute' function below.) It is also used when calculating the
20084 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
20087 CTX is required: see the comment for VLR_CONTEXT. */
20090 add_data_member_location_attribute (dw_die_ref die
,
20092 struct vlr_context
*ctx
)
20094 HOST_WIDE_INT offset
;
20095 dw_loc_descr_ref loc_descr
= 0;
20097 if (TREE_CODE (decl
) == TREE_BINFO
)
20099 /* We're working on the TAG_inheritance for a base class. */
20100 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
20102 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
20103 aren't at a fixed offset from all (sub)objects of the same
20104 type. We need to extract the appropriate offset from our
20105 vtable. The following dwarf expression means
20107 BaseAddr = ObAddr + *((*ObAddr) - Offset)
20109 This is specific to the V3 ABI, of course. */
20111 dw_loc_descr_ref tmp
;
20113 /* Make a copy of the object address. */
20114 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
20115 add_loc_descr (&loc_descr
, tmp
);
20117 /* Extract the vtable address. */
20118 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
20119 add_loc_descr (&loc_descr
, tmp
);
20121 /* Calculate the address of the offset. */
20122 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
20123 gcc_assert (offset
< 0);
20125 tmp
= int_loc_descriptor (-offset
);
20126 add_loc_descr (&loc_descr
, tmp
);
20127 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
20128 add_loc_descr (&loc_descr
, tmp
);
20130 /* Extract the offset. */
20131 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
20132 add_loc_descr (&loc_descr
, tmp
);
20134 /* Add it to the object address. */
20135 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
20136 add_loc_descr (&loc_descr
, tmp
);
20139 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
20143 loc_descr
= field_byte_offset (decl
, ctx
, &offset
);
20148 /* If loc_descr is available, then we know the offset is dynamic. */
20149 else if (gnat_encodings
== DWARF_GNAT_ENCODINGS_ALL
)
20155 /* Data member location evaluation starts with the base address on the
20156 stack. Compute the field offset and add it to this base address. */
20158 add_loc_descr (&loc_descr
, new_loc_descr (DW_OP_plus
, 0, 0));
20163 /* While DW_AT_data_bit_offset has been added already in DWARF4,
20164 e.g. GDB only added support to it in November 2016. For DWARF5
20165 we need newer debug info consumers anyway. We might change this
20166 to dwarf_version >= 4 once most consumers catched up. */
20167 if (dwarf_version
>= 5
20168 && TREE_CODE (decl
) == FIELD_DECL
20169 && DECL_BIT_FIELD_TYPE (decl
)
20170 && (ctx
->variant_part_offset
== NULL_TREE
20171 || TREE_CODE (ctx
->variant_part_offset
) == INTEGER_CST
))
20173 tree off
= bit_position (decl
);
20174 if (ctx
->variant_part_offset
)
20175 off
= bit_from_pos (ctx
->variant_part_offset
, off
);
20176 if (tree_fits_uhwi_p (off
) && get_AT (die
, DW_AT_bit_size
))
20178 remove_AT (die
, DW_AT_byte_size
);
20179 remove_AT (die
, DW_AT_bit_offset
);
20180 add_AT_unsigned (die
, DW_AT_data_bit_offset
, tree_to_uhwi (off
));
20184 if (dwarf_version
> 2)
20186 /* Don't need to output a location expression, just the constant. */
20188 add_AT_int (die
, DW_AT_data_member_location
, offset
);
20190 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
20195 enum dwarf_location_atom op
;
20197 /* The DWARF2 standard says that we should assume that the structure
20198 address is already on the stack, so we can specify a structure
20199 field address by using DW_OP_plus_uconst. */
20200 op
= DW_OP_plus_uconst
;
20201 loc_descr
= new_loc_descr (op
, offset
, 0);
20205 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
20208 /* Writes integer values to dw_vec_const array. */
20211 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
20215 *dest
++ = val
& 0xff;
20221 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
20223 static HOST_WIDE_INT
20224 extract_int (const unsigned char *src
, unsigned int size
)
20226 HOST_WIDE_INT val
= 0;
20232 val
|= *--src
& 0xff;
20238 /* Writes wide_int values to dw_vec_const array. */
20241 insert_wide_int (const wide_int_ref
&val
, unsigned char *dest
, int elt_size
)
20245 if (elt_size
<= HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
)
20247 insert_int ((HOST_WIDE_INT
) val
.elt (0), elt_size
, dest
);
20251 /* We'd have to extend this code to support odd sizes. */
20252 gcc_assert (elt_size
% (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
) == 0);
20254 int n
= elt_size
/ (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
20256 if (WORDS_BIG_ENDIAN
)
20257 for (i
= n
- 1; i
>= 0; i
--)
20259 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
20260 dest
+= sizeof (HOST_WIDE_INT
);
20263 for (i
= 0; i
< n
; i
++)
20265 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
20266 dest
+= sizeof (HOST_WIDE_INT
);
20270 /* Writes floating point values to dw_vec_const array. */
20273 insert_float (const_rtx rtl
, unsigned char *array
)
20277 scalar_float_mode mode
= as_a
<scalar_float_mode
> (GET_MODE (rtl
));
20279 real_to_target (val
, CONST_DOUBLE_REAL_VALUE (rtl
), mode
);
20281 /* real_to_target puts 32-bit pieces in each long. Pack them. */
20282 if (GET_MODE_SIZE (mode
) < 4)
20284 gcc_assert (GET_MODE_SIZE (mode
) == 2);
20285 insert_int (val
[0], 2, array
);
20289 for (i
= 0; i
< GET_MODE_SIZE (mode
) / 4; i
++)
20291 insert_int (val
[i
], 4, array
);
20297 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
20298 does not have a "location" either in memory or in a register. These
20299 things can arise in GNU C when a constant is passed as an actual parameter
20300 to an inlined function. They can also arise in C++ where declared
20301 constants do not necessarily get memory "homes". */
20304 add_const_value_attribute (dw_die_ref die
, machine_mode mode
, rtx rtl
)
20306 scalar_mode int_mode
;
20308 switch (GET_CODE (rtl
))
20312 HOST_WIDE_INT val
= INTVAL (rtl
);
20315 add_AT_int (die
, DW_AT_const_value
, val
);
20317 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
20321 case CONST_WIDE_INT
:
20322 if (is_int_mode (mode
, &int_mode
)
20323 && (GET_MODE_PRECISION (int_mode
)
20324 & (HOST_BITS_PER_WIDE_INT
- 1)) == 0)
20326 add_AT_wide (die
, DW_AT_const_value
, rtx_mode_t (rtl
, int_mode
));
20332 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
20333 floating-point constant. A CONST_DOUBLE is used whenever the
20334 constant requires more than one word in order to be adequately
20336 if (TARGET_SUPPORTS_WIDE_INT
== 0
20337 && !SCALAR_FLOAT_MODE_P (GET_MODE (rtl
)))
20338 add_AT_double (die
, DW_AT_const_value
,
20339 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
20342 scalar_float_mode mode
= as_a
<scalar_float_mode
> (GET_MODE (rtl
));
20343 unsigned int length
= GET_MODE_SIZE (mode
);
20344 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
20345 unsigned int elt_size
= insert_float (rtl
, array
);
20347 add_AT_vec (die
, DW_AT_const_value
, length
/ elt_size
, elt_size
,
20354 unsigned int length
;
20355 if (!CONST_VECTOR_NUNITS (rtl
).is_constant (&length
))
20358 machine_mode mode
= GET_MODE (rtl
);
20359 /* The combination of a length and byte elt_size doesn't extend
20360 naturally to boolean vectors, where several elements are packed
20361 into the same byte. */
20362 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_BOOL
)
20365 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
20366 unsigned char *array
20367 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
20370 machine_mode imode
= GET_MODE_INNER (mode
);
20372 switch (GET_MODE_CLASS (mode
))
20374 case MODE_VECTOR_INT
:
20375 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
20377 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
20378 insert_wide_int (rtx_mode_t (elt
, imode
), p
, elt_size
);
20382 case MODE_VECTOR_FLOAT
:
20383 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
20385 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
20386 insert_float (elt
, p
);
20391 gcc_unreachable ();
20394 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
20399 if (dwarf_version
>= 4 || !dwarf_strict
)
20401 dw_loc_descr_ref loc_result
;
20402 resolve_one_addr (&rtl
);
20404 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
20405 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
20406 add_AT_loc (die
, DW_AT_location
, loc_result
);
20407 vec_safe_push (used_rtx_array
, rtl
);
20413 if (CONSTANT_P (XEXP (rtl
, 0)))
20414 return add_const_value_attribute (die
, mode
, XEXP (rtl
, 0));
20417 if (!const_ok_for_output (rtl
))
20421 if (dwarf_version
>= 4 || !dwarf_strict
)
20426 /* In cases where an inlined instance of an inline function is passed
20427 the address of an `auto' variable (which is local to the caller) we
20428 can get a situation where the DECL_RTL of the artificial local
20429 variable (for the inlining) which acts as a stand-in for the
20430 corresponding formal parameter (of the inline function) will look
20431 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
20432 exactly a compile-time constant expression, but it isn't the address
20433 of the (artificial) local variable either. Rather, it represents the
20434 *value* which the artificial local variable always has during its
20435 lifetime. We currently have no way to represent such quasi-constant
20436 values in Dwarf, so for now we just punt and generate nothing. */
20444 case CONST_POLY_INT
:
20448 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
20449 && MEM_READONLY_P (rtl
)
20450 && GET_MODE (rtl
) == BLKmode
)
20452 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
20458 /* No other kinds of rtx should be possible here. */
20459 gcc_unreachable ();
20463 /* Determine whether the evaluation of EXPR references any variables
20464 or functions which aren't otherwise used (and therefore may not be
20467 reference_to_unused (tree
* tp
, int * walk_subtrees
,
20468 void * data ATTRIBUTE_UNUSED
)
20470 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
20471 *walk_subtrees
= 0;
20473 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
20474 && ! TREE_ASM_WRITTEN (*tp
))
20476 /* ??? The C++ FE emits debug information for using decls, so
20477 putting gcc_unreachable here falls over. See PR31899. For now
20478 be conservative. */
20479 else if (!symtab
->global_info_ready
&& VAR_P (*tp
))
20481 else if (VAR_P (*tp
))
20483 varpool_node
*node
= varpool_node::get (*tp
);
20484 if (!node
|| !node
->definition
)
20487 else if (TREE_CODE (*tp
) == FUNCTION_DECL
20488 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
20490 /* The call graph machinery must have finished analyzing,
20491 optimizing and gimplifying the CU by now.
20492 So if *TP has no call graph node associated
20493 to it, it means *TP will not be emitted. */
20494 if (!symtab
->global_info_ready
|| !cgraph_node::get (*tp
))
20497 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
20503 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
20504 for use in a later add_const_value_attribute call. */
20507 rtl_for_decl_init (tree init
, tree type
)
20509 rtx rtl
= NULL_RTX
;
20513 /* If a variable is initialized with a string constant without embedded
20514 zeros, build CONST_STRING. */
20515 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
20517 tree enttype
= TREE_TYPE (type
);
20518 tree domain
= TYPE_DOMAIN (type
);
20519 scalar_int_mode mode
;
20521 if (is_int_mode (TYPE_MODE (enttype
), &mode
)
20522 && GET_MODE_SIZE (mode
) == 1
20524 && TYPE_MAX_VALUE (domain
)
20525 && TREE_CODE (TYPE_MAX_VALUE (domain
)) == INTEGER_CST
20526 && integer_zerop (TYPE_MIN_VALUE (domain
))
20527 && compare_tree_int (TYPE_MAX_VALUE (domain
),
20528 TREE_STRING_LENGTH (init
) - 1) == 0
20529 && ((size_t) TREE_STRING_LENGTH (init
)
20530 == strlen (TREE_STRING_POINTER (init
)) + 1))
20532 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
20533 ggc_strdup (TREE_STRING_POINTER (init
)));
20534 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
20535 MEM_READONLY_P (rtl
) = 1;
20538 /* Other aggregates, and complex values, could be represented using
20540 If this changes, please adjust tree_add_const_value_attribute
20541 so that for early_dwarf it will for such initializers mangle referenced
20543 else if (AGGREGATE_TYPE_P (type
)
20544 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
20545 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
20546 || TREE_CODE (type
) == COMPLEX_TYPE
)
20548 /* Vectors only work if their mode is supported by the target.
20549 FIXME: generic vectors ought to work too. */
20550 else if (TREE_CODE (type
) == VECTOR_TYPE
20551 && !VECTOR_MODE_P (TYPE_MODE (type
)))
20553 /* If the initializer is something that we know will expand into an
20554 immediate RTL constant, expand it now. We must be careful not to
20555 reference variables which won't be output. */
20556 else if (initializer_constant_valid_p (init
, type
)
20557 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
20559 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
20561 if (TREE_CODE (type
) == VECTOR_TYPE
)
20562 switch (TREE_CODE (init
))
20567 if (TREE_CONSTANT (init
))
20569 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
20570 bool constant_p
= true;
20572 unsigned HOST_WIDE_INT ix
;
20574 /* Even when ctor is constant, it might contain non-*_CST
20575 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
20576 belong into VECTOR_CST nodes. */
20577 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
20578 if (!CONSTANT_CLASS_P (value
))
20580 constant_p
= false;
20586 init
= build_vector_from_ctor (type
, elts
);
20596 /* Large _BitInt BLKmode INTEGER_CSTs would yield a MEM. */
20597 if (TREE_CODE (init
) == INTEGER_CST
20598 && TREE_CODE (TREE_TYPE (init
)) == BITINT_TYPE
20599 && TYPE_MODE (TREE_TYPE (init
)) == BLKmode
)
20601 if (tree_fits_shwi_p (init
))
20602 return GEN_INT (tree_to_shwi (init
));
20607 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
20609 /* If expand_expr returns a MEM, it wasn't immediate. */
20610 gcc_assert (!rtl
|| !MEM_P (rtl
));
20616 /* Generate RTL for the variable DECL to represent its location. */
20619 rtl_for_decl_location (tree decl
)
20623 /* Here we have to decide where we are going to say the parameter "lives"
20624 (as far as the debugger is concerned). We only have a couple of
20625 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
20627 DECL_RTL normally indicates where the parameter lives during most of the
20628 activation of the function. If optimization is enabled however, this
20629 could be either NULL or else a pseudo-reg. Both of those cases indicate
20630 that the parameter doesn't really live anywhere (as far as the code
20631 generation parts of GCC are concerned) during most of the function's
20632 activation. That will happen (for example) if the parameter is never
20633 referenced within the function.
20635 We could just generate a location descriptor here for all non-NULL
20636 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
20637 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
20638 where DECL_RTL is NULL or is a pseudo-reg.
20640 Note however that we can only get away with using DECL_INCOMING_RTL as
20641 a backup substitute for DECL_RTL in certain limited cases. In cases
20642 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
20643 we can be sure that the parameter was passed using the same type as it is
20644 declared to have within the function, and that its DECL_INCOMING_RTL
20645 points us to a place where a value of that type is passed.
20647 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
20648 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
20649 because in these cases DECL_INCOMING_RTL points us to a value of some
20650 type which is *different* from the type of the parameter itself. Thus,
20651 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
20652 such cases, the debugger would end up (for example) trying to fetch a
20653 `float' from a place which actually contains the first part of a
20654 `double'. That would lead to really incorrect and confusing
20655 output at debug-time.
20657 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
20658 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
20659 are a couple of exceptions however. On little-endian machines we can
20660 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
20661 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
20662 an integral type that is smaller than TREE_TYPE (decl). These cases arise
20663 when (on a little-endian machine) a non-prototyped function has a
20664 parameter declared to be of type `short' or `char'. In such cases,
20665 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
20666 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
20667 passed `int' value. If the debugger then uses that address to fetch
20668 a `short' or a `char' (on a little-endian machine) the result will be
20669 the correct data, so we allow for such exceptional cases below.
20671 Note that our goal here is to describe the place where the given formal
20672 parameter lives during most of the function's activation (i.e. between the
20673 end of the prologue and the start of the epilogue). We'll do that as best
20674 as we can. Note however that if the given formal parameter is modified
20675 sometime during the execution of the function, then a stack backtrace (at
20676 debug-time) will show the function as having been called with the *new*
20677 value rather than the value which was originally passed in. This happens
20678 rarely enough that it is not a major problem, but it *is* a problem, and
20679 I'd like to fix it.
20681 A future version of dwarf2out.cc may generate two additional attributes for
20682 any given DW_TAG_formal_parameter DIE which will describe the "passed
20683 type" and the "passed location" for the given formal parameter in addition
20684 to the attributes we now generate to indicate the "declared type" and the
20685 "active location" for each parameter. This additional set of attributes
20686 could be used by debuggers for stack backtraces. Separately, note that
20687 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
20688 This happens (for example) for inlined-instances of inline function formal
20689 parameters which are never referenced. This really shouldn't be
20690 happening. All PARM_DECL nodes should get valid non-NULL
20691 DECL_INCOMING_RTL values. FIXME. */
20693 /* Use DECL_RTL as the "location" unless we find something better. */
20694 rtl
= DECL_RTL_IF_SET (decl
);
20696 /* When generating abstract instances, ignore everything except
20697 constants, symbols living in memory, and symbols living in
20698 fixed registers. */
20699 if (! reload_completed
)
20702 && (CONSTANT_P (rtl
)
20704 && CONSTANT_P (XEXP (rtl
, 0)))
20707 && TREE_STATIC (decl
))))
20709 rtl
= targetm
.delegitimize_address (rtl
);
20714 else if (TREE_CODE (decl
) == PARM_DECL
)
20716 if (rtl
== NULL_RTX
20717 || is_pseudo_reg (rtl
)
20719 && is_pseudo_reg (XEXP (rtl
, 0))
20720 && DECL_INCOMING_RTL (decl
)
20721 && MEM_P (DECL_INCOMING_RTL (decl
))
20722 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
20724 tree declared_type
= TREE_TYPE (decl
);
20725 tree passed_type
= DECL_ARG_TYPE (decl
);
20726 machine_mode dmode
= TYPE_MODE (declared_type
);
20727 machine_mode pmode
= TYPE_MODE (passed_type
);
20729 /* This decl represents a formal parameter which was optimized out.
20730 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
20731 all cases where (rtl == NULL_RTX) just below. */
20732 if (dmode
== pmode
)
20733 rtl
= DECL_INCOMING_RTL (decl
);
20734 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
20735 && SCALAR_INT_MODE_P (dmode
)
20736 && known_le (GET_MODE_SIZE (dmode
), GET_MODE_SIZE (pmode
))
20737 && DECL_INCOMING_RTL (decl
))
20739 rtx inc
= DECL_INCOMING_RTL (decl
);
20742 else if (MEM_P (inc
))
20744 if (BYTES_BIG_ENDIAN
)
20745 rtl
= adjust_address_nv (inc
, dmode
,
20746 GET_MODE_SIZE (pmode
)
20747 - GET_MODE_SIZE (dmode
));
20754 /* If the parm was passed in registers, but lives on the stack, then
20755 make a big endian correction if the mode of the type of the
20756 parameter is not the same as the mode of the rtl. */
20757 /* ??? This is the same series of checks that are made in dbxout.cc before
20758 we reach the big endian correction code there. It isn't clear if all
20759 of these checks are necessary here, but keeping them all is the safe
20761 else if (MEM_P (rtl
)
20762 && XEXP (rtl
, 0) != const0_rtx
20763 && ! CONSTANT_P (XEXP (rtl
, 0))
20764 /* Not passed in memory. */
20765 && !MEM_P (DECL_INCOMING_RTL (decl
))
20766 /* Not passed by invisible reference. */
20767 && (!REG_P (XEXP (rtl
, 0))
20768 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
20769 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
20770 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
20771 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
20774 /* Big endian correction check. */
20775 && BYTES_BIG_ENDIAN
20776 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
20777 && known_lt (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))),
20780 machine_mode addr_mode
= get_address_mode (rtl
);
20781 poly_int64 offset
= (UNITS_PER_WORD
20782 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
20784 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
20785 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
20788 else if (VAR_P (decl
)
20791 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
)))
20793 machine_mode addr_mode
= get_address_mode (rtl
);
20794 poly_int64 offset
= byte_lowpart_offset (TYPE_MODE (TREE_TYPE (decl
)),
20797 /* If a variable is declared "register" yet is smaller than
20798 a register, then if we store the variable to memory, it
20799 looks like we're storing a register-sized value, when in
20800 fact we are not. We need to adjust the offset of the
20801 storage location to reflect the actual value's bytes,
20802 else gdb will not be able to display it. */
20803 if (maybe_ne (offset
, 0))
20804 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
20805 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
20808 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
20809 and will have been substituted directly into all expressions that use it.
20810 C does not have such a concept, but C++ and other languages do. */
20811 if (!rtl
&& VAR_P (decl
) && DECL_INITIAL (decl
))
20812 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
20815 rtl
= targetm
.delegitimize_address (rtl
);
20817 /* If we don't look past the constant pool, we risk emitting a
20818 reference to a constant pool entry that isn't referenced from
20819 code, and thus is not emitted. */
20821 rtl
= avoid_constant_pool_reference (rtl
);
20823 /* Try harder to get a rtl. If this symbol ends up not being emitted
20824 in the current CU, resolve_addr will remove the expression referencing
20826 if (rtl
== NULL_RTX
20827 && !(early_dwarf
&& (flag_generate_lto
|| flag_generate_offload
))
20829 && !DECL_EXTERNAL (decl
)
20830 && TREE_STATIC (decl
)
20831 && DECL_NAME (decl
)
20832 && !DECL_HARD_REGISTER (decl
)
20833 && DECL_MODE (decl
) != VOIDmode
)
20835 rtl
= make_decl_rtl_for_debug (decl
);
20837 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
20838 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
20845 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
20846 returned. If so, the decl for the COMMON block is returned, and the
20847 value is the offset into the common block for the symbol. */
20850 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
20852 tree val_expr
, cvar
;
20854 poly_int64 bitsize
, bitpos
;
20856 HOST_WIDE_INT cbitpos
;
20857 int unsignedp
, reversep
, volatilep
= 0;
20859 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
20860 it does not have a value (the offset into the common area), or if it
20861 is thread local (as opposed to global) then it isn't common, and shouldn't
20862 be handled as such. */
20864 || !TREE_STATIC (decl
)
20865 || !DECL_HAS_VALUE_EXPR_P (decl
)
20869 val_expr
= DECL_VALUE_EXPR (decl
);
20870 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
20873 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
, &mode
,
20874 &unsignedp
, &reversep
, &volatilep
);
20876 if (cvar
== NULL_TREE
20878 || DECL_ARTIFICIAL (cvar
)
20879 || !TREE_PUBLIC (cvar
)
20880 /* We don't expect to have to cope with variable offsets,
20881 since at present all static data must have a constant size. */
20882 || !bitpos
.is_constant (&cbitpos
))
20886 if (offset
!= NULL
)
20888 if (!tree_fits_shwi_p (offset
))
20890 *value
= tree_to_shwi (offset
);
20893 *value
+= cbitpos
/ BITS_PER_UNIT
;
20898 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
20899 data attribute for a variable or a parameter. We generate the
20900 DW_AT_const_value attribute only in those cases where the given variable
20901 or parameter does not have a true "location" either in memory or in a
20902 register. This can happen (for example) when a constant is passed as an
20903 actual argument in a call to an inline function. (It's possible that
20904 these things can crop up in other ways also.) Note that one type of
20905 constant value which can be passed into an inlined function is a constant
20906 pointer. This can happen for example if an actual argument in an inlined
20907 function call evaluates to a compile-time constant address.
20909 CACHE_P is true if it is worth caching the location list for DECL,
20910 so that future calls can reuse it rather than regenerate it from scratch.
20911 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
20912 since we will need to refer to them each time the function is inlined. */
20915 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
)
20918 dw_loc_list_ref list
;
20919 var_loc_list
*loc_list
;
20920 cached_dw_loc_list
*cache
;
20925 if (TREE_CODE (decl
) == ERROR_MARK
)
20928 if (get_AT (die
, DW_AT_location
)
20929 || get_AT (die
, DW_AT_const_value
))
20932 gcc_assert (VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
20933 || TREE_CODE (decl
) == RESULT_DECL
);
20935 /* Try to get some constant RTL for this decl, and use that as the value of
20938 rtl
= rtl_for_decl_location (decl
);
20939 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
20940 && add_const_value_attribute (die
, DECL_MODE (decl
), rtl
))
20943 /* See if we have single element location list that is equivalent to
20944 a constant value. That way we are better to use add_const_value_attribute
20945 rather than expanding constant value equivalent. */
20946 loc_list
= lookup_decl_loc (decl
);
20949 && loc_list
->first
->next
== NULL
20950 && NOTE_P (loc_list
->first
->loc
)
20951 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
20952 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
20954 struct var_loc_node
*node
;
20956 node
= loc_list
->first
;
20957 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
20958 if (GET_CODE (rtl
) == EXPR_LIST
)
20959 rtl
= XEXP (rtl
, 0);
20960 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
20961 && add_const_value_attribute (die
, DECL_MODE (decl
), rtl
))
20964 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
20965 list several times. See if we've already cached the contents. */
20967 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
20971 cache
= cached_dw_loc_list_table
->find_with_hash (decl
, DECL_UID (decl
));
20973 list
= cache
->loc_list
;
20977 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2,
20979 /* It is usually worth caching this result if the decl is from
20980 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
20981 if (cache_p
&& list
&& list
->dw_loc_next
)
20983 cached_dw_loc_list
**slot
20984 = cached_dw_loc_list_table
->find_slot_with_hash (decl
,
20987 cache
= ggc_cleared_alloc
<cached_dw_loc_list
> ();
20988 cache
->decl_id
= DECL_UID (decl
);
20989 cache
->loc_list
= list
;
20995 add_AT_location_description (die
, DW_AT_location
, list
);
20998 /* None of that worked, so it must not really have a location;
20999 try adding a constant value attribute from the DECL_INITIAL. */
21000 return tree_add_const_value_attribute_for_decl (die
, decl
);
21003 /* Mangle referenced decls. */
21005 mangle_referenced_decls (tree
*tp
, int *walk_subtrees
, void *)
21007 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
21008 *walk_subtrees
= 0;
21010 if (VAR_OR_FUNCTION_DECL_P (*tp
))
21011 assign_assembler_name_if_needed (*tp
);
21016 /* Attach a DW_AT_const_value attribute to DIE. The value of the
21017 attribute is the const value T. */
21020 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
21023 tree type
= TREE_TYPE (t
);
21025 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
21029 gcc_assert (!DECL_P (init
));
21031 if (TREE_CODE (init
) == INTEGER_CST
)
21033 if (tree_fits_uhwi_p (init
))
21035 add_AT_unsigned (die
, DW_AT_const_value
, tree_to_uhwi (init
));
21038 if (tree_fits_shwi_p (init
))
21040 add_AT_int (die
, DW_AT_const_value
, tree_to_shwi (init
));
21046 rtx rtl
= rtl_for_decl_init (init
, type
);
21048 return add_const_value_attribute (die
, TYPE_MODE (type
), rtl
);
21052 /* For early_dwarf force mangling of all referenced symbols. */
21053 tree initializer
= init
;
21054 STRIP_NOPS (initializer
);
21055 /* rtl_for_decl_init punts on other aggregates, and complex values. */
21056 if (AGGREGATE_TYPE_P (type
)
21057 || (TREE_CODE (initializer
) == VIEW_CONVERT_EXPR
21058 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (initializer
, 0))))
21059 || TREE_CODE (type
) == COMPLEX_TYPE
)
21061 else if (initializer_constant_valid_p (initializer
, type
))
21062 walk_tree (&initializer
, mangle_referenced_decls
, NULL
, NULL
);
21064 /* If the host and target are sane, try harder. */
21065 if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
21066 && initializer_constant_valid_p (init
, type
))
21068 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
21069 if (size
> 0 && (int) size
== size
)
21071 unsigned char *array
= ggc_cleared_vec_alloc
<unsigned char> (size
);
21073 if (native_encode_initializer (init
, array
, size
) == size
)
21075 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
21084 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
21085 attribute is the const value of T, where T is an integral constant
21086 variable with static storage duration
21087 (so it can't be a PARM_DECL or a RESULT_DECL). */
21090 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
21094 || (!VAR_P (decl
) && TREE_CODE (decl
) != CONST_DECL
)
21095 || (VAR_P (decl
) && !TREE_STATIC (decl
)))
21098 if (TREE_READONLY (decl
)
21099 && ! TREE_THIS_VOLATILE (decl
)
21100 && DECL_INITIAL (decl
))
21105 /* Don't add DW_AT_const_value if abstract origin already has one. */
21106 if (get_AT (var_die
, DW_AT_const_value
))
21109 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
21112 /* Convert the CFI instructions for the current function into a
21113 location list. This is used for DW_AT_frame_base when we targeting
21114 a dwarf2 consumer that does not support the dwarf3
21115 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
21118 static dw_loc_list_ref
21119 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
21123 dw_loc_list_ref list
, *list_tail
;
21125 dw_cfa_location last_cfa
, next_cfa
;
21126 const char *start_label
, *last_label
, *section
;
21127 dw_cfa_location remember
;
21130 gcc_assert (fde
!= NULL
);
21132 section
= secname_for_decl (current_function_decl
);
21136 memset (&next_cfa
, 0, sizeof (next_cfa
));
21137 next_cfa
.reg
.set_by_dwreg (INVALID_REGNUM
);
21138 remember
= next_cfa
;
21140 start_label
= fde
->dw_fde_begin
;
21142 /* ??? Bald assumption that the CIE opcode list does not contain
21143 advance opcodes. */
21144 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
21145 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
21147 last_cfa
= next_cfa
;
21148 last_label
= start_label
;
21150 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
21152 /* If the first partition contained no CFI adjustments, the
21153 CIE opcodes apply to the whole first partition. */
21154 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
21155 fde
->dw_fde_begin
, 0, fde
->dw_fde_end
, 0, section
);
21156 list_tail
=&(*list_tail
)->dw_loc_next
;
21157 start_label
= last_label
= fde
->dw_fde_second_begin
;
21160 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
21162 switch (cfi
->dw_cfi_opc
)
21164 case DW_CFA_set_loc
:
21165 case DW_CFA_advance_loc1
:
21166 case DW_CFA_advance_loc2
:
21167 case DW_CFA_advance_loc4
:
21168 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
21170 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
21171 start_label
, 0, last_label
, 0, section
);
21173 list_tail
= &(*list_tail
)->dw_loc_next
;
21174 last_cfa
= next_cfa
;
21175 start_label
= last_label
;
21177 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
21180 case DW_CFA_advance_loc
:
21181 /* The encoding is complex enough that we should never emit this. */
21182 gcc_unreachable ();
21185 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
21188 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
21190 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
21192 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
21193 start_label
, 0, last_label
, 0, section
);
21195 list_tail
= &(*list_tail
)->dw_loc_next
;
21196 last_cfa
= next_cfa
;
21197 start_label
= last_label
;
21199 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
21200 start_label
, 0, fde
->dw_fde_end
, 0, section
);
21201 list_tail
= &(*list_tail
)->dw_loc_next
;
21202 start_label
= last_label
= fde
->dw_fde_second_begin
;
21206 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
21208 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
21209 start_label
, 0, last_label
, 0, section
);
21210 list_tail
= &(*list_tail
)->dw_loc_next
;
21211 start_label
= last_label
;
21214 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
21216 fde
->dw_fde_second_begin
21217 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
, 0,
21220 maybe_gen_llsym (list
);
21225 /* Compute a displacement from the "steady-state frame pointer" to the
21226 frame base (often the same as the CFA), and store it in
21227 frame_pointer_fb_offset. OFFSET is added to the displacement
21228 before the latter is negated. */
21231 compute_frame_pointer_to_fb_displacement (poly_int64 offset
)
21235 #ifdef FRAME_POINTER_CFA_OFFSET
21236 reg
= frame_pointer_rtx
;
21237 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
21239 reg
= arg_pointer_rtx
;
21240 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
21243 elim
= (ira_use_lra_p
21244 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
21245 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
21246 elim
= strip_offset_and_add (elim
, &offset
);
21248 frame_pointer_fb_offset
= -offset
;
21250 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
21251 in which to eliminate. This is because it's stack pointer isn't
21252 directly accessible as a register within the ISA. To work around
21253 this, assume that while we cannot provide a proper value for
21254 frame_pointer_fb_offset, we won't need one either. We can use
21255 hard frame pointer in debug info even if frame pointer isn't used
21256 since hard frame pointer in debug info is encoded with DW_OP_fbreg
21257 which uses the DW_AT_frame_base attribute, not hard frame pointer
21259 frame_pointer_fb_offset_valid
21260 = (elim
== hard_frame_pointer_rtx
|| elim
== stack_pointer_rtx
);
21263 /* Generate a DW_AT_name attribute given some string value to be included as
21264 the value of the attribute. */
21267 add_name_attribute (dw_die_ref die
, const char *name_string
)
21269 if (name_string
!= NULL
&& *name_string
!= 0)
21271 if (demangle_name_func
)
21272 name_string
= (*demangle_name_func
) (name_string
);
21274 add_AT_string (die
, DW_AT_name
, name_string
);
21278 /* Generate a DW_AT_name attribute given some string value representing a
21279 file or filepath to be included as value of the attribute. */
21281 add_filename_attribute (dw_die_ref die
, const char *name_string
)
21283 if (name_string
!= NULL
&& *name_string
!= 0)
21284 add_filepath_AT_string (die
, DW_AT_name
, name_string
);
21287 /* Generate a DW_AT_description attribute given some string value to be included
21288 as the value of the attribute. */
21291 add_desc_attribute (dw_die_ref die
, const char *name_string
)
21293 if (!flag_describe_dies
|| (dwarf_version
< 3 && dwarf_strict
))
21296 if (name_string
== NULL
|| *name_string
== 0)
21299 if (demangle_name_func
)
21300 name_string
= (*demangle_name_func
) (name_string
);
21302 add_AT_string (die
, DW_AT_description
, name_string
);
21305 /* Generate a DW_AT_description attribute given some decl to be included
21306 as the value of the attribute. */
21309 add_desc_attribute (dw_die_ref die
, tree decl
)
21313 if (!flag_describe_dies
|| (dwarf_version
< 3 && dwarf_strict
))
21316 if (decl
== NULL_TREE
|| !DECL_P (decl
))
21318 decl_name
= DECL_NAME (decl
);
21320 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
21322 const char *name
= dwarf2_name (decl
, 0);
21323 add_desc_attribute (die
, name
? name
: IDENTIFIER_POINTER (decl_name
));
21327 char *desc
= print_generic_expr_to_str (decl
);
21328 add_desc_attribute (die
, desc
);
21333 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
21334 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
21335 of TYPE accordingly.
21337 ??? This is a temporary measure until after we're able to generate
21338 regular DWARF for the complex Ada type system. */
21341 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
21342 dw_die_ref context_die
)
21345 dw_die_ref dtype_die
;
21347 if (!lang_hooks
.types
.descriptive_type
)
21350 dtype
= lang_hooks
.types
.descriptive_type (type
);
21354 dtype_die
= lookup_type_die (dtype
);
21357 gen_type_die (dtype
, context_die
);
21358 dtype_die
= lookup_type_die (dtype
);
21359 gcc_assert (dtype_die
);
21362 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
21365 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
21367 static const char *
21368 comp_dir_string (void)
21371 char *wd_plus_sep
= NULL
;
21372 static const char *cached_wd
= NULL
;
21374 if (cached_wd
!= NULL
)
21377 wd
= get_src_pwd ();
21381 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
21383 size_t wdlen
= strlen (wd
);
21384 wd_plus_sep
= XNEWVEC (char, wdlen
+ 2);
21385 strcpy (wd_plus_sep
, wd
);
21386 wd_plus_sep
[wdlen
] = DIR_SEPARATOR
;
21387 wd_plus_sep
[wdlen
+ 1] = 0;
21391 cached_wd
= remap_debug_filename (wd
);
21393 /* remap_debug_filename can just pass through wd or return a new gc string.
21394 These two types can't be both stored in a GTY(())-tagged string, but since
21395 the cached value lives forever just copy it if needed. */
21396 if (cached_wd
!= wd
)
21398 cached_wd
= xstrdup (cached_wd
);
21399 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
&& wd_plus_sep
!= NULL
)
21400 free (wd_plus_sep
);
21406 /* Generate a DW_AT_comp_dir attribute for DIE. */
21409 add_comp_dir_attribute (dw_die_ref die
)
21411 const char * wd
= comp_dir_string ();
21413 add_filepath_AT_string (die
, DW_AT_comp_dir
, wd
);
21416 /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
21417 pointer computation, ...), output a representation for that bound according
21418 to the accepted FORMS (see enum dw_scalar_form) and add it to DIE. See
21419 loc_list_from_tree for the meaning of CONTEXT. */
21422 add_scalar_info (dw_die_ref die
, enum dwarf_attribute attr
, tree value
,
21423 int forms
, struct loc_descr_context
*context
)
21425 dw_die_ref context_die
, decl_die
= NULL
;
21426 dw_loc_list_ref list
;
21427 bool strip_conversions
= true;
21428 bool placeholder_seen
= false;
21430 while (strip_conversions
)
21431 switch (TREE_CODE (value
))
21438 case VIEW_CONVERT_EXPR
:
21439 value
= TREE_OPERAND (value
, 0);
21443 strip_conversions
= false;
21447 /* If possible and permitted, output the attribute as a constant. */
21448 if ((forms
& dw_scalar_form_constant
) != 0
21449 && TREE_CODE (value
) == INTEGER_CST
)
21451 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (value
));
21453 /* If HOST_WIDE_INT is big enough then represent the bound as
21454 a constant value. We need to choose a form based on
21455 whether the type is signed or unsigned. We cannot just
21456 call add_AT_unsigned if the value itself is positive
21457 (add_AT_unsigned might add the unsigned value encoded as
21458 DW_FORM_data[1248]). Some DWARF consumers will lookup the
21459 bounds type and then sign extend any unsigned values found
21460 for signed types. This is needed only for
21461 DW_AT_{lower,upper}_bound, since for most other attributes,
21462 consumers will treat DW_FORM_data[1248] as unsigned values,
21463 regardless of the underlying type. */
21464 if (prec
<= HOST_BITS_PER_WIDE_INT
21465 || tree_fits_uhwi_p (value
))
21467 if (TYPE_UNSIGNED (TREE_TYPE (value
)))
21468 add_AT_unsigned (die
, attr
, TREE_INT_CST_LOW (value
));
21470 add_AT_int (die
, attr
, TREE_INT_CST_LOW (value
));
21472 else if (dwarf_version
>= 5
21473 && TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (value
))) == 128)
21474 /* Otherwise represent the bound as an unsigned value with
21475 the precision of its type. The precision and signedness
21476 of the type will be necessary to re-interpret it
21478 add_AT_wide (die
, attr
, wi::to_wide (value
));
21481 rtx v
= immed_wide_int_const (wi::to_wide (value
),
21482 TYPE_MODE (TREE_TYPE (value
)));
21483 dw_loc_descr_ref loc
21484 = loc_descriptor (v
, TYPE_MODE (TREE_TYPE (value
)),
21485 VAR_INIT_STATUS_INITIALIZED
);
21487 add_AT_loc (die
, attr
, loc
);
21492 /* Otherwise, if it's possible and permitted too, output a reference to
21494 if ((forms
& dw_scalar_form_reference
) != 0)
21496 tree decl
= NULL_TREE
;
21498 /* Some type attributes reference an outer type. For instance, the upper
21499 bound of an array may reference an embedding record (this happens in
21501 if (TREE_CODE (value
) == COMPONENT_REF
21502 && TREE_CODE (TREE_OPERAND (value
, 0)) == PLACEHOLDER_EXPR
21503 && TREE_CODE (TREE_OPERAND (value
, 1)) == FIELD_DECL
)
21504 decl
= TREE_OPERAND (value
, 1);
21506 else if (VAR_P (value
)
21507 || TREE_CODE (value
) == PARM_DECL
21508 || TREE_CODE (value
) == RESULT_DECL
)
21511 if (decl
!= NULL_TREE
)
21513 decl_die
= lookup_decl_die (decl
);
21515 /* ??? Can this happen, or should the variable have been bound
21516 first? Probably it can, since I imagine that we try to create
21517 the types of parameters in the order in which they exist in
21518 the list, and won't have created a forward reference to a
21519 later parameter. */
21520 if (decl_die
!= NULL
)
21522 if (get_AT (decl_die
, DW_AT_location
)
21523 || get_AT (decl_die
, DW_AT_data_member_location
)
21524 || get_AT (decl_die
, DW_AT_data_bit_offset
)
21525 || get_AT (decl_die
, DW_AT_const_value
))
21527 add_AT_die_ref (die
, attr
, decl_die
);
21534 /* Last chance: try to create a stack operation procedure to evaluate the
21535 value. Do nothing if even that is not possible or permitted. */
21536 if ((forms
& dw_scalar_form_exprloc
) == 0)
21539 list
= loc_list_from_tree (value
, 2, context
);
21540 if (context
&& context
->placeholder_arg
)
21542 placeholder_seen
= context
->placeholder_seen
;
21543 context
->placeholder_seen
= false;
21545 if (list
== NULL
|| single_element_loc_list_p (list
))
21547 /* If this attribute is not a reference nor constant, it is
21548 a DWARF expression rather than location description. For that
21549 loc_list_from_tree (value, 0, &context) is needed. */
21550 dw_loc_list_ref list2
= loc_list_from_tree (value
, 0, context
);
21551 if (list2
&& single_element_loc_list_p (list2
))
21553 if (placeholder_seen
)
21555 struct dwarf_procedure_info dpi
;
21556 dpi
.fndecl
= NULL_TREE
;
21557 dpi
.args_count
= 1;
21558 if (!resolve_args_picking (list2
->expr
, 1, &dpi
))
21561 add_AT_loc (die
, attr
, list2
->expr
);
21566 /* If that failed to give a single element location list, fall back to
21567 outputting this as a reference... still if permitted. */
21569 || (forms
& dw_scalar_form_reference
) == 0
21570 || placeholder_seen
)
21575 if (current_function_decl
== 0)
21576 context_die
= comp_unit_die ();
21578 context_die
= lookup_decl_die (current_function_decl
);
21580 decl_die
= new_die (DW_TAG_variable
, context_die
, value
);
21581 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
21582 add_type_attribute (decl_die
, TREE_TYPE (value
), TYPE_QUAL_CONST
, false,
21586 add_AT_location_description (decl_die
, DW_AT_location
, list
);
21587 add_AT_die_ref (die
, attr
, decl_die
);
21590 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
21594 lower_bound_default (void)
21596 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
21602 case DW_LANG_C_plus_plus
:
21603 case DW_LANG_C_plus_plus_11
:
21604 case DW_LANG_C_plus_plus_14
:
21606 case DW_LANG_ObjC_plus_plus
:
21608 case DW_LANG_Fortran77
:
21609 case DW_LANG_Fortran90
:
21610 case DW_LANG_Fortran95
:
21611 case DW_LANG_Fortran03
:
21612 case DW_LANG_Fortran08
:
21616 case DW_LANG_Python
:
21617 return dwarf_version
>= 4 ? 0 : -1;
21618 case DW_LANG_Ada95
:
21619 case DW_LANG_Ada83
:
21620 case DW_LANG_Cobol74
:
21621 case DW_LANG_Cobol85
:
21622 case DW_LANG_Modula2
:
21624 return dwarf_version
>= 4 ? 1 : -1;
21630 /* Given a tree node describing an array bound (either lower or upper) output
21631 a representation for that bound. */
21634 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
,
21635 tree bound
, struct loc_descr_context
*context
)
21640 switch (TREE_CODE (bound
))
21642 /* Strip all conversions. */
21644 case VIEW_CONVERT_EXPR
:
21645 bound
= TREE_OPERAND (bound
, 0);
21648 /* All fixed-bounds are represented by INTEGER_CST nodes. Lower bounds
21649 are even omitted when they are the default. */
21651 /* If the value for this bound is the default one, we can even omit the
21653 if (bound_attr
== DW_AT_lower_bound
21654 && tree_fits_shwi_p (bound
)
21655 && (dflt
= lower_bound_default ()) != -1
21656 && tree_to_shwi (bound
) == dflt
)
21662 /* Let GNAT encodings do the magic for self-referential bounds. */
21664 && gnat_encodings
== DWARF_GNAT_ENCODINGS_ALL
21665 && contains_placeholder_p (bound
))
21668 add_scalar_info (subrange_die
, bound_attr
, bound
,
21669 dw_scalar_form_constant
21670 | dw_scalar_form_exprloc
21671 | dw_scalar_form_reference
,
21677 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
21678 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
21680 This function reuses previously set type and bound information if
21684 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
21686 dw_die_ref child
= type_die
->die_child
;
21687 struct array_descr_info info
;
21688 int dimension_number
;
21690 if (lang_hooks
.types
.get_array_descr_info
)
21692 memset (&info
, 0, sizeof (info
));
21693 if (lang_hooks
.types
.get_array_descr_info (type
, &info
))
21694 /* Fortran sometimes emits array types with no dimension. */
21695 gcc_assert (info
.ndimensions
>= 0
21696 && info
.ndimensions
21697 <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN
);
21700 info
.ndimensions
= 0;
21702 for (dimension_number
= 0;
21703 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
21704 type
= TREE_TYPE (type
), dimension_number
++)
21706 tree domain
= TYPE_DOMAIN (type
);
21708 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
21711 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
21712 and (in GNU C only) variable bounds. Handle all three forms
21715 /* Find and reuse a previously generated DW_TAG_subrange_type if
21718 For multi-dimensional arrays, as we iterate through the
21719 various dimensions in the enclosing for loop above, we also
21720 iterate through the DIE children and pick at each
21721 DW_TAG_subrange_type previously generated (if available).
21722 Each child DW_TAG_subrange_type DIE describes the range of
21723 the current dimension. At this point we should have as many
21724 DW_TAG_subrange_type's as we have dimensions in the
21726 dw_die_ref subrange_die
= NULL
;
21730 child
= child
->die_sib
;
21731 if (child
->die_tag
== DW_TAG_subrange_type
)
21732 subrange_die
= child
;
21733 if (child
== type_die
->die_child
)
21735 /* If we wrapped around, stop looking next time. */
21739 if (child
->die_tag
== DW_TAG_subrange_type
)
21743 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
21747 /* We have an array type with specified bounds. */
21748 tree lower
= TYPE_MIN_VALUE (domain
);
21749 tree upper
= TYPE_MAX_VALUE (domain
);
21750 tree index_type
= TREE_TYPE (domain
);
21752 if (dimension_number
<= info
.ndimensions
- 1)
21754 lower
= info
.dimen
[dimension_number
].lower_bound
;
21755 upper
= info
.dimen
[dimension_number
].upper_bound
;
21756 index_type
= info
.dimen
[dimension_number
].bounds_type
;
21759 /* Define the index type. */
21760 if (index_type
&& !get_AT (subrange_die
, DW_AT_type
))
21761 add_type_attribute (subrange_die
, index_type
, TYPE_UNQUALIFIED
,
21764 /* ??? If upper is NULL, the array has unspecified length,
21765 but it does have a lower bound. This happens with Fortran
21767 Since the debugger is definitely going to need to know N
21768 to produce useful results, go ahead and output the lower
21769 bound solo, and hope the debugger can cope. */
21771 if (lower
&& !get_AT (subrange_die
, DW_AT_lower_bound
))
21772 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
, NULL
);
21774 if (!get_AT (subrange_die
, DW_AT_upper_bound
)
21775 && !get_AT (subrange_die
, DW_AT_count
))
21778 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
, NULL
);
21779 else if ((is_c () || is_cxx ()) && COMPLETE_TYPE_P (type
))
21780 /* Zero-length array. */
21781 add_bound_info (subrange_die
, DW_AT_count
,
21782 build_int_cst (TREE_TYPE (lower
), 0), NULL
);
21786 /* Otherwise we have an array type with an unspecified length. The
21787 DWARF-2 spec does not say how to handle this; let's just leave out the
21792 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
21795 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
21797 dw_die_ref decl_die
;
21798 HOST_WIDE_INT size
;
21800 switch (TREE_CODE (tree_node
))
21805 case ENUMERAL_TYPE
:
21808 case QUAL_UNION_TYPE
:
21809 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
21810 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
21812 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
21815 size
= int_size_in_bytes (tree_node
);
21818 /* For a data member of a struct or union, the DW_AT_byte_size is
21819 generally given as the number of bytes normally allocated for an
21820 object of the *declared* type of the member itself. This is true
21821 even for bit-fields. */
21822 size
= int_size_in_bytes (field_type (tree_node
));
21825 gcc_unreachable ();
21828 /* Note that `size' might be -1 when we get to this point. If it is, that
21829 indicates that the byte size of the entity in question is variable. */
21831 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
21833 /* Support for dynamically-sized objects was introduced in DWARF3. */
21834 else if (TYPE_P (tree_node
)
21835 && (dwarf_version
>= 3 || !dwarf_strict
)
21836 && gnat_encodings
!= DWARF_GNAT_ENCODINGS_ALL
)
21838 struct loc_descr_context ctx
= {
21839 const_cast<tree
> (tree_node
), /* context_type */
21840 NULL_TREE
, /* base_decl */
21842 false, /* placeholder_arg */
21843 false, /* placeholder_seen */
21844 false /* strict_signedness */
21847 tree tree_size
= TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (tree_node
));
21848 add_scalar_info (die
, DW_AT_byte_size
, tree_size
,
21849 dw_scalar_form_constant
21850 | dw_scalar_form_exprloc
21851 | dw_scalar_form_reference
,
21856 /* Add a DW_AT_alignment attribute to DIE with TREE_NODE's non-default
21860 add_alignment_attribute (dw_die_ref die
, tree tree_node
)
21862 if (dwarf_version
< 5 && dwarf_strict
)
21867 if (DECL_P (tree_node
))
21869 if (!DECL_USER_ALIGN (tree_node
))
21872 align
= DECL_ALIGN_UNIT (tree_node
);
21874 else if (TYPE_P (tree_node
))
21876 if (!TYPE_USER_ALIGN (tree_node
))
21879 align
= TYPE_ALIGN_UNIT (tree_node
);
21882 gcc_unreachable ();
21884 add_AT_unsigned (die
, DW_AT_alignment
, align
);
21887 /* For a FIELD_DECL node which represents a bit-field, output an attribute
21888 which specifies the distance in bits from the highest order bit of the
21889 "containing object" for the bit-field to the highest order bit of the
21892 For any given bit-field, the "containing object" is a hypothetical object
21893 (of some integral or enum type) within which the given bit-field lives. The
21894 type of this hypothetical "containing object" is always the same as the
21895 declared type of the individual bit-field itself. The determination of the
21896 exact location of the "containing object" for a bit-field is rather
21897 complicated. It's handled by the `field_byte_offset' function (above).
21899 Note that it is the size (in bytes) of the hypothetical "containing object"
21900 which will be given in the DW_AT_byte_size attribute for this bit-field.
21901 (See `byte_size_attribute' above). */
21904 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
21906 HOST_WIDE_INT object_offset_in_bytes
;
21907 tree original_type
= DECL_BIT_FIELD_TYPE (decl
);
21908 HOST_WIDE_INT bitpos_int
;
21909 HOST_WIDE_INT highest_order_object_bit_offset
;
21910 HOST_WIDE_INT highest_order_field_bit_offset
;
21911 HOST_WIDE_INT bit_offset
;
21913 /* The containing object is within the DECL_CONTEXT. */
21914 struct vlr_context ctx
= { DECL_CONTEXT (decl
), NULL_TREE
};
21916 field_byte_offset (decl
, &ctx
, &object_offset_in_bytes
);
21918 /* Must be a field and a bit field. */
21919 gcc_assert (original_type
&& TREE_CODE (decl
) == FIELD_DECL
);
21921 /* We can't yet handle bit-fields whose offsets are variable, so if we
21922 encounter such things, just return without generating any attribute
21923 whatsoever. Likewise for variable or too large size. */
21924 if (! tree_fits_shwi_p (bit_position (decl
))
21925 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
21928 bitpos_int
= int_bit_position (decl
);
21930 /* Note that the bit offset is always the distance (in bits) from the
21931 highest-order bit of the "containing object" to the highest-order bit of
21932 the bit-field itself. Since the "high-order end" of any object or field
21933 is different on big-endian and little-endian machines, the computation
21934 below must take account of these differences. */
21935 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
21936 highest_order_field_bit_offset
= bitpos_int
;
21938 if (! BYTES_BIG_ENDIAN
)
21940 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
21941 highest_order_object_bit_offset
+=
21942 simple_type_size_in_bits (original_type
);
21946 = (! BYTES_BIG_ENDIAN
21947 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
21948 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
21950 if (bit_offset
< 0)
21951 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
21953 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
21956 /* For a FIELD_DECL node which represents a bit field, output an attribute
21957 which specifies the length in bits of the given field. */
21960 add_bit_size_attribute (dw_die_ref die
, tree decl
)
21962 /* Must be a field and a bit field. */
21963 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
21964 && DECL_BIT_FIELD_TYPE (decl
));
21966 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
21967 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
21970 /* If the compiled language is ANSI C, then add a 'prototyped'
21971 attribute, if arg types are given for the parameters of a function. */
21974 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
21976 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
21983 if (prototype_p (func_type
))
21984 add_AT_flag (die
, DW_AT_prototyped
, 1);
21991 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
21992 by looking in the type declaration, the object declaration equate table or
21993 the block mapping. */
21996 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
21998 dw_die_ref origin_die
= NULL
;
22000 /* For late LTO debug output we want to refer directly to the abstract
22001 DIE in the early debug rather to the possibly existing concrete
22002 instance and avoid creating that just for this purpose. */
22003 sym_off_pair
*desc
;
22005 && external_die_map
22006 && (desc
= external_die_map
->get (origin
)))
22008 add_AT_external_die_ref (die
, DW_AT_abstract_origin
,
22009 desc
->sym
, desc
->off
);
22013 if (DECL_P (origin
))
22014 origin_die
= lookup_decl_die (origin
);
22015 else if (TYPE_P (origin
))
22016 origin_die
= lookup_type_die (origin
);
22017 else if (TREE_CODE (origin
) == BLOCK
)
22018 origin_die
= lookup_block_die (origin
);
22020 /* XXX: Functions that are never lowered don't always have correct block
22021 trees (in the case of java, they simply have no block tree, in some other
22022 languages). For these functions, there is nothing we can really do to
22023 output correct debug info for inlined functions in all cases. Rather
22024 than die, we'll just produce deficient debug info now, in that we will
22025 have variables without a proper abstract origin. In the future, when all
22026 functions are lowered, we should re-add a gcc_assert (origin_die)
22032 /* Like above, if we already created a concrete instance DIE
22033 do not use that for the abstract origin but the early DIE
22036 && (a
= get_AT (origin_die
, DW_AT_abstract_origin
)))
22037 origin_die
= AT_ref (a
);
22038 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
22042 /* We do not currently support the pure_virtual attribute. */
22045 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
22047 if (DECL_VINDEX (func_decl
))
22049 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
22051 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
22052 add_AT_loc (die
, DW_AT_vtable_elem_location
,
22053 new_loc_descr (DW_OP_constu
,
22054 tree_to_shwi (DECL_VINDEX (func_decl
)),
22057 /* GNU extension: Record what type this method came from originally. */
22058 if (debug_info_level
> DINFO_LEVEL_TERSE
22059 && DECL_CONTEXT (func_decl
))
22060 add_AT_die_ref (die
, DW_AT_containing_type
,
22061 lookup_type_die (DECL_CONTEXT (func_decl
)));
22065 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
22066 given decl. This used to be a vendor extension until after DWARF 4
22067 standardized it. */
22070 add_linkage_attr (dw_die_ref die
, tree decl
)
22072 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
22074 /* Mimic what assemble_name_raw does with a leading '*'. */
22075 if (name
[0] == '*')
22078 if (dwarf_version
>= 4)
22079 add_AT_string (die
, DW_AT_linkage_name
, name
);
22081 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
22084 /* Add source coordinate attributes for the given decl. */
22087 add_src_coords_attributes (dw_die_ref die
, tree decl
)
22089 expanded_location s
;
22091 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
22093 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
22094 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
22095 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
22096 if (debug_column_info
&& s
.column
)
22097 add_AT_unsigned (die
, DW_AT_decl_column
, s
.column
);
22100 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
22103 add_linkage_name_raw (dw_die_ref die
, tree decl
)
22105 /* Defer until we have an assembler name set. */
22106 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
22108 limbo_die_node
*asm_name
;
22110 asm_name
= ggc_cleared_alloc
<limbo_die_node
> ();
22111 asm_name
->die
= die
;
22112 asm_name
->created_for
= decl
;
22113 asm_name
->next
= deferred_asm_name
;
22114 deferred_asm_name
= asm_name
;
22116 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
22117 add_linkage_attr (die
, decl
);
22120 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl if desired. */
22123 add_linkage_name (dw_die_ref die
, tree decl
)
22125 if (debug_info_level
> DINFO_LEVEL_NONE
22126 && VAR_OR_FUNCTION_DECL_P (decl
)
22127 && TREE_PUBLIC (decl
)
22128 && !(VAR_P (decl
) && DECL_REGISTER (decl
))
22129 && die
->die_tag
!= DW_TAG_member
)
22130 add_linkage_name_raw (die
, decl
);
22133 /* Add a DW_AT_name attribute and source coordinate attribute for the
22134 given decl, but only if it actually has a name. */
22137 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
,
22138 bool no_linkage_name
)
22142 decl_name
= DECL_NAME (decl
);
22143 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
22145 const char *name
= dwarf2_name (decl
, 0);
22147 add_name_attribute (die
, name
);
22149 add_desc_attribute (die
, decl
);
22151 if (! DECL_ARTIFICIAL (decl
))
22152 add_src_coords_attributes (die
, decl
);
22154 if (!no_linkage_name
)
22155 add_linkage_name (die
, decl
);
22158 add_desc_attribute (die
, decl
);
22160 #ifdef VMS_DEBUGGING_INFO
22161 /* Get the function's name, as described by its RTL. This may be different
22162 from the DECL_NAME name used in the source file. */
22163 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
22165 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
22166 XEXP (DECL_RTL (decl
), 0), false);
22167 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
22169 #endif /* VMS_DEBUGGING_INFO */
22172 /* Add VALUE as a DW_AT_discr_value attribute to DIE. */
22175 add_discr_value (dw_die_ref die
, dw_discr_value
*value
)
22179 attr
.dw_attr
= DW_AT_discr_value
;
22180 attr
.dw_attr_val
.val_class
= dw_val_class_discr_value
;
22181 attr
.dw_attr_val
.val_entry
= NULL
;
22182 attr
.dw_attr_val
.v
.val_discr_value
.pos
= value
->pos
;
22184 attr
.dw_attr_val
.v
.val_discr_value
.v
.uval
= value
->v
.uval
;
22186 attr
.dw_attr_val
.v
.val_discr_value
.v
.sval
= value
->v
.sval
;
22187 add_dwarf_attr (die
, &attr
);
22190 /* Add DISCR_LIST as a DW_AT_discr_list to DIE. */
22193 add_discr_list (dw_die_ref die
, dw_discr_list_ref discr_list
)
22197 attr
.dw_attr
= DW_AT_discr_list
;
22198 attr
.dw_attr_val
.val_class
= dw_val_class_discr_list
;
22199 attr
.dw_attr_val
.val_entry
= NULL
;
22200 attr
.dw_attr_val
.v
.val_discr_list
= discr_list
;
22201 add_dwarf_attr (die
, &attr
);
22204 static inline dw_discr_list_ref
22205 AT_discr_list (dw_attr_node
*attr
)
22207 return attr
->dw_attr_val
.v
.val_discr_list
;
22210 #ifdef VMS_DEBUGGING_INFO
22211 /* Output the debug main pointer die for VMS */
22214 dwarf2out_vms_debug_main_pointer (void)
22216 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
22219 /* Allocate the VMS debug main subprogram die. */
22220 die
= new_die_raw (DW_TAG_subprogram
);
22221 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
22222 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
22223 current_function_funcdef_no
);
22224 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
22226 /* Make it the first child of comp_unit_die (). */
22227 die
->die_parent
= comp_unit_die ();
22228 if (comp_unit_die ()->die_child
)
22230 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
22231 comp_unit_die ()->die_child
->die_sib
= die
;
22235 die
->die_sib
= die
;
22236 comp_unit_die ()->die_child
= die
;
22239 #endif /* VMS_DEBUGGING_INFO */
22241 /* walk_tree helper function for uses_local_type, below. */
22244 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
22247 *walk_subtrees
= 0;
22250 tree name
= TYPE_NAME (*tp
);
22251 if (name
&& DECL_P (name
) && decl_function_context (name
))
22257 /* If TYPE involves a function-local type (including a local typedef to a
22258 non-local type), returns that type; otherwise returns NULL_TREE. */
22261 uses_local_type (tree type
)
22263 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
22267 /* Return the DIE for the scope that immediately contains this type.
22268 Non-named types that do not involve a function-local type get global
22269 scope. Named types nested in namespaces or other types get their
22270 containing scope. All other types (i.e. function-local named types) get
22271 the current active scope. */
22274 scope_die_for (tree t
, dw_die_ref context_die
)
22276 dw_die_ref scope_die
= NULL
;
22277 tree containing_scope
;
22279 /* Non-types always go in the current scope. */
22280 gcc_assert (TYPE_P (t
));
22282 /* Use the scope of the typedef, rather than the scope of the type
22284 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
22285 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
22287 containing_scope
= TYPE_CONTEXT (t
);
22289 /* Use the containing namespace if there is one. */
22290 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
22292 if (context_die
== lookup_decl_die (containing_scope
))
22294 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
22295 context_die
= get_context_die (containing_scope
);
22297 containing_scope
= NULL_TREE
;
22300 /* Ignore function type "scopes" from the C frontend. They mean that
22301 a tagged type is local to a parmlist of a function declarator, but
22302 that isn't useful to DWARF. */
22303 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
22304 containing_scope
= NULL_TREE
;
22306 if (SCOPE_FILE_SCOPE_P (containing_scope
))
22308 /* If T uses a local type keep it local as well, to avoid references
22309 to function-local DIEs from outside the function. */
22310 if (current_function_decl
&& uses_local_type (t
))
22311 scope_die
= context_die
;
22313 scope_die
= comp_unit_die ();
22315 else if (TYPE_P (containing_scope
))
22317 /* For types, we can just look up the appropriate DIE. */
22318 if (debug_info_level
> DINFO_LEVEL_TERSE
)
22319 scope_die
= get_context_die (containing_scope
);
22322 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
22323 if (scope_die
== NULL
)
22324 scope_die
= comp_unit_die ();
22328 scope_die
= context_die
;
22333 /* Returns true if CONTEXT_DIE is internal to a function. */
22336 local_scope_p (dw_die_ref context_die
)
22338 for (; context_die
; context_die
= context_die
->die_parent
)
22339 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
22340 || context_die
->die_tag
== DW_TAG_subprogram
)
22346 /* Returns true if CONTEXT_DIE is a class. */
22349 class_scope_p (dw_die_ref context_die
)
22351 return (context_die
22352 && (context_die
->die_tag
== DW_TAG_structure_type
22353 || context_die
->die_tag
== DW_TAG_class_type
22354 || context_die
->die_tag
== DW_TAG_interface_type
22355 || context_die
->die_tag
== DW_TAG_union_type
));
22358 /* Returns true if CONTEXT_DIE is a class or namespace, for deciding
22359 whether or not to treat a DIE in this context as a declaration. */
22362 class_or_namespace_scope_p (dw_die_ref context_die
)
22364 return (class_scope_p (context_die
)
22365 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
22368 /* Many forms of DIEs require a "type description" attribute. This
22369 routine locates the proper "type descriptor" die for the type given
22370 by 'type' plus any additional qualifiers given by 'cv_quals', and
22371 adds a DW_AT_type attribute below the given die. */
22374 add_type_attribute (dw_die_ref object_die
, tree type
, int cv_quals
,
22375 bool reverse
, dw_die_ref context_die
)
22377 enum tree_code code
= TREE_CODE (type
);
22378 dw_die_ref type_die
= NULL
;
22380 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
22383 /* ??? If this type is an unnamed subrange type of an integral, floating-point
22384 or fixed-point type, use the inner type. This is because we have no
22385 support for unnamed types in base_type_die. This can happen if this is
22386 an Ada subrange type. Correct solution is emit a subrange type die. */
22387 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
22388 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
22389 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
22391 if (code
== ERROR_MARK
22392 /* Handle a special case. For functions whose return type is void, we
22393 generate *no* type attribute. (Note that no object may have type
22394 `void', so this only applies to function return types). */
22395 || code
== VOID_TYPE
)
22398 type_die
= modified_type_die (type
,
22399 cv_quals
| TYPE_QUALS (type
),
22403 if (type_die
!= NULL
)
22404 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
22407 /* Given an object die, add the calling convention attribute for the
22408 function call type. */
22410 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
22412 enum dwarf_calling_convention value
= DW_CC_normal
;
22414 value
= ((enum dwarf_calling_convention
)
22415 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
22418 && id_equal (DECL_ASSEMBLER_NAME (decl
), "MAIN__"))
22420 /* DWARF 2 doesn't provide a way to identify a program's source-level
22421 entry point. DW_AT_calling_convention attributes are only meant
22422 to describe functions' calling conventions. However, lacking a
22423 better way to signal the Fortran main program, we used this for
22424 a long time, following existing custom. Now, DWARF 4 has
22425 DW_AT_main_subprogram, which we add below, but some tools still
22426 rely on the old way, which we thus keep. */
22427 value
= DW_CC_program
;
22429 if (dwarf_version
>= 4 || !dwarf_strict
)
22430 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
22433 /* Only add the attribute if the backend requests it, and
22434 is not DW_CC_normal. */
22435 if (value
&& (value
!= DW_CC_normal
))
22436 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
22439 /* Given a tree pointer to a struct, class, union, or enum type node, return
22440 a pointer to the (string) tag name for the given type, or zero if the type
22441 was declared without a tag. */
22443 static const char *
22444 type_tag (const_tree type
)
22446 const char *name
= 0;
22448 if (TYPE_NAME (type
) != 0)
22452 /* Find the IDENTIFIER_NODE for the type name. */
22453 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
22454 && !TYPE_NAMELESS (type
))
22455 t
= TYPE_NAME (type
);
22457 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
22458 a TYPE_DECL node, regardless of whether or not a `typedef' was
22460 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
22461 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
22463 /* We want to be extra verbose. Don't call dwarf_name if
22464 DECL_NAME isn't set. The default hook for decl_printable_name
22465 doesn't like that, and in this context it's correct to return
22466 0, instead of "<anonymous>" or the like. */
22467 if (DECL_NAME (TYPE_NAME (type
))
22468 && !DECL_NAMELESS (TYPE_NAME (type
)))
22469 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
22472 /* Now get the name as a string, or invent one. */
22473 if (!name
&& t
!= 0)
22474 name
= IDENTIFIER_POINTER (t
);
22477 return (name
== 0 || *name
== '\0') ? 0 : name
;
22480 /* Return the type associated with a data member, make a special check
22481 for bit field types. */
22484 member_declared_type (const_tree member
)
22486 return (DECL_BIT_FIELD_TYPE (member
)
22487 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
22490 /* Get the decl's label, as described by its RTL. This may be different
22491 from the DECL_NAME name used in the source file. */
22494 static const char *
22495 decl_start_label (tree decl
)
22498 const char *fnname
;
22500 x
= DECL_RTL (decl
);
22501 gcc_assert (MEM_P (x
));
22504 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
22506 fnname
= XSTR (x
, 0);
22511 /* For variable-length arrays that have been previously generated, but
22512 may be incomplete due to missing subscript info, fill the subscript
22513 info. Return TRUE if this is one of those cases. */
22516 fill_variable_array_bounds (tree type
)
22518 if (TREE_ASM_WRITTEN (type
)
22519 && TREE_CODE (type
) == ARRAY_TYPE
22520 && variably_modified_type_p (type
, NULL
))
22522 dw_die_ref array_die
= lookup_type_die (type
);
22525 add_subscript_info (array_die
, type
, !is_ada ());
22531 /* These routines generate the internal representation of the DIE's for
22532 the compilation unit. Debugging information is collected by walking
22533 the declaration trees passed in from dwarf2out_decl(). */
22536 gen_array_type_die (tree type
, dw_die_ref context_die
)
22538 dw_die_ref array_die
;
22540 /* GNU compilers represent multidimensional array types as sequences of one
22541 dimensional array types whose element types are themselves array types.
22542 We sometimes squish that down to a single array_type DIE with multiple
22543 subscripts in the Dwarf debugging info. The draft Dwarf specification
22544 say that we are allowed to do this kind of compression in C, because
22545 there is no difference between an array of arrays and a multidimensional
22546 array. We don't do this for Ada to remain as close as possible to the
22547 actual representation, which is especially important against the language
22548 flexibilty wrt arrays of variable size. */
22550 bool collapse_nested_arrays
= !is_ada ();
22552 if (fill_variable_array_bounds (type
))
22555 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
22558 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
22559 DW_TAG_string_type doesn't have DW_AT_type attribute). */
22560 if (TREE_CODE (type
) == ARRAY_TYPE
22561 && TYPE_STRING_FLAG (type
)
22563 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
22565 HOST_WIDE_INT size
;
22567 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
22568 add_name_attribute (array_die
, type_tag (type
));
22569 equate_type_number_to_die (type
, array_die
);
22570 size
= int_size_in_bytes (type
);
22572 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
22573 /* ??? We can't annotate types late, but for LTO we may not
22574 generate a location early either (gfortran.dg/save_6.f90). */
22575 else if (! (early_dwarf
&& (flag_generate_lto
|| flag_generate_offload
))
22576 && TYPE_DOMAIN (type
) != NULL_TREE
22577 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
)
22579 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
22580 tree rszdecl
= szdecl
;
22582 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
22583 if (!DECL_P (szdecl
))
22585 if (INDIRECT_REF_P (szdecl
)
22586 && DECL_P (TREE_OPERAND (szdecl
, 0)))
22588 rszdecl
= TREE_OPERAND (szdecl
, 0);
22589 if (int_size_in_bytes (TREE_TYPE (rszdecl
))
22590 != DWARF2_ADDR_SIZE
)
22598 dw_loc_list_ref loc
22599 = loc_list_from_tree (rszdecl
, szdecl
== rszdecl
? 2 : 0,
22603 add_AT_location_description (array_die
, DW_AT_string_length
,
22605 if (size
!= DWARF2_ADDR_SIZE
)
22606 add_AT_unsigned (array_die
, dwarf_version
>= 5
22607 ? DW_AT_string_length_byte_size
22608 : DW_AT_byte_size
, size
);
22615 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
22616 add_name_attribute (array_die
, type_tag (type
));
22617 equate_type_number_to_die (type
, array_die
);
22619 if (VECTOR_TYPE_P (type
))
22620 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
22622 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
22624 && TREE_CODE (type
) == ARRAY_TYPE
22625 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
22626 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
22627 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
22630 /* We default the array ordering. Debuggers will probably do the right
22631 things even if DW_AT_ordering is not present. It's not even an issue
22632 until we start to get into multidimensional arrays anyway. If a debugger
22633 is ever caught doing the Wrong Thing for multi-dimensional arrays,
22634 then we'll have to put the DW_AT_ordering attribute back in. (But if
22635 and when we find out that we need to put these in, we will only do so
22636 for multidimensional arrays. */
22637 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
22640 if (VECTOR_TYPE_P (type
))
22642 /* For VECTOR_TYPEs we use an array DIE with appropriate bounds. */
22643 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
22644 int lb
= lower_bound_default ();
22647 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_int (lb
), NULL
);
22648 add_bound_info (subrange_die
, DW_AT_upper_bound
,
22649 size_int (lb
+ TYPE_VECTOR_SUBPARTS (type
) - 1), NULL
);
22652 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
22654 /* Add representation of the type of the elements of this array type and
22655 emit the corresponding DIE if we haven't done it already. */
22656 element_type
= TREE_TYPE (type
);
22657 if (collapse_nested_arrays
)
22658 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
22660 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
22662 element_type
= TREE_TYPE (element_type
);
22665 add_type_attribute (array_die
, element_type
, TYPE_UNQUALIFIED
,
22666 TREE_CODE (type
) == ARRAY_TYPE
22667 && TYPE_REVERSE_STORAGE_ORDER (type
),
22670 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
22671 if (TYPE_ARTIFICIAL (type
))
22672 add_AT_flag (array_die
, DW_AT_artificial
, 1);
22674 if (get_AT (array_die
, DW_AT_name
))
22675 add_pubtype (type
, array_die
);
22677 add_alignment_attribute (array_die
, type
);
22680 /* This routine generates DIE for array with hidden descriptor, details
22681 are filled into *info by a langhook. */
22684 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
22685 dw_die_ref context_die
)
22687 const dw_die_ref scope_die
= scope_die_for (type
, context_die
);
22688 const dw_die_ref array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
22689 struct loc_descr_context context
= {
22690 type
, /* context_type */
22691 info
->base_decl
, /* base_decl */
22693 false, /* placeholder_arg */
22694 false, /* placeholder_seen */
22695 false /* strict_signedness */
22697 enum dwarf_tag subrange_tag
= DW_TAG_subrange_type
;
22700 add_name_attribute (array_die
, type_tag (type
));
22701 equate_type_number_to_die (type
, array_die
);
22703 if (info
->ndimensions
> 1)
22704 switch (info
->ordering
)
22706 case array_descr_ordering_row_major
:
22707 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
22709 case array_descr_ordering_column_major
:
22710 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
22716 if (dwarf_version
>= 3 || !dwarf_strict
)
22718 if (info
->data_location
)
22719 add_scalar_info (array_die
, DW_AT_data_location
, info
->data_location
,
22720 dw_scalar_form_exprloc
, &context
);
22721 if (info
->associated
)
22722 add_scalar_info (array_die
, DW_AT_associated
, info
->associated
,
22723 dw_scalar_form_constant
22724 | dw_scalar_form_exprloc
22725 | dw_scalar_form_reference
, &context
);
22726 if (info
->allocated
)
22727 add_scalar_info (array_die
, DW_AT_allocated
, info
->allocated
,
22728 dw_scalar_form_constant
22729 | dw_scalar_form_exprloc
22730 | dw_scalar_form_reference
, &context
);
22733 const enum dwarf_attribute attr
22734 = (info
->stride_in_bits
) ? DW_AT_bit_stride
: DW_AT_byte_stride
;
22736 = (info
->stride_in_bits
)
22737 ? dw_scalar_form_constant
22738 : (dw_scalar_form_constant
22739 | dw_scalar_form_exprloc
22740 | dw_scalar_form_reference
);
22742 add_scalar_info (array_die
, attr
, info
->stride
, forms
, &context
);
22745 if (dwarf_version
>= 5)
22749 add_scalar_info (array_die
, DW_AT_rank
, info
->rank
,
22750 dw_scalar_form_constant
22751 | dw_scalar_form_exprloc
, &context
);
22752 subrange_tag
= DW_TAG_generic_subrange
;
22753 context
.placeholder_arg
= true;
22757 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
22759 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
22761 dw_die_ref subrange_die
= new_die (subrange_tag
, array_die
, NULL
);
22763 if (info
->dimen
[dim
].bounds_type
)
22764 add_type_attribute (subrange_die
,
22765 info
->dimen
[dim
].bounds_type
, TYPE_UNQUALIFIED
,
22766 false, context_die
);
22767 if (info
->dimen
[dim
].lower_bound
)
22768 add_bound_info (subrange_die
, DW_AT_lower_bound
,
22769 info
->dimen
[dim
].lower_bound
, &context
);
22770 if (info
->dimen
[dim
].upper_bound
)
22771 add_bound_info (subrange_die
, DW_AT_upper_bound
,
22772 info
->dimen
[dim
].upper_bound
, &context
);
22773 if ((dwarf_version
>= 3 || !dwarf_strict
) && info
->dimen
[dim
].stride
)
22774 add_scalar_info (subrange_die
, DW_AT_byte_stride
,
22775 info
->dimen
[dim
].stride
,
22776 dw_scalar_form_constant
22777 | dw_scalar_form_exprloc
22778 | dw_scalar_form_reference
,
22782 gen_type_die (info
->element_type
, context_die
);
22783 add_type_attribute (array_die
, info
->element_type
, TYPE_UNQUALIFIED
,
22784 TREE_CODE (type
) == ARRAY_TYPE
22785 && TYPE_REVERSE_STORAGE_ORDER (type
),
22788 if (get_AT (array_die
, DW_AT_name
))
22789 add_pubtype (type
, array_die
);
22791 add_alignment_attribute (array_die
, type
);
22796 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
22798 tree origin
= decl_ultimate_origin (decl
);
22799 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
22801 if (origin
!= NULL
)
22802 add_abstract_origin_attribute (decl_die
, origin
);
22805 add_name_and_src_coords_attributes (decl_die
, decl
);
22806 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
22807 TYPE_UNQUALIFIED
, false, context_die
);
22810 if (DECL_ABSTRACT_P (decl
))
22811 equate_decl_number_to_die (decl
, decl_die
);
22813 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
22817 /* Walk through the list of incomplete types again, trying once more to
22818 emit full debugging info for them. */
22821 retry_incomplete_types (void)
22826 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
22827 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
22828 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
22829 vec_safe_truncate (incomplete_types
, 0);
22832 /* Determine what tag to use for a record type. */
22834 static enum dwarf_tag
22835 record_type_tag (tree type
)
22837 if (! lang_hooks
.types
.classify_record
)
22838 return DW_TAG_structure_type
;
22840 switch (lang_hooks
.types
.classify_record (type
))
22842 case RECORD_IS_STRUCT
:
22843 return DW_TAG_structure_type
;
22845 case RECORD_IS_CLASS
:
22846 return DW_TAG_class_type
;
22848 case RECORD_IS_INTERFACE
:
22849 if (dwarf_version
>= 3 || !dwarf_strict
)
22850 return DW_TAG_interface_type
;
22851 return DW_TAG_structure_type
;
22854 gcc_unreachable ();
22858 /* Generate a DIE to represent an enumeration type. Note that these DIEs
22859 include all of the information about the enumeration values also. Each
22860 enumerated type name/value is listed as a child of the enumerated type
22861 DIE. REVERSE is true if the type is to be interpreted in the reverse
22862 storage order wrt the target order. */
22865 gen_enumeration_type_die (tree type
, dw_die_ref context_die
, bool reverse
)
22867 dw_die_ref type_die
= lookup_type_die (type
);
22868 dw_die_ref orig_type_die
= type_die
;
22870 if (type_die
== NULL
|| reverse
)
22872 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
22874 /* The DIE with DW_AT_endianity is placed right after the naked DIE. */
22877 gcc_assert (type_die
);
22878 dw_die_ref after_die
= type_die
;
22879 type_die
= new_die_raw (DW_TAG_enumeration_type
);
22880 add_child_die_after (scope_die
, type_die
, after_die
);
22884 type_die
= new_die (DW_TAG_enumeration_type
, scope_die
, type
);
22885 equate_type_number_to_die (type
, type_die
);
22887 add_name_attribute (type_die
, type_tag (type
));
22888 if ((dwarf_version
>= 4 || !dwarf_strict
)
22889 && ENUM_IS_SCOPED (type
))
22890 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
22891 if (ENUM_IS_OPAQUE (type
) && TYPE_SIZE (type
))
22892 add_AT_flag (type_die
, DW_AT_declaration
, 1);
22894 add_AT_unsigned (type_die
, DW_AT_encoding
,
22895 TYPE_UNSIGNED (type
)
22899 add_AT_unsigned (type_die
, DW_AT_endianity
,
22900 BYTES_BIG_ENDIAN
? DW_END_little
: DW_END_big
);
22902 else if (! TYPE_SIZE (type
) || ENUM_IS_OPAQUE (type
))
22905 remove_AT (type_die
, DW_AT_declaration
);
22907 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
22908 given enum type is incomplete, do not generate the DW_AT_byte_size
22909 attribute or the DW_AT_element_list attribute. */
22910 if (TYPE_SIZE (type
))
22914 if (!ENUM_IS_OPAQUE (type
))
22915 TREE_ASM_WRITTEN (type
) = 1;
22916 if (!orig_type_die
|| !get_AT (type_die
, DW_AT_byte_size
))
22917 add_byte_size_attribute (type_die
, type
);
22918 if (!orig_type_die
|| !get_AT (type_die
, DW_AT_alignment
))
22919 add_alignment_attribute (type_die
, type
);
22920 if ((dwarf_version
>= 3 || !dwarf_strict
)
22921 && (!orig_type_die
|| !get_AT (type_die
, DW_AT_type
)))
22923 tree underlying
= lang_hooks
.types
.enum_underlying_base_type (type
);
22924 add_type_attribute (type_die
, underlying
, TYPE_UNQUALIFIED
, false,
22927 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
22929 if (!orig_type_die
|| !get_AT (type_die
, DW_AT_decl_file
))
22930 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
22931 if (!orig_type_die
|| !get_AT (type_die
, DW_AT_accessibility
))
22932 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
22935 /* If the first reference to this type was as the return type of an
22936 inline function, then it may not have a parent. Fix this now. */
22937 if (type_die
->die_parent
== NULL
)
22938 add_child_die (scope_die_for (type
, context_die
), type_die
);
22940 for (link
= TYPE_VALUES (type
);
22941 link
!= NULL
; link
= TREE_CHAIN (link
))
22943 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
22944 tree value
= TREE_VALUE (link
);
22946 if (DECL_P (value
))
22947 equate_decl_number_to_die (value
, enum_die
);
22949 gcc_assert (!ENUM_IS_OPAQUE (type
));
22950 add_name_attribute (enum_die
,
22951 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
22953 if (TREE_CODE (value
) == CONST_DECL
)
22954 value
= DECL_INITIAL (value
);
22956 if (simple_type_size_in_bits (TREE_TYPE (value
))
22957 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
22959 /* For constant forms created by add_AT_unsigned DWARF
22960 consumers (GDB, elfutils, etc.) always zero extend
22961 the value. Only when the actual value is negative
22962 do we need to use add_AT_int to generate a constant
22963 form that can represent negative values. */
22964 HOST_WIDE_INT val
= TREE_INT_CST_LOW (value
);
22965 if (TYPE_UNSIGNED (TREE_TYPE (value
)) || val
>= 0)
22966 add_AT_unsigned (enum_die
, DW_AT_const_value
,
22967 (unsigned HOST_WIDE_INT
) val
);
22969 add_AT_int (enum_die
, DW_AT_const_value
, val
);
22972 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
22973 that here. TODO: This should be re-worked to use correct
22974 signed/unsigned double tags for all cases. */
22975 add_AT_wide (enum_die
, DW_AT_const_value
, wi::to_wide (value
));
22978 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
22979 if (TYPE_ARTIFICIAL (type
)
22980 && (!orig_type_die
|| !get_AT (type_die
, DW_AT_artificial
)))
22981 add_AT_flag (type_die
, DW_AT_artificial
, 1);
22984 add_AT_flag (type_die
, DW_AT_declaration
, 1);
22986 add_pubtype (type
, type_die
);
22991 /* Generate a DIE to represent either a real live formal parameter decl or to
22992 represent just the type of some formal parameter position in some function
22995 Note that this routine is a bit unusual because its argument may be a
22996 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
22997 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
22998 node. If it's the former then this function is being called to output a
22999 DIE to represent a formal parameter object (or some inlining thereof). If
23000 it's the latter, then this function is only being called to output a
23001 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
23002 argument type of some subprogram type.
23003 If EMIT_NAME_P is true, name and source coordinate attributes
23007 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
23008 dw_die_ref context_die
)
23010 tree node_or_origin
= node
? node
: origin
;
23011 tree ultimate_origin
;
23012 dw_die_ref parm_die
= NULL
;
23014 if (DECL_P (node_or_origin
))
23016 parm_die
= lookup_decl_die (node
);
23018 /* If the contexts differ, we may not be talking about the same
23020 ??? When in LTO the DIE parent is the "abstract" copy and the
23021 context_die is the specification "copy". */
23023 && parm_die
->die_parent
!= context_die
23024 && (parm_die
->die_parent
->die_tag
!= DW_TAG_GNU_formal_parameter_pack
23025 || parm_die
->die_parent
->die_parent
!= context_die
)
23028 gcc_assert (!DECL_ABSTRACT_P (node
));
23029 /* This can happen when creating a concrete instance, in
23030 which case we need to create a new DIE that will get
23031 annotated with DW_AT_abstract_origin. */
23035 if (parm_die
&& parm_die
->die_parent
== NULL
)
23037 /* Check that parm_die already has the right attributes that
23038 we would have added below. If any attributes are
23039 missing, fall through to add them. */
23040 if (! DECL_ABSTRACT_P (node_or_origin
)
23041 && !get_AT (parm_die
, DW_AT_location
)
23042 && !get_AT (parm_die
, DW_AT_const_value
))
23043 /* We are missing location info, and are about to add it. */
23047 add_child_die (context_die
, parm_die
);
23053 /* If we have a previously generated DIE, use it, unless this is an
23054 concrete instance (origin != NULL), in which case we need a new
23055 DIE with a corresponding DW_AT_abstract_origin. */
23057 if (parm_die
&& origin
== NULL
)
23058 reusing_die
= true;
23061 parm_die
= new_die (DW_TAG_formal_parameter
, context_die
, node
);
23062 reusing_die
= false;
23065 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
23067 case tcc_declaration
:
23068 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
23069 if (node
|| ultimate_origin
)
23070 origin
= ultimate_origin
;
23075 if (origin
!= NULL
)
23076 add_abstract_origin_attribute (parm_die
, origin
);
23077 else if (emit_name_p
)
23078 add_name_and_src_coords_attributes (parm_die
, node
);
23080 || (! DECL_ABSTRACT_P (node_or_origin
)
23081 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
23082 decl_function_context
23083 (node_or_origin
))))
23085 tree type
= TREE_TYPE (node_or_origin
);
23086 if (decl_by_reference_p (node_or_origin
))
23087 add_type_attribute (parm_die
, TREE_TYPE (type
),
23089 false, context_die
);
23091 add_type_attribute (parm_die
, type
,
23092 decl_quals (node_or_origin
),
23093 false, context_die
);
23095 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
23096 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
23098 if (node
&& node
!= origin
)
23099 equate_decl_number_to_die (node
, parm_die
);
23100 if (! DECL_ABSTRACT_P (node_or_origin
))
23101 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
23107 /* We were called with some kind of a ..._TYPE node. */
23108 add_type_attribute (parm_die
, node_or_origin
, TYPE_UNQUALIFIED
, false,
23113 gcc_unreachable ();
23119 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
23120 children DW_TAG_formal_parameter DIEs representing the arguments of the
23123 PARM_PACK must be a function parameter pack.
23124 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
23125 must point to the subsequent arguments of the function PACK_ARG belongs to.
23126 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
23127 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
23128 following the last one for which a DIE was generated. */
23131 gen_formal_parameter_pack_die (tree parm_pack
,
23133 dw_die_ref subr_die
,
23137 dw_die_ref parm_pack_die
;
23139 gcc_assert (parm_pack
23140 && lang_hooks
.function_parameter_pack_p (parm_pack
)
23143 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
23144 add_src_coords_attributes (parm_pack_die
, parm_pack
);
23146 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
23148 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
23151 gen_formal_parameter_die (arg
, NULL
,
23152 false /* Don't emit name attribute. */,
23157 return parm_pack_die
;
23160 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
23161 at the end of an (ANSI prototyped) formal parameters list. */
23164 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
23166 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
23169 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
23170 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
23171 parameters as specified in some function type specification (except for
23172 those which appear as part of a function *definition*). */
23175 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
23178 tree formal_type
= NULL
;
23179 tree first_parm_type
;
23182 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
23184 arg
= DECL_ARGUMENTS (function_or_method_type
);
23185 function_or_method_type
= TREE_TYPE (function_or_method_type
);
23190 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
23192 /* Make our first pass over the list of formal parameter types and output a
23193 DW_TAG_formal_parameter DIE for each one. */
23194 for (link
= first_parm_type
; link
; )
23196 dw_die_ref parm_die
;
23198 formal_type
= TREE_VALUE (link
);
23199 if (formal_type
== void_type_node
)
23202 /* Output a (nameless) DIE to represent the formal parameter itself. */
23203 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
23204 true /* Emit name attribute. */,
23206 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
23207 && link
== first_parm_type
)
23209 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
23210 if (dwarf_version
>= 3 || !dwarf_strict
)
23211 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
23213 else if (arg
&& DECL_ARTIFICIAL (arg
))
23214 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
23216 link
= TREE_CHAIN (link
);
23218 arg
= DECL_CHAIN (arg
);
23221 /* If this function type has an ellipsis, add a
23222 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
23223 if (formal_type
!= void_type_node
)
23224 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
23226 /* Make our second (and final) pass over the list of formal parameter types
23227 and output DIEs to represent those types (as necessary). */
23228 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
23229 link
&& TREE_VALUE (link
);
23230 link
= TREE_CHAIN (link
))
23231 gen_type_die (TREE_VALUE (link
), context_die
);
23234 /* We want to generate the DIE for TYPE so that we can generate the
23235 die for MEMBER, which has been defined; we will need to refer back
23236 to the member declaration nested within TYPE. If we're trying to
23237 generate minimal debug info for TYPE, processing TYPE won't do the
23238 trick; we need to attach the member declaration by hand. */
23241 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
23243 gen_type_die (type
, context_die
);
23245 /* If we're trying to avoid duplicate debug info, we may not have
23246 emitted the member decl for this function. Emit it now. */
23247 if (TYPE_STUB_DECL (type
)
23248 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
23249 && ! lookup_decl_die (member
))
23251 dw_die_ref type_die
;
23252 gcc_assert (!decl_ultimate_origin (member
));
23254 type_die
= lookup_type_die_strip_naming_typedef (type
);
23255 if (TREE_CODE (member
) == FUNCTION_DECL
)
23256 gen_subprogram_die (member
, type_die
);
23257 else if (TREE_CODE (member
) == FIELD_DECL
)
23259 /* Ignore the nameless fields that are used to skip bits but handle
23260 C++ anonymous unions and structs. */
23261 if (DECL_NAME (member
) != NULL_TREE
23262 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
23263 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
23265 struct vlr_context vlr_ctx
= {
23266 DECL_CONTEXT (member
), /* struct_type */
23267 NULL_TREE
/* variant_part_offset */
23269 gen_type_die (member_declared_type (member
), type_die
);
23270 gen_field_die (member
, &vlr_ctx
, type_die
);
23274 gen_variable_die (member
, NULL_TREE
, type_die
);
23278 /* Forward declare these functions, because they are mutually recursive
23279 with their set_block_* pairing functions. */
23280 static void set_decl_origin_self (tree
);
23282 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
23283 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
23284 that it points to the node itself, thus indicating that the node is its
23285 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
23286 the given node is NULL, recursively descend the decl/block tree which
23287 it is the root of, and for each other ..._DECL or BLOCK node contained
23288 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
23289 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
23290 values to point to themselves. */
23293 set_block_origin_self (tree stmt
)
23295 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
23297 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
23302 for (local_decl
= BLOCK_VARS (stmt
);
23303 local_decl
!= NULL_TREE
;
23304 local_decl
= DECL_CHAIN (local_decl
))
23305 /* Do not recurse on nested functions since the inlining status
23306 of parent and child can be different as per the DWARF spec. */
23307 if (TREE_CODE (local_decl
) != FUNCTION_DECL
23308 && !DECL_EXTERNAL (local_decl
))
23309 set_decl_origin_self (local_decl
);
23315 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
23316 subblock
!= NULL_TREE
;
23317 subblock
= BLOCK_CHAIN (subblock
))
23318 set_block_origin_self (subblock
); /* Recurse. */
23323 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
23324 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
23325 node to so that it points to the node itself, thus indicating that the
23326 node represents its own (abstract) origin. Additionally, if the
23327 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
23328 the decl/block tree of which the given node is the root of, and for
23329 each other ..._DECL or BLOCK node contained therein whose
23330 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
23331 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
23332 point to themselves. */
23335 set_decl_origin_self (tree decl
)
23337 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
23339 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
23340 if (TREE_CODE (decl
) == FUNCTION_DECL
)
23344 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
23345 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
23346 if (DECL_INITIAL (decl
) != NULL_TREE
23347 && DECL_INITIAL (decl
) != error_mark_node
)
23348 set_block_origin_self (DECL_INITIAL (decl
));
23353 /* Mark the early DIE for DECL as the abstract instance. */
23356 dwarf2out_abstract_function (tree decl
)
23358 dw_die_ref old_die
;
23360 /* Make sure we have the actual abstract inline, not a clone. */
23361 decl
= DECL_ORIGIN (decl
);
23363 if (DECL_IGNORED_P (decl
))
23366 /* In LTO we're all set. We already created abstract instances
23367 early and we want to avoid creating a concrete instance of that
23368 if we don't output it. */
23372 old_die
= lookup_decl_die (decl
);
23373 gcc_assert (old_die
!= NULL
);
23374 if (get_AT (old_die
, DW_AT_inline
))
23375 /* We've already generated the abstract instance. */
23378 /* Go ahead and put DW_AT_inline on the DIE. */
23379 if (DECL_DECLARED_INLINE_P (decl
))
23381 if (cgraph_function_possibly_inlined_p (decl
))
23382 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_declared_inlined
);
23384 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
23388 if (cgraph_function_possibly_inlined_p (decl
))
23389 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_inlined
);
23391 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_not_inlined
);
23394 if (DECL_DECLARED_INLINE_P (decl
)
23395 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
23396 add_AT_flag (old_die
, DW_AT_artificial
, 1);
23398 set_decl_origin_self (decl
);
23401 /* Helper function of premark_used_types() which gets called through
23404 Marks the DIE of a given type in *SLOT as perennial, so it never gets
23405 marked as unused by prune_unused_types. */
23408 premark_used_types_helper (tree
const &type
, void *)
23412 die
= lookup_type_die (type
);
23414 die
->die_perennial_p
= 1;
23418 /* Helper function of premark_types_used_by_global_vars which gets called
23419 through htab_traverse.
23421 Marks the DIE of a given type in *SLOT as perennial, so it never gets
23422 marked as unused by prune_unused_types. The DIE of the type is marked
23423 only if the global variable using the type will actually be emitted. */
23426 premark_types_used_by_global_vars_helper (types_used_by_vars_entry
**slot
,
23429 struct types_used_by_vars_entry
*entry
;
23432 entry
= (struct types_used_by_vars_entry
*) *slot
;
23433 gcc_assert (entry
->type
!= NULL
23434 && entry
->var_decl
!= NULL
);
23435 die
= lookup_type_die (entry
->type
);
23438 /* Ask cgraph if the global variable really is to be emitted.
23439 If yes, then we'll keep the DIE of ENTRY->TYPE. */
23440 varpool_node
*node
= varpool_node::get (entry
->var_decl
);
23441 if (node
&& node
->definition
)
23443 die
->die_perennial_p
= 1;
23444 /* Keep the parent DIEs as well. */
23445 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
23446 die
->die_perennial_p
= 1;
23452 /* Mark all members of used_types_hash as perennial. */
23455 premark_used_types (struct function
*fun
)
23457 if (fun
&& fun
->used_types_hash
)
23458 fun
->used_types_hash
->traverse
<void *, premark_used_types_helper
> (NULL
);
23461 /* Mark all members of types_used_by_vars_entry as perennial. */
23464 premark_types_used_by_global_vars (void)
23466 if (types_used_by_vars_hash
)
23467 types_used_by_vars_hash
23468 ->traverse
<void *, premark_types_used_by_global_vars_helper
> (NULL
);
23471 /* Mark all variables used by the symtab as perennial. */
23474 premark_used_variables (void)
23476 /* Mark DIEs in the symtab as used. */
23478 FOR_EACH_VARIABLE (var
)
23480 dw_die_ref die
= lookup_decl_die (var
->decl
);
23482 die
->die_perennial_p
= 1;
23486 /* Generate a DW_TAG_call_site DIE in function DECL under SUBR_DIE
23487 for CA_LOC call arg loc node. */
23490 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
23491 struct call_arg_loc_node
*ca_loc
)
23493 dw_die_ref stmt_die
= NULL
, die
;
23494 tree block
= ca_loc
->block
;
23497 && block
!= DECL_INITIAL (decl
)
23498 && TREE_CODE (block
) == BLOCK
)
23500 stmt_die
= lookup_block_die (block
);
23503 block
= BLOCK_SUPERCONTEXT (block
);
23505 if (stmt_die
== NULL
)
23506 stmt_die
= subr_die
;
23507 die
= new_die (dwarf_TAG (DW_TAG_call_site
), stmt_die
, NULL_TREE
);
23508 add_AT_lbl_id (die
, dwarf_AT (DW_AT_call_return_pc
), ca_loc
->label
);
23509 if (ca_loc
->tail_call_p
)
23510 add_AT_flag (die
, dwarf_AT (DW_AT_call_tail_call
), 1);
23511 if (ca_loc
->symbol_ref
)
23513 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
23515 add_AT_die_ref (die
, dwarf_AT (DW_AT_call_origin
), tdie
);
23517 add_AT_addr (die
, dwarf_AT (DW_AT_call_origin
), ca_loc
->symbol_ref
,
23523 /* Generate a DIE to represent a declared function (either file-scope or
23527 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
23529 tree origin
= decl_ultimate_origin (decl
);
23530 dw_die_ref subr_die
;
23531 dw_die_ref old_die
= lookup_decl_die (decl
);
23532 bool old_die_had_no_children
= false;
23534 /* This function gets called multiple times for different stages of
23535 the debug process. For example, for func() in this code:
23539 void func() { ... }
23542 ...we get called 4 times. Twice in early debug and twice in
23548 1. Once while generating func() within the namespace. This is
23549 the declaration. The declaration bit below is set, as the
23550 context is the namespace.
23552 A new DIE will be generated with DW_AT_declaration set.
23554 2. Once for func() itself. This is the specification. The
23555 declaration bit below is clear as the context is the CU.
23557 We will use the cached DIE from (1) to create a new DIE with
23558 DW_AT_specification pointing to the declaration in (1).
23560 Late debug via rest_of_handle_final()
23561 -------------------------------------
23563 3. Once generating func() within the namespace. This is also the
23564 declaration, as in (1), but this time we will early exit below
23565 as we have a cached DIE and a declaration needs no additional
23566 annotations (no locations), as the source declaration line
23569 4. Once for func() itself. As in (2), this is the specification,
23570 but this time we will re-use the cached DIE, and just annotate
23571 it with the location information that should now be available.
23573 For something without namespaces, but with abstract instances, we
23574 are also called a multiple times:
23579 Base (); // constructor declaration (1)
23582 Base::Base () { } // constructor specification (2)
23587 1. Once for the Base() constructor by virtue of it being a
23588 member of the Base class. This is done via
23589 rest_of_type_compilation.
23591 This is a declaration, so a new DIE will be created with
23594 2. Once for the Base() constructor definition, but this time
23595 while generating the abstract instance of the base
23596 constructor (__base_ctor) which is being generated via early
23597 debug of reachable functions.
23599 Even though we have a cached version of the declaration (1),
23600 we will create a DW_AT_specification of the declaration DIE
23603 3. Once for the __base_ctor itself, but this time, we generate
23604 an DW_AT_abstract_origin version of the DW_AT_specification in
23607 Late debug via rest_of_handle_final
23608 -----------------------------------
23610 4. One final time for the __base_ctor (which will have a cached
23611 DIE with DW_AT_abstract_origin created in (3). This time,
23612 we will just annotate the location information now
23615 int declaration
= (current_function_decl
!= decl
23616 || (!DECL_INITIAL (decl
) && !origin
)
23617 || class_or_namespace_scope_p (context_die
));
23619 /* A declaration that has been previously dumped needs no
23620 additional information. */
23621 if (old_die
&& declaration
)
23624 if (in_lto_p
&& old_die
&& old_die
->die_child
== NULL
)
23625 old_die_had_no_children
= true;
23627 /* Now that the C++ front end lazily declares artificial member fns, we
23628 might need to retrofit the declaration into its class. */
23629 if (!declaration
&& !origin
&& !old_die
23630 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
23631 && !class_or_namespace_scope_p (context_die
)
23632 && debug_info_level
> DINFO_LEVEL_TERSE
)
23633 old_die
= force_decl_die (decl
);
23635 /* A concrete instance, tag a new DIE with DW_AT_abstract_origin. */
23636 if (origin
!= NULL
)
23638 gcc_assert (!declaration
|| local_scope_p (context_die
));
23640 /* Fixup die_parent for the abstract instance of a nested
23641 inline function. */
23642 if (old_die
&& old_die
->die_parent
== NULL
)
23643 add_child_die (context_die
, old_die
);
23645 if (old_die
&& get_AT_ref (old_die
, DW_AT_abstract_origin
))
23647 /* If we have a DW_AT_abstract_origin we have a working
23649 subr_die
= old_die
;
23653 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
23654 add_abstract_origin_attribute (subr_die
, origin
);
23655 /* This is where the actual code for a cloned function is.
23656 Let's emit linkage name attribute for it. This helps
23657 debuggers to e.g, set breakpoints into
23658 constructors/destructors when the user asks "break
23660 add_linkage_name (subr_die
, decl
);
23663 /* A cached copy, possibly from early dwarf generation. Reuse as
23664 much as possible. */
23667 if (!get_AT_flag (old_die
, DW_AT_declaration
)
23668 /* We can have a normal definition following an inline one in the
23669 case of redefinition of GNU C extern inlines.
23670 It seems reasonable to use AT_specification in this case. */
23671 && !get_AT (old_die
, DW_AT_inline
))
23673 /* Detect and ignore this case, where we are trying to output
23674 something we have already output. */
23675 if (get_AT (old_die
, DW_AT_low_pc
)
23676 || get_AT (old_die
, DW_AT_ranges
))
23679 /* If we have no location information, this must be a
23680 partially generated DIE from early dwarf generation.
23681 Fall through and generate it. */
23684 /* If the definition comes from the same place as the declaration,
23685 maybe use the old DIE. We always want the DIE for this function
23686 that has the *_pc attributes to be under comp_unit_die so the
23687 debugger can find it. We also need to do this for abstract
23688 instances of inlines, since the spec requires the out-of-line copy
23689 to have the same parent. For local class methods, this doesn't
23690 apply; we just use the old DIE. */
23691 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
23692 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
23693 if (((is_unit_die (old_die
->die_parent
)
23694 /* This condition fixes the inconsistency/ICE with the
23695 following Fortran test (or some derivative thereof) while
23696 building libgfortran:
23700 logical function funky (FLAG)
23705 || (old_die
->die_parent
23706 && old_die
->die_parent
->die_tag
== DW_TAG_module
)
23707 || local_scope_p (old_die
->die_parent
)
23708 || context_die
== NULL
)
23709 && (DECL_ARTIFICIAL (decl
)
23710 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
23711 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
23712 == (unsigned) s
.line
)
23713 && (!debug_column_info
23715 || (get_AT_unsigned (old_die
, DW_AT_decl_column
)
23716 == (unsigned) s
.column
)))))
23717 /* With LTO if there's an abstract instance for
23718 the old DIE, this is a concrete instance and
23719 thus re-use the DIE. */
23720 || get_AT (old_die
, DW_AT_abstract_origin
))
23722 subr_die
= old_die
;
23724 /* Clear out the declaration attribute, but leave the
23725 parameters so they can be augmented with location
23726 information later. Unless this was a declaration, in
23727 which case, wipe out the nameless parameters and recreate
23728 them further down. */
23729 if (remove_AT (subr_die
, DW_AT_declaration
))
23732 remove_AT (subr_die
, DW_AT_object_pointer
);
23733 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
23736 /* Make a specification pointing to the previously built
23740 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
23741 add_AT_specification (subr_die
, old_die
);
23742 add_pubname (decl
, subr_die
);
23743 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
23744 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
23745 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
23746 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
23747 if (debug_column_info
23749 && (get_AT_unsigned (old_die
, DW_AT_decl_column
)
23750 != (unsigned) s
.column
))
23751 add_AT_unsigned (subr_die
, DW_AT_decl_column
, s
.column
);
23753 /* If the prototype had an 'auto' or 'decltype(auto)' in
23754 the return type, emit the real type on the definition die. */
23755 if (is_cxx () && debug_info_level
> DINFO_LEVEL_TERSE
)
23757 dw_die_ref die
= get_AT_ref (old_die
, DW_AT_type
);
23759 && (die
->die_tag
== DW_TAG_reference_type
23760 || die
->die_tag
== DW_TAG_rvalue_reference_type
23761 || die
->die_tag
== DW_TAG_pointer_type
23762 || die
->die_tag
== DW_TAG_const_type
23763 || die
->die_tag
== DW_TAG_volatile_type
23764 || die
->die_tag
== DW_TAG_restrict_type
23765 || die
->die_tag
== DW_TAG_array_type
23766 || die
->die_tag
== DW_TAG_ptr_to_member_type
23767 || die
->die_tag
== DW_TAG_subroutine_type
))
23768 die
= get_AT_ref (die
, DW_AT_type
);
23769 if (die
== auto_die
|| die
== decltype_auto_die
)
23770 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
23771 TYPE_UNQUALIFIED
, false, context_die
);
23774 /* When we process the method declaration, we haven't seen
23775 the out-of-class defaulted definition yet, so we have to
23777 if ((dwarf_version
>= 5 || ! dwarf_strict
)
23778 && !get_AT (subr_die
, DW_AT_defaulted
))
23781 = lang_hooks
.decls
.decl_dwarf_attribute (decl
,
23783 if (defaulted
!= -1)
23785 /* Other values must have been handled before. */
23786 gcc_assert (defaulted
== DW_DEFAULTED_out_of_class
);
23787 add_AT_unsigned (subr_die
, DW_AT_defaulted
, defaulted
);
23792 /* Create a fresh DIE for anything else. */
23795 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
23797 if (TREE_PUBLIC (decl
))
23798 add_AT_flag (subr_die
, DW_AT_external
, 1);
23800 add_name_and_src_coords_attributes (subr_die
, decl
);
23801 add_pubname (decl
, subr_die
);
23802 if (debug_info_level
> DINFO_LEVEL_TERSE
)
23804 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
23805 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
23806 TYPE_UNQUALIFIED
, false, context_die
);
23809 add_pure_or_virtual_attribute (subr_die
, decl
);
23810 if (DECL_ARTIFICIAL (decl
))
23811 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
23813 if (TREE_THIS_VOLATILE (decl
) && (dwarf_version
>= 5 || !dwarf_strict
))
23814 add_AT_flag (subr_die
, DW_AT_noreturn
, 1);
23816 add_alignment_attribute (subr_die
, decl
);
23818 add_accessibility_attribute (subr_die
, decl
);
23821 /* Unless we have an existing non-declaration DIE, equate the new
23823 if (!old_die
|| is_declaration_die (old_die
))
23824 equate_decl_number_to_die (decl
, subr_die
);
23828 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
23830 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
23832 /* If this is an explicit function declaration then generate
23833 a DW_AT_explicit attribute. */
23834 if ((dwarf_version
>= 3 || !dwarf_strict
)
23835 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
23836 DW_AT_explicit
) == 1)
23837 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
23839 /* If this is a C++11 deleted special function member then generate
23840 a DW_AT_deleted attribute. */
23841 if ((dwarf_version
>= 5 || !dwarf_strict
)
23842 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
23843 DW_AT_deleted
) == 1)
23844 add_AT_flag (subr_die
, DW_AT_deleted
, 1);
23846 /* If this is a C++11 defaulted special function member then
23847 generate a DW_AT_defaulted attribute. */
23848 if (dwarf_version
>= 5 || !dwarf_strict
)
23851 = lang_hooks
.decls
.decl_dwarf_attribute (decl
,
23853 if (defaulted
!= -1)
23854 add_AT_unsigned (subr_die
, DW_AT_defaulted
, defaulted
);
23857 /* If this is a C++11 non-static member function with & ref-qualifier
23858 then generate a DW_AT_reference attribute. */
23859 if ((dwarf_version
>= 5 || !dwarf_strict
)
23860 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
23861 DW_AT_reference
) == 1)
23862 add_AT_flag (subr_die
, DW_AT_reference
, 1);
23864 /* If this is a C++11 non-static member function with &&
23865 ref-qualifier then generate a DW_AT_reference attribute. */
23866 if ((dwarf_version
>= 5 || !dwarf_strict
)
23867 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
23868 DW_AT_rvalue_reference
)
23870 add_AT_flag (subr_die
, DW_AT_rvalue_reference
, 1);
23873 /* For non DECL_EXTERNALs, if range information is available, fill
23874 the DIE with it. */
23875 else if (!DECL_EXTERNAL (decl
) && !early_dwarf
)
23877 HOST_WIDE_INT cfa_fb_offset
;
23879 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
23881 if (!crtl
->has_bb_partition
)
23883 dw_fde_ref fde
= fun
->fde
;
23884 if (fde
->dw_fde_begin
)
23886 /* We have already generated the labels. */
23887 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
23888 fde
->dw_fde_end
, false);
23892 /* Create start/end labels and add the range. */
23893 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
23894 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
23895 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
23896 current_function_funcdef_no
);
23897 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
23898 current_function_funcdef_no
);
23899 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
23903 #if VMS_DEBUGGING_INFO
23904 /* HP OpenVMS Industry Standard 64: DWARF Extensions
23905 Section 2.3 Prologue and Epilogue Attributes:
23906 When a breakpoint is set on entry to a function, it is generally
23907 desirable for execution to be suspended, not on the very first
23908 instruction of the function, but rather at a point after the
23909 function's frame has been set up, after any language defined local
23910 declaration processing has been completed, and before execution of
23911 the first statement of the function begins. Debuggers generally
23912 cannot properly determine where this point is. Similarly for a
23913 breakpoint set on exit from a function. The prologue and epilogue
23914 attributes allow a compiler to communicate the location(s) to use. */
23917 if (fde
->dw_fde_vms_end_prologue
)
23918 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
23919 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
23921 if (fde
->dw_fde_vms_begin_epilogue
)
23922 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
23923 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
23930 /* Generate pubnames entries for the split function code ranges. */
23931 dw_fde_ref fde
= fun
->fde
;
23933 if (fde
->dw_fde_second_begin
)
23935 if (dwarf_version
>= 3 || !dwarf_strict
)
23937 /* We should use ranges for non-contiguous code section
23938 addresses. Use the actual code range for the initial
23939 section, since the HOT/COLD labels might precede an
23940 alignment offset. */
23941 bool range_list_added
= false;
23942 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
23943 fde
->dw_fde_end
, &range_list_added
,
23945 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
23946 fde
->dw_fde_second_end
,
23947 &range_list_added
, false);
23948 if (range_list_added
)
23953 /* There is no real support in DW2 for this .. so we make
23954 a work-around. First, emit the pub name for the segment
23955 containing the function label. Then make and emit a
23956 simplified subprogram DIE for the second segment with the
23957 name pre-fixed by __hot/cold_sect_of_. We use the same
23958 linkage name for the second die so that gdb will find both
23959 sections when given "b foo". */
23960 const char *name
= NULL
;
23961 tree decl_name
= DECL_NAME (decl
);
23962 dw_die_ref seg_die
;
23964 /* Do the 'primary' section. */
23965 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
23966 fde
->dw_fde_end
, false);
23968 /* Build a minimal DIE for the secondary section. */
23969 seg_die
= new_die (DW_TAG_subprogram
,
23970 subr_die
->die_parent
, decl
);
23972 if (TREE_PUBLIC (decl
))
23973 add_AT_flag (seg_die
, DW_AT_external
, 1);
23975 if (decl_name
!= NULL
23976 && IDENTIFIER_POINTER (decl_name
) != NULL
)
23978 name
= dwarf2_name (decl
, 1);
23979 if (! DECL_ARTIFICIAL (decl
))
23980 add_src_coords_attributes (seg_die
, decl
);
23982 add_linkage_name (seg_die
, decl
);
23984 gcc_assert (name
!= NULL
);
23985 add_pure_or_virtual_attribute (seg_die
, decl
);
23986 if (DECL_ARTIFICIAL (decl
))
23987 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
23989 name
= concat ("__second_sect_of_", name
, NULL
);
23990 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
23991 fde
->dw_fde_second_end
, false);
23992 add_name_attribute (seg_die
, name
);
23993 if (want_pubnames ())
23994 add_pubname_string (name
, seg_die
);
23998 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
24002 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
24004 /* We define the "frame base" as the function's CFA. This is more
24005 convenient for several reasons: (1) It's stable across the prologue
24006 and epilogue, which makes it better than just a frame pointer,
24007 (2) With dwarf3, there exists a one-byte encoding that allows us
24008 to reference the .debug_frame data by proxy, but failing that,
24009 (3) We can at least reuse the code inspection and interpretation
24010 code that determines the CFA position at various points in the
24012 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
24014 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
24015 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
24019 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
24020 if (list
->dw_loc_next
)
24021 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
24023 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
24026 /* Compute a displacement from the "steady-state frame pointer" to
24027 the CFA. The former is what all stack slots and argument slots
24028 will reference in the rtl; the latter is what we've told the
24029 debugger about. We'll need to adjust all frame_base references
24030 by this displacement. */
24031 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
24033 if (fun
->static_chain_decl
)
24035 /* DWARF requires here a location expression that computes the
24036 address of the enclosing subprogram's frame base. The machinery
24037 in tree-nested.cc is supposed to store this specific address in the
24038 last field of the FRAME record. */
24039 const tree frame_type
24040 = TREE_TYPE (TREE_TYPE (fun
->static_chain_decl
));
24041 const tree fb_decl
= tree_last (TYPE_FIELDS (frame_type
));
24044 = build1 (INDIRECT_REF
, frame_type
, fun
->static_chain_decl
);
24045 fb_expr
= build3 (COMPONENT_REF
, TREE_TYPE (fb_decl
),
24046 fb_expr
, fb_decl
, NULL_TREE
);
24048 add_AT_location_description (subr_die
, DW_AT_static_link
,
24049 loc_list_from_tree (fb_expr
, 0, NULL
));
24052 resolve_variable_values ();
24055 /* Generate child dies for template parameters. */
24056 if (early_dwarf
&& debug_info_level
> DINFO_LEVEL_TERSE
)
24057 gen_generic_params_dies (decl
);
24059 /* Now output descriptions of the arguments for this function. This gets
24060 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
24061 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
24062 `...' at the end of the formal parameter list. In order to find out if
24063 there was a trailing ellipsis or not, we must instead look at the type
24064 associated with the FUNCTION_DECL. This will be a node of type
24065 FUNCTION_TYPE. If the chain of type nodes hanging off of this
24066 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
24067 an ellipsis at the end. */
24069 /* In the case where we are describing a mere function declaration, all we
24070 need to do here (and all we *can* do here) is to describe the *types* of
24071 its formal parameters. */
24072 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
24074 else if (declaration
)
24075 gen_formal_types_die (decl
, subr_die
);
24078 /* Generate DIEs to represent all known formal parameters. */
24079 tree parm
= DECL_ARGUMENTS (decl
);
24080 tree generic_decl
= early_dwarf
24081 ? lang_hooks
.decls
.get_generic_function_decl (decl
) : NULL
;
24082 tree generic_decl_parm
= generic_decl
24083 ? DECL_ARGUMENTS (generic_decl
)
24086 /* Now we want to walk the list of parameters of the function and
24087 emit their relevant DIEs.
24089 We consider the case of DECL being an instance of a generic function
24090 as well as it being a normal function.
24092 If DECL is an instance of a generic function we walk the
24093 parameters of the generic function declaration _and_ the parameters of
24094 DECL itself. This is useful because we want to emit specific DIEs for
24095 function parameter packs and those are declared as part of the
24096 generic function declaration. In that particular case,
24097 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
24098 That DIE has children DIEs representing the set of arguments
24099 of the pack. Note that the set of pack arguments can be empty.
24100 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
24103 Otherwise, we just consider the parameters of DECL. */
24104 while (generic_decl_parm
|| parm
)
24106 if (generic_decl_parm
24107 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
24108 gen_formal_parameter_pack_die (generic_decl_parm
,
24113 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, NULL
, subr_die
);
24116 && parm
== DECL_ARGUMENTS (decl
)
24117 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
24119 && (dwarf_version
>= 3 || !dwarf_strict
))
24120 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
24122 parm
= DECL_CHAIN (parm
);
24125 if (generic_decl_parm
)
24126 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
24129 /* Decide whether we need an unspecified_parameters DIE at the end.
24130 There are 2 more cases to do this for: 1) the ansi ... declaration -
24131 this is detectable when the end of the arg list is not a
24132 void_type_node 2) an unprototyped function declaration (not a
24133 definition). This just means that we have no info about the
24134 parameters at all. */
24137 if (prototype_p (TREE_TYPE (decl
)))
24139 /* This is the prototyped case, check for.... */
24140 if (stdarg_p (TREE_TYPE (decl
)))
24141 gen_unspecified_parameters_die (decl
, subr_die
);
24143 else if (DECL_INITIAL (decl
) == NULL_TREE
)
24144 gen_unspecified_parameters_die (decl
, subr_die
);
24146 else if ((subr_die
!= old_die
|| old_die_had_no_children
)
24147 && prototype_p (TREE_TYPE (decl
))
24148 && stdarg_p (TREE_TYPE (decl
)))
24149 gen_unspecified_parameters_die (decl
, subr_die
);
24152 if (subr_die
!= old_die
)
24153 /* Add the calling convention attribute if requested. */
24154 add_calling_convention_attribute (subr_die
, decl
);
24156 /* Output Dwarf info for all of the stuff within the body of the function
24157 (if it has one - it may be just a declaration).
24159 OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
24160 a function. This BLOCK actually represents the outermost binding contour
24161 for the function, i.e. the contour in which the function's formal
24162 parameters and labels get declared. Curiously, it appears that the front
24163 end doesn't actually put the PARM_DECL nodes for the current function onto
24164 the BLOCK_VARS list for this outer scope, but are strung off of the
24165 DECL_ARGUMENTS list for the function instead.
24167 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
24168 the LABEL_DECL nodes for the function however, and we output DWARF info
24169 for those in decls_for_scope. Just within the `outer_scope' there will be
24170 a BLOCK node representing the function's outermost pair of curly braces,
24171 and any blocks used for the base and member initializers of a C++
24172 constructor function. */
24173 tree outer_scope
= DECL_INITIAL (decl
);
24174 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
24176 int call_site_note_count
= 0;
24177 int tail_call_site_note_count
= 0;
24179 /* Emit a DW_TAG_variable DIE for a named return value. */
24180 if (DECL_NAME (DECL_RESULT (decl
)))
24181 gen_decl_die (DECL_RESULT (decl
), NULL
, NULL
, subr_die
);
24183 /* The first time through decls_for_scope we will generate the
24184 DIEs for the locals. The second time, we fill in the
24186 decls_for_scope (outer_scope
, subr_die
);
24188 if (call_arg_locations
&& (!dwarf_strict
|| dwarf_version
>= 5))
24190 struct call_arg_loc_node
*ca_loc
;
24191 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
24193 dw_die_ref die
= NULL
;
24194 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
24196 tree arg_decl
= NULL_TREE
;
24198 for (arg
= (ca_loc
->call_arg_loc_note
!= NULL_RTX
24199 ? XEXP (ca_loc
->call_arg_loc_note
, 0)
24201 arg
; arg
= next_arg
)
24203 dw_loc_descr_ref reg
, val
;
24204 machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
24205 dw_die_ref cdie
, tdie
= NULL
;
24207 next_arg
= XEXP (arg
, 1);
24208 if (REG_P (XEXP (XEXP (arg
, 0), 0))
24210 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
24211 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
24212 && REGNO (XEXP (XEXP (arg
, 0), 0))
24213 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
24214 next_arg
= XEXP (next_arg
, 1);
24215 if (mode
== VOIDmode
)
24217 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
24218 if (mode
== VOIDmode
)
24219 mode
= GET_MODE (XEXP (arg
, 0));
24221 if (mode
== VOIDmode
|| mode
== BLKmode
)
24223 /* Get dynamic information about call target only if we
24224 have no static information: we cannot generate both
24225 DW_AT_call_origin and DW_AT_call_target
24227 if (ca_loc
->symbol_ref
== NULL_RTX
)
24229 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
24231 tloc
= XEXP (XEXP (arg
, 0), 1);
24234 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
24235 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
24237 tlocc
= XEXP (XEXP (arg
, 0), 1);
24242 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
24243 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
24244 VAR_INIT_STATUS_INITIALIZED
);
24245 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
24247 rtx mem
= XEXP (XEXP (arg
, 0), 0);
24248 reg
= mem_loc_descriptor (XEXP (mem
, 0),
24249 get_address_mode (mem
),
24251 VAR_INIT_STATUS_INITIALIZED
);
24253 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
24254 == DEBUG_PARAMETER_REF
)
24257 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
24258 tdie
= lookup_decl_die (tdecl
);
24266 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
24267 != DEBUG_PARAMETER_REF
)
24269 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
24271 VAR_INIT_STATUS_INITIALIZED
);
24275 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
24276 cdie
= new_die (dwarf_TAG (DW_TAG_call_site_parameter
), die
,
24278 add_desc_attribute (cdie
, arg_decl
);
24280 add_AT_loc (cdie
, DW_AT_location
, reg
);
24281 else if (tdie
!= NULL
)
24282 add_AT_die_ref (cdie
, dwarf_AT (DW_AT_call_parameter
),
24284 add_AT_loc (cdie
, dwarf_AT (DW_AT_call_value
), val
);
24285 if (next_arg
!= XEXP (arg
, 1))
24287 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
24288 if (mode
== VOIDmode
)
24289 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
24290 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
24293 VAR_INIT_STATUS_INITIALIZED
);
24295 add_AT_loc (cdie
, dwarf_AT (DW_AT_call_data_value
),
24300 && (ca_loc
->symbol_ref
|| tloc
))
24301 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
24302 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
24304 dw_loc_descr_ref tval
= NULL
;
24306 if (tloc
!= NULL_RTX
)
24307 tval
= mem_loc_descriptor (tloc
,
24308 GET_MODE (tloc
) == VOIDmode
24309 ? Pmode
: GET_MODE (tloc
),
24311 VAR_INIT_STATUS_INITIALIZED
);
24313 add_AT_loc (die
, dwarf_AT (DW_AT_call_target
), tval
);
24314 else if (tlocc
!= NULL_RTX
)
24316 tval
= mem_loc_descriptor (tlocc
,
24317 GET_MODE (tlocc
) == VOIDmode
24318 ? Pmode
: GET_MODE (tlocc
),
24320 VAR_INIT_STATUS_INITIALIZED
);
24323 dwarf_AT (DW_AT_call_target_clobbered
),
24329 call_site_note_count
++;
24330 if (ca_loc
->tail_call_p
)
24331 tail_call_site_note_count
++;
24335 call_arg_locations
= NULL
;
24336 call_arg_loc_last
= NULL
;
24337 if (tail_call_site_count
>= 0
24338 && tail_call_site_count
== tail_call_site_note_count
24339 && (!dwarf_strict
|| dwarf_version
>= 5))
24341 if (call_site_count
>= 0
24342 && call_site_count
== call_site_note_count
)
24343 add_AT_flag (subr_die
, dwarf_AT (DW_AT_call_all_calls
), 1);
24345 add_AT_flag (subr_die
, dwarf_AT (DW_AT_call_all_tail_calls
), 1);
24347 call_site_count
= -1;
24348 tail_call_site_count
= -1;
24351 /* Mark used types after we have created DIEs for the functions scopes. */
24352 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
24355 /* Returns a hash value for X (which really is a die_struct). */
24358 block_die_hasher::hash (die_struct
*d
)
24360 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
24363 /* Return true if decl_id and die_parent of die_struct X is the same
24364 as decl_id and die_parent of die_struct Y. */
24367 block_die_hasher::equal (die_struct
*x
, die_struct
*y
)
24369 return x
->decl_id
== y
->decl_id
&& x
->die_parent
== y
->die_parent
;
24372 /* Hold information about markers for inlined entry points. */
24373 struct GTY ((for_user
)) inline_entry_data
24375 /* The block that's the inlined_function_outer_scope for an inlined
24379 /* The label at the inlined entry point. */
24380 const char *label_pfx
;
24381 unsigned int label_num
;
24383 /* The view number to be used as the inlined entry point. */
24387 struct inline_entry_data_hasher
: ggc_ptr_hash
<inline_entry_data
>
24389 typedef tree compare_type
;
24390 static inline hashval_t
hash (const inline_entry_data
*);
24391 static inline bool equal (const inline_entry_data
*, const_tree
);
24394 /* Hash table routines for inline_entry_data. */
24397 inline_entry_data_hasher::hash (const inline_entry_data
*data
)
24399 return htab_hash_pointer (data
->block
);
24403 inline_entry_data_hasher::equal (const inline_entry_data
*data
,
24406 return data
->block
== block
;
24409 /* Inlined entry points pending DIE creation in this compilation unit. */
24411 static GTY(()) hash_table
<inline_entry_data_hasher
> *inline_entry_data_table
;
24414 /* Return TRUE if DECL, which may have been previously generated as
24415 OLD_DIE, is a candidate for a DW_AT_specification. DECLARATION is
24416 true if decl (or its origin) is either an extern declaration or a
24417 class/namespace scoped declaration.
24419 The declare_in_namespace support causes us to get two DIEs for one
24420 variable, both of which are declarations. We want to avoid
24421 considering one to be a specification, so we must test for
24422 DECLARATION and DW_AT_declaration. */
24424 decl_will_get_specification_p (dw_die_ref old_die
, tree decl
, bool declaration
)
24426 return (old_die
&& TREE_STATIC (decl
) && !declaration
24427 && get_AT_flag (old_die
, DW_AT_declaration
) == 1);
24430 /* Return true if DECL is a local static. */
24433 local_function_static (tree decl
)
24435 gcc_assert (VAR_P (decl
));
24436 return TREE_STATIC (decl
)
24437 && DECL_CONTEXT (decl
)
24438 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
;
24441 /* Return true iff DECL overrides (presumably completes) the type of
24442 OLD_DIE within CONTEXT_DIE. */
24445 override_type_for_decl_p (tree decl
, dw_die_ref old_die
,
24446 dw_die_ref context_die
)
24448 tree type
= TREE_TYPE (decl
);
24451 if (decl_by_reference_p (decl
))
24453 type
= TREE_TYPE (type
);
24454 cv_quals
= TYPE_UNQUALIFIED
;
24457 cv_quals
= decl_quals (decl
);
24459 dw_die_ref type_die
= modified_type_die (type
,
24460 cv_quals
| TYPE_QUALS (type
),
24464 dw_die_ref old_type_die
= get_AT_ref (old_die
, DW_AT_type
);
24466 return type_die
!= old_type_die
;
24469 /* Generate a DIE to represent a declared data object.
24470 Either DECL or ORIGIN must be non-null. */
24473 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
24475 HOST_WIDE_INT off
= 0;
24477 tree decl_or_origin
= decl
? decl
: origin
;
24478 tree ultimate_origin
;
24479 dw_die_ref var_die
;
24480 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
24481 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
24482 || class_or_namespace_scope_p (context_die
));
24483 bool specialization_p
= false;
24484 bool no_linkage_name
= false;
24486 /* While C++ inline static data members have definitions inside of the
24487 class, force the first DIE to be a declaration, then let gen_member_die
24488 reparent it to the class context and call gen_variable_die again
24489 to create the outside of the class DIE for the definition. */
24493 && DECL_CONTEXT (decl
)
24494 && TYPE_P (DECL_CONTEXT (decl
))
24495 && lang_hooks
.decls
.decl_dwarf_attribute (decl
, DW_AT_inline
) != -1)
24497 declaration
= true;
24498 if (dwarf_version
< 5)
24499 no_linkage_name
= true;
24502 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
24503 if (decl
|| ultimate_origin
)
24504 origin
= ultimate_origin
;
24505 com_decl
= fortran_common (decl_or_origin
, &off
);
24507 /* Symbol in common gets emitted as a child of the common block, in the form
24508 of a data member. */
24511 dw_die_ref com_die
;
24512 dw_loc_list_ref loc
= NULL
;
24513 die_node com_die_arg
;
24515 var_die
= lookup_decl_die (decl_or_origin
);
24518 if (! early_dwarf
&& get_AT (var_die
, DW_AT_location
) == NULL
)
24520 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2, NULL
);
24525 /* Optimize the common case. */
24526 if (single_element_loc_list_p (loc
)
24527 && loc
->expr
->dw_loc_opc
== DW_OP_addr
24528 && loc
->expr
->dw_loc_next
== NULL
24529 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
24532 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
24533 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
24534 = plus_constant (GET_MODE (x
), x
, off
);
24537 loc_list_plus_const (loc
, off
);
24539 add_AT_location_description (var_die
, DW_AT_location
, loc
);
24540 remove_AT (var_die
, DW_AT_declaration
);
24546 if (common_block_die_table
== NULL
)
24547 common_block_die_table
= hash_table
<block_die_hasher
>::create_ggc (10);
24549 com_die_arg
.decl_id
= DECL_UID (com_decl
);
24550 com_die_arg
.die_parent
= context_die
;
24551 com_die
= common_block_die_table
->find (&com_die_arg
);
24553 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
24554 if (com_die
== NULL
)
24557 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
24560 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
24561 add_name_and_src_coords_attributes (com_die
, com_decl
);
24564 add_AT_location_description (com_die
, DW_AT_location
, loc
);
24565 /* Avoid sharing the same loc descriptor between
24566 DW_TAG_common_block and DW_TAG_variable. */
24567 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
24569 else if (DECL_EXTERNAL (decl_or_origin
))
24570 add_AT_flag (com_die
, DW_AT_declaration
, 1);
24571 if (want_pubnames ())
24572 add_pubname_string (cnam
, com_die
); /* ??? needed? */
24573 com_die
->decl_id
= DECL_UID (com_decl
);
24574 slot
= common_block_die_table
->find_slot (com_die
, INSERT
);
24577 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
24579 add_AT_location_description (com_die
, DW_AT_location
, loc
);
24580 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
24581 remove_AT (com_die
, DW_AT_declaration
);
24583 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
24584 add_name_and_src_coords_attributes (var_die
, decl_or_origin
);
24585 add_type_attribute (var_die
, TREE_TYPE (decl_or_origin
),
24586 decl_quals (decl_or_origin
), false,
24588 add_alignment_attribute (var_die
, decl
);
24589 add_AT_flag (var_die
, DW_AT_external
, 1);
24594 /* Optimize the common case. */
24595 if (single_element_loc_list_p (loc
)
24596 && loc
->expr
->dw_loc_opc
== DW_OP_addr
24597 && loc
->expr
->dw_loc_next
== NULL
24598 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
24600 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
24601 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
24602 = plus_constant (GET_MODE (x
), x
, off
);
24605 loc_list_plus_const (loc
, off
);
24607 add_AT_location_description (var_die
, DW_AT_location
, loc
);
24609 else if (DECL_EXTERNAL (decl_or_origin
))
24610 add_AT_flag (var_die
, DW_AT_declaration
, 1);
24612 equate_decl_number_to_die (decl
, var_die
);
24620 /* A declaration that has been previously dumped, needs no
24621 further annotations, since it doesn't need location on
24622 the second pass. */
24625 else if (decl_will_get_specification_p (old_die
, decl
, declaration
)
24626 && !get_AT (old_die
, DW_AT_specification
))
24628 /* Fall-thru so we can make a new variable die along with a
24629 DW_AT_specification. */
24631 else if (origin
&& old_die
->die_parent
!= context_die
)
24633 /* If we will be creating an inlined instance, we need a
24634 new DIE that will get annotated with
24635 DW_AT_abstract_origin. */
24636 gcc_assert (!DECL_ABSTRACT_P (decl
));
24640 /* If a DIE was dumped early, it still needs location info.
24641 Skip to where we fill the location bits. */
24644 /* ??? In LTRANS we cannot annotate early created variably
24645 modified type DIEs without copying them and adjusting all
24646 references to them. Thus we dumped them again. Also add a
24647 reference to them but beware of -g0 compile and -g link
24648 in which case the reference will be already present. */
24649 tree type
= TREE_TYPE (decl_or_origin
);
24651 && ! get_AT (var_die
, DW_AT_type
)
24652 && variably_modified_type_p
24653 (type
, decl_function_context (decl_or_origin
)))
24655 if (decl_by_reference_p (decl_or_origin
))
24656 add_type_attribute (var_die
, TREE_TYPE (type
),
24657 TYPE_UNQUALIFIED
, false, context_die
);
24659 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
),
24660 false, context_die
);
24663 goto gen_variable_die_location
;
24667 /* For static data members, the declaration in the class is supposed
24668 to have DW_TAG_member tag in DWARF{3,4} and we emit it for compatibility
24669 also in DWARF2; the specification should still be DW_TAG_variable
24670 referencing the DW_TAG_member DIE. */
24671 if (declaration
&& class_scope_p (context_die
) && dwarf_version
< 5)
24672 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
24674 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
24676 if (origin
!= NULL
)
24677 add_abstract_origin_attribute (var_die
, origin
);
24679 /* Loop unrolling can create multiple blocks that refer to the same
24680 static variable, so we must test for the DW_AT_declaration flag.
24682 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
24683 copy decls and set the DECL_ABSTRACT_P flag on them instead of
24686 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
24687 else if (decl_will_get_specification_p (old_die
, decl
, declaration
))
24689 /* This is a definition of a C++ class level static. */
24690 add_AT_specification (var_die
, old_die
);
24691 specialization_p
= true;
24692 if (DECL_NAME (decl
))
24694 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
24695 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
24697 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
24698 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
24700 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
24701 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
24703 if (debug_column_info
24705 && (get_AT_unsigned (old_die
, DW_AT_decl_column
)
24706 != (unsigned) s
.column
))
24707 add_AT_unsigned (var_die
, DW_AT_decl_column
, s
.column
);
24709 if (old_die
->die_tag
== DW_TAG_member
)
24710 add_linkage_name (var_die
, decl
);
24714 add_name_and_src_coords_attributes (var_die
, decl
, no_linkage_name
);
24716 if ((origin
== NULL
&& !specialization_p
)
24718 && !DECL_ABSTRACT_P (decl_or_origin
)
24719 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
24720 decl_function_context
24722 || (old_die
&& specialization_p
24723 && override_type_for_decl_p (decl_or_origin
, old_die
, context_die
)))
24725 tree type
= TREE_TYPE (decl_or_origin
);
24727 if (decl_by_reference_p (decl_or_origin
))
24728 add_type_attribute (var_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
24731 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
), false,
24735 if (origin
== NULL
&& !specialization_p
)
24737 if (TREE_PUBLIC (decl
))
24738 add_AT_flag (var_die
, DW_AT_external
, 1);
24740 if (DECL_ARTIFICIAL (decl
))
24741 add_AT_flag (var_die
, DW_AT_artificial
, 1);
24743 add_alignment_attribute (var_die
, decl
);
24745 add_accessibility_attribute (var_die
, decl
);
24749 add_AT_flag (var_die
, DW_AT_declaration
, 1);
24751 if (decl
&& (DECL_ABSTRACT_P (decl
)
24752 || !old_die
|| is_declaration_die (old_die
)))
24753 equate_decl_number_to_die (decl
, var_die
);
24755 gen_variable_die_location
:
24757 && (! DECL_ABSTRACT_P (decl_or_origin
)
24758 /* Local static vars are shared between all clones/inlines,
24759 so emit DW_AT_location on the abstract DIE if DECL_RTL is
24761 || (VAR_P (decl_or_origin
)
24762 && TREE_STATIC (decl_or_origin
)
24763 && DECL_RTL_SET_P (decl_or_origin
))))
24767 add_pubname (decl_or_origin
, var_die
);
24768 /* For global register variables, emit DW_AT_location if possible
24769 already during early_dwarf, as late_global_decl won't be usually
24771 if (DECL_HARD_REGISTER (decl_or_origin
)
24772 && TREE_STATIC (decl_or_origin
)
24773 && !decl_by_reference_p (decl_or_origin
)
24774 && !get_AT (var_die
, DW_AT_location
)
24775 && !get_AT (var_die
, DW_AT_const_value
)
24776 && DECL_RTL_SET_P (decl_or_origin
)
24777 && REG_P (DECL_RTL (decl_or_origin
)))
24779 dw_loc_descr_ref descr
24780 = reg_loc_descriptor (DECL_RTL (decl_or_origin
),
24781 VAR_INIT_STATUS_INITIALIZED
);
24783 add_AT_loc (var_die
, DW_AT_location
, descr
);
24787 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
24791 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
24793 if ((dwarf_version
>= 4 || !dwarf_strict
)
24794 && lang_hooks
.decls
.decl_dwarf_attribute (decl_or_origin
,
24795 DW_AT_const_expr
) == 1
24796 && !get_AT (var_die
, DW_AT_const_expr
)
24797 && !specialization_p
)
24798 add_AT_flag (var_die
, DW_AT_const_expr
, 1);
24802 int inl
= lang_hooks
.decls
.decl_dwarf_attribute (decl_or_origin
,
24805 && !get_AT (var_die
, DW_AT_inline
)
24806 && !specialization_p
)
24807 add_AT_unsigned (var_die
, DW_AT_inline
, inl
);
24811 /* Generate a DIE to represent a named constant. */
24814 gen_const_die (tree decl
, dw_die_ref context_die
)
24816 dw_die_ref const_die
;
24817 tree type
= TREE_TYPE (decl
);
24819 const_die
= lookup_decl_die (decl
);
24823 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
24824 equate_decl_number_to_die (decl
, const_die
);
24825 add_name_and_src_coords_attributes (const_die
, decl
);
24826 add_type_attribute (const_die
, type
, TYPE_QUAL_CONST
, false, context_die
);
24827 if (TREE_PUBLIC (decl
))
24828 add_AT_flag (const_die
, DW_AT_external
, 1);
24829 if (DECL_ARTIFICIAL (decl
))
24830 add_AT_flag (const_die
, DW_AT_artificial
, 1);
24831 tree_add_const_value_attribute_for_decl (const_die
, decl
);
24834 /* Generate a DIE to represent a label identifier. */
24837 gen_label_die (tree decl
, dw_die_ref context_die
)
24839 tree origin
= decl_ultimate_origin (decl
);
24840 dw_die_ref lbl_die
= lookup_decl_die (decl
);
24842 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
24846 lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
24847 equate_decl_number_to_die (decl
, lbl_die
);
24849 if (origin
!= NULL
)
24850 add_abstract_origin_attribute (lbl_die
, origin
);
24852 add_name_and_src_coords_attributes (lbl_die
, decl
);
24855 if (DECL_ABSTRACT_P (decl
))
24856 equate_decl_number_to_die (decl
, lbl_die
);
24857 else if (! early_dwarf
)
24859 insn
= DECL_RTL_IF_SET (decl
);
24861 /* Deleted labels are programmer specified labels which have been
24862 eliminated because of various optimizations. We still emit them
24863 here so that it is possible to put breakpoints on them. */
24867 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
24869 /* When optimization is enabled (via -O) some parts of the compiler
24870 (e.g. jump.cc and cse.cc) may try to delete CODE_LABEL insns which
24871 represent source-level labels which were explicitly declared by
24872 the user. This really shouldn't be happening though, so catch
24873 it if it ever does happen. */
24874 gcc_assert (!as_a
<rtx_insn
*> (insn
)->deleted ());
24876 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
24877 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
24881 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
24882 && CODE_LABEL_NUMBER (insn
) != -1)
24884 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
24885 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
24890 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
24891 attributes to the DIE for a block STMT, to describe where the inlined
24892 function was called from. This is similar to add_src_coords_attributes. */
24895 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
24897 /* We can end up with BUILTINS_LOCATION here. */
24898 if (RESERVED_LOCATION_P (BLOCK_SOURCE_LOCATION (stmt
)))
24901 location_t locus
= BLOCK_SOURCE_LOCATION (stmt
);
24902 expanded_location s
= expand_location (locus
);
24904 if (dwarf_version
>= 3 || !dwarf_strict
)
24906 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
24907 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
24908 if (debug_column_info
&& s
.column
)
24909 add_AT_unsigned (die
, DW_AT_call_column
, s
.column
);
24910 unsigned discr
= get_discriminator_from_loc (locus
);
24912 add_AT_unsigned (die
, DW_AT_GNU_discriminator
, discr
);
24917 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
24918 Add low_pc and high_pc attributes to the DIE for a block STMT. */
24921 add_high_low_attributes (tree stmt
, dw_die_ref die
)
24923 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
24925 if (inline_entry_data
**iedp
24926 = !inline_entry_data_table
? NULL
24927 : inline_entry_data_table
->find_slot_with_hash (stmt
,
24928 htab_hash_pointer (stmt
),
24931 inline_entry_data
*ied
= *iedp
;
24932 gcc_assert (MAY_HAVE_DEBUG_MARKER_INSNS
);
24933 gcc_assert (debug_inline_points
);
24934 gcc_assert (inlined_function_outer_scope_p (stmt
));
24936 ASM_GENERATE_INTERNAL_LABEL (label
, ied
->label_pfx
, ied
->label_num
);
24937 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
24939 if (debug_variable_location_views
&& !ZERO_VIEW_P (ied
->view
)
24942 if (!output_asm_line_debug_info ())
24943 add_AT_unsigned (die
, DW_AT_GNU_entry_view
, ied
->view
);
24946 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", ied
->view
);
24947 /* FIXME: this will resolve to a small number. Could we
24948 possibly emit smaller data? Ideally we'd emit a
24949 uleb128, but that would make the size of DIEs
24950 impossible for the compiler to compute, since it's
24951 the assembler that computes the value of the view
24952 label in this case. Ideally, we'd have a single form
24953 encompassing both the address and the view, and
24954 indirecting them through a table might make things
24955 easier, but even that would be more wasteful,
24956 space-wise, than what we have now. */
24957 add_AT_symview (die
, DW_AT_GNU_entry_view
, label
);
24961 inline_entry_data_table
->clear_slot (iedp
);
24964 if (BLOCK_FRAGMENT_CHAIN (stmt
)
24965 && (dwarf_version
>= 3 || !dwarf_strict
))
24967 tree chain
, superblock
= NULL_TREE
;
24969 dw_attr_node
*attr
= NULL
;
24971 if (!debug_inline_points
&& inlined_function_outer_scope_p (stmt
))
24973 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
24974 BLOCK_NUMBER (stmt
));
24975 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
24978 /* Optimize duplicate .debug_ranges lists or even tails of
24979 lists. If this BLOCK has same ranges as its supercontext,
24980 lookup DW_AT_ranges attribute in the supercontext (and
24981 recursively so), verify that the ranges_table contains the
24982 right values and use it instead of adding a new .debug_range. */
24983 for (chain
= stmt
, pdie
= die
;
24984 BLOCK_SAME_RANGE (chain
);
24985 chain
= BLOCK_SUPERCONTEXT (chain
))
24987 dw_attr_node
*new_attr
;
24989 pdie
= pdie
->die_parent
;
24992 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
24994 new_attr
= get_AT (pdie
, DW_AT_ranges
);
24995 if (new_attr
== NULL
24996 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
24999 superblock
= BLOCK_SUPERCONTEXT (chain
);
25002 && ((*ranges_table
)[attr
->dw_attr_val
.v
.val_offset
].num
25003 == (int)BLOCK_NUMBER (superblock
))
25004 && BLOCK_FRAGMENT_CHAIN (superblock
))
25006 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
;
25007 unsigned long supercnt
= 0, thiscnt
= 0;
25008 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
25009 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
25012 gcc_checking_assert ((*ranges_table
)[off
+ supercnt
].num
25013 == (int)BLOCK_NUMBER (chain
));
25015 gcc_checking_assert ((*ranges_table
)[off
+ supercnt
+ 1].num
== 0);
25016 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
25017 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
25019 gcc_assert (supercnt
>= thiscnt
);
25020 add_AT_range_list (die
, DW_AT_ranges
, off
+ supercnt
- thiscnt
,
25022 note_rnglist_head (off
+ supercnt
- thiscnt
);
25026 unsigned int offset
= add_ranges (stmt
, true);
25027 add_AT_range_list (die
, DW_AT_ranges
, offset
, false);
25028 note_rnglist_head (offset
);
25030 bool prev_in_cold
= BLOCK_IN_COLD_SECTION_P (stmt
);
25031 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
25034 add_ranges (chain
, prev_in_cold
!= BLOCK_IN_COLD_SECTION_P (chain
));
25035 prev_in_cold
= BLOCK_IN_COLD_SECTION_P (chain
);
25036 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
25043 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
25044 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
25045 BLOCK_NUMBER (stmt
));
25046 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
25047 BLOCK_NUMBER (stmt
));
25048 add_AT_low_high_pc (die
, label
, label_high
, false);
25052 /* Generate a DIE for a lexical block. */
25055 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
)
25057 dw_die_ref old_die
= lookup_block_die (stmt
);
25058 dw_die_ref stmt_die
= NULL
;
25061 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
25062 equate_block_to_die (stmt
, stmt_die
);
25065 if (BLOCK_ABSTRACT_ORIGIN (stmt
))
25067 /* If this is an inlined or conrecte instance, create a new lexical
25068 die for anything below to attach DW_AT_abstract_origin to. */
25070 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
25072 tree origin
= block_ultimate_origin (stmt
);
25073 if (origin
!= NULL_TREE
&& (origin
!= stmt
|| old_die
))
25074 add_abstract_origin_attribute (stmt_die
, origin
);
25080 stmt_die
= old_die
;
25082 /* A non abstract block whose blocks have already been reordered
25083 should have the instruction range for this block. If so, set the
25084 high/low attributes. */
25085 if (!early_dwarf
&& TREE_ASM_WRITTEN (stmt
))
25087 gcc_assert (stmt_die
);
25088 add_high_low_attributes (stmt
, stmt_die
);
25091 decls_for_scope (stmt
, stmt_die
);
25094 /* Generate a DIE for an inlined subprogram. */
25097 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
)
25099 tree decl
= block_ultimate_origin (stmt
);
25101 /* Make sure any inlined functions are known to be inlineable. */
25102 gcc_checking_assert (DECL_ABSTRACT_P (decl
)
25103 || cgraph_function_possibly_inlined_p (decl
));
25105 dw_die_ref subr_die
= new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
25107 if (call_arg_locations
|| debug_inline_points
)
25108 equate_block_to_die (stmt
, subr_die
);
25109 add_abstract_origin_attribute (subr_die
, decl
);
25110 if (TREE_ASM_WRITTEN (stmt
))
25111 add_high_low_attributes (stmt
, subr_die
);
25112 add_call_src_coords_attributes (stmt
, subr_die
);
25114 /* The inliner creates an extra BLOCK for the parameter setup,
25115 we want to merge that with the actual outermost BLOCK of the
25116 inlined function to avoid duplicate locals in consumers.
25117 Do that by doing the recursion to subblocks on the single subblock
25119 bool unwrap_one
= false;
25120 if (BLOCK_SUBBLOCKS (stmt
) && !BLOCK_CHAIN (BLOCK_SUBBLOCKS (stmt
)))
25122 tree origin
= block_ultimate_origin (BLOCK_SUBBLOCKS (stmt
));
25124 && TREE_CODE (origin
) == BLOCK
25125 && BLOCK_SUPERCONTEXT (origin
) == decl
)
25128 decls_for_scope (stmt
, subr_die
, !unwrap_one
);
25130 decls_for_scope (BLOCK_SUBBLOCKS (stmt
), subr_die
);
25133 /* Generate a DIE for a field in a record, or structure. CTX is required: see
25134 the comment for VLR_CONTEXT. */
25137 gen_field_die (tree decl
, struct vlr_context
*ctx
, dw_die_ref context_die
)
25139 dw_die_ref decl_die
;
25141 if (TREE_TYPE (decl
) == error_mark_node
)
25144 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
25145 add_name_and_src_coords_attributes (decl_die
, decl
);
25146 add_type_attribute (decl_die
, member_declared_type (decl
), decl_quals (decl
),
25147 TYPE_REVERSE_STORAGE_ORDER (DECL_FIELD_CONTEXT (decl
)),
25150 if (DECL_BIT_FIELD_TYPE (decl
))
25152 add_byte_size_attribute (decl_die
, decl
);
25153 add_bit_size_attribute (decl_die
, decl
);
25154 add_bit_offset_attribute (decl_die
, decl
);
25157 add_alignment_attribute (decl_die
, decl
);
25159 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
25160 add_data_member_location_attribute (decl_die
, decl
, ctx
);
25162 if (DECL_ARTIFICIAL (decl
))
25163 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
25165 add_accessibility_attribute (decl_die
, decl
);
25167 /* Add DW_AT_export_symbols to anonymous unions or structs. */
25168 if ((dwarf_version
>= 5 || !dwarf_strict
) && DECL_NAME (decl
) == NULL_TREE
)
25169 if (tree type
= member_declared_type (decl
))
25170 if (lang_hooks
.types
.type_dwarf_attribute (TYPE_MAIN_VARIANT (type
),
25171 DW_AT_export_symbols
) != -1)
25173 dw_die_ref type_die
= lookup_type_die (TYPE_MAIN_VARIANT (type
));
25174 if (type_die
&& get_AT (type_die
, DW_AT_export_symbols
) == NULL
)
25175 add_AT_flag (type_die
, DW_AT_export_symbols
, 1);
25178 /* Equate decl number to die, so that we can look up this decl later on. */
25179 equate_decl_number_to_die (decl
, decl_die
);
25182 /* Generate a DIE for a pointer to a member type. TYPE can be an
25183 OFFSET_TYPE, for a pointer to data member, or a RECORD_TYPE, for a
25184 pointer to member function. */
25187 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
25189 if (lookup_type_die (type
))
25192 dw_die_ref ptr_die
= new_die (DW_TAG_ptr_to_member_type
,
25193 scope_die_for (type
, context_die
), type
);
25195 equate_type_number_to_die (type
, ptr_die
);
25196 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
25197 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
25198 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
25200 add_alignment_attribute (ptr_die
, type
);
25202 if (TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
25203 && TREE_CODE (TREE_TYPE (type
)) != METHOD_TYPE
)
25205 dw_loc_descr_ref op
= new_loc_descr (DW_OP_plus
, 0, 0);
25206 add_AT_loc (ptr_die
, DW_AT_use_location
, op
);
25210 static char *producer_string
;
25212 /* Given a C and/or C++ language/version string return the "highest".
25213 C++ is assumed to be "higher" than C in this case. Used for merging
25214 LTO translation unit languages. */
25215 static const char *
25216 highest_c_language (const char *lang1
, const char *lang2
)
25218 if (strcmp ("GNU C++26", lang1
) == 0 || strcmp ("GNU C++26", lang2
) == 0)
25219 return "GNU C++26";
25220 if (strcmp ("GNU C++23", lang1
) == 0 || strcmp ("GNU C++23", lang2
) == 0)
25221 return "GNU C++23";
25222 if (strcmp ("GNU C++20", lang1
) == 0 || strcmp ("GNU C++20", lang2
) == 0)
25223 return "GNU C++20";
25224 if (strcmp ("GNU C++17", lang1
) == 0 || strcmp ("GNU C++17", lang2
) == 0)
25225 return "GNU C++17";
25226 if (strcmp ("GNU C++14", lang1
) == 0 || strcmp ("GNU C++14", lang2
) == 0)
25227 return "GNU C++14";
25228 if (strcmp ("GNU C++11", lang1
) == 0 || strcmp ("GNU C++11", lang2
) == 0)
25229 return "GNU C++11";
25230 if (strcmp ("GNU C++98", lang1
) == 0 || strcmp ("GNU C++98", lang2
) == 0)
25231 return "GNU C++98";
25233 if (strcmp ("GNU C23", lang1
) == 0 || strcmp ("GNU C23", lang2
) == 0)
25235 if (strcmp ("GNU C17", lang1
) == 0 || strcmp ("GNU C17", lang2
) == 0)
25237 if (strcmp ("GNU C11", lang1
) == 0 || strcmp ("GNU C11", lang2
) == 0)
25239 if (strcmp ("GNU C99", lang1
) == 0 || strcmp ("GNU C99", lang2
) == 0)
25241 if (strcmp ("GNU C89", lang1
) == 0 || strcmp ("GNU C89", lang2
) == 0)
25244 gcc_unreachable ();
25248 /* Generate the DIE for the compilation unit. */
25251 gen_compile_unit_die (const char *filename
)
25254 const char *language_string
= lang_hooks
.name
;
25257 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
25261 add_filename_attribute (die
, filename
);
25262 /* Don't add cwd for <built-in>. */
25263 if (filename
[0] != '<')
25264 add_comp_dir_attribute (die
);
25267 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
25269 /* If our producer is LTO try to figure out a common language to use
25270 from the global list of translation units. */
25271 if (strcmp (language_string
, "GNU GIMPLE") == 0)
25275 const char *common_lang
= NULL
;
25277 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
25279 if (!TRANSLATION_UNIT_LANGUAGE (t
))
25282 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
25283 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
25285 else if (startswith (common_lang
, "GNU C")
25286 && startswith (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C"))
25287 /* Mixing C and C++ is ok, use C++ in that case. */
25288 common_lang
= highest_c_language (common_lang
,
25289 TRANSLATION_UNIT_LANGUAGE (t
));
25292 /* Fall back to C. */
25293 common_lang
= NULL
;
25299 language_string
= common_lang
;
25302 language
= DW_LANG_C
;
25303 if (startswith (language_string
, "GNU C")
25304 && ISDIGIT (language_string
[5]))
25306 language
= DW_LANG_C89
;
25307 if (dwarf_version
>= 3 || !dwarf_strict
)
25309 if (strcmp (language_string
, "GNU C89") != 0)
25310 language
= DW_LANG_C99
;
25312 if (dwarf_version
>= 5 /* || !dwarf_strict */)
25313 if (strcmp (language_string
, "GNU C11") == 0
25314 || strcmp (language_string
, "GNU C17") == 0
25315 || strcmp (language_string
, "GNU C23") == 0)
25316 language
= DW_LANG_C11
;
25319 else if (startswith (language_string
, "GNU C++"))
25321 language
= DW_LANG_C_plus_plus
;
25322 if (dwarf_version
>= 5 /* || !dwarf_strict */)
25324 if (strcmp (language_string
, "GNU C++11") == 0)
25325 language
= DW_LANG_C_plus_plus_11
;
25326 else if (strcmp (language_string
, "GNU C++14") == 0)
25327 language
= DW_LANG_C_plus_plus_14
;
25328 else if (strcmp (language_string
, "GNU C++17") == 0
25329 || strcmp (language_string
, "GNU C++20") == 0
25330 || strcmp (language_string
, "GNU C++23") == 0
25331 || strcmp (language_string
, "GNU C++26") == 0)
25333 language
= DW_LANG_C_plus_plus_14
;
25336 else if (strcmp (language_string
, "GNU F77") == 0)
25337 language
= DW_LANG_Fortran77
;
25338 else if (strcmp (language_string
, "GNU Modula-2") == 0)
25339 language
= DW_LANG_Modula2
;
25340 else if (dwarf_version
>= 3 || !dwarf_strict
)
25342 if (strcmp (language_string
, "GNU Ada") == 0)
25343 language
= DW_LANG_Ada95
;
25344 else if (startswith (language_string
, "GNU Fortran"))
25346 language
= DW_LANG_Fortran95
;
25347 if (dwarf_version
>= 5 /* || !dwarf_strict */)
25349 if (strcmp (language_string
, "GNU Fortran2003") == 0)
25350 language
= DW_LANG_Fortran03
;
25351 else if (strcmp (language_string
, "GNU Fortran2008") == 0)
25352 language
= DW_LANG_Fortran08
;
25355 else if (strcmp (language_string
, "GNU Objective-C") == 0)
25356 language
= DW_LANG_ObjC
;
25357 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
25358 language
= DW_LANG_ObjC_plus_plus
;
25359 else if (strcmp (language_string
, "GNU D") == 0)
25360 language
= DW_LANG_D
;
25361 else if (dwarf_version
>= 5 || !dwarf_strict
)
25363 if (strcmp (language_string
, "GNU Go") == 0)
25364 language
= DW_LANG_Go
;
25365 else if (strcmp (language_string
, "GNU Rust") == 0)
25366 language
= DW_LANG_Rust
;
25369 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
25370 else if (startswith (language_string
, "GNU Fortran"))
25371 language
= DW_LANG_Fortran90
;
25372 /* Likewise for Ada. */
25373 else if (strcmp (language_string
, "GNU Ada") == 0)
25374 language
= DW_LANG_Ada83
;
25376 add_AT_unsigned (die
, DW_AT_language
, language
);
25380 case DW_LANG_Fortran77
:
25381 case DW_LANG_Fortran90
:
25382 case DW_LANG_Fortran95
:
25383 case DW_LANG_Fortran03
:
25384 case DW_LANG_Fortran08
:
25385 /* Fortran has case insensitive identifiers and the front-end
25386 lowercases everything. */
25387 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
25390 /* The default DW_ID_case_sensitive doesn't need to be specified. */
25396 /* Generate the DIE for a base class. */
25399 gen_inheritance_die (tree binfo
, tree access
, tree type
,
25400 dw_die_ref context_die
)
25402 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
25403 struct vlr_context ctx
= { type
, NULL
};
25405 add_type_attribute (die
, BINFO_TYPE (binfo
), TYPE_UNQUALIFIED
, false,
25407 add_data_member_location_attribute (die
, binfo
, &ctx
);
25409 if (BINFO_VIRTUAL_P (binfo
))
25410 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
25412 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
25413 children, otherwise the default is DW_ACCESS_public. In DWARF2
25414 the default has always been DW_ACCESS_private. */
25415 if (access
== access_public_node
)
25417 if (dwarf_version
== 2
25418 || context_die
->die_tag
== DW_TAG_class_type
)
25419 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
25421 else if (access
== access_protected_node
)
25422 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
25423 else if (dwarf_version
> 2
25424 && context_die
->die_tag
!= DW_TAG_class_type
)
25425 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
25428 /* Return whether DECL is a FIELD_DECL that represents the variant part of a
25432 is_variant_part (tree decl
)
25434 return (TREE_CODE (decl
) == FIELD_DECL
25435 && TREE_CODE (TREE_TYPE (decl
)) == QUAL_UNION_TYPE
);
25438 /* Check that OPERAND is a reference to a field in STRUCT_TYPE. If it is,
25439 return the FIELD_DECL. Return NULL_TREE otherwise. */
25442 analyze_discr_in_predicate (tree operand
, tree struct_type
)
25444 while (CONVERT_EXPR_P (operand
))
25445 operand
= TREE_OPERAND (operand
, 0);
25447 /* Match field access to members of struct_type only. */
25448 if (TREE_CODE (operand
) == COMPONENT_REF
25449 && TREE_CODE (TREE_OPERAND (operand
, 0)) == PLACEHOLDER_EXPR
25450 && TREE_TYPE (TREE_OPERAND (operand
, 0)) == struct_type
25451 && TREE_CODE (TREE_OPERAND (operand
, 1)) == FIELD_DECL
)
25452 return TREE_OPERAND (operand
, 1);
25457 /* Check that SRC is a constant integer that can be represented as a native
25458 integer constant (either signed or unsigned). If so, store it into DEST and
25459 return true. Return false otherwise. */
25462 get_discr_value (tree src
, dw_discr_value
*dest
)
25464 tree discr_type
= TREE_TYPE (src
);
25466 if (lang_hooks
.types
.get_debug_type
)
25468 tree debug_type
= lang_hooks
.types
.get_debug_type (discr_type
);
25469 if (debug_type
!= NULL
)
25470 discr_type
= debug_type
;
25473 if (TREE_CODE (src
) != INTEGER_CST
|| !INTEGRAL_TYPE_P (discr_type
))
25476 /* Signedness can vary between the original type and the debug type. This
25477 can happen for character types in Ada for instance: the character type
25478 used for code generation can be signed, to be compatible with the C one,
25479 but from a debugger point of view, it must be unsigned. */
25480 bool is_orig_unsigned
= TYPE_UNSIGNED (TREE_TYPE (src
));
25481 bool is_debug_unsigned
= TYPE_UNSIGNED (discr_type
);
25483 if (is_orig_unsigned
!= is_debug_unsigned
)
25484 src
= fold_convert (discr_type
, src
);
25486 if (!(is_debug_unsigned
? tree_fits_uhwi_p (src
) : tree_fits_shwi_p (src
)))
25489 dest
->pos
= is_debug_unsigned
;
25490 if (is_debug_unsigned
)
25491 dest
->v
.uval
= tree_to_uhwi (src
);
25493 dest
->v
.sval
= tree_to_shwi (src
);
25498 /* Try to extract synthetic properties out of VARIANT_PART_DECL, which is a
25499 FIELD_DECL in STRUCT_TYPE that represents a variant part. If unsuccessful,
25500 store NULL_TREE in DISCR_DECL. Otherwise:
25502 - store the discriminant field in STRUCT_TYPE that controls the variant
25503 part to *DISCR_DECL
25505 - put in *DISCR_LISTS_P an array where for each variant, the item
25506 represents the corresponding matching list of discriminant values.
25508 - put in *DISCR_LISTS_LENGTH the number of variants, which is the size of
25511 Note that when the array is allocated (i.e. when the analysis is
25512 successful), it is up to the caller to free the array. */
25515 analyze_variants_discr (tree variant_part_decl
,
25518 dw_discr_list_ref
**discr_lists_p
,
25519 unsigned *discr_lists_length
)
25521 tree variant_part_type
= TREE_TYPE (variant_part_decl
);
25523 dw_discr_list_ref
*discr_lists
;
25526 /* Compute how many variants there are in this variant part. */
25527 *discr_lists_length
= 0;
25528 for (variant
= TYPE_FIELDS (variant_part_type
);
25529 variant
!= NULL_TREE
;
25530 variant
= DECL_CHAIN (variant
))
25531 ++*discr_lists_length
;
25533 *discr_decl
= NULL_TREE
;
25535 = (dw_discr_list_ref
*) xcalloc (*discr_lists_length
,
25536 sizeof (**discr_lists_p
));
25537 discr_lists
= *discr_lists_p
;
25539 /* And then analyze all variants to extract discriminant information for all
25540 of them. This analysis is conservative: as soon as we detect something we
25541 do not support, abort everything and pretend we found nothing. */
25542 for (variant
= TYPE_FIELDS (variant_part_type
), i
= 0;
25543 variant
!= NULL_TREE
;
25544 variant
= DECL_CHAIN (variant
), ++i
)
25546 tree match_expr
= DECL_QUALIFIER (variant
);
25548 /* Now, try to analyze the predicate and deduce a discriminant for
25550 if (match_expr
== boolean_true_node
)
25551 /* Typically happens for the default variant: it matches all cases that
25552 previous variants rejected. Don't output any matching value for
25556 /* The following loop tries to iterate over each discriminant
25557 possibility: single values or ranges. */
25558 while (match_expr
!= NULL_TREE
)
25560 tree next_round_match_expr
;
25561 tree candidate_discr
= NULL_TREE
;
25562 dw_discr_list_ref new_node
= NULL
;
25564 /* Possibilities are matched one after the other by nested
25565 TRUTH_ORIF_EXPR expressions. Process the current possibility and
25566 continue with the rest at next iteration. */
25567 if (TREE_CODE (match_expr
) == TRUTH_ORIF_EXPR
)
25569 next_round_match_expr
= TREE_OPERAND (match_expr
, 0);
25570 match_expr
= TREE_OPERAND (match_expr
, 1);
25573 next_round_match_expr
= NULL_TREE
;
25575 if (match_expr
== boolean_false_node
)
25576 /* This sub-expression matches nothing: just wait for the next
25580 else if (TREE_CODE (match_expr
) == EQ_EXPR
)
25582 /* We are matching: <discr_field> == <integer_cst>
25583 This sub-expression matches a single value. */
25584 tree integer_cst
= TREE_OPERAND (match_expr
, 1);
25587 = analyze_discr_in_predicate (TREE_OPERAND (match_expr
, 0),
25590 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
25591 if (!get_discr_value (integer_cst
,
25592 &new_node
->dw_discr_lower_bound
))
25594 new_node
->dw_discr_range
= false;
25597 else if (TREE_CODE (match_expr
) == TRUTH_ANDIF_EXPR
)
25599 /* We are matching:
25600 <discr_field> > <integer_cst>
25601 && <discr_field> < <integer_cst>.
25602 This sub-expression matches the range of values between the
25603 two matched integer constants. Note that comparisons can be
25604 inclusive or exclusive. */
25605 tree candidate_discr_1
, candidate_discr_2
;
25606 tree lower_cst
, upper_cst
;
25607 bool lower_cst_included
, upper_cst_included
;
25608 tree lower_op
= TREE_OPERAND (match_expr
, 0);
25609 tree upper_op
= TREE_OPERAND (match_expr
, 1);
25611 /* When the comparison is exclusive, the integer constant is not
25612 the discriminant range bound we are looking for: we will have
25613 to increment or decrement it. */
25614 if (TREE_CODE (lower_op
) == GE_EXPR
)
25615 lower_cst_included
= true;
25616 else if (TREE_CODE (lower_op
) == GT_EXPR
)
25617 lower_cst_included
= false;
25621 if (TREE_CODE (upper_op
) == LE_EXPR
)
25622 upper_cst_included
= true;
25623 else if (TREE_CODE (upper_op
) == LT_EXPR
)
25624 upper_cst_included
= false;
25628 /* Extract the discriminant from the first operand and check it
25629 is consistant with the same analysis in the second
25632 = analyze_discr_in_predicate (TREE_OPERAND (lower_op
, 0),
25635 = analyze_discr_in_predicate (TREE_OPERAND (upper_op
, 0),
25637 if (candidate_discr_1
== candidate_discr_2
)
25638 candidate_discr
= candidate_discr_1
;
25642 /* Extract bounds from both. */
25643 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
25644 lower_cst
= TREE_OPERAND (lower_op
, 1);
25645 upper_cst
= TREE_OPERAND (upper_op
, 1);
25647 if (!lower_cst_included
)
25649 = fold_build2 (PLUS_EXPR
, TREE_TYPE (lower_cst
), lower_cst
,
25650 build_int_cst (TREE_TYPE (lower_cst
), 1));
25651 if (!upper_cst_included
)
25653 = fold_build2 (MINUS_EXPR
, TREE_TYPE (upper_cst
), upper_cst
,
25654 build_int_cst (TREE_TYPE (upper_cst
), 1));
25656 if (!get_discr_value (lower_cst
,
25657 &new_node
->dw_discr_lower_bound
)
25658 || !get_discr_value (upper_cst
,
25659 &new_node
->dw_discr_upper_bound
))
25662 new_node
->dw_discr_range
= true;
25665 else if ((candidate_discr
25666 = analyze_discr_in_predicate (match_expr
, struct_type
))
25667 && (TREE_TYPE (candidate_discr
) == boolean_type_node
25668 || TREE_TYPE (TREE_TYPE (candidate_discr
))
25669 == boolean_type_node
))
25671 /* We are matching: <discr_field> for a boolean discriminant.
25672 This sub-expression matches boolean_true_node. */
25673 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
25674 if (!get_discr_value (boolean_true_node
,
25675 &new_node
->dw_discr_lower_bound
))
25677 new_node
->dw_discr_range
= false;
25681 /* Unsupported sub-expression: we cannot determine the set of
25682 matching discriminant values. Abort everything. */
25685 /* If the discriminant info is not consistant with what we saw so
25686 far, consider the analysis failed and abort everything. */
25687 if (candidate_discr
== NULL_TREE
25688 || (*discr_decl
!= NULL_TREE
&& candidate_discr
!= *discr_decl
))
25691 *discr_decl
= candidate_discr
;
25693 if (new_node
!= NULL
)
25695 new_node
->dw_discr_next
= discr_lists
[i
];
25696 discr_lists
[i
] = new_node
;
25698 match_expr
= next_round_match_expr
;
25702 /* If we reach this point, we could match everything we were interested
25707 /* Clean all data structure and return no result. */
25708 free (*discr_lists_p
);
25709 *discr_lists_p
= NULL
;
25710 *discr_decl
= NULL_TREE
;
25713 /* Generate a DIE to represent VARIANT_PART_DECL, a variant part that is part
25714 of STRUCT_TYPE, a record type. This new DIE is emitted as the next child
25717 Variant parts are supposed to be implemented as a FIELD_DECL whose type is a
25718 QUAL_UNION_TYPE: this is the VARIANT_PART_DECL parameter. The members for
25719 this type, which are record types, represent the available variants and each
25720 has a DECL_QUALIFIER attribute. The discriminant and the discriminant
25721 values are inferred from these attributes.
25723 In trees, the offsets for the fields inside these sub-records are relative
25724 to the variant part itself, whereas the corresponding DIEs should have
25725 offset attributes that are relative to the embedding record base address.
25726 This is why the caller must provide a VARIANT_PART_OFFSET expression: it
25727 must be an expression that computes the offset of the variant part to
25728 describe in DWARF. */
25731 gen_variant_part (tree variant_part_decl
, struct vlr_context
*vlr_ctx
,
25732 dw_die_ref context_die
)
25734 const tree variant_part_type
= TREE_TYPE (variant_part_decl
);
25735 tree variant_part_offset
= vlr_ctx
->variant_part_offset
;
25737 /* The FIELD_DECL node in STRUCT_TYPE that acts as the discriminant, or
25738 NULL_TREE if there is no such field. */
25739 tree discr_decl
= NULL_TREE
;
25740 dw_discr_list_ref
*discr_lists
;
25741 unsigned discr_lists_length
= 0;
25744 dw_die_ref dwarf_proc_die
= NULL
;
25745 dw_die_ref variant_part_die
25746 = new_die (DW_TAG_variant_part
, context_die
, variant_part_type
);
25748 equate_decl_number_to_die (variant_part_decl
, variant_part_die
);
25750 analyze_variants_discr (variant_part_decl
, vlr_ctx
->struct_type
,
25751 &discr_decl
, &discr_lists
, &discr_lists_length
);
25753 if (discr_decl
!= NULL_TREE
)
25755 dw_die_ref discr_die
= lookup_decl_die (discr_decl
);
25758 add_AT_die_ref (variant_part_die
, DW_AT_discr
, discr_die
);
25760 /* We have no DIE for the discriminant, so just discard all
25761 discrimimant information in the output. */
25762 discr_decl
= NULL_TREE
;
25765 /* If the offset for this variant part is more complex than a constant,
25766 create a DWARF procedure for it so that we will not have to generate
25767 DWARF expressions for it for each member. */
25768 if (TREE_CODE (variant_part_offset
) != INTEGER_CST
25769 && (dwarf_version
>= 3 || !dwarf_strict
))
25771 struct loc_descr_context ctx
= {
25772 vlr_ctx
->struct_type
, /* context_type */
25773 NULL_TREE
, /* base_decl */
25775 false, /* placeholder_arg */
25776 false, /* placeholder_seen */
25777 false /* strict_signedness */
25779 const tree dwarf_proc_fndecl
25780 = build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, NULL_TREE
,
25781 build_function_type (TREE_TYPE (variant_part_offset
),
25783 const tree dwarf_proc_call
= build_call_expr (dwarf_proc_fndecl
, 0);
25784 const dw_loc_descr_ref dwarf_proc_body
25785 = loc_descriptor_from_tree (variant_part_offset
, 0, &ctx
);
25787 dwarf_proc_die
= new_dwarf_proc_die (dwarf_proc_body
,
25788 dwarf_proc_fndecl
, context_die
);
25789 if (dwarf_proc_die
!= NULL
)
25790 variant_part_offset
= dwarf_proc_call
;
25793 /* Output DIEs for all variants. */
25795 for (tree variant
= TYPE_FIELDS (variant_part_type
);
25796 variant
!= NULL_TREE
;
25797 variant
= DECL_CHAIN (variant
), ++i
)
25799 tree variant_type
= TREE_TYPE (variant
);
25800 dw_die_ref variant_die
;
25802 /* All variants (i.e. members of a variant part) are supposed to be
25803 encoded as structures. Sub-variant parts are QUAL_UNION_TYPE fields
25804 under these records. */
25805 gcc_assert (TREE_CODE (variant_type
) == RECORD_TYPE
);
25807 variant_die
= new_die (DW_TAG_variant
, variant_part_die
, variant_type
);
25808 equate_decl_number_to_die (variant
, variant_die
);
25810 /* Output discriminant values this variant matches, if any. */
25811 if (discr_decl
== NULL
|| discr_lists
[i
] == NULL
)
25812 /* In the case we have discriminant information at all, this is
25813 probably the default variant: as the standard says, don't
25814 output any discriminant value/list attribute. */
25816 else if (discr_lists
[i
]->dw_discr_next
== NULL
25817 && !discr_lists
[i
]->dw_discr_range
)
25818 /* If there is only one accepted value, don't bother outputting a
25820 add_discr_value (variant_die
, &discr_lists
[i
]->dw_discr_lower_bound
);
25822 add_discr_list (variant_die
, discr_lists
[i
]);
25824 for (tree member
= TYPE_FIELDS (variant_type
);
25825 member
!= NULL_TREE
;
25826 member
= DECL_CHAIN (member
))
25828 struct vlr_context vlr_sub_ctx
= {
25829 vlr_ctx
->struct_type
, /* struct_type */
25830 NULL
/* variant_part_offset */
25832 if (is_variant_part (member
))
25834 /* All offsets for fields inside variant parts are relative to
25835 the top-level embedding RECORD_TYPE's base address. On the
25836 other hand, offsets in GCC's types are relative to the
25837 nested-most variant part. So we have to sum offsets each time
25840 vlr_sub_ctx
.variant_part_offset
25841 = fold_build2 (PLUS_EXPR
, TREE_TYPE (variant_part_offset
),
25842 variant_part_offset
, byte_position (member
));
25843 gen_variant_part (member
, &vlr_sub_ctx
, variant_die
);
25847 vlr_sub_ctx
.variant_part_offset
= variant_part_offset
;
25848 gen_decl_die (member
, NULL
, &vlr_sub_ctx
, variant_die
);
25853 free (discr_lists
);
25856 /* Generate a DIE for a class member. */
25859 gen_member_die (tree type
, dw_die_ref context_die
)
25862 tree binfo
= TYPE_BINFO (type
);
25864 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
25866 /* If this is not an incomplete type, output descriptions of each of its
25867 members. Note that as we output the DIEs necessary to represent the
25868 members of this record or union type, we will also be trying to output
25869 DIEs to represent the *types* of those members. However the `type'
25870 function (above) will specifically avoid generating type DIEs for member
25871 types *within* the list of member DIEs for this (containing) type except
25872 for those types (of members) which are explicitly marked as also being
25873 members of this (containing) type themselves. The g++ front- end can
25874 force any given type to be treated as a member of some other (containing)
25875 type by setting the TYPE_CONTEXT of the given (member) type to point to
25876 the TREE node representing the appropriate (containing) type. */
25878 /* First output info about the base classes. */
25879 if (binfo
&& early_dwarf
)
25881 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
25885 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
25886 gen_inheritance_die (base
,
25887 (accesses
? (*accesses
)[i
] : access_public_node
),
25892 /* Now output info about the members. */
25893 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
25895 /* Ignore clones. */
25896 if (DECL_ABSTRACT_ORIGIN (member
))
25899 struct vlr_context vlr_ctx
= { type
, NULL_TREE
};
25900 bool static_inline_p
25902 && TREE_STATIC (member
)
25903 && (lang_hooks
.decls
.decl_dwarf_attribute (member
, DW_AT_inline
)
25906 /* If we thought we were generating minimal debug info for TYPE
25907 and then changed our minds, some of the member declarations
25908 may have already been defined. Don't define them again, but
25909 do put them in the right order. */
25911 if (dw_die_ref child
= lookup_decl_die (member
))
25913 /* Handle inline static data members, which only have in-class
25915 bool splice
= true;
25917 dw_die_ref ref
= NULL
;
25918 if (child
->die_tag
== DW_TAG_variable
25919 && child
->die_parent
== comp_unit_die ())
25921 ref
= get_AT_ref (child
, DW_AT_specification
);
25923 /* For C++17 inline static data members followed by redundant
25924 out of class redeclaration, we might get here with
25925 child being the DIE created for the out of class
25926 redeclaration and with its DW_AT_specification being
25927 the DIE created for in-class definition. We want to
25928 reparent the latter, and don't want to create another
25929 DIE with DW_AT_specification in that case, because
25930 we already have one. */
25933 && ref
->die_tag
== DW_TAG_variable
25934 && ref
->die_parent
== comp_unit_die ()
25935 && get_AT (ref
, DW_AT_specification
) == NULL
)
25939 static_inline_p
= false;
25944 reparent_child (child
, context_die
);
25945 if (dwarf_version
< 5)
25946 child
->die_tag
= DW_TAG_member
;
25950 else if (child
->die_tag
== DW_TAG_enumerator
)
25951 /* Enumerators remain under their enumeration even if
25952 their names are introduced in the enclosing scope. */
25956 splice_child_die (context_die
, child
);
25959 /* Do not generate DWARF for variant parts if we are generating the
25960 corresponding GNAT encodings: DIEs generated for the two schemes
25961 would conflict in our mappings. */
25962 else if (is_variant_part (member
)
25963 && gnat_encodings
!= DWARF_GNAT_ENCODINGS_ALL
)
25965 vlr_ctx
.variant_part_offset
= byte_position (member
);
25966 gen_variant_part (member
, &vlr_ctx
, context_die
);
25970 vlr_ctx
.variant_part_offset
= NULL_TREE
;
25971 gen_decl_die (member
, NULL
, &vlr_ctx
, context_die
);
25974 /* For C++ inline static data members emit immediately a DW_TAG_variable
25975 DIE that will refer to that DW_TAG_member/DW_TAG_variable through
25976 DW_AT_specification. */
25977 if (static_inline_p
)
25979 int old_extern
= DECL_EXTERNAL (member
);
25980 DECL_EXTERNAL (member
) = 0;
25981 gen_decl_die (member
, NULL
, NULL
, comp_unit_die ());
25982 DECL_EXTERNAL (member
) = old_extern
;
25987 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
25988 is set, we pretend that the type was never defined, so we only get the
25989 member DIEs needed by later specification DIEs. */
25992 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
25993 enum debug_info_usage usage
)
25995 if (TREE_ASM_WRITTEN (type
))
25997 /* Fill in the bound of variable-length fields in late dwarf if
25998 still incomplete. */
25999 if (!early_dwarf
&& variably_modified_type_p (type
, NULL
))
26000 for (tree member
= TYPE_FIELDS (type
);
26002 member
= DECL_CHAIN (member
))
26003 fill_variable_array_bounds (TREE_TYPE (member
));
26007 dw_die_ref type_die
= lookup_type_die (type
);
26008 dw_die_ref scope_die
= 0;
26009 bool nested
= false;
26010 bool complete
= (TYPE_SIZE (type
)
26011 && (! TYPE_STUB_DECL (type
)
26012 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
26013 bool ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
26014 complete
= complete
&& should_emit_struct_debug (type
, usage
);
26016 if (type_die
&& ! complete
)
26019 if (TYPE_CONTEXT (type
) != NULL_TREE
26020 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
26021 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
26024 scope_die
= scope_die_for (type
, context_die
);
26026 /* Generate child dies for template parameters. */
26027 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
26028 schedule_generic_params_dies_gen (type
);
26030 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
26031 /* First occurrence of type or toplevel definition of nested class. */
26033 dw_die_ref old_die
= type_die
;
26035 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
26036 ? record_type_tag (type
) : DW_TAG_union_type
,
26038 equate_type_number_to_die (type
, type_die
);
26040 add_AT_specification (type_die
, old_die
);
26042 add_name_attribute (type_die
, type_tag (type
));
26045 remove_AT (type_die
, DW_AT_declaration
);
26047 /* If this type has been completed, then give it a byte_size attribute and
26048 then give a list of members. */
26049 if (complete
&& !ns_decl
)
26051 /* Prevent infinite recursion in cases where the type of some member of
26052 this type is expressed in terms of this type itself. */
26053 TREE_ASM_WRITTEN (type
) = 1;
26054 add_byte_size_attribute (type_die
, type
);
26055 add_alignment_attribute (type_die
, type
);
26056 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
26058 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
26059 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
26062 /* If the first reference to this type was as the return type of an
26063 inline function, then it may not have a parent. Fix this now. */
26064 if (type_die
->die_parent
== NULL
)
26065 add_child_die (scope_die
, type_die
);
26067 gen_member_die (type
, type_die
);
26069 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
26070 if (TYPE_ARTIFICIAL (type
))
26071 add_AT_flag (type_die
, DW_AT_artificial
, 1);
26073 /* GNU extension: Record what type our vtable lives in. */
26074 if (TYPE_VFIELD (type
))
26076 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
26078 gen_type_die (vtype
, context_die
);
26079 add_AT_die_ref (type_die
, DW_AT_containing_type
,
26080 lookup_type_die (vtype
));
26085 add_AT_flag (type_die
, DW_AT_declaration
, 1);
26087 /* We don't need to do this for function-local types. */
26088 if (TYPE_STUB_DECL (type
)
26089 && ! decl_function_context (TYPE_STUB_DECL (type
)))
26090 vec_safe_push (incomplete_types
, type
);
26093 if (get_AT (type_die
, DW_AT_name
))
26094 add_pubtype (type
, type_die
);
26097 /* Generate a DIE for a subroutine _type_. */
26100 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
26102 tree return_type
= TREE_TYPE (type
);
26103 dw_die_ref subr_die
26104 = new_die (DW_TAG_subroutine_type
,
26105 scope_die_for (type
, context_die
), type
);
26107 equate_type_number_to_die (type
, subr_die
);
26108 add_prototyped_attribute (subr_die
, type
);
26109 add_type_attribute (subr_die
, return_type
, TYPE_UNQUALIFIED
, false,
26111 add_alignment_attribute (subr_die
, type
);
26112 gen_formal_types_die (type
, subr_die
);
26114 if (get_AT (subr_die
, DW_AT_name
))
26115 add_pubtype (type
, subr_die
);
26116 if ((dwarf_version
>= 5 || !dwarf_strict
)
26117 && lang_hooks
.types
.type_dwarf_attribute (type
, DW_AT_reference
) != -1)
26118 add_AT_flag (subr_die
, DW_AT_reference
, 1);
26119 if ((dwarf_version
>= 5 || !dwarf_strict
)
26120 && lang_hooks
.types
.type_dwarf_attribute (type
,
26121 DW_AT_rvalue_reference
) != -1)
26122 add_AT_flag (subr_die
, DW_AT_rvalue_reference
, 1);
26125 /* Generate a DIE for a type definition. */
26128 gen_typedef_die (tree decl
, dw_die_ref context_die
)
26130 dw_die_ref type_die
;
26133 if (TREE_ASM_WRITTEN (decl
))
26135 if (DECL_ORIGINAL_TYPE (decl
))
26136 fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl
));
26140 /* As we avoid creating DIEs for local typedefs (see decl_ultimate_origin
26141 checks in process_scope_var and modified_type_die), this should be called
26142 only for original types. */
26143 gcc_assert (decl_ultimate_origin (decl
) == NULL
26144 || decl_ultimate_origin (decl
) == decl
);
26146 TREE_ASM_WRITTEN (decl
) = 1;
26147 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
26149 add_name_and_src_coords_attributes (type_die
, decl
);
26150 if (DECL_ORIGINAL_TYPE (decl
))
26152 type
= DECL_ORIGINAL_TYPE (decl
);
26153 if (type
== error_mark_node
)
26156 gcc_assert (type
!= TREE_TYPE (decl
));
26157 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
26161 type
= TREE_TYPE (decl
);
26162 if (type
== error_mark_node
)
26165 if (is_naming_typedef_decl (TYPE_NAME (type
)))
26167 /* Here, we are in the case of decl being a typedef naming
26168 an anonymous type, e.g:
26169 typedef struct {...} foo;
26170 In that case TREE_TYPE (decl) is not a typedef variant
26171 type and TYPE_NAME of the anonymous type is set to the
26172 TYPE_DECL of the typedef. This construct is emitted by
26175 TYPE is the anonymous struct named by the typedef
26176 DECL. As we need the DW_AT_type attribute of the
26177 DW_TAG_typedef to point to the DIE of TYPE, let's
26178 generate that DIE right away. add_type_attribute
26179 called below will then pick (via lookup_type_die) that
26180 anonymous struct DIE. */
26181 if (!TREE_ASM_WRITTEN (type
))
26182 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
26184 /* This is a GNU Extension. We are adding a
26185 DW_AT_linkage_name attribute to the DIE of the
26186 anonymous struct TYPE. The value of that attribute
26187 is the name of the typedef decl naming the anonymous
26188 struct. This greatly eases the work of consumers of
26189 this debug info. */
26190 add_linkage_name_raw (lookup_type_die (type
), decl
);
26194 add_type_attribute (type_die
, type
, decl_quals (decl
), false,
26197 if (is_naming_typedef_decl (decl
))
26198 /* We want that all subsequent calls to lookup_type_die with
26199 TYPE in argument yield the DW_TAG_typedef we have just
26201 equate_type_number_to_die (type
, type_die
);
26203 add_alignment_attribute (type_die
, TREE_TYPE (decl
));
26205 add_accessibility_attribute (type_die
, decl
);
26207 if (DECL_ABSTRACT_P (decl
))
26208 equate_decl_number_to_die (decl
, type_die
);
26210 if (get_AT (type_die
, DW_AT_name
))
26211 add_pubtype (decl
, type_die
);
26214 /* Generate a DIE for a struct, class, enum or union type. */
26217 gen_tagged_type_die (tree type
,
26218 dw_die_ref context_die
,
26219 enum debug_info_usage usage
,
26222 if (type
== NULL_TREE
26223 || !is_tagged_type (type
))
26226 if (TREE_ASM_WRITTEN (type
))
26228 /* If this is a nested type whose containing class hasn't been written
26229 out yet, writing it out will cover this one, too. This does not apply
26230 to instantiations of member class templates; they need to be added to
26231 the containing class as they are generated. FIXME: This hurts the
26232 idea of combining type decls from multiple TUs, since we can't predict
26233 what set of template instantiations we'll get. */
26234 else if (TYPE_CONTEXT (type
)
26235 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
26236 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
26238 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
26240 if (TREE_ASM_WRITTEN (type
))
26243 /* If that failed, attach ourselves to the stub. */
26244 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
26246 else if (TYPE_CONTEXT (type
) != NULL_TREE
26247 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
26249 /* If this type is local to a function that hasn't been written
26250 out yet, use a NULL context for now; it will be fixed up in
26251 decls_for_scope. */
26252 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
26253 /* A declaration DIE doesn't count; nested types need to go in the
26255 if (context_die
&& is_declaration_die (context_die
))
26256 context_die
= NULL
;
26259 context_die
= declare_in_namespace (type
, context_die
);
26261 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
26263 /* This might have been written out by the call to
26264 declare_in_namespace. */
26265 if (!TREE_ASM_WRITTEN (type
) || reverse
)
26266 gen_enumeration_type_die (type
, context_die
, reverse
);
26269 gen_struct_or_union_type_die (type
, context_die
, usage
);
26271 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
26272 it up if it is ever completed. gen_*_type_die will set it for us
26273 when appropriate. */
26276 /* Generate a type description DIE. */
26279 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
26280 enum debug_info_usage usage
, bool reverse
)
26282 struct array_descr_info info
;
26284 if (type
== NULL_TREE
|| type
== error_mark_node
)
26287 if (flag_checking
&& type
)
26288 verify_type (type
);
26290 if (TYPE_NAME (type
) != NULL_TREE
26291 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
26292 && is_redundant_typedef (TYPE_NAME (type
))
26293 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
26294 /* The DECL of this type is a typedef we don't want to emit debug
26295 info for but we want debug info for its underlying typedef.
26296 This can happen for e.g, the injected-class-name of a C++
26298 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
26300 /* If TYPE is a typedef type variant, let's generate debug info
26301 for the parent typedef which TYPE is a type of. */
26302 if (typedef_variant_p (type
))
26304 if (TREE_ASM_WRITTEN (type
))
26307 tree name
= TYPE_NAME (type
);
26308 tree origin
= decl_ultimate_origin (name
);
26309 if (origin
!= NULL
&& origin
!= name
)
26311 gen_decl_die (origin
, NULL
, NULL
, context_die
);
26315 /* Prevent broken recursion; we can't hand off to the same type. */
26316 gcc_assert (DECL_ORIGINAL_TYPE (name
) != type
);
26318 /* Give typedefs the right scope. */
26319 context_die
= scope_die_for (type
, context_die
);
26321 TREE_ASM_WRITTEN (type
) = 1;
26323 gen_decl_die (name
, NULL
, NULL
, context_die
);
26327 /* If type is an anonymous tagged type named by a typedef, let's
26328 generate debug info for the typedef. */
26329 if (is_naming_typedef_decl (TYPE_NAME (type
)))
26331 /* Give typedefs the right scope. */
26332 context_die
= scope_die_for (type
, context_die
);
26334 gen_decl_die (TYPE_NAME (type
), NULL
, NULL
, context_die
);
26338 if (lang_hooks
.types
.get_debug_type
)
26340 tree debug_type
= lang_hooks
.types
.get_debug_type (type
);
26342 if (debug_type
!= NULL_TREE
&& debug_type
!= type
)
26344 gen_type_die_with_usage (debug_type
, context_die
, usage
, reverse
);
26349 /* We are going to output a DIE to represent the unqualified version
26350 of this type (i.e. without any const or volatile qualifiers) so
26351 get the main variant (i.e. the unqualified version) of this type
26352 now. (Vectors and arrays are special because the debugging info is in the
26353 cloned type itself. Similarly function/method types can contain extra
26354 ref-qualification). */
26355 if (FUNC_OR_METHOD_TYPE_P (type
))
26357 /* For function/method types, can't use type_main_variant here,
26358 because that can have different ref-qualifiers for C++,
26359 but try to canonicalize. */
26360 tree main
= TYPE_MAIN_VARIANT (type
);
26361 for (tree t
= main
; t
; t
= TYPE_NEXT_VARIANT (t
))
26362 if (TYPE_QUALS_NO_ADDR_SPACE (t
) == 0
26363 && check_base_type (t
, main
)
26364 && check_lang_type (t
, type
))
26370 else if (TREE_CODE (type
) != VECTOR_TYPE
26371 && TREE_CODE (type
) != ARRAY_TYPE
)
26372 type
= type_main_variant (type
);
26374 /* If this is an array type with hidden descriptor, handle it first. */
26375 if (!TREE_ASM_WRITTEN (type
)
26376 && lang_hooks
.types
.get_array_descr_info
)
26378 memset (&info
, 0, sizeof (info
));
26379 if (lang_hooks
.types
.get_array_descr_info (type
, &info
))
26381 /* Fortran sometimes emits array types with no dimension. */
26382 gcc_assert (info
.ndimensions
>= 0
26383 && (info
.ndimensions
26384 <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN
));
26385 gen_descr_array_type_die (type
, &info
, context_die
);
26386 TREE_ASM_WRITTEN (type
) = 1;
26391 if (TREE_ASM_WRITTEN (type
) && !reverse
)
26393 /* Variable-length types may be incomplete even if
26394 TREE_ASM_WRITTEN. For such types, fall through to
26395 gen_array_type_die() and possibly fill in
26396 DW_AT_{upper,lower}_bound attributes. */
26397 if ((TREE_CODE (type
) != ARRAY_TYPE
26398 && TREE_CODE (type
) != RECORD_TYPE
26399 && TREE_CODE (type
) != UNION_TYPE
26400 && TREE_CODE (type
) != QUAL_UNION_TYPE
)
26401 || !variably_modified_type_p (type
, NULL
))
26405 switch (TREE_CODE (type
))
26411 case REFERENCE_TYPE
:
26412 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
26413 ensures that the gen_type_die recursion will terminate even if the
26414 type is recursive. Recursive types are possible in Ada. */
26415 /* ??? We could perhaps do this for all types before the switch
26417 TREE_ASM_WRITTEN (type
) = 1;
26419 /* For these types, all that is required is that we output a DIE (or a
26420 set of DIEs) to represent the "basis" type. */
26421 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
26422 DINFO_USAGE_IND_USE
);
26426 /* This code is used for C++ pointer-to-data-member types.
26427 Output a description of the relevant class type. */
26428 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
26429 DINFO_USAGE_IND_USE
);
26431 /* Output a description of the type of the object pointed to. */
26432 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
26433 DINFO_USAGE_IND_USE
);
26435 /* Now output a DIE to represent this pointer-to-data-member type
26437 gen_ptr_to_mbr_type_die (type
, context_die
);
26440 case FUNCTION_TYPE
:
26441 /* Force out return type (in case it wasn't forced out already). */
26442 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
26443 DINFO_USAGE_DIR_USE
);
26444 gen_subroutine_type_die (type
, context_die
);
26448 /* Force out return type (in case it wasn't forced out already). */
26449 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
26450 DINFO_USAGE_DIR_USE
);
26451 gen_subroutine_type_die (type
, context_die
);
26456 gen_array_type_die (type
, context_die
);
26459 case ENUMERAL_TYPE
:
26462 case QUAL_UNION_TYPE
:
26463 gen_tagged_type_die (type
, context_die
, usage
, reverse
);
26470 case FIXED_POINT_TYPE
:
26474 /* No DIEs needed for fundamental types. */
26479 /* Just use DW_TAG_unspecified_type. */
26481 dw_die_ref type_die
= lookup_type_die (type
);
26482 if (type_die
== NULL
)
26484 tree name
= TYPE_IDENTIFIER (type
);
26485 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (),
26487 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
26488 equate_type_number_to_die (type
, type_die
);
26494 if (is_cxx_auto (type
))
26496 tree name
= TYPE_IDENTIFIER (type
);
26497 dw_die_ref
*die
= (name
== get_identifier ("auto")
26498 ? &auto_die
: &decltype_auto_die
);
26501 *die
= new_die (DW_TAG_unspecified_type
,
26502 comp_unit_die (), NULL_TREE
);
26503 add_name_attribute (*die
, IDENTIFIER_POINTER (name
));
26505 equate_type_number_to_die (type
, *die
);
26508 gcc_unreachable ();
26511 TREE_ASM_WRITTEN (type
) = 1;
26515 gen_type_die (tree type
, dw_die_ref context_die
, bool reverse
)
26517 if (type
!= error_mark_node
)
26519 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
, reverse
);
26522 dw_die_ref die
= lookup_type_die (type
);
26529 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
26530 things which are local to the given block. */
26533 gen_block_die (tree stmt
, dw_die_ref context_die
)
26535 int must_output_die
= 0;
26538 /* Ignore blocks that are NULL. */
26539 if (stmt
== NULL_TREE
)
26542 inlined_func
= inlined_function_outer_scope_p (stmt
);
26544 /* If the block is one fragment of a non-contiguous block, do not
26545 process the variables, since they will have been done by the
26546 origin block. Do process subblocks. */
26547 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
26551 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
26552 gen_block_die (sub
, context_die
);
26557 /* Determine if we need to output any Dwarf DIEs at all to represent this
26560 /* The outer scopes for inlinings *must* always be represented. We
26561 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
26562 must_output_die
= 1;
26563 else if (lookup_block_die (stmt
))
26564 /* If we already have a DIE then it was filled early. Meanwhile
26565 we might have pruned all BLOCK_VARS as optimized out but we
26566 still want to generate high/low PC attributes so output it. */
26567 must_output_die
= 1;
26568 else if (TREE_USED (stmt
)
26569 || TREE_ASM_WRITTEN (stmt
))
26571 /* Determine if this block directly contains any "significant"
26572 local declarations which we will need to output DIEs for. */
26573 if (debug_info_level
> DINFO_LEVEL_TERSE
)
26575 /* We are not in terse mode so any local declaration that
26576 is not ignored for debug purposes counts as being a
26577 "significant" one. */
26578 if (BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
26579 must_output_die
= 1;
26581 for (tree var
= BLOCK_VARS (stmt
); var
; var
= DECL_CHAIN (var
))
26582 if (!DECL_IGNORED_P (var
))
26584 must_output_die
= 1;
26588 else if (!dwarf2out_ignore_block (stmt
))
26589 must_output_die
= 1;
26592 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
26593 DIE for any block which contains no significant local declarations at
26594 all. Rather, in such cases we just call `decls_for_scope' so that any
26595 needed Dwarf info for any sub-blocks will get properly generated. Note
26596 that in terse mode, our definition of what constitutes a "significant"
26597 local declaration gets restricted to include only inlined function
26598 instances and local (nested) function definitions. */
26599 if (must_output_die
)
26602 gen_inlined_subroutine_die (stmt
, context_die
);
26604 gen_lexical_block_die (stmt
, context_die
);
26607 decls_for_scope (stmt
, context_die
);
26610 /* Process variable DECL (or variable with origin ORIGIN) within
26611 block STMT and add it to CONTEXT_DIE. */
26613 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
26616 tree decl_or_origin
= decl
? decl
: origin
;
26618 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
26619 die
= lookup_decl_die (decl_or_origin
);
26620 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
)
26622 if (TYPE_DECL_IS_STUB (decl_or_origin
))
26623 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
26625 die
= lookup_decl_die (decl_or_origin
);
26626 /* Avoid re-creating the DIE late if it was optimized as unused early. */
26627 if (! die
&& ! early_dwarf
)
26633 /* Avoid creating DIEs for local typedefs and concrete static variables that
26634 will only be pruned later. */
26635 if ((origin
|| decl_ultimate_origin (decl
))
26636 && (TREE_CODE (decl_or_origin
) == TYPE_DECL
26637 || (VAR_P (decl_or_origin
) && TREE_STATIC (decl_or_origin
))))
26639 origin
= decl_ultimate_origin (decl_or_origin
);
26640 if (decl
&& VAR_P (decl
) && die
!= NULL
)
26642 die
= lookup_decl_die (origin
);
26644 equate_decl_number_to_die (decl
, die
);
26649 if (die
!= NULL
&& die
->die_parent
== NULL
)
26650 add_child_die (context_die
, die
);
26652 if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
26655 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
26656 stmt
, context_die
);
26660 if (decl
&& DECL_P (decl
))
26662 die
= lookup_decl_die (decl
);
26664 /* Early created DIEs do not have a parent as the decls refer
26665 to the function as DECL_CONTEXT rather than the BLOCK. */
26666 if (die
&& die
->die_parent
== NULL
)
26668 gcc_assert (in_lto_p
);
26669 add_child_die (context_die
, die
);
26673 gen_decl_die (decl
, origin
, NULL
, context_die
);
26677 /* Generate all of the decls declared within a given scope and (recursively)
26678 all of its sub-blocks. */
26681 decls_for_scope (tree stmt
, dw_die_ref context_die
, bool recurse
)
26687 /* Ignore NULL blocks. */
26688 if (stmt
== NULL_TREE
)
26691 /* Output the DIEs to represent all of the data objects and typedefs
26692 declared directly within this block but not within any nested
26693 sub-blocks. Also, nested function and tag DIEs have been
26694 generated with a parent of NULL; fix that up now. We don't
26695 have to do this if we're at -g1. */
26696 if (debug_info_level
> DINFO_LEVEL_TERSE
)
26698 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
26699 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
26700 /* BLOCK_NONLOCALIZED_VARs simply generate DIE stubs with abstract
26701 origin - avoid doing this twice as we have no good way to see
26702 if we've done it once already. */
26704 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
26706 decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
26707 if (decl
== current_function_decl
)
26708 /* Ignore declarations of the current function, while they
26709 are declarations, gen_subprogram_die would treat them
26710 as definitions again, because they are equal to
26711 current_function_decl and endlessly recurse. */;
26712 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
26713 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
26715 process_scope_var (stmt
, NULL_TREE
, decl
, context_die
);
26719 /* Even if we're at -g1, we need to process the subblocks in order to get
26720 inlined call information. */
26722 /* Output the DIEs to represent all sub-blocks (and the items declared
26723 therein) of this block. */
26725 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
26727 subblocks
= BLOCK_CHAIN (subblocks
))
26728 gen_block_die (subblocks
, context_die
);
26731 /* Is this a typedef we can avoid emitting? */
26734 is_redundant_typedef (const_tree decl
)
26736 if (TYPE_DECL_IS_STUB (decl
))
26739 if (DECL_ARTIFICIAL (decl
)
26740 && DECL_CONTEXT (decl
)
26741 && is_tagged_type (DECL_CONTEXT (decl
))
26742 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
26743 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
26744 /* Also ignore the artificial member typedef for the class name. */
26750 /* Return TRUE if TYPE is a typedef that names a type for linkage
26751 purposes. This kind of typedefs is produced by the C++ FE for
26754 typedef struct {...} foo;
26756 In that case, there is no typedef variant type produced for foo.
26757 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
26761 is_naming_typedef_decl (const_tree decl
)
26763 if (decl
== NULL_TREE
26764 || TREE_CODE (decl
) != TYPE_DECL
26765 || DECL_NAMELESS (decl
)
26766 || !is_tagged_type (TREE_TYPE (decl
))
26767 || DECL_IS_UNDECLARED_BUILTIN (decl
)
26768 || is_redundant_typedef (decl
)
26769 /* It looks like Ada produces TYPE_DECLs that are very similar
26770 to C++ naming typedefs but that have different
26771 semantics. Let's be specific to c++ for now. */
26775 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
26776 && TYPE_NAME (TREE_TYPE (decl
)) == decl
26777 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
26778 != TYPE_NAME (TREE_TYPE (decl
))));
26781 /* Looks up the DIE for a context. */
26783 static inline dw_die_ref
26784 lookup_context_die (tree context
)
26788 /* Find die that represents this context. */
26789 if (TYPE_P (context
))
26791 context
= TYPE_MAIN_VARIANT (context
);
26792 dw_die_ref ctx
= lookup_type_die (context
);
26795 return strip_naming_typedef (context
, ctx
);
26798 return lookup_decl_die (context
);
26800 return comp_unit_die ();
26803 /* Returns the DIE for a context. */
26805 static inline dw_die_ref
26806 get_context_die (tree context
)
26810 /* Find die that represents this context. */
26811 if (TYPE_P (context
))
26813 context
= TYPE_MAIN_VARIANT (context
);
26814 return strip_naming_typedef (context
, force_type_die (context
));
26817 return force_decl_die (context
);
26819 return comp_unit_die ();
26822 /* Returns the DIE for decl. A DIE will always be returned. */
26825 force_decl_die (tree decl
)
26827 dw_die_ref decl_die
;
26828 unsigned saved_external_flag
;
26829 tree save_fn
= NULL_TREE
;
26830 decl_die
= lookup_decl_die (decl
);
26833 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
26835 decl_die
= lookup_decl_die (decl
);
26839 switch (TREE_CODE (decl
))
26841 case FUNCTION_DECL
:
26842 /* Clear current_function_decl, so that gen_subprogram_die thinks
26843 that this is a declaration. At this point, we just want to force
26844 declaration die. */
26845 save_fn
= current_function_decl
;
26846 current_function_decl
= NULL_TREE
;
26847 gen_subprogram_die (decl
, context_die
);
26848 current_function_decl
= save_fn
;
26852 /* Set external flag to force declaration die. Restore it after
26853 gen_decl_die() call. */
26854 saved_external_flag
= DECL_EXTERNAL (decl
);
26855 DECL_EXTERNAL (decl
) = 1;
26856 gen_decl_die (decl
, NULL
, NULL
, context_die
);
26857 DECL_EXTERNAL (decl
) = saved_external_flag
;
26860 case NAMESPACE_DECL
:
26861 if (dwarf_version
>= 3 || !dwarf_strict
)
26862 dwarf2out_decl (decl
);
26864 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
26865 decl_die
= comp_unit_die ();
26869 /* Enumerators shouldn't need force_decl_die. */
26870 gcc_assert (DECL_CONTEXT (decl
) == NULL_TREE
26871 || TREE_CODE (DECL_CONTEXT (decl
)) != ENUMERAL_TYPE
);
26872 gen_decl_die (decl
, NULL
, NULL
, context_die
);
26875 case TRANSLATION_UNIT_DECL
:
26876 decl_die
= comp_unit_die ();
26880 gcc_unreachable ();
26883 /* We should be able to find the DIE now. */
26885 decl_die
= lookup_decl_die (decl
);
26886 gcc_assert (decl_die
);
26892 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
26893 always returned. */
26896 force_type_die (tree type
)
26898 dw_die_ref type_die
;
26900 type_die
= lookup_type_die (type
);
26903 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
26905 type_die
= modified_type_die (type
, TYPE_QUALS_NO_ADDR_SPACE (type
),
26906 false, context_die
);
26907 gcc_assert (type_die
);
26912 /* Force out any required namespaces to be able to output DECL,
26913 and return the new context_die for it, if it's changed. */
26916 setup_namespace_context (tree thing
, dw_die_ref context_die
)
26918 tree context
= (DECL_P (thing
)
26919 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
26920 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
26921 /* Force out the namespace. */
26922 context_die
= force_decl_die (context
);
26924 return context_die
;
26927 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
26928 type) within its namespace, if appropriate.
26930 For compatibility with older debuggers, namespace DIEs only contain
26931 declarations; all definitions are emitted at CU scope, with
26932 DW_AT_specification pointing to the declaration (like with class
26936 declare_in_namespace (tree thing
, dw_die_ref context_die
)
26938 dw_die_ref ns_context
;
26940 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
26941 return context_die
;
26943 /* External declarations in the local scope only need to be emitted
26944 once, not once in the namespace and once in the scope.
26946 This avoids declaring the `extern' below in the
26947 namespace DIE as well as in the innermost scope:
26960 if (DECL_P (thing
) && DECL_EXTERNAL (thing
) && local_scope_p (context_die
))
26961 return context_die
;
26963 /* If this decl is from an inlined function, then don't try to emit it in its
26964 namespace, as we will get confused. It would have already been emitted
26965 when the abstract instance of the inline function was emitted anyways. */
26966 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
26967 return context_die
;
26969 ns_context
= setup_namespace_context (thing
, context_die
);
26971 if (ns_context
!= context_die
)
26973 if (is_fortran () || is_dlang ())
26975 if (DECL_P (thing
))
26976 gen_decl_die (thing
, NULL
, NULL
, ns_context
);
26978 gen_type_die (thing
, ns_context
);
26980 return context_die
;
26983 /* Generate a DIE for a namespace or namespace alias. */
26986 gen_namespace_die (tree decl
, dw_die_ref context_die
)
26988 dw_die_ref namespace_die
;
26990 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
26991 they are an alias of. */
26992 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
26994 /* Output a real namespace or module. */
26995 context_die
= setup_namespace_context (decl
, comp_unit_die ());
26996 namespace_die
= new_die (is_fortran () || is_dlang ()
26997 ? DW_TAG_module
: DW_TAG_namespace
,
26998 context_die
, decl
);
26999 /* For Fortran modules defined in different CU don't add src coords. */
27000 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
27002 const char *name
= dwarf2_name (decl
, 0);
27004 add_name_attribute (namespace_die
, name
);
27007 add_name_and_src_coords_attributes (namespace_die
, decl
);
27008 if (DECL_EXTERNAL (decl
))
27009 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
27010 equate_decl_number_to_die (decl
, namespace_die
);
27014 /* Output a namespace alias. */
27016 /* Force out the namespace we are an alias of, if necessary. */
27017 dw_die_ref origin_die
27018 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
27020 if (DECL_FILE_SCOPE_P (decl
)
27021 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
27022 context_die
= setup_namespace_context (decl
, comp_unit_die ());
27023 /* Now create the namespace alias DIE. */
27024 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
27025 add_name_and_src_coords_attributes (namespace_die
, decl
);
27026 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
27027 equate_decl_number_to_die (decl
, namespace_die
);
27029 if ((dwarf_version
>= 5 || !dwarf_strict
)
27030 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
27031 DW_AT_export_symbols
) == 1)
27032 add_AT_flag (namespace_die
, DW_AT_export_symbols
, 1);
27034 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
27035 if (want_pubnames ())
27036 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
27039 /* Generate Dwarf debug information for a decl described by DECL.
27040 The return value is currently only meaningful for PARM_DECLs,
27041 for all other decls it returns NULL.
27043 If DECL is a FIELD_DECL, CTX is required: see the comment for VLR_CONTEXT.
27044 It can be NULL otherwise. */
27047 gen_decl_die (tree decl
, tree origin
, struct vlr_context
*ctx
,
27048 dw_die_ref context_die
)
27050 tree decl_or_origin
= decl
? decl
: origin
;
27051 tree class_origin
= NULL
, ultimate_origin
;
27053 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
27056 switch (TREE_CODE (decl_or_origin
))
27062 if (!is_fortran () && !is_ada () && !is_dlang ())
27064 /* The individual enumerators of an enum type get output when we output
27065 the Dwarf representation of the relevant enum type itself. */
27069 /* Emit its type. */
27070 gen_type_die (TREE_TYPE (decl
), context_die
);
27072 /* And its containing namespace. */
27073 context_die
= declare_in_namespace (decl
, context_die
);
27075 gen_const_die (decl
, context_die
);
27078 case FUNCTION_DECL
:
27081 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
27082 on local redeclarations of global functions. That seems broken. */
27083 if (current_function_decl
!= decl
)
27084 /* This is only a declaration. */;
27087 /* We should have abstract copies already and should not generate
27088 stray type DIEs in late LTO dumping. */
27092 /* If we're emitting a clone, emit info for the abstract instance. */
27093 else if (origin
|| DECL_ORIGIN (decl
) != decl
)
27094 dwarf2out_abstract_function (origin
27095 ? DECL_ORIGIN (origin
)
27096 : DECL_ABSTRACT_ORIGIN (decl
));
27098 /* If we're emitting a possibly inlined function emit it as
27099 abstract instance. */
27100 else if (cgraph_function_possibly_inlined_p (decl
)
27101 && ! DECL_ABSTRACT_P (decl
)
27102 && ! class_or_namespace_scope_p (context_die
)
27103 /* dwarf2out_abstract_function won't emit a die if this is just
27104 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
27105 that case, because that works only if we have a die. */
27106 && DECL_INITIAL (decl
) != NULL_TREE
)
27107 dwarf2out_abstract_function (decl
);
27109 /* Otherwise we're emitting the primary DIE for this decl. */
27110 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
27112 /* Before we describe the FUNCTION_DECL itself, make sure that we
27113 have its containing type. */
27115 origin
= decl_class_context (decl
);
27116 if (origin
!= NULL_TREE
)
27117 gen_type_die (origin
, context_die
);
27119 /* And its return type. */
27120 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
27122 /* And its virtual context. */
27123 if (DECL_VINDEX (decl
) != NULL_TREE
)
27124 gen_type_die (DECL_CONTEXT (decl
), context_die
);
27126 /* Make sure we have a member DIE for decl. */
27127 if (origin
!= NULL_TREE
)
27128 gen_type_die_for_member (origin
, decl
, context_die
);
27130 /* And its containing namespace. */
27131 context_die
= declare_in_namespace (decl
, context_die
);
27134 /* Now output a DIE to represent the function itself. */
27136 gen_subprogram_die (decl
, context_die
);
27140 /* If we are in terse mode, don't generate any DIEs to represent any
27141 actual typedefs. */
27142 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
27145 /* In the special case of a TYPE_DECL node representing the declaration
27146 of some type tag, if the given TYPE_DECL is marked as having been
27147 instantiated from some other (original) TYPE_DECL node (e.g. one which
27148 was generated within the original definition of an inline function) we
27149 used to generate a special (abbreviated) DW_TAG_structure_type,
27150 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
27151 should be actually referencing those DIEs, as variable DIEs with that
27152 type would be emitted already in the abstract origin, so it was always
27153 removed during unused type prunning. Don't add anything in this
27155 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
27158 if (is_redundant_typedef (decl
))
27159 gen_type_die (TREE_TYPE (decl
), context_die
);
27161 /* Output a DIE to represent the typedef itself. */
27162 gen_typedef_die (decl
, context_die
);
27166 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
27167 gen_label_die (decl
, context_die
);
27172 /* If we are in terse mode, don't generate any DIEs to represent any
27173 variable declarations or definitions unless it is external. */
27174 if (debug_info_level
< DINFO_LEVEL_TERSE
27175 || (debug_info_level
== DINFO_LEVEL_TERSE
27176 && !TREE_PUBLIC (decl_or_origin
)))
27179 if (debug_info_level
> DINFO_LEVEL_TERSE
)
27181 /* Avoid generating stray type DIEs during late dwarf dumping.
27182 All types have been dumped early. */
27184 /* ??? But in LTRANS we cannot annotate early created variably
27185 modified type DIEs without copying them and adjusting all
27186 references to them. Dump them again as happens for inlining
27187 which copies both the decl and the types. */
27188 /* ??? And even non-LTO needs to re-visit type DIEs to fill
27189 in VLA bound information for example. */
27190 || (decl
&& variably_modified_type_p (TREE_TYPE (decl
),
27191 current_function_decl
)))
27193 /* Output any DIEs that are needed to specify the type of this data
27195 if (decl_by_reference_p (decl_or_origin
))
27196 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
27198 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
27203 /* And its containing type. */
27204 class_origin
= decl_class_context (decl_or_origin
);
27205 if (class_origin
!= NULL_TREE
)
27206 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
27208 /* And its containing namespace. */
27209 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
27213 /* Now output the DIE to represent the data object itself. This gets
27214 complicated because of the possibility that the VAR_DECL really
27215 represents an inlined instance of a formal parameter for an inline
27217 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
27218 if (ultimate_origin
!= NULL_TREE
27219 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
27220 gen_formal_parameter_die (decl
, origin
,
27221 true /* Emit name attribute. */,
27224 gen_variable_die (decl
, origin
, context_die
);
27228 gcc_assert (ctx
!= NULL
&& ctx
->struct_type
!= NULL
);
27229 /* Ignore the nameless fields that are used to skip bits but handle C++
27230 anonymous unions and structs. */
27231 if (DECL_NAME (decl
) != NULL_TREE
27232 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
27233 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
27235 gen_type_die (member_declared_type (decl
), context_die
);
27236 gen_field_die (decl
, ctx
, context_die
);
27241 /* Avoid generating stray type DIEs during late dwarf dumping.
27242 All types have been dumped early. */
27244 /* ??? But in LTRANS we cannot annotate early created variably
27245 modified type DIEs without copying them and adjusting all
27246 references to them. Dump them again as happens for inlining
27247 which copies both the decl and the types. */
27248 /* ??? And even non-LTO needs to re-visit type DIEs to fill
27249 in VLA bound information for example. */
27250 || (decl
&& variably_modified_type_p (TREE_TYPE (decl
),
27251 current_function_decl
)))
27253 if (DECL_BY_REFERENCE (decl_or_origin
))
27254 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
27256 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
27258 return gen_formal_parameter_die (decl
, origin
,
27259 true /* Emit name attribute. */,
27262 case NAMESPACE_DECL
:
27263 if (dwarf_version
>= 3 || !dwarf_strict
)
27264 gen_namespace_die (decl
, context_die
);
27267 case IMPORTED_DECL
:
27268 dwarf2out_imported_module_or_decl_1 (decl
, DECL_NAME (decl
),
27269 DECL_CONTEXT (decl
), context_die
);
27272 case NAMELIST_DECL
:
27273 gen_namelist_decl (DECL_NAME (decl
), context_die
,
27274 NAMELIST_DECL_ASSOCIATED_DECL (decl
));
27278 /* Probably some frontend-internal decl. Assume we don't care. */
27279 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
27286 /* Output initial debug information for global DECL. Called at the
27287 end of the parsing process.
27289 This is the initial debug generation process. As such, the DIEs
27290 generated may be incomplete. A later debug generation pass
27291 (dwarf2out_late_global_decl) will augment the information generated
27292 in this pass (e.g., with complete location info). */
27295 dwarf2out_early_global_decl (tree decl
)
27299 /* gen_decl_die() will set DECL_ABSTRACT because
27300 cgraph_function_possibly_inlined_p() returns true. This is in
27301 turn will cause DW_AT_inline attributes to be set.
27303 This happens because at early dwarf generation, there is no
27304 cgraph information, causing cgraph_function_possibly_inlined_p()
27305 to return true. Trick cgraph_function_possibly_inlined_p()
27306 while we generate dwarf early. */
27307 bool save
= symtab
->global_info_ready
;
27308 symtab
->global_info_ready
= true;
27310 /* We don't handle TYPE_DECLs. If required, they'll be reached via
27311 other DECLs and they can point to template types or other things
27312 that dwarf2out can't handle when done via dwarf2out_decl. */
27313 if (TREE_CODE (decl
) != TYPE_DECL
27314 && TREE_CODE (decl
) != PARM_DECL
)
27316 if (TREE_CODE (decl
) == FUNCTION_DECL
)
27318 tree save_fndecl
= current_function_decl
;
27320 /* For nested functions, make sure we have DIEs for the parents first
27321 so that all nested DIEs are generated at the proper scope in the
27323 tree context
= decl_function_context (decl
);
27324 if (context
!= NULL
)
27326 dw_die_ref context_die
= lookup_decl_die (context
);
27327 current_function_decl
= context
;
27329 /* Avoid emitting DIEs multiple times, but still process CONTEXT
27330 enough so that it lands in its own context. This avoids type
27331 pruning issues later on. */
27332 if (context_die
== NULL
|| is_declaration_die (context_die
))
27333 dwarf2out_early_global_decl (context
);
27336 /* Emit an abstract origin of a function first. This happens
27337 with C++ constructor clones for example and makes
27338 dwarf2out_abstract_function happy which requires the early
27339 DIE of the abstract instance to be present. */
27340 tree origin
= DECL_ABSTRACT_ORIGIN (decl
);
27341 dw_die_ref origin_die
;
27343 /* Do not emit the DIE multiple times but make sure to
27344 process it fully here in case we just saw a declaration. */
27345 && ((origin_die
= lookup_decl_die (origin
)) == NULL
27346 || is_declaration_die (origin_die
)))
27348 current_function_decl
= origin
;
27349 dwarf2out_decl (origin
);
27352 /* Emit the DIE for decl but avoid doing that multiple times. */
27353 dw_die_ref old_die
;
27354 if ((old_die
= lookup_decl_die (decl
)) == NULL
27355 || is_declaration_die (old_die
))
27357 current_function_decl
= decl
;
27358 dwarf2out_decl (decl
);
27361 current_function_decl
= save_fndecl
;
27364 dwarf2out_decl (decl
);
27366 symtab
->global_info_ready
= save
;
27369 /* Return whether EXPR is an expression with the following pattern:
27370 INDIRECT_REF (NOP_EXPR (INTEGER_CST)). */
27373 is_trivial_indirect_ref (tree expr
)
27375 if (expr
== NULL_TREE
|| TREE_CODE (expr
) != INDIRECT_REF
)
27378 tree nop
= TREE_OPERAND (expr
, 0);
27379 if (nop
== NULL_TREE
|| TREE_CODE (nop
) != NOP_EXPR
)
27382 tree int_cst
= TREE_OPERAND (nop
, 0);
27383 return int_cst
!= NULL_TREE
&& TREE_CODE (int_cst
) == INTEGER_CST
;
27386 /* Output debug information for global decl DECL. Called from
27387 toplev.cc after compilation proper has finished. */
27390 dwarf2out_late_global_decl (tree decl
)
27392 /* Fill-in any location information we were unable to determine
27393 on the first pass. */
27396 dw_die_ref die
= lookup_decl_die (decl
);
27398 /* We may have to generate full debug late for LTO in case debug
27399 was not enabled at compile-time or the target doesn't support
27400 the LTO early debug scheme. */
27401 if (! die
&& in_lto_p
27402 /* Function scope variables are emitted when emitting the
27403 DIE for the function. */
27404 && ! local_function_static (decl
))
27405 dwarf2out_decl (decl
);
27408 /* We get called via the symtab code invoking late_global_decl
27409 for symbols that are optimized out.
27411 Do not add locations for those, except if they have a
27412 DECL_VALUE_EXPR, in which case they are relevant for debuggers.
27413 Still don't add a location if the DECL_VALUE_EXPR is not a trivial
27414 INDIRECT_REF expression, as this could generate relocations to
27415 text symbols in LTO object files, which is invalid. */
27416 varpool_node
*node
= varpool_node::get (decl
);
27417 if ((! node
|| ! node
->definition
)
27418 && ! (DECL_HAS_VALUE_EXPR_P (decl
)
27419 && is_trivial_indirect_ref (DECL_VALUE_EXPR (decl
))))
27420 tree_add_const_value_attribute_for_decl (die
, decl
);
27422 add_location_or_const_value_attribute (die
, decl
, false);
27427 /* Output debug information for type decl DECL. Called from toplev.cc
27428 and from language front ends (to record built-in types). */
27430 dwarf2out_type_decl (tree decl
, int local
)
27435 dwarf2out_decl (decl
);
27439 /* Output debug information for imported module or decl DECL.
27440 NAME is non-NULL name in the lexical block if the decl has been renamed.
27441 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
27442 that DECL belongs to.
27443 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
27445 dwarf2out_imported_module_or_decl_1 (tree decl
,
27447 tree lexical_block
,
27448 dw_die_ref lexical_block_die
)
27450 expanded_location xloc
;
27451 dw_die_ref imported_die
= NULL
;
27452 dw_die_ref at_import_die
;
27454 if (TREE_CODE (decl
) == IMPORTED_DECL
)
27456 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
27457 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
27461 xloc
= expand_location (input_location
);
27463 if (TREE_CODE (decl
) == TYPE_DECL
)
27465 at_import_die
= force_type_die (TREE_TYPE (decl
));
27466 /* For namespace N { typedef void T; } using N::T; base_type_die
27467 returns NULL, but DW_TAG_imported_declaration requires
27468 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
27469 if (!at_import_die
)
27471 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
27472 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
27473 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
27474 gcc_assert (at_import_die
);
27479 at_import_die
= lookup_decl_die (decl
);
27480 if (!at_import_die
)
27482 /* If we're trying to avoid duplicate debug info, we may not have
27483 emitted the member decl for this field. Emit it now. */
27484 if (TREE_CODE (decl
) == FIELD_DECL
)
27486 tree type
= DECL_CONTEXT (decl
);
27488 if (TYPE_CONTEXT (type
)
27489 && TYPE_P (TYPE_CONTEXT (type
))
27490 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
27491 DINFO_USAGE_DIR_USE
))
27493 gen_type_die_for_member (type
, decl
,
27494 get_context_die (TYPE_CONTEXT (type
)));
27496 if (TREE_CODE (decl
) == CONST_DECL
)
27498 /* Individual enumerators of an enum type do not get output here
27499 (see gen_decl_die), so we cannot call force_decl_die. */
27500 if (!is_fortran () && !is_ada () && !is_dlang ())
27503 if (TREE_CODE (decl
) == NAMELIST_DECL
)
27504 at_import_die
= gen_namelist_decl (DECL_NAME (decl
),
27505 get_context_die (DECL_CONTEXT (decl
)),
27508 at_import_die
= force_decl_die (decl
);
27512 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
27514 if (dwarf_version
>= 3 || !dwarf_strict
)
27515 imported_die
= new_die (DW_TAG_imported_module
,
27522 imported_die
= new_die (DW_TAG_imported_declaration
,
27526 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
27527 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
27528 if (debug_column_info
&& xloc
.column
)
27529 add_AT_unsigned (imported_die
, DW_AT_decl_column
, xloc
.column
);
27531 add_AT_string (imported_die
, DW_AT_name
,
27532 IDENTIFIER_POINTER (name
));
27533 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
27536 /* Output debug information for imported module or decl DECL.
27537 NAME is non-NULL name in context if the decl has been renamed.
27538 CHILD is true if decl is one of the renamed decls as part of
27539 importing whole module.
27540 IMPLICIT is set if this hook is called for an implicit import
27541 such as inline namespace. */
27544 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
27545 bool child
, bool implicit
)
27547 /* dw_die_ref at_import_die; */
27548 dw_die_ref scope_die
;
27550 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
27555 /* For DWARF5, just DW_AT_export_symbols on the DW_TAG_namespace
27556 should be enough, for DWARF4 and older even if we emit as extension
27557 DW_AT_export_symbols add the implicit DW_TAG_imported_module anyway
27558 for the benefit of consumers unaware of DW_AT_export_symbols. */
27560 && dwarf_version
>= 5
27561 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
27562 DW_AT_export_symbols
) == 1)
27567 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
27568 We need decl DIE for reference and scope die. First, get DIE for the decl
27571 /* Get the scope die for decl context. Use comp_unit_die for global module
27572 or decl. If die is not found for non globals, force new die. */
27574 && TYPE_P (context
)
27575 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
27578 scope_die
= get_context_die (context
);
27582 /* DW_TAG_imported_module was introduced in the DWARFv3 specification, so
27583 there is nothing we can do, here. */
27584 if (dwarf_version
< 3 && dwarf_strict
)
27587 gcc_assert (scope_die
->die_child
);
27588 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
27589 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
27590 scope_die
= scope_die
->die_child
;
27593 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
27594 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
27597 /* Output debug information for namelists. */
27600 gen_namelist_decl (tree name
, dw_die_ref scope_die
, tree item_decls
)
27602 dw_die_ref nml_die
, nml_item_die
, nml_item_ref_die
;
27606 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
27609 gcc_assert (scope_die
!= NULL
);
27610 nml_die
= new_die (DW_TAG_namelist
, scope_die
, NULL
);
27611 add_AT_string (nml_die
, DW_AT_name
, IDENTIFIER_POINTER (name
));
27613 /* If there are no item_decls, we have a nondefining namelist, e.g.
27614 with USE association; hence, set DW_AT_declaration. */
27615 if (item_decls
== NULL_TREE
)
27617 add_AT_flag (nml_die
, DW_AT_declaration
, 1);
27621 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls
), i
, value
)
27623 nml_item_ref_die
= lookup_decl_die (value
);
27624 if (!nml_item_ref_die
)
27625 nml_item_ref_die
= force_decl_die (value
);
27627 nml_item_die
= new_die (DW_TAG_namelist_item
, nml_die
, NULL
);
27628 add_AT_die_ref (nml_item_die
, DW_AT_namelist_item
, nml_item_ref_die
);
27634 /* Write the debugging output for DECL and return the DIE. */
27637 dwarf2out_decl (tree decl
)
27639 dw_die_ref context_die
= comp_unit_die ();
27641 switch (TREE_CODE (decl
))
27646 case FUNCTION_DECL
:
27647 /* If we're a nested function, initially use a parent of NULL; if we're
27648 a plain function, this will be fixed up in decls_for_scope. If
27649 we're a method, it will be ignored, since we already have a DIE.
27650 Avoid doing this late though since clones of class methods may
27651 otherwise end up in limbo and create type DIEs late. */
27653 && decl_function_context (decl
)
27654 /* But if we're in terse mode, we don't care about scope. */
27655 && debug_info_level
> DINFO_LEVEL_TERSE
)
27656 context_die
= NULL
;
27660 /* For local statics lookup proper context die. */
27661 if (local_function_static (decl
))
27662 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
27664 /* If we are in terse mode, don't generate any DIEs to represent any
27665 variable declarations or definitions unless it is external. */
27666 if (debug_info_level
< DINFO_LEVEL_TERSE
27667 || (debug_info_level
== DINFO_LEVEL_TERSE
27668 && !TREE_PUBLIC (decl
)))
27673 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
27675 if (!is_fortran () && !is_ada () && !is_dlang ())
27677 if (TREE_STATIC (decl
) && decl_function_context (decl
))
27678 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
27681 case NAMESPACE_DECL
:
27682 case IMPORTED_DECL
:
27683 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
27685 if (lookup_decl_die (decl
) != NULL
)
27690 /* Don't emit stubs for types unless they are needed by other DIEs. */
27691 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
27694 /* Don't bother trying to generate any DIEs to represent any of the
27695 normal built-in types for the language we are compiling. */
27696 if (DECL_IS_UNDECLARED_BUILTIN (decl
))
27699 /* If we are in terse mode, don't generate any DIEs for types. */
27700 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
27703 /* If we're a function-scope tag, initially use a parent of NULL;
27704 this will be fixed up in decls_for_scope. */
27705 if (decl_function_context (decl
))
27706 context_die
= NULL
;
27710 case NAMELIST_DECL
:
27717 gen_decl_die (decl
, NULL
, NULL
, context_die
);
27721 dw_die_ref die
= lookup_decl_die (decl
);
27727 /* Write the debugging output for DECL. */
27730 dwarf2out_function_decl (tree decl
)
27732 dwarf2out_decl (decl
);
27733 call_arg_locations
= NULL
;
27734 call_arg_loc_last
= NULL
;
27735 call_site_count
= -1;
27736 tail_call_site_count
= -1;
27737 decl_loc_table
->empty ();
27738 cached_dw_loc_list_table
->empty ();
27741 /* Output a marker (i.e. a label) for the beginning of the generated code for
27742 a lexical block. */
27745 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
27746 unsigned int blocknum
)
27748 switch_to_section (current_function_section ());
27749 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
27752 /* Output a marker (i.e. a label) for the end of the generated code for a
27756 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
27758 switch_to_section (current_function_section ());
27759 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
27762 /* Returns true if it is appropriate not to emit any debugging
27763 information for BLOCK, because it doesn't contain any instructions.
27765 Don't allow this for blocks with nested functions or local classes
27766 as we would end up with orphans, and in the presence of scheduling
27767 we may end up calling them anyway. */
27770 dwarf2out_ignore_block (const_tree block
)
27775 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
27776 if (TREE_CODE (decl
) == FUNCTION_DECL
27777 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
27779 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
27781 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
27782 if (TREE_CODE (decl
) == FUNCTION_DECL
27783 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
27790 /* Hash table routines for file_hash. */
27793 dwarf_file_hasher::equal (dwarf_file_data
*p1
, const char *p2
)
27795 return filename_cmp (p1
->key
, p2
) == 0;
27799 dwarf_file_hasher::hash (dwarf_file_data
*p
)
27801 return htab_hash_string (p
->key
);
27804 /* Lookup FILE_NAME (in the list of filenames that we know about here in
27805 dwarf2out.cc) and return its "index". The index of each (known) filename is
27806 just a unique number which is associated with only that one filename. We
27807 need such numbers for the sake of generating labels (in the .debug_sfnames
27808 section) and references to those files numbers (in the .debug_srcinfo
27809 and .debug_macinfo sections). If the filename given as an argument is not
27810 found in our current list, add it to the list and assign it the next
27811 available unique index number. */
27813 static struct dwarf_file_data
*
27814 lookup_filename (const char *file_name
)
27816 struct dwarf_file_data
* created
;
27822 file_name
= "<stdin>";
27824 dwarf_file_data
**slot
27825 = file_table
->find_slot_with_hash (file_name
, htab_hash_string (file_name
),
27830 created
= ggc_alloc
<dwarf_file_data
> ();
27831 created
->key
= file_name
;
27832 created
->filename
= remap_debug_filename (file_name
);
27833 created
->emitted_number
= 0;
27838 /* If the assembler will construct the file table, then translate the compiler
27839 internal file table number into the assembler file table number, and emit
27840 a .file directive if we haven't already emitted one yet. The file table
27841 numbers are different because we prune debug info for unused variables and
27842 types, which may include filenames. */
27845 maybe_emit_file (struct dwarf_file_data
* fd
)
27847 if (! fd
->emitted_number
)
27849 if (last_emitted_file
)
27850 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
27852 fd
->emitted_number
= 1;
27853 last_emitted_file
= fd
;
27855 if (output_asm_line_debug_info ())
27857 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
27858 output_quoted_string (asm_out_file
, fd
->filename
);
27859 fputc ('\n', asm_out_file
);
27863 return fd
->emitted_number
;
27866 /* Schedule generation of a DW_AT_const_value attribute to DIE.
27867 That generation should happen after function debug info has been
27868 generated. The value of the attribute is the constant value of ARG. */
27871 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
27873 die_arg_entry entry
;
27878 gcc_assert (early_dwarf
);
27880 if (!tmpl_value_parm_die_table
)
27881 vec_alloc (tmpl_value_parm_die_table
, 32);
27885 vec_safe_push (tmpl_value_parm_die_table
, entry
);
27888 /* Return TRUE if T is an instance of generic type, FALSE
27892 generic_type_p (tree t
)
27894 if (t
== NULL_TREE
|| !TYPE_P (t
))
27896 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
27899 /* Schedule the generation of the generic parameter dies for the
27900 instance of generic type T. The proper generation itself is later
27901 done by gen_scheduled_generic_parms_dies. */
27904 schedule_generic_params_dies_gen (tree t
)
27906 if (!generic_type_p (t
))
27909 gcc_assert (early_dwarf
);
27911 if (!generic_type_instances
)
27912 vec_alloc (generic_type_instances
, 256);
27914 vec_safe_push (generic_type_instances
, t
);
27917 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
27918 by append_entry_to_tmpl_value_parm_die_table. This function must
27919 be called after function DIEs have been generated. */
27922 gen_remaining_tmpl_value_param_die_attribute (void)
27924 if (tmpl_value_parm_die_table
)
27929 /* We do this in two phases - first get the cases we can
27930 handle during early-finish, preserving those we cannot
27931 (containing symbolic constants where we don't yet know
27932 whether we are going to output the referenced symbols).
27933 For those we try again at late-finish. */
27935 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
27937 if (!e
->die
->removed
27938 && !tree_add_const_value_attribute (e
->die
, e
->arg
))
27940 dw_loc_descr_ref loc
= NULL
;
27942 && (dwarf_version
>= 5 || !dwarf_strict
))
27943 loc
= loc_descriptor_from_tree (e
->arg
, 2, NULL
);
27945 add_AT_loc (e
->die
, DW_AT_location
, loc
);
27947 (*tmpl_value_parm_die_table
)[j
++] = *e
;
27950 tmpl_value_parm_die_table
->truncate (j
);
27954 /* Generate generic parameters DIEs for instances of generic types
27955 that have been previously scheduled by
27956 schedule_generic_params_dies_gen. This function must be called
27957 after all the types of the CU have been laid out. */
27960 gen_scheduled_generic_parms_dies (void)
27965 if (!generic_type_instances
)
27968 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
27969 if (COMPLETE_TYPE_P (t
))
27970 gen_generic_params_dies (t
);
27972 generic_type_instances
= NULL
;
27976 /* Replace DW_AT_name for the decl with name. */
27979 dwarf2out_set_name (tree decl
, tree name
)
27982 dw_attr_node
*attr
;
27985 die
= TYPE_SYMTAB_DIE (decl
);
27989 dname
= dwarf2_name (name
, 0);
27993 attr
= get_AT (die
, DW_AT_name
);
27996 struct indirect_string_node
*node
;
27998 node
= find_AT_string (dname
);
27999 /* replace the string. */
28000 attr
->dw_attr_val
.v
.val_str
= node
;
28004 add_name_attribute (die
, dname
);
28007 /* True if before or during processing of the first function being emitted. */
28008 static bool in_first_function_p
= true;
28009 /* True if loc_note during dwarf2out_var_location call might still be
28010 before first real instruction at address equal to .Ltext0. */
28011 static bool maybe_at_text_label_p
= true;
28012 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
28013 static unsigned int first_loclabel_num_not_at_text_label
;
28015 /* Look ahead for a real insn. */
28018 dwarf2out_next_real_insn (rtx_insn
*loc_note
)
28020 rtx_insn
*next_real
= NEXT_INSN (loc_note
);
28023 if (INSN_P (next_real
))
28026 next_real
= NEXT_INSN (next_real
);
28031 /* Called by the final INSN scan whenever we see a var location. We
28032 use it to drop labels in the right places, and throw the location in
28033 our lookup table. */
28036 dwarf2out_var_location (rtx_insn
*loc_note
)
28038 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
28039 struct var_loc_node
*newloc
;
28040 rtx_insn
*next_real
;
28041 rtx_insn
*call_insn
= NULL
;
28042 static const char *last_label
;
28043 static const char *last_postcall_label
;
28044 static bool last_in_cold_section_p
;
28045 static rtx_insn
*expected_next_loc_note
;
28048 var_loc_view view
= 0;
28050 if (!NOTE_P (loc_note
))
28052 if (CALL_P (loc_note
))
28054 maybe_reset_location_view (loc_note
, cur_line_info_table
);
28056 if (SIBLING_CALL_P (loc_note
))
28057 tail_call_site_count
++;
28058 if (find_reg_note (loc_note
, REG_CALL_ARG_LOCATION
, NULL_RTX
))
28060 call_insn
= loc_note
;
28064 next_real
= dwarf2out_next_real_insn (call_insn
);
28065 cached_next_real_insn
= NULL
;
28068 if (optimize
== 0 && !flag_var_tracking
)
28070 /* When the var-tracking pass is not running, there is no note
28071 for indirect calls whose target is compile-time known. In this
28072 case, process such calls specifically so that we generate call
28073 sites for them anyway. */
28074 rtx x
= PATTERN (loc_note
);
28075 if (GET_CODE (x
) == PARALLEL
)
28076 x
= XVECEXP (x
, 0, 0);
28077 if (GET_CODE (x
) == SET
)
28079 if (GET_CODE (x
) == CALL
)
28082 || GET_CODE (XEXP (x
, 0)) != SYMBOL_REF
28083 || !SYMBOL_REF_DECL (XEXP (x
, 0))
28084 || (TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0)))
28087 call_insn
= loc_note
;
28091 next_real
= dwarf2out_next_real_insn (call_insn
);
28092 cached_next_real_insn
= NULL
;
28097 else if (!debug_variable_location_views
)
28098 gcc_unreachable ();
28100 maybe_reset_location_view (loc_note
, cur_line_info_table
);
28105 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
28106 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
28109 /* Optimize processing a large consecutive sequence of location
28110 notes so we don't spend too much time in next_real_insn. If the
28111 next insn is another location note, remember the next_real_insn
28112 calculation for next time. */
28113 next_real
= cached_next_real_insn
;
28116 if (expected_next_loc_note
!= loc_note
)
28121 next_real
= dwarf2out_next_real_insn (loc_note
);
28125 rtx_insn
*next_note
= NEXT_INSN (loc_note
);
28126 while (next_note
!= next_real
)
28128 if (! next_note
->deleted ()
28129 && NOTE_P (next_note
)
28130 && NOTE_KIND (next_note
) == NOTE_INSN_VAR_LOCATION
)
28132 next_note
= NEXT_INSN (next_note
);
28135 if (next_note
== next_real
)
28136 cached_next_real_insn
= NULL
;
28139 expected_next_loc_note
= next_note
;
28140 cached_next_real_insn
= next_real
;
28144 cached_next_real_insn
= NULL
;
28146 /* If there are no instructions which would be affected by this note,
28147 don't do anything. */
28149 && next_real
== NULL_RTX
28150 && !NOTE_DURING_CALL_P (loc_note
))
28155 if (next_real
== NULL_RTX
)
28156 next_real
= get_last_insn ();
28158 /* If there were any real insns between note we processed last time
28159 and this note (or if it is the first note), clear
28160 last_{,postcall_}label so that they are not reused this time. */
28161 if (last_var_location_insn
== NULL_RTX
28162 || last_var_location_insn
!= next_real
28163 || last_in_cold_section_p
!= in_cold_section_p
)
28166 last_postcall_label
= NULL
;
28172 = NOTE_DURING_CALL_P (loc_note
) ? last_postcall_label
: last_label
;
28173 view
= cur_line_info_table
->view
;
28174 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
28175 newloc
= add_var_loc_to_decl (decl
, loc_note
, label
, view
);
28176 if (newloc
== NULL
)
28185 /* If there were no real insns between note we processed last time
28186 and this note, use the label we emitted last time. Otherwise
28187 create a new label and emit it. */
28188 if (last_label
== NULL
)
28190 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
28191 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
28193 last_label
= ggc_strdup (loclabel
);
28194 /* See if loclabel might be equal to .Ltext0. If yes,
28195 bump first_loclabel_num_not_at_text_label. */
28196 if (!have_multiple_function_sections
28197 && in_first_function_p
28198 && maybe_at_text_label_p
)
28200 static rtx_insn
*last_start
;
28202 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
28203 if (insn
== last_start
)
28205 else if (!NONDEBUG_INSN_P (insn
))
28209 rtx body
= PATTERN (insn
);
28210 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
28212 /* Inline asm could occupy zero bytes. */
28213 else if (GET_CODE (body
) == ASM_INPUT
28214 || asm_noperands (body
) >= 0)
28216 #ifdef HAVE_ATTR_length /* ??? We don't include insn-attr.h. */
28217 else if (HAVE_ATTR_length
&& get_attr_min_length (insn
) == 0)
28222 /* Assume insn has non-zero length. */
28223 maybe_at_text_label_p
= false;
28227 if (maybe_at_text_label_p
)
28229 last_start
= loc_note
;
28230 first_loclabel_num_not_at_text_label
= loclabel_num
;
28235 gcc_assert ((loc_note
== NULL_RTX
&& call_insn
!= NULL_RTX
)
28236 || (loc_note
!= NULL_RTX
&& call_insn
== NULL_RTX
));
28240 struct call_arg_loc_node
*ca_loc
28241 = ggc_cleared_alloc
<call_arg_loc_node
> ();
28242 rtx_insn
*prev
= call_insn
;
28244 ca_loc
->call_arg_loc_note
28245 = find_reg_note (call_insn
, REG_CALL_ARG_LOCATION
, NULL_RTX
);
28246 ca_loc
->next
= NULL
;
28247 ca_loc
->label
= last_label
;
28250 || (NONJUMP_INSN_P (prev
)
28251 && GET_CODE (PATTERN (prev
)) == SEQUENCE
28252 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
28253 if (!CALL_P (prev
))
28254 prev
= as_a
<rtx_sequence
*> (PATTERN (prev
))->insn (0);
28255 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
28257 /* Look for a SYMBOL_REF in the "prev" instruction. */
28258 rtx x
= get_call_rtx_from (prev
);
28261 /* Try to get the call symbol, if any. */
28262 if (MEM_P (XEXP (x
, 0)))
28264 /* First, look for a memory access to a symbol_ref. */
28265 if (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
28266 && SYMBOL_REF_DECL (XEXP (x
, 0))
28267 && TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0))) == FUNCTION_DECL
)
28268 ca_loc
->symbol_ref
= XEXP (x
, 0);
28269 /* Otherwise, look at a compile-time known user-level function
28273 && TREE_CODE (MEM_EXPR (x
)) == FUNCTION_DECL
)
28274 ca_loc
->symbol_ref
= XEXP (DECL_RTL (MEM_EXPR (x
)), 0);
28277 ca_loc
->block
= insn_scope (prev
);
28278 if (call_arg_locations
)
28279 call_arg_loc_last
->next
= ca_loc
;
28281 call_arg_locations
= ca_loc
;
28282 call_arg_loc_last
= ca_loc
;
28284 else if (loc_note
!= NULL_RTX
&& !NOTE_DURING_CALL_P (loc_note
))
28286 newloc
->label
= last_label
;
28287 newloc
->view
= view
;
28291 if (!last_postcall_label
)
28293 sprintf (loclabel
, "%s-1", last_label
);
28294 last_postcall_label
= ggc_strdup (loclabel
);
28296 newloc
->label
= last_postcall_label
;
28297 /* ??? This view is at last_label, not last_label-1, but we
28298 could only assume view at last_label-1 is zero if we could
28299 assume calls always have length greater than one. This is
28300 probably true in general, though there might be a rare
28301 exception to this rule, e.g. if a call insn is optimized out
28302 by target magic. Then, even the -1 in the label will be
28303 wrong, which might invalidate the range. Anyway, using view,
28304 though technically possibly incorrect, will work as far as
28305 ranges go: since L-1 is in the middle of the call insn,
28306 (L-1).0 and (L-1).V shouldn't make any difference, and having
28307 the loclist entry refer to the .loc entry might be useful, so
28308 leave it like this. */
28309 newloc
->view
= view
;
28312 if (var_loc_p
&& flag_debug_asm
)
28314 const char *name
, *sep
, *patstr
;
28315 if (decl
&& DECL_NAME (decl
))
28316 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
28319 if (NOTE_VAR_LOCATION_LOC (loc_note
))
28322 patstr
= str_pattern_slim (NOTE_VAR_LOCATION_LOC (loc_note
));
28329 fprintf (asm_out_file
, "\t%s DEBUG %s%s%s\n", ASM_COMMENT_START
,
28330 name
, sep
, patstr
);
28333 last_var_location_insn
= next_real
;
28334 last_in_cold_section_p
= in_cold_section_p
;
28337 /* Check whether BLOCK, a lexical block, is nested within OUTER, or is
28338 OUTER itself. If BOTHWAYS, check not only that BLOCK can reach
28339 OUTER through BLOCK_SUPERCONTEXT links, but also that there is a
28340 path from OUTER to BLOCK through BLOCK_SUBBLOCKs and
28341 BLOCK_FRAGMENT_ORIGIN links. */
28343 block_within_block_p (tree block
, tree outer
, bool bothways
)
28345 if (block
== outer
)
28348 /* Quickly check that OUTER is up BLOCK's supercontext chain. */
28349 for (tree context
= BLOCK_SUPERCONTEXT (block
);
28351 context
= BLOCK_SUPERCONTEXT (context
))
28352 if (!context
|| TREE_CODE (context
) != BLOCK
)
28358 /* Now check that each block is actually referenced by its
28360 for (tree context
= BLOCK_SUPERCONTEXT (block
); ;
28361 context
= BLOCK_SUPERCONTEXT (context
))
28363 if (BLOCK_FRAGMENT_ORIGIN (context
))
28365 gcc_assert (!BLOCK_SUBBLOCKS (context
));
28366 context
= BLOCK_FRAGMENT_ORIGIN (context
);
28368 for (tree sub
= BLOCK_SUBBLOCKS (context
);
28370 sub
= BLOCK_CHAIN (sub
))
28373 if (context
== outer
)
28380 /* Called during final while assembling the marker of the entry point
28381 for an inlined function. */
28384 dwarf2out_inline_entry (tree block
)
28386 gcc_assert (debug_inline_points
);
28388 /* If we can't represent it, don't bother. */
28389 if (!(dwarf_version
>= 3 || !dwarf_strict
))
28392 gcc_assert (DECL_P (block_ultimate_origin (block
)));
28394 /* Sanity check the block tree. This would catch a case in which
28395 BLOCK got removed from the tree reachable from the outermost
28396 lexical block, but got retained in markers. It would still link
28397 back to its parents, but some ancestor would be missing a link
28398 down the path to the sub BLOCK. If the block got removed, its
28399 BLOCK_NUMBER will not be a usable value. */
28401 gcc_assert (block_within_block_p (block
,
28402 DECL_INITIAL (current_function_decl
),
28405 gcc_assert (inlined_function_outer_scope_p (block
));
28406 gcc_assert (!lookup_block_die (block
));
28408 if (BLOCK_FRAGMENT_ORIGIN (block
))
28409 block
= BLOCK_FRAGMENT_ORIGIN (block
);
28410 /* Can the entry point ever not be at the beginning of an
28411 unfragmented lexical block? */
28412 else if (!(BLOCK_FRAGMENT_CHAIN (block
)
28413 || (cur_line_info_table
28414 && !ZERO_VIEW_P (cur_line_info_table
->view
))))
28417 if (!inline_entry_data_table
)
28418 inline_entry_data_table
28419 = hash_table
<inline_entry_data_hasher
>::create_ggc (10);
28422 inline_entry_data
**iedp
28423 = inline_entry_data_table
->find_slot_with_hash (block
,
28424 htab_hash_pointer (block
),
28427 /* ??? Ideally, we'd record all entry points for the same inlined
28428 function (some may have been duplicated by e.g. unrolling), but
28429 we have no way to represent that ATM. */
28432 inline_entry_data
*ied
= *iedp
= ggc_cleared_alloc
<inline_entry_data
> ();
28433 ied
->block
= block
;
28434 ied
->label_pfx
= BLOCK_INLINE_ENTRY_LABEL
;
28435 ied
->label_num
= BLOCK_NUMBER (block
);
28436 if (cur_line_info_table
)
28437 ied
->view
= cur_line_info_table
->view
;
28439 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_INLINE_ENTRY_LABEL
,
28440 BLOCK_NUMBER (block
));
28443 /* Called from finalize_size_functions for size functions so that their body
28444 can be encoded in the debug info to describe the layout of variable-length
28448 dwarf2out_size_function (tree decl
)
28451 function_to_dwarf_procedure (decl
);
28454 /* Note in one location list that text section has changed. */
28457 var_location_switch_text_section_1 (var_loc_list
**slot
, void *)
28459 var_loc_list
*list
= *slot
;
28461 list
->last_before_switch
28462 = list
->last
->next
? list
->last
->next
: list
->last
;
28466 /* Note in all location lists that text section has changed. */
28469 var_location_switch_text_section (void)
28471 if (decl_loc_table
== NULL
)
28474 decl_loc_table
->traverse
<void *, var_location_switch_text_section_1
> (NULL
);
28477 /* Create a new line number table. */
28479 static dw_line_info_table
*
28480 new_line_info_table (void)
28482 dw_line_info_table
*table
;
28484 table
= ggc_cleared_alloc
<dw_line_info_table
> ();
28485 table
->file_num
= 1;
28486 table
->line_num
= 1;
28487 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
28488 FORCE_RESET_NEXT_VIEW (table
->view
);
28489 table
->symviews_since_reset
= 0;
28494 /* Lookup the "current" table into which we emit line info, so
28495 that we don't have to do it for every source line. */
28498 set_cur_line_info_table (section
*sec
)
28500 dw_line_info_table
*table
;
28502 if (sec
== text_section
)
28503 table
= text_section_line_info
;
28504 else if (sec
== cold_text_section
)
28506 table
= cold_text_section_line_info
;
28509 cold_text_section_line_info
= table
= new_line_info_table ();
28510 table
->end_label
= cold_end_label
;
28515 const char *end_label
;
28517 if (crtl
->has_bb_partition
)
28519 if (in_cold_section_p
)
28520 end_label
= crtl
->subsections
.cold_section_end_label
;
28522 end_label
= crtl
->subsections
.hot_section_end_label
;
28526 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
28527 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
28528 current_function_funcdef_no
);
28529 end_label
= ggc_strdup (label
);
28532 table
= new_line_info_table ();
28533 table
->end_label
= end_label
;
28535 vec_safe_push (separate_line_info
, table
);
28538 if (output_asm_line_debug_info ())
28539 table
->is_stmt
= (cur_line_info_table
28540 ? cur_line_info_table
->is_stmt
28541 : DWARF_LINE_DEFAULT_IS_STMT_START
);
28542 cur_line_info_table
= table
;
28546 /* We need to reset the locations at the beginning of each
28547 function. We can't do this in the end_function hook, because the
28548 declarations that use the locations won't have been output when
28549 that hook is called. Also compute have_multiple_function_sections here. */
28552 dwarf2out_begin_function (tree fun
)
28554 section
*sec
= function_section (fun
);
28556 if (sec
!= text_section
)
28557 have_multiple_function_sections
= true;
28559 if (crtl
->has_bb_partition
&& !cold_text_section
)
28561 gcc_assert (current_function_decl
== fun
);
28562 cold_text_section
= unlikely_text_section ();
28563 switch_to_section (cold_text_section
);
28564 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
28565 switch_to_section (sec
);
28568 call_site_count
= 0;
28569 tail_call_site_count
= 0;
28571 set_cur_line_info_table (sec
);
28572 FORCE_RESET_NEXT_VIEW (cur_line_info_table
->view
);
28575 /* Helper function of dwarf2out_end_function, called only after emitting
28576 the very first function into assembly. Check if some .debug_loc range
28577 might end with a .LVL* label that could be equal to .Ltext0.
28578 In that case we must force using absolute addresses in .debug_loc ranges,
28579 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
28580 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
28582 Set have_multiple_function_sections to true in that case and
28583 terminate htab traversal. */
28586 find_empty_loc_ranges_at_text_label (var_loc_list
**slot
, int)
28588 var_loc_list
*entry
= *slot
;
28589 struct var_loc_node
*node
;
28591 node
= entry
->first
;
28592 if (node
&& node
->next
&& node
->next
->label
)
28595 const char *label
= node
->next
->label
;
28596 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
28598 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
28600 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
28601 if (strcmp (label
, loclabel
) == 0)
28603 have_multiple_function_sections
= true;
28611 /* Hook called after emitting a function into assembly.
28612 This does something only for the very first function emitted. */
28615 dwarf2out_end_function (unsigned int)
28617 if (in_first_function_p
28618 && !have_multiple_function_sections
28619 && first_loclabel_num_not_at_text_label
28621 decl_loc_table
->traverse
<int, find_empty_loc_ranges_at_text_label
> (0);
28622 in_first_function_p
= false;
28623 maybe_at_text_label_p
= false;
28626 /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
28627 front-ends register a translation unit even before dwarf2out_init is
28629 static tree main_translation_unit
= NULL_TREE
;
28631 /* Hook called by front-ends after they built their main translation unit.
28632 Associate comp_unit_die to UNIT. */
28635 dwarf2out_register_main_translation_unit (tree unit
)
28637 gcc_assert (TREE_CODE (unit
) == TRANSLATION_UNIT_DECL
28638 && main_translation_unit
== NULL_TREE
);
28639 main_translation_unit
= unit
;
28640 /* If dwarf2out_init has not been called yet, it will perform the association
28641 itself looking at main_translation_unit. */
28642 if (decl_die_table
!= NULL
)
28643 equate_decl_number_to_die (unit
, comp_unit_die ());
28646 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
28649 push_dw_line_info_entry (dw_line_info_table
*table
,
28650 enum dw_line_info_opcode opcode
, unsigned int val
)
28652 dw_line_info_entry e
;
28655 vec_safe_push (table
->entries
, e
);
28658 /* Output a label to mark the beginning of a source code line entry
28659 and record information relating to this source line, in
28660 'line_info_table' for later output of the .debug_line section. */
28661 /* ??? The discriminator parameter ought to be unsigned. */
28664 dwarf2out_source_line (unsigned int line
, unsigned int column
,
28665 const char *filename
,
28666 int discriminator
, bool is_stmt
)
28668 unsigned int file_num
;
28669 dw_line_info_table
*table
;
28670 static var_loc_view lvugid
;
28672 /* 'line_info_table' information gathering is not needed when the debug
28673 info level is set to the lowest value. Also, the current DWARF-based
28674 debug formats do not use this info. */
28675 if (debug_info_level
< DINFO_LEVEL_TERSE
|| !dwarf_debuginfo_p ())
28678 table
= cur_line_info_table
;
28682 if (debug_variable_location_views
28683 && output_asm_line_debug_info ()
28684 && table
&& !RESETTING_VIEW_P (table
->view
))
28686 /* If we're using the assembler to compute view numbers, we
28687 can't issue a .loc directive for line zero, so we can't
28688 get a view number at this point. We might attempt to
28689 compute it from the previous view, or equate it to a
28690 subsequent view (though it might not be there!), but
28691 since we're omitting the line number entry, we might as
28692 well omit the view number as well. That means pretending
28693 it's a view number zero, which might very well turn out
28694 to be correct. ??? Extend the assembler so that the
28695 compiler could emit e.g. ".locview .LVU#", to output a
28696 view without changing line number information. We'd then
28697 have to count it in symviews_since_reset; when it's omitted,
28698 it doesn't count. */
28700 zero_view_p
= BITMAP_GGC_ALLOC ();
28701 bitmap_set_bit (zero_view_p
, table
->view
);
28702 if (flag_debug_asm
)
28704 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
28705 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", table
->view
);
28706 fprintf (asm_out_file
, "\t%s line 0, omitted view ",
28707 ASM_COMMENT_START
);
28708 assemble_name (asm_out_file
, label
);
28709 putc ('\n', asm_out_file
);
28711 table
->view
= ++lvugid
;
28716 /* The discriminator column was added in dwarf4. Simplify the below
28717 by simply removing it if we're not supposed to output it. */
28718 if (dwarf_version
< 4 && dwarf_strict
)
28721 if (!debug_column_info
)
28724 file_num
= maybe_emit_file (lookup_filename (filename
));
28726 /* ??? TODO: Elide duplicate line number entries. Traditionally,
28727 the debugger has used the second (possibly duplicate) line number
28728 at the beginning of the function to mark the end of the prologue.
28729 We could eliminate any other duplicates within the function. For
28730 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
28731 that second line number entry. */
28732 /* Recall that this end-of-prologue indication is *not* the same thing
28733 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
28734 to which the hook corresponds, follows the last insn that was
28735 emitted by gen_prologue. What we need is to precede the first insn
28736 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
28737 insn that corresponds to something the user wrote. These may be
28738 very different locations once scheduling is enabled. */
28740 if (0 && file_num
== table
->file_num
28741 && line
== table
->line_num
28742 && column
== table
->column_num
28743 && discriminator
== table
->discrim_num
28744 && is_stmt
== table
->is_stmt
)
28747 switch_to_section (current_function_section ());
28749 /* If requested, emit something human-readable. */
28750 if (flag_debug_asm
)
28752 if (debug_column_info
)
28753 fprintf (asm_out_file
, "\t%s %s:%d:%d\n", ASM_COMMENT_START
,
28754 filename
, line
, column
);
28756 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
28760 if (output_asm_line_debug_info ())
28762 /* Emit the .loc directive understood by GNU as. */
28763 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
28764 file_num, line, is_stmt, discriminator */
28765 fputs ("\t.loc ", asm_out_file
);
28766 fprint_ul (asm_out_file
, file_num
);
28767 putc (' ', asm_out_file
);
28768 fprint_ul (asm_out_file
, line
);
28769 putc (' ', asm_out_file
);
28770 fprint_ul (asm_out_file
, column
);
28772 if (is_stmt
!= table
->is_stmt
)
28774 #if HAVE_GAS_LOC_STMT
28775 fputs (" is_stmt ", asm_out_file
);
28776 putc (is_stmt
? '1' : '0', asm_out_file
);
28779 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
28781 gcc_assert (discriminator
> 0);
28782 fputs (" discriminator ", asm_out_file
);
28783 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
28785 if (debug_variable_location_views
)
28787 if (!RESETTING_VIEW_P (table
->view
))
28789 table
->symviews_since_reset
++;
28790 if (table
->symviews_since_reset
> symview_upper_bound
)
28791 symview_upper_bound
= table
->symviews_since_reset
;
28792 /* When we're using the assembler to compute view
28793 numbers, we output symbolic labels after "view" in
28794 .loc directives, and the assembler will set them for
28795 us, so that we can refer to the view numbers in
28796 location lists. The only exceptions are when we know
28797 a view will be zero: "-0" is a forced reset, used
28798 e.g. in the beginning of functions, whereas "0" tells
28799 the assembler to check that there was a PC change
28800 since the previous view, in a way that implicitly
28801 resets the next view. */
28802 fputs (" view ", asm_out_file
);
28803 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
28804 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", table
->view
);
28805 assemble_name (asm_out_file
, label
);
28806 table
->view
= ++lvugid
;
28810 table
->symviews_since_reset
= 0;
28811 if (FORCE_RESETTING_VIEW_P (table
->view
))
28812 fputs (" view -0", asm_out_file
);
28814 fputs (" view 0", asm_out_file
);
28815 /* Mark the present view as a zero view. Earlier debug
28816 binds may have already added its id to loclists to be
28817 emitted later, so we can't reuse the id for something
28818 else. However, it's good to know whether a view is
28819 known to be zero, because then we may be able to
28820 optimize out locviews that are all zeros, so take
28821 note of it in zero_view_p. */
28823 zero_view_p
= BITMAP_GGC_ALLOC ();
28824 bitmap_set_bit (zero_view_p
, lvugid
);
28825 table
->view
= ++lvugid
;
28828 putc ('\n', asm_out_file
);
28832 unsigned int label_num
= ++line_info_label_num
;
28834 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
28836 if (debug_variable_location_views
&& !RESETTING_VIEW_P (table
->view
))
28837 push_dw_line_info_entry (table
, LI_adv_address
, label_num
);
28839 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
28840 if (debug_variable_location_views
)
28842 bool resetting
= FORCE_RESETTING_VIEW_P (table
->view
);
28846 if (flag_debug_asm
)
28847 fprintf (asm_out_file
, "\t%s view %s%d\n",
28849 resetting
? "-" : "",
28854 if (file_num
!= table
->file_num
)
28855 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
28856 if (discriminator
!= table
->discrim_num
)
28857 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
28858 if (is_stmt
!= table
->is_stmt
)
28859 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
28860 push_dw_line_info_entry (table
, LI_set_line
, line
);
28861 if (debug_column_info
)
28862 push_dw_line_info_entry (table
, LI_set_column
, column
);
28865 table
->file_num
= file_num
;
28866 table
->line_num
= line
;
28867 table
->column_num
= column
;
28868 table
->discrim_num
= discriminator
;
28869 table
->is_stmt
= is_stmt
;
28870 table
->in_use
= true;
28873 /* Record a source file location for a DECL_IGNORED_P function. */
28876 dwarf2out_set_ignored_loc (unsigned int line
, unsigned int column
,
28877 const char *filename
)
28879 dw_fde_ref fde
= cfun
->fde
;
28881 fde
->ignored_debug
= false;
28882 set_cur_line_info_table (function_section (fde
->decl
));
28884 dwarf2out_source_line (line
, column
, filename
, 0, true);
28887 /* Record the beginning of a new source file. */
28890 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
28892 #ifdef CODEVIEW_DEBUGGING_INFO
28893 if (codeview_debuginfo_p ())
28894 codeview_start_source_file (filename
);
28897 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
28900 e
.code
= DW_MACINFO_start_file
;
28902 e
.info
= ggc_strdup (filename
);
28903 vec_safe_push (macinfo_table
, e
);
28907 /* Record the end of a source file. */
28910 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
28912 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
28915 e
.code
= DW_MACINFO_end_file
;
28918 vec_safe_push (macinfo_table
, e
);
28922 /* Called from debug_define in toplev.cc. The `buffer' parameter contains
28923 the tail part of the directive line, i.e. the part which is past the
28924 initial whitespace, #, whitespace, directive-name, whitespace part. */
28927 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
28928 const char *buffer ATTRIBUTE_UNUSED
)
28930 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
28933 /* Insert a dummy first entry to be able to optimize the whole
28934 predefined macro block using DW_MACRO_import. */
28935 if (macinfo_table
->is_empty () && lineno
<= 1)
28940 vec_safe_push (macinfo_table
, e
);
28942 e
.code
= DW_MACINFO_define
;
28944 e
.info
= ggc_strdup (buffer
);
28945 vec_safe_push (macinfo_table
, e
);
28949 /* Called from debug_undef in toplev.cc. The `buffer' parameter contains
28950 the tail part of the directive line, i.e. the part which is past the
28951 initial whitespace, #, whitespace, directive-name, whitespace part. */
28954 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
28955 const char *buffer ATTRIBUTE_UNUSED
)
28957 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
28960 /* Insert a dummy first entry to be able to optimize the whole
28961 predefined macro block using DW_MACRO_import. */
28962 if (macinfo_table
->is_empty () && lineno
<= 1)
28967 vec_safe_push (macinfo_table
, e
);
28969 e
.code
= DW_MACINFO_undef
;
28971 e
.info
= ggc_strdup (buffer
);
28972 vec_safe_push (macinfo_table
, e
);
28976 /* Helpers to manipulate hash table of CUs. */
28978 struct macinfo_entry_hasher
: nofree_ptr_hash
<macinfo_entry
>
28980 static inline hashval_t
hash (const macinfo_entry
*);
28981 static inline bool equal (const macinfo_entry
*, const macinfo_entry
*);
28985 macinfo_entry_hasher::hash (const macinfo_entry
*entry
)
28987 return htab_hash_string (entry
->info
);
28991 macinfo_entry_hasher::equal (const macinfo_entry
*entry1
,
28992 const macinfo_entry
*entry2
)
28994 return !strcmp (entry1
->info
, entry2
->info
);
28997 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
28999 /* Output a single .debug_macinfo entry. */
29002 output_macinfo_op (macinfo_entry
*ref
)
29006 struct indirect_string_node
*node
;
29007 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
29008 struct dwarf_file_data
*fd
;
29012 case DW_MACINFO_start_file
:
29013 fd
= lookup_filename (ref
->info
);
29014 file_num
= maybe_emit_file (fd
);
29015 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
29016 dw2_asm_output_data_uleb128 (ref
->lineno
,
29017 "Included from line number "
29018 HOST_WIDE_INT_PRINT_UNSIGNED
,
29020 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
29022 case DW_MACINFO_end_file
:
29023 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
29025 case DW_MACINFO_define
:
29026 case DW_MACINFO_undef
:
29027 len
= strlen (ref
->info
) + 1;
29028 if ((!dwarf_strict
|| dwarf_version
>= 5)
29029 && len
> (size_t) dwarf_offset_size
29030 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
29031 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
29033 if (dwarf_split_debug_info
&& dwarf_version
>= 5)
29034 ref
->code
= ref
->code
== DW_MACINFO_define
29035 ? DW_MACRO_define_strx
: DW_MACRO_undef_strx
;
29037 ref
->code
= ref
->code
== DW_MACINFO_define
29038 ? DW_MACRO_define_strp
: DW_MACRO_undef_strp
;
29039 output_macinfo_op (ref
);
29042 dw2_asm_output_data (1, ref
->code
,
29043 ref
->code
== DW_MACINFO_define
29044 ? "Define macro" : "Undefine macro");
29045 dw2_asm_output_data_uleb128 (ref
->lineno
,
29047 HOST_WIDE_INT_PRINT_UNSIGNED
,
29049 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
29051 case DW_MACRO_define_strp
:
29052 dw2_asm_output_data (1, ref
->code
, "Define macro strp");
29053 goto do_DW_MACRO_define_strpx
;
29054 case DW_MACRO_undef_strp
:
29055 dw2_asm_output_data (1, ref
->code
, "Undefine macro strp");
29056 goto do_DW_MACRO_define_strpx
;
29057 case DW_MACRO_define_strx
:
29058 dw2_asm_output_data (1, ref
->code
, "Define macro strx");
29059 goto do_DW_MACRO_define_strpx
;
29060 case DW_MACRO_undef_strx
:
29061 dw2_asm_output_data (1, ref
->code
, "Undefine macro strx");
29063 do_DW_MACRO_define_strpx
:
29064 /* NB: dwarf2out_finish performs:
29065 1. save_macinfo_strings
29066 2. hash table traverse of index_string
29067 3. output_macinfo -> output_macinfo_op
29068 4. output_indirect_strings
29069 -> hash table traverse of output_index_string
29071 When output_macinfo_op is called, all index strings have been
29072 added to hash table by save_macinfo_strings and we can't pass
29073 INSERT to find_slot_with_hash which may expand hash table, even
29074 if no insertion is needed, and change hash table traverse order
29075 between index_string and output_index_string. */
29076 node
= find_AT_string (ref
->info
, NO_INSERT
);
29078 && (node
->form
== DW_FORM_strp
29079 || node
->form
== dwarf_FORM (DW_FORM_strx
)));
29080 dw2_asm_output_data_uleb128 (ref
->lineno
,
29082 HOST_WIDE_INT_PRINT_UNSIGNED
,
29084 if (node
->form
== DW_FORM_strp
)
29085 dw2_asm_output_offset (dwarf_offset_size
, node
->label
,
29086 debug_str_section
, "The macro: \"%s\"",
29089 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
29092 case DW_MACRO_import
:
29093 dw2_asm_output_data (1, ref
->code
, "Import");
29094 ASM_GENERATE_INTERNAL_LABEL (label
,
29095 DEBUG_MACRO_SECTION_LABEL
,
29096 ref
->lineno
+ macinfo_label_base
);
29097 dw2_asm_output_offset (dwarf_offset_size
, label
, NULL
, NULL
);
29100 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
29101 ASM_COMMENT_START
, (unsigned long) ref
->code
);
29106 /* Attempt to make a sequence of define/undef macinfo ops shareable with
29107 other compilation unit .debug_macinfo sections. IDX is the first
29108 index of a define/undef, return the number of ops that should be
29109 emitted in a comdat .debug_macinfo section and emit
29110 a DW_MACRO_import entry referencing it.
29111 If the define/undef entry should be emitted normally, return 0. */
29114 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
29115 macinfo_hash_type
**macinfo_htab
)
29117 macinfo_entry
*first
, *second
, *cur
, *inc
;
29118 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
29119 unsigned char checksum
[16];
29120 struct md5_ctx ctx
;
29121 char *grp_name
, *tail
;
29123 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
29124 macinfo_entry
**slot
;
29126 first
= &(*macinfo_table
)[idx
];
29127 second
= &(*macinfo_table
)[idx
+ 1];
29129 /* Optimize only if there are at least two consecutive define/undef ops,
29130 and either all of them are before first DW_MACINFO_start_file
29131 with lineno {0,1} (i.e. predefined macro block), or all of them are
29132 in some included header file. */
29133 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
29135 if (vec_safe_is_empty (files
))
29137 if (first
->lineno
> 1 || second
->lineno
> 1)
29140 else if (first
->lineno
== 0)
29143 /* Find the last define/undef entry that can be grouped together
29144 with first and at the same time compute md5 checksum of their
29145 codes, linenumbers and strings. */
29146 md5_init_ctx (&ctx
);
29147 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
29148 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
29150 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
29154 unsigned char code
= cur
->code
;
29155 md5_process_bytes (&code
, 1, &ctx
);
29156 checksum_uleb128 (cur
->lineno
, &ctx
);
29157 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
29159 md5_finish_ctx (&ctx
, checksum
);
29162 /* From the containing include filename (if any) pick up just
29163 usable characters from its basename. */
29164 if (vec_safe_is_empty (files
))
29167 base
= lbasename (files
->last ().info
);
29168 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
29169 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
29170 encoded_filename_len
++;
29171 /* Count . at the end. */
29172 if (encoded_filename_len
)
29173 encoded_filename_len
++;
29175 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
29176 linebuf_len
= strlen (linebuf
);
29178 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
29179 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
29181 memcpy (grp_name
, dwarf_offset_size
== 4 ? "wm4." : "wm8.", 4);
29182 tail
= grp_name
+ 4;
29183 if (encoded_filename_len
)
29185 for (i
= 0; base
[i
]; i
++)
29186 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
29190 memcpy (tail
, linebuf
, linebuf_len
);
29191 tail
+= linebuf_len
;
29193 for (i
= 0; i
< 16; i
++)
29194 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
29196 /* Construct a macinfo_entry for DW_MACRO_import
29197 in the empty vector entry before the first define/undef. */
29198 inc
= &(*macinfo_table
)[idx
- 1];
29199 inc
->code
= DW_MACRO_import
;
29201 inc
->info
= ggc_strdup (grp_name
);
29202 if (!*macinfo_htab
)
29203 *macinfo_htab
= new macinfo_hash_type (10);
29204 /* Avoid emitting duplicates. */
29205 slot
= (*macinfo_htab
)->find_slot (inc
, INSERT
);
29210 /* If such an entry has been used before, just emit
29211 a DW_MACRO_import op. */
29213 output_macinfo_op (inc
);
29214 /* And clear all macinfo_entry in the range to avoid emitting them
29215 in the second pass. */
29216 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
29225 inc
->lineno
= (*macinfo_htab
)->elements ();
29226 output_macinfo_op (inc
);
29231 /* Save any strings needed by the macinfo table in the debug str
29232 table. All strings must be collected into the table by the time
29233 index_string is called. */
29236 save_macinfo_strings (void)
29240 macinfo_entry
*ref
;
29242 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
29246 /* Match the logic in output_macinfo_op to decide on
29247 indirect strings. */
29248 case DW_MACINFO_define
:
29249 case DW_MACINFO_undef
:
29250 len
= strlen (ref
->info
) + 1;
29251 if ((!dwarf_strict
|| dwarf_version
>= 5)
29252 && len
> (unsigned) dwarf_offset_size
29253 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
29254 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
29255 set_indirect_string (find_AT_string (ref
->info
));
29257 case DW_MACINFO_start_file
:
29258 /* -gsplit-dwarf -g3 will also output filename as indirect
29260 if (!dwarf_split_debug_info
)
29262 /* Fall through. */
29263 case DW_MACRO_define_strp
:
29264 case DW_MACRO_undef_strp
:
29265 case DW_MACRO_define_strx
:
29266 case DW_MACRO_undef_strx
:
29267 set_indirect_string (find_AT_string (ref
->info
));
29275 /* Output macinfo section(s). */
29278 output_macinfo (const char *debug_line_label
, bool early_lto_debug
)
29281 unsigned long length
= vec_safe_length (macinfo_table
);
29282 macinfo_entry
*ref
;
29283 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
29284 macinfo_hash_type
*macinfo_htab
= NULL
;
29285 char dl_section_ref
[MAX_ARTIFICIAL_LABEL_BYTES
];
29290 /* output_macinfo* uses these interchangeably. */
29291 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_define
29292 && (int) DW_MACINFO_undef
== (int) DW_MACRO_undef
29293 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_start_file
29294 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_end_file
);
29296 /* AIX Assembler inserts the length, so adjust the reference to match the
29297 offset expected by debuggers. */
29298 strcpy (dl_section_ref
, debug_line_label
);
29299 if (XCOFF_DEBUGGING_INFO
)
29300 strcat (dl_section_ref
, DWARF_INITIAL_LENGTH_SIZE_STR
);
29302 /* For .debug_macro emit the section header. */
29303 if (!dwarf_strict
|| dwarf_version
>= 5)
29305 dw2_asm_output_data (2, dwarf_version
>= 5 ? 5 : 4,
29306 "DWARF macro version number");
29307 if (dwarf_offset_size
== 8)
29308 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
29310 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
29311 dw2_asm_output_offset (dwarf_offset_size
, debug_line_label
,
29312 debug_line_section
, NULL
);
29315 /* In the first loop, it emits the primary .debug_macinfo section
29316 and after each emitted op the macinfo_entry is cleared.
29317 If a longer range of define/undef ops can be optimized using
29318 DW_MACRO_import, the DW_MACRO_import op is emitted and kept in
29319 the vector before the first define/undef in the range and the
29320 whole range of define/undef ops is not emitted and kept. */
29321 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
29325 case DW_MACINFO_start_file
:
29326 vec_safe_push (files
, *ref
);
29328 case DW_MACINFO_end_file
:
29329 if (!vec_safe_is_empty (files
))
29332 case DW_MACINFO_define
:
29333 case DW_MACINFO_undef
:
29334 if ((!dwarf_strict
|| dwarf_version
>= 5)
29335 && !dwarf_split_debug_info
29336 && HAVE_COMDAT_GROUP
29337 && vec_safe_length (files
) != 1
29340 && (*macinfo_table
)[i
- 1].code
== 0)
29342 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
29351 /* A dummy entry may be inserted at the beginning to be able
29352 to optimize the whole block of predefined macros. */
29358 output_macinfo_op (ref
);
29366 /* Save the number of transparent includes so we can adjust the
29367 label number for the fat LTO object DWARF. */
29368 unsigned macinfo_label_base_adj
= macinfo_htab
->elements ();
29370 delete macinfo_htab
;
29371 macinfo_htab
= NULL
;
29373 /* If any DW_MACRO_import were used, on those DW_MACRO_import entries
29374 terminate the current chain and switch to a new comdat .debug_macinfo
29375 section and emit the define/undef entries within it. */
29376 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
29381 case DW_MACRO_import
:
29383 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
29384 tree comdat_key
= get_identifier (ref
->info
);
29385 /* Terminate the previous .debug_macinfo section. */
29386 dw2_asm_output_data (1, 0, "End compilation unit");
29387 targetm
.asm_out
.named_section (debug_macinfo_section_name
,
29391 ? SECTION_EXCLUDE
: 0),
29393 ASM_GENERATE_INTERNAL_LABEL (label
,
29394 DEBUG_MACRO_SECTION_LABEL
,
29395 ref
->lineno
+ macinfo_label_base
);
29396 ASM_OUTPUT_LABEL (asm_out_file
, label
);
29399 dw2_asm_output_data (2, dwarf_version
>= 5 ? 5 : 4,
29400 "DWARF macro version number");
29401 if (dwarf_offset_size
== 8)
29402 dw2_asm_output_data (1, 1, "Flags: 64-bit");
29404 dw2_asm_output_data (1, 0, "Flags: 32-bit");
29407 case DW_MACINFO_define
:
29408 case DW_MACINFO_undef
:
29409 output_macinfo_op (ref
);
29414 gcc_unreachable ();
29417 macinfo_label_base
+= macinfo_label_base_adj
;
29420 /* As init_sections_and_labels may get called multiple times, have a
29421 generation count for labels. */
29422 static unsigned init_sections_and_labels_generation
;
29424 /* Initialize the various sections and labels for dwarf output and prefix
29425 them with PREFIX if non-NULL. Returns the generation (zero based
29426 number of times function was called). */
29429 init_sections_and_labels (bool early_lto_debug
)
29431 if (early_lto_debug
)
29433 if (!dwarf_split_debug_info
)
29435 debug_info_section
= get_section (DEBUG_LTO_INFO_SECTION
,
29436 SECTION_DEBUG
| SECTION_EXCLUDE
,
29438 debug_abbrev_section
= get_section (DEBUG_LTO_ABBREV_SECTION
,
29439 SECTION_DEBUG
| SECTION_EXCLUDE
,
29441 debug_macinfo_section_name
29442 = ((dwarf_strict
&& dwarf_version
< 5)
29443 ? DEBUG_LTO_MACINFO_SECTION
: DEBUG_LTO_MACRO_SECTION
);
29444 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
29446 | SECTION_EXCLUDE
, NULL
);
29450 /* ??? Which of the following do we need early? */
29451 debug_info_section
= get_section (DEBUG_LTO_DWO_INFO_SECTION
,
29452 SECTION_DEBUG
| SECTION_EXCLUDE
,
29454 debug_abbrev_section
= get_section (DEBUG_LTO_DWO_ABBREV_SECTION
,
29455 SECTION_DEBUG
| SECTION_EXCLUDE
,
29457 debug_skeleton_info_section
= get_section (DEBUG_LTO_INFO_SECTION
,
29459 | SECTION_EXCLUDE
, NULL
);
29460 debug_skeleton_abbrev_section
29461 = get_section (DEBUG_LTO_ABBREV_SECTION
,
29462 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
29463 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
29464 DEBUG_SKELETON_ABBREV_SECTION_LABEL
,
29465 init_sections_and_labels_generation
);
29467 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections
29468 stay in the main .o, but the skeleton_line goes into the split
29470 debug_skeleton_line_section
29471 = get_section (DEBUG_LTO_LINE_SECTION
,
29472 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
29473 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
29474 DEBUG_SKELETON_LINE_SECTION_LABEL
,
29475 init_sections_and_labels_generation
);
29476 debug_str_offsets_section
29477 = get_section (DEBUG_LTO_DWO_STR_OFFSETS_SECTION
,
29478 SECTION_DEBUG
| SECTION_EXCLUDE
,
29480 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
29481 DEBUG_SKELETON_INFO_SECTION_LABEL
,
29482 init_sections_and_labels_generation
);
29483 debug_str_dwo_section
= get_section (DEBUG_LTO_STR_DWO_SECTION
,
29484 DEBUG_STR_DWO_SECTION_FLAGS
,
29486 debug_macinfo_section_name
29487 = ((dwarf_strict
&& dwarf_version
< 5)
29488 ? DEBUG_LTO_DWO_MACINFO_SECTION
: DEBUG_LTO_DWO_MACRO_SECTION
);
29489 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
29490 SECTION_DEBUG
| SECTION_EXCLUDE
,
29493 /* For macro info and the file table we have to refer to a
29494 debug_line section. */
29495 debug_line_section
= get_section (DEBUG_LTO_LINE_SECTION
,
29496 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
29497 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
29498 DEBUG_LINE_SECTION_LABEL
,
29499 init_sections_and_labels_generation
);
29501 debug_str_section
= get_section (DEBUG_LTO_STR_SECTION
,
29502 DEBUG_STR_SECTION_FLAGS
29503 | SECTION_EXCLUDE
, NULL
);
29504 if (!dwarf_split_debug_info
)
29505 debug_line_str_section
29506 = get_section (DEBUG_LTO_LINE_STR_SECTION
,
29507 DEBUG_STR_SECTION_FLAGS
| SECTION_EXCLUDE
, NULL
);
29511 if (!dwarf_split_debug_info
)
29513 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
29514 SECTION_DEBUG
, NULL
);
29515 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
29516 SECTION_DEBUG
, NULL
);
29517 debug_loc_section
= get_section (dwarf_version
>= 5
29518 ? DEBUG_LOCLISTS_SECTION
29519 : DEBUG_LOC_SECTION
,
29520 SECTION_DEBUG
, NULL
);
29521 debug_macinfo_section_name
29522 = ((dwarf_strict
&& dwarf_version
< 5)
29523 ? DEBUG_MACINFO_SECTION
: DEBUG_MACRO_SECTION
);
29524 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
29525 SECTION_DEBUG
, NULL
);
29529 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
29530 SECTION_DEBUG
| SECTION_EXCLUDE
,
29532 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
29533 SECTION_DEBUG
| SECTION_EXCLUDE
,
29535 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
29536 SECTION_DEBUG
, NULL
);
29537 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
29538 SECTION_DEBUG
, NULL
);
29539 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
29540 SECTION_DEBUG
, NULL
);
29541 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
29542 DEBUG_SKELETON_ABBREV_SECTION_LABEL
,
29543 init_sections_and_labels_generation
);
29545 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections
29546 stay in the main .o, but the skeleton_line goes into the
29548 debug_skeleton_line_section
29549 = get_section (DEBUG_DWO_LINE_SECTION
,
29550 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
29551 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
29552 DEBUG_SKELETON_LINE_SECTION_LABEL
,
29553 init_sections_and_labels_generation
);
29554 debug_str_offsets_section
29555 = get_section (DEBUG_DWO_STR_OFFSETS_SECTION
,
29556 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
29557 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
29558 DEBUG_SKELETON_INFO_SECTION_LABEL
,
29559 init_sections_and_labels_generation
);
29560 debug_loc_section
= get_section (dwarf_version
>= 5
29561 ? DEBUG_DWO_LOCLISTS_SECTION
29562 : DEBUG_DWO_LOC_SECTION
,
29563 SECTION_DEBUG
| SECTION_EXCLUDE
,
29565 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
29566 DEBUG_STR_DWO_SECTION_FLAGS
,
29568 debug_macinfo_section_name
29569 = ((dwarf_strict
&& dwarf_version
< 5)
29570 ? DEBUG_DWO_MACINFO_SECTION
: DEBUG_DWO_MACRO_SECTION
);
29571 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
29572 SECTION_DEBUG
| SECTION_EXCLUDE
,
29574 if (dwarf_version
>= 5)
29575 debug_ranges_dwo_section
29576 = get_section (DEBUG_DWO_RNGLISTS_SECTION
,
29577 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
29579 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
29580 SECTION_DEBUG
, NULL
);
29581 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
29582 SECTION_DEBUG
, NULL
);
29583 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
29584 SECTION_DEBUG
, NULL
);
29585 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
29586 SECTION_DEBUG
, NULL
);
29587 debug_str_section
= get_section (DEBUG_STR_SECTION
,
29588 DEBUG_STR_SECTION_FLAGS
, NULL
);
29589 if ((!dwarf_split_debug_info
&& !output_asm_line_debug_info ())
29590 || asm_outputs_debug_line_str ())
29591 debug_line_str_section
= get_section (DEBUG_LINE_STR_SECTION
,
29592 DEBUG_STR_SECTION_FLAGS
, NULL
);
29594 debug_ranges_section
= get_section (dwarf_version
>= 5
29595 ? DEBUG_RNGLISTS_SECTION
29596 : DEBUG_RANGES_SECTION
,
29597 SECTION_DEBUG
, NULL
);
29598 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
29599 SECTION_DEBUG
, NULL
);
29602 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
29603 DEBUG_ABBREV_SECTION_LABEL
,
29604 init_sections_and_labels_generation
);
29605 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
29606 DEBUG_INFO_SECTION_LABEL
,
29607 init_sections_and_labels_generation
);
29608 info_section_emitted
= false;
29609 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
29610 DEBUG_LINE_SECTION_LABEL
,
29611 init_sections_and_labels_generation
);
29612 /* There are up to 6 unique ranges labels per generation.
29613 See also output_rnglists. */
29614 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
29615 DEBUG_RANGES_SECTION_LABEL
,
29616 init_sections_and_labels_generation
* 6);
29617 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
29618 ASM_GENERATE_INTERNAL_LABEL (ranges_base_label
,
29619 DEBUG_RANGES_SECTION_LABEL
,
29620 1 + init_sections_and_labels_generation
* 6);
29621 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
29622 DEBUG_ADDR_SECTION_LABEL
,
29623 init_sections_and_labels_generation
);
29624 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
29625 (dwarf_strict
&& dwarf_version
< 5)
29626 ? DEBUG_MACINFO_SECTION_LABEL
29627 : DEBUG_MACRO_SECTION_LABEL
,
29628 init_sections_and_labels_generation
);
29629 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
,
29630 init_sections_and_labels_generation
);
29632 ++init_sections_and_labels_generation
;
29633 return init_sections_and_labels_generation
- 1;
29636 /* Set up for Dwarf output at the start of compilation. */
29639 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
29641 /* Allocate the file_table. */
29642 file_table
= hash_table
<dwarf_file_hasher
>::create_ggc (50);
29644 #ifndef DWARF2_LINENO_DEBUGGING_INFO
29645 /* Allocate the decl_die_table. */
29646 decl_die_table
= hash_table
<decl_die_hasher
>::create_ggc (10);
29648 /* Allocate the decl_loc_table. */
29649 decl_loc_table
= hash_table
<decl_loc_hasher
>::create_ggc (10);
29651 /* Allocate the cached_dw_loc_list_table. */
29652 cached_dw_loc_list_table
= hash_table
<dw_loc_list_hasher
>::create_ggc (10);
29654 /* Allocate the initial hunk of the abbrev_die_table. */
29655 vec_alloc (abbrev_die_table
, 256);
29656 /* Zero-th entry is allocated, but unused. */
29657 abbrev_die_table
->quick_push (NULL
);
29659 /* Allocate the dwarf_proc_stack_usage_map. */
29660 dwarf_proc_stack_usage_map
= new hash_map
<dw_die_ref
, int>;
29662 /* Allocate the pubtypes and pubnames vectors. */
29663 vec_alloc (pubname_table
, 32);
29664 vec_alloc (pubtype_table
, 32);
29666 vec_alloc (incomplete_types
, 64);
29668 vec_alloc (used_rtx_array
, 32);
29670 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
29671 vec_alloc (macinfo_table
, 64);
29674 /* If front-ends already registered a main translation unit but we were not
29675 ready to perform the association, do this now. */
29676 if (main_translation_unit
!= NULL_TREE
)
29677 equate_decl_number_to_die (main_translation_unit
, comp_unit_die ());
29680 /* Called before compile () starts outputtting functions, variables
29681 and toplevel asms into assembly. */
29684 dwarf2out_assembly_start (void)
29686 if (text_section_line_info
)
29689 #ifndef DWARF2_LINENO_DEBUGGING_INFO
29690 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
29691 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
29692 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
29693 COLD_TEXT_SECTION_LABEL
, 0);
29694 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
29696 switch_to_section (text_section
);
29697 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
29700 /* Make sure the line number table for .text always exists. */
29701 text_section_line_info
= new_line_info_table ();
29702 text_section_line_info
->end_label
= text_end_label
;
29704 #ifdef DWARF2_LINENO_DEBUGGING_INFO
29705 cur_line_info_table
= text_section_line_info
;
29708 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
29709 && dwarf2out_do_cfi_asm ()
29710 && !dwarf2out_do_eh_frame ())
29711 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
29713 #if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG)
29714 if (output_asm_line_debug_info () && dwarf_version
>= 5)
29716 /* When gas outputs DWARF5 .debug_line[_str] then we have to
29717 tell it the comp_dir and main file name for the zero entry
29719 const char *comp_dir
, *filename0
;
29721 comp_dir
= comp_dir_string ();
29722 if (comp_dir
== NULL
)
29725 filename0
= get_AT_string (comp_unit_die (), DW_AT_name
);
29726 if (filename0
== NULL
)
29729 fprintf (asm_out_file
, "\t.file 0 ");
29730 output_quoted_string (asm_out_file
, remap_debug_filename (comp_dir
));
29731 fputc (' ', asm_out_file
);
29732 output_quoted_string (asm_out_file
, remap_debug_filename (filename0
));
29733 fputc ('\n', asm_out_file
);
29737 /* Work around for PR101575: output a dummy .file directive. */
29738 if (!last_emitted_file
&& dwarf_debuginfo_p ()
29739 && debug_info_level
>= DINFO_LEVEL_TERSE
)
29741 const char *filename0
= get_AT_string (comp_unit_die (), DW_AT_name
);
29743 if (filename0
== NULL
)
29744 filename0
= "<dummy>";
29745 maybe_emit_file (lookup_filename (filename0
));
29749 /* A helper function for dwarf2out_finish called through
29750 htab_traverse. Assign a string its index. All strings must be
29751 collected into the table by the time index_string is called,
29752 because the indexing code relies on htab_traverse to traverse nodes
29753 in the same order for each run. */
29756 index_string (indirect_string_node
**h
, unsigned int *index
)
29758 indirect_string_node
*node
= *h
;
29760 find_string_form (node
);
29761 if (node
->form
== dwarf_FORM (DW_FORM_strx
) && node
->refcount
> 0)
29763 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
29764 node
->index
= *index
;
29770 /* A helper function for output_indirect_strings called through
29771 htab_traverse. Output the offset to a string and update the
29775 output_index_string_offset (indirect_string_node
**h
, unsigned int *offset
)
29777 indirect_string_node
*node
= *h
;
29779 if (node
->form
== dwarf_FORM (DW_FORM_strx
) && node
->refcount
> 0)
29781 /* Assert that this node has been assigned an index. */
29782 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
29783 && node
->index
!= NOT_INDEXED
);
29784 dw2_asm_output_data (dwarf_offset_size
, *offset
,
29785 "indexed string 0x%x: %s", node
->index
, node
->str
);
29786 *offset
+= strlen (node
->str
) + 1;
29791 /* A helper function for dwarf2out_finish called through
29792 htab_traverse. Output the indexed string. */
29795 output_index_string (indirect_string_node
**h
, unsigned int *cur_idx
)
29797 struct indirect_string_node
*node
= *h
;
29799 if (node
->form
== dwarf_FORM (DW_FORM_strx
) && node
->refcount
> 0)
29801 /* Assert that the strings are output in the same order as their
29802 indexes were assigned. */
29803 gcc_assert (*cur_idx
== node
->index
);
29804 assemble_string (node
->str
, strlen (node
->str
) + 1);
29810 /* A helper function for output_indirect_strings. Counts the number
29811 of index strings offsets. Must match the logic of the functions
29812 output_index_string[_offsets] above. */
29814 count_index_strings (indirect_string_node
**h
, unsigned int *last_idx
)
29816 struct indirect_string_node
*node
= *h
;
29818 if (node
->form
== dwarf_FORM (DW_FORM_strx
) && node
->refcount
> 0)
29823 /* A helper function for dwarf2out_finish called through
29824 htab_traverse. Emit one queued .debug_str string. */
29827 output_indirect_string (indirect_string_node
**h
, enum dwarf_form form
)
29829 struct indirect_string_node
*node
= *h
;
29831 node
->form
= find_string_form (node
);
29832 if (node
->form
== form
&& node
->refcount
> 0)
29834 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
29835 assemble_string (node
->str
, strlen (node
->str
) + 1);
29841 /* Output the indexed string table. */
29844 output_indirect_strings (void)
29846 switch_to_section (debug_str_section
);
29847 if (!dwarf_split_debug_info
)
29848 debug_str_hash
->traverse
<enum dwarf_form
,
29849 output_indirect_string
> (DW_FORM_strp
);
29852 unsigned int offset
= 0;
29853 unsigned int cur_idx
= 0;
29855 if (skeleton_debug_str_hash
)
29856 skeleton_debug_str_hash
->traverse
<enum dwarf_form
,
29857 output_indirect_string
> (DW_FORM_strp
);
29859 switch_to_section (debug_str_offsets_section
);
29860 /* For DWARF5 the .debug_str_offsets[.dwo] section needs a unit
29861 header. Note that we don't need to generate a label to the
29862 actual index table following the header here, because this is
29863 for the split dwarf case only. In an .dwo file there is only
29864 one string offsets table (and one debug info section). But
29865 if we would start using string offset tables for the main (or
29866 skeleton) unit, then we have to add a DW_AT_str_offsets_base
29867 pointing to the actual index after the header. Split dwarf
29868 units will never have a string offsets base attribute. When
29869 a split unit is moved into a .dwp file the string offsets can
29870 be found through the .debug_cu_index section table. */
29871 if (dwarf_version
>= 5)
29873 unsigned int last_idx
= 0;
29874 unsigned long str_offsets_length
;
29876 debug_str_hash
->traverse_noresize
29877 <unsigned int *, count_index_strings
> (&last_idx
);
29878 str_offsets_length
= last_idx
* dwarf_offset_size
+ 4;
29879 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
29880 dw2_asm_output_data (4, 0xffffffff,
29881 "Escape value for 64-bit DWARF extension");
29882 dw2_asm_output_data (dwarf_offset_size
, str_offsets_length
,
29883 "Length of string offsets unit");
29884 dw2_asm_output_data (2, 5, "DWARF string offsets version");
29885 dw2_asm_output_data (2, 0, "Header zero padding");
29887 debug_str_hash
->traverse_noresize
29888 <unsigned int *, output_index_string_offset
> (&offset
);
29889 switch_to_section (debug_str_dwo_section
);
29890 debug_str_hash
->traverse_noresize
<unsigned int *, output_index_string
>
29895 /* Callback for htab_traverse to assign an index to an entry in the
29896 table, and to write that entry to the .debug_addr section. */
29899 output_addr_table_entry (addr_table_entry
**slot
, unsigned int *cur_index
)
29901 addr_table_entry
*entry
= *slot
;
29903 if (entry
->refcount
== 0)
29905 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
29906 || entry
->index
== NOT_INDEXED
);
29910 gcc_assert (entry
->index
== *cur_index
);
29913 switch (entry
->kind
)
29916 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
29917 "0x%x", entry
->index
);
29919 case ate_kind_rtx_dtprel
:
29920 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
29921 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
29924 fputc ('\n', asm_out_file
);
29926 case ate_kind_label
:
29927 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
29928 "0x%x", entry
->index
);
29931 gcc_unreachable ();
29936 /* A helper function for dwarf2out_finish. Counts the number
29937 of indexed addresses. Must match the logic of the functions
29938 output_addr_table_entry above. */
29940 count_index_addrs (addr_table_entry
**slot
, unsigned int *last_idx
)
29942 addr_table_entry
*entry
= *slot
;
29944 if (entry
->refcount
> 0)
29949 /* Produce the .debug_addr section. */
29952 output_addr_table (void)
29954 unsigned int index
= 0;
29955 if (addr_index_table
== NULL
|| addr_index_table
->size () == 0)
29958 switch_to_section (debug_addr_section
);
29959 /* GNU DebugFission https://gcc.gnu.org/wiki/DebugFission
29960 which GCC uses to implement -gsplit-dwarf as DWARF GNU extension
29961 before DWARF5, didn't have a header for .debug_addr units.
29962 DWARF5 specifies a small header when address tables are used. */
29963 if (dwarf_version
>= 5)
29965 unsigned int last_idx
= 0;
29966 unsigned long addrs_length
;
29968 addr_index_table
->traverse_noresize
29969 <unsigned int *, count_index_addrs
> (&last_idx
);
29970 addrs_length
= last_idx
* DWARF2_ADDR_SIZE
+ 4;
29972 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
29973 dw2_asm_output_data (4, 0xffffffff,
29974 "Escape value for 64-bit DWARF extension");
29975 dw2_asm_output_data (dwarf_offset_size
, addrs_length
,
29976 "Length of Address Unit");
29977 dw2_asm_output_data (2, 5, "DWARF addr version");
29978 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
29979 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
29981 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
29984 ->traverse_noresize
<unsigned int *, output_addr_table_entry
> (&index
);
29987 #if ENABLE_ASSERT_CHECKING
29988 /* Verify that all marks are clear. */
29991 verify_marks_clear (dw_die_ref die
)
29995 gcc_assert (! die
->die_mark
);
29996 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
29998 #endif /* ENABLE_ASSERT_CHECKING */
30000 /* Clear the marks for a die and its children.
30001 Be cool if the mark isn't set. */
30004 prune_unmark_dies (dw_die_ref die
)
30010 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
30013 /* Given LOC that is referenced by a DIE we're marking as used, find all
30014 referenced DWARF procedures it references and mark them as used. */
30017 prune_unused_types_walk_loc_descr (dw_loc_descr_ref loc
)
30019 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
30020 switch (loc
->dw_loc_opc
)
30022 case DW_OP_implicit_pointer
:
30023 case DW_OP_convert
:
30024 case DW_OP_reinterpret
:
30025 case DW_OP_GNU_implicit_pointer
:
30026 case DW_OP_GNU_convert
:
30027 case DW_OP_GNU_reinterpret
:
30028 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
)
30029 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
30031 case DW_OP_GNU_variable_value
:
30032 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
30035 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
30038 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
30039 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
30040 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
30045 case DW_OP_call_ref
:
30046 case DW_OP_const_type
:
30047 case DW_OP_GNU_const_type
:
30048 case DW_OP_GNU_parameter_ref
:
30049 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
);
30050 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
30052 case DW_OP_regval_type
:
30053 case DW_OP_deref_type
:
30054 case DW_OP_GNU_regval_type
:
30055 case DW_OP_GNU_deref_type
:
30056 gcc_assert (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_die_ref
);
30057 prune_unused_types_mark (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
, 1);
30059 case DW_OP_entry_value
:
30060 case DW_OP_GNU_entry_value
:
30061 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
);
30062 prune_unused_types_walk_loc_descr (loc
->dw_loc_oprnd1
.v
.val_loc
);
30069 /* Given DIE that we're marking as used, find any other dies
30070 it references as attributes and mark them as used. */
30073 prune_unused_types_walk_attribs (dw_die_ref die
)
30078 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
30080 switch (AT_class (a
))
30082 /* Make sure DWARF procedures referenced by location descriptions will
30084 case dw_val_class_loc
:
30085 prune_unused_types_walk_loc_descr (AT_loc (a
));
30087 case dw_val_class_loc_list
:
30088 for (dw_loc_list_ref list
= AT_loc_list (a
);
30090 list
= list
->dw_loc_next
)
30091 prune_unused_types_walk_loc_descr (list
->expr
);
30094 case dw_val_class_view_list
:
30095 /* This points to a loc_list in another attribute, so it's
30096 already covered. */
30099 case dw_val_class_die_ref
:
30100 /* A reference to another DIE.
30101 Make sure that it will get emitted.
30102 If it was broken out into a comdat group, don't follow it. */
30103 if (! AT_ref (a
)->comdat_type_p
30104 || a
->dw_attr
== DW_AT_specification
)
30105 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
30108 case dw_val_class_str
:
30109 /* Set the string's refcount to 0 so that prune_unused_types_mark
30110 accounts properly for it. */
30111 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
30120 /* Mark the generic parameters and arguments children DIEs of DIE. */
30123 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
30127 if (die
== NULL
|| die
->die_child
== NULL
)
30129 c
= die
->die_child
;
30132 if (is_template_parameter (c
))
30133 prune_unused_types_mark (c
, 1);
30135 } while (c
&& c
!= die
->die_child
);
30138 /* Mark DIE as being used. If DOKIDS is true, then walk down
30139 to DIE's children. */
30142 prune_unused_types_mark (dw_die_ref die
, int dokids
)
30146 if (die
->die_mark
== 0)
30148 /* We haven't done this node yet. Mark it as used. */
30150 /* If this is the DIE of a generic type instantiation,
30151 mark the children DIEs that describe its generic parms and
30153 prune_unused_types_mark_generic_parms_dies (die
);
30155 /* We also have to mark its parents as used.
30156 (But we don't want to mark our parent's kids due to this,
30157 unless it is a class.) */
30158 if (die
->die_parent
)
30159 prune_unused_types_mark (die
->die_parent
,
30160 class_scope_p (die
->die_parent
));
30162 /* Mark any referenced nodes. */
30163 prune_unused_types_walk_attribs (die
);
30165 /* If this node is a specification,
30166 also mark the definition, if it exists. */
30167 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
30168 prune_unused_types_mark (die
->die_definition
, 1);
30171 if (dokids
&& die
->die_mark
!= 2)
30173 /* We need to walk the children, but haven't done so yet.
30174 Remember that we've walked the kids. */
30177 /* If this is an array type, we need to make sure our
30178 kids get marked, even if they're types. If we're
30179 breaking out types into comdat sections, do this
30180 for all type definitions. */
30181 if (die
->die_tag
== DW_TAG_array_type
30182 || (use_debug_types
30183 && is_type_die (die
) && ! is_declaration_die (die
)))
30184 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
30186 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
30190 /* For local classes, look if any static member functions were emitted
30191 and if so, mark them. */
30194 prune_unused_types_walk_local_classes (dw_die_ref die
)
30198 if (die
->die_mark
== 2)
30201 switch (die
->die_tag
)
30203 case DW_TAG_structure_type
:
30204 case DW_TAG_union_type
:
30205 case DW_TAG_class_type
:
30206 case DW_TAG_interface_type
:
30209 case DW_TAG_subprogram
:
30210 if (!get_AT_flag (die
, DW_AT_declaration
)
30211 || die
->die_definition
!= NULL
)
30212 prune_unused_types_mark (die
, 1);
30219 /* Mark children. */
30220 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
30223 /* Walk the tree DIE and mark types that we actually use. */
30226 prune_unused_types_walk (dw_die_ref die
)
30230 /* Don't do anything if this node is already marked and
30231 children have been marked as well. */
30232 if (die
->die_mark
== 2)
30235 switch (die
->die_tag
)
30237 case DW_TAG_structure_type
:
30238 case DW_TAG_union_type
:
30239 case DW_TAG_class_type
:
30240 case DW_TAG_interface_type
:
30241 if (die
->die_perennial_p
)
30244 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
30245 if (c
->die_tag
== DW_TAG_subprogram
)
30248 /* Finding used static member functions inside of classes
30249 is needed just for local classes, because for other classes
30250 static member function DIEs with DW_AT_specification
30251 are emitted outside of the DW_TAG_*_type. If we ever change
30252 it, we'd need to call this even for non-local classes. */
30254 prune_unused_types_walk_local_classes (die
);
30256 /* It's a type node --- don't mark it. */
30259 case DW_TAG_const_type
:
30260 case DW_TAG_packed_type
:
30261 case DW_TAG_pointer_type
:
30262 case DW_TAG_reference_type
:
30263 case DW_TAG_rvalue_reference_type
:
30264 case DW_TAG_volatile_type
:
30265 case DW_TAG_restrict_type
:
30266 case DW_TAG_shared_type
:
30267 case DW_TAG_atomic_type
:
30268 case DW_TAG_immutable_type
:
30269 case DW_TAG_typedef
:
30270 case DW_TAG_array_type
:
30271 case DW_TAG_coarray_type
:
30272 case DW_TAG_friend
:
30273 case DW_TAG_enumeration_type
:
30274 case DW_TAG_subroutine_type
:
30275 case DW_TAG_string_type
:
30276 case DW_TAG_set_type
:
30277 case DW_TAG_subrange_type
:
30278 case DW_TAG_ptr_to_member_type
:
30279 case DW_TAG_file_type
:
30280 case DW_TAG_unspecified_type
:
30281 case DW_TAG_dynamic_type
:
30282 /* Type nodes are useful only when other DIEs reference them --- don't
30286 case DW_TAG_dwarf_procedure
:
30287 /* Likewise for DWARF procedures. */
30289 if (die
->die_perennial_p
)
30294 case DW_TAG_variable
:
30295 if (flag_debug_only_used_symbols
)
30297 if (die
->die_perennial_p
)
30300 /* For static data members, the declaration in the class is supposed
30301 to have DW_TAG_member tag in DWARF{3,4} but DW_TAG_variable in
30302 DWARF5. DW_TAG_member will be marked, so mark even such
30303 DW_TAG_variables in DWARF5, as long as it has DW_AT_const_value
30305 if (dwarf_version
>= 5
30306 && class_scope_p (die
->die_parent
)
30307 && get_AT (die
, DW_AT_const_value
))
30310 /* premark_used_variables marks external variables --- don't mark
30311 them here. But function-local externals are always considered
30313 if (get_AT (die
, DW_AT_external
))
30315 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
30316 if (c
->die_tag
== DW_TAG_subprogram
)
30325 /* Mark everything else. */
30329 if (die
->die_mark
== 0)
30333 /* Now, mark any dies referenced from here. */
30334 prune_unused_types_walk_attribs (die
);
30339 /* Mark children. */
30340 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
30343 /* Increment the string counts on strings referred to from DIE's
30347 prune_unused_types_update_strings (dw_die_ref die
)
30352 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
30353 if (AT_class (a
) == dw_val_class_str
)
30355 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
30357 /* Avoid unnecessarily putting strings that are used less than
30358 twice in the hash table. */
30359 if (s
->form
!= DW_FORM_line_strp
30361 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2)))
30363 indirect_string_node
**slot
30364 = debug_str_hash
->find_slot_with_hash (s
->str
,
30365 htab_hash_string (s
->str
),
30367 gcc_assert (*slot
== NULL
);
30373 /* Mark DIE and its children as removed. */
30376 mark_removed (dw_die_ref die
)
30379 die
->removed
= true;
30380 FOR_EACH_CHILD (die
, c
, mark_removed (c
));
30383 /* Remove from the tree DIE any dies that aren't marked. */
30386 prune_unused_types_prune (dw_die_ref die
)
30390 gcc_assert (die
->die_mark
);
30391 prune_unused_types_update_strings (die
);
30393 if (! die
->die_child
)
30396 c
= die
->die_child
;
30398 dw_die_ref prev
= c
, next
;
30399 for (c
= c
->die_sib
; ! c
->die_mark
; c
= next
)
30400 if (c
== die
->die_child
)
30402 /* No marked children between 'prev' and the end of the list. */
30404 /* No marked children at all. */
30405 die
->die_child
= NULL
;
30408 prev
->die_sib
= c
->die_sib
;
30409 die
->die_child
= prev
;
30422 if (c
!= prev
->die_sib
)
30424 prune_unused_types_prune (c
);
30425 } while (c
!= die
->die_child
);
30428 /* Remove dies representing declarations that we never use. */
30431 prune_unused_types (void)
30434 limbo_die_node
*node
;
30435 comdat_type_node
*ctnode
;
30436 pubname_entry
*pub
;
30437 dw_die_ref base_type
;
30439 #if ENABLE_ASSERT_CHECKING
30440 /* All the marks should already be clear. */
30441 verify_marks_clear (comp_unit_die ());
30442 for (node
= limbo_die_list
; node
; node
= node
->next
)
30443 verify_marks_clear (node
->die
);
30444 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
30445 verify_marks_clear (ctnode
->root_die
);
30446 #endif /* ENABLE_ASSERT_CHECKING */
30448 /* Mark types that are used in global variables. */
30449 premark_types_used_by_global_vars ();
30451 /* Mark variables used in the symtab. */
30452 if (flag_debug_only_used_symbols
)
30453 premark_used_variables ();
30455 /* Set the mark on nodes that are actually used. */
30456 prune_unused_types_walk (comp_unit_die ());
30457 for (node
= limbo_die_list
; node
; node
= node
->next
)
30458 prune_unused_types_walk (node
->die
);
30459 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
30461 prune_unused_types_walk (ctnode
->root_die
);
30462 prune_unused_types_mark (ctnode
->type_die
, 1);
30465 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
30466 are unusual in that they are pubnames that are the children of pubtypes.
30467 They should only be marked via their parent DW_TAG_enumeration_type die,
30468 not as roots in themselves. */
30469 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
30470 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
30471 prune_unused_types_mark (pub
->die
, 1);
30472 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
30473 prune_unused_types_mark (base_type
, 1);
30475 /* Also set the mark on nodes that could be referenced by
30476 DW_TAG_call_site DW_AT_call_origin (i.e. direct call callees) or
30477 by DW_TAG_inlined_subroutine origins. */
30478 cgraph_node
*cnode
;
30479 FOR_EACH_FUNCTION (cnode
)
30480 if (cnode
->referred_to_p (false))
30482 dw_die_ref die
= lookup_decl_die (cnode
->decl
);
30483 if (die
== NULL
|| die
->die_mark
)
30485 for (cgraph_edge
*e
= cnode
->callers
; e
; e
= e
->next_caller
)
30486 if (e
->caller
!= cnode
)
30488 prune_unused_types_mark (die
, 1);
30493 if (debug_str_hash
)
30494 debug_str_hash
->empty ();
30495 if (skeleton_debug_str_hash
)
30496 skeleton_debug_str_hash
->empty ();
30497 prune_unused_types_prune (comp_unit_die ());
30498 for (limbo_die_node
**pnode
= &limbo_die_list
; *pnode
; )
30501 if (!node
->die
->die_mark
)
30502 *pnode
= node
->next
;
30505 prune_unused_types_prune (node
->die
);
30506 pnode
= &node
->next
;
30509 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
30510 prune_unused_types_prune (ctnode
->root_die
);
30512 /* Leave the marks clear. */
30513 prune_unmark_dies (comp_unit_die ());
30514 for (node
= limbo_die_list
; node
; node
= node
->next
)
30515 prune_unmark_dies (node
->die
);
30516 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
30517 prune_unmark_dies (ctnode
->root_die
);
30520 /* Helpers to manipulate hash table of comdat type units. */
30522 struct comdat_type_hasher
: nofree_ptr_hash
<comdat_type_node
>
30524 static inline hashval_t
hash (const comdat_type_node
*);
30525 static inline bool equal (const comdat_type_node
*, const comdat_type_node
*);
30529 comdat_type_hasher::hash (const comdat_type_node
*type_node
)
30532 memcpy (&h
, type_node
->signature
, sizeof (h
));
30537 comdat_type_hasher::equal (const comdat_type_node
*type_node_1
,
30538 const comdat_type_node
*type_node_2
)
30540 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
30541 DWARF_TYPE_SIGNATURE_SIZE
));
30544 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
30545 to the location it would have been added, should we know its
30546 DECL_ASSEMBLER_NAME when we added other attributes. This will
30547 probably improve compactness of debug info, removing equivalent
30548 abbrevs, and hide any differences caused by deferring the
30549 computation of the assembler name, triggered by e.g. PCH. */
30552 move_linkage_attr (dw_die_ref die
)
30554 unsigned ix
= vec_safe_length (die
->die_attr
);
30555 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
30557 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
30558 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
30562 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
30564 if (prev
->dw_attr
== DW_AT_decl_line
30565 || prev
->dw_attr
== DW_AT_decl_column
30566 || prev
->dw_attr
== DW_AT_name
)
30570 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
30572 die
->die_attr
->pop ();
30573 die
->die_attr
->quick_insert (ix
, linkage
);
30577 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
30578 referenced from typed stack ops and count how often they are used. */
30581 mark_base_types (dw_loc_descr_ref loc
)
30583 dw_die_ref base_type
= NULL
;
30585 for (; loc
; loc
= loc
->dw_loc_next
)
30587 switch (loc
->dw_loc_opc
)
30589 case DW_OP_regval_type
:
30590 case DW_OP_deref_type
:
30591 case DW_OP_GNU_regval_type
:
30592 case DW_OP_GNU_deref_type
:
30593 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
30595 case DW_OP_convert
:
30596 case DW_OP_reinterpret
:
30597 case DW_OP_GNU_convert
:
30598 case DW_OP_GNU_reinterpret
:
30599 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
30602 case DW_OP_const_type
:
30603 case DW_OP_GNU_const_type
:
30604 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
30606 case DW_OP_entry_value
:
30607 case DW_OP_GNU_entry_value
:
30608 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
30613 gcc_assert (base_type
->die_parent
== comp_unit_die ());
30614 if (base_type
->die_mark
)
30615 base_type
->die_mark
++;
30618 base_types
.safe_push (base_type
);
30619 base_type
->die_mark
= 1;
30624 /* Stripped-down variant of resolve_addr, mark DW_TAG_base_type nodes
30625 referenced from typed stack ops and count how often they are used. */
30628 mark_base_types (dw_die_ref die
)
30632 dw_loc_list_ref
*curr
;
30635 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
30636 switch (AT_class (a
))
30638 case dw_val_class_loc_list
:
30639 curr
= AT_loc_list_ptr (a
);
30642 mark_base_types ((*curr
)->expr
);
30643 curr
= &(*curr
)->dw_loc_next
;
30647 case dw_val_class_loc
:
30648 mark_base_types (AT_loc (a
));
30655 FOR_EACH_CHILD (die
, c
, mark_base_types (c
));
30658 /* Comparison function for sorting marked base types. */
30661 base_type_cmp (const void *x
, const void *y
)
30663 dw_die_ref dx
= *(const dw_die_ref
*) x
;
30664 dw_die_ref dy
= *(const dw_die_ref
*) y
;
30665 unsigned int byte_size1
, byte_size2
;
30666 unsigned int encoding1
, encoding2
;
30667 unsigned int align1
, align2
;
30668 if (dx
->die_mark
> dy
->die_mark
)
30670 if (dx
->die_mark
< dy
->die_mark
)
30672 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
30673 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
30674 if (byte_size1
< byte_size2
)
30676 if (byte_size1
> byte_size2
)
30678 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
30679 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
30680 if (encoding1
< encoding2
)
30682 if (encoding1
> encoding2
)
30684 align1
= get_AT_unsigned (dx
, DW_AT_alignment
);
30685 align2
= get_AT_unsigned (dy
, DW_AT_alignment
);
30686 if (align1
< align2
)
30688 if (align1
> align2
)
30693 /* Move base types marked by mark_base_types as early as possible
30694 in the CU, sorted by decreasing usage count both to make the
30695 uleb128 references as small as possible and to make sure they
30696 will have die_offset already computed by calc_die_sizes when
30697 sizes of typed stack loc ops is computed. */
30700 move_marked_base_types (void)
30703 dw_die_ref base_type
, die
, c
;
30705 if (base_types
.is_empty ())
30708 /* Sort by decreasing usage count, they will be added again in that
30710 base_types
.qsort (base_type_cmp
);
30711 die
= comp_unit_die ();
30712 c
= die
->die_child
;
30715 dw_die_ref prev
= c
;
30717 while (c
->die_mark
)
30719 remove_child_with_prev (c
, prev
);
30720 /* As base types got marked, there must be at least
30721 one node other than DW_TAG_base_type. */
30722 gcc_assert (die
->die_child
!= NULL
);
30726 while (c
!= die
->die_child
);
30727 gcc_assert (die
->die_child
);
30728 c
= die
->die_child
;
30729 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
30731 base_type
->die_mark
= 0;
30732 base_type
->die_sib
= c
->die_sib
;
30733 c
->die_sib
= base_type
;
30738 /* Helper function for resolve_addr, attempt to resolve
30739 one CONST_STRING, return true if successful. Similarly verify that
30740 SYMBOL_REFs refer to variables emitted in the current CU. */
30743 resolve_one_addr (rtx
*addr
)
30747 if (GET_CODE (rtl
) == CONST_STRING
)
30749 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
30750 tree t
= build_string (len
, XSTR (rtl
, 0));
30751 tree tlen
= size_int (len
- 1);
30753 = build_array_type (char_type_node
, build_index_type (tlen
));
30754 rtl
= lookup_constant_def (t
);
30755 if (!rtl
|| !MEM_P (rtl
))
30757 rtl
= XEXP (rtl
, 0);
30758 if (GET_CODE (rtl
) == SYMBOL_REF
30759 && SYMBOL_REF_DECL (rtl
)
30760 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
30762 vec_safe_push (used_rtx_array
, rtl
);
30767 if (GET_CODE (rtl
) == SYMBOL_REF
30768 && SYMBOL_REF_DECL (rtl
))
30770 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
30772 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
30775 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
30779 if (GET_CODE (rtl
) == CONST
)
30781 subrtx_ptr_iterator::array_type array
;
30782 FOR_EACH_SUBRTX_PTR (iter
, array
, &XEXP (rtl
, 0), ALL
)
30783 if (!resolve_one_addr (*iter
))
30790 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
30791 if possible, and create DW_TAG_dwarf_procedure that can be referenced
30792 from DW_OP_implicit_pointer if the string hasn't been seen yet. */
30795 string_cst_pool_decl (tree t
)
30797 rtx rtl
= output_constant_def (t
, 1);
30798 unsigned char *array
;
30799 dw_loc_descr_ref l
;
30804 if (!rtl
|| !MEM_P (rtl
))
30806 rtl
= XEXP (rtl
, 0);
30807 if (GET_CODE (rtl
) != SYMBOL_REF
30808 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
30811 decl
= SYMBOL_REF_DECL (rtl
);
30812 if (!lookup_decl_die (decl
))
30814 len
= TREE_STRING_LENGTH (t
);
30815 vec_safe_push (used_rtx_array
, rtl
);
30816 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
30817 array
= ggc_vec_alloc
<unsigned char> (len
);
30818 memcpy (array
, TREE_STRING_POINTER (t
), len
);
30819 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
30820 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
30821 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
30822 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
30823 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
30824 add_AT_loc (ref
, DW_AT_location
, l
);
30825 equate_decl_number_to_die (decl
, ref
);
30830 /* Helper function of resolve_addr_in_expr. LOC is
30831 a DW_OP_addr followed by DW_OP_stack_value, either at the start
30832 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
30833 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
30834 with DW_OP_implicit_pointer if possible
30835 and return true, if unsuccessful, return false. */
30838 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
30840 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
30841 HOST_WIDE_INT offset
= 0;
30842 dw_die_ref ref
= NULL
;
30845 if (GET_CODE (rtl
) == CONST
30846 && GET_CODE (XEXP (rtl
, 0)) == PLUS
30847 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
30849 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
30850 rtl
= XEXP (XEXP (rtl
, 0), 0);
30852 if (GET_CODE (rtl
) == CONST_STRING
)
30854 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
30855 tree t
= build_string (len
, XSTR (rtl
, 0));
30856 tree tlen
= size_int (len
- 1);
30859 = build_array_type (char_type_node
, build_index_type (tlen
));
30860 rtl
= string_cst_pool_decl (t
);
30864 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
30866 decl
= SYMBOL_REF_DECL (rtl
);
30867 if (VAR_P (decl
) && !DECL_EXTERNAL (decl
))
30869 ref
= lookup_decl_die (decl
);
30870 if (ref
&& (get_AT (ref
, DW_AT_location
)
30871 || get_AT (ref
, DW_AT_const_value
)))
30873 loc
->dw_loc_opc
= dwarf_OP (DW_OP_implicit_pointer
);
30874 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
30875 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
30876 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
30877 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
30878 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
30879 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
30887 /* Helper function for resolve_addr, handle one location
30888 expression, return false if at least one CONST_STRING or SYMBOL_REF in
30889 the location list couldn't be resolved. */
30892 resolve_addr_in_expr (dw_attr_node
*a
, dw_loc_descr_ref loc
)
30894 dw_loc_descr_ref keep
= NULL
;
30895 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
30896 switch (loc
->dw_loc_opc
)
30899 if (!resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
30902 || prev
->dw_loc_opc
== DW_OP_piece
30903 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
30904 && loc
->dw_loc_next
30905 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
30906 && (!dwarf_strict
|| dwarf_version
>= 5)
30907 && optimize_one_addr_into_implicit_ptr (loc
))
30912 case DW_OP_GNU_addr_index
:
30914 case DW_OP_GNU_const_index
:
30916 if ((loc
->dw_loc_opc
== DW_OP_GNU_addr_index
30917 || loc
->dw_loc_opc
== DW_OP_addrx
)
30918 || ((loc
->dw_loc_opc
== DW_OP_GNU_const_index
30919 || loc
->dw_loc_opc
== DW_OP_constx
)
30922 rtx rtl
= loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
;
30923 if (!resolve_one_addr (&rtl
))
30925 remove_addr_table_entry (loc
->dw_loc_oprnd1
.val_entry
);
30926 loc
->dw_loc_oprnd1
.val_entry
30927 = add_addr_table_entry (rtl
, ate_kind_rtx
);
30930 case DW_OP_const4u
:
30931 case DW_OP_const8u
:
30933 && !resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
30936 case DW_OP_plus_uconst
:
30937 if (size_of_loc_descr (loc
)
30938 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
30940 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
30942 dw_loc_descr_ref repl
30943 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
30944 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
30945 add_loc_descr (&repl
, loc
->dw_loc_next
);
30949 case DW_OP_implicit_value
:
30950 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
30951 && !resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
))
30954 case DW_OP_implicit_pointer
:
30955 case DW_OP_GNU_implicit_pointer
:
30956 case DW_OP_GNU_parameter_ref
:
30957 case DW_OP_GNU_variable_value
:
30958 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
30961 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
30964 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
30965 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
30966 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
30968 if (loc
->dw_loc_opc
== DW_OP_GNU_variable_value
)
30971 && loc
->dw_loc_next
== NULL
30972 && AT_class (a
) == dw_val_class_loc
)
30973 switch (a
->dw_attr
)
30975 /* Following attributes allow both exprloc and reference,
30976 so if the whole expression is DW_OP_GNU_variable_value
30977 alone we could transform it into reference. */
30978 case DW_AT_byte_size
:
30979 case DW_AT_bit_size
:
30980 case DW_AT_lower_bound
:
30981 case DW_AT_upper_bound
:
30982 case DW_AT_bit_stride
:
30984 case DW_AT_allocated
:
30985 case DW_AT_associated
:
30986 case DW_AT_byte_stride
:
30987 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
30988 a
->dw_attr_val
.val_entry
= NULL
;
30989 a
->dw_attr_val
.v
.val_die_ref
.die
30990 = loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
30991 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
31000 case DW_OP_const_type
:
31001 case DW_OP_regval_type
:
31002 case DW_OP_deref_type
:
31003 case DW_OP_convert
:
31004 case DW_OP_reinterpret
:
31005 case DW_OP_GNU_const_type
:
31006 case DW_OP_GNU_regval_type
:
31007 case DW_OP_GNU_deref_type
:
31008 case DW_OP_GNU_convert
:
31009 case DW_OP_GNU_reinterpret
:
31010 while (loc
->dw_loc_next
31011 && (loc
->dw_loc_next
->dw_loc_opc
== DW_OP_convert
31012 || loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
))
31014 dw_die_ref base1
, base2
;
31015 unsigned enc1
, enc2
, size1
, size2
;
31016 if (loc
->dw_loc_opc
== DW_OP_regval_type
31017 || loc
->dw_loc_opc
== DW_OP_deref_type
31018 || loc
->dw_loc_opc
== DW_OP_GNU_regval_type
31019 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
31020 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
31021 else if (loc
->dw_loc_oprnd1
.val_class
31022 == dw_val_class_unsigned_const
)
31025 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
31026 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
31027 == dw_val_class_unsigned_const
)
31029 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
31030 gcc_assert (base1
->die_tag
== DW_TAG_base_type
31031 && base2
->die_tag
== DW_TAG_base_type
);
31032 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
31033 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
31034 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
31035 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
31037 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
31038 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
31042 /* Optimize away next DW_OP_convert after
31043 adjusting LOC's base type die reference. */
31044 if (loc
->dw_loc_opc
== DW_OP_regval_type
31045 || loc
->dw_loc_opc
== DW_OP_deref_type
31046 || loc
->dw_loc_opc
== DW_OP_GNU_regval_type
31047 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
31048 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
31050 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
31051 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
31054 /* Don't change integer DW_OP_convert after e.g. floating
31055 point typed stack entry. */
31056 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
31057 keep
= loc
->dw_loc_next
;
31067 /* Helper function of resolve_addr. DIE had DW_AT_location of
31068 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
31069 and DW_OP_addr couldn't be resolved. resolve_addr has already
31070 removed the DW_AT_location attribute. This function attempts to
31071 add a new DW_AT_location attribute with DW_OP_implicit_pointer
31072 to it or DW_AT_const_value attribute, if possible. */
31075 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
31078 || lookup_decl_die (decl
) != die
31079 || DECL_EXTERNAL (decl
)
31080 || !TREE_STATIC (decl
)
31081 || DECL_INITIAL (decl
) == NULL_TREE
31082 || DECL_P (DECL_INITIAL (decl
))
31083 || get_AT (die
, DW_AT_const_value
))
31086 tree init
= DECL_INITIAL (decl
);
31087 HOST_WIDE_INT offset
= 0;
31088 /* For variables that have been optimized away and thus
31089 don't have a memory location, see if we can emit
31090 DW_AT_const_value instead. */
31091 if (tree_add_const_value_attribute (die
, init
))
31093 if (dwarf_strict
&& dwarf_version
< 5)
31095 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
31096 and ADDR_EXPR refers to a decl that has DW_AT_location or
31097 DW_AT_const_value (but isn't addressable, otherwise
31098 resolving the original DW_OP_addr wouldn't fail), see if
31099 we can add DW_OP_implicit_pointer. */
31101 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
31102 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
31104 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
31105 init
= TREE_OPERAND (init
, 0);
31108 if (TREE_CODE (init
) != ADDR_EXPR
)
31110 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
31111 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
31112 || (VAR_P (TREE_OPERAND (init
, 0))
31113 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
31114 && TREE_OPERAND (init
, 0) != decl
))
31117 dw_loc_descr_ref l
;
31119 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
31121 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
31124 decl
= SYMBOL_REF_DECL (rtl
);
31127 decl
= TREE_OPERAND (init
, 0);
31128 ref
= lookup_decl_die (decl
);
31130 || (!get_AT (ref
, DW_AT_location
)
31131 && !get_AT (ref
, DW_AT_const_value
)))
31133 l
= new_loc_descr (dwarf_OP (DW_OP_implicit_pointer
), 0, offset
);
31134 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
31135 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
31136 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
31137 add_AT_loc (die
, DW_AT_location
, l
);
31141 /* Return NULL if l is a DWARF expression, or first op that is not
31142 valid DWARF expression. */
31144 static dw_loc_descr_ref
31145 non_dwarf_expression (dw_loc_descr_ref l
)
31149 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
31151 switch (l
->dw_loc_opc
)
31154 case DW_OP_implicit_value
:
31155 case DW_OP_stack_value
:
31156 case DW_OP_implicit_pointer
:
31157 case DW_OP_GNU_implicit_pointer
:
31158 case DW_OP_GNU_parameter_ref
:
31160 case DW_OP_bit_piece
:
31165 l
= l
->dw_loc_next
;
31170 /* Return adjusted copy of EXPR:
31171 If it is empty DWARF expression, return it.
31172 If it is valid non-empty DWARF expression,
31173 return copy of EXPR with DW_OP_deref appended to it.
31174 If it is DWARF expression followed by DW_OP_reg{N,x}, return
31175 copy of the DWARF expression with DW_OP_breg{N,x} <0> appended.
31176 If it is DWARF expression followed by DW_OP_stack_value, return
31177 copy of the DWARF expression without anything appended.
31178 Otherwise, return NULL. */
31180 static dw_loc_descr_ref
31181 copy_deref_exprloc (dw_loc_descr_ref expr
)
31183 dw_loc_descr_ref tail
= NULL
;
31188 dw_loc_descr_ref l
= non_dwarf_expression (expr
);
31189 if (l
&& l
->dw_loc_next
)
31194 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
31195 tail
= new_loc_descr ((enum dwarf_location_atom
)
31196 (DW_OP_breg0
+ (l
->dw_loc_opc
- DW_OP_reg0
)),
31199 switch (l
->dw_loc_opc
)
31202 tail
= new_loc_descr (DW_OP_bregx
,
31203 l
->dw_loc_oprnd1
.v
.val_unsigned
, 0);
31205 case DW_OP_stack_value
:
31212 tail
= new_loc_descr (DW_OP_deref
, 0, 0);
31214 dw_loc_descr_ref ret
= NULL
, *p
= &ret
;
31217 *p
= new_loc_descr (expr
->dw_loc_opc
, 0, 0);
31218 (*p
)->dw_loc_oprnd1
= expr
->dw_loc_oprnd1
;
31219 (*p
)->dw_loc_oprnd2
= expr
->dw_loc_oprnd2
;
31220 p
= &(*p
)->dw_loc_next
;
31221 expr
= expr
->dw_loc_next
;
31227 /* For DW_AT_string_length attribute with DW_OP_GNU_variable_value
31228 reference to a variable or argument, adjust it if needed and return:
31229 -1 if the DW_AT_string_length attribute and DW_AT_{string_length_,}byte_size
31230 attribute if present should be removed
31231 0 keep the attribute perhaps with minor modifications, no need to rescan
31232 1 if the attribute has been successfully adjusted. */
31235 optimize_string_length (dw_attr_node
*a
)
31237 dw_loc_descr_ref l
= AT_loc (a
), lv
;
31239 if (l
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
31241 tree decl
= l
->dw_loc_oprnd1
.v
.val_decl_ref
;
31242 die
= lookup_decl_die (decl
);
31245 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
31246 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= die
;
31247 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
31253 die
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
31255 /* DWARF5 allows reference class, so we can then reference the DIE.
31256 Only do this for DW_OP_GNU_variable_value DW_OP_stack_value. */
31257 if (l
->dw_loc_next
!= NULL
&& dwarf_version
>= 5)
31259 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
31260 a
->dw_attr_val
.val_entry
= NULL
;
31261 a
->dw_attr_val
.v
.val_die_ref
.die
= die
;
31262 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
31266 dw_attr_node
*av
= get_AT (die
, DW_AT_location
);
31268 bool non_dwarf_expr
= false;
31271 return dwarf_strict
? -1 : 0;
31272 switch (AT_class (av
))
31274 case dw_val_class_loc_list
:
31275 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
31276 if (d
->expr
&& non_dwarf_expression (d
->expr
))
31277 non_dwarf_expr
= true;
31279 case dw_val_class_view_list
:
31280 gcc_unreachable ();
31281 case dw_val_class_loc
:
31284 return dwarf_strict
? -1 : 0;
31285 if (non_dwarf_expression (lv
))
31286 non_dwarf_expr
= true;
31289 return dwarf_strict
? -1 : 0;
31292 /* If it is safe to transform DW_OP_GNU_variable_value DW_OP_stack_value
31293 into DW_OP_call4 or DW_OP_GNU_variable_value into
31294 DW_OP_call4 DW_OP_deref, do so. */
31295 if (!non_dwarf_expr
31296 && (l
->dw_loc_next
!= NULL
|| AT_class (av
) == dw_val_class_loc
))
31298 l
->dw_loc_opc
= DW_OP_call4
;
31299 if (l
->dw_loc_next
)
31300 l
->dw_loc_next
= NULL
;
31302 l
->dw_loc_next
= new_loc_descr (DW_OP_deref
, 0, 0);
31306 /* For DW_OP_GNU_variable_value DW_OP_stack_value, we can just
31307 copy over the DW_AT_location attribute from die to a. */
31308 if (l
->dw_loc_next
!= NULL
)
31310 a
->dw_attr_val
= av
->dw_attr_val
;
31314 dw_loc_list_ref list
, *p
;
31315 switch (AT_class (av
))
31317 case dw_val_class_loc_list
:
31320 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
31322 lv
= copy_deref_exprloc (d
->expr
);
31325 *p
= new_loc_list (lv
, d
->begin
, d
->vbegin
, d
->end
, d
->vend
, d
->section
);
31326 p
= &(*p
)->dw_loc_next
;
31328 else if (!dwarf_strict
&& d
->expr
)
31332 return dwarf_strict
? -1 : 0;
31333 a
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
31335 *AT_loc_list_ptr (a
) = list
;
31337 case dw_val_class_loc
:
31338 lv
= copy_deref_exprloc (AT_loc (av
));
31340 return dwarf_strict
? -1 : 0;
31341 a
->dw_attr_val
.v
.val_loc
= lv
;
31344 gcc_unreachable ();
31348 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
31349 an address in .rodata section if the string literal is emitted there,
31350 or remove the containing location list or replace DW_AT_const_value
31351 with DW_AT_location and empty location expression, if it isn't found
31352 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
31353 to something that has been emitted in the current CU. */
31356 resolve_addr (dw_die_ref die
)
31360 dw_loc_list_ref
*curr
, *start
, loc
;
31362 bool remove_AT_byte_size
= false;
31364 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
31365 switch (AT_class (a
))
31367 case dw_val_class_loc_list
:
31368 start
= curr
= AT_loc_list_ptr (a
);
31371 /* The same list can be referenced more than once. See if we have
31372 already recorded the result from a previous pass. */
31374 *curr
= loc
->dw_loc_next
;
31375 else if (!loc
->resolved_addr
)
31377 /* As things stand, we do not expect or allow one die to
31378 reference a suffix of another die's location list chain.
31379 References must be identical or completely separate.
31380 There is therefore no need to cache the result of this
31381 pass on any list other than the first; doing so
31382 would lead to unnecessary writes. */
31385 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
31386 if (!resolve_addr_in_expr (a
, (*curr
)->expr
))
31388 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
31389 dw_loc_descr_ref l
= (*curr
)->expr
;
31391 if (next
&& (*curr
)->ll_symbol
)
31393 gcc_assert (!next
->ll_symbol
);
31394 next
->ll_symbol
= (*curr
)->ll_symbol
;
31395 next
->vl_symbol
= (*curr
)->vl_symbol
;
31397 if (dwarf_split_debug_info
)
31398 remove_loc_list_addr_table_entries (l
);
31403 mark_base_types ((*curr
)->expr
);
31404 curr
= &(*curr
)->dw_loc_next
;
31408 loc
->resolved_addr
= 1;
31412 loc
->dw_loc_next
= *start
;
31417 remove_AT (die
, a
->dw_attr
);
31421 case dw_val_class_view_list
:
31423 gcc_checking_assert (a
->dw_attr
== DW_AT_GNU_locviews
);
31424 gcc_checking_assert (dwarf2out_locviews_in_attribute ());
31425 dw_val_node
*llnode
31426 = view_list_to_loc_list_val_node (&a
->dw_attr_val
);
31427 /* If we no longer have a loclist, or it no longer needs
31428 views, drop this attribute. */
31429 if (!llnode
|| !llnode
->v
.val_loc_list
->vl_symbol
)
31431 remove_AT (die
, a
->dw_attr
);
31436 case dw_val_class_loc
:
31438 dw_loc_descr_ref l
= AT_loc (a
);
31439 /* DW_OP_GNU_variable_value DW_OP_stack_value or
31440 DW_OP_GNU_variable_value in DW_AT_string_length can be converted
31441 into DW_OP_call4 or DW_OP_call4 DW_OP_deref, which is standard
31442 DWARF4 unlike DW_OP_GNU_variable_value. Or for DWARF5
31443 DW_OP_GNU_variable_value DW_OP_stack_value can be replaced
31444 with DW_FORM_ref referencing the same DIE as
31445 DW_OP_GNU_variable_value used to reference. */
31446 if (a
->dw_attr
== DW_AT_string_length
31448 && l
->dw_loc_opc
== DW_OP_GNU_variable_value
31449 && (l
->dw_loc_next
== NULL
31450 || (l
->dw_loc_next
->dw_loc_next
== NULL
31451 && l
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
)))
31453 switch (optimize_string_length (a
))
31456 remove_AT (die
, a
->dw_attr
);
31458 /* If we drop DW_AT_string_length, we need to drop also
31459 DW_AT_{string_length_,}byte_size. */
31460 remove_AT_byte_size
= true;
31465 /* Even if we keep the optimized DW_AT_string_length,
31466 it might have changed AT_class, so process it again. */
31471 /* For -gdwarf-2 don't attempt to optimize
31472 DW_AT_data_member_location containing
31473 DW_OP_plus_uconst - older consumers might
31474 rely on it being that op instead of a more complex,
31475 but shorter, location description. */
31476 if ((dwarf_version
> 2
31477 || a
->dw_attr
!= DW_AT_data_member_location
31479 || l
->dw_loc_opc
!= DW_OP_plus_uconst
31480 || l
->dw_loc_next
!= NULL
)
31481 && !resolve_addr_in_expr (a
, l
))
31483 if (dwarf_split_debug_info
)
31484 remove_loc_list_addr_table_entries (l
);
31486 && l
->dw_loc_next
== NULL
31487 && l
->dw_loc_opc
== DW_OP_addr
31488 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
31489 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
31490 && a
->dw_attr
== DW_AT_location
)
31492 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
31493 remove_AT (die
, a
->dw_attr
);
31495 optimize_location_into_implicit_ptr (die
, decl
);
31498 if (a
->dw_attr
== DW_AT_string_length
)
31499 /* If we drop DW_AT_string_length, we need to drop also
31500 DW_AT_{string_length_,}byte_size. */
31501 remove_AT_byte_size
= true;
31502 remove_AT (die
, a
->dw_attr
);
31506 mark_base_types (l
);
31509 case dw_val_class_addr
:
31510 if (a
->dw_attr
== DW_AT_const_value
31511 && !resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
))
31513 if (AT_index (a
) != NOT_INDEXED
)
31514 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
31515 remove_AT (die
, a
->dw_attr
);
31518 if ((die
->die_tag
== DW_TAG_call_site
31519 && a
->dw_attr
== DW_AT_call_origin
)
31520 || (die
->die_tag
== DW_TAG_GNU_call_site
31521 && a
->dw_attr
== DW_AT_abstract_origin
))
31523 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
31524 dw_die_ref tdie
= lookup_decl_die (tdecl
);
31527 && DECL_EXTERNAL (tdecl
)
31528 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
31529 && (cdie
= lookup_context_die (DECL_CONTEXT (tdecl
))))
31531 dw_die_ref pdie
= cdie
;
31532 /* Make sure we don't add these DIEs into type units.
31533 We could emit skeleton DIEs for context (namespaces,
31534 outer structs/classes) and a skeleton DIE for the
31535 innermost context with DW_AT_signature pointing to the
31536 type unit. See PR78835. */
31537 while (pdie
&& pdie
->die_tag
!= DW_TAG_type_unit
)
31538 pdie
= pdie
->die_parent
;
31541 /* Creating a full DIE for tdecl is overly expensive and
31542 at this point even wrong when in the LTO phase
31543 as it can end up generating new type DIEs we didn't
31544 output and thus optimize_external_refs will crash. */
31545 tdie
= new_die (DW_TAG_subprogram
, cdie
, NULL_TREE
);
31546 add_AT_flag (tdie
, DW_AT_external
, 1);
31547 add_AT_flag (tdie
, DW_AT_declaration
, 1);
31548 add_linkage_attr (tdie
, tdecl
);
31549 add_name_and_src_coords_attributes (tdie
, tdecl
, true);
31550 equate_decl_number_to_die (tdecl
, tdie
);
31555 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
31556 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
31557 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
31561 if (AT_index (a
) != NOT_INDEXED
)
31562 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
31563 remove_AT (die
, a
->dw_attr
);
31572 if (remove_AT_byte_size
)
31573 remove_AT (die
, dwarf_version
>= 5
31574 ? DW_AT_string_length_byte_size
31575 : DW_AT_byte_size
);
31577 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
31580 /* Helper routines for optimize_location_lists.
31581 This pass tries to share identical local lists in .debug_loc
31584 /* Iteratively hash operands of LOC opcode into HSTATE. */
31587 hash_loc_operands (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
31589 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
31590 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
31592 switch (loc
->dw_loc_opc
)
31594 case DW_OP_const4u
:
31595 case DW_OP_const8u
:
31599 case DW_OP_const1u
:
31600 case DW_OP_const1s
:
31601 case DW_OP_const2u
:
31602 case DW_OP_const2s
:
31603 case DW_OP_const4s
:
31604 case DW_OP_const8s
:
31608 case DW_OP_plus_uconst
:
31644 case DW_OP_deref_size
:
31645 case DW_OP_xderef_size
:
31646 hstate
.add_object (val1
->v
.val_int
);
31653 gcc_assert (val1
->val_class
== dw_val_class_loc
);
31654 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
31655 hstate
.add_object (offset
);
31658 case DW_OP_implicit_value
:
31659 hstate
.add_object (val1
->v
.val_unsigned
);
31660 switch (val2
->val_class
)
31662 case dw_val_class_const
:
31663 hstate
.add_object (val2
->v
.val_int
);
31665 case dw_val_class_vec
:
31667 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
31668 unsigned int len
= val2
->v
.val_vec
.length
;
31670 hstate
.add_int (elt_size
);
31671 hstate
.add_int (len
);
31672 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
31675 case dw_val_class_const_double
:
31676 hstate
.add_object (val2
->v
.val_double
.low
);
31677 hstate
.add_object (val2
->v
.val_double
.high
);
31679 case dw_val_class_wide_int
:
31680 hstate
.add (val2
->v
.val_wide
->get_val (),
31681 get_full_len (*val2
->v
.val_wide
)
31682 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
31684 case dw_val_class_addr
:
31685 inchash::add_rtx (val2
->v
.val_addr
, hstate
);
31688 gcc_unreachable ();
31692 case DW_OP_bit_piece
:
31693 hstate
.add_object (val1
->v
.val_int
);
31694 hstate
.add_object (val2
->v
.val_int
);
31700 unsigned char dtprel
= 0xd1;
31701 hstate
.add_object (dtprel
);
31703 inchash::add_rtx (val1
->v
.val_addr
, hstate
);
31705 case DW_OP_GNU_addr_index
:
31707 case DW_OP_GNU_const_index
:
31712 unsigned char dtprel
= 0xd1;
31713 hstate
.add_object (dtprel
);
31715 inchash::add_rtx (val1
->val_entry
->addr
.rtl
, hstate
);
31718 case DW_OP_implicit_pointer
:
31719 case DW_OP_GNU_implicit_pointer
:
31720 hstate
.add_int (val2
->v
.val_int
);
31722 case DW_OP_entry_value
:
31723 case DW_OP_GNU_entry_value
:
31724 hstate
.add_object (val1
->v
.val_loc
);
31726 case DW_OP_regval_type
:
31727 case DW_OP_deref_type
:
31728 case DW_OP_GNU_regval_type
:
31729 case DW_OP_GNU_deref_type
:
31731 unsigned int byte_size
31732 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
31733 unsigned int encoding
31734 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
31735 hstate
.add_object (val1
->v
.val_int
);
31736 hstate
.add_object (byte_size
);
31737 hstate
.add_object (encoding
);
31740 case DW_OP_convert
:
31741 case DW_OP_reinterpret
:
31742 case DW_OP_GNU_convert
:
31743 case DW_OP_GNU_reinterpret
:
31744 if (val1
->val_class
== dw_val_class_unsigned_const
)
31746 hstate
.add_object (val1
->v
.val_unsigned
);
31750 case DW_OP_const_type
:
31751 case DW_OP_GNU_const_type
:
31753 unsigned int byte_size
31754 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
31755 unsigned int encoding
31756 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
31757 hstate
.add_object (byte_size
);
31758 hstate
.add_object (encoding
);
31759 if (loc
->dw_loc_opc
!= DW_OP_const_type
31760 && loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
31762 hstate
.add_object (val2
->val_class
);
31763 switch (val2
->val_class
)
31765 case dw_val_class_const
:
31766 hstate
.add_object (val2
->v
.val_int
);
31768 case dw_val_class_vec
:
31770 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
31771 unsigned int len
= val2
->v
.val_vec
.length
;
31773 hstate
.add_object (elt_size
);
31774 hstate
.add_object (len
);
31775 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
31778 case dw_val_class_const_double
:
31779 hstate
.add_object (val2
->v
.val_double
.low
);
31780 hstate
.add_object (val2
->v
.val_double
.high
);
31782 case dw_val_class_wide_int
:
31783 hstate
.add (val2
->v
.val_wide
->get_val (),
31784 get_full_len (*val2
->v
.val_wide
)
31785 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
31788 gcc_unreachable ();
31794 /* Other codes have no operands. */
31799 /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
31802 hash_locs (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
31804 dw_loc_descr_ref l
;
31805 bool sizes_computed
= false;
31806 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
31807 size_of_locs (loc
);
31809 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
31811 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
31812 hstate
.add_object (opc
);
31813 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
31815 size_of_locs (loc
);
31816 sizes_computed
= true;
31818 hash_loc_operands (l
, hstate
);
31822 /* Compute hash of the whole location list LIST_HEAD. */
31825 hash_loc_list (dw_loc_list_ref list_head
)
31827 dw_loc_list_ref curr
= list_head
;
31828 inchash::hash hstate
;
31830 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
31832 hstate
.add (curr
->begin
, strlen (curr
->begin
) + 1);
31833 hstate
.add (curr
->end
, strlen (curr
->end
) + 1);
31834 hstate
.add_object (curr
->vbegin
);
31835 hstate
.add_object (curr
->vend
);
31837 hstate
.add (curr
->section
, strlen (curr
->section
) + 1);
31838 hash_locs (curr
->expr
, hstate
);
31840 list_head
->hash
= hstate
.end ();
31843 /* Return true if X and Y opcodes have the same operands. */
31846 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
31848 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
31849 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
31850 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
31851 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
31853 switch (x
->dw_loc_opc
)
31855 case DW_OP_const4u
:
31856 case DW_OP_const8u
:
31860 case DW_OP_const1u
:
31861 case DW_OP_const1s
:
31862 case DW_OP_const2u
:
31863 case DW_OP_const2s
:
31864 case DW_OP_const4s
:
31865 case DW_OP_const8s
:
31869 case DW_OP_plus_uconst
:
31905 case DW_OP_deref_size
:
31906 case DW_OP_xderef_size
:
31907 return valx1
->v
.val_int
== valy1
->v
.val_int
;
31910 /* If splitting debug info, the use of DW_OP_GNU_addr_index
31911 can cause irrelevant differences in dw_loc_addr. */
31912 gcc_assert (valx1
->val_class
== dw_val_class_loc
31913 && valy1
->val_class
== dw_val_class_loc
31914 && (dwarf_split_debug_info
31915 || x
->dw_loc_addr
== y
->dw_loc_addr
));
31916 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
31917 case DW_OP_implicit_value
:
31918 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
31919 || valx2
->val_class
!= valy2
->val_class
)
31921 switch (valx2
->val_class
)
31923 case dw_val_class_const
:
31924 return valx2
->v
.val_int
== valy2
->v
.val_int
;
31925 case dw_val_class_vec
:
31926 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
31927 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
31928 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
31929 valx2
->v
.val_vec
.elt_size
31930 * valx2
->v
.val_vec
.length
) == 0;
31931 case dw_val_class_const_double
:
31932 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
31933 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
31934 case dw_val_class_wide_int
:
31935 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
31936 case dw_val_class_addr
:
31937 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
31939 gcc_unreachable ();
31942 case DW_OP_bit_piece
:
31943 return valx1
->v
.val_int
== valy1
->v
.val_int
31944 && valx2
->v
.val_int
== valy2
->v
.val_int
;
31947 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
31948 case DW_OP_GNU_addr_index
:
31950 case DW_OP_GNU_const_index
:
31953 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
31954 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
31955 return rtx_equal_p (ax1
, ay1
);
31957 case DW_OP_implicit_pointer
:
31958 case DW_OP_GNU_implicit_pointer
:
31959 return valx1
->val_class
== dw_val_class_die_ref
31960 && valx1
->val_class
== valy1
->val_class
31961 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
31962 && valx2
->v
.val_int
== valy2
->v
.val_int
;
31963 case DW_OP_entry_value
:
31964 case DW_OP_GNU_entry_value
:
31965 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
31966 case DW_OP_const_type
:
31967 case DW_OP_GNU_const_type
:
31968 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
31969 || valx2
->val_class
!= valy2
->val_class
)
31971 switch (valx2
->val_class
)
31973 case dw_val_class_const
:
31974 return valx2
->v
.val_int
== valy2
->v
.val_int
;
31975 case dw_val_class_vec
:
31976 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
31977 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
31978 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
31979 valx2
->v
.val_vec
.elt_size
31980 * valx2
->v
.val_vec
.length
) == 0;
31981 case dw_val_class_const_double
:
31982 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
31983 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
31984 case dw_val_class_wide_int
:
31985 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
31987 gcc_unreachable ();
31989 case DW_OP_regval_type
:
31990 case DW_OP_deref_type
:
31991 case DW_OP_GNU_regval_type
:
31992 case DW_OP_GNU_deref_type
:
31993 return valx1
->v
.val_int
== valy1
->v
.val_int
31994 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
31995 case DW_OP_convert
:
31996 case DW_OP_reinterpret
:
31997 case DW_OP_GNU_convert
:
31998 case DW_OP_GNU_reinterpret
:
31999 if (valx1
->val_class
!= valy1
->val_class
)
32001 if (valx1
->val_class
== dw_val_class_unsigned_const
)
32002 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
32003 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
32004 case DW_OP_GNU_parameter_ref
:
32005 return valx1
->val_class
== dw_val_class_die_ref
32006 && valx1
->val_class
== valy1
->val_class
32007 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
32009 /* Other codes have no operands. */
32014 /* Return true if DWARF location expressions X and Y are the same. */
32017 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
32019 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
32020 if (x
->dw_loc_opc
!= y
->dw_loc_opc
32021 || x
->dtprel
!= y
->dtprel
32022 || !compare_loc_operands (x
, y
))
32024 return x
== NULL
&& y
== NULL
;
32027 /* Hashtable helpers. */
32029 struct loc_list_hasher
: nofree_ptr_hash
<dw_loc_list_struct
>
32031 static inline hashval_t
hash (const dw_loc_list_struct
*);
32032 static inline bool equal (const dw_loc_list_struct
*,
32033 const dw_loc_list_struct
*);
32036 /* Return precomputed hash of location list X. */
32039 loc_list_hasher::hash (const dw_loc_list_struct
*x
)
32044 /* Return true if location lists A and B are the same. */
32047 loc_list_hasher::equal (const dw_loc_list_struct
*a
,
32048 const dw_loc_list_struct
*b
)
32052 if (a
->hash
!= b
->hash
)
32054 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
32055 if (strcmp (a
->begin
, b
->begin
) != 0
32056 || strcmp (a
->end
, b
->end
) != 0
32057 || (a
->section
== NULL
) != (b
->section
== NULL
)
32058 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
32059 || a
->vbegin
!= b
->vbegin
|| a
->vend
!= b
->vend
32060 || !compare_locs (a
->expr
, b
->expr
))
32062 return a
== NULL
&& b
== NULL
;
32065 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
32068 /* Recursively optimize location lists referenced from DIE
32069 children and share them whenever possible. */
32072 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type
*htab
)
32077 dw_loc_list_struct
**slot
;
32078 bool drop_locviews
= false;
32079 bool has_locviews
= false;
32081 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
32082 if (AT_class (a
) == dw_val_class_loc_list
)
32084 dw_loc_list_ref list
= AT_loc_list (a
);
32085 /* TODO: perform some optimizations here, before hashing
32086 it and storing into the hash table. */
32087 hash_loc_list (list
);
32088 slot
= htab
->find_slot_with_hash (list
, list
->hash
, INSERT
);
32092 if (loc_list_has_views (list
))
32093 gcc_assert (list
->vl_symbol
);
32094 else if (list
->vl_symbol
)
32096 drop_locviews
= true;
32097 list
->vl_symbol
= NULL
;
32102 if (list
->vl_symbol
&& !(*slot
)->vl_symbol
)
32103 drop_locviews
= true;
32104 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
32107 else if (AT_class (a
) == dw_val_class_view_list
)
32109 gcc_checking_assert (a
->dw_attr
== DW_AT_GNU_locviews
);
32110 has_locviews
= true;
32114 if (drop_locviews
&& has_locviews
)
32115 remove_AT (die
, DW_AT_GNU_locviews
);
32117 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
32121 /* Recursively assign each location list a unique index into the debug_addr
32125 index_location_lists (dw_die_ref die
)
32131 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
32132 if (AT_class (a
) == dw_val_class_loc_list
)
32134 dw_loc_list_ref list
= AT_loc_list (a
);
32135 dw_loc_list_ref curr
;
32136 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
32138 /* Don't index an entry that has already been indexed
32139 or won't be output. Make sure skip_loc_list_entry doesn't
32140 call size_of_locs, because that might cause circular dependency,
32141 index_location_lists requiring address table indexes to be
32142 computed, but adding new indexes through add_addr_table_entry
32143 and address table index computation requiring no new additions
32144 to the hash table. In the rare case of DWARF[234] >= 64KB
32145 location expression, we'll just waste unused address table entry
32147 if (curr
->begin_entry
!= NULL
|| skip_loc_list_entry (curr
))
32151 = add_addr_table_entry (xstrdup (curr
->begin
), ate_kind_label
);
32152 if (dwarf_version
>= 5 && !HAVE_AS_LEB128
)
32154 = add_addr_table_entry (xstrdup (curr
->end
), ate_kind_label
);
32158 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
32161 /* Optimize location lists referenced from DIE
32162 children and share them whenever possible. */
32165 optimize_location_lists (dw_die_ref die
)
32167 loc_list_hash_type
htab (500);
32168 optimize_location_lists_1 (die
, &htab
);
32171 /* Traverse the limbo die list, and add parent/child links. The only
32172 dies without parents that should be here are concrete instances of
32173 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
32174 For concrete instances, we can get the parent die from the abstract
32178 flush_limbo_die_list (void)
32180 limbo_die_node
*node
;
32182 /* get_context_die calls force_decl_die, which can put new DIEs on the
32183 limbo list in LTO mode when nested functions are put in a different
32184 partition than that of their parent function. */
32185 while ((node
= limbo_die_list
))
32187 dw_die_ref die
= node
->die
;
32188 limbo_die_list
= node
->next
;
32190 if (die
->die_parent
== NULL
)
32192 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
32194 if (origin
&& origin
->die_parent
)
32195 add_child_die (origin
->die_parent
, die
);
32196 else if (is_cu_die (die
))
32198 else if (seen_error ())
32199 /* It's OK to be confused by errors in the input. */
32200 add_child_die (comp_unit_die (), die
);
32203 /* In certain situations, the lexical block containing a
32204 nested function can be optimized away, which results
32205 in the nested function die being orphaned. Likewise
32206 with the return type of that nested function. Force
32207 this to be a child of the containing function.
32209 It may happen that even the containing function got fully
32210 inlined and optimized out. In that case we are lost and
32211 assign the empty child. This should not be big issue as
32212 the function is likely unreachable too. */
32213 gcc_assert (node
->created_for
);
32215 if (DECL_P (node
->created_for
))
32216 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
32217 else if (TYPE_P (node
->created_for
))
32218 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
32220 origin
= comp_unit_die ();
32222 add_child_die (origin
, die
);
32228 /* Reset DIEs so we can output them again. */
32231 reset_dies (dw_die_ref die
)
32235 /* Remove stuff we re-generate. */
32237 die
->die_offset
= 0;
32238 die
->die_abbrev
= 0;
32239 remove_AT (die
, DW_AT_sibling
);
32241 FOR_EACH_CHILD (die
, c
, reset_dies (c
));
32244 /* reset_indirect_string removed the references coming from DW_AT_name
32245 and DW_AT_comp_dir attributes on compilation unit DIEs. Readd them as
32246 .debug_line_str strings again. */
32249 adjust_name_comp_dir (dw_die_ref die
)
32251 for (int i
= 0; i
< 2; i
++)
32253 dwarf_attribute attr_kind
= i
? DW_AT_comp_dir
: DW_AT_name
;
32254 dw_attr_node
*a
= get_AT (die
, attr_kind
);
32255 if (a
== NULL
|| a
->dw_attr_val
.val_class
!= dw_val_class_str
)
32258 if (!debug_line_str_hash
)
32259 debug_line_str_hash
32260 = hash_table
<indirect_string_hasher
>::create_ggc (10);
32262 struct indirect_string_node
*node
32263 = find_AT_string_in_table (a
->dw_attr_val
.v
.val_str
->str
,
32264 debug_line_str_hash
);
32265 set_indirect_string (node
);
32266 node
->form
= DW_FORM_line_strp
;
32267 a
->dw_attr_val
.v
.val_str
= node
;
32271 /* Output stuff that dwarf requires at the end of every file,
32272 and generate the DWARF-2 debugging info. */
32275 dwarf2out_finish (const char *filename
)
32277 comdat_type_node
*ctnode
;
32278 dw_die_ref main_comp_unit_die
;
32279 unsigned char checksum
[16];
32280 char dl_section_ref
[MAX_ARTIFICIAL_LABEL_BYTES
];
32282 /* Generate CTF/BTF debug info. */
32283 if ((ctf_debug_info_level
> CTFINFO_LEVEL_NONE
32284 || btf_debuginfo_p ()) && lang_GNU_C ())
32285 ctf_debug_finish (filename
);
32287 #ifdef CODEVIEW_DEBUGGING_INFO
32288 if (codeview_debuginfo_p ())
32289 codeview_debug_finish ();
32292 /* Skip emitting DWARF if not required. */
32293 if (!dwarf_debuginfo_p ())
32296 /* Flush out any latecomers to the limbo party. */
32297 flush_limbo_die_list ();
32299 if (inline_entry_data_table
)
32300 gcc_assert (inline_entry_data_table
->is_empty ());
32304 verify_die (comp_unit_die ());
32305 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
32306 verify_die (node
->die
);
32309 /* We shouldn't have any symbols with delayed asm names for
32310 DIEs generated after early finish. */
32311 gcc_assert (deferred_asm_name
== NULL
);
32313 gen_remaining_tmpl_value_param_die_attribute ();
32315 if (flag_generate_lto
|| flag_generate_offload
)
32317 gcc_assert (flag_fat_lto_objects
|| flag_generate_offload
);
32319 /* Prune stuff so that dwarf2out_finish runs successfully
32320 for the fat part of the object. */
32321 reset_dies (comp_unit_die ());
32322 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
32323 reset_dies (node
->die
);
32324 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
32326 /* Remove the pointer to the line table. */
32327 remove_AT (ctnode
->root_die
, DW_AT_stmt_list
);
32328 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
32329 reset_dies (ctnode
->root_die
);
32332 /* Reset die CU symbol so we don't output it twice. */
32333 comp_unit_die ()->die_id
.die_symbol
= NULL
;
32335 /* Remove DW_AT_macro and DW_AT_stmt_list from the early output. */
32336 remove_AT (comp_unit_die (), DW_AT_stmt_list
);
32338 remove_AT (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE
);
32340 /* Remove indirect string decisions. */
32341 debug_str_hash
->traverse
<void *, reset_indirect_string
> (NULL
);
32342 if (debug_line_str_hash
)
32344 debug_line_str_hash
->traverse
<void *, reset_indirect_string
> (NULL
);
32345 debug_line_str_hash
= NULL
;
32346 if (asm_outputs_debug_line_str ())
32348 adjust_name_comp_dir (comp_unit_die ());
32349 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
32350 adjust_name_comp_dir (node
->die
);
32355 #if ENABLE_ASSERT_CHECKING
32357 dw_die_ref die
= comp_unit_die (), c
;
32358 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
32361 base_types
.truncate (0);
32362 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
32363 resolve_addr (ctnode
->root_die
);
32364 resolve_addr (comp_unit_die ());
32365 move_marked_base_types ();
32369 fprintf (dump_file
, "DWARF for %s\n", filename
);
32370 print_die (comp_unit_die (), dump_file
);
32373 /* Initialize sections and labels used for actual assembler output. */
32374 unsigned generation
= init_sections_and_labels (false);
32376 /* Traverse the DIE's and add sibling attributes to those DIE's that
32378 add_sibling_attributes (comp_unit_die ());
32379 limbo_die_node
*node
;
32380 for (node
= cu_die_list
; node
; node
= node
->next
)
32381 add_sibling_attributes (node
->die
);
32382 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
32383 add_sibling_attributes (ctnode
->root_die
);
32385 /* When splitting DWARF info, we put some attributes in the
32386 skeleton compile_unit DIE that remains in the .o, while
32387 most attributes go in the DWO compile_unit_die. */
32388 if (dwarf_split_debug_info
)
32390 limbo_die_node
*cu
;
32391 main_comp_unit_die
= gen_compile_unit_die (NULL
);
32392 if (dwarf_version
>= 5)
32393 main_comp_unit_die
->die_tag
= DW_TAG_skeleton_unit
;
32394 cu
= limbo_die_list
;
32395 gcc_assert (cu
->die
== main_comp_unit_die
);
32396 limbo_die_list
= limbo_die_list
->next
;
32397 cu
->next
= cu_die_list
;
32401 main_comp_unit_die
= comp_unit_die ();
32403 /* Output a terminator label for the .text section. */
32404 switch_to_section (text_section
);
32405 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
32406 if (cold_text_section
)
32408 switch_to_section (cold_text_section
);
32409 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
32412 /* We can only use the low/high_pc attributes if all of the code was
32414 if ((!have_multiple_function_sections
32415 && vec_safe_length (switch_text_ranges
) < 2)
32416 || (dwarf_version
< 3 && dwarf_strict
))
32418 const char *end_label
= text_end_label
;
32419 if (vec_safe_length (switch_text_ranges
) == 1)
32420 end_label
= (*switch_text_ranges
)[0];
32421 /* Don't add if the CU has no associated code. */
32422 if (switch_text_ranges
)
32423 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
32430 bool range_list_added
= false;
32431 if (switch_text_ranges
)
32433 const char *prev_loc
= text_section_label
;
32437 FOR_EACH_VEC_ELT (*switch_text_ranges
, idx
, loc
)
32440 add_ranges_by_labels (main_comp_unit_die
, prev_loc
,
32441 loc
, &range_list_added
, true);
32448 add_ranges_by_labels (main_comp_unit_die
, prev_loc
,
32449 text_end_label
, &range_list_added
, true);
32452 if (switch_cold_ranges
)
32454 const char *prev_loc
= cold_text_section_label
;
32458 FOR_EACH_VEC_ELT (*switch_cold_ranges
, idx
, loc
)
32461 add_ranges_by_labels (main_comp_unit_die
, prev_loc
,
32462 loc
, &range_list_added
, true);
32469 add_ranges_by_labels (main_comp_unit_die
, prev_loc
,
32470 cold_end_label
, &range_list_added
, true);
32473 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
32475 if (fde
->ignored_debug
)
32477 if (!fde
->in_std_section
)
32478 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
32479 fde
->dw_fde_end
, &range_list_added
,
32481 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
32482 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
32483 fde
->dw_fde_second_end
, &range_list_added
,
32487 if (range_list_added
)
32489 /* We need to give .debug_loc and .debug_ranges an appropriate
32490 "base address". Use zero so that these addresses become
32491 absolute. Historically, we've emitted the unexpected
32492 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
32493 Emit both to give time for other tools to adapt. */
32494 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
32495 if (! dwarf_strict
&& dwarf_version
< 4)
32496 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
32499 have_multiple_function_sections
= true;
32503 /* AIX Assembler inserts the length, so adjust the reference to match the
32504 offset expected by debuggers. */
32505 strcpy (dl_section_ref
, debug_line_section_label
);
32506 if (XCOFF_DEBUGGING_INFO
)
32507 strcat (dl_section_ref
, DWARF_INITIAL_LENGTH_SIZE_STR
);
32509 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
32510 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
32514 add_AT_macptr (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE
,
32515 macinfo_section_label
);
32517 if (dwarf_split_debug_info
)
32519 if (have_location_lists
)
32521 /* Since we generate the loclists in the split DWARF .dwo
32522 file itself, we don't need to generate a loclists_base
32523 attribute for the split compile unit DIE. That attribute
32524 (and using relocatable sec_offset FORMs) isn't allowed
32525 for a split compile unit. Only if the .debug_loclists
32526 section was in the main file, would we need to generate a
32527 loclists_base attribute here (for the full or skeleton
32530 /* optimize_location_lists calculates the size of the lists,
32531 so index them first, and assign indices to the entries.
32532 Although optimize_location_lists will remove entries from
32533 the table, it only does so for duplicates, and therefore
32534 only reduces ref_counts to 1. */
32535 index_location_lists (comp_unit_die ());
32538 if (dwarf_version
>= 5 && !vec_safe_is_empty (ranges_table
))
32541 if (addr_index_table
!= NULL
)
32543 unsigned int index
= 0;
32545 ->traverse_noresize
<unsigned int *, index_addr_table_entry
>
32551 if (have_location_lists
)
32553 optimize_location_lists (comp_unit_die ());
32554 /* And finally assign indexes to the entries for -gsplit-dwarf. */
32555 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
32556 assign_location_list_indexes (comp_unit_die ());
32559 save_macinfo_strings ();
32561 if (dwarf_split_debug_info
)
32563 unsigned int index
= 0;
32565 /* Add attributes common to skeleton compile_units and
32566 type_units. Because these attributes include strings, it
32567 must be done before freezing the string table. Top-level
32568 skeleton die attrs are added when the skeleton type unit is
32569 created, so ensure it is created by this point. */
32570 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
32571 debug_str_hash
->traverse_noresize
<unsigned int *, index_string
> (&index
);
32574 /* Output all of the compilation units. We put the main one last so that
32575 the offsets are available to output_pubnames. */
32576 for (node
= cu_die_list
; node
; node
= node
->next
)
32577 output_comp_unit (node
->die
, 0, NULL
);
32579 hash_table
<comdat_type_hasher
> comdat_type_table (100);
32580 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
32582 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
32584 /* Don't output duplicate types. */
32585 if (*slot
!= HTAB_EMPTY_ENTRY
)
32588 /* Add a pointer to the line table for the main compilation unit
32589 so that the debugger can make sense of DW_AT_decl_file
32591 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
32592 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
32593 (!dwarf_split_debug_info
32595 : debug_skeleton_line_section_label
));
32597 output_comdat_type_unit (ctnode
, false);
32601 if (dwarf_split_debug_info
)
32604 struct md5_ctx ctx
;
32606 /* Compute a checksum of the comp_unit to use as the dwo_id. */
32607 md5_init_ctx (&ctx
);
32609 die_checksum (comp_unit_die (), &ctx
, &mark
);
32610 unmark_all_dies (comp_unit_die ());
32611 md5_finish_ctx (&ctx
, checksum
);
32613 if (dwarf_version
< 5)
32615 /* Use the first 8 bytes of the checksum as the dwo_id,
32616 and add it to both comp-unit DIEs. */
32617 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
32618 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
32621 /* Add the base offset of the ranges table to the skeleton
32623 if (!vec_safe_is_empty (ranges_table
))
32625 if (dwarf_version
< 5)
32626 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
32627 ranges_section_label
);
32630 output_addr_table ();
32633 /* Output the main compilation unit if non-empty or if .debug_macinfo
32634 or .debug_macro will be emitted. */
32635 output_comp_unit (comp_unit_die (), have_macinfo
,
32636 dwarf_split_debug_info
? checksum
: NULL
);
32638 if (dwarf_split_debug_info
&& info_section_emitted
)
32639 output_skeleton_debug_sections (main_comp_unit_die
, checksum
);
32641 /* Output the abbreviation table. */
32642 if (vec_safe_length (abbrev_die_table
) != 1)
32644 switch_to_section (debug_abbrev_section
);
32645 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
32646 output_abbrev_section ();
32649 /* Output location list section if necessary. */
32650 if (have_location_lists
)
32652 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
32653 char l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
32654 /* Output the location lists info. */
32655 switch_to_section (debug_loc_section
);
32656 if (dwarf_version
>= 5)
32658 ASM_GENERATE_INTERNAL_LABEL (l1
, DEBUG_LOC_SECTION_LABEL
, 2);
32659 ASM_GENERATE_INTERNAL_LABEL (l2
, DEBUG_LOC_SECTION_LABEL
, 3);
32660 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
32661 dw2_asm_output_data (4, 0xffffffff,
32662 "Initial length escape value indicating "
32663 "64-bit DWARF extension");
32664 dw2_asm_output_delta (dwarf_offset_size
, l2
, l1
,
32665 "Length of Location Lists");
32666 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
32667 output_dwarf_version ();
32668 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
32669 dw2_asm_output_data (1, 0, "Segment Size");
32670 dw2_asm_output_data (4, dwarf_split_debug_info
? loc_list_idx
: 0,
32671 "Offset Entry Count");
32673 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
32674 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
32676 unsigned int save_loc_list_idx
= loc_list_idx
;
32678 output_loclists_offsets (comp_unit_die ());
32679 gcc_assert (save_loc_list_idx
== loc_list_idx
);
32681 output_location_lists (comp_unit_die ());
32682 if (dwarf_version
>= 5)
32683 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
32686 output_pubtables ();
32688 /* Output the address range information if a CU (.debug_info section)
32689 was emitted. We output an empty table even if we had no functions
32690 to put in it. This because the consumer has no way to tell the
32691 difference between an empty table that we omitted and failure to
32692 generate a table that would have contained data. */
32693 if (info_section_emitted
)
32695 switch_to_section (debug_aranges_section
);
32699 /* Output ranges section if necessary. */
32700 if (!vec_safe_is_empty (ranges_table
))
32702 if (dwarf_version
>= 5)
32704 if (dwarf_split_debug_info
)
32706 /* We don't know right now whether there are any
32707 ranges for .debug_rnglists and any for .debug_rnglists.dwo.
32708 Depending on into which of those two belongs the first
32709 ranges_table entry, emit that section first and that
32710 output_rnglists call will return true if the other kind of
32711 ranges needs to be emitted as well. */
32712 bool dwo
= (*ranges_table
)[0].idx
!= DW_RANGES_IDX_SKELETON
;
32713 if (output_rnglists (generation
, dwo
))
32714 output_rnglists (generation
, !dwo
);
32717 output_rnglists (generation
, false);
32723 /* Have to end the macro section. */
32726 switch_to_section (debug_macinfo_section
);
32727 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
32728 output_macinfo (!dwarf_split_debug_info
? debug_line_section_label
32729 : debug_skeleton_line_section_label
, false);
32730 dw2_asm_output_data (1, 0, "End compilation unit");
32733 /* Output the source line correspondence table. We must do this
32734 even if there is no line information. Otherwise, on an empty
32735 translation unit, we will generate a present, but empty,
32736 .debug_info section. IRIX 6.5 `nm' will then complain when
32737 examining the file. This is done late so that any filenames
32738 used by the debug_info section are marked as 'used'. */
32739 switch_to_section (debug_line_section
);
32740 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
32741 if (! output_asm_line_debug_info ())
32742 output_line_info (false);
32744 if (dwarf_split_debug_info
&& info_section_emitted
)
32746 switch_to_section (debug_skeleton_line_section
);
32747 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
32748 output_line_info (true);
32751 /* If we emitted any indirect strings, output the string table too. */
32752 if (debug_str_hash
|| skeleton_debug_str_hash
)
32753 output_indirect_strings ();
32754 if (debug_line_str_hash
)
32756 switch_to_section (debug_line_str_section
);
32757 const enum dwarf_form form
= DW_FORM_line_strp
;
32758 debug_line_str_hash
->traverse
<enum dwarf_form
,
32759 output_indirect_string
> (form
);
32762 /* ??? Move lvugid out of dwarf2out_source_line and reset it too? */
32763 symview_upper_bound
= 0;
32765 bitmap_clear (zero_view_p
);
32768 /* Returns a hash value for X (which really is a variable_value_struct). */
32771 variable_value_hasher::hash (variable_value_struct
*x
)
32773 return (hashval_t
) x
->decl_id
;
32776 /* Return true if decl_id of variable_value_struct X is the same as
32780 variable_value_hasher::equal (variable_value_struct
*x
, tree y
)
32782 return x
->decl_id
== DECL_UID (y
);
32785 /* Helper function for resolve_variable_value, handle
32786 DW_OP_GNU_variable_value in one location expression.
32787 Return true if exprloc has been changed into loclist. */
32790 resolve_variable_value_in_expr (dw_attr_node
*a
, dw_loc_descr_ref loc
)
32792 dw_loc_descr_ref next
;
32793 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= next
)
32795 next
= loc
->dw_loc_next
;
32796 if (loc
->dw_loc_opc
!= DW_OP_GNU_variable_value
32797 || loc
->dw_loc_oprnd1
.val_class
!= dw_val_class_decl_ref
)
32800 tree decl
= loc
->dw_loc_oprnd1
.v
.val_decl_ref
;
32801 if (DECL_CONTEXT (decl
) != current_function_decl
)
32804 dw_die_ref ref
= lookup_decl_die (decl
);
32807 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
32808 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
32809 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
32812 dw_loc_list_ref l
= loc_list_from_tree (decl
, 0, NULL
);
32815 if (l
->dw_loc_next
)
32817 if (AT_class (a
) != dw_val_class_loc
)
32819 switch (a
->dw_attr
)
32821 /* Following attributes allow both exprloc and loclist
32822 classes, so we can change them into a loclist. */
32823 case DW_AT_location
:
32824 case DW_AT_string_length
:
32825 case DW_AT_return_addr
:
32826 case DW_AT_data_member_location
:
32827 case DW_AT_frame_base
:
32828 case DW_AT_segment
:
32829 case DW_AT_static_link
:
32830 case DW_AT_use_location
:
32831 case DW_AT_vtable_elem_location
:
32834 prev
->dw_loc_next
= NULL
;
32835 prepend_loc_descr_to_each (l
, AT_loc (a
));
32838 add_loc_descr_to_each (l
, next
);
32839 a
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
32840 a
->dw_attr_val
.val_entry
= NULL
;
32841 a
->dw_attr_val
.v
.val_loc_list
= l
;
32842 have_location_lists
= true;
32844 /* Following attributes allow both exprloc and reference,
32845 so if the whole expression is DW_OP_GNU_variable_value alone
32846 we could transform it into reference. */
32847 case DW_AT_byte_size
:
32848 case DW_AT_bit_size
:
32849 case DW_AT_lower_bound
:
32850 case DW_AT_upper_bound
:
32851 case DW_AT_bit_stride
:
32853 case DW_AT_allocated
:
32854 case DW_AT_associated
:
32855 case DW_AT_byte_stride
:
32856 if (prev
== NULL
&& next
== NULL
)
32864 /* Create DW_TAG_variable that we can refer to. */
32865 gen_decl_die (decl
, NULL_TREE
, NULL
,
32866 lookup_decl_die (current_function_decl
));
32867 ref
= lookup_decl_die (decl
);
32870 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
32871 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
32872 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
32878 prev
->dw_loc_next
= l
->expr
;
32879 add_loc_descr (&prev
->dw_loc_next
, next
);
32880 free_loc_descr (loc
, NULL
);
32881 next
= prev
->dw_loc_next
;
32885 memcpy (loc
, l
->expr
, sizeof (dw_loc_descr_node
));
32886 add_loc_descr (&loc
, next
);
32894 /* Attempt to resolve DW_OP_GNU_variable_value using loc_list_from_tree. */
32897 resolve_variable_value (dw_die_ref die
)
32900 dw_loc_list_ref loc
;
32903 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
32904 switch (AT_class (a
))
32906 case dw_val_class_loc
:
32907 if (!resolve_variable_value_in_expr (a
, AT_loc (a
)))
32910 case dw_val_class_loc_list
:
32911 loc
= AT_loc_list (a
);
32913 for (; loc
; loc
= loc
->dw_loc_next
)
32914 resolve_variable_value_in_expr (a
, loc
->expr
);
32921 /* Attempt to optimize DW_OP_GNU_variable_value refering to
32922 temporaries in the current function. */
32925 resolve_variable_values (void)
32927 if (!variable_value_hash
|| !current_function_decl
)
32930 struct variable_value_struct
*node
32931 = variable_value_hash
->find_with_hash (current_function_decl
,
32932 DECL_UID (current_function_decl
));
32939 FOR_EACH_VEC_SAFE_ELT (node
->dies
, i
, die
)
32940 resolve_variable_value (die
);
32943 /* Helper function for note_variable_value, handle one location
32947 note_variable_value_in_expr (dw_die_ref die
, dw_loc_descr_ref loc
)
32949 for (; loc
; loc
= loc
->dw_loc_next
)
32950 if (loc
->dw_loc_opc
== DW_OP_GNU_variable_value
32951 && loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
32953 tree decl
= loc
->dw_loc_oprnd1
.v
.val_decl_ref
;
32954 dw_die_ref ref
= lookup_decl_die (decl
);
32955 if (! ref
&& (flag_generate_lto
|| flag_generate_offload
))
32957 /* ??? This is somewhat a hack because we do not create DIEs
32958 for variables not in BLOCK trees early but when generating
32959 early LTO output we need the dw_val_class_decl_ref to be
32960 fully resolved. For fat LTO objects we'd also like to
32961 undo this after LTO dwarf output. */
32962 gcc_assert (DECL_CONTEXT (decl
));
32963 dw_die_ref ctx
= lookup_decl_die (DECL_CONTEXT (decl
));
32964 gcc_assert (ctx
!= NULL
);
32965 gen_decl_die (decl
, NULL_TREE
, NULL
, ctx
);
32966 ref
= lookup_decl_die (decl
);
32967 gcc_assert (ref
!= NULL
);
32971 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
32972 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
32973 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
32977 && DECL_CONTEXT (decl
)
32978 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
32979 && lookup_decl_die (DECL_CONTEXT (decl
)))
32981 if (!variable_value_hash
)
32982 variable_value_hash
32983 = hash_table
<variable_value_hasher
>::create_ggc (10);
32985 tree fndecl
= DECL_CONTEXT (decl
);
32986 struct variable_value_struct
*node
;
32987 struct variable_value_struct
**slot
32988 = variable_value_hash
->find_slot_with_hash (fndecl
,
32993 node
= ggc_cleared_alloc
<variable_value_struct
> ();
32994 node
->decl_id
= DECL_UID (fndecl
);
33000 vec_safe_push (node
->dies
, die
);
33005 /* Walk the tree DIE and note DIEs with DW_OP_GNU_variable_value still
33006 with dw_val_class_decl_ref operand. */
33009 note_variable_value (dw_die_ref die
)
33013 dw_loc_list_ref loc
;
33016 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
33017 switch (AT_class (a
))
33019 case dw_val_class_loc_list
:
33020 loc
= AT_loc_list (a
);
33022 if (!loc
->noted_variable_value
)
33024 loc
->noted_variable_value
= 1;
33025 for (; loc
; loc
= loc
->dw_loc_next
)
33026 note_variable_value_in_expr (die
, loc
->expr
);
33029 case dw_val_class_loc
:
33030 note_variable_value_in_expr (die
, AT_loc (a
));
33036 /* Mark children. */
33037 FOR_EACH_CHILD (die
, c
, note_variable_value (c
));
33040 /* Process DWARF dies for CTF generation. */
33043 ctf_debug_do_cu (dw_die_ref die
)
33047 if (!ctf_do_die (die
))
33050 FOR_EACH_CHILD (die
, c
, ctf_do_die (c
));
33053 /* Perform any cleanups needed after the early debug generation pass
33057 dwarf2out_early_finish (const char *filename
)
33059 comdat_type_node
*ctnode
;
33061 char dl_section_ref
[MAX_ARTIFICIAL_LABEL_BYTES
];
33063 /* PCH might result in DW_AT_producer string being restored from the
33064 header compilation, so always fill it with empty string initially
33065 and overwrite only here. */
33066 dw_attr_node
*producer
= get_AT (comp_unit_die (), DW_AT_producer
);
33068 if (dwarf_record_gcc_switches
)
33069 producer_string
= gen_producer_string (lang_hooks
.name
,
33070 save_decoded_options
,
33071 save_decoded_options_count
);
33073 producer_string
= concat (lang_hooks
.name
, " ", version_string
, NULL
);
33075 producer
->dw_attr_val
.v
.val_str
->refcount
--;
33076 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
33078 /* Add the name for the main input file now. We delayed this from
33079 dwarf2out_init to avoid complications with PCH. */
33080 add_filename_attribute (comp_unit_die (), remap_debug_filename (filename
));
33081 add_comp_dir_attribute (comp_unit_die ());
33083 /* With LTO early dwarf was really finished at compile-time, so make
33084 sure to adjust the phase after annotating the LTRANS CU DIE. */
33087 early_dwarf_finished
= true;
33090 fprintf (dump_file
, "LTO EARLY DWARF for %s\n", filename
);
33091 print_die (comp_unit_die (), dump_file
);
33096 /* Walk through the list of incomplete types again, trying once more to
33097 emit full debugging info for them. */
33098 retry_incomplete_types ();
33100 gen_scheduled_generic_parms_dies ();
33101 gen_remaining_tmpl_value_param_die_attribute ();
33103 /* The point here is to flush out the limbo list so that it is empty
33104 and we don't need to stream it for LTO. */
33105 flush_limbo_die_list ();
33107 /* Add DW_AT_linkage_name for all deferred DIEs. */
33108 for (limbo_die_node
*node
= deferred_asm_name
; node
; node
= node
->next
)
33110 tree decl
= node
->created_for
;
33111 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
33112 /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
33113 ended up in deferred_asm_name before we knew it was
33114 constant and never written to disk. */
33115 && DECL_ASSEMBLER_NAME (decl
))
33117 add_linkage_attr (node
->die
, decl
);
33118 move_linkage_attr (node
->die
);
33121 deferred_asm_name
= NULL
;
33123 if (flag_eliminate_unused_debug_types
)
33124 prune_unused_types ();
33126 /* Generate separate COMDAT sections for type DIEs. */
33127 if (use_debug_types
)
33129 break_out_comdat_types (comp_unit_die ());
33131 /* Each new type_unit DIE was added to the limbo die list when created.
33132 Since these have all been added to comdat_type_list, clear the
33134 limbo_die_list
= NULL
;
33136 /* For each new comdat type unit, copy declarations for incomplete
33137 types to make the new unit self-contained (i.e., no direct
33138 references to the main compile unit). */
33139 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
33140 copy_decls_for_unworthy_types (ctnode
->root_die
);
33141 copy_decls_for_unworthy_types (comp_unit_die ());
33143 /* In the process of copying declarations from one unit to another,
33144 we may have left some declarations behind that are no longer
33145 referenced. Prune them. */
33146 prune_unused_types ();
33149 /* Traverse the DIE's and note DIEs with DW_OP_GNU_variable_value still
33150 with dw_val_class_decl_ref operand. */
33151 note_variable_value (comp_unit_die ());
33152 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
33153 note_variable_value (node
->die
);
33154 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
33155 note_variable_value (ctnode
->root_die
);
33156 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
33157 note_variable_value (node
->die
);
33159 /* The AT_pubnames attribute needs to go in all skeleton dies, including
33160 both the main_cu and all skeleton TUs. Making this call unconditional
33161 would end up either adding a second copy of the AT_pubnames attribute, or
33162 requiring a special case in add_top_level_skeleton_die_attrs. */
33163 if (!dwarf_split_debug_info
)
33164 add_AT_pubnames (comp_unit_die ());
33166 /* The early debug phase is now finished. */
33167 early_dwarf_finished
= true;
33170 fprintf (dump_file
, "EARLY DWARF for %s\n", filename
);
33171 print_die (comp_unit_die (), dump_file
);
33174 /* Generate CTF/BTF debug info. */
33175 if ((ctf_debug_info_level
> CTFINFO_LEVEL_NONE
33176 || btf_debuginfo_p ()) && lang_GNU_C ())
33179 ctf_debug_do_cu (comp_unit_die ());
33180 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
33181 ctf_debug_do_cu (node
->die
);
33182 /* Post process the debug data in the CTF container if necessary. */
33183 ctf_debug_init_postprocess (btf_debuginfo_p ());
33185 ctf_debug_early_finish (filename
);
33188 /* Do not generate DWARF assembler now when not producing LTO bytecode. */
33189 if ((!flag_generate_lto
&& !flag_generate_offload
)
33190 /* FIXME: Disable debug info generation for (PE-)COFF targets since the
33191 copy_lto_debug_sections operation of the simple object support in
33192 libiberty is not implemented for them yet. */
33193 || TARGET_PECOFF
|| TARGET_COFF
)
33196 /* Now as we are going to output for LTO initialize sections and labels
33197 to the LTO variants. We don't need a random-seed postfix as other
33198 LTO sections as linking the LTO debug sections into one in a partial
33200 init_sections_and_labels (true);
33202 /* The output below is modeled after dwarf2out_finish with all
33203 location related output removed and some LTO specific changes.
33204 Some refactoring might make both smaller and easier to match up. */
33206 base_types
.truncate (0);
33207 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
33208 mark_base_types (ctnode
->root_die
);
33209 mark_base_types (comp_unit_die ());
33210 move_marked_base_types ();
33212 /* Traverse the DIE's and add sibling attributes to those DIE's
33213 that have children. */
33214 add_sibling_attributes (comp_unit_die ());
33215 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
33216 add_sibling_attributes (node
->die
);
33217 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
33218 add_sibling_attributes (ctnode
->root_die
);
33220 /* AIX Assembler inserts the length, so adjust the reference to match the
33221 offset expected by debuggers. */
33222 strcpy (dl_section_ref
, debug_line_section_label
);
33223 if (XCOFF_DEBUGGING_INFO
)
33224 strcat (dl_section_ref
, DWARF_INITIAL_LENGTH_SIZE_STR
);
33226 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
33227 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list
, dl_section_ref
);
33230 add_AT_macptr (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE
,
33231 macinfo_section_label
);
33233 save_macinfo_strings ();
33235 if (dwarf_split_debug_info
)
33237 unsigned int index
= 0;
33238 debug_str_hash
->traverse_noresize
<unsigned int *, index_string
> (&index
);
33241 /* Output all of the compilation units. We put the main one last so that
33242 the offsets are available to output_pubnames. */
33243 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
33244 output_comp_unit (node
->die
, 0, NULL
);
33246 hash_table
<comdat_type_hasher
> comdat_type_table (100);
33247 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
33249 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
33251 /* Don't output duplicate types. */
33252 if (*slot
!= HTAB_EMPTY_ENTRY
)
33255 /* Add a pointer to the line table for the main compilation unit
33256 so that the debugger can make sense of DW_AT_decl_file
33258 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
33259 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
33260 (!dwarf_split_debug_info
33261 ? debug_line_section_label
33262 : debug_skeleton_line_section_label
));
33264 output_comdat_type_unit (ctnode
, true);
33268 /* Stick a unique symbol to the main debuginfo section. */
33269 compute_comp_unit_symbol (comp_unit_die ());
33271 /* Output the main compilation unit. We always need it if only for
33273 output_comp_unit (comp_unit_die (), true, NULL
);
33275 /* Output the abbreviation table. */
33276 if (vec_safe_length (abbrev_die_table
) != 1)
33278 switch_to_section (debug_abbrev_section
);
33279 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
33280 output_abbrev_section ();
33283 /* Have to end the macro section. */
33286 /* We have to save macinfo state if we need to output it again
33287 for the FAT part of the object. */
33288 vec
<macinfo_entry
, va_gc
> *saved_macinfo_table
= macinfo_table
;
33289 if (flag_fat_lto_objects
)
33290 macinfo_table
= macinfo_table
->copy ();
33292 switch_to_section (debug_macinfo_section
);
33293 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
33294 output_macinfo (debug_line_section_label
, true);
33295 dw2_asm_output_data (1, 0, "End compilation unit");
33297 if (flag_fat_lto_objects
)
33299 vec_free (macinfo_table
);
33300 macinfo_table
= saved_macinfo_table
;
33304 /* Emit a skeleton debug_line section. */
33305 switch_to_section (debug_line_section
);
33306 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
33307 output_line_info (true);
33309 /* If we emitted any indirect strings, output the string table too. */
33310 if (debug_str_hash
|| skeleton_debug_str_hash
)
33311 output_indirect_strings ();
33312 if (debug_line_str_hash
)
33314 switch_to_section (debug_line_str_section
);
33315 const enum dwarf_form form
= DW_FORM_line_strp
;
33316 debug_line_str_hash
->traverse
<enum dwarf_form
,
33317 output_indirect_string
> (form
);
33320 /* Switch back to the text section. */
33321 switch_to_section (text_section
);
33324 /* Reset all state within dwarf2out.cc so that we can rerun the compiler
33325 within the same process. For use by toplev::finalize. */
33328 dwarf2out_cc_finalize (void)
33330 last_var_location_insn
= NULL
;
33331 cached_next_real_insn
= NULL
;
33332 used_rtx_array
= NULL
;
33333 incomplete_types
= NULL
;
33334 debug_info_section
= NULL
;
33335 debug_skeleton_info_section
= NULL
;
33336 debug_abbrev_section
= NULL
;
33337 debug_skeleton_abbrev_section
= NULL
;
33338 debug_aranges_section
= NULL
;
33339 debug_addr_section
= NULL
;
33340 debug_macinfo_section
= NULL
;
33341 debug_line_section
= NULL
;
33342 debug_skeleton_line_section
= NULL
;
33343 debug_loc_section
= NULL
;
33344 debug_pubnames_section
= NULL
;
33345 debug_pubtypes_section
= NULL
;
33346 debug_str_section
= NULL
;
33347 debug_line_str_section
= NULL
;
33348 debug_str_dwo_section
= NULL
;
33349 debug_str_offsets_section
= NULL
;
33350 debug_ranges_section
= NULL
;
33351 debug_ranges_dwo_section
= NULL
;
33352 debug_frame_section
= NULL
;
33354 debug_str_hash
= NULL
;
33355 debug_line_str_hash
= NULL
;
33356 skeleton_debug_str_hash
= NULL
;
33357 dw2_string_counter
= 0;
33358 have_multiple_function_sections
= false;
33359 in_text_section_p
= false;
33360 cold_text_section
= NULL
;
33361 last_text_label
= NULL
;
33362 last_cold_label
= NULL
;
33363 switch_text_ranges
= NULL
;
33364 switch_cold_ranges
= NULL
;
33365 current_unit_personality
= NULL
;
33367 early_dwarf
= false;
33368 early_dwarf_finished
= false;
33370 next_die_offset
= 0;
33371 single_comp_unit_die
= NULL
;
33372 comdat_type_list
= NULL
;
33373 limbo_die_list
= NULL
;
33375 decl_die_table
= NULL
;
33376 common_block_die_table
= NULL
;
33377 decl_loc_table
= NULL
;
33378 call_arg_locations
= NULL
;
33379 call_arg_loc_last
= NULL
;
33380 call_site_count
= -1;
33381 tail_call_site_count
= -1;
33382 cached_dw_loc_list_table
= NULL
;
33383 abbrev_die_table
= NULL
;
33384 delete dwarf_proc_stack_usage_map
;
33385 dwarf_proc_stack_usage_map
= NULL
;
33386 line_info_label_num
= 0;
33387 cur_line_info_table
= NULL
;
33388 text_section_line_info
= NULL
;
33389 cold_text_section_line_info
= NULL
;
33390 separate_line_info
= NULL
;
33391 info_section_emitted
= false;
33392 pubname_table
= NULL
;
33393 pubtype_table
= NULL
;
33394 macinfo_table
= NULL
;
33395 ranges_table
= NULL
;
33396 ranges_by_label
= NULL
;
33398 have_location_lists
= false;
33401 last_emitted_file
= NULL
;
33403 tmpl_value_parm_die_table
= NULL
;
33404 generic_type_instances
= NULL
;
33405 frame_pointer_fb_offset
= 0;
33406 frame_pointer_fb_offset_valid
= false;
33407 base_types
.release ();
33408 XDELETEVEC (producer_string
);
33409 producer_string
= NULL
;
33410 output_line_info_generation
= 0;
33411 init_sections_and_labels_generation
= 0;
33414 #include "gt-dwarf2out.h"