1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992-2021 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 "dwarf2asm.h"
86 #include "tree-pretty-print.h"
87 #include "print-rtl.h"
89 #include "common/common-target.h"
90 #include "langhooks.h"
95 #include "gdb/gdb-index.h"
97 #include "stringpool.h"
99 #include "file-prefix-map.h" /* remap_debug_filename() */
101 static void dwarf2out_source_line (unsigned int, unsigned int, const char *,
103 static rtx_insn
*last_var_location_insn
;
104 static rtx_insn
*cached_next_real_insn
;
105 static void dwarf2out_decl (tree
);
106 static bool is_redundant_typedef (const_tree
);
108 #ifndef XCOFF_DEBUGGING_INFO
109 #define XCOFF_DEBUGGING_INFO 0
112 #ifndef HAVE_XCOFF_DWARF_EXTRAS
113 #define HAVE_XCOFF_DWARF_EXTRAS 0
116 #ifdef VMS_DEBUGGING_INFO
117 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
119 /* Define this macro to be a nonzero value if the directory specifications
120 which are output in the debug info should end with a separator. */
121 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
122 /* Define this macro to evaluate to a nonzero value if GCC should refrain
123 from generating indirect strings in DWARF2 debug information, for instance
124 if your target is stuck with an old version of GDB that is unable to
125 process them properly or uses VMS Debug. */
126 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
128 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
129 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
132 /* ??? Poison these here until it can be done generically. They've been
133 totally replaced in this file; make sure it stays that way. */
134 #undef DWARF2_UNWIND_INFO
135 #undef DWARF2_FRAME_INFO
136 #if (GCC_VERSION >= 3000)
137 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
140 /* The size of the target's pointer type. */
142 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
145 /* Array of RTXes referenced by the debugging information, which therefore
146 must be kept around forever. */
147 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
149 /* A pointer to the base of a list of incomplete types which might be
150 completed at some later time. incomplete_types_list needs to be a
151 vec<tree, va_gc> *because we want to tell the garbage collector about
153 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
155 /* Pointers to various DWARF2 sections. */
156 static GTY(()) section
*debug_info_section
;
157 static GTY(()) section
*debug_skeleton_info_section
;
158 static GTY(()) section
*debug_abbrev_section
;
159 static GTY(()) section
*debug_skeleton_abbrev_section
;
160 static GTY(()) section
*debug_aranges_section
;
161 static GTY(()) section
*debug_addr_section
;
162 static GTY(()) section
*debug_macinfo_section
;
163 static const char *debug_macinfo_section_name
;
164 static unsigned macinfo_label_base
= 1;
165 static GTY(()) section
*debug_line_section
;
166 static GTY(()) section
*debug_skeleton_line_section
;
167 static GTY(()) section
*debug_loc_section
;
168 static GTY(()) section
*debug_pubnames_section
;
169 static GTY(()) section
*debug_pubtypes_section
;
170 static GTY(()) section
*debug_str_section
;
171 static GTY(()) section
*debug_line_str_section
;
172 static GTY(()) section
*debug_str_dwo_section
;
173 static GTY(()) section
*debug_str_offsets_section
;
174 static GTY(()) section
*debug_ranges_section
;
175 static GTY(()) section
*debug_ranges_dwo_section
;
176 static GTY(()) section
*debug_frame_section
;
178 /* Maximum size (in bytes) of an artificially generated label. */
179 #define MAX_ARTIFICIAL_LABEL_BYTES 40
181 /* According to the (draft) DWARF 3 specification, the initial length
182 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
183 bytes are 0xffffffff, followed by the length stored in the next 8
186 However, the SGI/MIPS ABI uses an initial length which is equal to
187 dwarf_offset_size. It is defined (elsewhere) accordingly. */
189 #ifndef DWARF_INITIAL_LENGTH_SIZE
190 #define DWARF_INITIAL_LENGTH_SIZE (dwarf_offset_size == 4 ? 4 : 12)
193 #ifndef DWARF_INITIAL_LENGTH_SIZE_STR
194 #define DWARF_INITIAL_LENGTH_SIZE_STR (dwarf_offset_size == 4 ? "-4" : "-12")
197 /* Round SIZE up to the nearest BOUNDARY. */
198 #define DWARF_ROUND(SIZE,BOUNDARY) \
199 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
201 /* CIE identifier. */
202 #if HOST_BITS_PER_WIDE_INT >= 64
203 #define DWARF_CIE_ID \
204 (unsigned HOST_WIDE_INT) (dwarf_offset_size == 4 ? DW_CIE_ID : DW64_CIE_ID)
206 #define DWARF_CIE_ID DW_CIE_ID
210 /* A vector for a table that contains frame description
211 information for each routine. */
212 #define NOT_INDEXED (-1U)
213 #define NO_INDEX_ASSIGNED (-2U)
215 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
217 struct GTY((for_user
)) indirect_string_node
{
219 unsigned int refcount
;
220 enum dwarf_form form
;
225 struct indirect_string_hasher
: ggc_ptr_hash
<indirect_string_node
>
227 typedef const char *compare_type
;
229 static hashval_t
hash (indirect_string_node
*);
230 static bool equal (indirect_string_node
*, const char *);
233 static GTY (()) hash_table
<indirect_string_hasher
> *debug_str_hash
;
235 static GTY (()) hash_table
<indirect_string_hasher
> *debug_line_str_hash
;
237 /* With split_debug_info, both the comp_dir and dwo_name go in the
238 main object file, rather than the dwo, similar to the force_direct
239 parameter elsewhere but with additional complications:
241 1) The string is needed in both the main object file and the dwo.
242 That is, the comp_dir and dwo_name will appear in both places.
244 2) Strings can use four forms: DW_FORM_string, DW_FORM_strp,
245 DW_FORM_line_strp or DW_FORM_strx/GNU_str_index.
247 3) GCC chooses the form to use late, depending on the size and
250 Rather than forcing the all debug string handling functions and
251 callers to deal with these complications, simply use a separate,
252 special-cased string table for any attribute that should go in the
253 main object file. This limits the complexity to just the places
256 static GTY (()) hash_table
<indirect_string_hasher
> *skeleton_debug_str_hash
;
258 static GTY(()) int dw2_string_counter
;
260 /* True if the compilation unit places functions in more than one section. */
261 static GTY(()) bool have_multiple_function_sections
= false;
263 /* The default cold text section. */
264 static GTY(()) section
*cold_text_section
;
266 /* True if currently in text section. */
267 static GTY(()) bool in_text_section_p
= false;
269 /* Last debug-on location in corresponding section. */
270 static GTY(()) const char *last_text_label
;
271 static GTY(()) const char *last_cold_label
;
273 /* Mark debug-on/off locations per section.
274 NULL means the section is not used at all. */
275 static GTY(()) vec
<const char *, va_gc
> *switch_text_ranges
;
276 static GTY(()) vec
<const char *, va_gc
> *switch_cold_ranges
;
278 /* The DIE for C++14 'auto' in a function return type. */
279 static GTY(()) dw_die_ref auto_die
;
281 /* The DIE for C++14 'decltype(auto)' in a function return type. */
282 static GTY(()) dw_die_ref decltype_auto_die
;
284 /* Forward declarations for functions defined in this file. */
286 static void output_call_frame_info (int);
288 /* Personality decl of current unit. Used only when assembler does not support
290 static GTY(()) rtx current_unit_personality
;
292 /* Whether an eh_frame section is required. */
293 static GTY(()) bool do_eh_frame
= false;
295 /* .debug_rnglists next index. */
296 static unsigned int rnglist_idx
;
298 /* Data and reference forms for relocatable data. */
299 #define DW_FORM_data (dwarf_offset_size == 8 ? DW_FORM_data8 : DW_FORM_data4)
300 #define DW_FORM_ref (dwarf_offset_size == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
302 #ifndef DEBUG_FRAME_SECTION
303 #define DEBUG_FRAME_SECTION ".debug_frame"
306 #ifndef FUNC_BEGIN_LABEL
307 #define FUNC_BEGIN_LABEL "LFB"
310 #ifndef FUNC_SECOND_SECT_LABEL
311 #define FUNC_SECOND_SECT_LABEL "LFSB"
314 #ifndef FUNC_END_LABEL
315 #define FUNC_END_LABEL "LFE"
318 #ifndef PROLOGUE_END_LABEL
319 #define PROLOGUE_END_LABEL "LPE"
322 #ifndef EPILOGUE_BEGIN_LABEL
323 #define EPILOGUE_BEGIN_LABEL "LEB"
326 #ifndef FRAME_BEGIN_LABEL
327 #define FRAME_BEGIN_LABEL "Lframe"
329 #define CIE_AFTER_SIZE_LABEL "LSCIE"
330 #define CIE_END_LABEL "LECIE"
331 #define FDE_LABEL "LSFDE"
332 #define FDE_AFTER_SIZE_LABEL "LASFDE"
333 #define FDE_END_LABEL "LEFDE"
334 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
335 #define LINE_NUMBER_END_LABEL "LELT"
336 #define LN_PROLOG_AS_LABEL "LASLTP"
337 #define LN_PROLOG_END_LABEL "LELTP"
338 #define DIE_LABEL_PREFIX "DW"
340 /* Match the base name of a file to the base name of a compilation unit. */
343 matches_main_base (const char *path
)
345 /* Cache the last query. */
346 static const char *last_path
= NULL
;
347 static int last_match
= 0;
348 if (path
!= last_path
)
351 int length
= base_of_path (path
, &base
);
353 last_match
= (length
== main_input_baselength
354 && memcmp (base
, main_input_basename
, length
) == 0);
359 #ifdef DEBUG_DEBUG_STRUCT
362 dump_struct_debug (tree type
, enum debug_info_usage usage
,
363 enum debug_struct_file criterion
, int generic
,
364 int matches
, int result
)
366 /* Find the type name. */
367 tree type_decl
= TYPE_STUB_DECL (type
);
369 const char *name
= 0;
370 if (TREE_CODE (t
) == TYPE_DECL
)
373 name
= IDENTIFIER_POINTER (t
);
375 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
377 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
378 matches
? "bas" : "hdr",
379 generic
? "gen" : "ord",
380 usage
== DINFO_USAGE_DFN
? ";" :
381 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
383 (void*) type_decl
, name
);
386 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
387 dump_struct_debug (type, usage, criterion, generic, matches, result)
391 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
396 /* Get the number of HOST_WIDE_INTs needed to represent the precision
400 get_full_len (const wide_int
&op
)
402 int prec
= wi::get_precision (op
);
403 return ((prec
+ HOST_BITS_PER_WIDE_INT
- 1)
404 / HOST_BITS_PER_WIDE_INT
);
408 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
410 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
413 enum debug_struct_file criterion
;
415 bool generic
= lang_hooks
.types
.generic_p (type
);
418 criterion
= debug_struct_generic
[usage
];
420 criterion
= debug_struct_ordinary
[usage
];
422 if (criterion
== DINFO_STRUCT_FILE_NONE
)
423 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
424 if (criterion
== DINFO_STRUCT_FILE_ANY
)
425 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
427 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
429 if (type_decl
!= NULL
)
431 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
432 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
434 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
435 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
438 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
441 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
442 switch to the data section instead, and write out a synthetic start label
443 for collect2 the first time around. */
446 switch_to_eh_frame_section (bool back ATTRIBUTE_UNUSED
)
448 if (eh_frame_section
== 0)
452 if (EH_TABLES_CAN_BE_READ_ONLY
)
458 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
460 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
462 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
465 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
466 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
467 && (per_encoding
& 0x70) != DW_EH_PE_absptr
468 && (per_encoding
& 0x70) != DW_EH_PE_aligned
469 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
470 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
471 ? 0 : SECTION_WRITE
);
474 flags
= SECTION_WRITE
;
476 #ifdef EH_FRAME_SECTION_NAME
477 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
479 eh_frame_section
= ((flags
== SECTION_WRITE
)
480 ? data_section
: readonly_data_section
);
481 #endif /* EH_FRAME_SECTION_NAME */
484 switch_to_section (eh_frame_section
);
486 #ifdef EH_FRAME_THROUGH_COLLECT2
487 /* We have no special eh_frame section. Emit special labels to guide
491 tree label
= get_file_function_name ("F");
492 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
493 targetm
.asm_out
.globalize_label (asm_out_file
,
494 IDENTIFIER_POINTER (label
));
495 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
500 /* Switch [BACK] to the eh or debug frame table section, depending on
504 switch_to_frame_table_section (int for_eh
, bool back
)
507 switch_to_eh_frame_section (back
);
510 if (!debug_frame_section
)
511 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
512 SECTION_DEBUG
, NULL
);
513 switch_to_section (debug_frame_section
);
517 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
519 enum dw_cfi_oprnd_type
520 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
525 case DW_CFA_GNU_window_save
:
526 case DW_CFA_remember_state
:
527 case DW_CFA_restore_state
:
528 return dw_cfi_oprnd_unused
;
531 case DW_CFA_advance_loc1
:
532 case DW_CFA_advance_loc2
:
533 case DW_CFA_advance_loc4
:
534 case DW_CFA_MIPS_advance_loc8
:
535 return dw_cfi_oprnd_addr
;
538 case DW_CFA_offset_extended
:
540 case DW_CFA_offset_extended_sf
:
541 case DW_CFA_def_cfa_sf
:
543 case DW_CFA_restore_extended
:
544 case DW_CFA_undefined
:
545 case DW_CFA_same_value
:
546 case DW_CFA_def_cfa_register
:
547 case DW_CFA_register
:
548 case DW_CFA_expression
:
549 case DW_CFA_val_expression
:
550 return dw_cfi_oprnd_reg_num
;
552 case DW_CFA_def_cfa_offset
:
553 case DW_CFA_GNU_args_size
:
554 case DW_CFA_def_cfa_offset_sf
:
555 return dw_cfi_oprnd_offset
;
557 case DW_CFA_def_cfa_expression
:
558 return dw_cfi_oprnd_loc
;
565 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
567 enum dw_cfi_oprnd_type
568 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
573 case DW_CFA_def_cfa_sf
:
575 case DW_CFA_offset_extended_sf
:
576 case DW_CFA_offset_extended
:
577 return dw_cfi_oprnd_offset
;
579 case DW_CFA_register
:
580 return dw_cfi_oprnd_reg_num
;
582 case DW_CFA_expression
:
583 case DW_CFA_val_expression
:
584 return dw_cfi_oprnd_loc
;
586 case DW_CFA_def_cfa_expression
:
587 return dw_cfi_oprnd_cfa_loc
;
590 return dw_cfi_oprnd_unused
;
594 /* Output one FDE. */
597 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
598 char *section_start_label
, int fde_encoding
, char *augmentation
,
599 bool any_lsda_needed
, int lsda_encoding
)
601 const char *begin
, *end
;
602 static unsigned int j
;
603 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
605 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
607 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
609 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
610 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
611 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
613 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4 && !for_eh
)
614 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
615 " indicating 64-bit DWARF extension");
616 dw2_asm_output_delta (for_eh
? 4 : dwarf_offset_size
, l2
, l1
,
619 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
622 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
624 dw2_asm_output_offset (dwarf_offset_size
, section_start_label
,
625 debug_frame_section
, "FDE CIE offset");
627 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
628 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
632 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
633 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
634 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
635 "FDE initial location");
636 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
637 end
, begin
, "FDE address range");
641 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
642 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
649 int size
= size_of_encoded_value (lsda_encoding
);
651 if (lsda_encoding
== DW_EH_PE_aligned
)
653 int offset
= ( 4 /* Length */
655 + 2 * size_of_encoded_value (fde_encoding
)
656 + 1 /* Augmentation size */ );
657 int pad
= -offset
& (PTR_SIZE
- 1);
660 gcc_assert (size_of_uleb128 (size
) == 1);
663 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
665 if (fde
->uses_eh_lsda
)
667 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
668 fde
->funcdef_number
);
669 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
670 gen_rtx_SYMBOL_REF (Pmode
, l1
),
672 "Language Specific Data Area");
676 if (lsda_encoding
== DW_EH_PE_aligned
)
677 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
678 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
679 "Language Specific Data Area (none)");
683 dw2_asm_output_data_uleb128 (0, "Augmentation size");
686 /* Loop through the Call Frame Instructions associated with this FDE. */
687 fde
->dw_fde_current_label
= begin
;
689 size_t from
, until
, i
;
692 until
= vec_safe_length (fde
->dw_fde_cfi
);
694 if (fde
->dw_fde_second_begin
== NULL
)
697 until
= fde
->dw_fde_switch_cfi_index
;
699 from
= fde
->dw_fde_switch_cfi_index
;
701 for (i
= from
; i
< until
; i
++)
702 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
705 /* If we are to emit a ref/link from function bodies to their frame tables,
706 do it now. This is typically performed to make sure that tables
707 associated with functions are dragged with them and not discarded in
708 garbage collecting links. We need to do this on a per function basis to
709 cope with -ffunction-sections. */
711 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
712 /* Switch to the function section, emit the ref to the tables, and
713 switch *back* into the table section. */
714 switch_to_section (function_section (fde
->decl
));
715 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
716 switch_to_frame_table_section (for_eh
, true);
719 /* Pad the FDE out to an address sized boundary. */
720 ASM_OUTPUT_ALIGN (asm_out_file
,
721 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
722 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
727 /* Return true if frame description entry FDE is needed for EH. */
730 fde_needed_for_eh_p (dw_fde_ref fde
)
732 if (flag_asynchronous_unwind_tables
)
735 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
738 if (fde
->uses_eh_lsda
)
741 /* If exceptions are enabled, we have collected nothrow info. */
742 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
748 /* Output the call frame information used to record information
749 that relates to calculating the frame pointer, and records the
750 location of saved registers. */
753 output_call_frame_info (int for_eh
)
758 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
759 char section_start_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
760 bool any_lsda_needed
= false;
761 char augmentation
[6];
762 int augmentation_size
;
763 int fde_encoding
= DW_EH_PE_absptr
;
764 int per_encoding
= DW_EH_PE_absptr
;
765 int lsda_encoding
= DW_EH_PE_absptr
;
767 rtx personality
= NULL
;
770 /* Don't emit a CIE if there won't be any FDEs. */
774 /* Nothing to do if the assembler's doing it all. */
775 if (dwarf2out_do_cfi_asm ())
778 /* If we don't have any functions we'll want to unwind out of, don't emit
779 any EH unwind information. If we make FDEs linkonce, we may have to
780 emit an empty label for an FDE that wouldn't otherwise be emitted. We
781 want to avoid having an FDE kept around when the function it refers to
782 is discarded. Example where this matters: a primary function template
783 in C++ requires EH information, an explicit specialization doesn't. */
786 bool any_eh_needed
= false;
788 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
790 if (fde
->uses_eh_lsda
)
791 any_eh_needed
= any_lsda_needed
= true;
792 else if (fde_needed_for_eh_p (fde
))
793 any_eh_needed
= true;
794 else if (TARGET_USES_WEAK_UNWIND_INFO
)
795 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
802 /* We're going to be generating comments, so turn on app. */
806 /* Switch to the proper frame section, first time. */
807 switch_to_frame_table_section (for_eh
, false);
809 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
810 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
812 /* Output the CIE. */
813 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
814 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
815 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
817 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4 && !for_eh
)
818 dw2_asm_output_data (4, 0xffffffff,
819 "Initial length escape value indicating 64-bit DWARF extension");
820 dw2_asm_output_delta (for_eh
? 4 : dwarf_offset_size
, l2
, l1
,
821 "Length of Common Information Entry");
823 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
825 /* Now that the CIE pointer is PC-relative for EH,
826 use 0 to identify the CIE. */
827 dw2_asm_output_data ((for_eh
? 4 : dwarf_offset_size
),
828 (for_eh
? 0 : DWARF_CIE_ID
),
829 "CIE Identifier Tag");
831 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
832 use CIE version 1, unless that would produce incorrect results
833 due to overflowing the return register column. */
834 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
836 if (return_reg
>= 256 || dwarf_version
> 2)
838 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
841 augmentation_size
= 0;
843 personality
= current_unit_personality
;
849 z Indicates that a uleb128 is present to size the
850 augmentation section.
851 L Indicates the encoding (and thus presence) of
852 an LSDA pointer in the FDE augmentation.
853 R Indicates a non-default pointer encoding for
855 P Indicates the presence of an encoding + language
856 personality routine in the CIE augmentation. */
858 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
859 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
860 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
862 p
= augmentation
+ 1;
866 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
867 assemble_external_libcall (personality
);
872 augmentation_size
+= 1;
874 if (fde_encoding
!= DW_EH_PE_absptr
)
877 augmentation_size
+= 1;
879 if (p
> augmentation
+ 1)
881 augmentation
[0] = 'z';
885 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
886 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
888 int offset
= ( 4 /* Length */
890 + 1 /* CIE version */
891 + strlen (augmentation
) + 1 /* Augmentation */
892 + size_of_uleb128 (1) /* Code alignment */
893 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
895 + 1 /* Augmentation size */
896 + 1 /* Personality encoding */ );
897 int pad
= -offset
& (PTR_SIZE
- 1);
899 augmentation_size
+= pad
;
901 /* Augmentations should be small, so there's scarce need to
902 iterate for a solution. Die if we exceed one uleb128 byte. */
903 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
907 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
908 if (dw_cie_version
>= 4)
910 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
911 dw2_asm_output_data (1, 0, "CIE Segment Size");
913 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
914 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
915 "CIE Data Alignment Factor");
917 if (dw_cie_version
== 1)
918 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
920 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
924 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
927 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
928 eh_data_format_name (per_encoding
));
929 dw2_asm_output_encoded_addr_rtx (per_encoding
,
935 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
936 eh_data_format_name (lsda_encoding
));
938 if (fde_encoding
!= DW_EH_PE_absptr
)
939 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
940 eh_data_format_name (fde_encoding
));
943 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
944 output_cfi (cfi
, NULL
, for_eh
);
946 /* Pad the CIE out to an address sized boundary. */
947 ASM_OUTPUT_ALIGN (asm_out_file
,
948 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
949 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
951 /* Loop through all of the FDE's. */
952 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
956 /* Don't emit EH unwind info for leaf functions that don't need it. */
957 if (for_eh
&& !fde_needed_for_eh_p (fde
))
960 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
961 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
962 augmentation
, any_lsda_needed
, lsda_encoding
);
965 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
966 dw2_asm_output_data (4, 0, "End of Table");
968 /* Turn off app to make assembly quicker. */
973 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
976 dwarf2out_do_cfi_startproc (bool second
)
981 fprintf (asm_out_file
, "\t.cfi_startproc\n");
983 targetm
.asm_out
.post_cfi_startproc (asm_out_file
, current_function_decl
);
985 /* .cfi_personality and .cfi_lsda are only relevant to DWARF2
987 if (targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
)
990 rtx personality
= get_personality_function (current_function_decl
);
994 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
997 /* ??? The GAS support isn't entirely consistent. We have to
998 handle indirect support ourselves, but PC-relative is done
999 in the assembler. Further, the assembler can't handle any
1000 of the weirder relocation types. */
1001 if (enc
& DW_EH_PE_indirect
)
1003 if (targetm
.asm_out
.make_eh_symbol_indirect
!= NULL
)
1004 ref
= targetm
.asm_out
.make_eh_symbol_indirect (ref
, true);
1006 ref
= dw2_force_const_mem (ref
, true);
1009 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
1010 output_addr_const (asm_out_file
, ref
);
1011 fputc ('\n', asm_out_file
);
1014 if (crtl
->uses_eh_lsda
)
1016 char lab
[MAX_ARTIFICIAL_LABEL_BYTES
];
1018 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1019 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
1020 current_function_funcdef_no
);
1021 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
1022 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
1024 if (enc
& DW_EH_PE_indirect
)
1026 if (targetm
.asm_out
.make_eh_symbol_indirect
!= NULL
)
1027 ref
= targetm
.asm_out
.make_eh_symbol_indirect (ref
, true);
1029 ref
= dw2_force_const_mem (ref
, true);
1032 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
1033 output_addr_const (asm_out_file
, ref
);
1034 fputc ('\n', asm_out_file
);
1038 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
1039 this allocation may be done before pass_final. */
1042 dwarf2out_alloc_current_fde (void)
1046 fde
= ggc_cleared_alloc
<dw_fde_node
> ();
1047 fde
->decl
= current_function_decl
;
1048 fde
->funcdef_number
= current_function_funcdef_no
;
1049 fde
->fde_index
= vec_safe_length (fde_vec
);
1050 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
1051 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
1052 fde
->nothrow
= crtl
->nothrow
;
1053 fde
->drap_reg
= INVALID_REGNUM
;
1054 fde
->vdrap_reg
= INVALID_REGNUM
;
1056 /* Record the FDE associated with this function. */
1058 vec_safe_push (fde_vec
, fde
);
1063 /* Output a marker (i.e. a label) for the beginning of a function, before
1067 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1068 unsigned int column ATTRIBUTE_UNUSED
,
1069 const char *file ATTRIBUTE_UNUSED
)
1071 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1077 current_function_func_begin_label
= NULL
;
1079 do_frame
= dwarf2out_do_frame ();
1081 /* ??? current_function_func_begin_label is also used by except.c for
1082 call-site information. We must emit this label if it might be used. */
1084 && (!flag_exceptions
1085 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1088 fnsec
= function_section (current_function_decl
);
1089 switch_to_section (fnsec
);
1090 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1091 current_function_funcdef_no
);
1092 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1093 current_function_funcdef_no
);
1094 dup_label
= xstrdup (label
);
1095 current_function_func_begin_label
= dup_label
;
1097 /* We can elide FDE allocation if we're not emitting frame unwind info. */
1101 /* Unlike the debug version, the EH version of frame unwind info is a per-
1102 function setting so we need to record whether we need it for the unit. */
1103 do_eh_frame
|= dwarf2out_do_eh_frame ();
1105 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1106 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1107 would include pass_dwarf2_frame. If we've not created the FDE yet,
1111 fde
= dwarf2out_alloc_current_fde ();
1113 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1114 fde
->dw_fde_begin
= dup_label
;
1115 fde
->dw_fde_current_label
= dup_label
;
1116 fde
->in_std_section
= (fnsec
== text_section
1117 || (cold_text_section
&& fnsec
== cold_text_section
));
1118 fde
->ignored_debug
= DECL_IGNORED_P (current_function_decl
);
1119 in_text_section_p
= fnsec
== text_section
;
1121 /* We only want to output line number information for the genuine dwarf2
1122 prologue case, not the eh frame case. */
1123 #ifdef DWARF2_DEBUGGING_INFO
1125 dwarf2out_source_line (line
, column
, file
, 0, true);
1128 if (dwarf2out_do_cfi_asm ())
1129 dwarf2out_do_cfi_startproc (false);
1132 rtx personality
= get_personality_function (current_function_decl
);
1133 if (!current_unit_personality
)
1134 current_unit_personality
= personality
;
1136 /* We cannot keep a current personality per function as without CFI
1137 asm, at the point where we emit the CFI data, there is no current
1138 function anymore. */
1139 if (personality
&& current_unit_personality
!= personality
)
1140 sorry ("multiple EH personalities are supported only with assemblers "
1141 "supporting %<.cfi_personality%> directive");
1145 /* Output a marker (i.e. a label) for the end of the generated code
1146 for a function prologue. This gets called *after* the prologue code has
1150 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1151 const char *file ATTRIBUTE_UNUSED
)
1153 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1155 /* Output a label to mark the endpoint of the code generated for this
1157 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1158 current_function_funcdef_no
);
1159 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1160 current_function_funcdef_no
);
1161 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1164 /* Output a marker (i.e. a label) for the beginning of the generated code
1165 for a function epilogue. This gets called *before* the prologue code has
1169 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1170 const char *file ATTRIBUTE_UNUSED
)
1172 dw_fde_ref fde
= cfun
->fde
;
1173 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1175 if (fde
->dw_fde_vms_begin_epilogue
)
1178 /* Output a label to mark the endpoint of the code generated for this
1180 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1181 current_function_funcdef_no
);
1182 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1183 current_function_funcdef_no
);
1184 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1187 /* Mark the ranges of non-debug subsections in the std text sections. */
1190 mark_ignored_debug_section (dw_fde_ref fde
, bool second
)
1193 const char *begin_label
, *end_label
;
1194 const char **last_end_label
;
1195 vec
<const char *, va_gc
> **switch_ranges
;
1199 std_section
= fde
->second_in_std_section
;
1200 begin_label
= fde
->dw_fde_second_begin
;
1201 end_label
= fde
->dw_fde_second_end
;
1205 std_section
= fde
->in_std_section
;
1206 begin_label
= fde
->dw_fde_begin
;
1207 end_label
= fde
->dw_fde_end
;
1213 if (in_text_section_p
)
1215 last_end_label
= &last_text_label
;
1216 switch_ranges
= &switch_text_ranges
;
1220 last_end_label
= &last_cold_label
;
1221 switch_ranges
= &switch_cold_ranges
;
1224 if (fde
->ignored_debug
)
1226 if (*switch_ranges
&& !(vec_safe_length (*switch_ranges
) & 1))
1227 vec_safe_push (*switch_ranges
, *last_end_label
);
1231 *last_end_label
= end_label
;
1233 if (!*switch_ranges
)
1234 vec_alloc (*switch_ranges
, 16);
1235 else if (vec_safe_length (*switch_ranges
) & 1)
1236 vec_safe_push (*switch_ranges
, begin_label
);
1240 /* Output a marker (i.e. a label) for the absolute end of the generated code
1241 for a function definition. This gets called *after* the epilogue code has
1245 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1246 const char *file ATTRIBUTE_UNUSED
)
1249 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1251 last_var_location_insn
= NULL
;
1252 cached_next_real_insn
= NULL
;
1254 if (dwarf2out_do_cfi_asm ())
1255 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1257 /* Output a label to mark the endpoint of the code generated for this
1259 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1260 current_function_funcdef_no
);
1261 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1263 gcc_assert (fde
!= NULL
);
1264 if (fde
->dw_fde_second_begin
== NULL
)
1265 fde
->dw_fde_end
= xstrdup (label
);
1267 mark_ignored_debug_section (fde
, fde
->dw_fde_second_begin
!= NULL
);
1271 dwarf2out_frame_finish (void)
1273 /* Output call frame information. */
1274 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1275 output_call_frame_info (0);
1277 /* Output another copy for the unwinder. */
1279 output_call_frame_info (1);
1282 static void var_location_switch_text_section (void);
1283 static void set_cur_line_info_table (section
*);
1286 dwarf2out_switch_text_section (void)
1288 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1290 dw_fde_ref fde
= cfun
->fde
;
1292 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1294 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_SECOND_SECT_LABEL
,
1295 current_function_funcdef_no
);
1297 fde
->dw_fde_second_begin
= ggc_strdup (label
);
1298 if (!in_cold_section_p
)
1300 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1301 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1305 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1306 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1308 have_multiple_function_sections
= true;
1310 if (dwarf2out_do_cfi_asm ())
1311 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1313 mark_ignored_debug_section (fde
, false);
1315 /* Now do the real section switch. */
1316 sect
= current_function_section ();
1317 switch_to_section (sect
);
1319 fde
->second_in_std_section
1320 = (sect
== text_section
1321 || (cold_text_section
&& sect
== cold_text_section
));
1322 in_text_section_p
= sect
== text_section
;
1324 if (dwarf2out_do_cfi_asm ())
1325 dwarf2out_do_cfi_startproc (true);
1327 var_location_switch_text_section ();
1329 if (cold_text_section
!= NULL
)
1330 set_cur_line_info_table (sect
);
1333 /* And now, the subset of the debugging information support code necessary
1334 for emitting location expressions. */
1336 /* Describe an entry into the .debug_addr section. */
1340 ate_kind_rtx_dtprel
,
1344 struct GTY((for_user
)) addr_table_entry
{
1346 unsigned int refcount
;
1348 union addr_table_entry_struct_union
1350 rtx
GTY ((tag ("0"))) rtl
;
1351 char * GTY ((tag ("1"))) label
;
1353 GTY ((desc ("%1.kind"))) addr
;
1356 typedef unsigned int var_loc_view
;
1358 /* Location lists are ranges + location descriptions for that range,
1359 so you can track variables that are in different places over
1360 their entire life. */
1361 typedef struct GTY(()) dw_loc_list_struct
{
1362 dw_loc_list_ref dw_loc_next
;
1363 const char *begin
; /* Label and addr_entry for start of range */
1364 addr_table_entry
*begin_entry
;
1365 const char *end
; /* Label for end of range */
1366 addr_table_entry
*end_entry
;
1367 char *ll_symbol
; /* Label for beginning of location list.
1368 Only on head of list. */
1369 char *vl_symbol
; /* Label for beginning of view list. Ditto. */
1370 const char *section
; /* Section this loclist is relative to */
1371 dw_loc_descr_ref expr
;
1372 var_loc_view vbegin
, vend
;
1374 /* True if all addresses in this and subsequent lists are known to be
1377 /* True if this list has been replaced by dw_loc_next. */
1379 /* True if it has been emitted into .debug_loc* / .debug_loclists*
1381 unsigned char emitted
: 1;
1382 /* True if hash field is index rather than hash value. */
1383 unsigned char num_assigned
: 1;
1384 /* True if .debug_loclists.dwo offset has been emitted for it already. */
1385 unsigned char offset_emitted
: 1;
1386 /* True if note_variable_value_in_expr has been called on it. */
1387 unsigned char noted_variable_value
: 1;
1388 /* True if the range should be emitted even if begin and end
1393 static dw_loc_descr_ref
int_loc_descriptor (poly_int64
);
1394 static dw_loc_descr_ref
uint_loc_descriptor (unsigned HOST_WIDE_INT
);
1396 /* Convert a DWARF stack opcode into its string name. */
1399 dwarf_stack_op_name (unsigned int op
)
1401 const char *name
= get_DW_OP_name (op
);
1406 return "OP_<unknown>";
1409 /* Return TRUE iff we're to output location view lists as a separate
1410 attribute next to the location lists, as an extension compatible
1411 with DWARF 2 and above. */
1414 dwarf2out_locviews_in_attribute ()
1416 return debug_variable_location_views
== 1;
1419 /* Return TRUE iff we're to output location view lists as part of the
1420 location lists, as proposed for standardization after DWARF 5. */
1423 dwarf2out_locviews_in_loclist ()
1425 #ifndef DW_LLE_view_pair
1428 return debug_variable_location_views
== -1;
1432 /* Return a pointer to a newly allocated location description. Location
1433 descriptions are simple expression terms that can be strung
1434 together to form more complicated location (address) descriptions. */
1436 static inline dw_loc_descr_ref
1437 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1438 unsigned HOST_WIDE_INT oprnd2
)
1440 dw_loc_descr_ref descr
= ggc_cleared_alloc
<dw_loc_descr_node
> ();
1442 descr
->dw_loc_opc
= op
;
1443 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1444 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1445 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1446 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1447 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1448 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1453 /* Add a location description term to a location description expression. */
1456 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1458 dw_loc_descr_ref
*d
;
1460 /* Find the end of the chain. */
1461 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1467 /* Compare two location operands for exact equality. */
1470 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1472 if (a
->val_class
!= b
->val_class
)
1474 switch (a
->val_class
)
1476 case dw_val_class_none
:
1478 case dw_val_class_addr
:
1479 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1481 case dw_val_class_offset
:
1482 case dw_val_class_unsigned_const
:
1483 case dw_val_class_const
:
1484 case dw_val_class_unsigned_const_implicit
:
1485 case dw_val_class_const_implicit
:
1486 case dw_val_class_range_list
:
1487 /* These are all HOST_WIDE_INT, signed or unsigned. */
1488 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1490 case dw_val_class_loc
:
1491 return a
->v
.val_loc
== b
->v
.val_loc
;
1492 case dw_val_class_loc_list
:
1493 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1494 case dw_val_class_view_list
:
1495 return a
->v
.val_view_list
== b
->v
.val_view_list
;
1496 case dw_val_class_die_ref
:
1497 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1498 case dw_val_class_fde_ref
:
1499 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1500 case dw_val_class_symview
:
1501 return strcmp (a
->v
.val_symbolic_view
, b
->v
.val_symbolic_view
) == 0;
1502 case dw_val_class_lbl_id
:
1503 case dw_val_class_lineptr
:
1504 case dw_val_class_macptr
:
1505 case dw_val_class_loclistsptr
:
1506 case dw_val_class_high_pc
:
1507 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1508 case dw_val_class_str
:
1509 return a
->v
.val_str
== b
->v
.val_str
;
1510 case dw_val_class_flag
:
1511 return a
->v
.val_flag
== b
->v
.val_flag
;
1512 case dw_val_class_file
:
1513 case dw_val_class_file_implicit
:
1514 return a
->v
.val_file
== b
->v
.val_file
;
1515 case dw_val_class_decl_ref
:
1516 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1518 case dw_val_class_const_double
:
1519 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1520 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1522 case dw_val_class_wide_int
:
1523 return *a
->v
.val_wide
== *b
->v
.val_wide
;
1525 case dw_val_class_vec
:
1527 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1528 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1530 return (a_len
== b_len
1531 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1534 case dw_val_class_data8
:
1535 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1537 case dw_val_class_vms_delta
:
1538 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1539 && !strcmp (a
->v
.val_vms_delta
.lbl2
, b
->v
.val_vms_delta
.lbl2
));
1541 case dw_val_class_discr_value
:
1542 return (a
->v
.val_discr_value
.pos
== b
->v
.val_discr_value
.pos
1543 && a
->v
.val_discr_value
.v
.uval
== b
->v
.val_discr_value
.v
.uval
);
1544 case dw_val_class_discr_list
:
1545 /* It makes no sense comparing two discriminant value lists. */
1551 /* Compare two location atoms for exact equality. */
1554 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1556 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1559 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1560 address size, but since we always allocate cleared storage it
1561 should be zero for other types of locations. */
1562 if (a
->dtprel
!= b
->dtprel
)
1565 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1566 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1569 /* Compare two complete location expressions for exact equality. */
1572 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1578 if (a
== NULL
|| b
== NULL
)
1580 if (!loc_descr_equal_p_1 (a
, b
))
1589 /* Add a constant POLY_OFFSET to a location expression. */
1592 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, poly_int64 poly_offset
)
1594 dw_loc_descr_ref loc
;
1597 gcc_assert (*list_head
!= NULL
);
1599 if (known_eq (poly_offset
, 0))
1602 /* Find the end of the chain. */
1603 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1606 HOST_WIDE_INT offset
;
1607 if (!poly_offset
.is_constant (&offset
))
1609 loc
->dw_loc_next
= int_loc_descriptor (poly_offset
);
1610 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_plus
, 0, 0));
1615 if (loc
->dw_loc_opc
== DW_OP_fbreg
1616 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1617 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1618 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1619 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1621 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1622 offset. Don't optimize if an signed integer overflow would happen. */
1624 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1625 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1628 else if (offset
> 0)
1629 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1634 = uint_loc_descriptor (-(unsigned HOST_WIDE_INT
) offset
);
1635 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1639 /* Return a pointer to a newly allocated location description for
1642 static inline dw_loc_descr_ref
1643 new_reg_loc_descr (unsigned int reg
, poly_int64 offset
)
1645 HOST_WIDE_INT const_offset
;
1646 if (offset
.is_constant (&const_offset
))
1649 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1652 return new_loc_descr (DW_OP_bregx
, reg
, const_offset
);
1656 dw_loc_descr_ref ret
= new_reg_loc_descr (reg
, 0);
1657 loc_descr_plus_const (&ret
, offset
);
1662 /* Add a constant OFFSET to a location list. */
1665 loc_list_plus_const (dw_loc_list_ref list_head
, poly_int64 offset
)
1668 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1669 loc_descr_plus_const (&d
->expr
, offset
);
1672 #define DWARF_REF_SIZE \
1673 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : dwarf_offset_size)
1675 /* The number of bits that can be encoded by largest DW_FORM_dataN.
1676 In DWARF4 and earlier it is DW_FORM_data8 with 64 bits, in DWARF5
1677 DW_FORM_data16 with 128 bits. */
1678 #define DWARF_LARGEST_DATA_FORM_BITS \
1679 (dwarf_version >= 5 ? 128 : 64)
1681 /* Utility inline function for construction of ops that were GNU extension
1683 static inline enum dwarf_location_atom
1684 dwarf_OP (enum dwarf_location_atom op
)
1688 case DW_OP_implicit_pointer
:
1689 if (dwarf_version
< 5)
1690 return DW_OP_GNU_implicit_pointer
;
1693 case DW_OP_entry_value
:
1694 if (dwarf_version
< 5)
1695 return DW_OP_GNU_entry_value
;
1698 case DW_OP_const_type
:
1699 if (dwarf_version
< 5)
1700 return DW_OP_GNU_const_type
;
1703 case DW_OP_regval_type
:
1704 if (dwarf_version
< 5)
1705 return DW_OP_GNU_regval_type
;
1708 case DW_OP_deref_type
:
1709 if (dwarf_version
< 5)
1710 return DW_OP_GNU_deref_type
;
1714 if (dwarf_version
< 5)
1715 return DW_OP_GNU_convert
;
1718 case DW_OP_reinterpret
:
1719 if (dwarf_version
< 5)
1720 return DW_OP_GNU_reinterpret
;
1724 if (dwarf_version
< 5)
1725 return DW_OP_GNU_addr_index
;
1729 if (dwarf_version
< 5)
1730 return DW_OP_GNU_const_index
;
1739 /* Similarly for attributes. */
1740 static inline enum dwarf_attribute
1741 dwarf_AT (enum dwarf_attribute at
)
1745 case DW_AT_call_return_pc
:
1746 if (dwarf_version
< 5)
1747 return DW_AT_low_pc
;
1750 case DW_AT_call_tail_call
:
1751 if (dwarf_version
< 5)
1752 return DW_AT_GNU_tail_call
;
1755 case DW_AT_call_origin
:
1756 if (dwarf_version
< 5)
1757 return DW_AT_abstract_origin
;
1760 case DW_AT_call_target
:
1761 if (dwarf_version
< 5)
1762 return DW_AT_GNU_call_site_target
;
1765 case DW_AT_call_target_clobbered
:
1766 if (dwarf_version
< 5)
1767 return DW_AT_GNU_call_site_target_clobbered
;
1770 case DW_AT_call_parameter
:
1771 if (dwarf_version
< 5)
1772 return DW_AT_abstract_origin
;
1775 case DW_AT_call_value
:
1776 if (dwarf_version
< 5)
1777 return DW_AT_GNU_call_site_value
;
1780 case DW_AT_call_data_value
:
1781 if (dwarf_version
< 5)
1782 return DW_AT_GNU_call_site_data_value
;
1785 case DW_AT_call_all_calls
:
1786 if (dwarf_version
< 5)
1787 return DW_AT_GNU_all_call_sites
;
1790 case DW_AT_call_all_tail_calls
:
1791 if (dwarf_version
< 5)
1792 return DW_AT_GNU_all_tail_call_sites
;
1795 case DW_AT_dwo_name
:
1796 if (dwarf_version
< 5)
1797 return DW_AT_GNU_dwo_name
;
1800 case DW_AT_addr_base
:
1801 if (dwarf_version
< 5)
1802 return DW_AT_GNU_addr_base
;
1811 /* And similarly for tags. */
1812 static inline enum dwarf_tag
1813 dwarf_TAG (enum dwarf_tag tag
)
1817 case DW_TAG_call_site
:
1818 if (dwarf_version
< 5)
1819 return DW_TAG_GNU_call_site
;
1822 case DW_TAG_call_site_parameter
:
1823 if (dwarf_version
< 5)
1824 return DW_TAG_GNU_call_site_parameter
;
1833 /* And similarly for forms. */
1834 static inline enum dwarf_form
1835 dwarf_FORM (enum dwarf_form form
)
1840 if (dwarf_version
< 5)
1841 return DW_FORM_GNU_addr_index
;
1845 if (dwarf_version
< 5)
1846 return DW_FORM_GNU_str_index
;
1855 static unsigned long int get_base_type_offset (dw_die_ref
);
1857 /* Return the size of a location descriptor. */
1859 static unsigned long
1860 size_of_loc_descr (dw_loc_descr_ref loc
)
1862 unsigned long size
= 1;
1864 switch (loc
->dw_loc_opc
)
1867 size
+= DWARF2_ADDR_SIZE
;
1869 case DW_OP_GNU_addr_index
:
1871 case DW_OP_GNU_const_index
:
1873 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1874 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1893 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1896 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1901 case DW_OP_plus_uconst
:
1902 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1940 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1943 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1946 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1949 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1950 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1953 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1955 case DW_OP_bit_piece
:
1956 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1957 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1959 case DW_OP_deref_size
:
1960 case DW_OP_xderef_size
:
1969 case DW_OP_call_ref
:
1970 case DW_OP_GNU_variable_value
:
1971 size
+= DWARF_REF_SIZE
;
1973 case DW_OP_implicit_value
:
1974 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1975 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1977 case DW_OP_implicit_pointer
:
1978 case DW_OP_GNU_implicit_pointer
:
1979 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1981 case DW_OP_entry_value
:
1982 case DW_OP_GNU_entry_value
:
1984 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1985 size
+= size_of_uleb128 (op_size
) + op_size
;
1988 case DW_OP_const_type
:
1989 case DW_OP_GNU_const_type
:
1992 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1993 size
+= size_of_uleb128 (o
) + 1;
1994 switch (loc
->dw_loc_oprnd2
.val_class
)
1996 case dw_val_class_vec
:
1997 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1998 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
2000 case dw_val_class_const
:
2001 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
2003 case dw_val_class_const_double
:
2004 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
2006 case dw_val_class_wide_int
:
2007 size
+= (get_full_len (*loc
->dw_loc_oprnd2
.v
.val_wide
)
2008 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
2015 case DW_OP_regval_type
:
2016 case DW_OP_GNU_regval_type
:
2019 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
2020 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
2021 + size_of_uleb128 (o
);
2024 case DW_OP_deref_type
:
2025 case DW_OP_GNU_deref_type
:
2028 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
2029 size
+= 1 + size_of_uleb128 (o
);
2033 case DW_OP_reinterpret
:
2034 case DW_OP_GNU_convert
:
2035 case DW_OP_GNU_reinterpret
:
2036 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2037 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2041 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
2042 size
+= size_of_uleb128 (o
);
2045 case DW_OP_GNU_parameter_ref
:
2055 /* Return the size of a series of location descriptors. */
2058 size_of_locs (dw_loc_descr_ref loc
)
2063 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
2064 field, to avoid writing to a PCH file. */
2065 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
2067 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
2069 size
+= size_of_loc_descr (l
);
2074 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
2076 l
->dw_loc_addr
= size
;
2077 size
+= size_of_loc_descr (l
);
2083 /* Return the size of the value in a DW_AT_discr_value attribute. */
2086 size_of_discr_value (dw_discr_value
*discr_value
)
2088 if (discr_value
->pos
)
2089 return size_of_uleb128 (discr_value
->v
.uval
);
2091 return size_of_sleb128 (discr_value
->v
.sval
);
2094 /* Return the size of the value in a DW_AT_discr_list attribute. */
2097 size_of_discr_list (dw_discr_list_ref discr_list
)
2101 for (dw_discr_list_ref list
= discr_list
;
2103 list
= list
->dw_discr_next
)
2105 /* One byte for the discriminant value descriptor, and then one or two
2106 LEB128 numbers, depending on whether it's a single case label or a
2109 size
+= size_of_discr_value (&list
->dw_discr_lower_bound
);
2110 if (list
->dw_discr_range
!= 0)
2111 size
+= size_of_discr_value (&list
->dw_discr_upper_bound
);
2116 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
2117 static void get_ref_die_offset_label (char *, dw_die_ref
);
2118 static unsigned long int get_ref_die_offset (dw_die_ref
);
2120 /* Output location description stack opcode's operands (if any).
2121 The for_eh_or_skip parameter controls whether register numbers are
2122 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2123 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2124 info). This should be suppressed for the cases that have not been converted
2125 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2128 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2130 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2131 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2133 switch (loc
->dw_loc_opc
)
2135 #ifdef DWARF2_DEBUGGING_INFO
2138 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
2143 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
2144 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
2146 fputc ('\n', asm_out_file
);
2151 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
2156 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
2157 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
2159 fputc ('\n', asm_out_file
);
2164 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2165 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
2172 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2173 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2175 dw2_asm_output_data (2, offset
, NULL
);
2178 case DW_OP_implicit_value
:
2179 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2180 switch (val2
->val_class
)
2182 case dw_val_class_const
:
2183 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
2185 case dw_val_class_vec
:
2187 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2188 unsigned int len
= val2
->v
.val_vec
.length
;
2192 if (elt_size
> sizeof (HOST_WIDE_INT
))
2197 for (i
= 0, p
= (unsigned char *) val2
->v
.val_vec
.array
;
2200 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2201 "fp or vector constant word %u", i
);
2204 case dw_val_class_const_double
:
2206 unsigned HOST_WIDE_INT first
, second
;
2208 if (WORDS_BIG_ENDIAN
)
2210 first
= val2
->v
.val_double
.high
;
2211 second
= val2
->v
.val_double
.low
;
2215 first
= val2
->v
.val_double
.low
;
2216 second
= val2
->v
.val_double
.high
;
2218 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2220 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2224 case dw_val_class_wide_int
:
2227 int len
= get_full_len (*val2
->v
.val_wide
);
2228 if (WORDS_BIG_ENDIAN
)
2229 for (i
= len
- 1; i
>= 0; --i
)
2230 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2231 val2
->v
.val_wide
->elt (i
), NULL
);
2233 for (i
= 0; i
< len
; ++i
)
2234 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2235 val2
->v
.val_wide
->elt (i
), NULL
);
2238 case dw_val_class_addr
:
2239 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
2240 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
2255 case DW_OP_implicit_value
:
2256 /* We currently don't make any attempt to make sure these are
2257 aligned properly like we do for the main unwind info, so
2258 don't support emitting things larger than a byte if we're
2259 only doing unwinding. */
2264 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2267 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2270 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2273 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2275 case DW_OP_plus_uconst
:
2276 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2310 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2314 unsigned r
= val1
->v
.val_unsigned
;
2315 if (for_eh_or_skip
>= 0)
2316 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2317 gcc_assert (size_of_uleb128 (r
)
2318 == size_of_uleb128 (val1
->v
.val_unsigned
));
2319 dw2_asm_output_data_uleb128 (r
, NULL
);
2323 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2327 unsigned r
= val1
->v
.val_unsigned
;
2328 if (for_eh_or_skip
>= 0)
2329 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2330 gcc_assert (size_of_uleb128 (r
)
2331 == size_of_uleb128 (val1
->v
.val_unsigned
));
2332 dw2_asm_output_data_uleb128 (r
, NULL
);
2333 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2337 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2339 case DW_OP_bit_piece
:
2340 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2341 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
2343 case DW_OP_deref_size
:
2344 case DW_OP_xderef_size
:
2345 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2351 if (targetm
.asm_out
.output_dwarf_dtprel
)
2353 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
2356 fputc ('\n', asm_out_file
);
2363 #ifdef DWARF2_DEBUGGING_INFO
2364 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2371 case DW_OP_GNU_addr_index
:
2373 case DW_OP_GNU_const_index
:
2375 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
2376 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
2377 "(index into .debug_addr)");
2383 unsigned long die_offset
2384 = get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2385 /* Make sure the offset has been computed and that we can encode it as
2387 gcc_assert (die_offset
> 0
2388 && die_offset
<= (loc
->dw_loc_opc
== DW_OP_call2
2391 dw2_asm_output_data ((loc
->dw_loc_opc
== DW_OP_call2
) ? 2 : 4,
2396 case DW_OP_call_ref
:
2397 case DW_OP_GNU_variable_value
:
2399 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2400 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2401 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2402 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2403 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2407 case DW_OP_implicit_pointer
:
2408 case DW_OP_GNU_implicit_pointer
:
2410 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2411 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2412 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2413 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2414 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2415 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2419 case DW_OP_entry_value
:
2420 case DW_OP_GNU_entry_value
:
2421 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
2422 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
2425 case DW_OP_const_type
:
2426 case DW_OP_GNU_const_type
:
2428 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
2430 dw2_asm_output_data_uleb128 (o
, NULL
);
2431 switch (val2
->val_class
)
2433 case dw_val_class_const
:
2434 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2435 dw2_asm_output_data (1, l
, NULL
);
2436 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
2438 case dw_val_class_vec
:
2440 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2441 unsigned int len
= val2
->v
.val_vec
.length
;
2446 dw2_asm_output_data (1, l
, NULL
);
2447 if (elt_size
> sizeof (HOST_WIDE_INT
))
2452 for (i
= 0, p
= (unsigned char *) val2
->v
.val_vec
.array
;
2455 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2456 "fp or vector constant word %u", i
);
2459 case dw_val_class_const_double
:
2461 unsigned HOST_WIDE_INT first
, second
;
2462 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2464 dw2_asm_output_data (1, 2 * l
, NULL
);
2465 if (WORDS_BIG_ENDIAN
)
2467 first
= val2
->v
.val_double
.high
;
2468 second
= val2
->v
.val_double
.low
;
2472 first
= val2
->v
.val_double
.low
;
2473 second
= val2
->v
.val_double
.high
;
2475 dw2_asm_output_data (l
, first
, NULL
);
2476 dw2_asm_output_data (l
, second
, NULL
);
2479 case dw_val_class_wide_int
:
2482 int len
= get_full_len (*val2
->v
.val_wide
);
2483 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2485 dw2_asm_output_data (1, len
* l
, NULL
);
2486 if (WORDS_BIG_ENDIAN
)
2487 for (i
= len
- 1; i
>= 0; --i
)
2488 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2490 for (i
= 0; i
< len
; ++i
)
2491 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2499 case DW_OP_regval_type
:
2500 case DW_OP_GNU_regval_type
:
2502 unsigned r
= val1
->v
.val_unsigned
;
2503 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2505 if (for_eh_or_skip
>= 0)
2507 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2508 gcc_assert (size_of_uleb128 (r
)
2509 == size_of_uleb128 (val1
->v
.val_unsigned
));
2511 dw2_asm_output_data_uleb128 (r
, NULL
);
2512 dw2_asm_output_data_uleb128 (o
, NULL
);
2515 case DW_OP_deref_type
:
2516 case DW_OP_GNU_deref_type
:
2518 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2520 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2521 dw2_asm_output_data_uleb128 (o
, NULL
);
2525 case DW_OP_reinterpret
:
2526 case DW_OP_GNU_convert
:
2527 case DW_OP_GNU_reinterpret
:
2528 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2529 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2532 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2534 dw2_asm_output_data_uleb128 (o
, NULL
);
2538 case DW_OP_GNU_parameter_ref
:
2541 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2542 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2543 dw2_asm_output_data (4, o
, NULL
);
2548 /* Other codes have no operands. */
2553 /* Output a sequence of location operations.
2554 The for_eh_or_skip parameter controls whether register numbers are
2555 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2556 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2557 info). This should be suppressed for the cases that have not been converted
2558 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2561 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2563 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2565 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2566 /* Output the opcode. */
2567 if (for_eh_or_skip
>= 0
2568 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2570 unsigned r
= (opc
- DW_OP_breg0
);
2571 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2572 gcc_assert (r
<= 31);
2573 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2575 else if (for_eh_or_skip
>= 0
2576 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2578 unsigned r
= (opc
- DW_OP_reg0
);
2579 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2580 gcc_assert (r
<= 31);
2581 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2584 dw2_asm_output_data (1, opc
,
2585 "%s", dwarf_stack_op_name (opc
));
2587 /* Output the operand(s) (if any). */
2588 output_loc_operands (loc
, for_eh_or_skip
);
2592 /* Output location description stack opcode's operands (if any).
2593 The output is single bytes on a line, suitable for .cfi_escape. */
2596 output_loc_operands_raw (dw_loc_descr_ref loc
)
2598 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2599 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2601 switch (loc
->dw_loc_opc
)
2604 case DW_OP_GNU_addr_index
:
2606 case DW_OP_GNU_const_index
:
2608 case DW_OP_implicit_value
:
2609 /* We cannot output addresses in .cfi_escape, only bytes. */
2615 case DW_OP_deref_size
:
2616 case DW_OP_xderef_size
:
2617 fputc (',', asm_out_file
);
2618 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2623 fputc (',', asm_out_file
);
2624 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2629 fputc (',', asm_out_file
);
2630 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2635 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2636 fputc (',', asm_out_file
);
2637 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2645 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2646 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2648 fputc (',', asm_out_file
);
2649 dw2_asm_output_data_raw (2, offset
);
2655 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2656 gcc_assert (size_of_uleb128 (r
)
2657 == size_of_uleb128 (val1
->v
.val_unsigned
));
2658 fputc (',', asm_out_file
);
2659 dw2_asm_output_data_uleb128_raw (r
);
2664 case DW_OP_plus_uconst
:
2666 fputc (',', asm_out_file
);
2667 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2670 case DW_OP_bit_piece
:
2671 fputc (',', asm_out_file
);
2672 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2673 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2710 fputc (',', asm_out_file
);
2711 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2716 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2717 gcc_assert (size_of_uleb128 (r
)
2718 == size_of_uleb128 (val1
->v
.val_unsigned
));
2719 fputc (',', asm_out_file
);
2720 dw2_asm_output_data_uleb128_raw (r
);
2721 fputc (',', asm_out_file
);
2722 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2726 case DW_OP_implicit_pointer
:
2727 case DW_OP_entry_value
:
2728 case DW_OP_const_type
:
2729 case DW_OP_regval_type
:
2730 case DW_OP_deref_type
:
2732 case DW_OP_reinterpret
:
2733 case DW_OP_GNU_implicit_pointer
:
2734 case DW_OP_GNU_entry_value
:
2735 case DW_OP_GNU_const_type
:
2736 case DW_OP_GNU_regval_type
:
2737 case DW_OP_GNU_deref_type
:
2738 case DW_OP_GNU_convert
:
2739 case DW_OP_GNU_reinterpret
:
2740 case DW_OP_GNU_parameter_ref
:
2745 /* Other codes have no operands. */
2751 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2755 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2756 /* Output the opcode. */
2757 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2759 unsigned r
= (opc
- DW_OP_breg0
);
2760 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2761 gcc_assert (r
<= 31);
2762 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2764 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2766 unsigned r
= (opc
- DW_OP_reg0
);
2767 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2768 gcc_assert (r
<= 31);
2769 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2771 /* Output the opcode. */
2772 fprintf (asm_out_file
, "%#x", opc
);
2773 output_loc_operands_raw (loc
);
2775 if (!loc
->dw_loc_next
)
2777 loc
= loc
->dw_loc_next
;
2779 fputc (',', asm_out_file
);
2783 /* This function builds a dwarf location descriptor sequence from a
2784 dw_cfa_location, adding the given OFFSET to the result of the
2787 struct dw_loc_descr_node
*
2788 build_cfa_loc (dw_cfa_location
*cfa
, poly_int64 offset
)
2790 struct dw_loc_descr_node
*head
, *tmp
;
2792 offset
+= cfa
->offset
;
2796 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2797 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2798 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2799 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2800 add_loc_descr (&head
, tmp
);
2801 loc_descr_plus_const (&head
, offset
);
2804 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2809 /* This function builds a dwarf location descriptor sequence for
2810 the address at OFFSET from the CFA when stack is aligned to
2813 struct dw_loc_descr_node
*
2814 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2815 poly_int64 offset
, HOST_WIDE_INT alignment
)
2817 struct dw_loc_descr_node
*head
;
2818 unsigned int dwarf_fp
2819 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2821 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2822 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2824 head
= new_reg_loc_descr (dwarf_fp
, 0);
2825 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2826 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2827 loc_descr_plus_const (&head
, offset
);
2830 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2834 /* And now, the support for symbolic debugging information. */
2836 /* .debug_str support. */
2838 static void dwarf2out_init (const char *);
2839 static void dwarf2out_finish (const char *);
2840 static void dwarf2out_early_finish (const char *);
2841 static void dwarf2out_assembly_start (void);
2842 static void dwarf2out_define (unsigned int, const char *);
2843 static void dwarf2out_undef (unsigned int, const char *);
2844 static void dwarf2out_start_source_file (unsigned, const char *);
2845 static void dwarf2out_end_source_file (unsigned);
2846 static void dwarf2out_function_decl (tree
);
2847 static void dwarf2out_begin_block (unsigned, unsigned);
2848 static void dwarf2out_end_block (unsigned, unsigned);
2849 static bool dwarf2out_ignore_block (const_tree
);
2850 static void dwarf2out_set_ignored_loc (unsigned, unsigned, const char *);
2851 static void dwarf2out_early_global_decl (tree
);
2852 static void dwarf2out_late_global_decl (tree
);
2853 static void dwarf2out_type_decl (tree
, int);
2854 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool, bool);
2855 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2857 static void dwarf2out_abstract_function (tree
);
2858 static void dwarf2out_var_location (rtx_insn
*);
2859 static void dwarf2out_inline_entry (tree
);
2860 static void dwarf2out_size_function (tree
);
2861 static void dwarf2out_begin_function (tree
);
2862 static void dwarf2out_end_function (unsigned int);
2863 static void dwarf2out_register_main_translation_unit (tree unit
);
2864 static void dwarf2out_set_name (tree
, tree
);
2865 static void dwarf2out_register_external_die (tree decl
, const char *sym
,
2866 unsigned HOST_WIDE_INT off
);
2867 static bool dwarf2out_die_ref_for_decl (tree decl
, const char **sym
,
2868 unsigned HOST_WIDE_INT
*off
);
2870 /* The debug hooks structure. */
2872 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2876 dwarf2out_early_finish
,
2877 dwarf2out_assembly_start
,
2880 dwarf2out_start_source_file
,
2881 dwarf2out_end_source_file
,
2882 dwarf2out_begin_block
,
2883 dwarf2out_end_block
,
2884 dwarf2out_ignore_block
,
2885 dwarf2out_source_line
,
2886 dwarf2out_set_ignored_loc
,
2887 dwarf2out_begin_prologue
,
2888 #if VMS_DEBUGGING_INFO
2889 dwarf2out_vms_end_prologue
,
2890 dwarf2out_vms_begin_epilogue
,
2892 debug_nothing_int_charstar
,
2893 debug_nothing_int_charstar
,
2895 dwarf2out_end_epilogue
,
2896 dwarf2out_begin_function
,
2897 dwarf2out_end_function
, /* end_function */
2898 dwarf2out_register_main_translation_unit
,
2899 dwarf2out_function_decl
, /* function_decl */
2900 dwarf2out_early_global_decl
,
2901 dwarf2out_late_global_decl
,
2902 dwarf2out_type_decl
, /* type_decl */
2903 dwarf2out_imported_module_or_decl
,
2904 dwarf2out_die_ref_for_decl
,
2905 dwarf2out_register_external_die
,
2906 debug_nothing_tree
, /* deferred_inline_function */
2907 /* The DWARF 2 backend tries to reduce debugging bloat by not
2908 emitting the abstract description of inline functions until
2909 something tries to reference them. */
2910 dwarf2out_abstract_function
, /* outlining_inline_function */
2911 debug_nothing_rtx_code_label
, /* label */
2912 debug_nothing_int
, /* handle_pch */
2913 dwarf2out_var_location
,
2914 dwarf2out_inline_entry
, /* inline_entry */
2915 dwarf2out_size_function
, /* size_function */
2916 dwarf2out_switch_text_section
,
2918 1, /* start_end_main_source_file */
2919 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2922 const struct gcc_debug_hooks dwarf2_lineno_debug_hooks
=
2925 debug_nothing_charstar
,
2926 debug_nothing_charstar
,
2927 dwarf2out_assembly_start
,
2928 debug_nothing_int_charstar
,
2929 debug_nothing_int_charstar
,
2930 debug_nothing_int_charstar
,
2932 debug_nothing_int_int
, /* begin_block */
2933 debug_nothing_int_int
, /* end_block */
2934 debug_true_const_tree
, /* ignore_block */
2935 dwarf2out_source_line
, /* source_line */
2936 debug_nothing_int_int_charstar
, /* set_ignored_loc */
2937 debug_nothing_int_int_charstar
, /* begin_prologue */
2938 debug_nothing_int_charstar
, /* end_prologue */
2939 debug_nothing_int_charstar
, /* begin_epilogue */
2940 debug_nothing_int_charstar
, /* end_epilogue */
2941 debug_nothing_tree
, /* begin_function */
2942 debug_nothing_int
, /* end_function */
2943 debug_nothing_tree
, /* register_main_translation_unit */
2944 debug_nothing_tree
, /* function_decl */
2945 debug_nothing_tree
, /* early_global_decl */
2946 debug_nothing_tree
, /* late_global_decl */
2947 debug_nothing_tree_int
, /* type_decl */
2948 debug_nothing_tree_tree_tree_bool_bool
,/* imported_module_or_decl */
2949 debug_false_tree_charstarstar_uhwistar
,/* die_ref_for_decl */
2950 debug_nothing_tree_charstar_uhwi
, /* register_external_die */
2951 debug_nothing_tree
, /* deferred_inline_function */
2952 debug_nothing_tree
, /* outlining_inline_function */
2953 debug_nothing_rtx_code_label
, /* label */
2954 debug_nothing_int
, /* handle_pch */
2955 debug_nothing_rtx_insn
, /* var_location */
2956 debug_nothing_tree
, /* inline_entry */
2957 debug_nothing_tree
, /* size_function */
2958 debug_nothing_void
, /* switch_text_section */
2959 debug_nothing_tree_tree
, /* set_name */
2960 0, /* start_end_main_source_file */
2961 TYPE_SYMTAB_IS_ADDRESS
/* tree_type_symtab_field */
2964 /* NOTE: In the comments in this file, many references are made to
2965 "Debugging Information Entries". This term is abbreviated as `DIE'
2966 throughout the remainder of this file. */
2968 /* An internal representation of the DWARF output is built, and then
2969 walked to generate the DWARF debugging info. The walk of the internal
2970 representation is done after the entire program has been compiled.
2971 The types below are used to describe the internal representation. */
2973 /* Whether to put type DIEs into their own section .debug_types instead
2974 of making them part of the .debug_info section. Only supported for
2975 Dwarf V4 or higher and the user didn't disable them through
2976 -fno-debug-types-section. It is more efficient to put them in a
2977 separate comdat sections since the linker will then be able to
2978 remove duplicates. But not all tools support .debug_types sections
2979 yet. For Dwarf V5 or higher .debug_types doesn't exist any more,
2980 it is DW_UT_type unit type in .debug_info section. For late LTO
2981 debug there should be almost no types emitted so avoid enabling
2982 -fdebug-types-section there. */
2984 #define use_debug_types (dwarf_version >= 4 \
2985 && flag_debug_types_section \
2988 /* Various DIE's use offsets relative to the beginning of the
2989 .debug_info section to refer to each other. */
2991 typedef long int dw_offset
;
2993 struct comdat_type_node
;
2995 /* The entries in the line_info table more-or-less mirror the opcodes
2996 that are used in the real dwarf line table. Arrays of these entries
2997 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
3000 enum dw_line_info_opcode
{
3001 /* Emit DW_LNE_set_address; the operand is the label index. */
3004 /* Emit a row to the matrix with the given line. This may be done
3005 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
3009 /* Emit a DW_LNS_set_file. */
3012 /* Emit a DW_LNS_set_column. */
3015 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
3018 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
3019 LI_set_prologue_end
,
3020 LI_set_epilogue_begin
,
3022 /* Emit a DW_LNE_set_discriminator. */
3023 LI_set_discriminator
,
3025 /* Output a Fixed Advance PC; the target PC is the label index; the
3026 base PC is the previous LI_adv_address or LI_set_address entry.
3027 We only use this when emitting debug views without assembler
3028 support, at explicit user request. Ideally, we should only use
3029 it when the offset might be zero but we can't tell: it's the only
3030 way to maybe change the PC without resetting the view number. */
3034 typedef struct GTY(()) dw_line_info_struct
{
3035 enum dw_line_info_opcode opcode
;
3037 } dw_line_info_entry
;
3040 struct GTY(()) dw_line_info_table
{
3041 /* The label that marks the end of this section. */
3042 const char *end_label
;
3044 /* The values for the last row of the matrix, as collected in the table.
3045 These are used to minimize the changes to the next row. */
3046 unsigned int file_num
;
3047 unsigned int line_num
;
3048 unsigned int column_num
;
3053 /* This denotes the NEXT view number.
3055 If it is 0, it is known that the NEXT view will be the first view
3058 If it is -1, we're forcing the view number to be reset, e.g. at a
3061 The meaning of other nonzero values depends on whether we're
3062 computing views internally or leaving it for the assembler to do
3063 so. If we're emitting them internally, view denotes the view
3064 number since the last known advance of PC. If we're leaving it
3065 for the assembler, it denotes the LVU label number that we're
3066 going to ask the assembler to assign. */
3069 /* This counts the number of symbolic views emitted in this table
3070 since the latest view reset. Its max value, over all tables,
3071 sets symview_upper_bound. */
3072 var_loc_view symviews_since_reset
;
3074 #define FORCE_RESET_NEXT_VIEW(x) ((x) = (var_loc_view)-1)
3075 #define RESET_NEXT_VIEW(x) ((x) = (var_loc_view)0)
3076 #define FORCE_RESETTING_VIEW_P(x) ((x) == (var_loc_view)-1)
3077 #define RESETTING_VIEW_P(x) ((x) == (var_loc_view)0 || FORCE_RESETTING_VIEW_P (x))
3079 vec
<dw_line_info_entry
, va_gc
> *entries
;
3082 /* This is an upper bound for view numbers that the assembler may
3083 assign to symbolic views output in this translation. It is used to
3084 decide how big a field to use to represent view numbers in
3085 symview-classed attributes. */
3087 static var_loc_view symview_upper_bound
;
3089 /* If we're keep track of location views and their reset points, and
3090 INSN is a reset point (i.e., it necessarily advances the PC), mark
3091 the next view in TABLE as reset. */
3094 maybe_reset_location_view (rtx_insn
*insn
, dw_line_info_table
*table
)
3096 if (!debug_internal_reset_location_views
)
3099 /* Maybe turn (part of?) this test into a default target hook. */
3102 if (targetm
.reset_location_view
)
3103 reset
= targetm
.reset_location_view (insn
);
3107 else if (JUMP_TABLE_DATA_P (insn
))
3109 else if (GET_CODE (insn
) == USE
3110 || GET_CODE (insn
) == CLOBBER
3111 || GET_CODE (insn
) == ASM_INPUT
3112 || asm_noperands (insn
) >= 0)
3114 else if (get_attr_min_length (insn
) > 0)
3117 if (reset
> 0 && !RESETTING_VIEW_P (table
->view
))
3118 RESET_NEXT_VIEW (table
->view
);
3121 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
3122 The children of each node form a circular list linked by
3123 die_sib. die_child points to the node *before* the "first" child node. */
3125 typedef struct GTY((chain_circular ("%h.die_sib"), for_user
)) die_struct
{
3126 union die_symbol_or_type_node
3128 const char * GTY ((tag ("0"))) die_symbol
;
3129 comdat_type_node
*GTY ((tag ("1"))) die_type_node
;
3131 GTY ((desc ("%0.comdat_type_p"))) die_id
;
3132 vec
<dw_attr_node
, va_gc
> *die_attr
;
3133 dw_die_ref die_parent
;
3134 dw_die_ref die_child
;
3136 dw_die_ref die_definition
; /* ref from a specification to its definition */
3137 dw_offset die_offset
;
3138 unsigned long die_abbrev
;
3140 unsigned int decl_id
;
3141 enum dwarf_tag die_tag
;
3142 /* Die is used and must not be pruned as unused. */
3143 BOOL_BITFIELD die_perennial_p
: 1;
3144 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
3145 /* For an external ref to die_symbol if die_offset contains an extra
3146 offset to that symbol. */
3147 BOOL_BITFIELD with_offset
: 1;
3148 /* Whether this DIE was removed from the DIE tree, for example via
3149 prune_unused_types. We don't consider those present from the
3150 DIE lookup routines. */
3151 BOOL_BITFIELD removed
: 1;
3152 /* Lots of spare bits. */
3156 /* Set to TRUE while dwarf2out_early_global_decl is running. */
3157 static bool early_dwarf
;
3158 static bool early_dwarf_finished
;
3159 class set_early_dwarf
{
3162 set_early_dwarf () : saved(early_dwarf
)
3164 gcc_assert (! early_dwarf_finished
);
3167 ~set_early_dwarf () { early_dwarf
= saved
; }
3170 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
3171 #define FOR_EACH_CHILD(die, c, expr) do { \
3172 c = die->die_child; \
3176 } while (c != die->die_child); \
3179 /* The pubname structure */
3181 typedef struct GTY(()) pubname_struct
{
3188 struct GTY(()) dw_ranges
{
3190 /* If this is positive, it's a block number, otherwise it's a
3191 bitwise-negated index into dw_ranges_by_label. */
3193 /* If idx is equal to DW_RANGES_IDX_SKELETON, it should be emitted
3194 into .debug_rnglists section rather than .debug_rnglists.dwo
3195 for -gsplit-dwarf and DWARF >= 5. */
3196 #define DW_RANGES_IDX_SKELETON ((1U << 31) - 1)
3197 /* Index for the range list for DW_FORM_rnglistx. */
3198 unsigned int idx
: 31;
3199 /* True if this range might be possibly in a different section
3200 from previous entry. */
3201 unsigned int maybe_new_sec
: 1;
3202 addr_table_entry
*begin_entry
;
3203 addr_table_entry
*end_entry
;
3206 /* A structure to hold a macinfo entry. */
3208 typedef struct GTY(()) macinfo_struct
{
3210 unsigned HOST_WIDE_INT lineno
;
3216 struct GTY(()) dw_ranges_by_label
{
3221 /* The comdat type node structure. */
3222 struct GTY(()) comdat_type_node
3224 dw_die_ref root_die
;
3225 dw_die_ref type_die
;
3226 dw_die_ref skeleton_die
;
3227 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
3228 comdat_type_node
*next
;
3231 /* A list of DIEs for which we can't determine ancestry (parent_die
3232 field) just yet. Later in dwarf2out_finish we will fill in the
3234 typedef struct GTY(()) limbo_die_struct
{
3236 /* The tree for which this DIE was created. We use this to
3237 determine ancestry later. */
3239 struct limbo_die_struct
*next
;
3243 typedef struct skeleton_chain_struct
3247 struct skeleton_chain_struct
*parent
;
3249 skeleton_chain_node
;
3251 /* Define a macro which returns nonzero for a TYPE_DECL which was
3252 implicitly generated for a type.
3254 Note that, unlike the C front-end (which generates a NULL named
3255 TYPE_DECL node for each complete tagged type, each array type,
3256 and each function type node created) the C++ front-end generates
3257 a _named_ TYPE_DECL node for each tagged type node created.
3258 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3259 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
3260 front-end, but for each type, tagged or not. */
3262 #define TYPE_DECL_IS_STUB(decl) \
3263 (DECL_NAME (decl) == NULL_TREE \
3264 || (DECL_ARTIFICIAL (decl) \
3265 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3266 /* This is necessary for stub decls that \
3267 appear in nested inline functions. */ \
3268 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3269 && (decl_ultimate_origin (decl) \
3270 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3272 /* Information concerning the compilation unit's programming
3273 language, and compiler version. */
3275 /* Fixed size portion of the DWARF compilation unit header. */
3276 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3277 (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size \
3278 + (dwarf_version >= 5 ? 4 : 3))
3280 /* Fixed size portion of the DWARF comdat type unit header. */
3281 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
3282 (DWARF_COMPILE_UNIT_HEADER_SIZE \
3283 + DWARF_TYPE_SIGNATURE_SIZE + dwarf_offset_size)
3285 /* Fixed size portion of the DWARF skeleton compilation unit header. */
3286 #define DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE \
3287 (DWARF_COMPILE_UNIT_HEADER_SIZE + (dwarf_version >= 5 ? 8 : 0))
3289 /* Fixed size portion of public names info. */
3290 #define DWARF_PUBNAMES_HEADER_SIZE (2 * dwarf_offset_size + 2)
3292 /* Fixed size portion of the address range info. */
3293 #define DWARF_ARANGES_HEADER_SIZE \
3294 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size + 4, \
3295 DWARF2_ADDR_SIZE * 2) \
3296 - DWARF_INITIAL_LENGTH_SIZE)
3298 /* Size of padding portion in the address range info. It must be
3299 aligned to twice the pointer size. */
3300 #define DWARF_ARANGES_PAD_SIZE \
3301 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size + 4, \
3302 DWARF2_ADDR_SIZE * 2) \
3303 - (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size + 4))
3305 /* Use assembler line directives if available. */
3306 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3307 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3308 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3310 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3314 /* Use assembler views in line directives if available. */
3315 #ifndef DWARF2_ASM_VIEW_DEBUG_INFO
3316 #ifdef HAVE_AS_DWARF2_DEBUG_VIEW
3317 #define DWARF2_ASM_VIEW_DEBUG_INFO 1
3319 #define DWARF2_ASM_VIEW_DEBUG_INFO 0
3323 /* Return true if GCC configure detected assembler support for .loc. */
3326 dwarf2out_default_as_loc_support (void)
3328 return DWARF2_ASM_LINE_DEBUG_INFO
;
3329 #if (GCC_VERSION >= 3000)
3330 # undef DWARF2_ASM_LINE_DEBUG_INFO
3331 # pragma GCC poison DWARF2_ASM_LINE_DEBUG_INFO
3335 /* Return true if GCC configure detected assembler support for views
3336 in .loc directives. */
3339 dwarf2out_default_as_locview_support (void)
3341 return DWARF2_ASM_VIEW_DEBUG_INFO
;
3342 #if (GCC_VERSION >= 3000)
3343 # undef DWARF2_ASM_VIEW_DEBUG_INFO
3344 # pragma GCC poison DWARF2_ASM_VIEW_DEBUG_INFO
3348 /* A bit is set in ZERO_VIEW_P if we are using the assembler-supported
3349 view computation, and it refers to a view identifier for which we
3350 will not emit a label because it is known to map to a view number
3351 zero. We won't allocate the bitmap if we're not using assembler
3352 support for location views, but we have to make the variable
3353 visible for GGC and for code that will be optimized out for lack of
3354 support but that's still parsed and compiled. We could abstract it
3355 out with macros, but it's not worth it. */
3356 static GTY(()) bitmap zero_view_p
;
3358 /* Evaluate to TRUE iff N is known to identify the first location view
3359 at its PC. When not using assembler location view computation,
3360 that must be view number zero. Otherwise, ZERO_VIEW_P is allocated
3361 and views label numbers recorded in it are the ones known to be
3363 #define ZERO_VIEW_P(N) ((N) == (var_loc_view)0 \
3364 || (N) == (var_loc_view)-1 \
3366 && bitmap_bit_p (zero_view_p, (N))))
3368 /* Return true iff we're to emit .loc directives for the assembler to
3369 generate line number sections.
3371 When we're not emitting views, all we need from the assembler is
3372 support for .loc directives.
3374 If we are emitting views, we can only use the assembler's .loc
3375 support if it also supports views.
3377 When the compiler is emitting the line number programs and
3378 computing view numbers itself, it resets view numbers at known PC
3379 changes and counts from that, and then it emits view numbers as
3380 literal constants in locviewlists. There are cases in which the
3381 compiler is not sure about PC changes, e.g. when extra alignment is
3382 requested for a label. In these cases, the compiler may not reset
3383 the view counter, and the potential PC advance in the line number
3384 program will use an opcode that does not reset the view counter
3385 even if the PC actually changes, so that compiler and debug info
3386 consumer can keep view numbers in sync.
3388 When the compiler defers view computation to the assembler, it
3389 emits symbolic view numbers in locviewlists, with the exception of
3390 views known to be zero (forced resets, or reset after
3391 compiler-visible PC changes): instead of emitting symbols for
3392 these, we emit literal zero and assert the assembler agrees with
3393 the compiler's assessment. We could use symbolic views everywhere,
3394 instead of special-casing zero views, but then we'd be unable to
3395 optimize out locviewlists that contain only zeros. */
3398 output_asm_line_debug_info (void)
3400 return (dwarf2out_as_loc_support
3401 && (dwarf2out_as_locview_support
3402 || !debug_variable_location_views
));
3405 static bool asm_outputs_debug_line_str (void);
3407 /* Minimum line offset in a special line info. opcode.
3408 This value was chosen to give a reasonable range of values. */
3409 #define DWARF_LINE_BASE -10
3411 /* First special line opcode - leave room for the standard opcodes. */
3412 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
3414 /* Range of line offsets in a special line info. opcode. */
3415 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3417 /* Flag that indicates the initial value of the is_stmt_start flag.
3418 In the present implementation, we do not mark any lines as
3419 the beginning of a source statement, because that information
3420 is not made available by the GCC front-end. */
3421 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3423 /* Maximum number of operations per instruction bundle. */
3424 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
3425 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
3428 /* This location is used by calc_die_sizes() to keep track
3429 the offset of each DIE within the .debug_info section. */
3430 static unsigned long next_die_offset
;
3432 /* Record the root of the DIE's built for the current compilation unit. */
3433 static GTY(()) dw_die_ref single_comp_unit_die
;
3435 /* A list of type DIEs that have been separated into comdat sections. */
3436 static GTY(()) comdat_type_node
*comdat_type_list
;
3438 /* A list of CU DIEs that have been separated. */
3439 static GTY(()) limbo_die_node
*cu_die_list
;
3441 /* A list of DIEs with a NULL parent waiting to be relocated. */
3442 static GTY(()) limbo_die_node
*limbo_die_list
;
3444 /* A list of DIEs for which we may have to generate
3445 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
3446 static GTY(()) limbo_die_node
*deferred_asm_name
;
3448 struct dwarf_file_hasher
: ggc_ptr_hash
<dwarf_file_data
>
3450 typedef const char *compare_type
;
3452 static hashval_t
hash (dwarf_file_data
*);
3453 static bool equal (dwarf_file_data
*, const char *);
3456 /* Filenames referenced by this compilation unit. */
3457 static GTY(()) hash_table
<dwarf_file_hasher
> *file_table
;
3459 struct decl_die_hasher
: ggc_ptr_hash
<die_node
>
3461 typedef tree compare_type
;
3463 static hashval_t
hash (die_node
*);
3464 static bool equal (die_node
*, tree
);
3466 /* A hash table of references to DIE's that describe declarations.
3467 The key is a DECL_UID() which is a unique number identifying each decl. */
3468 static GTY (()) hash_table
<decl_die_hasher
> *decl_die_table
;
3470 struct GTY ((for_user
)) variable_value_struct
{
3471 unsigned int decl_id
;
3472 vec
<dw_die_ref
, va_gc
> *dies
;
3475 struct variable_value_hasher
: ggc_ptr_hash
<variable_value_struct
>
3477 typedef tree compare_type
;
3479 static hashval_t
hash (variable_value_struct
*);
3480 static bool equal (variable_value_struct
*, tree
);
3482 /* A hash table of DIEs that contain DW_OP_GNU_variable_value with
3483 dw_val_class_decl_ref class, indexed by FUNCTION_DECLs which is
3484 DECL_CONTEXT of the referenced VAR_DECLs. */
3485 static GTY (()) hash_table
<variable_value_hasher
> *variable_value_hash
;
3487 struct block_die_hasher
: ggc_ptr_hash
<die_struct
>
3489 static hashval_t
hash (die_struct
*);
3490 static bool equal (die_struct
*, die_struct
*);
3493 /* A hash table of references to DIE's that describe COMMON blocks.
3494 The key is DECL_UID() ^ die_parent. */
3495 static GTY (()) hash_table
<block_die_hasher
> *common_block_die_table
;
3497 typedef struct GTY(()) die_arg_entry_struct
{
3503 /* Node of the variable location list. */
3504 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
3505 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
3506 EXPR_LIST chain. For small bitsizes, bitsize is encoded
3507 in mode of the EXPR_LIST node and first EXPR_LIST operand
3508 is either NOTE_INSN_VAR_LOCATION for a piece with a known
3509 location or NULL for padding. For larger bitsizes,
3510 mode is 0 and first operand is a CONCAT with bitsize
3511 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
3512 NULL as second operand. */
3514 const char * GTY (()) label
;
3515 struct var_loc_node
* GTY (()) next
;
3519 /* Variable location list. */
3520 struct GTY ((for_user
)) var_loc_list_def
{
3521 struct var_loc_node
* GTY (()) first
;
3523 /* Pointer to the last but one or last element of the
3524 chained list. If the list is empty, both first and
3525 last are NULL, if the list contains just one node
3526 or the last node certainly is not redundant, it points
3527 to the last node, otherwise points to the last but one.
3528 Do not mark it for GC because it is marked through the chain. */
3529 struct var_loc_node
* GTY ((skip ("%h"))) last
;
3531 /* Pointer to the last element before section switch,
3532 if NULL, either sections weren't switched or first
3533 is after section switch. */
3534 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
3536 /* DECL_UID of the variable decl. */
3537 unsigned int decl_id
;
3539 typedef struct var_loc_list_def var_loc_list
;
3541 /* Call argument location list. */
3542 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
3543 rtx
GTY (()) call_arg_loc_note
;
3544 const char * GTY (()) label
;
3545 tree
GTY (()) block
;
3547 rtx
GTY (()) symbol_ref
;
3548 struct call_arg_loc_node
* GTY (()) next
;
3552 struct decl_loc_hasher
: ggc_ptr_hash
<var_loc_list
>
3554 typedef const_tree compare_type
;
3556 static hashval_t
hash (var_loc_list
*);
3557 static bool equal (var_loc_list
*, const_tree
);
3560 /* Table of decl location linked lists. */
3561 static GTY (()) hash_table
<decl_loc_hasher
> *decl_loc_table
;
3563 /* Head and tail of call_arg_loc chain. */
3564 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
3565 static struct call_arg_loc_node
*call_arg_loc_last
;
3567 /* Number of call sites in the current function. */
3568 static int call_site_count
= -1;
3569 /* Number of tail call sites in the current function. */
3570 static int tail_call_site_count
= -1;
3572 /* A cached location list. */
3573 struct GTY ((for_user
)) cached_dw_loc_list_def
{
3574 /* The DECL_UID of the decl that this entry describes. */
3575 unsigned int decl_id
;
3577 /* The cached location list. */
3578 dw_loc_list_ref loc_list
;
3580 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
3582 struct dw_loc_list_hasher
: ggc_ptr_hash
<cached_dw_loc_list
>
3585 typedef const_tree compare_type
;
3587 static hashval_t
hash (cached_dw_loc_list
*);
3588 static bool equal (cached_dw_loc_list
*, const_tree
);
3591 /* Table of cached location lists. */
3592 static GTY (()) hash_table
<dw_loc_list_hasher
> *cached_dw_loc_list_table
;
3594 /* A vector of references to DIE's that are uniquely identified by their tag,
3595 presence/absence of children DIE's, and list of attribute/value pairs. */
3596 static GTY(()) vec
<dw_die_ref
, va_gc
> *abbrev_die_table
;
3598 /* A hash map to remember the stack usage for DWARF procedures. The value
3599 stored is the stack size difference between before the DWARF procedure
3600 invokation and after it returned. In other words, for a DWARF procedure
3601 that consumes N stack slots and that pushes M ones, this stores M - N. */
3602 static hash_map
<dw_die_ref
, int> *dwarf_proc_stack_usage_map
;
3604 /* A global counter for generating labels for line number data. */
3605 static unsigned int line_info_label_num
;
3607 /* The current table to which we should emit line number information
3608 for the current function. This will be set up at the beginning of
3609 assembly for the function. */
3610 static GTY(()) dw_line_info_table
*cur_line_info_table
;
3612 /* The two default tables of line number info. */
3613 static GTY(()) dw_line_info_table
*text_section_line_info
;
3614 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
3616 /* The set of all non-default tables of line number info. */
3617 static GTY(()) vec
<dw_line_info_table
*, va_gc
> *separate_line_info
;
3619 /* A flag to tell pubnames/types export if there is an info section to
3621 static bool info_section_emitted
;
3623 /* A pointer to the base of a table that contains a list of publicly
3624 accessible names. */
3625 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
3627 /* A pointer to the base of a table that contains a list of publicly
3628 accessible types. */
3629 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
3631 /* A pointer to the base of a table that contains a list of macro
3632 defines/undefines (and file start/end markers). */
3633 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
3635 /* True if .debug_macinfo or .debug_macros section is going to be
3637 #define have_macinfo \
3638 ((!XCOFF_DEBUGGING_INFO || HAVE_XCOFF_DWARF_EXTRAS) \
3639 && debug_info_level >= DINFO_LEVEL_VERBOSE \
3640 && !macinfo_table->is_empty ())
3642 /* Vector of dies for which we should generate .debug_ranges info. */
3643 static GTY (()) vec
<dw_ranges
, va_gc
> *ranges_table
;
3645 /* Vector of pairs of labels referenced in ranges_table. */
3646 static GTY (()) vec
<dw_ranges_by_label
, va_gc
> *ranges_by_label
;
3648 /* Whether we have location lists that need outputting */
3649 static GTY(()) bool have_location_lists
;
3651 /* Unique label counter. */
3652 static GTY(()) unsigned int loclabel_num
;
3654 /* Unique label counter for point-of-call tables. */
3655 static GTY(()) unsigned int poc_label_num
;
3657 /* The last file entry emitted by maybe_emit_file(). */
3658 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
3660 /* Number of internal labels generated by gen_internal_sym(). */
3661 static GTY(()) int label_num
;
3663 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
3665 /* Instances of generic types for which we need to generate debug
3666 info that describe their generic parameters and arguments. That
3667 generation needs to happen once all types are properly laid out so
3668 we do it at the end of compilation. */
3669 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
3671 /* Offset from the "steady-state frame pointer" to the frame base,
3672 within the current function. */
3673 static poly_int64 frame_pointer_fb_offset
;
3674 static bool frame_pointer_fb_offset_valid
;
3676 static vec
<dw_die_ref
> base_types
;
3678 /* Flags to represent a set of attribute classes for attributes that represent
3679 a scalar value (bounds, pointers, ...). */
3682 dw_scalar_form_constant
= 0x01,
3683 dw_scalar_form_exprloc
= 0x02,
3684 dw_scalar_form_reference
= 0x04
3687 /* Forward declarations for functions defined in this file. */
3689 static int is_pseudo_reg (const_rtx
);
3690 static tree
type_main_variant (tree
);
3691 static int is_tagged_type (const_tree
);
3692 static const char *dwarf_tag_name (unsigned);
3693 static const char *dwarf_attr_name (unsigned);
3694 static const char *dwarf_form_name (unsigned);
3695 static tree
decl_ultimate_origin (const_tree
);
3696 static tree
decl_class_context (tree
);
3697 static void add_dwarf_attr (dw_die_ref
, dw_attr_node
*);
3698 static inline unsigned int AT_index (dw_attr_node
*);
3699 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3700 static inline unsigned AT_flag (dw_attr_node
*);
3701 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3702 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3703 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
3704 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
3705 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3706 unsigned int, unsigned char *);
3707 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
3708 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3709 static inline const char *AT_string (dw_attr_node
*);
3710 static enum dwarf_form
AT_string_form (dw_attr_node
*);
3711 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3712 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3713 static inline dw_die_ref
AT_ref (dw_attr_node
*);
3714 static inline int AT_ref_external (dw_attr_node
*);
3715 static inline void set_AT_ref_external (dw_attr_node
*, int);
3716 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3717 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3719 static inline dw_loc_list_ref
AT_loc_list (dw_attr_node
*);
3720 static void add_AT_view_list (dw_die_ref
, enum dwarf_attribute
);
3721 static inline dw_loc_list_ref
AT_loc_list (dw_attr_node
*);
3722 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
3723 static void remove_addr_table_entry (addr_table_entry
*);
3724 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
3725 static inline rtx
AT_addr (dw_attr_node
*);
3726 static void add_AT_symview (dw_die_ref
, enum dwarf_attribute
, const char *);
3727 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3728 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3729 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3730 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3731 unsigned long, bool);
3732 static inline const char *AT_lbl (dw_attr_node
*);
3733 static const char *get_AT_low_pc (dw_die_ref
);
3734 static bool is_c (void);
3735 static bool is_cxx (void);
3736 static bool is_cxx (const_tree
);
3737 static bool is_fortran (void);
3738 static bool is_ada (void);
3739 static bool remove_AT (dw_die_ref
, enum dwarf_attribute
);
3740 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3741 static void add_child_die (dw_die_ref
, dw_die_ref
);
3742 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3743 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3744 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3745 static void equate_type_number_to_die (tree
, dw_die_ref
);
3746 static var_loc_list
*lookup_decl_loc (const_tree
);
3747 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3748 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *, var_loc_view
);
3749 static void print_spaces (FILE *);
3750 static void print_die (dw_die_ref
, FILE *);
3751 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3752 static void attr_checksum (dw_attr_node
*, struct md5_ctx
*, int *);
3753 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3754 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3755 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3756 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3757 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_node
*,
3758 struct md5_ctx
*, int *);
3759 struct checksum_attributes
;
3760 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3761 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3762 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3763 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3764 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3765 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3766 static int same_attr_p (dw_attr_node
*, dw_attr_node
*, int *);
3767 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3768 static int is_type_die (dw_die_ref
);
3769 static inline bool is_template_instantiation (dw_die_ref
);
3770 static int is_declaration_die (dw_die_ref
);
3771 static int should_move_die_to_comdat (dw_die_ref
);
3772 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3773 static dw_die_ref
clone_die (dw_die_ref
);
3774 static dw_die_ref
clone_tree (dw_die_ref
);
3775 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3776 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3777 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3778 static dw_die_ref
generate_skeleton (dw_die_ref
);
3779 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3782 static void break_out_comdat_types (dw_die_ref
);
3783 static void copy_decls_for_unworthy_types (dw_die_ref
);
3785 static void add_sibling_attributes (dw_die_ref
);
3786 static void output_location_lists (dw_die_ref
);
3787 static int constant_size (unsigned HOST_WIDE_INT
);
3788 static unsigned long size_of_die (dw_die_ref
);
3789 static void calc_die_sizes (dw_die_ref
);
3790 static void calc_base_type_die_sizes (void);
3791 static void mark_dies (dw_die_ref
);
3792 static void unmark_dies (dw_die_ref
);
3793 static void unmark_all_dies (dw_die_ref
);
3794 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3795 static unsigned long size_of_aranges (void);
3796 static enum dwarf_form
value_format (dw_attr_node
*);
3797 static void output_value_format (dw_attr_node
*);
3798 static void output_abbrev_section (void);
3799 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3800 static void output_die (dw_die_ref
);
3801 static void output_compilation_unit_header (enum dwarf_unit_type
);
3802 static void output_comp_unit (dw_die_ref
, int, const unsigned char *);
3803 static void output_comdat_type_unit (comdat_type_node
*, bool);
3804 static const char *dwarf2_name (tree
, int);
3805 static void add_pubname (tree
, dw_die_ref
);
3806 static void add_enumerator_pubname (const char *, dw_die_ref
);
3807 static void add_pubname_string (const char *, dw_die_ref
);
3808 static void add_pubtype (tree
, dw_die_ref
);
3809 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3810 static void output_aranges (void);
3811 static unsigned int add_ranges (const_tree
, bool = false);
3812 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3814 static void output_ranges (void);
3815 static dw_line_info_table
*new_line_info_table (void);
3816 static void output_line_info (bool);
3817 static void output_file_names (void);
3818 static int is_base_type (tree
);
3819 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, tree
, dw_die_ref
);
3820 static int decl_quals (const_tree
);
3821 static dw_die_ref
modified_type_die (tree
, int, bool, dw_die_ref
);
3822 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3823 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3824 static unsigned int dbx_reg_number (const_rtx
);
3825 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3826 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3827 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3828 enum var_init_status
);
3829 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3830 enum var_init_status
);
3831 static dw_loc_descr_ref
based_loc_descr (rtx
, poly_int64
,
3832 enum var_init_status
);
3833 static int is_based_loc (const_rtx
);
3834 static bool resolve_one_addr (rtx
*);
3835 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3836 enum var_init_status
);
3837 static dw_loc_descr_ref
loc_descriptor (rtx
, machine_mode mode
,
3838 enum var_init_status
);
3839 struct loc_descr_context
;
3840 static void add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
);
3841 static void add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
);
3842 static dw_loc_list_ref
loc_list_from_tree (tree
, int,
3843 struct loc_descr_context
*);
3844 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int,
3845 struct loc_descr_context
*);
3846 static tree
field_type (const_tree
);
3847 static unsigned int simple_type_align_in_bits (const_tree
);
3848 static unsigned int simple_decl_align_in_bits (const_tree
);
3849 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3851 static dw_loc_descr_ref
field_byte_offset (const_tree
, struct vlr_context
*,
3853 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3855 static void add_data_member_location_attribute (dw_die_ref
, tree
,
3856 struct vlr_context
*);
3857 static bool add_const_value_attribute (dw_die_ref
, machine_mode
, rtx
);
3858 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3859 static void insert_wide_int (const wide_int
&, unsigned char *, int);
3860 static unsigned insert_float (const_rtx
, unsigned char *);
3861 static rtx
rtl_for_decl_location (tree
);
3862 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool);
3863 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3864 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3865 static void add_desc_attribute (dw_die_ref
, tree
);
3866 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3867 static void add_comp_dir_attribute (dw_die_ref
);
3868 static void add_scalar_info (dw_die_ref
, enum dwarf_attribute
, tree
, int,
3869 struct loc_descr_context
*);
3870 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
,
3871 struct loc_descr_context
*);
3872 static void add_subscript_info (dw_die_ref
, tree
, bool);
3873 static void add_byte_size_attribute (dw_die_ref
, tree
);
3874 static void add_alignment_attribute (dw_die_ref
, tree
);
3875 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3876 static void add_bit_size_attribute (dw_die_ref
, tree
);
3877 static void add_prototyped_attribute (dw_die_ref
, tree
);
3878 static void add_abstract_origin_attribute (dw_die_ref
, tree
);
3879 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3880 static void add_src_coords_attributes (dw_die_ref
, tree
);
3881 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
, bool = false);
3882 static void add_discr_value (dw_die_ref
, dw_discr_value
*);
3883 static void add_discr_list (dw_die_ref
, dw_discr_list_ref
);
3884 static inline dw_discr_list_ref
AT_discr_list (dw_attr_node
*);
3885 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3886 static inline int local_scope_p (dw_die_ref
);
3887 static inline int class_scope_p (dw_die_ref
);
3888 static inline int class_or_namespace_scope_p (dw_die_ref
);
3889 static void add_type_attribute (dw_die_ref
, tree
, int, bool, dw_die_ref
);
3890 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3891 static const char *type_tag (const_tree
);
3892 static tree
member_declared_type (const_tree
);
3894 static const char *decl_start_label (tree
);
3896 static void gen_array_type_die (tree
, dw_die_ref
);
3897 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3899 static void gen_entry_point_die (tree
, dw_die_ref
);
3901 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3902 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3903 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3904 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3905 static void gen_formal_types_die (tree
, dw_die_ref
);
3906 static void gen_subprogram_die (tree
, dw_die_ref
);
3907 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3908 static void gen_const_die (tree
, dw_die_ref
);
3909 static void gen_label_die (tree
, dw_die_ref
);
3910 static void gen_lexical_block_die (tree
, dw_die_ref
);
3911 static void gen_inlined_subroutine_die (tree
, dw_die_ref
);
3912 static void gen_field_die (tree
, struct vlr_context
*, dw_die_ref
);
3913 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3914 static dw_die_ref
gen_compile_unit_die (const char *);
3915 static void gen_inheritance_die (tree
, tree
, tree
, dw_die_ref
);
3916 static void gen_member_die (tree
, dw_die_ref
);
3917 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3918 enum debug_info_usage
);
3919 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3920 static void gen_typedef_die (tree
, dw_die_ref
);
3921 static void gen_type_die (tree
, dw_die_ref
);
3922 static void gen_block_die (tree
, dw_die_ref
);
3923 static void decls_for_scope (tree
, dw_die_ref
, bool = true);
3924 static bool is_naming_typedef_decl (const_tree
);
3925 static inline dw_die_ref
get_context_die (tree
);
3926 static void gen_namespace_die (tree
, dw_die_ref
);
3927 static dw_die_ref
gen_namelist_decl (tree
, dw_die_ref
, tree
);
3928 static dw_die_ref
gen_decl_die (tree
, tree
, struct vlr_context
*, dw_die_ref
);
3929 static dw_die_ref
force_decl_die (tree
);
3930 static dw_die_ref
force_type_die (tree
);
3931 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3932 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3933 static struct dwarf_file_data
* lookup_filename (const char *);
3934 static void retry_incomplete_types (void);
3935 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3936 static void gen_generic_params_dies (tree
);
3937 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3938 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3939 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3940 static int file_info_cmp (const void *, const void *);
3941 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *, var_loc_view
,
3942 const char *, var_loc_view
, const char *);
3943 static void output_loc_list (dw_loc_list_ref
);
3944 static char *gen_internal_sym (const char *);
3945 static bool want_pubnames (void);
3947 static void prune_unmark_dies (dw_die_ref
);
3948 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3949 static void prune_unused_types_mark (dw_die_ref
, int);
3950 static void prune_unused_types_walk (dw_die_ref
);
3951 static void prune_unused_types_walk_attribs (dw_die_ref
);
3952 static void prune_unused_types_prune (dw_die_ref
);
3953 static void prune_unused_types (void);
3954 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3955 static inline const char *AT_vms_delta1 (dw_attr_node
*);
3956 static inline const char *AT_vms_delta2 (dw_attr_node
*);
3957 #if VMS_DEBUGGING_INFO
3958 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3959 const char *, const char *);
3961 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3962 static void gen_remaining_tmpl_value_param_die_attribute (void);
3963 static bool generic_type_p (tree
);
3964 static void schedule_generic_params_dies_gen (tree t
);
3965 static void gen_scheduled_generic_parms_dies (void);
3966 static void resolve_variable_values (void);
3968 static const char *comp_dir_string (void);
3970 static void hash_loc_operands (dw_loc_descr_ref
, inchash::hash
&);
3972 /* enum for tracking thread-local variables whose address is really an offset
3973 relative to the TLS pointer, which will need link-time relocation, but will
3974 not need relocation by the DWARF consumer. */
3982 /* Return the operator to use for an address of a variable. For dtprel_true, we
3983 use DW_OP_const*. For regular variables, which need both link-time
3984 relocation and consumer-level relocation (e.g., to account for shared objects
3985 loaded at a random address), we use DW_OP_addr*. */
3987 static inline enum dwarf_location_atom
3988 dw_addr_op (enum dtprel_bool dtprel
)
3990 if (dtprel
== dtprel_true
)
3991 return (dwarf_split_debug_info
? dwarf_OP (DW_OP_constx
)
3992 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3994 return dwarf_split_debug_info
? dwarf_OP (DW_OP_addrx
) : DW_OP_addr
;
3997 /* Return a pointer to a newly allocated address location description. If
3998 dwarf_split_debug_info is true, then record the address with the appropriate
4000 static inline dw_loc_descr_ref
4001 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
4003 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
4005 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
4006 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
4007 ref
->dtprel
= dtprel
;
4008 if (dwarf_split_debug_info
)
4009 ref
->dw_loc_oprnd1
.val_entry
4010 = add_addr_table_entry (addr
,
4011 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
4013 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
4018 /* Section names used to hold DWARF debugging information. */
4020 #ifndef DEBUG_INFO_SECTION
4021 #define DEBUG_INFO_SECTION ".debug_info"
4023 #ifndef DEBUG_DWO_INFO_SECTION
4024 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
4026 #ifndef DEBUG_LTO_INFO_SECTION
4027 #define DEBUG_LTO_INFO_SECTION ".gnu.debuglto_.debug_info"
4029 #ifndef DEBUG_LTO_DWO_INFO_SECTION
4030 #define DEBUG_LTO_DWO_INFO_SECTION ".gnu.debuglto_.debug_info.dwo"
4032 #ifndef DEBUG_ABBREV_SECTION
4033 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4035 #ifndef DEBUG_LTO_ABBREV_SECTION
4036 #define DEBUG_LTO_ABBREV_SECTION ".gnu.debuglto_.debug_abbrev"
4038 #ifndef DEBUG_DWO_ABBREV_SECTION
4039 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
4041 #ifndef DEBUG_LTO_DWO_ABBREV_SECTION
4042 #define DEBUG_LTO_DWO_ABBREV_SECTION ".gnu.debuglto_.debug_abbrev.dwo"
4044 #ifndef DEBUG_ARANGES_SECTION
4045 #define DEBUG_ARANGES_SECTION ".debug_aranges"
4047 #ifndef DEBUG_ADDR_SECTION
4048 #define DEBUG_ADDR_SECTION ".debug_addr"
4050 #ifndef DEBUG_MACINFO_SECTION
4051 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4053 #ifndef DEBUG_LTO_MACINFO_SECTION
4054 #define DEBUG_LTO_MACINFO_SECTION ".gnu.debuglto_.debug_macinfo"
4056 #ifndef DEBUG_DWO_MACINFO_SECTION
4057 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
4059 #ifndef DEBUG_LTO_DWO_MACINFO_SECTION
4060 #define DEBUG_LTO_DWO_MACINFO_SECTION ".gnu.debuglto_.debug_macinfo.dwo"
4062 #ifndef DEBUG_MACRO_SECTION
4063 #define DEBUG_MACRO_SECTION ".debug_macro"
4065 #ifndef DEBUG_LTO_MACRO_SECTION
4066 #define DEBUG_LTO_MACRO_SECTION ".gnu.debuglto_.debug_macro"
4068 #ifndef DEBUG_DWO_MACRO_SECTION
4069 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
4071 #ifndef DEBUG_LTO_DWO_MACRO_SECTION
4072 #define DEBUG_LTO_DWO_MACRO_SECTION ".gnu.debuglto_.debug_macro.dwo"
4074 #ifndef DEBUG_LINE_SECTION
4075 #define DEBUG_LINE_SECTION ".debug_line"
4077 #ifndef DEBUG_LTO_LINE_SECTION
4078 #define DEBUG_LTO_LINE_SECTION ".gnu.debuglto_.debug_line"
4080 #ifndef DEBUG_DWO_LINE_SECTION
4081 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
4083 #ifndef DEBUG_LTO_DWO_LINE_SECTION
4084 #define DEBUG_LTO_DWO_LINE_SECTION ".gnu.debuglto_.debug_line.dwo"
4086 #ifndef DEBUG_LOC_SECTION
4087 #define DEBUG_LOC_SECTION ".debug_loc"
4089 #ifndef DEBUG_DWO_LOC_SECTION
4090 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
4092 #ifndef DEBUG_LOCLISTS_SECTION
4093 #define DEBUG_LOCLISTS_SECTION ".debug_loclists"
4095 #ifndef DEBUG_DWO_LOCLISTS_SECTION
4096 #define DEBUG_DWO_LOCLISTS_SECTION ".debug_loclists.dwo"
4098 #ifndef DEBUG_PUBNAMES_SECTION
4099 #define DEBUG_PUBNAMES_SECTION \
4100 ((debug_generate_pub_sections == 2) \
4101 ? ".debug_gnu_pubnames" : ".debug_pubnames")
4103 #ifndef DEBUG_PUBTYPES_SECTION
4104 #define DEBUG_PUBTYPES_SECTION \
4105 ((debug_generate_pub_sections == 2) \
4106 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
4108 #ifndef DEBUG_STR_OFFSETS_SECTION
4109 #define DEBUG_STR_OFFSETS_SECTION ".debug_str_offsets"
4111 #ifndef DEBUG_DWO_STR_OFFSETS_SECTION
4112 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
4114 #ifndef DEBUG_LTO_DWO_STR_OFFSETS_SECTION
4115 #define DEBUG_LTO_DWO_STR_OFFSETS_SECTION ".gnu.debuglto_.debug_str_offsets.dwo"
4117 #ifndef DEBUG_STR_SECTION
4118 #define DEBUG_STR_SECTION ".debug_str"
4120 #ifndef DEBUG_LTO_STR_SECTION
4121 #define DEBUG_LTO_STR_SECTION ".gnu.debuglto_.debug_str"
4123 #ifndef DEBUG_STR_DWO_SECTION
4124 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
4126 #ifndef DEBUG_LTO_STR_DWO_SECTION
4127 #define DEBUG_LTO_STR_DWO_SECTION ".gnu.debuglto_.debug_str.dwo"
4129 #ifndef DEBUG_RANGES_SECTION
4130 #define DEBUG_RANGES_SECTION ".debug_ranges"
4132 #ifndef DEBUG_RNGLISTS_SECTION
4133 #define DEBUG_RNGLISTS_SECTION ".debug_rnglists"
4135 #ifndef DEBUG_DWO_RNGLISTS_SECTION
4136 #define DEBUG_DWO_RNGLISTS_SECTION ".debug_rnglists.dwo"
4138 #ifndef DEBUG_LINE_STR_SECTION
4139 #define DEBUG_LINE_STR_SECTION ".debug_line_str"
4141 #ifndef DEBUG_LTO_LINE_STR_SECTION
4142 #define DEBUG_LTO_LINE_STR_SECTION ".gnu.debuglto_.debug_line_str"
4145 /* Standard ELF section names for compiled code and data. */
4146 #ifndef TEXT_SECTION_NAME
4147 #define TEXT_SECTION_NAME ".text"
4150 /* Section flags for .debug_str section. */
4151 #define DEBUG_STR_SECTION_FLAGS \
4152 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
4153 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4156 /* Section flags for .debug_str.dwo section. */
4157 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
4159 /* Attribute used to refer to the macro section. */
4160 #define DEBUG_MACRO_ATTRIBUTE (dwarf_version >= 5 ? DW_AT_macros \
4161 : dwarf_strict ? DW_AT_macro_info : DW_AT_GNU_macros)
4163 /* Labels we insert at beginning sections we can reference instead of
4164 the section names themselves. */
4166 #ifndef TEXT_SECTION_LABEL
4167 #define TEXT_SECTION_LABEL "Ltext"
4169 #ifndef COLD_TEXT_SECTION_LABEL
4170 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
4172 #ifndef DEBUG_LINE_SECTION_LABEL
4173 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4175 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
4176 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
4178 #ifndef DEBUG_INFO_SECTION_LABEL
4179 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4181 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
4182 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
4184 #ifndef DEBUG_ABBREV_SECTION_LABEL
4185 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4187 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
4188 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
4190 #ifndef DEBUG_ADDR_SECTION_LABEL
4191 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
4193 #ifndef DEBUG_LOC_SECTION_LABEL
4194 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4196 #ifndef DEBUG_RANGES_SECTION_LABEL
4197 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4199 #ifndef DEBUG_MACINFO_SECTION_LABEL
4200 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4202 #ifndef DEBUG_MACRO_SECTION_LABEL
4203 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
4205 #define SKELETON_COMP_DIE_ABBREV 1
4206 #define SKELETON_TYPE_DIE_ABBREV 2
4208 /* Definitions of defaults for formats and names of various special
4209 (artificial) labels which may be generated within this file (when the -g
4210 options is used and DWARF2_DEBUGGING_INFO is in effect.
4211 If necessary, these may be overridden from within the tm.h file, but
4212 typically, overriding these defaults is unnecessary. */
4214 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4215 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4216 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4217 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4218 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4219 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4220 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4221 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4222 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4223 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4224 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4225 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4226 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4227 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
4228 static char ranges_base_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
4230 #ifndef TEXT_END_LABEL
4231 #define TEXT_END_LABEL "Letext"
4233 #ifndef COLD_END_LABEL
4234 #define COLD_END_LABEL "Letext_cold"
4236 #ifndef BLOCK_BEGIN_LABEL
4237 #define BLOCK_BEGIN_LABEL "LBB"
4239 #ifndef BLOCK_INLINE_ENTRY_LABEL
4240 #define BLOCK_INLINE_ENTRY_LABEL "LBI"
4242 #ifndef BLOCK_END_LABEL
4243 #define BLOCK_END_LABEL "LBE"
4245 #ifndef LINE_CODE_LABEL
4246 #define LINE_CODE_LABEL "LM"
4250 /* Return the root of the DIE's built for the current compilation unit. */
4252 comp_unit_die (void)
4254 if (!single_comp_unit_die
)
4255 single_comp_unit_die
= gen_compile_unit_die (NULL
);
4256 return single_comp_unit_die
;
4259 /* We allow a language front-end to designate a function that is to be
4260 called to "demangle" any name before it is put into a DIE. */
4262 static const char *(*demangle_name_func
) (const char *);
4265 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
4267 demangle_name_func
= func
;
4270 /* Test if rtl node points to a pseudo register. */
4273 is_pseudo_reg (const_rtx rtl
)
4275 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
4276 || (GET_CODE (rtl
) == SUBREG
4277 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
4280 /* Return a reference to a type, with its const and volatile qualifiers
4284 type_main_variant (tree type
)
4286 type
= TYPE_MAIN_VARIANT (type
);
4288 /* ??? There really should be only one main variant among any group of
4289 variants of a given type (and all of the MAIN_VARIANT values for all
4290 members of the group should point to that one type) but sometimes the C
4291 front-end messes this up for array types, so we work around that bug
4293 if (TREE_CODE (type
) == ARRAY_TYPE
)
4294 while (type
!= TYPE_MAIN_VARIANT (type
))
4295 type
= TYPE_MAIN_VARIANT (type
);
4300 /* Return nonzero if the given type node represents a tagged type. */
4303 is_tagged_type (const_tree type
)
4305 enum tree_code code
= TREE_CODE (type
);
4307 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
4308 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
4311 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
4314 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
4316 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
4319 /* Return die_offset of a DIE reference to a base type. */
4321 static unsigned long int
4322 get_base_type_offset (dw_die_ref ref
)
4324 if (ref
->die_offset
)
4325 return ref
->die_offset
;
4326 if (comp_unit_die ()->die_abbrev
)
4328 calc_base_type_die_sizes ();
4329 gcc_assert (ref
->die_offset
);
4331 return ref
->die_offset
;
4334 /* Return die_offset of a DIE reference other than base type. */
4336 static unsigned long int
4337 get_ref_die_offset (dw_die_ref ref
)
4339 gcc_assert (ref
->die_offset
);
4340 return ref
->die_offset
;
4343 /* Convert a DIE tag into its string name. */
4346 dwarf_tag_name (unsigned int tag
)
4348 const char *name
= get_DW_TAG_name (tag
);
4353 return "DW_TAG_<unknown>";
4356 /* Convert a DWARF attribute code into its string name. */
4359 dwarf_attr_name (unsigned int attr
)
4365 #if VMS_DEBUGGING_INFO
4366 case DW_AT_HP_prologue
:
4367 return "DW_AT_HP_prologue";
4369 case DW_AT_MIPS_loop_unroll_factor
:
4370 return "DW_AT_MIPS_loop_unroll_factor";
4373 #if VMS_DEBUGGING_INFO
4374 case DW_AT_HP_epilogue
:
4375 return "DW_AT_HP_epilogue";
4377 case DW_AT_MIPS_stride
:
4378 return "DW_AT_MIPS_stride";
4382 name
= get_DW_AT_name (attr
);
4387 return "DW_AT_<unknown>";
4390 /* Convert a DWARF value form code into its string name. */
4393 dwarf_form_name (unsigned int form
)
4395 const char *name
= get_DW_FORM_name (form
);
4400 return "DW_FORM_<unknown>";
4403 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4404 instance of an inlined instance of a decl which is local to an inline
4405 function, so we have to trace all of the way back through the origin chain
4406 to find out what sort of node actually served as the original seed for the
4410 decl_ultimate_origin (const_tree decl
)
4412 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
4415 /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
4416 we're trying to output the abstract instance of this function. */
4417 if (DECL_ABSTRACT_P (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4420 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4421 most distant ancestor, this should never happen. */
4422 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
4424 return DECL_ABSTRACT_ORIGIN (decl
);
4427 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4428 of a virtual function may refer to a base class, so we check the 'this'
4432 decl_class_context (tree decl
)
4434 tree context
= NULL_TREE
;
4436 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4437 context
= DECL_CONTEXT (decl
);
4439 context
= TYPE_MAIN_VARIANT
4440 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4442 if (context
&& !TYPE_P (context
))
4443 context
= NULL_TREE
;
4448 /* Add an attribute/value pair to a DIE. */
4451 add_dwarf_attr (dw_die_ref die
, dw_attr_node
*attr
)
4453 /* Maybe this should be an assert? */
4459 /* Check we do not add duplicate attrs. Can't use get_AT here
4460 because that recurses to the specification/abstract origin DIE. */
4463 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4464 gcc_assert (a
->dw_attr
!= attr
->dw_attr
);
4467 vec_safe_reserve (die
->die_attr
, 1);
4468 vec_safe_push (die
->die_attr
, *attr
);
4472 AT_class (dw_attr_node
*a
)
4474 return a
->dw_attr_val
.val_class
;
4477 /* Return the index for any attribute that will be referenced with a
4478 DW_FORM_addrx/GNU_addr_index or DW_FORM_strx/GNU_str_index. String
4479 indices are stored in dw_attr_val.v.val_str for reference counting
4482 static inline unsigned int
4483 AT_index (dw_attr_node
*a
)
4485 if (AT_class (a
) == dw_val_class_str
)
4486 return a
->dw_attr_val
.v
.val_str
->index
;
4487 else if (a
->dw_attr_val
.val_entry
!= NULL
)
4488 return a
->dw_attr_val
.val_entry
->index
;
4492 /* Add a flag value attribute to a DIE. */
4495 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
4499 attr
.dw_attr
= attr_kind
;
4500 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
4501 attr
.dw_attr_val
.val_entry
= NULL
;
4502 attr
.dw_attr_val
.v
.val_flag
= flag
;
4503 add_dwarf_attr (die
, &attr
);
4506 static inline unsigned
4507 AT_flag (dw_attr_node
*a
)
4509 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
4510 return a
->dw_attr_val
.v
.val_flag
;
4513 /* Add a signed integer attribute value to a DIE. */
4516 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
4520 attr
.dw_attr
= attr_kind
;
4521 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
4522 attr
.dw_attr_val
.val_entry
= NULL
;
4523 attr
.dw_attr_val
.v
.val_int
= int_val
;
4524 add_dwarf_attr (die
, &attr
);
4528 AT_int (dw_attr_node
*a
)
4530 gcc_assert (a
&& (AT_class (a
) == dw_val_class_const
4531 || AT_class (a
) == dw_val_class_const_implicit
));
4532 return a
->dw_attr_val
.v
.val_int
;
4535 /* Add an unsigned integer attribute value to a DIE. */
4538 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4539 unsigned HOST_WIDE_INT unsigned_val
)
4543 attr
.dw_attr
= attr_kind
;
4544 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4545 attr
.dw_attr_val
.val_entry
= NULL
;
4546 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4547 add_dwarf_attr (die
, &attr
);
4550 unsigned HOST_WIDE_INT
4551 AT_unsigned (dw_attr_node
*a
)
4553 gcc_assert (a
&& (AT_class (a
) == dw_val_class_unsigned_const
4554 || AT_class (a
) == dw_val_class_unsigned_const_implicit
));
4555 return a
->dw_attr_val
.v
.val_unsigned
;
4558 /* Add an unsigned wide integer attribute value to a DIE. */
4561 add_AT_wide (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4566 attr
.dw_attr
= attr_kind
;
4567 attr
.dw_attr_val
.val_class
= dw_val_class_wide_int
;
4568 attr
.dw_attr_val
.val_entry
= NULL
;
4569 attr
.dw_attr_val
.v
.val_wide
= ggc_alloc
<wide_int
> ();
4570 *attr
.dw_attr_val
.v
.val_wide
= w
;
4571 add_dwarf_attr (die
, &attr
);
4574 /* Add an unsigned double integer attribute value to a DIE. */
4577 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4578 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
4582 attr
.dw_attr
= attr_kind
;
4583 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
4584 attr
.dw_attr_val
.val_entry
= NULL
;
4585 attr
.dw_attr_val
.v
.val_double
.high
= high
;
4586 attr
.dw_attr_val
.v
.val_double
.low
= low
;
4587 add_dwarf_attr (die
, &attr
);
4590 /* Add a floating point attribute value to a DIE and return it. */
4593 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4594 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
4598 attr
.dw_attr
= attr_kind
;
4599 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
4600 attr
.dw_attr_val
.val_entry
= NULL
;
4601 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
4602 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
4603 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
4604 add_dwarf_attr (die
, &attr
);
4607 /* Add an 8-byte data attribute value to a DIE. */
4610 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4611 unsigned char data8
[8])
4615 attr
.dw_attr
= attr_kind
;
4616 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
4617 attr
.dw_attr_val
.val_entry
= NULL
;
4618 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
4619 add_dwarf_attr (die
, &attr
);
4622 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
4623 dwarf_split_debug_info, address attributes in dies destined for the
4624 final executable have force_direct set to avoid using indexed
4628 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
4634 lbl_id
= xstrdup (lbl_low
);
4635 attr
.dw_attr
= DW_AT_low_pc
;
4636 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4637 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4638 if (dwarf_split_debug_info
&& !force_direct
)
4639 attr
.dw_attr_val
.val_entry
4640 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4642 attr
.dw_attr_val
.val_entry
= NULL
;
4643 add_dwarf_attr (die
, &attr
);
4645 attr
.dw_attr
= DW_AT_high_pc
;
4646 if (dwarf_version
< 4)
4647 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4649 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
4650 lbl_id
= xstrdup (lbl_high
);
4651 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4652 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
4653 && dwarf_split_debug_info
&& !force_direct
)
4654 attr
.dw_attr_val
.val_entry
4655 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4657 attr
.dw_attr_val
.val_entry
= NULL
;
4658 add_dwarf_attr (die
, &attr
);
4661 /* Hash and equality functions for debug_str_hash. */
4664 indirect_string_hasher::hash (indirect_string_node
*x
)
4666 return htab_hash_string (x
->str
);
4670 indirect_string_hasher::equal (indirect_string_node
*x1
, const char *x2
)
4672 return strcmp (x1
->str
, x2
) == 0;
4675 /* Add STR to the given string hash table. */
4677 static struct indirect_string_node
*
4678 find_AT_string_in_table (const char *str
,
4679 hash_table
<indirect_string_hasher
> *table
,
4680 enum insert_option insert
= INSERT
)
4682 struct indirect_string_node
*node
;
4684 indirect_string_node
**slot
4685 = table
->find_slot_with_hash (str
, htab_hash_string (str
), insert
);
4688 node
= ggc_cleared_alloc
<indirect_string_node
> ();
4689 node
->str
= ggc_strdup (str
);
4699 /* Add STR to the indirect string hash table. */
4701 static struct indirect_string_node
*
4702 find_AT_string (const char *str
, enum insert_option insert
= INSERT
)
4704 if (! debug_str_hash
)
4705 debug_str_hash
= hash_table
<indirect_string_hasher
>::create_ggc (10);
4707 return find_AT_string_in_table (str
, debug_str_hash
, insert
);
4710 /* Add a string attribute value to a DIE. */
4713 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4716 struct indirect_string_node
*node
;
4718 node
= find_AT_string (str
);
4720 attr
.dw_attr
= attr_kind
;
4721 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4722 attr
.dw_attr_val
.val_entry
= NULL
;
4723 attr
.dw_attr_val
.v
.val_str
= node
;
4724 add_dwarf_attr (die
, &attr
);
4727 static inline const char *
4728 AT_string (dw_attr_node
*a
)
4730 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4731 return a
->dw_attr_val
.v
.val_str
->str
;
4734 /* Call this function directly to bypass AT_string_form's logic to put
4735 the string inline in the die. */
4738 set_indirect_string (struct indirect_string_node
*node
)
4740 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4741 /* Already indirect is a no op. */
4742 if (node
->form
== DW_FORM_strp
4743 || node
->form
== DW_FORM_line_strp
4744 || node
->form
== dwarf_FORM (DW_FORM_strx
))
4746 gcc_assert (node
->label
);
4749 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4750 ++dw2_string_counter
;
4751 node
->label
= xstrdup (label
);
4753 if (!dwarf_split_debug_info
)
4755 node
->form
= DW_FORM_strp
;
4756 node
->index
= NOT_INDEXED
;
4760 node
->form
= dwarf_FORM (DW_FORM_strx
);
4761 node
->index
= NO_INDEX_ASSIGNED
;
4765 /* A helper function for dwarf2out_finish, called to reset indirect
4766 string decisions done for early LTO dwarf output before fat object
4770 reset_indirect_string (indirect_string_node
**h
, void *)
4772 struct indirect_string_node
*node
= *h
;
4773 if (node
->form
== DW_FORM_strp
4774 || node
->form
== DW_FORM_line_strp
4775 || node
->form
== dwarf_FORM (DW_FORM_strx
))
4779 node
->form
= (dwarf_form
) 0;
4785 /* Add a string representing a file or filepath attribute value to a DIE. */
4788 add_filepath_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4791 if (! asm_outputs_debug_line_str ())
4792 add_AT_string (die
, attr_kind
, str
);
4796 struct indirect_string_node
*node
;
4798 if (!debug_line_str_hash
)
4800 = hash_table
<indirect_string_hasher
>::create_ggc (10);
4802 node
= find_AT_string_in_table (str
, debug_line_str_hash
);
4803 set_indirect_string (node
);
4804 node
->form
= DW_FORM_line_strp
;
4806 attr
.dw_attr
= attr_kind
;
4807 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4808 attr
.dw_attr_val
.val_entry
= NULL
;
4809 attr
.dw_attr_val
.v
.val_str
= node
;
4810 add_dwarf_attr (die
, &attr
);
4814 /* Find out whether a string should be output inline in DIE
4815 or out-of-line in .debug_str section. */
4817 static enum dwarf_form
4818 find_string_form (struct indirect_string_node
*node
)
4825 len
= strlen (node
->str
) + 1;
4827 /* If the string is shorter or equal to the size of the reference, it is
4828 always better to put it inline. */
4829 if (len
<= (unsigned) dwarf_offset_size
|| node
->refcount
== 0)
4830 return node
->form
= DW_FORM_string
;
4832 /* If we cannot expect the linker to merge strings in .debug_str
4833 section, only put it into .debug_str if it is worth even in this
4835 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4836 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4837 && (len
- dwarf_offset_size
) * node
->refcount
<= len
))
4838 return node
->form
= DW_FORM_string
;
4840 set_indirect_string (node
);
4845 /* Find out whether the string referenced from the attribute should be
4846 output inline in DIE or out-of-line in .debug_str section. */
4848 static enum dwarf_form
4849 AT_string_form (dw_attr_node
*a
)
4851 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4852 return find_string_form (a
->dw_attr_val
.v
.val_str
);
4855 /* Add a DIE reference attribute value to a DIE. */
4858 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4861 gcc_checking_assert (targ_die
!= NULL
);
4863 /* With LTO we can end up trying to reference something we didn't create
4864 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4865 if (targ_die
== NULL
)
4868 attr
.dw_attr
= attr_kind
;
4869 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4870 attr
.dw_attr_val
.val_entry
= NULL
;
4871 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4872 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4873 add_dwarf_attr (die
, &attr
);
4876 /* Change DIE reference REF to point to NEW_DIE instead. */
4879 change_AT_die_ref (dw_attr_node
*ref
, dw_die_ref new_die
)
4881 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4882 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4883 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4886 /* Add an AT_specification attribute to a DIE, and also make the back
4887 pointer from the specification to the definition. */
4890 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4892 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4893 gcc_assert (!targ_die
->die_definition
);
4894 targ_die
->die_definition
= die
;
4897 static inline dw_die_ref
4898 AT_ref (dw_attr_node
*a
)
4900 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4901 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4905 AT_ref_external (dw_attr_node
*a
)
4907 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4908 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4914 set_AT_ref_external (dw_attr_node
*a
, int i
)
4916 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4917 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4920 /* Add a location description attribute value to a DIE. */
4923 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4927 attr
.dw_attr
= attr_kind
;
4928 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4929 attr
.dw_attr_val
.val_entry
= NULL
;
4930 attr
.dw_attr_val
.v
.val_loc
= loc
;
4931 add_dwarf_attr (die
, &attr
);
4935 AT_loc (dw_attr_node
*a
)
4937 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4938 return a
->dw_attr_val
.v
.val_loc
;
4942 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4946 if (XCOFF_DEBUGGING_INFO
&& !HAVE_XCOFF_DWARF_EXTRAS
)
4949 attr
.dw_attr
= attr_kind
;
4950 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4951 attr
.dw_attr_val
.val_entry
= NULL
;
4952 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4953 add_dwarf_attr (die
, &attr
);
4954 have_location_lists
= true;
4957 static inline dw_loc_list_ref
4958 AT_loc_list (dw_attr_node
*a
)
4960 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4961 return a
->dw_attr_val
.v
.val_loc_list
;
4964 /* Add a view list attribute to DIE. It must have a DW_AT_location
4965 attribute, because the view list complements the location list. */
4968 add_AT_view_list (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4972 if (XCOFF_DEBUGGING_INFO
&& !HAVE_XCOFF_DWARF_EXTRAS
)
4975 attr
.dw_attr
= attr_kind
;
4976 attr
.dw_attr_val
.val_class
= dw_val_class_view_list
;
4977 attr
.dw_attr_val
.val_entry
= NULL
;
4978 attr
.dw_attr_val
.v
.val_view_list
= die
;
4979 add_dwarf_attr (die
, &attr
);
4980 gcc_checking_assert (get_AT (die
, DW_AT_location
));
4981 gcc_assert (have_location_lists
);
4984 /* Return a pointer to the location list referenced by the attribute.
4985 If the named attribute is a view list, look up the corresponding
4986 DW_AT_location attribute and return its location list. */
4988 static inline dw_loc_list_ref
*
4989 AT_loc_list_ptr (dw_attr_node
*a
)
4992 switch (AT_class (a
))
4994 case dw_val_class_loc_list
:
4995 return &a
->dw_attr_val
.v
.val_loc_list
;
4996 case dw_val_class_view_list
:
4999 l
= get_AT (a
->dw_attr_val
.v
.val_view_list
, DW_AT_location
);
5002 gcc_checking_assert (l
+ 1 == a
);
5003 return AT_loc_list_ptr (l
);
5010 /* Return the location attribute value associated with a view list
5013 static inline dw_val_node
*
5014 view_list_to_loc_list_val_node (dw_val_node
*val
)
5016 gcc_assert (val
->val_class
== dw_val_class_view_list
);
5017 dw_attr_node
*loc
= get_AT (val
->v
.val_view_list
, DW_AT_location
);
5020 gcc_checking_assert (&(loc
+ 1)->dw_attr_val
== val
);
5021 gcc_assert (AT_class (loc
) == dw_val_class_loc_list
);
5022 return &loc
->dw_attr_val
;
5025 struct addr_hasher
: ggc_ptr_hash
<addr_table_entry
>
5027 static hashval_t
hash (addr_table_entry
*);
5028 static bool equal (addr_table_entry
*, addr_table_entry
*);
5031 /* Table of entries into the .debug_addr section. */
5033 static GTY (()) hash_table
<addr_hasher
> *addr_index_table
;
5035 /* Hash an address_table_entry. */
5038 addr_hasher::hash (addr_table_entry
*a
)
5040 inchash::hash hstate
;
5046 case ate_kind_rtx_dtprel
:
5049 case ate_kind_label
:
5050 return htab_hash_string (a
->addr
.label
);
5054 inchash::add_rtx (a
->addr
.rtl
, hstate
);
5055 return hstate
.end ();
5058 /* Determine equality for two address_table_entries. */
5061 addr_hasher::equal (addr_table_entry
*a1
, addr_table_entry
*a2
)
5063 if (a1
->kind
!= a2
->kind
)
5068 case ate_kind_rtx_dtprel
:
5069 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
5070 case ate_kind_label
:
5071 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
5077 /* Initialize an addr_table_entry. */
5080 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
5086 case ate_kind_rtx_dtprel
:
5087 e
->addr
.rtl
= (rtx
) addr
;
5089 case ate_kind_label
:
5090 e
->addr
.label
= (char *) addr
;
5094 e
->index
= NO_INDEX_ASSIGNED
;
5097 /* Add attr to the address table entry to the table. Defer setting an
5098 index until output time. */
5100 static addr_table_entry
*
5101 add_addr_table_entry (void *addr
, enum ate_kind kind
)
5103 addr_table_entry
*node
;
5104 addr_table_entry finder
;
5106 gcc_assert (dwarf_split_debug_info
);
5107 if (! addr_index_table
)
5108 addr_index_table
= hash_table
<addr_hasher
>::create_ggc (10);
5109 init_addr_table_entry (&finder
, kind
, addr
);
5110 addr_table_entry
**slot
= addr_index_table
->find_slot (&finder
, INSERT
);
5112 if (*slot
== HTAB_EMPTY_ENTRY
)
5114 node
= ggc_cleared_alloc
<addr_table_entry
> ();
5115 init_addr_table_entry (node
, kind
, addr
);
5125 /* Remove an entry from the addr table by decrementing its refcount.
5126 Strictly, decrementing the refcount would be enough, but the
5127 assertion that the entry is actually in the table has found
5131 remove_addr_table_entry (addr_table_entry
*entry
)
5133 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
5134 /* After an index is assigned, the table is frozen. */
5135 gcc_assert (entry
->refcount
> 0 && entry
->index
== NO_INDEX_ASSIGNED
);
5139 /* Given a location list, remove all addresses it refers to from the
5143 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
5145 for (; descr
; descr
= descr
->dw_loc_next
)
5146 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
5148 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
5149 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
5153 /* A helper function for dwarf2out_finish called through
5154 htab_traverse. Assign an addr_table_entry its index. All entries
5155 must be collected into the table when this function is called,
5156 because the indexing code relies on htab_traverse to traverse nodes
5157 in the same order for each run. */
5160 index_addr_table_entry (addr_table_entry
**h
, unsigned int *index
)
5162 addr_table_entry
*node
= *h
;
5164 /* Don't index unreferenced nodes. */
5165 if (node
->refcount
== 0)
5168 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
5169 node
->index
= *index
;
5175 /* Return the tag of a given DIE. */
5178 dw_get_die_tag (dw_die_ref die
)
5180 return die
->die_tag
;
5183 /* Return a reference to the children list of a given DIE. */
5186 dw_get_die_child (dw_die_ref die
)
5188 return die
->die_child
;
5191 /* Return a reference to the sibling of a given DIE. */
5194 dw_get_die_sib (dw_die_ref die
)
5196 return die
->die_sib
;
5199 /* Add an address constant attribute value to a DIE. When using
5200 dwarf_split_debug_info, address attributes in dies destined for the
5201 final executable should be direct references--setting the parameter
5202 force_direct ensures this behavior. */
5205 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
5210 attr
.dw_attr
= attr_kind
;
5211 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
5212 attr
.dw_attr_val
.v
.val_addr
= addr
;
5213 if (dwarf_split_debug_info
&& !force_direct
)
5214 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
5216 attr
.dw_attr_val
.val_entry
= NULL
;
5217 add_dwarf_attr (die
, &attr
);
5220 /* Get the RTX from to an address DIE attribute. */
5223 AT_addr (dw_attr_node
*a
)
5225 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
5226 return a
->dw_attr_val
.v
.val_addr
;
5229 /* Add a file attribute value to a DIE. */
5232 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5233 struct dwarf_file_data
*fd
)
5237 attr
.dw_attr
= attr_kind
;
5238 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
5239 attr
.dw_attr_val
.val_entry
= NULL
;
5240 attr
.dw_attr_val
.v
.val_file
= fd
;
5241 add_dwarf_attr (die
, &attr
);
5244 /* Get the dwarf_file_data from a file DIE attribute. */
5246 static inline struct dwarf_file_data
*
5247 AT_file (dw_attr_node
*a
)
5249 gcc_assert (a
&& (AT_class (a
) == dw_val_class_file
5250 || AT_class (a
) == dw_val_class_file_implicit
));
5251 return a
->dw_attr_val
.v
.val_file
;
5254 #if VMS_DEBUGGING_INFO
5255 /* Add a vms delta attribute value to a DIE. */
5258 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5259 const char *lbl1
, const char *lbl2
)
5263 attr
.dw_attr
= attr_kind
;
5264 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
5265 attr
.dw_attr_val
.val_entry
= NULL
;
5266 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
5267 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
5268 add_dwarf_attr (die
, &attr
);
5272 /* Add a symbolic view identifier attribute value to a DIE. */
5275 add_AT_symview (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5276 const char *view_label
)
5280 attr
.dw_attr
= attr_kind
;
5281 attr
.dw_attr_val
.val_class
= dw_val_class_symview
;
5282 attr
.dw_attr_val
.val_entry
= NULL
;
5283 attr
.dw_attr_val
.v
.val_symbolic_view
= xstrdup (view_label
);
5284 add_dwarf_attr (die
, &attr
);
5287 /* Add a label identifier attribute value to a DIE. */
5290 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5295 attr
.dw_attr
= attr_kind
;
5296 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
5297 attr
.dw_attr_val
.val_entry
= NULL
;
5298 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
5299 if (dwarf_split_debug_info
)
5300 attr
.dw_attr_val
.val_entry
5301 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
5303 add_dwarf_attr (die
, &attr
);
5306 /* Add a section offset attribute value to a DIE, an offset into the
5307 debug_line section. */
5310 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5315 attr
.dw_attr
= attr_kind
;
5316 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
5317 attr
.dw_attr_val
.val_entry
= NULL
;
5318 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
5319 add_dwarf_attr (die
, &attr
);
5322 /* Add a section offset attribute value to a DIE, an offset into the
5323 debug_macinfo section. */
5326 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5331 attr
.dw_attr
= attr_kind
;
5332 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
5333 attr
.dw_attr_val
.val_entry
= NULL
;
5334 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
5335 add_dwarf_attr (die
, &attr
);
5338 /* Add a range_list attribute value to a DIE. When using
5339 dwarf_split_debug_info, address attributes in dies destined for the
5340 final executable should be direct references--setting the parameter
5341 force_direct ensures this behavior. */
5343 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
5344 #define RELOCATED_OFFSET (NULL)
5347 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5348 long unsigned int offset
, bool force_direct
)
5352 attr
.dw_attr
= attr_kind
;
5353 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
5354 /* For the range_list attribute, use val_entry to store whether the
5355 offset should follow split-debug-info or normal semantics. This
5356 value is read in output_range_list_offset. */
5357 if (dwarf_split_debug_info
&& !force_direct
)
5358 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
5360 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
5361 attr
.dw_attr_val
.v
.val_offset
= offset
;
5362 add_dwarf_attr (die
, &attr
);
5365 /* Return the start label of a delta attribute. */
5367 static inline const char *
5368 AT_vms_delta1 (dw_attr_node
*a
)
5370 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
5371 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
5374 /* Return the end label of a delta attribute. */
5376 static inline const char *
5377 AT_vms_delta2 (dw_attr_node
*a
)
5379 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
5380 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
5383 static inline const char *
5384 AT_lbl (dw_attr_node
*a
)
5386 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
5387 || AT_class (a
) == dw_val_class_lineptr
5388 || AT_class (a
) == dw_val_class_macptr
5389 || AT_class (a
) == dw_val_class_loclistsptr
5390 || AT_class (a
) == dw_val_class_high_pc
));
5391 return a
->dw_attr_val
.v
.val_lbl_id
;
5394 /* Get the attribute of type attr_kind. */
5397 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5401 dw_die_ref spec
= NULL
;
5406 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5407 if (a
->dw_attr
== attr_kind
)
5409 else if (a
->dw_attr
== DW_AT_specification
5410 || a
->dw_attr
== DW_AT_abstract_origin
)
5414 return get_AT (spec
, attr_kind
);
5419 /* Returns the parent of the declaration of DIE. */
5422 get_die_parent (dw_die_ref die
)
5429 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
5430 || (t
= get_AT_ref (die
, DW_AT_specification
)))
5433 return die
->die_parent
;
5436 /* Return the "low pc" attribute value, typically associated with a subprogram
5437 DIE. Return null if the "low pc" attribute is either not present, or if it
5438 cannot be represented as an assembler label identifier. */
5440 static inline const char *
5441 get_AT_low_pc (dw_die_ref die
)
5443 dw_attr_node
*a
= get_AT (die
, DW_AT_low_pc
);
5445 return a
? AT_lbl (a
) : NULL
;
5448 /* Return the value of the string attribute designated by ATTR_KIND, or
5449 NULL if it is not present. */
5452 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5454 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5456 return a
? AT_string (a
) : NULL
;
5459 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5460 if it is not present. */
5463 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5465 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5467 return a
? AT_flag (a
) : 0;
5470 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5471 if it is not present. */
5474 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5476 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5478 return a
? AT_unsigned (a
) : 0;
5482 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5484 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5486 return a
? AT_ref (a
) : NULL
;
5489 struct dwarf_file_data
*
5490 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5492 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5494 return a
? AT_file (a
) : NULL
;
5497 /* Return TRUE if the language is C. */
5502 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5504 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
|| lang
== DW_LANG_C99
5505 || lang
== DW_LANG_C11
|| lang
== DW_LANG_ObjC
);
5510 /* Return TRUE if the language is C++. */
5515 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5517 return (lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
5518 || lang
== DW_LANG_C_plus_plus_11
|| lang
== DW_LANG_C_plus_plus_14
);
5521 /* Return TRUE if DECL was created by the C++ frontend. */
5524 is_cxx (const_tree decl
)
5528 const_tree context
= get_ultimate_context (decl
);
5529 if (context
&& TRANSLATION_UNIT_LANGUAGE (context
))
5530 return startswith (TRANSLATION_UNIT_LANGUAGE (context
), "GNU C++");
5535 /* Return TRUE if the language is Fortran. */
5540 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5542 return (lang
== DW_LANG_Fortran77
5543 || lang
== DW_LANG_Fortran90
5544 || lang
== DW_LANG_Fortran95
5545 || lang
== DW_LANG_Fortran03
5546 || lang
== DW_LANG_Fortran08
);
5550 is_fortran (const_tree decl
)
5554 const_tree context
= get_ultimate_context (decl
);
5555 if (context
&& TRANSLATION_UNIT_LANGUAGE (context
))
5556 return (strncmp (TRANSLATION_UNIT_LANGUAGE (context
),
5557 "GNU Fortran", 11) == 0
5558 || strcmp (TRANSLATION_UNIT_LANGUAGE (context
),
5561 return is_fortran ();
5564 /* Return TRUE if the language is Ada. */
5569 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5571 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
5574 /* Return TRUE if the language is D. */
5579 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5581 return lang
== DW_LANG_D
;
5584 /* Remove the specified attribute if present. Return TRUE if removal
5588 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5596 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5597 if (a
->dw_attr
== attr_kind
)
5599 if (AT_class (a
) == dw_val_class_str
)
5600 if (a
->dw_attr_val
.v
.val_str
->refcount
)
5601 a
->dw_attr_val
.v
.val_str
->refcount
--;
5603 /* vec::ordered_remove should help reduce the number of abbrevs
5605 die
->die_attr
->ordered_remove (ix
);
5611 /* Remove CHILD from its parent. PREV must have the property that
5612 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
5615 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
5617 gcc_assert (child
->die_parent
== prev
->die_parent
);
5618 gcc_assert (prev
->die_sib
== child
);
5621 gcc_assert (child
->die_parent
->die_child
== child
);
5625 prev
->die_sib
= child
->die_sib
;
5626 if (child
->die_parent
->die_child
== child
)
5627 child
->die_parent
->die_child
= prev
;
5628 child
->die_sib
= NULL
;
5631 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
5632 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
5635 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
5637 dw_die_ref parent
= old_child
->die_parent
;
5639 gcc_assert (parent
== prev
->die_parent
);
5640 gcc_assert (prev
->die_sib
== old_child
);
5642 new_child
->die_parent
= parent
;
5643 if (prev
== old_child
)
5645 gcc_assert (parent
->die_child
== old_child
);
5646 new_child
->die_sib
= new_child
;
5650 prev
->die_sib
= new_child
;
5651 new_child
->die_sib
= old_child
->die_sib
;
5653 if (old_child
->die_parent
->die_child
== old_child
)
5654 old_child
->die_parent
->die_child
= new_child
;
5655 old_child
->die_sib
= NULL
;
5658 /* Move all children from OLD_PARENT to NEW_PARENT. */
5661 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
5664 new_parent
->die_child
= old_parent
->die_child
;
5665 old_parent
->die_child
= NULL
;
5666 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
5669 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
5673 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
5679 dw_die_ref prev
= c
;
5681 while (c
->die_tag
== tag
)
5683 remove_child_with_prev (c
, prev
);
5684 c
->die_parent
= NULL
;
5685 /* Might have removed every child. */
5686 if (die
->die_child
== NULL
)
5690 } while (c
!= die
->die_child
);
5693 /* Add a CHILD_DIE as the last child of DIE. */
5696 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
5698 /* FIXME this should probably be an assert. */
5699 if (! die
|| ! child_die
)
5701 gcc_assert (die
!= child_die
);
5703 child_die
->die_parent
= die
;
5706 child_die
->die_sib
= die
->die_child
->die_sib
;
5707 die
->die_child
->die_sib
= child_die
;
5710 child_die
->die_sib
= child_die
;
5711 die
->die_child
= child_die
;
5714 /* Like add_child_die, but put CHILD_DIE after AFTER_DIE. */
5717 add_child_die_after (dw_die_ref die
, dw_die_ref child_die
,
5718 dw_die_ref after_die
)
5724 && die
!= child_die
);
5726 child_die
->die_parent
= die
;
5727 child_die
->die_sib
= after_die
->die_sib
;
5728 after_die
->die_sib
= child_die
;
5729 if (die
->die_child
== after_die
)
5730 die
->die_child
= child_die
;
5733 /* Unassociate CHILD from its parent, and make its parent be
5737 reparent_child (dw_die_ref child
, dw_die_ref new_parent
)
5739 for (dw_die_ref p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
5740 if (p
->die_sib
== child
)
5742 remove_child_with_prev (child
, p
);
5745 add_child_die (new_parent
, child
);
5748 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5749 is the specification, to the end of PARENT's list of children.
5750 This is done by removing and re-adding it. */
5753 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
5755 /* We want the declaration DIE from inside the class, not the
5756 specification DIE at toplevel. */
5757 if (child
->die_parent
!= parent
)
5759 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5765 gcc_assert (child
->die_parent
== parent
5766 || (child
->die_parent
5767 == get_AT_ref (parent
, DW_AT_specification
)));
5769 reparent_child (child
, parent
);
5772 /* Create and return a new die with TAG_VALUE as tag. */
5775 new_die_raw (enum dwarf_tag tag_value
)
5777 dw_die_ref die
= ggc_cleared_alloc
<die_node
> ();
5778 die
->die_tag
= tag_value
;
5782 /* Create and return a new die with a parent of PARENT_DIE. If
5783 PARENT_DIE is NULL, the new DIE is placed in limbo and an
5784 associated tree T must be supplied to determine parenthood
5787 static inline dw_die_ref
5788 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
5790 dw_die_ref die
= new_die_raw (tag_value
);
5792 if (parent_die
!= NULL
)
5793 add_child_die (parent_die
, die
);
5796 limbo_die_node
*limbo_node
;
5798 /* No DIEs created after early dwarf should end up in limbo,
5799 because the limbo list should not persist past LTO
5801 if (tag_value
!= DW_TAG_compile_unit
5802 /* These are allowed because they're generated while
5803 breaking out COMDAT units late. */
5804 && tag_value
!= DW_TAG_type_unit
5805 && tag_value
!= DW_TAG_skeleton_unit
5807 /* Allow nested functions to live in limbo because they will
5808 only temporarily live there, as decls_for_scope will fix
5810 && (TREE_CODE (t
) != FUNCTION_DECL
5811 || !decl_function_context (t
))
5812 /* Same as nested functions above but for types. Types that
5813 are local to a function will be fixed in
5815 && (!RECORD_OR_UNION_TYPE_P (t
)
5816 || !TYPE_CONTEXT (t
)
5817 || TREE_CODE (TYPE_CONTEXT (t
)) != FUNCTION_DECL
)
5818 /* FIXME debug-early: Allow late limbo DIE creation for LTO,
5819 especially in the ltrans stage, but once we implement LTO
5820 dwarf streaming, we should remove this exception. */
5823 fprintf (stderr
, "symbol ended up in limbo too late:");
5824 debug_generic_stmt (t
);
5828 limbo_node
= ggc_cleared_alloc
<limbo_die_node
> ();
5829 limbo_node
->die
= die
;
5830 limbo_node
->created_for
= t
;
5831 limbo_node
->next
= limbo_die_list
;
5832 limbo_die_list
= limbo_node
;
5838 /* Return the DIE associated with the given type specifier. */
5841 lookup_type_die (tree type
)
5843 dw_die_ref die
= TYPE_SYMTAB_DIE (type
);
5844 if (die
&& die
->removed
)
5846 TYPE_SYMTAB_DIE (type
) = NULL
;
5852 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
5853 anonymous type named by the typedef TYPE_DIE, return the DIE of the
5854 anonymous type instead the one of the naming typedef. */
5856 static inline dw_die_ref
5857 strip_naming_typedef (tree type
, dw_die_ref type_die
)
5860 && TREE_CODE (type
) == RECORD_TYPE
5862 && type_die
->die_tag
== DW_TAG_typedef
5863 && is_naming_typedef_decl (TYPE_NAME (type
)))
5864 type_die
= get_AT_ref (type_die
, DW_AT_type
);
5868 /* Like lookup_type_die, but if type is an anonymous type named by a
5869 typedef[1], return the DIE of the anonymous type instead the one of
5870 the naming typedef. This is because in gen_typedef_die, we did
5871 equate the anonymous struct named by the typedef with the DIE of
5872 the naming typedef. So by default, lookup_type_die on an anonymous
5873 struct yields the DIE of the naming typedef.
5875 [1]: Read the comment of is_naming_typedef_decl to learn about what
5876 a naming typedef is. */
5878 static inline dw_die_ref
5879 lookup_type_die_strip_naming_typedef (tree type
)
5881 dw_die_ref die
= lookup_type_die (type
);
5882 return strip_naming_typedef (type
, die
);
5885 /* Equate a DIE to a given type specifier. */
5888 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5890 TYPE_SYMTAB_DIE (type
) = type_die
;
5893 static dw_die_ref
maybe_create_die_with_external_ref (tree
);
5894 struct GTY(()) sym_off_pair
5896 const char * GTY((skip
)) sym
;
5897 unsigned HOST_WIDE_INT off
;
5899 static GTY(()) hash_map
<tree
, sym_off_pair
> *external_die_map
;
5901 /* Returns a hash value for X (which really is a die_struct). */
5904 decl_die_hasher::hash (die_node
*x
)
5906 return (hashval_t
) x
->decl_id
;
5909 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5912 decl_die_hasher::equal (die_node
*x
, tree y
)
5914 return (x
->decl_id
== DECL_UID (y
));
5917 /* Return the DIE associated with a given declaration. */
5920 lookup_decl_die (tree decl
)
5922 dw_die_ref
*die
= decl_die_table
->find_slot_with_hash (decl
, DECL_UID (decl
),
5927 return maybe_create_die_with_external_ref (decl
);
5930 if ((*die
)->removed
)
5932 decl_die_table
->clear_slot (die
);
5939 /* Return the DIE associated with BLOCK. */
5941 static inline dw_die_ref
5942 lookup_block_die (tree block
)
5944 dw_die_ref die
= BLOCK_DIE (block
);
5945 if (!die
&& in_lto_p
)
5946 return maybe_create_die_with_external_ref (block
);
5950 /* Associate DIE with BLOCK. */
5953 equate_block_to_die (tree block
, dw_die_ref die
)
5955 BLOCK_DIE (block
) = die
;
5960 /* For DECL which might have early dwarf output query a SYMBOL + OFFSET
5961 style reference. Return true if we found one refering to a DIE for
5962 DECL, otherwise return false. */
5965 dwarf2out_die_ref_for_decl (tree decl
, const char **sym
,
5966 unsigned HOST_WIDE_INT
*off
)
5972 /* During WPA stage and incremental linking we use a hash-map
5973 to store the decl <-> label + offset map. */
5974 if (!external_die_map
)
5976 sym_off_pair
*desc
= external_die_map
->get (decl
);
5984 if (TREE_CODE (decl
) == BLOCK
)
5985 die
= lookup_block_die (decl
);
5987 die
= lookup_decl_die (decl
);
5991 /* Similar to get_ref_die_offset_label, but using the "correct"
5993 *off
= die
->die_offset
;
5994 while (die
->die_parent
)
5995 die
= die
->die_parent
;
5996 /* For the containing CU DIE we compute a die_symbol in
5997 compute_comp_unit_symbol. */
5998 gcc_assert (die
->die_tag
== DW_TAG_compile_unit
5999 && die
->die_id
.die_symbol
!= NULL
);
6000 *sym
= die
->die_id
.die_symbol
;
6004 /* Add a reference of kind ATTR_KIND to a DIE at SYMBOL + OFFSET to DIE. */
6007 add_AT_external_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
,
6008 const char *symbol
, HOST_WIDE_INT offset
)
6010 /* Create a fake DIE that contains the reference. Don't use
6011 new_die because we don't want to end up in the limbo list. */
6012 /* ??? We probably want to share these, thus put a ref to the DIE
6013 we create here to the external_die_map entry. */
6014 dw_die_ref ref
= new_die_raw (die
->die_tag
);
6015 ref
->die_id
.die_symbol
= symbol
;
6016 ref
->die_offset
= offset
;
6017 ref
->with_offset
= 1;
6018 add_AT_die_ref (die
, attr_kind
, ref
);
6021 /* Create a DIE for DECL if required and add a reference to a DIE
6022 at SYMBOL + OFFSET which contains attributes dumped early. */
6025 dwarf2out_register_external_die (tree decl
, const char *sym
,
6026 unsigned HOST_WIDE_INT off
)
6028 if (debug_info_level
== DINFO_LEVEL_NONE
)
6031 if (!external_die_map
)
6032 external_die_map
= hash_map
<tree
, sym_off_pair
>::create_ggc (1000);
6033 gcc_checking_assert (!external_die_map
->get (decl
));
6034 sym_off_pair p
= { IDENTIFIER_POINTER (get_identifier (sym
)), off
};
6035 external_die_map
->put (decl
, p
);
6038 /* If we have a registered external DIE for DECL return a new DIE for
6039 the concrete instance with an appropriate abstract origin. */
6042 maybe_create_die_with_external_ref (tree decl
)
6044 if (!external_die_map
)
6046 sym_off_pair
*desc
= external_die_map
->get (decl
);
6050 const char *sym
= desc
->sym
;
6051 unsigned HOST_WIDE_INT off
= desc
->off
;
6052 external_die_map
->remove (decl
);
6055 dw_die_ref die
= (TREE_CODE (decl
) == BLOCK
6056 ? lookup_block_die (decl
) : lookup_decl_die (decl
));
6061 dw_die_ref parent
= NULL
;
6062 /* Need to lookup a DIE for the decls context - the containing
6063 function or translation unit. */
6064 if (TREE_CODE (decl
) == BLOCK
)
6066 ctx
= BLOCK_SUPERCONTEXT (decl
);
6067 /* ??? We do not output DIEs for all scopes thus skip as
6068 many DIEs as needed. */
6069 while (TREE_CODE (ctx
) == BLOCK
6070 && !lookup_block_die (ctx
))
6071 ctx
= BLOCK_SUPERCONTEXT (ctx
);
6074 ctx
= DECL_CONTEXT (decl
);
6075 /* Peel types in the context stack. */
6076 while (ctx
&& TYPE_P (ctx
))
6077 ctx
= TYPE_CONTEXT (ctx
);
6078 /* Likewise namespaces in case we do not want to emit DIEs for them. */
6079 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
6080 while (ctx
&& TREE_CODE (ctx
) == NAMESPACE_DECL
)
6081 ctx
= DECL_CONTEXT (ctx
);
6084 if (TREE_CODE (ctx
) == BLOCK
)
6085 parent
= lookup_block_die (ctx
);
6086 else if (TREE_CODE (ctx
) == TRANSLATION_UNIT_DECL
6087 /* Keep the 1:1 association during WPA. */
6089 && flag_incremental_link
!= INCREMENTAL_LINK_LTO
)
6090 /* Otherwise all late annotations go to the main CU which
6091 imports the original CUs. */
6092 parent
= comp_unit_die ();
6093 else if (TREE_CODE (ctx
) == FUNCTION_DECL
6094 && TREE_CODE (decl
) != FUNCTION_DECL
6095 && TREE_CODE (decl
) != PARM_DECL
6096 && TREE_CODE (decl
) != RESULT_DECL
6097 && TREE_CODE (decl
) != BLOCK
)
6098 /* Leave function local entities parent determination to when
6099 we process scope vars. */
6102 parent
= lookup_decl_die (ctx
);
6105 /* In some cases the FEs fail to set DECL_CONTEXT properly.
6106 Handle this case gracefully by globalizing stuff. */
6107 parent
= comp_unit_die ();
6108 /* Create a DIE "stub". */
6109 switch (TREE_CODE (decl
))
6111 case TRANSLATION_UNIT_DECL
:
6113 die
= comp_unit_die ();
6114 /* We re-target all CU decls to the LTRANS CU DIE, so no need
6115 to create a DIE for the original CUs. */
6118 case NAMESPACE_DECL
:
6119 if (is_fortran (decl
))
6120 die
= new_die (DW_TAG_module
, parent
, decl
);
6122 die
= new_die (DW_TAG_namespace
, parent
, decl
);
6125 die
= new_die (DW_TAG_subprogram
, parent
, decl
);
6128 die
= new_die (DW_TAG_variable
, parent
, decl
);
6131 die
= new_die (DW_TAG_variable
, parent
, decl
);
6134 die
= new_die (DW_TAG_formal_parameter
, parent
, decl
);
6137 die
= new_die (DW_TAG_constant
, parent
, decl
);
6140 die
= new_die (DW_TAG_label
, parent
, decl
);
6143 die
= new_die (DW_TAG_lexical_block
, parent
, decl
);
6148 if (TREE_CODE (decl
) == BLOCK
)
6149 equate_block_to_die (decl
, die
);
6151 equate_decl_number_to_die (decl
, die
);
6153 add_desc_attribute (die
, decl
);
6155 /* Add a reference to the DIE providing early debug at $sym + off. */
6156 add_AT_external_die_ref (die
, DW_AT_abstract_origin
, sym
, off
);
6161 /* Returns a hash value for X (which really is a var_loc_list). */
6164 decl_loc_hasher::hash (var_loc_list
*x
)
6166 return (hashval_t
) x
->decl_id
;
6169 /* Return nonzero if decl_id of var_loc_list X is the same as
6173 decl_loc_hasher::equal (var_loc_list
*x
, const_tree y
)
6175 return (x
->decl_id
== DECL_UID (y
));
6178 /* Return the var_loc list associated with a given declaration. */
6180 static inline var_loc_list
*
6181 lookup_decl_loc (const_tree decl
)
6183 if (!decl_loc_table
)
6185 return decl_loc_table
->find_with_hash (decl
, DECL_UID (decl
));
6188 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
6191 dw_loc_list_hasher::hash (cached_dw_loc_list
*x
)
6193 return (hashval_t
) x
->decl_id
;
6196 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
6200 dw_loc_list_hasher::equal (cached_dw_loc_list
*x
, const_tree y
)
6202 return (x
->decl_id
== DECL_UID (y
));
6205 /* Equate a DIE to a particular declaration. */
6208 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
6210 unsigned int decl_id
= DECL_UID (decl
);
6212 *decl_die_table
->find_slot_with_hash (decl
, decl_id
, INSERT
) = decl_die
;
6213 decl_die
->decl_id
= decl_id
;
6216 /* Return how many bits covers PIECE EXPR_LIST. */
6218 static HOST_WIDE_INT
6219 decl_piece_bitsize (rtx piece
)
6221 int ret
= (int) GET_MODE (piece
);
6224 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
6225 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
6226 return INTVAL (XEXP (XEXP (piece
, 0), 0));
6229 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
6232 decl_piece_varloc_ptr (rtx piece
)
6234 if ((int) GET_MODE (piece
))
6235 return &XEXP (piece
, 0);
6237 return &XEXP (XEXP (piece
, 0), 1);
6240 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
6241 Next is the chain of following piece nodes. */
6243 static rtx_expr_list
*
6244 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
6246 if (bitsize
> 0 && bitsize
<= (int) MAX_MACHINE_MODE
)
6247 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
6249 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
6254 /* Return rtx that should be stored into loc field for
6255 LOC_NOTE and BITPOS/BITSIZE. */
6258 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
6259 HOST_WIDE_INT bitsize
)
6263 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
6265 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
6270 /* This function either modifies location piece list *DEST in
6271 place (if SRC and INNER is NULL), or copies location piece list
6272 *SRC to *DEST while modifying it. Location BITPOS is modified
6273 to contain LOC_NOTE, any pieces overlapping it are removed resp.
6274 not copied and if needed some padding around it is added.
6275 When modifying in place, DEST should point to EXPR_LIST where
6276 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
6277 to the start of the whole list and INNER points to the EXPR_LIST
6278 where earlier pieces cover PIECE_BITPOS bits. */
6281 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
6282 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
6283 HOST_WIDE_INT bitsize
, rtx loc_note
)
6286 bool copy
= inner
!= NULL
;
6290 /* First copy all nodes preceding the current bitpos. */
6291 while (src
!= inner
)
6293 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
6294 decl_piece_bitsize (*src
), NULL_RTX
);
6295 dest
= &XEXP (*dest
, 1);
6296 src
= &XEXP (*src
, 1);
6299 /* Add padding if needed. */
6300 if (bitpos
!= piece_bitpos
)
6302 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
6303 copy
? NULL_RTX
: *dest
);
6304 dest
= &XEXP (*dest
, 1);
6306 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
6309 /* A piece with correct bitpos and bitsize already exist,
6310 just update the location for it and return. */
6311 *decl_piece_varloc_ptr (*dest
) = loc_note
;
6314 /* Add the piece that changed. */
6315 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
6316 dest
= &XEXP (*dest
, 1);
6317 /* Skip over pieces that overlap it. */
6318 diff
= bitpos
- piece_bitpos
+ bitsize
;
6321 while (diff
> 0 && *src
)
6324 diff
-= decl_piece_bitsize (piece
);
6326 src
= &XEXP (piece
, 1);
6329 *src
= XEXP (piece
, 1);
6330 free_EXPR_LIST_node (piece
);
6333 /* Add padding if needed. */
6334 if (diff
< 0 && *src
)
6338 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
6339 dest
= &XEXP (*dest
, 1);
6343 /* Finally copy all nodes following it. */
6346 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
6347 decl_piece_bitsize (*src
), NULL_RTX
);
6348 dest
= &XEXP (*dest
, 1);
6349 src
= &XEXP (*src
, 1);
6353 /* Add a variable location node to the linked list for DECL. */
6355 static struct var_loc_node
*
6356 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
, var_loc_view view
)
6358 unsigned int decl_id
;
6360 struct var_loc_node
*loc
= NULL
;
6361 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
6363 if (VAR_P (decl
) && DECL_HAS_DEBUG_EXPR_P (decl
))
6365 tree realdecl
= DECL_DEBUG_EXPR (decl
);
6366 if (handled_component_p (realdecl
)
6367 || (TREE_CODE (realdecl
) == MEM_REF
6368 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
6371 tree innerdecl
= get_ref_base_and_extent_hwi (realdecl
, &bitpos
,
6372 &bitsize
, &reverse
);
6374 || !DECL_P (innerdecl
)
6375 || DECL_IGNORED_P (innerdecl
)
6376 || TREE_STATIC (innerdecl
)
6378 || bitpos
+ bitsize
> 256)
6384 decl_id
= DECL_UID (decl
);
6386 = decl_loc_table
->find_slot_with_hash (decl
, decl_id
, INSERT
);
6389 temp
= ggc_cleared_alloc
<var_loc_list
> ();
6390 temp
->decl_id
= decl_id
;
6396 /* For PARM_DECLs try to keep around the original incoming value,
6397 even if that means we'll emit a zero-range .debug_loc entry. */
6399 && temp
->first
== temp
->last
6400 && TREE_CODE (decl
) == PARM_DECL
6401 && NOTE_P (temp
->first
->loc
)
6402 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
6403 && DECL_INCOMING_RTL (decl
)
6404 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
6405 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
6406 == GET_CODE (DECL_INCOMING_RTL (decl
))
6407 && prev_real_insn (as_a
<rtx_insn
*> (temp
->first
->loc
)) == NULL_RTX
6409 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
6410 NOTE_VAR_LOCATION_LOC (loc_note
))
6411 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
6412 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
6414 loc
= ggc_cleared_alloc
<var_loc_node
> ();
6415 temp
->first
->next
= loc
;
6417 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
6419 else if (temp
->last
)
6421 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
6422 rtx
*piece_loc
= NULL
, last_loc_note
;
6423 HOST_WIDE_INT piece_bitpos
= 0;
6427 gcc_assert (last
->next
== NULL
);
6429 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
6431 piece_loc
= &last
->loc
;
6434 HOST_WIDE_INT cur_bitsize
= decl_piece_bitsize (*piece_loc
);
6435 if (piece_bitpos
+ cur_bitsize
> bitpos
)
6437 piece_bitpos
+= cur_bitsize
;
6438 piece_loc
= &XEXP (*piece_loc
, 1);
6442 /* TEMP->LAST here is either pointer to the last but one or
6443 last element in the chained list, LAST is pointer to the
6445 if (label
&& strcmp (last
->label
, label
) == 0 && last
->view
== view
)
6447 /* For SRA optimized variables if there weren't any real
6448 insns since last note, just modify the last node. */
6449 if (piece_loc
!= NULL
)
6451 adjust_piece_list (piece_loc
, NULL
, NULL
,
6452 bitpos
, piece_bitpos
, bitsize
, loc_note
);
6455 /* If the last note doesn't cover any instructions, remove it. */
6456 if (temp
->last
!= last
)
6458 temp
->last
->next
= NULL
;
6461 gcc_assert (strcmp (last
->label
, label
) != 0 || last
->view
!= view
);
6465 gcc_assert (temp
->first
== temp
->last
6466 || (temp
->first
->next
== temp
->last
6467 && TREE_CODE (decl
) == PARM_DECL
));
6468 memset (temp
->last
, '\0', sizeof (*temp
->last
));
6469 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
6473 if (bitsize
== -1 && NOTE_P (last
->loc
))
6474 last_loc_note
= last
->loc
;
6475 else if (piece_loc
!= NULL
6476 && *piece_loc
!= NULL_RTX
6477 && piece_bitpos
== bitpos
6478 && decl_piece_bitsize (*piece_loc
) == bitsize
)
6479 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
6481 last_loc_note
= NULL_RTX
;
6482 /* If the current location is the same as the end of the list,
6483 and either both or neither of the locations is uninitialized,
6484 we have nothing to do. */
6485 if (last_loc_note
== NULL_RTX
6486 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
6487 NOTE_VAR_LOCATION_LOC (loc_note
)))
6488 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
6489 != NOTE_VAR_LOCATION_STATUS (loc_note
))
6490 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
6491 == VAR_INIT_STATUS_UNINITIALIZED
)
6492 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
6493 == VAR_INIT_STATUS_UNINITIALIZED
))))
6495 /* Add LOC to the end of list and update LAST. If the last
6496 element of the list has been removed above, reuse its
6497 memory for the new node, otherwise allocate a new one. */
6501 memset (loc
, '\0', sizeof (*loc
));
6504 loc
= ggc_cleared_alloc
<var_loc_node
> ();
6505 if (bitsize
== -1 || piece_loc
== NULL
)
6506 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
6508 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
6509 bitpos
, piece_bitpos
, bitsize
, loc_note
);
6511 /* Ensure TEMP->LAST will point either to the new last but one
6512 element of the chain, or to the last element in it. */
6513 if (last
!= temp
->last
)
6521 loc
= ggc_cleared_alloc
<var_loc_node
> ();
6524 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
6529 /* Keep track of the number of spaces used to indent the
6530 output of the debugging routines that print the structure of
6531 the DIE internal representation. */
6532 static int print_indent
;
6534 /* Indent the line the number of spaces given by print_indent. */
6537 print_spaces (FILE *outfile
)
6539 fprintf (outfile
, "%*s", print_indent
, "");
6542 /* Print a type signature in hex. */
6545 print_signature (FILE *outfile
, char *sig
)
6549 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
6550 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
6554 print_discr_value (FILE *outfile
, dw_discr_value
*discr_value
)
6556 if (discr_value
->pos
)
6557 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, discr_value
->v
.sval
);
6559 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, discr_value
->v
.uval
);
6562 static void print_loc_descr (dw_loc_descr_ref
, FILE *);
6564 /* Print the value associated to the VAL DWARF value node to OUTFILE. If
6565 RECURSE, output location descriptor operations. */
6568 print_dw_val (dw_val_node
*val
, bool recurse
, FILE *outfile
)
6570 switch (val
->val_class
)
6572 case dw_val_class_addr
:
6573 fprintf (outfile
, "address");
6575 case dw_val_class_offset
:
6576 fprintf (outfile
, "offset");
6578 case dw_val_class_loc
:
6579 fprintf (outfile
, "location descriptor");
6580 if (val
->v
.val_loc
== NULL
)
6581 fprintf (outfile
, " -> <null>\n");
6584 fprintf (outfile
, ":\n");
6586 print_loc_descr (val
->v
.val_loc
, outfile
);
6591 if (flag_dump_noaddr
|| flag_dump_unnumbered
)
6592 fprintf (outfile
, " #\n");
6594 fprintf (outfile
, " (%p)\n", (void *) val
->v
.val_loc
);
6597 case dw_val_class_loc_list
:
6598 fprintf (outfile
, "location list -> label:%s",
6599 val
->v
.val_loc_list
->ll_symbol
);
6601 case dw_val_class_view_list
:
6602 val
= view_list_to_loc_list_val_node (val
);
6603 fprintf (outfile
, "location list with views -> labels:%s and %s",
6604 val
->v
.val_loc_list
->ll_symbol
,
6605 val
->v
.val_loc_list
->vl_symbol
);
6607 case dw_val_class_range_list
:
6608 fprintf (outfile
, "range list");
6610 case dw_val_class_const
:
6611 case dw_val_class_const_implicit
:
6612 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, val
->v
.val_int
);
6614 case dw_val_class_unsigned_const
:
6615 case dw_val_class_unsigned_const_implicit
:
6616 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, val
->v
.val_unsigned
);
6618 case dw_val_class_const_double
:
6619 fprintf (outfile
, "constant (" HOST_WIDE_INT_PRINT_DEC
","\
6620 HOST_WIDE_INT_PRINT_UNSIGNED
")",
6621 val
->v
.val_double
.high
,
6622 val
->v
.val_double
.low
);
6624 case dw_val_class_wide_int
:
6626 int i
= val
->v
.val_wide
->get_len ();
6627 fprintf (outfile
, "constant (");
6629 if (val
->v
.val_wide
->elt (i
- 1) == 0)
6630 fprintf (outfile
, "0x");
6631 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
,
6632 val
->v
.val_wide
->elt (--i
));
6634 fprintf (outfile
, HOST_WIDE_INT_PRINT_PADDED_HEX
,
6635 val
->v
.val_wide
->elt (i
));
6636 fprintf (outfile
, ")");
6639 case dw_val_class_vec
:
6640 fprintf (outfile
, "floating-point or vector constant");
6642 case dw_val_class_flag
:
6643 fprintf (outfile
, "%u", val
->v
.val_flag
);
6645 case dw_val_class_die_ref
:
6646 if (val
->v
.val_die_ref
.die
!= NULL
)
6648 dw_die_ref die
= val
->v
.val_die_ref
.die
;
6650 if (die
->comdat_type_p
)
6652 fprintf (outfile
, "die -> signature: ");
6653 print_signature (outfile
,
6654 die
->die_id
.die_type_node
->signature
);
6656 else if (die
->die_id
.die_symbol
)
6658 fprintf (outfile
, "die -> label: %s", die
->die_id
.die_symbol
);
6659 if (die
->with_offset
)
6660 fprintf (outfile
, " + %ld", die
->die_offset
);
6663 fprintf (outfile
, "die -> %ld", die
->die_offset
);
6664 if (flag_dump_noaddr
|| flag_dump_unnumbered
)
6665 fprintf (outfile
, " #");
6667 fprintf (outfile
, " (%p)", (void *) die
);
6670 fprintf (outfile
, "die -> <null>");
6672 case dw_val_class_vms_delta
:
6673 fprintf (outfile
, "delta: @slotcount(%s-%s)",
6674 val
->v
.val_vms_delta
.lbl2
, val
->v
.val_vms_delta
.lbl1
);
6676 case dw_val_class_symview
:
6677 fprintf (outfile
, "view: %s", val
->v
.val_symbolic_view
);
6679 case dw_val_class_lbl_id
:
6680 case dw_val_class_lineptr
:
6681 case dw_val_class_macptr
:
6682 case dw_val_class_loclistsptr
:
6683 case dw_val_class_high_pc
:
6684 fprintf (outfile
, "label: %s", val
->v
.val_lbl_id
);
6686 case dw_val_class_str
:
6687 if (val
->v
.val_str
->str
!= NULL
)
6688 fprintf (outfile
, "\"%s\"", val
->v
.val_str
->str
);
6690 fprintf (outfile
, "<null>");
6692 case dw_val_class_file
:
6693 case dw_val_class_file_implicit
:
6694 fprintf (outfile
, "\"%s\" (%d)", val
->v
.val_file
->filename
,
6695 val
->v
.val_file
->emitted_number
);
6697 case dw_val_class_data8
:
6701 for (i
= 0; i
< 8; i
++)
6702 fprintf (outfile
, "%02x", val
->v
.val_data8
[i
]);
6705 case dw_val_class_discr_value
:
6706 print_discr_value (outfile
, &val
->v
.val_discr_value
);
6708 case dw_val_class_discr_list
:
6709 for (dw_discr_list_ref node
= val
->v
.val_discr_list
;
6711 node
= node
->dw_discr_next
)
6713 if (node
->dw_discr_range
)
6715 fprintf (outfile
, " .. ");
6716 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
6717 print_discr_value (outfile
, &node
->dw_discr_upper_bound
);
6720 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
6722 if (node
->dw_discr_next
!= NULL
)
6723 fprintf (outfile
, " | ");
6730 /* Likewise, for a DIE attribute. */
6733 print_attribute (dw_attr_node
*a
, bool recurse
, FILE *outfile
)
6735 print_dw_val (&a
->dw_attr_val
, recurse
, outfile
);
6739 /* Print the list of operands in the LOC location description to OUTFILE. This
6740 routine is a debugging aid only. */
6743 print_loc_descr (dw_loc_descr_ref loc
, FILE *outfile
)
6745 dw_loc_descr_ref l
= loc
;
6749 print_spaces (outfile
);
6750 fprintf (outfile
, "<null>\n");
6754 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
6756 print_spaces (outfile
);
6757 if (flag_dump_noaddr
|| flag_dump_unnumbered
)
6758 fprintf (outfile
, "#");
6760 fprintf (outfile
, "(%p)", (void *) l
);
6761 fprintf (outfile
, " %s",
6762 dwarf_stack_op_name (l
->dw_loc_opc
));
6763 if (l
->dw_loc_oprnd1
.val_class
!= dw_val_class_none
)
6765 fprintf (outfile
, " ");
6766 print_dw_val (&l
->dw_loc_oprnd1
, false, outfile
);
6768 if (l
->dw_loc_oprnd2
.val_class
!= dw_val_class_none
)
6770 fprintf (outfile
, ", ");
6771 print_dw_val (&l
->dw_loc_oprnd2
, false, outfile
);
6773 fprintf (outfile
, "\n");
6777 /* Print the information associated with a given DIE, and its children.
6778 This routine is a debugging aid only. */
6781 print_die (dw_die_ref die
, FILE *outfile
)
6787 print_spaces (outfile
);
6788 fprintf (outfile
, "DIE %4ld: %s ",
6789 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
6790 if (flag_dump_noaddr
|| flag_dump_unnumbered
)
6791 fprintf (outfile
, "#\n");
6793 fprintf (outfile
, "(%p)\n", (void*) die
);
6794 print_spaces (outfile
);
6795 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
6796 fprintf (outfile
, " offset: %ld", die
->die_offset
);
6797 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
6799 if (die
->comdat_type_p
)
6801 print_spaces (outfile
);
6802 fprintf (outfile
, " signature: ");
6803 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
6804 fprintf (outfile
, "\n");
6807 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6809 print_spaces (outfile
);
6810 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
6812 print_attribute (a
, true, outfile
);
6813 fprintf (outfile
, "\n");
6816 if (die
->die_child
!= NULL
)
6819 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
6822 if (print_indent
== 0)
6823 fprintf (outfile
, "\n");
6826 /* Print the list of operations in the LOC location description. */
6829 debug_dwarf_loc_descr (dw_loc_descr_ref loc
)
6831 print_loc_descr (loc
, stderr
);
6834 /* Print the information collected for a given DIE. */
6837 debug_dwarf_die (dw_die_ref die
)
6839 print_die (die
, stderr
);
6843 debug (die_struct
&ref
)
6845 print_die (&ref
, stderr
);
6849 debug (die_struct
*ptr
)
6854 fprintf (stderr
, "<nil>\n");
6858 /* Print all DWARF information collected for the compilation unit.
6859 This routine is a debugging aid only. */
6865 print_die (comp_unit_die (), stderr
);
6868 /* Verify the DIE tree structure. */
6871 verify_die (dw_die_ref die
)
6873 gcc_assert (!die
->die_mark
);
6874 if (die
->die_parent
== NULL
6875 && die
->die_sib
== NULL
)
6877 /* Verify the die_sib list is cyclic. */
6884 while (x
&& !x
->die_mark
);
6885 gcc_assert (x
== die
);
6889 /* Verify all dies have the same parent. */
6890 gcc_assert (x
->die_parent
== die
->die_parent
);
6893 /* Verify the child has the proper parent and recurse. */
6894 gcc_assert (x
->die_child
->die_parent
== x
);
6895 verify_die (x
->die_child
);
6900 while (x
&& x
->die_mark
);
6903 /* Sanity checks on DIEs. */
6906 check_die (dw_die_ref die
)
6910 bool inline_found
= false;
6911 int n_location
= 0, n_low_pc
= 0, n_high_pc
= 0, n_artificial
= 0;
6912 int n_decl_line
= 0, n_decl_column
= 0, n_decl_file
= 0;
6913 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6918 if (a
->dw_attr_val
.v
.val_unsigned
)
6919 inline_found
= true;
6921 case DW_AT_location
:
6930 case DW_AT_artificial
:
6933 case DW_AT_decl_column
:
6936 case DW_AT_decl_line
:
6939 case DW_AT_decl_file
:
6946 if (n_location
> 1 || n_low_pc
> 1 || n_high_pc
> 1 || n_artificial
> 1
6947 || n_decl_column
> 1 || n_decl_line
> 1 || n_decl_file
> 1)
6949 fprintf (stderr
, "Duplicate attributes in DIE:\n");
6950 debug_dwarf_die (die
);
6955 /* A debugging information entry that is a member of an abstract
6956 instance tree [that has DW_AT_inline] should not contain any
6957 attributes which describe aspects of the subroutine which vary
6958 between distinct inlined expansions or distinct out-of-line
6960 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6961 gcc_assert (a
->dw_attr
!= DW_AT_low_pc
6962 && a
->dw_attr
!= DW_AT_high_pc
6963 && a
->dw_attr
!= DW_AT_location
6964 && a
->dw_attr
!= DW_AT_frame_base
6965 && a
->dw_attr
!= DW_AT_call_all_calls
6966 && a
->dw_attr
!= DW_AT_GNU_all_call_sites
);
6970 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6971 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
6972 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
6974 /* Calculate the checksum of a location expression. */
6977 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
6980 inchash::hash hstate
;
6983 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
6985 hash_loc_operands (loc
, hstate
);
6986 hash
= hstate
.end();
6990 /* Calculate the checksum of an attribute. */
6993 attr_checksum (dw_attr_node
*at
, struct md5_ctx
*ctx
, int *mark
)
6995 dw_loc_descr_ref loc
;
6998 CHECKSUM (at
->dw_attr
);
7000 /* We don't care that this was compiled with a different compiler
7001 snapshot; if the output is the same, that's what matters. */
7002 if (at
->dw_attr
== DW_AT_producer
)
7005 switch (AT_class (at
))
7007 case dw_val_class_const
:
7008 case dw_val_class_const_implicit
:
7009 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
7011 case dw_val_class_unsigned_const
:
7012 case dw_val_class_unsigned_const_implicit
:
7013 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
7015 case dw_val_class_const_double
:
7016 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
7018 case dw_val_class_wide_int
:
7019 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
7020 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
7021 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
7023 case dw_val_class_vec
:
7024 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
7025 (at
->dw_attr_val
.v
.val_vec
.length
7026 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
7028 case dw_val_class_flag
:
7029 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
7031 case dw_val_class_str
:
7032 CHECKSUM_STRING (AT_string (at
));
7035 case dw_val_class_addr
:
7037 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
7038 CHECKSUM_STRING (XSTR (r
, 0));
7041 case dw_val_class_offset
:
7042 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
7045 case dw_val_class_loc
:
7046 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
7047 loc_checksum (loc
, ctx
);
7050 case dw_val_class_die_ref
:
7051 die_checksum (AT_ref (at
), ctx
, mark
);
7054 case dw_val_class_fde_ref
:
7055 case dw_val_class_vms_delta
:
7056 case dw_val_class_symview
:
7057 case dw_val_class_lbl_id
:
7058 case dw_val_class_lineptr
:
7059 case dw_val_class_macptr
:
7060 case dw_val_class_loclistsptr
:
7061 case dw_val_class_high_pc
:
7064 case dw_val_class_file
:
7065 case dw_val_class_file_implicit
:
7066 CHECKSUM_STRING (AT_file (at
)->filename
);
7069 case dw_val_class_data8
:
7070 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
7078 /* Calculate the checksum of a DIE. */
7081 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
7087 /* To avoid infinite recursion. */
7090 CHECKSUM (die
->die_mark
);
7093 die
->die_mark
= ++(*mark
);
7095 CHECKSUM (die
->die_tag
);
7097 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7098 attr_checksum (a
, ctx
, mark
);
7100 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
7104 #undef CHECKSUM_BLOCK
7105 #undef CHECKSUM_STRING
7107 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
7108 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
7109 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
7110 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
7111 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
7112 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
7113 #define CHECKSUM_ATTR(FOO) \
7114 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
7116 /* Calculate the checksum of a number in signed LEB128 format. */
7119 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
7126 byte
= (value
& 0x7f);
7128 more
= !((value
== 0 && (byte
& 0x40) == 0)
7129 || (value
== -1 && (byte
& 0x40) != 0));
7138 /* Calculate the checksum of a number in unsigned LEB128 format. */
7141 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
7145 unsigned char byte
= (value
& 0x7f);
7148 /* More bytes to follow. */
7156 /* Checksum the context of the DIE. This adds the names of any
7157 surrounding namespaces or structures to the checksum. */
7160 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
7164 int tag
= die
->die_tag
;
7166 if (tag
!= DW_TAG_namespace
7167 && tag
!= DW_TAG_structure_type
7168 && tag
!= DW_TAG_class_type
)
7171 name
= get_AT_string (die
, DW_AT_name
);
7173 spec
= get_AT_ref (die
, DW_AT_specification
);
7177 if (die
->die_parent
!= NULL
)
7178 checksum_die_context (die
->die_parent
, ctx
);
7180 CHECKSUM_ULEB128 ('C');
7181 CHECKSUM_ULEB128 (tag
);
7183 CHECKSUM_STRING (name
);
7186 /* Calculate the checksum of a location expression. */
7189 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
7191 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
7192 were emitted as a DW_FORM_sdata instead of a location expression. */
7193 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
7195 CHECKSUM_ULEB128 (DW_FORM_sdata
);
7196 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
7200 /* Otherwise, just checksum the raw location expression. */
7203 inchash::hash hstate
;
7206 CHECKSUM_ULEB128 (loc
->dtprel
);
7207 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
7208 hash_loc_operands (loc
, hstate
);
7209 hash
= hstate
.end ();
7211 loc
= loc
->dw_loc_next
;
7215 /* Calculate the checksum of an attribute. */
7218 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_node
*at
,
7219 struct md5_ctx
*ctx
, int *mark
)
7221 dw_loc_descr_ref loc
;
7224 if (AT_class (at
) == dw_val_class_die_ref
)
7226 dw_die_ref target_die
= AT_ref (at
);
7228 /* For pointer and reference types, we checksum only the (qualified)
7229 name of the target type (if there is a name). For friend entries,
7230 we checksum only the (qualified) name of the target type or function.
7231 This allows the checksum to remain the same whether the target type
7232 is complete or not. */
7233 if ((at
->dw_attr
== DW_AT_type
7234 && (tag
== DW_TAG_pointer_type
7235 || tag
== DW_TAG_reference_type
7236 || tag
== DW_TAG_rvalue_reference_type
7237 || tag
== DW_TAG_ptr_to_member_type
))
7238 || (at
->dw_attr
== DW_AT_friend
7239 && tag
== DW_TAG_friend
))
7241 dw_attr_node
*name_attr
= get_AT (target_die
, DW_AT_name
);
7243 if (name_attr
!= NULL
)
7245 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
7249 CHECKSUM_ULEB128 ('N');
7250 CHECKSUM_ULEB128 (at
->dw_attr
);
7251 if (decl
->die_parent
!= NULL
)
7252 checksum_die_context (decl
->die_parent
, ctx
);
7253 CHECKSUM_ULEB128 ('E');
7254 CHECKSUM_STRING (AT_string (name_attr
));
7259 /* For all other references to another DIE, we check to see if the
7260 target DIE has already been visited. If it has, we emit a
7261 backward reference; if not, we descend recursively. */
7262 if (target_die
->die_mark
> 0)
7264 CHECKSUM_ULEB128 ('R');
7265 CHECKSUM_ULEB128 (at
->dw_attr
);
7266 CHECKSUM_ULEB128 (target_die
->die_mark
);
7270 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
7274 target_die
->die_mark
= ++(*mark
);
7275 CHECKSUM_ULEB128 ('T');
7276 CHECKSUM_ULEB128 (at
->dw_attr
);
7277 if (decl
->die_parent
!= NULL
)
7278 checksum_die_context (decl
->die_parent
, ctx
);
7279 die_checksum_ordered (target_die
, ctx
, mark
);
7284 CHECKSUM_ULEB128 ('A');
7285 CHECKSUM_ULEB128 (at
->dw_attr
);
7287 switch (AT_class (at
))
7289 case dw_val_class_const
:
7290 case dw_val_class_const_implicit
:
7291 CHECKSUM_ULEB128 (DW_FORM_sdata
);
7292 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
7295 case dw_val_class_unsigned_const
:
7296 case dw_val_class_unsigned_const_implicit
:
7297 CHECKSUM_ULEB128 (DW_FORM_sdata
);
7298 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
7301 case dw_val_class_const_double
:
7302 CHECKSUM_ULEB128 (DW_FORM_block
);
7303 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
7304 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
7307 case dw_val_class_wide_int
:
7308 CHECKSUM_ULEB128 (DW_FORM_block
);
7309 CHECKSUM_ULEB128 (get_full_len (*at
->dw_attr_val
.v
.val_wide
)
7310 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
7311 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
7312 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
7313 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
7316 case dw_val_class_vec
:
7317 CHECKSUM_ULEB128 (DW_FORM_block
);
7318 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
7319 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
7320 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
7321 (at
->dw_attr_val
.v
.val_vec
.length
7322 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
7325 case dw_val_class_flag
:
7326 CHECKSUM_ULEB128 (DW_FORM_flag
);
7327 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
7330 case dw_val_class_str
:
7331 CHECKSUM_ULEB128 (DW_FORM_string
);
7332 CHECKSUM_STRING (AT_string (at
));
7335 case dw_val_class_addr
:
7337 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
7338 CHECKSUM_ULEB128 (DW_FORM_string
);
7339 CHECKSUM_STRING (XSTR (r
, 0));
7342 case dw_val_class_offset
:
7343 CHECKSUM_ULEB128 (DW_FORM_sdata
);
7344 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
7347 case dw_val_class_loc
:
7348 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
7349 loc_checksum_ordered (loc
, ctx
);
7352 case dw_val_class_fde_ref
:
7353 case dw_val_class_symview
:
7354 case dw_val_class_lbl_id
:
7355 case dw_val_class_lineptr
:
7356 case dw_val_class_macptr
:
7357 case dw_val_class_loclistsptr
:
7358 case dw_val_class_high_pc
:
7361 case dw_val_class_file
:
7362 case dw_val_class_file_implicit
:
7363 CHECKSUM_ULEB128 (DW_FORM_string
);
7364 CHECKSUM_STRING (AT_file (at
)->filename
);
7367 case dw_val_class_data8
:
7368 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
7376 struct checksum_attributes
7378 dw_attr_node
*at_name
;
7379 dw_attr_node
*at_type
;
7380 dw_attr_node
*at_friend
;
7381 dw_attr_node
*at_accessibility
;
7382 dw_attr_node
*at_address_class
;
7383 dw_attr_node
*at_alignment
;
7384 dw_attr_node
*at_allocated
;
7385 dw_attr_node
*at_artificial
;
7386 dw_attr_node
*at_associated
;
7387 dw_attr_node
*at_binary_scale
;
7388 dw_attr_node
*at_bit_offset
;
7389 dw_attr_node
*at_bit_size
;
7390 dw_attr_node
*at_bit_stride
;
7391 dw_attr_node
*at_byte_size
;
7392 dw_attr_node
*at_byte_stride
;
7393 dw_attr_node
*at_const_value
;
7394 dw_attr_node
*at_containing_type
;
7395 dw_attr_node
*at_count
;
7396 dw_attr_node
*at_data_location
;
7397 dw_attr_node
*at_data_member_location
;
7398 dw_attr_node
*at_decimal_scale
;
7399 dw_attr_node
*at_decimal_sign
;
7400 dw_attr_node
*at_default_value
;
7401 dw_attr_node
*at_digit_count
;
7402 dw_attr_node
*at_discr
;
7403 dw_attr_node
*at_discr_list
;
7404 dw_attr_node
*at_discr_value
;
7405 dw_attr_node
*at_encoding
;
7406 dw_attr_node
*at_endianity
;
7407 dw_attr_node
*at_explicit
;
7408 dw_attr_node
*at_is_optional
;
7409 dw_attr_node
*at_location
;
7410 dw_attr_node
*at_lower_bound
;
7411 dw_attr_node
*at_mutable
;
7412 dw_attr_node
*at_ordering
;
7413 dw_attr_node
*at_picture_string
;
7414 dw_attr_node
*at_prototyped
;
7415 dw_attr_node
*at_small
;
7416 dw_attr_node
*at_segment
;
7417 dw_attr_node
*at_string_length
;
7418 dw_attr_node
*at_string_length_bit_size
;
7419 dw_attr_node
*at_string_length_byte_size
;
7420 dw_attr_node
*at_threads_scaled
;
7421 dw_attr_node
*at_upper_bound
;
7422 dw_attr_node
*at_use_location
;
7423 dw_attr_node
*at_use_UTF8
;
7424 dw_attr_node
*at_variable_parameter
;
7425 dw_attr_node
*at_virtuality
;
7426 dw_attr_node
*at_visibility
;
7427 dw_attr_node
*at_vtable_elem_location
;
7430 /* Collect the attributes that we will want to use for the checksum. */
7433 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
7438 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7449 attrs
->at_friend
= a
;
7451 case DW_AT_accessibility
:
7452 attrs
->at_accessibility
= a
;
7454 case DW_AT_address_class
:
7455 attrs
->at_address_class
= a
;
7457 case DW_AT_alignment
:
7458 attrs
->at_alignment
= a
;
7460 case DW_AT_allocated
:
7461 attrs
->at_allocated
= a
;
7463 case DW_AT_artificial
:
7464 attrs
->at_artificial
= a
;
7466 case DW_AT_associated
:
7467 attrs
->at_associated
= a
;
7469 case DW_AT_binary_scale
:
7470 attrs
->at_binary_scale
= a
;
7472 case DW_AT_bit_offset
:
7473 attrs
->at_bit_offset
= a
;
7475 case DW_AT_bit_size
:
7476 attrs
->at_bit_size
= a
;
7478 case DW_AT_bit_stride
:
7479 attrs
->at_bit_stride
= a
;
7481 case DW_AT_byte_size
:
7482 attrs
->at_byte_size
= a
;
7484 case DW_AT_byte_stride
:
7485 attrs
->at_byte_stride
= a
;
7487 case DW_AT_const_value
:
7488 attrs
->at_const_value
= a
;
7490 case DW_AT_containing_type
:
7491 attrs
->at_containing_type
= a
;
7494 attrs
->at_count
= a
;
7496 case DW_AT_data_location
:
7497 attrs
->at_data_location
= a
;
7499 case DW_AT_data_member_location
:
7500 attrs
->at_data_member_location
= a
;
7502 case DW_AT_decimal_scale
:
7503 attrs
->at_decimal_scale
= a
;
7505 case DW_AT_decimal_sign
:
7506 attrs
->at_decimal_sign
= a
;
7508 case DW_AT_default_value
:
7509 attrs
->at_default_value
= a
;
7511 case DW_AT_digit_count
:
7512 attrs
->at_digit_count
= a
;
7515 attrs
->at_discr
= a
;
7517 case DW_AT_discr_list
:
7518 attrs
->at_discr_list
= a
;
7520 case DW_AT_discr_value
:
7521 attrs
->at_discr_value
= a
;
7523 case DW_AT_encoding
:
7524 attrs
->at_encoding
= a
;
7526 case DW_AT_endianity
:
7527 attrs
->at_endianity
= a
;
7529 case DW_AT_explicit
:
7530 attrs
->at_explicit
= a
;
7532 case DW_AT_is_optional
:
7533 attrs
->at_is_optional
= a
;
7535 case DW_AT_location
:
7536 attrs
->at_location
= a
;
7538 case DW_AT_lower_bound
:
7539 attrs
->at_lower_bound
= a
;
7542 attrs
->at_mutable
= a
;
7544 case DW_AT_ordering
:
7545 attrs
->at_ordering
= a
;
7547 case DW_AT_picture_string
:
7548 attrs
->at_picture_string
= a
;
7550 case DW_AT_prototyped
:
7551 attrs
->at_prototyped
= a
;
7554 attrs
->at_small
= a
;
7557 attrs
->at_segment
= a
;
7559 case DW_AT_string_length
:
7560 attrs
->at_string_length
= a
;
7562 case DW_AT_string_length_bit_size
:
7563 attrs
->at_string_length_bit_size
= a
;
7565 case DW_AT_string_length_byte_size
:
7566 attrs
->at_string_length_byte_size
= a
;
7568 case DW_AT_threads_scaled
:
7569 attrs
->at_threads_scaled
= a
;
7571 case DW_AT_upper_bound
:
7572 attrs
->at_upper_bound
= a
;
7574 case DW_AT_use_location
:
7575 attrs
->at_use_location
= a
;
7577 case DW_AT_use_UTF8
:
7578 attrs
->at_use_UTF8
= a
;
7580 case DW_AT_variable_parameter
:
7581 attrs
->at_variable_parameter
= a
;
7583 case DW_AT_virtuality
:
7584 attrs
->at_virtuality
= a
;
7586 case DW_AT_visibility
:
7587 attrs
->at_visibility
= a
;
7589 case DW_AT_vtable_elem_location
:
7590 attrs
->at_vtable_elem_location
= a
;
7598 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
7601 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
7605 struct checksum_attributes attrs
;
7607 CHECKSUM_ULEB128 ('D');
7608 CHECKSUM_ULEB128 (die
->die_tag
);
7610 memset (&attrs
, 0, sizeof (attrs
));
7612 decl
= get_AT_ref (die
, DW_AT_specification
);
7614 collect_checksum_attributes (&attrs
, decl
);
7615 collect_checksum_attributes (&attrs
, die
);
7617 CHECKSUM_ATTR (attrs
.at_name
);
7618 CHECKSUM_ATTR (attrs
.at_accessibility
);
7619 CHECKSUM_ATTR (attrs
.at_address_class
);
7620 CHECKSUM_ATTR (attrs
.at_allocated
);
7621 CHECKSUM_ATTR (attrs
.at_artificial
);
7622 CHECKSUM_ATTR (attrs
.at_associated
);
7623 CHECKSUM_ATTR (attrs
.at_binary_scale
);
7624 CHECKSUM_ATTR (attrs
.at_bit_offset
);
7625 CHECKSUM_ATTR (attrs
.at_bit_size
);
7626 CHECKSUM_ATTR (attrs
.at_bit_stride
);
7627 CHECKSUM_ATTR (attrs
.at_byte_size
);
7628 CHECKSUM_ATTR (attrs
.at_byte_stride
);
7629 CHECKSUM_ATTR (attrs
.at_const_value
);
7630 CHECKSUM_ATTR (attrs
.at_containing_type
);
7631 CHECKSUM_ATTR (attrs
.at_count
);
7632 CHECKSUM_ATTR (attrs
.at_data_location
);
7633 CHECKSUM_ATTR (attrs
.at_data_member_location
);
7634 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
7635 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
7636 CHECKSUM_ATTR (attrs
.at_default_value
);
7637 CHECKSUM_ATTR (attrs
.at_digit_count
);
7638 CHECKSUM_ATTR (attrs
.at_discr
);
7639 CHECKSUM_ATTR (attrs
.at_discr_list
);
7640 CHECKSUM_ATTR (attrs
.at_discr_value
);
7641 CHECKSUM_ATTR (attrs
.at_encoding
);
7642 CHECKSUM_ATTR (attrs
.at_endianity
);
7643 CHECKSUM_ATTR (attrs
.at_explicit
);
7644 CHECKSUM_ATTR (attrs
.at_is_optional
);
7645 CHECKSUM_ATTR (attrs
.at_location
);
7646 CHECKSUM_ATTR (attrs
.at_lower_bound
);
7647 CHECKSUM_ATTR (attrs
.at_mutable
);
7648 CHECKSUM_ATTR (attrs
.at_ordering
);
7649 CHECKSUM_ATTR (attrs
.at_picture_string
);
7650 CHECKSUM_ATTR (attrs
.at_prototyped
);
7651 CHECKSUM_ATTR (attrs
.at_small
);
7652 CHECKSUM_ATTR (attrs
.at_segment
);
7653 CHECKSUM_ATTR (attrs
.at_string_length
);
7654 CHECKSUM_ATTR (attrs
.at_string_length_bit_size
);
7655 CHECKSUM_ATTR (attrs
.at_string_length_byte_size
);
7656 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
7657 CHECKSUM_ATTR (attrs
.at_upper_bound
);
7658 CHECKSUM_ATTR (attrs
.at_use_location
);
7659 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
7660 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
7661 CHECKSUM_ATTR (attrs
.at_virtuality
);
7662 CHECKSUM_ATTR (attrs
.at_visibility
);
7663 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
7664 CHECKSUM_ATTR (attrs
.at_type
);
7665 CHECKSUM_ATTR (attrs
.at_friend
);
7666 CHECKSUM_ATTR (attrs
.at_alignment
);
7668 /* Checksum the child DIEs. */
7671 dw_attr_node
*name_attr
;
7674 name_attr
= get_AT (c
, DW_AT_name
);
7675 if (is_template_instantiation (c
))
7677 /* Ignore instantiations of member type and function templates. */
7679 else if (name_attr
!= NULL
7680 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
7682 /* Use a shallow checksum for named nested types and member
7684 CHECKSUM_ULEB128 ('S');
7685 CHECKSUM_ULEB128 (c
->die_tag
);
7686 CHECKSUM_STRING (AT_string (name_attr
));
7690 /* Use a deep checksum for other children. */
7691 /* Mark this DIE so it gets processed when unmarking. */
7692 if (c
->die_mark
== 0)
7694 die_checksum_ordered (c
, ctx
, mark
);
7696 } while (c
!= die
->die_child
);
7698 CHECKSUM_ULEB128 (0);
7701 /* Add a type name and tag to a hash. */
7703 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
7705 CHECKSUM_ULEB128 (tag
);
7706 CHECKSUM_STRING (name
);
7710 #undef CHECKSUM_STRING
7711 #undef CHECKSUM_ATTR
7712 #undef CHECKSUM_LEB128
7713 #undef CHECKSUM_ULEB128
7715 /* Generate the type signature for DIE. This is computed by generating an
7716 MD5 checksum over the DIE's tag, its relevant attributes, and its
7717 children. Attributes that are references to other DIEs are processed
7718 by recursion, using the MARK field to prevent infinite recursion.
7719 If the DIE is nested inside a namespace or another type, we also
7720 need to include that context in the signature. The lower 64 bits
7721 of the resulting MD5 checksum comprise the signature. */
7724 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
7728 unsigned char checksum
[16];
7733 name
= get_AT_string (die
, DW_AT_name
);
7734 decl
= get_AT_ref (die
, DW_AT_specification
);
7735 parent
= get_die_parent (die
);
7737 /* First, compute a signature for just the type name (and its surrounding
7738 context, if any. This is stored in the type unit DIE for link-time
7739 ODR (one-definition rule) checking. */
7741 if (is_cxx () && name
!= NULL
)
7743 md5_init_ctx (&ctx
);
7745 /* Checksum the names of surrounding namespaces and structures. */
7747 checksum_die_context (parent
, &ctx
);
7749 /* Checksum the current DIE. */
7750 die_odr_checksum (die
->die_tag
, name
, &ctx
);
7751 md5_finish_ctx (&ctx
, checksum
);
7753 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
7756 /* Next, compute the complete type signature. */
7758 md5_init_ctx (&ctx
);
7760 die
->die_mark
= mark
;
7762 /* Checksum the names of surrounding namespaces and structures. */
7764 checksum_die_context (parent
, &ctx
);
7766 /* Checksum the DIE and its children. */
7767 die_checksum_ordered (die
, &ctx
, &mark
);
7768 unmark_all_dies (die
);
7769 md5_finish_ctx (&ctx
, checksum
);
7771 /* Store the signature in the type node and link the type DIE and the
7772 type node together. */
7773 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
7774 DWARF_TYPE_SIGNATURE_SIZE
);
7775 die
->comdat_type_p
= true;
7776 die
->die_id
.die_type_node
= type_node
;
7777 type_node
->type_die
= die
;
7779 /* If the DIE is a specification, link its declaration to the type node
7783 decl
->comdat_type_p
= true;
7784 decl
->die_id
.die_type_node
= type_node
;
7788 /* Do the location expressions look same? */
7790 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
7792 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
7793 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
7794 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
7797 /* Do the values look the same? */
7799 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
7801 dw_loc_descr_ref loc1
, loc2
;
7804 if (v1
->val_class
!= v2
->val_class
)
7807 switch (v1
->val_class
)
7809 case dw_val_class_const
:
7810 case dw_val_class_const_implicit
:
7811 return v1
->v
.val_int
== v2
->v
.val_int
;
7812 case dw_val_class_unsigned_const
:
7813 case dw_val_class_unsigned_const_implicit
:
7814 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
7815 case dw_val_class_const_double
:
7816 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
7817 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
7818 case dw_val_class_wide_int
:
7819 return *v1
->v
.val_wide
== *v2
->v
.val_wide
;
7820 case dw_val_class_vec
:
7821 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
7822 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
7824 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
7825 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
7828 case dw_val_class_flag
:
7829 return v1
->v
.val_flag
== v2
->v
.val_flag
;
7830 case dw_val_class_str
:
7831 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
7833 case dw_val_class_addr
:
7834 r1
= v1
->v
.val_addr
;
7835 r2
= v2
->v
.val_addr
;
7836 if (GET_CODE (r1
) != GET_CODE (r2
))
7838 return !rtx_equal_p (r1
, r2
);
7840 case dw_val_class_offset
:
7841 return v1
->v
.val_offset
== v2
->v
.val_offset
;
7843 case dw_val_class_loc
:
7844 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
7846 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
7847 if (!same_loc_p (loc1
, loc2
, mark
))
7849 return !loc1
&& !loc2
;
7851 case dw_val_class_die_ref
:
7852 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
7854 case dw_val_class_symview
:
7855 return strcmp (v1
->v
.val_symbolic_view
, v2
->v
.val_symbolic_view
) == 0;
7857 case dw_val_class_fde_ref
:
7858 case dw_val_class_vms_delta
:
7859 case dw_val_class_lbl_id
:
7860 case dw_val_class_lineptr
:
7861 case dw_val_class_macptr
:
7862 case dw_val_class_loclistsptr
:
7863 case dw_val_class_high_pc
:
7866 case dw_val_class_file
:
7867 case dw_val_class_file_implicit
:
7868 return v1
->v
.val_file
== v2
->v
.val_file
;
7870 case dw_val_class_data8
:
7871 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
7878 /* Do the attributes look the same? */
7881 same_attr_p (dw_attr_node
*at1
, dw_attr_node
*at2
, int *mark
)
7883 if (at1
->dw_attr
!= at2
->dw_attr
)
7886 /* We don't care that this was compiled with a different compiler
7887 snapshot; if the output is the same, that's what matters. */
7888 if (at1
->dw_attr
== DW_AT_producer
)
7891 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
7894 /* Do the dies look the same? */
7897 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
7903 /* To avoid infinite recursion. */
7905 return die1
->die_mark
== die2
->die_mark
;
7906 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
7908 if (die1
->die_tag
!= die2
->die_tag
)
7911 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
7914 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
7915 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
7918 c1
= die1
->die_child
;
7919 c2
= die2
->die_child
;
7928 if (!same_die_p (c1
, c2
, mark
))
7932 if (c1
== die1
->die_child
)
7934 if (c2
== die2
->die_child
)
7944 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
7945 children, and set die_symbol. */
7948 compute_comp_unit_symbol (dw_die_ref unit_die
)
7950 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
7951 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
7952 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
7955 unsigned char checksum
[16];
7958 /* Compute the checksum of the DIE, then append part of it as hex digits to
7959 the name filename of the unit. */
7961 md5_init_ctx (&ctx
);
7963 die_checksum (unit_die
, &ctx
, &mark
);
7964 unmark_all_dies (unit_die
);
7965 md5_finish_ctx (&ctx
, checksum
);
7967 /* When we this for comp_unit_die () we have a DW_AT_name that might
7968 not start with a letter but with anything valid for filenames and
7969 clean_symbol_name doesn't fix that up. Prepend 'g' if the first
7970 character is not a letter. */
7971 sprintf (name
, "%s%s.", ISALPHA (*base
) ? "" : "g", base
);
7972 clean_symbol_name (name
);
7974 p
= name
+ strlen (name
);
7975 for (i
= 0; i
< 4; i
++)
7977 sprintf (p
, "%.2x", checksum
[i
]);
7981 unit_die
->die_id
.die_symbol
= xstrdup (name
);
7984 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
7987 is_type_die (dw_die_ref die
)
7989 switch (die
->die_tag
)
7991 case DW_TAG_array_type
:
7992 case DW_TAG_class_type
:
7993 case DW_TAG_interface_type
:
7994 case DW_TAG_enumeration_type
:
7995 case DW_TAG_pointer_type
:
7996 case DW_TAG_reference_type
:
7997 case DW_TAG_rvalue_reference_type
:
7998 case DW_TAG_string_type
:
7999 case DW_TAG_structure_type
:
8000 case DW_TAG_subroutine_type
:
8001 case DW_TAG_union_type
:
8002 case DW_TAG_ptr_to_member_type
:
8003 case DW_TAG_set_type
:
8004 case DW_TAG_subrange_type
:
8005 case DW_TAG_base_type
:
8006 case DW_TAG_const_type
:
8007 case DW_TAG_file_type
:
8008 case DW_TAG_packed_type
:
8009 case DW_TAG_volatile_type
:
8010 case DW_TAG_typedef
:
8017 /* Returns true iff C is a compile-unit DIE. */
8020 is_cu_die (dw_die_ref c
)
8022 return c
&& (c
->die_tag
== DW_TAG_compile_unit
8023 || c
->die_tag
== DW_TAG_skeleton_unit
);
8026 /* Returns true iff C is a unit DIE of some sort. */
8029 is_unit_die (dw_die_ref c
)
8031 return c
&& (c
->die_tag
== DW_TAG_compile_unit
8032 || c
->die_tag
== DW_TAG_partial_unit
8033 || c
->die_tag
== DW_TAG_type_unit
8034 || c
->die_tag
== DW_TAG_skeleton_unit
);
8037 /* Returns true iff C is a namespace DIE. */
8040 is_namespace_die (dw_die_ref c
)
8042 return c
&& c
->die_tag
== DW_TAG_namespace
;
8045 /* Return non-zero if this DIE is a template parameter. */
8048 is_template_parameter (dw_die_ref die
)
8050 switch (die
->die_tag
)
8052 case DW_TAG_template_type_param
:
8053 case DW_TAG_template_value_param
:
8054 case DW_TAG_GNU_template_template_param
:
8055 case DW_TAG_GNU_template_parameter_pack
:
8062 /* Return non-zero if this DIE represents a template instantiation. */
8065 is_template_instantiation (dw_die_ref die
)
8069 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
8071 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
8076 gen_internal_sym (const char *prefix
)
8078 char buf
[MAX_ARTIFICIAL_LABEL_BYTES
];
8080 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
8081 return xstrdup (buf
);
8084 /* Return non-zero if this DIE is a declaration. */
8087 is_declaration_die (dw_die_ref die
)
8092 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8093 if (a
->dw_attr
== DW_AT_declaration
)
8099 /* Return non-zero if this DIE is nested inside a subprogram. */
8102 is_nested_in_subprogram (dw_die_ref die
)
8104 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
8108 return local_scope_p (decl
);
8111 /* Return non-zero if this DIE contains a defining declaration of a
8115 contains_subprogram_definition (dw_die_ref die
)
8119 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
8121 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
8125 /* Return non-zero if this is a type DIE that should be moved to a
8126 COMDAT .debug_types section or .debug_info section with DW_UT_*type
8130 should_move_die_to_comdat (dw_die_ref die
)
8132 switch (die
->die_tag
)
8134 case DW_TAG_class_type
:
8135 case DW_TAG_structure_type
:
8136 case DW_TAG_enumeration_type
:
8137 case DW_TAG_union_type
:
8138 /* Don't move declarations, inlined instances, types nested in a
8139 subprogram, or types that contain subprogram definitions. */
8140 if (is_declaration_die (die
)
8141 || get_AT (die
, DW_AT_abstract_origin
)
8142 || is_nested_in_subprogram (die
)
8143 || contains_subprogram_definition (die
))
8146 case DW_TAG_array_type
:
8147 case DW_TAG_interface_type
:
8148 case DW_TAG_pointer_type
:
8149 case DW_TAG_reference_type
:
8150 case DW_TAG_rvalue_reference_type
:
8151 case DW_TAG_string_type
:
8152 case DW_TAG_subroutine_type
:
8153 case DW_TAG_ptr_to_member_type
:
8154 case DW_TAG_set_type
:
8155 case DW_TAG_subrange_type
:
8156 case DW_TAG_base_type
:
8157 case DW_TAG_const_type
:
8158 case DW_TAG_file_type
:
8159 case DW_TAG_packed_type
:
8160 case DW_TAG_volatile_type
:
8161 case DW_TAG_typedef
:
8167 /* Make a clone of DIE. */
8170 clone_die (dw_die_ref die
)
8172 dw_die_ref clone
= new_die_raw (die
->die_tag
);
8176 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8177 add_dwarf_attr (clone
, a
);
8182 /* Make a clone of the tree rooted at DIE. */
8185 clone_tree (dw_die_ref die
)
8188 dw_die_ref clone
= clone_die (die
);
8190 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
8195 /* Make a clone of DIE as a declaration. */
8198 clone_as_declaration (dw_die_ref die
)
8205 /* If the DIE is already a declaration, just clone it. */
8206 if (is_declaration_die (die
))
8207 return clone_die (die
);
8209 /* If the DIE is a specification, just clone its declaration DIE. */
8210 decl
= get_AT_ref (die
, DW_AT_specification
);
8213 clone
= clone_die (decl
);
8214 if (die
->comdat_type_p
)
8215 add_AT_die_ref (clone
, DW_AT_signature
, die
);
8219 clone
= new_die_raw (die
->die_tag
);
8221 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8223 /* We don't want to copy over all attributes.
8224 For example we don't want DW_AT_byte_size because otherwise we will no
8225 longer have a declaration and GDB will treat it as a definition. */
8229 case DW_AT_abstract_origin
:
8230 case DW_AT_artificial
:
8231 case DW_AT_containing_type
:
8232 case DW_AT_external
:
8235 case DW_AT_virtuality
:
8236 case DW_AT_linkage_name
:
8237 case DW_AT_MIPS_linkage_name
:
8238 add_dwarf_attr (clone
, a
);
8240 case DW_AT_byte_size
:
8241 case DW_AT_alignment
:
8247 if (die
->comdat_type_p
)
8248 add_AT_die_ref (clone
, DW_AT_signature
, die
);
8250 add_AT_flag (clone
, DW_AT_declaration
, 1);
8255 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
8257 struct decl_table_entry
8263 /* Helpers to manipulate hash table of copied declarations. */
8265 /* Hashtable helpers. */
8267 struct decl_table_entry_hasher
: free_ptr_hash
<decl_table_entry
>
8269 typedef die_struct
*compare_type
;
8270 static inline hashval_t
hash (const decl_table_entry
*);
8271 static inline bool equal (const decl_table_entry
*, const die_struct
*);
8275 decl_table_entry_hasher::hash (const decl_table_entry
*entry
)
8277 return htab_hash_pointer (entry
->orig
);
8281 decl_table_entry_hasher::equal (const decl_table_entry
*entry1
,
8282 const die_struct
*entry2
)
8284 return entry1
->orig
== entry2
;
8287 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
8289 /* Copy DIE and its ancestors, up to, but not including, the compile unit
8290 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
8291 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
8292 to check if the ancestor has already been copied into UNIT. */
8295 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
,
8296 decl_hash_type
*decl_table
)
8298 dw_die_ref parent
= die
->die_parent
;
8299 dw_die_ref new_parent
= unit
;
8301 decl_table_entry
**slot
= NULL
;
8302 struct decl_table_entry
*entry
= NULL
;
8304 /* If DIE refers to a stub unfold that so we get the appropriate
8305 DIE registered as orig in decl_table. */
8306 if (dw_die_ref c
= get_AT_ref (die
, DW_AT_signature
))
8311 /* Check if the entry has already been copied to UNIT. */
8312 slot
= decl_table
->find_slot_with_hash (die
, htab_hash_pointer (die
),
8314 if (*slot
!= HTAB_EMPTY_ENTRY
)
8320 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
8321 entry
= XCNEW (struct decl_table_entry
);
8329 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
8332 if (!is_unit_die (parent
))
8333 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
8336 copy
= clone_as_declaration (die
);
8337 add_child_die (new_parent
, copy
);
8341 /* Record the pointer to the copy. */
8347 /* Copy the declaration context to the new type unit DIE. This includes
8348 any surrounding namespace or type declarations. If the DIE has an
8349 AT_specification attribute, it also includes attributes and children
8350 attached to the specification, and returns a pointer to the original
8351 parent of the declaration DIE. Returns NULL otherwise. */
8354 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
8357 dw_die_ref new_decl
;
8358 dw_die_ref orig_parent
= NULL
;
8360 decl
= get_AT_ref (die
, DW_AT_specification
);
8369 /* The original DIE will be changed to a declaration, and must
8370 be moved to be a child of the original declaration DIE. */
8371 orig_parent
= decl
->die_parent
;
8373 /* Copy the type node pointer from the new DIE to the original
8374 declaration DIE so we can forward references later. */
8375 decl
->comdat_type_p
= true;
8376 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
8378 remove_AT (die
, DW_AT_specification
);
8380 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
8382 if (a
->dw_attr
!= DW_AT_name
8383 && a
->dw_attr
!= DW_AT_declaration
8384 && a
->dw_attr
!= DW_AT_external
)
8385 add_dwarf_attr (die
, a
);
8388 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
8391 if (decl
->die_parent
!= NULL
8392 && !is_unit_die (decl
->die_parent
))
8394 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
8395 if (new_decl
!= NULL
)
8397 remove_AT (new_decl
, DW_AT_signature
);
8398 add_AT_specification (die
, new_decl
);
8405 /* Generate the skeleton ancestor tree for the given NODE, then clone
8406 the DIE and add the clone into the tree. */
8409 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
8411 if (node
->new_die
!= NULL
)
8414 node
->new_die
= clone_as_declaration (node
->old_die
);
8416 if (node
->parent
!= NULL
)
8418 generate_skeleton_ancestor_tree (node
->parent
);
8419 add_child_die (node
->parent
->new_die
, node
->new_die
);
8423 /* Generate a skeleton tree of DIEs containing any declarations that are
8424 found in the original tree. We traverse the tree looking for declaration
8425 DIEs, and construct the skeleton from the bottom up whenever we find one. */
8428 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
8430 skeleton_chain_node node
;
8433 dw_die_ref prev
= NULL
;
8434 dw_die_ref next
= NULL
;
8436 node
.parent
= parent
;
8438 first
= c
= parent
->old_die
->die_child
;
8442 if (prev
== NULL
|| prev
->die_sib
== c
)
8445 next
= (c
== first
? NULL
: c
->die_sib
);
8447 node
.new_die
= NULL
;
8448 if (is_declaration_die (c
))
8450 if (is_template_instantiation (c
))
8452 /* Instantiated templates do not need to be cloned into the
8453 type unit. Just move the DIE and its children back to
8454 the skeleton tree (in the main CU). */
8455 remove_child_with_prev (c
, prev
);
8456 add_child_die (parent
->new_die
, c
);
8459 else if (c
->comdat_type_p
)
8461 /* This is the skeleton of earlier break_out_comdat_types
8462 type. Clone the existing DIE, but keep the children
8463 under the original (which is in the main CU). */
8464 dw_die_ref clone
= clone_die (c
);
8466 replace_child (c
, clone
, prev
);
8467 generate_skeleton_ancestor_tree (parent
);
8468 add_child_die (parent
->new_die
, c
);
8474 /* Clone the existing DIE, move the original to the skeleton
8475 tree (which is in the main CU), and put the clone, with
8476 all the original's children, where the original came from
8477 (which is about to be moved to the type unit). */
8478 dw_die_ref clone
= clone_die (c
);
8479 move_all_children (c
, clone
);
8481 /* If the original has a DW_AT_object_pointer attribute,
8482 it would now point to a child DIE just moved to the
8483 cloned tree, so we need to remove that attribute from
8485 remove_AT (c
, DW_AT_object_pointer
);
8487 replace_child (c
, clone
, prev
);
8488 generate_skeleton_ancestor_tree (parent
);
8489 add_child_die (parent
->new_die
, c
);
8490 node
.old_die
= clone
;
8495 generate_skeleton_bottom_up (&node
);
8496 } while (next
!= NULL
);
8499 /* Wrapper function for generate_skeleton_bottom_up. */
8502 generate_skeleton (dw_die_ref die
)
8504 skeleton_chain_node node
;
8507 node
.new_die
= NULL
;
8510 /* If this type definition is nested inside another type,
8511 and is not an instantiation of a template, always leave
8512 at least a declaration in its place. */
8513 if (die
->die_parent
!= NULL
8514 && is_type_die (die
->die_parent
)
8515 && !is_template_instantiation (die
))
8516 node
.new_die
= clone_as_declaration (die
);
8518 generate_skeleton_bottom_up (&node
);
8519 return node
.new_die
;
8522 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
8523 declaration. The original DIE is moved to a new compile unit so that
8524 existing references to it follow it to the new location. If any of the
8525 original DIE's descendants is a declaration, we need to replace the
8526 original DIE with a skeleton tree and move the declarations back into the
8530 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
8533 dw_die_ref skeleton
, orig_parent
;
8535 /* Copy the declaration context to the type unit DIE. If the returned
8536 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
8538 orig_parent
= copy_declaration_context (unit
, child
);
8540 skeleton
= generate_skeleton (child
);
8541 if (skeleton
== NULL
)
8542 remove_child_with_prev (child
, prev
);
8545 skeleton
->comdat_type_p
= true;
8546 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
8548 /* If the original DIE was a specification, we need to put
8549 the skeleton under the parent DIE of the declaration.
8550 This leaves the original declaration in the tree, but
8551 it will be pruned later since there are no longer any
8552 references to it. */
8553 if (orig_parent
!= NULL
)
8555 remove_child_with_prev (child
, prev
);
8556 add_child_die (orig_parent
, skeleton
);
8559 replace_child (child
, skeleton
, prev
);
8566 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
8567 comdat_type_node
*type_node
,
8568 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
);
8570 /* Helper for copy_dwarf_procs_ref_in_dies. Make a copy of the DIE DWARF
8571 procedure, put it under TYPE_NODE and return the copy. Continue looking for
8572 DWARF procedure references in the DW_AT_location attribute. */
8575 copy_dwarf_procedure (dw_die_ref die
,
8576 comdat_type_node
*type_node
,
8577 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8579 gcc_assert (die
->die_tag
== DW_TAG_dwarf_procedure
);
8581 /* DWARF procedures are not supposed to have children... */
8582 gcc_assert (die
->die_child
== NULL
);
8584 /* ... and they are supposed to have only one attribute: DW_AT_location. */
8585 gcc_assert (vec_safe_length (die
->die_attr
) == 1
8586 && ((*die
->die_attr
)[0].dw_attr
== DW_AT_location
));
8588 /* Do not copy more than once DWARF procedures. */
8590 dw_die_ref
&die_copy
= copied_dwarf_procs
.get_or_insert (die
, &existed
);
8594 die_copy
= clone_die (die
);
8595 add_child_die (type_node
->root_die
, die_copy
);
8596 copy_dwarf_procs_ref_in_attrs (die_copy
, type_node
, copied_dwarf_procs
);
8600 /* Helper for copy_dwarf_procs_ref_in_dies. Look for references to DWARF
8601 procedures in DIE's attributes. */
8604 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
8605 comdat_type_node
*type_node
,
8606 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8611 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, i
, a
)
8613 dw_loc_descr_ref loc
;
8615 if (a
->dw_attr_val
.val_class
!= dw_val_class_loc
)
8618 for (loc
= a
->dw_attr_val
.v
.val_loc
; loc
!= NULL
; loc
= loc
->dw_loc_next
)
8620 switch (loc
->dw_loc_opc
)
8624 case DW_OP_call_ref
:
8625 gcc_assert (loc
->dw_loc_oprnd1
.val_class
8626 == dw_val_class_die_ref
);
8627 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
8628 = copy_dwarf_procedure (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
,
8630 copied_dwarf_procs
);
8639 /* Copy DWARF procedures that are referenced by the DIE tree to TREE_NODE and
8640 rewrite references to point to the copies.
8642 References are looked for in DIE's attributes and recursively in all its
8643 children attributes that are location descriptions. COPIED_DWARF_PROCS is a
8644 mapping from old DWARF procedures to their copy. It is used not to copy
8645 twice the same DWARF procedure under TYPE_NODE. */
8648 copy_dwarf_procs_ref_in_dies (dw_die_ref die
,
8649 comdat_type_node
*type_node
,
8650 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8654 copy_dwarf_procs_ref_in_attrs (die
, type_node
, copied_dwarf_procs
);
8655 FOR_EACH_CHILD (die
, c
, copy_dwarf_procs_ref_in_dies (c
,
8657 copied_dwarf_procs
));
8660 /* Traverse the DIE and set up additional .debug_types or .debug_info
8661 DW_UT_*type sections for each type worthy of being placed in a COMDAT
8665 break_out_comdat_types (dw_die_ref die
)
8669 dw_die_ref prev
= NULL
;
8670 dw_die_ref next
= NULL
;
8671 dw_die_ref unit
= NULL
;
8673 first
= c
= die
->die_child
;
8677 if (prev
== NULL
|| prev
->die_sib
== c
)
8680 next
= (c
== first
? NULL
: c
->die_sib
);
8681 if (should_move_die_to_comdat (c
))
8683 dw_die_ref replacement
;
8684 comdat_type_node
*type_node
;
8686 /* Break out nested types into their own type units. */
8687 break_out_comdat_types (c
);
8689 /* Create a new type unit DIE as the root for the new tree. */
8690 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8691 add_AT_unsigned (unit
, DW_AT_language
,
8692 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
8694 /* Add the new unit's type DIE into the comdat type list. */
8695 type_node
= ggc_cleared_alloc
<comdat_type_node
> ();
8696 type_node
->root_die
= unit
;
8697 type_node
->next
= comdat_type_list
;
8698 comdat_type_list
= type_node
;
8700 /* Generate the type signature. */
8701 generate_type_signature (c
, type_node
);
8703 /* Copy the declaration context, attributes, and children of the
8704 declaration into the new type unit DIE, then remove this DIE
8705 from the main CU (or replace it with a skeleton if necessary). */
8706 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
8707 type_node
->skeleton_die
= replacement
;
8709 /* Add the DIE to the new compunit. */
8710 add_child_die (unit
, c
);
8712 /* Types can reference DWARF procedures for type size or data location
8713 expressions. Calls in DWARF expressions cannot target procedures
8714 that are not in the same section. So we must copy DWARF procedures
8715 along with this type and then rewrite references to them. */
8716 hash_map
<dw_die_ref
, dw_die_ref
> copied_dwarf_procs
;
8717 copy_dwarf_procs_ref_in_dies (c
, type_node
, copied_dwarf_procs
);
8719 if (replacement
!= NULL
)
8722 else if (c
->die_tag
== DW_TAG_namespace
8723 || c
->die_tag
== DW_TAG_class_type
8724 || c
->die_tag
== DW_TAG_structure_type
8725 || c
->die_tag
== DW_TAG_union_type
)
8727 /* Look for nested types that can be broken out. */
8728 break_out_comdat_types (c
);
8730 } while (next
!= NULL
);
8733 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
8734 Enter all the cloned children into the hash table decl_table. */
8737 clone_tree_partial (dw_die_ref die
, decl_hash_type
*decl_table
)
8741 struct decl_table_entry
*entry
;
8742 decl_table_entry
**slot
;
8744 if (die
->die_tag
== DW_TAG_subprogram
)
8745 clone
= clone_as_declaration (die
);
8747 clone
= clone_die (die
);
8749 slot
= decl_table
->find_slot_with_hash (die
,
8750 htab_hash_pointer (die
), INSERT
);
8752 /* Assert that DIE isn't in the hash table yet. If it would be there
8753 before, the ancestors would be necessarily there as well, therefore
8754 clone_tree_partial wouldn't be called. */
8755 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
8757 entry
= XCNEW (struct decl_table_entry
);
8759 entry
->copy
= clone
;
8762 if (die
->die_tag
!= DW_TAG_subprogram
)
8763 FOR_EACH_CHILD (die
, c
,
8764 add_child_die (clone
, clone_tree_partial (c
, decl_table
)));
8769 /* Walk the DIE and its children, looking for references to incomplete
8770 or trivial types that are unmarked (i.e., that are not in the current
8774 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type
*decl_table
)
8780 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8782 if (AT_class (a
) == dw_val_class_die_ref
)
8784 dw_die_ref targ
= AT_ref (a
);
8785 decl_table_entry
**slot
;
8786 struct decl_table_entry
*entry
;
8788 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
8791 slot
= decl_table
->find_slot_with_hash (targ
,
8792 htab_hash_pointer (targ
),
8795 if (*slot
!= HTAB_EMPTY_ENTRY
)
8797 /* TARG has already been copied, so we just need to
8798 modify the reference to point to the copy. */
8800 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
8804 dw_die_ref parent
= unit
;
8805 dw_die_ref copy
= clone_die (targ
);
8807 /* Record in DECL_TABLE that TARG has been copied.
8808 Need to do this now, before the recursive call,
8809 because DECL_TABLE may be expanded and SLOT
8810 would no longer be a valid pointer. */
8811 entry
= XCNEW (struct decl_table_entry
);
8816 /* If TARG is not a declaration DIE, we need to copy its
8818 if (!is_declaration_die (targ
))
8822 add_child_die (copy
,
8823 clone_tree_partial (c
, decl_table
)));
8826 /* Make sure the cloned tree is marked as part of the
8830 /* If TARG has surrounding context, copy its ancestor tree
8831 into the new type unit. */
8832 if (targ
->die_parent
!= NULL
8833 && !is_unit_die (targ
->die_parent
))
8834 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
8837 add_child_die (parent
, copy
);
8838 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
8840 /* Make sure the newly-copied DIE is walked. If it was
8841 installed in a previously-added context, it won't
8842 get visited otherwise. */
8845 /* Find the highest point of the newly-added tree,
8846 mark each node along the way, and walk from there. */
8847 parent
->die_mark
= 1;
8848 while (parent
->die_parent
8849 && parent
->die_parent
->die_mark
== 0)
8851 parent
= parent
->die_parent
;
8852 parent
->die_mark
= 1;
8854 copy_decls_walk (unit
, parent
, decl_table
);
8860 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
8863 /* Collect skeleton dies in DIE created by break_out_comdat_types already
8864 and record them in DECL_TABLE. */
8867 collect_skeleton_dies (dw_die_ref die
, decl_hash_type
*decl_table
)
8871 if (dw_attr_node
*a
= get_AT (die
, DW_AT_signature
))
8873 dw_die_ref targ
= AT_ref (a
);
8874 gcc_assert (targ
->die_mark
== 0 && targ
->comdat_type_p
);
8875 decl_table_entry
**slot
8876 = decl_table
->find_slot_with_hash (targ
,
8877 htab_hash_pointer (targ
),
8879 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
8880 /* Record in DECL_TABLE that TARG has been already copied
8881 by remove_child_or_replace_with_skeleton. */
8882 decl_table_entry
*entry
= XCNEW (struct decl_table_entry
);
8887 FOR_EACH_CHILD (die
, c
, collect_skeleton_dies (c
, decl_table
));
8890 /* Copy declarations for "unworthy" types into the new comdat section.
8891 Incomplete types, modified types, and certain other types aren't broken
8892 out into comdat sections of their own, so they don't have a signature,
8893 and we need to copy the declaration into the same section so that we
8894 don't have an external reference. */
8897 copy_decls_for_unworthy_types (dw_die_ref unit
)
8900 decl_hash_type
decl_table (10);
8901 collect_skeleton_dies (unit
, &decl_table
);
8902 copy_decls_walk (unit
, unit
, &decl_table
);
8906 /* Traverse the DIE and add a sibling attribute if it may have the
8907 effect of speeding up access to siblings. To save some space,
8908 avoid generating sibling attributes for DIE's without children. */
8911 add_sibling_attributes (dw_die_ref die
)
8915 if (! die
->die_child
)
8918 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
8919 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
8921 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
8924 /* Output all location lists for the DIE and its children. */
8927 output_location_lists (dw_die_ref die
)
8933 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8934 if (AT_class (a
) == dw_val_class_loc_list
)
8935 output_loc_list (AT_loc_list (a
));
8937 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
8940 /* During assign_location_list_indexes and output_loclists_offset the
8941 current index, after it the number of assigned indexes (i.e. how
8942 large the .debug_loclists* offset table should be). */
8943 static unsigned int loc_list_idx
;
8945 /* Output all location list offsets for the DIE and its children. */
8948 output_loclists_offsets (dw_die_ref die
)
8954 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8955 if (AT_class (a
) == dw_val_class_loc_list
)
8957 dw_loc_list_ref l
= AT_loc_list (a
);
8958 if (l
->offset_emitted
)
8960 dw2_asm_output_delta (dwarf_offset_size
, l
->ll_symbol
,
8961 loc_section_label
, NULL
);
8962 gcc_assert (l
->hash
== loc_list_idx
);
8964 l
->offset_emitted
= true;
8967 FOR_EACH_CHILD (die
, c
, output_loclists_offsets (c
));
8970 /* Recursively set indexes of location lists. */
8973 assign_location_list_indexes (dw_die_ref die
)
8979 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8980 if (AT_class (a
) == dw_val_class_loc_list
)
8982 dw_loc_list_ref list
= AT_loc_list (a
);
8983 if (!list
->num_assigned
)
8985 list
->num_assigned
= true;
8986 list
->hash
= loc_list_idx
++;
8990 FOR_EACH_CHILD (die
, c
, assign_location_list_indexes (c
));
8993 /* We want to limit the number of external references, because they are
8994 larger than local references: a relocation takes multiple words, and
8995 even a sig8 reference is always eight bytes, whereas a local reference
8996 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
8997 So if we encounter multiple external references to the same type DIE, we
8998 make a local typedef stub for it and redirect all references there.
9000 This is the element of the hash table for keeping track of these
9010 /* Hashtable helpers. */
9012 struct external_ref_hasher
: free_ptr_hash
<external_ref
>
9014 static inline hashval_t
hash (const external_ref
*);
9015 static inline bool equal (const external_ref
*, const external_ref
*);
9019 external_ref_hasher::hash (const external_ref
*r
)
9021 dw_die_ref die
= r
->type
;
9024 /* We can't use the address of the DIE for hashing, because
9025 that will make the order of the stub DIEs non-deterministic. */
9026 if (! die
->comdat_type_p
)
9027 /* We have a symbol; use it to compute a hash. */
9028 h
= htab_hash_string (die
->die_id
.die_symbol
);
9031 /* We have a type signature; use a subset of the bits as the hash.
9032 The 8-byte signature is at least as large as hashval_t. */
9033 comdat_type_node
*type_node
= die
->die_id
.die_type_node
;
9034 memcpy (&h
, type_node
->signature
, sizeof (h
));
9040 external_ref_hasher::equal (const external_ref
*r1
, const external_ref
*r2
)
9042 return r1
->type
== r2
->type
;
9045 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
9047 /* Return a pointer to the external_ref for references to DIE. */
9049 static struct external_ref
*
9050 lookup_external_ref (external_ref_hash_type
*map
, dw_die_ref die
)
9052 struct external_ref ref
, *ref_p
;
9053 external_ref
**slot
;
9056 slot
= map
->find_slot (&ref
, INSERT
);
9057 if (*slot
!= HTAB_EMPTY_ENTRY
)
9060 ref_p
= XCNEW (struct external_ref
);
9066 /* Subroutine of optimize_external_refs, below.
9068 If we see a type skeleton, record it as our stub. If we see external
9069 references, remember how many we've seen. */
9072 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type
*map
)
9077 struct external_ref
*ref_p
;
9079 if (is_type_die (die
)
9080 && (c
= get_AT_ref (die
, DW_AT_signature
)))
9082 /* This is a local skeleton; use it for local references. */
9083 ref_p
= lookup_external_ref (map
, c
);
9087 /* Scan the DIE references, and remember any that refer to DIEs from
9088 other CUs (i.e. those which are not marked). */
9089 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9090 if (AT_class (a
) == dw_val_class_die_ref
9091 && (c
= AT_ref (a
))->die_mark
== 0
9094 ref_p
= lookup_external_ref (map
, c
);
9098 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
9101 /* htab_traverse callback function for optimize_external_refs, below. SLOT
9102 points to an external_ref, DATA is the CU we're processing. If we don't
9103 already have a local stub, and we have multiple refs, build a stub. */
9106 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
9108 struct external_ref
*ref_p
= *slot
;
9110 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
9112 /* We have multiple references to this type, so build a small stub.
9113 Both of these forms are a bit dodgy from the perspective of the
9114 DWARF standard, since technically they should have names. */
9115 dw_die_ref cu
= data
;
9116 dw_die_ref type
= ref_p
->type
;
9117 dw_die_ref stub
= NULL
;
9119 if (type
->comdat_type_p
)
9121 /* If we refer to this type via sig8, use AT_signature. */
9122 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
9123 add_AT_die_ref (stub
, DW_AT_signature
, type
);
9127 /* Otherwise, use a typedef with no name. */
9128 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
9129 add_AT_die_ref (stub
, DW_AT_type
, type
);
9138 /* DIE is a unit; look through all the DIE references to see if there are
9139 any external references to types, and if so, create local stubs for
9140 them which will be applied in build_abbrev_table. This is useful because
9141 references to local DIEs are smaller. */
9143 static external_ref_hash_type
*
9144 optimize_external_refs (dw_die_ref die
)
9146 external_ref_hash_type
*map
= new external_ref_hash_type (10);
9147 optimize_external_refs_1 (die
, map
);
9148 map
->traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
9152 /* The following 3 variables are temporaries that are computed only during the
9153 build_abbrev_table call and used and released during the following
9154 optimize_abbrev_table call. */
9156 /* First abbrev_id that can be optimized based on usage. */
9157 static unsigned int abbrev_opt_start
;
9159 /* Maximum abbrev_id of a base type plus one (we can't optimize DIEs with
9160 abbrev_id smaller than this, because they must be already sized
9161 during build_abbrev_table). */
9162 static unsigned int abbrev_opt_base_type_end
;
9164 /* Vector of usage counts during build_abbrev_table. Indexed by
9165 abbrev_id - abbrev_opt_start. */
9166 static vec
<unsigned int> abbrev_usage_count
;
9168 /* Vector of all DIEs added with die_abbrev >= abbrev_opt_start. */
9169 static vec
<dw_die_ref
> sorted_abbrev_dies
;
9171 /* The format of each DIE (and its attribute value pairs) is encoded in an
9172 abbreviation table. This routine builds the abbreviation table and assigns
9173 a unique abbreviation id for each abbreviation entry. The children of each
9174 die are visited recursively. */
9177 build_abbrev_table (dw_die_ref die
, external_ref_hash_type
*extern_map
)
9179 unsigned int abbrev_id
= 0;
9185 /* Scan the DIE references, and replace any that refer to
9186 DIEs from other CUs (i.e. those which are not marked) with
9187 the local stubs we built in optimize_external_refs. */
9188 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9189 if (AT_class (a
) == dw_val_class_die_ref
9190 && (c
= AT_ref (a
))->die_mark
== 0)
9192 struct external_ref
*ref_p
;
9193 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
9196 && (ref_p
= lookup_external_ref (extern_map
, c
))
9197 && ref_p
->stub
&& ref_p
->stub
!= die
)
9199 gcc_assert (a
->dw_attr
!= DW_AT_signature
);
9200 change_AT_die_ref (a
, ref_p
->stub
);
9203 /* We aren't changing this reference, so mark it external. */
9204 set_AT_ref_external (a
, 1);
9207 FOR_EACH_VEC_SAFE_ELT (abbrev_die_table
, abbrev_id
, abbrev
)
9209 dw_attr_node
*die_a
, *abbrev_a
;
9215 if (abbrev
->die_tag
!= die
->die_tag
)
9217 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
9220 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
9223 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
9225 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
9226 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
9227 || (value_format (abbrev_a
) != value_format (die_a
)))
9237 if (abbrev_id
>= vec_safe_length (abbrev_die_table
))
9239 vec_safe_push (abbrev_die_table
, die
);
9240 if (abbrev_opt_start
)
9241 abbrev_usage_count
.safe_push (0);
9243 if (abbrev_opt_start
&& abbrev_id
>= abbrev_opt_start
)
9245 abbrev_usage_count
[abbrev_id
- abbrev_opt_start
]++;
9246 sorted_abbrev_dies
.safe_push (die
);
9249 die
->die_abbrev
= abbrev_id
;
9250 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
9253 /* Callback function for sorted_abbrev_dies vector sorting. We sort
9254 by die_abbrev's usage count, from the most commonly used
9255 abbreviation to the least. */
9258 die_abbrev_cmp (const void *p1
, const void *p2
)
9260 dw_die_ref die1
= *(const dw_die_ref
*) p1
;
9261 dw_die_ref die2
= *(const dw_die_ref
*) p2
;
9263 gcc_checking_assert (die1
->die_abbrev
>= abbrev_opt_start
);
9264 gcc_checking_assert (die2
->die_abbrev
>= abbrev_opt_start
);
9266 if (die1
->die_abbrev
>= abbrev_opt_base_type_end
9267 && die2
->die_abbrev
>= abbrev_opt_base_type_end
)
9269 if (abbrev_usage_count
[die1
->die_abbrev
- abbrev_opt_start
]
9270 > abbrev_usage_count
[die2
->die_abbrev
- abbrev_opt_start
])
9272 if (abbrev_usage_count
[die1
->die_abbrev
- abbrev_opt_start
]
9273 < abbrev_usage_count
[die2
->die_abbrev
- abbrev_opt_start
])
9277 /* Stabilize the sort. */
9278 if (die1
->die_abbrev
< die2
->die_abbrev
)
9280 if (die1
->die_abbrev
> die2
->die_abbrev
)
9286 /* Convert dw_val_class_const and dw_val_class_unsigned_const class attributes
9287 of DIEs in between sorted_abbrev_dies[first_id] and abbrev_dies[end_id - 1]
9288 into dw_val_class_const_implicit or
9289 dw_val_class_unsigned_const_implicit. */
9292 optimize_implicit_const (unsigned int first_id
, unsigned int end
,
9293 vec
<bool> &implicit_consts
)
9295 /* It never makes sense if there is just one DIE using the abbreviation. */
9296 if (end
< first_id
+ 2)
9301 dw_die_ref die
= sorted_abbrev_dies
[first_id
];
9302 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9303 if (implicit_consts
[ix
])
9305 enum dw_val_class new_class
= dw_val_class_none
;
9306 switch (AT_class (a
))
9308 case dw_val_class_unsigned_const
:
9309 if ((HOST_WIDE_INT
) AT_unsigned (a
) < 0)
9312 /* The .debug_abbrev section will grow by
9313 size_of_sleb128 (AT_unsigned (a)) and we avoid the constants
9314 in all the DIEs using that abbreviation. */
9315 if (constant_size (AT_unsigned (a
)) * (end
- first_id
)
9316 <= (unsigned) size_of_sleb128 (AT_unsigned (a
)))
9319 new_class
= dw_val_class_unsigned_const_implicit
;
9322 case dw_val_class_const
:
9323 new_class
= dw_val_class_const_implicit
;
9326 case dw_val_class_file
:
9327 new_class
= dw_val_class_file_implicit
;
9333 for (i
= first_id
; i
< end
; i
++)
9334 (*sorted_abbrev_dies
[i
]->die_attr
)[ix
].dw_attr_val
.val_class
9339 /* Attempt to optimize abbreviation table from abbrev_opt_start
9340 abbreviation above. */
9343 optimize_abbrev_table (void)
9345 if (abbrev_opt_start
9346 && vec_safe_length (abbrev_die_table
) > abbrev_opt_start
9347 && (dwarf_version
>= 5 || vec_safe_length (abbrev_die_table
) > 127))
9349 auto_vec
<bool, 32> implicit_consts
;
9350 sorted_abbrev_dies
.qsort (die_abbrev_cmp
);
9352 unsigned int abbrev_id
= abbrev_opt_start
- 1;
9353 unsigned int first_id
= ~0U;
9354 unsigned int last_abbrev_id
= 0;
9357 if (abbrev_opt_base_type_end
> abbrev_opt_start
)
9358 abbrev_id
= abbrev_opt_base_type_end
- 1;
9359 /* Reassign abbreviation ids from abbrev_opt_start above, so that
9360 most commonly used abbreviations come first. */
9361 FOR_EACH_VEC_ELT (sorted_abbrev_dies
, i
, die
)
9366 /* If calc_base_type_die_sizes has been called, the CU and
9367 base types after it can't be optimized, because we've already
9368 calculated their DIE offsets. We've sorted them first. */
9369 if (die
->die_abbrev
< abbrev_opt_base_type_end
)
9371 if (die
->die_abbrev
!= last_abbrev_id
)
9373 last_abbrev_id
= die
->die_abbrev
;
9374 if (dwarf_version
>= 5 && first_id
!= ~0U)
9375 optimize_implicit_const (first_id
, i
, implicit_consts
);
9377 (*abbrev_die_table
)[abbrev_id
] = die
;
9378 if (dwarf_version
>= 5)
9381 implicit_consts
.truncate (0);
9383 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9384 switch (AT_class (a
))
9386 case dw_val_class_const
:
9387 case dw_val_class_unsigned_const
:
9388 case dw_val_class_file
:
9389 implicit_consts
.safe_push (true);
9392 implicit_consts
.safe_push (false);
9397 else if (dwarf_version
>= 5)
9399 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9400 if (!implicit_consts
[ix
])
9404 dw_attr_node
*other_a
9405 = &(*(*abbrev_die_table
)[abbrev_id
]->die_attr
)[ix
];
9406 if (!dw_val_equal_p (&a
->dw_attr_val
,
9407 &other_a
->dw_attr_val
))
9408 implicit_consts
[ix
] = false;
9411 die
->die_abbrev
= abbrev_id
;
9413 gcc_assert (abbrev_id
== vec_safe_length (abbrev_die_table
) - 1);
9414 if (dwarf_version
>= 5 && first_id
!= ~0U)
9415 optimize_implicit_const (first_id
, i
, implicit_consts
);
9418 abbrev_opt_start
= 0;
9419 abbrev_opt_base_type_end
= 0;
9420 abbrev_usage_count
.release ();
9421 sorted_abbrev_dies
.release ();
9424 /* Return the power-of-two number of bytes necessary to represent VALUE. */
9427 constant_size (unsigned HOST_WIDE_INT value
)
9434 log
= floor_log2 (value
);
9437 log
= 1 << (floor_log2 (log
) + 1);
9442 /* Return the size of a DIE as it is represented in the
9443 .debug_info section. */
9445 static unsigned long
9446 size_of_die (dw_die_ref die
)
9448 unsigned long size
= 0;
9451 enum dwarf_form form
;
9453 size
+= size_of_uleb128 (die
->die_abbrev
);
9454 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9456 switch (AT_class (a
))
9458 case dw_val_class_addr
:
9459 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
9461 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
9462 size
+= size_of_uleb128 (AT_index (a
));
9465 size
+= DWARF2_ADDR_SIZE
;
9467 case dw_val_class_offset
:
9468 size
+= dwarf_offset_size
;
9470 case dw_val_class_loc
:
9472 unsigned long lsize
= size_of_locs (AT_loc (a
));
9475 if (dwarf_version
>= 4)
9476 size
+= size_of_uleb128 (lsize
);
9478 size
+= constant_size (lsize
);
9482 case dw_val_class_loc_list
:
9483 if (dwarf_split_debug_info
&& dwarf_version
>= 5)
9485 gcc_assert (AT_loc_list (a
)->num_assigned
);
9486 size
+= size_of_uleb128 (AT_loc_list (a
)->hash
);
9489 size
+= dwarf_offset_size
;
9491 case dw_val_class_view_list
:
9492 size
+= dwarf_offset_size
;
9494 case dw_val_class_range_list
:
9495 if (value_format (a
) == DW_FORM_rnglistx
)
9497 gcc_assert (rnglist_idx
);
9498 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
9499 size
+= size_of_uleb128 (r
->idx
);
9502 size
+= dwarf_offset_size
;
9504 case dw_val_class_const
:
9505 size
+= size_of_sleb128 (AT_int (a
));
9507 case dw_val_class_unsigned_const
:
9509 int csize
= constant_size (AT_unsigned (a
));
9510 if (dwarf_version
== 3
9511 && a
->dw_attr
== DW_AT_data_member_location
9513 size
+= size_of_uleb128 (AT_unsigned (a
));
9518 case dw_val_class_symview
:
9519 if (symview_upper_bound
<= 0xff)
9521 else if (symview_upper_bound
<= 0xffff)
9523 else if (symview_upper_bound
<= 0xffffffff)
9528 case dw_val_class_const_implicit
:
9529 case dw_val_class_unsigned_const_implicit
:
9530 case dw_val_class_file_implicit
:
9531 /* These occupy no size in the DIE, just an extra sleb128 in
9534 case dw_val_class_const_double
:
9535 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
9536 if (HOST_BITS_PER_WIDE_INT
>= DWARF_LARGEST_DATA_FORM_BITS
)
9539 case dw_val_class_wide_int
:
9540 size
+= (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
9541 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
9542 if (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
9543 * HOST_BITS_PER_WIDE_INT
> DWARF_LARGEST_DATA_FORM_BITS
)
9546 case dw_val_class_vec
:
9547 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
9548 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
9549 + a
->dw_attr_val
.v
.val_vec
.length
9550 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
9552 case dw_val_class_flag
:
9553 if (dwarf_version
>= 4)
9554 /* Currently all add_AT_flag calls pass in 1 as last argument,
9555 so DW_FORM_flag_present can be used. If that ever changes,
9556 we'll need to use DW_FORM_flag and have some optimization
9557 in build_abbrev_table that will change those to
9558 DW_FORM_flag_present if it is set to 1 in all DIEs using
9559 the same abbrev entry. */
9560 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
9564 case dw_val_class_die_ref
:
9565 if (AT_ref_external (a
))
9567 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
9568 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
9569 is sized by target address length, whereas in DWARF3
9570 it's always sized as an offset. */
9571 if (AT_ref (a
)->comdat_type_p
)
9572 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
9573 else if (dwarf_version
== 2)
9574 size
+= DWARF2_ADDR_SIZE
;
9576 size
+= dwarf_offset_size
;
9579 size
+= dwarf_offset_size
;
9581 case dw_val_class_fde_ref
:
9582 size
+= dwarf_offset_size
;
9584 case dw_val_class_lbl_id
:
9585 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
9587 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
9588 size
+= size_of_uleb128 (AT_index (a
));
9591 size
+= DWARF2_ADDR_SIZE
;
9593 case dw_val_class_lineptr
:
9594 case dw_val_class_macptr
:
9595 case dw_val_class_loclistsptr
:
9596 size
+= dwarf_offset_size
;
9598 case dw_val_class_str
:
9599 form
= AT_string_form (a
);
9600 if (form
== DW_FORM_strp
|| form
== DW_FORM_line_strp
)
9601 size
+= dwarf_offset_size
;
9602 else if (form
== dwarf_FORM (DW_FORM_strx
))
9603 size
+= size_of_uleb128 (AT_index (a
));
9605 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
9607 case dw_val_class_file
:
9608 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
9610 case dw_val_class_data8
:
9613 case dw_val_class_vms_delta
:
9614 size
+= dwarf_offset_size
;
9616 case dw_val_class_high_pc
:
9617 size
+= DWARF2_ADDR_SIZE
;
9619 case dw_val_class_discr_value
:
9620 size
+= size_of_discr_value (&a
->dw_attr_val
.v
.val_discr_value
);
9622 case dw_val_class_discr_list
:
9624 unsigned block_size
= size_of_discr_list (AT_discr_list (a
));
9626 /* This is a block, so we have the block length and then its
9628 size
+= constant_size (block_size
) + block_size
;
9639 /* Size the debugging information associated with a given DIE. Visits the
9640 DIE's children recursively. Updates the global variable next_die_offset, on
9641 each time through. Uses the current value of next_die_offset to update the
9642 die_offset field in each DIE. */
9645 calc_die_sizes (dw_die_ref die
)
9649 gcc_assert (die
->die_offset
== 0
9650 || (unsigned long int) die
->die_offset
== next_die_offset
);
9651 die
->die_offset
= next_die_offset
;
9652 next_die_offset
+= size_of_die (die
);
9654 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
9656 if (die
->die_child
!= NULL
)
9657 /* Count the null byte used to terminate sibling lists. */
9658 next_die_offset
+= 1;
9661 /* Size just the base type children at the start of the CU.
9662 This is needed because build_abbrev needs to size locs
9663 and sizing of type based stack ops needs to know die_offset
9664 values for the base types. */
9667 calc_base_type_die_sizes (void)
9669 unsigned long die_offset
= (dwarf_split_debug_info
9670 ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
9671 : DWARF_COMPILE_UNIT_HEADER_SIZE
);
9673 dw_die_ref base_type
;
9674 #if ENABLE_ASSERT_CHECKING
9675 dw_die_ref prev
= comp_unit_die ()->die_child
;
9678 die_offset
+= size_of_die (comp_unit_die ());
9679 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
9681 #if ENABLE_ASSERT_CHECKING
9682 gcc_assert (base_type
->die_offset
== 0
9683 && prev
->die_sib
== base_type
9684 && base_type
->die_child
== NULL
9685 && base_type
->die_abbrev
);
9688 if (abbrev_opt_start
9689 && base_type
->die_abbrev
>= abbrev_opt_base_type_end
)
9690 abbrev_opt_base_type_end
= base_type
->die_abbrev
+ 1;
9691 base_type
->die_offset
= die_offset
;
9692 die_offset
+= size_of_die (base_type
);
9696 /* Set the marks for a die and its children. We do this so
9697 that we know whether or not a reference needs to use FORM_ref_addr; only
9698 DIEs in the same CU will be marked. We used to clear out the offset
9699 and use that as the flag, but ran into ordering problems. */
9702 mark_dies (dw_die_ref die
)
9706 gcc_assert (!die
->die_mark
);
9709 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
9712 /* Clear the marks for a die and its children. */
9715 unmark_dies (dw_die_ref die
)
9719 if (! use_debug_types
)
9720 gcc_assert (die
->die_mark
);
9723 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
9726 /* Clear the marks for a die, its children and referred dies. */
9729 unmark_all_dies (dw_die_ref die
)
9739 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
9741 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9742 if (AT_class (a
) == dw_val_class_die_ref
)
9743 unmark_all_dies (AT_ref (a
));
9746 /* Calculate if the entry should appear in the final output file. It may be
9747 from a pruned a type. */
9750 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
9752 /* By limiting gnu pubnames to definitions only, gold can generate a
9753 gdb index without entries for declarations, which don't include
9754 enough information to be useful. */
9755 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
9758 if (table
== pubname_table
)
9760 /* Enumerator names are part of the pubname table, but the
9761 parent DW_TAG_enumeration_type die may have been pruned.
9762 Don't output them if that is the case. */
9763 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
9764 (p
->die
->die_parent
== NULL
9765 || !p
->die
->die_parent
->die_perennial_p
))
9768 /* Everything else in the pubname table is included. */
9772 /* The pubtypes table shouldn't include types that have been
9774 return (p
->die
->die_offset
!= 0
9775 || !flag_eliminate_unused_debug_types
);
9778 /* Return the size of the .debug_pubnames or .debug_pubtypes table
9779 generated for the compilation unit. */
9781 static unsigned long
9782 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9787 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
9789 size
= DWARF_PUBNAMES_HEADER_SIZE
;
9790 FOR_EACH_VEC_ELT (*names
, i
, p
)
9791 if (include_pubname_in_output (names
, p
))
9792 size
+= strlen (p
->name
) + dwarf_offset_size
+ 1 + space_for_flags
;
9794 size
+= dwarf_offset_size
;
9798 /* Return the size of the information in the .debug_aranges section. */
9800 static unsigned long
9801 size_of_aranges (void)
9805 size
= DWARF_ARANGES_HEADER_SIZE
;
9807 /* Count the address/length pair for this compilation unit. */
9808 if (switch_text_ranges
)
9809 size
+= 2 * DWARF2_ADDR_SIZE
9810 * (vec_safe_length (switch_text_ranges
) / 2 + 1);
9811 if (switch_cold_ranges
)
9812 size
+= 2 * DWARF2_ADDR_SIZE
9813 * (vec_safe_length (switch_cold_ranges
) / 2 + 1);
9814 if (have_multiple_function_sections
)
9819 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9821 if (fde
->ignored_debug
)
9823 if (!fde
->in_std_section
)
9824 size
+= 2 * DWARF2_ADDR_SIZE
;
9825 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9826 size
+= 2 * DWARF2_ADDR_SIZE
;
9830 /* Count the two zero words used to terminated the address range table. */
9831 size
+= 2 * DWARF2_ADDR_SIZE
;
9835 /* Select the encoding of an attribute value. */
9837 static enum dwarf_form
9838 value_format (dw_attr_node
*a
)
9840 switch (AT_class (a
))
9842 case dw_val_class_addr
:
9843 /* Only very few attributes allow DW_FORM_addr. */
9848 case DW_AT_entry_pc
:
9849 case DW_AT_trampoline
:
9850 return (AT_index (a
) == NOT_INDEXED
9851 ? DW_FORM_addr
: dwarf_FORM (DW_FORM_addrx
));
9855 switch (DWARF2_ADDR_SIZE
)
9858 return DW_FORM_data1
;
9860 return DW_FORM_data2
;
9862 return DW_FORM_data4
;
9864 return DW_FORM_data8
;
9868 case dw_val_class_loc_list
:
9869 if (dwarf_split_debug_info
9870 && dwarf_version
>= 5
9871 && AT_loc_list (a
)->num_assigned
)
9872 return DW_FORM_loclistx
;
9874 case dw_val_class_view_list
:
9875 case dw_val_class_range_list
:
9876 /* For range lists in DWARF 5, use DW_FORM_rnglistx from .debug_info.dwo
9877 but in .debug_info use DW_FORM_sec_offset, which is shorter if we
9878 care about sizes of .debug* sections in shared libraries and
9879 executables and don't take into account relocations that affect just
9880 relocatable objects - for DW_FORM_rnglistx we'd have to emit offset
9881 table in the .debug_rnglists section. */
9882 if (dwarf_split_debug_info
9883 && dwarf_version
>= 5
9884 && AT_class (a
) == dw_val_class_range_list
9886 && a
->dw_attr_val
.val_entry
!= RELOCATED_OFFSET
)
9887 return DW_FORM_rnglistx
;
9888 if (dwarf_version
>= 4)
9889 return DW_FORM_sec_offset
;
9891 case dw_val_class_vms_delta
:
9892 case dw_val_class_offset
:
9893 switch (dwarf_offset_size
)
9896 return DW_FORM_data4
;
9898 return DW_FORM_data8
;
9902 case dw_val_class_loc
:
9903 if (dwarf_version
>= 4)
9904 return DW_FORM_exprloc
;
9905 switch (constant_size (size_of_locs (AT_loc (a
))))
9908 return DW_FORM_block1
;
9910 return DW_FORM_block2
;
9912 return DW_FORM_block4
;
9916 case dw_val_class_const
:
9917 return DW_FORM_sdata
;
9918 case dw_val_class_unsigned_const
:
9919 switch (constant_size (AT_unsigned (a
)))
9922 return DW_FORM_data1
;
9924 return DW_FORM_data2
;
9926 /* In DWARF3 DW_AT_data_member_location with
9927 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
9928 constant, so we need to use DW_FORM_udata if we need
9929 a large constant. */
9930 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
9931 return DW_FORM_udata
;
9932 return DW_FORM_data4
;
9934 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
9935 return DW_FORM_udata
;
9936 return DW_FORM_data8
;
9940 case dw_val_class_const_implicit
:
9941 case dw_val_class_unsigned_const_implicit
:
9942 case dw_val_class_file_implicit
:
9943 return DW_FORM_implicit_const
;
9944 case dw_val_class_const_double
:
9945 switch (HOST_BITS_PER_WIDE_INT
)
9948 return DW_FORM_data2
;
9950 return DW_FORM_data4
;
9952 return DW_FORM_data8
;
9954 if (dwarf_version
>= 5)
9955 return DW_FORM_data16
;
9958 return DW_FORM_block1
;
9960 case dw_val_class_wide_int
:
9961 switch (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
)
9964 return DW_FORM_data1
;
9966 return DW_FORM_data2
;
9968 return DW_FORM_data4
;
9970 return DW_FORM_data8
;
9972 if (dwarf_version
>= 5)
9973 return DW_FORM_data16
;
9976 return DW_FORM_block1
;
9978 case dw_val_class_symview
:
9979 /* ??? We might use uleb128, but then we'd have to compute
9980 .debug_info offsets in the assembler. */
9981 if (symview_upper_bound
<= 0xff)
9982 return DW_FORM_data1
;
9983 else if (symview_upper_bound
<= 0xffff)
9984 return DW_FORM_data2
;
9985 else if (symview_upper_bound
<= 0xffffffff)
9986 return DW_FORM_data4
;
9988 return DW_FORM_data8
;
9989 case dw_val_class_vec
:
9990 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
9991 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
9994 return DW_FORM_block1
;
9996 return DW_FORM_block2
;
9998 return DW_FORM_block4
;
10000 gcc_unreachable ();
10002 case dw_val_class_flag
:
10003 if (dwarf_version
>= 4)
10005 /* Currently all add_AT_flag calls pass in 1 as last argument,
10006 so DW_FORM_flag_present can be used. If that ever changes,
10007 we'll need to use DW_FORM_flag and have some optimization
10008 in build_abbrev_table that will change those to
10009 DW_FORM_flag_present if it is set to 1 in all DIEs using
10010 the same abbrev entry. */
10011 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
10012 return DW_FORM_flag_present
;
10014 return DW_FORM_flag
;
10015 case dw_val_class_die_ref
:
10016 if (AT_ref_external (a
))
10018 if (AT_ref (a
)->comdat_type_p
)
10019 return DW_FORM_ref_sig8
;
10021 return DW_FORM_ref_addr
;
10024 return DW_FORM_ref
;
10025 case dw_val_class_fde_ref
:
10026 return DW_FORM_data
;
10027 case dw_val_class_lbl_id
:
10028 return (AT_index (a
) == NOT_INDEXED
10029 ? DW_FORM_addr
: dwarf_FORM (DW_FORM_addrx
));
10030 case dw_val_class_lineptr
:
10031 case dw_val_class_macptr
:
10032 case dw_val_class_loclistsptr
:
10033 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
10034 case dw_val_class_str
:
10035 return AT_string_form (a
);
10036 case dw_val_class_file
:
10037 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
10040 return DW_FORM_data1
;
10042 return DW_FORM_data2
;
10044 return DW_FORM_data4
;
10046 gcc_unreachable ();
10049 case dw_val_class_data8
:
10050 return DW_FORM_data8
;
10052 case dw_val_class_high_pc
:
10053 switch (DWARF2_ADDR_SIZE
)
10056 return DW_FORM_data1
;
10058 return DW_FORM_data2
;
10060 return DW_FORM_data4
;
10062 return DW_FORM_data8
;
10064 gcc_unreachable ();
10067 case dw_val_class_discr_value
:
10068 return (a
->dw_attr_val
.v
.val_discr_value
.pos
10071 case dw_val_class_discr_list
:
10072 switch (constant_size (size_of_discr_list (AT_discr_list (a
))))
10075 return DW_FORM_block1
;
10077 return DW_FORM_block2
;
10079 return DW_FORM_block4
;
10081 gcc_unreachable ();
10085 gcc_unreachable ();
10089 /* Output the encoding of an attribute value. */
10092 output_value_format (dw_attr_node
*a
)
10094 enum dwarf_form form
= value_format (a
);
10096 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
10099 /* Given a die and id, produce the appropriate abbreviations. */
10102 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
10105 dw_attr_node
*a_attr
;
10107 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
10108 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
10109 dwarf_tag_name (abbrev
->die_tag
));
10111 if (abbrev
->die_child
!= NULL
)
10112 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
10114 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
10116 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
10118 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
10119 dwarf_attr_name (a_attr
->dw_attr
));
10120 output_value_format (a_attr
);
10121 if (value_format (a_attr
) == DW_FORM_implicit_const
)
10123 if (AT_class (a_attr
) == dw_val_class_file_implicit
)
10125 int f
= maybe_emit_file (a_attr
->dw_attr_val
.v
.val_file
);
10126 const char *filename
= a_attr
->dw_attr_val
.v
.val_file
->filename
;
10127 dw2_asm_output_data_sleb128 (f
, "(%s)", filename
);
10130 dw2_asm_output_data_sleb128 (a_attr
->dw_attr_val
.v
.val_int
, NULL
);
10134 dw2_asm_output_data (1, 0, NULL
);
10135 dw2_asm_output_data (1, 0, NULL
);
10139 /* Output the .debug_abbrev section which defines the DIE abbreviation
10143 output_abbrev_section (void)
10145 unsigned int abbrev_id
;
10148 FOR_EACH_VEC_SAFE_ELT (abbrev_die_table
, abbrev_id
, abbrev
)
10149 if (abbrev_id
!= 0)
10150 output_die_abbrevs (abbrev_id
, abbrev
);
10152 /* Terminate the table. */
10153 dw2_asm_output_data (1, 0, NULL
);
10156 /* Return a new location list, given the begin and end range, and the
10159 static inline dw_loc_list_ref
10160 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, var_loc_view vbegin
,
10161 const char *end
, var_loc_view vend
,
10162 const char *section
)
10164 dw_loc_list_ref retlist
= ggc_cleared_alloc
<dw_loc_list_node
> ();
10166 retlist
->begin
= begin
;
10167 retlist
->begin_entry
= NULL
;
10168 retlist
->end
= end
;
10169 retlist
->end_entry
= NULL
;
10170 retlist
->expr
= expr
;
10171 retlist
->section
= section
;
10172 retlist
->vbegin
= vbegin
;
10173 retlist
->vend
= vend
;
10178 /* Return true iff there's any nonzero view number in the loc list.
10180 ??? When views are not enabled, we'll often extend a single range
10181 to the entire function, so that we emit a single location
10182 expression rather than a location list. With views, even with a
10183 single range, we'll output a list if start or end have a nonzero
10184 view. If we change this, we may want to stop splitting a single
10185 range in dw_loc_list just because of a nonzero view, even if it
10186 straddles across hot/cold partitions. */
10189 loc_list_has_views (dw_loc_list_ref list
)
10191 if (!debug_variable_location_views
)
10194 for (dw_loc_list_ref loc
= list
;
10195 loc
!= NULL
; loc
= loc
->dw_loc_next
)
10196 if (!ZERO_VIEW_P (loc
->vbegin
) || !ZERO_VIEW_P (loc
->vend
))
10202 /* Generate a new internal symbol for this location list node, if it
10203 hasn't got one yet. */
10206 gen_llsym (dw_loc_list_ref list
)
10208 gcc_assert (!list
->ll_symbol
);
10209 list
->ll_symbol
= gen_internal_sym ("LLST");
10211 if (!loc_list_has_views (list
))
10214 if (dwarf2out_locviews_in_attribute ())
10216 /* Use the same label_num for the view list. */
10218 list
->vl_symbol
= gen_internal_sym ("LVUS");
10221 list
->vl_symbol
= list
->ll_symbol
;
10224 /* Generate a symbol for the list, but only if we really want to emit
10228 maybe_gen_llsym (dw_loc_list_ref list
)
10230 if (!list
|| (!list
->dw_loc_next
&& !loc_list_has_views (list
)))
10236 /* Determine whether or not to skip loc_list entry CURR. If SIZEP is
10237 NULL, don't consider size of the location expression. If we're not
10238 to skip it, and SIZEP is non-null, store the size of CURR->expr's
10239 representation in *SIZEP. */
10242 skip_loc_list_entry (dw_loc_list_ref curr
, unsigned long *sizep
= NULL
)
10244 /* Don't output an entry that starts and ends at the same address. */
10245 if (strcmp (curr
->begin
, curr
->end
) == 0
10246 && curr
->vbegin
== curr
->vend
&& !curr
->force
)
10252 unsigned long size
= size_of_locs (curr
->expr
);
10254 /* If the expression is too large, drop it on the floor. We could
10255 perhaps put it into DW_TAG_dwarf_procedure and refer to that
10256 in the expression, but >= 64KB expressions for a single value
10257 in a single range are unlikely very useful. */
10258 if (dwarf_version
< 5 && size
> 0xffff)
10266 /* Output a view pair loclist entry for CURR, if it requires one. */
10269 dwarf2out_maybe_output_loclist_view_pair (dw_loc_list_ref curr
)
10271 if (!dwarf2out_locviews_in_loclist ())
10274 if (ZERO_VIEW_P (curr
->vbegin
) && ZERO_VIEW_P (curr
->vend
))
10277 #ifdef DW_LLE_view_pair
10278 dw2_asm_output_data (1, DW_LLE_view_pair
, "DW_LLE_view_pair");
10280 if (dwarf2out_as_locview_support
)
10282 if (ZERO_VIEW_P (curr
->vbegin
))
10283 dw2_asm_output_data_uleb128 (0, "Location view begin");
10286 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10287 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", curr
->vbegin
);
10288 dw2_asm_output_symname_uleb128 (label
, "Location view begin");
10291 if (ZERO_VIEW_P (curr
->vend
))
10292 dw2_asm_output_data_uleb128 (0, "Location view end");
10295 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10296 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", curr
->vend
);
10297 dw2_asm_output_symname_uleb128 (label
, "Location view end");
10302 dw2_asm_output_data_uleb128 (curr
->vbegin
, "Location view begin");
10303 dw2_asm_output_data_uleb128 (curr
->vend
, "Location view end");
10305 #endif /* DW_LLE_view_pair */
10310 /* Output the location list given to us. */
10313 output_loc_list (dw_loc_list_ref list_head
)
10315 int vcount
= 0, lcount
= 0;
10317 if (list_head
->emitted
)
10319 list_head
->emitted
= true;
10321 if (list_head
->vl_symbol
&& dwarf2out_locviews_in_attribute ())
10323 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->vl_symbol
);
10325 for (dw_loc_list_ref curr
= list_head
; curr
!= NULL
;
10326 curr
= curr
->dw_loc_next
)
10328 unsigned long size
;
10330 if (skip_loc_list_entry (curr
, &size
))
10335 /* ?? dwarf_split_debug_info? */
10336 if (dwarf2out_as_locview_support
)
10338 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10340 if (!ZERO_VIEW_P (curr
->vbegin
))
10342 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", curr
->vbegin
);
10343 dw2_asm_output_symname_uleb128 (label
,
10344 "View list begin (%s)",
10345 list_head
->vl_symbol
);
10348 dw2_asm_output_data_uleb128 (0,
10349 "View list begin (%s)",
10350 list_head
->vl_symbol
);
10352 if (!ZERO_VIEW_P (curr
->vend
))
10354 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", curr
->vend
);
10355 dw2_asm_output_symname_uleb128 (label
,
10356 "View list end (%s)",
10357 list_head
->vl_symbol
);
10360 dw2_asm_output_data_uleb128 (0,
10361 "View list end (%s)",
10362 list_head
->vl_symbol
);
10366 dw2_asm_output_data_uleb128 (curr
->vbegin
,
10367 "View list begin (%s)",
10368 list_head
->vl_symbol
);
10369 dw2_asm_output_data_uleb128 (curr
->vend
,
10370 "View list end (%s)",
10371 list_head
->vl_symbol
);
10376 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
10378 const char *last_section
= NULL
;
10379 const char *base_label
= NULL
;
10381 /* Walk the location list, and output each range + expression. */
10382 for (dw_loc_list_ref curr
= list_head
; curr
!= NULL
;
10383 curr
= curr
->dw_loc_next
)
10385 unsigned long size
;
10387 /* Skip this entry? If we skip it here, we must skip it in the
10388 view list above as well. */
10389 if (skip_loc_list_entry (curr
, &size
))
10394 if (dwarf_version
>= 5)
10396 if (dwarf_split_debug_info
&& HAVE_AS_LEB128
)
10398 dwarf2out_maybe_output_loclist_view_pair (curr
);
10399 /* For -gsplit-dwarf, emit DW_LLE_startx_length, which has
10400 uleb128 index into .debug_addr and uleb128 length. */
10401 dw2_asm_output_data (1, DW_LLE_startx_length
,
10402 "DW_LLE_startx_length (%s)",
10403 list_head
->ll_symbol
);
10404 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
10405 "Location list range start index "
10406 "(%s)", curr
->begin
);
10407 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->begin
,
10408 "Location list length (%s)",
10409 list_head
->ll_symbol
);
10411 else if (dwarf_split_debug_info
)
10413 dwarf2out_maybe_output_loclist_view_pair (curr
);
10414 /* For -gsplit-dwarf without usable .uleb128 support, emit
10415 DW_LLE_startx_endx, which has two uleb128 indexes into
10417 dw2_asm_output_data (1, DW_LLE_startx_endx
,
10418 "DW_LLE_startx_endx (%s)",
10419 list_head
->ll_symbol
);
10420 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
10421 "Location list range start index "
10422 "(%s)", curr
->begin
);
10423 dw2_asm_output_data_uleb128 (curr
->end_entry
->index
,
10424 "Location list range end index "
10425 "(%s)", curr
->end
);
10427 else if (!have_multiple_function_sections
&& HAVE_AS_LEB128
)
10429 dwarf2out_maybe_output_loclist_view_pair (curr
);
10430 /* If all code is in .text section, the base address is
10431 already provided by the CU attributes. Use
10432 DW_LLE_offset_pair where both addresses are uleb128 encoded
10433 offsets against that base. */
10434 dw2_asm_output_data (1, DW_LLE_offset_pair
,
10435 "DW_LLE_offset_pair (%s)",
10436 list_head
->ll_symbol
);
10437 dw2_asm_output_delta_uleb128 (curr
->begin
, curr
->section
,
10438 "Location list begin address (%s)",
10439 list_head
->ll_symbol
);
10440 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->section
,
10441 "Location list end address (%s)",
10442 list_head
->ll_symbol
);
10444 else if (HAVE_AS_LEB128
)
10446 /* Otherwise, find out how many consecutive entries could share
10447 the same base entry. If just one, emit DW_LLE_start_length,
10448 otherwise emit DW_LLE_base_address for the base address
10449 followed by a series of DW_LLE_offset_pair. */
10450 if (last_section
== NULL
|| curr
->section
!= last_section
)
10452 dw_loc_list_ref curr2
;
10453 for (curr2
= curr
->dw_loc_next
; curr2
!= NULL
;
10454 curr2
= curr2
->dw_loc_next
)
10456 if (strcmp (curr2
->begin
, curr2
->end
) == 0
10461 if (curr2
== NULL
|| curr
->section
!= curr2
->section
)
10462 last_section
= NULL
;
10465 last_section
= curr
->section
;
10466 base_label
= curr
->begin
;
10467 dw2_asm_output_data (1, DW_LLE_base_address
,
10468 "DW_LLE_base_address (%s)",
10469 list_head
->ll_symbol
);
10470 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, base_label
,
10471 "Base address (%s)",
10472 list_head
->ll_symbol
);
10475 /* Only one entry with the same base address. Use
10476 DW_LLE_start_length with absolute address and uleb128
10478 if (last_section
== NULL
)
10480 dwarf2out_maybe_output_loclist_view_pair (curr
);
10481 dw2_asm_output_data (1, DW_LLE_start_length
,
10482 "DW_LLE_start_length (%s)",
10483 list_head
->ll_symbol
);
10484 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
10485 "Location list begin address (%s)",
10486 list_head
->ll_symbol
);
10487 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->begin
,
10488 "Location list length "
10489 "(%s)", list_head
->ll_symbol
);
10491 /* Otherwise emit DW_LLE_offset_pair, relative to above emitted
10492 DW_LLE_base_address. */
10495 dwarf2out_maybe_output_loclist_view_pair (curr
);
10496 dw2_asm_output_data (1, DW_LLE_offset_pair
,
10497 "DW_LLE_offset_pair (%s)",
10498 list_head
->ll_symbol
);
10499 dw2_asm_output_delta_uleb128 (curr
->begin
, base_label
,
10500 "Location list begin address "
10501 "(%s)", list_head
->ll_symbol
);
10502 dw2_asm_output_delta_uleb128 (curr
->end
, base_label
,
10503 "Location list end address "
10504 "(%s)", list_head
->ll_symbol
);
10507 /* The assembler does not support .uleb128 directive. Emit
10508 DW_LLE_start_end with a pair of absolute addresses. */
10511 dwarf2out_maybe_output_loclist_view_pair (curr
);
10512 dw2_asm_output_data (1, DW_LLE_start_end
,
10513 "DW_LLE_start_end (%s)",
10514 list_head
->ll_symbol
);
10515 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
10516 "Location list begin address (%s)",
10517 list_head
->ll_symbol
);
10518 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
10519 "Location list end address (%s)",
10520 list_head
->ll_symbol
);
10523 else if (dwarf_split_debug_info
)
10525 /* For -gsplit-dwarf -gdwarf-{2,3,4} emit index into .debug_addr
10526 and 4 byte length. */
10527 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
10528 "Location list start/length entry (%s)",
10529 list_head
->ll_symbol
);
10530 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
10531 "Location list range start index (%s)",
10533 /* The length field is 4 bytes. If we ever need to support
10534 an 8-byte length, we can add a new DW_LLE code or fall back
10535 to DW_LLE_GNU_start_end_entry. */
10536 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
10537 "Location list range length (%s)",
10538 list_head
->ll_symbol
);
10540 else if (!have_multiple_function_sections
)
10542 /* Pair of relative addresses against start of text section. */
10543 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
10544 "Location list begin address (%s)",
10545 list_head
->ll_symbol
);
10546 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
10547 "Location list end address (%s)",
10548 list_head
->ll_symbol
);
10552 /* Pair of absolute addresses. */
10553 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
10554 "Location list begin address (%s)",
10555 list_head
->ll_symbol
);
10556 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
10557 "Location list end address (%s)",
10558 list_head
->ll_symbol
);
10561 /* Output the block length for this list of location operations. */
10562 if (dwarf_version
>= 5)
10563 dw2_asm_output_data_uleb128 (size
, "Location expression size");
10566 gcc_assert (size
<= 0xffff);
10567 dw2_asm_output_data (2, size
, "Location expression size");
10570 output_loc_sequence (curr
->expr
, -1);
10573 /* And finally list termination. */
10574 if (dwarf_version
>= 5)
10575 dw2_asm_output_data (1, DW_LLE_end_of_list
,
10576 "DW_LLE_end_of_list (%s)", list_head
->ll_symbol
);
10577 else if (dwarf_split_debug_info
)
10578 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
10579 "Location list terminator (%s)",
10580 list_head
->ll_symbol
);
10583 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
10584 "Location list terminator begin (%s)",
10585 list_head
->ll_symbol
);
10586 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
10587 "Location list terminator end (%s)",
10588 list_head
->ll_symbol
);
10591 gcc_assert (!list_head
->vl_symbol
10592 || vcount
== lcount
* (dwarf2out_locviews_in_attribute () ? 1 : 0));
10595 /* Output a range_list offset into the .debug_ranges or .debug_rnglists
10596 section. Emit a relocated reference if val_entry is NULL, otherwise,
10597 emit an indirect reference. */
10600 output_range_list_offset (dw_attr_node
*a
)
10602 const char *name
= dwarf_attr_name (a
->dw_attr
);
10604 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
10606 if (dwarf_version
>= 5)
10608 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
10609 dw2_asm_output_offset (dwarf_offset_size
, r
->label
,
10610 debug_ranges_section
, "%s", name
);
10614 char *p
= strchr (ranges_section_label
, '\0');
10615 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
10616 a
->dw_attr_val
.v
.val_offset
* 2 * DWARF2_ADDR_SIZE
);
10617 dw2_asm_output_offset (dwarf_offset_size
, ranges_section_label
,
10618 debug_ranges_section
, "%s", name
);
10622 else if (dwarf_version
>= 5)
10624 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
10625 gcc_assert (rnglist_idx
);
10626 dw2_asm_output_data_uleb128 (r
->idx
, "%s", name
);
10629 dw2_asm_output_data (dwarf_offset_size
,
10630 a
->dw_attr_val
.v
.val_offset
* 2 * DWARF2_ADDR_SIZE
,
10631 "%s (offset from %s)", name
, ranges_section_label
);
10634 /* Output the offset into the debug_loc section. */
10637 output_loc_list_offset (dw_attr_node
*a
)
10639 char *sym
= AT_loc_list (a
)->ll_symbol
;
10642 if (!dwarf_split_debug_info
)
10643 dw2_asm_output_offset (dwarf_offset_size
, sym
, debug_loc_section
,
10644 "%s", dwarf_attr_name (a
->dw_attr
));
10645 else if (dwarf_version
>= 5)
10647 gcc_assert (AT_loc_list (a
)->num_assigned
);
10648 dw2_asm_output_data_uleb128 (AT_loc_list (a
)->hash
, "%s (%s)",
10649 dwarf_attr_name (a
->dw_attr
),
10653 dw2_asm_output_delta (dwarf_offset_size
, sym
, loc_section_label
,
10654 "%s", dwarf_attr_name (a
->dw_attr
));
10657 /* Output the offset into the debug_loc section. */
10660 output_view_list_offset (dw_attr_node
*a
)
10662 char *sym
= (*AT_loc_list_ptr (a
))->vl_symbol
;
10665 if (dwarf_split_debug_info
)
10666 dw2_asm_output_delta (dwarf_offset_size
, sym
, loc_section_label
,
10667 "%s", dwarf_attr_name (a
->dw_attr
));
10669 dw2_asm_output_offset (dwarf_offset_size
, sym
, debug_loc_section
,
10670 "%s", dwarf_attr_name (a
->dw_attr
));
10673 /* Output an attribute's index or value appropriately. */
10676 output_attr_index_or_value (dw_attr_node
*a
)
10678 const char *name
= dwarf_attr_name (a
->dw_attr
);
10680 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
10682 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
10685 switch (AT_class (a
))
10687 case dw_val_class_addr
:
10688 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
10690 case dw_val_class_high_pc
:
10691 case dw_val_class_lbl_id
:
10692 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
10695 gcc_unreachable ();
10699 /* Output a type signature. */
10702 output_signature (const char *sig
, const char *name
)
10706 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
10707 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
10710 /* Output a discriminant value. */
10713 output_discr_value (dw_discr_value
*discr_value
, const char *name
)
10715 if (discr_value
->pos
)
10716 dw2_asm_output_data_uleb128 (discr_value
->v
.uval
, "%s", name
);
10718 dw2_asm_output_data_sleb128 (discr_value
->v
.sval
, "%s", name
);
10721 /* Output the DIE and its attributes. Called recursively to generate
10722 the definitions of each child DIE. */
10725 output_die (dw_die_ref die
)
10729 unsigned long size
;
10732 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
10733 (unsigned long)die
->die_offset
,
10734 dwarf_tag_name (die
->die_tag
));
10736 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
10738 const char *name
= dwarf_attr_name (a
->dw_attr
);
10740 switch (AT_class (a
))
10742 case dw_val_class_addr
:
10743 output_attr_index_or_value (a
);
10746 case dw_val_class_offset
:
10747 dw2_asm_output_data (dwarf_offset_size
, a
->dw_attr_val
.v
.val_offset
,
10751 case dw_val_class_range_list
:
10752 output_range_list_offset (a
);
10755 case dw_val_class_loc
:
10756 size
= size_of_locs (AT_loc (a
));
10758 /* Output the block length for this list of location operations. */
10759 if (dwarf_version
>= 4)
10760 dw2_asm_output_data_uleb128 (size
, "%s", name
);
10762 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
10764 output_loc_sequence (AT_loc (a
), -1);
10767 case dw_val_class_const
:
10768 /* ??? It would be slightly more efficient to use a scheme like is
10769 used for unsigned constants below, but gdb 4.x does not sign
10770 extend. Gdb 5.x does sign extend. */
10771 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
10774 case dw_val_class_unsigned_const
:
10776 int csize
= constant_size (AT_unsigned (a
));
10777 if (dwarf_version
== 3
10778 && a
->dw_attr
== DW_AT_data_member_location
10780 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
10782 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
10786 case dw_val_class_symview
:
10789 if (symview_upper_bound
<= 0xff)
10791 else if (symview_upper_bound
<= 0xffff)
10793 else if (symview_upper_bound
<= 0xffffffff)
10797 dw2_asm_output_addr (vsize
, a
->dw_attr_val
.v
.val_symbolic_view
,
10802 case dw_val_class_const_implicit
:
10803 if (flag_debug_asm
)
10804 fprintf (asm_out_file
, "\t\t\t%s %s ("
10805 HOST_WIDE_INT_PRINT_DEC
")\n",
10806 ASM_COMMENT_START
, name
, AT_int (a
));
10809 case dw_val_class_unsigned_const_implicit
:
10810 if (flag_debug_asm
)
10811 fprintf (asm_out_file
, "\t\t\t%s %s ("
10812 HOST_WIDE_INT_PRINT_HEX
")\n",
10813 ASM_COMMENT_START
, name
, AT_unsigned (a
));
10816 case dw_val_class_const_double
:
10818 unsigned HOST_WIDE_INT first
, second
;
10820 if (HOST_BITS_PER_WIDE_INT
>= DWARF_LARGEST_DATA_FORM_BITS
)
10821 dw2_asm_output_data (1,
10822 HOST_BITS_PER_DOUBLE_INT
10823 / HOST_BITS_PER_CHAR
,
10826 if (WORDS_BIG_ENDIAN
)
10828 first
= a
->dw_attr_val
.v
.val_double
.high
;
10829 second
= a
->dw_attr_val
.v
.val_double
.low
;
10833 first
= a
->dw_attr_val
.v
.val_double
.low
;
10834 second
= a
->dw_attr_val
.v
.val_double
.high
;
10837 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
10838 first
, "%s", name
);
10839 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
10844 case dw_val_class_wide_int
:
10847 int len
= get_full_len (*a
->dw_attr_val
.v
.val_wide
);
10848 int l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
10849 if (len
* HOST_BITS_PER_WIDE_INT
> DWARF_LARGEST_DATA_FORM_BITS
)
10850 dw2_asm_output_data (1, get_full_len (*a
->dw_attr_val
.v
.val_wide
)
10853 if (WORDS_BIG_ENDIAN
)
10854 for (i
= len
- 1; i
>= 0; --i
)
10856 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
10861 for (i
= 0; i
< len
; ++i
)
10863 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
10870 case dw_val_class_vec
:
10872 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
10873 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
10877 dw2_asm_output_data (constant_size (len
* elt_size
),
10878 len
* elt_size
, "%s", name
);
10879 if (elt_size
> sizeof (HOST_WIDE_INT
))
10884 for (i
= 0, p
= (unsigned char *) a
->dw_attr_val
.v
.val_vec
.array
;
10886 i
++, p
+= elt_size
)
10887 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
10888 "fp or vector constant word %u", i
);
10892 case dw_val_class_flag
:
10893 if (dwarf_version
>= 4)
10895 /* Currently all add_AT_flag calls pass in 1 as last argument,
10896 so DW_FORM_flag_present can be used. If that ever changes,
10897 we'll need to use DW_FORM_flag and have some optimization
10898 in build_abbrev_table that will change those to
10899 DW_FORM_flag_present if it is set to 1 in all DIEs using
10900 the same abbrev entry. */
10901 gcc_assert (AT_flag (a
) == 1);
10902 if (flag_debug_asm
)
10903 fprintf (asm_out_file
, "\t\t\t%s %s\n",
10904 ASM_COMMENT_START
, name
);
10907 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
10910 case dw_val_class_loc_list
:
10911 output_loc_list_offset (a
);
10914 case dw_val_class_view_list
:
10915 output_view_list_offset (a
);
10918 case dw_val_class_die_ref
:
10919 if (AT_ref_external (a
))
10921 if (AT_ref (a
)->comdat_type_p
)
10923 comdat_type_node
*type_node
10924 = AT_ref (a
)->die_id
.die_type_node
;
10926 gcc_assert (type_node
);
10927 output_signature (type_node
->signature
, name
);
10931 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
10935 /* In DWARF2, DW_FORM_ref_addr is sized by target address
10936 length, whereas in DWARF3 it's always sized as an
10938 if (dwarf_version
== 2)
10939 size
= DWARF2_ADDR_SIZE
;
10941 size
= dwarf_offset_size
;
10942 /* ??? We cannot unconditionally output die_offset if
10943 non-zero - others might create references to those
10945 And we do not clear its DIE offset after outputting it
10946 (and the label refers to the actual DIEs, not the
10947 DWARF CU unit header which is when using label + offset
10948 would be the correct thing to do).
10949 ??? This is the reason for the with_offset flag. */
10950 if (AT_ref (a
)->with_offset
)
10951 dw2_asm_output_offset (size
, sym
, AT_ref (a
)->die_offset
,
10952 debug_info_section
, "%s", name
);
10954 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
10960 gcc_assert (AT_ref (a
)->die_offset
);
10961 dw2_asm_output_data (dwarf_offset_size
, AT_ref (a
)->die_offset
,
10966 case dw_val_class_fde_ref
:
10968 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
10970 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
10971 a
->dw_attr_val
.v
.val_fde_index
* 2);
10972 dw2_asm_output_offset (dwarf_offset_size
, l1
, debug_frame_section
,
10977 case dw_val_class_vms_delta
:
10978 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
10979 dw2_asm_output_vms_delta (dwarf_offset_size
,
10980 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
10983 dw2_asm_output_delta (dwarf_offset_size
,
10984 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
10989 case dw_val_class_lbl_id
:
10990 output_attr_index_or_value (a
);
10993 case dw_val_class_lineptr
:
10994 dw2_asm_output_offset (dwarf_offset_size
, AT_lbl (a
),
10995 debug_line_section
, "%s", name
);
10998 case dw_val_class_macptr
:
10999 dw2_asm_output_offset (dwarf_offset_size
, AT_lbl (a
),
11000 debug_macinfo_section
, "%s", name
);
11003 case dw_val_class_loclistsptr
:
11004 dw2_asm_output_offset (dwarf_offset_size
, AT_lbl (a
),
11005 debug_loc_section
, "%s", name
);
11008 case dw_val_class_str
:
11009 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
11010 dw2_asm_output_offset (dwarf_offset_size
,
11011 a
->dw_attr_val
.v
.val_str
->label
,
11013 "%s: \"%s\"", name
, AT_string (a
));
11014 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_line_strp
)
11015 dw2_asm_output_offset (dwarf_offset_size
,
11016 a
->dw_attr_val
.v
.val_str
->label
,
11017 debug_line_str_section
,
11018 "%s: \"%s\"", name
, AT_string (a
));
11019 else if (a
->dw_attr_val
.v
.val_str
->form
== dwarf_FORM (DW_FORM_strx
))
11020 dw2_asm_output_data_uleb128 (AT_index (a
),
11021 "%s: \"%s\"", name
, AT_string (a
));
11023 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
11026 case dw_val_class_file
:
11028 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
11030 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
11031 a
->dw_attr_val
.v
.val_file
->filename
);
11035 case dw_val_class_file_implicit
:
11036 if (flag_debug_asm
)
11037 fprintf (asm_out_file
, "\t\t\t%s %s (%d, %s)\n",
11038 ASM_COMMENT_START
, name
,
11039 maybe_emit_file (a
->dw_attr_val
.v
.val_file
),
11040 a
->dw_attr_val
.v
.val_file
->filename
);
11043 case dw_val_class_data8
:
11047 for (i
= 0; i
< 8; i
++)
11048 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
11049 i
== 0 ? "%s" : NULL
, name
);
11053 case dw_val_class_high_pc
:
11054 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
11055 get_AT_low_pc (die
), "DW_AT_high_pc");
11058 case dw_val_class_discr_value
:
11059 output_discr_value (&a
->dw_attr_val
.v
.val_discr_value
, name
);
11062 case dw_val_class_discr_list
:
11064 dw_discr_list_ref list
= AT_discr_list (a
);
11065 const int size
= size_of_discr_list (list
);
11067 /* This is a block, so output its length first. */
11068 dw2_asm_output_data (constant_size (size
), size
,
11069 "%s: block size", name
);
11071 for (; list
!= NULL
; list
= list
->dw_discr_next
)
11073 /* One byte for the discriminant value descriptor, and then as
11074 many LEB128 numbers as required. */
11075 if (list
->dw_discr_range
)
11076 dw2_asm_output_data (1, DW_DSC_range
,
11077 "%s: DW_DSC_range", name
);
11079 dw2_asm_output_data (1, DW_DSC_label
,
11080 "%s: DW_DSC_label", name
);
11082 output_discr_value (&list
->dw_discr_lower_bound
, name
);
11083 if (list
->dw_discr_range
)
11084 output_discr_value (&list
->dw_discr_upper_bound
, name
);
11090 gcc_unreachable ();
11094 FOR_EACH_CHILD (die
, c
, output_die (c
));
11096 /* Add null byte to terminate sibling list. */
11097 if (die
->die_child
!= NULL
)
11098 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11099 (unsigned long) die
->die_offset
);
11102 /* Output the dwarf version number. */
11105 output_dwarf_version ()
11107 /* ??? For now, if -gdwarf-6 is specified, we output version 5 with
11108 views in loclist. That will change eventually. */
11109 if (dwarf_version
== 6)
11114 warning (0, "%<-gdwarf-6%> is output as version 5 with "
11115 "incompatibilities");
11118 dw2_asm_output_data (2, 5, "DWARF version number");
11121 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
11124 /* Output the compilation unit that appears at the beginning of the
11125 .debug_info section, and precedes the DIE descriptions. */
11128 output_compilation_unit_header (enum dwarf_unit_type ut
)
11130 if (!XCOFF_DEBUGGING_INFO
)
11132 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
11133 dw2_asm_output_data (4, 0xffffffff,
11134 "Initial length escape value indicating 64-bit DWARF extension");
11135 dw2_asm_output_data (dwarf_offset_size
,
11136 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
11137 "Length of Compilation Unit Info");
11140 output_dwarf_version ();
11141 if (dwarf_version
>= 5)
11146 case DW_UT_compile
: name
= "DW_UT_compile"; break;
11147 case DW_UT_type
: name
= "DW_UT_type"; break;
11148 case DW_UT_split_compile
: name
= "DW_UT_split_compile"; break;
11149 case DW_UT_split_type
: name
= "DW_UT_split_type"; break;
11150 default: gcc_unreachable ();
11152 dw2_asm_output_data (1, ut
, "%s", name
);
11153 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
11155 dw2_asm_output_offset (dwarf_offset_size
, abbrev_section_label
,
11156 debug_abbrev_section
,
11157 "Offset Into Abbrev. Section");
11158 if (dwarf_version
< 5)
11159 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
11162 /* Output the compilation unit DIE and its children. */
11165 output_comp_unit (dw_die_ref die
, int output_if_empty
,
11166 const unsigned char *dwo_id
)
11168 const char *secname
, *oldsym
;
11171 /* Unless we are outputting main CU, we may throw away empty ones. */
11172 if (!output_if_empty
&& die
->die_child
== NULL
)
11175 /* Even if there are no children of this DIE, we must output the information
11176 about the compilation unit. Otherwise, on an empty translation unit, we
11177 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
11178 will then complain when examining the file. First mark all the DIEs in
11179 this CU so we know which get local refs. */
11182 external_ref_hash_type
*extern_map
= optimize_external_refs (die
);
11184 /* For now, optimize only the main CU, in order to optimize the rest
11185 we'd need to see all of them earlier. Leave the rest for post-linking
11187 if (die
== comp_unit_die ())
11188 abbrev_opt_start
= vec_safe_length (abbrev_die_table
);
11190 build_abbrev_table (die
, extern_map
);
11192 optimize_abbrev_table ();
11196 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11197 next_die_offset
= (dwo_id
11198 ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
11199 : DWARF_COMPILE_UNIT_HEADER_SIZE
);
11200 calc_die_sizes (die
);
11202 oldsym
= die
->die_id
.die_symbol
;
11203 if (oldsym
&& die
->comdat_type_p
)
11205 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
11207 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
11209 die
->die_id
.die_symbol
= NULL
;
11210 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
11214 switch_to_section (debug_info_section
);
11215 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
11216 info_section_emitted
= true;
11219 /* For LTO cross unit DIE refs we want a symbol on the start of the
11220 debuginfo section, not on the CU DIE. */
11221 if ((flag_generate_lto
|| flag_generate_offload
) && oldsym
)
11223 /* ??? No way to get visibility assembled without a decl. */
11224 tree decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
,
11225 get_identifier (oldsym
), char_type_node
);
11226 TREE_PUBLIC (decl
) = true;
11227 TREE_STATIC (decl
) = true;
11228 DECL_ARTIFICIAL (decl
) = true;
11229 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
11230 DECL_VISIBILITY_SPECIFIED (decl
) = true;
11231 targetm
.asm_out
.assemble_visibility (decl
, VISIBILITY_HIDDEN
);
11232 #ifdef ASM_WEAKEN_LABEL
11233 /* We prefer a .weak because that handles duplicates from duplicate
11234 archive members in a graceful way. */
11235 ASM_WEAKEN_LABEL (asm_out_file
, oldsym
);
11237 targetm
.asm_out
.globalize_label (asm_out_file
, oldsym
);
11239 ASM_OUTPUT_LABEL (asm_out_file
, oldsym
);
11242 /* Output debugging information. */
11243 output_compilation_unit_header (dwo_id
11244 ? DW_UT_split_compile
: DW_UT_compile
);
11245 if (dwarf_version
>= 5)
11247 if (dwo_id
!= NULL
)
11248 for (int i
= 0; i
< 8; i
++)
11249 dw2_asm_output_data (1, dwo_id
[i
], i
== 0 ? "DWO id" : NULL
);
11253 /* Leave the marks on the main CU, so we can check them in
11254 output_pubnames. */
11258 die
->die_id
.die_symbol
= oldsym
;
11262 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
11263 and .debug_pubtypes. This is configured per-target, but can be
11264 overridden by the -gpubnames or -gno-pubnames options. */
11267 want_pubnames (void)
11269 if (debug_info_level
<= DINFO_LEVEL_TERSE
11270 /* Names and types go to the early debug part only. */
11273 if (debug_generate_pub_sections
!= -1)
11274 return debug_generate_pub_sections
;
11275 return targetm
.want_debug_pub_sections
;
11278 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
11281 add_AT_pubnames (dw_die_ref die
)
11283 if (want_pubnames ())
11284 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
11287 /* Add a string attribute value to a skeleton DIE. */
11290 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
11294 struct indirect_string_node
*node
;
11296 if (! skeleton_debug_str_hash
)
11297 skeleton_debug_str_hash
11298 = hash_table
<indirect_string_hasher
>::create_ggc (10);
11300 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
11301 find_string_form (node
);
11302 if (node
->form
== dwarf_FORM (DW_FORM_strx
))
11303 node
->form
= DW_FORM_strp
;
11305 attr
.dw_attr
= attr_kind
;
11306 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
11307 attr
.dw_attr_val
.val_entry
= NULL
;
11308 attr
.dw_attr_val
.v
.val_str
= node
;
11309 add_dwarf_attr (die
, &attr
);
11312 /* Helper function to generate top-level dies for skeleton debug_info and
11316 add_top_level_skeleton_die_attrs (dw_die_ref die
)
11318 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
11319 const char *comp_dir
= comp_dir_string ();
11321 add_skeleton_AT_string (die
, dwarf_AT (DW_AT_dwo_name
), dwo_file_name
);
11322 if (comp_dir
!= NULL
)
11323 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
11324 add_AT_pubnames (die
);
11325 if (addr_index_table
!= NULL
&& addr_index_table
->size () > 0)
11326 add_AT_lineptr (die
, dwarf_AT (DW_AT_addr_base
), debug_addr_section_label
);
11329 /* Output skeleton debug sections that point to the dwo file. */
11332 output_skeleton_debug_sections (dw_die_ref comp_unit
,
11333 const unsigned char *dwo_id
)
11335 /* These attributes will be found in the full debug_info section. */
11336 remove_AT (comp_unit
, DW_AT_producer
);
11337 remove_AT (comp_unit
, DW_AT_language
);
11339 switch_to_section (debug_skeleton_info_section
);
11340 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
11342 /* Produce the skeleton compilation-unit header. This one differs enough from
11343 a normal CU header that it's better not to call output_compilation_unit
11345 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
11346 dw2_asm_output_data (4, 0xffffffff,
11347 "Initial length escape value indicating 64-bit "
11348 "DWARF extension");
11350 dw2_asm_output_data (dwarf_offset_size
,
11351 DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
11352 - DWARF_INITIAL_LENGTH_SIZE
11353 + size_of_die (comp_unit
),
11354 "Length of Compilation Unit Info");
11355 output_dwarf_version ();
11356 if (dwarf_version
>= 5)
11358 dw2_asm_output_data (1, DW_UT_skeleton
, "DW_UT_skeleton");
11359 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
11361 dw2_asm_output_offset (dwarf_offset_size
, debug_skeleton_abbrev_section_label
,
11362 debug_skeleton_abbrev_section
,
11363 "Offset Into Abbrev. Section");
11364 if (dwarf_version
< 5)
11365 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
11367 for (int i
= 0; i
< 8; i
++)
11368 dw2_asm_output_data (1, dwo_id
[i
], i
== 0 ? "DWO id" : NULL
);
11370 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
11371 output_die (comp_unit
);
11373 /* Build the skeleton debug_abbrev section. */
11374 switch_to_section (debug_skeleton_abbrev_section
);
11375 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
11377 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
11379 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
11382 /* Output a comdat type unit DIE and its children. */
11385 output_comdat_type_unit (comdat_type_node
*node
,
11386 bool early_lto_debug ATTRIBUTE_UNUSED
)
11388 const char *secname
;
11391 #if defined (OBJECT_FORMAT_ELF)
11395 /* First mark all the DIEs in this CU so we know which get local refs. */
11396 mark_dies (node
->root_die
);
11398 external_ref_hash_type
*extern_map
= optimize_external_refs (node
->root_die
);
11400 build_abbrev_table (node
->root_die
, extern_map
);
11405 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11406 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
11407 calc_die_sizes (node
->root_die
);
11409 #if defined (OBJECT_FORMAT_ELF)
11410 if (dwarf_version
>= 5)
11412 if (!dwarf_split_debug_info
)
11413 secname
= early_lto_debug
? DEBUG_LTO_INFO_SECTION
: DEBUG_INFO_SECTION
;
11415 secname
= (early_lto_debug
11416 ? DEBUG_LTO_DWO_INFO_SECTION
: DEBUG_DWO_INFO_SECTION
);
11418 else if (!dwarf_split_debug_info
)
11419 secname
= early_lto_debug
? ".gnu.debuglto_.debug_types" : ".debug_types";
11421 secname
= (early_lto_debug
11422 ? ".gnu.debuglto_.debug_types.dwo" : ".debug_types.dwo");
11424 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
11425 sprintf (tmp
, dwarf_version
>= 5 ? "wi." : "wt.");
11426 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
11427 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
11428 comdat_key
= get_identifier (tmp
);
11429 targetm
.asm_out
.named_section (secname
,
11430 SECTION_DEBUG
| SECTION_LINKONCE
,
11433 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
11434 sprintf (tmp
, (dwarf_version
>= 5
11435 ? ".gnu.linkonce.wi." : ".gnu.linkonce.wt."));
11436 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
11437 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
11439 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
11442 /* Output debugging information. */
11443 output_compilation_unit_header (dwarf_split_debug_info
11444 ? DW_UT_split_type
: DW_UT_type
);
11445 output_signature (node
->signature
, "Type Signature");
11446 dw2_asm_output_data (dwarf_offset_size
, node
->type_die
->die_offset
,
11447 "Offset to Type DIE");
11448 output_die (node
->root_die
);
11450 unmark_dies (node
->root_die
);
11453 /* Return the DWARF2/3 pubname associated with a decl. */
11455 static const char *
11456 dwarf2_name (tree decl
, int scope
)
11458 if (DECL_NAMELESS (decl
))
11460 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
11463 /* Add a new entry to .debug_pubnames if appropriate. */
11466 add_pubname_string (const char *str
, dw_die_ref die
)
11471 e
.name
= xstrdup (str
);
11472 vec_safe_push (pubname_table
, e
);
11476 add_pubname (tree decl
, dw_die_ref die
)
11478 if (!want_pubnames ())
11481 /* Don't add items to the table when we expect that the consumer will have
11482 just read the enclosing die. For example, if the consumer is looking at a
11483 class_member, it will either be inside the class already, or will have just
11484 looked up the class to find the member. Either way, searching the class is
11485 faster than searching the index. */
11486 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
11487 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
11489 const char *name
= dwarf2_name (decl
, 1);
11492 add_pubname_string (name
, die
);
11496 /* Add an enumerator to the pubnames section. */
11499 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
11503 gcc_assert (scope_name
);
11504 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
11506 vec_safe_push (pubname_table
, e
);
11509 /* Add a new entry to .debug_pubtypes if appropriate. */
11512 add_pubtype (tree decl
, dw_die_ref die
)
11516 if (!want_pubnames ())
11519 if ((TREE_PUBLIC (decl
)
11520 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
11521 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
11524 const char *scope_name
= "";
11525 const char *sep
= is_cxx () ? "::" : ".";
11528 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
11529 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
11531 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
11532 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
11533 scope_name
= concat (scope_name
, sep
, NULL
);
11539 name
= type_tag (decl
);
11541 name
= lang_hooks
.dwarf_name (decl
, 1);
11543 /* If we don't have a name for the type, there's no point in adding
11544 it to the table. */
11545 if (name
!= NULL
&& name
[0] != '\0')
11548 e
.name
= concat (scope_name
, name
, NULL
);
11549 vec_safe_push (pubtype_table
, e
);
11552 /* Although it might be more consistent to add the pubinfo for the
11553 enumerators as their dies are created, they should only be added if the
11554 enum type meets the criteria above. So rather than re-check the parent
11555 enum type whenever an enumerator die is created, just output them all
11556 here. This isn't protected by the name conditional because anonymous
11557 enums don't have names. */
11558 if (die
->die_tag
== DW_TAG_enumeration_type
)
11562 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
11567 /* Output a single entry in the pubnames table. */
11570 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
11572 dw_die_ref die
= entry
->die
;
11573 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
11575 dw2_asm_output_data (dwarf_offset_size
, die_offset
, "DIE offset");
11577 if (debug_generate_pub_sections
== 2)
11579 /* This logic follows gdb's method for determining the value of the flag
11581 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
11582 switch (die
->die_tag
)
11584 case DW_TAG_typedef
:
11585 case DW_TAG_base_type
:
11586 case DW_TAG_subrange_type
:
11587 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
11588 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
11590 case DW_TAG_enumerator
:
11591 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
11592 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
11594 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
11596 case DW_TAG_subprogram
:
11597 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
11598 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
11600 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
11602 case DW_TAG_constant
:
11603 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
11604 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
11605 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
11607 case DW_TAG_variable
:
11608 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
11609 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
11610 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
11612 case DW_TAG_namespace
:
11613 case DW_TAG_imported_declaration
:
11614 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
11616 case DW_TAG_class_type
:
11617 case DW_TAG_interface_type
:
11618 case DW_TAG_structure_type
:
11619 case DW_TAG_union_type
:
11620 case DW_TAG_enumeration_type
:
11621 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
11623 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
11626 /* An unusual tag. Leave the flag-byte empty. */
11629 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
11630 "GDB-index flags");
11633 dw2_asm_output_nstring (entry
->name
, -1, "external name");
11637 /* Output the public names table used to speed up access to externally
11638 visible names; or the public types table used to find type definitions. */
11641 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
11644 unsigned long pubnames_length
= size_of_pubnames (names
);
11645 pubname_entry
*pub
;
11647 if (!XCOFF_DEBUGGING_INFO
)
11649 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
11650 dw2_asm_output_data (4, 0xffffffff,
11651 "Initial length escape value indicating 64-bit DWARF extension");
11652 dw2_asm_output_data (dwarf_offset_size
, pubnames_length
,
11653 "Pub Info Length");
11656 /* Version number for pubnames/pubtypes is independent of dwarf version. */
11657 dw2_asm_output_data (2, 2, "DWARF pubnames/pubtypes version");
11659 if (dwarf_split_debug_info
)
11660 dw2_asm_output_offset (dwarf_offset_size
, debug_skeleton_info_section_label
,
11661 debug_skeleton_info_section
,
11662 "Offset of Compilation Unit Info");
11664 dw2_asm_output_offset (dwarf_offset_size
, debug_info_section_label
,
11665 debug_info_section
,
11666 "Offset of Compilation Unit Info");
11667 dw2_asm_output_data (dwarf_offset_size
, next_die_offset
,
11668 "Compilation Unit Length");
11670 FOR_EACH_VEC_ELT (*names
, i
, pub
)
11672 if (include_pubname_in_output (names
, pub
))
11674 dw_offset die_offset
= pub
->die
->die_offset
;
11676 /* We shouldn't see pubnames for DIEs outside of the main CU. */
11677 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
11678 gcc_assert (pub
->die
->die_mark
);
11680 /* If we're putting types in their own .debug_types sections,
11681 the .debug_pubtypes table will still point to the compile
11682 unit (not the type unit), so we want to use the offset of
11683 the skeleton DIE (if there is one). */
11684 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
11686 comdat_type_node
*type_node
= pub
->die
->die_id
.die_type_node
;
11688 if (type_node
!= NULL
)
11689 die_offset
= (type_node
->skeleton_die
!= NULL
11690 ? type_node
->skeleton_die
->die_offset
11691 : comp_unit_die ()->die_offset
);
11694 output_pubname (die_offset
, pub
);
11698 dw2_asm_output_data (dwarf_offset_size
, 0, NULL
);
11701 /* Output public names and types tables if necessary. */
11704 output_pubtables (void)
11706 if (!want_pubnames () || !info_section_emitted
)
11709 switch_to_section (debug_pubnames_section
);
11710 output_pubnames (pubname_table
);
11711 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
11712 It shouldn't hurt to emit it always, since pure DWARF2 consumers
11713 simply won't look for the section. */
11714 switch_to_section (debug_pubtypes_section
);
11715 output_pubnames (pubtype_table
);
11719 /* Output the information that goes into the .debug_aranges table.
11720 Namely, define the beginning and ending address range of the
11721 text section generated for this compilation unit. */
11724 output_aranges (void)
11727 unsigned long aranges_length
= size_of_aranges ();
11729 if (!XCOFF_DEBUGGING_INFO
)
11731 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
11732 dw2_asm_output_data (4, 0xffffffff,
11733 "Initial length escape value indicating 64-bit DWARF extension");
11734 dw2_asm_output_data (dwarf_offset_size
, aranges_length
,
11735 "Length of Address Ranges Info");
11738 /* Version number for aranges is still 2, even up to DWARF5. */
11739 dw2_asm_output_data (2, 2, "DWARF aranges version");
11740 if (dwarf_split_debug_info
)
11741 dw2_asm_output_offset (dwarf_offset_size
, debug_skeleton_info_section_label
,
11742 debug_skeleton_info_section
,
11743 "Offset of Compilation Unit Info");
11745 dw2_asm_output_offset (dwarf_offset_size
, debug_info_section_label
,
11746 debug_info_section
,
11747 "Offset of Compilation Unit Info");
11748 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
11749 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
11751 /* We need to align to twice the pointer size here. */
11752 if (DWARF_ARANGES_PAD_SIZE
)
11754 /* Pad using a 2 byte words so that padding is correct for any
11756 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
11757 2 * DWARF2_ADDR_SIZE
);
11758 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
11759 dw2_asm_output_data (2, 0, NULL
);
11762 /* It is necessary not to output these entries if the sections were
11763 not used; if the sections were not used, the length will be 0 and
11764 the address may end up as 0 if the section is discarded by ld
11765 --gc-sections, leaving an invalid (0, 0) entry that can be
11766 confused with the terminator. */
11767 if (switch_text_ranges
)
11769 const char *prev_loc
= text_section_label
;
11773 FOR_EACH_VEC_ELT (*switch_text_ranges
, idx
, loc
)
11776 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, prev_loc
, "Address");
11777 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, loc
, prev_loc
, "Length");
11785 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, prev_loc
, "Address");
11786 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
11787 prev_loc
, "Length");
11791 if (switch_cold_ranges
)
11793 const char *prev_loc
= cold_text_section_label
;
11797 FOR_EACH_VEC_ELT (*switch_cold_ranges
, idx
, loc
)
11800 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, prev_loc
, "Address");
11801 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, loc
, prev_loc
, "Length");
11809 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, prev_loc
, "Address");
11810 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
11811 prev_loc
, "Length");
11815 if (have_multiple_function_sections
)
11820 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
11822 if (fde
->ignored_debug
)
11824 if (!fde
->in_std_section
)
11826 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
11828 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
11829 fde
->dw_fde_begin
, "Length");
11831 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
11833 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
11835 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
11836 fde
->dw_fde_second_begin
, "Length");
11841 /* Output the terminator words. */
11842 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11843 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11846 /* Add a new entry to .debug_ranges. Return its index into
11847 ranges_table vector. */
11849 static unsigned int
11850 add_ranges_num (int num
, bool maybe_new_sec
)
11852 dw_ranges r
= { NULL
, num
, 0, maybe_new_sec
, NULL
, NULL
};
11853 vec_safe_push (ranges_table
, r
);
11854 return vec_safe_length (ranges_table
) - 1;
11857 /* Add a new entry to .debug_ranges corresponding to a block, or a
11858 range terminator if BLOCK is NULL. MAYBE_NEW_SEC is true if
11859 this entry might be in a different section from previous range. */
11861 static unsigned int
11862 add_ranges (const_tree block
, bool maybe_new_sec
)
11864 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0, maybe_new_sec
);
11867 /* Note that (*rnglist_table)[offset] is either a head of a rnglist
11868 chain, or middle entry of a chain that will be directly referred to. */
11871 note_rnglist_head (unsigned int offset
)
11873 if (dwarf_version
< 5 || (*ranges_table
)[offset
].label
)
11875 (*ranges_table
)[offset
].label
= gen_internal_sym ("LLRL");
11878 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
11879 When using dwarf_split_debug_info, address attributes in dies destined
11880 for the final executable should be direct references--setting the
11881 parameter force_direct ensures this behavior. */
11884 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
11885 bool *added
, bool force_direct
)
11887 unsigned int in_use
= vec_safe_length (ranges_by_label
);
11888 unsigned int offset
;
11889 dw_ranges_by_label rbl
= { begin
, end
};
11890 vec_safe_push (ranges_by_label
, rbl
);
11891 offset
= add_ranges_num (-(int)in_use
- 1, true);
11894 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
11896 note_rnglist_head (offset
);
11897 if (dwarf_split_debug_info
&& force_direct
)
11898 (*ranges_table
)[offset
].idx
= DW_RANGES_IDX_SKELETON
;
11902 /* Emit .debug_ranges section. */
11905 output_ranges (void)
11908 static const char *const start_fmt
= "Offset %#x";
11909 const char *fmt
= start_fmt
;
11912 switch_to_section (debug_ranges_section
);
11913 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
11914 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11916 int block_num
= r
->num
;
11920 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11921 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11923 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
11924 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
11926 /* If all code is in the text section, then the compilation
11927 unit base address defaults to DW_AT_low_pc, which is the
11928 base of the text section. */
11929 if (!have_multiple_function_sections
)
11931 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
11932 text_section_label
,
11933 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11934 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
11935 text_section_label
, NULL
);
11938 /* Otherwise, the compilation unit base address is zero,
11939 which allows us to use absolute addresses, and not worry
11940 about whether the target supports cross-section
11944 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11945 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11946 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
11952 /* Negative block_num stands for an index into ranges_by_label. */
11953 else if (block_num
< 0)
11955 int lab_idx
= - block_num
- 1;
11957 if (!have_multiple_function_sections
)
11959 gcc_unreachable ();
11961 /* If we ever use add_ranges_by_labels () for a single
11962 function section, all we have to do is to take out
11963 the #if 0 above. */
11964 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11965 (*ranges_by_label
)[lab_idx
].begin
,
11966 text_section_label
,
11967 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11968 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11969 (*ranges_by_label
)[lab_idx
].end
,
11970 text_section_label
, NULL
);
11975 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11976 (*ranges_by_label
)[lab_idx
].begin
,
11977 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11978 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11979 (*ranges_by_label
)[lab_idx
].end
,
11985 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11986 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11992 /* Non-zero if .debug_line_str should be used for .debug_line section
11993 strings or strings that are likely shareable with those. */
11994 #define DWARF5_USE_DEBUG_LINE_STR \
11995 (!DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET \
11996 && (DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) != 0 \
11997 /* FIXME: there is no .debug_line_str.dwo section, \
11998 for -gsplit-dwarf we should use DW_FORM_strx instead. */ \
11999 && !dwarf_split_debug_info)
12002 /* Returns TRUE if we are outputting DWARF5 and the assembler supports
12003 DWARF5 .debug_line tables using .debug_line_str or we generate
12004 it ourselves, except for split-dwarf which doesn't have a
12005 .debug_line_str. */
12007 asm_outputs_debug_line_str (void)
12009 if (dwarf_version
>= 5
12010 && ! output_asm_line_debug_info ()
12011 && DWARF5_USE_DEBUG_LINE_STR
)
12015 #if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG)
12016 return !dwarf_split_debug_info
&& dwarf_version
>= 5;
12023 /* Return true if it is beneficial to use DW_RLE_base_address{,x}.
12024 I is index of the following range. */
12027 use_distinct_base_address_for_range (unsigned int i
)
12029 if (i
>= vec_safe_length (ranges_table
))
12032 dw_ranges
*r2
= &(*ranges_table
)[i
];
12033 /* Use DW_RLE_base_address{,x} if there is a next range in the
12034 range list and is guaranteed to be in the same section. */
12035 return r2
->num
!= 0 && r2
->label
== NULL
&& !r2
->maybe_new_sec
;
12038 /* Assign .debug_rnglists indexes and unique indexes into the debug_addr
12039 section when needed. */
12042 index_rnglists (void)
12048 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
12050 if (r
->label
&& r
->idx
!= DW_RANGES_IDX_SKELETON
)
12051 r
->idx
= rnglist_idx
++;
12053 if (!have_multiple_function_sections
)
12055 int block_num
= r
->num
;
12056 if (HAVE_AS_LEB128
&& (r
->label
|| r
->maybe_new_sec
))
12060 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
12061 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
12063 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
12064 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
12066 if (HAVE_AS_LEB128
)
12068 if (!base
&& use_distinct_base_address_for_range (i
+ 1))
12070 r
->begin_entry
= add_addr_table_entry (xstrdup (blabel
),
12075 /* If we have a base, no need for further
12076 begin_entry/end_entry, as DW_RLE_offset_pair will be
12080 = add_addr_table_entry (xstrdup (blabel
), ate_kind_label
);
12081 /* No need for end_entry, DW_RLE_start{,x}_length will use
12082 length as opposed to a pair of addresses. */
12087 = add_addr_table_entry (xstrdup (blabel
), ate_kind_label
);
12089 = add_addr_table_entry (xstrdup (elabel
), ate_kind_label
);
12093 /* Negative block_num stands for an index into ranges_by_label. */
12094 else if (block_num
< 0)
12096 int lab_idx
= - block_num
- 1;
12097 const char *blabel
= (*ranges_by_label
)[lab_idx
].begin
;
12098 const char *elabel
= (*ranges_by_label
)[lab_idx
].end
;
12101 = add_addr_table_entry (xstrdup (blabel
), ate_kind_label
);
12102 if (!HAVE_AS_LEB128
)
12104 = add_addr_table_entry (xstrdup (elabel
), ate_kind_label
);
12109 /* Emit .debug_rnglists or (when DWO is true) .debug_rnglists.dwo section. */
12112 output_rnglists (unsigned generation
, bool dwo
)
12116 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
12117 char l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
12118 char basebuf
[MAX_ARTIFICIAL_LABEL_BYTES
];
12121 switch_to_section (debug_ranges_dwo_section
);
12124 switch_to_section (debug_ranges_section
);
12125 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
12127 /* There are up to 4 unique ranges labels per generation.
12128 See also init_sections_and_labels. */
12129 ASM_GENERATE_INTERNAL_LABEL (l1
, DEBUG_RANGES_SECTION_LABEL
,
12130 2 + 2 * dwo
+ generation
* 6);
12131 ASM_GENERATE_INTERNAL_LABEL (l2
, DEBUG_RANGES_SECTION_LABEL
,
12132 3 + 2 * dwo
+ generation
* 6);
12133 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
12134 dw2_asm_output_data (4, 0xffffffff,
12135 "Initial length escape value indicating "
12136 "64-bit DWARF extension");
12137 dw2_asm_output_delta (dwarf_offset_size
, l2
, l1
,
12138 "Length of Range Lists");
12139 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
12140 output_dwarf_version ();
12141 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
12142 dw2_asm_output_data (1, 0, "Segment Size");
12143 /* Emit the offset table only for -gsplit-dwarf. If we don't care
12144 about relocation sizes and primarily care about the size of .debug*
12145 sections in linked shared libraries and executables, then
12146 the offset table plus corresponding DW_FORM_rnglistx uleb128 indexes
12147 into it are usually larger than just DW_FORM_sec_offset offsets
12148 into the .debug_rnglists section. */
12149 dw2_asm_output_data (4, dwo
? rnglist_idx
: 0,
12150 "Offset Entry Count");
12153 ASM_OUTPUT_LABEL (asm_out_file
, ranges_base_label
);
12154 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
12155 if (r
->label
&& r
->idx
!= DW_RANGES_IDX_SKELETON
)
12156 dw2_asm_output_delta (dwarf_offset_size
, r
->label
,
12157 ranges_base_label
, NULL
);
12160 const char *lab
= "";
12161 const char *base
= NULL
;
12162 bool skipping
= false;
12164 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
12166 int block_num
= r
->num
;
12170 if (dwarf_split_debug_info
12171 && (r
->idx
== DW_RANGES_IDX_SKELETON
) == dwo
)
12177 ASM_OUTPUT_LABEL (asm_out_file
, r
->label
);
12182 if (block_num
== 0)
12186 if (HAVE_AS_LEB128
&& (r
->label
|| r
->maybe_new_sec
))
12190 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
12191 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
12193 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
12194 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
12196 if (HAVE_AS_LEB128
)
12198 /* If all code is in the text section, then the compilation
12199 unit base address defaults to DW_AT_low_pc, which is the
12200 base of the text section. */
12201 if (!have_multiple_function_sections
)
12203 dw2_asm_output_data (1, DW_RLE_offset_pair
,
12204 "DW_RLE_offset_pair (%s)", lab
);
12205 dw2_asm_output_delta_uleb128 (blabel
, text_section_label
,
12206 "Range begin address (%s)", lab
);
12207 dw2_asm_output_delta_uleb128 (elabel
, text_section_label
,
12208 "Range end address (%s)", lab
);
12211 if (base
== NULL
&& use_distinct_base_address_for_range (i
+ 1))
12213 if (dwarf_split_debug_info
)
12215 dw2_asm_output_data (1, DW_RLE_base_addressx
,
12216 "DW_RLE_base_addressx (%s)", lab
);
12217 dw2_asm_output_data_uleb128 (r
->begin_entry
->index
,
12218 "Base address index (%s)",
12223 dw2_asm_output_data (1, DW_RLE_base_address
,
12224 "DW_RLE_base_address (%s)", lab
);
12225 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
12226 "Base address (%s)", lab
);
12228 strcpy (basebuf
, blabel
);
12233 dw2_asm_output_data (1, DW_RLE_offset_pair
,
12234 "DW_RLE_offset_pair (%s)", lab
);
12235 dw2_asm_output_delta_uleb128 (blabel
, base
,
12236 "Range begin address (%s)", lab
);
12237 dw2_asm_output_delta_uleb128 (elabel
, base
,
12238 "Range end address (%s)", lab
);
12241 if (dwarf_split_debug_info
)
12243 dw2_asm_output_data (1, DW_RLE_startx_length
,
12244 "DW_RLE_startx_length (%s)", lab
);
12245 dw2_asm_output_data_uleb128 (r
->begin_entry
->index
,
12246 "Range begin address index "
12251 dw2_asm_output_data (1, DW_RLE_start_length
,
12252 "DW_RLE_start_length (%s)", lab
);
12253 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
12254 "Range begin address (%s)", lab
);
12256 dw2_asm_output_delta_uleb128 (elabel
, blabel
,
12257 "Range length (%s)", lab
);
12259 else if (dwarf_split_debug_info
)
12261 dw2_asm_output_data (1, DW_RLE_startx_endx
,
12262 "DW_RLE_startx_endx (%s)", lab
);
12263 dw2_asm_output_data_uleb128 (r
->begin_entry
->index
,
12264 "Range begin address index "
12266 dw2_asm_output_data_uleb128 (r
->end_entry
->index
,
12267 "Range end address index "
12272 dw2_asm_output_data (1, DW_RLE_start_end
,
12273 "DW_RLE_start_end (%s)", lab
);
12274 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
12275 "Range begin address (%s)", lab
);
12276 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
,
12277 "Range end address (%s)", lab
);
12281 /* Negative block_num stands for an index into ranges_by_label. */
12282 else if (block_num
< 0)
12284 int lab_idx
= - block_num
- 1;
12285 const char *blabel
= (*ranges_by_label
)[lab_idx
].begin
;
12286 const char *elabel
= (*ranges_by_label
)[lab_idx
].end
;
12288 if (!have_multiple_function_sections
)
12289 gcc_unreachable ();
12290 if (HAVE_AS_LEB128
)
12292 if (dwarf_split_debug_info
)
12294 dw2_asm_output_data (1, DW_RLE_startx_length
,
12295 "DW_RLE_startx_length (%s)", lab
);
12296 dw2_asm_output_data_uleb128 (r
->begin_entry
->index
,
12297 "Range begin address index "
12302 dw2_asm_output_data (1, DW_RLE_start_length
,
12303 "DW_RLE_start_length (%s)", lab
);
12304 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
12305 "Range begin address (%s)", lab
);
12307 dw2_asm_output_delta_uleb128 (elabel
, blabel
,
12308 "Range length (%s)", lab
);
12310 else if (dwarf_split_debug_info
)
12312 dw2_asm_output_data (1, DW_RLE_startx_endx
,
12313 "DW_RLE_startx_endx (%s)", lab
);
12314 dw2_asm_output_data_uleb128 (r
->begin_entry
->index
,
12315 "Range begin address index "
12317 dw2_asm_output_data_uleb128 (r
->end_entry
->index
,
12318 "Range end address index "
12323 dw2_asm_output_data (1, DW_RLE_start_end
,
12324 "DW_RLE_start_end (%s)", lab
);
12325 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
12326 "Range begin address (%s)", lab
);
12327 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
,
12328 "Range end address (%s)", lab
);
12332 dw2_asm_output_data (1, DW_RLE_end_of_list
,
12333 "DW_RLE_end_of_list (%s)", lab
);
12335 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
12339 /* Data structure containing information about input files. */
12342 const char *path
; /* Complete file name. */
12343 const char *fname
; /* File name part. */
12344 int length
; /* Length of entire string. */
12345 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
12346 int dir_idx
; /* Index in directory table. */
12349 /* Data structure containing information about directories with source
12353 const char *path
; /* Path including directory name. */
12354 int length
; /* Path length. */
12355 int prefix
; /* Index of directory entry which is a prefix. */
12356 int count
; /* Number of files in this directory. */
12357 int dir_idx
; /* Index of directory used as base. */
12360 /* Callback function for file_info comparison. We sort by looking at
12361 the directories in the path. */
12364 file_info_cmp (const void *p1
, const void *p2
)
12366 const struct file_info
*const s1
= (const struct file_info
*) p1
;
12367 const struct file_info
*const s2
= (const struct file_info
*) p2
;
12368 const unsigned char *cp1
;
12369 const unsigned char *cp2
;
12371 /* Take care of file names without directories. We need to make sure that
12372 we return consistent values to qsort since some will get confused if
12373 we return the same value when identical operands are passed in opposite
12374 orders. So if neither has a directory, return 0 and otherwise return
12375 1 or -1 depending on which one has the directory. We want the one with
12376 the directory to sort after the one without, so all no directory files
12377 are at the start (normally only the compilation unit file). */
12378 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
12379 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
12381 cp1
= (const unsigned char *) s1
->path
;
12382 cp2
= (const unsigned char *) s2
->path
;
12388 /* Reached the end of the first path? If so, handle like above,
12389 but now we want longer directory prefixes before shorter ones. */
12390 if ((cp1
== (const unsigned char *) s1
->fname
)
12391 || (cp2
== (const unsigned char *) s2
->fname
))
12392 return ((cp1
== (const unsigned char *) s1
->fname
)
12393 - (cp2
== (const unsigned char *) s2
->fname
));
12395 /* Character of current path component the same? */
12396 else if (*cp1
!= *cp2
)
12397 return *cp1
- *cp2
;
12401 struct file_name_acquire_data
12403 struct file_info
*files
;
12408 /* Traversal function for the hash table. */
12411 file_name_acquire (dwarf_file_data
**slot
, file_name_acquire_data
*fnad
)
12413 struct dwarf_file_data
*d
= *slot
;
12414 struct file_info
*fi
;
12417 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
12419 if (! d
->emitted_number
)
12422 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
12424 fi
= fnad
->files
+ fnad
->used_files
++;
12428 /* Skip all leading "./". */
12429 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
12432 /* Create a new array entry. */
12434 fi
->length
= strlen (f
);
12437 /* Search for the file name part. */
12438 f
= strrchr (f
, DIR_SEPARATOR
);
12439 #if defined (DIR_SEPARATOR_2)
12441 const char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
12445 if (f
== NULL
|| f
< g
)
12451 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
12455 /* Helper function for output_file_names. Emit a FORM encoded
12456 string STR, with assembly comment start ENTRY_KIND and
12460 output_line_string (enum dwarf_form form
, const char *str
,
12461 const char *entry_kind
, unsigned int idx
)
12465 case DW_FORM_string
:
12466 dw2_asm_output_nstring (str
, -1, "%s: %#x", entry_kind
, idx
);
12468 case DW_FORM_line_strp
:
12469 if (!debug_line_str_hash
)
12470 debug_line_str_hash
12471 = hash_table
<indirect_string_hasher
>::create_ggc (10);
12473 struct indirect_string_node
*node
;
12474 node
= find_AT_string_in_table (str
, debug_line_str_hash
);
12475 set_indirect_string (node
);
12477 dw2_asm_output_offset (dwarf_offset_size
, node
->label
,
12478 debug_line_str_section
, "%s: %#x: \"%s\"",
12479 entry_kind
, 0, node
->str
);
12482 gcc_unreachable ();
12486 /* Output the directory table and the file name table. We try to minimize
12487 the total amount of memory needed. A heuristic is used to avoid large
12488 slowdowns with many input files. */
12491 output_file_names (void)
12493 struct file_name_acquire_data fnad
;
12495 struct file_info
*files
;
12496 struct dir_info
*dirs
;
12504 if (!last_emitted_file
)
12506 if (dwarf_version
>= 5)
12508 const char *comp_dir
= comp_dir_string ();
12509 if (comp_dir
== NULL
)
12511 dw2_asm_output_data (1, 1, "Directory entry format count");
12512 enum dwarf_form str_form
= DW_FORM_string
;
12513 if (DWARF5_USE_DEBUG_LINE_STR
)
12514 str_form
= DW_FORM_line_strp
;
12515 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
12516 dw2_asm_output_data_uleb128 (str_form
, "%s",
12517 get_DW_FORM_name (str_form
));
12518 dw2_asm_output_data_uleb128 (1, "Directories count");
12519 if (str_form
== DW_FORM_string
)
12520 dw2_asm_output_nstring (comp_dir
, -1, "Directory Entry: %#x", 0);
12522 output_line_string (str_form
, comp_dir
, "Directory Entry", 0);
12523 const char *filename0
= get_AT_string (comp_unit_die (), DW_AT_name
);
12524 if (filename0
== NULL
)
12526 #ifdef VMS_DEBUGGING_INFO
12527 dw2_asm_output_data (1, 4, "File name entry format count");
12529 dw2_asm_output_data (1, 2, "File name entry format count");
12531 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
12532 dw2_asm_output_data_uleb128 (str_form
, "%s",
12533 get_DW_FORM_name (str_form
));
12534 dw2_asm_output_data_uleb128 (DW_LNCT_directory_index
,
12535 "DW_LNCT_directory_index");
12536 dw2_asm_output_data_uleb128 (DW_FORM_data1
, "%s",
12537 get_DW_FORM_name (DW_FORM_data1
));
12538 #ifdef VMS_DEBUGGING_INFO
12539 dw2_asm_output_data_uleb128 (DW_LNCT_timestamp
, "DW_LNCT_timestamp");
12540 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
12541 dw2_asm_output_data_uleb128 (DW_LNCT_size
, "DW_LNCT_size");
12542 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
12544 dw2_asm_output_data_uleb128 (1, "File names count");
12546 output_line_string (str_form
, filename0
, "File Entry", 0);
12547 dw2_asm_output_data (1, 0, NULL
);
12548 #ifdef VMS_DEBUGGING_INFO
12549 dw2_asm_output_data_uleb128 (0, NULL
);
12550 dw2_asm_output_data_uleb128 (0, NULL
);
12555 dw2_asm_output_data (1, 0, "End directory table");
12556 dw2_asm_output_data (1, 0, "End file name table");
12561 numfiles
= last_emitted_file
->emitted_number
;
12563 /* Allocate the various arrays we need. */
12564 files
= XALLOCAVEC (struct file_info
, numfiles
);
12565 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
12567 fnad
.files
= files
;
12568 fnad
.used_files
= 0;
12569 fnad
.max_files
= numfiles
;
12570 file_table
->traverse
<file_name_acquire_data
*, file_name_acquire
> (&fnad
);
12571 gcc_assert (fnad
.used_files
== fnad
.max_files
);
12573 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
12575 /* Find all the different directories used. */
12576 dirs
[0].path
= files
[0].path
;
12577 dirs
[0].length
= files
[0].fname
- files
[0].path
;
12578 dirs
[0].prefix
= -1;
12580 dirs
[0].dir_idx
= 0;
12581 files
[0].dir_idx
= 0;
12584 for (i
= 1; i
< numfiles
; i
++)
12585 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
12586 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
12587 dirs
[ndirs
- 1].length
) == 0)
12589 /* Same directory as last entry. */
12590 files
[i
].dir_idx
= ndirs
- 1;
12591 ++dirs
[ndirs
- 1].count
;
12597 /* This is a new directory. */
12598 dirs
[ndirs
].path
= files
[i
].path
;
12599 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
12600 dirs
[ndirs
].count
= 1;
12601 dirs
[ndirs
].dir_idx
= ndirs
;
12602 files
[i
].dir_idx
= ndirs
;
12604 /* Search for a prefix. */
12605 dirs
[ndirs
].prefix
= -1;
12606 for (j
= 0; j
< ndirs
; j
++)
12607 if (dirs
[j
].length
< dirs
[ndirs
].length
12608 && dirs
[j
].length
> 1
12609 && (dirs
[ndirs
].prefix
== -1
12610 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
12611 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
12612 dirs
[ndirs
].prefix
= j
;
12617 /* Now to the actual work. We have to find a subset of the directories which
12618 allow expressing the file name using references to the directory table
12619 with the least amount of characters. We do not do an exhaustive search
12620 where we would have to check out every combination of every single
12621 possible prefix. Instead we use a heuristic which provides nearly optimal
12622 results in most cases and never is much off. */
12623 saved
= XALLOCAVEC (int, ndirs
);
12624 savehere
= XALLOCAVEC (int, ndirs
);
12626 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
12627 for (i
= 0; i
< ndirs
; i
++)
12632 /* We can always save some space for the current directory. But this
12633 does not mean it will be enough to justify adding the directory. */
12634 savehere
[i
] = dirs
[i
].length
;
12635 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
12637 for (j
= i
+ 1; j
< ndirs
; j
++)
12640 if (saved
[j
] < dirs
[i
].length
)
12642 /* Determine whether the dirs[i] path is a prefix of the
12646 k
= dirs
[j
].prefix
;
12647 while (k
!= -1 && k
!= (int) i
)
12648 k
= dirs
[k
].prefix
;
12652 /* Yes it is. We can possibly save some memory by
12653 writing the filenames in dirs[j] relative to
12655 savehere
[j
] = dirs
[i
].length
;
12656 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
12661 /* Check whether we can save enough to justify adding the dirs[i]
12663 if (total
> dirs
[i
].length
+ 1)
12665 /* It's worthwhile adding. */
12666 for (j
= i
; j
< ndirs
; j
++)
12667 if (savehere
[j
] > 0)
12669 /* Remember how much we saved for this directory so far. */
12670 saved
[j
] = savehere
[j
];
12672 /* Remember the prefix directory. */
12673 dirs
[j
].dir_idx
= i
;
12678 /* Emit the directory name table. */
12679 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
12680 enum dwarf_form str_form
= DW_FORM_string
;
12681 enum dwarf_form idx_form
= DW_FORM_udata
;
12682 if (dwarf_version
>= 5)
12684 const char *comp_dir
= comp_dir_string ();
12685 if (comp_dir
== NULL
)
12687 dw2_asm_output_data (1, 1, "Directory entry format count");
12688 if (DWARF5_USE_DEBUG_LINE_STR
)
12689 str_form
= DW_FORM_line_strp
;
12690 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
12691 dw2_asm_output_data_uleb128 (str_form
, "%s",
12692 get_DW_FORM_name (str_form
));
12693 dw2_asm_output_data_uleb128 (ndirs
+ idx_offset
, "Directories count");
12694 if (str_form
== DW_FORM_string
)
12696 dw2_asm_output_nstring (comp_dir
, -1, "Directory Entry: %#x", 0);
12697 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
12698 dw2_asm_output_nstring (dirs
[i
].path
,
12700 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
12701 "Directory Entry: %#x", i
+ idx_offset
);
12705 output_line_string (str_form
, comp_dir
, "Directory Entry", 0);
12706 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
12709 = ggc_alloc_string (dirs
[i
].path
,
12711 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
);
12712 output_line_string (str_form
, str
, "Directory Entry",
12713 (unsigned) i
+ idx_offset
);
12719 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
12720 dw2_asm_output_nstring (dirs
[i
].path
,
12722 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
12723 "Directory Entry: %#x", i
+ idx_offset
);
12725 dw2_asm_output_data (1, 0, "End directory table");
12728 /* We have to emit them in the order of emitted_number since that's
12729 used in the debug info generation. To do this efficiently we
12730 generate a back-mapping of the indices first. */
12731 backmap
= XALLOCAVEC (int, numfiles
);
12732 for (i
= 0; i
< numfiles
; i
++)
12733 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
12735 if (dwarf_version
>= 5)
12737 const char *filename0
= get_AT_string (comp_unit_die (), DW_AT_name
);
12738 if (filename0
== NULL
)
12740 /* DW_LNCT_directory_index can use DW_FORM_udata, DW_FORM_data1 and
12741 DW_FORM_data2. Choose one based on the number of directories
12742 and how much space would they occupy in each encoding.
12743 If we have at most 256 directories, all indexes fit into
12744 a single byte, so DW_FORM_data1 is most compact (if there
12745 are at most 128 directories, DW_FORM_udata would be as
12746 compact as that, but not shorter and slower to decode). */
12747 if (ndirs
+ idx_offset
<= 256)
12748 idx_form
= DW_FORM_data1
;
12749 /* If there are more than 65536 directories, we have to use
12750 DW_FORM_udata, DW_FORM_data2 can't refer to them.
12751 Otherwise, compute what space would occupy if all the indexes
12752 used DW_FORM_udata - sum - and compare that to how large would
12753 be DW_FORM_data2 encoding, and pick the more efficient one. */
12754 else if (ndirs
+ idx_offset
<= 65536)
12756 unsigned HOST_WIDE_INT sum
= 1;
12757 for (i
= 0; i
< numfiles
; i
++)
12759 int file_idx
= backmap
[i
];
12760 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
12761 sum
+= size_of_uleb128 (dir_idx
);
12763 if (sum
>= HOST_WIDE_INT_UC (2) * (numfiles
+ 1))
12764 idx_form
= DW_FORM_data2
;
12766 #ifdef VMS_DEBUGGING_INFO
12767 dw2_asm_output_data (1, 4, "File name entry format count");
12769 dw2_asm_output_data (1, 2, "File name entry format count");
12771 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
12772 dw2_asm_output_data_uleb128 (str_form
, "%s",
12773 get_DW_FORM_name (str_form
));
12774 dw2_asm_output_data_uleb128 (DW_LNCT_directory_index
,
12775 "DW_LNCT_directory_index");
12776 dw2_asm_output_data_uleb128 (idx_form
, "%s",
12777 get_DW_FORM_name (idx_form
));
12778 #ifdef VMS_DEBUGGING_INFO
12779 dw2_asm_output_data_uleb128 (DW_LNCT_timestamp
, "DW_LNCT_timestamp");
12780 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
12781 dw2_asm_output_data_uleb128 (DW_LNCT_size
, "DW_LNCT_size");
12782 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
12784 dw2_asm_output_data_uleb128 (numfiles
+ 1, "File names count");
12786 output_line_string (str_form
, filename0
, "File Entry", 0);
12788 /* Include directory index. */
12789 if (idx_form
!= DW_FORM_udata
)
12790 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
12793 dw2_asm_output_data_uleb128 (0, NULL
);
12795 #ifdef VMS_DEBUGGING_INFO
12796 dw2_asm_output_data_uleb128 (0, NULL
);
12797 dw2_asm_output_data_uleb128 (0, NULL
);
12801 /* Now write all the file names. */
12802 for (i
= 0; i
< numfiles
; i
++)
12804 int file_idx
= backmap
[i
];
12805 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
12807 #ifdef VMS_DEBUGGING_INFO
12808 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
12810 /* Setting these fields can lead to debugger miscomparisons,
12811 but VMS Debug requires them to be set correctly. */
12816 int maxfilelen
= (strlen (files
[file_idx
].path
)
12817 + dirs
[dir_idx
].length
12818 + MAX_VMS_VERSION_LEN
+ 1);
12819 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
12821 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
12822 snprintf (filebuf
, maxfilelen
, "%s;%d",
12823 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
12825 output_line_string (str_form
, filebuf
, "File Entry", (unsigned) i
+ 1);
12827 /* Include directory index. */
12828 if (dwarf_version
>= 5 && idx_form
!= DW_FORM_udata
)
12829 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
12830 dir_idx
+ idx_offset
, NULL
);
12832 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
12834 /* Modification time. */
12835 dw2_asm_output_data_uleb128 ((vms_file_stats_name (files
[file_idx
].path
,
12836 &cdt
, 0, 0, 0) == 0)
12839 /* File length in bytes. */
12840 dw2_asm_output_data_uleb128 ((vms_file_stats_name (files
[file_idx
].path
,
12841 0, &siz
, 0, 0) == 0)
12844 output_line_string (str_form
,
12845 files
[file_idx
].path
+ dirs
[dir_idx
].length
,
12846 "File Entry", (unsigned) i
+ 1);
12848 /* Include directory index. */
12849 if (dwarf_version
>= 5 && idx_form
!= DW_FORM_udata
)
12850 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
12851 dir_idx
+ idx_offset
, NULL
);
12853 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
12855 if (dwarf_version
>= 5)
12858 /* Modification time. */
12859 dw2_asm_output_data_uleb128 (0, NULL
);
12861 /* File length in bytes. */
12862 dw2_asm_output_data_uleb128 (0, NULL
);
12863 #endif /* VMS_DEBUGGING_INFO */
12866 if (dwarf_version
< 5)
12867 dw2_asm_output_data (1, 0, "End file name table");
12871 /* Output one line number table into the .debug_line section. */
12874 output_one_line_info_table (dw_line_info_table
*table
)
12876 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
12877 unsigned int current_line
= 1;
12878 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
12879 dw_line_info_entry
*ent
, *prev_addr
;
12885 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
12887 switch (ent
->opcode
)
12889 case LI_set_address
:
12890 /* ??? Unfortunately, we have little choice here currently, and
12891 must always use the most general form. GCC does not know the
12892 address delta itself, so we can't use DW_LNS_advance_pc. Many
12893 ports do have length attributes which will give an upper bound
12894 on the address range. We could perhaps use length attributes
12895 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
12896 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
12900 /* This can handle any delta. This takes
12901 4+DWARF2_ADDR_SIZE bytes. */
12902 dw2_asm_output_data (1, 0, "set address %s%s", line_label
,
12903 debug_variable_location_views
12904 ? ", reset view to 0" : "");
12905 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
12906 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
12907 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
12912 case LI_adv_address
:
12914 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
12915 char prev_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
12916 ASM_GENERATE_INTERNAL_LABEL (prev_label
, LINE_CODE_LABEL
, prev_addr
->val
);
12920 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
, "fixed advance PC, increment view to %i", view
);
12921 dw2_asm_output_delta (2, line_label
, prev_label
,
12922 "from %s to %s", prev_label
, line_label
);
12929 if (ent
->val
== current_line
)
12931 /* We still need to start a new row, so output a copy insn. */
12932 dw2_asm_output_data (1, DW_LNS_copy
,
12933 "copy line %u", current_line
);
12937 int line_offset
= ent
->val
- current_line
;
12938 int line_delta
= line_offset
- DWARF_LINE_BASE
;
12940 current_line
= ent
->val
;
12941 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
12943 /* This can handle deltas from -10 to 234, using the current
12944 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
12945 This takes 1 byte. */
12946 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
12947 "line %u", current_line
);
12951 /* This can handle any delta. This takes at least 4 bytes,
12952 depending on the value being encoded. */
12953 dw2_asm_output_data (1, DW_LNS_advance_line
,
12954 "advance to line %u", current_line
);
12955 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
12956 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
12962 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
12963 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
12966 case LI_set_column
:
12967 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
12968 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
12971 case LI_negate_stmt
:
12972 current_is_stmt
= !current_is_stmt
;
12973 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
12974 "is_stmt %d", current_is_stmt
);
12977 case LI_set_prologue_end
:
12978 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
12979 "set prologue end");
12982 case LI_set_epilogue_begin
:
12983 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
12984 "set epilogue begin");
12987 case LI_set_discriminator
:
12988 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
12989 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
12990 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
12991 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
12996 /* Emit debug info for the address of the end of the table. */
12997 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
12998 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
12999 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
13000 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
13002 dw2_asm_output_data (1, 0, "end sequence");
13003 dw2_asm_output_data_uleb128 (1, NULL
);
13004 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
13007 static unsigned int output_line_info_generation
;
13009 /* Output the source line number correspondence information. This
13010 information goes into the .debug_line section. */
13013 output_line_info (bool prologue_only
)
13015 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
13016 char p1
[MAX_ARTIFICIAL_LABEL_BYTES
], p2
[MAX_ARTIFICIAL_LABEL_BYTES
];
13017 bool saw_one
= false;
13020 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
,
13021 output_line_info_generation
);
13022 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
,
13023 output_line_info_generation
);
13024 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
,
13025 output_line_info_generation
);
13026 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
,
13027 output_line_info_generation
++);
13029 if (!XCOFF_DEBUGGING_INFO
)
13031 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
13032 dw2_asm_output_data (4, 0xffffffff,
13033 "Initial length escape value indicating 64-bit DWARF extension");
13034 dw2_asm_output_delta (dwarf_offset_size
, l2
, l1
,
13035 "Length of Source Line Info");
13038 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
13040 output_dwarf_version ();
13041 if (dwarf_version
>= 5)
13043 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
13044 dw2_asm_output_data (1, 0, "Segment Size");
13046 dw2_asm_output_delta (dwarf_offset_size
, p2
, p1
, "Prolog Length");
13047 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
13049 /* Define the architecture-dependent minimum instruction length (in bytes).
13050 In this implementation of DWARF, this field is used for information
13051 purposes only. Since GCC generates assembly language, we have no
13052 a priori knowledge of how many instruction bytes are generated for each
13053 source line, and therefore can use only the DW_LNE_set_address and
13054 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
13055 this as '1', which is "correct enough" for all architectures,
13056 and don't let the target override. */
13057 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
13059 if (dwarf_version
>= 4)
13060 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
13061 "Maximum Operations Per Instruction");
13062 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
13063 "Default is_stmt_start flag");
13064 dw2_asm_output_data (1, DWARF_LINE_BASE
,
13065 "Line Base Value (Special Opcodes)");
13066 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
13067 "Line Range Value (Special Opcodes)");
13068 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
13069 "Special Opcode Base");
13071 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
13076 case DW_LNS_advance_pc
:
13077 case DW_LNS_advance_line
:
13078 case DW_LNS_set_file
:
13079 case DW_LNS_set_column
:
13080 case DW_LNS_fixed_advance_pc
:
13081 case DW_LNS_set_isa
:
13089 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
13093 /* Write out the information about the files we use. */
13094 output_file_names ();
13095 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
13098 /* Output the marker for the end of the line number info. */
13099 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
13103 if (separate_line_info
)
13105 dw_line_info_table
*table
;
13108 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
13111 output_one_line_info_table (table
);
13115 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
13117 output_one_line_info_table (cold_text_section_line_info
);
13121 /* ??? Some Darwin linkers crash on a .debug_line section with no
13122 sequences. Further, merely a DW_LNE_end_sequence entry is not
13123 sufficient -- the address column must also be initialized.
13124 Make sure to output at least one set_address/end_sequence pair,
13125 choosing .text since that section is always present. */
13126 if (text_section_line_info
->in_use
|| !saw_one
)
13127 output_one_line_info_table (text_section_line_info
);
13129 /* Output the marker for the end of the line number info. */
13130 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
13133 /* Return true if DW_AT_endianity should be emitted according to REVERSE. */
13136 need_endianity_attribute_p (bool reverse
)
13138 return reverse
&& (dwarf_version
>= 3 || !dwarf_strict
);
13141 /* Given a pointer to a tree node for some base type, return a pointer to
13142 a DIE that describes the given type. REVERSE is true if the type is
13143 to be interpreted in the reverse storage order wrt the target order.
13145 This routine must only be called for GCC type nodes that correspond to
13146 Dwarf base (fundamental) types. */
13149 base_type_die (tree type
, bool reverse
)
13151 dw_die_ref base_type_result
;
13152 enum dwarf_type encoding
;
13153 bool fpt_used
= false;
13154 struct fixed_point_type_info fpt_info
;
13155 tree type_bias
= NULL_TREE
;
13157 /* If this is a subtype that should not be emitted as a subrange type,
13158 use the base type. See subrange_type_for_debug_p. */
13159 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
13160 type
= TREE_TYPE (type
);
13162 switch (TREE_CODE (type
))
13165 if ((dwarf_version
>= 4 || !dwarf_strict
)
13166 && TYPE_NAME (type
)
13167 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
13168 && DECL_IS_UNDECLARED_BUILTIN (TYPE_NAME (type
))
13169 && DECL_NAME (TYPE_NAME (type
)))
13171 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
13172 if (strcmp (name
, "char16_t") == 0
13173 || strcmp (name
, "char32_t") == 0)
13175 encoding
= DW_ATE_UTF
;
13179 if ((dwarf_version
>= 3 || !dwarf_strict
)
13180 && lang_hooks
.types
.get_fixed_point_type_info
)
13182 memset (&fpt_info
, 0, sizeof (fpt_info
));
13183 if (lang_hooks
.types
.get_fixed_point_type_info (type
, &fpt_info
))
13186 encoding
= ((TYPE_UNSIGNED (type
))
13187 ? DW_ATE_unsigned_fixed
13188 : DW_ATE_signed_fixed
);
13192 if (TYPE_STRING_FLAG (type
))
13194 if (TYPE_UNSIGNED (type
))
13195 encoding
= DW_ATE_unsigned_char
;
13197 encoding
= DW_ATE_signed_char
;
13199 else if (TYPE_UNSIGNED (type
))
13200 encoding
= DW_ATE_unsigned
;
13202 encoding
= DW_ATE_signed
;
13205 && lang_hooks
.types
.get_type_bias
)
13206 type_bias
= lang_hooks
.types
.get_type_bias (type
);
13210 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
13212 if (dwarf_version
>= 3 || !dwarf_strict
)
13213 encoding
= DW_ATE_decimal_float
;
13215 encoding
= DW_ATE_lo_user
;
13218 encoding
= DW_ATE_float
;
13221 case FIXED_POINT_TYPE
:
13222 if (!(dwarf_version
>= 3 || !dwarf_strict
))
13223 encoding
= DW_ATE_lo_user
;
13224 else if (TYPE_UNSIGNED (type
))
13225 encoding
= DW_ATE_unsigned_fixed
;
13227 encoding
= DW_ATE_signed_fixed
;
13230 /* Dwarf2 doesn't know anything about complex ints, so use
13231 a user defined type for it. */
13233 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
13234 encoding
= DW_ATE_complex_float
;
13236 encoding
= DW_ATE_lo_user
;
13240 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
13241 encoding
= DW_ATE_boolean
;
13245 /* No other TREE_CODEs are Dwarf fundamental types. */
13246 gcc_unreachable ();
13249 base_type_result
= new_die_raw (DW_TAG_base_type
);
13251 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
13252 int_size_in_bytes (type
));
13253 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
13255 if (need_endianity_attribute_p (reverse
))
13256 add_AT_unsigned (base_type_result
, DW_AT_endianity
,
13257 BYTES_BIG_ENDIAN
? DW_END_little
: DW_END_big
);
13259 add_alignment_attribute (base_type_result
, type
);
13263 switch (fpt_info
.scale_factor_kind
)
13265 case fixed_point_scale_factor_binary
:
13266 add_AT_int (base_type_result
, DW_AT_binary_scale
,
13267 fpt_info
.scale_factor
.binary
);
13270 case fixed_point_scale_factor_decimal
:
13271 add_AT_int (base_type_result
, DW_AT_decimal_scale
,
13272 fpt_info
.scale_factor
.decimal
);
13275 case fixed_point_scale_factor_arbitrary
:
13276 /* Arbitrary scale factors cannot be described in standard DWARF. */
13279 /* Describe the scale factor as a rational constant. */
13280 const dw_die_ref scale_factor
13281 = new_die (DW_TAG_constant
, comp_unit_die (), type
);
13283 add_scalar_info (scale_factor
, DW_AT_GNU_numerator
,
13284 fpt_info
.scale_factor
.arbitrary
.numerator
,
13285 dw_scalar_form_constant
, NULL
);
13286 add_scalar_info (scale_factor
, DW_AT_GNU_denominator
,
13287 fpt_info
.scale_factor
.arbitrary
.denominator
,
13288 dw_scalar_form_constant
, NULL
);
13290 add_AT_die_ref (base_type_result
, DW_AT_small
, scale_factor
);
13295 gcc_unreachable ();
13300 add_scalar_info (base_type_result
, DW_AT_GNU_bias
, type_bias
,
13301 dw_scalar_form_constant
13302 | dw_scalar_form_exprloc
13303 | dw_scalar_form_reference
,
13306 return base_type_result
;
13309 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
13310 named 'auto' in its type: return true for it, false otherwise. */
13313 is_cxx_auto (tree type
)
13317 tree name
= TYPE_IDENTIFIER (type
);
13318 if (name
== get_identifier ("auto")
13319 || name
== get_identifier ("decltype(auto)"))
13325 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
13326 given input type is a Dwarf "fundamental" type. Otherwise return null. */
13329 is_base_type (tree type
)
13331 switch (TREE_CODE (type
))
13335 case FIXED_POINT_TYPE
:
13345 case QUAL_UNION_TYPE
:
13346 case ENUMERAL_TYPE
:
13347 case FUNCTION_TYPE
:
13350 case REFERENCE_TYPE
:
13358 if (is_cxx_auto (type
))
13360 gcc_unreachable ();
13366 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
13367 node, return the size in bits for the type if it is a constant, or else
13368 return the alignment for the type if the type's size is not constant, or
13369 else return BITS_PER_WORD if the type actually turns out to be an
13370 ERROR_MARK node. */
13372 static inline unsigned HOST_WIDE_INT
13373 simple_type_size_in_bits (const_tree type
)
13375 if (TREE_CODE (type
) == ERROR_MARK
)
13376 return BITS_PER_WORD
;
13377 else if (TYPE_SIZE (type
) == NULL_TREE
)
13379 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
13380 return tree_to_uhwi (TYPE_SIZE (type
));
13382 return TYPE_ALIGN (type
);
13385 /* Similarly, but return an offset_int instead of UHWI. */
13387 static inline offset_int
13388 offset_int_type_size_in_bits (const_tree type
)
13390 if (TREE_CODE (type
) == ERROR_MARK
)
13391 return BITS_PER_WORD
;
13392 else if (TYPE_SIZE (type
) == NULL_TREE
)
13394 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
13395 return wi::to_offset (TYPE_SIZE (type
));
13397 return TYPE_ALIGN (type
);
13400 /* Given a pointer to a tree node for a subrange type, return a pointer
13401 to a DIE that describes the given type. */
13404 subrange_type_die (tree type
, tree low
, tree high
, tree bias
,
13405 dw_die_ref context_die
)
13407 dw_die_ref subrange_die
;
13408 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
13410 if (context_die
== NULL
)
13411 context_die
= comp_unit_die ();
13413 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
13415 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
13417 /* The size of the subrange type and its base type do not match,
13418 so we need to generate a size attribute for the subrange type. */
13419 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
13422 add_alignment_attribute (subrange_die
, type
);
13425 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
, NULL
);
13427 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
, NULL
);
13428 if (bias
&& !dwarf_strict
)
13429 add_scalar_info (subrange_die
, DW_AT_GNU_bias
, bias
,
13430 dw_scalar_form_constant
13431 | dw_scalar_form_exprloc
13432 | dw_scalar_form_reference
,
13435 return subrange_die
;
13438 /* Returns the (const and/or volatile) cv_qualifiers associated with
13439 the decl node. This will normally be augmented with the
13440 cv_qualifiers of the underlying type in add_type_attribute. */
13443 decl_quals (const_tree decl
)
13445 return ((TREE_READONLY (decl
)
13446 /* The C++ front-end correctly marks reference-typed
13447 variables as readonly, but from a language (and debug
13448 info) standpoint they are not const-qualified. */
13449 && TREE_CODE (TREE_TYPE (decl
)) != REFERENCE_TYPE
13450 ? TYPE_QUAL_CONST
: TYPE_UNQUALIFIED
)
13451 | (TREE_THIS_VOLATILE (decl
)
13452 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
));
13455 /* Determine the TYPE whose qualifiers match the largest strict subset
13456 of the given TYPE_QUALS, and return its qualifiers. Ignore all
13457 qualifiers outside QUAL_MASK. */
13460 get_nearest_type_subqualifiers (tree type
, int type_quals
, int qual_mask
)
13463 int best_rank
= 0, best_qual
= 0, max_rank
;
13465 type_quals
&= qual_mask
;
13466 max_rank
= popcount_hwi (type_quals
) - 1;
13468 for (t
= TYPE_MAIN_VARIANT (type
); t
&& best_rank
< max_rank
;
13469 t
= TYPE_NEXT_VARIANT (t
))
13471 int q
= TYPE_QUALS (t
) & qual_mask
;
13473 if ((q
& type_quals
) == q
&& q
!= type_quals
13474 && check_base_type (t
, type
))
13476 int rank
= popcount_hwi (q
);
13478 if (rank
> best_rank
)
13489 struct dwarf_qual_info_t
{ int q
; enum dwarf_tag t
; };
13490 static const dwarf_qual_info_t dwarf_qual_info
[] =
13492 { TYPE_QUAL_CONST
, DW_TAG_const_type
},
13493 { TYPE_QUAL_VOLATILE
, DW_TAG_volatile_type
},
13494 { TYPE_QUAL_RESTRICT
, DW_TAG_restrict_type
},
13495 { TYPE_QUAL_ATOMIC
, DW_TAG_atomic_type
}
13497 static const unsigned int dwarf_qual_info_size
13498 = sizeof (dwarf_qual_info
) / sizeof (dwarf_qual_info
[0]);
13500 /* If DIE is a qualified DIE of some base DIE with the same parent,
13501 return the base DIE, otherwise return NULL. Set MASK to the
13502 qualifiers added compared to the returned DIE. */
13505 qualified_die_p (dw_die_ref die
, int *mask
, unsigned int depth
)
13508 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
13509 if (die
->die_tag
== dwarf_qual_info
[i
].t
)
13511 if (i
== dwarf_qual_info_size
)
13513 if (vec_safe_length (die
->die_attr
) != 1)
13515 dw_die_ref type
= get_AT_ref (die
, DW_AT_type
);
13516 if (type
== NULL
|| type
->die_parent
!= die
->die_parent
)
13518 *mask
|= dwarf_qual_info
[i
].q
;
13521 dw_die_ref ret
= qualified_die_p (type
, mask
, depth
- 1);
13528 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
13529 entry that chains the modifiers specified by CV_QUALS in front of the
13530 given type. REVERSE is true if the type is to be interpreted in the
13531 reverse storage order wrt the target order. */
13534 modified_type_die (tree type
, int cv_quals
, bool reverse
,
13535 dw_die_ref context_die
)
13537 enum tree_code code
= TREE_CODE (type
);
13538 dw_die_ref mod_type_die
;
13539 dw_die_ref sub_die
= NULL
;
13540 tree item_type
= NULL
;
13541 tree qualified_type
;
13542 tree name
, low
, high
;
13543 dw_die_ref mod_scope
;
13544 struct array_descr_info info
;
13545 /* Only these cv-qualifiers are currently handled. */
13546 const int cv_qual_mask
= (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
13547 | TYPE_QUAL_RESTRICT
| TYPE_QUAL_ATOMIC
|
13548 ENCODE_QUAL_ADDR_SPACE(~0U));
13549 const bool reverse_base_type
13550 = need_endianity_attribute_p (reverse
) && is_base_type (type
);
13552 if (code
== ERROR_MARK
)
13555 if (lang_hooks
.types
.get_debug_type
)
13557 tree debug_type
= lang_hooks
.types
.get_debug_type (type
);
13559 if (debug_type
!= NULL_TREE
&& debug_type
!= type
)
13560 return modified_type_die (debug_type
, cv_quals
, reverse
, context_die
);
13563 cv_quals
&= cv_qual_mask
;
13565 /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
13566 tag modifier (and not an attribute) old consumers won't be able
13568 if (dwarf_version
< 3)
13569 cv_quals
&= ~TYPE_QUAL_RESTRICT
;
13571 /* Likewise for DW_TAG_atomic_type for DWARFv5. */
13572 if (dwarf_version
< 5)
13573 cv_quals
&= ~TYPE_QUAL_ATOMIC
;
13575 /* See if we already have the appropriately qualified variant of
13577 qualified_type
= get_qualified_type (type
, cv_quals
);
13579 if (qualified_type
== sizetype
)
13581 /* Try not to expose the internal sizetype type's name. */
13582 if (TYPE_NAME (qualified_type
)
13583 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
13585 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
13587 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
13588 && (TYPE_PRECISION (t
)
13589 == TYPE_PRECISION (qualified_type
))
13590 && (TYPE_UNSIGNED (t
)
13591 == TYPE_UNSIGNED (qualified_type
)));
13592 qualified_type
= t
;
13594 else if (qualified_type
== sizetype
13595 && TREE_CODE (sizetype
) == TREE_CODE (size_type_node
)
13596 && TYPE_PRECISION (sizetype
) == TYPE_PRECISION (size_type_node
)
13597 && TYPE_UNSIGNED (sizetype
) == TYPE_UNSIGNED (size_type_node
))
13598 qualified_type
= size_type_node
;
13599 if (type
== sizetype
)
13600 type
= qualified_type
;
13603 /* If we do, then we can just use its DIE, if it exists. */
13604 if (qualified_type
)
13606 mod_type_die
= lookup_type_die (qualified_type
);
13608 /* DW_AT_endianity doesn't come from a qualifier on the type, so it is
13609 dealt with specially: the DIE with the attribute, if it exists, is
13610 placed immediately after the regular DIE for the same base type. */
13612 && (!reverse_base_type
13613 || ((mod_type_die
= mod_type_die
->die_sib
) != NULL
13614 && get_AT_unsigned (mod_type_die
, DW_AT_endianity
))))
13615 return mod_type_die
;
13618 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
13620 /* Handle C typedef types. */
13622 && TREE_CODE (name
) == TYPE_DECL
13623 && DECL_ORIGINAL_TYPE (name
)
13624 && !DECL_ARTIFICIAL (name
))
13626 tree dtype
= TREE_TYPE (name
);
13628 /* Skip the typedef for base types with DW_AT_endianity, no big deal. */
13629 if (qualified_type
== dtype
&& !reverse_base_type
)
13631 tree origin
= decl_ultimate_origin (name
);
13633 /* Typedef variants that have an abstract origin don't get their own
13634 type DIE (see gen_typedef_die), so fall back on the ultimate
13635 abstract origin instead. */
13636 if (origin
!= NULL
&& origin
!= name
)
13637 return modified_type_die (TREE_TYPE (origin
), cv_quals
, reverse
,
13640 /* For a named type, use the typedef. */
13641 gen_type_die (qualified_type
, context_die
);
13642 return lookup_type_die (qualified_type
);
13646 int dquals
= TYPE_QUALS_NO_ADDR_SPACE (dtype
);
13647 dquals
&= cv_qual_mask
;
13648 if ((dquals
& ~cv_quals
) != TYPE_UNQUALIFIED
13649 || (cv_quals
== dquals
&& DECL_ORIGINAL_TYPE (name
) != type
))
13650 /* cv-unqualified version of named type. Just use
13651 the unnamed type to which it refers. */
13652 return modified_type_die (DECL_ORIGINAL_TYPE (name
), cv_quals
,
13653 reverse
, context_die
);
13654 /* Else cv-qualified version of named type; fall through. */
13658 mod_scope
= scope_die_for (type
, context_die
);
13662 int sub_quals
= 0, first_quals
= 0;
13664 dw_die_ref first
= NULL
, last
= NULL
;
13666 /* Determine a lesser qualified type that most closely matches
13667 this one. Then generate DW_TAG_* entries for the remaining
13669 sub_quals
= get_nearest_type_subqualifiers (type
, cv_quals
,
13671 if (sub_quals
&& use_debug_types
)
13673 bool needed
= false;
13674 /* If emitting type units, make sure the order of qualifiers
13675 is canonical. Thus, start from unqualified type if
13676 an earlier qualifier is missing in sub_quals, but some later
13677 one is present there. */
13678 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
13679 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
13681 else if (needed
&& (dwarf_qual_info
[i
].q
& cv_quals
))
13687 mod_type_die
= modified_type_die (type
, sub_quals
, reverse
, context_die
);
13688 if (mod_scope
&& mod_type_die
&& mod_type_die
->die_parent
== mod_scope
)
13690 /* As not all intermediate qualified DIEs have corresponding
13691 tree types, ensure that qualified DIEs in the same scope
13692 as their DW_AT_type are emitted after their DW_AT_type,
13693 only with other qualified DIEs for the same type possibly
13694 in between them. Determine the range of such qualified
13695 DIEs now (first being the base type, last being corresponding
13696 last qualified DIE for it). */
13697 unsigned int count
= 0;
13698 first
= qualified_die_p (mod_type_die
, &first_quals
,
13699 dwarf_qual_info_size
);
13701 first
= mod_type_die
;
13702 gcc_assert ((first_quals
& ~sub_quals
) == 0);
13703 for (count
= 0, last
= first
;
13704 count
< (1U << dwarf_qual_info_size
);
13705 count
++, last
= last
->die_sib
)
13708 if (last
== mod_scope
->die_child
)
13710 if (qualified_die_p (last
->die_sib
, &quals
, dwarf_qual_info_size
)
13716 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
13717 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
13720 if (first
&& first
!= last
)
13722 for (d
= first
->die_sib
; ; d
= d
->die_sib
)
13725 qualified_die_p (d
, &quals
, dwarf_qual_info_size
);
13726 if (quals
== (first_quals
| dwarf_qual_info
[i
].q
))
13742 d
= new_die_raw (dwarf_qual_info
[i
].t
);
13743 add_child_die_after (mod_scope
, d
, last
);
13747 d
= new_die (dwarf_qual_info
[i
].t
, mod_scope
, type
);
13749 add_AT_die_ref (d
, DW_AT_type
, mod_type_die
);
13751 first_quals
|= dwarf_qual_info
[i
].q
;
13754 else if (code
== POINTER_TYPE
|| code
== REFERENCE_TYPE
)
13756 dwarf_tag tag
= DW_TAG_pointer_type
;
13757 if (code
== REFERENCE_TYPE
)
13759 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
13760 tag
= DW_TAG_rvalue_reference_type
;
13762 tag
= DW_TAG_reference_type
;
13764 mod_type_die
= new_die (tag
, mod_scope
, type
);
13766 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
13767 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
13768 add_alignment_attribute (mod_type_die
, type
);
13769 item_type
= TREE_TYPE (type
);
13771 addr_space_t as
= TYPE_ADDR_SPACE (item_type
);
13772 if (!ADDR_SPACE_GENERIC_P (as
))
13774 int action
= targetm
.addr_space
.debug (as
);
13777 /* Positive values indicate an address_class. */
13778 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, action
);
13782 /* Negative values indicate an (inverted) segment base reg. */
13784 = one_reg_loc_descriptor (~action
, VAR_INIT_STATUS_INITIALIZED
);
13785 add_AT_loc (mod_type_die
, DW_AT_segment
, d
);
13789 else if (code
== ARRAY_TYPE
13790 || (lang_hooks
.types
.get_array_descr_info
13791 && lang_hooks
.types
.get_array_descr_info (type
, &info
)))
13793 gen_type_die (type
, context_die
);
13794 return lookup_type_die (type
);
13796 else if (code
== INTEGER_TYPE
13797 && TREE_TYPE (type
) != NULL_TREE
13798 && subrange_type_for_debug_p (type
, &low
, &high
))
13800 tree bias
= NULL_TREE
;
13801 if (lang_hooks
.types
.get_type_bias
)
13802 bias
= lang_hooks
.types
.get_type_bias (type
);
13803 mod_type_die
= subrange_type_die (type
, low
, high
, bias
, context_die
);
13804 item_type
= TREE_TYPE (type
);
13806 else if (is_base_type (type
))
13808 mod_type_die
= base_type_die (type
, reverse
);
13810 /* The DIE with DW_AT_endianity is placed right after the naked DIE. */
13811 if (reverse_base_type
)
13813 dw_die_ref after_die
13814 = modified_type_die (type
, cv_quals
, false, context_die
);
13815 add_child_die_after (comp_unit_die (), mod_type_die
, after_die
);
13818 add_child_die (comp_unit_die (), mod_type_die
);
13820 add_pubtype (type
, mod_type_die
);
13824 gen_type_die (type
, context_die
);
13826 /* We have to get the type_main_variant here (and pass that to the
13827 `lookup_type_die' routine) because the ..._TYPE node we have
13828 might simply be a *copy* of some original type node (where the
13829 copy was created to help us keep track of typedef names) and
13830 that copy might have a different TYPE_UID from the original
13832 if (code
== FUNCTION_TYPE
|| code
== METHOD_TYPE
)
13834 /* For function/method types, can't just use type_main_variant here,
13835 because that can have different ref-qualifiers for C++,
13836 but try to canonicalize. */
13837 tree main
= TYPE_MAIN_VARIANT (type
);
13838 for (tree t
= main
; t
; t
= TYPE_NEXT_VARIANT (t
))
13839 if (TYPE_QUALS_NO_ADDR_SPACE (t
) == 0
13840 && check_base_type (t
, main
)
13841 && check_lang_type (t
, type
))
13842 return lookup_type_die (t
);
13843 return lookup_type_die (type
);
13845 /* Vectors have the debugging information in the type,
13846 not the main variant. */
13847 else if (code
== VECTOR_TYPE
)
13848 return lookup_type_die (type
);
13850 return lookup_type_die (type_main_variant (type
));
13853 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
13854 don't output a DW_TAG_typedef, since there isn't one in the
13855 user's program; just attach a DW_AT_name to the type.
13856 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
13857 if the base type already has the same name. */
13859 && ((TREE_CODE (name
) != TYPE_DECL
13860 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
13861 || (cv_quals
== TYPE_UNQUALIFIED
)))
13862 || (TREE_CODE (name
) == TYPE_DECL
13863 && TREE_TYPE (name
) == qualified_type
13864 && DECL_NAME (name
))))
13866 if (TREE_CODE (name
) == TYPE_DECL
)
13867 /* Could just call add_name_and_src_coords_attributes here,
13868 but since this is a builtin type it doesn't have any
13869 useful source coordinates anyway. */
13870 name
= DECL_NAME (name
);
13871 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
13873 /* This probably indicates a bug. */
13874 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
13876 name
= TYPE_IDENTIFIER (type
);
13877 add_name_attribute (mod_type_die
,
13878 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
13881 if (qualified_type
&& !reverse_base_type
)
13882 equate_type_number_to_die (qualified_type
, mod_type_die
);
13885 /* We must do this after the equate_type_number_to_die call, in case
13886 this is a recursive type. This ensures that the modified_type_die
13887 recursion will terminate even if the type is recursive. Recursive
13888 types are possible in Ada. */
13889 sub_die
= modified_type_die (item_type
,
13890 TYPE_QUALS_NO_ADDR_SPACE (item_type
),
13894 if (sub_die
!= NULL
)
13895 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
13897 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
13898 if (TYPE_ARTIFICIAL (type
))
13899 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
13901 return mod_type_die
;
13904 /* Generate DIEs for the generic parameters of T.
13905 T must be either a generic type or a generic function.
13906 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
13909 gen_generic_params_dies (tree t
)
13913 dw_die_ref die
= NULL
;
13916 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
13920 die
= lookup_type_die (t
);
13921 else if (DECL_P (t
))
13922 die
= lookup_decl_die (t
);
13926 parms
= lang_hooks
.get_innermost_generic_parms (t
);
13928 /* T has no generic parameter. It means T is neither a generic type
13929 or function. End of story. */
13932 parms_num
= TREE_VEC_LENGTH (parms
);
13933 args
= lang_hooks
.get_innermost_generic_args (t
);
13934 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
13935 non_default
= int_cst_value (TREE_CHAIN (args
));
13937 non_default
= TREE_VEC_LENGTH (args
);
13938 for (i
= 0; i
< parms_num
; i
++)
13940 tree parm
, arg
, arg_pack_elems
;
13941 dw_die_ref parm_die
;
13943 parm
= TREE_VEC_ELT (parms
, i
);
13944 arg
= TREE_VEC_ELT (args
, i
);
13945 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
13946 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
13948 if (parm
&& TREE_VALUE (parm
) && arg
)
13950 /* If PARM represents a template parameter pack,
13951 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
13952 by DW_TAG_template_*_parameter DIEs for the argument
13953 pack elements of ARG. Note that ARG would then be
13954 an argument pack. */
13955 if (arg_pack_elems
)
13956 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
13960 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
13961 true /* emit name */, die
);
13962 if (i
>= non_default
)
13963 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
13968 /* Create and return a DIE for PARM which should be
13969 the representation of a generic type parameter.
13970 For instance, in the C++ front end, PARM would be a template parameter.
13971 ARG is the argument to PARM.
13972 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
13974 PARENT_DIE is the parent DIE which the new created DIE should be added to,
13975 as a child node. */
13978 generic_parameter_die (tree parm
, tree arg
,
13980 dw_die_ref parent_die
)
13982 dw_die_ref tmpl_die
= NULL
;
13983 const char *name
= NULL
;
13985 /* C++20 accepts class literals as template parameters, and var
13986 decls with initializers represent them. The VAR_DECLs would be
13987 rejected, but we can take the DECL_INITIAL constructor and
13988 attempt to expand it. */
13989 if (arg
&& VAR_P (arg
))
13990 arg
= DECL_INITIAL (arg
);
13992 if (!parm
|| !DECL_NAME (parm
) || !arg
)
13995 /* We support non-type generic parameters and arguments,
13996 type generic parameters and arguments, as well as
13997 generic generic parameters (a.k.a. template template parameters in C++)
13999 if (TREE_CODE (parm
) == PARM_DECL
)
14000 /* PARM is a nontype generic parameter */
14001 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
14002 else if (TREE_CODE (parm
) == TYPE_DECL
)
14003 /* PARM is a type generic parameter. */
14004 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
14005 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
14006 /* PARM is a generic generic parameter.
14007 Its DIE is a GNU extension. It shall have a
14008 DW_AT_name attribute to represent the name of the template template
14009 parameter, and a DW_AT_GNU_template_name attribute to represent the
14010 name of the template template argument. */
14011 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
14014 gcc_unreachable ();
14020 /* If PARM is a generic parameter pack, it means we are
14021 emitting debug info for a template argument pack element.
14022 In other terms, ARG is a template argument pack element.
14023 In that case, we don't emit any DW_AT_name attribute for
14027 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
14029 add_AT_string (tmpl_die
, DW_AT_name
, name
);
14032 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
14034 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
14035 TMPL_DIE should have a child DW_AT_type attribute that is set
14036 to the type of the argument to PARM, which is ARG.
14037 If PARM is a type generic parameter, TMPL_DIE should have a
14038 child DW_AT_type that is set to ARG. */
14039 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
14040 add_type_attribute (tmpl_die
, tmpl_type
,
14041 (TREE_THIS_VOLATILE (tmpl_type
)
14042 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
),
14043 false, parent_die
);
14047 /* So TMPL_DIE is a DIE representing a
14048 a generic generic template parameter, a.k.a template template
14049 parameter in C++ and arg is a template. */
14051 /* The DW_AT_GNU_template_name attribute of the DIE must be set
14052 to the name of the argument. */
14053 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
14055 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
14058 if (TREE_CODE (parm
) == PARM_DECL
)
14059 /* So PARM is a non-type generic parameter.
14060 DWARF3 5.6.8 says we must set a DW_AT_const_value child
14061 attribute of TMPL_DIE which value represents the value
14063 We must be careful here:
14064 The value of ARG might reference some function decls.
14065 We might currently be emitting debug info for a generic
14066 type and types are emitted before function decls, we don't
14067 know if the function decls referenced by ARG will actually be
14068 emitted after cgraph computations.
14069 So must defer the generation of the DW_AT_const_value to
14070 after cgraph is ready. */
14071 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
14077 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
14078 PARM_PACK must be a template parameter pack. The returned DIE
14079 will be child DIE of PARENT_DIE. */
14082 template_parameter_pack_die (tree parm_pack
,
14083 tree parm_pack_args
,
14084 dw_die_ref parent_die
)
14089 gcc_assert (parent_die
&& parm_pack
);
14091 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
14092 add_name_and_src_coords_attributes (die
, parm_pack
);
14093 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
14094 generic_parameter_die (parm_pack
,
14095 TREE_VEC_ELT (parm_pack_args
, j
),
14096 false /* Don't emit DW_AT_name */,
14101 /* Return the DBX register number described by a given RTL node. */
14103 static unsigned int
14104 dbx_reg_number (const_rtx rtl
)
14106 unsigned regno
= REGNO (rtl
);
14108 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
14110 #ifdef LEAF_REG_REMAP
14111 if (crtl
->uses_only_leaf_regs
)
14113 int leaf_reg
= LEAF_REG_REMAP (regno
);
14114 if (leaf_reg
!= -1)
14115 regno
= (unsigned) leaf_reg
;
14119 regno
= DBX_REGISTER_NUMBER (regno
);
14120 gcc_assert (regno
!= INVALID_REGNUM
);
14124 /* Optionally add a DW_OP_piece term to a location description expression.
14125 DW_OP_piece is only added if the location description expression already
14126 doesn't end with DW_OP_piece. */
14129 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
14131 dw_loc_descr_ref loc
;
14133 if (*list_head
!= NULL
)
14135 /* Find the end of the chain. */
14136 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
14139 if (loc
->dw_loc_opc
!= DW_OP_piece
)
14140 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
14144 /* Return a location descriptor that designates a machine register or
14145 zero if there is none. */
14147 static dw_loc_descr_ref
14148 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
14152 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
14155 /* We only use "frame base" when we're sure we're talking about the
14156 post-prologue local stack frame. We do this by *not* running
14157 register elimination until this point, and recognizing the special
14158 argument pointer and soft frame pointer rtx's.
14159 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
14160 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
14161 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
14163 dw_loc_descr_ref result
= NULL
;
14165 if (dwarf_version
>= 4 || !dwarf_strict
)
14167 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
14170 add_loc_descr (&result
,
14171 new_loc_descr (DW_OP_stack_value
, 0, 0));
14176 regs
= targetm
.dwarf_register_span (rtl
);
14178 if (REG_NREGS (rtl
) > 1 || regs
)
14179 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
14182 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
14183 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
14185 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
14189 /* Return a location descriptor that designates a machine register for
14190 a given hard register number. */
14192 static dw_loc_descr_ref
14193 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
14195 dw_loc_descr_ref reg_loc_descr
;
14199 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
14201 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
14203 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14204 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14206 return reg_loc_descr
;
14209 /* Given an RTL of a register, return a location descriptor that
14210 designates a value that spans more than one register. */
14212 static dw_loc_descr_ref
14213 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
14214 enum var_init_status initialized
)
14217 dw_loc_descr_ref loc_result
= NULL
;
14219 /* Simple, contiguous registers. */
14220 if (regs
== NULL_RTX
)
14222 unsigned reg
= REGNO (rtl
);
14225 #ifdef LEAF_REG_REMAP
14226 if (crtl
->uses_only_leaf_regs
)
14228 int leaf_reg
= LEAF_REG_REMAP (reg
);
14229 if (leaf_reg
!= -1)
14230 reg
= (unsigned) leaf_reg
;
14234 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
14235 nregs
= REG_NREGS (rtl
);
14237 /* At present we only track constant-sized pieces. */
14238 if (!GET_MODE_SIZE (GET_MODE (rtl
)).is_constant (&size
))
14245 dw_loc_descr_ref t
;
14247 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
14248 VAR_INIT_STATUS_INITIALIZED
);
14249 add_loc_descr (&loc_result
, t
);
14250 add_loc_descr_op_piece (&loc_result
, size
);
14256 /* Now onto stupid register sets in non contiguous locations. */
14258 gcc_assert (GET_CODE (regs
) == PARALLEL
);
14260 /* At present we only track constant-sized pieces. */
14261 if (!GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0))).is_constant (&size
))
14265 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
14267 dw_loc_descr_ref t
;
14269 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
14270 VAR_INIT_STATUS_INITIALIZED
);
14271 add_loc_descr (&loc_result
, t
);
14272 add_loc_descr_op_piece (&loc_result
, size
);
14275 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14276 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14280 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
14282 /* Return a location descriptor that designates a constant i,
14283 as a compound operation from constant (i >> shift), constant shift
14286 static dw_loc_descr_ref
14287 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
14289 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
14290 add_loc_descr (&ret
, int_loc_descriptor (shift
));
14291 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
14295 /* Return a location descriptor that designates constant POLY_I. */
14297 static dw_loc_descr_ref
14298 int_loc_descriptor (poly_int64 poly_i
)
14300 enum dwarf_location_atom op
;
14303 if (!poly_i
.is_constant (&i
))
14305 /* Create location descriptions for the non-constant part and
14306 add any constant offset at the end. */
14307 dw_loc_descr_ref ret
= NULL
;
14308 HOST_WIDE_INT constant
= poly_i
.coeffs
[0];
14309 for (unsigned int j
= 1; j
< NUM_POLY_INT_COEFFS
; ++j
)
14311 HOST_WIDE_INT coeff
= poly_i
.coeffs
[j
];
14314 dw_loc_descr_ref start
= ret
;
14315 unsigned int factor
;
14317 unsigned int regno
= targetm
.dwarf_poly_indeterminate_value
14318 (j
, &factor
, &bias
);
14320 /* Add COEFF * ((REGNO / FACTOR) - BIAS) to the value:
14321 add COEFF * (REGNO / FACTOR) now and subtract
14322 COEFF * BIAS from the final constant part. */
14323 constant
-= coeff
* bias
;
14324 add_loc_descr (&ret
, new_reg_loc_descr (regno
, 0));
14325 if (coeff
% factor
== 0)
14329 int amount
= exact_log2 (factor
);
14330 gcc_assert (amount
>= 0);
14331 add_loc_descr (&ret
, int_loc_descriptor (amount
));
14332 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
14336 add_loc_descr (&ret
, int_loc_descriptor (coeff
));
14337 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14340 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
14343 loc_descr_plus_const (&ret
, constant
);
14347 /* Pick the smallest representation of a constant, rather than just
14348 defaulting to the LEB encoding. */
14351 int clz
= clz_hwi (i
);
14352 int ctz
= ctz_hwi (i
);
14354 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
14355 else if (i
<= 0xff)
14356 op
= DW_OP_const1u
;
14357 else if (i
<= 0xffff)
14358 op
= DW_OP_const2u
;
14359 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
14360 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
14361 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
14362 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
14363 while DW_OP_const4u is 5 bytes. */
14364 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
14365 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
14366 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
14367 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
14368 while DW_OP_const4u is 5 bytes. */
14369 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
14371 else if (DWARF2_ADDR_SIZE
== 4 && i
> 0x7fffffff
14372 && size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
)
14375 /* As i >= 2**31, the double cast above will yield a negative number.
14376 Since wrapping is defined in DWARF expressions we can output big
14377 positive integers as small negative ones, regardless of the size
14380 Here, since the evaluator will handle 32-bit values and since i >=
14381 2**31, we know it's going to be interpreted as a negative literal:
14382 store it this way if we can do better than 5 bytes this way. */
14383 return int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
);
14385 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
14386 op
= DW_OP_const4u
;
14388 /* Past this point, i >= 0x100000000 and thus DW_OP_constu will take at
14389 least 6 bytes: see if we can do better before falling back to it. */
14390 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
14391 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
14392 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes. */
14393 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
14394 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
14395 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
14396 >= HOST_BITS_PER_WIDE_INT
)
14397 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
14398 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes. */
14399 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
14400 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
14401 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
14402 && size_of_uleb128 (i
) > 6)
14403 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
14404 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
14411 op
= DW_OP_const1s
;
14412 else if (i
>= -0x8000)
14413 op
= DW_OP_const2s
;
14414 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
14416 if (size_of_int_loc_descriptor (i
) < 5)
14418 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
14419 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
14422 op
= DW_OP_const4s
;
14426 if (size_of_int_loc_descriptor (i
)
14427 < (unsigned long) 1 + size_of_sleb128 (i
))
14429 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
14430 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
14437 return new_loc_descr (op
, i
, 0);
14440 /* Likewise, for unsigned constants. */
14442 static dw_loc_descr_ref
14443 uint_loc_descriptor (unsigned HOST_WIDE_INT i
)
14445 const unsigned HOST_WIDE_INT max_int
= INTTYPE_MAXIMUM (HOST_WIDE_INT
);
14446 const unsigned HOST_WIDE_INT max_uint
14447 = INTTYPE_MAXIMUM (unsigned HOST_WIDE_INT
);
14449 /* If possible, use the clever signed constants handling. */
14451 return int_loc_descriptor ((HOST_WIDE_INT
) i
);
14453 /* Here, we are left with positive numbers that cannot be represented as
14454 HOST_WIDE_INT, i.e.:
14455 max (HOST_WIDE_INT) < i <= max (unsigned HOST_WIDE_INT)
14457 Using DW_OP_const4/8/./u operation to encode them consumes a lot of bytes
14458 whereas may be better to output a negative integer: thanks to integer
14459 wrapping, we know that:
14460 x = x - 2 ** DWARF2_ADDR_SIZE
14461 = x - 2 * (max (HOST_WIDE_INT) + 1)
14462 So numbers close to max (unsigned HOST_WIDE_INT) could be represented as
14463 small negative integers. Let's try that in cases it will clearly improve
14464 the encoding: there is no gain turning DW_OP_const4u into
14466 if (DWARF2_ADDR_SIZE
* 8 == HOST_BITS_PER_WIDE_INT
14467 && ((DWARF2_ADDR_SIZE
== 4 && i
> max_uint
- 0x8000)
14468 || (DWARF2_ADDR_SIZE
== 8 && i
> max_uint
- 0x80000000)))
14470 const unsigned HOST_WIDE_INT first_shift
= i
- max_int
- 1;
14472 /* Now, -1 < first_shift <= max (HOST_WIDE_INT)
14473 i.e. 0 <= first_shift <= max (HOST_WIDE_INT). */
14474 const HOST_WIDE_INT second_shift
14475 = (HOST_WIDE_INT
) first_shift
- (HOST_WIDE_INT
) max_int
- 1;
14477 /* So we finally have:
14478 -max (HOST_WIDE_INT) - 1 <= second_shift <= -1.
14479 i.e. min (HOST_WIDE_INT) <= second_shift < 0. */
14480 return int_loc_descriptor (second_shift
);
14483 /* Last chance: fallback to a simple constant operation. */
14484 return new_loc_descr
14485 ((HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
14491 /* Generate and return a location description that computes the unsigned
14492 comparison of the two stack top entries (a OP b where b is the top-most
14493 entry and a is the second one). The KIND of comparison can be LT_EXPR,
14494 LE_EXPR, GT_EXPR or GE_EXPR. */
14496 static dw_loc_descr_ref
14497 uint_comparison_loc_list (enum tree_code kind
)
14499 enum dwarf_location_atom op
, flip_op
;
14500 dw_loc_descr_ref ret
, bra_node
, jmp_node
, tmp
;
14517 gcc_unreachable ();
14520 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14521 jmp_node
= new_loc_descr (DW_OP_skip
, 0, 0);
14523 /* Until DWARFv4, operations all work on signed integers. It is nevertheless
14524 possible to perform unsigned comparisons: we just have to distinguish
14527 1. when a and b have the same sign (as signed integers); then we should
14528 return: a OP(signed) b;
14530 2. when a is a negative signed integer while b is a positive one, then a
14531 is a greater unsigned integer than b; likewise when a and b's roles
14534 So first, compare the sign of the two operands. */
14535 ret
= new_loc_descr (DW_OP_over
, 0, 0);
14536 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
14537 add_loc_descr (&ret
, new_loc_descr (DW_OP_xor
, 0, 0));
14538 /* If they have different signs (i.e. they have different sign bits), then
14539 the stack top value has now the sign bit set and thus it's smaller than
14541 add_loc_descr (&ret
, new_loc_descr (DW_OP_lit0
, 0, 0));
14542 add_loc_descr (&ret
, new_loc_descr (DW_OP_lt
, 0, 0));
14543 add_loc_descr (&ret
, bra_node
);
14545 /* We are in case 1. At this point, we know both operands have the same
14546 sign, to it's safe to use the built-in signed comparison. */
14547 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
14548 add_loc_descr (&ret
, jmp_node
);
14550 /* We are in case 2. Here, we know both operands do not have the same sign,
14551 so we have to flip the signed comparison. */
14552 flip_op
= (kind
== LT_EXPR
|| kind
== LE_EXPR
) ? DW_OP_gt
: DW_OP_lt
;
14553 tmp
= new_loc_descr (flip_op
, 0, 0);
14554 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14555 bra_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14556 add_loc_descr (&ret
, tmp
);
14558 /* This dummy operation is necessary to make the two branches join. */
14559 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
14560 jmp_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14561 jmp_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14562 add_loc_descr (&ret
, tmp
);
14567 /* Likewise, but takes the location description lists (might be destructive on
14568 them). Return NULL if either is NULL or if concatenation fails. */
14570 static dw_loc_list_ref
14571 loc_list_from_uint_comparison (dw_loc_list_ref left
, dw_loc_list_ref right
,
14572 enum tree_code kind
)
14574 if (left
== NULL
|| right
== NULL
)
14577 add_loc_list (&left
, right
);
14581 add_loc_descr_to_each (left
, uint_comparison_loc_list (kind
));
14585 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
14586 without actually allocating it. */
14588 static unsigned long
14589 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
14591 return size_of_int_loc_descriptor (i
>> shift
)
14592 + size_of_int_loc_descriptor (shift
)
14596 /* Return size_of_locs (int_loc_descriptor (i)) without
14597 actually allocating it. */
14599 static unsigned long
14600 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
14609 else if (i
<= 0xff)
14611 else if (i
<= 0xffff)
14615 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
14616 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
14617 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
14619 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
14620 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
14621 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
14623 else if (DWARF2_ADDR_SIZE
== 4 && i
> 0x7fffffff
14624 && size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
)
14626 return size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
);
14627 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
14629 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
14630 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
14631 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
14632 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
14634 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
14635 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
14636 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
14638 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
14639 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
14641 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
14650 else if (i
>= -0x8000)
14652 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
14654 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
14656 s
= size_of_int_loc_descriptor (-i
) + 1;
14664 unsigned long r
= 1 + size_of_sleb128 (i
);
14665 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
14667 s
= size_of_int_loc_descriptor (-i
) + 1;
14676 /* Return loc description representing "address" of integer value.
14677 This can appear only as toplevel expression. */
14679 static dw_loc_descr_ref
14680 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
14683 dw_loc_descr_ref loc_result
= NULL
;
14685 if (!(dwarf_version
>= 4 || !dwarf_strict
))
14688 litsize
= size_of_int_loc_descriptor (i
);
14689 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
14690 is more compact. For DW_OP_stack_value we need:
14691 litsize + 1 (DW_OP_stack_value)
14692 and for DW_OP_implicit_value:
14693 1 (DW_OP_implicit_value) + 1 (length) + size. */
14694 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
14696 loc_result
= int_loc_descriptor (i
);
14697 add_loc_descr (&loc_result
,
14698 new_loc_descr (DW_OP_stack_value
, 0, 0));
14702 loc_result
= new_loc_descr (DW_OP_implicit_value
,
14704 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
14705 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
14709 /* Return a location descriptor that designates a base+offset location. */
14711 static dw_loc_descr_ref
14712 based_loc_descr (rtx reg
, poly_int64 offset
,
14713 enum var_init_status initialized
)
14715 unsigned int regno
;
14716 dw_loc_descr_ref result
;
14717 dw_fde_ref fde
= cfun
->fde
;
14719 /* We only use "frame base" when we're sure we're talking about the
14720 post-prologue local stack frame. We do this by *not* running
14721 register elimination until this point, and recognizing the special
14722 argument pointer and soft frame pointer rtx's. */
14723 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
14725 rtx elim
= (ira_use_lra_p
14726 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
14727 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
14731 /* Allow hard frame pointer here even if frame pointer
14732 isn't used since hard frame pointer is encoded with
14733 DW_OP_fbreg which uses the DW_AT_frame_base attribute,
14734 not hard frame pointer directly. */
14735 elim
= strip_offset_and_add (elim
, &offset
);
14736 gcc_assert (elim
== hard_frame_pointer_rtx
14737 || elim
== stack_pointer_rtx
);
14739 /* If drap register is used to align stack, use frame
14740 pointer + offset to access stack variables. If stack
14741 is aligned without drap, use stack pointer + offset to
14742 access stack variables. */
14743 if (crtl
->stack_realign_tried
14744 && reg
== frame_pointer_rtx
)
14747 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
14748 ? HARD_FRAME_POINTER_REGNUM
14750 return new_reg_loc_descr (base_reg
, offset
);
14753 gcc_assert (frame_pointer_fb_offset_valid
);
14754 offset
+= frame_pointer_fb_offset
;
14755 HOST_WIDE_INT const_offset
;
14756 if (offset
.is_constant (&const_offset
))
14757 return new_loc_descr (DW_OP_fbreg
, const_offset
, 0);
14760 dw_loc_descr_ref ret
= new_loc_descr (DW_OP_fbreg
, 0, 0);
14761 loc_descr_plus_const (&ret
, offset
);
14767 regno
= REGNO (reg
);
14768 #ifdef LEAF_REG_REMAP
14769 if (crtl
->uses_only_leaf_regs
)
14771 int leaf_reg
= LEAF_REG_REMAP (regno
);
14772 if (leaf_reg
!= -1)
14773 regno
= (unsigned) leaf_reg
;
14776 regno
= DWARF_FRAME_REGNUM (regno
);
14778 HOST_WIDE_INT const_offset
;
14779 if (!optimize
&& fde
14780 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
)
14781 && offset
.is_constant (&const_offset
))
14783 /* Use cfa+offset to represent the location of arguments passed
14784 on the stack when drap is used to align stack.
14785 Only do this when not optimizing, for optimized code var-tracking
14786 is supposed to track where the arguments live and the register
14787 used as vdrap or drap in some spot might be used for something
14788 else in other part of the routine. */
14789 return new_loc_descr (DW_OP_fbreg
, const_offset
, 0);
14792 result
= new_reg_loc_descr (regno
, offset
);
14794 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14795 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14800 /* Return true if this RTL expression describes a base+offset calculation. */
14803 is_based_loc (const_rtx rtl
)
14805 return (GET_CODE (rtl
) == PLUS
14806 && ((REG_P (XEXP (rtl
, 0))
14807 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
14808 && CONST_INT_P (XEXP (rtl
, 1)))));
14811 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
14814 static dw_loc_descr_ref
14815 tls_mem_loc_descriptor (rtx mem
)
14818 dw_loc_descr_ref loc_result
;
14820 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
14823 base
= get_base_address (MEM_EXPR (mem
));
14826 || !DECL_THREAD_LOCAL_P (base
))
14829 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1, NULL
);
14830 if (loc_result
== NULL
)
14833 if (maybe_ne (MEM_OFFSET (mem
), 0))
14834 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
14839 /* Output debug info about reason why we failed to expand expression as dwarf
14843 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
14845 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
14847 fprintf (dump_file
, "Failed to expand as dwarf: ");
14849 print_generic_expr (dump_file
, expr
, dump_flags
);
14852 fprintf (dump_file
, "\n");
14853 print_rtl (dump_file
, rtl
);
14855 fprintf (dump_file
, "\nReason: %s\n", reason
);
14859 /* Helper function for const_ok_for_output. */
14862 const_ok_for_output_1 (rtx rtl
)
14864 if (targetm
.const_not_ok_for_debug_p (rtl
))
14866 if (GET_CODE (rtl
) != UNSPEC
)
14868 expansion_failed (NULL_TREE
, rtl
,
14869 "Expression rejected for debug by the backend.\n");
14873 /* If delegitimize_address couldn't do anything with the UNSPEC, and
14874 the target hook doesn't explicitly allow it in debug info, assume
14875 we can't express it in the debug info. */
14876 /* Don't complain about TLS UNSPECs, those are just too hard to
14877 delegitimize. Note this could be a non-decl SYMBOL_REF such as
14878 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
14879 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
14881 && (XVECLEN (rtl
, 0) == 0
14882 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
14883 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
))
14884 inform (current_function_decl
14885 ? DECL_SOURCE_LOCATION (current_function_decl
)
14886 : UNKNOWN_LOCATION
,
14887 #if NUM_UNSPEC_VALUES > 0
14888 "non-delegitimized UNSPEC %s (%d) found in variable location",
14889 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
14890 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
14892 "non-delegitimized UNSPEC %d found in variable location",
14895 expansion_failed (NULL_TREE
, rtl
,
14896 "UNSPEC hasn't been delegitimized.\n");
14900 if (CONST_POLY_INT_P (rtl
))
14903 /* FIXME: Refer to PR60655. It is possible for simplification
14904 of rtl expressions in var tracking to produce such expressions.
14905 We should really identify / validate expressions
14906 enclosed in CONST that can be handled by assemblers on various
14907 targets and only handle legitimate cases here. */
14908 switch (GET_CODE (rtl
))
14917 /* Make sure SYMBOL_REFs/UNSPECs are at most in one of the
14919 subrtx_var_iterator::array_type array
;
14920 bool first
= false;
14921 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 0), ALL
)
14922 if (SYMBOL_REF_P (*iter
)
14924 || GET_CODE (*iter
) == UNSPEC
)
14931 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 1), ALL
)
14932 if (SYMBOL_REF_P (*iter
)
14934 || GET_CODE (*iter
) == UNSPEC
)
14940 /* Disallow negation of SYMBOL_REFs or UNSPECs when they
14941 appear in the second operand of MINUS. */
14942 subrtx_var_iterator::array_type array
;
14943 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 1), ALL
)
14944 if (SYMBOL_REF_P (*iter
)
14946 || GET_CODE (*iter
) == UNSPEC
)
14954 if (CONSTANT_POOL_ADDRESS_P (rtl
))
14957 get_pool_constant_mark (rtl
, &marked
);
14958 /* If all references to this pool constant were optimized away,
14959 it was not output and thus we can't represent it. */
14962 expansion_failed (NULL_TREE
, rtl
,
14963 "Constant was removed from constant pool.\n");
14968 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
14971 /* Avoid references to external symbols in debug info, on several targets
14972 the linker might even refuse to link when linking a shared library,
14973 and in many other cases the relocations for .debug_info/.debug_loc are
14974 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
14975 to be defined within the same shared library or executable are fine. */
14976 if (SYMBOL_REF_EXTERNAL_P (rtl
))
14978 tree decl
= SYMBOL_REF_DECL (rtl
);
14980 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
14982 expansion_failed (NULL_TREE
, rtl
,
14983 "Symbol not defined in current TU.\n");
14991 /* Return true if constant RTL can be emitted in DW_OP_addr or
14992 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
14993 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
14996 const_ok_for_output (rtx rtl
)
14998 if (GET_CODE (rtl
) == SYMBOL_REF
)
14999 return const_ok_for_output_1 (rtl
);
15001 if (GET_CODE (rtl
) == CONST
)
15003 subrtx_var_iterator::array_type array
;
15004 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 0), ALL
)
15005 if (!const_ok_for_output_1 (*iter
))
15013 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
15014 if possible, NULL otherwise. */
15017 base_type_for_mode (machine_mode mode
, bool unsignedp
)
15019 dw_die_ref type_die
;
15020 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
15024 switch (TREE_CODE (type
))
15032 type_die
= lookup_type_die (type
);
15034 type_die
= modified_type_die (type
, TYPE_UNQUALIFIED
, false,
15036 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
15041 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
15042 type matching MODE, or, if MODE is narrower than or as wide as
15043 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
15046 static dw_loc_descr_ref
15047 convert_descriptor_to_mode (scalar_int_mode mode
, dw_loc_descr_ref op
)
15049 machine_mode outer_mode
= mode
;
15050 dw_die_ref type_die
;
15051 dw_loc_descr_ref cvt
;
15053 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
15055 add_loc_descr (&op
, new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0));
15058 type_die
= base_type_for_mode (outer_mode
, 1);
15059 if (type_die
== NULL
)
15061 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15062 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15063 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15064 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15065 add_loc_descr (&op
, cvt
);
15069 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
15071 static dw_loc_descr_ref
15072 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
15073 dw_loc_descr_ref op1
)
15075 dw_loc_descr_ref ret
= op0
;
15076 add_loc_descr (&ret
, op1
);
15077 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
15078 if (STORE_FLAG_VALUE
!= 1)
15080 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
15081 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
15086 /* Subroutine of scompare_loc_descriptor for the case in which we're
15087 comparing two scalar integer operands OP0 and OP1 that have mode OP_MODE,
15088 and in which OP_MODE is bigger than DWARF2_ADDR_SIZE. */
15090 static dw_loc_descr_ref
15091 scompare_loc_descriptor_wide (enum dwarf_location_atom op
,
15092 scalar_int_mode op_mode
,
15093 dw_loc_descr_ref op0
, dw_loc_descr_ref op1
)
15095 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
15096 dw_loc_descr_ref cvt
;
15098 if (type_die
== NULL
)
15100 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15101 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15102 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15103 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15104 add_loc_descr (&op0
, cvt
);
15105 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15106 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15107 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15108 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15109 add_loc_descr (&op1
, cvt
);
15110 return compare_loc_descriptor (op
, op0
, op1
);
15113 /* Subroutine of scompare_loc_descriptor for the case in which we're
15114 comparing two scalar integer operands OP0 and OP1 that have mode OP_MODE,
15115 and in which OP_MODE is smaller than DWARF2_ADDR_SIZE. */
15117 static dw_loc_descr_ref
15118 scompare_loc_descriptor_narrow (enum dwarf_location_atom op
, rtx rtl
,
15119 scalar_int_mode op_mode
,
15120 dw_loc_descr_ref op0
, dw_loc_descr_ref op1
)
15122 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
15123 /* For eq/ne, if the operands are known to be zero-extended,
15124 there is no need to do the fancy shifting up. */
15125 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
15127 dw_loc_descr_ref last0
, last1
;
15128 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
15130 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
15132 /* deref_size zero extends, and for constants we can check
15133 whether they are zero extended or not. */
15134 if (((last0
->dw_loc_opc
== DW_OP_deref_size
15135 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
15136 || (CONST_INT_P (XEXP (rtl
, 0))
15137 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
15138 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
15139 && ((last1
->dw_loc_opc
== DW_OP_deref_size
15140 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
15141 || (CONST_INT_P (XEXP (rtl
, 1))
15142 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
15143 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
15144 return compare_loc_descriptor (op
, op0
, op1
);
15146 /* EQ/NE comparison against constant in narrower type than
15147 DWARF2_ADDR_SIZE can be performed either as
15148 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
15151 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
15152 DW_OP_{eq,ne}. Pick whatever is shorter. */
15153 if (CONST_INT_P (XEXP (rtl
, 1))
15154 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
15155 && (size_of_int_loc_descriptor (shift
) + 1
15156 + size_of_int_loc_descriptor (UINTVAL (XEXP (rtl
, 1)) << shift
)
15157 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
15158 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
15159 & GET_MODE_MASK (op_mode
))))
15161 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
15162 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
15163 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
15164 & GET_MODE_MASK (op_mode
));
15165 return compare_loc_descriptor (op
, op0
, op1
);
15168 add_loc_descr (&op0
, int_loc_descriptor (shift
));
15169 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
15170 if (CONST_INT_P (XEXP (rtl
, 1)))
15171 op1
= int_loc_descriptor (UINTVAL (XEXP (rtl
, 1)) << shift
);
15174 add_loc_descr (&op1
, int_loc_descriptor (shift
));
15175 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
15177 return compare_loc_descriptor (op
, op0
, op1
);
15180 /* Return location descriptor for signed comparison OP RTL. */
15182 static dw_loc_descr_ref
15183 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
15184 machine_mode mem_mode
)
15186 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
15187 dw_loc_descr_ref op0
, op1
;
15189 if (op_mode
== VOIDmode
)
15190 op_mode
= GET_MODE (XEXP (rtl
, 1));
15191 if (op_mode
== VOIDmode
)
15194 scalar_int_mode int_op_mode
;
15196 && dwarf_version
< 5
15197 && (!is_a
<scalar_int_mode
> (op_mode
, &int_op_mode
)
15198 || GET_MODE_SIZE (int_op_mode
) > DWARF2_ADDR_SIZE
))
15201 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
15202 VAR_INIT_STATUS_INITIALIZED
);
15203 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
15204 VAR_INIT_STATUS_INITIALIZED
);
15206 if (op0
== NULL
|| op1
== NULL
)
15209 if (is_a
<scalar_int_mode
> (op_mode
, &int_op_mode
))
15211 if (GET_MODE_SIZE (int_op_mode
) < DWARF2_ADDR_SIZE
)
15212 return scompare_loc_descriptor_narrow (op
, rtl
, int_op_mode
, op0
, op1
);
15214 if (GET_MODE_SIZE (int_op_mode
) > DWARF2_ADDR_SIZE
)
15215 return scompare_loc_descriptor_wide (op
, int_op_mode
, op0
, op1
);
15217 return compare_loc_descriptor (op
, op0
, op1
);
15220 /* Return location descriptor for unsigned comparison OP RTL. */
15222 static dw_loc_descr_ref
15223 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
15224 machine_mode mem_mode
)
15226 dw_loc_descr_ref op0
, op1
;
15228 machine_mode test_op_mode
= GET_MODE (XEXP (rtl
, 0));
15229 if (test_op_mode
== VOIDmode
)
15230 test_op_mode
= GET_MODE (XEXP (rtl
, 1));
15232 scalar_int_mode op_mode
;
15233 if (!is_a
<scalar_int_mode
> (test_op_mode
, &op_mode
))
15237 && dwarf_version
< 5
15238 && GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
15241 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
15242 VAR_INIT_STATUS_INITIALIZED
);
15243 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
15244 VAR_INIT_STATUS_INITIALIZED
);
15246 if (op0
== NULL
|| op1
== NULL
)
15249 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
15251 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
15252 dw_loc_descr_ref last0
, last1
;
15253 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
15255 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
15257 if (CONST_INT_P (XEXP (rtl
, 0)))
15258 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
15259 /* deref_size zero extends, so no need to mask it again. */
15260 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
15261 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
15263 add_loc_descr (&op0
, int_loc_descriptor (mask
));
15264 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
15266 if (CONST_INT_P (XEXP (rtl
, 1)))
15267 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
15268 /* deref_size zero extends, so no need to mask it again. */
15269 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
15270 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
15272 add_loc_descr (&op1
, int_loc_descriptor (mask
));
15273 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
15276 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
15278 HOST_WIDE_INT bias
= 1;
15279 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
15280 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
15281 if (CONST_INT_P (XEXP (rtl
, 1)))
15282 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
15283 + INTVAL (XEXP (rtl
, 1)));
15285 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
15288 return compare_loc_descriptor (op
, op0
, op1
);
15291 /* Return location descriptor for {U,S}{MIN,MAX}. */
15293 static dw_loc_descr_ref
15294 minmax_loc_descriptor (rtx rtl
, machine_mode mode
,
15295 machine_mode mem_mode
)
15297 enum dwarf_location_atom op
;
15298 dw_loc_descr_ref op0
, op1
, ret
;
15299 dw_loc_descr_ref bra_node
, drop_node
;
15301 scalar_int_mode int_mode
;
15303 && dwarf_version
< 5
15304 && (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
15305 || GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
))
15308 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15309 VAR_INIT_STATUS_INITIALIZED
);
15310 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15311 VAR_INIT_STATUS_INITIALIZED
);
15313 if (op0
== NULL
|| op1
== NULL
)
15316 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
15317 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
15318 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
15319 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
15321 /* Checked by the caller. */
15322 int_mode
= as_a
<scalar_int_mode
> (mode
);
15323 if (GET_MODE_SIZE (int_mode
) < DWARF2_ADDR_SIZE
)
15325 HOST_WIDE_INT mask
= GET_MODE_MASK (int_mode
);
15326 add_loc_descr (&op0
, int_loc_descriptor (mask
));
15327 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
15328 add_loc_descr (&op1
, int_loc_descriptor (mask
));
15329 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
15331 else if (GET_MODE_SIZE (int_mode
) == DWARF2_ADDR_SIZE
)
15333 HOST_WIDE_INT bias
= 1;
15334 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
15335 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
15336 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
15339 else if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
15340 && GET_MODE_SIZE (int_mode
) < DWARF2_ADDR_SIZE
)
15342 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (int_mode
)) * BITS_PER_UNIT
;
15343 add_loc_descr (&op0
, int_loc_descriptor (shift
));
15344 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
15345 add_loc_descr (&op1
, int_loc_descriptor (shift
));
15346 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
15348 else if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
15349 && GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
15351 dw_die_ref type_die
= base_type_for_mode (int_mode
, 0);
15352 dw_loc_descr_ref cvt
;
15353 if (type_die
== NULL
)
15355 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15356 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15357 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15358 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15359 add_loc_descr (&op0
, cvt
);
15360 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15361 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15362 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15363 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15364 add_loc_descr (&op1
, cvt
);
15367 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
15372 add_loc_descr (&ret
, op1
);
15373 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
15374 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
15375 add_loc_descr (&ret
, bra_node
);
15376 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15377 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
15378 add_loc_descr (&ret
, drop_node
);
15379 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15380 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
15381 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
15382 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
15383 && GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
15384 ret
= convert_descriptor_to_mode (int_mode
, ret
);
15388 /* Helper function for mem_loc_descriptor. Perform OP binary op,
15389 but after converting arguments to type_die, afterwards
15390 convert back to unsigned. */
15392 static dw_loc_descr_ref
15393 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
15394 scalar_int_mode mode
, machine_mode mem_mode
)
15396 dw_loc_descr_ref cvt
, op0
, op1
;
15398 if (type_die
== NULL
)
15400 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15401 VAR_INIT_STATUS_INITIALIZED
);
15402 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15403 VAR_INIT_STATUS_INITIALIZED
);
15404 if (op0
== NULL
|| op1
== NULL
)
15406 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15407 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15408 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15409 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15410 add_loc_descr (&op0
, cvt
);
15411 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15412 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15413 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15414 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15415 add_loc_descr (&op1
, cvt
);
15416 add_loc_descr (&op0
, op1
);
15417 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
15418 return convert_descriptor_to_mode (mode
, op0
);
15421 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
15422 const0 is DW_OP_lit0 or corresponding typed constant,
15423 const1 is DW_OP_lit1 or corresponding typed constant
15424 and constMSB is constant with just the MSB bit set
15426 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
15427 L1: const0 DW_OP_swap
15428 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
15429 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
15434 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
15435 L1: const0 DW_OP_swap
15436 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
15437 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
15442 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
15443 L1: const1 DW_OP_swap
15444 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
15445 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
15449 static dw_loc_descr_ref
15450 clz_loc_descriptor (rtx rtl
, scalar_int_mode mode
,
15451 machine_mode mem_mode
)
15453 dw_loc_descr_ref op0
, ret
, tmp
;
15454 HOST_WIDE_INT valv
;
15455 dw_loc_descr_ref l1jump
, l1label
;
15456 dw_loc_descr_ref l2jump
, l2label
;
15457 dw_loc_descr_ref l3jump
, l3label
;
15458 dw_loc_descr_ref l4jump
, l4label
;
15461 if (GET_MODE (XEXP (rtl
, 0)) != mode
)
15464 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15465 VAR_INIT_STATUS_INITIALIZED
);
15469 if (GET_CODE (rtl
) == CLZ
)
15471 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
15472 valv
= GET_MODE_BITSIZE (mode
);
15474 else if (GET_CODE (rtl
) == FFS
)
15476 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
15477 valv
= GET_MODE_BITSIZE (mode
);
15478 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
15479 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
15480 add_loc_descr (&ret
, l1jump
);
15481 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
15482 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
15483 VAR_INIT_STATUS_INITIALIZED
);
15486 add_loc_descr (&ret
, tmp
);
15487 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
15488 add_loc_descr (&ret
, l4jump
);
15489 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
15490 ? const1_rtx
: const0_rtx
,
15492 VAR_INIT_STATUS_INITIALIZED
);
15493 if (l1label
== NULL
)
15495 add_loc_descr (&ret
, l1label
);
15496 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15497 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
15498 add_loc_descr (&ret
, l2label
);
15499 if (GET_CODE (rtl
) != CLZ
)
15501 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
15502 msb
= GEN_INT (HOST_WIDE_INT_1U
15503 << (GET_MODE_BITSIZE (mode
) - 1));
15505 msb
= immed_wide_int_const
15506 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode
) - 1,
15507 GET_MODE_PRECISION (mode
)), mode
);
15508 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
15509 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
15510 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
15511 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
15513 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
15514 VAR_INIT_STATUS_INITIALIZED
);
15517 add_loc_descr (&ret
, tmp
);
15518 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
15519 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
15520 add_loc_descr (&ret
, l3jump
);
15521 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
15522 VAR_INIT_STATUS_INITIALIZED
);
15525 add_loc_descr (&ret
, tmp
);
15526 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
15527 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
15528 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15529 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
15530 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15531 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
15532 add_loc_descr (&ret
, l2jump
);
15533 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
15534 add_loc_descr (&ret
, l3label
);
15535 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
15536 add_loc_descr (&ret
, l4label
);
15537 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15538 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
15539 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15540 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
15541 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15542 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
15543 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15544 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
15548 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
15549 const1 is DW_OP_lit1 or corresponding typed constant):
15551 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
15552 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
15556 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
15557 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
15560 static dw_loc_descr_ref
15561 popcount_loc_descriptor (rtx rtl
, scalar_int_mode mode
,
15562 machine_mode mem_mode
)
15564 dw_loc_descr_ref op0
, ret
, tmp
;
15565 dw_loc_descr_ref l1jump
, l1label
;
15566 dw_loc_descr_ref l2jump
, l2label
;
15568 if (GET_MODE (XEXP (rtl
, 0)) != mode
)
15571 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15572 VAR_INIT_STATUS_INITIALIZED
);
15576 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
15577 VAR_INIT_STATUS_INITIALIZED
);
15580 add_loc_descr (&ret
, tmp
);
15581 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15582 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
15583 add_loc_descr (&ret
, l1label
);
15584 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
15585 add_loc_descr (&ret
, l2jump
);
15586 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
15587 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
15588 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
15589 VAR_INIT_STATUS_INITIALIZED
);
15592 add_loc_descr (&ret
, tmp
);
15593 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
15594 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
15595 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
15596 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15597 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
15598 VAR_INIT_STATUS_INITIALIZED
);
15599 add_loc_descr (&ret
, tmp
);
15600 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
15601 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
15602 add_loc_descr (&ret
, l1jump
);
15603 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
15604 add_loc_descr (&ret
, l2label
);
15605 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15606 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
15607 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15608 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
15612 /* BSWAP (constS is initial shift count, either 56 or 24):
15614 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
15615 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
15616 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
15617 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
15618 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
15620 static dw_loc_descr_ref
15621 bswap_loc_descriptor (rtx rtl
, scalar_int_mode mode
,
15622 machine_mode mem_mode
)
15624 dw_loc_descr_ref op0
, ret
, tmp
;
15625 dw_loc_descr_ref l1jump
, l1label
;
15626 dw_loc_descr_ref l2jump
, l2label
;
15628 if (BITS_PER_UNIT
!= 8
15629 || (GET_MODE_BITSIZE (mode
) != 32
15630 && GET_MODE_BITSIZE (mode
) != 64))
15633 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15634 VAR_INIT_STATUS_INITIALIZED
);
15639 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
15641 VAR_INIT_STATUS_INITIALIZED
);
15644 add_loc_descr (&ret
, tmp
);
15645 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
15646 VAR_INIT_STATUS_INITIALIZED
);
15649 add_loc_descr (&ret
, tmp
);
15650 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
15651 add_loc_descr (&ret
, l1label
);
15652 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
15654 VAR_INIT_STATUS_INITIALIZED
);
15655 add_loc_descr (&ret
, tmp
);
15656 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
15657 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
15658 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
15659 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
15660 VAR_INIT_STATUS_INITIALIZED
);
15663 add_loc_descr (&ret
, tmp
);
15664 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
15665 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
15666 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
15667 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
15668 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15669 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
15670 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
15671 VAR_INIT_STATUS_INITIALIZED
);
15672 add_loc_descr (&ret
, tmp
);
15673 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
15674 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
15675 add_loc_descr (&ret
, l2jump
);
15676 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
15677 VAR_INIT_STATUS_INITIALIZED
);
15678 add_loc_descr (&ret
, tmp
);
15679 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
15680 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15681 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
15682 add_loc_descr (&ret
, l1jump
);
15683 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
15684 add_loc_descr (&ret
, l2label
);
15685 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15686 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
15687 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15688 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
15689 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15690 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
15694 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
15695 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
15696 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
15697 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
15699 ROTATERT is similar:
15700 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
15701 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
15702 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
15704 static dw_loc_descr_ref
15705 rotate_loc_descriptor (rtx rtl
, scalar_int_mode mode
,
15706 machine_mode mem_mode
)
15708 rtx rtlop1
= XEXP (rtl
, 1);
15709 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
15712 if (is_narrower_int_mode (GET_MODE (rtlop1
), mode
))
15713 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
15714 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15715 VAR_INIT_STATUS_INITIALIZED
);
15716 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
15717 VAR_INIT_STATUS_INITIALIZED
);
15718 if (op0
== NULL
|| op1
== NULL
)
15720 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
15721 for (i
= 0; i
< 2; i
++)
15723 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
15724 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
15726 VAR_INIT_STATUS_INITIALIZED
);
15727 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
15728 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
15730 : HOST_BITS_PER_WIDE_INT
== 64
15731 ? DW_OP_const8u
: DW_OP_constu
,
15732 GET_MODE_MASK (mode
), 0);
15735 if (mask
[i
] == NULL
)
15737 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
15740 add_loc_descr (&ret
, op1
);
15741 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
15742 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
15743 if (GET_CODE (rtl
) == ROTATERT
)
15745 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
15746 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
15747 GET_MODE_BITSIZE (mode
), 0));
15749 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
15750 if (mask
[0] != NULL
)
15751 add_loc_descr (&ret
, mask
[0]);
15752 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
15753 if (mask
[1] != NULL
)
15755 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15756 add_loc_descr (&ret
, mask
[1]);
15757 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
15759 if (GET_CODE (rtl
) == ROTATE
)
15761 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
15762 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
15763 GET_MODE_BITSIZE (mode
), 0));
15765 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
15766 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
15770 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
15771 for DEBUG_PARAMETER_REF RTL. */
15773 static dw_loc_descr_ref
15774 parameter_ref_descriptor (rtx rtl
)
15776 dw_loc_descr_ref ret
;
15781 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
15782 /* With LTO during LTRANS we get the late DIE that refers to the early
15783 DIE, thus we add another indirection here. This seems to confuse
15784 gdb enough to make gcc.dg/guality/pr68860-1.c FAIL with LTO. */
15785 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
15786 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
15789 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15790 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
15791 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15795 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
15796 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
15801 /* The following routine converts the RTL for a variable or parameter
15802 (resident in memory) into an equivalent Dwarf representation of a
15803 mechanism for getting the address of that same variable onto the top of a
15804 hypothetical "address evaluation" stack.
15806 When creating memory location descriptors, we are effectively transforming
15807 the RTL for a memory-resident object into its Dwarf postfix expression
15808 equivalent. This routine recursively descends an RTL tree, turning
15809 it into Dwarf postfix code as it goes.
15811 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
15813 MEM_MODE is the mode of the memory reference, needed to handle some
15814 autoincrement addressing modes.
15816 Return 0 if we can't represent the location. */
15819 mem_loc_descriptor (rtx rtl
, machine_mode mode
,
15820 machine_mode mem_mode
,
15821 enum var_init_status initialized
)
15823 dw_loc_descr_ref mem_loc_result
= NULL
;
15824 enum dwarf_location_atom op
;
15825 dw_loc_descr_ref op0
, op1
;
15826 rtx inner
= NULL_RTX
;
15829 if (mode
== VOIDmode
)
15830 mode
= GET_MODE (rtl
);
15832 /* Note that for a dynamically sized array, the location we will generate a
15833 description of here will be the lowest numbered location which is
15834 actually within the array. That's *not* necessarily the same as the
15835 zeroth element of the array. */
15837 rtl
= targetm
.delegitimize_address (rtl
);
15839 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
15842 scalar_int_mode int_mode
= BImode
, inner_mode
, op1_mode
;
15843 switch (GET_CODE (rtl
))
15848 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
15851 /* The case of a subreg may arise when we have a local (register)
15852 variable or a formal (register) parameter which doesn't quite fill
15853 up an entire register. For now, just assume that it is
15854 legitimate to make the Dwarf info refer to the whole register which
15855 contains the given subreg. */
15856 if (!subreg_lowpart_p (rtl
))
15858 inner
= SUBREG_REG (rtl
);
15861 if (inner
== NULL_RTX
)
15862 inner
= XEXP (rtl
, 0);
15863 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
15864 && is_a
<scalar_int_mode
> (GET_MODE (inner
), &inner_mode
)
15865 && (GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
15866 #ifdef POINTERS_EXTEND_UNSIGNED
15867 || (int_mode
== Pmode
&& mem_mode
!= VOIDmode
)
15870 && GET_MODE_SIZE (inner_mode
) <= DWARF2_ADDR_SIZE
)
15872 mem_loc_result
= mem_loc_descriptor (inner
,
15874 mem_mode
, initialized
);
15877 if (dwarf_strict
&& dwarf_version
< 5)
15879 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
15880 && is_a
<scalar_int_mode
> (GET_MODE (inner
), &inner_mode
)
15881 ? GET_MODE_SIZE (int_mode
) <= GET_MODE_SIZE (inner_mode
)
15882 : known_eq (GET_MODE_SIZE (mode
), GET_MODE_SIZE (GET_MODE (inner
))))
15884 dw_die_ref type_die
;
15885 dw_loc_descr_ref cvt
;
15887 mem_loc_result
= mem_loc_descriptor (inner
,
15889 mem_mode
, initialized
);
15890 if (mem_loc_result
== NULL
)
15892 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
15893 if (type_die
== NULL
)
15895 mem_loc_result
= NULL
;
15898 if (maybe_ne (GET_MODE_SIZE (mode
), GET_MODE_SIZE (GET_MODE (inner
))))
15899 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15901 cvt
= new_loc_descr (dwarf_OP (DW_OP_reinterpret
), 0, 0);
15902 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15903 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15904 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15905 add_loc_descr (&mem_loc_result
, cvt
);
15906 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
15907 && GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
)
15909 /* Convert it to untyped afterwards. */
15910 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15911 add_loc_descr (&mem_loc_result
, cvt
);
15917 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
15918 || (GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
15919 && rtl
!= arg_pointer_rtx
15920 && rtl
!= frame_pointer_rtx
15921 #ifdef POINTERS_EXTEND_UNSIGNED
15922 && (int_mode
!= Pmode
|| mem_mode
== VOIDmode
)
15926 dw_die_ref type_die
;
15927 unsigned int dbx_regnum
;
15929 if (dwarf_strict
&& dwarf_version
< 5)
15931 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
15933 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
15934 if (type_die
== NULL
)
15937 dbx_regnum
= dbx_reg_number (rtl
);
15938 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
15940 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_regval_type
),
15942 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
15943 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
15944 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
15947 /* Whenever a register number forms a part of the description of the
15948 method for calculating the (dynamic) address of a memory resident
15949 object, DWARF rules require the register number be referred to as
15950 a "base register". This distinction is not based in any way upon
15951 what category of register the hardware believes the given register
15952 belongs to. This is strictly DWARF terminology we're dealing with
15953 here. Note that in cases where the location of a memory-resident
15954 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
15955 OP_CONST (0)) the actual DWARF location descriptor that we generate
15956 may just be OP_BASEREG (basereg). This may look deceptively like
15957 the object in question was allocated to a register (rather than in
15958 memory) so DWARF consumers need to be aware of the subtle
15959 distinction between OP_REG and OP_BASEREG. */
15960 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
15961 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
15962 else if (stack_realign_drap
15964 && crtl
->args
.internal_arg_pointer
== rtl
15965 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
15967 /* If RTL is internal_arg_pointer, which has been optimized
15968 out, use DRAP instead. */
15969 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
15970 VAR_INIT_STATUS_INITIALIZED
);
15976 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
15977 || !is_a
<scalar_int_mode
> (GET_MODE (XEXP (rtl
, 0)), &inner_mode
))
15979 op0
= mem_loc_descriptor (XEXP (rtl
, 0), inner_mode
,
15980 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
15983 else if (GET_CODE (rtl
) == ZERO_EXTEND
15984 && GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
15985 && GET_MODE_BITSIZE (inner_mode
) < HOST_BITS_PER_WIDE_INT
15986 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
15987 to expand zero extend as two shifts instead of
15989 && GET_MODE_SIZE (inner_mode
) <= 4)
15991 mem_loc_result
= op0
;
15992 add_loc_descr (&mem_loc_result
,
15993 int_loc_descriptor (GET_MODE_MASK (inner_mode
)));
15994 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
15996 else if (GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
)
15998 int shift
= DWARF2_ADDR_SIZE
- GET_MODE_SIZE (inner_mode
);
15999 shift
*= BITS_PER_UNIT
;
16000 if (GET_CODE (rtl
) == SIGN_EXTEND
)
16004 mem_loc_result
= op0
;
16005 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
16006 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
16007 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
16008 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
16010 else if (!dwarf_strict
|| dwarf_version
>= 5)
16012 dw_die_ref type_die1
, type_die2
;
16013 dw_loc_descr_ref cvt
;
16015 type_die1
= base_type_for_mode (inner_mode
,
16016 GET_CODE (rtl
) == ZERO_EXTEND
);
16017 if (type_die1
== NULL
)
16019 type_die2
= base_type_for_mode (int_mode
, 1);
16020 if (type_die2
== NULL
)
16022 mem_loc_result
= op0
;
16023 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
16024 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16025 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
16026 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16027 add_loc_descr (&mem_loc_result
, cvt
);
16028 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
16029 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16030 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
16031 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16032 add_loc_descr (&mem_loc_result
, cvt
);
16038 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
16039 if (new_rtl
!= rtl
)
16041 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
16043 if (mem_loc_result
!= NULL
)
16044 return mem_loc_result
;
16047 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
16048 get_address_mode (rtl
), mode
,
16049 VAR_INIT_STATUS_INITIALIZED
);
16050 if (mem_loc_result
== NULL
)
16051 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
16052 if (mem_loc_result
!= NULL
)
16054 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
16055 || GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
16057 dw_die_ref type_die
;
16058 dw_loc_descr_ref deref
;
16059 HOST_WIDE_INT size
;
16061 if (dwarf_strict
&& dwarf_version
< 5)
16063 if (!GET_MODE_SIZE (mode
).is_constant (&size
))
16066 = base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
16067 if (type_die
== NULL
)
16069 deref
= new_loc_descr (dwarf_OP (DW_OP_deref_type
), size
, 0);
16070 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
16071 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
16072 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
16073 add_loc_descr (&mem_loc_result
, deref
);
16075 else if (GET_MODE_SIZE (int_mode
) == DWARF2_ADDR_SIZE
)
16076 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
16078 add_loc_descr (&mem_loc_result
,
16079 new_loc_descr (DW_OP_deref_size
,
16080 GET_MODE_SIZE (int_mode
), 0));
16085 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
16088 /* Some ports can transform a symbol ref into a label ref, because
16089 the symbol ref is too far away and has to be dumped into a constant
16094 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
16095 || (GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
16096 #ifdef POINTERS_EXTEND_UNSIGNED
16097 && (int_mode
!= Pmode
|| mem_mode
== VOIDmode
)
16102 if (GET_CODE (rtl
) == UNSPEC
)
16104 /* If delegitimize_address couldn't do anything with the UNSPEC, we
16105 can't express it in the debug info. This can happen e.g. with some
16106 TLS UNSPECs. Allow UNSPECs formerly from CONST that the backend
16108 bool not_ok
= false;
16109 subrtx_var_iterator::array_type array
;
16110 FOR_EACH_SUBRTX_VAR (iter
, array
, rtl
, ALL
)
16111 if (*iter
!= rtl
&& !CONSTANT_P (*iter
))
16120 FOR_EACH_SUBRTX_VAR (iter
, array
, rtl
, ALL
)
16121 if (!const_ok_for_output_1 (*iter
))
16130 rtl
= gen_rtx_CONST (GET_MODE (rtl
), rtl
);
16134 if (GET_CODE (rtl
) == SYMBOL_REF
16135 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
16137 dw_loc_descr_ref temp
;
16139 /* If this is not defined, we have no way to emit the data. */
16140 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
16143 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
16145 /* We check for DWARF 5 here because gdb did not implement
16146 DW_OP_form_tls_address until after 7.12. */
16147 mem_loc_result
= new_loc_descr ((dwarf_version
>= 5
16148 ? DW_OP_form_tls_address
16149 : DW_OP_GNU_push_tls_address
),
16151 add_loc_descr (&mem_loc_result
, temp
);
16156 if (!const_ok_for_output (rtl
))
16158 if (GET_CODE (rtl
) == CONST
)
16159 switch (GET_CODE (XEXP (rtl
, 0)))
16163 goto try_const_unop
;
16166 goto try_const_unop
;
16169 arg
= XEXP (XEXP (rtl
, 0), 0);
16170 if (!CONSTANT_P (arg
))
16171 arg
= gen_rtx_CONST (int_mode
, arg
);
16172 op0
= mem_loc_descriptor (arg
, int_mode
, mem_mode
,
16176 mem_loc_result
= op0
;
16177 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
16181 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), int_mode
,
16182 mem_mode
, initialized
);
16189 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
16190 vec_safe_push (used_rtx_array
, rtl
);
16196 case DEBUG_IMPLICIT_PTR
:
16197 expansion_failed (NULL_TREE
, rtl
,
16198 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
16202 if (dwarf_strict
&& dwarf_version
< 5)
16204 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
16206 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
16207 || GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
16208 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
16209 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
16212 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
16213 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
16215 op0
= one_reg_loc_descriptor (dbx_regnum
,
16216 VAR_INIT_STATUS_INITIALIZED
);
16219 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
16220 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
16222 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
16223 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
16224 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
16228 gcc_unreachable ();
16231 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_entry_value
), 0, 0);
16232 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
16233 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
16236 case DEBUG_PARAMETER_REF
:
16237 mem_loc_result
= parameter_ref_descriptor (rtl
);
16241 /* Extract the PLUS expression nested inside and fall into
16242 PLUS code below. */
16243 rtl
= XEXP (rtl
, 1);
16248 /* Turn these into a PLUS expression and fall into the PLUS code
16250 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
16251 gen_int_mode (GET_CODE (rtl
) == PRE_INC
16252 ? GET_MODE_UNIT_SIZE (mem_mode
)
16253 : -GET_MODE_UNIT_SIZE (mem_mode
),
16260 if (is_based_loc (rtl
)
16261 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
16262 && (GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
16263 || XEXP (rtl
, 0) == arg_pointer_rtx
16264 || XEXP (rtl
, 0) == frame_pointer_rtx
))
16265 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
16266 INTVAL (XEXP (rtl
, 1)),
16267 VAR_INIT_STATUS_INITIALIZED
);
16270 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
16271 VAR_INIT_STATUS_INITIALIZED
);
16272 if (mem_loc_result
== 0)
16275 if (CONST_INT_P (XEXP (rtl
, 1))
16276 && (GET_MODE_SIZE (as_a
<scalar_int_mode
> (mode
))
16277 <= DWARF2_ADDR_SIZE
))
16278 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
16281 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
16282 VAR_INIT_STATUS_INITIALIZED
);
16285 add_loc_descr (&mem_loc_result
, op1
);
16286 add_loc_descr (&mem_loc_result
,
16287 new_loc_descr (DW_OP_plus
, 0, 0));
16292 /* If a pseudo-reg is optimized away, it is possible for it to
16293 be replaced with a MEM containing a multiply or shift. */
16303 if ((!dwarf_strict
|| dwarf_version
>= 5)
16304 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
16305 && GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
16307 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
16308 base_type_for_mode (mode
, 0),
16309 int_mode
, mem_mode
);
16332 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
))
16334 op0
= mem_loc_descriptor (XEXP (rtl
, 0), int_mode
, mem_mode
,
16335 VAR_INIT_STATUS_INITIALIZED
);
16337 rtx rtlop1
= XEXP (rtl
, 1);
16338 if (is_a
<scalar_int_mode
> (GET_MODE (rtlop1
), &op1_mode
)
16339 && GET_MODE_BITSIZE (op1_mode
) < GET_MODE_BITSIZE (int_mode
))
16340 rtlop1
= gen_rtx_ZERO_EXTEND (int_mode
, rtlop1
);
16341 op1
= mem_loc_descriptor (rtlop1
, int_mode
, mem_mode
,
16342 VAR_INIT_STATUS_INITIALIZED
);
16345 if (op0
== 0 || op1
== 0)
16348 mem_loc_result
= op0
;
16349 add_loc_descr (&mem_loc_result
, op1
);
16350 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
16366 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
16367 VAR_INIT_STATUS_INITIALIZED
);
16368 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
16369 VAR_INIT_STATUS_INITIALIZED
);
16371 if (op0
== 0 || op1
== 0)
16374 mem_loc_result
= op0
;
16375 add_loc_descr (&mem_loc_result
, op1
);
16376 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
16380 if ((!dwarf_strict
|| dwarf_version
>= 5)
16381 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
16382 && GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
16384 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
16385 base_type_for_mode (mode
, 0),
16386 int_mode
, mem_mode
);
16390 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
16391 VAR_INIT_STATUS_INITIALIZED
);
16392 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
16393 VAR_INIT_STATUS_INITIALIZED
);
16395 if (op0
== 0 || op1
== 0)
16398 mem_loc_result
= op0
;
16399 add_loc_descr (&mem_loc_result
, op1
);
16400 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
16401 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
16402 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
16403 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
16404 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
16408 if ((!dwarf_strict
|| dwarf_version
>= 5)
16409 && is_a
<scalar_int_mode
> (mode
, &int_mode
))
16411 /* We can use a signed divide if the sign bit is not set. */
16412 if (GET_MODE_SIZE (int_mode
) < DWARF2_ADDR_SIZE
)
16418 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
16419 base_type_for_mode (int_mode
, 1),
16420 int_mode
, mem_mode
);
16437 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
16438 VAR_INIT_STATUS_INITIALIZED
);
16443 mem_loc_result
= op0
;
16444 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
16448 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
16449 || GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
16450 #ifdef POINTERS_EXTEND_UNSIGNED
16451 || (int_mode
== Pmode
16452 && mem_mode
!= VOIDmode
16453 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
16457 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
16460 if ((!dwarf_strict
|| dwarf_version
>= 5)
16461 && (GET_MODE_BITSIZE (int_mode
) == HOST_BITS_PER_WIDE_INT
16462 || GET_MODE_BITSIZE (int_mode
) == HOST_BITS_PER_DOUBLE_INT
))
16464 dw_die_ref type_die
= base_type_for_mode (int_mode
, 1);
16465 scalar_int_mode amode
;
16466 if (type_die
== NULL
)
16468 if (INTVAL (rtl
) >= 0
16469 && (int_mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
, 0)
16471 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
16472 /* const DW_OP_convert <XXX> vs.
16473 DW_OP_const_type <XXX, 1, const>. */
16474 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
16475 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (int_mode
))
16477 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
16478 op0
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
16479 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16480 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
16481 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16482 add_loc_descr (&mem_loc_result
, op0
);
16483 return mem_loc_result
;
16485 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0,
16487 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16488 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
16489 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16490 if (GET_MODE_BITSIZE (int_mode
) == HOST_BITS_PER_WIDE_INT
)
16491 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
16494 mem_loc_result
->dw_loc_oprnd2
.val_class
16495 = dw_val_class_const_double
;
16496 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
16497 = double_int::from_shwi (INTVAL (rtl
));
16503 if (!dwarf_strict
|| dwarf_version
>= 5)
16505 dw_die_ref type_die
;
16507 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
16508 CONST_DOUBLE rtx could represent either a large integer
16509 or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
16510 the value is always a floating point constant.
16512 When it is an integer, a CONST_DOUBLE is used whenever
16513 the constant requires 2 HWIs to be adequately represented.
16514 We output CONST_DOUBLEs as blocks. */
16515 if (mode
== VOIDmode
16516 || (GET_MODE (rtl
) == VOIDmode
16517 && maybe_ne (GET_MODE_BITSIZE (mode
),
16518 HOST_BITS_PER_DOUBLE_INT
)))
16520 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
16521 if (type_die
== NULL
)
16523 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0, 0);
16524 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16525 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
16526 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16527 #if TARGET_SUPPORTS_WIDE_INT == 0
16528 if (!SCALAR_FLOAT_MODE_P (mode
))
16530 mem_loc_result
->dw_loc_oprnd2
.val_class
16531 = dw_val_class_const_double
;
16532 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
16533 = rtx_to_double_int (rtl
);
16538 scalar_float_mode float_mode
= as_a
<scalar_float_mode
> (mode
);
16539 unsigned int length
= GET_MODE_SIZE (float_mode
);
16540 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
16541 unsigned int elt_size
= insert_float (rtl
, array
);
16543 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
16544 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
16545 = length
/ elt_size
;
16546 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
16547 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
16552 case CONST_WIDE_INT
:
16553 if (!dwarf_strict
|| dwarf_version
>= 5)
16555 dw_die_ref type_die
;
16557 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
16558 if (type_die
== NULL
)
16560 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0, 0);
16561 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16562 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
16563 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16564 mem_loc_result
->dw_loc_oprnd2
.val_class
16565 = dw_val_class_wide_int
;
16566 mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
16567 *mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= rtx_mode_t (rtl
, mode
);
16571 case CONST_POLY_INT
:
16572 mem_loc_result
= int_loc_descriptor (rtx_to_poly_int64 (rtl
));
16576 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
16580 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
16584 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
16588 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
16592 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
16596 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
16600 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
16604 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
16608 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
16612 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
16617 if (!SCALAR_INT_MODE_P (mode
))
16622 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
16627 if (CONST_INT_P (XEXP (rtl
, 1))
16628 && CONST_INT_P (XEXP (rtl
, 2))
16629 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
16630 && is_a
<scalar_int_mode
> (GET_MODE (XEXP (rtl
, 0)), &inner_mode
)
16631 && GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
16632 && GET_MODE_SIZE (inner_mode
) <= DWARF2_ADDR_SIZE
16633 && ((unsigned) INTVAL (XEXP (rtl
, 1))
16634 + (unsigned) INTVAL (XEXP (rtl
, 2))
16635 <= GET_MODE_BITSIZE (int_mode
)))
16638 op0
= mem_loc_descriptor (XEXP (rtl
, 0), inner_mode
,
16639 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
16642 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
16646 mem_loc_result
= op0
;
16647 size
= INTVAL (XEXP (rtl
, 1));
16648 shift
= INTVAL (XEXP (rtl
, 2));
16649 if (BITS_BIG_ENDIAN
)
16650 shift
= GET_MODE_BITSIZE (inner_mode
) - shift
- size
;
16651 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
16653 add_loc_descr (&mem_loc_result
,
16654 int_loc_descriptor (DWARF2_ADDR_SIZE
16656 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
16658 if (size
!= (int) DWARF2_ADDR_SIZE
)
16660 add_loc_descr (&mem_loc_result
,
16661 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
16662 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
16669 dw_loc_descr_ref op2
, bra_node
, drop_node
;
16670 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
16671 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
16672 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
16673 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
16674 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
16675 VAR_INIT_STATUS_INITIALIZED
);
16676 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
16677 VAR_INIT_STATUS_INITIALIZED
);
16678 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
16681 mem_loc_result
= op1
;
16682 add_loc_descr (&mem_loc_result
, op2
);
16683 add_loc_descr (&mem_loc_result
, op0
);
16684 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
16685 add_loc_descr (&mem_loc_result
, bra_node
);
16686 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
16687 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
16688 add_loc_descr (&mem_loc_result
, drop_node
);
16689 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
16690 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
16695 case FLOAT_TRUNCATE
:
16697 case UNSIGNED_FLOAT
:
16700 if (!dwarf_strict
|| dwarf_version
>= 5)
16702 dw_die_ref type_die
;
16703 dw_loc_descr_ref cvt
;
16705 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
16706 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
16709 if (is_a
<scalar_int_mode
> (GET_MODE (XEXP (rtl
, 0)), &int_mode
)
16710 && (GET_CODE (rtl
) == FLOAT
16711 || GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
))
16713 type_die
= base_type_for_mode (int_mode
,
16714 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
16715 if (type_die
== NULL
)
16717 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
16718 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16719 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
16720 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16721 add_loc_descr (&op0
, cvt
);
16723 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
16724 if (type_die
== NULL
)
16726 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
16727 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16728 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
16729 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16730 add_loc_descr (&op0
, cvt
);
16731 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
16732 && (GET_CODE (rtl
) == FIX
16733 || GET_MODE_SIZE (int_mode
) < DWARF2_ADDR_SIZE
))
16735 op0
= convert_descriptor_to_mode (int_mode
, op0
);
16739 mem_loc_result
= op0
;
16746 if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
16747 mem_loc_result
= clz_loc_descriptor (rtl
, int_mode
, mem_mode
);
16752 if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
16753 mem_loc_result
= popcount_loc_descriptor (rtl
, int_mode
, mem_mode
);
16757 if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
16758 mem_loc_result
= bswap_loc_descriptor (rtl
, int_mode
, mem_mode
);
16763 if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
16764 mem_loc_result
= rotate_loc_descriptor (rtl
, int_mode
, mem_mode
);
16768 /* In theory, we could implement the above. */
16769 /* DWARF cannot represent the unsigned compare operations
16794 case FRACT_CONVERT
:
16795 case UNSIGNED_FRACT_CONVERT
:
16797 case UNSIGNED_SAT_FRACT
:
16803 case VEC_DUPLICATE
:
16807 case STRICT_LOW_PART
:
16812 case SMUL_HIGHPART
:
16813 case UMUL_HIGHPART
:
16817 resolve_one_addr (&rtl
);
16820 /* RTL sequences inside PARALLEL record a series of DWARF operations for
16821 the expression. An UNSPEC rtx represents a raw DWARF operation,
16822 new_loc_descr is called for it to build the operation directly.
16823 Otherwise mem_loc_descriptor is called recursively. */
16827 dw_loc_descr_ref exp_result
= NULL
;
16829 for (; index
< XVECLEN (rtl
, 0); index
++)
16831 rtx elem
= XVECEXP (rtl
, 0, index
);
16832 if (GET_CODE (elem
) == UNSPEC
)
16834 /* Each DWARF operation UNSPEC contain two operands, if
16835 one operand is not used for the operation, const0_rtx is
16837 gcc_assert (XVECLEN (elem
, 0) == 2);
16839 HOST_WIDE_INT dw_op
= XINT (elem
, 1);
16840 HOST_WIDE_INT oprnd1
= INTVAL (XVECEXP (elem
, 0, 0));
16841 HOST_WIDE_INT oprnd2
= INTVAL (XVECEXP (elem
, 0, 1));
16843 = new_loc_descr ((enum dwarf_location_atom
) dw_op
, oprnd1
,
16848 = mem_loc_descriptor (elem
, mode
, mem_mode
,
16849 VAR_INIT_STATUS_INITIALIZED
);
16851 if (!mem_loc_result
)
16852 mem_loc_result
= exp_result
;
16854 add_loc_descr (&mem_loc_result
, exp_result
);
16863 print_rtl (stderr
, rtl
);
16864 gcc_unreachable ();
16869 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
16870 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
16872 return mem_loc_result
;
16875 /* Return a descriptor that describes the concatenation of two locations.
16876 This is typically a complex variable. */
16878 static dw_loc_descr_ref
16879 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
16881 /* At present we only track constant-sized pieces. */
16882 unsigned int size0
, size1
;
16883 if (!GET_MODE_SIZE (GET_MODE (x0
)).is_constant (&size0
)
16884 || !GET_MODE_SIZE (GET_MODE (x1
)).is_constant (&size1
))
16887 dw_loc_descr_ref cc_loc_result
= NULL
;
16888 dw_loc_descr_ref x0_ref
16889 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
16890 dw_loc_descr_ref x1_ref
16891 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
16893 if (x0_ref
== 0 || x1_ref
== 0)
16896 cc_loc_result
= x0_ref
;
16897 add_loc_descr_op_piece (&cc_loc_result
, size0
);
16899 add_loc_descr (&cc_loc_result
, x1_ref
);
16900 add_loc_descr_op_piece (&cc_loc_result
, size1
);
16902 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
16903 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
16905 return cc_loc_result
;
16908 /* Return a descriptor that describes the concatenation of N
16911 static dw_loc_descr_ref
16912 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
16915 dw_loc_descr_ref cc_loc_result
= NULL
;
16916 unsigned int n
= XVECLEN (concatn
, 0);
16919 for (i
= 0; i
< n
; ++i
)
16921 dw_loc_descr_ref ref
;
16922 rtx x
= XVECEXP (concatn
, 0, i
);
16924 /* At present we only track constant-sized pieces. */
16925 if (!GET_MODE_SIZE (GET_MODE (x
)).is_constant (&size
))
16928 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
16932 add_loc_descr (&cc_loc_result
, ref
);
16933 add_loc_descr_op_piece (&cc_loc_result
, size
);
16936 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
16937 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
16939 return cc_loc_result
;
16942 /* Helper function for loc_descriptor. Return DW_OP_implicit_pointer
16943 for DEBUG_IMPLICIT_PTR RTL. */
16945 static dw_loc_descr_ref
16946 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
16948 dw_loc_descr_ref ret
;
16951 if (dwarf_strict
&& dwarf_version
< 5)
16953 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
16954 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
16955 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
16956 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
16957 ret
= new_loc_descr (dwarf_OP (DW_OP_implicit_pointer
), 0, offset
);
16958 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
16961 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
16962 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
16963 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
16967 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
16968 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
16973 /* Output a proper Dwarf location descriptor for a variable or parameter
16974 which is either allocated in a register or in a memory location. For a
16975 register, we just generate an OP_REG and the register number. For a
16976 memory location we provide a Dwarf postfix expression describing how to
16977 generate the (dynamic) address of the object onto the address stack.
16979 MODE is mode of the decl if this loc_descriptor is going to be used in
16980 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
16981 allowed, VOIDmode otherwise.
16983 If we don't know how to describe it, return 0. */
16985 static dw_loc_descr_ref
16986 loc_descriptor (rtx rtl
, machine_mode mode
,
16987 enum var_init_status initialized
)
16989 dw_loc_descr_ref loc_result
= NULL
;
16990 scalar_int_mode int_mode
;
16992 switch (GET_CODE (rtl
))
16995 /* The case of a subreg may arise when we have a local (register)
16996 variable or a formal (register) parameter which doesn't quite fill
16997 up an entire register. For now, just assume that it is
16998 legitimate to make the Dwarf info refer to the whole register which
16999 contains the given subreg. */
17000 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
17001 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
17002 GET_MODE (SUBREG_REG (rtl
)), initialized
);
17008 loc_result
= reg_loc_descriptor (rtl
, initialized
);
17012 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
17013 GET_MODE (rtl
), initialized
);
17014 if (loc_result
== NULL
)
17015 loc_result
= tls_mem_loc_descriptor (rtl
);
17016 if (loc_result
== NULL
)
17018 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
17019 if (new_rtl
!= rtl
)
17020 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
17025 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
17030 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
17035 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
17037 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
17038 if (GET_CODE (loc
) == EXPR_LIST
)
17039 loc
= XEXP (loc
, 0);
17040 loc_result
= loc_descriptor (loc
, mode
, initialized
);
17044 rtl
= XEXP (rtl
, 1);
17049 rtvec par_elems
= XVEC (rtl
, 0);
17050 int num_elem
= GET_NUM_ELEM (par_elems
);
17054 /* Create the first one, so we have something to add to. */
17055 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
17056 VOIDmode
, initialized
);
17057 if (loc_result
== NULL
)
17059 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
17060 /* At present we only track constant-sized pieces. */
17061 if (!GET_MODE_SIZE (mode
).is_constant (&size
))
17063 add_loc_descr_op_piece (&loc_result
, size
);
17064 for (i
= 1; i
< num_elem
; i
++)
17066 dw_loc_descr_ref temp
;
17068 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
17069 VOIDmode
, initialized
);
17072 add_loc_descr (&loc_result
, temp
);
17073 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
17074 /* At present we only track constant-sized pieces. */
17075 if (!GET_MODE_SIZE (mode
).is_constant (&size
))
17077 add_loc_descr_op_piece (&loc_result
, size
);
17083 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
17085 int_mode
= as_a
<scalar_int_mode
> (mode
);
17086 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (int_mode
),
17092 if (mode
== VOIDmode
)
17093 mode
= GET_MODE (rtl
);
17095 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
17097 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
17099 /* Note that a CONST_DOUBLE rtx could represent either an integer
17100 or a floating-point constant. A CONST_DOUBLE is used whenever
17101 the constant requires more than one word in order to be
17102 adequately represented. We output CONST_DOUBLEs as blocks. */
17103 scalar_mode smode
= as_a
<scalar_mode
> (mode
);
17104 loc_result
= new_loc_descr (DW_OP_implicit_value
,
17105 GET_MODE_SIZE (smode
), 0);
17106 #if TARGET_SUPPORTS_WIDE_INT == 0
17107 if (!SCALAR_FLOAT_MODE_P (smode
))
17109 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
17110 loc_result
->dw_loc_oprnd2
.v
.val_double
17111 = rtx_to_double_int (rtl
);
17116 unsigned int length
= GET_MODE_SIZE (smode
);
17117 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
17118 unsigned int elt_size
= insert_float (rtl
, array
);
17120 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
17121 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ elt_size
;
17122 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
17123 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
17128 case CONST_WIDE_INT
:
17129 if (mode
== VOIDmode
)
17130 mode
= GET_MODE (rtl
);
17132 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
17134 int_mode
= as_a
<scalar_int_mode
> (mode
);
17135 loc_result
= new_loc_descr (DW_OP_implicit_value
,
17136 GET_MODE_SIZE (int_mode
), 0);
17137 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_wide_int
;
17138 loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
17139 *loc_result
->dw_loc_oprnd2
.v
.val_wide
= rtx_mode_t (rtl
, int_mode
);
17144 if (mode
== VOIDmode
)
17145 mode
= GET_MODE (rtl
);
17147 if (mode
!= VOIDmode
17148 /* The combination of a length and byte elt_size doesn't extend
17149 naturally to boolean vectors, where several elements are packed
17150 into the same byte. */
17151 && GET_MODE_CLASS (mode
) != MODE_VECTOR_BOOL
17152 && (dwarf_version
>= 4 || !dwarf_strict
))
17154 unsigned int length
;
17155 if (!CONST_VECTOR_NUNITS (rtl
).is_constant (&length
))
17158 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
17159 unsigned char *array
17160 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
17163 machine_mode imode
= GET_MODE_INNER (mode
);
17165 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
17166 switch (GET_MODE_CLASS (mode
))
17168 case MODE_VECTOR_INT
:
17169 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
17171 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
17172 insert_wide_int (rtx_mode_t (elt
, imode
), p
, elt_size
);
17176 case MODE_VECTOR_FLOAT
:
17177 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
17179 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
17180 insert_float (elt
, p
);
17185 gcc_unreachable ();
17188 loc_result
= new_loc_descr (DW_OP_implicit_value
,
17189 length
* elt_size
, 0);
17190 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
17191 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
17192 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
17193 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
17198 if (mode
== VOIDmode
17199 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
17200 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
17201 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
17203 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
17208 if (!const_ok_for_output (rtl
))
17212 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
17213 && GET_MODE_SIZE (int_mode
) == DWARF2_ADDR_SIZE
17214 && (dwarf_version
>= 4 || !dwarf_strict
))
17216 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
17217 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
17218 vec_safe_push (used_rtx_array
, rtl
);
17222 case DEBUG_IMPLICIT_PTR
:
17223 loc_result
= implicit_ptr_descriptor (rtl
, 0);
17227 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
17228 && CONST_INT_P (XEXP (rtl
, 1)))
17231 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
17237 if ((is_a
<scalar_int_mode
> (mode
, &int_mode
)
17238 && GET_MODE (rtl
) == int_mode
17239 && GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
17240 && dwarf_version
>= 4)
17241 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
17243 /* Value expression. */
17244 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
17246 add_loc_descr (&loc_result
,
17247 new_loc_descr (DW_OP_stack_value
, 0, 0));
17255 /* We need to figure out what section we should use as the base for the
17256 address ranges where a given location is valid.
17257 1. If this particular DECL has a section associated with it, use that.
17258 2. If this function has a section associated with it, use that.
17259 3. Otherwise, use the text section.
17260 XXX: If you split a variable across multiple sections, we won't notice. */
17262 static const char *
17263 secname_for_decl (const_tree decl
)
17265 const char *secname
;
17267 if (VAR_OR_FUNCTION_DECL_P (decl
)
17268 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
) || TREE_STATIC (decl
))
17269 && DECL_SECTION_NAME (decl
))
17270 secname
= DECL_SECTION_NAME (decl
);
17271 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
17273 if (in_cold_section_p
)
17275 section
*sec
= current_function_section ();
17276 if (sec
->common
.flags
& SECTION_NAMED
)
17277 return sec
->named
.name
;
17279 secname
= DECL_SECTION_NAME (current_function_decl
);
17281 else if (cfun
&& in_cold_section_p
)
17282 secname
= crtl
->subsections
.cold_section_label
;
17284 secname
= text_section_label
;
17289 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
17292 decl_by_reference_p (tree decl
)
17294 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
17296 && DECL_BY_REFERENCE (decl
));
17299 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
17302 static dw_loc_descr_ref
17303 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
17304 enum var_init_status initialized
)
17306 int have_address
= 0;
17307 dw_loc_descr_ref descr
;
17310 if (want_address
!= 2)
17312 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
17314 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
17316 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
17317 if (GET_CODE (varloc
) == EXPR_LIST
)
17318 varloc
= XEXP (varloc
, 0);
17319 mode
= GET_MODE (varloc
);
17320 if (MEM_P (varloc
))
17322 rtx addr
= XEXP (varloc
, 0);
17323 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
17324 mode
, initialized
);
17329 rtx x
= avoid_constant_pool_reference (varloc
);
17331 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
17336 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
17343 if (GET_CODE (varloc
) == VAR_LOCATION
)
17344 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
17346 mode
= DECL_MODE (loc
);
17347 descr
= loc_descriptor (varloc
, mode
, initialized
);
17354 if (want_address
== 2 && !have_address
17355 && (dwarf_version
>= 4 || !dwarf_strict
))
17357 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
17359 expansion_failed (loc
, NULL_RTX
,
17360 "DWARF address size mismatch");
17363 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
17366 /* Show if we can't fill the request for an address. */
17367 if (want_address
&& !have_address
)
17369 expansion_failed (loc
, NULL_RTX
,
17370 "Want address and only have value");
17374 /* If we've got an address and don't want one, dereference. */
17375 if (!want_address
&& have_address
)
17377 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
17378 enum dwarf_location_atom op
;
17380 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
17382 expansion_failed (loc
, NULL_RTX
,
17383 "DWARF address size mismatch");
17386 else if (size
== DWARF2_ADDR_SIZE
)
17389 op
= DW_OP_deref_size
;
17391 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
17397 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
17398 if it is not possible. */
17400 static dw_loc_descr_ref
17401 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
17403 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
17404 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
17405 else if (dwarf_version
>= 3 || !dwarf_strict
)
17406 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
17411 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
17412 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
17414 static dw_loc_descr_ref
17415 dw_sra_loc_expr (tree decl
, rtx loc
)
17418 unsigned HOST_WIDE_INT padsize
= 0;
17419 dw_loc_descr_ref descr
, *descr_tail
;
17420 unsigned HOST_WIDE_INT decl_size
;
17422 enum var_init_status initialized
;
17424 if (DECL_SIZE (decl
) == NULL
17425 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
17428 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
17430 descr_tail
= &descr
;
17432 for (p
= loc
; p
; p
= XEXP (p
, 1))
17434 unsigned HOST_WIDE_INT bitsize
= decl_piece_bitsize (p
);
17435 rtx loc_note
= *decl_piece_varloc_ptr (p
);
17436 dw_loc_descr_ref cur_descr
;
17437 dw_loc_descr_ref
*tail
, last
= NULL
;
17438 unsigned HOST_WIDE_INT opsize
= 0;
17440 if (loc_note
== NULL_RTX
17441 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
17443 padsize
+= bitsize
;
17446 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
17447 varloc
= NOTE_VAR_LOCATION (loc_note
);
17448 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
17449 if (cur_descr
== NULL
)
17451 padsize
+= bitsize
;
17455 /* Check that cur_descr either doesn't use
17456 DW_OP_*piece operations, or their sum is equal
17457 to bitsize. Otherwise we can't embed it. */
17458 for (tail
= &cur_descr
; *tail
!= NULL
;
17459 tail
= &(*tail
)->dw_loc_next
)
17460 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
17462 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
17466 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
17468 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
17472 if (last
!= NULL
&& opsize
!= bitsize
)
17474 padsize
+= bitsize
;
17475 /* Discard the current piece of the descriptor and release any
17476 addr_table entries it uses. */
17477 remove_loc_list_addr_table_entries (cur_descr
);
17481 /* If there is a hole, add DW_OP_*piece after empty DWARF
17482 expression, which means that those bits are optimized out. */
17485 if (padsize
> decl_size
)
17487 remove_loc_list_addr_table_entries (cur_descr
);
17488 goto discard_descr
;
17490 decl_size
-= padsize
;
17491 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
17492 if (*descr_tail
== NULL
)
17494 remove_loc_list_addr_table_entries (cur_descr
);
17495 goto discard_descr
;
17497 descr_tail
= &(*descr_tail
)->dw_loc_next
;
17500 *descr_tail
= cur_descr
;
17502 if (bitsize
> decl_size
)
17503 goto discard_descr
;
17504 decl_size
-= bitsize
;
17507 HOST_WIDE_INT offset
= 0;
17508 if (GET_CODE (varloc
) == VAR_LOCATION
17509 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
17511 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
17512 if (GET_CODE (varloc
) == EXPR_LIST
)
17513 varloc
= XEXP (varloc
, 0);
17517 if (GET_CODE (varloc
) == CONST
17518 || GET_CODE (varloc
) == SIGN_EXTEND
17519 || GET_CODE (varloc
) == ZERO_EXTEND
)
17520 varloc
= XEXP (varloc
, 0);
17521 else if (GET_CODE (varloc
) == SUBREG
)
17522 varloc
= SUBREG_REG (varloc
);
17527 /* DW_OP_bit_size offset should be zero for register
17528 or implicit location descriptions and empty location
17529 descriptions, but for memory addresses needs big endian
17531 if (MEM_P (varloc
))
17533 unsigned HOST_WIDE_INT memsize
;
17534 if (!poly_uint64 (MEM_SIZE (varloc
)).is_constant (&memsize
))
17535 goto discard_descr
;
17536 memsize
*= BITS_PER_UNIT
;
17537 if (memsize
!= bitsize
)
17539 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
17540 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
17541 goto discard_descr
;
17542 if (memsize
< bitsize
)
17543 goto discard_descr
;
17544 if (BITS_BIG_ENDIAN
)
17545 offset
= memsize
- bitsize
;
17549 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
17550 if (*descr_tail
== NULL
)
17551 goto discard_descr
;
17552 descr_tail
= &(*descr_tail
)->dw_loc_next
;
17556 /* If there were any non-empty expressions, add padding till the end of
17558 if (descr
!= NULL
&& decl_size
!= 0)
17560 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
17561 if (*descr_tail
== NULL
)
17562 goto discard_descr
;
17567 /* Discard the descriptor and release any addr_table entries it uses. */
17568 remove_loc_list_addr_table_entries (descr
);
17572 /* Return the dwarf representation of the location list LOC_LIST of
17573 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
17576 static dw_loc_list_ref
17577 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
17579 const char *endname
, *secname
;
17580 var_loc_view endview
;
17582 enum var_init_status initialized
;
17583 struct var_loc_node
*node
;
17584 dw_loc_descr_ref descr
;
17585 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
17586 dw_loc_list_ref list
= NULL
;
17587 dw_loc_list_ref
*listp
= &list
;
17589 /* Now that we know what section we are using for a base,
17590 actually construct the list of locations.
17591 The first location information is what is passed to the
17592 function that creates the location list, and the remaining
17593 locations just get added on to that list.
17594 Note that we only know the start address for a location
17595 (IE location changes), so to build the range, we use
17596 the range [current location start, next location start].
17597 This means we have to special case the last node, and generate
17598 a range of [last location start, end of function label]. */
17600 if (cfun
&& crtl
->has_bb_partition
)
17602 bool save_in_cold_section_p
= in_cold_section_p
;
17603 in_cold_section_p
= first_function_block_is_cold
;
17604 if (loc_list
->last_before_switch
== NULL
)
17605 in_cold_section_p
= !in_cold_section_p
;
17606 secname
= secname_for_decl (decl
);
17607 in_cold_section_p
= save_in_cold_section_p
;
17610 secname
= secname_for_decl (decl
);
17612 for (node
= loc_list
->first
; node
; node
= node
->next
)
17614 bool range_across_switch
= false;
17615 if (GET_CODE (node
->loc
) == EXPR_LIST
17616 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
17618 if (GET_CODE (node
->loc
) == EXPR_LIST
)
17621 /* This requires DW_OP_{,bit_}piece, which is not usable
17622 inside DWARF expressions. */
17623 if (want_address
== 2)
17624 descr
= dw_sra_loc_expr (decl
, node
->loc
);
17628 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
17629 varloc
= NOTE_VAR_LOCATION (node
->loc
);
17630 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
17634 /* If section switch happens in between node->label
17635 and node->next->label (or end of function) and
17636 we can't emit it as a single entry list,
17637 emit two ranges, first one ending at the end
17638 of first partition and second one starting at the
17639 beginning of second partition. */
17640 if (node
== loc_list
->last_before_switch
17641 && (node
!= loc_list
->first
|| loc_list
->first
->next
17642 /* If we are to emit a view number, we will emit
17643 a loclist rather than a single location
17644 expression for the entire function (see
17645 loc_list_has_views), so we have to split the
17646 range that straddles across partitions. */
17647 || !ZERO_VIEW_P (node
->view
))
17648 && current_function_decl
)
17650 endname
= cfun
->fde
->dw_fde_end
;
17652 range_across_switch
= true;
17654 /* The variable has a location between NODE->LABEL and
17655 NODE->NEXT->LABEL. */
17656 else if (node
->next
)
17657 endname
= node
->next
->label
, endview
= node
->next
->view
;
17658 /* If the variable has a location at the last label
17659 it keeps its location until the end of function. */
17660 else if (!current_function_decl
)
17661 endname
= text_end_label
, endview
= 0;
17664 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
17665 current_function_funcdef_no
);
17666 endname
= ggc_strdup (label_id
);
17670 *listp
= new_loc_list (descr
, node
->label
, node
->view
,
17671 endname
, endview
, secname
);
17672 if (TREE_CODE (decl
) == PARM_DECL
17673 && node
== loc_list
->first
17674 && NOTE_P (node
->loc
)
17675 && strcmp (node
->label
, endname
) == 0)
17676 (*listp
)->force
= true;
17677 listp
= &(*listp
)->dw_loc_next
;
17682 && crtl
->has_bb_partition
17683 && node
== loc_list
->last_before_switch
)
17685 bool save_in_cold_section_p
= in_cold_section_p
;
17686 in_cold_section_p
= !first_function_block_is_cold
;
17687 secname
= secname_for_decl (decl
);
17688 in_cold_section_p
= save_in_cold_section_p
;
17691 if (range_across_switch
)
17693 if (GET_CODE (node
->loc
) == EXPR_LIST
)
17694 descr
= dw_sra_loc_expr (decl
, node
->loc
);
17697 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
17698 varloc
= NOTE_VAR_LOCATION (node
->loc
);
17699 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
17702 gcc_assert (descr
);
17703 /* The variable has a location between NODE->LABEL and
17704 NODE->NEXT->LABEL. */
17706 endname
= node
->next
->label
, endview
= node
->next
->view
;
17708 endname
= cfun
->fde
->dw_fde_second_end
, endview
= 0;
17709 *listp
= new_loc_list (descr
, cfun
->fde
->dw_fde_second_begin
, 0,
17710 endname
, endview
, secname
);
17711 listp
= &(*listp
)->dw_loc_next
;
17715 /* Try to avoid the overhead of a location list emitting a location
17716 expression instead, but only if we didn't have more than one
17717 location entry in the first place. If some entries were not
17718 representable, we don't want to pretend a single entry that was
17719 applies to the entire scope in which the variable is
17721 if (list
&& loc_list
->first
->next
)
17724 maybe_gen_llsym (list
);
17729 /* Return if the loc_list has only single element and thus can be represented
17730 as location description. */
17733 single_element_loc_list_p (dw_loc_list_ref list
)
17735 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
17736 return !list
->ll_symbol
;
17739 /* Duplicate a single element of location list. */
17741 static inline dw_loc_descr_ref
17742 copy_loc_descr (dw_loc_descr_ref ref
)
17744 dw_loc_descr_ref copy
= ggc_alloc
<dw_loc_descr_node
> ();
17745 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
17749 /* To each location in list LIST append loc descr REF. */
17752 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
17754 dw_loc_descr_ref copy
;
17755 add_loc_descr (&list
->expr
, ref
);
17756 list
= list
->dw_loc_next
;
17759 copy
= copy_loc_descr (ref
);
17760 add_loc_descr (&list
->expr
, copy
);
17761 while (copy
->dw_loc_next
)
17762 copy
= copy
->dw_loc_next
= copy_loc_descr (copy
->dw_loc_next
);
17763 list
= list
->dw_loc_next
;
17767 /* To each location in list LIST prepend loc descr REF. */
17770 prepend_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
17772 dw_loc_descr_ref copy
;
17773 dw_loc_descr_ref ref_end
= list
->expr
;
17774 add_loc_descr (&ref
, list
->expr
);
17776 list
= list
->dw_loc_next
;
17779 dw_loc_descr_ref end
= list
->expr
;
17780 list
->expr
= copy
= copy_loc_descr (ref
);
17781 while (copy
->dw_loc_next
!= ref_end
)
17782 copy
= copy
->dw_loc_next
= copy_loc_descr (copy
->dw_loc_next
);
17783 copy
->dw_loc_next
= end
;
17784 list
= list
->dw_loc_next
;
17788 /* Given two lists RET and LIST
17789 produce location list that is result of adding expression in LIST
17790 to expression in RET on each position in program.
17791 Might be destructive on both RET and LIST.
17793 TODO: We handle only simple cases of RET or LIST having at most one
17794 element. General case would involve sorting the lists in program order
17795 and merging them that will need some additional work.
17796 Adding that will improve quality of debug info especially for SRA-ed
17800 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
17809 if (!list
->dw_loc_next
)
17811 add_loc_descr_to_each (*ret
, list
->expr
);
17814 if (!(*ret
)->dw_loc_next
)
17816 prepend_loc_descr_to_each (list
, (*ret
)->expr
);
17820 expansion_failed (NULL_TREE
, NULL_RTX
,
17821 "Don't know how to merge two non-trivial"
17822 " location lists.\n");
17827 /* LOC is constant expression. Try a luck, look it up in constant
17828 pool and return its loc_descr of its address. */
17830 static dw_loc_descr_ref
17831 cst_pool_loc_descr (tree loc
)
17833 /* Get an RTL for this, if something has been emitted. */
17834 rtx rtl
= lookup_constant_def (loc
);
17836 if (!rtl
|| !MEM_P (rtl
))
17841 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
17843 /* TODO: We might get more coverage if we was actually delaying expansion
17844 of all expressions till end of compilation when constant pools are fully
17846 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
17848 expansion_failed (loc
, NULL_RTX
,
17849 "CST value in contant pool but not marked.");
17852 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
17853 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
17856 /* Return dw_loc_list representing address of addr_expr LOC
17857 by looking for inner INDIRECT_REF expression and turning
17858 it into simple arithmetics.
17860 See loc_list_from_tree for the meaning of CONTEXT. */
17862 static dw_loc_list_ref
17863 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
,
17864 loc_descr_context
*context
)
17867 poly_int64 bitsize
, bitpos
, bytepos
;
17869 int unsignedp
, reversep
, volatilep
= 0;
17870 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
17872 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
17873 &bitsize
, &bitpos
, &offset
, &mode
,
17874 &unsignedp
, &reversep
, &volatilep
);
17876 if (!multiple_p (bitpos
, BITS_PER_UNIT
, &bytepos
))
17878 expansion_failed (loc
, NULL_RTX
, "bitfield access");
17881 if (!INDIRECT_REF_P (obj
))
17883 expansion_failed (obj
,
17884 NULL_RTX
, "no indirect ref in inner refrence");
17887 if (!offset
&& known_eq (bitpos
, 0))
17888 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1,
17891 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
17892 && (dwarf_version
>= 4 || !dwarf_strict
))
17894 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0, context
);
17899 /* Variable offset. */
17900 list_ret1
= loc_list_from_tree (offset
, 0, context
);
17901 if (list_ret1
== 0)
17903 add_loc_list (&list_ret
, list_ret1
);
17906 add_loc_descr_to_each (list_ret
,
17907 new_loc_descr (DW_OP_plus
, 0, 0));
17909 HOST_WIDE_INT value
;
17910 if (bytepos
.is_constant (&value
) && value
> 0)
17911 add_loc_descr_to_each (list_ret
,
17912 new_loc_descr (DW_OP_plus_uconst
, value
, 0));
17913 else if (maybe_ne (bytepos
, 0))
17914 loc_list_plus_const (list_ret
, bytepos
);
17915 add_loc_descr_to_each (list_ret
,
17916 new_loc_descr (DW_OP_stack_value
, 0, 0));
17921 /* Set LOC to the next operation that is not a DW_OP_nop operation. In the case
17922 all operations from LOC are nops, move to the last one. Insert in NOPS all
17923 operations that are skipped. */
17926 loc_descr_to_next_no_nop (dw_loc_descr_ref
&loc
,
17927 hash_set
<dw_loc_descr_ref
> &nops
)
17929 while (loc
->dw_loc_next
!= NULL
&& loc
->dw_loc_opc
== DW_OP_nop
)
17932 loc
= loc
->dw_loc_next
;
17936 /* Helper for loc_descr_without_nops: free the location description operation
17940 free_loc_descr (const dw_loc_descr_ref
&loc
, void *data ATTRIBUTE_UNUSED
)
17946 /* Remove all DW_OP_nop operations from LOC except, if it exists, the one that
17950 loc_descr_without_nops (dw_loc_descr_ref
&loc
)
17952 if (loc
->dw_loc_opc
== DW_OP_nop
&& loc
->dw_loc_next
== NULL
)
17955 /* Set of all DW_OP_nop operations we remove. */
17956 hash_set
<dw_loc_descr_ref
> nops
;
17958 /* First, strip all prefix NOP operations in order to keep the head of the
17959 operations list. */
17960 loc_descr_to_next_no_nop (loc
, nops
);
17962 for (dw_loc_descr_ref cur
= loc
; cur
!= NULL
;)
17964 /* For control flow operations: strip "prefix" nops in destination
17966 if (cur
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
)
17967 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd1
.v
.val_loc
, nops
);
17968 if (cur
->dw_loc_oprnd2
.val_class
== dw_val_class_loc
)
17969 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd2
.v
.val_loc
, nops
);
17971 /* Do the same for the operations that follow, then move to the next
17973 if (cur
->dw_loc_next
!= NULL
)
17974 loc_descr_to_next_no_nop (cur
->dw_loc_next
, nops
);
17975 cur
= cur
->dw_loc_next
;
17978 nops
.traverse
<void *, free_loc_descr
> (NULL
);
17982 struct dwarf_procedure_info
;
17984 /* Helper structure for location descriptions generation. */
17985 struct loc_descr_context
17987 /* The type that is implicitly referenced by DW_OP_push_object_address, or
17988 NULL_TREE if DW_OP_push_object_address in invalid for this location
17989 description. This is used when processing PLACEHOLDER_EXPR nodes. */
17991 /* The ..._DECL node that should be translated as a
17992 DW_OP_push_object_address operation. */
17994 /* Information about the DWARF procedure we are currently generating. NULL if
17995 we are not generating a DWARF procedure. */
17996 struct dwarf_procedure_info
*dpi
;
17997 /* True if integral PLACEHOLDER_EXPR stands for the first argument passed
17998 by consumer. Used for DW_TAG_generic_subrange attributes. */
17999 bool placeholder_arg
;
18000 /* True if PLACEHOLDER_EXPR has been seen. */
18001 bool placeholder_seen
;
18002 /* True if strict preservation of signedness has been requested. */
18003 bool strict_signedness
;
18006 /* DWARF procedures generation
18008 DWARF expressions (aka. location descriptions) are used to encode variable
18009 things such as sizes or offsets. Such computations can have redundant parts
18010 that can be factorized in order to reduce the size of the output debug
18011 information. This is the whole point of DWARF procedures.
18013 Thanks to stor-layout.c, size and offset expressions in GENERIC trees are
18014 already factorized into functions ("size functions") in order to handle very
18015 big and complex types. Such functions are quite simple: they have integral
18016 arguments, they return an integral result and their body contains only a
18017 return statement with arithmetic expressions. This is the only kind of
18018 function we are interested in translating into DWARF procedures, here.
18020 DWARF expressions and DWARF procedure are executed using a stack, so we have
18021 to define some calling convention for them to interact. Let's say that:
18023 - Before calling a DWARF procedure, DWARF expressions must push on the stack
18024 all arguments in reverse order (right-to-left) so that when the DWARF
18025 procedure execution starts, the first argument is the top of the stack.
18027 - Then, when returning, the DWARF procedure must have consumed all arguments
18028 on the stack, must have pushed the result and touched nothing else.
18030 - Each integral argument and the result are integral types can be hold in a
18033 - We call "frame offset" the number of stack slots that are "under DWARF
18034 procedure control": it includes the arguments slots, the temporaries and
18035 the result slot. Thus, it is equal to the number of arguments when the
18036 procedure execution starts and must be equal to one (the result) when it
18039 /* Helper structure used when generating operations for a DWARF procedure. */
18040 struct dwarf_procedure_info
18042 /* The FUNCTION_DECL node corresponding to the DWARF procedure that is
18043 currently translated. */
18045 /* The number of arguments FNDECL takes. */
18046 unsigned args_count
;
18049 /* Return a pointer to a newly created DIE node for a DWARF procedure. Add
18050 LOCATION as its DW_AT_location attribute. If FNDECL is not NULL_TREE,
18051 equate it to this DIE. */
18054 new_dwarf_proc_die (dw_loc_descr_ref location
, tree fndecl
,
18055 dw_die_ref parent_die
)
18057 dw_die_ref dwarf_proc_die
;
18059 if ((dwarf_version
< 3 && dwarf_strict
)
18060 || location
== NULL
)
18063 dwarf_proc_die
= new_die (DW_TAG_dwarf_procedure
, parent_die
, fndecl
);
18065 equate_decl_number_to_die (fndecl
, dwarf_proc_die
);
18066 add_AT_loc (dwarf_proc_die
, DW_AT_location
, location
);
18067 return dwarf_proc_die
;
18070 /* Return whether TYPE is a supported type as a DWARF procedure argument
18071 type or return type (we handle only scalar types and pointer types that
18072 aren't wider than the DWARF expression evaluation stack). */
18075 is_handled_procedure_type (tree type
)
18077 return ((INTEGRAL_TYPE_P (type
)
18078 || TREE_CODE (type
) == OFFSET_TYPE
18079 || TREE_CODE (type
) == POINTER_TYPE
)
18080 && int_size_in_bytes (type
) <= DWARF2_ADDR_SIZE
);
18083 /* Helper for resolve_args_picking: do the same but stop when coming across
18084 visited nodes. For each node we visit, register in FRAME_OFFSETS the frame
18085 offset *before* evaluating the corresponding operation. */
18088 resolve_args_picking_1 (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
18089 struct dwarf_procedure_info
*dpi
,
18090 hash_map
<dw_loc_descr_ref
, unsigned> &frame_offsets
)
18092 /* The "frame_offset" identifier is already used to name a macro... */
18093 unsigned frame_offset_
= initial_frame_offset
;
18094 dw_loc_descr_ref l
;
18096 for (l
= loc
; l
!= NULL
;)
18099 unsigned &l_frame_offset
= frame_offsets
.get_or_insert (l
, &existed
);
18101 /* If we already met this node, there is nothing to compute anymore. */
18104 /* Make sure that the stack size is consistent wherever the execution
18105 flow comes from. */
18106 gcc_assert ((unsigned) l_frame_offset
== frame_offset_
);
18109 l_frame_offset
= frame_offset_
;
18111 /* If needed, relocate the picking offset with respect to the frame
18113 if (l
->frame_offset_rel
)
18115 unsigned HOST_WIDE_INT off
;
18116 switch (l
->dw_loc_opc
)
18119 off
= l
->dw_loc_oprnd1
.v
.val_unsigned
;
18128 gcc_unreachable ();
18130 /* frame_offset_ is the size of the current stack frame, including
18131 incoming arguments. Besides, the arguments are pushed
18132 right-to-left. Thus, in order to access the Nth argument from
18133 this operation node, the picking has to skip temporaries *plus*
18134 one stack slot per argument (0 for the first one, 1 for the second
18137 The targetted argument number (N) is already set as the operand,
18138 and the number of temporaries can be computed with:
18139 frame_offsets_ - dpi->args_count */
18140 off
+= frame_offset_
- dpi
->args_count
;
18142 /* DW_OP_pick handles only offsets from 0 to 255 (inclusive)... */
18148 l
->dw_loc_opc
= DW_OP_dup
;
18149 l
->dw_loc_oprnd1
.v
.val_unsigned
= 0;
18153 l
->dw_loc_opc
= DW_OP_over
;
18154 l
->dw_loc_oprnd1
.v
.val_unsigned
= 0;
18158 l
->dw_loc_opc
= DW_OP_pick
;
18159 l
->dw_loc_oprnd1
.v
.val_unsigned
= off
;
18163 /* Update frame_offset according to the effect the current operation has
18165 switch (l
->dw_loc_opc
)
18173 case DW_OP_plus_uconst
:
18209 case DW_OP_deref_size
:
18211 case DW_OP_bit_piece
:
18212 case DW_OP_implicit_value
:
18213 case DW_OP_stack_value
:
18214 case DW_OP_deref_type
:
18215 case DW_OP_convert
:
18216 case DW_OP_reinterpret
:
18217 case DW_OP_GNU_deref_type
:
18218 case DW_OP_GNU_convert
:
18219 case DW_OP_GNU_reinterpret
:
18223 case DW_OP_const1u
:
18224 case DW_OP_const1s
:
18225 case DW_OP_const2u
:
18226 case DW_OP_const2s
:
18227 case DW_OP_const4u
:
18228 case DW_OP_const4s
:
18229 case DW_OP_const8u
:
18230 case DW_OP_const8s
:
18301 case DW_OP_push_object_address
:
18302 case DW_OP_call_frame_cfa
:
18303 case DW_OP_GNU_variable_value
:
18304 case DW_OP_GNU_addr_index
:
18305 case DW_OP_GNU_const_index
:
18330 case DW_OP_xderef_size
:
18336 case DW_OP_call_ref
:
18338 dw_die_ref dwarf_proc
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
18339 int *stack_usage
= dwarf_proc_stack_usage_map
->get (dwarf_proc
);
18341 if (stack_usage
== NULL
)
18343 frame_offset_
+= *stack_usage
;
18347 case DW_OP_implicit_pointer
:
18348 case DW_OP_entry_value
:
18349 case DW_OP_const_type
:
18350 case DW_OP_regval_type
:
18351 case DW_OP_form_tls_address
:
18352 case DW_OP_GNU_push_tls_address
:
18353 case DW_OP_GNU_uninit
:
18354 case DW_OP_GNU_encoded_addr
:
18355 case DW_OP_GNU_implicit_pointer
:
18356 case DW_OP_GNU_entry_value
:
18357 case DW_OP_GNU_const_type
:
18358 case DW_OP_GNU_regval_type
:
18359 case DW_OP_GNU_parameter_ref
:
18360 /* loc_list_from_tree will probably not output these operations for
18361 size functions, so assume they will not appear here. */
18362 /* Fall through... */
18365 gcc_unreachable ();
18368 /* Now, follow the control flow (except subroutine calls). */
18369 switch (l
->dw_loc_opc
)
18372 if (!resolve_args_picking_1 (l
->dw_loc_next
, frame_offset_
, dpi
,
18375 /* Fall through. */
18378 l
= l
->dw_loc_oprnd1
.v
.val_loc
;
18381 case DW_OP_stack_value
:
18385 l
= l
->dw_loc_next
;
18393 /* Make a DFS over operations reachable through LOC (i.e. follow branch
18394 operations) in order to resolve the operand of DW_OP_pick operations that
18395 target DWARF procedure arguments (DPI). INITIAL_FRAME_OFFSET is the frame
18396 offset *before* LOC is executed. Return if all relocations were
18400 resolve_args_picking (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
18401 struct dwarf_procedure_info
*dpi
)
18403 /* Associate to all visited operations the frame offset *before* evaluating
18405 hash_map
<dw_loc_descr_ref
, unsigned> frame_offsets
;
18408 resolve_args_picking_1 (loc
, initial_frame_offset
, dpi
, frame_offsets
);
18411 /* Try to generate a DWARF procedure that computes the same result as FNDECL.
18412 Return NULL if it is not possible. */
18415 function_to_dwarf_procedure (tree fndecl
)
18417 struct dwarf_procedure_info dpi
;
18418 struct loc_descr_context ctx
= {
18419 NULL_TREE
, /* context_type */
18420 NULL_TREE
, /* base_decl */
18422 false, /* placeholder_arg */
18423 false, /* placeholder_seen */
18424 true /* strict_signedness */
18426 dw_die_ref dwarf_proc_die
;
18427 tree tree_body
= DECL_SAVED_TREE (fndecl
);
18428 dw_loc_descr_ref loc_body
, epilogue
;
18433 /* Do not generate multiple DWARF procedures for the same function
18435 dwarf_proc_die
= lookup_decl_die (fndecl
);
18436 if (dwarf_proc_die
!= NULL
)
18437 return dwarf_proc_die
;
18439 /* DWARF procedures are available starting with the DWARFv3 standard. */
18440 if (dwarf_version
< 3 && dwarf_strict
)
18443 /* We handle only functions for which we still have a body, that return a
18444 supported type and that takes arguments with supported types. Note that
18445 there is no point translating functions that return nothing. */
18446 if (tree_body
== NULL_TREE
18447 || DECL_RESULT (fndecl
) == NULL_TREE
18448 || !is_handled_procedure_type (TREE_TYPE (DECL_RESULT (fndecl
))))
18451 for (cursor
= DECL_ARGUMENTS (fndecl
);
18452 cursor
!= NULL_TREE
;
18453 cursor
= TREE_CHAIN (cursor
))
18454 if (!is_handled_procedure_type (TREE_TYPE (cursor
)))
18457 /* Match only "expr" in: RETURN_EXPR (MODIFY_EXPR (RESULT_DECL, expr)). */
18458 if (TREE_CODE (tree_body
) != RETURN_EXPR
)
18460 tree_body
= TREE_OPERAND (tree_body
, 0);
18461 if (TREE_CODE (tree_body
) != MODIFY_EXPR
18462 || TREE_OPERAND (tree_body
, 0) != DECL_RESULT (fndecl
))
18464 tree_body
= TREE_OPERAND (tree_body
, 1);
18466 /* Try to translate the body expression itself. Note that this will probably
18467 cause an infinite recursion if its call graph has a cycle. This is very
18468 unlikely for size functions, however, so don't bother with such things at
18470 dpi
.fndecl
= fndecl
;
18471 dpi
.args_count
= list_length (DECL_ARGUMENTS (fndecl
));
18472 loc_body
= loc_descriptor_from_tree (tree_body
, 0, &ctx
);
18476 /* After evaluating all operands in "loc_body", we should still have on the
18477 stack all arguments plus the desired function result (top of the stack).
18478 Generate code in order to keep only the result in our stack frame. */
18480 for (i
= 0; i
< dpi
.args_count
; ++i
)
18482 dw_loc_descr_ref op_couple
= new_loc_descr (DW_OP_swap
, 0, 0);
18483 op_couple
->dw_loc_next
= new_loc_descr (DW_OP_drop
, 0, 0);
18484 op_couple
->dw_loc_next
->dw_loc_next
= epilogue
;
18485 epilogue
= op_couple
;
18487 add_loc_descr (&loc_body
, epilogue
);
18488 if (!resolve_args_picking (loc_body
, dpi
.args_count
, &dpi
))
18491 /* Trailing nops from loc_descriptor_from_tree (if any) cannot be removed
18492 because they are considered useful. Now there is an epilogue, they are
18493 not anymore, so give it another try. */
18494 loc_descr_without_nops (loc_body
);
18496 /* fndecl may be used both as a regular DW_TAG_subprogram DIE and as
18497 a DW_TAG_dwarf_procedure, so we may have a conflict, here. It's unlikely,
18498 though, given that size functions do not come from source, so they should
18499 not have a dedicated DW_TAG_subprogram DIE. */
18501 = new_dwarf_proc_die (loc_body
, fndecl
,
18502 get_context_die (DECL_CONTEXT (fndecl
)));
18504 /* The called DWARF procedure consumes one stack slot per argument and
18505 returns one stack slot. */
18506 dwarf_proc_stack_usage_map
->put (dwarf_proc_die
, 1 - dpi
.args_count
);
18508 return dwarf_proc_die
;
18511 /* Helper function for loc_list_from_tree. Perform OP binary op,
18512 but after converting arguments to type_die, afterwards convert
18513 back to unsigned. */
18515 static dw_loc_list_ref
18516 typed_binop_from_tree (enum dwarf_location_atom op
, tree loc
,
18517 dw_die_ref type_die
, scalar_int_mode mode
,
18518 struct loc_descr_context
*context
)
18520 dw_loc_list_ref op0
, op1
;
18521 dw_loc_descr_ref cvt
, binop
;
18523 if (type_die
== NULL
)
18526 op0
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
18527 op1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
18528 if (op0
== NULL
|| op1
== NULL
)
18531 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
18532 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
18533 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
18534 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
18535 add_loc_descr_to_each (op0
, cvt
);
18537 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
18538 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
18539 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
18540 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
18541 add_loc_descr_to_each (op1
, cvt
);
18543 add_loc_list (&op0
, op1
);
18547 binop
= new_loc_descr (op
, 0, 0);
18548 convert_descriptor_to_mode (mode
, binop
);
18549 add_loc_descr_to_each (op0
, binop
);
18554 /* Generate Dwarf location list representing LOC.
18555 If WANT_ADDRESS is false, expression computing LOC will be computed
18556 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
18557 if WANT_ADDRESS is 2, expression computing address useable in location
18558 will be returned (i.e. DW_OP_reg can be used
18559 to refer to register values).
18561 CONTEXT provides information to customize the location descriptions
18562 generation. Its context_type field specifies what type is implicitly
18563 referenced by DW_OP_push_object_address. If it is NULL_TREE, this operation
18564 will not be generated.
18566 Its DPI field determines whether we are generating a DWARF expression for a
18567 DWARF procedure, so PARM_DECL references are processed specifically.
18569 If CONTEXT is NULL, the behavior is the same as if context_type, base_decl
18570 and dpi fields were null. */
18572 static dw_loc_list_ref
18573 loc_list_from_tree_1 (tree loc
, int want_address
,
18574 struct loc_descr_context
*context
)
18576 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
18577 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
18578 int have_address
= 0;
18579 enum dwarf_location_atom op
;
18581 /* ??? Most of the time we do not take proper care for sign/zero
18582 extending the values properly. Hopefully this won't be a real
18585 if (context
!= NULL
18586 && context
->base_decl
== loc
18587 && want_address
== 0)
18589 if (dwarf_version
>= 3 || !dwarf_strict
)
18590 return new_loc_list (new_loc_descr (DW_OP_push_object_address
, 0, 0),
18591 NULL
, 0, NULL
, 0, NULL
);
18596 switch (TREE_CODE (loc
))
18599 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
18602 case PLACEHOLDER_EXPR
:
18603 /* This case involves extracting fields from an object to determine the
18604 position of other fields. It is supposed to appear only as the first
18605 operand of COMPONENT_REF nodes and to reference precisely the type
18606 that the context allows or its enclosing type. */
18607 if (context
!= NULL
18608 && (TREE_TYPE (loc
) == context
->context_type
18609 || TREE_TYPE (loc
) == TYPE_CONTEXT (context
->context_type
))
18610 && want_address
>= 1)
18612 if (dwarf_version
>= 3 || !dwarf_strict
)
18614 ret
= new_loc_descr (DW_OP_push_object_address
, 0, 0);
18621 /* For DW_TAG_generic_subrange attributes, PLACEHOLDER_EXPR stands for
18622 the single argument passed by consumer. */
18623 else if (context
!= NULL
18624 && context
->placeholder_arg
18625 && INTEGRAL_TYPE_P (TREE_TYPE (loc
))
18626 && want_address
== 0)
18628 ret
= new_loc_descr (DW_OP_pick
, 0, 0);
18629 ret
->frame_offset_rel
= 1;
18630 context
->placeholder_seen
= true;
18634 expansion_failed (loc
, NULL_RTX
,
18635 "PLACEHOLDER_EXPR for an unexpected type");
18640 tree callee
= get_callee_fndecl (loc
);
18641 dw_die_ref dwarf_proc
;
18644 && is_handled_procedure_type (TREE_TYPE (TREE_TYPE (callee
)))
18645 && (dwarf_proc
= function_to_dwarf_procedure (callee
)))
18647 /* DWARF procedures are used for size functions, which are built
18648 when size expressions contain conditional constructs, so we
18649 request strict preservation of signedness for comparisons. */
18650 bool old_strict_signedness
;
18653 old_strict_signedness
= context
->strict_signedness
;
18654 context
->strict_signedness
= true;
18657 /* Evaluate arguments right-to-left so that the first argument
18658 will be the top-most one on the stack. */
18659 for (int i
= call_expr_nargs (loc
) - 1; i
>= 0; --i
)
18661 tree arg
= CALL_EXPR_ARG (loc
, i
);
18662 ret1
= loc_descriptor_from_tree (arg
, 0, context
);
18665 expansion_failed (arg
, NULL_RTX
, "CALL_EXPR argument");
18668 add_loc_descr (&ret
, ret1
);
18671 ret1
= new_loc_descr (DW_OP_call4
, 0, 0);
18672 ret1
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
18673 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.die
= dwarf_proc
;
18674 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
18675 add_loc_descr (&ret
, ret1
);
18677 context
->strict_signedness
= old_strict_signedness
;
18680 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR target");
18684 case PREINCREMENT_EXPR
:
18685 case PREDECREMENT_EXPR
:
18686 case POSTINCREMENT_EXPR
:
18687 case POSTDECREMENT_EXPR
:
18688 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
18689 /* There are no opcodes for these operations. */
18693 /* If we already want an address, see if there is INDIRECT_REF inside
18694 e.g. for &this->field. */
18697 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
18698 (loc
, want_address
== 2, context
);
18701 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
18702 && (ret
= cst_pool_loc_descr (loc
)))
18705 /* Otherwise, process the argument and look for the address. */
18706 if (!list_ret
&& !ret
)
18707 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 1, context
);
18711 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
18717 if (DECL_THREAD_LOCAL_P (loc
))
18720 enum dwarf_location_atom tls_op
;
18721 enum dtprel_bool dtprel
= dtprel_false
;
18723 if (targetm
.have_tls
)
18725 /* If this is not defined, we have no way to emit the
18727 if (!targetm
.asm_out
.output_dwarf_dtprel
)
18730 /* The way DW_OP_GNU_push_tls_address is specified, we
18731 can only look up addresses of objects in the current
18732 module. We used DW_OP_addr as first op, but that's
18733 wrong, because DW_OP_addr is relocated by the debug
18734 info consumer, while DW_OP_GNU_push_tls_address
18735 operand shouldn't be. */
18736 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
18738 dtprel
= dtprel_true
;
18739 /* We check for DWARF 5 here because gdb did not implement
18740 DW_OP_form_tls_address until after 7.12. */
18741 tls_op
= (dwarf_version
>= 5 ? DW_OP_form_tls_address
18742 : DW_OP_GNU_push_tls_address
);
18746 if (!targetm
.emutls
.debug_form_tls_address
18747 || !(dwarf_version
>= 3 || !dwarf_strict
))
18749 /* We stuffed the control variable into the DECL_VALUE_EXPR
18750 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
18751 no longer appear in gimple code. We used the control
18752 variable in specific so that we could pick it up here. */
18753 loc
= DECL_VALUE_EXPR (loc
);
18754 tls_op
= DW_OP_form_tls_address
;
18757 rtl
= rtl_for_decl_location (loc
);
18758 if (rtl
== NULL_RTX
)
18763 rtl
= XEXP (rtl
, 0);
18764 if (! CONSTANT_P (rtl
))
18767 ret
= new_addr_loc_descr (rtl
, dtprel
);
18768 ret1
= new_loc_descr (tls_op
, 0, 0);
18769 add_loc_descr (&ret
, ret1
);
18777 if (context
!= NULL
&& context
->dpi
!= NULL
18778 && DECL_CONTEXT (loc
) == context
->dpi
->fndecl
)
18780 /* We are generating code for a DWARF procedure and we want to access
18781 one of its arguments: find the appropriate argument offset and let
18782 the resolve_args_picking pass compute the offset that complies
18783 with the stack frame size. */
18787 for (cursor
= DECL_ARGUMENTS (context
->dpi
->fndecl
);
18788 cursor
!= NULL_TREE
&& cursor
!= loc
;
18789 cursor
= TREE_CHAIN (cursor
), ++i
)
18791 /* If we are translating a DWARF procedure, all referenced parameters
18792 must belong to the current function. */
18793 gcc_assert (cursor
!= NULL_TREE
);
18795 ret
= new_loc_descr (DW_OP_pick
, i
, 0);
18796 ret
->frame_offset_rel
= 1;
18802 if (DECL_HAS_VALUE_EXPR_P (loc
))
18804 tree value_expr
= DECL_VALUE_EXPR (loc
);
18806 /* Non-local frame structures are DECL_IGNORED_P variables so we need
18807 to wait until they get an RTX in order to reference them. */
18809 && TREE_CODE (value_expr
) == COMPONENT_REF
18810 && VAR_P (TREE_OPERAND (value_expr
, 0))
18811 && DECL_NONLOCAL_FRAME (TREE_OPERAND (value_expr
, 0)))
18814 return loc_list_from_tree_1 (value_expr
, want_address
, context
);
18819 case FUNCTION_DECL
:
18822 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
18824 if (loc_list
&& loc_list
->first
)
18826 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
18827 have_address
= want_address
!= 0;
18830 rtl
= rtl_for_decl_location (loc
);
18831 if (rtl
== NULL_RTX
)
18833 if (TREE_CODE (loc
) != FUNCTION_DECL
18835 && want_address
!= 1
18836 && ! DECL_IGNORED_P (loc
)
18837 && (INTEGRAL_TYPE_P (TREE_TYPE (loc
))
18838 || POINTER_TYPE_P (TREE_TYPE (loc
)))
18839 && (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (loc
)))
18840 <= DWARF2_ADDR_SIZE
))
18842 dw_die_ref ref
= lookup_decl_die (loc
);
18845 ret
= new_loc_descr (DW_OP_GNU_variable_value
, 0, 0);
18846 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
18847 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
18848 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
18850 else if (current_function_decl
18851 && DECL_CONTEXT (loc
) == current_function_decl
)
18853 ret
= new_loc_descr (DW_OP_GNU_variable_value
, 0, 0);
18854 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
18855 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= loc
;
18859 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
18862 else if (CONST_INT_P (rtl
))
18864 HOST_WIDE_INT val
= INTVAL (rtl
);
18865 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
18866 val
&= GET_MODE_MASK (DECL_MODE (loc
));
18867 ret
= int_loc_descriptor (val
);
18869 else if (GET_CODE (rtl
) == CONST_STRING
)
18871 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
18874 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
18875 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
18878 machine_mode mode
, mem_mode
;
18880 /* Certain constructs can only be represented at top-level. */
18881 if (want_address
== 2)
18883 ret
= loc_descriptor (rtl
, VOIDmode
,
18884 VAR_INIT_STATUS_INITIALIZED
);
18889 mode
= GET_MODE (rtl
);
18890 mem_mode
= VOIDmode
;
18894 mode
= get_address_mode (rtl
);
18895 rtl
= XEXP (rtl
, 0);
18898 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
18899 VAR_INIT_STATUS_INITIALIZED
);
18902 expansion_failed (loc
, rtl
,
18903 "failed to produce loc descriptor for rtl");
18909 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
18916 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
18920 case TARGET_MEM_REF
:
18922 case DEBUG_EXPR_DECL
:
18925 case COMPOUND_EXPR
:
18926 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), want_address
,
18930 case VIEW_CONVERT_EXPR
:
18933 case NON_LVALUE_EXPR
:
18934 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), want_address
,
18937 case COMPONENT_REF
:
18938 case BIT_FIELD_REF
:
18940 case ARRAY_RANGE_REF
:
18941 case REALPART_EXPR
:
18942 case IMAGPART_EXPR
:
18945 poly_int64 bitsize
, bitpos
, bytepos
;
18947 int unsignedp
, reversep
, volatilep
= 0;
18949 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
18950 &unsignedp
, &reversep
, &volatilep
);
18952 gcc_assert (obj
!= loc
);
18954 list_ret
= loc_list_from_tree_1 (obj
,
18956 && known_eq (bitpos
, 0)
18957 && !offset
? 2 : 1,
18959 /* TODO: We can extract value of the small expression via shifting even
18960 for nonzero bitpos. */
18963 if (!multiple_p (bitpos
, BITS_PER_UNIT
, &bytepos
)
18964 || !multiple_p (bitsize
, BITS_PER_UNIT
))
18966 expansion_failed (loc
, NULL_RTX
,
18967 "bitfield access");
18971 if (offset
!= NULL_TREE
)
18973 /* Variable offset. */
18974 list_ret1
= loc_list_from_tree_1 (offset
, 0, context
);
18975 if (list_ret1
== 0)
18977 add_loc_list (&list_ret
, list_ret1
);
18980 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
18983 HOST_WIDE_INT value
;
18984 if (bytepos
.is_constant (&value
) && value
> 0)
18985 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
,
18987 else if (maybe_ne (bytepos
, 0))
18988 loc_list_plus_const (list_ret
, bytepos
);
18995 if ((want_address
|| !tree_fits_shwi_p (loc
))
18996 && (ret
= cst_pool_loc_descr (loc
)))
18998 else if (want_address
== 2
18999 && tree_fits_shwi_p (loc
)
19000 && (ret
= address_of_int_loc_descriptor
19001 (int_size_in_bytes (TREE_TYPE (loc
)),
19002 tree_to_shwi (loc
))))
19004 else if (tree_fits_shwi_p (loc
))
19005 ret
= int_loc_descriptor (tree_to_shwi (loc
));
19006 else if (tree_fits_uhwi_p (loc
))
19007 ret
= uint_loc_descriptor (tree_to_uhwi (loc
));
19010 expansion_failed (loc
, NULL_RTX
,
19011 "Integer operand is not host integer");
19020 expansion_failed (loc
, NULL_RTX
,
19021 "constant address with a runtime component");
19025 if (!poly_int_tree_p (loc
, &value
))
19027 expansion_failed (loc
, NULL_RTX
, "constant too big");
19030 ret
= int_loc_descriptor (value
);
19038 if ((ret
= cst_pool_loc_descr (loc
)))
19040 else if (TREE_CODE (loc
) == CONSTRUCTOR
)
19042 tree type
= TREE_TYPE (loc
);
19043 unsigned HOST_WIDE_INT size
= int_size_in_bytes (type
);
19044 unsigned HOST_WIDE_INT offset
= 0;
19045 unsigned HOST_WIDE_INT cnt
;
19046 constructor_elt
*ce
;
19048 if (TREE_CODE (type
) == RECORD_TYPE
)
19050 /* This is very limited, but it's enough to output
19051 pointers to member functions, as long as the
19052 referenced function is defined in the current
19053 translation unit. */
19054 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (loc
), cnt
, ce
)
19056 tree val
= ce
->value
;
19058 tree field
= ce
->index
;
19063 if (!field
|| DECL_BIT_FIELD (field
))
19065 expansion_failed (loc
, NULL_RTX
,
19066 "bitfield in record type constructor");
19067 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
19072 HOST_WIDE_INT fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
19073 unsigned HOST_WIDE_INT pos
= int_byte_position (field
);
19074 gcc_assert (pos
+ fieldsize
<= size
);
19077 expansion_failed (loc
, NULL_RTX
,
19078 "out-of-order fields in record constructor");
19079 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
19085 ret1
= new_loc_descr (DW_OP_piece
, pos
- offset
, 0);
19086 add_loc_descr (&ret
, ret1
);
19089 if (val
&& fieldsize
!= 0)
19091 ret1
= loc_descriptor_from_tree (val
, want_address
, context
);
19094 expansion_failed (loc
, NULL_RTX
,
19095 "unsupported expression in field");
19096 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
19100 add_loc_descr (&ret
, ret1
);
19104 ret1
= new_loc_descr (DW_OP_piece
, fieldsize
, 0);
19105 add_loc_descr (&ret
, ret1
);
19106 offset
= pos
+ fieldsize
;
19110 if (offset
!= size
)
19112 ret1
= new_loc_descr (DW_OP_piece
, size
- offset
, 0);
19113 add_loc_descr (&ret
, ret1
);
19117 have_address
= !!want_address
;
19120 expansion_failed (loc
, NULL_RTX
,
19121 "constructor of non-record type");
19124 /* We can construct small constants here using int_loc_descriptor. */
19125 expansion_failed (loc
, NULL_RTX
,
19126 "constructor or constant not in constant pool");
19129 case TRUTH_AND_EXPR
:
19130 case TRUTH_ANDIF_EXPR
:
19135 case TRUTH_XOR_EXPR
:
19140 case TRUTH_OR_EXPR
:
19141 case TRUTH_ORIF_EXPR
:
19146 case EXACT_DIV_EXPR
:
19147 case FLOOR_DIV_EXPR
:
19148 case TRUNC_DIV_EXPR
:
19149 /* Turn a divide by a power of 2 into a shift when possible. */
19150 if (TYPE_UNSIGNED (TREE_TYPE (loc
))
19151 && tree_fits_uhwi_p (TREE_OPERAND (loc
, 1)))
19153 const int log2
= exact_log2 (tree_to_uhwi (TREE_OPERAND (loc
, 1)));
19157 = loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
19161 add_loc_descr_to_each (list_ret
, uint_loc_descriptor (log2
));
19162 add_loc_descr_to_each (list_ret
,
19163 new_loc_descr (DW_OP_shr
, 0, 0));
19170 case CEIL_DIV_EXPR
:
19171 case ROUND_DIV_EXPR
:
19172 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
19174 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (loc
));
19175 scalar_int_mode int_mode
;
19177 if ((dwarf_strict
&& dwarf_version
< 5)
19178 || !is_a
<scalar_int_mode
> (mode
, &int_mode
))
19181 /* We can use a signed divide if the sign bit is not set. */
19182 if (GET_MODE_SIZE (int_mode
) < DWARF2_ADDR_SIZE
)
19188 list_ret
= typed_binop_from_tree (DW_OP_div
, loc
,
19189 base_type_for_mode (int_mode
, 1),
19190 int_mode
, context
);
19200 case FLOOR_MOD_EXPR
:
19201 case CEIL_MOD_EXPR
:
19202 case ROUND_MOD_EXPR
:
19203 case TRUNC_MOD_EXPR
:
19204 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
19209 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
19210 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
19211 if (list_ret
== 0 || list_ret1
== 0)
19214 add_loc_list (&list_ret
, list_ret1
);
19217 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
19218 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
19219 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
19220 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
19221 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
19233 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
19236 case POINTER_PLUS_EXPR
:
19239 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
19241 /* Big unsigned numbers can fit in HOST_WIDE_INT but it may be
19242 smarter to encode their opposite. The DW_OP_plus_uconst operation
19243 takes 1 + X bytes, X being the size of the ULEB128 addend. On the
19244 other hand, a "<push literal>; DW_OP_minus" pattern takes 1 + Y
19245 bytes, Y being the size of the operation that pushes the opposite
19246 of the addend. So let's choose the smallest representation. */
19247 const tree tree_addend
= TREE_OPERAND (loc
, 1);
19248 offset_int wi_addend
;
19249 HOST_WIDE_INT shwi_addend
;
19250 dw_loc_descr_ref loc_naddend
;
19252 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
19256 /* Try to get the literal to push. It is the opposite of the addend,
19257 so as we rely on wrapping during DWARF evaluation, first decode
19258 the literal as a "DWARF-sized" signed number. */
19259 wi_addend
= wi::to_offset (tree_addend
);
19260 wi_addend
= wi::sext (wi_addend
, DWARF2_ADDR_SIZE
* 8);
19261 shwi_addend
= wi_addend
.to_shwi ();
19262 loc_naddend
= (shwi_addend
!= INTTYPE_MINIMUM (HOST_WIDE_INT
))
19263 ? int_loc_descriptor (-shwi_addend
)
19266 if (loc_naddend
!= NULL
19267 && ((unsigned) size_of_uleb128 (shwi_addend
)
19268 > size_of_loc_descr (loc_naddend
)))
19270 add_loc_descr_to_each (list_ret
, loc_naddend
);
19271 add_loc_descr_to_each (list_ret
,
19272 new_loc_descr (DW_OP_minus
, 0, 0));
19276 for (dw_loc_descr_ref loc_cur
= loc_naddend
; loc_cur
!= NULL
; )
19278 loc_naddend
= loc_cur
;
19279 loc_cur
= loc_cur
->dw_loc_next
;
19280 ggc_free (loc_naddend
);
19282 loc_list_plus_const (list_ret
, wi_addend
.to_shwi ());
19292 goto do_comp_binop
;
19296 goto do_comp_binop
;
19300 goto do_comp_binop
;
19304 goto do_comp_binop
;
19307 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
19309 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
19310 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
19311 list_ret
= loc_list_from_uint_comparison (list_ret
, list_ret1
,
19327 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
19328 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
19329 if (list_ret
== 0 || list_ret1
== 0)
19332 add_loc_list (&list_ret
, list_ret1
);
19335 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
19338 case TRUTH_NOT_EXPR
:
19352 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
19356 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
19362 const enum tree_code code
=
19363 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
19365 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
19366 build2 (code
, integer_type_node
,
19367 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
19368 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
19375 dw_loc_descr_ref lhs
19376 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
19377 dw_loc_list_ref rhs
19378 = loc_list_from_tree_1 (TREE_OPERAND (loc
, 2), 0, context
);
19379 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
19381 /* DW_OP_bra is branch-on-nonzero so avoid doing useless work. */
19382 if (TREE_CODE (TREE_OPERAND (loc
, 0)) == NE_EXPR
19383 && integer_zerop (TREE_OPERAND (TREE_OPERAND (loc
, 0), 1)))
19385 = loc_list_from_tree_1 (TREE_OPERAND (TREE_OPERAND (loc
, 0), 0),
19388 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
19389 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
19392 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
19393 add_loc_descr_to_each (list_ret
, bra_node
);
19395 add_loc_list (&list_ret
, rhs
);
19396 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
19397 add_loc_descr_to_each (list_ret
, jump_node
);
19399 add_loc_descr_to_each (list_ret
, lhs
);
19400 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
19401 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
19403 /* ??? Need a node to point the skip at. Use a nop. */
19404 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
19405 add_loc_descr_to_each (list_ret
, tmp
);
19406 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
19407 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
19411 case FIX_TRUNC_EXPR
:
19414 case COMPOUND_LITERAL_EXPR
:
19415 return loc_list_from_tree_1 (COMPOUND_LITERAL_EXPR_DECL (loc
),
19419 /* Leave front-end specific codes as simply unknown. This comes
19420 up, for instance, with the C STMT_EXPR. */
19421 if ((unsigned int) TREE_CODE (loc
)
19422 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
19424 expansion_failed (loc
, NULL_RTX
,
19425 "language specific tree node");
19429 /* Otherwise this is a generic code; we should just lists all of
19430 these explicitly. We forgot one. */
19432 gcc_unreachable ();
19434 /* In a release build, we want to degrade gracefully: better to
19435 generate incomplete debugging information than to crash. */
19439 if (!ret
&& !list_ret
)
19442 if (want_address
== 2 && !have_address
19443 && (dwarf_version
>= 4 || !dwarf_strict
))
19445 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
19447 expansion_failed (loc
, NULL_RTX
,
19448 "DWARF address size mismatch");
19452 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
19454 add_loc_descr_to_each (list_ret
,
19455 new_loc_descr (DW_OP_stack_value
, 0, 0));
19458 /* Show if we can't fill the request for an address. */
19459 if (want_address
&& !have_address
)
19461 expansion_failed (loc
, NULL_RTX
,
19462 "Want address and only have value");
19466 gcc_assert (!ret
|| !list_ret
);
19468 /* If we've got an address and don't want one, dereference. */
19469 if (!want_address
&& have_address
)
19471 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
19472 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (loc
));
19473 scalar_int_mode int_mode
;
19474 dw_die_ref type_die
;
19475 dw_loc_descr_ref deref
;
19477 /* If the size is greater than DWARF2_ADDR_SIZE, bail out. */
19478 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
19480 expansion_failed (loc
, NULL_RTX
,
19481 "DWARF address size mismatch");
19485 /* If it is equal to DWARF2_ADDR_SIZE, extension does not matter. */
19486 else if (size
== DWARF2_ADDR_SIZE
)
19487 deref
= new_loc_descr (DW_OP_deref
, size
, 0);
19489 /* If it is lower than DWARF2_ADDR_SIZE, DW_OP_deref_size will zero-
19490 extend the value, which is really OK for unsigned types only. */
19491 else if (!(context
&& context
->strict_signedness
)
19492 || TYPE_UNSIGNED (TREE_TYPE (loc
))
19493 || (dwarf_strict
&& dwarf_version
< 5)
19494 || !is_a
<scalar_int_mode
> (mode
, &int_mode
)
19495 || !(type_die
= base_type_for_mode (mode
, false)))
19496 deref
= new_loc_descr (DW_OP_deref_size
, size
, 0);
19498 /* Use DW_OP_deref_type for signed integral types if possible, but
19499 convert back to the generic type to avoid type mismatches later. */
19502 deref
= new_loc_descr (dwarf_OP (DW_OP_deref_type
), size
, 0);
19503 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
19504 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
19505 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
19506 add_loc_descr (&deref
,
19507 new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0));
19511 add_loc_descr (&ret
, deref
);
19513 add_loc_descr_to_each (list_ret
, deref
);
19517 list_ret
= new_loc_list (ret
, NULL
, 0, NULL
, 0, NULL
);
19522 /* Likewise, but strip useless DW_OP_nop operations in the resulting
19525 static dw_loc_list_ref
19526 loc_list_from_tree (tree loc
, int want_address
,
19527 struct loc_descr_context
*context
)
19529 dw_loc_list_ref result
= loc_list_from_tree_1 (loc
, want_address
, context
);
19531 for (dw_loc_list_ref loc_cur
= result
;
19532 loc_cur
!= NULL
; loc_cur
= loc_cur
->dw_loc_next
)
19533 loc_descr_without_nops (loc_cur
->expr
);
19537 /* Same as above but return only single location expression. */
19538 static dw_loc_descr_ref
19539 loc_descriptor_from_tree (tree loc
, int want_address
,
19540 struct loc_descr_context
*context
)
19542 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
, context
);
19545 if (ret
->dw_loc_next
)
19547 expansion_failed (loc
, NULL_RTX
,
19548 "Location list where only loc descriptor needed");
19554 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
19555 pointer to the declared type for the relevant field variable, or return
19556 `integer_type_node' if the given node turns out to be an
19557 ERROR_MARK node. */
19560 field_type (const_tree decl
)
19564 if (TREE_CODE (decl
) == ERROR_MARK
)
19565 return integer_type_node
;
19567 type
= DECL_BIT_FIELD_TYPE (decl
);
19568 if (type
== NULL_TREE
)
19569 type
= TREE_TYPE (decl
);
19574 /* Given a pointer to a tree node, return the alignment in bits for
19575 it, or else return BITS_PER_WORD if the node actually turns out to
19576 be an ERROR_MARK node. */
19578 static inline unsigned
19579 simple_type_align_in_bits (const_tree type
)
19581 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
19584 static inline unsigned
19585 simple_decl_align_in_bits (const_tree decl
)
19587 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
19590 /* Return the result of rounding T up to ALIGN. */
19592 static inline offset_int
19593 round_up_to_align (const offset_int
&t
, unsigned int align
)
19595 return wi::udiv_trunc (t
+ align
- 1, align
) * align
;
19598 /* Helper structure for RECORD_TYPE processing. */
19601 /* Root RECORD_TYPE. It is needed to generate data member location
19602 descriptions in variable-length records (VLR), but also to cope with
19603 variants, which are composed of nested structures multiplexed with
19604 QUAL_UNION_TYPE nodes. Each time such a structure is passed to a
19605 function processing a FIELD_DECL, it is required to be non null. */
19608 /* When generating a variant part in a RECORD_TYPE (i.e. a nested
19609 QUAL_UNION_TYPE), this holds an expression that computes the offset for
19610 this variant part as part of the root record (in storage units). For
19611 regular records, it must be NULL_TREE. */
19612 tree variant_part_offset
;
19615 /* Given a pointer to a FIELD_DECL, compute the byte offset of the lowest
19616 addressed byte of the "containing object" for the given FIELD_DECL. If
19617 possible, return a native constant through CST_OFFSET (in which case NULL is
19618 returned); otherwise return a DWARF expression that computes the offset.
19620 Set *CST_OFFSET to 0 and return NULL if we are unable to determine what
19621 that offset is, either because the argument turns out to be a pointer to an
19622 ERROR_MARK node, or because the offset expression is too complex for us.
19624 CTX is required: see the comment for VLR_CONTEXT. */
19626 static dw_loc_descr_ref
19627 field_byte_offset (const_tree decl
, struct vlr_context
*ctx
,
19628 HOST_WIDE_INT
*cst_offset
)
19631 dw_loc_list_ref loc_result
;
19635 if (TREE_CODE (decl
) == ERROR_MARK
)
19638 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
19640 /* We cannot handle variable bit offsets at the moment, so abort if it's the
19642 if (TREE_CODE (DECL_FIELD_BIT_OFFSET (decl
)) != INTEGER_CST
)
19645 /* We used to handle only constant offsets in all cases. Now, we handle
19646 properly dynamic byte offsets only when PCC bitfield type doesn't
19648 if (PCC_BITFIELD_TYPE_MATTERS
19649 && TREE_CODE (DECL_FIELD_OFFSET (decl
)) == INTEGER_CST
)
19651 offset_int object_offset_in_bits
;
19652 offset_int object_offset_in_bytes
;
19653 offset_int bitpos_int
;
19655 tree field_size_tree
;
19656 offset_int deepest_bitpos
;
19657 offset_int field_size_in_bits
;
19658 unsigned int type_align_in_bits
;
19659 unsigned int decl_align_in_bits
;
19660 offset_int type_size_in_bits
;
19662 bitpos_int
= wi::to_offset (bit_position (decl
));
19663 type
= field_type (decl
);
19664 type_size_in_bits
= offset_int_type_size_in_bits (type
);
19665 type_align_in_bits
= simple_type_align_in_bits (type
);
19667 field_size_tree
= DECL_SIZE (decl
);
19669 /* The size could be unspecified if there was an error, or for
19670 a flexible array member. */
19671 if (!field_size_tree
)
19672 field_size_tree
= bitsize_zero_node
;
19674 /* If the size of the field is not constant, use the type size. */
19675 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
19676 field_size_in_bits
= wi::to_offset (field_size_tree
);
19678 field_size_in_bits
= type_size_in_bits
;
19680 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
19682 /* The GCC front-end doesn't make any attempt to keep track of the
19683 starting bit offset (relative to the start of the containing
19684 structure type) of the hypothetical "containing object" for a
19685 bit-field. Thus, when computing the byte offset value for the
19686 start of the "containing object" of a bit-field, we must deduce
19687 this information on our own. This can be rather tricky to do in
19688 some cases. For example, handling the following structure type
19689 definition when compiling for an i386/i486 target (which only
19690 aligns long long's to 32-bit boundaries) can be very tricky:
19692 struct S { int field1; long long field2:31; };
19694 Fortunately, there is a simple rule-of-thumb which can be used
19695 in such cases. When compiling for an i386/i486, GCC will
19696 allocate 8 bytes for the structure shown above. It decides to
19697 do this based upon one simple rule for bit-field allocation.
19698 GCC allocates each "containing object" for each bit-field at
19699 the first (i.e. lowest addressed) legitimate alignment boundary
19700 (based upon the required minimum alignment for the declared
19701 type of the field) which it can possibly use, subject to the
19702 condition that there is still enough available space remaining
19703 in the containing object (when allocated at the selected point)
19704 to fully accommodate all of the bits of the bit-field itself.
19706 This simple rule makes it obvious why GCC allocates 8 bytes for
19707 each object of the structure type shown above. When looking
19708 for a place to allocate the "containing object" for `field2',
19709 the compiler simply tries to allocate a 64-bit "containing
19710 object" at each successive 32-bit boundary (starting at zero)
19711 until it finds a place to allocate that 64- bit field such that
19712 at least 31 contiguous (and previously unallocated) bits remain
19713 within that selected 64 bit field. (As it turns out, for the
19714 example above, the compiler finds it is OK to allocate the
19715 "containing object" 64-bit field at bit-offset zero within the
19718 Here we attempt to work backwards from the limited set of facts
19719 we're given, and we try to deduce from those facts, where GCC
19720 must have believed that the containing object started (within
19721 the structure type). The value we deduce is then used (by the
19722 callers of this routine) to generate DW_AT_location and
19723 DW_AT_bit_offset attributes for fields (both bit-fields and, in
19724 the case of DW_AT_location, regular fields as well). */
19726 /* Figure out the bit-distance from the start of the structure to
19727 the "deepest" bit of the bit-field. */
19728 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
19730 /* This is the tricky part. Use some fancy footwork to deduce
19731 where the lowest addressed bit of the containing object must
19733 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
19735 /* Round up to type_align by default. This works best for
19737 object_offset_in_bits
19738 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
19740 if (wi::gtu_p (object_offset_in_bits
, bitpos_int
))
19742 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
19744 /* Round up to decl_align instead. */
19745 object_offset_in_bits
19746 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
19749 object_offset_in_bytes
19750 = wi::lrshift (object_offset_in_bits
, LOG2_BITS_PER_UNIT
);
19751 if (ctx
->variant_part_offset
== NULL_TREE
)
19753 *cst_offset
= object_offset_in_bytes
.to_shwi ();
19756 tree_result
= wide_int_to_tree (sizetype
, object_offset_in_bytes
);
19759 tree_result
= byte_position (decl
);
19761 if (ctx
->variant_part_offset
!= NULL_TREE
)
19762 tree_result
= fold_build2 (PLUS_EXPR
, TREE_TYPE (tree_result
),
19763 ctx
->variant_part_offset
, tree_result
);
19765 /* If the byte offset is a constant, it's simplier to handle a native
19766 constant rather than a DWARF expression. */
19767 if (TREE_CODE (tree_result
) == INTEGER_CST
)
19769 *cst_offset
= wi::to_offset (tree_result
).to_shwi ();
19773 struct loc_descr_context loc_ctx
= {
19774 ctx
->struct_type
, /* context_type */
19775 NULL_TREE
, /* base_decl */
19777 false, /* placeholder_arg */
19778 false, /* placeholder_seen */
19779 false /* strict_signedness */
19781 loc_result
= loc_list_from_tree (tree_result
, 0, &loc_ctx
);
19783 /* We want a DWARF expression: abort if we only have a location list with
19784 multiple elements. */
19785 if (!loc_result
|| !single_element_loc_list_p (loc_result
))
19788 return loc_result
->expr
;
19791 /* The following routines define various Dwarf attributes and any data
19792 associated with them. */
19794 /* Add a location description attribute value to a DIE.
19796 This emits location attributes suitable for whole variables and
19797 whole parameters. Note that the location attributes for struct fields are
19798 generated by the routine `data_member_location_attribute' below. */
19801 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
19802 dw_loc_list_ref descr
)
19804 bool check_no_locviews
= true;
19807 if (single_element_loc_list_p (descr
))
19808 add_AT_loc (die
, attr_kind
, descr
->expr
);
19811 add_AT_loc_list (die
, attr_kind
, descr
);
19812 gcc_assert (descr
->ll_symbol
);
19813 if (attr_kind
== DW_AT_location
&& descr
->vl_symbol
19814 && dwarf2out_locviews_in_attribute ())
19816 add_AT_view_list (die
, DW_AT_GNU_locviews
);
19817 check_no_locviews
= false;
19821 if (check_no_locviews
)
19822 gcc_assert (!get_AT (die
, DW_AT_GNU_locviews
));
19825 /* Add DW_AT_accessibility attribute to DIE if needed. */
19828 add_accessibility_attribute (dw_die_ref die
, tree decl
)
19830 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
19831 children, otherwise the default is DW_ACCESS_public. In DWARF2
19832 the default has always been DW_ACCESS_public. */
19833 if (TREE_PROTECTED (decl
))
19834 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
19835 else if (TREE_PRIVATE (decl
))
19837 if (dwarf_version
== 2
19838 || die
->die_parent
== NULL
19839 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
19840 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
19842 else if (dwarf_version
> 2
19844 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
19845 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
19848 /* Attach the specialized form of location attribute used for data members of
19849 struct and union types. In the special case of a FIELD_DECL node which
19850 represents a bit-field, the "offset" part of this special location
19851 descriptor must indicate the distance in bytes from the lowest-addressed
19852 byte of the containing struct or union type to the lowest-addressed byte of
19853 the "containing object" for the bit-field. (See the `field_byte_offset'
19856 For any given bit-field, the "containing object" is a hypothetical object
19857 (of some integral or enum type) within which the given bit-field lives. The
19858 type of this hypothetical "containing object" is always the same as the
19859 declared type of the individual bit-field itself (for GCC anyway... the
19860 DWARF spec doesn't actually mandate this). Note that it is the size (in
19861 bytes) of the hypothetical "containing object" which will be given in the
19862 DW_AT_byte_size attribute for this bit-field. (See the
19863 `byte_size_attribute' function below.) It is also used when calculating the
19864 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
19867 CTX is required: see the comment for VLR_CONTEXT. */
19870 add_data_member_location_attribute (dw_die_ref die
,
19872 struct vlr_context
*ctx
)
19874 HOST_WIDE_INT offset
;
19875 dw_loc_descr_ref loc_descr
= 0;
19877 if (TREE_CODE (decl
) == TREE_BINFO
)
19879 /* We're working on the TAG_inheritance for a base class. */
19880 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
19882 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
19883 aren't at a fixed offset from all (sub)objects of the same
19884 type. We need to extract the appropriate offset from our
19885 vtable. The following dwarf expression means
19887 BaseAddr = ObAddr + *((*ObAddr) - Offset)
19889 This is specific to the V3 ABI, of course. */
19891 dw_loc_descr_ref tmp
;
19893 /* Make a copy of the object address. */
19894 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
19895 add_loc_descr (&loc_descr
, tmp
);
19897 /* Extract the vtable address. */
19898 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
19899 add_loc_descr (&loc_descr
, tmp
);
19901 /* Calculate the address of the offset. */
19902 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
19903 gcc_assert (offset
< 0);
19905 tmp
= int_loc_descriptor (-offset
);
19906 add_loc_descr (&loc_descr
, tmp
);
19907 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
19908 add_loc_descr (&loc_descr
, tmp
);
19910 /* Extract the offset. */
19911 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
19912 add_loc_descr (&loc_descr
, tmp
);
19914 /* Add it to the object address. */
19915 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
19916 add_loc_descr (&loc_descr
, tmp
);
19919 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
19923 loc_descr
= field_byte_offset (decl
, ctx
, &offset
);
19928 /* If loc_descr is available, then we know the offset is dynamic. */
19929 else if (gnat_encodings
== DWARF_GNAT_ENCODINGS_ALL
)
19935 /* Data member location evaluation starts with the base address on the
19936 stack. Compute the field offset and add it to this base address. */
19938 add_loc_descr (&loc_descr
, new_loc_descr (DW_OP_plus
, 0, 0));
19943 /* While DW_AT_data_bit_offset has been added already in DWARF4,
19944 e.g. GDB only added support to it in November 2016. For DWARF5
19945 we need newer debug info consumers anyway. We might change this
19946 to dwarf_version >= 4 once most consumers catched up. */
19947 if (dwarf_version
>= 5
19948 && TREE_CODE (decl
) == FIELD_DECL
19949 && DECL_BIT_FIELD_TYPE (decl
)
19950 && (ctx
->variant_part_offset
== NULL_TREE
19951 || TREE_CODE (ctx
->variant_part_offset
) == INTEGER_CST
))
19953 tree off
= bit_position (decl
);
19954 if (ctx
->variant_part_offset
)
19955 off
= bit_from_pos (ctx
->variant_part_offset
, off
);
19956 if (tree_fits_uhwi_p (off
) && get_AT (die
, DW_AT_bit_size
))
19958 remove_AT (die
, DW_AT_byte_size
);
19959 remove_AT (die
, DW_AT_bit_offset
);
19960 add_AT_unsigned (die
, DW_AT_data_bit_offset
, tree_to_uhwi (off
));
19964 if (dwarf_version
> 2)
19966 /* Don't need to output a location expression, just the constant. */
19968 add_AT_int (die
, DW_AT_data_member_location
, offset
);
19970 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
19975 enum dwarf_location_atom op
;
19977 /* The DWARF2 standard says that we should assume that the structure
19978 address is already on the stack, so we can specify a structure
19979 field address by using DW_OP_plus_uconst. */
19980 op
= DW_OP_plus_uconst
;
19981 loc_descr
= new_loc_descr (op
, offset
, 0);
19985 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
19988 /* Writes integer values to dw_vec_const array. */
19991 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
19995 *dest
++ = val
& 0xff;
20001 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
20003 static HOST_WIDE_INT
20004 extract_int (const unsigned char *src
, unsigned int size
)
20006 HOST_WIDE_INT val
= 0;
20012 val
|= *--src
& 0xff;
20018 /* Writes wide_int values to dw_vec_const array. */
20021 insert_wide_int (const wide_int
&val
, unsigned char *dest
, int elt_size
)
20025 if (elt_size
<= HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
)
20027 insert_int ((HOST_WIDE_INT
) val
.elt (0), elt_size
, dest
);
20031 /* We'd have to extend this code to support odd sizes. */
20032 gcc_assert (elt_size
% (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
) == 0);
20034 int n
= elt_size
/ (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
20036 if (WORDS_BIG_ENDIAN
)
20037 for (i
= n
- 1; i
>= 0; i
--)
20039 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
20040 dest
+= sizeof (HOST_WIDE_INT
);
20043 for (i
= 0; i
< n
; i
++)
20045 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
20046 dest
+= sizeof (HOST_WIDE_INT
);
20050 /* Writes floating point values to dw_vec_const array. */
20053 insert_float (const_rtx rtl
, unsigned char *array
)
20057 scalar_float_mode mode
= as_a
<scalar_float_mode
> (GET_MODE (rtl
));
20059 real_to_target (val
, CONST_DOUBLE_REAL_VALUE (rtl
), mode
);
20061 /* real_to_target puts 32-bit pieces in each long. Pack them. */
20062 if (GET_MODE_SIZE (mode
) < 4)
20064 gcc_assert (GET_MODE_SIZE (mode
) == 2);
20065 insert_int (val
[0], 2, array
);
20069 for (i
= 0; i
< GET_MODE_SIZE (mode
) / 4; i
++)
20071 insert_int (val
[i
], 4, array
);
20077 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
20078 does not have a "location" either in memory or in a register. These
20079 things can arise in GNU C when a constant is passed as an actual parameter
20080 to an inlined function. They can also arise in C++ where declared
20081 constants do not necessarily get memory "homes". */
20084 add_const_value_attribute (dw_die_ref die
, machine_mode mode
, rtx rtl
)
20086 scalar_mode int_mode
;
20088 switch (GET_CODE (rtl
))
20092 HOST_WIDE_INT val
= INTVAL (rtl
);
20095 add_AT_int (die
, DW_AT_const_value
, val
);
20097 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
20101 case CONST_WIDE_INT
:
20102 if (is_int_mode (mode
, &int_mode
)
20103 && (GET_MODE_PRECISION (int_mode
)
20104 & (HOST_BITS_PER_WIDE_INT
- 1)) == 0)
20106 wide_int w
= rtx_mode_t (rtl
, int_mode
);
20107 add_AT_wide (die
, DW_AT_const_value
, w
);
20113 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
20114 floating-point constant. A CONST_DOUBLE is used whenever the
20115 constant requires more than one word in order to be adequately
20117 if (TARGET_SUPPORTS_WIDE_INT
== 0
20118 && !SCALAR_FLOAT_MODE_P (GET_MODE (rtl
)))
20119 add_AT_double (die
, DW_AT_const_value
,
20120 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
20123 scalar_float_mode mode
= as_a
<scalar_float_mode
> (GET_MODE (rtl
));
20124 unsigned int length
= GET_MODE_SIZE (mode
);
20125 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
20126 unsigned int elt_size
= insert_float (rtl
, array
);
20128 add_AT_vec (die
, DW_AT_const_value
, length
/ elt_size
, elt_size
,
20135 unsigned int length
;
20136 if (!CONST_VECTOR_NUNITS (rtl
).is_constant (&length
))
20139 machine_mode mode
= GET_MODE (rtl
);
20140 /* The combination of a length and byte elt_size doesn't extend
20141 naturally to boolean vectors, where several elements are packed
20142 into the same byte. */
20143 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_BOOL
)
20146 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
20147 unsigned char *array
20148 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
20151 machine_mode imode
= GET_MODE_INNER (mode
);
20153 switch (GET_MODE_CLASS (mode
))
20155 case MODE_VECTOR_INT
:
20156 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
20158 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
20159 insert_wide_int (rtx_mode_t (elt
, imode
), p
, elt_size
);
20163 case MODE_VECTOR_FLOAT
:
20164 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
20166 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
20167 insert_float (elt
, p
);
20172 gcc_unreachable ();
20175 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
20180 if (dwarf_version
>= 4 || !dwarf_strict
)
20182 dw_loc_descr_ref loc_result
;
20183 resolve_one_addr (&rtl
);
20185 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
20186 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
20187 add_AT_loc (die
, DW_AT_location
, loc_result
);
20188 vec_safe_push (used_rtx_array
, rtl
);
20194 if (CONSTANT_P (XEXP (rtl
, 0)))
20195 return add_const_value_attribute (die
, mode
, XEXP (rtl
, 0));
20198 if (!const_ok_for_output (rtl
))
20202 if (dwarf_version
>= 4 || !dwarf_strict
)
20207 /* In cases where an inlined instance of an inline function is passed
20208 the address of an `auto' variable (which is local to the caller) we
20209 can get a situation where the DECL_RTL of the artificial local
20210 variable (for the inlining) which acts as a stand-in for the
20211 corresponding formal parameter (of the inline function) will look
20212 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
20213 exactly a compile-time constant expression, but it isn't the address
20214 of the (artificial) local variable either. Rather, it represents the
20215 *value* which the artificial local variable always has during its
20216 lifetime. We currently have no way to represent such quasi-constant
20217 values in Dwarf, so for now we just punt and generate nothing. */
20225 case CONST_POLY_INT
:
20229 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
20230 && MEM_READONLY_P (rtl
)
20231 && GET_MODE (rtl
) == BLKmode
)
20233 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
20239 /* No other kinds of rtx should be possible here. */
20240 gcc_unreachable ();
20245 /* Determine whether the evaluation of EXPR references any variables
20246 or functions which aren't otherwise used (and therefore may not be
20249 reference_to_unused (tree
* tp
, int * walk_subtrees
,
20250 void * data ATTRIBUTE_UNUSED
)
20252 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
20253 *walk_subtrees
= 0;
20255 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
20256 && ! TREE_ASM_WRITTEN (*tp
))
20258 /* ??? The C++ FE emits debug information for using decls, so
20259 putting gcc_unreachable here falls over. See PR31899. For now
20260 be conservative. */
20261 else if (!symtab
->global_info_ready
&& VAR_P (*tp
))
20263 else if (VAR_P (*tp
))
20265 varpool_node
*node
= varpool_node::get (*tp
);
20266 if (!node
|| !node
->definition
)
20269 else if (TREE_CODE (*tp
) == FUNCTION_DECL
20270 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
20272 /* The call graph machinery must have finished analyzing,
20273 optimizing and gimplifying the CU by now.
20274 So if *TP has no call graph node associated
20275 to it, it means *TP will not be emitted. */
20276 if (!symtab
->global_info_ready
|| !cgraph_node::get (*tp
))
20279 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
20285 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
20286 for use in a later add_const_value_attribute call. */
20289 rtl_for_decl_init (tree init
, tree type
)
20291 rtx rtl
= NULL_RTX
;
20295 /* If a variable is initialized with a string constant without embedded
20296 zeros, build CONST_STRING. */
20297 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
20299 tree enttype
= TREE_TYPE (type
);
20300 tree domain
= TYPE_DOMAIN (type
);
20301 scalar_int_mode mode
;
20303 if (is_int_mode (TYPE_MODE (enttype
), &mode
)
20304 && GET_MODE_SIZE (mode
) == 1
20306 && TYPE_MAX_VALUE (domain
)
20307 && TREE_CODE (TYPE_MAX_VALUE (domain
)) == INTEGER_CST
20308 && integer_zerop (TYPE_MIN_VALUE (domain
))
20309 && compare_tree_int (TYPE_MAX_VALUE (domain
),
20310 TREE_STRING_LENGTH (init
) - 1) == 0
20311 && ((size_t) TREE_STRING_LENGTH (init
)
20312 == strlen (TREE_STRING_POINTER (init
)) + 1))
20314 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
20315 ggc_strdup (TREE_STRING_POINTER (init
)));
20316 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
20317 MEM_READONLY_P (rtl
) = 1;
20320 /* Other aggregates, and complex values, could be represented using
20322 else if (AGGREGATE_TYPE_P (type
)
20323 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
20324 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
20325 || TREE_CODE (type
) == COMPLEX_TYPE
)
20327 /* Vectors only work if their mode is supported by the target.
20328 FIXME: generic vectors ought to work too. */
20329 else if (TREE_CODE (type
) == VECTOR_TYPE
20330 && !VECTOR_MODE_P (TYPE_MODE (type
)))
20332 /* If the initializer is something that we know will expand into an
20333 immediate RTL constant, expand it now. We must be careful not to
20334 reference variables which won't be output. */
20335 else if (initializer_constant_valid_p (init
, type
)
20336 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
20338 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
20340 if (TREE_CODE (type
) == VECTOR_TYPE
)
20341 switch (TREE_CODE (init
))
20346 if (TREE_CONSTANT (init
))
20348 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
20349 bool constant_p
= true;
20351 unsigned HOST_WIDE_INT ix
;
20353 /* Even when ctor is constant, it might contain non-*_CST
20354 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
20355 belong into VECTOR_CST nodes. */
20356 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
20357 if (!CONSTANT_CLASS_P (value
))
20359 constant_p
= false;
20365 init
= build_vector_from_ctor (type
, elts
);
20375 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
20377 /* If expand_expr returns a MEM, it wasn't immediate. */
20378 gcc_assert (!rtl
|| !MEM_P (rtl
));
20384 /* Generate RTL for the variable DECL to represent its location. */
20387 rtl_for_decl_location (tree decl
)
20391 /* Here we have to decide where we are going to say the parameter "lives"
20392 (as far as the debugger is concerned). We only have a couple of
20393 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
20395 DECL_RTL normally indicates where the parameter lives during most of the
20396 activation of the function. If optimization is enabled however, this
20397 could be either NULL or else a pseudo-reg. Both of those cases indicate
20398 that the parameter doesn't really live anywhere (as far as the code
20399 generation parts of GCC are concerned) during most of the function's
20400 activation. That will happen (for example) if the parameter is never
20401 referenced within the function.
20403 We could just generate a location descriptor here for all non-NULL
20404 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
20405 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
20406 where DECL_RTL is NULL or is a pseudo-reg.
20408 Note however that we can only get away with using DECL_INCOMING_RTL as
20409 a backup substitute for DECL_RTL in certain limited cases. In cases
20410 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
20411 we can be sure that the parameter was passed using the same type as it is
20412 declared to have within the function, and that its DECL_INCOMING_RTL
20413 points us to a place where a value of that type is passed.
20415 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
20416 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
20417 because in these cases DECL_INCOMING_RTL points us to a value of some
20418 type which is *different* from the type of the parameter itself. Thus,
20419 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
20420 such cases, the debugger would end up (for example) trying to fetch a
20421 `float' from a place which actually contains the first part of a
20422 `double'. That would lead to really incorrect and confusing
20423 output at debug-time.
20425 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
20426 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
20427 are a couple of exceptions however. On little-endian machines we can
20428 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
20429 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
20430 an integral type that is smaller than TREE_TYPE (decl). These cases arise
20431 when (on a little-endian machine) a non-prototyped function has a
20432 parameter declared to be of type `short' or `char'. In such cases,
20433 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
20434 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
20435 passed `int' value. If the debugger then uses that address to fetch
20436 a `short' or a `char' (on a little-endian machine) the result will be
20437 the correct data, so we allow for such exceptional cases below.
20439 Note that our goal here is to describe the place where the given formal
20440 parameter lives during most of the function's activation (i.e. between the
20441 end of the prologue and the start of the epilogue). We'll do that as best
20442 as we can. Note however that if the given formal parameter is modified
20443 sometime during the execution of the function, then a stack backtrace (at
20444 debug-time) will show the function as having been called with the *new*
20445 value rather than the value which was originally passed in. This happens
20446 rarely enough that it is not a major problem, but it *is* a problem, and
20447 I'd like to fix it.
20449 A future version of dwarf2out.c may generate two additional attributes for
20450 any given DW_TAG_formal_parameter DIE which will describe the "passed
20451 type" and the "passed location" for the given formal parameter in addition
20452 to the attributes we now generate to indicate the "declared type" and the
20453 "active location" for each parameter. This additional set of attributes
20454 could be used by debuggers for stack backtraces. Separately, note that
20455 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
20456 This happens (for example) for inlined-instances of inline function formal
20457 parameters which are never referenced. This really shouldn't be
20458 happening. All PARM_DECL nodes should get valid non-NULL
20459 DECL_INCOMING_RTL values. FIXME. */
20461 /* Use DECL_RTL as the "location" unless we find something better. */
20462 rtl
= DECL_RTL_IF_SET (decl
);
20464 /* When generating abstract instances, ignore everything except
20465 constants, symbols living in memory, and symbols living in
20466 fixed registers. */
20467 if (! reload_completed
)
20470 && (CONSTANT_P (rtl
)
20472 && CONSTANT_P (XEXP (rtl
, 0)))
20475 && TREE_STATIC (decl
))))
20477 rtl
= targetm
.delegitimize_address (rtl
);
20482 else if (TREE_CODE (decl
) == PARM_DECL
)
20484 if (rtl
== NULL_RTX
20485 || is_pseudo_reg (rtl
)
20487 && is_pseudo_reg (XEXP (rtl
, 0))
20488 && DECL_INCOMING_RTL (decl
)
20489 && MEM_P (DECL_INCOMING_RTL (decl
))
20490 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
20492 tree declared_type
= TREE_TYPE (decl
);
20493 tree passed_type
= DECL_ARG_TYPE (decl
);
20494 machine_mode dmode
= TYPE_MODE (declared_type
);
20495 machine_mode pmode
= TYPE_MODE (passed_type
);
20497 /* This decl represents a formal parameter which was optimized out.
20498 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
20499 all cases where (rtl == NULL_RTX) just below. */
20500 if (dmode
== pmode
)
20501 rtl
= DECL_INCOMING_RTL (decl
);
20502 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
20503 && SCALAR_INT_MODE_P (dmode
)
20504 && known_le (GET_MODE_SIZE (dmode
), GET_MODE_SIZE (pmode
))
20505 && DECL_INCOMING_RTL (decl
))
20507 rtx inc
= DECL_INCOMING_RTL (decl
);
20510 else if (MEM_P (inc
))
20512 if (BYTES_BIG_ENDIAN
)
20513 rtl
= adjust_address_nv (inc
, dmode
,
20514 GET_MODE_SIZE (pmode
)
20515 - GET_MODE_SIZE (dmode
));
20522 /* If the parm was passed in registers, but lives on the stack, then
20523 make a big endian correction if the mode of the type of the
20524 parameter is not the same as the mode of the rtl. */
20525 /* ??? This is the same series of checks that are made in dbxout.c before
20526 we reach the big endian correction code there. It isn't clear if all
20527 of these checks are necessary here, but keeping them all is the safe
20529 else if (MEM_P (rtl
)
20530 && XEXP (rtl
, 0) != const0_rtx
20531 && ! CONSTANT_P (XEXP (rtl
, 0))
20532 /* Not passed in memory. */
20533 && !MEM_P (DECL_INCOMING_RTL (decl
))
20534 /* Not passed by invisible reference. */
20535 && (!REG_P (XEXP (rtl
, 0))
20536 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
20537 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
20538 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
20539 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
20542 /* Big endian correction check. */
20543 && BYTES_BIG_ENDIAN
20544 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
20545 && known_lt (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))),
20548 machine_mode addr_mode
= get_address_mode (rtl
);
20549 poly_int64 offset
= (UNITS_PER_WORD
20550 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
20552 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
20553 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
20556 else if (VAR_P (decl
)
20559 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
)))
20561 machine_mode addr_mode
= get_address_mode (rtl
);
20562 poly_int64 offset
= byte_lowpart_offset (TYPE_MODE (TREE_TYPE (decl
)),
20565 /* If a variable is declared "register" yet is smaller than
20566 a register, then if we store the variable to memory, it
20567 looks like we're storing a register-sized value, when in
20568 fact we are not. We need to adjust the offset of the
20569 storage location to reflect the actual value's bytes,
20570 else gdb will not be able to display it. */
20571 if (maybe_ne (offset
, 0))
20572 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
20573 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
20576 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
20577 and will have been substituted directly into all expressions that use it.
20578 C does not have such a concept, but C++ and other languages do. */
20579 if (!rtl
&& VAR_P (decl
) && DECL_INITIAL (decl
))
20580 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
20583 rtl
= targetm
.delegitimize_address (rtl
);
20585 /* If we don't look past the constant pool, we risk emitting a
20586 reference to a constant pool entry that isn't referenced from
20587 code, and thus is not emitted. */
20589 rtl
= avoid_constant_pool_reference (rtl
);
20591 /* Try harder to get a rtl. If this symbol ends up not being emitted
20592 in the current CU, resolve_addr will remove the expression referencing
20594 if (rtl
== NULL_RTX
20595 && !(early_dwarf
&& (flag_generate_lto
|| flag_generate_offload
))
20597 && !DECL_EXTERNAL (decl
)
20598 && TREE_STATIC (decl
)
20599 && DECL_NAME (decl
)
20600 && !DECL_HARD_REGISTER (decl
)
20601 && DECL_MODE (decl
) != VOIDmode
)
20603 rtl
= make_decl_rtl_for_debug (decl
);
20605 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
20606 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
20613 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
20614 returned. If so, the decl for the COMMON block is returned, and the
20615 value is the offset into the common block for the symbol. */
20618 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
20620 tree val_expr
, cvar
;
20622 poly_int64 bitsize
, bitpos
;
20624 HOST_WIDE_INT cbitpos
;
20625 int unsignedp
, reversep
, volatilep
= 0;
20627 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
20628 it does not have a value (the offset into the common area), or if it
20629 is thread local (as opposed to global) then it isn't common, and shouldn't
20630 be handled as such. */
20632 || !TREE_STATIC (decl
)
20633 || !DECL_HAS_VALUE_EXPR_P (decl
)
20637 val_expr
= DECL_VALUE_EXPR (decl
);
20638 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
20641 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
, &mode
,
20642 &unsignedp
, &reversep
, &volatilep
);
20644 if (cvar
== NULL_TREE
20646 || DECL_ARTIFICIAL (cvar
)
20647 || !TREE_PUBLIC (cvar
)
20648 /* We don't expect to have to cope with variable offsets,
20649 since at present all static data must have a constant size. */
20650 || !bitpos
.is_constant (&cbitpos
))
20654 if (offset
!= NULL
)
20656 if (!tree_fits_shwi_p (offset
))
20658 *value
= tree_to_shwi (offset
);
20661 *value
+= cbitpos
/ BITS_PER_UNIT
;
20666 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
20667 data attribute for a variable or a parameter. We generate the
20668 DW_AT_const_value attribute only in those cases where the given variable
20669 or parameter does not have a true "location" either in memory or in a
20670 register. This can happen (for example) when a constant is passed as an
20671 actual argument in a call to an inline function. (It's possible that
20672 these things can crop up in other ways also.) Note that one type of
20673 constant value which can be passed into an inlined function is a constant
20674 pointer. This can happen for example if an actual argument in an inlined
20675 function call evaluates to a compile-time constant address.
20677 CACHE_P is true if it is worth caching the location list for DECL,
20678 so that future calls can reuse it rather than regenerate it from scratch.
20679 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
20680 since we will need to refer to them each time the function is inlined. */
20683 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
)
20686 dw_loc_list_ref list
;
20687 var_loc_list
*loc_list
;
20688 cached_dw_loc_list
*cache
;
20693 if (TREE_CODE (decl
) == ERROR_MARK
)
20696 if (get_AT (die
, DW_AT_location
)
20697 || get_AT (die
, DW_AT_const_value
))
20700 gcc_assert (VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
20701 || TREE_CODE (decl
) == RESULT_DECL
);
20703 /* Try to get some constant RTL for this decl, and use that as the value of
20706 rtl
= rtl_for_decl_location (decl
);
20707 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
20708 && add_const_value_attribute (die
, DECL_MODE (decl
), rtl
))
20711 /* See if we have single element location list that is equivalent to
20712 a constant value. That way we are better to use add_const_value_attribute
20713 rather than expanding constant value equivalent. */
20714 loc_list
= lookup_decl_loc (decl
);
20717 && loc_list
->first
->next
== NULL
20718 && NOTE_P (loc_list
->first
->loc
)
20719 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
20720 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
20722 struct var_loc_node
*node
;
20724 node
= loc_list
->first
;
20725 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
20726 if (GET_CODE (rtl
) == EXPR_LIST
)
20727 rtl
= XEXP (rtl
, 0);
20728 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
20729 && add_const_value_attribute (die
, DECL_MODE (decl
), rtl
))
20732 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
20733 list several times. See if we've already cached the contents. */
20735 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
20739 cache
= cached_dw_loc_list_table
->find_with_hash (decl
, DECL_UID (decl
));
20741 list
= cache
->loc_list
;
20745 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2,
20747 /* It is usually worth caching this result if the decl is from
20748 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
20749 if (cache_p
&& list
&& list
->dw_loc_next
)
20751 cached_dw_loc_list
**slot
20752 = cached_dw_loc_list_table
->find_slot_with_hash (decl
,
20755 cache
= ggc_cleared_alloc
<cached_dw_loc_list
> ();
20756 cache
->decl_id
= DECL_UID (decl
);
20757 cache
->loc_list
= list
;
20763 add_AT_location_description (die
, DW_AT_location
, list
);
20766 /* None of that worked, so it must not really have a location;
20767 try adding a constant value attribute from the DECL_INITIAL. */
20768 return tree_add_const_value_attribute_for_decl (die
, decl
);
20771 /* Attach a DW_AT_const_value attribute to DIE. The value of the
20772 attribute is the const value T. */
20775 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
20778 tree type
= TREE_TYPE (t
);
20781 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
20785 gcc_assert (!DECL_P (init
));
20787 if (TREE_CODE (init
) == INTEGER_CST
)
20789 if (tree_fits_uhwi_p (init
))
20791 add_AT_unsigned (die
, DW_AT_const_value
, tree_to_uhwi (init
));
20794 if (tree_fits_shwi_p (init
))
20796 add_AT_int (die
, DW_AT_const_value
, tree_to_shwi (init
));
20800 /* Generate the RTL even if early_dwarf to force mangling of all refered to
20802 rtl
= rtl_for_decl_init (init
, type
);
20803 if (rtl
&& !early_dwarf
)
20804 return add_const_value_attribute (die
, TYPE_MODE (type
), rtl
);
20805 /* If the host and target are sane, try harder. */
20806 if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
20807 && initializer_constant_valid_p (init
, type
))
20809 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
20810 if (size
> 0 && (int) size
== size
)
20812 unsigned char *array
= ggc_cleared_vec_alloc
<unsigned char> (size
);
20814 if (native_encode_initializer (init
, array
, size
) == size
)
20816 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
20825 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
20826 attribute is the const value of T, where T is an integral constant
20827 variable with static storage duration
20828 (so it can't be a PARM_DECL or a RESULT_DECL). */
20831 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
20835 || (!VAR_P (decl
) && TREE_CODE (decl
) != CONST_DECL
)
20836 || (VAR_P (decl
) && !TREE_STATIC (decl
)))
20839 if (TREE_READONLY (decl
)
20840 && ! TREE_THIS_VOLATILE (decl
)
20841 && DECL_INITIAL (decl
))
20846 /* Don't add DW_AT_const_value if abstract origin already has one. */
20847 if (get_AT (var_die
, DW_AT_const_value
))
20850 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
20853 /* Convert the CFI instructions for the current function into a
20854 location list. This is used for DW_AT_frame_base when we targeting
20855 a dwarf2 consumer that does not support the dwarf3
20856 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
20859 static dw_loc_list_ref
20860 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
20864 dw_loc_list_ref list
, *list_tail
;
20866 dw_cfa_location last_cfa
, next_cfa
;
20867 const char *start_label
, *last_label
, *section
;
20868 dw_cfa_location remember
;
20871 gcc_assert (fde
!= NULL
);
20873 section
= secname_for_decl (current_function_decl
);
20877 memset (&next_cfa
, 0, sizeof (next_cfa
));
20878 next_cfa
.reg
= INVALID_REGNUM
;
20879 remember
= next_cfa
;
20881 start_label
= fde
->dw_fde_begin
;
20883 /* ??? Bald assumption that the CIE opcode list does not contain
20884 advance opcodes. */
20885 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
20886 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
20888 last_cfa
= next_cfa
;
20889 last_label
= start_label
;
20891 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
20893 /* If the first partition contained no CFI adjustments, the
20894 CIE opcodes apply to the whole first partition. */
20895 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
20896 fde
->dw_fde_begin
, 0, fde
->dw_fde_end
, 0, section
);
20897 list_tail
=&(*list_tail
)->dw_loc_next
;
20898 start_label
= last_label
= fde
->dw_fde_second_begin
;
20901 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
20903 switch (cfi
->dw_cfi_opc
)
20905 case DW_CFA_set_loc
:
20906 case DW_CFA_advance_loc1
:
20907 case DW_CFA_advance_loc2
:
20908 case DW_CFA_advance_loc4
:
20909 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
20911 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
20912 start_label
, 0, last_label
, 0, section
);
20914 list_tail
= &(*list_tail
)->dw_loc_next
;
20915 last_cfa
= next_cfa
;
20916 start_label
= last_label
;
20918 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
20921 case DW_CFA_advance_loc
:
20922 /* The encoding is complex enough that we should never emit this. */
20923 gcc_unreachable ();
20926 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
20929 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
20931 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
20933 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
20934 start_label
, 0, last_label
, 0, section
);
20936 list_tail
= &(*list_tail
)->dw_loc_next
;
20937 last_cfa
= next_cfa
;
20938 start_label
= last_label
;
20940 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
20941 start_label
, 0, fde
->dw_fde_end
, 0, section
);
20942 list_tail
= &(*list_tail
)->dw_loc_next
;
20943 start_label
= last_label
= fde
->dw_fde_second_begin
;
20947 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
20949 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
20950 start_label
, 0, last_label
, 0, section
);
20951 list_tail
= &(*list_tail
)->dw_loc_next
;
20952 start_label
= last_label
;
20955 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
20957 fde
->dw_fde_second_begin
20958 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
, 0,
20961 maybe_gen_llsym (list
);
20966 /* Compute a displacement from the "steady-state frame pointer" to the
20967 frame base (often the same as the CFA), and store it in
20968 frame_pointer_fb_offset. OFFSET is added to the displacement
20969 before the latter is negated. */
20972 compute_frame_pointer_to_fb_displacement (poly_int64 offset
)
20976 #ifdef FRAME_POINTER_CFA_OFFSET
20977 reg
= frame_pointer_rtx
;
20978 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
20980 reg
= arg_pointer_rtx
;
20981 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
20984 elim
= (ira_use_lra_p
20985 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
20986 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
20987 elim
= strip_offset_and_add (elim
, &offset
);
20989 frame_pointer_fb_offset
= -offset
;
20991 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
20992 in which to eliminate. This is because it's stack pointer isn't
20993 directly accessible as a register within the ISA. To work around
20994 this, assume that while we cannot provide a proper value for
20995 frame_pointer_fb_offset, we won't need one either. We can use
20996 hard frame pointer in debug info even if frame pointer isn't used
20997 since hard frame pointer in debug info is encoded with DW_OP_fbreg
20998 which uses the DW_AT_frame_base attribute, not hard frame pointer
21000 frame_pointer_fb_offset_valid
21001 = (elim
== hard_frame_pointer_rtx
|| elim
== stack_pointer_rtx
);
21004 /* Generate a DW_AT_name attribute given some string value to be included as
21005 the value of the attribute. */
21008 add_name_attribute (dw_die_ref die
, const char *name_string
)
21010 if (name_string
!= NULL
&& *name_string
!= 0)
21012 if (demangle_name_func
)
21013 name_string
= (*demangle_name_func
) (name_string
);
21015 add_AT_string (die
, DW_AT_name
, name_string
);
21019 /* Generate a DW_AT_name attribute given some string value representing a
21020 file or filepath to be included as value of the attribute. */
21022 add_filename_attribute (dw_die_ref die
, const char *name_string
)
21024 if (name_string
!= NULL
&& *name_string
!= 0)
21025 add_filepath_AT_string (die
, DW_AT_name
, name_string
);
21028 /* Generate a DW_AT_description attribute given some string value to be included
21029 as the value of the attribute. */
21032 add_desc_attribute (dw_die_ref die
, const char *name_string
)
21034 if (!flag_describe_dies
|| (dwarf_version
< 3 && dwarf_strict
))
21037 if (name_string
== NULL
|| *name_string
== 0)
21040 if (demangle_name_func
)
21041 name_string
= (*demangle_name_func
) (name_string
);
21043 add_AT_string (die
, DW_AT_description
, name_string
);
21046 /* Generate a DW_AT_description attribute given some decl to be included
21047 as the value of the attribute. */
21050 add_desc_attribute (dw_die_ref die
, tree decl
)
21054 if (!flag_describe_dies
|| (dwarf_version
< 3 && dwarf_strict
))
21057 if (decl
== NULL_TREE
|| !DECL_P (decl
))
21059 decl_name
= DECL_NAME (decl
);
21061 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
21063 const char *name
= dwarf2_name (decl
, 0);
21064 add_desc_attribute (die
, name
? name
: IDENTIFIER_POINTER (decl_name
));
21068 char *desc
= print_generic_expr_to_str (decl
);
21069 add_desc_attribute (die
, desc
);
21074 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
21075 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
21076 of TYPE accordingly.
21078 ??? This is a temporary measure until after we're able to generate
21079 regular DWARF for the complex Ada type system. */
21082 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
21083 dw_die_ref context_die
)
21086 dw_die_ref dtype_die
;
21088 if (!lang_hooks
.types
.descriptive_type
)
21091 dtype
= lang_hooks
.types
.descriptive_type (type
);
21095 dtype_die
= lookup_type_die (dtype
);
21098 gen_type_die (dtype
, context_die
);
21099 dtype_die
= lookup_type_die (dtype
);
21100 gcc_assert (dtype_die
);
21103 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
21106 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
21108 static const char *
21109 comp_dir_string (void)
21112 char *wd_plus_sep
= NULL
;
21113 static const char *cached_wd
= NULL
;
21115 if (cached_wd
!= NULL
)
21118 wd
= get_src_pwd ();
21122 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
21124 size_t wdlen
= strlen (wd
);
21125 wd_plus_sep
= XNEWVEC (char, wdlen
+ 2);
21126 strcpy (wd_plus_sep
, wd
);
21127 wd_plus_sep
[wdlen
] = DIR_SEPARATOR
;
21128 wd_plus_sep
[wdlen
+ 1] = 0;
21132 cached_wd
= remap_debug_filename (wd
);
21134 /* remap_debug_filename can just pass through wd or return a new gc string.
21135 These two types can't be both stored in a GTY(())-tagged string, but since
21136 the cached value lives forever just copy it if needed. */
21137 if (cached_wd
!= wd
)
21139 cached_wd
= xstrdup (cached_wd
);
21140 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
&& wd_plus_sep
!= NULL
)
21141 free (wd_plus_sep
);
21147 /* Generate a DW_AT_comp_dir attribute for DIE. */
21150 add_comp_dir_attribute (dw_die_ref die
)
21152 const char * wd
= comp_dir_string ();
21154 add_filepath_AT_string (die
, DW_AT_comp_dir
, wd
);
21157 /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
21158 pointer computation, ...), output a representation for that bound according
21159 to the accepted FORMS (see enum dw_scalar_form) and add it to DIE. See
21160 loc_list_from_tree for the meaning of CONTEXT. */
21163 add_scalar_info (dw_die_ref die
, enum dwarf_attribute attr
, tree value
,
21164 int forms
, struct loc_descr_context
*context
)
21166 dw_die_ref context_die
, decl_die
= NULL
;
21167 dw_loc_list_ref list
;
21168 bool strip_conversions
= true;
21169 bool placeholder_seen
= false;
21171 while (strip_conversions
)
21172 switch (TREE_CODE (value
))
21179 case VIEW_CONVERT_EXPR
:
21180 value
= TREE_OPERAND (value
, 0);
21184 strip_conversions
= false;
21188 /* If possible and permitted, output the attribute as a constant. */
21189 if ((forms
& dw_scalar_form_constant
) != 0
21190 && TREE_CODE (value
) == INTEGER_CST
)
21192 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (value
));
21194 /* If HOST_WIDE_INT is big enough then represent the bound as
21195 a constant value. We need to choose a form based on
21196 whether the type is signed or unsigned. We cannot just
21197 call add_AT_unsigned if the value itself is positive
21198 (add_AT_unsigned might add the unsigned value encoded as
21199 DW_FORM_data[1248]). Some DWARF consumers will lookup the
21200 bounds type and then sign extend any unsigned values found
21201 for signed types. This is needed only for
21202 DW_AT_{lower,upper}_bound, since for most other attributes,
21203 consumers will treat DW_FORM_data[1248] as unsigned values,
21204 regardless of the underlying type. */
21205 if (prec
<= HOST_BITS_PER_WIDE_INT
21206 || tree_fits_uhwi_p (value
))
21208 if (TYPE_UNSIGNED (TREE_TYPE (value
)))
21209 add_AT_unsigned (die
, attr
, TREE_INT_CST_LOW (value
));
21211 add_AT_int (die
, attr
, TREE_INT_CST_LOW (value
));
21213 else if (dwarf_version
>= 5
21214 && TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (value
))) == 128)
21215 /* Otherwise represent the bound as an unsigned value with
21216 the precision of its type. The precision and signedness
21217 of the type will be necessary to re-interpret it
21219 add_AT_wide (die
, attr
, wi::to_wide (value
));
21222 rtx v
= immed_wide_int_const (wi::to_wide (value
),
21223 TYPE_MODE (TREE_TYPE (value
)));
21224 dw_loc_descr_ref loc
21225 = loc_descriptor (v
, TYPE_MODE (TREE_TYPE (value
)),
21226 VAR_INIT_STATUS_INITIALIZED
);
21228 add_AT_loc (die
, attr
, loc
);
21233 /* Otherwise, if it's possible and permitted too, output a reference to
21235 if ((forms
& dw_scalar_form_reference
) != 0)
21237 tree decl
= NULL_TREE
;
21239 /* Some type attributes reference an outer type. For instance, the upper
21240 bound of an array may reference an embedding record (this happens in
21242 if (TREE_CODE (value
) == COMPONENT_REF
21243 && TREE_CODE (TREE_OPERAND (value
, 0)) == PLACEHOLDER_EXPR
21244 && TREE_CODE (TREE_OPERAND (value
, 1)) == FIELD_DECL
)
21245 decl
= TREE_OPERAND (value
, 1);
21247 else if (VAR_P (value
)
21248 || TREE_CODE (value
) == PARM_DECL
21249 || TREE_CODE (value
) == RESULT_DECL
)
21252 if (decl
!= NULL_TREE
)
21254 decl_die
= lookup_decl_die (decl
);
21256 /* ??? Can this happen, or should the variable have been bound
21257 first? Probably it can, since I imagine that we try to create
21258 the types of parameters in the order in which they exist in
21259 the list, and won't have created a forward reference to a
21260 later parameter. */
21261 if (decl_die
!= NULL
)
21263 if (get_AT (decl_die
, DW_AT_location
)
21264 || get_AT (decl_die
, DW_AT_data_member_location
)
21265 || get_AT (decl_die
, DW_AT_data_bit_offset
)
21266 || get_AT (decl_die
, DW_AT_const_value
))
21268 add_AT_die_ref (die
, attr
, decl_die
);
21275 /* Last chance: try to create a stack operation procedure to evaluate the
21276 value. Do nothing if even that is not possible or permitted. */
21277 if ((forms
& dw_scalar_form_exprloc
) == 0)
21280 list
= loc_list_from_tree (value
, 2, context
);
21281 if (context
&& context
->placeholder_arg
)
21283 placeholder_seen
= context
->placeholder_seen
;
21284 context
->placeholder_seen
= false;
21286 if (list
== NULL
|| single_element_loc_list_p (list
))
21288 /* If this attribute is not a reference nor constant, it is
21289 a DWARF expression rather than location description. For that
21290 loc_list_from_tree (value, 0, &context) is needed. */
21291 dw_loc_list_ref list2
= loc_list_from_tree (value
, 0, context
);
21292 if (list2
&& single_element_loc_list_p (list2
))
21294 if (placeholder_seen
)
21296 struct dwarf_procedure_info dpi
;
21297 dpi
.fndecl
= NULL_TREE
;
21298 dpi
.args_count
= 1;
21299 if (!resolve_args_picking (list2
->expr
, 1, &dpi
))
21302 add_AT_loc (die
, attr
, list2
->expr
);
21307 /* If that failed to give a single element location list, fall back to
21308 outputting this as a reference... still if permitted. */
21310 || (forms
& dw_scalar_form_reference
) == 0
21311 || placeholder_seen
)
21316 if (current_function_decl
== 0)
21317 context_die
= comp_unit_die ();
21319 context_die
= lookup_decl_die (current_function_decl
);
21321 decl_die
= new_die (DW_TAG_variable
, context_die
, value
);
21322 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
21323 add_type_attribute (decl_die
, TREE_TYPE (value
), TYPE_QUAL_CONST
, false,
21327 add_AT_location_description (decl_die
, DW_AT_location
, list
);
21328 add_AT_die_ref (die
, attr
, decl_die
);
21331 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
21335 lower_bound_default (void)
21337 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
21343 case DW_LANG_C_plus_plus
:
21344 case DW_LANG_C_plus_plus_11
:
21345 case DW_LANG_C_plus_plus_14
:
21347 case DW_LANG_ObjC_plus_plus
:
21349 case DW_LANG_Fortran77
:
21350 case DW_LANG_Fortran90
:
21351 case DW_LANG_Fortran95
:
21352 case DW_LANG_Fortran03
:
21353 case DW_LANG_Fortran08
:
21357 case DW_LANG_Python
:
21358 return dwarf_version
>= 4 ? 0 : -1;
21359 case DW_LANG_Ada95
:
21360 case DW_LANG_Ada83
:
21361 case DW_LANG_Cobol74
:
21362 case DW_LANG_Cobol85
:
21363 case DW_LANG_Modula2
:
21365 return dwarf_version
>= 4 ? 1 : -1;
21371 /* Given a tree node describing an array bound (either lower or upper) output
21372 a representation for that bound. */
21375 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
,
21376 tree bound
, struct loc_descr_context
*context
)
21381 switch (TREE_CODE (bound
))
21383 /* Strip all conversions. */
21385 case VIEW_CONVERT_EXPR
:
21386 bound
= TREE_OPERAND (bound
, 0);
21389 /* All fixed-bounds are represented by INTEGER_CST nodes. Lower bounds
21390 are even omitted when they are the default. */
21392 /* If the value for this bound is the default one, we can even omit the
21394 if (bound_attr
== DW_AT_lower_bound
21395 && tree_fits_shwi_p (bound
)
21396 && (dflt
= lower_bound_default ()) != -1
21397 && tree_to_shwi (bound
) == dflt
)
21403 /* Let GNAT encodings do the magic for self-referential bounds. */
21405 && gnat_encodings
== DWARF_GNAT_ENCODINGS_ALL
21406 && contains_placeholder_p (bound
))
21409 add_scalar_info (subrange_die
, bound_attr
, bound
,
21410 dw_scalar_form_constant
21411 | dw_scalar_form_exprloc
21412 | dw_scalar_form_reference
,
21418 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
21419 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
21421 This function reuses previously set type and bound information if
21425 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
21427 dw_die_ref child
= type_die
->die_child
;
21428 struct array_descr_info info
;
21429 int dimension_number
;
21431 if (lang_hooks
.types
.get_array_descr_info
)
21433 memset (&info
, 0, sizeof (info
));
21434 if (lang_hooks
.types
.get_array_descr_info (type
, &info
))
21435 /* Fortran sometimes emits array types with no dimension. */
21436 gcc_assert (info
.ndimensions
>= 0
21437 && info
.ndimensions
21438 <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN
);
21441 info
.ndimensions
= 0;
21443 for (dimension_number
= 0;
21444 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
21445 type
= TREE_TYPE (type
), dimension_number
++)
21447 tree domain
= TYPE_DOMAIN (type
);
21449 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
21452 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
21453 and (in GNU C only) variable bounds. Handle all three forms
21456 /* Find and reuse a previously generated DW_TAG_subrange_type if
21459 For multi-dimensional arrays, as we iterate through the
21460 various dimensions in the enclosing for loop above, we also
21461 iterate through the DIE children and pick at each
21462 DW_TAG_subrange_type previously generated (if available).
21463 Each child DW_TAG_subrange_type DIE describes the range of
21464 the current dimension. At this point we should have as many
21465 DW_TAG_subrange_type's as we have dimensions in the
21467 dw_die_ref subrange_die
= NULL
;
21471 child
= child
->die_sib
;
21472 if (child
->die_tag
== DW_TAG_subrange_type
)
21473 subrange_die
= child
;
21474 if (child
== type_die
->die_child
)
21476 /* If we wrapped around, stop looking next time. */
21480 if (child
->die_tag
== DW_TAG_subrange_type
)
21484 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
21488 /* We have an array type with specified bounds. */
21489 tree lower
= TYPE_MIN_VALUE (domain
);
21490 tree upper
= TYPE_MAX_VALUE (domain
);
21491 tree index_type
= TREE_TYPE (domain
);
21493 if (dimension_number
<= info
.ndimensions
- 1)
21495 lower
= info
.dimen
[dimension_number
].lower_bound
;
21496 upper
= info
.dimen
[dimension_number
].upper_bound
;
21497 index_type
= info
.dimen
[dimension_number
].bounds_type
;
21500 /* Define the index type. */
21501 if (index_type
&& !get_AT (subrange_die
, DW_AT_type
))
21502 add_type_attribute (subrange_die
, index_type
, TYPE_UNQUALIFIED
,
21505 /* ??? If upper is NULL, the array has unspecified length,
21506 but it does have a lower bound. This happens with Fortran
21508 Since the debugger is definitely going to need to know N
21509 to produce useful results, go ahead and output the lower
21510 bound solo, and hope the debugger can cope. */
21512 if (lower
&& !get_AT (subrange_die
, DW_AT_lower_bound
))
21513 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
, NULL
);
21515 if (!get_AT (subrange_die
, DW_AT_upper_bound
)
21516 && !get_AT (subrange_die
, DW_AT_count
))
21519 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
, NULL
);
21520 else if ((is_c () || is_cxx ()) && COMPLETE_TYPE_P (type
))
21521 /* Zero-length array. */
21522 add_bound_info (subrange_die
, DW_AT_count
,
21523 build_int_cst (TREE_TYPE (lower
), 0), NULL
);
21527 /* Otherwise we have an array type with an unspecified length. The
21528 DWARF-2 spec does not say how to handle this; let's just leave out the
21533 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
21536 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
21538 dw_die_ref decl_die
;
21539 HOST_WIDE_INT size
;
21541 switch (TREE_CODE (tree_node
))
21546 case ENUMERAL_TYPE
:
21549 case QUAL_UNION_TYPE
:
21550 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
21551 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
21553 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
21556 size
= int_size_in_bytes (tree_node
);
21559 /* For a data member of a struct or union, the DW_AT_byte_size is
21560 generally given as the number of bytes normally allocated for an
21561 object of the *declared* type of the member itself. This is true
21562 even for bit-fields. */
21563 size
= int_size_in_bytes (field_type (tree_node
));
21566 gcc_unreachable ();
21569 /* Note that `size' might be -1 when we get to this point. If it is, that
21570 indicates that the byte size of the entity in question is variable. */
21572 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
21574 /* Support for dynamically-sized objects was introduced in DWARF3. */
21575 else if (TYPE_P (tree_node
)
21576 && (dwarf_version
>= 3 || !dwarf_strict
)
21577 && gnat_encodings
!= DWARF_GNAT_ENCODINGS_ALL
)
21579 struct loc_descr_context ctx
= {
21580 const_cast<tree
> (tree_node
), /* context_type */
21581 NULL_TREE
, /* base_decl */
21583 false, /* placeholder_arg */
21584 false, /* placeholder_seen */
21585 false /* strict_signedness */
21588 tree tree_size
= TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (tree_node
));
21589 add_scalar_info (die
, DW_AT_byte_size
, tree_size
,
21590 dw_scalar_form_constant
21591 | dw_scalar_form_exprloc
21592 | dw_scalar_form_reference
,
21597 /* Add a DW_AT_alignment attribute to DIE with TREE_NODE's non-default
21601 add_alignment_attribute (dw_die_ref die
, tree tree_node
)
21603 if (dwarf_version
< 5 && dwarf_strict
)
21608 if (DECL_P (tree_node
))
21610 if (!DECL_USER_ALIGN (tree_node
))
21613 align
= DECL_ALIGN_UNIT (tree_node
);
21615 else if (TYPE_P (tree_node
))
21617 if (!TYPE_USER_ALIGN (tree_node
))
21620 align
= TYPE_ALIGN_UNIT (tree_node
);
21623 gcc_unreachable ();
21625 add_AT_unsigned (die
, DW_AT_alignment
, align
);
21628 /* For a FIELD_DECL node which represents a bit-field, output an attribute
21629 which specifies the distance in bits from the highest order bit of the
21630 "containing object" for the bit-field to the highest order bit of the
21633 For any given bit-field, the "containing object" is a hypothetical object
21634 (of some integral or enum type) within which the given bit-field lives. The
21635 type of this hypothetical "containing object" is always the same as the
21636 declared type of the individual bit-field itself. The determination of the
21637 exact location of the "containing object" for a bit-field is rather
21638 complicated. It's handled by the `field_byte_offset' function (above).
21640 Note that it is the size (in bytes) of the hypothetical "containing object"
21641 which will be given in the DW_AT_byte_size attribute for this bit-field.
21642 (See `byte_size_attribute' above). */
21645 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
21647 HOST_WIDE_INT object_offset_in_bytes
;
21648 tree original_type
= DECL_BIT_FIELD_TYPE (decl
);
21649 HOST_WIDE_INT bitpos_int
;
21650 HOST_WIDE_INT highest_order_object_bit_offset
;
21651 HOST_WIDE_INT highest_order_field_bit_offset
;
21652 HOST_WIDE_INT bit_offset
;
21654 /* The containing object is within the DECL_CONTEXT. */
21655 struct vlr_context ctx
= { DECL_CONTEXT (decl
), NULL_TREE
};
21657 field_byte_offset (decl
, &ctx
, &object_offset_in_bytes
);
21659 /* Must be a field and a bit field. */
21660 gcc_assert (original_type
&& TREE_CODE (decl
) == FIELD_DECL
);
21662 /* We can't yet handle bit-fields whose offsets are variable, so if we
21663 encounter such things, just return without generating any attribute
21664 whatsoever. Likewise for variable or too large size. */
21665 if (! tree_fits_shwi_p (bit_position (decl
))
21666 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
21669 bitpos_int
= int_bit_position (decl
);
21671 /* Note that the bit offset is always the distance (in bits) from the
21672 highest-order bit of the "containing object" to the highest-order bit of
21673 the bit-field itself. Since the "high-order end" of any object or field
21674 is different on big-endian and little-endian machines, the computation
21675 below must take account of these differences. */
21676 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
21677 highest_order_field_bit_offset
= bitpos_int
;
21679 if (! BYTES_BIG_ENDIAN
)
21681 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
21682 highest_order_object_bit_offset
+=
21683 simple_type_size_in_bits (original_type
);
21687 = (! BYTES_BIG_ENDIAN
21688 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
21689 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
21691 if (bit_offset
< 0)
21692 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
21694 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
21697 /* For a FIELD_DECL node which represents a bit field, output an attribute
21698 which specifies the length in bits of the given field. */
21701 add_bit_size_attribute (dw_die_ref die
, tree decl
)
21703 /* Must be a field and a bit field. */
21704 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
21705 && DECL_BIT_FIELD_TYPE (decl
));
21707 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
21708 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
21711 /* If the compiled language is ANSI C, then add a 'prototyped'
21712 attribute, if arg types are given for the parameters of a function. */
21715 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
21717 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
21724 if (prototype_p (func_type
))
21725 add_AT_flag (die
, DW_AT_prototyped
, 1);
21732 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
21733 by looking in the type declaration, the object declaration equate table or
21734 the block mapping. */
21737 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
21739 dw_die_ref origin_die
= NULL
;
21741 /* For late LTO debug output we want to refer directly to the abstract
21742 DIE in the early debug rather to the possibly existing concrete
21743 instance and avoid creating that just for this purpose. */
21744 sym_off_pair
*desc
;
21746 && external_die_map
21747 && (desc
= external_die_map
->get (origin
)))
21749 add_AT_external_die_ref (die
, DW_AT_abstract_origin
,
21750 desc
->sym
, desc
->off
);
21754 if (DECL_P (origin
))
21755 origin_die
= lookup_decl_die (origin
);
21756 else if (TYPE_P (origin
))
21757 origin_die
= lookup_type_die (origin
);
21758 else if (TREE_CODE (origin
) == BLOCK
)
21759 origin_die
= lookup_block_die (origin
);
21761 /* XXX: Functions that are never lowered don't always have correct block
21762 trees (in the case of java, they simply have no block tree, in some other
21763 languages). For these functions, there is nothing we can really do to
21764 output correct debug info for inlined functions in all cases. Rather
21765 than die, we'll just produce deficient debug info now, in that we will
21766 have variables without a proper abstract origin. In the future, when all
21767 functions are lowered, we should re-add a gcc_assert (origin_die)
21773 /* Like above, if we already created a concrete instance DIE
21774 do not use that for the abstract origin but the early DIE
21777 && (a
= get_AT (origin_die
, DW_AT_abstract_origin
)))
21778 origin_die
= AT_ref (a
);
21779 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
21783 /* We do not currently support the pure_virtual attribute. */
21786 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
21788 if (DECL_VINDEX (func_decl
))
21790 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
21792 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
21793 add_AT_loc (die
, DW_AT_vtable_elem_location
,
21794 new_loc_descr (DW_OP_constu
,
21795 tree_to_shwi (DECL_VINDEX (func_decl
)),
21798 /* GNU extension: Record what type this method came from originally. */
21799 if (debug_info_level
> DINFO_LEVEL_TERSE
21800 && DECL_CONTEXT (func_decl
))
21801 add_AT_die_ref (die
, DW_AT_containing_type
,
21802 lookup_type_die (DECL_CONTEXT (func_decl
)));
21806 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
21807 given decl. This used to be a vendor extension until after DWARF 4
21808 standardized it. */
21811 add_linkage_attr (dw_die_ref die
, tree decl
)
21813 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
21815 /* Mimic what assemble_name_raw does with a leading '*'. */
21816 if (name
[0] == '*')
21819 if (dwarf_version
>= 4)
21820 add_AT_string (die
, DW_AT_linkage_name
, name
);
21822 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
21825 /* Add source coordinate attributes for the given decl. */
21828 add_src_coords_attributes (dw_die_ref die
, tree decl
)
21830 expanded_location s
;
21832 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
21834 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
21835 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
21836 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
21837 if (debug_column_info
&& s
.column
)
21838 add_AT_unsigned (die
, DW_AT_decl_column
, s
.column
);
21841 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
21844 add_linkage_name_raw (dw_die_ref die
, tree decl
)
21846 /* Defer until we have an assembler name set. */
21847 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
21849 limbo_die_node
*asm_name
;
21851 asm_name
= ggc_cleared_alloc
<limbo_die_node
> ();
21852 asm_name
->die
= die
;
21853 asm_name
->created_for
= decl
;
21854 asm_name
->next
= deferred_asm_name
;
21855 deferred_asm_name
= asm_name
;
21857 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
21858 add_linkage_attr (die
, decl
);
21861 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl if desired. */
21864 add_linkage_name (dw_die_ref die
, tree decl
)
21866 if (debug_info_level
> DINFO_LEVEL_NONE
21867 && VAR_OR_FUNCTION_DECL_P (decl
)
21868 && TREE_PUBLIC (decl
)
21869 && !(VAR_P (decl
) && DECL_REGISTER (decl
))
21870 && die
->die_tag
!= DW_TAG_member
)
21871 add_linkage_name_raw (die
, decl
);
21874 /* Add a DW_AT_name attribute and source coordinate attribute for the
21875 given decl, but only if it actually has a name. */
21878 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
,
21879 bool no_linkage_name
)
21883 decl_name
= DECL_NAME (decl
);
21884 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
21886 const char *name
= dwarf2_name (decl
, 0);
21888 add_name_attribute (die
, name
);
21890 add_desc_attribute (die
, decl
);
21892 if (! DECL_ARTIFICIAL (decl
))
21893 add_src_coords_attributes (die
, decl
);
21895 if (!no_linkage_name
)
21896 add_linkage_name (die
, decl
);
21899 add_desc_attribute (die
, decl
);
21901 #ifdef VMS_DEBUGGING_INFO
21902 /* Get the function's name, as described by its RTL. This may be different
21903 from the DECL_NAME name used in the source file. */
21904 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
21906 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
21907 XEXP (DECL_RTL (decl
), 0), false);
21908 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
21910 #endif /* VMS_DEBUGGING_INFO */
21913 /* Add VALUE as a DW_AT_discr_value attribute to DIE. */
21916 add_discr_value (dw_die_ref die
, dw_discr_value
*value
)
21920 attr
.dw_attr
= DW_AT_discr_value
;
21921 attr
.dw_attr_val
.val_class
= dw_val_class_discr_value
;
21922 attr
.dw_attr_val
.val_entry
= NULL
;
21923 attr
.dw_attr_val
.v
.val_discr_value
.pos
= value
->pos
;
21925 attr
.dw_attr_val
.v
.val_discr_value
.v
.uval
= value
->v
.uval
;
21927 attr
.dw_attr_val
.v
.val_discr_value
.v
.sval
= value
->v
.sval
;
21928 add_dwarf_attr (die
, &attr
);
21931 /* Add DISCR_LIST as a DW_AT_discr_list to DIE. */
21934 add_discr_list (dw_die_ref die
, dw_discr_list_ref discr_list
)
21938 attr
.dw_attr
= DW_AT_discr_list
;
21939 attr
.dw_attr_val
.val_class
= dw_val_class_discr_list
;
21940 attr
.dw_attr_val
.val_entry
= NULL
;
21941 attr
.dw_attr_val
.v
.val_discr_list
= discr_list
;
21942 add_dwarf_attr (die
, &attr
);
21945 static inline dw_discr_list_ref
21946 AT_discr_list (dw_attr_node
*attr
)
21948 return attr
->dw_attr_val
.v
.val_discr_list
;
21951 #ifdef VMS_DEBUGGING_INFO
21952 /* Output the debug main pointer die for VMS */
21955 dwarf2out_vms_debug_main_pointer (void)
21957 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21960 /* Allocate the VMS debug main subprogram die. */
21961 die
= new_die_raw (DW_TAG_subprogram
);
21962 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
21963 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
21964 current_function_funcdef_no
);
21965 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
21967 /* Make it the first child of comp_unit_die (). */
21968 die
->die_parent
= comp_unit_die ();
21969 if (comp_unit_die ()->die_child
)
21971 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
21972 comp_unit_die ()->die_child
->die_sib
= die
;
21976 die
->die_sib
= die
;
21977 comp_unit_die ()->die_child
= die
;
21980 #endif /* VMS_DEBUGGING_INFO */
21982 /* walk_tree helper function for uses_local_type, below. */
21985 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
21988 *walk_subtrees
= 0;
21991 tree name
= TYPE_NAME (*tp
);
21992 if (name
&& DECL_P (name
) && decl_function_context (name
))
21998 /* If TYPE involves a function-local type (including a local typedef to a
21999 non-local type), returns that type; otherwise returns NULL_TREE. */
22002 uses_local_type (tree type
)
22004 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
22008 /* Return the DIE for the scope that immediately contains this type.
22009 Non-named types that do not involve a function-local type get global
22010 scope. Named types nested in namespaces or other types get their
22011 containing scope. All other types (i.e. function-local named types) get
22012 the current active scope. */
22015 scope_die_for (tree t
, dw_die_ref context_die
)
22017 dw_die_ref scope_die
= NULL
;
22018 tree containing_scope
;
22020 /* Non-types always go in the current scope. */
22021 gcc_assert (TYPE_P (t
));
22023 /* Use the scope of the typedef, rather than the scope of the type
22025 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
22026 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
22028 containing_scope
= TYPE_CONTEXT (t
);
22030 /* Use the containing namespace if there is one. */
22031 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
22033 if (context_die
== lookup_decl_die (containing_scope
))
22035 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
22036 context_die
= get_context_die (containing_scope
);
22038 containing_scope
= NULL_TREE
;
22041 /* Ignore function type "scopes" from the C frontend. They mean that
22042 a tagged type is local to a parmlist of a function declarator, but
22043 that isn't useful to DWARF. */
22044 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
22045 containing_scope
= NULL_TREE
;
22047 if (SCOPE_FILE_SCOPE_P (containing_scope
))
22049 /* If T uses a local type keep it local as well, to avoid references
22050 to function-local DIEs from outside the function. */
22051 if (current_function_decl
&& uses_local_type (t
))
22052 scope_die
= context_die
;
22054 scope_die
= comp_unit_die ();
22056 else if (TYPE_P (containing_scope
))
22058 /* For types, we can just look up the appropriate DIE. */
22059 if (debug_info_level
> DINFO_LEVEL_TERSE
)
22060 scope_die
= get_context_die (containing_scope
);
22063 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
22064 if (scope_die
== NULL
)
22065 scope_die
= comp_unit_die ();
22069 scope_die
= context_die
;
22074 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
22077 local_scope_p (dw_die_ref context_die
)
22079 for (; context_die
; context_die
= context_die
->die_parent
)
22080 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
22081 || context_die
->die_tag
== DW_TAG_subprogram
)
22087 /* Returns nonzero if CONTEXT_DIE is a class. */
22090 class_scope_p (dw_die_ref context_die
)
22092 return (context_die
22093 && (context_die
->die_tag
== DW_TAG_structure_type
22094 || context_die
->die_tag
== DW_TAG_class_type
22095 || context_die
->die_tag
== DW_TAG_interface_type
22096 || context_die
->die_tag
== DW_TAG_union_type
));
22099 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
22100 whether or not to treat a DIE in this context as a declaration. */
22103 class_or_namespace_scope_p (dw_die_ref context_die
)
22105 return (class_scope_p (context_die
)
22106 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
22109 /* Many forms of DIEs require a "type description" attribute. This
22110 routine locates the proper "type descriptor" die for the type given
22111 by 'type' plus any additional qualifiers given by 'cv_quals', and
22112 adds a DW_AT_type attribute below the given die. */
22115 add_type_attribute (dw_die_ref object_die
, tree type
, int cv_quals
,
22116 bool reverse
, dw_die_ref context_die
)
22118 enum tree_code code
= TREE_CODE (type
);
22119 dw_die_ref type_die
= NULL
;
22121 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
22124 /* ??? If this type is an unnamed subrange type of an integral, floating-point
22125 or fixed-point type, use the inner type. This is because we have no
22126 support for unnamed types in base_type_die. This can happen if this is
22127 an Ada subrange type. Correct solution is emit a subrange type die. */
22128 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
22129 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
22130 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
22132 if (code
== ERROR_MARK
22133 /* Handle a special case. For functions whose return type is void, we
22134 generate *no* type attribute. (Note that no object may have type
22135 `void', so this only applies to function return types). */
22136 || code
== VOID_TYPE
)
22139 type_die
= modified_type_die (type
,
22140 cv_quals
| TYPE_QUALS (type
),
22144 if (type_die
!= NULL
)
22145 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
22148 /* Given an object die, add the calling convention attribute for the
22149 function call type. */
22151 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
22153 enum dwarf_calling_convention value
= DW_CC_normal
;
22155 value
= ((enum dwarf_calling_convention
)
22156 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
22159 && id_equal (DECL_ASSEMBLER_NAME (decl
), "MAIN__"))
22161 /* DWARF 2 doesn't provide a way to identify a program's source-level
22162 entry point. DW_AT_calling_convention attributes are only meant
22163 to describe functions' calling conventions. However, lacking a
22164 better way to signal the Fortran main program, we used this for
22165 a long time, following existing custom. Now, DWARF 4 has
22166 DW_AT_main_subprogram, which we add below, but some tools still
22167 rely on the old way, which we thus keep. */
22168 value
= DW_CC_program
;
22170 if (dwarf_version
>= 4 || !dwarf_strict
)
22171 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
22174 /* Only add the attribute if the backend requests it, and
22175 is not DW_CC_normal. */
22176 if (value
&& (value
!= DW_CC_normal
))
22177 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
22180 /* Given a tree pointer to a struct, class, union, or enum type node, return
22181 a pointer to the (string) tag name for the given type, or zero if the type
22182 was declared without a tag. */
22184 static const char *
22185 type_tag (const_tree type
)
22187 const char *name
= 0;
22189 if (TYPE_NAME (type
) != 0)
22193 /* Find the IDENTIFIER_NODE for the type name. */
22194 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
22195 && !TYPE_NAMELESS (type
))
22196 t
= TYPE_NAME (type
);
22198 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
22199 a TYPE_DECL node, regardless of whether or not a `typedef' was
22201 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
22202 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
22204 /* We want to be extra verbose. Don't call dwarf_name if
22205 DECL_NAME isn't set. The default hook for decl_printable_name
22206 doesn't like that, and in this context it's correct to return
22207 0, instead of "<anonymous>" or the like. */
22208 if (DECL_NAME (TYPE_NAME (type
))
22209 && !DECL_NAMELESS (TYPE_NAME (type
)))
22210 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
22213 /* Now get the name as a string, or invent one. */
22214 if (!name
&& t
!= 0)
22215 name
= IDENTIFIER_POINTER (t
);
22218 return (name
== 0 || *name
== '\0') ? 0 : name
;
22221 /* Return the type associated with a data member, make a special check
22222 for bit field types. */
22225 member_declared_type (const_tree member
)
22227 return (DECL_BIT_FIELD_TYPE (member
)
22228 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
22231 /* Get the decl's label, as described by its RTL. This may be different
22232 from the DECL_NAME name used in the source file. */
22235 static const char *
22236 decl_start_label (tree decl
)
22239 const char *fnname
;
22241 x
= DECL_RTL (decl
);
22242 gcc_assert (MEM_P (x
));
22245 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
22247 fnname
= XSTR (x
, 0);
22252 /* For variable-length arrays that have been previously generated, but
22253 may be incomplete due to missing subscript info, fill the subscript
22254 info. Return TRUE if this is one of those cases. */
22257 fill_variable_array_bounds (tree type
)
22259 if (TREE_ASM_WRITTEN (type
)
22260 && TREE_CODE (type
) == ARRAY_TYPE
22261 && variably_modified_type_p (type
, NULL
))
22263 dw_die_ref array_die
= lookup_type_die (type
);
22266 add_subscript_info (array_die
, type
, !is_ada ());
22272 /* These routines generate the internal representation of the DIE's for
22273 the compilation unit. Debugging information is collected by walking
22274 the declaration trees passed in from dwarf2out_decl(). */
22277 gen_array_type_die (tree type
, dw_die_ref context_die
)
22279 dw_die_ref array_die
;
22281 /* GNU compilers represent multidimensional array types as sequences of one
22282 dimensional array types whose element types are themselves array types.
22283 We sometimes squish that down to a single array_type DIE with multiple
22284 subscripts in the Dwarf debugging info. The draft Dwarf specification
22285 say that we are allowed to do this kind of compression in C, because
22286 there is no difference between an array of arrays and a multidimensional
22287 array. We don't do this for Ada to remain as close as possible to the
22288 actual representation, which is especially important against the language
22289 flexibilty wrt arrays of variable size. */
22291 bool collapse_nested_arrays
= !is_ada ();
22293 if (fill_variable_array_bounds (type
))
22296 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
22299 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
22300 DW_TAG_string_type doesn't have DW_AT_type attribute). */
22301 if (TREE_CODE (type
) == ARRAY_TYPE
22302 && TYPE_STRING_FLAG (type
)
22304 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
22306 HOST_WIDE_INT size
;
22308 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
22309 add_name_attribute (array_die
, type_tag (type
));
22310 equate_type_number_to_die (type
, array_die
);
22311 size
= int_size_in_bytes (type
);
22313 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
22314 /* ??? We can't annotate types late, but for LTO we may not
22315 generate a location early either (gfortran.dg/save_6.f90). */
22316 else if (! (early_dwarf
&& (flag_generate_lto
|| flag_generate_offload
))
22317 && TYPE_DOMAIN (type
) != NULL_TREE
22318 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
)
22320 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
22321 tree rszdecl
= szdecl
;
22323 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
22324 if (!DECL_P (szdecl
))
22326 if (TREE_CODE (szdecl
) == INDIRECT_REF
22327 && DECL_P (TREE_OPERAND (szdecl
, 0)))
22329 rszdecl
= TREE_OPERAND (szdecl
, 0);
22330 if (int_size_in_bytes (TREE_TYPE (rszdecl
))
22331 != DWARF2_ADDR_SIZE
)
22339 dw_loc_list_ref loc
22340 = loc_list_from_tree (rszdecl
, szdecl
== rszdecl
? 2 : 0,
22344 add_AT_location_description (array_die
, DW_AT_string_length
,
22346 if (size
!= DWARF2_ADDR_SIZE
)
22347 add_AT_unsigned (array_die
, dwarf_version
>= 5
22348 ? DW_AT_string_length_byte_size
22349 : DW_AT_byte_size
, size
);
22356 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
22357 add_name_attribute (array_die
, type_tag (type
));
22358 equate_type_number_to_die (type
, array_die
);
22360 if (TREE_CODE (type
) == VECTOR_TYPE
)
22361 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
22363 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
22365 && TREE_CODE (type
) == ARRAY_TYPE
22366 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
22367 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
22368 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
22371 /* We default the array ordering. Debuggers will probably do the right
22372 things even if DW_AT_ordering is not present. It's not even an issue
22373 until we start to get into multidimensional arrays anyway. If a debugger
22374 is ever caught doing the Wrong Thing for multi-dimensional arrays,
22375 then we'll have to put the DW_AT_ordering attribute back in. (But if
22376 and when we find out that we need to put these in, we will only do so
22377 for multidimensional arrays. */
22378 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
22381 if (TREE_CODE (type
) == VECTOR_TYPE
)
22383 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
22384 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
22385 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
, NULL
);
22386 add_bound_info (subrange_die
, DW_AT_upper_bound
,
22387 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1), NULL
);
22390 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
22392 /* Add representation of the type of the elements of this array type and
22393 emit the corresponding DIE if we haven't done it already. */
22394 element_type
= TREE_TYPE (type
);
22395 if (collapse_nested_arrays
)
22396 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
22398 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
22400 element_type
= TREE_TYPE (element_type
);
22403 add_type_attribute (array_die
, element_type
, TYPE_UNQUALIFIED
,
22404 TREE_CODE (type
) == ARRAY_TYPE
22405 && TYPE_REVERSE_STORAGE_ORDER (type
),
22408 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
22409 if (TYPE_ARTIFICIAL (type
))
22410 add_AT_flag (array_die
, DW_AT_artificial
, 1);
22412 if (get_AT (array_die
, DW_AT_name
))
22413 add_pubtype (type
, array_die
);
22415 add_alignment_attribute (array_die
, type
);
22418 /* This routine generates DIE for array with hidden descriptor, details
22419 are filled into *info by a langhook. */
22422 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
22423 dw_die_ref context_die
)
22425 const dw_die_ref scope_die
= scope_die_for (type
, context_die
);
22426 const dw_die_ref array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
22427 struct loc_descr_context context
= {
22428 type
, /* context_type */
22429 info
->base_decl
, /* base_decl */
22431 false, /* placeholder_arg */
22432 false, /* placeholder_seen */
22433 false /* strict_signedness */
22435 enum dwarf_tag subrange_tag
= DW_TAG_subrange_type
;
22438 add_name_attribute (array_die
, type_tag (type
));
22439 equate_type_number_to_die (type
, array_die
);
22441 if (info
->ndimensions
> 1)
22442 switch (info
->ordering
)
22444 case array_descr_ordering_row_major
:
22445 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
22447 case array_descr_ordering_column_major
:
22448 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
22454 if (dwarf_version
>= 3 || !dwarf_strict
)
22456 if (info
->data_location
)
22457 add_scalar_info (array_die
, DW_AT_data_location
, info
->data_location
,
22458 dw_scalar_form_exprloc
, &context
);
22459 if (info
->associated
)
22460 add_scalar_info (array_die
, DW_AT_associated
, info
->associated
,
22461 dw_scalar_form_constant
22462 | dw_scalar_form_exprloc
22463 | dw_scalar_form_reference
, &context
);
22464 if (info
->allocated
)
22465 add_scalar_info (array_die
, DW_AT_allocated
, info
->allocated
,
22466 dw_scalar_form_constant
22467 | dw_scalar_form_exprloc
22468 | dw_scalar_form_reference
, &context
);
22471 const enum dwarf_attribute attr
22472 = (info
->stride_in_bits
) ? DW_AT_bit_stride
: DW_AT_byte_stride
;
22474 = (info
->stride_in_bits
)
22475 ? dw_scalar_form_constant
22476 : (dw_scalar_form_constant
22477 | dw_scalar_form_exprloc
22478 | dw_scalar_form_reference
);
22480 add_scalar_info (array_die
, attr
, info
->stride
, forms
, &context
);
22483 if (dwarf_version
>= 5)
22487 add_scalar_info (array_die
, DW_AT_rank
, info
->rank
,
22488 dw_scalar_form_constant
22489 | dw_scalar_form_exprloc
, &context
);
22490 subrange_tag
= DW_TAG_generic_subrange
;
22491 context
.placeholder_arg
= true;
22495 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
22497 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
22499 dw_die_ref subrange_die
= new_die (subrange_tag
, array_die
, NULL
);
22501 if (info
->dimen
[dim
].bounds_type
)
22502 add_type_attribute (subrange_die
,
22503 info
->dimen
[dim
].bounds_type
, TYPE_UNQUALIFIED
,
22504 false, context_die
);
22505 if (info
->dimen
[dim
].lower_bound
)
22506 add_bound_info (subrange_die
, DW_AT_lower_bound
,
22507 info
->dimen
[dim
].lower_bound
, &context
);
22508 if (info
->dimen
[dim
].upper_bound
)
22509 add_bound_info (subrange_die
, DW_AT_upper_bound
,
22510 info
->dimen
[dim
].upper_bound
, &context
);
22511 if ((dwarf_version
>= 3 || !dwarf_strict
) && info
->dimen
[dim
].stride
)
22512 add_scalar_info (subrange_die
, DW_AT_byte_stride
,
22513 info
->dimen
[dim
].stride
,
22514 dw_scalar_form_constant
22515 | dw_scalar_form_exprloc
22516 | dw_scalar_form_reference
,
22520 gen_type_die (info
->element_type
, context_die
);
22521 add_type_attribute (array_die
, info
->element_type
, TYPE_UNQUALIFIED
,
22522 TREE_CODE (type
) == ARRAY_TYPE
22523 && TYPE_REVERSE_STORAGE_ORDER (type
),
22526 if (get_AT (array_die
, DW_AT_name
))
22527 add_pubtype (type
, array_die
);
22529 add_alignment_attribute (array_die
, type
);
22534 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
22536 tree origin
= decl_ultimate_origin (decl
);
22537 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
22539 if (origin
!= NULL
)
22540 add_abstract_origin_attribute (decl_die
, origin
);
22543 add_name_and_src_coords_attributes (decl_die
, decl
);
22544 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
22545 TYPE_UNQUALIFIED
, false, context_die
);
22548 if (DECL_ABSTRACT_P (decl
))
22549 equate_decl_number_to_die (decl
, decl_die
);
22551 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
22555 /* Walk through the list of incomplete types again, trying once more to
22556 emit full debugging info for them. */
22559 retry_incomplete_types (void)
22564 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
22565 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
22566 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
22567 vec_safe_truncate (incomplete_types
, 0);
22570 /* Determine what tag to use for a record type. */
22572 static enum dwarf_tag
22573 record_type_tag (tree type
)
22575 if (! lang_hooks
.types
.classify_record
)
22576 return DW_TAG_structure_type
;
22578 switch (lang_hooks
.types
.classify_record (type
))
22580 case RECORD_IS_STRUCT
:
22581 return DW_TAG_structure_type
;
22583 case RECORD_IS_CLASS
:
22584 return DW_TAG_class_type
;
22586 case RECORD_IS_INTERFACE
:
22587 if (dwarf_version
>= 3 || !dwarf_strict
)
22588 return DW_TAG_interface_type
;
22589 return DW_TAG_structure_type
;
22592 gcc_unreachable ();
22596 /* Generate a DIE to represent an enumeration type. Note that these DIEs
22597 include all of the information about the enumeration values also. Each
22598 enumerated type name/value is listed as a child of the enumerated type
22602 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
22604 dw_die_ref type_die
= lookup_type_die (type
);
22605 dw_die_ref orig_type_die
= type_die
;
22607 if (type_die
== NULL
)
22609 type_die
= new_die (DW_TAG_enumeration_type
,
22610 scope_die_for (type
, context_die
), type
);
22611 equate_type_number_to_die (type
, type_die
);
22612 add_name_attribute (type_die
, type_tag (type
));
22613 if ((dwarf_version
>= 4 || !dwarf_strict
)
22614 && ENUM_IS_SCOPED (type
))
22615 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
22616 if (ENUM_IS_OPAQUE (type
) && TYPE_SIZE (type
))
22617 add_AT_flag (type_die
, DW_AT_declaration
, 1);
22619 add_AT_unsigned (type_die
, DW_AT_encoding
,
22620 TYPE_UNSIGNED (type
)
22624 else if (! TYPE_SIZE (type
) || ENUM_IS_OPAQUE (type
))
22627 remove_AT (type_die
, DW_AT_declaration
);
22629 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
22630 given enum type is incomplete, do not generate the DW_AT_byte_size
22631 attribute or the DW_AT_element_list attribute. */
22632 if (TYPE_SIZE (type
))
22636 if (!ENUM_IS_OPAQUE (type
))
22637 TREE_ASM_WRITTEN (type
) = 1;
22638 if (!orig_type_die
|| !get_AT (type_die
, DW_AT_byte_size
))
22639 add_byte_size_attribute (type_die
, type
);
22640 if (!orig_type_die
|| !get_AT (type_die
, DW_AT_alignment
))
22641 add_alignment_attribute (type_die
, type
);
22642 if ((dwarf_version
>= 3 || !dwarf_strict
)
22643 && (!orig_type_die
|| !get_AT (type_die
, DW_AT_type
)))
22645 tree underlying
= lang_hooks
.types
.enum_underlying_base_type (type
);
22646 add_type_attribute (type_die
, underlying
, TYPE_UNQUALIFIED
, false,
22649 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
22651 if (!orig_type_die
|| !get_AT (type_die
, DW_AT_decl_file
))
22652 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
22653 if (!orig_type_die
|| !get_AT (type_die
, DW_AT_accessibility
))
22654 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
22657 /* If the first reference to this type was as the return type of an
22658 inline function, then it may not have a parent. Fix this now. */
22659 if (type_die
->die_parent
== NULL
)
22660 add_child_die (scope_die_for (type
, context_die
), type_die
);
22662 for (link
= TYPE_VALUES (type
);
22663 link
!= NULL
; link
= TREE_CHAIN (link
))
22665 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
22666 tree value
= TREE_VALUE (link
);
22668 if (DECL_P (value
))
22669 equate_decl_number_to_die (value
, enum_die
);
22671 gcc_assert (!ENUM_IS_OPAQUE (type
));
22672 add_name_attribute (enum_die
,
22673 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
22675 if (TREE_CODE (value
) == CONST_DECL
)
22676 value
= DECL_INITIAL (value
);
22678 if (simple_type_size_in_bits (TREE_TYPE (value
))
22679 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
22681 /* For constant forms created by add_AT_unsigned DWARF
22682 consumers (GDB, elfutils, etc.) always zero extend
22683 the value. Only when the actual value is negative
22684 do we need to use add_AT_int to generate a constant
22685 form that can represent negative values. */
22686 HOST_WIDE_INT val
= TREE_INT_CST_LOW (value
);
22687 if (TYPE_UNSIGNED (TREE_TYPE (value
)) || val
>= 0)
22688 add_AT_unsigned (enum_die
, DW_AT_const_value
,
22689 (unsigned HOST_WIDE_INT
) val
);
22691 add_AT_int (enum_die
, DW_AT_const_value
, val
);
22694 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
22695 that here. TODO: This should be re-worked to use correct
22696 signed/unsigned double tags for all cases. */
22697 add_AT_wide (enum_die
, DW_AT_const_value
, wi::to_wide (value
));
22700 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
22701 if (TYPE_ARTIFICIAL (type
)
22702 && (!orig_type_die
|| !get_AT (type_die
, DW_AT_artificial
)))
22703 add_AT_flag (type_die
, DW_AT_artificial
, 1);
22706 add_AT_flag (type_die
, DW_AT_declaration
, 1);
22708 add_pubtype (type
, type_die
);
22713 /* Generate a DIE to represent either a real live formal parameter decl or to
22714 represent just the type of some formal parameter position in some function
22717 Note that this routine is a bit unusual because its argument may be a
22718 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
22719 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
22720 node. If it's the former then this function is being called to output a
22721 DIE to represent a formal parameter object (or some inlining thereof). If
22722 it's the latter, then this function is only being called to output a
22723 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
22724 argument type of some subprogram type.
22725 If EMIT_NAME_P is true, name and source coordinate attributes
22729 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
22730 dw_die_ref context_die
)
22732 tree node_or_origin
= node
? node
: origin
;
22733 tree ultimate_origin
;
22734 dw_die_ref parm_die
= NULL
;
22736 if (DECL_P (node_or_origin
))
22738 parm_die
= lookup_decl_die (node
);
22740 /* If the contexts differ, we may not be talking about the same
22742 ??? When in LTO the DIE parent is the "abstract" copy and the
22743 context_die is the specification "copy". */
22745 && parm_die
->die_parent
!= context_die
22746 && (parm_die
->die_parent
->die_tag
!= DW_TAG_GNU_formal_parameter_pack
22747 || parm_die
->die_parent
->die_parent
!= context_die
)
22750 gcc_assert (!DECL_ABSTRACT_P (node
));
22751 /* This can happen when creating a concrete instance, in
22752 which case we need to create a new DIE that will get
22753 annotated with DW_AT_abstract_origin. */
22757 if (parm_die
&& parm_die
->die_parent
== NULL
)
22759 /* Check that parm_die already has the right attributes that
22760 we would have added below. If any attributes are
22761 missing, fall through to add them. */
22762 if (! DECL_ABSTRACT_P (node_or_origin
)
22763 && !get_AT (parm_die
, DW_AT_location
)
22764 && !get_AT (parm_die
, DW_AT_const_value
))
22765 /* We are missing location info, and are about to add it. */
22769 add_child_die (context_die
, parm_die
);
22775 /* If we have a previously generated DIE, use it, unless this is an
22776 concrete instance (origin != NULL), in which case we need a new
22777 DIE with a corresponding DW_AT_abstract_origin. */
22779 if (parm_die
&& origin
== NULL
)
22780 reusing_die
= true;
22783 parm_die
= new_die (DW_TAG_formal_parameter
, context_die
, node
);
22784 reusing_die
= false;
22787 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
22789 case tcc_declaration
:
22790 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
22791 if (node
|| ultimate_origin
)
22792 origin
= ultimate_origin
;
22797 if (origin
!= NULL
)
22798 add_abstract_origin_attribute (parm_die
, origin
);
22799 else if (emit_name_p
)
22800 add_name_and_src_coords_attributes (parm_die
, node
);
22802 || (! DECL_ABSTRACT_P (node_or_origin
)
22803 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
22804 decl_function_context
22805 (node_or_origin
))))
22807 tree type
= TREE_TYPE (node_or_origin
);
22808 if (decl_by_reference_p (node_or_origin
))
22809 add_type_attribute (parm_die
, TREE_TYPE (type
),
22811 false, context_die
);
22813 add_type_attribute (parm_die
, type
,
22814 decl_quals (node_or_origin
),
22815 false, context_die
);
22817 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
22818 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
22820 if (node
&& node
!= origin
)
22821 equate_decl_number_to_die (node
, parm_die
);
22822 if (! DECL_ABSTRACT_P (node_or_origin
))
22823 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
22829 /* We were called with some kind of a ..._TYPE node. */
22830 add_type_attribute (parm_die
, node_or_origin
, TYPE_UNQUALIFIED
, false,
22835 gcc_unreachable ();
22841 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
22842 children DW_TAG_formal_parameter DIEs representing the arguments of the
22845 PARM_PACK must be a function parameter pack.
22846 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
22847 must point to the subsequent arguments of the function PACK_ARG belongs to.
22848 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
22849 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
22850 following the last one for which a DIE was generated. */
22853 gen_formal_parameter_pack_die (tree parm_pack
,
22855 dw_die_ref subr_die
,
22859 dw_die_ref parm_pack_die
;
22861 gcc_assert (parm_pack
22862 && lang_hooks
.function_parameter_pack_p (parm_pack
)
22865 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
22866 add_src_coords_attributes (parm_pack_die
, parm_pack
);
22868 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
22870 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
22873 gen_formal_parameter_die (arg
, NULL
,
22874 false /* Don't emit name attribute. */,
22879 return parm_pack_die
;
22882 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
22883 at the end of an (ANSI prototyped) formal parameters list. */
22886 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
22888 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
22891 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
22892 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
22893 parameters as specified in some function type specification (except for
22894 those which appear as part of a function *definition*). */
22897 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
22900 tree formal_type
= NULL
;
22901 tree first_parm_type
;
22904 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
22906 arg
= DECL_ARGUMENTS (function_or_method_type
);
22907 function_or_method_type
= TREE_TYPE (function_or_method_type
);
22912 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
22914 /* Make our first pass over the list of formal parameter types and output a
22915 DW_TAG_formal_parameter DIE for each one. */
22916 for (link
= first_parm_type
; link
; )
22918 dw_die_ref parm_die
;
22920 formal_type
= TREE_VALUE (link
);
22921 if (formal_type
== void_type_node
)
22924 /* Output a (nameless) DIE to represent the formal parameter itself. */
22925 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
22926 true /* Emit name attribute. */,
22928 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
22929 && link
== first_parm_type
)
22931 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
22932 if (dwarf_version
>= 3 || !dwarf_strict
)
22933 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
22935 else if (arg
&& DECL_ARTIFICIAL (arg
))
22936 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
22938 link
= TREE_CHAIN (link
);
22940 arg
= DECL_CHAIN (arg
);
22943 /* If this function type has an ellipsis, add a
22944 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
22945 if (formal_type
!= void_type_node
)
22946 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
22948 /* Make our second (and final) pass over the list of formal parameter types
22949 and output DIEs to represent those types (as necessary). */
22950 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
22951 link
&& TREE_VALUE (link
);
22952 link
= TREE_CHAIN (link
))
22953 gen_type_die (TREE_VALUE (link
), context_die
);
22956 /* We want to generate the DIE for TYPE so that we can generate the
22957 die for MEMBER, which has been defined; we will need to refer back
22958 to the member declaration nested within TYPE. If we're trying to
22959 generate minimal debug info for TYPE, processing TYPE won't do the
22960 trick; we need to attach the member declaration by hand. */
22963 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
22965 gen_type_die (type
, context_die
);
22967 /* If we're trying to avoid duplicate debug info, we may not have
22968 emitted the member decl for this function. Emit it now. */
22969 if (TYPE_STUB_DECL (type
)
22970 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
22971 && ! lookup_decl_die (member
))
22973 dw_die_ref type_die
;
22974 gcc_assert (!decl_ultimate_origin (member
));
22976 type_die
= lookup_type_die_strip_naming_typedef (type
);
22977 if (TREE_CODE (member
) == FUNCTION_DECL
)
22978 gen_subprogram_die (member
, type_die
);
22979 else if (TREE_CODE (member
) == FIELD_DECL
)
22981 /* Ignore the nameless fields that are used to skip bits but handle
22982 C++ anonymous unions and structs. */
22983 if (DECL_NAME (member
) != NULL_TREE
22984 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
22985 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
22987 struct vlr_context vlr_ctx
= {
22988 DECL_CONTEXT (member
), /* struct_type */
22989 NULL_TREE
/* variant_part_offset */
22991 gen_type_die (member_declared_type (member
), type_die
);
22992 gen_field_die (member
, &vlr_ctx
, type_die
);
22996 gen_variable_die (member
, NULL_TREE
, type_die
);
23000 /* Forward declare these functions, because they are mutually recursive
23001 with their set_block_* pairing functions. */
23002 static void set_decl_origin_self (tree
);
23004 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
23005 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
23006 that it points to the node itself, thus indicating that the node is its
23007 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
23008 the given node is NULL, recursively descend the decl/block tree which
23009 it is the root of, and for each other ..._DECL or BLOCK node contained
23010 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
23011 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
23012 values to point to themselves. */
23015 set_block_origin_self (tree stmt
)
23017 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
23019 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
23024 for (local_decl
= BLOCK_VARS (stmt
);
23025 local_decl
!= NULL_TREE
;
23026 local_decl
= DECL_CHAIN (local_decl
))
23027 /* Do not recurse on nested functions since the inlining status
23028 of parent and child can be different as per the DWARF spec. */
23029 if (TREE_CODE (local_decl
) != FUNCTION_DECL
23030 && !DECL_EXTERNAL (local_decl
))
23031 set_decl_origin_self (local_decl
);
23037 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
23038 subblock
!= NULL_TREE
;
23039 subblock
= BLOCK_CHAIN (subblock
))
23040 set_block_origin_self (subblock
); /* Recurse. */
23045 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
23046 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
23047 node to so that it points to the node itself, thus indicating that the
23048 node represents its own (abstract) origin. Additionally, if the
23049 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
23050 the decl/block tree of which the given node is the root of, and for
23051 each other ..._DECL or BLOCK node contained therein whose
23052 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
23053 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
23054 point to themselves. */
23057 set_decl_origin_self (tree decl
)
23059 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
23061 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
23062 if (TREE_CODE (decl
) == FUNCTION_DECL
)
23066 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
23067 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
23068 if (DECL_INITIAL (decl
) != NULL_TREE
23069 && DECL_INITIAL (decl
) != error_mark_node
)
23070 set_block_origin_self (DECL_INITIAL (decl
));
23075 /* Mark the early DIE for DECL as the abstract instance. */
23078 dwarf2out_abstract_function (tree decl
)
23080 dw_die_ref old_die
;
23082 /* Make sure we have the actual abstract inline, not a clone. */
23083 decl
= DECL_ORIGIN (decl
);
23085 if (DECL_IGNORED_P (decl
))
23088 /* In LTO we're all set. We already created abstract instances
23089 early and we want to avoid creating a concrete instance of that
23090 if we don't output it. */
23094 old_die
= lookup_decl_die (decl
);
23095 gcc_assert (old_die
!= NULL
);
23096 if (get_AT (old_die
, DW_AT_inline
))
23097 /* We've already generated the abstract instance. */
23100 /* Go ahead and put DW_AT_inline on the DIE. */
23101 if (DECL_DECLARED_INLINE_P (decl
))
23103 if (cgraph_function_possibly_inlined_p (decl
))
23104 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_declared_inlined
);
23106 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
23110 if (cgraph_function_possibly_inlined_p (decl
))
23111 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_inlined
);
23113 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_not_inlined
);
23116 if (DECL_DECLARED_INLINE_P (decl
)
23117 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
23118 add_AT_flag (old_die
, DW_AT_artificial
, 1);
23120 set_decl_origin_self (decl
);
23123 /* Helper function of premark_used_types() which gets called through
23126 Marks the DIE of a given type in *SLOT as perennial, so it never gets
23127 marked as unused by prune_unused_types. */
23130 premark_used_types_helper (tree
const &type
, void *)
23134 die
= lookup_type_die (type
);
23136 die
->die_perennial_p
= 1;
23140 /* Helper function of premark_types_used_by_global_vars which gets called
23141 through htab_traverse.
23143 Marks the DIE of a given type in *SLOT as perennial, so it never gets
23144 marked as unused by prune_unused_types. The DIE of the type is marked
23145 only if the global variable using the type will actually be emitted. */
23148 premark_types_used_by_global_vars_helper (types_used_by_vars_entry
**slot
,
23151 struct types_used_by_vars_entry
*entry
;
23154 entry
= (struct types_used_by_vars_entry
*) *slot
;
23155 gcc_assert (entry
->type
!= NULL
23156 && entry
->var_decl
!= NULL
);
23157 die
= lookup_type_die (entry
->type
);
23160 /* Ask cgraph if the global variable really is to be emitted.
23161 If yes, then we'll keep the DIE of ENTRY->TYPE. */
23162 varpool_node
*node
= varpool_node::get (entry
->var_decl
);
23163 if (node
&& node
->definition
)
23165 die
->die_perennial_p
= 1;
23166 /* Keep the parent DIEs as well. */
23167 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
23168 die
->die_perennial_p
= 1;
23174 /* Mark all members of used_types_hash as perennial. */
23177 premark_used_types (struct function
*fun
)
23179 if (fun
&& fun
->used_types_hash
)
23180 fun
->used_types_hash
->traverse
<void *, premark_used_types_helper
> (NULL
);
23183 /* Mark all members of types_used_by_vars_entry as perennial. */
23186 premark_types_used_by_global_vars (void)
23188 if (types_used_by_vars_hash
)
23189 types_used_by_vars_hash
23190 ->traverse
<void *, premark_types_used_by_global_vars_helper
> (NULL
);
23193 /* Mark all variables used by the symtab as perennial. */
23196 premark_used_variables (void)
23198 /* Mark DIEs in the symtab as used. */
23200 FOR_EACH_VARIABLE (var
)
23202 dw_die_ref die
= lookup_decl_die (var
->decl
);
23204 die
->die_perennial_p
= 1;
23208 /* Generate a DW_TAG_call_site DIE in function DECL under SUBR_DIE
23209 for CA_LOC call arg loc node. */
23212 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
23213 struct call_arg_loc_node
*ca_loc
)
23215 dw_die_ref stmt_die
= NULL
, die
;
23216 tree block
= ca_loc
->block
;
23219 && block
!= DECL_INITIAL (decl
)
23220 && TREE_CODE (block
) == BLOCK
)
23222 stmt_die
= lookup_block_die (block
);
23225 block
= BLOCK_SUPERCONTEXT (block
);
23227 if (stmt_die
== NULL
)
23228 stmt_die
= subr_die
;
23229 die
= new_die (dwarf_TAG (DW_TAG_call_site
), stmt_die
, NULL_TREE
);
23230 add_AT_lbl_id (die
, dwarf_AT (DW_AT_call_return_pc
), ca_loc
->label
);
23231 if (ca_loc
->tail_call_p
)
23232 add_AT_flag (die
, dwarf_AT (DW_AT_call_tail_call
), 1);
23233 if (ca_loc
->symbol_ref
)
23235 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
23237 add_AT_die_ref (die
, dwarf_AT (DW_AT_call_origin
), tdie
);
23239 add_AT_addr (die
, dwarf_AT (DW_AT_call_origin
), ca_loc
->symbol_ref
,
23245 /* Generate a DIE to represent a declared function (either file-scope or
23249 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
23251 tree origin
= decl_ultimate_origin (decl
);
23252 dw_die_ref subr_die
;
23253 dw_die_ref old_die
= lookup_decl_die (decl
);
23254 bool old_die_had_no_children
= false;
23256 /* This function gets called multiple times for different stages of
23257 the debug process. For example, for func() in this code:
23261 void func() { ... }
23264 ...we get called 4 times. Twice in early debug and twice in
23270 1. Once while generating func() within the namespace. This is
23271 the declaration. The declaration bit below is set, as the
23272 context is the namespace.
23274 A new DIE will be generated with DW_AT_declaration set.
23276 2. Once for func() itself. This is the specification. The
23277 declaration bit below is clear as the context is the CU.
23279 We will use the cached DIE from (1) to create a new DIE with
23280 DW_AT_specification pointing to the declaration in (1).
23282 Late debug via rest_of_handle_final()
23283 -------------------------------------
23285 3. Once generating func() within the namespace. This is also the
23286 declaration, as in (1), but this time we will early exit below
23287 as we have a cached DIE and a declaration needs no additional
23288 annotations (no locations), as the source declaration line
23291 4. Once for func() itself. As in (2), this is the specification,
23292 but this time we will re-use the cached DIE, and just annotate
23293 it with the location information that should now be available.
23295 For something without namespaces, but with abstract instances, we
23296 are also called a multiple times:
23301 Base (); // constructor declaration (1)
23304 Base::Base () { } // constructor specification (2)
23309 1. Once for the Base() constructor by virtue of it being a
23310 member of the Base class. This is done via
23311 rest_of_type_compilation.
23313 This is a declaration, so a new DIE will be created with
23316 2. Once for the Base() constructor definition, but this time
23317 while generating the abstract instance of the base
23318 constructor (__base_ctor) which is being generated via early
23319 debug of reachable functions.
23321 Even though we have a cached version of the declaration (1),
23322 we will create a DW_AT_specification of the declaration DIE
23325 3. Once for the __base_ctor itself, but this time, we generate
23326 an DW_AT_abstract_origin version of the DW_AT_specification in
23329 Late debug via rest_of_handle_final
23330 -----------------------------------
23332 4. One final time for the __base_ctor (which will have a cached
23333 DIE with DW_AT_abstract_origin created in (3). This time,
23334 we will just annotate the location information now
23337 int declaration
= (current_function_decl
!= decl
23338 || (!DECL_INITIAL (decl
) && !origin
)
23339 || class_or_namespace_scope_p (context_die
));
23341 /* A declaration that has been previously dumped needs no
23342 additional information. */
23343 if (old_die
&& declaration
)
23346 if (in_lto_p
&& old_die
&& old_die
->die_child
== NULL
)
23347 old_die_had_no_children
= true;
23349 /* Now that the C++ front end lazily declares artificial member fns, we
23350 might need to retrofit the declaration into its class. */
23351 if (!declaration
&& !origin
&& !old_die
23352 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
23353 && !class_or_namespace_scope_p (context_die
)
23354 && debug_info_level
> DINFO_LEVEL_TERSE
)
23355 old_die
= force_decl_die (decl
);
23357 /* A concrete instance, tag a new DIE with DW_AT_abstract_origin. */
23358 if (origin
!= NULL
)
23360 gcc_assert (!declaration
|| local_scope_p (context_die
));
23362 /* Fixup die_parent for the abstract instance of a nested
23363 inline function. */
23364 if (old_die
&& old_die
->die_parent
== NULL
)
23365 add_child_die (context_die
, old_die
);
23367 if (old_die
&& get_AT_ref (old_die
, DW_AT_abstract_origin
))
23369 /* If we have a DW_AT_abstract_origin we have a working
23371 subr_die
= old_die
;
23375 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
23376 add_abstract_origin_attribute (subr_die
, origin
);
23377 /* This is where the actual code for a cloned function is.
23378 Let's emit linkage name attribute for it. This helps
23379 debuggers to e.g, set breakpoints into
23380 constructors/destructors when the user asks "break
23382 add_linkage_name (subr_die
, decl
);
23385 /* A cached copy, possibly from early dwarf generation. Reuse as
23386 much as possible. */
23389 if (!get_AT_flag (old_die
, DW_AT_declaration
)
23390 /* We can have a normal definition following an inline one in the
23391 case of redefinition of GNU C extern inlines.
23392 It seems reasonable to use AT_specification in this case. */
23393 && !get_AT (old_die
, DW_AT_inline
))
23395 /* Detect and ignore this case, where we are trying to output
23396 something we have already output. */
23397 if (get_AT (old_die
, DW_AT_low_pc
)
23398 || get_AT (old_die
, DW_AT_ranges
))
23401 /* If we have no location information, this must be a
23402 partially generated DIE from early dwarf generation.
23403 Fall through and generate it. */
23406 /* If the definition comes from the same place as the declaration,
23407 maybe use the old DIE. We always want the DIE for this function
23408 that has the *_pc attributes to be under comp_unit_die so the
23409 debugger can find it. We also need to do this for abstract
23410 instances of inlines, since the spec requires the out-of-line copy
23411 to have the same parent. For local class methods, this doesn't
23412 apply; we just use the old DIE. */
23413 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
23414 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
23415 if (((is_unit_die (old_die
->die_parent
)
23416 /* This condition fixes the inconsistency/ICE with the
23417 following Fortran test (or some derivative thereof) while
23418 building libgfortran:
23422 logical function funky (FLAG)
23427 || (old_die
->die_parent
23428 && old_die
->die_parent
->die_tag
== DW_TAG_module
)
23429 || local_scope_p (old_die
->die_parent
)
23430 || context_die
== NULL
)
23431 && (DECL_ARTIFICIAL (decl
)
23432 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
23433 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
23434 == (unsigned) s
.line
)
23435 && (!debug_column_info
23437 || (get_AT_unsigned (old_die
, DW_AT_decl_column
)
23438 == (unsigned) s
.column
)))))
23439 /* With LTO if there's an abstract instance for
23440 the old DIE, this is a concrete instance and
23441 thus re-use the DIE. */
23442 || get_AT (old_die
, DW_AT_abstract_origin
))
23444 subr_die
= old_die
;
23446 /* Clear out the declaration attribute, but leave the
23447 parameters so they can be augmented with location
23448 information later. Unless this was a declaration, in
23449 which case, wipe out the nameless parameters and recreate
23450 them further down. */
23451 if (remove_AT (subr_die
, DW_AT_declaration
))
23454 remove_AT (subr_die
, DW_AT_object_pointer
);
23455 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
23458 /* Make a specification pointing to the previously built
23462 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
23463 add_AT_specification (subr_die
, old_die
);
23464 add_pubname (decl
, subr_die
);
23465 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
23466 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
23467 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
23468 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
23469 if (debug_column_info
23471 && (get_AT_unsigned (old_die
, DW_AT_decl_column
)
23472 != (unsigned) s
.column
))
23473 add_AT_unsigned (subr_die
, DW_AT_decl_column
, s
.column
);
23475 /* If the prototype had an 'auto' or 'decltype(auto)' in
23476 the return type, emit the real type on the definition die. */
23477 if (is_cxx () && debug_info_level
> DINFO_LEVEL_TERSE
)
23479 dw_die_ref die
= get_AT_ref (old_die
, DW_AT_type
);
23481 && (die
->die_tag
== DW_TAG_reference_type
23482 || die
->die_tag
== DW_TAG_rvalue_reference_type
23483 || die
->die_tag
== DW_TAG_pointer_type
23484 || die
->die_tag
== DW_TAG_const_type
23485 || die
->die_tag
== DW_TAG_volatile_type
23486 || die
->die_tag
== DW_TAG_restrict_type
23487 || die
->die_tag
== DW_TAG_array_type
23488 || die
->die_tag
== DW_TAG_ptr_to_member_type
23489 || die
->die_tag
== DW_TAG_subroutine_type
))
23490 die
= get_AT_ref (die
, DW_AT_type
);
23491 if (die
== auto_die
|| die
== decltype_auto_die
)
23492 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
23493 TYPE_UNQUALIFIED
, false, context_die
);
23496 /* When we process the method declaration, we haven't seen
23497 the out-of-class defaulted definition yet, so we have to
23499 if ((dwarf_version
>= 5 || ! dwarf_strict
)
23500 && !get_AT (subr_die
, DW_AT_defaulted
))
23503 = lang_hooks
.decls
.decl_dwarf_attribute (decl
,
23505 if (defaulted
!= -1)
23507 /* Other values must have been handled before. */
23508 gcc_assert (defaulted
== DW_DEFAULTED_out_of_class
);
23509 add_AT_unsigned (subr_die
, DW_AT_defaulted
, defaulted
);
23514 /* Create a fresh DIE for anything else. */
23517 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
23519 if (TREE_PUBLIC (decl
))
23520 add_AT_flag (subr_die
, DW_AT_external
, 1);
23522 add_name_and_src_coords_attributes (subr_die
, decl
);
23523 add_pubname (decl
, subr_die
);
23524 if (debug_info_level
> DINFO_LEVEL_TERSE
)
23526 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
23527 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
23528 TYPE_UNQUALIFIED
, false, context_die
);
23531 add_pure_or_virtual_attribute (subr_die
, decl
);
23532 if (DECL_ARTIFICIAL (decl
))
23533 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
23535 if (TREE_THIS_VOLATILE (decl
) && (dwarf_version
>= 5 || !dwarf_strict
))
23536 add_AT_flag (subr_die
, DW_AT_noreturn
, 1);
23538 add_alignment_attribute (subr_die
, decl
);
23540 add_accessibility_attribute (subr_die
, decl
);
23543 /* Unless we have an existing non-declaration DIE, equate the new
23545 if (!old_die
|| is_declaration_die (old_die
))
23546 equate_decl_number_to_die (decl
, subr_die
);
23550 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
23552 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
23554 /* If this is an explicit function declaration then generate
23555 a DW_AT_explicit attribute. */
23556 if ((dwarf_version
>= 3 || !dwarf_strict
)
23557 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
23558 DW_AT_explicit
) == 1)
23559 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
23561 /* If this is a C++11 deleted special function member then generate
23562 a DW_AT_deleted attribute. */
23563 if ((dwarf_version
>= 5 || !dwarf_strict
)
23564 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
23565 DW_AT_deleted
) == 1)
23566 add_AT_flag (subr_die
, DW_AT_deleted
, 1);
23568 /* If this is a C++11 defaulted special function member then
23569 generate a DW_AT_defaulted attribute. */
23570 if (dwarf_version
>= 5 || !dwarf_strict
)
23573 = lang_hooks
.decls
.decl_dwarf_attribute (decl
,
23575 if (defaulted
!= -1)
23576 add_AT_unsigned (subr_die
, DW_AT_defaulted
, defaulted
);
23579 /* If this is a C++11 non-static member function with & ref-qualifier
23580 then generate a DW_AT_reference attribute. */
23581 if ((dwarf_version
>= 5 || !dwarf_strict
)
23582 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
23583 DW_AT_reference
) == 1)
23584 add_AT_flag (subr_die
, DW_AT_reference
, 1);
23586 /* If this is a C++11 non-static member function with &&
23587 ref-qualifier then generate a DW_AT_reference attribute. */
23588 if ((dwarf_version
>= 5 || !dwarf_strict
)
23589 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
23590 DW_AT_rvalue_reference
)
23592 add_AT_flag (subr_die
, DW_AT_rvalue_reference
, 1);
23595 /* For non DECL_EXTERNALs, if range information is available, fill
23596 the DIE with it. */
23597 else if (!DECL_EXTERNAL (decl
) && !early_dwarf
)
23599 HOST_WIDE_INT cfa_fb_offset
;
23601 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
23603 if (!crtl
->has_bb_partition
)
23605 dw_fde_ref fde
= fun
->fde
;
23606 if (fde
->dw_fde_begin
)
23608 /* We have already generated the labels. */
23609 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
23610 fde
->dw_fde_end
, false);
23614 /* Create start/end labels and add the range. */
23615 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
23616 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
23617 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
23618 current_function_funcdef_no
);
23619 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
23620 current_function_funcdef_no
);
23621 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
23625 #if VMS_DEBUGGING_INFO
23626 /* HP OpenVMS Industry Standard 64: DWARF Extensions
23627 Section 2.3 Prologue and Epilogue Attributes:
23628 When a breakpoint is set on entry to a function, it is generally
23629 desirable for execution to be suspended, not on the very first
23630 instruction of the function, but rather at a point after the
23631 function's frame has been set up, after any language defined local
23632 declaration processing has been completed, and before execution of
23633 the first statement of the function begins. Debuggers generally
23634 cannot properly determine where this point is. Similarly for a
23635 breakpoint set on exit from a function. The prologue and epilogue
23636 attributes allow a compiler to communicate the location(s) to use. */
23639 if (fde
->dw_fde_vms_end_prologue
)
23640 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
23641 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
23643 if (fde
->dw_fde_vms_begin_epilogue
)
23644 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
23645 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
23652 /* Generate pubnames entries for the split function code ranges. */
23653 dw_fde_ref fde
= fun
->fde
;
23655 if (fde
->dw_fde_second_begin
)
23657 if (dwarf_version
>= 3 || !dwarf_strict
)
23659 /* We should use ranges for non-contiguous code section
23660 addresses. Use the actual code range for the initial
23661 section, since the HOT/COLD labels might precede an
23662 alignment offset. */
23663 bool range_list_added
= false;
23664 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
23665 fde
->dw_fde_end
, &range_list_added
,
23667 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
23668 fde
->dw_fde_second_end
,
23669 &range_list_added
, false);
23670 if (range_list_added
)
23675 /* There is no real support in DW2 for this .. so we make
23676 a work-around. First, emit the pub name for the segment
23677 containing the function label. Then make and emit a
23678 simplified subprogram DIE for the second segment with the
23679 name pre-fixed by __hot/cold_sect_of_. We use the same
23680 linkage name for the second die so that gdb will find both
23681 sections when given "b foo". */
23682 const char *name
= NULL
;
23683 tree decl_name
= DECL_NAME (decl
);
23684 dw_die_ref seg_die
;
23686 /* Do the 'primary' section. */
23687 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
23688 fde
->dw_fde_end
, false);
23690 /* Build a minimal DIE for the secondary section. */
23691 seg_die
= new_die (DW_TAG_subprogram
,
23692 subr_die
->die_parent
, decl
);
23694 if (TREE_PUBLIC (decl
))
23695 add_AT_flag (seg_die
, DW_AT_external
, 1);
23697 if (decl_name
!= NULL
23698 && IDENTIFIER_POINTER (decl_name
) != NULL
)
23700 name
= dwarf2_name (decl
, 1);
23701 if (! DECL_ARTIFICIAL (decl
))
23702 add_src_coords_attributes (seg_die
, decl
);
23704 add_linkage_name (seg_die
, decl
);
23706 gcc_assert (name
!= NULL
);
23707 add_pure_or_virtual_attribute (seg_die
, decl
);
23708 if (DECL_ARTIFICIAL (decl
))
23709 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
23711 name
= concat ("__second_sect_of_", name
, NULL
);
23712 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
23713 fde
->dw_fde_second_end
, false);
23714 add_name_attribute (seg_die
, name
);
23715 if (want_pubnames ())
23716 add_pubname_string (name
, seg_die
);
23720 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
23724 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
23726 /* We define the "frame base" as the function's CFA. This is more
23727 convenient for several reasons: (1) It's stable across the prologue
23728 and epilogue, which makes it better than just a frame pointer,
23729 (2) With dwarf3, there exists a one-byte encoding that allows us
23730 to reference the .debug_frame data by proxy, but failing that,
23731 (3) We can at least reuse the code inspection and interpretation
23732 code that determines the CFA position at various points in the
23734 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
23736 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
23737 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
23741 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
23742 if (list
->dw_loc_next
)
23743 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
23745 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
23748 /* Compute a displacement from the "steady-state frame pointer" to
23749 the CFA. The former is what all stack slots and argument slots
23750 will reference in the rtl; the latter is what we've told the
23751 debugger about. We'll need to adjust all frame_base references
23752 by this displacement. */
23753 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
23755 if (fun
->static_chain_decl
)
23757 /* DWARF requires here a location expression that computes the
23758 address of the enclosing subprogram's frame base. The machinery
23759 in tree-nested.c is supposed to store this specific address in the
23760 last field of the FRAME record. */
23761 const tree frame_type
23762 = TREE_TYPE (TREE_TYPE (fun
->static_chain_decl
));
23763 const tree fb_decl
= tree_last (TYPE_FIELDS (frame_type
));
23766 = build1 (INDIRECT_REF
, frame_type
, fun
->static_chain_decl
);
23767 fb_expr
= build3 (COMPONENT_REF
, TREE_TYPE (fb_decl
),
23768 fb_expr
, fb_decl
, NULL_TREE
);
23770 add_AT_location_description (subr_die
, DW_AT_static_link
,
23771 loc_list_from_tree (fb_expr
, 0, NULL
));
23774 resolve_variable_values ();
23777 /* Generate child dies for template parameters. */
23778 if (early_dwarf
&& debug_info_level
> DINFO_LEVEL_TERSE
)
23779 gen_generic_params_dies (decl
);
23781 /* Now output descriptions of the arguments for this function. This gets
23782 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
23783 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
23784 `...' at the end of the formal parameter list. In order to find out if
23785 there was a trailing ellipsis or not, we must instead look at the type
23786 associated with the FUNCTION_DECL. This will be a node of type
23787 FUNCTION_TYPE. If the chain of type nodes hanging off of this
23788 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
23789 an ellipsis at the end. */
23791 /* In the case where we are describing a mere function declaration, all we
23792 need to do here (and all we *can* do here) is to describe the *types* of
23793 its formal parameters. */
23794 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
23796 else if (declaration
)
23797 gen_formal_types_die (decl
, subr_die
);
23800 /* Generate DIEs to represent all known formal parameters. */
23801 tree parm
= DECL_ARGUMENTS (decl
);
23802 tree generic_decl
= early_dwarf
23803 ? lang_hooks
.decls
.get_generic_function_decl (decl
) : NULL
;
23804 tree generic_decl_parm
= generic_decl
23805 ? DECL_ARGUMENTS (generic_decl
)
23808 /* Now we want to walk the list of parameters of the function and
23809 emit their relevant DIEs.
23811 We consider the case of DECL being an instance of a generic function
23812 as well as it being a normal function.
23814 If DECL is an instance of a generic function we walk the
23815 parameters of the generic function declaration _and_ the parameters of
23816 DECL itself. This is useful because we want to emit specific DIEs for
23817 function parameter packs and those are declared as part of the
23818 generic function declaration. In that particular case,
23819 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
23820 That DIE has children DIEs representing the set of arguments
23821 of the pack. Note that the set of pack arguments can be empty.
23822 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
23825 Otherwise, we just consider the parameters of DECL. */
23826 while (generic_decl_parm
|| parm
)
23828 if (generic_decl_parm
23829 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
23830 gen_formal_parameter_pack_die (generic_decl_parm
,
23835 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, NULL
, subr_die
);
23838 && parm
== DECL_ARGUMENTS (decl
)
23839 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
23841 && (dwarf_version
>= 3 || !dwarf_strict
))
23842 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
23844 parm
= DECL_CHAIN (parm
);
23847 if (generic_decl_parm
)
23848 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
23851 /* Decide whether we need an unspecified_parameters DIE at the end.
23852 There are 2 more cases to do this for: 1) the ansi ... declaration -
23853 this is detectable when the end of the arg list is not a
23854 void_type_node 2) an unprototyped function declaration (not a
23855 definition). This just means that we have no info about the
23856 parameters at all. */
23859 if (prototype_p (TREE_TYPE (decl
)))
23861 /* This is the prototyped case, check for.... */
23862 if (stdarg_p (TREE_TYPE (decl
)))
23863 gen_unspecified_parameters_die (decl
, subr_die
);
23865 else if (DECL_INITIAL (decl
) == NULL_TREE
)
23866 gen_unspecified_parameters_die (decl
, subr_die
);
23868 else if ((subr_die
!= old_die
|| old_die_had_no_children
)
23869 && prototype_p (TREE_TYPE (decl
))
23870 && stdarg_p (TREE_TYPE (decl
)))
23871 gen_unspecified_parameters_die (decl
, subr_die
);
23874 if (subr_die
!= old_die
)
23875 /* Add the calling convention attribute if requested. */
23876 add_calling_convention_attribute (subr_die
, decl
);
23878 /* Output Dwarf info for all of the stuff within the body of the function
23879 (if it has one - it may be just a declaration).
23881 OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
23882 a function. This BLOCK actually represents the outermost binding contour
23883 for the function, i.e. the contour in which the function's formal
23884 parameters and labels get declared. Curiously, it appears that the front
23885 end doesn't actually put the PARM_DECL nodes for the current function onto
23886 the BLOCK_VARS list for this outer scope, but are strung off of the
23887 DECL_ARGUMENTS list for the function instead.
23889 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
23890 the LABEL_DECL nodes for the function however, and we output DWARF info
23891 for those in decls_for_scope. Just within the `outer_scope' there will be
23892 a BLOCK node representing the function's outermost pair of curly braces,
23893 and any blocks used for the base and member initializers of a C++
23894 constructor function. */
23895 tree outer_scope
= DECL_INITIAL (decl
);
23896 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
23898 int call_site_note_count
= 0;
23899 int tail_call_site_note_count
= 0;
23901 /* Emit a DW_TAG_variable DIE for a named return value. */
23902 if (DECL_NAME (DECL_RESULT (decl
)))
23903 gen_decl_die (DECL_RESULT (decl
), NULL
, NULL
, subr_die
);
23905 /* The first time through decls_for_scope we will generate the
23906 DIEs for the locals. The second time, we fill in the
23908 decls_for_scope (outer_scope
, subr_die
);
23910 if (call_arg_locations
&& (!dwarf_strict
|| dwarf_version
>= 5))
23912 struct call_arg_loc_node
*ca_loc
;
23913 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
23915 dw_die_ref die
= NULL
;
23916 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
23918 tree arg_decl
= NULL_TREE
;
23920 for (arg
= (ca_loc
->call_arg_loc_note
!= NULL_RTX
23921 ? XEXP (ca_loc
->call_arg_loc_note
, 0)
23923 arg
; arg
= next_arg
)
23925 dw_loc_descr_ref reg
, val
;
23926 machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
23927 dw_die_ref cdie
, tdie
= NULL
;
23929 next_arg
= XEXP (arg
, 1);
23930 if (REG_P (XEXP (XEXP (arg
, 0), 0))
23932 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
23933 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
23934 && REGNO (XEXP (XEXP (arg
, 0), 0))
23935 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
23936 next_arg
= XEXP (next_arg
, 1);
23937 if (mode
== VOIDmode
)
23939 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
23940 if (mode
== VOIDmode
)
23941 mode
= GET_MODE (XEXP (arg
, 0));
23943 if (mode
== VOIDmode
|| mode
== BLKmode
)
23945 /* Get dynamic information about call target only if we
23946 have no static information: we cannot generate both
23947 DW_AT_call_origin and DW_AT_call_target
23949 if (ca_loc
->symbol_ref
== NULL_RTX
)
23951 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
23953 tloc
= XEXP (XEXP (arg
, 0), 1);
23956 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
23957 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
23959 tlocc
= XEXP (XEXP (arg
, 0), 1);
23964 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
23965 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
23966 VAR_INIT_STATUS_INITIALIZED
);
23967 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
23969 rtx mem
= XEXP (XEXP (arg
, 0), 0);
23970 reg
= mem_loc_descriptor (XEXP (mem
, 0),
23971 get_address_mode (mem
),
23973 VAR_INIT_STATUS_INITIALIZED
);
23975 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
23976 == DEBUG_PARAMETER_REF
)
23979 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
23980 tdie
= lookup_decl_die (tdecl
);
23988 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
23989 != DEBUG_PARAMETER_REF
)
23991 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
23993 VAR_INIT_STATUS_INITIALIZED
);
23997 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
23998 cdie
= new_die (dwarf_TAG (DW_TAG_call_site_parameter
), die
,
24000 add_desc_attribute (cdie
, arg_decl
);
24002 add_AT_loc (cdie
, DW_AT_location
, reg
);
24003 else if (tdie
!= NULL
)
24004 add_AT_die_ref (cdie
, dwarf_AT (DW_AT_call_parameter
),
24006 add_AT_loc (cdie
, dwarf_AT (DW_AT_call_value
), val
);
24007 if (next_arg
!= XEXP (arg
, 1))
24009 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
24010 if (mode
== VOIDmode
)
24011 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
24012 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
24015 VAR_INIT_STATUS_INITIALIZED
);
24017 add_AT_loc (cdie
, dwarf_AT (DW_AT_call_data_value
),
24022 && (ca_loc
->symbol_ref
|| tloc
))
24023 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
24024 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
24026 dw_loc_descr_ref tval
= NULL
;
24028 if (tloc
!= NULL_RTX
)
24029 tval
= mem_loc_descriptor (tloc
,
24030 GET_MODE (tloc
) == VOIDmode
24031 ? Pmode
: GET_MODE (tloc
),
24033 VAR_INIT_STATUS_INITIALIZED
);
24035 add_AT_loc (die
, dwarf_AT (DW_AT_call_target
), tval
);
24036 else if (tlocc
!= NULL_RTX
)
24038 tval
= mem_loc_descriptor (tlocc
,
24039 GET_MODE (tlocc
) == VOIDmode
24040 ? Pmode
: GET_MODE (tlocc
),
24042 VAR_INIT_STATUS_INITIALIZED
);
24045 dwarf_AT (DW_AT_call_target_clobbered
),
24051 call_site_note_count
++;
24052 if (ca_loc
->tail_call_p
)
24053 tail_call_site_note_count
++;
24057 call_arg_locations
= NULL
;
24058 call_arg_loc_last
= NULL
;
24059 if (tail_call_site_count
>= 0
24060 && tail_call_site_count
== tail_call_site_note_count
24061 && (!dwarf_strict
|| dwarf_version
>= 5))
24063 if (call_site_count
>= 0
24064 && call_site_count
== call_site_note_count
)
24065 add_AT_flag (subr_die
, dwarf_AT (DW_AT_call_all_calls
), 1);
24067 add_AT_flag (subr_die
, dwarf_AT (DW_AT_call_all_tail_calls
), 1);
24069 call_site_count
= -1;
24070 tail_call_site_count
= -1;
24073 /* Mark used types after we have created DIEs for the functions scopes. */
24074 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
24077 /* Returns a hash value for X (which really is a die_struct). */
24080 block_die_hasher::hash (die_struct
*d
)
24082 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
24085 /* Return nonzero if decl_id and die_parent of die_struct X is the same
24086 as decl_id and die_parent of die_struct Y. */
24089 block_die_hasher::equal (die_struct
*x
, die_struct
*y
)
24091 return x
->decl_id
== y
->decl_id
&& x
->die_parent
== y
->die_parent
;
24094 /* Hold information about markers for inlined entry points. */
24095 struct GTY ((for_user
)) inline_entry_data
24097 /* The block that's the inlined_function_outer_scope for an inlined
24101 /* The label at the inlined entry point. */
24102 const char *label_pfx
;
24103 unsigned int label_num
;
24105 /* The view number to be used as the inlined entry point. */
24109 struct inline_entry_data_hasher
: ggc_ptr_hash
<inline_entry_data
>
24111 typedef tree compare_type
;
24112 static inline hashval_t
hash (const inline_entry_data
*);
24113 static inline bool equal (const inline_entry_data
*, const_tree
);
24116 /* Hash table routines for inline_entry_data. */
24119 inline_entry_data_hasher::hash (const inline_entry_data
*data
)
24121 return htab_hash_pointer (data
->block
);
24125 inline_entry_data_hasher::equal (const inline_entry_data
*data
,
24128 return data
->block
== block
;
24131 /* Inlined entry points pending DIE creation in this compilation unit. */
24133 static GTY(()) hash_table
<inline_entry_data_hasher
> *inline_entry_data_table
;
24136 /* Return TRUE if DECL, which may have been previously generated as
24137 OLD_DIE, is a candidate for a DW_AT_specification. DECLARATION is
24138 true if decl (or its origin) is either an extern declaration or a
24139 class/namespace scoped declaration.
24141 The declare_in_namespace support causes us to get two DIEs for one
24142 variable, both of which are declarations. We want to avoid
24143 considering one to be a specification, so we must test for
24144 DECLARATION and DW_AT_declaration. */
24146 decl_will_get_specification_p (dw_die_ref old_die
, tree decl
, bool declaration
)
24148 return (old_die
&& TREE_STATIC (decl
) && !declaration
24149 && get_AT_flag (old_die
, DW_AT_declaration
) == 1);
24152 /* Return true if DECL is a local static. */
24155 local_function_static (tree decl
)
24157 gcc_assert (VAR_P (decl
));
24158 return TREE_STATIC (decl
)
24159 && DECL_CONTEXT (decl
)
24160 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
;
24163 /* Return true iff DECL overrides (presumably completes) the type of
24164 OLD_DIE within CONTEXT_DIE. */
24167 override_type_for_decl_p (tree decl
, dw_die_ref old_die
,
24168 dw_die_ref context_die
)
24170 tree type
= TREE_TYPE (decl
);
24173 if (decl_by_reference_p (decl
))
24175 type
= TREE_TYPE (type
);
24176 cv_quals
= TYPE_UNQUALIFIED
;
24179 cv_quals
= decl_quals (decl
);
24181 dw_die_ref type_die
= modified_type_die (type
,
24182 cv_quals
| TYPE_QUALS (type
),
24186 dw_die_ref old_type_die
= get_AT_ref (old_die
, DW_AT_type
);
24188 return type_die
!= old_type_die
;
24191 /* Generate a DIE to represent a declared data object.
24192 Either DECL or ORIGIN must be non-null. */
24195 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
24197 HOST_WIDE_INT off
= 0;
24199 tree decl_or_origin
= decl
? decl
: origin
;
24200 tree ultimate_origin
;
24201 dw_die_ref var_die
;
24202 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
24203 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
24204 || class_or_namespace_scope_p (context_die
));
24205 bool specialization_p
= false;
24206 bool no_linkage_name
= false;
24208 /* While C++ inline static data members have definitions inside of the
24209 class, force the first DIE to be a declaration, then let gen_member_die
24210 reparent it to the class context and call gen_variable_die again
24211 to create the outside of the class DIE for the definition. */
24215 && DECL_CONTEXT (decl
)
24216 && TYPE_P (DECL_CONTEXT (decl
))
24217 && lang_hooks
.decls
.decl_dwarf_attribute (decl
, DW_AT_inline
) != -1)
24219 declaration
= true;
24220 if (dwarf_version
< 5)
24221 no_linkage_name
= true;
24224 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
24225 if (decl
|| ultimate_origin
)
24226 origin
= ultimate_origin
;
24227 com_decl
= fortran_common (decl_or_origin
, &off
);
24229 /* Symbol in common gets emitted as a child of the common block, in the form
24230 of a data member. */
24233 dw_die_ref com_die
;
24234 dw_loc_list_ref loc
= NULL
;
24235 die_node com_die_arg
;
24237 var_die
= lookup_decl_die (decl_or_origin
);
24240 if (! early_dwarf
&& get_AT (var_die
, DW_AT_location
) == NULL
)
24242 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2, NULL
);
24247 /* Optimize the common case. */
24248 if (single_element_loc_list_p (loc
)
24249 && loc
->expr
->dw_loc_opc
== DW_OP_addr
24250 && loc
->expr
->dw_loc_next
== NULL
24251 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
24254 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
24255 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
24256 = plus_constant (GET_MODE (x
), x
, off
);
24259 loc_list_plus_const (loc
, off
);
24261 add_AT_location_description (var_die
, DW_AT_location
, loc
);
24262 remove_AT (var_die
, DW_AT_declaration
);
24268 if (common_block_die_table
== NULL
)
24269 common_block_die_table
= hash_table
<block_die_hasher
>::create_ggc (10);
24271 com_die_arg
.decl_id
= DECL_UID (com_decl
);
24272 com_die_arg
.die_parent
= context_die
;
24273 com_die
= common_block_die_table
->find (&com_die_arg
);
24275 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
24276 if (com_die
== NULL
)
24279 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
24282 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
24283 add_name_and_src_coords_attributes (com_die
, com_decl
);
24286 add_AT_location_description (com_die
, DW_AT_location
, loc
);
24287 /* Avoid sharing the same loc descriptor between
24288 DW_TAG_common_block and DW_TAG_variable. */
24289 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
24291 else if (DECL_EXTERNAL (decl_or_origin
))
24292 add_AT_flag (com_die
, DW_AT_declaration
, 1);
24293 if (want_pubnames ())
24294 add_pubname_string (cnam
, com_die
); /* ??? needed? */
24295 com_die
->decl_id
= DECL_UID (com_decl
);
24296 slot
= common_block_die_table
->find_slot (com_die
, INSERT
);
24299 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
24301 add_AT_location_description (com_die
, DW_AT_location
, loc
);
24302 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
24303 remove_AT (com_die
, DW_AT_declaration
);
24305 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
24306 add_name_and_src_coords_attributes (var_die
, decl_or_origin
);
24307 add_type_attribute (var_die
, TREE_TYPE (decl_or_origin
),
24308 decl_quals (decl_or_origin
), false,
24310 add_alignment_attribute (var_die
, decl
);
24311 add_AT_flag (var_die
, DW_AT_external
, 1);
24316 /* Optimize the common case. */
24317 if (single_element_loc_list_p (loc
)
24318 && loc
->expr
->dw_loc_opc
== DW_OP_addr
24319 && loc
->expr
->dw_loc_next
== NULL
24320 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
24322 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
24323 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
24324 = plus_constant (GET_MODE (x
), x
, off
);
24327 loc_list_plus_const (loc
, off
);
24329 add_AT_location_description (var_die
, DW_AT_location
, loc
);
24331 else if (DECL_EXTERNAL (decl_or_origin
))
24332 add_AT_flag (var_die
, DW_AT_declaration
, 1);
24334 equate_decl_number_to_die (decl
, var_die
);
24342 /* A declaration that has been previously dumped, needs no
24343 further annotations, since it doesn't need location on
24344 the second pass. */
24347 else if (decl_will_get_specification_p (old_die
, decl
, declaration
)
24348 && !get_AT (old_die
, DW_AT_specification
))
24350 /* Fall-thru so we can make a new variable die along with a
24351 DW_AT_specification. */
24353 else if (origin
&& old_die
->die_parent
!= context_die
)
24355 /* If we will be creating an inlined instance, we need a
24356 new DIE that will get annotated with
24357 DW_AT_abstract_origin. */
24358 gcc_assert (!DECL_ABSTRACT_P (decl
));
24362 /* If a DIE was dumped early, it still needs location info.
24363 Skip to where we fill the location bits. */
24366 /* ??? In LTRANS we cannot annotate early created variably
24367 modified type DIEs without copying them and adjusting all
24368 references to them. Thus we dumped them again. Also add a
24369 reference to them but beware of -g0 compile and -g link
24370 in which case the reference will be already present. */
24371 tree type
= TREE_TYPE (decl_or_origin
);
24373 && ! get_AT (var_die
, DW_AT_type
)
24374 && variably_modified_type_p
24375 (type
, decl_function_context (decl_or_origin
)))
24377 if (decl_by_reference_p (decl_or_origin
))
24378 add_type_attribute (var_die
, TREE_TYPE (type
),
24379 TYPE_UNQUALIFIED
, false, context_die
);
24381 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
),
24382 false, context_die
);
24385 goto gen_variable_die_location
;
24389 /* For static data members, the declaration in the class is supposed
24390 to have DW_TAG_member tag in DWARF{3,4} and we emit it for compatibility
24391 also in DWARF2; the specification should still be DW_TAG_variable
24392 referencing the DW_TAG_member DIE. */
24393 if (declaration
&& class_scope_p (context_die
) && dwarf_version
< 5)
24394 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
24396 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
24398 if (origin
!= NULL
)
24399 add_abstract_origin_attribute (var_die
, origin
);
24401 /* Loop unrolling can create multiple blocks that refer to the same
24402 static variable, so we must test for the DW_AT_declaration flag.
24404 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
24405 copy decls and set the DECL_ABSTRACT_P flag on them instead of
24408 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
24409 else if (decl_will_get_specification_p (old_die
, decl
, declaration
))
24411 /* This is a definition of a C++ class level static. */
24412 add_AT_specification (var_die
, old_die
);
24413 specialization_p
= true;
24414 if (DECL_NAME (decl
))
24416 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
24417 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
24419 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
24420 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
24422 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
24423 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
24425 if (debug_column_info
24427 && (get_AT_unsigned (old_die
, DW_AT_decl_column
)
24428 != (unsigned) s
.column
))
24429 add_AT_unsigned (var_die
, DW_AT_decl_column
, s
.column
);
24431 if (old_die
->die_tag
== DW_TAG_member
)
24432 add_linkage_name (var_die
, decl
);
24436 add_name_and_src_coords_attributes (var_die
, decl
, no_linkage_name
);
24438 if ((origin
== NULL
&& !specialization_p
)
24440 && !DECL_ABSTRACT_P (decl_or_origin
)
24441 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
24442 decl_function_context
24444 || (old_die
&& specialization_p
24445 && override_type_for_decl_p (decl_or_origin
, old_die
, context_die
)))
24447 tree type
= TREE_TYPE (decl_or_origin
);
24449 if (decl_by_reference_p (decl_or_origin
))
24450 add_type_attribute (var_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
24453 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
), false,
24457 if (origin
== NULL
&& !specialization_p
)
24459 if (TREE_PUBLIC (decl
))
24460 add_AT_flag (var_die
, DW_AT_external
, 1);
24462 if (DECL_ARTIFICIAL (decl
))
24463 add_AT_flag (var_die
, DW_AT_artificial
, 1);
24465 add_alignment_attribute (var_die
, decl
);
24467 add_accessibility_attribute (var_die
, decl
);
24471 add_AT_flag (var_die
, DW_AT_declaration
, 1);
24473 if (decl
&& (DECL_ABSTRACT_P (decl
)
24474 || !old_die
|| is_declaration_die (old_die
)))
24475 equate_decl_number_to_die (decl
, var_die
);
24477 gen_variable_die_location
:
24479 && (! DECL_ABSTRACT_P (decl_or_origin
)
24480 /* Local static vars are shared between all clones/inlines,
24481 so emit DW_AT_location on the abstract DIE if DECL_RTL is
24483 || (VAR_P (decl_or_origin
)
24484 && TREE_STATIC (decl_or_origin
)
24485 && DECL_RTL_SET_P (decl_or_origin
))))
24489 add_pubname (decl_or_origin
, var_die
);
24490 /* For global register variables, emit DW_AT_location if possible
24491 already during early_dwarf, as late_global_decl won't be usually
24493 if (DECL_HARD_REGISTER (decl_or_origin
)
24494 && TREE_STATIC (decl_or_origin
)
24495 && !decl_by_reference_p (decl_or_origin
)
24496 && !get_AT (var_die
, DW_AT_location
)
24497 && !get_AT (var_die
, DW_AT_const_value
)
24498 && DECL_RTL_SET_P (decl_or_origin
)
24499 && REG_P (DECL_RTL (decl_or_origin
)))
24501 dw_loc_descr_ref descr
24502 = reg_loc_descriptor (DECL_RTL (decl_or_origin
),
24503 VAR_INIT_STATUS_INITIALIZED
);
24505 add_AT_loc (var_die
, DW_AT_location
, descr
);
24509 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
24513 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
24515 if ((dwarf_version
>= 4 || !dwarf_strict
)
24516 && lang_hooks
.decls
.decl_dwarf_attribute (decl_or_origin
,
24517 DW_AT_const_expr
) == 1
24518 && !get_AT (var_die
, DW_AT_const_expr
)
24519 && !specialization_p
)
24520 add_AT_flag (var_die
, DW_AT_const_expr
, 1);
24524 int inl
= lang_hooks
.decls
.decl_dwarf_attribute (decl_or_origin
,
24527 && !get_AT (var_die
, DW_AT_inline
)
24528 && !specialization_p
)
24529 add_AT_unsigned (var_die
, DW_AT_inline
, inl
);
24533 /* Generate a DIE to represent a named constant. */
24536 gen_const_die (tree decl
, dw_die_ref context_die
)
24538 dw_die_ref const_die
;
24539 tree type
= TREE_TYPE (decl
);
24541 const_die
= lookup_decl_die (decl
);
24545 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
24546 equate_decl_number_to_die (decl
, const_die
);
24547 add_name_and_src_coords_attributes (const_die
, decl
);
24548 add_type_attribute (const_die
, type
, TYPE_QUAL_CONST
, false, context_die
);
24549 if (TREE_PUBLIC (decl
))
24550 add_AT_flag (const_die
, DW_AT_external
, 1);
24551 if (DECL_ARTIFICIAL (decl
))
24552 add_AT_flag (const_die
, DW_AT_artificial
, 1);
24553 tree_add_const_value_attribute_for_decl (const_die
, decl
);
24556 /* Generate a DIE to represent a label identifier. */
24559 gen_label_die (tree decl
, dw_die_ref context_die
)
24561 tree origin
= decl_ultimate_origin (decl
);
24562 dw_die_ref lbl_die
= lookup_decl_die (decl
);
24564 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
24568 lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
24569 equate_decl_number_to_die (decl
, lbl_die
);
24571 if (origin
!= NULL
)
24572 add_abstract_origin_attribute (lbl_die
, origin
);
24574 add_name_and_src_coords_attributes (lbl_die
, decl
);
24577 if (DECL_ABSTRACT_P (decl
))
24578 equate_decl_number_to_die (decl
, lbl_die
);
24579 else if (! early_dwarf
)
24581 insn
= DECL_RTL_IF_SET (decl
);
24583 /* Deleted labels are programmer specified labels which have been
24584 eliminated because of various optimizations. We still emit them
24585 here so that it is possible to put breakpoints on them. */
24589 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
24591 /* When optimization is enabled (via -O) some parts of the compiler
24592 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
24593 represent source-level labels which were explicitly declared by
24594 the user. This really shouldn't be happening though, so catch
24595 it if it ever does happen. */
24596 gcc_assert (!as_a
<rtx_insn
*> (insn
)->deleted ());
24598 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
24599 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
24603 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
24604 && CODE_LABEL_NUMBER (insn
) != -1)
24606 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
24607 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
24612 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
24613 attributes to the DIE for a block STMT, to describe where the inlined
24614 function was called from. This is similar to add_src_coords_attributes. */
24617 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
24619 /* We can end up with BUILTINS_LOCATION here. */
24620 if (RESERVED_LOCATION_P (BLOCK_SOURCE_LOCATION (stmt
)))
24623 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
24625 if (dwarf_version
>= 3 || !dwarf_strict
)
24627 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
24628 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
24629 if (debug_column_info
&& s
.column
)
24630 add_AT_unsigned (die
, DW_AT_call_column
, s
.column
);
24635 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
24636 Add low_pc and high_pc attributes to the DIE for a block STMT. */
24639 add_high_low_attributes (tree stmt
, dw_die_ref die
)
24641 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
24643 if (inline_entry_data
**iedp
24644 = !inline_entry_data_table
? NULL
24645 : inline_entry_data_table
->find_slot_with_hash (stmt
,
24646 htab_hash_pointer (stmt
),
24649 inline_entry_data
*ied
= *iedp
;
24650 gcc_assert (MAY_HAVE_DEBUG_MARKER_INSNS
);
24651 gcc_assert (debug_inline_points
);
24652 gcc_assert (inlined_function_outer_scope_p (stmt
));
24654 ASM_GENERATE_INTERNAL_LABEL (label
, ied
->label_pfx
, ied
->label_num
);
24655 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
24657 if (debug_variable_location_views
&& !ZERO_VIEW_P (ied
->view
)
24660 if (!output_asm_line_debug_info ())
24661 add_AT_unsigned (die
, DW_AT_GNU_entry_view
, ied
->view
);
24664 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", ied
->view
);
24665 /* FIXME: this will resolve to a small number. Could we
24666 possibly emit smaller data? Ideally we'd emit a
24667 uleb128, but that would make the size of DIEs
24668 impossible for the compiler to compute, since it's
24669 the assembler that computes the value of the view
24670 label in this case. Ideally, we'd have a single form
24671 encompassing both the address and the view, and
24672 indirecting them through a table might make things
24673 easier, but even that would be more wasteful,
24674 space-wise, than what we have now. */
24675 add_AT_symview (die
, DW_AT_GNU_entry_view
, label
);
24679 inline_entry_data_table
->clear_slot (iedp
);
24682 if (BLOCK_FRAGMENT_CHAIN (stmt
)
24683 && (dwarf_version
>= 3 || !dwarf_strict
))
24685 tree chain
, superblock
= NULL_TREE
;
24687 dw_attr_node
*attr
= NULL
;
24689 if (!debug_inline_points
&& inlined_function_outer_scope_p (stmt
))
24691 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
24692 BLOCK_NUMBER (stmt
));
24693 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
24696 /* Optimize duplicate .debug_ranges lists or even tails of
24697 lists. If this BLOCK has same ranges as its supercontext,
24698 lookup DW_AT_ranges attribute in the supercontext (and
24699 recursively so), verify that the ranges_table contains the
24700 right values and use it instead of adding a new .debug_range. */
24701 for (chain
= stmt
, pdie
= die
;
24702 BLOCK_SAME_RANGE (chain
);
24703 chain
= BLOCK_SUPERCONTEXT (chain
))
24705 dw_attr_node
*new_attr
;
24707 pdie
= pdie
->die_parent
;
24710 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
24712 new_attr
= get_AT (pdie
, DW_AT_ranges
);
24713 if (new_attr
== NULL
24714 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
24717 superblock
= BLOCK_SUPERCONTEXT (chain
);
24720 && ((*ranges_table
)[attr
->dw_attr_val
.v
.val_offset
].num
24721 == (int)BLOCK_NUMBER (superblock
))
24722 && BLOCK_FRAGMENT_CHAIN (superblock
))
24724 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
;
24725 unsigned long supercnt
= 0, thiscnt
= 0;
24726 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
24727 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
24730 gcc_checking_assert ((*ranges_table
)[off
+ supercnt
].num
24731 == (int)BLOCK_NUMBER (chain
));
24733 gcc_checking_assert ((*ranges_table
)[off
+ supercnt
+ 1].num
== 0);
24734 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
24735 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
24737 gcc_assert (supercnt
>= thiscnt
);
24738 add_AT_range_list (die
, DW_AT_ranges
, off
+ supercnt
- thiscnt
,
24740 note_rnglist_head (off
+ supercnt
- thiscnt
);
24744 unsigned int offset
= add_ranges (stmt
, true);
24745 add_AT_range_list (die
, DW_AT_ranges
, offset
, false);
24746 note_rnglist_head (offset
);
24748 bool prev_in_cold
= BLOCK_IN_COLD_SECTION_P (stmt
);
24749 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
24752 add_ranges (chain
, prev_in_cold
!= BLOCK_IN_COLD_SECTION_P (chain
));
24753 prev_in_cold
= BLOCK_IN_COLD_SECTION_P (chain
);
24754 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
24761 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
24762 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
24763 BLOCK_NUMBER (stmt
));
24764 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
24765 BLOCK_NUMBER (stmt
));
24766 add_AT_low_high_pc (die
, label
, label_high
, false);
24770 /* Generate a DIE for a lexical block. */
24773 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
)
24775 dw_die_ref old_die
= lookup_block_die (stmt
);
24776 dw_die_ref stmt_die
= NULL
;
24779 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
24780 equate_block_to_die (stmt
, stmt_die
);
24783 if (BLOCK_ABSTRACT_ORIGIN (stmt
))
24785 /* If this is an inlined or conrecte instance, create a new lexical
24786 die for anything below to attach DW_AT_abstract_origin to. */
24788 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
24790 tree origin
= block_ultimate_origin (stmt
);
24791 if (origin
!= NULL_TREE
&& (origin
!= stmt
|| old_die
))
24792 add_abstract_origin_attribute (stmt_die
, origin
);
24798 stmt_die
= old_die
;
24800 /* A non abstract block whose blocks have already been reordered
24801 should have the instruction range for this block. If so, set the
24802 high/low attributes. */
24803 if (!early_dwarf
&& TREE_ASM_WRITTEN (stmt
))
24805 gcc_assert (stmt_die
);
24806 add_high_low_attributes (stmt
, stmt_die
);
24809 decls_for_scope (stmt
, stmt_die
);
24812 /* Generate a DIE for an inlined subprogram. */
24815 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
)
24817 tree decl
= block_ultimate_origin (stmt
);
24819 /* Make sure any inlined functions are known to be inlineable. */
24820 gcc_checking_assert (DECL_ABSTRACT_P (decl
)
24821 || cgraph_function_possibly_inlined_p (decl
));
24823 dw_die_ref subr_die
= new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
24825 if (call_arg_locations
|| debug_inline_points
)
24826 equate_block_to_die (stmt
, subr_die
);
24827 add_abstract_origin_attribute (subr_die
, decl
);
24828 if (TREE_ASM_WRITTEN (stmt
))
24829 add_high_low_attributes (stmt
, subr_die
);
24830 add_call_src_coords_attributes (stmt
, subr_die
);
24832 /* The inliner creates an extra BLOCK for the parameter setup,
24833 we want to merge that with the actual outermost BLOCK of the
24834 inlined function to avoid duplicate locals in consumers.
24835 Do that by doing the recursion to subblocks on the single subblock
24837 bool unwrap_one
= false;
24838 if (BLOCK_SUBBLOCKS (stmt
) && !BLOCK_CHAIN (BLOCK_SUBBLOCKS (stmt
)))
24840 tree origin
= block_ultimate_origin (BLOCK_SUBBLOCKS (stmt
));
24842 && TREE_CODE (origin
) == BLOCK
24843 && BLOCK_SUPERCONTEXT (origin
) == decl
)
24846 decls_for_scope (stmt
, subr_die
, !unwrap_one
);
24848 decls_for_scope (BLOCK_SUBBLOCKS (stmt
), subr_die
);
24851 /* Generate a DIE for a field in a record, or structure. CTX is required: see
24852 the comment for VLR_CONTEXT. */
24855 gen_field_die (tree decl
, struct vlr_context
*ctx
, dw_die_ref context_die
)
24857 dw_die_ref decl_die
;
24859 if (TREE_TYPE (decl
) == error_mark_node
)
24862 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
24863 add_name_and_src_coords_attributes (decl_die
, decl
);
24864 add_type_attribute (decl_die
, member_declared_type (decl
), decl_quals (decl
),
24865 TYPE_REVERSE_STORAGE_ORDER (DECL_FIELD_CONTEXT (decl
)),
24868 if (DECL_BIT_FIELD_TYPE (decl
))
24870 add_byte_size_attribute (decl_die
, decl
);
24871 add_bit_size_attribute (decl_die
, decl
);
24872 add_bit_offset_attribute (decl_die
, decl
);
24875 add_alignment_attribute (decl_die
, decl
);
24877 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
24878 add_data_member_location_attribute (decl_die
, decl
, ctx
);
24880 if (DECL_ARTIFICIAL (decl
))
24881 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
24883 add_accessibility_attribute (decl_die
, decl
);
24885 /* Equate decl number to die, so that we can look up this decl later on. */
24886 equate_decl_number_to_die (decl
, decl_die
);
24889 /* Generate a DIE for a pointer to a member type. TYPE can be an
24890 OFFSET_TYPE, for a pointer to data member, or a RECORD_TYPE, for a
24891 pointer to member function. */
24894 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
24896 if (lookup_type_die (type
))
24899 dw_die_ref ptr_die
= new_die (DW_TAG_ptr_to_member_type
,
24900 scope_die_for (type
, context_die
), type
);
24902 equate_type_number_to_die (type
, ptr_die
);
24903 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
24904 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
24905 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
24907 add_alignment_attribute (ptr_die
, type
);
24909 if (TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
24910 && TREE_CODE (TREE_TYPE (type
)) != METHOD_TYPE
)
24912 dw_loc_descr_ref op
= new_loc_descr (DW_OP_plus
, 0, 0);
24913 add_AT_loc (ptr_die
, DW_AT_use_location
, op
);
24917 static char *producer_string
;
24919 /* Given a C and/or C++ language/version string return the "highest".
24920 C++ is assumed to be "higher" than C in this case. Used for merging
24921 LTO translation unit languages. */
24922 static const char *
24923 highest_c_language (const char *lang1
, const char *lang2
)
24925 if (strcmp ("GNU C++23", lang1
) == 0 || strcmp ("GNU C++23", lang2
) == 0)
24926 return "GNU C++23";
24927 if (strcmp ("GNU C++20", lang1
) == 0 || strcmp ("GNU C++20", lang2
) == 0)
24928 return "GNU C++20";
24929 if (strcmp ("GNU C++17", lang1
) == 0 || strcmp ("GNU C++17", lang2
) == 0)
24930 return "GNU C++17";
24931 if (strcmp ("GNU C++14", lang1
) == 0 || strcmp ("GNU C++14", lang2
) == 0)
24932 return "GNU C++14";
24933 if (strcmp ("GNU C++11", lang1
) == 0 || strcmp ("GNU C++11", lang2
) == 0)
24934 return "GNU C++11";
24935 if (strcmp ("GNU C++98", lang1
) == 0 || strcmp ("GNU C++98", lang2
) == 0)
24936 return "GNU C++98";
24938 if (strcmp ("GNU C2X", lang1
) == 0 || strcmp ("GNU C2X", lang2
) == 0)
24940 if (strcmp ("GNU C17", lang1
) == 0 || strcmp ("GNU C17", lang2
) == 0)
24942 if (strcmp ("GNU C11", lang1
) == 0 || strcmp ("GNU C11", lang2
) == 0)
24944 if (strcmp ("GNU C99", lang1
) == 0 || strcmp ("GNU C99", lang2
) == 0)
24946 if (strcmp ("GNU C89", lang1
) == 0 || strcmp ("GNU C89", lang2
) == 0)
24949 gcc_unreachable ();
24953 /* Generate the DIE for the compilation unit. */
24956 gen_compile_unit_die (const char *filename
)
24959 const char *language_string
= lang_hooks
.name
;
24962 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
24966 add_filename_attribute (die
, filename
);
24967 /* Don't add cwd for <built-in>. */
24968 if (filename
[0] != '<')
24969 add_comp_dir_attribute (die
);
24972 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
24974 /* If our producer is LTO try to figure out a common language to use
24975 from the global list of translation units. */
24976 if (strcmp (language_string
, "GNU GIMPLE") == 0)
24980 const char *common_lang
= NULL
;
24982 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
24984 if (!TRANSLATION_UNIT_LANGUAGE (t
))
24987 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
24988 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
24990 else if (startswith (common_lang
, "GNU C")
24991 && startswith (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C"))
24992 /* Mixing C and C++ is ok, use C++ in that case. */
24993 common_lang
= highest_c_language (common_lang
,
24994 TRANSLATION_UNIT_LANGUAGE (t
));
24997 /* Fall back to C. */
24998 common_lang
= NULL
;
25004 language_string
= common_lang
;
25007 language
= DW_LANG_C
;
25008 if (startswith (language_string
, "GNU C")
25009 && ISDIGIT (language_string
[5]))
25011 language
= DW_LANG_C89
;
25012 if (dwarf_version
>= 3 || !dwarf_strict
)
25014 if (strcmp (language_string
, "GNU C89") != 0)
25015 language
= DW_LANG_C99
;
25017 if (dwarf_version
>= 5 /* || !dwarf_strict */)
25018 if (strcmp (language_string
, "GNU C11") == 0
25019 || strcmp (language_string
, "GNU C17") == 0
25020 || strcmp (language_string
, "GNU C2X") == 0)
25021 language
= DW_LANG_C11
;
25024 else if (startswith (language_string
, "GNU C++"))
25026 language
= DW_LANG_C_plus_plus
;
25027 if (dwarf_version
>= 5 /* || !dwarf_strict */)
25029 if (strcmp (language_string
, "GNU C++11") == 0)
25030 language
= DW_LANG_C_plus_plus_11
;
25031 else if (strcmp (language_string
, "GNU C++14") == 0)
25032 language
= DW_LANG_C_plus_plus_14
;
25033 else if (strcmp (language_string
, "GNU C++17") == 0
25034 || strcmp (language_string
, "GNU C++20") == 0
25035 || strcmp (language_string
, "GNU C++23") == 0)
25037 language
= DW_LANG_C_plus_plus_14
;
25040 else if (strcmp (language_string
, "GNU F77") == 0)
25041 language
= DW_LANG_Fortran77
;
25042 else if (dwarf_version
>= 3 || !dwarf_strict
)
25044 if (strcmp (language_string
, "GNU Ada") == 0)
25045 language
= DW_LANG_Ada95
;
25046 else if (startswith (language_string
, "GNU Fortran"))
25048 language
= DW_LANG_Fortran95
;
25049 if (dwarf_version
>= 5 /* || !dwarf_strict */)
25051 if (strcmp (language_string
, "GNU Fortran2003") == 0)
25052 language
= DW_LANG_Fortran03
;
25053 else if (strcmp (language_string
, "GNU Fortran2008") == 0)
25054 language
= DW_LANG_Fortran08
;
25057 else if (strcmp (language_string
, "GNU Objective-C") == 0)
25058 language
= DW_LANG_ObjC
;
25059 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
25060 language
= DW_LANG_ObjC_plus_plus
;
25061 else if (strcmp (language_string
, "GNU D") == 0)
25062 language
= DW_LANG_D
;
25063 else if (dwarf_version
>= 5 || !dwarf_strict
)
25065 if (strcmp (language_string
, "GNU Go") == 0)
25066 language
= DW_LANG_Go
;
25069 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
25070 else if (startswith (language_string
, "GNU Fortran"))
25071 language
= DW_LANG_Fortran90
;
25072 /* Likewise for Ada. */
25073 else if (strcmp (language_string
, "GNU Ada") == 0)
25074 language
= DW_LANG_Ada83
;
25076 add_AT_unsigned (die
, DW_AT_language
, language
);
25080 case DW_LANG_Fortran77
:
25081 case DW_LANG_Fortran90
:
25082 case DW_LANG_Fortran95
:
25083 case DW_LANG_Fortran03
:
25084 case DW_LANG_Fortran08
:
25085 /* Fortran has case insensitive identifiers and the front-end
25086 lowercases everything. */
25087 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
25090 /* The default DW_ID_case_sensitive doesn't need to be specified. */
25096 /* Generate the DIE for a base class. */
25099 gen_inheritance_die (tree binfo
, tree access
, tree type
,
25100 dw_die_ref context_die
)
25102 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
25103 struct vlr_context ctx
= { type
, NULL
};
25105 add_type_attribute (die
, BINFO_TYPE (binfo
), TYPE_UNQUALIFIED
, false,
25107 add_data_member_location_attribute (die
, binfo
, &ctx
);
25109 if (BINFO_VIRTUAL_P (binfo
))
25110 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
25112 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
25113 children, otherwise the default is DW_ACCESS_public. In DWARF2
25114 the default has always been DW_ACCESS_private. */
25115 if (access
== access_public_node
)
25117 if (dwarf_version
== 2
25118 || context_die
->die_tag
== DW_TAG_class_type
)
25119 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
25121 else if (access
== access_protected_node
)
25122 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
25123 else if (dwarf_version
> 2
25124 && context_die
->die_tag
!= DW_TAG_class_type
)
25125 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
25128 /* Return whether DECL is a FIELD_DECL that represents the variant part of a
25132 is_variant_part (tree decl
)
25134 return (TREE_CODE (decl
) == FIELD_DECL
25135 && TREE_CODE (TREE_TYPE (decl
)) == QUAL_UNION_TYPE
);
25138 /* Check that OPERAND is a reference to a field in STRUCT_TYPE. If it is,
25139 return the FIELD_DECL. Return NULL_TREE otherwise. */
25142 analyze_discr_in_predicate (tree operand
, tree struct_type
)
25144 while (CONVERT_EXPR_P (operand
))
25145 operand
= TREE_OPERAND (operand
, 0);
25147 /* Match field access to members of struct_type only. */
25148 if (TREE_CODE (operand
) == COMPONENT_REF
25149 && TREE_CODE (TREE_OPERAND (operand
, 0)) == PLACEHOLDER_EXPR
25150 && TREE_TYPE (TREE_OPERAND (operand
, 0)) == struct_type
25151 && TREE_CODE (TREE_OPERAND (operand
, 1)) == FIELD_DECL
)
25152 return TREE_OPERAND (operand
, 1);
25157 /* Check that SRC is a constant integer that can be represented as a native
25158 integer constant (either signed or unsigned). If so, store it into DEST and
25159 return true. Return false otherwise. */
25162 get_discr_value (tree src
, dw_discr_value
*dest
)
25164 tree discr_type
= TREE_TYPE (src
);
25166 if (lang_hooks
.types
.get_debug_type
)
25168 tree debug_type
= lang_hooks
.types
.get_debug_type (discr_type
);
25169 if (debug_type
!= NULL
)
25170 discr_type
= debug_type
;
25173 if (TREE_CODE (src
) != INTEGER_CST
|| !INTEGRAL_TYPE_P (discr_type
))
25176 /* Signedness can vary between the original type and the debug type. This
25177 can happen for character types in Ada for instance: the character type
25178 used for code generation can be signed, to be compatible with the C one,
25179 but from a debugger point of view, it must be unsigned. */
25180 bool is_orig_unsigned
= TYPE_UNSIGNED (TREE_TYPE (src
));
25181 bool is_debug_unsigned
= TYPE_UNSIGNED (discr_type
);
25183 if (is_orig_unsigned
!= is_debug_unsigned
)
25184 src
= fold_convert (discr_type
, src
);
25186 if (!(is_debug_unsigned
? tree_fits_uhwi_p (src
) : tree_fits_shwi_p (src
)))
25189 dest
->pos
= is_debug_unsigned
;
25190 if (is_debug_unsigned
)
25191 dest
->v
.uval
= tree_to_uhwi (src
);
25193 dest
->v
.sval
= tree_to_shwi (src
);
25198 /* Try to extract synthetic properties out of VARIANT_PART_DECL, which is a
25199 FIELD_DECL in STRUCT_TYPE that represents a variant part. If unsuccessful,
25200 store NULL_TREE in DISCR_DECL. Otherwise:
25202 - store the discriminant field in STRUCT_TYPE that controls the variant
25203 part to *DISCR_DECL
25205 - put in *DISCR_LISTS_P an array where for each variant, the item
25206 represents the corresponding matching list of discriminant values.
25208 - put in *DISCR_LISTS_LENGTH the number of variants, which is the size of
25211 Note that when the array is allocated (i.e. when the analysis is
25212 successful), it is up to the caller to free the array. */
25215 analyze_variants_discr (tree variant_part_decl
,
25218 dw_discr_list_ref
**discr_lists_p
,
25219 unsigned *discr_lists_length
)
25221 tree variant_part_type
= TREE_TYPE (variant_part_decl
);
25223 dw_discr_list_ref
*discr_lists
;
25226 /* Compute how many variants there are in this variant part. */
25227 *discr_lists_length
= 0;
25228 for (variant
= TYPE_FIELDS (variant_part_type
);
25229 variant
!= NULL_TREE
;
25230 variant
= DECL_CHAIN (variant
))
25231 ++*discr_lists_length
;
25233 *discr_decl
= NULL_TREE
;
25235 = (dw_discr_list_ref
*) xcalloc (*discr_lists_length
,
25236 sizeof (**discr_lists_p
));
25237 discr_lists
= *discr_lists_p
;
25239 /* And then analyze all variants to extract discriminant information for all
25240 of them. This analysis is conservative: as soon as we detect something we
25241 do not support, abort everything and pretend we found nothing. */
25242 for (variant
= TYPE_FIELDS (variant_part_type
), i
= 0;
25243 variant
!= NULL_TREE
;
25244 variant
= DECL_CHAIN (variant
), ++i
)
25246 tree match_expr
= DECL_QUALIFIER (variant
);
25248 /* Now, try to analyze the predicate and deduce a discriminant for
25250 if (match_expr
== boolean_true_node
)
25251 /* Typically happens for the default variant: it matches all cases that
25252 previous variants rejected. Don't output any matching value for
25256 /* The following loop tries to iterate over each discriminant
25257 possibility: single values or ranges. */
25258 while (match_expr
!= NULL_TREE
)
25260 tree next_round_match_expr
;
25261 tree candidate_discr
= NULL_TREE
;
25262 dw_discr_list_ref new_node
= NULL
;
25264 /* Possibilities are matched one after the other by nested
25265 TRUTH_ORIF_EXPR expressions. Process the current possibility and
25266 continue with the rest at next iteration. */
25267 if (TREE_CODE (match_expr
) == TRUTH_ORIF_EXPR
)
25269 next_round_match_expr
= TREE_OPERAND (match_expr
, 0);
25270 match_expr
= TREE_OPERAND (match_expr
, 1);
25273 next_round_match_expr
= NULL_TREE
;
25275 if (match_expr
== boolean_false_node
)
25276 /* This sub-expression matches nothing: just wait for the next
25280 else if (TREE_CODE (match_expr
) == EQ_EXPR
)
25282 /* We are matching: <discr_field> == <integer_cst>
25283 This sub-expression matches a single value. */
25284 tree integer_cst
= TREE_OPERAND (match_expr
, 1);
25287 = analyze_discr_in_predicate (TREE_OPERAND (match_expr
, 0),
25290 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
25291 if (!get_discr_value (integer_cst
,
25292 &new_node
->dw_discr_lower_bound
))
25294 new_node
->dw_discr_range
= false;
25297 else if (TREE_CODE (match_expr
) == TRUTH_ANDIF_EXPR
)
25299 /* We are matching:
25300 <discr_field> > <integer_cst>
25301 && <discr_field> < <integer_cst>.
25302 This sub-expression matches the range of values between the
25303 two matched integer constants. Note that comparisons can be
25304 inclusive or exclusive. */
25305 tree candidate_discr_1
, candidate_discr_2
;
25306 tree lower_cst
, upper_cst
;
25307 bool lower_cst_included
, upper_cst_included
;
25308 tree lower_op
= TREE_OPERAND (match_expr
, 0);
25309 tree upper_op
= TREE_OPERAND (match_expr
, 1);
25311 /* When the comparison is exclusive, the integer constant is not
25312 the discriminant range bound we are looking for: we will have
25313 to increment or decrement it. */
25314 if (TREE_CODE (lower_op
) == GE_EXPR
)
25315 lower_cst_included
= true;
25316 else if (TREE_CODE (lower_op
) == GT_EXPR
)
25317 lower_cst_included
= false;
25321 if (TREE_CODE (upper_op
) == LE_EXPR
)
25322 upper_cst_included
= true;
25323 else if (TREE_CODE (upper_op
) == LT_EXPR
)
25324 upper_cst_included
= false;
25328 /* Extract the discriminant from the first operand and check it
25329 is consistant with the same analysis in the second
25332 = analyze_discr_in_predicate (TREE_OPERAND (lower_op
, 0),
25335 = analyze_discr_in_predicate (TREE_OPERAND (upper_op
, 0),
25337 if (candidate_discr_1
== candidate_discr_2
)
25338 candidate_discr
= candidate_discr_1
;
25342 /* Extract bounds from both. */
25343 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
25344 lower_cst
= TREE_OPERAND (lower_op
, 1);
25345 upper_cst
= TREE_OPERAND (upper_op
, 1);
25347 if (!lower_cst_included
)
25349 = fold_build2 (PLUS_EXPR
, TREE_TYPE (lower_cst
), lower_cst
,
25350 build_int_cst (TREE_TYPE (lower_cst
), 1));
25351 if (!upper_cst_included
)
25353 = fold_build2 (MINUS_EXPR
, TREE_TYPE (upper_cst
), upper_cst
,
25354 build_int_cst (TREE_TYPE (upper_cst
), 1));
25356 if (!get_discr_value (lower_cst
,
25357 &new_node
->dw_discr_lower_bound
)
25358 || !get_discr_value (upper_cst
,
25359 &new_node
->dw_discr_upper_bound
))
25362 new_node
->dw_discr_range
= true;
25365 else if ((candidate_discr
25366 = analyze_discr_in_predicate (match_expr
, struct_type
))
25367 && (TREE_TYPE (candidate_discr
) == boolean_type_node
25368 || TREE_TYPE (TREE_TYPE (candidate_discr
))
25369 == boolean_type_node
))
25371 /* We are matching: <discr_field> for a boolean discriminant.
25372 This sub-expression matches boolean_true_node. */
25373 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
25374 if (!get_discr_value (boolean_true_node
,
25375 &new_node
->dw_discr_lower_bound
))
25377 new_node
->dw_discr_range
= false;
25381 /* Unsupported sub-expression: we cannot determine the set of
25382 matching discriminant values. Abort everything. */
25385 /* If the discriminant info is not consistant with what we saw so
25386 far, consider the analysis failed and abort everything. */
25387 if (candidate_discr
== NULL_TREE
25388 || (*discr_decl
!= NULL_TREE
&& candidate_discr
!= *discr_decl
))
25391 *discr_decl
= candidate_discr
;
25393 if (new_node
!= NULL
)
25395 new_node
->dw_discr_next
= discr_lists
[i
];
25396 discr_lists
[i
] = new_node
;
25398 match_expr
= next_round_match_expr
;
25402 /* If we reach this point, we could match everything we were interested
25407 /* Clean all data structure and return no result. */
25408 free (*discr_lists_p
);
25409 *discr_lists_p
= NULL
;
25410 *discr_decl
= NULL_TREE
;
25413 /* Generate a DIE to represent VARIANT_PART_DECL, a variant part that is part
25414 of STRUCT_TYPE, a record type. This new DIE is emitted as the next child
25417 Variant parts are supposed to be implemented as a FIELD_DECL whose type is a
25418 QUAL_UNION_TYPE: this is the VARIANT_PART_DECL parameter. The members for
25419 this type, which are record types, represent the available variants and each
25420 has a DECL_QUALIFIER attribute. The discriminant and the discriminant
25421 values are inferred from these attributes.
25423 In trees, the offsets for the fields inside these sub-records are relative
25424 to the variant part itself, whereas the corresponding DIEs should have
25425 offset attributes that are relative to the embedding record base address.
25426 This is why the caller must provide a VARIANT_PART_OFFSET expression: it
25427 must be an expression that computes the offset of the variant part to
25428 describe in DWARF. */
25431 gen_variant_part (tree variant_part_decl
, struct vlr_context
*vlr_ctx
,
25432 dw_die_ref context_die
)
25434 const tree variant_part_type
= TREE_TYPE (variant_part_decl
);
25435 tree variant_part_offset
= vlr_ctx
->variant_part_offset
;
25437 /* The FIELD_DECL node in STRUCT_TYPE that acts as the discriminant, or
25438 NULL_TREE if there is no such field. */
25439 tree discr_decl
= NULL_TREE
;
25440 dw_discr_list_ref
*discr_lists
;
25441 unsigned discr_lists_length
= 0;
25444 dw_die_ref dwarf_proc_die
= NULL
;
25445 dw_die_ref variant_part_die
25446 = new_die (DW_TAG_variant_part
, context_die
, variant_part_type
);
25448 equate_decl_number_to_die (variant_part_decl
, variant_part_die
);
25450 analyze_variants_discr (variant_part_decl
, vlr_ctx
->struct_type
,
25451 &discr_decl
, &discr_lists
, &discr_lists_length
);
25453 if (discr_decl
!= NULL_TREE
)
25455 dw_die_ref discr_die
= lookup_decl_die (discr_decl
);
25458 add_AT_die_ref (variant_part_die
, DW_AT_discr
, discr_die
);
25460 /* We have no DIE for the discriminant, so just discard all
25461 discrimimant information in the output. */
25462 discr_decl
= NULL_TREE
;
25465 /* If the offset for this variant part is more complex than a constant,
25466 create a DWARF procedure for it so that we will not have to generate
25467 DWARF expressions for it for each member. */
25468 if (TREE_CODE (variant_part_offset
) != INTEGER_CST
25469 && (dwarf_version
>= 3 || !dwarf_strict
))
25471 struct loc_descr_context ctx
= {
25472 vlr_ctx
->struct_type
, /* context_type */
25473 NULL_TREE
, /* base_decl */
25475 false, /* placeholder_arg */
25476 false, /* placeholder_seen */
25477 false /* strict_signedness */
25479 const tree dwarf_proc_fndecl
25480 = build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, NULL_TREE
,
25481 build_function_type (TREE_TYPE (variant_part_offset
),
25483 const tree dwarf_proc_call
= build_call_expr (dwarf_proc_fndecl
, 0);
25484 const dw_loc_descr_ref dwarf_proc_body
25485 = loc_descriptor_from_tree (variant_part_offset
, 0, &ctx
);
25487 dwarf_proc_die
= new_dwarf_proc_die (dwarf_proc_body
,
25488 dwarf_proc_fndecl
, context_die
);
25489 if (dwarf_proc_die
!= NULL
)
25490 variant_part_offset
= dwarf_proc_call
;
25493 /* Output DIEs for all variants. */
25495 for (tree variant
= TYPE_FIELDS (variant_part_type
);
25496 variant
!= NULL_TREE
;
25497 variant
= DECL_CHAIN (variant
), ++i
)
25499 tree variant_type
= TREE_TYPE (variant
);
25500 dw_die_ref variant_die
;
25502 /* All variants (i.e. members of a variant part) are supposed to be
25503 encoded as structures. Sub-variant parts are QUAL_UNION_TYPE fields
25504 under these records. */
25505 gcc_assert (TREE_CODE (variant_type
) == RECORD_TYPE
);
25507 variant_die
= new_die (DW_TAG_variant
, variant_part_die
, variant_type
);
25508 equate_decl_number_to_die (variant
, variant_die
);
25510 /* Output discriminant values this variant matches, if any. */
25511 if (discr_decl
== NULL
|| discr_lists
[i
] == NULL
)
25512 /* In the case we have discriminant information at all, this is
25513 probably the default variant: as the standard says, don't
25514 output any discriminant value/list attribute. */
25516 else if (discr_lists
[i
]->dw_discr_next
== NULL
25517 && !discr_lists
[i
]->dw_discr_range
)
25518 /* If there is only one accepted value, don't bother outputting a
25520 add_discr_value (variant_die
, &discr_lists
[i
]->dw_discr_lower_bound
);
25522 add_discr_list (variant_die
, discr_lists
[i
]);
25524 for (tree member
= TYPE_FIELDS (variant_type
);
25525 member
!= NULL_TREE
;
25526 member
= DECL_CHAIN (member
))
25528 struct vlr_context vlr_sub_ctx
= {
25529 vlr_ctx
->struct_type
, /* struct_type */
25530 NULL
/* variant_part_offset */
25532 if (is_variant_part (member
))
25534 /* All offsets for fields inside variant parts are relative to
25535 the top-level embedding RECORD_TYPE's base address. On the
25536 other hand, offsets in GCC's types are relative to the
25537 nested-most variant part. So we have to sum offsets each time
25540 vlr_sub_ctx
.variant_part_offset
25541 = fold_build2 (PLUS_EXPR
, TREE_TYPE (variant_part_offset
),
25542 variant_part_offset
, byte_position (member
));
25543 gen_variant_part (member
, &vlr_sub_ctx
, variant_die
);
25547 vlr_sub_ctx
.variant_part_offset
= variant_part_offset
;
25548 gen_decl_die (member
, NULL
, &vlr_sub_ctx
, variant_die
);
25553 free (discr_lists
);
25556 /* Generate a DIE for a class member. */
25559 gen_member_die (tree type
, dw_die_ref context_die
)
25562 tree binfo
= TYPE_BINFO (type
);
25564 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
25566 /* If this is not an incomplete type, output descriptions of each of its
25567 members. Note that as we output the DIEs necessary to represent the
25568 members of this record or union type, we will also be trying to output
25569 DIEs to represent the *types* of those members. However the `type'
25570 function (above) will specifically avoid generating type DIEs for member
25571 types *within* the list of member DIEs for this (containing) type except
25572 for those types (of members) which are explicitly marked as also being
25573 members of this (containing) type themselves. The g++ front- end can
25574 force any given type to be treated as a member of some other (containing)
25575 type by setting the TYPE_CONTEXT of the given (member) type to point to
25576 the TREE node representing the appropriate (containing) type. */
25578 /* First output info about the base classes. */
25579 if (binfo
&& early_dwarf
)
25581 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
25585 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
25586 gen_inheritance_die (base
,
25587 (accesses
? (*accesses
)[i
] : access_public_node
),
25592 /* Now output info about the members. */
25593 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
25595 /* Ignore clones. */
25596 if (DECL_ABSTRACT_ORIGIN (member
))
25599 struct vlr_context vlr_ctx
= { type
, NULL_TREE
};
25600 bool static_inline_p
25602 && TREE_STATIC (member
)
25603 && (lang_hooks
.decls
.decl_dwarf_attribute (member
, DW_AT_inline
)
25606 /* If we thought we were generating minimal debug info for TYPE
25607 and then changed our minds, some of the member declarations
25608 may have already been defined. Don't define them again, but
25609 do put them in the right order. */
25611 if (dw_die_ref child
= lookup_decl_die (member
))
25613 /* Handle inline static data members, which only have in-class
25615 bool splice
= true;
25617 dw_die_ref ref
= NULL
;
25618 if (child
->die_tag
== DW_TAG_variable
25619 && child
->die_parent
== comp_unit_die ())
25621 ref
= get_AT_ref (child
, DW_AT_specification
);
25623 /* For C++17 inline static data members followed by redundant
25624 out of class redeclaration, we might get here with
25625 child being the DIE created for the out of class
25626 redeclaration and with its DW_AT_specification being
25627 the DIE created for in-class definition. We want to
25628 reparent the latter, and don't want to create another
25629 DIE with DW_AT_specification in that case, because
25630 we already have one. */
25633 && ref
->die_tag
== DW_TAG_variable
25634 && ref
->die_parent
== comp_unit_die ()
25635 && get_AT (ref
, DW_AT_specification
) == NULL
)
25639 static_inline_p
= false;
25644 reparent_child (child
, context_die
);
25645 if (dwarf_version
< 5)
25646 child
->die_tag
= DW_TAG_member
;
25650 else if (child
->die_tag
== DW_TAG_enumerator
)
25651 /* Enumerators remain under their enumeration even if
25652 their names are introduced in the enclosing scope. */
25656 splice_child_die (context_die
, child
);
25659 /* Do not generate DWARF for variant parts if we are generating the
25660 corresponding GNAT encodings: DIEs generated for the two schemes
25661 would conflict in our mappings. */
25662 else if (is_variant_part (member
)
25663 && gnat_encodings
!= DWARF_GNAT_ENCODINGS_ALL
)
25665 vlr_ctx
.variant_part_offset
= byte_position (member
);
25666 gen_variant_part (member
, &vlr_ctx
, context_die
);
25670 vlr_ctx
.variant_part_offset
= NULL_TREE
;
25671 gen_decl_die (member
, NULL
, &vlr_ctx
, context_die
);
25674 /* For C++ inline static data members emit immediately a DW_TAG_variable
25675 DIE that will refer to that DW_TAG_member/DW_TAG_variable through
25676 DW_AT_specification. */
25677 if (static_inline_p
)
25679 int old_extern
= DECL_EXTERNAL (member
);
25680 DECL_EXTERNAL (member
) = 0;
25681 gen_decl_die (member
, NULL
, NULL
, comp_unit_die ());
25682 DECL_EXTERNAL (member
) = old_extern
;
25687 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
25688 is set, we pretend that the type was never defined, so we only get the
25689 member DIEs needed by later specification DIEs. */
25692 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
25693 enum debug_info_usage usage
)
25695 if (TREE_ASM_WRITTEN (type
))
25697 /* Fill in the bound of variable-length fields in late dwarf if
25698 still incomplete. */
25699 if (!early_dwarf
&& variably_modified_type_p (type
, NULL
))
25700 for (tree member
= TYPE_FIELDS (type
);
25702 member
= DECL_CHAIN (member
))
25703 fill_variable_array_bounds (TREE_TYPE (member
));
25707 dw_die_ref type_die
= lookup_type_die (type
);
25708 dw_die_ref scope_die
= 0;
25710 int complete
= (TYPE_SIZE (type
)
25711 && (! TYPE_STUB_DECL (type
)
25712 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
25713 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
25714 complete
= complete
&& should_emit_struct_debug (type
, usage
);
25716 if (type_die
&& ! complete
)
25719 if (TYPE_CONTEXT (type
) != NULL_TREE
25720 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
25721 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
25724 scope_die
= scope_die_for (type
, context_die
);
25726 /* Generate child dies for template parameters. */
25727 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
25728 schedule_generic_params_dies_gen (type
);
25730 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
25731 /* First occurrence of type or toplevel definition of nested class. */
25733 dw_die_ref old_die
= type_die
;
25735 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
25736 ? record_type_tag (type
) : DW_TAG_union_type
,
25738 equate_type_number_to_die (type
, type_die
);
25740 add_AT_specification (type_die
, old_die
);
25742 add_name_attribute (type_die
, type_tag (type
));
25745 remove_AT (type_die
, DW_AT_declaration
);
25747 /* If this type has been completed, then give it a byte_size attribute and
25748 then give a list of members. */
25749 if (complete
&& !ns_decl
)
25751 /* Prevent infinite recursion in cases where the type of some member of
25752 this type is expressed in terms of this type itself. */
25753 TREE_ASM_WRITTEN (type
) = 1;
25754 add_byte_size_attribute (type_die
, type
);
25755 add_alignment_attribute (type_die
, type
);
25756 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
25758 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
25759 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
25762 /* If the first reference to this type was as the return type of an
25763 inline function, then it may not have a parent. Fix this now. */
25764 if (type_die
->die_parent
== NULL
)
25765 add_child_die (scope_die
, type_die
);
25767 gen_member_die (type
, type_die
);
25769 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
25770 if (TYPE_ARTIFICIAL (type
))
25771 add_AT_flag (type_die
, DW_AT_artificial
, 1);
25773 /* GNU extension: Record what type our vtable lives in. */
25774 if (TYPE_VFIELD (type
))
25776 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
25778 gen_type_die (vtype
, context_die
);
25779 add_AT_die_ref (type_die
, DW_AT_containing_type
,
25780 lookup_type_die (vtype
));
25785 add_AT_flag (type_die
, DW_AT_declaration
, 1);
25787 /* We don't need to do this for function-local types. */
25788 if (TYPE_STUB_DECL (type
)
25789 && ! decl_function_context (TYPE_STUB_DECL (type
)))
25790 vec_safe_push (incomplete_types
, type
);
25793 if (get_AT (type_die
, DW_AT_name
))
25794 add_pubtype (type
, type_die
);
25797 /* Generate a DIE for a subroutine _type_. */
25800 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
25802 tree return_type
= TREE_TYPE (type
);
25803 dw_die_ref subr_die
25804 = new_die (DW_TAG_subroutine_type
,
25805 scope_die_for (type
, context_die
), type
);
25807 equate_type_number_to_die (type
, subr_die
);
25808 add_prototyped_attribute (subr_die
, type
);
25809 add_type_attribute (subr_die
, return_type
, TYPE_UNQUALIFIED
, false,
25811 add_alignment_attribute (subr_die
, type
);
25812 gen_formal_types_die (type
, subr_die
);
25814 if (get_AT (subr_die
, DW_AT_name
))
25815 add_pubtype (type
, subr_die
);
25816 if ((dwarf_version
>= 5 || !dwarf_strict
)
25817 && lang_hooks
.types
.type_dwarf_attribute (type
, DW_AT_reference
) != -1)
25818 add_AT_flag (subr_die
, DW_AT_reference
, 1);
25819 if ((dwarf_version
>= 5 || !dwarf_strict
)
25820 && lang_hooks
.types
.type_dwarf_attribute (type
,
25821 DW_AT_rvalue_reference
) != -1)
25822 add_AT_flag (subr_die
, DW_AT_rvalue_reference
, 1);
25825 /* Generate a DIE for a type definition. */
25828 gen_typedef_die (tree decl
, dw_die_ref context_die
)
25830 dw_die_ref type_die
;
25833 if (TREE_ASM_WRITTEN (decl
))
25835 if (DECL_ORIGINAL_TYPE (decl
))
25836 fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl
));
25840 /* As we avoid creating DIEs for local typedefs (see decl_ultimate_origin
25841 checks in process_scope_var and modified_type_die), this should be called
25842 only for original types. */
25843 gcc_assert (decl_ultimate_origin (decl
) == NULL
25844 || decl_ultimate_origin (decl
) == decl
);
25846 TREE_ASM_WRITTEN (decl
) = 1;
25847 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
25849 add_name_and_src_coords_attributes (type_die
, decl
);
25850 if (DECL_ORIGINAL_TYPE (decl
))
25852 type
= DECL_ORIGINAL_TYPE (decl
);
25853 if (type
== error_mark_node
)
25856 gcc_assert (type
!= TREE_TYPE (decl
));
25857 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
25861 type
= TREE_TYPE (decl
);
25862 if (type
== error_mark_node
)
25865 if (is_naming_typedef_decl (TYPE_NAME (type
)))
25867 /* Here, we are in the case of decl being a typedef naming
25868 an anonymous type, e.g:
25869 typedef struct {...} foo;
25870 In that case TREE_TYPE (decl) is not a typedef variant
25871 type and TYPE_NAME of the anonymous type is set to the
25872 TYPE_DECL of the typedef. This construct is emitted by
25875 TYPE is the anonymous struct named by the typedef
25876 DECL. As we need the DW_AT_type attribute of the
25877 DW_TAG_typedef to point to the DIE of TYPE, let's
25878 generate that DIE right away. add_type_attribute
25879 called below will then pick (via lookup_type_die) that
25880 anonymous struct DIE. */
25881 if (!TREE_ASM_WRITTEN (type
))
25882 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
25884 /* This is a GNU Extension. We are adding a
25885 DW_AT_linkage_name attribute to the DIE of the
25886 anonymous struct TYPE. The value of that attribute
25887 is the name of the typedef decl naming the anonymous
25888 struct. This greatly eases the work of consumers of
25889 this debug info. */
25890 add_linkage_name_raw (lookup_type_die (type
), decl
);
25894 add_type_attribute (type_die
, type
, decl_quals (decl
), false,
25897 if (is_naming_typedef_decl (decl
))
25898 /* We want that all subsequent calls to lookup_type_die with
25899 TYPE in argument yield the DW_TAG_typedef we have just
25901 equate_type_number_to_die (type
, type_die
);
25903 add_alignment_attribute (type_die
, TREE_TYPE (decl
));
25905 add_accessibility_attribute (type_die
, decl
);
25907 if (DECL_ABSTRACT_P (decl
))
25908 equate_decl_number_to_die (decl
, type_die
);
25910 if (get_AT (type_die
, DW_AT_name
))
25911 add_pubtype (decl
, type_die
);
25914 /* Generate a DIE for a struct, class, enum or union type. */
25917 gen_tagged_type_die (tree type
,
25918 dw_die_ref context_die
,
25919 enum debug_info_usage usage
)
25921 if (type
== NULL_TREE
25922 || !is_tagged_type (type
))
25925 if (TREE_ASM_WRITTEN (type
))
25927 /* If this is a nested type whose containing class hasn't been written
25928 out yet, writing it out will cover this one, too. This does not apply
25929 to instantiations of member class templates; they need to be added to
25930 the containing class as they are generated. FIXME: This hurts the
25931 idea of combining type decls from multiple TUs, since we can't predict
25932 what set of template instantiations we'll get. */
25933 else if (TYPE_CONTEXT (type
)
25934 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
25935 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
25937 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
25939 if (TREE_ASM_WRITTEN (type
))
25942 /* If that failed, attach ourselves to the stub. */
25943 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
25945 else if (TYPE_CONTEXT (type
) != NULL_TREE
25946 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
25948 /* If this type is local to a function that hasn't been written
25949 out yet, use a NULL context for now; it will be fixed up in
25950 decls_for_scope. */
25951 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
25952 /* A declaration DIE doesn't count; nested types need to go in the
25954 if (context_die
&& is_declaration_die (context_die
))
25955 context_die
= NULL
;
25958 context_die
= declare_in_namespace (type
, context_die
);
25960 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
25962 /* This might have been written out by the call to
25963 declare_in_namespace. */
25964 if (!TREE_ASM_WRITTEN (type
))
25965 gen_enumeration_type_die (type
, context_die
);
25968 gen_struct_or_union_type_die (type
, context_die
, usage
);
25970 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
25971 it up if it is ever completed. gen_*_type_die will set it for us
25972 when appropriate. */
25975 /* Generate a type description DIE. */
25978 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
25979 enum debug_info_usage usage
)
25981 struct array_descr_info info
;
25983 if (type
== NULL_TREE
|| type
== error_mark_node
)
25986 if (flag_checking
&& type
)
25987 verify_type (type
);
25989 if (TYPE_NAME (type
) != NULL_TREE
25990 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
25991 && is_redundant_typedef (TYPE_NAME (type
))
25992 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
25993 /* The DECL of this type is a typedef we don't want to emit debug
25994 info for but we want debug info for its underlying typedef.
25995 This can happen for e.g, the injected-class-name of a C++
25997 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
25999 /* If TYPE is a typedef type variant, let's generate debug info
26000 for the parent typedef which TYPE is a type of. */
26001 if (typedef_variant_p (type
))
26003 if (TREE_ASM_WRITTEN (type
))
26006 tree name
= TYPE_NAME (type
);
26007 tree origin
= decl_ultimate_origin (name
);
26008 if (origin
!= NULL
&& origin
!= name
)
26010 gen_decl_die (origin
, NULL
, NULL
, context_die
);
26014 /* Prevent broken recursion; we can't hand off to the same type. */
26015 gcc_assert (DECL_ORIGINAL_TYPE (name
) != type
);
26017 /* Give typedefs the right scope. */
26018 context_die
= scope_die_for (type
, context_die
);
26020 TREE_ASM_WRITTEN (type
) = 1;
26022 gen_decl_die (name
, NULL
, NULL
, context_die
);
26026 /* If type is an anonymous tagged type named by a typedef, let's
26027 generate debug info for the typedef. */
26028 if (is_naming_typedef_decl (TYPE_NAME (type
)))
26030 /* Give typedefs the right scope. */
26031 context_die
= scope_die_for (type
, context_die
);
26033 gen_decl_die (TYPE_NAME (type
), NULL
, NULL
, context_die
);
26037 if (lang_hooks
.types
.get_debug_type
)
26039 tree debug_type
= lang_hooks
.types
.get_debug_type (type
);
26041 if (debug_type
!= NULL_TREE
&& debug_type
!= type
)
26043 gen_type_die_with_usage (debug_type
, context_die
, usage
);
26048 /* We are going to output a DIE to represent the unqualified version
26049 of this type (i.e. without any const or volatile qualifiers) so
26050 get the main variant (i.e. the unqualified version) of this type
26051 now. (Vectors and arrays are special because the debugging info is in the
26052 cloned type itself. Similarly function/method types can contain extra
26053 ref-qualification). */
26054 if (TREE_CODE (type
) == FUNCTION_TYPE
26055 || TREE_CODE (type
) == METHOD_TYPE
)
26057 /* For function/method types, can't use type_main_variant here,
26058 because that can have different ref-qualifiers for C++,
26059 but try to canonicalize. */
26060 tree main
= TYPE_MAIN_VARIANT (type
);
26061 for (tree t
= main
; t
; t
= TYPE_NEXT_VARIANT (t
))
26062 if (TYPE_QUALS_NO_ADDR_SPACE (t
) == 0
26063 && check_base_type (t
, main
)
26064 && check_lang_type (t
, type
))
26070 else if (TREE_CODE (type
) != VECTOR_TYPE
26071 && TREE_CODE (type
) != ARRAY_TYPE
)
26072 type
= type_main_variant (type
);
26074 /* If this is an array type with hidden descriptor, handle it first. */
26075 if (!TREE_ASM_WRITTEN (type
)
26076 && lang_hooks
.types
.get_array_descr_info
)
26078 memset (&info
, 0, sizeof (info
));
26079 if (lang_hooks
.types
.get_array_descr_info (type
, &info
))
26081 /* Fortran sometimes emits array types with no dimension. */
26082 gcc_assert (info
.ndimensions
>= 0
26083 && (info
.ndimensions
26084 <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN
));
26085 gen_descr_array_type_die (type
, &info
, context_die
);
26086 TREE_ASM_WRITTEN (type
) = 1;
26091 if (TREE_ASM_WRITTEN (type
))
26093 /* Variable-length types may be incomplete even if
26094 TREE_ASM_WRITTEN. For such types, fall through to
26095 gen_array_type_die() and possibly fill in
26096 DW_AT_{upper,lower}_bound attributes. */
26097 if ((TREE_CODE (type
) != ARRAY_TYPE
26098 && TREE_CODE (type
) != RECORD_TYPE
26099 && TREE_CODE (type
) != UNION_TYPE
26100 && TREE_CODE (type
) != QUAL_UNION_TYPE
)
26101 || !variably_modified_type_p (type
, NULL
))
26105 switch (TREE_CODE (type
))
26111 case REFERENCE_TYPE
:
26112 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
26113 ensures that the gen_type_die recursion will terminate even if the
26114 type is recursive. Recursive types are possible in Ada. */
26115 /* ??? We could perhaps do this for all types before the switch
26117 TREE_ASM_WRITTEN (type
) = 1;
26119 /* For these types, all that is required is that we output a DIE (or a
26120 set of DIEs) to represent the "basis" type. */
26121 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
26122 DINFO_USAGE_IND_USE
);
26126 /* This code is used for C++ pointer-to-data-member types.
26127 Output a description of the relevant class type. */
26128 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
26129 DINFO_USAGE_IND_USE
);
26131 /* Output a description of the type of the object pointed to. */
26132 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
26133 DINFO_USAGE_IND_USE
);
26135 /* Now output a DIE to represent this pointer-to-data-member type
26137 gen_ptr_to_mbr_type_die (type
, context_die
);
26140 case FUNCTION_TYPE
:
26141 /* Force out return type (in case it wasn't forced out already). */
26142 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
26143 DINFO_USAGE_DIR_USE
);
26144 gen_subroutine_type_die (type
, context_die
);
26148 /* Force out return type (in case it wasn't forced out already). */
26149 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
26150 DINFO_USAGE_DIR_USE
);
26151 gen_subroutine_type_die (type
, context_die
);
26156 gen_array_type_die (type
, context_die
);
26159 case ENUMERAL_TYPE
:
26162 case QUAL_UNION_TYPE
:
26163 gen_tagged_type_die (type
, context_die
, usage
);
26170 case FIXED_POINT_TYPE
:
26173 /* No DIEs needed for fundamental types. */
26178 /* Just use DW_TAG_unspecified_type. */
26180 dw_die_ref type_die
= lookup_type_die (type
);
26181 if (type_die
== NULL
)
26183 tree name
= TYPE_IDENTIFIER (type
);
26184 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (),
26186 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
26187 equate_type_number_to_die (type
, type_die
);
26193 if (is_cxx_auto (type
))
26195 tree name
= TYPE_IDENTIFIER (type
);
26196 dw_die_ref
*die
= (name
== get_identifier ("auto")
26197 ? &auto_die
: &decltype_auto_die
);
26200 *die
= new_die (DW_TAG_unspecified_type
,
26201 comp_unit_die (), NULL_TREE
);
26202 add_name_attribute (*die
, IDENTIFIER_POINTER (name
));
26204 equate_type_number_to_die (type
, *die
);
26207 gcc_unreachable ();
26210 TREE_ASM_WRITTEN (type
) = 1;
26214 gen_type_die (tree type
, dw_die_ref context_die
)
26216 if (type
!= error_mark_node
)
26218 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
26221 dw_die_ref die
= lookup_type_die (type
);
26228 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
26229 things which are local to the given block. */
26232 gen_block_die (tree stmt
, dw_die_ref context_die
)
26234 int must_output_die
= 0;
26237 /* Ignore blocks that are NULL. */
26238 if (stmt
== NULL_TREE
)
26241 inlined_func
= inlined_function_outer_scope_p (stmt
);
26243 /* If the block is one fragment of a non-contiguous block, do not
26244 process the variables, since they will have been done by the
26245 origin block. Do process subblocks. */
26246 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
26250 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
26251 gen_block_die (sub
, context_die
);
26256 /* Determine if we need to output any Dwarf DIEs at all to represent this
26259 /* The outer scopes for inlinings *must* always be represented. We
26260 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
26261 must_output_die
= 1;
26262 else if (lookup_block_die (stmt
))
26263 /* If we already have a DIE then it was filled early. Meanwhile
26264 we might have pruned all BLOCK_VARS as optimized out but we
26265 still want to generate high/low PC attributes so output it. */
26266 must_output_die
= 1;
26267 else if (TREE_USED (stmt
)
26268 || TREE_ASM_WRITTEN (stmt
))
26270 /* Determine if this block directly contains any "significant"
26271 local declarations which we will need to output DIEs for. */
26272 if (debug_info_level
> DINFO_LEVEL_TERSE
)
26274 /* We are not in terse mode so any local declaration that
26275 is not ignored for debug purposes counts as being a
26276 "significant" one. */
26277 if (BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
26278 must_output_die
= 1;
26280 for (tree var
= BLOCK_VARS (stmt
); var
; var
= DECL_CHAIN (var
))
26281 if (!DECL_IGNORED_P (var
))
26283 must_output_die
= 1;
26287 else if (!dwarf2out_ignore_block (stmt
))
26288 must_output_die
= 1;
26291 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
26292 DIE for any block which contains no significant local declarations at
26293 all. Rather, in such cases we just call `decls_for_scope' so that any
26294 needed Dwarf info for any sub-blocks will get properly generated. Note
26295 that in terse mode, our definition of what constitutes a "significant"
26296 local declaration gets restricted to include only inlined function
26297 instances and local (nested) function definitions. */
26298 if (must_output_die
)
26301 gen_inlined_subroutine_die (stmt
, context_die
);
26303 gen_lexical_block_die (stmt
, context_die
);
26306 decls_for_scope (stmt
, context_die
);
26309 /* Process variable DECL (or variable with origin ORIGIN) within
26310 block STMT and add it to CONTEXT_DIE. */
26312 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
26315 tree decl_or_origin
= decl
? decl
: origin
;
26317 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
26318 die
= lookup_decl_die (decl_or_origin
);
26319 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
)
26321 if (TYPE_DECL_IS_STUB (decl_or_origin
))
26322 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
26324 die
= lookup_decl_die (decl_or_origin
);
26325 /* Avoid re-creating the DIE late if it was optimized as unused early. */
26326 if (! die
&& ! early_dwarf
)
26332 /* Avoid creating DIEs for local typedefs and concrete static variables that
26333 will only be pruned later. */
26334 if ((origin
|| decl_ultimate_origin (decl
))
26335 && (TREE_CODE (decl_or_origin
) == TYPE_DECL
26336 || (VAR_P (decl_or_origin
) && TREE_STATIC (decl_or_origin
))))
26338 origin
= decl_ultimate_origin (decl_or_origin
);
26339 if (decl
&& VAR_P (decl
) && die
!= NULL
)
26341 die
= lookup_decl_die (origin
);
26343 equate_decl_number_to_die (decl
, die
);
26348 if (die
!= NULL
&& die
->die_parent
== NULL
)
26349 add_child_die (context_die
, die
);
26350 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
26353 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
26354 stmt
, context_die
);
26358 if (decl
&& DECL_P (decl
))
26360 die
= lookup_decl_die (decl
);
26362 /* Early created DIEs do not have a parent as the decls refer
26363 to the function as DECL_CONTEXT rather than the BLOCK. */
26364 if (die
&& die
->die_parent
== NULL
)
26366 gcc_assert (in_lto_p
);
26367 add_child_die (context_die
, die
);
26371 gen_decl_die (decl
, origin
, NULL
, context_die
);
26375 /* Generate all of the decls declared within a given scope and (recursively)
26376 all of its sub-blocks. */
26379 decls_for_scope (tree stmt
, dw_die_ref context_die
, bool recurse
)
26385 /* Ignore NULL blocks. */
26386 if (stmt
== NULL_TREE
)
26389 /* Output the DIEs to represent all of the data objects and typedefs
26390 declared directly within this block but not within any nested
26391 sub-blocks. Also, nested function and tag DIEs have been
26392 generated with a parent of NULL; fix that up now. We don't
26393 have to do this if we're at -g1. */
26394 if (debug_info_level
> DINFO_LEVEL_TERSE
)
26396 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
26397 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
26398 /* BLOCK_NONLOCALIZED_VARs simply generate DIE stubs with abstract
26399 origin - avoid doing this twice as we have no good way to see
26400 if we've done it once already. */
26402 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
26404 decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
26405 if (decl
== current_function_decl
)
26406 /* Ignore declarations of the current function, while they
26407 are declarations, gen_subprogram_die would treat them
26408 as definitions again, because they are equal to
26409 current_function_decl and endlessly recurse. */;
26410 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
26411 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
26413 process_scope_var (stmt
, NULL_TREE
, decl
, context_die
);
26417 /* Even if we're at -g1, we need to process the subblocks in order to get
26418 inlined call information. */
26420 /* Output the DIEs to represent all sub-blocks (and the items declared
26421 therein) of this block. */
26423 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
26425 subblocks
= BLOCK_CHAIN (subblocks
))
26426 gen_block_die (subblocks
, context_die
);
26429 /* Is this a typedef we can avoid emitting? */
26432 is_redundant_typedef (const_tree decl
)
26434 if (TYPE_DECL_IS_STUB (decl
))
26437 if (DECL_ARTIFICIAL (decl
)
26438 && DECL_CONTEXT (decl
)
26439 && is_tagged_type (DECL_CONTEXT (decl
))
26440 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
26441 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
26442 /* Also ignore the artificial member typedef for the class name. */
26448 /* Return TRUE if TYPE is a typedef that names a type for linkage
26449 purposes. This kind of typedefs is produced by the C++ FE for
26452 typedef struct {...} foo;
26454 In that case, there is no typedef variant type produced for foo.
26455 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
26459 is_naming_typedef_decl (const_tree decl
)
26461 if (decl
== NULL_TREE
26462 || TREE_CODE (decl
) != TYPE_DECL
26463 || DECL_NAMELESS (decl
)
26464 || !is_tagged_type (TREE_TYPE (decl
))
26465 || DECL_IS_UNDECLARED_BUILTIN (decl
)
26466 || is_redundant_typedef (decl
)
26467 /* It looks like Ada produces TYPE_DECLs that are very similar
26468 to C++ naming typedefs but that have different
26469 semantics. Let's be specific to c++ for now. */
26473 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
26474 && TYPE_NAME (TREE_TYPE (decl
)) == decl
26475 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
26476 != TYPE_NAME (TREE_TYPE (decl
))));
26479 /* Looks up the DIE for a context. */
26481 static inline dw_die_ref
26482 lookup_context_die (tree context
)
26486 /* Find die that represents this context. */
26487 if (TYPE_P (context
))
26489 context
= TYPE_MAIN_VARIANT (context
);
26490 dw_die_ref ctx
= lookup_type_die (context
);
26493 return strip_naming_typedef (context
, ctx
);
26496 return lookup_decl_die (context
);
26498 return comp_unit_die ();
26501 /* Returns the DIE for a context. */
26503 static inline dw_die_ref
26504 get_context_die (tree context
)
26508 /* Find die that represents this context. */
26509 if (TYPE_P (context
))
26511 context
= TYPE_MAIN_VARIANT (context
);
26512 return strip_naming_typedef (context
, force_type_die (context
));
26515 return force_decl_die (context
);
26517 return comp_unit_die ();
26520 /* Returns the DIE for decl. A DIE will always be returned. */
26523 force_decl_die (tree decl
)
26525 dw_die_ref decl_die
;
26526 unsigned saved_external_flag
;
26527 tree save_fn
= NULL_TREE
;
26528 decl_die
= lookup_decl_die (decl
);
26531 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
26533 decl_die
= lookup_decl_die (decl
);
26537 switch (TREE_CODE (decl
))
26539 case FUNCTION_DECL
:
26540 /* Clear current_function_decl, so that gen_subprogram_die thinks
26541 that this is a declaration. At this point, we just want to force
26542 declaration die. */
26543 save_fn
= current_function_decl
;
26544 current_function_decl
= NULL_TREE
;
26545 gen_subprogram_die (decl
, context_die
);
26546 current_function_decl
= save_fn
;
26550 /* Set external flag to force declaration die. Restore it after
26551 gen_decl_die() call. */
26552 saved_external_flag
= DECL_EXTERNAL (decl
);
26553 DECL_EXTERNAL (decl
) = 1;
26554 gen_decl_die (decl
, NULL
, NULL
, context_die
);
26555 DECL_EXTERNAL (decl
) = saved_external_flag
;
26558 case NAMESPACE_DECL
:
26559 if (dwarf_version
>= 3 || !dwarf_strict
)
26560 dwarf2out_decl (decl
);
26562 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
26563 decl_die
= comp_unit_die ();
26567 /* Enumerators shouldn't need force_decl_die. */
26568 gcc_assert (DECL_CONTEXT (decl
) == NULL_TREE
26569 || TREE_CODE (DECL_CONTEXT (decl
)) != ENUMERAL_TYPE
);
26570 gen_decl_die (decl
, NULL
, NULL
, context_die
);
26573 case TRANSLATION_UNIT_DECL
:
26574 decl_die
= comp_unit_die ();
26578 gcc_unreachable ();
26581 /* We should be able to find the DIE now. */
26583 decl_die
= lookup_decl_die (decl
);
26584 gcc_assert (decl_die
);
26590 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
26591 always returned. */
26594 force_type_die (tree type
)
26596 dw_die_ref type_die
;
26598 type_die
= lookup_type_die (type
);
26601 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
26603 type_die
= modified_type_die (type
, TYPE_QUALS_NO_ADDR_SPACE (type
),
26604 false, context_die
);
26605 gcc_assert (type_die
);
26610 /* Force out any required namespaces to be able to output DECL,
26611 and return the new context_die for it, if it's changed. */
26614 setup_namespace_context (tree thing
, dw_die_ref context_die
)
26616 tree context
= (DECL_P (thing
)
26617 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
26618 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
26619 /* Force out the namespace. */
26620 context_die
= force_decl_die (context
);
26622 return context_die
;
26625 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
26626 type) within its namespace, if appropriate.
26628 For compatibility with older debuggers, namespace DIEs only contain
26629 declarations; all definitions are emitted at CU scope, with
26630 DW_AT_specification pointing to the declaration (like with class
26634 declare_in_namespace (tree thing
, dw_die_ref context_die
)
26636 dw_die_ref ns_context
;
26638 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
26639 return context_die
;
26641 /* External declarations in the local scope only need to be emitted
26642 once, not once in the namespace and once in the scope.
26644 This avoids declaring the `extern' below in the
26645 namespace DIE as well as in the innermost scope:
26658 if (DECL_P (thing
) && DECL_EXTERNAL (thing
) && local_scope_p (context_die
))
26659 return context_die
;
26661 /* If this decl is from an inlined function, then don't try to emit it in its
26662 namespace, as we will get confused. It would have already been emitted
26663 when the abstract instance of the inline function was emitted anyways. */
26664 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
26665 return context_die
;
26667 ns_context
= setup_namespace_context (thing
, context_die
);
26669 if (ns_context
!= context_die
)
26671 if (is_fortran () || is_dlang ())
26673 if (DECL_P (thing
))
26674 gen_decl_die (thing
, NULL
, NULL
, ns_context
);
26676 gen_type_die (thing
, ns_context
);
26678 return context_die
;
26681 /* Generate a DIE for a namespace or namespace alias. */
26684 gen_namespace_die (tree decl
, dw_die_ref context_die
)
26686 dw_die_ref namespace_die
;
26688 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
26689 they are an alias of. */
26690 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
26692 /* Output a real namespace or module. */
26693 context_die
= setup_namespace_context (decl
, comp_unit_die ());
26694 namespace_die
= new_die (is_fortran () || is_dlang ()
26695 ? DW_TAG_module
: DW_TAG_namespace
,
26696 context_die
, decl
);
26697 /* For Fortran modules defined in different CU don't add src coords. */
26698 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
26700 const char *name
= dwarf2_name (decl
, 0);
26702 add_name_attribute (namespace_die
, name
);
26705 add_name_and_src_coords_attributes (namespace_die
, decl
);
26706 if (DECL_EXTERNAL (decl
))
26707 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
26708 equate_decl_number_to_die (decl
, namespace_die
);
26712 /* Output a namespace alias. */
26714 /* Force out the namespace we are an alias of, if necessary. */
26715 dw_die_ref origin_die
26716 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
26718 if (DECL_FILE_SCOPE_P (decl
)
26719 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
26720 context_die
= setup_namespace_context (decl
, comp_unit_die ());
26721 /* Now create the namespace alias DIE. */
26722 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
26723 add_name_and_src_coords_attributes (namespace_die
, decl
);
26724 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
26725 equate_decl_number_to_die (decl
, namespace_die
);
26727 if ((dwarf_version
>= 5 || !dwarf_strict
)
26728 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
26729 DW_AT_export_symbols
) == 1)
26730 add_AT_flag (namespace_die
, DW_AT_export_symbols
, 1);
26732 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
26733 if (want_pubnames ())
26734 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
26737 /* Generate Dwarf debug information for a decl described by DECL.
26738 The return value is currently only meaningful for PARM_DECLs,
26739 for all other decls it returns NULL.
26741 If DECL is a FIELD_DECL, CTX is required: see the comment for VLR_CONTEXT.
26742 It can be NULL otherwise. */
26745 gen_decl_die (tree decl
, tree origin
, struct vlr_context
*ctx
,
26746 dw_die_ref context_die
)
26748 tree decl_or_origin
= decl
? decl
: origin
;
26749 tree class_origin
= NULL
, ultimate_origin
;
26751 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
26754 switch (TREE_CODE (decl_or_origin
))
26760 if (!is_fortran () && !is_ada () && !is_dlang ())
26762 /* The individual enumerators of an enum type get output when we output
26763 the Dwarf representation of the relevant enum type itself. */
26767 /* Emit its type. */
26768 gen_type_die (TREE_TYPE (decl
), context_die
);
26770 /* And its containing namespace. */
26771 context_die
= declare_in_namespace (decl
, context_die
);
26773 gen_const_die (decl
, context_die
);
26776 case FUNCTION_DECL
:
26779 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
26780 on local redeclarations of global functions. That seems broken. */
26781 if (current_function_decl
!= decl
)
26782 /* This is only a declaration. */;
26785 /* We should have abstract copies already and should not generate
26786 stray type DIEs in late LTO dumping. */
26790 /* If we're emitting a clone, emit info for the abstract instance. */
26791 else if (origin
|| DECL_ORIGIN (decl
) != decl
)
26792 dwarf2out_abstract_function (origin
26793 ? DECL_ORIGIN (origin
)
26794 : DECL_ABSTRACT_ORIGIN (decl
));
26796 /* If we're emitting a possibly inlined function emit it as
26797 abstract instance. */
26798 else if (cgraph_function_possibly_inlined_p (decl
)
26799 && ! DECL_ABSTRACT_P (decl
)
26800 && ! class_or_namespace_scope_p (context_die
)
26801 /* dwarf2out_abstract_function won't emit a die if this is just
26802 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
26803 that case, because that works only if we have a die. */
26804 && DECL_INITIAL (decl
) != NULL_TREE
)
26805 dwarf2out_abstract_function (decl
);
26807 /* Otherwise we're emitting the primary DIE for this decl. */
26808 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
26810 /* Before we describe the FUNCTION_DECL itself, make sure that we
26811 have its containing type. */
26813 origin
= decl_class_context (decl
);
26814 if (origin
!= NULL_TREE
)
26815 gen_type_die (origin
, context_die
);
26817 /* And its return type. */
26818 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
26820 /* And its virtual context. */
26821 if (DECL_VINDEX (decl
) != NULL_TREE
)
26822 gen_type_die (DECL_CONTEXT (decl
), context_die
);
26824 /* Make sure we have a member DIE for decl. */
26825 if (origin
!= NULL_TREE
)
26826 gen_type_die_for_member (origin
, decl
, context_die
);
26828 /* And its containing namespace. */
26829 context_die
= declare_in_namespace (decl
, context_die
);
26832 /* Now output a DIE to represent the function itself. */
26834 gen_subprogram_die (decl
, context_die
);
26838 /* If we are in terse mode, don't generate any DIEs to represent any
26839 actual typedefs. */
26840 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
26843 /* In the special case of a TYPE_DECL node representing the declaration
26844 of some type tag, if the given TYPE_DECL is marked as having been
26845 instantiated from some other (original) TYPE_DECL node (e.g. one which
26846 was generated within the original definition of an inline function) we
26847 used to generate a special (abbreviated) DW_TAG_structure_type,
26848 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
26849 should be actually referencing those DIEs, as variable DIEs with that
26850 type would be emitted already in the abstract origin, so it was always
26851 removed during unused type prunning. Don't add anything in this
26853 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
26856 if (is_redundant_typedef (decl
))
26857 gen_type_die (TREE_TYPE (decl
), context_die
);
26859 /* Output a DIE to represent the typedef itself. */
26860 gen_typedef_die (decl
, context_die
);
26864 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
26865 gen_label_die (decl
, context_die
);
26870 /* If we are in terse mode, don't generate any DIEs to represent any
26871 variable declarations or definitions unless it is external. */
26872 if (debug_info_level
< DINFO_LEVEL_TERSE
26873 || (debug_info_level
== DINFO_LEVEL_TERSE
26874 && !TREE_PUBLIC (decl_or_origin
)))
26877 if (debug_info_level
> DINFO_LEVEL_TERSE
)
26879 /* Avoid generating stray type DIEs during late dwarf dumping.
26880 All types have been dumped early. */
26882 /* ??? But in LTRANS we cannot annotate early created variably
26883 modified type DIEs without copying them and adjusting all
26884 references to them. Dump them again as happens for inlining
26885 which copies both the decl and the types. */
26886 /* ??? And even non-LTO needs to re-visit type DIEs to fill
26887 in VLA bound information for example. */
26888 || (decl
&& variably_modified_type_p (TREE_TYPE (decl
),
26889 current_function_decl
)))
26891 /* Output any DIEs that are needed to specify the type of this data
26893 if (decl_by_reference_p (decl_or_origin
))
26894 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
26896 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
26901 /* And its containing type. */
26902 class_origin
= decl_class_context (decl_or_origin
);
26903 if (class_origin
!= NULL_TREE
)
26904 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
26906 /* And its containing namespace. */
26907 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
26911 /* Now output the DIE to represent the data object itself. This gets
26912 complicated because of the possibility that the VAR_DECL really
26913 represents an inlined instance of a formal parameter for an inline
26915 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
26916 if (ultimate_origin
!= NULL_TREE
26917 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
26918 gen_formal_parameter_die (decl
, origin
,
26919 true /* Emit name attribute. */,
26922 gen_variable_die (decl
, origin
, context_die
);
26926 gcc_assert (ctx
!= NULL
&& ctx
->struct_type
!= NULL
);
26927 /* Ignore the nameless fields that are used to skip bits but handle C++
26928 anonymous unions and structs. */
26929 if (DECL_NAME (decl
) != NULL_TREE
26930 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
26931 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
26933 gen_type_die (member_declared_type (decl
), context_die
);
26934 gen_field_die (decl
, ctx
, context_die
);
26939 /* Avoid generating stray type DIEs during late dwarf dumping.
26940 All types have been dumped early. */
26942 /* ??? But in LTRANS we cannot annotate early created variably
26943 modified type DIEs without copying them and adjusting all
26944 references to them. Dump them again as happens for inlining
26945 which copies both the decl and the types. */
26946 /* ??? And even non-LTO needs to re-visit type DIEs to fill
26947 in VLA bound information for example. */
26948 || (decl
&& variably_modified_type_p (TREE_TYPE (decl
),
26949 current_function_decl
)))
26951 if (DECL_BY_REFERENCE (decl_or_origin
))
26952 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
26954 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
26956 return gen_formal_parameter_die (decl
, origin
,
26957 true /* Emit name attribute. */,
26960 case NAMESPACE_DECL
:
26961 if (dwarf_version
>= 3 || !dwarf_strict
)
26962 gen_namespace_die (decl
, context_die
);
26965 case IMPORTED_DECL
:
26966 dwarf2out_imported_module_or_decl_1 (decl
, DECL_NAME (decl
),
26967 DECL_CONTEXT (decl
), context_die
);
26970 case NAMELIST_DECL
:
26971 gen_namelist_decl (DECL_NAME (decl
), context_die
,
26972 NAMELIST_DECL_ASSOCIATED_DECL (decl
));
26976 /* Probably some frontend-internal decl. Assume we don't care. */
26977 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
26984 /* Output initial debug information for global DECL. Called at the
26985 end of the parsing process.
26987 This is the initial debug generation process. As such, the DIEs
26988 generated may be incomplete. A later debug generation pass
26989 (dwarf2out_late_global_decl) will augment the information generated
26990 in this pass (e.g., with complete location info). */
26993 dwarf2out_early_global_decl (tree decl
)
26997 /* gen_decl_die() will set DECL_ABSTRACT because
26998 cgraph_function_possibly_inlined_p() returns true. This is in
26999 turn will cause DW_AT_inline attributes to be set.
27001 This happens because at early dwarf generation, there is no
27002 cgraph information, causing cgraph_function_possibly_inlined_p()
27003 to return true. Trick cgraph_function_possibly_inlined_p()
27004 while we generate dwarf early. */
27005 bool save
= symtab
->global_info_ready
;
27006 symtab
->global_info_ready
= true;
27008 /* We don't handle TYPE_DECLs. If required, they'll be reached via
27009 other DECLs and they can point to template types or other things
27010 that dwarf2out can't handle when done via dwarf2out_decl. */
27011 if (TREE_CODE (decl
) != TYPE_DECL
27012 && TREE_CODE (decl
) != PARM_DECL
)
27014 if (TREE_CODE (decl
) == FUNCTION_DECL
)
27016 tree save_fndecl
= current_function_decl
;
27018 /* For nested functions, make sure we have DIEs for the parents first
27019 so that all nested DIEs are generated at the proper scope in the
27021 tree context
= decl_function_context (decl
);
27022 if (context
!= NULL
)
27024 dw_die_ref context_die
= lookup_decl_die (context
);
27025 current_function_decl
= context
;
27027 /* Avoid emitting DIEs multiple times, but still process CONTEXT
27028 enough so that it lands in its own context. This avoids type
27029 pruning issues later on. */
27030 if (context_die
== NULL
|| is_declaration_die (context_die
))
27031 dwarf2out_early_global_decl (context
);
27034 /* Emit an abstract origin of a function first. This happens
27035 with C++ constructor clones for example and makes
27036 dwarf2out_abstract_function happy which requires the early
27037 DIE of the abstract instance to be present. */
27038 tree origin
= DECL_ABSTRACT_ORIGIN (decl
);
27039 dw_die_ref origin_die
;
27041 /* Do not emit the DIE multiple times but make sure to
27042 process it fully here in case we just saw a declaration. */
27043 && ((origin_die
= lookup_decl_die (origin
)) == NULL
27044 || is_declaration_die (origin_die
)))
27046 current_function_decl
= origin
;
27047 dwarf2out_decl (origin
);
27050 /* Emit the DIE for decl but avoid doing that multiple times. */
27051 dw_die_ref old_die
;
27052 if ((old_die
= lookup_decl_die (decl
)) == NULL
27053 || is_declaration_die (old_die
))
27055 current_function_decl
= decl
;
27056 dwarf2out_decl (decl
);
27059 current_function_decl
= save_fndecl
;
27062 dwarf2out_decl (decl
);
27064 symtab
->global_info_ready
= save
;
27067 /* Return whether EXPR is an expression with the following pattern:
27068 INDIRECT_REF (NOP_EXPR (INTEGER_CST)). */
27071 is_trivial_indirect_ref (tree expr
)
27073 if (expr
== NULL_TREE
|| TREE_CODE (expr
) != INDIRECT_REF
)
27076 tree nop
= TREE_OPERAND (expr
, 0);
27077 if (nop
== NULL_TREE
|| TREE_CODE (nop
) != NOP_EXPR
)
27080 tree int_cst
= TREE_OPERAND (nop
, 0);
27081 return int_cst
!= NULL_TREE
&& TREE_CODE (int_cst
) == INTEGER_CST
;
27084 /* Output debug information for global decl DECL. Called from
27085 toplev.c after compilation proper has finished. */
27088 dwarf2out_late_global_decl (tree decl
)
27090 /* Fill-in any location information we were unable to determine
27091 on the first pass. */
27094 dw_die_ref die
= lookup_decl_die (decl
);
27096 /* We may have to generate full debug late for LTO in case debug
27097 was not enabled at compile-time or the target doesn't support
27098 the LTO early debug scheme. */
27099 if (! die
&& in_lto_p
)
27100 dwarf2out_decl (decl
);
27103 /* We get called via the symtab code invoking late_global_decl
27104 for symbols that are optimized out.
27106 Do not add locations for those, except if they have a
27107 DECL_VALUE_EXPR, in which case they are relevant for debuggers.
27108 Still don't add a location if the DECL_VALUE_EXPR is not a trivial
27109 INDIRECT_REF expression, as this could generate relocations to
27110 text symbols in LTO object files, which is invalid. */
27111 varpool_node
*node
= varpool_node::get (decl
);
27112 if ((! node
|| ! node
->definition
)
27113 && ! (DECL_HAS_VALUE_EXPR_P (decl
)
27114 && is_trivial_indirect_ref (DECL_VALUE_EXPR (decl
))))
27115 tree_add_const_value_attribute_for_decl (die
, decl
);
27117 add_location_or_const_value_attribute (die
, decl
, false);
27122 /* Output debug information for type decl DECL. Called from toplev.c
27123 and from language front ends (to record built-in types). */
27125 dwarf2out_type_decl (tree decl
, int local
)
27130 dwarf2out_decl (decl
);
27134 /* Output debug information for imported module or decl DECL.
27135 NAME is non-NULL name in the lexical block if the decl has been renamed.
27136 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
27137 that DECL belongs to.
27138 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
27140 dwarf2out_imported_module_or_decl_1 (tree decl
,
27142 tree lexical_block
,
27143 dw_die_ref lexical_block_die
)
27145 expanded_location xloc
;
27146 dw_die_ref imported_die
= NULL
;
27147 dw_die_ref at_import_die
;
27149 if (TREE_CODE (decl
) == IMPORTED_DECL
)
27151 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
27152 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
27156 xloc
= expand_location (input_location
);
27158 if (TREE_CODE (decl
) == TYPE_DECL
)
27160 at_import_die
= force_type_die (TREE_TYPE (decl
));
27161 /* For namespace N { typedef void T; } using N::T; base_type_die
27162 returns NULL, but DW_TAG_imported_declaration requires
27163 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
27164 if (!at_import_die
)
27166 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
27167 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
27168 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
27169 gcc_assert (at_import_die
);
27174 at_import_die
= lookup_decl_die (decl
);
27175 if (!at_import_die
)
27177 /* If we're trying to avoid duplicate debug info, we may not have
27178 emitted the member decl for this field. Emit it now. */
27179 if (TREE_CODE (decl
) == FIELD_DECL
)
27181 tree type
= DECL_CONTEXT (decl
);
27183 if (TYPE_CONTEXT (type
)
27184 && TYPE_P (TYPE_CONTEXT (type
))
27185 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
27186 DINFO_USAGE_DIR_USE
))
27188 gen_type_die_for_member (type
, decl
,
27189 get_context_die (TYPE_CONTEXT (type
)));
27191 if (TREE_CODE (decl
) == CONST_DECL
)
27193 /* Individual enumerators of an enum type do not get output here
27194 (see gen_decl_die), so we cannot call force_decl_die. */
27195 if (!is_fortran () && !is_ada () && !is_dlang ())
27198 if (TREE_CODE (decl
) == NAMELIST_DECL
)
27199 at_import_die
= gen_namelist_decl (DECL_NAME (decl
),
27200 get_context_die (DECL_CONTEXT (decl
)),
27203 at_import_die
= force_decl_die (decl
);
27207 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
27209 if (dwarf_version
>= 3 || !dwarf_strict
)
27210 imported_die
= new_die (DW_TAG_imported_module
,
27217 imported_die
= new_die (DW_TAG_imported_declaration
,
27221 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
27222 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
27223 if (debug_column_info
&& xloc
.column
)
27224 add_AT_unsigned (imported_die
, DW_AT_decl_column
, xloc
.column
);
27226 add_AT_string (imported_die
, DW_AT_name
,
27227 IDENTIFIER_POINTER (name
));
27228 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
27231 /* Output debug information for imported module or decl DECL.
27232 NAME is non-NULL name in context if the decl has been renamed.
27233 CHILD is true if decl is one of the renamed decls as part of
27234 importing whole module.
27235 IMPLICIT is set if this hook is called for an implicit import
27236 such as inline namespace. */
27239 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
27240 bool child
, bool implicit
)
27242 /* dw_die_ref at_import_die; */
27243 dw_die_ref scope_die
;
27245 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
27250 /* For DWARF5, just DW_AT_export_symbols on the DW_TAG_namespace
27251 should be enough, for DWARF4 and older even if we emit as extension
27252 DW_AT_export_symbols add the implicit DW_TAG_imported_module anyway
27253 for the benefit of consumers unaware of DW_AT_export_symbols. */
27255 && dwarf_version
>= 5
27256 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
27257 DW_AT_export_symbols
) == 1)
27262 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
27263 We need decl DIE for reference and scope die. First, get DIE for the decl
27266 /* Get the scope die for decl context. Use comp_unit_die for global module
27267 or decl. If die is not found for non globals, force new die. */
27269 && TYPE_P (context
)
27270 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
27273 scope_die
= get_context_die (context
);
27277 /* DW_TAG_imported_module was introduced in the DWARFv3 specification, so
27278 there is nothing we can do, here. */
27279 if (dwarf_version
< 3 && dwarf_strict
)
27282 gcc_assert (scope_die
->die_child
);
27283 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
27284 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
27285 scope_die
= scope_die
->die_child
;
27288 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
27289 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
27292 /* Output debug information for namelists. */
27295 gen_namelist_decl (tree name
, dw_die_ref scope_die
, tree item_decls
)
27297 dw_die_ref nml_die
, nml_item_die
, nml_item_ref_die
;
27301 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
27304 gcc_assert (scope_die
!= NULL
);
27305 nml_die
= new_die (DW_TAG_namelist
, scope_die
, NULL
);
27306 add_AT_string (nml_die
, DW_AT_name
, IDENTIFIER_POINTER (name
));
27308 /* If there are no item_decls, we have a nondefining namelist, e.g.
27309 with USE association; hence, set DW_AT_declaration. */
27310 if (item_decls
== NULL_TREE
)
27312 add_AT_flag (nml_die
, DW_AT_declaration
, 1);
27316 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls
), i
, value
)
27318 nml_item_ref_die
= lookup_decl_die (value
);
27319 if (!nml_item_ref_die
)
27320 nml_item_ref_die
= force_decl_die (value
);
27322 nml_item_die
= new_die (DW_TAG_namelist_item
, nml_die
, NULL
);
27323 add_AT_die_ref (nml_item_die
, DW_AT_namelist_items
, nml_item_ref_die
);
27329 /* Write the debugging output for DECL and return the DIE. */
27332 dwarf2out_decl (tree decl
)
27334 dw_die_ref context_die
= comp_unit_die ();
27336 switch (TREE_CODE (decl
))
27341 case FUNCTION_DECL
:
27342 /* If we're a nested function, initially use a parent of NULL; if we're
27343 a plain function, this will be fixed up in decls_for_scope. If
27344 we're a method, it will be ignored, since we already have a DIE.
27345 Avoid doing this late though since clones of class methods may
27346 otherwise end up in limbo and create type DIEs late. */
27348 && decl_function_context (decl
)
27349 /* But if we're in terse mode, we don't care about scope. */
27350 && debug_info_level
> DINFO_LEVEL_TERSE
)
27351 context_die
= NULL
;
27355 /* For local statics lookup proper context die. */
27356 if (local_function_static (decl
))
27357 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
27359 /* If we are in terse mode, don't generate any DIEs to represent any
27360 variable declarations or definitions unless it is external. */
27361 if (debug_info_level
< DINFO_LEVEL_TERSE
27362 || (debug_info_level
== DINFO_LEVEL_TERSE
27363 && !TREE_PUBLIC (decl
)))
27368 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
27370 if (!is_fortran () && !is_ada () && !is_dlang ())
27372 if (TREE_STATIC (decl
) && decl_function_context (decl
))
27373 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
27376 case NAMESPACE_DECL
:
27377 case IMPORTED_DECL
:
27378 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
27380 if (lookup_decl_die (decl
) != NULL
)
27385 /* Don't emit stubs for types unless they are needed by other DIEs. */
27386 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
27389 /* Don't bother trying to generate any DIEs to represent any of the
27390 normal built-in types for the language we are compiling. */
27391 if (DECL_IS_UNDECLARED_BUILTIN (decl
))
27394 /* If we are in terse mode, don't generate any DIEs for types. */
27395 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
27398 /* If we're a function-scope tag, initially use a parent of NULL;
27399 this will be fixed up in decls_for_scope. */
27400 if (decl_function_context (decl
))
27401 context_die
= NULL
;
27405 case NAMELIST_DECL
:
27412 gen_decl_die (decl
, NULL
, NULL
, context_die
);
27416 dw_die_ref die
= lookup_decl_die (decl
);
27422 /* Write the debugging output for DECL. */
27425 dwarf2out_function_decl (tree decl
)
27427 dwarf2out_decl (decl
);
27428 call_arg_locations
= NULL
;
27429 call_arg_loc_last
= NULL
;
27430 call_site_count
= -1;
27431 tail_call_site_count
= -1;
27432 decl_loc_table
->empty ();
27433 cached_dw_loc_list_table
->empty ();
27436 /* Output a marker (i.e. a label) for the beginning of the generated code for
27437 a lexical block. */
27440 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
27441 unsigned int blocknum
)
27443 switch_to_section (current_function_section ());
27444 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
27447 /* Output a marker (i.e. a label) for the end of the generated code for a
27451 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
27453 switch_to_section (current_function_section ());
27454 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
27457 /* Returns nonzero if it is appropriate not to emit any debugging
27458 information for BLOCK, because it doesn't contain any instructions.
27460 Don't allow this for blocks with nested functions or local classes
27461 as we would end up with orphans, and in the presence of scheduling
27462 we may end up calling them anyway. */
27465 dwarf2out_ignore_block (const_tree block
)
27470 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
27471 if (TREE_CODE (decl
) == FUNCTION_DECL
27472 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
27474 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
27476 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
27477 if (TREE_CODE (decl
) == FUNCTION_DECL
27478 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
27485 /* Hash table routines for file_hash. */
27488 dwarf_file_hasher::equal (dwarf_file_data
*p1
, const char *p2
)
27490 return filename_cmp (p1
->key
, p2
) == 0;
27494 dwarf_file_hasher::hash (dwarf_file_data
*p
)
27496 return htab_hash_string (p
->key
);
27499 /* Lookup FILE_NAME (in the list of filenames that we know about here in
27500 dwarf2out.c) and return its "index". The index of each (known) filename is
27501 just a unique number which is associated with only that one filename. We
27502 need such numbers for the sake of generating labels (in the .debug_sfnames
27503 section) and references to those files numbers (in the .debug_srcinfo
27504 and .debug_macinfo sections). If the filename given as an argument is not
27505 found in our current list, add it to the list and assign it the next
27506 available unique index number. */
27508 static struct dwarf_file_data
*
27509 lookup_filename (const char *file_name
)
27511 struct dwarf_file_data
* created
;
27517 file_name
= "<stdin>";
27519 dwarf_file_data
**slot
27520 = file_table
->find_slot_with_hash (file_name
, htab_hash_string (file_name
),
27525 created
= ggc_alloc
<dwarf_file_data
> ();
27526 created
->key
= file_name
;
27527 created
->filename
= remap_debug_filename (file_name
);
27528 created
->emitted_number
= 0;
27533 /* If the assembler will construct the file table, then translate the compiler
27534 internal file table number into the assembler file table number, and emit
27535 a .file directive if we haven't already emitted one yet. The file table
27536 numbers are different because we prune debug info for unused variables and
27537 types, which may include filenames. */
27540 maybe_emit_file (struct dwarf_file_data
* fd
)
27542 if (! fd
->emitted_number
)
27544 if (last_emitted_file
)
27545 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
27547 fd
->emitted_number
= 1;
27548 last_emitted_file
= fd
;
27550 if (output_asm_line_debug_info ())
27552 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
27553 output_quoted_string (asm_out_file
, fd
->filename
);
27554 fputc ('\n', asm_out_file
);
27558 return fd
->emitted_number
;
27561 /* Schedule generation of a DW_AT_const_value attribute to DIE.
27562 That generation should happen after function debug info has been
27563 generated. The value of the attribute is the constant value of ARG. */
27566 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
27568 die_arg_entry entry
;
27573 gcc_assert (early_dwarf
);
27575 if (!tmpl_value_parm_die_table
)
27576 vec_alloc (tmpl_value_parm_die_table
, 32);
27580 vec_safe_push (tmpl_value_parm_die_table
, entry
);
27583 /* Return TRUE if T is an instance of generic type, FALSE
27587 generic_type_p (tree t
)
27589 if (t
== NULL_TREE
|| !TYPE_P (t
))
27591 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
27594 /* Schedule the generation of the generic parameter dies for the
27595 instance of generic type T. The proper generation itself is later
27596 done by gen_scheduled_generic_parms_dies. */
27599 schedule_generic_params_dies_gen (tree t
)
27601 if (!generic_type_p (t
))
27604 gcc_assert (early_dwarf
);
27606 if (!generic_type_instances
)
27607 vec_alloc (generic_type_instances
, 256);
27609 vec_safe_push (generic_type_instances
, t
);
27612 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
27613 by append_entry_to_tmpl_value_parm_die_table. This function must
27614 be called after function DIEs have been generated. */
27617 gen_remaining_tmpl_value_param_die_attribute (void)
27619 if (tmpl_value_parm_die_table
)
27624 /* We do this in two phases - first get the cases we can
27625 handle during early-finish, preserving those we cannot
27626 (containing symbolic constants where we don't yet know
27627 whether we are going to output the referenced symbols).
27628 For those we try again at late-finish. */
27630 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
27632 if (!e
->die
->removed
27633 && !tree_add_const_value_attribute (e
->die
, e
->arg
))
27635 dw_loc_descr_ref loc
= NULL
;
27637 && (dwarf_version
>= 5 || !dwarf_strict
))
27638 loc
= loc_descriptor_from_tree (e
->arg
, 2, NULL
);
27640 add_AT_loc (e
->die
, DW_AT_location
, loc
);
27642 (*tmpl_value_parm_die_table
)[j
++] = *e
;
27645 tmpl_value_parm_die_table
->truncate (j
);
27649 /* Generate generic parameters DIEs for instances of generic types
27650 that have been previously scheduled by
27651 schedule_generic_params_dies_gen. This function must be called
27652 after all the types of the CU have been laid out. */
27655 gen_scheduled_generic_parms_dies (void)
27660 if (!generic_type_instances
)
27663 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
27664 if (COMPLETE_TYPE_P (t
))
27665 gen_generic_params_dies (t
);
27667 generic_type_instances
= NULL
;
27671 /* Replace DW_AT_name for the decl with name. */
27674 dwarf2out_set_name (tree decl
, tree name
)
27677 dw_attr_node
*attr
;
27680 die
= TYPE_SYMTAB_DIE (decl
);
27684 dname
= dwarf2_name (name
, 0);
27688 attr
= get_AT (die
, DW_AT_name
);
27691 struct indirect_string_node
*node
;
27693 node
= find_AT_string (dname
);
27694 /* replace the string. */
27695 attr
->dw_attr_val
.v
.val_str
= node
;
27699 add_name_attribute (die
, dname
);
27702 /* True if before or during processing of the first function being emitted. */
27703 static bool in_first_function_p
= true;
27704 /* True if loc_note during dwarf2out_var_location call might still be
27705 before first real instruction at address equal to .Ltext0. */
27706 static bool maybe_at_text_label_p
= true;
27707 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
27708 static unsigned int first_loclabel_num_not_at_text_label
;
27710 /* Look ahead for a real insn. */
27713 dwarf2out_next_real_insn (rtx_insn
*loc_note
)
27715 rtx_insn
*next_real
= NEXT_INSN (loc_note
);
27718 if (INSN_P (next_real
))
27721 next_real
= NEXT_INSN (next_real
);
27726 /* Called by the final INSN scan whenever we see a var location. We
27727 use it to drop labels in the right places, and throw the location in
27728 our lookup table. */
27731 dwarf2out_var_location (rtx_insn
*loc_note
)
27733 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
27734 struct var_loc_node
*newloc
;
27735 rtx_insn
*next_real
;
27736 rtx_insn
*call_insn
= NULL
;
27737 static const char *last_label
;
27738 static const char *last_postcall_label
;
27739 static bool last_in_cold_section_p
;
27740 static rtx_insn
*expected_next_loc_note
;
27743 var_loc_view view
= 0;
27745 if (!NOTE_P (loc_note
))
27747 if (CALL_P (loc_note
))
27749 maybe_reset_location_view (loc_note
, cur_line_info_table
);
27751 if (SIBLING_CALL_P (loc_note
))
27752 tail_call_site_count
++;
27753 if (find_reg_note (loc_note
, REG_CALL_ARG_LOCATION
, NULL_RTX
))
27755 call_insn
= loc_note
;
27759 next_real
= dwarf2out_next_real_insn (call_insn
);
27760 cached_next_real_insn
= NULL
;
27763 if (optimize
== 0 && !flag_var_tracking
)
27765 /* When the var-tracking pass is not running, there is no note
27766 for indirect calls whose target is compile-time known. In this
27767 case, process such calls specifically so that we generate call
27768 sites for them anyway. */
27769 rtx x
= PATTERN (loc_note
);
27770 if (GET_CODE (x
) == PARALLEL
)
27771 x
= XVECEXP (x
, 0, 0);
27772 if (GET_CODE (x
) == SET
)
27774 if (GET_CODE (x
) == CALL
)
27777 || GET_CODE (XEXP (x
, 0)) != SYMBOL_REF
27778 || !SYMBOL_REF_DECL (XEXP (x
, 0))
27779 || (TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0)))
27782 call_insn
= loc_note
;
27786 next_real
= dwarf2out_next_real_insn (call_insn
);
27787 cached_next_real_insn
= NULL
;
27792 else if (!debug_variable_location_views
)
27793 gcc_unreachable ();
27795 maybe_reset_location_view (loc_note
, cur_line_info_table
);
27800 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
27801 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
27804 /* Optimize processing a large consecutive sequence of location
27805 notes so we don't spend too much time in next_real_insn. If the
27806 next insn is another location note, remember the next_real_insn
27807 calculation for next time. */
27808 next_real
= cached_next_real_insn
;
27811 if (expected_next_loc_note
!= loc_note
)
27816 next_real
= dwarf2out_next_real_insn (loc_note
);
27820 rtx_insn
*next_note
= NEXT_INSN (loc_note
);
27821 while (next_note
!= next_real
)
27823 if (! next_note
->deleted ()
27824 && NOTE_P (next_note
)
27825 && NOTE_KIND (next_note
) == NOTE_INSN_VAR_LOCATION
)
27827 next_note
= NEXT_INSN (next_note
);
27830 if (next_note
== next_real
)
27831 cached_next_real_insn
= NULL
;
27834 expected_next_loc_note
= next_note
;
27835 cached_next_real_insn
= next_real
;
27839 cached_next_real_insn
= NULL
;
27841 /* If there are no instructions which would be affected by this note,
27842 don't do anything. */
27844 && next_real
== NULL_RTX
27845 && !NOTE_DURING_CALL_P (loc_note
))
27850 if (next_real
== NULL_RTX
)
27851 next_real
= get_last_insn ();
27853 /* If there were any real insns between note we processed last time
27854 and this note (or if it is the first note), clear
27855 last_{,postcall_}label so that they are not reused this time. */
27856 if (last_var_location_insn
== NULL_RTX
27857 || last_var_location_insn
!= next_real
27858 || last_in_cold_section_p
!= in_cold_section_p
)
27861 last_postcall_label
= NULL
;
27867 = NOTE_DURING_CALL_P (loc_note
) ? last_postcall_label
: last_label
;
27868 view
= cur_line_info_table
->view
;
27869 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
27870 newloc
= add_var_loc_to_decl (decl
, loc_note
, label
, view
);
27871 if (newloc
== NULL
)
27880 /* If there were no real insns between note we processed last time
27881 and this note, use the label we emitted last time. Otherwise
27882 create a new label and emit it. */
27883 if (last_label
== NULL
)
27885 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
27886 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
27888 last_label
= ggc_strdup (loclabel
);
27889 /* See if loclabel might be equal to .Ltext0. If yes,
27890 bump first_loclabel_num_not_at_text_label. */
27891 if (!have_multiple_function_sections
27892 && in_first_function_p
27893 && maybe_at_text_label_p
)
27895 static rtx_insn
*last_start
;
27897 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
27898 if (insn
== last_start
)
27900 else if (!NONDEBUG_INSN_P (insn
))
27904 rtx body
= PATTERN (insn
);
27905 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
27907 /* Inline asm could occupy zero bytes. */
27908 else if (GET_CODE (body
) == ASM_INPUT
27909 || asm_noperands (body
) >= 0)
27911 #ifdef HAVE_ATTR_length /* ??? We don't include insn-attr.h. */
27912 else if (HAVE_ATTR_length
&& get_attr_min_length (insn
) == 0)
27917 /* Assume insn has non-zero length. */
27918 maybe_at_text_label_p
= false;
27922 if (maybe_at_text_label_p
)
27924 last_start
= loc_note
;
27925 first_loclabel_num_not_at_text_label
= loclabel_num
;
27930 gcc_assert ((loc_note
== NULL_RTX
&& call_insn
!= NULL_RTX
)
27931 || (loc_note
!= NULL_RTX
&& call_insn
== NULL_RTX
));
27935 struct call_arg_loc_node
*ca_loc
27936 = ggc_cleared_alloc
<call_arg_loc_node
> ();
27937 rtx_insn
*prev
= call_insn
;
27939 ca_loc
->call_arg_loc_note
27940 = find_reg_note (call_insn
, REG_CALL_ARG_LOCATION
, NULL_RTX
);
27941 ca_loc
->next
= NULL
;
27942 ca_loc
->label
= last_label
;
27945 || (NONJUMP_INSN_P (prev
)
27946 && GET_CODE (PATTERN (prev
)) == SEQUENCE
27947 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
27948 if (!CALL_P (prev
))
27949 prev
= as_a
<rtx_sequence
*> (PATTERN (prev
))->insn (0);
27950 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
27952 /* Look for a SYMBOL_REF in the "prev" instruction. */
27953 rtx x
= get_call_rtx_from (prev
);
27956 /* Try to get the call symbol, if any. */
27957 if (MEM_P (XEXP (x
, 0)))
27959 /* First, look for a memory access to a symbol_ref. */
27960 if (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
27961 && SYMBOL_REF_DECL (XEXP (x
, 0))
27962 && TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0))) == FUNCTION_DECL
)
27963 ca_loc
->symbol_ref
= XEXP (x
, 0);
27964 /* Otherwise, look at a compile-time known user-level function
27968 && TREE_CODE (MEM_EXPR (x
)) == FUNCTION_DECL
)
27969 ca_loc
->symbol_ref
= XEXP (DECL_RTL (MEM_EXPR (x
)), 0);
27972 ca_loc
->block
= insn_scope (prev
);
27973 if (call_arg_locations
)
27974 call_arg_loc_last
->next
= ca_loc
;
27976 call_arg_locations
= ca_loc
;
27977 call_arg_loc_last
= ca_loc
;
27979 else if (loc_note
!= NULL_RTX
&& !NOTE_DURING_CALL_P (loc_note
))
27981 newloc
->label
= last_label
;
27982 newloc
->view
= view
;
27986 if (!last_postcall_label
)
27988 sprintf (loclabel
, "%s-1", last_label
);
27989 last_postcall_label
= ggc_strdup (loclabel
);
27991 newloc
->label
= last_postcall_label
;
27992 /* ??? This view is at last_label, not last_label-1, but we
27993 could only assume view at last_label-1 is zero if we could
27994 assume calls always have length greater than one. This is
27995 probably true in general, though there might be a rare
27996 exception to this rule, e.g. if a call insn is optimized out
27997 by target magic. Then, even the -1 in the label will be
27998 wrong, which might invalidate the range. Anyway, using view,
27999 though technically possibly incorrect, will work as far as
28000 ranges go: since L-1 is in the middle of the call insn,
28001 (L-1).0 and (L-1).V shouldn't make any difference, and having
28002 the loclist entry refer to the .loc entry might be useful, so
28003 leave it like this. */
28004 newloc
->view
= view
;
28007 if (var_loc_p
&& flag_debug_asm
)
28009 const char *name
, *sep
, *patstr
;
28010 if (decl
&& DECL_NAME (decl
))
28011 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
28014 if (NOTE_VAR_LOCATION_LOC (loc_note
))
28017 patstr
= str_pattern_slim (NOTE_VAR_LOCATION_LOC (loc_note
));
28024 fprintf (asm_out_file
, "\t%s DEBUG %s%s%s\n", ASM_COMMENT_START
,
28025 name
, sep
, patstr
);
28028 last_var_location_insn
= next_real
;
28029 last_in_cold_section_p
= in_cold_section_p
;
28032 /* Check whether BLOCK, a lexical block, is nested within OUTER, or is
28033 OUTER itself. If BOTHWAYS, check not only that BLOCK can reach
28034 OUTER through BLOCK_SUPERCONTEXT links, but also that there is a
28035 path from OUTER to BLOCK through BLOCK_SUBBLOCKs and
28036 BLOCK_FRAGMENT_ORIGIN links. */
28038 block_within_block_p (tree block
, tree outer
, bool bothways
)
28040 if (block
== outer
)
28043 /* Quickly check that OUTER is up BLOCK's supercontext chain. */
28044 for (tree context
= BLOCK_SUPERCONTEXT (block
);
28046 context
= BLOCK_SUPERCONTEXT (context
))
28047 if (!context
|| TREE_CODE (context
) != BLOCK
)
28053 /* Now check that each block is actually referenced by its
28055 for (tree context
= BLOCK_SUPERCONTEXT (block
); ;
28056 context
= BLOCK_SUPERCONTEXT (context
))
28058 if (BLOCK_FRAGMENT_ORIGIN (context
))
28060 gcc_assert (!BLOCK_SUBBLOCKS (context
));
28061 context
= BLOCK_FRAGMENT_ORIGIN (context
);
28063 for (tree sub
= BLOCK_SUBBLOCKS (context
);
28065 sub
= BLOCK_CHAIN (sub
))
28068 if (context
== outer
)
28075 /* Called during final while assembling the marker of the entry point
28076 for an inlined function. */
28079 dwarf2out_inline_entry (tree block
)
28081 gcc_assert (debug_inline_points
);
28083 /* If we can't represent it, don't bother. */
28084 if (!(dwarf_version
>= 3 || !dwarf_strict
))
28087 gcc_assert (DECL_P (block_ultimate_origin (block
)));
28089 /* Sanity check the block tree. This would catch a case in which
28090 BLOCK got removed from the tree reachable from the outermost
28091 lexical block, but got retained in markers. It would still link
28092 back to its parents, but some ancestor would be missing a link
28093 down the path to the sub BLOCK. If the block got removed, its
28094 BLOCK_NUMBER will not be a usable value. */
28096 gcc_assert (block_within_block_p (block
,
28097 DECL_INITIAL (current_function_decl
),
28100 gcc_assert (inlined_function_outer_scope_p (block
));
28101 gcc_assert (!lookup_block_die (block
));
28103 if (BLOCK_FRAGMENT_ORIGIN (block
))
28104 block
= BLOCK_FRAGMENT_ORIGIN (block
);
28105 /* Can the entry point ever not be at the beginning of an
28106 unfragmented lexical block? */
28107 else if (!(BLOCK_FRAGMENT_CHAIN (block
)
28108 || (cur_line_info_table
28109 && !ZERO_VIEW_P (cur_line_info_table
->view
))))
28112 if (!inline_entry_data_table
)
28113 inline_entry_data_table
28114 = hash_table
<inline_entry_data_hasher
>::create_ggc (10);
28117 inline_entry_data
**iedp
28118 = inline_entry_data_table
->find_slot_with_hash (block
,
28119 htab_hash_pointer (block
),
28122 /* ??? Ideally, we'd record all entry points for the same inlined
28123 function (some may have been duplicated by e.g. unrolling), but
28124 we have no way to represent that ATM. */
28127 inline_entry_data
*ied
= *iedp
= ggc_cleared_alloc
<inline_entry_data
> ();
28128 ied
->block
= block
;
28129 ied
->label_pfx
= BLOCK_INLINE_ENTRY_LABEL
;
28130 ied
->label_num
= BLOCK_NUMBER (block
);
28131 if (cur_line_info_table
)
28132 ied
->view
= cur_line_info_table
->view
;
28134 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_INLINE_ENTRY_LABEL
,
28135 BLOCK_NUMBER (block
));
28138 /* Called from finalize_size_functions for size functions so that their body
28139 can be encoded in the debug info to describe the layout of variable-length
28143 dwarf2out_size_function (tree decl
)
28146 function_to_dwarf_procedure (decl
);
28149 /* Note in one location list that text section has changed. */
28152 var_location_switch_text_section_1 (var_loc_list
**slot
, void *)
28154 var_loc_list
*list
= *slot
;
28156 list
->last_before_switch
28157 = list
->last
->next
? list
->last
->next
: list
->last
;
28161 /* Note in all location lists that text section has changed. */
28164 var_location_switch_text_section (void)
28166 if (decl_loc_table
== NULL
)
28169 decl_loc_table
->traverse
<void *, var_location_switch_text_section_1
> (NULL
);
28172 /* Create a new line number table. */
28174 static dw_line_info_table
*
28175 new_line_info_table (void)
28177 dw_line_info_table
*table
;
28179 table
= ggc_cleared_alloc
<dw_line_info_table
> ();
28180 table
->file_num
= 1;
28181 table
->line_num
= 1;
28182 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
28183 FORCE_RESET_NEXT_VIEW (table
->view
);
28184 table
->symviews_since_reset
= 0;
28189 /* Lookup the "current" table into which we emit line info, so
28190 that we don't have to do it for every source line. */
28193 set_cur_line_info_table (section
*sec
)
28195 dw_line_info_table
*table
;
28197 if (sec
== text_section
)
28198 table
= text_section_line_info
;
28199 else if (sec
== cold_text_section
)
28201 table
= cold_text_section_line_info
;
28204 cold_text_section_line_info
= table
= new_line_info_table ();
28205 table
->end_label
= cold_end_label
;
28210 const char *end_label
;
28212 if (crtl
->has_bb_partition
)
28214 if (in_cold_section_p
)
28215 end_label
= crtl
->subsections
.cold_section_end_label
;
28217 end_label
= crtl
->subsections
.hot_section_end_label
;
28221 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
28222 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
28223 current_function_funcdef_no
);
28224 end_label
= ggc_strdup (label
);
28227 table
= new_line_info_table ();
28228 table
->end_label
= end_label
;
28230 vec_safe_push (separate_line_info
, table
);
28233 if (output_asm_line_debug_info ())
28234 table
->is_stmt
= (cur_line_info_table
28235 ? cur_line_info_table
->is_stmt
28236 : DWARF_LINE_DEFAULT_IS_STMT_START
);
28237 cur_line_info_table
= table
;
28241 /* We need to reset the locations at the beginning of each
28242 function. We can't do this in the end_function hook, because the
28243 declarations that use the locations won't have been output when
28244 that hook is called. Also compute have_multiple_function_sections here. */
28247 dwarf2out_begin_function (tree fun
)
28249 section
*sec
= function_section (fun
);
28251 if (sec
!= text_section
)
28252 have_multiple_function_sections
= true;
28254 if (crtl
->has_bb_partition
&& !cold_text_section
)
28256 gcc_assert (current_function_decl
== fun
);
28257 cold_text_section
= unlikely_text_section ();
28258 switch_to_section (cold_text_section
);
28259 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
28260 switch_to_section (sec
);
28263 call_site_count
= 0;
28264 tail_call_site_count
= 0;
28266 set_cur_line_info_table (sec
);
28267 FORCE_RESET_NEXT_VIEW (cur_line_info_table
->view
);
28270 /* Helper function of dwarf2out_end_function, called only after emitting
28271 the very first function into assembly. Check if some .debug_loc range
28272 might end with a .LVL* label that could be equal to .Ltext0.
28273 In that case we must force using absolute addresses in .debug_loc ranges,
28274 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
28275 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
28277 Set have_multiple_function_sections to true in that case and
28278 terminate htab traversal. */
28281 find_empty_loc_ranges_at_text_label (var_loc_list
**slot
, int)
28283 var_loc_list
*entry
= *slot
;
28284 struct var_loc_node
*node
;
28286 node
= entry
->first
;
28287 if (node
&& node
->next
&& node
->next
->label
)
28290 const char *label
= node
->next
->label
;
28291 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
28293 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
28295 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
28296 if (strcmp (label
, loclabel
) == 0)
28298 have_multiple_function_sections
= true;
28306 /* Hook called after emitting a function into assembly.
28307 This does something only for the very first function emitted. */
28310 dwarf2out_end_function (unsigned int)
28312 if (in_first_function_p
28313 && !have_multiple_function_sections
28314 && first_loclabel_num_not_at_text_label
28316 decl_loc_table
->traverse
<int, find_empty_loc_ranges_at_text_label
> (0);
28317 in_first_function_p
= false;
28318 maybe_at_text_label_p
= false;
28321 /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
28322 front-ends register a translation unit even before dwarf2out_init is
28324 static tree main_translation_unit
= NULL_TREE
;
28326 /* Hook called by front-ends after they built their main translation unit.
28327 Associate comp_unit_die to UNIT. */
28330 dwarf2out_register_main_translation_unit (tree unit
)
28332 gcc_assert (TREE_CODE (unit
) == TRANSLATION_UNIT_DECL
28333 && main_translation_unit
== NULL_TREE
);
28334 main_translation_unit
= unit
;
28335 /* If dwarf2out_init has not been called yet, it will perform the association
28336 itself looking at main_translation_unit. */
28337 if (decl_die_table
!= NULL
)
28338 equate_decl_number_to_die (unit
, comp_unit_die ());
28341 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
28344 push_dw_line_info_entry (dw_line_info_table
*table
,
28345 enum dw_line_info_opcode opcode
, unsigned int val
)
28347 dw_line_info_entry e
;
28350 vec_safe_push (table
->entries
, e
);
28353 /* Output a label to mark the beginning of a source code line entry
28354 and record information relating to this source line, in
28355 'line_info_table' for later output of the .debug_line section. */
28356 /* ??? The discriminator parameter ought to be unsigned. */
28359 dwarf2out_source_line (unsigned int line
, unsigned int column
,
28360 const char *filename
,
28361 int discriminator
, bool is_stmt
)
28363 unsigned int file_num
;
28364 dw_line_info_table
*table
;
28365 static var_loc_view lvugid
;
28367 /* 'line_info_table' information gathering is not needed when the debug
28368 info level is set to the lowest value. Also, the current DWARF-based
28369 debug formats do not use this info. */
28370 if (debug_info_level
< DINFO_LEVEL_TERSE
|| !dwarf_debuginfo_p ())
28373 table
= cur_line_info_table
;
28377 if (debug_variable_location_views
28378 && output_asm_line_debug_info ()
28379 && table
&& !RESETTING_VIEW_P (table
->view
))
28381 /* If we're using the assembler to compute view numbers, we
28382 can't issue a .loc directive for line zero, so we can't
28383 get a view number at this point. We might attempt to
28384 compute it from the previous view, or equate it to a
28385 subsequent view (though it might not be there!), but
28386 since we're omitting the line number entry, we might as
28387 well omit the view number as well. That means pretending
28388 it's a view number zero, which might very well turn out
28389 to be correct. ??? Extend the assembler so that the
28390 compiler could emit e.g. ".locview .LVU#", to output a
28391 view without changing line number information. We'd then
28392 have to count it in symviews_since_reset; when it's omitted,
28393 it doesn't count. */
28395 zero_view_p
= BITMAP_GGC_ALLOC ();
28396 bitmap_set_bit (zero_view_p
, table
->view
);
28397 if (flag_debug_asm
)
28399 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
28400 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", table
->view
);
28401 fprintf (asm_out_file
, "\t%s line 0, omitted view ",
28402 ASM_COMMENT_START
);
28403 assemble_name (asm_out_file
, label
);
28404 putc ('\n', asm_out_file
);
28406 table
->view
= ++lvugid
;
28411 /* The discriminator column was added in dwarf4. Simplify the below
28412 by simply removing it if we're not supposed to output it. */
28413 if (dwarf_version
< 4 && dwarf_strict
)
28416 if (!debug_column_info
)
28419 file_num
= maybe_emit_file (lookup_filename (filename
));
28421 /* ??? TODO: Elide duplicate line number entries. Traditionally,
28422 the debugger has used the second (possibly duplicate) line number
28423 at the beginning of the function to mark the end of the prologue.
28424 We could eliminate any other duplicates within the function. For
28425 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
28426 that second line number entry. */
28427 /* Recall that this end-of-prologue indication is *not* the same thing
28428 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
28429 to which the hook corresponds, follows the last insn that was
28430 emitted by gen_prologue. What we need is to precede the first insn
28431 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
28432 insn that corresponds to something the user wrote. These may be
28433 very different locations once scheduling is enabled. */
28435 if (0 && file_num
== table
->file_num
28436 && line
== table
->line_num
28437 && column
== table
->column_num
28438 && discriminator
== table
->discrim_num
28439 && is_stmt
== table
->is_stmt
)
28442 switch_to_section (current_function_section ());
28444 /* If requested, emit something human-readable. */
28445 if (flag_debug_asm
)
28447 if (debug_column_info
)
28448 fprintf (asm_out_file
, "\t%s %s:%d:%d\n", ASM_COMMENT_START
,
28449 filename
, line
, column
);
28451 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
28455 if (output_asm_line_debug_info ())
28457 /* Emit the .loc directive understood by GNU as. */
28458 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
28459 file_num, line, is_stmt, discriminator */
28460 fputs ("\t.loc ", asm_out_file
);
28461 fprint_ul (asm_out_file
, file_num
);
28462 putc (' ', asm_out_file
);
28463 fprint_ul (asm_out_file
, line
);
28464 putc (' ', asm_out_file
);
28465 fprint_ul (asm_out_file
, column
);
28467 if (is_stmt
!= table
->is_stmt
)
28469 #if HAVE_GAS_LOC_STMT
28470 fputs (" is_stmt ", asm_out_file
);
28471 putc (is_stmt
? '1' : '0', asm_out_file
);
28474 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
28476 gcc_assert (discriminator
> 0);
28477 fputs (" discriminator ", asm_out_file
);
28478 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
28480 if (debug_variable_location_views
)
28482 if (!RESETTING_VIEW_P (table
->view
))
28484 table
->symviews_since_reset
++;
28485 if (table
->symviews_since_reset
> symview_upper_bound
)
28486 symview_upper_bound
= table
->symviews_since_reset
;
28487 /* When we're using the assembler to compute view
28488 numbers, we output symbolic labels after "view" in
28489 .loc directives, and the assembler will set them for
28490 us, so that we can refer to the view numbers in
28491 location lists. The only exceptions are when we know
28492 a view will be zero: "-0" is a forced reset, used
28493 e.g. in the beginning of functions, whereas "0" tells
28494 the assembler to check that there was a PC change
28495 since the previous view, in a way that implicitly
28496 resets the next view. */
28497 fputs (" view ", asm_out_file
);
28498 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
28499 ASM_GENERATE_INTERNAL_LABEL (label
, "LVU", table
->view
);
28500 assemble_name (asm_out_file
, label
);
28501 table
->view
= ++lvugid
;
28505 table
->symviews_since_reset
= 0;
28506 if (FORCE_RESETTING_VIEW_P (table
->view
))
28507 fputs (" view -0", asm_out_file
);
28509 fputs (" view 0", asm_out_file
);
28510 /* Mark the present view as a zero view. Earlier debug
28511 binds may have already added its id to loclists to be
28512 emitted later, so we can't reuse the id for something
28513 else. However, it's good to know whether a view is
28514 known to be zero, because then we may be able to
28515 optimize out locviews that are all zeros, so take
28516 note of it in zero_view_p. */
28518 zero_view_p
= BITMAP_GGC_ALLOC ();
28519 bitmap_set_bit (zero_view_p
, lvugid
);
28520 table
->view
= ++lvugid
;
28523 putc ('\n', asm_out_file
);
28527 unsigned int label_num
= ++line_info_label_num
;
28529 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
28531 if (debug_variable_location_views
&& !RESETTING_VIEW_P (table
->view
))
28532 push_dw_line_info_entry (table
, LI_adv_address
, label_num
);
28534 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
28535 if (debug_variable_location_views
)
28537 bool resetting
= FORCE_RESETTING_VIEW_P (table
->view
);
28541 if (flag_debug_asm
)
28542 fprintf (asm_out_file
, "\t%s view %s%d\n",
28544 resetting
? "-" : "",
28549 if (file_num
!= table
->file_num
)
28550 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
28551 if (discriminator
!= table
->discrim_num
)
28552 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
28553 if (is_stmt
!= table
->is_stmt
)
28554 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
28555 push_dw_line_info_entry (table
, LI_set_line
, line
);
28556 if (debug_column_info
)
28557 push_dw_line_info_entry (table
, LI_set_column
, column
);
28560 table
->file_num
= file_num
;
28561 table
->line_num
= line
;
28562 table
->column_num
= column
;
28563 table
->discrim_num
= discriminator
;
28564 table
->is_stmt
= is_stmt
;
28565 table
->in_use
= true;
28568 /* Record a source file location for a DECL_IGNORED_P function. */
28571 dwarf2out_set_ignored_loc (unsigned int line
, unsigned int column
,
28572 const char *filename
)
28574 dw_fde_ref fde
= cfun
->fde
;
28576 fde
->ignored_debug
= false;
28577 set_cur_line_info_table (function_section (fde
->decl
));
28579 dwarf2out_source_line (line
, column
, filename
, 0, true);
28582 /* Record the beginning of a new source file. */
28585 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
28587 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
28590 e
.code
= DW_MACINFO_start_file
;
28592 e
.info
= ggc_strdup (filename
);
28593 vec_safe_push (macinfo_table
, e
);
28597 /* Record the end of a source file. */
28600 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
28602 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
28605 e
.code
= DW_MACINFO_end_file
;
28608 vec_safe_push (macinfo_table
, e
);
28612 /* Called from debug_define in toplev.c. The `buffer' parameter contains
28613 the tail part of the directive line, i.e. the part which is past the
28614 initial whitespace, #, whitespace, directive-name, whitespace part. */
28617 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
28618 const char *buffer ATTRIBUTE_UNUSED
)
28620 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
28623 /* Insert a dummy first entry to be able to optimize the whole
28624 predefined macro block using DW_MACRO_import. */
28625 if (macinfo_table
->is_empty () && lineno
<= 1)
28630 vec_safe_push (macinfo_table
, e
);
28632 e
.code
= DW_MACINFO_define
;
28634 e
.info
= ggc_strdup (buffer
);
28635 vec_safe_push (macinfo_table
, e
);
28639 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
28640 the tail part of the directive line, i.e. the part which is past the
28641 initial whitespace, #, whitespace, directive-name, whitespace part. */
28644 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
28645 const char *buffer ATTRIBUTE_UNUSED
)
28647 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
28650 /* Insert a dummy first entry to be able to optimize the whole
28651 predefined macro block using DW_MACRO_import. */
28652 if (macinfo_table
->is_empty () && lineno
<= 1)
28657 vec_safe_push (macinfo_table
, e
);
28659 e
.code
= DW_MACINFO_undef
;
28661 e
.info
= ggc_strdup (buffer
);
28662 vec_safe_push (macinfo_table
, e
);
28666 /* Helpers to manipulate hash table of CUs. */
28668 struct macinfo_entry_hasher
: nofree_ptr_hash
<macinfo_entry
>
28670 static inline hashval_t
hash (const macinfo_entry
*);
28671 static inline bool equal (const macinfo_entry
*, const macinfo_entry
*);
28675 macinfo_entry_hasher::hash (const macinfo_entry
*entry
)
28677 return htab_hash_string (entry
->info
);
28681 macinfo_entry_hasher::equal (const macinfo_entry
*entry1
,
28682 const macinfo_entry
*entry2
)
28684 return !strcmp (entry1
->info
, entry2
->info
);
28687 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
28689 /* Output a single .debug_macinfo entry. */
28692 output_macinfo_op (macinfo_entry
*ref
)
28696 struct indirect_string_node
*node
;
28697 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
28698 struct dwarf_file_data
*fd
;
28702 case DW_MACINFO_start_file
:
28703 fd
= lookup_filename (ref
->info
);
28704 file_num
= maybe_emit_file (fd
);
28705 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
28706 dw2_asm_output_data_uleb128 (ref
->lineno
,
28707 "Included from line number %lu",
28708 (unsigned long) ref
->lineno
);
28709 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
28711 case DW_MACINFO_end_file
:
28712 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
28714 case DW_MACINFO_define
:
28715 case DW_MACINFO_undef
:
28716 len
= strlen (ref
->info
) + 1;
28717 if ((!dwarf_strict
|| dwarf_version
>= 5)
28718 && len
> (size_t) dwarf_offset_size
28719 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
28720 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
28722 if (dwarf_split_debug_info
&& dwarf_version
>= 5)
28723 ref
->code
= ref
->code
== DW_MACINFO_define
28724 ? DW_MACRO_define_strx
: DW_MACRO_undef_strx
;
28726 ref
->code
= ref
->code
== DW_MACINFO_define
28727 ? DW_MACRO_define_strp
: DW_MACRO_undef_strp
;
28728 output_macinfo_op (ref
);
28731 dw2_asm_output_data (1, ref
->code
,
28732 ref
->code
== DW_MACINFO_define
28733 ? "Define macro" : "Undefine macro");
28734 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
28735 (unsigned long) ref
->lineno
);
28736 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
28738 case DW_MACRO_define_strp
:
28739 dw2_asm_output_data (1, ref
->code
, "Define macro strp");
28740 goto do_DW_MACRO_define_strpx
;
28741 case DW_MACRO_undef_strp
:
28742 dw2_asm_output_data (1, ref
->code
, "Undefine macro strp");
28743 goto do_DW_MACRO_define_strpx
;
28744 case DW_MACRO_define_strx
:
28745 dw2_asm_output_data (1, ref
->code
, "Define macro strx");
28746 goto do_DW_MACRO_define_strpx
;
28747 case DW_MACRO_undef_strx
:
28748 dw2_asm_output_data (1, ref
->code
, "Undefine macro strx");
28750 do_DW_MACRO_define_strpx
:
28751 /* NB: dwarf2out_finish performs:
28752 1. save_macinfo_strings
28753 2. hash table traverse of index_string
28754 3. output_macinfo -> output_macinfo_op
28755 4. output_indirect_strings
28756 -> hash table traverse of output_index_string
28758 When output_macinfo_op is called, all index strings have been
28759 added to hash table by save_macinfo_strings and we can't pass
28760 INSERT to find_slot_with_hash which may expand hash table, even
28761 if no insertion is needed, and change hash table traverse order
28762 between index_string and output_index_string. */
28763 node
= find_AT_string (ref
->info
, NO_INSERT
);
28765 && (node
->form
== DW_FORM_strp
28766 || node
->form
== dwarf_FORM (DW_FORM_strx
)));
28767 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
28768 (unsigned long) ref
->lineno
);
28769 if (node
->form
== DW_FORM_strp
)
28770 dw2_asm_output_offset (dwarf_offset_size
, node
->label
,
28771 debug_str_section
, "The macro: \"%s\"",
28774 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
28777 case DW_MACRO_import
:
28778 dw2_asm_output_data (1, ref
->code
, "Import");
28779 ASM_GENERATE_INTERNAL_LABEL (label
,
28780 DEBUG_MACRO_SECTION_LABEL
,
28781 ref
->lineno
+ macinfo_label_base
);
28782 dw2_asm_output_offset (dwarf_offset_size
, label
, NULL
, NULL
);
28785 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
28786 ASM_COMMENT_START
, (unsigned long) ref
->code
);
28791 /* Attempt to make a sequence of define/undef macinfo ops shareable with
28792 other compilation unit .debug_macinfo sections. IDX is the first
28793 index of a define/undef, return the number of ops that should be
28794 emitted in a comdat .debug_macinfo section and emit
28795 a DW_MACRO_import entry referencing it.
28796 If the define/undef entry should be emitted normally, return 0. */
28799 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
28800 macinfo_hash_type
**macinfo_htab
)
28802 macinfo_entry
*first
, *second
, *cur
, *inc
;
28803 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
28804 unsigned char checksum
[16];
28805 struct md5_ctx ctx
;
28806 char *grp_name
, *tail
;
28808 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
28809 macinfo_entry
**slot
;
28811 first
= &(*macinfo_table
)[idx
];
28812 second
= &(*macinfo_table
)[idx
+ 1];
28814 /* Optimize only if there are at least two consecutive define/undef ops,
28815 and either all of them are before first DW_MACINFO_start_file
28816 with lineno {0,1} (i.e. predefined macro block), or all of them are
28817 in some included header file. */
28818 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
28820 if (vec_safe_is_empty (files
))
28822 if (first
->lineno
> 1 || second
->lineno
> 1)
28825 else if (first
->lineno
== 0)
28828 /* Find the last define/undef entry that can be grouped together
28829 with first and at the same time compute md5 checksum of their
28830 codes, linenumbers and strings. */
28831 md5_init_ctx (&ctx
);
28832 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
28833 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
28835 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
28839 unsigned char code
= cur
->code
;
28840 md5_process_bytes (&code
, 1, &ctx
);
28841 checksum_uleb128 (cur
->lineno
, &ctx
);
28842 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
28844 md5_finish_ctx (&ctx
, checksum
);
28847 /* From the containing include filename (if any) pick up just
28848 usable characters from its basename. */
28849 if (vec_safe_is_empty (files
))
28852 base
= lbasename (files
->last ().info
);
28853 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
28854 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
28855 encoded_filename_len
++;
28856 /* Count . at the end. */
28857 if (encoded_filename_len
)
28858 encoded_filename_len
++;
28860 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
28861 linebuf_len
= strlen (linebuf
);
28863 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
28864 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
28866 memcpy (grp_name
, dwarf_offset_size
== 4 ? "wm4." : "wm8.", 4);
28867 tail
= grp_name
+ 4;
28868 if (encoded_filename_len
)
28870 for (i
= 0; base
[i
]; i
++)
28871 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
28875 memcpy (tail
, linebuf
, linebuf_len
);
28876 tail
+= linebuf_len
;
28878 for (i
= 0; i
< 16; i
++)
28879 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
28881 /* Construct a macinfo_entry for DW_MACRO_import
28882 in the empty vector entry before the first define/undef. */
28883 inc
= &(*macinfo_table
)[idx
- 1];
28884 inc
->code
= DW_MACRO_import
;
28886 inc
->info
= ggc_strdup (grp_name
);
28887 if (!*macinfo_htab
)
28888 *macinfo_htab
= new macinfo_hash_type (10);
28889 /* Avoid emitting duplicates. */
28890 slot
= (*macinfo_htab
)->find_slot (inc
, INSERT
);
28895 /* If such an entry has been used before, just emit
28896 a DW_MACRO_import op. */
28898 output_macinfo_op (inc
);
28899 /* And clear all macinfo_entry in the range to avoid emitting them
28900 in the second pass. */
28901 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
28910 inc
->lineno
= (*macinfo_htab
)->elements ();
28911 output_macinfo_op (inc
);
28916 /* Save any strings needed by the macinfo table in the debug str
28917 table. All strings must be collected into the table by the time
28918 index_string is called. */
28921 save_macinfo_strings (void)
28925 macinfo_entry
*ref
;
28927 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
28931 /* Match the logic in output_macinfo_op to decide on
28932 indirect strings. */
28933 case DW_MACINFO_define
:
28934 case DW_MACINFO_undef
:
28935 len
= strlen (ref
->info
) + 1;
28936 if ((!dwarf_strict
|| dwarf_version
>= 5)
28937 && len
> (unsigned) dwarf_offset_size
28938 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
28939 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
28940 set_indirect_string (find_AT_string (ref
->info
));
28942 case DW_MACINFO_start_file
:
28943 /* -gsplit-dwarf -g3 will also output filename as indirect
28945 if (!dwarf_split_debug_info
)
28947 /* Fall through. */
28948 case DW_MACRO_define_strp
:
28949 case DW_MACRO_undef_strp
:
28950 case DW_MACRO_define_strx
:
28951 case DW_MACRO_undef_strx
:
28952 set_indirect_string (find_AT_string (ref
->info
));
28960 /* Output macinfo section(s). */
28963 output_macinfo (const char *debug_line_label
, bool early_lto_debug
)
28966 unsigned long length
= vec_safe_length (macinfo_table
);
28967 macinfo_entry
*ref
;
28968 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
28969 macinfo_hash_type
*macinfo_htab
= NULL
;
28970 char dl_section_ref
[MAX_ARTIFICIAL_LABEL_BYTES
];
28975 /* output_macinfo* uses these interchangeably. */
28976 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_define
28977 && (int) DW_MACINFO_undef
== (int) DW_MACRO_undef
28978 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_start_file
28979 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_end_file
);
28981 /* AIX Assembler inserts the length, so adjust the reference to match the
28982 offset expected by debuggers. */
28983 strcpy (dl_section_ref
, debug_line_label
);
28984 if (XCOFF_DEBUGGING_INFO
)
28985 strcat (dl_section_ref
, DWARF_INITIAL_LENGTH_SIZE_STR
);
28987 /* For .debug_macro emit the section header. */
28988 if (!dwarf_strict
|| dwarf_version
>= 5)
28990 dw2_asm_output_data (2, dwarf_version
>= 5 ? 5 : 4,
28991 "DWARF macro version number");
28992 if (dwarf_offset_size
== 8)
28993 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
28995 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
28996 dw2_asm_output_offset (dwarf_offset_size
, debug_line_label
,
28997 debug_line_section
, NULL
);
29000 /* In the first loop, it emits the primary .debug_macinfo section
29001 and after each emitted op the macinfo_entry is cleared.
29002 If a longer range of define/undef ops can be optimized using
29003 DW_MACRO_import, the DW_MACRO_import op is emitted and kept in
29004 the vector before the first define/undef in the range and the
29005 whole range of define/undef ops is not emitted and kept. */
29006 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
29010 case DW_MACINFO_start_file
:
29011 vec_safe_push (files
, *ref
);
29013 case DW_MACINFO_end_file
:
29014 if (!vec_safe_is_empty (files
))
29017 case DW_MACINFO_define
:
29018 case DW_MACINFO_undef
:
29019 if ((!dwarf_strict
|| dwarf_version
>= 5)
29020 && HAVE_COMDAT_GROUP
29021 && vec_safe_length (files
) != 1
29024 && (*macinfo_table
)[i
- 1].code
== 0)
29026 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
29035 /* A dummy entry may be inserted at the beginning to be able
29036 to optimize the whole block of predefined macros. */
29042 output_macinfo_op (ref
);
29050 /* Save the number of transparent includes so we can adjust the
29051 label number for the fat LTO object DWARF. */
29052 unsigned macinfo_label_base_adj
= macinfo_htab
->elements ();
29054 delete macinfo_htab
;
29055 macinfo_htab
= NULL
;
29057 /* If any DW_MACRO_import were used, on those DW_MACRO_import entries
29058 terminate the current chain and switch to a new comdat .debug_macinfo
29059 section and emit the define/undef entries within it. */
29060 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
29065 case DW_MACRO_import
:
29067 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
29068 tree comdat_key
= get_identifier (ref
->info
);
29069 /* Terminate the previous .debug_macinfo section. */
29070 dw2_asm_output_data (1, 0, "End compilation unit");
29071 targetm
.asm_out
.named_section (debug_macinfo_section_name
,
29075 ? SECTION_EXCLUDE
: 0),
29077 ASM_GENERATE_INTERNAL_LABEL (label
,
29078 DEBUG_MACRO_SECTION_LABEL
,
29079 ref
->lineno
+ macinfo_label_base
);
29080 ASM_OUTPUT_LABEL (asm_out_file
, label
);
29083 dw2_asm_output_data (2, dwarf_version
>= 5 ? 5 : 4,
29084 "DWARF macro version number");
29085 if (dwarf_offset_size
== 8)
29086 dw2_asm_output_data (1, 1, "Flags: 64-bit");
29088 dw2_asm_output_data (1, 0, "Flags: 32-bit");
29091 case DW_MACINFO_define
:
29092 case DW_MACINFO_undef
:
29093 output_macinfo_op (ref
);
29098 gcc_unreachable ();
29101 macinfo_label_base
+= macinfo_label_base_adj
;
29104 /* As init_sections_and_labels may get called multiple times, have a
29105 generation count for labels. */
29106 static unsigned init_sections_and_labels_generation
;
29108 /* Initialize the various sections and labels for dwarf output and prefix
29109 them with PREFIX if non-NULL. Returns the generation (zero based
29110 number of times function was called). */
29113 init_sections_and_labels (bool early_lto_debug
)
29115 if (early_lto_debug
)
29117 if (!dwarf_split_debug_info
)
29119 debug_info_section
= get_section (DEBUG_LTO_INFO_SECTION
,
29120 SECTION_DEBUG
| SECTION_EXCLUDE
,
29122 debug_abbrev_section
= get_section (DEBUG_LTO_ABBREV_SECTION
,
29123 SECTION_DEBUG
| SECTION_EXCLUDE
,
29125 debug_macinfo_section_name
29126 = ((dwarf_strict
&& dwarf_version
< 5)
29127 ? DEBUG_LTO_MACINFO_SECTION
: DEBUG_LTO_MACRO_SECTION
);
29128 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
29130 | SECTION_EXCLUDE
, NULL
);
29134 /* ??? Which of the following do we need early? */
29135 debug_info_section
= get_section (DEBUG_LTO_DWO_INFO_SECTION
,
29136 SECTION_DEBUG
| SECTION_EXCLUDE
,
29138 debug_abbrev_section
= get_section (DEBUG_LTO_DWO_ABBREV_SECTION
,
29139 SECTION_DEBUG
| SECTION_EXCLUDE
,
29141 debug_skeleton_info_section
= get_section (DEBUG_LTO_INFO_SECTION
,
29143 | SECTION_EXCLUDE
, NULL
);
29144 debug_skeleton_abbrev_section
29145 = get_section (DEBUG_LTO_ABBREV_SECTION
,
29146 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
29147 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
29148 DEBUG_SKELETON_ABBREV_SECTION_LABEL
,
29149 init_sections_and_labels_generation
);
29151 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections
29152 stay in the main .o, but the skeleton_line goes into the split
29154 debug_skeleton_line_section
29155 = get_section (DEBUG_LTO_LINE_SECTION
,
29156 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
29157 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
29158 DEBUG_SKELETON_LINE_SECTION_LABEL
,
29159 init_sections_and_labels_generation
);
29160 debug_str_offsets_section
29161 = get_section (DEBUG_LTO_DWO_STR_OFFSETS_SECTION
,
29162 SECTION_DEBUG
| SECTION_EXCLUDE
,
29164 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
29165 DEBUG_SKELETON_INFO_SECTION_LABEL
,
29166 init_sections_and_labels_generation
);
29167 debug_str_dwo_section
= get_section (DEBUG_LTO_STR_DWO_SECTION
,
29168 DEBUG_STR_DWO_SECTION_FLAGS
,
29170 debug_macinfo_section_name
29171 = ((dwarf_strict
&& dwarf_version
< 5)
29172 ? DEBUG_LTO_DWO_MACINFO_SECTION
: DEBUG_LTO_DWO_MACRO_SECTION
);
29173 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
29174 SECTION_DEBUG
| SECTION_EXCLUDE
,
29177 /* For macro info and the file table we have to refer to a
29178 debug_line section. */
29179 debug_line_section
= get_section (DEBUG_LTO_LINE_SECTION
,
29180 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
29181 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
29182 DEBUG_LINE_SECTION_LABEL
,
29183 init_sections_and_labels_generation
);
29185 debug_str_section
= get_section (DEBUG_LTO_STR_SECTION
,
29186 DEBUG_STR_SECTION_FLAGS
29187 | SECTION_EXCLUDE
, NULL
);
29188 if (!dwarf_split_debug_info
)
29189 debug_line_str_section
29190 = get_section (DEBUG_LTO_LINE_STR_SECTION
,
29191 DEBUG_STR_SECTION_FLAGS
| SECTION_EXCLUDE
, NULL
);
29195 if (!dwarf_split_debug_info
)
29197 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
29198 SECTION_DEBUG
, NULL
);
29199 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
29200 SECTION_DEBUG
, NULL
);
29201 debug_loc_section
= get_section (dwarf_version
>= 5
29202 ? DEBUG_LOCLISTS_SECTION
29203 : DEBUG_LOC_SECTION
,
29204 SECTION_DEBUG
, NULL
);
29205 debug_macinfo_section_name
29206 = ((dwarf_strict
&& dwarf_version
< 5)
29207 ? DEBUG_MACINFO_SECTION
: DEBUG_MACRO_SECTION
);
29208 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
29209 SECTION_DEBUG
, NULL
);
29213 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
29214 SECTION_DEBUG
| SECTION_EXCLUDE
,
29216 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
29217 SECTION_DEBUG
| SECTION_EXCLUDE
,
29219 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
29220 SECTION_DEBUG
, NULL
);
29221 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
29222 SECTION_DEBUG
, NULL
);
29223 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
29224 SECTION_DEBUG
, NULL
);
29225 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
29226 DEBUG_SKELETON_ABBREV_SECTION_LABEL
,
29227 init_sections_and_labels_generation
);
29229 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections
29230 stay in the main .o, but the skeleton_line goes into the
29232 debug_skeleton_line_section
29233 = get_section (DEBUG_DWO_LINE_SECTION
,
29234 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
29235 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
29236 DEBUG_SKELETON_LINE_SECTION_LABEL
,
29237 init_sections_and_labels_generation
);
29238 debug_str_offsets_section
29239 = get_section (DEBUG_DWO_STR_OFFSETS_SECTION
,
29240 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
29241 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
29242 DEBUG_SKELETON_INFO_SECTION_LABEL
,
29243 init_sections_and_labels_generation
);
29244 debug_loc_section
= get_section (dwarf_version
>= 5
29245 ? DEBUG_DWO_LOCLISTS_SECTION
29246 : DEBUG_DWO_LOC_SECTION
,
29247 SECTION_DEBUG
| SECTION_EXCLUDE
,
29249 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
29250 DEBUG_STR_DWO_SECTION_FLAGS
,
29252 debug_macinfo_section_name
29253 = ((dwarf_strict
&& dwarf_version
< 5)
29254 ? DEBUG_DWO_MACINFO_SECTION
: DEBUG_DWO_MACRO_SECTION
);
29255 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
29256 SECTION_DEBUG
| SECTION_EXCLUDE
,
29258 if (dwarf_version
>= 5)
29259 debug_ranges_dwo_section
29260 = get_section (DEBUG_DWO_RNGLISTS_SECTION
,
29261 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
29263 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
29264 SECTION_DEBUG
, NULL
);
29265 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
29266 SECTION_DEBUG
, NULL
);
29267 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
29268 SECTION_DEBUG
, NULL
);
29269 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
29270 SECTION_DEBUG
, NULL
);
29271 debug_str_section
= get_section (DEBUG_STR_SECTION
,
29272 DEBUG_STR_SECTION_FLAGS
, NULL
);
29273 if ((!dwarf_split_debug_info
&& !output_asm_line_debug_info ())
29274 || asm_outputs_debug_line_str ())
29275 debug_line_str_section
= get_section (DEBUG_LINE_STR_SECTION
,
29276 DEBUG_STR_SECTION_FLAGS
, NULL
);
29278 debug_ranges_section
= get_section (dwarf_version
>= 5
29279 ? DEBUG_RNGLISTS_SECTION
29280 : DEBUG_RANGES_SECTION
,
29281 SECTION_DEBUG
, NULL
);
29282 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
29283 SECTION_DEBUG
, NULL
);
29286 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
29287 DEBUG_ABBREV_SECTION_LABEL
,
29288 init_sections_and_labels_generation
);
29289 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
29290 DEBUG_INFO_SECTION_LABEL
,
29291 init_sections_and_labels_generation
);
29292 info_section_emitted
= false;
29293 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
29294 DEBUG_LINE_SECTION_LABEL
,
29295 init_sections_and_labels_generation
);
29296 /* There are up to 6 unique ranges labels per generation.
29297 See also output_rnglists. */
29298 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
29299 DEBUG_RANGES_SECTION_LABEL
,
29300 init_sections_and_labels_generation
* 6);
29301 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
29302 ASM_GENERATE_INTERNAL_LABEL (ranges_base_label
,
29303 DEBUG_RANGES_SECTION_LABEL
,
29304 1 + init_sections_and_labels_generation
* 6);
29305 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
29306 DEBUG_ADDR_SECTION_LABEL
,
29307 init_sections_and_labels_generation
);
29308 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
29309 (dwarf_strict
&& dwarf_version
< 5)
29310 ? DEBUG_MACINFO_SECTION_LABEL
29311 : DEBUG_MACRO_SECTION_LABEL
,
29312 init_sections_and_labels_generation
);
29313 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
,
29314 init_sections_and_labels_generation
);
29316 ++init_sections_and_labels_generation
;
29317 return init_sections_and_labels_generation
- 1;
29320 /* Set up for Dwarf output at the start of compilation. */
29323 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
29325 /* Allocate the file_table. */
29326 file_table
= hash_table
<dwarf_file_hasher
>::create_ggc (50);
29328 #ifndef DWARF2_LINENO_DEBUGGING_INFO
29329 /* Allocate the decl_die_table. */
29330 decl_die_table
= hash_table
<decl_die_hasher
>::create_ggc (10);
29332 /* Allocate the decl_loc_table. */
29333 decl_loc_table
= hash_table
<decl_loc_hasher
>::create_ggc (10);
29335 /* Allocate the cached_dw_loc_list_table. */
29336 cached_dw_loc_list_table
= hash_table
<dw_loc_list_hasher
>::create_ggc (10);
29338 /* Allocate the initial hunk of the abbrev_die_table. */
29339 vec_alloc (abbrev_die_table
, 256);
29340 /* Zero-th entry is allocated, but unused. */
29341 abbrev_die_table
->quick_push (NULL
);
29343 /* Allocate the dwarf_proc_stack_usage_map. */
29344 dwarf_proc_stack_usage_map
= new hash_map
<dw_die_ref
, int>;
29346 /* Allocate the pubtypes and pubnames vectors. */
29347 vec_alloc (pubname_table
, 32);
29348 vec_alloc (pubtype_table
, 32);
29350 vec_alloc (incomplete_types
, 64);
29352 vec_alloc (used_rtx_array
, 32);
29354 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
29355 vec_alloc (macinfo_table
, 64);
29358 /* If front-ends already registered a main translation unit but we were not
29359 ready to perform the association, do this now. */
29360 if (main_translation_unit
!= NULL_TREE
)
29361 equate_decl_number_to_die (main_translation_unit
, comp_unit_die ());
29364 /* Called before compile () starts outputtting functions, variables
29365 and toplevel asms into assembly. */
29368 dwarf2out_assembly_start (void)
29370 if (text_section_line_info
)
29373 #ifndef DWARF2_LINENO_DEBUGGING_INFO
29374 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
29375 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
29376 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
29377 COLD_TEXT_SECTION_LABEL
, 0);
29378 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
29380 switch_to_section (text_section
);
29381 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
29384 /* Make sure the line number table for .text always exists. */
29385 text_section_line_info
= new_line_info_table ();
29386 text_section_line_info
->end_label
= text_end_label
;
29388 #ifdef DWARF2_LINENO_DEBUGGING_INFO
29389 cur_line_info_table
= text_section_line_info
;
29392 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
29393 && dwarf2out_do_cfi_asm ()
29394 && !dwarf2out_do_eh_frame ())
29395 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
29397 #if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG)
29398 if (output_asm_line_debug_info () && dwarf_version
>= 5)
29400 /* When gas outputs DWARF5 .debug_line[_str] then we have to
29401 tell it the comp_dir and main file name for the zero entry
29403 const char *comp_dir
, *filename0
;
29405 comp_dir
= comp_dir_string ();
29406 if (comp_dir
== NULL
)
29409 filename0
= get_AT_string (comp_unit_die (), DW_AT_name
);
29410 if (filename0
== NULL
)
29413 fprintf (asm_out_file
, "\t.file 0 ");
29414 output_quoted_string (asm_out_file
, remap_debug_filename (comp_dir
));
29415 fputc (' ', asm_out_file
);
29416 output_quoted_string (asm_out_file
, remap_debug_filename (filename0
));
29417 fputc ('\n', asm_out_file
);
29421 /* Work around for PR101575: output a dummy .file directive. */
29422 if (!last_emitted_file
&& dwarf_debuginfo_p ()
29423 && debug_info_level
>= DINFO_LEVEL_TERSE
)
29425 const char *filename0
= get_AT_string (comp_unit_die (), DW_AT_name
);
29427 if (filename0
== NULL
)
29428 filename0
= "<dummy>";
29429 maybe_emit_file (lookup_filename (filename0
));
29433 /* A helper function for dwarf2out_finish called through
29434 htab_traverse. Assign a string its index. All strings must be
29435 collected into the table by the time index_string is called,
29436 because the indexing code relies on htab_traverse to traverse nodes
29437 in the same order for each run. */
29440 index_string (indirect_string_node
**h
, unsigned int *index
)
29442 indirect_string_node
*node
= *h
;
29444 find_string_form (node
);
29445 if (node
->form
== dwarf_FORM (DW_FORM_strx
) && node
->refcount
> 0)
29447 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
29448 node
->index
= *index
;
29454 /* A helper function for output_indirect_strings called through
29455 htab_traverse. Output the offset to a string and update the
29459 output_index_string_offset (indirect_string_node
**h
, unsigned int *offset
)
29461 indirect_string_node
*node
= *h
;
29463 if (node
->form
== dwarf_FORM (DW_FORM_strx
) && node
->refcount
> 0)
29465 /* Assert that this node has been assigned an index. */
29466 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
29467 && node
->index
!= NOT_INDEXED
);
29468 dw2_asm_output_data (dwarf_offset_size
, *offset
,
29469 "indexed string 0x%x: %s", node
->index
, node
->str
);
29470 *offset
+= strlen (node
->str
) + 1;
29475 /* A helper function for dwarf2out_finish called through
29476 htab_traverse. Output the indexed string. */
29479 output_index_string (indirect_string_node
**h
, unsigned int *cur_idx
)
29481 struct indirect_string_node
*node
= *h
;
29483 if (node
->form
== dwarf_FORM (DW_FORM_strx
) && node
->refcount
> 0)
29485 /* Assert that the strings are output in the same order as their
29486 indexes were assigned. */
29487 gcc_assert (*cur_idx
== node
->index
);
29488 assemble_string (node
->str
, strlen (node
->str
) + 1);
29494 /* A helper function for output_indirect_strings. Counts the number
29495 of index strings offsets. Must match the logic of the functions
29496 output_index_string[_offsets] above. */
29498 count_index_strings (indirect_string_node
**h
, unsigned int *last_idx
)
29500 struct indirect_string_node
*node
= *h
;
29502 if (node
->form
== dwarf_FORM (DW_FORM_strx
) && node
->refcount
> 0)
29507 /* A helper function for dwarf2out_finish called through
29508 htab_traverse. Emit one queued .debug_str string. */
29511 output_indirect_string (indirect_string_node
**h
, enum dwarf_form form
)
29513 struct indirect_string_node
*node
= *h
;
29515 node
->form
= find_string_form (node
);
29516 if (node
->form
== form
&& node
->refcount
> 0)
29518 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
29519 assemble_string (node
->str
, strlen (node
->str
) + 1);
29525 /* Output the indexed string table. */
29528 output_indirect_strings (void)
29530 switch_to_section (debug_str_section
);
29531 if (!dwarf_split_debug_info
)
29532 debug_str_hash
->traverse
<enum dwarf_form
,
29533 output_indirect_string
> (DW_FORM_strp
);
29536 unsigned int offset
= 0;
29537 unsigned int cur_idx
= 0;
29539 if (skeleton_debug_str_hash
)
29540 skeleton_debug_str_hash
->traverse
<enum dwarf_form
,
29541 output_indirect_string
> (DW_FORM_strp
);
29543 switch_to_section (debug_str_offsets_section
);
29544 /* For DWARF5 the .debug_str_offsets[.dwo] section needs a unit
29545 header. Note that we don't need to generate a label to the
29546 actual index table following the header here, because this is
29547 for the split dwarf case only. In an .dwo file there is only
29548 one string offsets table (and one debug info section). But
29549 if we would start using string offset tables for the main (or
29550 skeleton) unit, then we have to add a DW_AT_str_offsets_base
29551 pointing to the actual index after the header. Split dwarf
29552 units will never have a string offsets base attribute. When
29553 a split unit is moved into a .dwp file the string offsets can
29554 be found through the .debug_cu_index section table. */
29555 if (dwarf_version
>= 5)
29557 unsigned int last_idx
= 0;
29558 unsigned long str_offsets_length
;
29560 debug_str_hash
->traverse_noresize
29561 <unsigned int *, count_index_strings
> (&last_idx
);
29562 str_offsets_length
= last_idx
* dwarf_offset_size
+ 4;
29563 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
29564 dw2_asm_output_data (4, 0xffffffff,
29565 "Escape value for 64-bit DWARF extension");
29566 dw2_asm_output_data (dwarf_offset_size
, str_offsets_length
,
29567 "Length of string offsets unit");
29568 dw2_asm_output_data (2, 5, "DWARF string offsets version");
29569 dw2_asm_output_data (2, 0, "Header zero padding");
29571 debug_str_hash
->traverse_noresize
29572 <unsigned int *, output_index_string_offset
> (&offset
);
29573 switch_to_section (debug_str_dwo_section
);
29574 debug_str_hash
->traverse_noresize
<unsigned int *, output_index_string
>
29579 /* Callback for htab_traverse to assign an index to an entry in the
29580 table, and to write that entry to the .debug_addr section. */
29583 output_addr_table_entry (addr_table_entry
**slot
, unsigned int *cur_index
)
29585 addr_table_entry
*entry
= *slot
;
29587 if (entry
->refcount
== 0)
29589 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
29590 || entry
->index
== NOT_INDEXED
);
29594 gcc_assert (entry
->index
== *cur_index
);
29597 switch (entry
->kind
)
29600 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
29601 "0x%x", entry
->index
);
29603 case ate_kind_rtx_dtprel
:
29604 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
29605 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
29608 fputc ('\n', asm_out_file
);
29610 case ate_kind_label
:
29611 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
29612 "0x%x", entry
->index
);
29615 gcc_unreachable ();
29620 /* A helper function for dwarf2out_finish. Counts the number
29621 of indexed addresses. Must match the logic of the functions
29622 output_addr_table_entry above. */
29624 count_index_addrs (addr_table_entry
**slot
, unsigned int *last_idx
)
29626 addr_table_entry
*entry
= *slot
;
29628 if (entry
->refcount
> 0)
29633 /* Produce the .debug_addr section. */
29636 output_addr_table (void)
29638 unsigned int index
= 0;
29639 if (addr_index_table
== NULL
|| addr_index_table
->size () == 0)
29642 switch_to_section (debug_addr_section
);
29643 /* GNU DebugFission https://gcc.gnu.org/wiki/DebugFission
29644 which GCC uses to implement -gsplit-dwarf as DWARF GNU extension
29645 before DWARF5, didn't have a header for .debug_addr units.
29646 DWARF5 specifies a small header when address tables are used. */
29647 if (dwarf_version
>= 5)
29649 unsigned int last_idx
= 0;
29650 unsigned long addrs_length
;
29652 addr_index_table
->traverse_noresize
29653 <unsigned int *, count_index_addrs
> (&last_idx
);
29654 addrs_length
= last_idx
* DWARF2_ADDR_SIZE
+ 4;
29656 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
29657 dw2_asm_output_data (4, 0xffffffff,
29658 "Escape value for 64-bit DWARF extension");
29659 dw2_asm_output_data (dwarf_offset_size
, addrs_length
,
29660 "Length of Address Unit");
29661 dw2_asm_output_data (2, 5, "DWARF addr version");
29662 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
29663 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
29665 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
29668 ->traverse_noresize
<unsigned int *, output_addr_table_entry
> (&index
);
29671 #if ENABLE_ASSERT_CHECKING
29672 /* Verify that all marks are clear. */
29675 verify_marks_clear (dw_die_ref die
)
29679 gcc_assert (! die
->die_mark
);
29680 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
29682 #endif /* ENABLE_ASSERT_CHECKING */
29684 /* Clear the marks for a die and its children.
29685 Be cool if the mark isn't set. */
29688 prune_unmark_dies (dw_die_ref die
)
29694 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
29697 /* Given LOC that is referenced by a DIE we're marking as used, find all
29698 referenced DWARF procedures it references and mark them as used. */
29701 prune_unused_types_walk_loc_descr (dw_loc_descr_ref loc
)
29703 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
29704 switch (loc
->dw_loc_opc
)
29706 case DW_OP_implicit_pointer
:
29707 case DW_OP_convert
:
29708 case DW_OP_reinterpret
:
29709 case DW_OP_GNU_implicit_pointer
:
29710 case DW_OP_GNU_convert
:
29711 case DW_OP_GNU_reinterpret
:
29712 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
)
29713 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
29715 case DW_OP_GNU_variable_value
:
29716 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
29719 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
29722 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
29723 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
29724 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
29729 case DW_OP_call_ref
:
29730 case DW_OP_const_type
:
29731 case DW_OP_GNU_const_type
:
29732 case DW_OP_GNU_parameter_ref
:
29733 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
);
29734 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
29736 case DW_OP_regval_type
:
29737 case DW_OP_deref_type
:
29738 case DW_OP_GNU_regval_type
:
29739 case DW_OP_GNU_deref_type
:
29740 gcc_assert (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_die_ref
);
29741 prune_unused_types_mark (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
, 1);
29743 case DW_OP_entry_value
:
29744 case DW_OP_GNU_entry_value
:
29745 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
);
29746 prune_unused_types_walk_loc_descr (loc
->dw_loc_oprnd1
.v
.val_loc
);
29753 /* Given DIE that we're marking as used, find any other dies
29754 it references as attributes and mark them as used. */
29757 prune_unused_types_walk_attribs (dw_die_ref die
)
29762 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
29764 switch (AT_class (a
))
29766 /* Make sure DWARF procedures referenced by location descriptions will
29768 case dw_val_class_loc
:
29769 prune_unused_types_walk_loc_descr (AT_loc (a
));
29771 case dw_val_class_loc_list
:
29772 for (dw_loc_list_ref list
= AT_loc_list (a
);
29774 list
= list
->dw_loc_next
)
29775 prune_unused_types_walk_loc_descr (list
->expr
);
29778 case dw_val_class_view_list
:
29779 /* This points to a loc_list in another attribute, so it's
29780 already covered. */
29783 case dw_val_class_die_ref
:
29784 /* A reference to another DIE.
29785 Make sure that it will get emitted.
29786 If it was broken out into a comdat group, don't follow it. */
29787 if (! AT_ref (a
)->comdat_type_p
29788 || a
->dw_attr
== DW_AT_specification
)
29789 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
29792 case dw_val_class_str
:
29793 /* Set the string's refcount to 0 so that prune_unused_types_mark
29794 accounts properly for it. */
29795 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
29804 /* Mark the generic parameters and arguments children DIEs of DIE. */
29807 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
29811 if (die
== NULL
|| die
->die_child
== NULL
)
29813 c
= die
->die_child
;
29816 if (is_template_parameter (c
))
29817 prune_unused_types_mark (c
, 1);
29819 } while (c
&& c
!= die
->die_child
);
29822 /* Mark DIE as being used. If DOKIDS is true, then walk down
29823 to DIE's children. */
29826 prune_unused_types_mark (dw_die_ref die
, int dokids
)
29830 if (die
->die_mark
== 0)
29832 /* We haven't done this node yet. Mark it as used. */
29834 /* If this is the DIE of a generic type instantiation,
29835 mark the children DIEs that describe its generic parms and
29837 prune_unused_types_mark_generic_parms_dies (die
);
29839 /* We also have to mark its parents as used.
29840 (But we don't want to mark our parent's kids due to this,
29841 unless it is a class.) */
29842 if (die
->die_parent
)
29843 prune_unused_types_mark (die
->die_parent
,
29844 class_scope_p (die
->die_parent
));
29846 /* Mark any referenced nodes. */
29847 prune_unused_types_walk_attribs (die
);
29849 /* If this node is a specification,
29850 also mark the definition, if it exists. */
29851 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
29852 prune_unused_types_mark (die
->die_definition
, 1);
29855 if (dokids
&& die
->die_mark
!= 2)
29857 /* We need to walk the children, but haven't done so yet.
29858 Remember that we've walked the kids. */
29861 /* If this is an array type, we need to make sure our
29862 kids get marked, even if they're types. If we're
29863 breaking out types into comdat sections, do this
29864 for all type definitions. */
29865 if (die
->die_tag
== DW_TAG_array_type
29866 || (use_debug_types
29867 && is_type_die (die
) && ! is_declaration_die (die
)))
29868 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
29870 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
29874 /* For local classes, look if any static member functions were emitted
29875 and if so, mark them. */
29878 prune_unused_types_walk_local_classes (dw_die_ref die
)
29882 if (die
->die_mark
== 2)
29885 switch (die
->die_tag
)
29887 case DW_TAG_structure_type
:
29888 case DW_TAG_union_type
:
29889 case DW_TAG_class_type
:
29890 case DW_TAG_interface_type
:
29893 case DW_TAG_subprogram
:
29894 if (!get_AT_flag (die
, DW_AT_declaration
)
29895 || die
->die_definition
!= NULL
)
29896 prune_unused_types_mark (die
, 1);
29903 /* Mark children. */
29904 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
29907 /* Walk the tree DIE and mark types that we actually use. */
29910 prune_unused_types_walk (dw_die_ref die
)
29914 /* Don't do anything if this node is already marked and
29915 children have been marked as well. */
29916 if (die
->die_mark
== 2)
29919 switch (die
->die_tag
)
29921 case DW_TAG_structure_type
:
29922 case DW_TAG_union_type
:
29923 case DW_TAG_class_type
:
29924 case DW_TAG_interface_type
:
29925 if (die
->die_perennial_p
)
29928 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
29929 if (c
->die_tag
== DW_TAG_subprogram
)
29932 /* Finding used static member functions inside of classes
29933 is needed just for local classes, because for other classes
29934 static member function DIEs with DW_AT_specification
29935 are emitted outside of the DW_TAG_*_type. If we ever change
29936 it, we'd need to call this even for non-local classes. */
29938 prune_unused_types_walk_local_classes (die
);
29940 /* It's a type node --- don't mark it. */
29943 case DW_TAG_const_type
:
29944 case DW_TAG_packed_type
:
29945 case DW_TAG_pointer_type
:
29946 case DW_TAG_reference_type
:
29947 case DW_TAG_rvalue_reference_type
:
29948 case DW_TAG_volatile_type
:
29949 case DW_TAG_typedef
:
29950 case DW_TAG_array_type
:
29951 case DW_TAG_friend
:
29952 case DW_TAG_enumeration_type
:
29953 case DW_TAG_subroutine_type
:
29954 case DW_TAG_string_type
:
29955 case DW_TAG_set_type
:
29956 case DW_TAG_subrange_type
:
29957 case DW_TAG_ptr_to_member_type
:
29958 case DW_TAG_file_type
:
29959 /* Type nodes are useful only when other DIEs reference them --- don't
29963 case DW_TAG_dwarf_procedure
:
29964 /* Likewise for DWARF procedures. */
29966 if (die
->die_perennial_p
)
29971 case DW_TAG_variable
:
29972 if (flag_debug_only_used_symbols
)
29974 if (die
->die_perennial_p
)
29977 /* For static data members, the declaration in the class is supposed
29978 to have DW_TAG_member tag in DWARF{3,4} but DW_TAG_variable in
29979 DWARF5. DW_TAG_member will be marked, so mark even such
29980 DW_TAG_variables in DWARF5, as long as it has DW_AT_const_value
29982 if (dwarf_version
>= 5
29983 && class_scope_p (die
->die_parent
)
29984 && get_AT (die
, DW_AT_const_value
))
29987 /* premark_used_variables marks external variables --- don't mark
29988 them here. But function-local externals are always considered
29990 if (get_AT (die
, DW_AT_external
))
29992 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
29993 if (c
->die_tag
== DW_TAG_subprogram
)
30002 /* Mark everything else. */
30006 if (die
->die_mark
== 0)
30010 /* Now, mark any dies referenced from here. */
30011 prune_unused_types_walk_attribs (die
);
30016 /* Mark children. */
30017 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
30020 /* Increment the string counts on strings referred to from DIE's
30024 prune_unused_types_update_strings (dw_die_ref die
)
30029 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
30030 if (AT_class (a
) == dw_val_class_str
)
30032 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
30034 /* Avoid unnecessarily putting strings that are used less than
30035 twice in the hash table. */
30036 if (s
->form
!= DW_FORM_line_strp
30038 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2)))
30040 indirect_string_node
**slot
30041 = debug_str_hash
->find_slot_with_hash (s
->str
,
30042 htab_hash_string (s
->str
),
30044 gcc_assert (*slot
== NULL
);
30050 /* Mark DIE and its children as removed. */
30053 mark_removed (dw_die_ref die
)
30056 die
->removed
= true;
30057 FOR_EACH_CHILD (die
, c
, mark_removed (c
));
30060 /* Remove from the tree DIE any dies that aren't marked. */
30063 prune_unused_types_prune (dw_die_ref die
)
30067 gcc_assert (die
->die_mark
);
30068 prune_unused_types_update_strings (die
);
30070 if (! die
->die_child
)
30073 c
= die
->die_child
;
30075 dw_die_ref prev
= c
, next
;
30076 for (c
= c
->die_sib
; ! c
->die_mark
; c
= next
)
30077 if (c
== die
->die_child
)
30079 /* No marked children between 'prev' and the end of the list. */
30081 /* No marked children at all. */
30082 die
->die_child
= NULL
;
30085 prev
->die_sib
= c
->die_sib
;
30086 die
->die_child
= prev
;
30099 if (c
!= prev
->die_sib
)
30101 prune_unused_types_prune (c
);
30102 } while (c
!= die
->die_child
);
30105 /* Remove dies representing declarations that we never use. */
30108 prune_unused_types (void)
30111 limbo_die_node
*node
;
30112 comdat_type_node
*ctnode
;
30113 pubname_entry
*pub
;
30114 dw_die_ref base_type
;
30116 #if ENABLE_ASSERT_CHECKING
30117 /* All the marks should already be clear. */
30118 verify_marks_clear (comp_unit_die ());
30119 for (node
= limbo_die_list
; node
; node
= node
->next
)
30120 verify_marks_clear (node
->die
);
30121 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
30122 verify_marks_clear (ctnode
->root_die
);
30123 #endif /* ENABLE_ASSERT_CHECKING */
30125 /* Mark types that are used in global variables. */
30126 premark_types_used_by_global_vars ();
30128 /* Mark variables used in the symtab. */
30129 if (flag_debug_only_used_symbols
)
30130 premark_used_variables ();
30132 /* Set the mark on nodes that are actually used. */
30133 prune_unused_types_walk (comp_unit_die ());
30134 for (node
= limbo_die_list
; node
; node
= node
->next
)
30135 prune_unused_types_walk (node
->die
);
30136 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
30138 prune_unused_types_walk (ctnode
->root_die
);
30139 prune_unused_types_mark (ctnode
->type_die
, 1);
30142 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
30143 are unusual in that they are pubnames that are the children of pubtypes.
30144 They should only be marked via their parent DW_TAG_enumeration_type die,
30145 not as roots in themselves. */
30146 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
30147 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
30148 prune_unused_types_mark (pub
->die
, 1);
30149 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
30150 prune_unused_types_mark (base_type
, 1);
30152 /* Also set the mark on nodes that could be referenced by
30153 DW_TAG_call_site DW_AT_call_origin (i.e. direct call callees) or
30154 by DW_TAG_inlined_subroutine origins. */
30155 cgraph_node
*cnode
;
30156 FOR_EACH_FUNCTION (cnode
)
30157 if (cnode
->referred_to_p (false))
30159 dw_die_ref die
= lookup_decl_die (cnode
->decl
);
30160 if (die
== NULL
|| die
->die_mark
)
30162 for (cgraph_edge
*e
= cnode
->callers
; e
; e
= e
->next_caller
)
30163 if (e
->caller
!= cnode
)
30165 prune_unused_types_mark (die
, 1);
30170 if (debug_str_hash
)
30171 debug_str_hash
->empty ();
30172 if (skeleton_debug_str_hash
)
30173 skeleton_debug_str_hash
->empty ();
30174 prune_unused_types_prune (comp_unit_die ());
30175 for (limbo_die_node
**pnode
= &limbo_die_list
; *pnode
; )
30178 if (!node
->die
->die_mark
)
30179 *pnode
= node
->next
;
30182 prune_unused_types_prune (node
->die
);
30183 pnode
= &node
->next
;
30186 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
30187 prune_unused_types_prune (ctnode
->root_die
);
30189 /* Leave the marks clear. */
30190 prune_unmark_dies (comp_unit_die ());
30191 for (node
= limbo_die_list
; node
; node
= node
->next
)
30192 prune_unmark_dies (node
->die
);
30193 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
30194 prune_unmark_dies (ctnode
->root_die
);
30197 /* Helpers to manipulate hash table of comdat type units. */
30199 struct comdat_type_hasher
: nofree_ptr_hash
<comdat_type_node
>
30201 static inline hashval_t
hash (const comdat_type_node
*);
30202 static inline bool equal (const comdat_type_node
*, const comdat_type_node
*);
30206 comdat_type_hasher::hash (const comdat_type_node
*type_node
)
30209 memcpy (&h
, type_node
->signature
, sizeof (h
));
30214 comdat_type_hasher::equal (const comdat_type_node
*type_node_1
,
30215 const comdat_type_node
*type_node_2
)
30217 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
30218 DWARF_TYPE_SIGNATURE_SIZE
));
30221 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
30222 to the location it would have been added, should we know its
30223 DECL_ASSEMBLER_NAME when we added other attributes. This will
30224 probably improve compactness of debug info, removing equivalent
30225 abbrevs, and hide any differences caused by deferring the
30226 computation of the assembler name, triggered by e.g. PCH. */
30229 move_linkage_attr (dw_die_ref die
)
30231 unsigned ix
= vec_safe_length (die
->die_attr
);
30232 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
30234 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
30235 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
30239 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
30241 if (prev
->dw_attr
== DW_AT_decl_line
30242 || prev
->dw_attr
== DW_AT_decl_column
30243 || prev
->dw_attr
== DW_AT_name
)
30247 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
30249 die
->die_attr
->pop ();
30250 die
->die_attr
->quick_insert (ix
, linkage
);
30254 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
30255 referenced from typed stack ops and count how often they are used. */
30258 mark_base_types (dw_loc_descr_ref loc
)
30260 dw_die_ref base_type
= NULL
;
30262 for (; loc
; loc
= loc
->dw_loc_next
)
30264 switch (loc
->dw_loc_opc
)
30266 case DW_OP_regval_type
:
30267 case DW_OP_deref_type
:
30268 case DW_OP_GNU_regval_type
:
30269 case DW_OP_GNU_deref_type
:
30270 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
30272 case DW_OP_convert
:
30273 case DW_OP_reinterpret
:
30274 case DW_OP_GNU_convert
:
30275 case DW_OP_GNU_reinterpret
:
30276 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
30279 case DW_OP_const_type
:
30280 case DW_OP_GNU_const_type
:
30281 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
30283 case DW_OP_entry_value
:
30284 case DW_OP_GNU_entry_value
:
30285 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
30290 gcc_assert (base_type
->die_parent
== comp_unit_die ());
30291 if (base_type
->die_mark
)
30292 base_type
->die_mark
++;
30295 base_types
.safe_push (base_type
);
30296 base_type
->die_mark
= 1;
30301 /* Stripped-down variant of resolve_addr, mark DW_TAG_base_type nodes
30302 referenced from typed stack ops and count how often they are used. */
30305 mark_base_types (dw_die_ref die
)
30309 dw_loc_list_ref
*curr
;
30312 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
30313 switch (AT_class (a
))
30315 case dw_val_class_loc_list
:
30316 curr
= AT_loc_list_ptr (a
);
30319 mark_base_types ((*curr
)->expr
);
30320 curr
= &(*curr
)->dw_loc_next
;
30324 case dw_val_class_loc
:
30325 mark_base_types (AT_loc (a
));
30332 FOR_EACH_CHILD (die
, c
, mark_base_types (c
));
30335 /* Comparison function for sorting marked base types. */
30338 base_type_cmp (const void *x
, const void *y
)
30340 dw_die_ref dx
= *(const dw_die_ref
*) x
;
30341 dw_die_ref dy
= *(const dw_die_ref
*) y
;
30342 unsigned int byte_size1
, byte_size2
;
30343 unsigned int encoding1
, encoding2
;
30344 unsigned int align1
, align2
;
30345 if (dx
->die_mark
> dy
->die_mark
)
30347 if (dx
->die_mark
< dy
->die_mark
)
30349 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
30350 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
30351 if (byte_size1
< byte_size2
)
30353 if (byte_size1
> byte_size2
)
30355 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
30356 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
30357 if (encoding1
< encoding2
)
30359 if (encoding1
> encoding2
)
30361 align1
= get_AT_unsigned (dx
, DW_AT_alignment
);
30362 align2
= get_AT_unsigned (dy
, DW_AT_alignment
);
30363 if (align1
< align2
)
30365 if (align1
> align2
)
30370 /* Move base types marked by mark_base_types as early as possible
30371 in the CU, sorted by decreasing usage count both to make the
30372 uleb128 references as small as possible and to make sure they
30373 will have die_offset already computed by calc_die_sizes when
30374 sizes of typed stack loc ops is computed. */
30377 move_marked_base_types (void)
30380 dw_die_ref base_type
, die
, c
;
30382 if (base_types
.is_empty ())
30385 /* Sort by decreasing usage count, they will be added again in that
30387 base_types
.qsort (base_type_cmp
);
30388 die
= comp_unit_die ();
30389 c
= die
->die_child
;
30392 dw_die_ref prev
= c
;
30394 while (c
->die_mark
)
30396 remove_child_with_prev (c
, prev
);
30397 /* As base types got marked, there must be at least
30398 one node other than DW_TAG_base_type. */
30399 gcc_assert (die
->die_child
!= NULL
);
30403 while (c
!= die
->die_child
);
30404 gcc_assert (die
->die_child
);
30405 c
= die
->die_child
;
30406 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
30408 base_type
->die_mark
= 0;
30409 base_type
->die_sib
= c
->die_sib
;
30410 c
->die_sib
= base_type
;
30415 /* Helper function for resolve_addr, attempt to resolve
30416 one CONST_STRING, return true if successful. Similarly verify that
30417 SYMBOL_REFs refer to variables emitted in the current CU. */
30420 resolve_one_addr (rtx
*addr
)
30424 if (GET_CODE (rtl
) == CONST_STRING
)
30426 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
30427 tree t
= build_string (len
, XSTR (rtl
, 0));
30428 tree tlen
= size_int (len
- 1);
30430 = build_array_type (char_type_node
, build_index_type (tlen
));
30431 rtl
= lookup_constant_def (t
);
30432 if (!rtl
|| !MEM_P (rtl
))
30434 rtl
= XEXP (rtl
, 0);
30435 if (GET_CODE (rtl
) == SYMBOL_REF
30436 && SYMBOL_REF_DECL (rtl
)
30437 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
30439 vec_safe_push (used_rtx_array
, rtl
);
30444 if (GET_CODE (rtl
) == SYMBOL_REF
30445 && SYMBOL_REF_DECL (rtl
))
30447 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
30449 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
30452 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
30456 if (GET_CODE (rtl
) == CONST
)
30458 subrtx_ptr_iterator::array_type array
;
30459 FOR_EACH_SUBRTX_PTR (iter
, array
, &XEXP (rtl
, 0), ALL
)
30460 if (!resolve_one_addr (*iter
))
30467 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
30468 if possible, and create DW_TAG_dwarf_procedure that can be referenced
30469 from DW_OP_implicit_pointer if the string hasn't been seen yet. */
30472 string_cst_pool_decl (tree t
)
30474 rtx rtl
= output_constant_def (t
, 1);
30475 unsigned char *array
;
30476 dw_loc_descr_ref l
;
30481 if (!rtl
|| !MEM_P (rtl
))
30483 rtl
= XEXP (rtl
, 0);
30484 if (GET_CODE (rtl
) != SYMBOL_REF
30485 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
30488 decl
= SYMBOL_REF_DECL (rtl
);
30489 if (!lookup_decl_die (decl
))
30491 len
= TREE_STRING_LENGTH (t
);
30492 vec_safe_push (used_rtx_array
, rtl
);
30493 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
30494 array
= ggc_vec_alloc
<unsigned char> (len
);
30495 memcpy (array
, TREE_STRING_POINTER (t
), len
);
30496 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
30497 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
30498 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
30499 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
30500 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
30501 add_AT_loc (ref
, DW_AT_location
, l
);
30502 equate_decl_number_to_die (decl
, ref
);
30507 /* Helper function of resolve_addr_in_expr. LOC is
30508 a DW_OP_addr followed by DW_OP_stack_value, either at the start
30509 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
30510 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
30511 with DW_OP_implicit_pointer if possible
30512 and return true, if unsuccessful, return false. */
30515 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
30517 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
30518 HOST_WIDE_INT offset
= 0;
30519 dw_die_ref ref
= NULL
;
30522 if (GET_CODE (rtl
) == CONST
30523 && GET_CODE (XEXP (rtl
, 0)) == PLUS
30524 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
30526 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
30527 rtl
= XEXP (XEXP (rtl
, 0), 0);
30529 if (GET_CODE (rtl
) == CONST_STRING
)
30531 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
30532 tree t
= build_string (len
, XSTR (rtl
, 0));
30533 tree tlen
= size_int (len
- 1);
30536 = build_array_type (char_type_node
, build_index_type (tlen
));
30537 rtl
= string_cst_pool_decl (t
);
30541 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
30543 decl
= SYMBOL_REF_DECL (rtl
);
30544 if (VAR_P (decl
) && !DECL_EXTERNAL (decl
))
30546 ref
= lookup_decl_die (decl
);
30547 if (ref
&& (get_AT (ref
, DW_AT_location
)
30548 || get_AT (ref
, DW_AT_const_value
)))
30550 loc
->dw_loc_opc
= dwarf_OP (DW_OP_implicit_pointer
);
30551 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
30552 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
30553 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
30554 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
30555 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
30556 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
30564 /* Helper function for resolve_addr, handle one location
30565 expression, return false if at least one CONST_STRING or SYMBOL_REF in
30566 the location list couldn't be resolved. */
30569 resolve_addr_in_expr (dw_attr_node
*a
, dw_loc_descr_ref loc
)
30571 dw_loc_descr_ref keep
= NULL
;
30572 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
30573 switch (loc
->dw_loc_opc
)
30576 if (!resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
30579 || prev
->dw_loc_opc
== DW_OP_piece
30580 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
30581 && loc
->dw_loc_next
30582 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
30583 && (!dwarf_strict
|| dwarf_version
>= 5)
30584 && optimize_one_addr_into_implicit_ptr (loc
))
30589 case DW_OP_GNU_addr_index
:
30591 case DW_OP_GNU_const_index
:
30593 if ((loc
->dw_loc_opc
== DW_OP_GNU_addr_index
30594 || loc
->dw_loc_opc
== DW_OP_addrx
)
30595 || ((loc
->dw_loc_opc
== DW_OP_GNU_const_index
30596 || loc
->dw_loc_opc
== DW_OP_constx
)
30599 rtx rtl
= loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
;
30600 if (!resolve_one_addr (&rtl
))
30602 remove_addr_table_entry (loc
->dw_loc_oprnd1
.val_entry
);
30603 loc
->dw_loc_oprnd1
.val_entry
30604 = add_addr_table_entry (rtl
, ate_kind_rtx
);
30607 case DW_OP_const4u
:
30608 case DW_OP_const8u
:
30610 && !resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
30613 case DW_OP_plus_uconst
:
30614 if (size_of_loc_descr (loc
)
30615 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
30617 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
30619 dw_loc_descr_ref repl
30620 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
30621 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
30622 add_loc_descr (&repl
, loc
->dw_loc_next
);
30626 case DW_OP_implicit_value
:
30627 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
30628 && !resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
))
30631 case DW_OP_implicit_pointer
:
30632 case DW_OP_GNU_implicit_pointer
:
30633 case DW_OP_GNU_parameter_ref
:
30634 case DW_OP_GNU_variable_value
:
30635 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
30638 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
30641 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
30642 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
30643 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
30645 if (loc
->dw_loc_opc
== DW_OP_GNU_variable_value
)
30648 && loc
->dw_loc_next
== NULL
30649 && AT_class (a
) == dw_val_class_loc
)
30650 switch (a
->dw_attr
)
30652 /* Following attributes allow both exprloc and reference,
30653 so if the whole expression is DW_OP_GNU_variable_value
30654 alone we could transform it into reference. */
30655 case DW_AT_byte_size
:
30656 case DW_AT_bit_size
:
30657 case DW_AT_lower_bound
:
30658 case DW_AT_upper_bound
:
30659 case DW_AT_bit_stride
:
30661 case DW_AT_allocated
:
30662 case DW_AT_associated
:
30663 case DW_AT_byte_stride
:
30664 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
30665 a
->dw_attr_val
.val_entry
= NULL
;
30666 a
->dw_attr_val
.v
.val_die_ref
.die
30667 = loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
30668 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
30677 case DW_OP_const_type
:
30678 case DW_OP_regval_type
:
30679 case DW_OP_deref_type
:
30680 case DW_OP_convert
:
30681 case DW_OP_reinterpret
:
30682 case DW_OP_GNU_const_type
:
30683 case DW_OP_GNU_regval_type
:
30684 case DW_OP_GNU_deref_type
:
30685 case DW_OP_GNU_convert
:
30686 case DW_OP_GNU_reinterpret
:
30687 while (loc
->dw_loc_next
30688 && (loc
->dw_loc_next
->dw_loc_opc
== DW_OP_convert
30689 || loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
))
30691 dw_die_ref base1
, base2
;
30692 unsigned enc1
, enc2
, size1
, size2
;
30693 if (loc
->dw_loc_opc
== DW_OP_regval_type
30694 || loc
->dw_loc_opc
== DW_OP_deref_type
30695 || loc
->dw_loc_opc
== DW_OP_GNU_regval_type
30696 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
30697 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
30698 else if (loc
->dw_loc_oprnd1
.val_class
30699 == dw_val_class_unsigned_const
)
30702 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
30703 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
30704 == dw_val_class_unsigned_const
)
30706 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
30707 gcc_assert (base1
->die_tag
== DW_TAG_base_type
30708 && base2
->die_tag
== DW_TAG_base_type
);
30709 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
30710 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
30711 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
30712 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
30714 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
30715 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
30719 /* Optimize away next DW_OP_convert after
30720 adjusting LOC's base type die reference. */
30721 if (loc
->dw_loc_opc
== DW_OP_regval_type
30722 || loc
->dw_loc_opc
== DW_OP_deref_type
30723 || loc
->dw_loc_opc
== DW_OP_GNU_regval_type
30724 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
30725 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
30727 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
30728 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
30731 /* Don't change integer DW_OP_convert after e.g. floating
30732 point typed stack entry. */
30733 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
30734 keep
= loc
->dw_loc_next
;
30744 /* Helper function of resolve_addr. DIE had DW_AT_location of
30745 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
30746 and DW_OP_addr couldn't be resolved. resolve_addr has already
30747 removed the DW_AT_location attribute. This function attempts to
30748 add a new DW_AT_location attribute with DW_OP_implicit_pointer
30749 to it or DW_AT_const_value attribute, if possible. */
30752 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
30755 || lookup_decl_die (decl
) != die
30756 || DECL_EXTERNAL (decl
)
30757 || !TREE_STATIC (decl
)
30758 || DECL_INITIAL (decl
) == NULL_TREE
30759 || DECL_P (DECL_INITIAL (decl
))
30760 || get_AT (die
, DW_AT_const_value
))
30763 tree init
= DECL_INITIAL (decl
);
30764 HOST_WIDE_INT offset
= 0;
30765 /* For variables that have been optimized away and thus
30766 don't have a memory location, see if we can emit
30767 DW_AT_const_value instead. */
30768 if (tree_add_const_value_attribute (die
, init
))
30770 if (dwarf_strict
&& dwarf_version
< 5)
30772 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
30773 and ADDR_EXPR refers to a decl that has DW_AT_location or
30774 DW_AT_const_value (but isn't addressable, otherwise
30775 resolving the original DW_OP_addr wouldn't fail), see if
30776 we can add DW_OP_implicit_pointer. */
30778 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
30779 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
30781 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
30782 init
= TREE_OPERAND (init
, 0);
30785 if (TREE_CODE (init
) != ADDR_EXPR
)
30787 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
30788 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
30789 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
30790 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
30791 && TREE_OPERAND (init
, 0) != decl
))
30794 dw_loc_descr_ref l
;
30796 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
30798 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
30801 decl
= SYMBOL_REF_DECL (rtl
);
30804 decl
= TREE_OPERAND (init
, 0);
30805 ref
= lookup_decl_die (decl
);
30807 || (!get_AT (ref
, DW_AT_location
)
30808 && !get_AT (ref
, DW_AT_const_value
)))
30810 l
= new_loc_descr (dwarf_OP (DW_OP_implicit_pointer
), 0, offset
);
30811 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
30812 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
30813 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
30814 add_AT_loc (die
, DW_AT_location
, l
);
30818 /* Return NULL if l is a DWARF expression, or first op that is not
30819 valid DWARF expression. */
30821 static dw_loc_descr_ref
30822 non_dwarf_expression (dw_loc_descr_ref l
)
30826 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
30828 switch (l
->dw_loc_opc
)
30831 case DW_OP_implicit_value
:
30832 case DW_OP_stack_value
:
30833 case DW_OP_implicit_pointer
:
30834 case DW_OP_GNU_implicit_pointer
:
30835 case DW_OP_GNU_parameter_ref
:
30837 case DW_OP_bit_piece
:
30842 l
= l
->dw_loc_next
;
30847 /* Return adjusted copy of EXPR:
30848 If it is empty DWARF expression, return it.
30849 If it is valid non-empty DWARF expression,
30850 return copy of EXPR with DW_OP_deref appended to it.
30851 If it is DWARF expression followed by DW_OP_reg{N,x}, return
30852 copy of the DWARF expression with DW_OP_breg{N,x} <0> appended.
30853 If it is DWARF expression followed by DW_OP_stack_value, return
30854 copy of the DWARF expression without anything appended.
30855 Otherwise, return NULL. */
30857 static dw_loc_descr_ref
30858 copy_deref_exprloc (dw_loc_descr_ref expr
)
30860 dw_loc_descr_ref tail
= NULL
;
30865 dw_loc_descr_ref l
= non_dwarf_expression (expr
);
30866 if (l
&& l
->dw_loc_next
)
30871 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
30872 tail
= new_loc_descr ((enum dwarf_location_atom
)
30873 (DW_OP_breg0
+ (l
->dw_loc_opc
- DW_OP_reg0
)),
30876 switch (l
->dw_loc_opc
)
30879 tail
= new_loc_descr (DW_OP_bregx
,
30880 l
->dw_loc_oprnd1
.v
.val_unsigned
, 0);
30882 case DW_OP_stack_value
:
30889 tail
= new_loc_descr (DW_OP_deref
, 0, 0);
30891 dw_loc_descr_ref ret
= NULL
, *p
= &ret
;
30894 *p
= new_loc_descr (expr
->dw_loc_opc
, 0, 0);
30895 (*p
)->dw_loc_oprnd1
= expr
->dw_loc_oprnd1
;
30896 (*p
)->dw_loc_oprnd2
= expr
->dw_loc_oprnd2
;
30897 p
= &(*p
)->dw_loc_next
;
30898 expr
= expr
->dw_loc_next
;
30904 /* For DW_AT_string_length attribute with DW_OP_GNU_variable_value
30905 reference to a variable or argument, adjust it if needed and return:
30906 -1 if the DW_AT_string_length attribute and DW_AT_{string_length_,}byte_size
30907 attribute if present should be removed
30908 0 keep the attribute perhaps with minor modifications, no need to rescan
30909 1 if the attribute has been successfully adjusted. */
30912 optimize_string_length (dw_attr_node
*a
)
30914 dw_loc_descr_ref l
= AT_loc (a
), lv
;
30916 if (l
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
30918 tree decl
= l
->dw_loc_oprnd1
.v
.val_decl_ref
;
30919 die
= lookup_decl_die (decl
);
30922 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
30923 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= die
;
30924 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
30930 die
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
30932 /* DWARF5 allows reference class, so we can then reference the DIE.
30933 Only do this for DW_OP_GNU_variable_value DW_OP_stack_value. */
30934 if (l
->dw_loc_next
!= NULL
&& dwarf_version
>= 5)
30936 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
30937 a
->dw_attr_val
.val_entry
= NULL
;
30938 a
->dw_attr_val
.v
.val_die_ref
.die
= die
;
30939 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
30943 dw_attr_node
*av
= get_AT (die
, DW_AT_location
);
30945 bool non_dwarf_expr
= false;
30948 return dwarf_strict
? -1 : 0;
30949 switch (AT_class (av
))
30951 case dw_val_class_loc_list
:
30952 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
30953 if (d
->expr
&& non_dwarf_expression (d
->expr
))
30954 non_dwarf_expr
= true;
30956 case dw_val_class_view_list
:
30957 gcc_unreachable ();
30958 case dw_val_class_loc
:
30961 return dwarf_strict
? -1 : 0;
30962 if (non_dwarf_expression (lv
))
30963 non_dwarf_expr
= true;
30966 return dwarf_strict
? -1 : 0;
30969 /* If it is safe to transform DW_OP_GNU_variable_value DW_OP_stack_value
30970 into DW_OP_call4 or DW_OP_GNU_variable_value into
30971 DW_OP_call4 DW_OP_deref, do so. */
30972 if (!non_dwarf_expr
30973 && (l
->dw_loc_next
!= NULL
|| AT_class (av
) == dw_val_class_loc
))
30975 l
->dw_loc_opc
= DW_OP_call4
;
30976 if (l
->dw_loc_next
)
30977 l
->dw_loc_next
= NULL
;
30979 l
->dw_loc_next
= new_loc_descr (DW_OP_deref
, 0, 0);
30983 /* For DW_OP_GNU_variable_value DW_OP_stack_value, we can just
30984 copy over the DW_AT_location attribute from die to a. */
30985 if (l
->dw_loc_next
!= NULL
)
30987 a
->dw_attr_val
= av
->dw_attr_val
;
30991 dw_loc_list_ref list
, *p
;
30992 switch (AT_class (av
))
30994 case dw_val_class_loc_list
:
30997 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
30999 lv
= copy_deref_exprloc (d
->expr
);
31002 *p
= new_loc_list (lv
, d
->begin
, d
->vbegin
, d
->end
, d
->vend
, d
->section
);
31003 p
= &(*p
)->dw_loc_next
;
31005 else if (!dwarf_strict
&& d
->expr
)
31009 return dwarf_strict
? -1 : 0;
31010 a
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
31012 *AT_loc_list_ptr (a
) = list
;
31014 case dw_val_class_loc
:
31015 lv
= copy_deref_exprloc (AT_loc (av
));
31017 return dwarf_strict
? -1 : 0;
31018 a
->dw_attr_val
.v
.val_loc
= lv
;
31021 gcc_unreachable ();
31025 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
31026 an address in .rodata section if the string literal is emitted there,
31027 or remove the containing location list or replace DW_AT_const_value
31028 with DW_AT_location and empty location expression, if it isn't found
31029 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
31030 to something that has been emitted in the current CU. */
31033 resolve_addr (dw_die_ref die
)
31037 dw_loc_list_ref
*curr
, *start
, loc
;
31039 bool remove_AT_byte_size
= false;
31041 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
31042 switch (AT_class (a
))
31044 case dw_val_class_loc_list
:
31045 start
= curr
= AT_loc_list_ptr (a
);
31048 /* The same list can be referenced more than once. See if we have
31049 already recorded the result from a previous pass. */
31051 *curr
= loc
->dw_loc_next
;
31052 else if (!loc
->resolved_addr
)
31054 /* As things stand, we do not expect or allow one die to
31055 reference a suffix of another die's location list chain.
31056 References must be identical or completely separate.
31057 There is therefore no need to cache the result of this
31058 pass on any list other than the first; doing so
31059 would lead to unnecessary writes. */
31062 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
31063 if (!resolve_addr_in_expr (a
, (*curr
)->expr
))
31065 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
31066 dw_loc_descr_ref l
= (*curr
)->expr
;
31068 if (next
&& (*curr
)->ll_symbol
)
31070 gcc_assert (!next
->ll_symbol
);
31071 next
->ll_symbol
= (*curr
)->ll_symbol
;
31072 next
->vl_symbol
= (*curr
)->vl_symbol
;
31074 if (dwarf_split_debug_info
)
31075 remove_loc_list_addr_table_entries (l
);
31080 mark_base_types ((*curr
)->expr
);
31081 curr
= &(*curr
)->dw_loc_next
;
31085 loc
->resolved_addr
= 1;
31089 loc
->dw_loc_next
= *start
;
31094 remove_AT (die
, a
->dw_attr
);
31098 case dw_val_class_view_list
:
31100 gcc_checking_assert (a
->dw_attr
== DW_AT_GNU_locviews
);
31101 gcc_checking_assert (dwarf2out_locviews_in_attribute ());
31102 dw_val_node
*llnode
31103 = view_list_to_loc_list_val_node (&a
->dw_attr_val
);
31104 /* If we no longer have a loclist, or it no longer needs
31105 views, drop this attribute. */
31106 if (!llnode
|| !llnode
->v
.val_loc_list
->vl_symbol
)
31108 remove_AT (die
, a
->dw_attr
);
31113 case dw_val_class_loc
:
31115 dw_loc_descr_ref l
= AT_loc (a
);
31116 /* DW_OP_GNU_variable_value DW_OP_stack_value or
31117 DW_OP_GNU_variable_value in DW_AT_string_length can be converted
31118 into DW_OP_call4 or DW_OP_call4 DW_OP_deref, which is standard
31119 DWARF4 unlike DW_OP_GNU_variable_value. Or for DWARF5
31120 DW_OP_GNU_variable_value DW_OP_stack_value can be replaced
31121 with DW_FORM_ref referencing the same DIE as
31122 DW_OP_GNU_variable_value used to reference. */
31123 if (a
->dw_attr
== DW_AT_string_length
31125 && l
->dw_loc_opc
== DW_OP_GNU_variable_value
31126 && (l
->dw_loc_next
== NULL
31127 || (l
->dw_loc_next
->dw_loc_next
== NULL
31128 && l
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
)))
31130 switch (optimize_string_length (a
))
31133 remove_AT (die
, a
->dw_attr
);
31135 /* If we drop DW_AT_string_length, we need to drop also
31136 DW_AT_{string_length_,}byte_size. */
31137 remove_AT_byte_size
= true;
31142 /* Even if we keep the optimized DW_AT_string_length,
31143 it might have changed AT_class, so process it again. */
31148 /* For -gdwarf-2 don't attempt to optimize
31149 DW_AT_data_member_location containing
31150 DW_OP_plus_uconst - older consumers might
31151 rely on it being that op instead of a more complex,
31152 but shorter, location description. */
31153 if ((dwarf_version
> 2
31154 || a
->dw_attr
!= DW_AT_data_member_location
31156 || l
->dw_loc_opc
!= DW_OP_plus_uconst
31157 || l
->dw_loc_next
!= NULL
)
31158 && !resolve_addr_in_expr (a
, l
))
31160 if (dwarf_split_debug_info
)
31161 remove_loc_list_addr_table_entries (l
);
31163 && l
->dw_loc_next
== NULL
31164 && l
->dw_loc_opc
== DW_OP_addr
31165 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
31166 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
31167 && a
->dw_attr
== DW_AT_location
)
31169 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
31170 remove_AT (die
, a
->dw_attr
);
31172 optimize_location_into_implicit_ptr (die
, decl
);
31175 if (a
->dw_attr
== DW_AT_string_length
)
31176 /* If we drop DW_AT_string_length, we need to drop also
31177 DW_AT_{string_length_,}byte_size. */
31178 remove_AT_byte_size
= true;
31179 remove_AT (die
, a
->dw_attr
);
31183 mark_base_types (l
);
31186 case dw_val_class_addr
:
31187 if (a
->dw_attr
== DW_AT_const_value
31188 && !resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
))
31190 if (AT_index (a
) != NOT_INDEXED
)
31191 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
31192 remove_AT (die
, a
->dw_attr
);
31195 if ((die
->die_tag
== DW_TAG_call_site
31196 && a
->dw_attr
== DW_AT_call_origin
)
31197 || (die
->die_tag
== DW_TAG_GNU_call_site
31198 && a
->dw_attr
== DW_AT_abstract_origin
))
31200 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
31201 dw_die_ref tdie
= lookup_decl_die (tdecl
);
31204 && DECL_EXTERNAL (tdecl
)
31205 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
31206 && (cdie
= lookup_context_die (DECL_CONTEXT (tdecl
))))
31208 dw_die_ref pdie
= cdie
;
31209 /* Make sure we don't add these DIEs into type units.
31210 We could emit skeleton DIEs for context (namespaces,
31211 outer structs/classes) and a skeleton DIE for the
31212 innermost context with DW_AT_signature pointing to the
31213 type unit. See PR78835. */
31214 while (pdie
&& pdie
->die_tag
!= DW_TAG_type_unit
)
31215 pdie
= pdie
->die_parent
;
31218 /* Creating a full DIE for tdecl is overly expensive and
31219 at this point even wrong when in the LTO phase
31220 as it can end up generating new type DIEs we didn't
31221 output and thus optimize_external_refs will crash. */
31222 tdie
= new_die (DW_TAG_subprogram
, cdie
, NULL_TREE
);
31223 add_AT_flag (tdie
, DW_AT_external
, 1);
31224 add_AT_flag (tdie
, DW_AT_declaration
, 1);
31225 add_linkage_attr (tdie
, tdecl
);
31226 add_name_and_src_coords_attributes (tdie
, tdecl
, true);
31227 equate_decl_number_to_die (tdecl
, tdie
);
31232 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
31233 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
31234 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
31238 if (AT_index (a
) != NOT_INDEXED
)
31239 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
31240 remove_AT (die
, a
->dw_attr
);
31249 if (remove_AT_byte_size
)
31250 remove_AT (die
, dwarf_version
>= 5
31251 ? DW_AT_string_length_byte_size
31252 : DW_AT_byte_size
);
31254 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
31257 /* Helper routines for optimize_location_lists.
31258 This pass tries to share identical local lists in .debug_loc
31261 /* Iteratively hash operands of LOC opcode into HSTATE. */
31264 hash_loc_operands (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
31266 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
31267 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
31269 switch (loc
->dw_loc_opc
)
31271 case DW_OP_const4u
:
31272 case DW_OP_const8u
:
31276 case DW_OP_const1u
:
31277 case DW_OP_const1s
:
31278 case DW_OP_const2u
:
31279 case DW_OP_const2s
:
31280 case DW_OP_const4s
:
31281 case DW_OP_const8s
:
31285 case DW_OP_plus_uconst
:
31321 case DW_OP_deref_size
:
31322 case DW_OP_xderef_size
:
31323 hstate
.add_object (val1
->v
.val_int
);
31330 gcc_assert (val1
->val_class
== dw_val_class_loc
);
31331 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
31332 hstate
.add_object (offset
);
31335 case DW_OP_implicit_value
:
31336 hstate
.add_object (val1
->v
.val_unsigned
);
31337 switch (val2
->val_class
)
31339 case dw_val_class_const
:
31340 hstate
.add_object (val2
->v
.val_int
);
31342 case dw_val_class_vec
:
31344 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
31345 unsigned int len
= val2
->v
.val_vec
.length
;
31347 hstate
.add_int (elt_size
);
31348 hstate
.add_int (len
);
31349 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
31352 case dw_val_class_const_double
:
31353 hstate
.add_object (val2
->v
.val_double
.low
);
31354 hstate
.add_object (val2
->v
.val_double
.high
);
31356 case dw_val_class_wide_int
:
31357 hstate
.add (val2
->v
.val_wide
->get_val (),
31358 get_full_len (*val2
->v
.val_wide
)
31359 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
31361 case dw_val_class_addr
:
31362 inchash::add_rtx (val2
->v
.val_addr
, hstate
);
31365 gcc_unreachable ();
31369 case DW_OP_bit_piece
:
31370 hstate
.add_object (val1
->v
.val_int
);
31371 hstate
.add_object (val2
->v
.val_int
);
31377 unsigned char dtprel
= 0xd1;
31378 hstate
.add_object (dtprel
);
31380 inchash::add_rtx (val1
->v
.val_addr
, hstate
);
31382 case DW_OP_GNU_addr_index
:
31384 case DW_OP_GNU_const_index
:
31389 unsigned char dtprel
= 0xd1;
31390 hstate
.add_object (dtprel
);
31392 inchash::add_rtx (val1
->val_entry
->addr
.rtl
, hstate
);
31395 case DW_OP_implicit_pointer
:
31396 case DW_OP_GNU_implicit_pointer
:
31397 hstate
.add_int (val2
->v
.val_int
);
31399 case DW_OP_entry_value
:
31400 case DW_OP_GNU_entry_value
:
31401 hstate
.add_object (val1
->v
.val_loc
);
31403 case DW_OP_regval_type
:
31404 case DW_OP_deref_type
:
31405 case DW_OP_GNU_regval_type
:
31406 case DW_OP_GNU_deref_type
:
31408 unsigned int byte_size
31409 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
31410 unsigned int encoding
31411 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
31412 hstate
.add_object (val1
->v
.val_int
);
31413 hstate
.add_object (byte_size
);
31414 hstate
.add_object (encoding
);
31417 case DW_OP_convert
:
31418 case DW_OP_reinterpret
:
31419 case DW_OP_GNU_convert
:
31420 case DW_OP_GNU_reinterpret
:
31421 if (val1
->val_class
== dw_val_class_unsigned_const
)
31423 hstate
.add_object (val1
->v
.val_unsigned
);
31427 case DW_OP_const_type
:
31428 case DW_OP_GNU_const_type
:
31430 unsigned int byte_size
31431 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
31432 unsigned int encoding
31433 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
31434 hstate
.add_object (byte_size
);
31435 hstate
.add_object (encoding
);
31436 if (loc
->dw_loc_opc
!= DW_OP_const_type
31437 && loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
31439 hstate
.add_object (val2
->val_class
);
31440 switch (val2
->val_class
)
31442 case dw_val_class_const
:
31443 hstate
.add_object (val2
->v
.val_int
);
31445 case dw_val_class_vec
:
31447 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
31448 unsigned int len
= val2
->v
.val_vec
.length
;
31450 hstate
.add_object (elt_size
);
31451 hstate
.add_object (len
);
31452 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
31455 case dw_val_class_const_double
:
31456 hstate
.add_object (val2
->v
.val_double
.low
);
31457 hstate
.add_object (val2
->v
.val_double
.high
);
31459 case dw_val_class_wide_int
:
31460 hstate
.add (val2
->v
.val_wide
->get_val (),
31461 get_full_len (*val2
->v
.val_wide
)
31462 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
31465 gcc_unreachable ();
31471 /* Other codes have no operands. */
31476 /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
31479 hash_locs (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
31481 dw_loc_descr_ref l
;
31482 bool sizes_computed
= false;
31483 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
31484 size_of_locs (loc
);
31486 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
31488 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
31489 hstate
.add_object (opc
);
31490 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
31492 size_of_locs (loc
);
31493 sizes_computed
= true;
31495 hash_loc_operands (l
, hstate
);
31499 /* Compute hash of the whole location list LIST_HEAD. */
31502 hash_loc_list (dw_loc_list_ref list_head
)
31504 dw_loc_list_ref curr
= list_head
;
31505 inchash::hash hstate
;
31507 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
31509 hstate
.add (curr
->begin
, strlen (curr
->begin
) + 1);
31510 hstate
.add (curr
->end
, strlen (curr
->end
) + 1);
31511 hstate
.add_object (curr
->vbegin
);
31512 hstate
.add_object (curr
->vend
);
31514 hstate
.add (curr
->section
, strlen (curr
->section
) + 1);
31515 hash_locs (curr
->expr
, hstate
);
31517 list_head
->hash
= hstate
.end ();
31520 /* Return true if X and Y opcodes have the same operands. */
31523 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
31525 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
31526 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
31527 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
31528 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
31530 switch (x
->dw_loc_opc
)
31532 case DW_OP_const4u
:
31533 case DW_OP_const8u
:
31537 case DW_OP_const1u
:
31538 case DW_OP_const1s
:
31539 case DW_OP_const2u
:
31540 case DW_OP_const2s
:
31541 case DW_OP_const4s
:
31542 case DW_OP_const8s
:
31546 case DW_OP_plus_uconst
:
31582 case DW_OP_deref_size
:
31583 case DW_OP_xderef_size
:
31584 return valx1
->v
.val_int
== valy1
->v
.val_int
;
31587 /* If splitting debug info, the use of DW_OP_GNU_addr_index
31588 can cause irrelevant differences in dw_loc_addr. */
31589 gcc_assert (valx1
->val_class
== dw_val_class_loc
31590 && valy1
->val_class
== dw_val_class_loc
31591 && (dwarf_split_debug_info
31592 || x
->dw_loc_addr
== y
->dw_loc_addr
));
31593 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
31594 case DW_OP_implicit_value
:
31595 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
31596 || valx2
->val_class
!= valy2
->val_class
)
31598 switch (valx2
->val_class
)
31600 case dw_val_class_const
:
31601 return valx2
->v
.val_int
== valy2
->v
.val_int
;
31602 case dw_val_class_vec
:
31603 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
31604 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
31605 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
31606 valx2
->v
.val_vec
.elt_size
31607 * valx2
->v
.val_vec
.length
) == 0;
31608 case dw_val_class_const_double
:
31609 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
31610 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
31611 case dw_val_class_wide_int
:
31612 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
31613 case dw_val_class_addr
:
31614 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
31616 gcc_unreachable ();
31619 case DW_OP_bit_piece
:
31620 return valx1
->v
.val_int
== valy1
->v
.val_int
31621 && valx2
->v
.val_int
== valy2
->v
.val_int
;
31624 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
31625 case DW_OP_GNU_addr_index
:
31627 case DW_OP_GNU_const_index
:
31630 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
31631 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
31632 return rtx_equal_p (ax1
, ay1
);
31634 case DW_OP_implicit_pointer
:
31635 case DW_OP_GNU_implicit_pointer
:
31636 return valx1
->val_class
== dw_val_class_die_ref
31637 && valx1
->val_class
== valy1
->val_class
31638 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
31639 && valx2
->v
.val_int
== valy2
->v
.val_int
;
31640 case DW_OP_entry_value
:
31641 case DW_OP_GNU_entry_value
:
31642 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
31643 case DW_OP_const_type
:
31644 case DW_OP_GNU_const_type
:
31645 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
31646 || valx2
->val_class
!= valy2
->val_class
)
31648 switch (valx2
->val_class
)
31650 case dw_val_class_const
:
31651 return valx2
->v
.val_int
== valy2
->v
.val_int
;
31652 case dw_val_class_vec
:
31653 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
31654 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
31655 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
31656 valx2
->v
.val_vec
.elt_size
31657 * valx2
->v
.val_vec
.length
) == 0;
31658 case dw_val_class_const_double
:
31659 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
31660 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
31661 case dw_val_class_wide_int
:
31662 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
31664 gcc_unreachable ();
31666 case DW_OP_regval_type
:
31667 case DW_OP_deref_type
:
31668 case DW_OP_GNU_regval_type
:
31669 case DW_OP_GNU_deref_type
:
31670 return valx1
->v
.val_int
== valy1
->v
.val_int
31671 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
31672 case DW_OP_convert
:
31673 case DW_OP_reinterpret
:
31674 case DW_OP_GNU_convert
:
31675 case DW_OP_GNU_reinterpret
:
31676 if (valx1
->val_class
!= valy1
->val_class
)
31678 if (valx1
->val_class
== dw_val_class_unsigned_const
)
31679 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
31680 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
31681 case DW_OP_GNU_parameter_ref
:
31682 return valx1
->val_class
== dw_val_class_die_ref
31683 && valx1
->val_class
== valy1
->val_class
31684 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
31686 /* Other codes have no operands. */
31691 /* Return true if DWARF location expressions X and Y are the same. */
31694 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
31696 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
31697 if (x
->dw_loc_opc
!= y
->dw_loc_opc
31698 || x
->dtprel
!= y
->dtprel
31699 || !compare_loc_operands (x
, y
))
31701 return x
== NULL
&& y
== NULL
;
31704 /* Hashtable helpers. */
31706 struct loc_list_hasher
: nofree_ptr_hash
<dw_loc_list_struct
>
31708 static inline hashval_t
hash (const dw_loc_list_struct
*);
31709 static inline bool equal (const dw_loc_list_struct
*,
31710 const dw_loc_list_struct
*);
31713 /* Return precomputed hash of location list X. */
31716 loc_list_hasher::hash (const dw_loc_list_struct
*x
)
31721 /* Return true if location lists A and B are the same. */
31724 loc_list_hasher::equal (const dw_loc_list_struct
*a
,
31725 const dw_loc_list_struct
*b
)
31729 if (a
->hash
!= b
->hash
)
31731 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
31732 if (strcmp (a
->begin
, b
->begin
) != 0
31733 || strcmp (a
->end
, b
->end
) != 0
31734 || (a
->section
== NULL
) != (b
->section
== NULL
)
31735 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
31736 || a
->vbegin
!= b
->vbegin
|| a
->vend
!= b
->vend
31737 || !compare_locs (a
->expr
, b
->expr
))
31739 return a
== NULL
&& b
== NULL
;
31742 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
31745 /* Recursively optimize location lists referenced from DIE
31746 children and share them whenever possible. */
31749 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type
*htab
)
31754 dw_loc_list_struct
**slot
;
31755 bool drop_locviews
= false;
31756 bool has_locviews
= false;
31758 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
31759 if (AT_class (a
) == dw_val_class_loc_list
)
31761 dw_loc_list_ref list
= AT_loc_list (a
);
31762 /* TODO: perform some optimizations here, before hashing
31763 it and storing into the hash table. */
31764 hash_loc_list (list
);
31765 slot
= htab
->find_slot_with_hash (list
, list
->hash
, INSERT
);
31769 if (loc_list_has_views (list
))
31770 gcc_assert (list
->vl_symbol
);
31771 else if (list
->vl_symbol
)
31773 drop_locviews
= true;
31774 list
->vl_symbol
= NULL
;
31779 if (list
->vl_symbol
&& !(*slot
)->vl_symbol
)
31780 drop_locviews
= true;
31781 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
31784 else if (AT_class (a
) == dw_val_class_view_list
)
31786 gcc_checking_assert (a
->dw_attr
== DW_AT_GNU_locviews
);
31787 has_locviews
= true;
31791 if (drop_locviews
&& has_locviews
)
31792 remove_AT (die
, DW_AT_GNU_locviews
);
31794 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
31798 /* Recursively assign each location list a unique index into the debug_addr
31802 index_location_lists (dw_die_ref die
)
31808 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
31809 if (AT_class (a
) == dw_val_class_loc_list
)
31811 dw_loc_list_ref list
= AT_loc_list (a
);
31812 dw_loc_list_ref curr
;
31813 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
31815 /* Don't index an entry that has already been indexed
31816 or won't be output. Make sure skip_loc_list_entry doesn't
31817 call size_of_locs, because that might cause circular dependency,
31818 index_location_lists requiring address table indexes to be
31819 computed, but adding new indexes through add_addr_table_entry
31820 and address table index computation requiring no new additions
31821 to the hash table. In the rare case of DWARF[234] >= 64KB
31822 location expression, we'll just waste unused address table entry
31824 if (curr
->begin_entry
!= NULL
|| skip_loc_list_entry (curr
))
31828 = add_addr_table_entry (xstrdup (curr
->begin
), ate_kind_label
);
31829 if (dwarf_version
>= 5 && !HAVE_AS_LEB128
)
31831 = add_addr_table_entry (xstrdup (curr
->end
), ate_kind_label
);
31835 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
31838 /* Optimize location lists referenced from DIE
31839 children and share them whenever possible. */
31842 optimize_location_lists (dw_die_ref die
)
31844 loc_list_hash_type
htab (500);
31845 optimize_location_lists_1 (die
, &htab
);
31848 /* Traverse the limbo die list, and add parent/child links. The only
31849 dies without parents that should be here are concrete instances of
31850 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
31851 For concrete instances, we can get the parent die from the abstract
31855 flush_limbo_die_list (void)
31857 limbo_die_node
*node
;
31859 /* get_context_die calls force_decl_die, which can put new DIEs on the
31860 limbo list in LTO mode when nested functions are put in a different
31861 partition than that of their parent function. */
31862 while ((node
= limbo_die_list
))
31864 dw_die_ref die
= node
->die
;
31865 limbo_die_list
= node
->next
;
31867 if (die
->die_parent
== NULL
)
31869 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
31871 if (origin
&& origin
->die_parent
)
31872 add_child_die (origin
->die_parent
, die
);
31873 else if (is_cu_die (die
))
31875 else if (seen_error ())
31876 /* It's OK to be confused by errors in the input. */
31877 add_child_die (comp_unit_die (), die
);
31880 /* In certain situations, the lexical block containing a
31881 nested function can be optimized away, which results
31882 in the nested function die being orphaned. Likewise
31883 with the return type of that nested function. Force
31884 this to be a child of the containing function.
31886 It may happen that even the containing function got fully
31887 inlined and optimized out. In that case we are lost and
31888 assign the empty child. This should not be big issue as
31889 the function is likely unreachable too. */
31890 gcc_assert (node
->created_for
);
31892 if (DECL_P (node
->created_for
))
31893 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
31894 else if (TYPE_P (node
->created_for
))
31895 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
31897 origin
= comp_unit_die ();
31899 add_child_die (origin
, die
);
31905 /* Reset DIEs so we can output them again. */
31908 reset_dies (dw_die_ref die
)
31912 /* Remove stuff we re-generate. */
31914 die
->die_offset
= 0;
31915 die
->die_abbrev
= 0;
31916 remove_AT (die
, DW_AT_sibling
);
31918 FOR_EACH_CHILD (die
, c
, reset_dies (c
));
31921 /* reset_indirect_string removed the references coming from DW_AT_name
31922 and DW_AT_comp_dir attributes on compilation unit DIEs. Readd them as
31923 .debug_line_str strings again. */
31926 adjust_name_comp_dir (dw_die_ref die
)
31928 for (int i
= 0; i
< 2; i
++)
31930 dwarf_attribute attr_kind
= i
? DW_AT_comp_dir
: DW_AT_name
;
31931 dw_attr_node
*a
= get_AT (die
, attr_kind
);
31932 if (a
== NULL
|| a
->dw_attr_val
.val_class
!= dw_val_class_str
)
31935 if (!debug_line_str_hash
)
31936 debug_line_str_hash
31937 = hash_table
<indirect_string_hasher
>::create_ggc (10);
31939 struct indirect_string_node
*node
31940 = find_AT_string_in_table (a
->dw_attr_val
.v
.val_str
->str
,
31941 debug_line_str_hash
);
31942 set_indirect_string (node
);
31943 node
->form
= DW_FORM_line_strp
;
31944 a
->dw_attr_val
.v
.val_str
= node
;
31948 /* Output stuff that dwarf requires at the end of every file,
31949 and generate the DWARF-2 debugging info. */
31952 dwarf2out_finish (const char *filename
)
31954 comdat_type_node
*ctnode
;
31955 dw_die_ref main_comp_unit_die
;
31956 unsigned char checksum
[16];
31957 char dl_section_ref
[MAX_ARTIFICIAL_LABEL_BYTES
];
31959 /* Generate CTF/BTF debug info. */
31960 if ((ctf_debug_info_level
> CTFINFO_LEVEL_NONE
31961 || btf_debuginfo_p ()) && lang_GNU_C ())
31962 ctf_debug_finish (filename
);
31964 /* Skip emitting DWARF if not required. */
31965 if (!dwarf_debuginfo_p ())
31968 /* Flush out any latecomers to the limbo party. */
31969 flush_limbo_die_list ();
31971 if (inline_entry_data_table
)
31972 gcc_assert (inline_entry_data_table
->is_empty ());
31976 verify_die (comp_unit_die ());
31977 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
31978 verify_die (node
->die
);
31981 /* We shouldn't have any symbols with delayed asm names for
31982 DIEs generated after early finish. */
31983 gcc_assert (deferred_asm_name
== NULL
);
31985 gen_remaining_tmpl_value_param_die_attribute ();
31987 if (flag_generate_lto
|| flag_generate_offload
)
31989 gcc_assert (flag_fat_lto_objects
|| flag_generate_offload
);
31991 /* Prune stuff so that dwarf2out_finish runs successfully
31992 for the fat part of the object. */
31993 reset_dies (comp_unit_die ());
31994 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
31995 reset_dies (node
->die
);
31997 hash_table
<comdat_type_hasher
> comdat_type_table (100);
31998 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
32000 comdat_type_node
**slot
32001 = comdat_type_table
.find_slot (ctnode
, INSERT
);
32003 /* Don't reset types twice. */
32004 if (*slot
!= HTAB_EMPTY_ENTRY
)
32007 /* Remove the pointer to the line table. */
32008 remove_AT (ctnode
->root_die
, DW_AT_stmt_list
);
32010 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
32011 reset_dies (ctnode
->root_die
);
32016 /* Reset die CU symbol so we don't output it twice. */
32017 comp_unit_die ()->die_id
.die_symbol
= NULL
;
32019 /* Remove DW_AT_macro and DW_AT_stmt_list from the early output. */
32020 remove_AT (comp_unit_die (), DW_AT_stmt_list
);
32022 remove_AT (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE
);
32024 /* Remove indirect string decisions. */
32025 debug_str_hash
->traverse
<void *, reset_indirect_string
> (NULL
);
32026 if (debug_line_str_hash
)
32028 debug_line_str_hash
->traverse
<void *, reset_indirect_string
> (NULL
);
32029 debug_line_str_hash
= NULL
;
32030 if (asm_outputs_debug_line_str ())
32032 adjust_name_comp_dir (comp_unit_die ());
32033 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
32034 adjust_name_comp_dir (node
->die
);
32039 #if ENABLE_ASSERT_CHECKING
32041 dw_die_ref die
= comp_unit_die (), c
;
32042 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
32045 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
32046 resolve_addr (ctnode
->root_die
);
32047 resolve_addr (comp_unit_die ());
32048 move_marked_base_types ();
32052 fprintf (dump_file
, "DWARF for %s\n", filename
);
32053 print_die (comp_unit_die (), dump_file
);
32056 /* Initialize sections and labels used for actual assembler output. */
32057 unsigned generation
= init_sections_and_labels (false);
32059 /* Traverse the DIE's and add sibling attributes to those DIE's that
32061 add_sibling_attributes (comp_unit_die ());
32062 limbo_die_node
*node
;
32063 for (node
= cu_die_list
; node
; node
= node
->next
)
32064 add_sibling_attributes (node
->die
);
32065 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
32066 add_sibling_attributes (ctnode
->root_die
);
32068 /* When splitting DWARF info, we put some attributes in the
32069 skeleton compile_unit DIE that remains in the .o, while
32070 most attributes go in the DWO compile_unit_die. */
32071 if (dwarf_split_debug_info
)
32073 limbo_die_node
*cu
;
32074 main_comp_unit_die
= gen_compile_unit_die (NULL
);
32075 if (dwarf_version
>= 5)
32076 main_comp_unit_die
->die_tag
= DW_TAG_skeleton_unit
;
32077 cu
= limbo_die_list
;
32078 gcc_assert (cu
->die
== main_comp_unit_die
);
32079 limbo_die_list
= limbo_die_list
->next
;
32080 cu
->next
= cu_die_list
;
32084 main_comp_unit_die
= comp_unit_die ();
32086 /* Output a terminator label for the .text section. */
32087 switch_to_section (text_section
);
32088 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
32089 if (cold_text_section
)
32091 switch_to_section (cold_text_section
);
32092 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
32095 /* We can only use the low/high_pc attributes if all of the code was
32097 if ((!have_multiple_function_sections
32098 && vec_safe_length (switch_text_ranges
) < 2)
32099 || (dwarf_version
< 3 && dwarf_strict
))
32101 const char *end_label
= text_end_label
;
32102 if (vec_safe_length (switch_text_ranges
) == 1)
32103 end_label
= (*switch_text_ranges
)[0];
32104 /* Don't add if the CU has no associated code. */
32105 if (switch_text_ranges
)
32106 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
32113 bool range_list_added
= false;
32114 if (switch_text_ranges
)
32116 const char *prev_loc
= text_section_label
;
32120 FOR_EACH_VEC_ELT (*switch_text_ranges
, idx
, loc
)
32123 add_ranges_by_labels (main_comp_unit_die
, prev_loc
,
32124 loc
, &range_list_added
, true);
32131 add_ranges_by_labels (main_comp_unit_die
, prev_loc
,
32132 text_end_label
, &range_list_added
, true);
32135 if (switch_cold_ranges
)
32137 const char *prev_loc
= cold_text_section_label
;
32141 FOR_EACH_VEC_ELT (*switch_cold_ranges
, idx
, loc
)
32144 add_ranges_by_labels (main_comp_unit_die
, prev_loc
,
32145 loc
, &range_list_added
, true);
32152 add_ranges_by_labels (main_comp_unit_die
, prev_loc
,
32153 cold_end_label
, &range_list_added
, true);
32156 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
32158 if (fde
->ignored_debug
)
32160 if (!fde
->in_std_section
)
32161 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
32162 fde
->dw_fde_end
, &range_list_added
,
32164 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
32165 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
32166 fde
->dw_fde_second_end
, &range_list_added
,
32170 if (range_list_added
)
32172 /* We need to give .debug_loc and .debug_ranges an appropriate
32173 "base address". Use zero so that these addresses become
32174 absolute. Historically, we've emitted the unexpected
32175 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
32176 Emit both to give time for other tools to adapt. */
32177 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
32178 if (! dwarf_strict
&& dwarf_version
< 4)
32179 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
32182 have_multiple_function_sections
= true;
32186 /* AIX Assembler inserts the length, so adjust the reference to match the
32187 offset expected by debuggers. */
32188 strcpy (dl_section_ref
, debug_line_section_label
);
32189 if (XCOFF_DEBUGGING_INFO
)
32190 strcat (dl_section_ref
, DWARF_INITIAL_LENGTH_SIZE_STR
);
32192 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
32193 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
32197 add_AT_macptr (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE
,
32198 macinfo_section_label
);
32200 if (dwarf_split_debug_info
)
32202 if (have_location_lists
)
32204 /* Since we generate the loclists in the split DWARF .dwo
32205 file itself, we don't need to generate a loclists_base
32206 attribute for the split compile unit DIE. That attribute
32207 (and using relocatable sec_offset FORMs) isn't allowed
32208 for a split compile unit. Only if the .debug_loclists
32209 section was in the main file, would we need to generate a
32210 loclists_base attribute here (for the full or skeleton
32213 /* optimize_location_lists calculates the size of the lists,
32214 so index them first, and assign indices to the entries.
32215 Although optimize_location_lists will remove entries from
32216 the table, it only does so for duplicates, and therefore
32217 only reduces ref_counts to 1. */
32218 index_location_lists (comp_unit_die ());
32221 if (dwarf_version
>= 5 && !vec_safe_is_empty (ranges_table
))
32224 if (addr_index_table
!= NULL
)
32226 unsigned int index
= 0;
32228 ->traverse_noresize
<unsigned int *, index_addr_table_entry
>
32234 if (have_location_lists
)
32236 optimize_location_lists (comp_unit_die ());
32237 /* And finally assign indexes to the entries for -gsplit-dwarf. */
32238 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
32239 assign_location_list_indexes (comp_unit_die ());
32242 save_macinfo_strings ();
32244 if (dwarf_split_debug_info
)
32246 unsigned int index
= 0;
32248 /* Add attributes common to skeleton compile_units and
32249 type_units. Because these attributes include strings, it
32250 must be done before freezing the string table. Top-level
32251 skeleton die attrs are added when the skeleton type unit is
32252 created, so ensure it is created by this point. */
32253 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
32254 debug_str_hash
->traverse_noresize
<unsigned int *, index_string
> (&index
);
32257 /* Output all of the compilation units. We put the main one last so that
32258 the offsets are available to output_pubnames. */
32259 for (node
= cu_die_list
; node
; node
= node
->next
)
32260 output_comp_unit (node
->die
, 0, NULL
);
32262 hash_table
<comdat_type_hasher
> comdat_type_table (100);
32263 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
32265 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
32267 /* Don't output duplicate types. */
32268 if (*slot
!= HTAB_EMPTY_ENTRY
)
32271 /* Add a pointer to the line table for the main compilation unit
32272 so that the debugger can make sense of DW_AT_decl_file
32274 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
32275 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
32276 (!dwarf_split_debug_info
32278 : debug_skeleton_line_section_label
));
32280 output_comdat_type_unit (ctnode
, false);
32284 if (dwarf_split_debug_info
)
32287 struct md5_ctx ctx
;
32289 /* Compute a checksum of the comp_unit to use as the dwo_id. */
32290 md5_init_ctx (&ctx
);
32292 die_checksum (comp_unit_die (), &ctx
, &mark
);
32293 unmark_all_dies (comp_unit_die ());
32294 md5_finish_ctx (&ctx
, checksum
);
32296 if (dwarf_version
< 5)
32298 /* Use the first 8 bytes of the checksum as the dwo_id,
32299 and add it to both comp-unit DIEs. */
32300 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
32301 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
32304 /* Add the base offset of the ranges table to the skeleton
32306 if (!vec_safe_is_empty (ranges_table
))
32308 if (dwarf_version
< 5)
32309 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
32310 ranges_section_label
);
32313 output_addr_table ();
32316 /* Output the main compilation unit if non-empty or if .debug_macinfo
32317 or .debug_macro will be emitted. */
32318 output_comp_unit (comp_unit_die (), have_macinfo
,
32319 dwarf_split_debug_info
? checksum
: NULL
);
32321 if (dwarf_split_debug_info
&& info_section_emitted
)
32322 output_skeleton_debug_sections (main_comp_unit_die
, checksum
);
32324 /* Output the abbreviation table. */
32325 if (vec_safe_length (abbrev_die_table
) != 1)
32327 switch_to_section (debug_abbrev_section
);
32328 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
32329 output_abbrev_section ();
32332 /* Output location list section if necessary. */
32333 if (have_location_lists
)
32335 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
32336 char l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
32337 /* Output the location lists info. */
32338 switch_to_section (debug_loc_section
);
32339 if (dwarf_version
>= 5)
32341 ASM_GENERATE_INTERNAL_LABEL (l1
, DEBUG_LOC_SECTION_LABEL
, 2);
32342 ASM_GENERATE_INTERNAL_LABEL (l2
, DEBUG_LOC_SECTION_LABEL
, 3);
32343 if (DWARF_INITIAL_LENGTH_SIZE
- dwarf_offset_size
== 4)
32344 dw2_asm_output_data (4, 0xffffffff,
32345 "Initial length escape value indicating "
32346 "64-bit DWARF extension");
32347 dw2_asm_output_delta (dwarf_offset_size
, l2
, l1
,
32348 "Length of Location Lists");
32349 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
32350 output_dwarf_version ();
32351 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
32352 dw2_asm_output_data (1, 0, "Segment Size");
32353 dw2_asm_output_data (4, dwarf_split_debug_info
? loc_list_idx
: 0,
32354 "Offset Entry Count");
32356 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
32357 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
32359 unsigned int save_loc_list_idx
= loc_list_idx
;
32361 output_loclists_offsets (comp_unit_die ());
32362 gcc_assert (save_loc_list_idx
== loc_list_idx
);
32364 output_location_lists (comp_unit_die ());
32365 if (dwarf_version
>= 5)
32366 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
32369 output_pubtables ();
32371 /* Output the address range information if a CU (.debug_info section)
32372 was emitted. We output an empty table even if we had no functions
32373 to put in it. This because the consumer has no way to tell the
32374 difference between an empty table that we omitted and failure to
32375 generate a table that would have contained data. */
32376 if (info_section_emitted
)
32378 switch_to_section (debug_aranges_section
);
32382 /* Output ranges section if necessary. */
32383 if (!vec_safe_is_empty (ranges_table
))
32385 if (dwarf_version
>= 5)
32387 if (dwarf_split_debug_info
)
32389 /* We don't know right now whether there are any
32390 ranges for .debug_rnglists and any for .debug_rnglists.dwo.
32391 Depending on into which of those two belongs the first
32392 ranges_table entry, emit that section first and that
32393 output_rnglists call will return true if the other kind of
32394 ranges needs to be emitted as well. */
32395 bool dwo
= (*ranges_table
)[0].idx
!= DW_RANGES_IDX_SKELETON
;
32396 if (output_rnglists (generation
, dwo
))
32397 output_rnglists (generation
, !dwo
);
32400 output_rnglists (generation
, false);
32406 /* Have to end the macro section. */
32409 switch_to_section (debug_macinfo_section
);
32410 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
32411 output_macinfo (!dwarf_split_debug_info
? debug_line_section_label
32412 : debug_skeleton_line_section_label
, false);
32413 dw2_asm_output_data (1, 0, "End compilation unit");
32416 /* Output the source line correspondence table. We must do this
32417 even if there is no line information. Otherwise, on an empty
32418 translation unit, we will generate a present, but empty,
32419 .debug_info section. IRIX 6.5 `nm' will then complain when
32420 examining the file. This is done late so that any filenames
32421 used by the debug_info section are marked as 'used'. */
32422 switch_to_section (debug_line_section
);
32423 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
32424 if (! output_asm_line_debug_info ())
32425 output_line_info (false);
32427 if (dwarf_split_debug_info
&& info_section_emitted
)
32429 switch_to_section (debug_skeleton_line_section
);
32430 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
32431 output_line_info (true);
32434 /* If we emitted any indirect strings, output the string table too. */
32435 if (debug_str_hash
|| skeleton_debug_str_hash
)
32436 output_indirect_strings ();
32437 if (debug_line_str_hash
)
32439 switch_to_section (debug_line_str_section
);
32440 const enum dwarf_form form
= DW_FORM_line_strp
;
32441 debug_line_str_hash
->traverse
<enum dwarf_form
,
32442 output_indirect_string
> (form
);
32445 /* ??? Move lvugid out of dwarf2out_source_line and reset it too? */
32446 symview_upper_bound
= 0;
32448 bitmap_clear (zero_view_p
);
32451 /* Returns a hash value for X (which really is a variable_value_struct). */
32454 variable_value_hasher::hash (variable_value_struct
*x
)
32456 return (hashval_t
) x
->decl_id
;
32459 /* Return nonzero if decl_id of variable_value_struct X is the same as
32463 variable_value_hasher::equal (variable_value_struct
*x
, tree y
)
32465 return x
->decl_id
== DECL_UID (y
);
32468 /* Helper function for resolve_variable_value, handle
32469 DW_OP_GNU_variable_value in one location expression.
32470 Return true if exprloc has been changed into loclist. */
32473 resolve_variable_value_in_expr (dw_attr_node
*a
, dw_loc_descr_ref loc
)
32475 dw_loc_descr_ref next
;
32476 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= next
)
32478 next
= loc
->dw_loc_next
;
32479 if (loc
->dw_loc_opc
!= DW_OP_GNU_variable_value
32480 || loc
->dw_loc_oprnd1
.val_class
!= dw_val_class_decl_ref
)
32483 tree decl
= loc
->dw_loc_oprnd1
.v
.val_decl_ref
;
32484 if (DECL_CONTEXT (decl
) != current_function_decl
)
32487 dw_die_ref ref
= lookup_decl_die (decl
);
32490 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
32491 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
32492 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
32495 dw_loc_list_ref l
= loc_list_from_tree (decl
, 0, NULL
);
32498 if (l
->dw_loc_next
)
32500 if (AT_class (a
) != dw_val_class_loc
)
32502 switch (a
->dw_attr
)
32504 /* Following attributes allow both exprloc and loclist
32505 classes, so we can change them into a loclist. */
32506 case DW_AT_location
:
32507 case DW_AT_string_length
:
32508 case DW_AT_return_addr
:
32509 case DW_AT_data_member_location
:
32510 case DW_AT_frame_base
:
32511 case DW_AT_segment
:
32512 case DW_AT_static_link
:
32513 case DW_AT_use_location
:
32514 case DW_AT_vtable_elem_location
:
32517 prev
->dw_loc_next
= NULL
;
32518 prepend_loc_descr_to_each (l
, AT_loc (a
));
32521 add_loc_descr_to_each (l
, next
);
32522 a
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
32523 a
->dw_attr_val
.val_entry
= NULL
;
32524 a
->dw_attr_val
.v
.val_loc_list
= l
;
32525 have_location_lists
= true;
32527 /* Following attributes allow both exprloc and reference,
32528 so if the whole expression is DW_OP_GNU_variable_value alone
32529 we could transform it into reference. */
32530 case DW_AT_byte_size
:
32531 case DW_AT_bit_size
:
32532 case DW_AT_lower_bound
:
32533 case DW_AT_upper_bound
:
32534 case DW_AT_bit_stride
:
32536 case DW_AT_allocated
:
32537 case DW_AT_associated
:
32538 case DW_AT_byte_stride
:
32539 if (prev
== NULL
&& next
== NULL
)
32547 /* Create DW_TAG_variable that we can refer to. */
32548 gen_decl_die (decl
, NULL_TREE
, NULL
,
32549 lookup_decl_die (current_function_decl
));
32550 ref
= lookup_decl_die (decl
);
32553 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
32554 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
32555 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
32561 prev
->dw_loc_next
= l
->expr
;
32562 add_loc_descr (&prev
->dw_loc_next
, next
);
32563 free_loc_descr (loc
, NULL
);
32564 next
= prev
->dw_loc_next
;
32568 memcpy (loc
, l
->expr
, sizeof (dw_loc_descr_node
));
32569 add_loc_descr (&loc
, next
);
32577 /* Attempt to resolve DW_OP_GNU_variable_value using loc_list_from_tree. */
32580 resolve_variable_value (dw_die_ref die
)
32583 dw_loc_list_ref loc
;
32586 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
32587 switch (AT_class (a
))
32589 case dw_val_class_loc
:
32590 if (!resolve_variable_value_in_expr (a
, AT_loc (a
)))
32593 case dw_val_class_loc_list
:
32594 loc
= AT_loc_list (a
);
32596 for (; loc
; loc
= loc
->dw_loc_next
)
32597 resolve_variable_value_in_expr (a
, loc
->expr
);
32604 /* Attempt to optimize DW_OP_GNU_variable_value refering to
32605 temporaries in the current function. */
32608 resolve_variable_values (void)
32610 if (!variable_value_hash
|| !current_function_decl
)
32613 struct variable_value_struct
*node
32614 = variable_value_hash
->find_with_hash (current_function_decl
,
32615 DECL_UID (current_function_decl
));
32622 FOR_EACH_VEC_SAFE_ELT (node
->dies
, i
, die
)
32623 resolve_variable_value (die
);
32626 /* Helper function for note_variable_value, handle one location
32630 note_variable_value_in_expr (dw_die_ref die
, dw_loc_descr_ref loc
)
32632 for (; loc
; loc
= loc
->dw_loc_next
)
32633 if (loc
->dw_loc_opc
== DW_OP_GNU_variable_value
32634 && loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
32636 tree decl
= loc
->dw_loc_oprnd1
.v
.val_decl_ref
;
32637 dw_die_ref ref
= lookup_decl_die (decl
);
32638 if (! ref
&& (flag_generate_lto
|| flag_generate_offload
))
32640 /* ??? This is somewhat a hack because we do not create DIEs
32641 for variables not in BLOCK trees early but when generating
32642 early LTO output we need the dw_val_class_decl_ref to be
32643 fully resolved. For fat LTO objects we'd also like to
32644 undo this after LTO dwarf output. */
32645 gcc_assert (DECL_CONTEXT (decl
));
32646 dw_die_ref ctx
= lookup_decl_die (DECL_CONTEXT (decl
));
32647 gcc_assert (ctx
!= NULL
);
32648 gen_decl_die (decl
, NULL_TREE
, NULL
, ctx
);
32649 ref
= lookup_decl_die (decl
);
32650 gcc_assert (ref
!= NULL
);
32654 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
32655 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
32656 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
32660 && DECL_CONTEXT (decl
)
32661 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
32662 && lookup_decl_die (DECL_CONTEXT (decl
)))
32664 if (!variable_value_hash
)
32665 variable_value_hash
32666 = hash_table
<variable_value_hasher
>::create_ggc (10);
32668 tree fndecl
= DECL_CONTEXT (decl
);
32669 struct variable_value_struct
*node
;
32670 struct variable_value_struct
**slot
32671 = variable_value_hash
->find_slot_with_hash (fndecl
,
32676 node
= ggc_cleared_alloc
<variable_value_struct
> ();
32677 node
->decl_id
= DECL_UID (fndecl
);
32683 vec_safe_push (node
->dies
, die
);
32688 /* Walk the tree DIE and note DIEs with DW_OP_GNU_variable_value still
32689 with dw_val_class_decl_ref operand. */
32692 note_variable_value (dw_die_ref die
)
32696 dw_loc_list_ref loc
;
32699 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
32700 switch (AT_class (a
))
32702 case dw_val_class_loc_list
:
32703 loc
= AT_loc_list (a
);
32705 if (!loc
->noted_variable_value
)
32707 loc
->noted_variable_value
= 1;
32708 for (; loc
; loc
= loc
->dw_loc_next
)
32709 note_variable_value_in_expr (die
, loc
->expr
);
32712 case dw_val_class_loc
:
32713 note_variable_value_in_expr (die
, AT_loc (a
));
32719 /* Mark children. */
32720 FOR_EACH_CHILD (die
, c
, note_variable_value (c
));
32723 /* Process DWARF dies for CTF generation. */
32726 ctf_debug_do_cu (dw_die_ref die
)
32730 if (!ctf_do_die (die
))
32733 FOR_EACH_CHILD (die
, c
, ctf_do_die (c
));
32736 /* Perform any cleanups needed after the early debug generation pass
32740 dwarf2out_early_finish (const char *filename
)
32742 comdat_type_node
*ctnode
;
32744 char dl_section_ref
[MAX_ARTIFICIAL_LABEL_BYTES
];
32746 /* PCH might result in DW_AT_producer string being restored from the
32747 header compilation, so always fill it with empty string initially
32748 and overwrite only here. */
32749 dw_attr_node
*producer
= get_AT (comp_unit_die (), DW_AT_producer
);
32751 if (dwarf_record_gcc_switches
)
32752 producer_string
= gen_producer_string (lang_hooks
.name
,
32753 save_decoded_options
,
32754 save_decoded_options_count
);
32756 producer_string
= concat (lang_hooks
.name
, " ", version_string
, NULL
);
32758 producer
->dw_attr_val
.v
.val_str
->refcount
--;
32759 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
32761 /* Add the name for the main input file now. We delayed this from
32762 dwarf2out_init to avoid complications with PCH. */
32763 add_filename_attribute (comp_unit_die (), remap_debug_filename (filename
));
32764 add_comp_dir_attribute (comp_unit_die ());
32766 /* With LTO early dwarf was really finished at compile-time, so make
32767 sure to adjust the phase after annotating the LTRANS CU DIE. */
32770 early_dwarf_finished
= true;
32773 fprintf (dump_file
, "LTO EARLY DWARF for %s\n", filename
);
32774 print_die (comp_unit_die (), dump_file
);
32779 /* Walk through the list of incomplete types again, trying once more to
32780 emit full debugging info for them. */
32781 retry_incomplete_types ();
32783 gen_scheduled_generic_parms_dies ();
32784 gen_remaining_tmpl_value_param_die_attribute ();
32786 /* The point here is to flush out the limbo list so that it is empty
32787 and we don't need to stream it for LTO. */
32788 flush_limbo_die_list ();
32790 /* Add DW_AT_linkage_name for all deferred DIEs. */
32791 for (limbo_die_node
*node
= deferred_asm_name
; node
; node
= node
->next
)
32793 tree decl
= node
->created_for
;
32794 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
32795 /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
32796 ended up in deferred_asm_name before we knew it was
32797 constant and never written to disk. */
32798 && DECL_ASSEMBLER_NAME (decl
))
32800 add_linkage_attr (node
->die
, decl
);
32801 move_linkage_attr (node
->die
);
32804 deferred_asm_name
= NULL
;
32806 if (flag_eliminate_unused_debug_types
)
32807 prune_unused_types ();
32809 /* Generate separate COMDAT sections for type DIEs. */
32810 if (use_debug_types
)
32812 break_out_comdat_types (comp_unit_die ());
32814 /* Each new type_unit DIE was added to the limbo die list when created.
32815 Since these have all been added to comdat_type_list, clear the
32817 limbo_die_list
= NULL
;
32819 /* For each new comdat type unit, copy declarations for incomplete
32820 types to make the new unit self-contained (i.e., no direct
32821 references to the main compile unit). */
32822 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
32823 copy_decls_for_unworthy_types (ctnode
->root_die
);
32824 copy_decls_for_unworthy_types (comp_unit_die ());
32826 /* In the process of copying declarations from one unit to another,
32827 we may have left some declarations behind that are no longer
32828 referenced. Prune them. */
32829 prune_unused_types ();
32832 /* Traverse the DIE's and note DIEs with DW_OP_GNU_variable_value still
32833 with dw_val_class_decl_ref operand. */
32834 note_variable_value (comp_unit_die ());
32835 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
32836 note_variable_value (node
->die
);
32837 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
32838 note_variable_value (ctnode
->root_die
);
32839 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
32840 note_variable_value (node
->die
);
32842 /* The AT_pubnames attribute needs to go in all skeleton dies, including
32843 both the main_cu and all skeleton TUs. Making this call unconditional
32844 would end up either adding a second copy of the AT_pubnames attribute, or
32845 requiring a special case in add_top_level_skeleton_die_attrs. */
32846 if (!dwarf_split_debug_info
)
32847 add_AT_pubnames (comp_unit_die ());
32849 /* The early debug phase is now finished. */
32850 early_dwarf_finished
= true;
32853 fprintf (dump_file
, "EARLY DWARF for %s\n", filename
);
32854 print_die (comp_unit_die (), dump_file
);
32857 /* Generate CTF/BTF debug info. */
32858 if ((ctf_debug_info_level
> CTFINFO_LEVEL_NONE
32859 || btf_debuginfo_p ()) && lang_GNU_C ())
32862 ctf_debug_do_cu (comp_unit_die ());
32863 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
32864 ctf_debug_do_cu (node
->die
);
32865 /* Post process the debug data in the CTF container if necessary. */
32866 ctf_debug_init_postprocess (btf_debuginfo_p ());
32868 ctf_debug_early_finish (filename
);
32871 /* Do not generate DWARF assembler now when not producing LTO bytecode. */
32872 if ((!flag_generate_lto
&& !flag_generate_offload
)
32873 /* FIXME: Disable debug info generation for (PE-)COFF targets since the
32874 copy_lto_debug_sections operation of the simple object support in
32875 libiberty is not implemented for them yet. */
32876 || TARGET_PECOFF
|| TARGET_COFF
)
32879 /* Now as we are going to output for LTO initialize sections and labels
32880 to the LTO variants. We don't need a random-seed postfix as other
32881 LTO sections as linking the LTO debug sections into one in a partial
32883 init_sections_and_labels (true);
32885 /* The output below is modeled after dwarf2out_finish with all
32886 location related output removed and some LTO specific changes.
32887 Some refactoring might make both smaller and easier to match up. */
32889 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
32890 mark_base_types (ctnode
->root_die
);
32891 mark_base_types (comp_unit_die ());
32892 move_marked_base_types ();
32894 /* Traverse the DIE's and add sibling attributes to those DIE's
32895 that have children. */
32896 add_sibling_attributes (comp_unit_die ());
32897 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
32898 add_sibling_attributes (node
->die
);
32899 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
32900 add_sibling_attributes (ctnode
->root_die
);
32902 /* AIX Assembler inserts the length, so adjust the reference to match the
32903 offset expected by debuggers. */
32904 strcpy (dl_section_ref
, debug_line_section_label
);
32905 if (XCOFF_DEBUGGING_INFO
)
32906 strcat (dl_section_ref
, DWARF_INITIAL_LENGTH_SIZE_STR
);
32908 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
32909 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list
, dl_section_ref
);
32912 add_AT_macptr (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE
,
32913 macinfo_section_label
);
32915 save_macinfo_strings ();
32917 if (dwarf_split_debug_info
)
32919 unsigned int index
= 0;
32920 debug_str_hash
->traverse_noresize
<unsigned int *, index_string
> (&index
);
32923 /* Output all of the compilation units. We put the main one last so that
32924 the offsets are available to output_pubnames. */
32925 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
32926 output_comp_unit (node
->die
, 0, NULL
);
32928 hash_table
<comdat_type_hasher
> comdat_type_table (100);
32929 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
32931 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
32933 /* Don't output duplicate types. */
32934 if (*slot
!= HTAB_EMPTY_ENTRY
)
32937 /* Add a pointer to the line table for the main compilation unit
32938 so that the debugger can make sense of DW_AT_decl_file
32940 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
32941 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
32942 (!dwarf_split_debug_info
32943 ? debug_line_section_label
32944 : debug_skeleton_line_section_label
));
32946 output_comdat_type_unit (ctnode
, true);
32950 /* Stick a unique symbol to the main debuginfo section. */
32951 compute_comp_unit_symbol (comp_unit_die ());
32953 /* Output the main compilation unit. We always need it if only for
32955 output_comp_unit (comp_unit_die (), true, NULL
);
32957 /* Output the abbreviation table. */
32958 if (vec_safe_length (abbrev_die_table
) != 1)
32960 switch_to_section (debug_abbrev_section
);
32961 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
32962 output_abbrev_section ();
32965 /* Have to end the macro section. */
32968 /* We have to save macinfo state if we need to output it again
32969 for the FAT part of the object. */
32970 vec
<macinfo_entry
, va_gc
> *saved_macinfo_table
= macinfo_table
;
32971 if (flag_fat_lto_objects
)
32972 macinfo_table
= macinfo_table
->copy ();
32974 switch_to_section (debug_macinfo_section
);
32975 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
32976 output_macinfo (debug_line_section_label
, true);
32977 dw2_asm_output_data (1, 0, "End compilation unit");
32979 if (flag_fat_lto_objects
)
32981 vec_free (macinfo_table
);
32982 macinfo_table
= saved_macinfo_table
;
32986 /* Emit a skeleton debug_line section. */
32987 switch_to_section (debug_line_section
);
32988 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
32989 output_line_info (true);
32991 /* If we emitted any indirect strings, output the string table too. */
32992 if (debug_str_hash
|| skeleton_debug_str_hash
)
32993 output_indirect_strings ();
32994 if (debug_line_str_hash
)
32996 switch_to_section (debug_line_str_section
);
32997 const enum dwarf_form form
= DW_FORM_line_strp
;
32998 debug_line_str_hash
->traverse
<enum dwarf_form
,
32999 output_indirect_string
> (form
);
33002 /* Switch back to the text section. */
33003 switch_to_section (text_section
);
33006 /* Reset all state within dwarf2out.c so that we can rerun the compiler
33007 within the same process. For use by toplev::finalize. */
33010 dwarf2out_c_finalize (void)
33012 last_var_location_insn
= NULL
;
33013 cached_next_real_insn
= NULL
;
33014 used_rtx_array
= NULL
;
33015 incomplete_types
= NULL
;
33016 debug_info_section
= NULL
;
33017 debug_skeleton_info_section
= NULL
;
33018 debug_abbrev_section
= NULL
;
33019 debug_skeleton_abbrev_section
= NULL
;
33020 debug_aranges_section
= NULL
;
33021 debug_addr_section
= NULL
;
33022 debug_macinfo_section
= NULL
;
33023 debug_line_section
= NULL
;
33024 debug_skeleton_line_section
= NULL
;
33025 debug_loc_section
= NULL
;
33026 debug_pubnames_section
= NULL
;
33027 debug_pubtypes_section
= NULL
;
33028 debug_str_section
= NULL
;
33029 debug_line_str_section
= NULL
;
33030 debug_str_dwo_section
= NULL
;
33031 debug_str_offsets_section
= NULL
;
33032 debug_ranges_section
= NULL
;
33033 debug_ranges_dwo_section
= NULL
;
33034 debug_frame_section
= NULL
;
33036 debug_str_hash
= NULL
;
33037 debug_line_str_hash
= NULL
;
33038 skeleton_debug_str_hash
= NULL
;
33039 dw2_string_counter
= 0;
33040 have_multiple_function_sections
= false;
33041 in_text_section_p
= false;
33042 cold_text_section
= NULL
;
33043 last_text_label
= NULL
;
33044 last_cold_label
= NULL
;
33045 switch_text_ranges
= NULL
;
33046 switch_cold_ranges
= NULL
;
33047 current_unit_personality
= NULL
;
33049 early_dwarf
= false;
33050 early_dwarf_finished
= false;
33052 next_die_offset
= 0;
33053 single_comp_unit_die
= NULL
;
33054 comdat_type_list
= NULL
;
33055 limbo_die_list
= NULL
;
33057 decl_die_table
= NULL
;
33058 common_block_die_table
= NULL
;
33059 decl_loc_table
= NULL
;
33060 call_arg_locations
= NULL
;
33061 call_arg_loc_last
= NULL
;
33062 call_site_count
= -1;
33063 tail_call_site_count
= -1;
33064 cached_dw_loc_list_table
= NULL
;
33065 abbrev_die_table
= NULL
;
33066 delete dwarf_proc_stack_usage_map
;
33067 dwarf_proc_stack_usage_map
= NULL
;
33068 line_info_label_num
= 0;
33069 cur_line_info_table
= NULL
;
33070 text_section_line_info
= NULL
;
33071 cold_text_section_line_info
= NULL
;
33072 separate_line_info
= NULL
;
33073 info_section_emitted
= false;
33074 pubname_table
= NULL
;
33075 pubtype_table
= NULL
;
33076 macinfo_table
= NULL
;
33077 ranges_table
= NULL
;
33078 ranges_by_label
= NULL
;
33080 have_location_lists
= false;
33083 last_emitted_file
= NULL
;
33085 tmpl_value_parm_die_table
= NULL
;
33086 generic_type_instances
= NULL
;
33087 frame_pointer_fb_offset
= 0;
33088 frame_pointer_fb_offset_valid
= false;
33089 base_types
.release ();
33090 XDELETEVEC (producer_string
);
33091 producer_string
= NULL
;
33092 output_line_info_generation
= 0;
33093 init_sections_and_labels_generation
= 0;
33096 #include "gt-dwarf2out.h"