1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992-2017 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 "dwarf2asm.h"
85 #include "tree-pretty-print.h"
87 #include "common/common-target.h"
88 #include "langhooks.h"
93 #include "gdb/gdb-index.h"
95 #include "stringpool.h"
98 static void dwarf2out_source_line (unsigned int, unsigned int, const char *,
100 static rtx_insn
*last_var_location_insn
;
101 static rtx_insn
*cached_next_real_insn
;
102 static void dwarf2out_decl (tree
);
104 #ifndef XCOFF_DEBUGGING_INFO
105 #define XCOFF_DEBUGGING_INFO 0
108 #ifndef HAVE_XCOFF_DWARF_EXTRAS
109 #define HAVE_XCOFF_DWARF_EXTRAS 0
112 #ifdef VMS_DEBUGGING_INFO
113 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
115 /* Define this macro to be a nonzero value if the directory specifications
116 which are output in the debug info should end with a separator. */
117 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
118 /* Define this macro to evaluate to a nonzero value if GCC should refrain
119 from generating indirect strings in DWARF2 debug information, for instance
120 if your target is stuck with an old version of GDB that is unable to
121 process them properly or uses VMS Debug. */
122 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
124 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
125 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
128 /* ??? Poison these here until it can be done generically. They've been
129 totally replaced in this file; make sure it stays that way. */
130 #undef DWARF2_UNWIND_INFO
131 #undef DWARF2_FRAME_INFO
132 #if (GCC_VERSION >= 3000)
133 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
136 /* The size of the target's pointer type. */
138 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
141 /* Array of RTXes referenced by the debugging information, which therefore
142 must be kept around forever. */
143 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
145 /* A pointer to the base of a list of incomplete types which might be
146 completed at some later time. incomplete_types_list needs to be a
147 vec<tree, va_gc> *because we want to tell the garbage collector about
149 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
151 /* A pointer to the base of a table of references to declaration
152 scopes. This table is a display which tracks the nesting
153 of declaration scopes at the current scope and containing
154 scopes. This table is used to find the proper place to
155 define type declaration DIE's. */
156 static GTY(()) vec
<tree
, va_gc
> *decl_scope_table
;
158 /* Pointers to various DWARF2 sections. */
159 static GTY(()) section
*debug_info_section
;
160 static GTY(()) section
*debug_skeleton_info_section
;
161 static GTY(()) section
*debug_abbrev_section
;
162 static GTY(()) section
*debug_skeleton_abbrev_section
;
163 static GTY(()) section
*debug_aranges_section
;
164 static GTY(()) section
*debug_addr_section
;
165 static GTY(()) section
*debug_macinfo_section
;
166 static const char *debug_macinfo_section_name
;
167 static unsigned macinfo_label_base
= 1;
168 static GTY(()) section
*debug_line_section
;
169 static GTY(()) section
*debug_skeleton_line_section
;
170 static GTY(()) section
*debug_loc_section
;
171 static GTY(()) section
*debug_pubnames_section
;
172 static GTY(()) section
*debug_pubtypes_section
;
173 static GTY(()) section
*debug_str_section
;
174 static GTY(()) section
*debug_line_str_section
;
175 static GTY(()) section
*debug_str_dwo_section
;
176 static GTY(()) section
*debug_str_offsets_section
;
177 static GTY(()) section
*debug_ranges_section
;
178 static GTY(()) section
*debug_frame_section
;
180 /* Maximum size (in bytes) of an artificially generated label. */
181 #define MAX_ARTIFICIAL_LABEL_BYTES 30
183 /* According to the (draft) DWARF 3 specification, the initial length
184 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
185 bytes are 0xffffffff, followed by the length stored in the next 8
188 However, the SGI/MIPS ABI uses an initial length which is equal to
189 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
191 #ifndef DWARF_INITIAL_LENGTH_SIZE
192 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
195 #ifndef DWARF_INITIAL_LENGTH_SIZE_STR
196 #define DWARF_INITIAL_LENGTH_SIZE_STR (DWARF_OFFSET_SIZE == 4 ? "-4" : "-12")
199 /* Round SIZE up to the nearest BOUNDARY. */
200 #define DWARF_ROUND(SIZE,BOUNDARY) \
201 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
203 /* CIE identifier. */
204 #if HOST_BITS_PER_WIDE_INT >= 64
205 #define DWARF_CIE_ID \
206 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
208 #define DWARF_CIE_ID DW_CIE_ID
212 /* A vector for a table that contains frame description
213 information for each routine. */
214 #define NOT_INDEXED (-1U)
215 #define NO_INDEX_ASSIGNED (-2U)
217 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
219 struct GTY((for_user
)) indirect_string_node
{
221 unsigned int refcount
;
222 enum dwarf_form form
;
227 struct indirect_string_hasher
: ggc_ptr_hash
<indirect_string_node
>
229 typedef const char *compare_type
;
231 static hashval_t
hash (indirect_string_node
*);
232 static bool equal (indirect_string_node
*, const char *);
235 static GTY (()) hash_table
<indirect_string_hasher
> *debug_str_hash
;
237 static GTY (()) hash_table
<indirect_string_hasher
> *debug_line_str_hash
;
239 /* With split_debug_info, both the comp_dir and dwo_name go in the
240 main object file, rather than the dwo, similar to the force_direct
241 parameter elsewhere but with additional complications:
243 1) The string is needed in both the main object file and the dwo.
244 That is, the comp_dir and dwo_name will appear in both places.
246 2) Strings can use four forms: DW_FORM_string, DW_FORM_strp,
247 DW_FORM_line_strp or DW_FORM_GNU_str_index.
249 3) GCC chooses the form to use late, depending on the size and
252 Rather than forcing the all debug string handling functions and
253 callers to deal with these complications, simply use a separate,
254 special-cased string table for any attribute that should go in the
255 main object file. This limits the complexity to just the places
258 static GTY (()) hash_table
<indirect_string_hasher
> *skeleton_debug_str_hash
;
260 static GTY(()) int dw2_string_counter
;
262 /* True if the compilation unit places functions in more than one section. */
263 static GTY(()) bool have_multiple_function_sections
= false;
265 /* Whether the default text and cold text sections have been used at all. */
267 static GTY(()) bool text_section_used
= false;
268 static GTY(()) bool cold_text_section_used
= false;
270 /* The default cold text section. */
271 static GTY(()) section
*cold_text_section
;
273 /* The DIE for C++14 'auto' in a function return type. */
274 static GTY(()) dw_die_ref auto_die
;
276 /* The DIE for C++14 'decltype(auto)' in a function return type. */
277 static GTY(()) dw_die_ref decltype_auto_die
;
279 /* Forward declarations for functions defined in this file. */
281 static void output_call_frame_info (int);
282 static void dwarf2out_note_section_used (void);
284 /* Personality decl of current unit. Used only when assembler does not support
286 static GTY(()) rtx current_unit_personality
;
288 /* .debug_rnglists next index. */
289 static unsigned int rnglist_idx
;
291 /* Data and reference forms for relocatable data. */
292 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
293 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
295 #ifndef DEBUG_FRAME_SECTION
296 #define DEBUG_FRAME_SECTION ".debug_frame"
299 #ifndef FUNC_BEGIN_LABEL
300 #define FUNC_BEGIN_LABEL "LFB"
303 #ifndef FUNC_END_LABEL
304 #define FUNC_END_LABEL "LFE"
307 #ifndef PROLOGUE_END_LABEL
308 #define PROLOGUE_END_LABEL "LPE"
311 #ifndef EPILOGUE_BEGIN_LABEL
312 #define EPILOGUE_BEGIN_LABEL "LEB"
315 #ifndef FRAME_BEGIN_LABEL
316 #define FRAME_BEGIN_LABEL "Lframe"
318 #define CIE_AFTER_SIZE_LABEL "LSCIE"
319 #define CIE_END_LABEL "LECIE"
320 #define FDE_LABEL "LSFDE"
321 #define FDE_AFTER_SIZE_LABEL "LASFDE"
322 #define FDE_END_LABEL "LEFDE"
323 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
324 #define LINE_NUMBER_END_LABEL "LELT"
325 #define LN_PROLOG_AS_LABEL "LASLTP"
326 #define LN_PROLOG_END_LABEL "LELTP"
327 #define DIE_LABEL_PREFIX "DW"
329 /* Match the base name of a file to the base name of a compilation unit. */
332 matches_main_base (const char *path
)
334 /* Cache the last query. */
335 static const char *last_path
= NULL
;
336 static int last_match
= 0;
337 if (path
!= last_path
)
340 int length
= base_of_path (path
, &base
);
342 last_match
= (length
== main_input_baselength
343 && memcmp (base
, main_input_basename
, length
) == 0);
348 #ifdef DEBUG_DEBUG_STRUCT
351 dump_struct_debug (tree type
, enum debug_info_usage usage
,
352 enum debug_struct_file criterion
, int generic
,
353 int matches
, int result
)
355 /* Find the type name. */
356 tree type_decl
= TYPE_STUB_DECL (type
);
358 const char *name
= 0;
359 if (TREE_CODE (t
) == TYPE_DECL
)
362 name
= IDENTIFIER_POINTER (t
);
364 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
366 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
367 matches
? "bas" : "hdr",
368 generic
? "gen" : "ord",
369 usage
== DINFO_USAGE_DFN
? ";" :
370 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
372 (void*) type_decl
, name
);
375 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
376 dump_struct_debug (type, usage, criterion, generic, matches, result)
380 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
385 /* Get the number of HOST_WIDE_INTs needed to represent the precision
386 of the number. Some constants have a large uniform precision, so
387 we get the precision needed for the actual value of the number. */
390 get_full_len (const wide_int
&op
)
392 int prec
= wi::min_precision (op
, UNSIGNED
);
393 return ((prec
+ HOST_BITS_PER_WIDE_INT
- 1)
394 / HOST_BITS_PER_WIDE_INT
);
398 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
400 enum debug_struct_file criterion
;
402 bool generic
= lang_hooks
.types
.generic_p (type
);
405 criterion
= debug_struct_generic
[usage
];
407 criterion
= debug_struct_ordinary
[usage
];
409 if (criterion
== DINFO_STRUCT_FILE_NONE
)
410 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
411 if (criterion
== DINFO_STRUCT_FILE_ANY
)
412 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
414 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
416 if (type_decl
!= NULL
)
418 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
419 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
421 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
422 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
425 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
428 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
429 switch to the data section instead, and write out a synthetic start label
430 for collect2 the first time around. */
433 switch_to_eh_frame_section (bool back ATTRIBUTE_UNUSED
)
435 if (eh_frame_section
== 0)
439 if (EH_TABLES_CAN_BE_READ_ONLY
)
445 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
447 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
449 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
452 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
453 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
454 && (per_encoding
& 0x70) != DW_EH_PE_absptr
455 && (per_encoding
& 0x70) != DW_EH_PE_aligned
456 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
457 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
458 ? 0 : SECTION_WRITE
);
461 flags
= SECTION_WRITE
;
463 #ifdef EH_FRAME_SECTION_NAME
464 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
466 eh_frame_section
= ((flags
== SECTION_WRITE
)
467 ? data_section
: readonly_data_section
);
468 #endif /* EH_FRAME_SECTION_NAME */
471 switch_to_section (eh_frame_section
);
473 #ifdef EH_FRAME_THROUGH_COLLECT2
474 /* We have no special eh_frame section. Emit special labels to guide
478 tree label
= get_file_function_name ("F");
479 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
480 targetm
.asm_out
.globalize_label (asm_out_file
,
481 IDENTIFIER_POINTER (label
));
482 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
487 /* Switch [BACK] to the eh or debug frame table section, depending on
491 switch_to_frame_table_section (int for_eh
, bool back
)
494 switch_to_eh_frame_section (back
);
497 if (!debug_frame_section
)
498 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
499 SECTION_DEBUG
, NULL
);
500 switch_to_section (debug_frame_section
);
504 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
506 enum dw_cfi_oprnd_type
507 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
512 case DW_CFA_GNU_window_save
:
513 case DW_CFA_remember_state
:
514 case DW_CFA_restore_state
:
515 return dw_cfi_oprnd_unused
;
518 case DW_CFA_advance_loc1
:
519 case DW_CFA_advance_loc2
:
520 case DW_CFA_advance_loc4
:
521 case DW_CFA_MIPS_advance_loc8
:
522 return dw_cfi_oprnd_addr
;
525 case DW_CFA_offset_extended
:
527 case DW_CFA_offset_extended_sf
:
528 case DW_CFA_def_cfa_sf
:
530 case DW_CFA_restore_extended
:
531 case DW_CFA_undefined
:
532 case DW_CFA_same_value
:
533 case DW_CFA_def_cfa_register
:
534 case DW_CFA_register
:
535 case DW_CFA_expression
:
536 case DW_CFA_val_expression
:
537 return dw_cfi_oprnd_reg_num
;
539 case DW_CFA_def_cfa_offset
:
540 case DW_CFA_GNU_args_size
:
541 case DW_CFA_def_cfa_offset_sf
:
542 return dw_cfi_oprnd_offset
;
544 case DW_CFA_def_cfa_expression
:
545 return dw_cfi_oprnd_loc
;
552 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
554 enum dw_cfi_oprnd_type
555 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
560 case DW_CFA_def_cfa_sf
:
562 case DW_CFA_offset_extended_sf
:
563 case DW_CFA_offset_extended
:
564 return dw_cfi_oprnd_offset
;
566 case DW_CFA_register
:
567 return dw_cfi_oprnd_reg_num
;
569 case DW_CFA_expression
:
570 case DW_CFA_val_expression
:
571 return dw_cfi_oprnd_loc
;
574 return dw_cfi_oprnd_unused
;
578 /* Output one FDE. */
581 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
582 char *section_start_label
, int fde_encoding
, char *augmentation
,
583 bool any_lsda_needed
, int lsda_encoding
)
585 const char *begin
, *end
;
586 static unsigned int j
;
587 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
589 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
591 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
593 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
594 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
595 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
597 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
598 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
599 " indicating 64-bit DWARF extension");
600 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
603 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
606 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
608 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
609 debug_frame_section
, "FDE CIE offset");
611 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
612 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
616 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
617 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
618 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
619 "FDE initial location");
620 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
621 end
, begin
, "FDE address range");
625 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
626 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
633 int size
= size_of_encoded_value (lsda_encoding
);
635 if (lsda_encoding
== DW_EH_PE_aligned
)
637 int offset
= ( 4 /* Length */
639 + 2 * size_of_encoded_value (fde_encoding
)
640 + 1 /* Augmentation size */ );
641 int pad
= -offset
& (PTR_SIZE
- 1);
644 gcc_assert (size_of_uleb128 (size
) == 1);
647 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
649 if (fde
->uses_eh_lsda
)
651 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
652 fde
->funcdef_number
);
653 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
654 gen_rtx_SYMBOL_REF (Pmode
, l1
),
656 "Language Specific Data Area");
660 if (lsda_encoding
== DW_EH_PE_aligned
)
661 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
662 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
663 "Language Specific Data Area (none)");
667 dw2_asm_output_data_uleb128 (0, "Augmentation size");
670 /* Loop through the Call Frame Instructions associated with this FDE. */
671 fde
->dw_fde_current_label
= begin
;
673 size_t from
, until
, i
;
676 until
= vec_safe_length (fde
->dw_fde_cfi
);
678 if (fde
->dw_fde_second_begin
== NULL
)
681 until
= fde
->dw_fde_switch_cfi_index
;
683 from
= fde
->dw_fde_switch_cfi_index
;
685 for (i
= from
; i
< until
; i
++)
686 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
689 /* If we are to emit a ref/link from function bodies to their frame tables,
690 do it now. This is typically performed to make sure that tables
691 associated with functions are dragged with them and not discarded in
692 garbage collecting links. We need to do this on a per function basis to
693 cope with -ffunction-sections. */
695 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
696 /* Switch to the function section, emit the ref to the tables, and
697 switch *back* into the table section. */
698 switch_to_section (function_section (fde
->decl
));
699 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
700 switch_to_frame_table_section (for_eh
, true);
703 /* Pad the FDE out to an address sized boundary. */
704 ASM_OUTPUT_ALIGN (asm_out_file
,
705 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
706 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
711 /* Return true if frame description entry FDE is needed for EH. */
714 fde_needed_for_eh_p (dw_fde_ref fde
)
716 if (flag_asynchronous_unwind_tables
)
719 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
722 if (fde
->uses_eh_lsda
)
725 /* If exceptions are enabled, we have collected nothrow info. */
726 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
732 /* Output the call frame information used to record information
733 that relates to calculating the frame pointer, and records the
734 location of saved registers. */
737 output_call_frame_info (int for_eh
)
742 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
743 char section_start_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
744 bool any_lsda_needed
= false;
745 char augmentation
[6];
746 int augmentation_size
;
747 int fde_encoding
= DW_EH_PE_absptr
;
748 int per_encoding
= DW_EH_PE_absptr
;
749 int lsda_encoding
= DW_EH_PE_absptr
;
751 rtx personality
= NULL
;
754 /* Don't emit a CIE if there won't be any FDEs. */
758 /* Nothing to do if the assembler's doing it all. */
759 if (dwarf2out_do_cfi_asm ())
762 /* If we don't have any functions we'll want to unwind out of, don't emit
763 any EH unwind information. If we make FDEs linkonce, we may have to
764 emit an empty label for an FDE that wouldn't otherwise be emitted. We
765 want to avoid having an FDE kept around when the function it refers to
766 is discarded. Example where this matters: a primary function template
767 in C++ requires EH information, an explicit specialization doesn't. */
770 bool any_eh_needed
= false;
772 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
774 if (fde
->uses_eh_lsda
)
775 any_eh_needed
= any_lsda_needed
= true;
776 else if (fde_needed_for_eh_p (fde
))
777 any_eh_needed
= true;
778 else if (TARGET_USES_WEAK_UNWIND_INFO
)
779 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
786 /* We're going to be generating comments, so turn on app. */
790 /* Switch to the proper frame section, first time. */
791 switch_to_frame_table_section (for_eh
, false);
793 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
794 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
796 /* Output the CIE. */
797 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
798 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
799 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
801 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
802 dw2_asm_output_data (4, 0xffffffff,
803 "Initial length escape value indicating 64-bit DWARF extension");
804 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
805 "Length of Common Information Entry");
807 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
809 /* Now that the CIE pointer is PC-relative for EH,
810 use 0 to identify the CIE. */
811 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
812 (for_eh
? 0 : DWARF_CIE_ID
),
813 "CIE Identifier Tag");
815 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
816 use CIE version 1, unless that would produce incorrect results
817 due to overflowing the return register column. */
818 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
820 if (return_reg
>= 256 || dwarf_version
> 2)
822 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
825 augmentation_size
= 0;
827 personality
= current_unit_personality
;
833 z Indicates that a uleb128 is present to size the
834 augmentation section.
835 L Indicates the encoding (and thus presence) of
836 an LSDA pointer in the FDE augmentation.
837 R Indicates a non-default pointer encoding for
839 P Indicates the presence of an encoding + language
840 personality routine in the CIE augmentation. */
842 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
843 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
844 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
846 p
= augmentation
+ 1;
850 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
851 assemble_external_libcall (personality
);
856 augmentation_size
+= 1;
858 if (fde_encoding
!= DW_EH_PE_absptr
)
861 augmentation_size
+= 1;
863 if (p
> augmentation
+ 1)
865 augmentation
[0] = 'z';
869 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
870 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
872 int offset
= ( 4 /* Length */
874 + 1 /* CIE version */
875 + strlen (augmentation
) + 1 /* Augmentation */
876 + size_of_uleb128 (1) /* Code alignment */
877 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
879 + 1 /* Augmentation size */
880 + 1 /* Personality encoding */ );
881 int pad
= -offset
& (PTR_SIZE
- 1);
883 augmentation_size
+= pad
;
885 /* Augmentations should be small, so there's scarce need to
886 iterate for a solution. Die if we exceed one uleb128 byte. */
887 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
891 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
892 if (dw_cie_version
>= 4)
894 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
895 dw2_asm_output_data (1, 0, "CIE Segment Size");
897 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
898 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
899 "CIE Data Alignment Factor");
901 if (dw_cie_version
== 1)
902 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
904 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
908 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
911 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
912 eh_data_format_name (per_encoding
));
913 dw2_asm_output_encoded_addr_rtx (per_encoding
,
919 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
920 eh_data_format_name (lsda_encoding
));
922 if (fde_encoding
!= DW_EH_PE_absptr
)
923 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
924 eh_data_format_name (fde_encoding
));
927 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
928 output_cfi (cfi
, NULL
, for_eh
);
930 /* Pad the CIE out to an address sized boundary. */
931 ASM_OUTPUT_ALIGN (asm_out_file
,
932 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
933 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
935 /* Loop through all of the FDE's. */
936 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
940 /* Don't emit EH unwind info for leaf functions that don't need it. */
941 if (for_eh
&& !fde_needed_for_eh_p (fde
))
944 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
945 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
946 augmentation
, any_lsda_needed
, lsda_encoding
);
949 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
950 dw2_asm_output_data (4, 0, "End of Table");
952 /* Turn off app to make assembly quicker. */
957 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
960 dwarf2out_do_cfi_startproc (bool second
)
964 rtx personality
= get_personality_function (current_function_decl
);
966 fprintf (asm_out_file
, "\t.cfi_startproc\n");
970 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
973 /* ??? The GAS support isn't entirely consistent. We have to
974 handle indirect support ourselves, but PC-relative is done
975 in the assembler. Further, the assembler can't handle any
976 of the weirder relocation types. */
977 if (enc
& DW_EH_PE_indirect
)
978 ref
= dw2_force_const_mem (ref
, true);
980 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
981 output_addr_const (asm_out_file
, ref
);
982 fputc ('\n', asm_out_file
);
985 if (crtl
->uses_eh_lsda
)
987 char lab
[MAX_ARTIFICIAL_LABEL_BYTES
];
989 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
990 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
991 current_function_funcdef_no
);
992 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
993 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
995 if (enc
& DW_EH_PE_indirect
)
996 ref
= dw2_force_const_mem (ref
, true);
998 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
999 output_addr_const (asm_out_file
, ref
);
1000 fputc ('\n', asm_out_file
);
1004 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
1005 this allocation may be done before pass_final. */
1008 dwarf2out_alloc_current_fde (void)
1012 fde
= ggc_cleared_alloc
<dw_fde_node
> ();
1013 fde
->decl
= current_function_decl
;
1014 fde
->funcdef_number
= current_function_funcdef_no
;
1015 fde
->fde_index
= vec_safe_length (fde_vec
);
1016 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
1017 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
1018 fde
->nothrow
= crtl
->nothrow
;
1019 fde
->drap_reg
= INVALID_REGNUM
;
1020 fde
->vdrap_reg
= INVALID_REGNUM
;
1022 /* Record the FDE associated with this function. */
1024 vec_safe_push (fde_vec
, fde
);
1029 /* Output a marker (i.e. a label) for the beginning of a function, before
1033 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1034 unsigned int column ATTRIBUTE_UNUSED
,
1035 const char *file ATTRIBUTE_UNUSED
)
1037 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1043 current_function_func_begin_label
= NULL
;
1045 do_frame
= dwarf2out_do_frame ();
1047 /* ??? current_function_func_begin_label is also used by except.c for
1048 call-site information. We must emit this label if it might be used. */
1050 && (!flag_exceptions
1051 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1054 fnsec
= function_section (current_function_decl
);
1055 switch_to_section (fnsec
);
1056 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1057 current_function_funcdef_no
);
1058 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1059 current_function_funcdef_no
);
1060 dup_label
= xstrdup (label
);
1061 current_function_func_begin_label
= dup_label
;
1063 /* We can elide the fde allocation if we're not emitting debug info. */
1067 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1068 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1069 would include pass_dwarf2_frame. If we've not created the FDE yet,
1073 fde
= dwarf2out_alloc_current_fde ();
1075 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1076 fde
->dw_fde_begin
= dup_label
;
1077 fde
->dw_fde_current_label
= dup_label
;
1078 fde
->in_std_section
= (fnsec
== text_section
1079 || (cold_text_section
&& fnsec
== cold_text_section
));
1081 /* We only want to output line number information for the genuine dwarf2
1082 prologue case, not the eh frame case. */
1083 #ifdef DWARF2_DEBUGGING_INFO
1085 dwarf2out_source_line (line
, column
, file
, 0, true);
1088 if (dwarf2out_do_cfi_asm ())
1089 dwarf2out_do_cfi_startproc (false);
1092 rtx personality
= get_personality_function (current_function_decl
);
1093 if (!current_unit_personality
)
1094 current_unit_personality
= personality
;
1096 /* We cannot keep a current personality per function as without CFI
1097 asm, at the point where we emit the CFI data, there is no current
1098 function anymore. */
1099 if (personality
&& current_unit_personality
!= personality
)
1100 sorry ("multiple EH personalities are supported only with assemblers "
1101 "supporting .cfi_personality directive");
1105 /* Output a marker (i.e. a label) for the end of the generated code
1106 for a function prologue. This gets called *after* the prologue code has
1110 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1111 const char *file ATTRIBUTE_UNUSED
)
1113 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1115 /* Output a label to mark the endpoint of the code generated for this
1117 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1118 current_function_funcdef_no
);
1119 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1120 current_function_funcdef_no
);
1121 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1124 /* Output a marker (i.e. a label) for the beginning of the generated code
1125 for a function epilogue. This gets called *before* the prologue code has
1129 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1130 const char *file ATTRIBUTE_UNUSED
)
1132 dw_fde_ref fde
= cfun
->fde
;
1133 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1135 if (fde
->dw_fde_vms_begin_epilogue
)
1138 /* Output a label to mark the endpoint of the code generated for this
1140 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1141 current_function_funcdef_no
);
1142 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1143 current_function_funcdef_no
);
1144 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1147 /* Output a marker (i.e. a label) for the absolute end of the generated code
1148 for a function definition. This gets called *after* the epilogue code has
1152 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1153 const char *file ATTRIBUTE_UNUSED
)
1156 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1158 last_var_location_insn
= NULL
;
1159 cached_next_real_insn
= NULL
;
1161 if (dwarf2out_do_cfi_asm ())
1162 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1164 /* Output a label to mark the endpoint of the code generated for this
1166 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1167 current_function_funcdef_no
);
1168 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1170 gcc_assert (fde
!= NULL
);
1171 if (fde
->dw_fde_second_begin
== NULL
)
1172 fde
->dw_fde_end
= xstrdup (label
);
1176 dwarf2out_frame_finish (void)
1178 /* Output call frame information. */
1179 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1180 output_call_frame_info (0);
1182 /* Output another copy for the unwinder. */
1183 if ((flag_unwind_tables
|| flag_exceptions
)
1184 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1185 output_call_frame_info (1);
1188 /* Note that the current function section is being used for code. */
1191 dwarf2out_note_section_used (void)
1193 section
*sec
= current_function_section ();
1194 if (sec
== text_section
)
1195 text_section_used
= true;
1196 else if (sec
== cold_text_section
)
1197 cold_text_section_used
= true;
1200 static void var_location_switch_text_section (void);
1201 static void set_cur_line_info_table (section
*);
1204 dwarf2out_switch_text_section (void)
1207 dw_fde_ref fde
= cfun
->fde
;
1209 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1211 if (!in_cold_section_p
)
1213 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1214 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1215 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1219 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1220 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1221 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1223 have_multiple_function_sections
= true;
1225 /* There is no need to mark used sections when not debugging. */
1226 if (cold_text_section
!= NULL
)
1227 dwarf2out_note_section_used ();
1229 if (dwarf2out_do_cfi_asm ())
1230 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1232 /* Now do the real section switch. */
1233 sect
= current_function_section ();
1234 switch_to_section (sect
);
1236 fde
->second_in_std_section
1237 = (sect
== text_section
1238 || (cold_text_section
&& sect
== cold_text_section
));
1240 if (dwarf2out_do_cfi_asm ())
1241 dwarf2out_do_cfi_startproc (true);
1243 var_location_switch_text_section ();
1245 if (cold_text_section
!= NULL
)
1246 set_cur_line_info_table (sect
);
1249 /* And now, the subset of the debugging information support code necessary
1250 for emitting location expressions. */
1252 /* Data about a single source file. */
1253 struct GTY((for_user
)) dwarf_file_data
{
1254 const char * filename
;
1258 /* Describe an entry into the .debug_addr section. */
1262 ate_kind_rtx_dtprel
,
1266 struct GTY((for_user
)) addr_table_entry
{
1268 unsigned int refcount
;
1270 union addr_table_entry_struct_union
1272 rtx
GTY ((tag ("0"))) rtl
;
1273 char * GTY ((tag ("1"))) label
;
1275 GTY ((desc ("%1.kind"))) addr
;
1278 /* Location lists are ranges + location descriptions for that range,
1279 so you can track variables that are in different places over
1280 their entire life. */
1281 typedef struct GTY(()) dw_loc_list_struct
{
1282 dw_loc_list_ref dw_loc_next
;
1283 const char *begin
; /* Label and addr_entry for start of range */
1284 addr_table_entry
*begin_entry
;
1285 const char *end
; /* Label for end of range */
1286 char *ll_symbol
; /* Label for beginning of location list.
1287 Only on head of list */
1288 const char *section
; /* Section this loclist is relative to */
1289 dw_loc_descr_ref expr
;
1291 /* True if all addresses in this and subsequent lists are known to be
1294 /* True if this list has been replaced by dw_loc_next. */
1296 /* True if it has been emitted into .debug_loc* / .debug_loclists*
1298 unsigned char emitted
: 1;
1299 /* True if hash field is index rather than hash value. */
1300 unsigned char num_assigned
: 1;
1301 /* True if .debug_loclists.dwo offset has been emitted for it already. */
1302 unsigned char offset_emitted
: 1;
1303 /* True if note_variable_value_in_expr has been called on it. */
1304 unsigned char noted_variable_value
: 1;
1305 /* True if the range should be emitted even if begin and end
1310 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1311 static dw_loc_descr_ref
uint_loc_descriptor (unsigned HOST_WIDE_INT
);
1313 /* Convert a DWARF stack opcode into its string name. */
1316 dwarf_stack_op_name (unsigned int op
)
1318 const char *name
= get_DW_OP_name (op
);
1323 return "OP_<unknown>";
1326 /* Return a pointer to a newly allocated location description. Location
1327 descriptions are simple expression terms that can be strung
1328 together to form more complicated location (address) descriptions. */
1330 static inline dw_loc_descr_ref
1331 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1332 unsigned HOST_WIDE_INT oprnd2
)
1334 dw_loc_descr_ref descr
= ggc_cleared_alloc
<dw_loc_descr_node
> ();
1336 descr
->dw_loc_opc
= op
;
1337 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1338 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1339 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1340 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1341 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1342 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1347 /* Return a pointer to a newly allocated location description for
1350 static inline dw_loc_descr_ref
1351 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1354 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1357 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1360 /* Add a location description term to a location description expression. */
1363 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1365 dw_loc_descr_ref
*d
;
1367 /* Find the end of the chain. */
1368 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1374 /* Compare two location operands for exact equality. */
1377 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1379 if (a
->val_class
!= b
->val_class
)
1381 switch (a
->val_class
)
1383 case dw_val_class_none
:
1385 case dw_val_class_addr
:
1386 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1388 case dw_val_class_offset
:
1389 case dw_val_class_unsigned_const
:
1390 case dw_val_class_const
:
1391 case dw_val_class_unsigned_const_implicit
:
1392 case dw_val_class_const_implicit
:
1393 case dw_val_class_range_list
:
1394 /* These are all HOST_WIDE_INT, signed or unsigned. */
1395 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1397 case dw_val_class_loc
:
1398 return a
->v
.val_loc
== b
->v
.val_loc
;
1399 case dw_val_class_loc_list
:
1400 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1401 case dw_val_class_die_ref
:
1402 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1403 case dw_val_class_fde_ref
:
1404 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1405 case dw_val_class_lbl_id
:
1406 case dw_val_class_lineptr
:
1407 case dw_val_class_macptr
:
1408 case dw_val_class_loclistsptr
:
1409 case dw_val_class_high_pc
:
1410 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1411 case dw_val_class_str
:
1412 return a
->v
.val_str
== b
->v
.val_str
;
1413 case dw_val_class_flag
:
1414 return a
->v
.val_flag
== b
->v
.val_flag
;
1415 case dw_val_class_file
:
1416 case dw_val_class_file_implicit
:
1417 return a
->v
.val_file
== b
->v
.val_file
;
1418 case dw_val_class_decl_ref
:
1419 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1421 case dw_val_class_const_double
:
1422 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1423 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1425 case dw_val_class_wide_int
:
1426 return *a
->v
.val_wide
== *b
->v
.val_wide
;
1428 case dw_val_class_vec
:
1430 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1431 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1433 return (a_len
== b_len
1434 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1437 case dw_val_class_data8
:
1438 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1440 case dw_val_class_vms_delta
:
1441 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1442 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1444 case dw_val_class_discr_value
:
1445 return (a
->v
.val_discr_value
.pos
== b
->v
.val_discr_value
.pos
1446 && a
->v
.val_discr_value
.v
.uval
== b
->v
.val_discr_value
.v
.uval
);
1447 case dw_val_class_discr_list
:
1448 /* It makes no sense comparing two discriminant value lists. */
1454 /* Compare two location atoms for exact equality. */
1457 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1459 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1462 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1463 address size, but since we always allocate cleared storage it
1464 should be zero for other types of locations. */
1465 if (a
->dtprel
!= b
->dtprel
)
1468 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1469 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1472 /* Compare two complete location expressions for exact equality. */
1475 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1481 if (a
== NULL
|| b
== NULL
)
1483 if (!loc_descr_equal_p_1 (a
, b
))
1492 /* Add a constant OFFSET to a location expression. */
1495 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1497 dw_loc_descr_ref loc
;
1500 gcc_assert (*list_head
!= NULL
);
1505 /* Find the end of the chain. */
1506 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1510 if (loc
->dw_loc_opc
== DW_OP_fbreg
1511 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1512 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1513 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1514 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1516 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1517 offset. Don't optimize if an signed integer overflow would happen. */
1519 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1520 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1523 else if (offset
> 0)
1524 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1529 = uint_loc_descriptor (-(unsigned HOST_WIDE_INT
) offset
);
1530 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1534 /* Add a constant OFFSET to a location list. */
1537 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1540 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1541 loc_descr_plus_const (&d
->expr
, offset
);
1544 #define DWARF_REF_SIZE \
1545 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1547 /* The number of bits that can be encoded by largest DW_FORM_dataN.
1548 In DWARF4 and earlier it is DW_FORM_data8 with 64 bits, in DWARF5
1549 DW_FORM_data16 with 128 bits. */
1550 #define DWARF_LARGEST_DATA_FORM_BITS \
1551 (dwarf_version >= 5 ? 128 : 64)
1553 /* Utility inline function for construction of ops that were GNU extension
1555 static inline enum dwarf_location_atom
1556 dwarf_OP (enum dwarf_location_atom op
)
1560 case DW_OP_implicit_pointer
:
1561 if (dwarf_version
< 5)
1562 return DW_OP_GNU_implicit_pointer
;
1565 case DW_OP_entry_value
:
1566 if (dwarf_version
< 5)
1567 return DW_OP_GNU_entry_value
;
1570 case DW_OP_const_type
:
1571 if (dwarf_version
< 5)
1572 return DW_OP_GNU_const_type
;
1575 case DW_OP_regval_type
:
1576 if (dwarf_version
< 5)
1577 return DW_OP_GNU_regval_type
;
1580 case DW_OP_deref_type
:
1581 if (dwarf_version
< 5)
1582 return DW_OP_GNU_deref_type
;
1586 if (dwarf_version
< 5)
1587 return DW_OP_GNU_convert
;
1590 case DW_OP_reinterpret
:
1591 if (dwarf_version
< 5)
1592 return DW_OP_GNU_reinterpret
;
1601 /* Similarly for attributes. */
1602 static inline enum dwarf_attribute
1603 dwarf_AT (enum dwarf_attribute at
)
1607 case DW_AT_call_return_pc
:
1608 if (dwarf_version
< 5)
1609 return DW_AT_low_pc
;
1612 case DW_AT_call_tail_call
:
1613 if (dwarf_version
< 5)
1614 return DW_AT_GNU_tail_call
;
1617 case DW_AT_call_origin
:
1618 if (dwarf_version
< 5)
1619 return DW_AT_abstract_origin
;
1622 case DW_AT_call_target
:
1623 if (dwarf_version
< 5)
1624 return DW_AT_GNU_call_site_target
;
1627 case DW_AT_call_target_clobbered
:
1628 if (dwarf_version
< 5)
1629 return DW_AT_GNU_call_site_target_clobbered
;
1632 case DW_AT_call_parameter
:
1633 if (dwarf_version
< 5)
1634 return DW_AT_abstract_origin
;
1637 case DW_AT_call_value
:
1638 if (dwarf_version
< 5)
1639 return DW_AT_GNU_call_site_value
;
1642 case DW_AT_call_data_value
:
1643 if (dwarf_version
< 5)
1644 return DW_AT_GNU_call_site_data_value
;
1647 case DW_AT_call_all_calls
:
1648 if (dwarf_version
< 5)
1649 return DW_AT_GNU_all_call_sites
;
1652 case DW_AT_call_all_tail_calls
:
1653 if (dwarf_version
< 5)
1654 return DW_AT_GNU_all_tail_call_sites
;
1657 case DW_AT_dwo_name
:
1658 if (dwarf_version
< 5)
1659 return DW_AT_GNU_dwo_name
;
1668 /* And similarly for tags. */
1669 static inline enum dwarf_tag
1670 dwarf_TAG (enum dwarf_tag tag
)
1674 case DW_TAG_call_site
:
1675 if (dwarf_version
< 5)
1676 return DW_TAG_GNU_call_site
;
1679 case DW_TAG_call_site_parameter
:
1680 if (dwarf_version
< 5)
1681 return DW_TAG_GNU_call_site_parameter
;
1690 static unsigned long int get_base_type_offset (dw_die_ref
);
1692 /* Return the size of a location descriptor. */
1694 static unsigned long
1695 size_of_loc_descr (dw_loc_descr_ref loc
)
1697 unsigned long size
= 1;
1699 switch (loc
->dw_loc_opc
)
1702 size
+= DWARF2_ADDR_SIZE
;
1704 case DW_OP_GNU_addr_index
:
1705 case DW_OP_GNU_const_index
:
1706 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1707 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1726 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1729 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1734 case DW_OP_plus_uconst
:
1735 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1773 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1776 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1779 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1782 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1783 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1786 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1788 case DW_OP_bit_piece
:
1789 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1790 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1792 case DW_OP_deref_size
:
1793 case DW_OP_xderef_size
:
1802 case DW_OP_call_ref
:
1803 case DW_OP_GNU_variable_value
:
1804 size
+= DWARF_REF_SIZE
;
1806 case DW_OP_implicit_value
:
1807 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1808 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1810 case DW_OP_implicit_pointer
:
1811 case DW_OP_GNU_implicit_pointer
:
1812 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1814 case DW_OP_entry_value
:
1815 case DW_OP_GNU_entry_value
:
1817 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1818 size
+= size_of_uleb128 (op_size
) + op_size
;
1821 case DW_OP_const_type
:
1822 case DW_OP_GNU_const_type
:
1825 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1826 size
+= size_of_uleb128 (o
) + 1;
1827 switch (loc
->dw_loc_oprnd2
.val_class
)
1829 case dw_val_class_vec
:
1830 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1831 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1833 case dw_val_class_const
:
1834 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1836 case dw_val_class_const_double
:
1837 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1839 case dw_val_class_wide_int
:
1840 size
+= (get_full_len (*loc
->dw_loc_oprnd2
.v
.val_wide
)
1841 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
1848 case DW_OP_regval_type
:
1849 case DW_OP_GNU_regval_type
:
1852 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1853 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1854 + size_of_uleb128 (o
);
1857 case DW_OP_deref_type
:
1858 case DW_OP_GNU_deref_type
:
1861 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1862 size
+= 1 + size_of_uleb128 (o
);
1866 case DW_OP_reinterpret
:
1867 case DW_OP_GNU_convert
:
1868 case DW_OP_GNU_reinterpret
:
1869 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1870 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1874 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1875 size
+= size_of_uleb128 (o
);
1878 case DW_OP_GNU_parameter_ref
:
1888 /* Return the size of a series of location descriptors. */
1891 size_of_locs (dw_loc_descr_ref loc
)
1896 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1897 field, to avoid writing to a PCH file. */
1898 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1900 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1902 size
+= size_of_loc_descr (l
);
1907 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1909 l
->dw_loc_addr
= size
;
1910 size
+= size_of_loc_descr (l
);
1916 /* Return the size of the value in a DW_AT_discr_value attribute. */
1919 size_of_discr_value (dw_discr_value
*discr_value
)
1921 if (discr_value
->pos
)
1922 return size_of_uleb128 (discr_value
->v
.uval
);
1924 return size_of_sleb128 (discr_value
->v
.sval
);
1927 /* Return the size of the value in a DW_AT_discr_list attribute. */
1930 size_of_discr_list (dw_discr_list_ref discr_list
)
1934 for (dw_discr_list_ref list
= discr_list
;
1936 list
= list
->dw_discr_next
)
1938 /* One byte for the discriminant value descriptor, and then one or two
1939 LEB128 numbers, depending on whether it's a single case label or a
1942 size
+= size_of_discr_value (&list
->dw_discr_lower_bound
);
1943 if (list
->dw_discr_range
!= 0)
1944 size
+= size_of_discr_value (&list
->dw_discr_upper_bound
);
1949 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1950 static void get_ref_die_offset_label (char *, dw_die_ref
);
1951 static unsigned long int get_ref_die_offset (dw_die_ref
);
1953 /* Output location description stack opcode's operands (if any).
1954 The for_eh_or_skip parameter controls whether register numbers are
1955 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1956 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1957 info). This should be suppressed for the cases that have not been converted
1958 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1961 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1963 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1964 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1966 switch (loc
->dw_loc_opc
)
1968 #ifdef DWARF2_DEBUGGING_INFO
1971 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1976 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1977 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1979 fputc ('\n', asm_out_file
);
1984 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1989 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1990 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1992 fputc ('\n', asm_out_file
);
1997 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1998 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
2005 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2006 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2008 dw2_asm_output_data (2, offset
, NULL
);
2011 case DW_OP_implicit_value
:
2012 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2013 switch (val2
->val_class
)
2015 case dw_val_class_const
:
2016 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
2018 case dw_val_class_vec
:
2020 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2021 unsigned int len
= val2
->v
.val_vec
.length
;
2025 if (elt_size
> sizeof (HOST_WIDE_INT
))
2030 for (i
= 0, p
= (unsigned char *) val2
->v
.val_vec
.array
;
2033 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2034 "fp or vector constant word %u", i
);
2037 case dw_val_class_const_double
:
2039 unsigned HOST_WIDE_INT first
, second
;
2041 if (WORDS_BIG_ENDIAN
)
2043 first
= val2
->v
.val_double
.high
;
2044 second
= val2
->v
.val_double
.low
;
2048 first
= val2
->v
.val_double
.low
;
2049 second
= val2
->v
.val_double
.high
;
2051 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2053 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2057 case dw_val_class_wide_int
:
2060 int len
= get_full_len (*val2
->v
.val_wide
);
2061 if (WORDS_BIG_ENDIAN
)
2062 for (i
= len
- 1; i
>= 0; --i
)
2063 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2064 val2
->v
.val_wide
->elt (i
), NULL
);
2066 for (i
= 0; i
< len
; ++i
)
2067 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2068 val2
->v
.val_wide
->elt (i
), NULL
);
2071 case dw_val_class_addr
:
2072 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
2073 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
2088 case DW_OP_implicit_value
:
2089 /* We currently don't make any attempt to make sure these are
2090 aligned properly like we do for the main unwind info, so
2091 don't support emitting things larger than a byte if we're
2092 only doing unwinding. */
2097 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2100 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2103 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2106 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2108 case DW_OP_plus_uconst
:
2109 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2143 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2147 unsigned r
= val1
->v
.val_unsigned
;
2148 if (for_eh_or_skip
>= 0)
2149 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2150 gcc_assert (size_of_uleb128 (r
)
2151 == size_of_uleb128 (val1
->v
.val_unsigned
));
2152 dw2_asm_output_data_uleb128 (r
, NULL
);
2156 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2160 unsigned r
= val1
->v
.val_unsigned
;
2161 if (for_eh_or_skip
>= 0)
2162 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2163 gcc_assert (size_of_uleb128 (r
)
2164 == size_of_uleb128 (val1
->v
.val_unsigned
));
2165 dw2_asm_output_data_uleb128 (r
, NULL
);
2166 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2170 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2172 case DW_OP_bit_piece
:
2173 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2174 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
2176 case DW_OP_deref_size
:
2177 case DW_OP_xderef_size
:
2178 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2184 if (targetm
.asm_out
.output_dwarf_dtprel
)
2186 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
2189 fputc ('\n', asm_out_file
);
2196 #ifdef DWARF2_DEBUGGING_INFO
2197 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2204 case DW_OP_GNU_addr_index
:
2205 case DW_OP_GNU_const_index
:
2206 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
2207 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
2208 "(index into .debug_addr)");
2214 unsigned long die_offset
2215 = get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2216 /* Make sure the offset has been computed and that we can encode it as
2218 gcc_assert (die_offset
> 0
2219 && die_offset
<= (loc
->dw_loc_opc
== DW_OP_call2
2222 dw2_asm_output_data ((loc
->dw_loc_opc
== DW_OP_call2
) ? 2 : 4,
2227 case DW_OP_call_ref
:
2228 case DW_OP_GNU_variable_value
:
2230 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2231 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2232 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2233 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2234 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2238 case DW_OP_implicit_pointer
:
2239 case DW_OP_GNU_implicit_pointer
:
2241 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2242 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2243 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2244 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2245 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2246 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2250 case DW_OP_entry_value
:
2251 case DW_OP_GNU_entry_value
:
2252 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
2253 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
2256 case DW_OP_const_type
:
2257 case DW_OP_GNU_const_type
:
2259 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
2261 dw2_asm_output_data_uleb128 (o
, NULL
);
2262 switch (val2
->val_class
)
2264 case dw_val_class_const
:
2265 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2266 dw2_asm_output_data (1, l
, NULL
);
2267 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
2269 case dw_val_class_vec
:
2271 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2272 unsigned int len
= val2
->v
.val_vec
.length
;
2277 dw2_asm_output_data (1, l
, NULL
);
2278 if (elt_size
> sizeof (HOST_WIDE_INT
))
2283 for (i
= 0, p
= (unsigned char *) val2
->v
.val_vec
.array
;
2286 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2287 "fp or vector constant word %u", i
);
2290 case dw_val_class_const_double
:
2292 unsigned HOST_WIDE_INT first
, second
;
2293 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2295 dw2_asm_output_data (1, 2 * l
, NULL
);
2296 if (WORDS_BIG_ENDIAN
)
2298 first
= val2
->v
.val_double
.high
;
2299 second
= val2
->v
.val_double
.low
;
2303 first
= val2
->v
.val_double
.low
;
2304 second
= val2
->v
.val_double
.high
;
2306 dw2_asm_output_data (l
, first
, NULL
);
2307 dw2_asm_output_data (l
, second
, NULL
);
2310 case dw_val_class_wide_int
:
2313 int len
= get_full_len (*val2
->v
.val_wide
);
2314 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2316 dw2_asm_output_data (1, len
* l
, NULL
);
2317 if (WORDS_BIG_ENDIAN
)
2318 for (i
= len
- 1; i
>= 0; --i
)
2319 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2321 for (i
= 0; i
< len
; ++i
)
2322 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2330 case DW_OP_regval_type
:
2331 case DW_OP_GNU_regval_type
:
2333 unsigned r
= val1
->v
.val_unsigned
;
2334 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2336 if (for_eh_or_skip
>= 0)
2338 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2339 gcc_assert (size_of_uleb128 (r
)
2340 == size_of_uleb128 (val1
->v
.val_unsigned
));
2342 dw2_asm_output_data_uleb128 (r
, NULL
);
2343 dw2_asm_output_data_uleb128 (o
, NULL
);
2346 case DW_OP_deref_type
:
2347 case DW_OP_GNU_deref_type
:
2349 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2351 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2352 dw2_asm_output_data_uleb128 (o
, NULL
);
2356 case DW_OP_reinterpret
:
2357 case DW_OP_GNU_convert
:
2358 case DW_OP_GNU_reinterpret
:
2359 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2360 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2363 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2365 dw2_asm_output_data_uleb128 (o
, NULL
);
2369 case DW_OP_GNU_parameter_ref
:
2372 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2373 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2374 dw2_asm_output_data (4, o
, NULL
);
2379 /* Other codes have no operands. */
2384 /* Output a sequence of location operations.
2385 The for_eh_or_skip parameter controls whether register numbers are
2386 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2387 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2388 info). This should be suppressed for the cases that have not been converted
2389 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2392 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2394 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2396 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2397 /* Output the opcode. */
2398 if (for_eh_or_skip
>= 0
2399 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2401 unsigned r
= (opc
- DW_OP_breg0
);
2402 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2403 gcc_assert (r
<= 31);
2404 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2406 else if (for_eh_or_skip
>= 0
2407 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2409 unsigned r
= (opc
- DW_OP_reg0
);
2410 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2411 gcc_assert (r
<= 31);
2412 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2415 dw2_asm_output_data (1, opc
,
2416 "%s", dwarf_stack_op_name (opc
));
2418 /* Output the operand(s) (if any). */
2419 output_loc_operands (loc
, for_eh_or_skip
);
2423 /* Output location description stack opcode's operands (if any).
2424 The output is single bytes on a line, suitable for .cfi_escape. */
2427 output_loc_operands_raw (dw_loc_descr_ref loc
)
2429 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2430 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2432 switch (loc
->dw_loc_opc
)
2435 case DW_OP_GNU_addr_index
:
2436 case DW_OP_GNU_const_index
:
2437 case DW_OP_implicit_value
:
2438 /* We cannot output addresses in .cfi_escape, only bytes. */
2444 case DW_OP_deref_size
:
2445 case DW_OP_xderef_size
:
2446 fputc (',', asm_out_file
);
2447 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2452 fputc (',', asm_out_file
);
2453 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2458 fputc (',', asm_out_file
);
2459 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2464 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2465 fputc (',', asm_out_file
);
2466 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2474 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2475 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2477 fputc (',', asm_out_file
);
2478 dw2_asm_output_data_raw (2, offset
);
2484 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2485 gcc_assert (size_of_uleb128 (r
)
2486 == size_of_uleb128 (val1
->v
.val_unsigned
));
2487 fputc (',', asm_out_file
);
2488 dw2_asm_output_data_uleb128_raw (r
);
2493 case DW_OP_plus_uconst
:
2495 fputc (',', asm_out_file
);
2496 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2499 case DW_OP_bit_piece
:
2500 fputc (',', asm_out_file
);
2501 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2502 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2539 fputc (',', asm_out_file
);
2540 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2545 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2546 gcc_assert (size_of_uleb128 (r
)
2547 == size_of_uleb128 (val1
->v
.val_unsigned
));
2548 fputc (',', asm_out_file
);
2549 dw2_asm_output_data_uleb128_raw (r
);
2550 fputc (',', asm_out_file
);
2551 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2555 case DW_OP_implicit_pointer
:
2556 case DW_OP_entry_value
:
2557 case DW_OP_const_type
:
2558 case DW_OP_regval_type
:
2559 case DW_OP_deref_type
:
2561 case DW_OP_reinterpret
:
2562 case DW_OP_GNU_implicit_pointer
:
2563 case DW_OP_GNU_entry_value
:
2564 case DW_OP_GNU_const_type
:
2565 case DW_OP_GNU_regval_type
:
2566 case DW_OP_GNU_deref_type
:
2567 case DW_OP_GNU_convert
:
2568 case DW_OP_GNU_reinterpret
:
2569 case DW_OP_GNU_parameter_ref
:
2574 /* Other codes have no operands. */
2580 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2584 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2585 /* Output the opcode. */
2586 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2588 unsigned r
= (opc
- DW_OP_breg0
);
2589 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2590 gcc_assert (r
<= 31);
2591 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2593 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2595 unsigned r
= (opc
- DW_OP_reg0
);
2596 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2597 gcc_assert (r
<= 31);
2598 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2600 /* Output the opcode. */
2601 fprintf (asm_out_file
, "%#x", opc
);
2602 output_loc_operands_raw (loc
);
2604 if (!loc
->dw_loc_next
)
2606 loc
= loc
->dw_loc_next
;
2608 fputc (',', asm_out_file
);
2612 /* This function builds a dwarf location descriptor sequence from a
2613 dw_cfa_location, adding the given OFFSET to the result of the
2616 struct dw_loc_descr_node
*
2617 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2619 struct dw_loc_descr_node
*head
, *tmp
;
2621 offset
+= cfa
->offset
;
2625 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2626 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2627 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2628 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2629 add_loc_descr (&head
, tmp
);
2632 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2633 add_loc_descr (&head
, tmp
);
2637 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2642 /* This function builds a dwarf location descriptor sequence for
2643 the address at OFFSET from the CFA when stack is aligned to
2646 struct dw_loc_descr_node
*
2647 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2648 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2650 struct dw_loc_descr_node
*head
;
2651 unsigned int dwarf_fp
2652 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2654 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2655 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2657 head
= new_reg_loc_descr (dwarf_fp
, 0);
2658 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2659 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2660 loc_descr_plus_const (&head
, offset
);
2663 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2667 /* And now, the support for symbolic debugging information. */
2669 /* .debug_str support. */
2671 static void dwarf2out_init (const char *);
2672 static void dwarf2out_finish (const char *);
2673 static void dwarf2out_early_finish (const char *);
2674 static void dwarf2out_assembly_start (void);
2675 static void dwarf2out_define (unsigned int, const char *);
2676 static void dwarf2out_undef (unsigned int, const char *);
2677 static void dwarf2out_start_source_file (unsigned, const char *);
2678 static void dwarf2out_end_source_file (unsigned);
2679 static void dwarf2out_function_decl (tree
);
2680 static void dwarf2out_begin_block (unsigned, unsigned);
2681 static void dwarf2out_end_block (unsigned, unsigned);
2682 static bool dwarf2out_ignore_block (const_tree
);
2683 static void dwarf2out_early_global_decl (tree
);
2684 static void dwarf2out_late_global_decl (tree
);
2685 static void dwarf2out_type_decl (tree
, int);
2686 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool, bool);
2687 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2689 static void dwarf2out_abstract_function (tree
);
2690 static void dwarf2out_var_location (rtx_insn
*);
2691 static void dwarf2out_size_function (tree
);
2692 static void dwarf2out_begin_function (tree
);
2693 static void dwarf2out_end_function (unsigned int);
2694 static void dwarf2out_register_main_translation_unit (tree unit
);
2695 static void dwarf2out_set_name (tree
, tree
);
2696 static void dwarf2out_register_external_die (tree decl
, const char *sym
,
2697 unsigned HOST_WIDE_INT off
);
2698 static bool dwarf2out_die_ref_for_decl (tree decl
, const char **sym
,
2699 unsigned HOST_WIDE_INT
*off
);
2701 /* The debug hooks structure. */
2703 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2707 dwarf2out_early_finish
,
2708 dwarf2out_assembly_start
,
2711 dwarf2out_start_source_file
,
2712 dwarf2out_end_source_file
,
2713 dwarf2out_begin_block
,
2714 dwarf2out_end_block
,
2715 dwarf2out_ignore_block
,
2716 dwarf2out_source_line
,
2717 dwarf2out_begin_prologue
,
2718 #if VMS_DEBUGGING_INFO
2719 dwarf2out_vms_end_prologue
,
2720 dwarf2out_vms_begin_epilogue
,
2722 debug_nothing_int_charstar
,
2723 debug_nothing_int_charstar
,
2725 dwarf2out_end_epilogue
,
2726 dwarf2out_begin_function
,
2727 dwarf2out_end_function
, /* end_function */
2728 dwarf2out_register_main_translation_unit
,
2729 dwarf2out_function_decl
, /* function_decl */
2730 dwarf2out_early_global_decl
,
2731 dwarf2out_late_global_decl
,
2732 dwarf2out_type_decl
, /* type_decl */
2733 dwarf2out_imported_module_or_decl
,
2734 dwarf2out_die_ref_for_decl
,
2735 dwarf2out_register_external_die
,
2736 debug_nothing_tree
, /* deferred_inline_function */
2737 /* The DWARF 2 backend tries to reduce debugging bloat by not
2738 emitting the abstract description of inline functions until
2739 something tries to reference them. */
2740 dwarf2out_abstract_function
, /* outlining_inline_function */
2741 debug_nothing_rtx_code_label
, /* label */
2742 debug_nothing_int
, /* handle_pch */
2743 dwarf2out_var_location
,
2744 dwarf2out_size_function
, /* size_function */
2745 dwarf2out_switch_text_section
,
2747 1, /* start_end_main_source_file */
2748 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2751 const struct gcc_debug_hooks dwarf2_lineno_debug_hooks
=
2754 debug_nothing_charstar
,
2755 debug_nothing_charstar
,
2756 dwarf2out_assembly_start
,
2757 debug_nothing_int_charstar
,
2758 debug_nothing_int_charstar
,
2759 debug_nothing_int_charstar
,
2761 debug_nothing_int_int
, /* begin_block */
2762 debug_nothing_int_int
, /* end_block */
2763 debug_true_const_tree
, /* ignore_block */
2764 dwarf2out_source_line
, /* source_line */
2765 debug_nothing_int_int_charstar
, /* begin_prologue */
2766 debug_nothing_int_charstar
, /* end_prologue */
2767 debug_nothing_int_charstar
, /* begin_epilogue */
2768 debug_nothing_int_charstar
, /* end_epilogue */
2769 debug_nothing_tree
, /* begin_function */
2770 debug_nothing_int
, /* end_function */
2771 debug_nothing_tree
, /* register_main_translation_unit */
2772 debug_nothing_tree
, /* function_decl */
2773 debug_nothing_tree
, /* early_global_decl */
2774 debug_nothing_tree
, /* late_global_decl */
2775 debug_nothing_tree_int
, /* type_decl */
2776 debug_nothing_tree_tree_tree_bool_bool
,/* imported_module_or_decl */
2777 debug_false_tree_charstarstar_uhwistar
,/* die_ref_for_decl */
2778 debug_nothing_tree_charstar_uhwi
, /* register_external_die */
2779 debug_nothing_tree
, /* deferred_inline_function */
2780 debug_nothing_tree
, /* outlining_inline_function */
2781 debug_nothing_rtx_code_label
, /* label */
2782 debug_nothing_int
, /* handle_pch */
2783 debug_nothing_rtx_insn
, /* var_location */
2784 debug_nothing_tree
, /* size_function */
2785 debug_nothing_void
, /* switch_text_section */
2786 debug_nothing_tree_tree
, /* set_name */
2787 0, /* start_end_main_source_file */
2788 TYPE_SYMTAB_IS_ADDRESS
/* tree_type_symtab_field */
2791 /* NOTE: In the comments in this file, many references are made to
2792 "Debugging Information Entries". This term is abbreviated as `DIE'
2793 throughout the remainder of this file. */
2795 /* An internal representation of the DWARF output is built, and then
2796 walked to generate the DWARF debugging info. The walk of the internal
2797 representation is done after the entire program has been compiled.
2798 The types below are used to describe the internal representation. */
2800 /* Whether to put type DIEs into their own section .debug_types instead
2801 of making them part of the .debug_info section. Only supported for
2802 Dwarf V4 or higher and the user didn't disable them through
2803 -fno-debug-types-section. It is more efficient to put them in a
2804 separate comdat sections since the linker will then be able to
2805 remove duplicates. But not all tools support .debug_types sections
2806 yet. For Dwarf V5 or higher .debug_types doesn't exist any more,
2807 it is DW_UT_type unit type in .debug_info section. */
2809 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2811 /* Various DIE's use offsets relative to the beginning of the
2812 .debug_info section to refer to each other. */
2814 typedef long int dw_offset
;
2816 struct comdat_type_node
;
2818 /* The entries in the line_info table more-or-less mirror the opcodes
2819 that are used in the real dwarf line table. Arrays of these entries
2820 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2823 enum dw_line_info_opcode
{
2824 /* Emit DW_LNE_set_address; the operand is the label index. */
2827 /* Emit a row to the matrix with the given line. This may be done
2828 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2832 /* Emit a DW_LNS_set_file. */
2835 /* Emit a DW_LNS_set_column. */
2838 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2841 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2842 LI_set_prologue_end
,
2843 LI_set_epilogue_begin
,
2845 /* Emit a DW_LNE_set_discriminator. */
2846 LI_set_discriminator
2849 typedef struct GTY(()) dw_line_info_struct
{
2850 enum dw_line_info_opcode opcode
;
2852 } dw_line_info_entry
;
2855 struct GTY(()) dw_line_info_table
{
2856 /* The label that marks the end of this section. */
2857 const char *end_label
;
2859 /* The values for the last row of the matrix, as collected in the table.
2860 These are used to minimize the changes to the next row. */
2861 unsigned int file_num
;
2862 unsigned int line_num
;
2863 unsigned int column_num
;
2868 vec
<dw_line_info_entry
, va_gc
> *entries
;
2872 /* Each DIE attribute has a field specifying the attribute kind,
2873 a link to the next attribute in the chain, and an attribute value.
2874 Attributes are typically linked below the DIE they modify. */
2876 typedef struct GTY(()) dw_attr_struct
{
2877 enum dwarf_attribute dw_attr
;
2878 dw_val_node dw_attr_val
;
2883 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2884 The children of each node form a circular list linked by
2885 die_sib. die_child points to the node *before* the "first" child node. */
2887 typedef struct GTY((chain_circular ("%h.die_sib"), for_user
)) die_struct
{
2888 union die_symbol_or_type_node
2890 const char * GTY ((tag ("0"))) die_symbol
;
2891 comdat_type_node
*GTY ((tag ("1"))) die_type_node
;
2893 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2894 vec
<dw_attr_node
, va_gc
> *die_attr
;
2895 dw_die_ref die_parent
;
2896 dw_die_ref die_child
;
2898 dw_die_ref die_definition
; /* ref from a specification to its definition */
2899 dw_offset die_offset
;
2900 unsigned long die_abbrev
;
2902 unsigned int decl_id
;
2903 enum dwarf_tag die_tag
;
2904 /* Die is used and must not be pruned as unused. */
2905 BOOL_BITFIELD die_perennial_p
: 1;
2906 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2907 /* For an external ref to die_symbol if die_offset contains an extra
2908 offset to that symbol. */
2909 BOOL_BITFIELD with_offset
: 1;
2910 /* Whether this DIE was removed from the DIE tree, for example via
2911 prune_unused_types. We don't consider those present from the
2912 DIE lookup routines. */
2913 BOOL_BITFIELD removed
: 1;
2914 /* Lots of spare bits. */
2918 /* Set to TRUE while dwarf2out_early_global_decl is running. */
2919 static bool early_dwarf
;
2920 static bool early_dwarf_finished
;
2921 struct set_early_dwarf
{
2923 set_early_dwarf () : saved(early_dwarf
)
2925 gcc_assert (! early_dwarf_finished
);
2928 ~set_early_dwarf () { early_dwarf
= saved
; }
2931 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2932 #define FOR_EACH_CHILD(die, c, expr) do { \
2933 c = die->die_child; \
2937 } while (c != die->die_child); \
2940 /* The pubname structure */
2942 typedef struct GTY(()) pubname_struct
{
2949 struct GTY(()) dw_ranges
{
2951 /* If this is positive, it's a block number, otherwise it's a
2952 bitwise-negated index into dw_ranges_by_label. */
2954 /* Index for the range list for DW_FORM_rnglistx. */
2955 unsigned int idx
: 31;
2956 /* True if this range might be possibly in a different section
2957 from previous entry. */
2958 unsigned int maybe_new_sec
: 1;
2961 /* A structure to hold a macinfo entry. */
2963 typedef struct GTY(()) macinfo_struct
{
2965 unsigned HOST_WIDE_INT lineno
;
2971 struct GTY(()) dw_ranges_by_label
{
2976 /* The comdat type node structure. */
2977 struct GTY(()) comdat_type_node
2979 dw_die_ref root_die
;
2980 dw_die_ref type_die
;
2981 dw_die_ref skeleton_die
;
2982 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2983 comdat_type_node
*next
;
2986 /* A list of DIEs for which we can't determine ancestry (parent_die
2987 field) just yet. Later in dwarf2out_finish we will fill in the
2989 typedef struct GTY(()) limbo_die_struct
{
2991 /* The tree for which this DIE was created. We use this to
2992 determine ancestry later. */
2994 struct limbo_die_struct
*next
;
2998 typedef struct skeleton_chain_struct
3002 struct skeleton_chain_struct
*parent
;
3004 skeleton_chain_node
;
3006 /* Define a macro which returns nonzero for a TYPE_DECL which was
3007 implicitly generated for a type.
3009 Note that, unlike the C front-end (which generates a NULL named
3010 TYPE_DECL node for each complete tagged type, each array type,
3011 and each function type node created) the C++ front-end generates
3012 a _named_ TYPE_DECL node for each tagged type node created.
3013 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3014 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
3015 front-end, but for each type, tagged or not. */
3017 #define TYPE_DECL_IS_STUB(decl) \
3018 (DECL_NAME (decl) == NULL_TREE \
3019 || (DECL_ARTIFICIAL (decl) \
3020 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3021 /* This is necessary for stub decls that \
3022 appear in nested inline functions. */ \
3023 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3024 && (decl_ultimate_origin (decl) \
3025 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3027 /* Information concerning the compilation unit's programming
3028 language, and compiler version. */
3030 /* Fixed size portion of the DWARF compilation unit header. */
3031 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3032 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE \
3033 + (dwarf_version >= 5 ? 4 : 3))
3035 /* Fixed size portion of the DWARF comdat type unit header. */
3036 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
3037 (DWARF_COMPILE_UNIT_HEADER_SIZE \
3038 + DWARF_TYPE_SIGNATURE_SIZE + DWARF_OFFSET_SIZE)
3040 /* Fixed size portion of the DWARF skeleton compilation unit header. */
3041 #define DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE \
3042 (DWARF_COMPILE_UNIT_HEADER_SIZE + (dwarf_version >= 5 ? 8 : 0))
3044 /* Fixed size portion of public names info. */
3045 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3047 /* Fixed size portion of the address range info. */
3048 #define DWARF_ARANGES_HEADER_SIZE \
3049 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3050 DWARF2_ADDR_SIZE * 2) \
3051 - DWARF_INITIAL_LENGTH_SIZE)
3053 /* Size of padding portion in the address range info. It must be
3054 aligned to twice the pointer size. */
3055 #define DWARF_ARANGES_PAD_SIZE \
3056 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3057 DWARF2_ADDR_SIZE * 2) \
3058 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3060 /* Use assembler line directives if available. */
3061 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3062 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3063 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3065 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3069 /* Minimum line offset in a special line info. opcode.
3070 This value was chosen to give a reasonable range of values. */
3071 #define DWARF_LINE_BASE -10
3073 /* First special line opcode - leave room for the standard opcodes. */
3074 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
3076 /* Range of line offsets in a special line info. opcode. */
3077 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3079 /* Flag that indicates the initial value of the is_stmt_start flag.
3080 In the present implementation, we do not mark any lines as
3081 the beginning of a source statement, because that information
3082 is not made available by the GCC front-end. */
3083 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3085 /* Maximum number of operations per instruction bundle. */
3086 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
3087 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
3090 /* This location is used by calc_die_sizes() to keep track
3091 the offset of each DIE within the .debug_info section. */
3092 static unsigned long next_die_offset
;
3094 /* Record the root of the DIE's built for the current compilation unit. */
3095 static GTY(()) dw_die_ref single_comp_unit_die
;
3097 /* A list of type DIEs that have been separated into comdat sections. */
3098 static GTY(()) comdat_type_node
*comdat_type_list
;
3100 /* A list of CU DIEs that have been separated. */
3101 static GTY(()) limbo_die_node
*cu_die_list
;
3103 /* A list of DIEs with a NULL parent waiting to be relocated. */
3104 static GTY(()) limbo_die_node
*limbo_die_list
;
3106 /* A list of DIEs for which we may have to generate
3107 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
3108 static GTY(()) limbo_die_node
*deferred_asm_name
;
3110 struct dwarf_file_hasher
: ggc_ptr_hash
<dwarf_file_data
>
3112 typedef const char *compare_type
;
3114 static hashval_t
hash (dwarf_file_data
*);
3115 static bool equal (dwarf_file_data
*, const char *);
3118 /* Filenames referenced by this compilation unit. */
3119 static GTY(()) hash_table
<dwarf_file_hasher
> *file_table
;
3121 struct decl_die_hasher
: ggc_ptr_hash
<die_node
>
3123 typedef tree compare_type
;
3125 static hashval_t
hash (die_node
*);
3126 static bool equal (die_node
*, tree
);
3128 /* A hash table of references to DIE's that describe declarations.
3129 The key is a DECL_UID() which is a unique number identifying each decl. */
3130 static GTY (()) hash_table
<decl_die_hasher
> *decl_die_table
;
3132 struct GTY ((for_user
)) variable_value_struct
{
3133 unsigned int decl_id
;
3134 vec
<dw_die_ref
, va_gc
> *dies
;
3137 struct variable_value_hasher
: ggc_ptr_hash
<variable_value_struct
>
3139 typedef tree compare_type
;
3141 static hashval_t
hash (variable_value_struct
*);
3142 static bool equal (variable_value_struct
*, tree
);
3144 /* A hash table of DIEs that contain DW_OP_GNU_variable_value with
3145 dw_val_class_decl_ref class, indexed by FUNCTION_DECLs which is
3146 DECL_CONTEXT of the referenced VAR_DECLs. */
3147 static GTY (()) hash_table
<variable_value_hasher
> *variable_value_hash
;
3149 struct block_die_hasher
: ggc_ptr_hash
<die_struct
>
3151 static hashval_t
hash (die_struct
*);
3152 static bool equal (die_struct
*, die_struct
*);
3155 /* A hash table of references to DIE's that describe COMMON blocks.
3156 The key is DECL_UID() ^ die_parent. */
3157 static GTY (()) hash_table
<block_die_hasher
> *common_block_die_table
;
3159 typedef struct GTY(()) die_arg_entry_struct
{
3165 /* Node of the variable location list. */
3166 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
3167 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
3168 EXPR_LIST chain. For small bitsizes, bitsize is encoded
3169 in mode of the EXPR_LIST node and first EXPR_LIST operand
3170 is either NOTE_INSN_VAR_LOCATION for a piece with a known
3171 location or NULL for padding. For larger bitsizes,
3172 mode is 0 and first operand is a CONCAT with bitsize
3173 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
3174 NULL as second operand. */
3176 const char * GTY (()) label
;
3177 struct var_loc_node
* GTY (()) next
;
3180 /* Variable location list. */
3181 struct GTY ((for_user
)) var_loc_list_def
{
3182 struct var_loc_node
* GTY (()) first
;
3184 /* Pointer to the last but one or last element of the
3185 chained list. If the list is empty, both first and
3186 last are NULL, if the list contains just one node
3187 or the last node certainly is not redundant, it points
3188 to the last node, otherwise points to the last but one.
3189 Do not mark it for GC because it is marked through the chain. */
3190 struct var_loc_node
* GTY ((skip ("%h"))) last
;
3192 /* Pointer to the last element before section switch,
3193 if NULL, either sections weren't switched or first
3194 is after section switch. */
3195 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
3197 /* DECL_UID of the variable decl. */
3198 unsigned int decl_id
;
3200 typedef struct var_loc_list_def var_loc_list
;
3202 /* Call argument location list. */
3203 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
3204 rtx
GTY (()) call_arg_loc_note
;
3205 const char * GTY (()) label
;
3206 tree
GTY (()) block
;
3208 rtx
GTY (()) symbol_ref
;
3209 struct call_arg_loc_node
* GTY (()) next
;
3213 struct decl_loc_hasher
: ggc_ptr_hash
<var_loc_list
>
3215 typedef const_tree compare_type
;
3217 static hashval_t
hash (var_loc_list
*);
3218 static bool equal (var_loc_list
*, const_tree
);
3221 /* Table of decl location linked lists. */
3222 static GTY (()) hash_table
<decl_loc_hasher
> *decl_loc_table
;
3224 /* Head and tail of call_arg_loc chain. */
3225 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
3226 static struct call_arg_loc_node
*call_arg_loc_last
;
3228 /* Number of call sites in the current function. */
3229 static int call_site_count
= -1;
3230 /* Number of tail call sites in the current function. */
3231 static int tail_call_site_count
= -1;
3233 /* A cached location list. */
3234 struct GTY ((for_user
)) cached_dw_loc_list_def
{
3235 /* The DECL_UID of the decl that this entry describes. */
3236 unsigned int decl_id
;
3238 /* The cached location list. */
3239 dw_loc_list_ref loc_list
;
3241 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
3243 struct dw_loc_list_hasher
: ggc_ptr_hash
<cached_dw_loc_list
>
3246 typedef const_tree compare_type
;
3248 static hashval_t
hash (cached_dw_loc_list
*);
3249 static bool equal (cached_dw_loc_list
*, const_tree
);
3252 /* Table of cached location lists. */
3253 static GTY (()) hash_table
<dw_loc_list_hasher
> *cached_dw_loc_list_table
;
3255 /* A vector of references to DIE's that are uniquely identified by their tag,
3256 presence/absence of children DIE's, and list of attribute/value pairs. */
3257 static GTY(()) vec
<dw_die_ref
, va_gc
> *abbrev_die_table
;
3259 /* A hash map to remember the stack usage for DWARF procedures. The value
3260 stored is the stack size difference between before the DWARF procedure
3261 invokation and after it returned. In other words, for a DWARF procedure
3262 that consumes N stack slots and that pushes M ones, this stores M - N. */
3263 static hash_map
<dw_die_ref
, int> *dwarf_proc_stack_usage_map
;
3265 /* A global counter for generating labels for line number data. */
3266 static unsigned int line_info_label_num
;
3268 /* The current table to which we should emit line number information
3269 for the current function. This will be set up at the beginning of
3270 assembly for the function. */
3271 static GTY(()) dw_line_info_table
*cur_line_info_table
;
3273 /* The two default tables of line number info. */
3274 static GTY(()) dw_line_info_table
*text_section_line_info
;
3275 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
3277 /* The set of all non-default tables of line number info. */
3278 static GTY(()) vec
<dw_line_info_table
*, va_gc
> *separate_line_info
;
3280 /* A flag to tell pubnames/types export if there is an info section to
3282 static bool info_section_emitted
;
3284 /* A pointer to the base of a table that contains a list of publicly
3285 accessible names. */
3286 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
3288 /* A pointer to the base of a table that contains a list of publicly
3289 accessible types. */
3290 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
3292 /* A pointer to the base of a table that contains a list of macro
3293 defines/undefines (and file start/end markers). */
3294 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
3296 /* True if .debug_macinfo or .debug_macros section is going to be
3298 #define have_macinfo \
3299 ((!XCOFF_DEBUGGING_INFO || HAVE_XCOFF_DWARF_EXTRAS) \
3300 && debug_info_level >= DINFO_LEVEL_VERBOSE \
3301 && !macinfo_table->is_empty ())
3303 /* Vector of dies for which we should generate .debug_ranges info. */
3304 static GTY (()) vec
<dw_ranges
, va_gc
> *ranges_table
;
3306 /* Vector of pairs of labels referenced in ranges_table. */
3307 static GTY (()) vec
<dw_ranges_by_label
, va_gc
> *ranges_by_label
;
3309 /* Whether we have location lists that need outputting */
3310 static GTY(()) bool have_location_lists
;
3312 /* Unique label counter. */
3313 static GTY(()) unsigned int loclabel_num
;
3315 /* Unique label counter for point-of-call tables. */
3316 static GTY(()) unsigned int poc_label_num
;
3318 /* The last file entry emitted by maybe_emit_file(). */
3319 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
3321 /* Number of internal labels generated by gen_internal_sym(). */
3322 static GTY(()) int label_num
;
3324 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
3326 /* Instances of generic types for which we need to generate debug
3327 info that describe their generic parameters and arguments. That
3328 generation needs to happen once all types are properly laid out so
3329 we do it at the end of compilation. */
3330 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
3332 /* Offset from the "steady-state frame pointer" to the frame base,
3333 within the current function. */
3334 static HOST_WIDE_INT frame_pointer_fb_offset
;
3335 static bool frame_pointer_fb_offset_valid
;
3337 static vec
<dw_die_ref
> base_types
;
3339 /* Flags to represent a set of attribute classes for attributes that represent
3340 a scalar value (bounds, pointers, ...). */
3343 dw_scalar_form_constant
= 0x01,
3344 dw_scalar_form_exprloc
= 0x02,
3345 dw_scalar_form_reference
= 0x04
3348 /* Forward declarations for functions defined in this file. */
3350 static int is_pseudo_reg (const_rtx
);
3351 static tree
type_main_variant (tree
);
3352 static int is_tagged_type (const_tree
);
3353 static const char *dwarf_tag_name (unsigned);
3354 static const char *dwarf_attr_name (unsigned);
3355 static const char *dwarf_form_name (unsigned);
3356 static tree
decl_ultimate_origin (const_tree
);
3357 static tree
decl_class_context (tree
);
3358 static void add_dwarf_attr (dw_die_ref
, dw_attr_node
*);
3359 static inline enum dw_val_class
AT_class (dw_attr_node
*);
3360 static inline unsigned int AT_index (dw_attr_node
*);
3361 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3362 static inline unsigned AT_flag (dw_attr_node
*);
3363 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3364 static inline HOST_WIDE_INT
AT_int (dw_attr_node
*);
3365 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3366 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_node
*);
3367 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
3368 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
3369 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3370 unsigned int, unsigned char *);
3371 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
3372 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3373 static inline const char *AT_string (dw_attr_node
*);
3374 static enum dwarf_form
AT_string_form (dw_attr_node
*);
3375 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3376 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3377 static inline dw_die_ref
AT_ref (dw_attr_node
*);
3378 static inline int AT_ref_external (dw_attr_node
*);
3379 static inline void set_AT_ref_external (dw_attr_node
*, int);
3380 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3381 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3382 static inline dw_loc_descr_ref
AT_loc (dw_attr_node
*);
3383 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3385 static inline dw_loc_list_ref
AT_loc_list (dw_attr_node
*);
3386 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
3387 static void remove_addr_table_entry (addr_table_entry
*);
3388 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
3389 static inline rtx
AT_addr (dw_attr_node
*);
3390 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3391 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3392 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3393 static void add_AT_loclistsptr (dw_die_ref
, enum dwarf_attribute
,
3395 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3396 unsigned HOST_WIDE_INT
);
3397 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3398 unsigned long, bool);
3399 static inline const char *AT_lbl (dw_attr_node
*);
3400 static dw_attr_node
*get_AT (dw_die_ref
, enum dwarf_attribute
);
3401 static const char *get_AT_low_pc (dw_die_ref
);
3402 static const char *get_AT_hi_pc (dw_die_ref
);
3403 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3404 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3405 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3406 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3407 static bool is_cxx (void);
3408 static bool is_cxx (const_tree
);
3409 static bool is_fortran (void);
3410 static bool is_ada (void);
3411 static bool remove_AT (dw_die_ref
, enum dwarf_attribute
);
3412 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3413 static void add_child_die (dw_die_ref
, dw_die_ref
);
3414 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3415 static dw_die_ref
lookup_type_die (tree
);
3416 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3417 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3418 static void equate_type_number_to_die (tree
, dw_die_ref
);
3419 static dw_die_ref
lookup_decl_die (tree
);
3420 static var_loc_list
*lookup_decl_loc (const_tree
);
3421 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3422 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3423 static void print_spaces (FILE *);
3424 static void print_die (dw_die_ref
, FILE *);
3425 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3426 static void attr_checksum (dw_attr_node
*, struct md5_ctx
*, int *);
3427 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3428 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3429 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3430 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3431 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_node
*,
3432 struct md5_ctx
*, int *);
3433 struct checksum_attributes
;
3434 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3435 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3436 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3437 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3438 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3439 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3440 static int same_attr_p (dw_attr_node
*, dw_attr_node
*, int *);
3441 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3442 static int is_type_die (dw_die_ref
);
3443 static int is_comdat_die (dw_die_ref
);
3444 static inline bool is_template_instantiation (dw_die_ref
);
3445 static int is_declaration_die (dw_die_ref
);
3446 static int should_move_die_to_comdat (dw_die_ref
);
3447 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3448 static dw_die_ref
clone_die (dw_die_ref
);
3449 static dw_die_ref
clone_tree (dw_die_ref
);
3450 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3451 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3452 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3453 static dw_die_ref
generate_skeleton (dw_die_ref
);
3454 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3457 static void break_out_comdat_types (dw_die_ref
);
3458 static void copy_decls_for_unworthy_types (dw_die_ref
);
3460 static void add_sibling_attributes (dw_die_ref
);
3461 static void output_location_lists (dw_die_ref
);
3462 static int constant_size (unsigned HOST_WIDE_INT
);
3463 static unsigned long size_of_die (dw_die_ref
);
3464 static void calc_die_sizes (dw_die_ref
);
3465 static void calc_base_type_die_sizes (void);
3466 static void mark_dies (dw_die_ref
);
3467 static void unmark_dies (dw_die_ref
);
3468 static void unmark_all_dies (dw_die_ref
);
3469 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3470 static unsigned long size_of_aranges (void);
3471 static enum dwarf_form
value_format (dw_attr_node
*);
3472 static void output_value_format (dw_attr_node
*);
3473 static void output_abbrev_section (void);
3474 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3475 static void output_die_symbol (dw_die_ref
);
3476 static void output_die (dw_die_ref
);
3477 static void output_compilation_unit_header (enum dwarf_unit_type
);
3478 static void output_comp_unit (dw_die_ref
, int, const unsigned char *);
3479 static void output_comdat_type_unit (comdat_type_node
*);
3480 static const char *dwarf2_name (tree
, int);
3481 static void add_pubname (tree
, dw_die_ref
);
3482 static void add_enumerator_pubname (const char *, dw_die_ref
);
3483 static void add_pubname_string (const char *, dw_die_ref
);
3484 static void add_pubtype (tree
, dw_die_ref
);
3485 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3486 static void output_aranges (void);
3487 static unsigned int add_ranges (const_tree
, bool = false);
3488 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3490 static void output_ranges (void);
3491 static dw_line_info_table
*new_line_info_table (void);
3492 static void output_line_info (bool);
3493 static void output_file_names (void);
3494 static dw_die_ref
base_type_die (tree
, bool);
3495 static int is_base_type (tree
);
3496 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, tree
, dw_die_ref
);
3497 static int decl_quals (const_tree
);
3498 static dw_die_ref
modified_type_die (tree
, int, bool, dw_die_ref
);
3499 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3500 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3501 static int type_is_enum (const_tree
);
3502 static unsigned int dbx_reg_number (const_rtx
);
3503 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3504 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3505 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3506 enum var_init_status
);
3507 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3508 enum var_init_status
);
3509 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3510 enum var_init_status
);
3511 static int is_based_loc (const_rtx
);
3512 static bool resolve_one_addr (rtx
*);
3513 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3514 enum var_init_status
);
3515 static dw_loc_descr_ref
loc_descriptor (rtx
, machine_mode mode
,
3516 enum var_init_status
);
3517 struct loc_descr_context
;
3518 static void add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
);
3519 static void add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
);
3520 static dw_loc_list_ref
loc_list_from_tree (tree
, int,
3521 struct loc_descr_context
*);
3522 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int,
3523 struct loc_descr_context
*);
3524 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3525 static tree
field_type (const_tree
);
3526 static unsigned int simple_type_align_in_bits (const_tree
);
3527 static unsigned int simple_decl_align_in_bits (const_tree
);
3528 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3530 static dw_loc_descr_ref
field_byte_offset (const_tree
, struct vlr_context
*,
3532 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3534 static void add_data_member_location_attribute (dw_die_ref
, tree
,
3535 struct vlr_context
*);
3536 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3537 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3538 static void insert_wide_int (const wide_int
&, unsigned char *, int);
3539 static void insert_float (const_rtx
, unsigned char *);
3540 static rtx
rtl_for_decl_location (tree
);
3541 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool);
3542 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3543 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3544 static void add_name_attribute (dw_die_ref
, const char *);
3545 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3546 static void add_comp_dir_attribute (dw_die_ref
);
3547 static void add_scalar_info (dw_die_ref
, enum dwarf_attribute
, tree
, int,
3548 struct loc_descr_context
*);
3549 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
,
3550 struct loc_descr_context
*);
3551 static void add_subscript_info (dw_die_ref
, tree
, bool);
3552 static void add_byte_size_attribute (dw_die_ref
, tree
);
3553 static void add_alignment_attribute (dw_die_ref
, tree
);
3554 static inline void add_bit_offset_attribute (dw_die_ref
, tree
,
3555 struct vlr_context
*);
3556 static void add_bit_size_attribute (dw_die_ref
, tree
);
3557 static void add_prototyped_attribute (dw_die_ref
, tree
);
3558 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3559 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3560 static void add_src_coords_attributes (dw_die_ref
, tree
);
3561 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
, bool = false);
3562 static void add_discr_value (dw_die_ref
, dw_discr_value
*);
3563 static void add_discr_list (dw_die_ref
, dw_discr_list_ref
);
3564 static inline dw_discr_list_ref
AT_discr_list (dw_attr_node
*);
3565 static void push_decl_scope (tree
);
3566 static void pop_decl_scope (void);
3567 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3568 static inline int local_scope_p (dw_die_ref
);
3569 static inline int class_scope_p (dw_die_ref
);
3570 static inline int class_or_namespace_scope_p (dw_die_ref
);
3571 static void add_type_attribute (dw_die_ref
, tree
, int, bool, dw_die_ref
);
3572 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3573 static const char *type_tag (const_tree
);
3574 static tree
member_declared_type (const_tree
);
3576 static const char *decl_start_label (tree
);
3578 static void gen_array_type_die (tree
, dw_die_ref
);
3579 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3581 static void gen_entry_point_die (tree
, dw_die_ref
);
3583 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3584 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3585 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3586 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3587 static void gen_formal_types_die (tree
, dw_die_ref
);
3588 static void gen_subprogram_die (tree
, dw_die_ref
);
3589 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3590 static void gen_const_die (tree
, dw_die_ref
);
3591 static void gen_label_die (tree
, dw_die_ref
);
3592 static void gen_lexical_block_die (tree
, dw_die_ref
);
3593 static void gen_inlined_subroutine_die (tree
, dw_die_ref
);
3594 static void gen_field_die (tree
, struct vlr_context
*, dw_die_ref
);
3595 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3596 static dw_die_ref
gen_compile_unit_die (const char *);
3597 static void gen_inheritance_die (tree
, tree
, tree
, dw_die_ref
);
3598 static void gen_member_die (tree
, dw_die_ref
);
3599 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3600 enum debug_info_usage
);
3601 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3602 static void gen_typedef_die (tree
, dw_die_ref
);
3603 static void gen_type_die (tree
, dw_die_ref
);
3604 static void gen_block_die (tree
, dw_die_ref
);
3605 static void decls_for_scope (tree
, dw_die_ref
);
3606 static bool is_naming_typedef_decl (const_tree
);
3607 static inline dw_die_ref
get_context_die (tree
);
3608 static void gen_namespace_die (tree
, dw_die_ref
);
3609 static dw_die_ref
gen_namelist_decl (tree
, dw_die_ref
, tree
);
3610 static dw_die_ref
gen_decl_die (tree
, tree
, struct vlr_context
*, dw_die_ref
);
3611 static dw_die_ref
force_decl_die (tree
);
3612 static dw_die_ref
force_type_die (tree
);
3613 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3614 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3615 static struct dwarf_file_data
* lookup_filename (const char *);
3616 static void retry_incomplete_types (void);
3617 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3618 static void gen_generic_params_dies (tree
);
3619 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3620 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3621 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3622 static int file_info_cmp (const void *, const void *);
3623 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3624 const char *, const char *);
3625 static void output_loc_list (dw_loc_list_ref
);
3626 static char *gen_internal_sym (const char *);
3627 static bool want_pubnames (void);
3629 static void prune_unmark_dies (dw_die_ref
);
3630 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3631 static void prune_unused_types_mark (dw_die_ref
, int);
3632 static void prune_unused_types_walk (dw_die_ref
);
3633 static void prune_unused_types_walk_attribs (dw_die_ref
);
3634 static void prune_unused_types_prune (dw_die_ref
);
3635 static void prune_unused_types (void);
3636 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3637 static inline const char *AT_vms_delta1 (dw_attr_node
*);
3638 static inline const char *AT_vms_delta2 (dw_attr_node
*);
3639 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3640 const char *, const char *);
3641 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3642 static void gen_remaining_tmpl_value_param_die_attribute (void);
3643 static bool generic_type_p (tree
);
3644 static void schedule_generic_params_dies_gen (tree t
);
3645 static void gen_scheduled_generic_parms_dies (void);
3646 static void resolve_variable_values (void);
3648 static const char *comp_dir_string (void);
3650 static void hash_loc_operands (dw_loc_descr_ref
, inchash::hash
&);
3652 /* enum for tracking thread-local variables whose address is really an offset
3653 relative to the TLS pointer, which will need link-time relocation, but will
3654 not need relocation by the DWARF consumer. */
3662 /* Return the operator to use for an address of a variable. For dtprel_true, we
3663 use DW_OP_const*. For regular variables, which need both link-time
3664 relocation and consumer-level relocation (e.g., to account for shared objects
3665 loaded at a random address), we use DW_OP_addr*. */
3667 static inline enum dwarf_location_atom
3668 dw_addr_op (enum dtprel_bool dtprel
)
3670 if (dtprel
== dtprel_true
)
3671 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3672 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3674 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3677 /* Return a pointer to a newly allocated address location description. If
3678 dwarf_split_debug_info is true, then record the address with the appropriate
3680 static inline dw_loc_descr_ref
3681 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3683 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3685 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3686 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3687 ref
->dtprel
= dtprel
;
3688 if (dwarf_split_debug_info
)
3689 ref
->dw_loc_oprnd1
.val_entry
3690 = add_addr_table_entry (addr
,
3691 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3693 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3698 /* Section names used to hold DWARF debugging information. */
3700 #ifndef DEBUG_INFO_SECTION
3701 #define DEBUG_INFO_SECTION ".debug_info"
3703 #ifndef DEBUG_DWO_INFO_SECTION
3704 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3706 #ifndef DEBUG_LTO_DWO_INFO_SECTION
3707 #define DEBUG_LTO_DWO_INFO_SECTION ".gnu.debuglto_.debug_info.dwo"
3709 #ifndef DEBUG_LTO_INFO_SECTION
3710 #define DEBUG_LTO_INFO_SECTION ".gnu.debuglto_.debug_info"
3712 #ifndef DEBUG_ABBREV_SECTION
3713 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3715 #ifndef DEBUG_DWO_ABBREV_SECTION
3716 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3718 #ifndef DEBUG_LTO_DWO_ABBREV_SECTION
3719 #define DEBUG_LTO_DWO_ABBREV_SECTION ".gnu.debuglto_.debug_abbrev.dwo"
3721 #ifndef DEBUG_LTO_ABBREV_SECTION
3722 #define DEBUG_LTO_ABBREV_SECTION ".gnu.debuglto_.debug_abbrev"
3724 #ifndef DEBUG_ARANGES_SECTION
3725 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3727 #ifndef DEBUG_ADDR_SECTION
3728 #define DEBUG_ADDR_SECTION ".debug_addr"
3730 #ifndef DEBUG_MACINFO_SECTION
3731 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3733 #ifndef DEBUG_DWO_MACINFO_SECTION
3734 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3736 #ifndef DEBUG_LTO_DWO_MACINFO_SECTION
3737 #define DEBUG_LTO_DWO_MACINFO_SECTION ".gnu.debuglto_.debug_macinfo.dwo"
3739 #ifndef DEBUG_LTO_MACINFO_SECTION
3740 #define DEBUG_LTO_MACINFO_SECTION ".gnu.debuglto_.debug_macinfo"
3742 #ifndef DEBUG_DWO_MACRO_SECTION
3743 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3745 #ifndef DEBUG_MACRO_SECTION
3746 #define DEBUG_MACRO_SECTION ".debug_macro"
3748 #ifndef DEBUG_LTO_DWO_MACRO_SECTION
3749 #define DEBUG_LTO_DWO_MACRO_SECTION ".gnu.debuglto_.debug_macro.dwo"
3751 #ifndef DEBUG_LTO_MACRO_SECTION
3752 #define DEBUG_LTO_MACRO_SECTION ".gnu.debuglto_.debug_macro"
3754 #ifndef DEBUG_LINE_SECTION
3755 #define DEBUG_LINE_SECTION ".debug_line"
3757 #ifndef DEBUG_DWO_LINE_SECTION
3758 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3760 #ifndef DEBUG_LTO_LINE_SECTION
3761 #define DEBUG_LTO_LINE_SECTION ".gnu.debuglto_.debug_line.dwo"
3763 #ifndef DEBUG_LOC_SECTION
3764 #define DEBUG_LOC_SECTION ".debug_loc"
3766 #ifndef DEBUG_DWO_LOC_SECTION
3767 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3769 #ifndef DEBUG_LOCLISTS_SECTION
3770 #define DEBUG_LOCLISTS_SECTION ".debug_loclists"
3772 #ifndef DEBUG_DWO_LOCLISTS_SECTION
3773 #define DEBUG_DWO_LOCLISTS_SECTION ".debug_loclists.dwo"
3775 #ifndef DEBUG_PUBNAMES_SECTION
3776 #define DEBUG_PUBNAMES_SECTION \
3777 ((debug_generate_pub_sections == 2) \
3778 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3780 #ifndef DEBUG_PUBTYPES_SECTION
3781 #define DEBUG_PUBTYPES_SECTION \
3782 ((debug_generate_pub_sections == 2) \
3783 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3785 #ifndef DEBUG_STR_OFFSETS_SECTION
3786 #define DEBUG_STR_OFFSETS_SECTION ".debug_str_offsets"
3788 #ifndef DEBUG_DWO_STR_OFFSETS_SECTION
3789 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3791 #ifndef DEBUG_LTO_DWO_STR_OFFSETS_SECTION
3792 #define DEBUG_LTO_DWO_STR_OFFSETS_SECTION ".gnu.debuglto_.debug_str_offsets.dwo"
3794 #ifndef DEBUG_STR_DWO_SECTION
3795 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3797 #ifndef DEBUG_LTO_STR_DWO_SECTION
3798 #define DEBUG_LTO_STR_DWO_SECTION ".gnu.debuglto_.debug_str.dwo"
3800 #ifndef DEBUG_STR_SECTION
3801 #define DEBUG_STR_SECTION ".debug_str"
3803 #ifndef DEBUG_LTO_STR_SECTION
3804 #define DEBUG_LTO_STR_SECTION ".gnu.debuglto_.debug_str"
3806 #ifndef DEBUG_RANGES_SECTION
3807 #define DEBUG_RANGES_SECTION ".debug_ranges"
3809 #ifndef DEBUG_RNGLISTS_SECTION
3810 #define DEBUG_RNGLISTS_SECTION ".debug_rnglists"
3812 #ifndef DEBUG_LINE_STR_SECTION
3813 #define DEBUG_LINE_STR_SECTION ".debug_line_str"
3816 /* Standard ELF section names for compiled code and data. */
3817 #ifndef TEXT_SECTION_NAME
3818 #define TEXT_SECTION_NAME ".text"
3821 /* Section flags for .debug_str section. */
3822 #define DEBUG_STR_SECTION_FLAGS \
3823 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3824 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3827 /* Section flags for .debug_str.dwo section. */
3828 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3830 /* Attribute used to refer to the macro section. */
3831 #define DEBUG_MACRO_ATTRIBUTE (dwarf_version >= 5 ? DW_AT_macros \
3832 : dwarf_strict ? DW_AT_macro_info : DW_AT_GNU_macros)
3834 /* Labels we insert at beginning sections we can reference instead of
3835 the section names themselves. */
3837 #ifndef TEXT_SECTION_LABEL
3838 #define TEXT_SECTION_LABEL "Ltext"
3840 #ifndef COLD_TEXT_SECTION_LABEL
3841 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3843 #ifndef DEBUG_LINE_SECTION_LABEL
3844 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3846 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3847 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3849 #ifndef DEBUG_INFO_SECTION_LABEL
3850 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3852 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3853 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3855 #ifndef DEBUG_ABBREV_SECTION_LABEL
3856 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3858 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3859 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3861 #ifndef DEBUG_ADDR_SECTION_LABEL
3862 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3864 #ifndef DEBUG_LOC_SECTION_LABEL
3865 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3867 #ifndef DEBUG_RANGES_SECTION_LABEL
3868 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3870 #ifndef DEBUG_MACINFO_SECTION_LABEL
3871 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3873 #ifndef DEBUG_MACRO_SECTION_LABEL
3874 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3876 #define SKELETON_COMP_DIE_ABBREV 1
3877 #define SKELETON_TYPE_DIE_ABBREV 2
3879 /* Definitions of defaults for formats and names of various special
3880 (artificial) labels which may be generated within this file (when the -g
3881 options is used and DWARF2_DEBUGGING_INFO is in effect.
3882 If necessary, these may be overridden from within the tm.h file, but
3883 typically, overriding these defaults is unnecessary. */
3885 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3886 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3887 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3888 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3889 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3890 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3891 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3892 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3893 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3894 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3895 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3896 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3897 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3898 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3899 static char ranges_base_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3901 #ifndef TEXT_END_LABEL
3902 #define TEXT_END_LABEL "Letext"
3904 #ifndef COLD_END_LABEL
3905 #define COLD_END_LABEL "Letext_cold"
3907 #ifndef BLOCK_BEGIN_LABEL
3908 #define BLOCK_BEGIN_LABEL "LBB"
3910 #ifndef BLOCK_END_LABEL
3911 #define BLOCK_END_LABEL "LBE"
3913 #ifndef LINE_CODE_LABEL
3914 #define LINE_CODE_LABEL "LM"
3918 /* Return the root of the DIE's built for the current compilation unit. */
3920 comp_unit_die (void)
3922 if (!single_comp_unit_die
)
3923 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3924 return single_comp_unit_die
;
3927 /* We allow a language front-end to designate a function that is to be
3928 called to "demangle" any name before it is put into a DIE. */
3930 static const char *(*demangle_name_func
) (const char *);
3933 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3935 demangle_name_func
= func
;
3938 /* Test if rtl node points to a pseudo register. */
3941 is_pseudo_reg (const_rtx rtl
)
3943 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3944 || (GET_CODE (rtl
) == SUBREG
3945 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3948 /* Return a reference to a type, with its const and volatile qualifiers
3952 type_main_variant (tree type
)
3954 type
= TYPE_MAIN_VARIANT (type
);
3956 /* ??? There really should be only one main variant among any group of
3957 variants of a given type (and all of the MAIN_VARIANT values for all
3958 members of the group should point to that one type) but sometimes the C
3959 front-end messes this up for array types, so we work around that bug
3961 if (TREE_CODE (type
) == ARRAY_TYPE
)
3962 while (type
!= TYPE_MAIN_VARIANT (type
))
3963 type
= TYPE_MAIN_VARIANT (type
);
3968 /* Return nonzero if the given type node represents a tagged type. */
3971 is_tagged_type (const_tree type
)
3973 enum tree_code code
= TREE_CODE (type
);
3975 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3976 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3979 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3982 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3984 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3987 /* Return die_offset of a DIE reference to a base type. */
3989 static unsigned long int
3990 get_base_type_offset (dw_die_ref ref
)
3992 if (ref
->die_offset
)
3993 return ref
->die_offset
;
3994 if (comp_unit_die ()->die_abbrev
)
3996 calc_base_type_die_sizes ();
3997 gcc_assert (ref
->die_offset
);
3999 return ref
->die_offset
;
4002 /* Return die_offset of a DIE reference other than base type. */
4004 static unsigned long int
4005 get_ref_die_offset (dw_die_ref ref
)
4007 gcc_assert (ref
->die_offset
);
4008 return ref
->die_offset
;
4011 /* Convert a DIE tag into its string name. */
4014 dwarf_tag_name (unsigned int tag
)
4016 const char *name
= get_DW_TAG_name (tag
);
4021 return "DW_TAG_<unknown>";
4024 /* Convert a DWARF attribute code into its string name. */
4027 dwarf_attr_name (unsigned int attr
)
4033 #if VMS_DEBUGGING_INFO
4034 case DW_AT_HP_prologue
:
4035 return "DW_AT_HP_prologue";
4037 case DW_AT_MIPS_loop_unroll_factor
:
4038 return "DW_AT_MIPS_loop_unroll_factor";
4041 #if VMS_DEBUGGING_INFO
4042 case DW_AT_HP_epilogue
:
4043 return "DW_AT_HP_epilogue";
4045 case DW_AT_MIPS_stride
:
4046 return "DW_AT_MIPS_stride";
4050 name
= get_DW_AT_name (attr
);
4055 return "DW_AT_<unknown>";
4058 /* Convert a DWARF value form code into its string name. */
4061 dwarf_form_name (unsigned int form
)
4063 const char *name
= get_DW_FORM_name (form
);
4068 return "DW_FORM_<unknown>";
4071 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4072 instance of an inlined instance of a decl which is local to an inline
4073 function, so we have to trace all of the way back through the origin chain
4074 to find out what sort of node actually served as the original seed for the
4078 decl_ultimate_origin (const_tree decl
)
4080 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
4083 /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
4084 we're trying to output the abstract instance of this function. */
4085 if (DECL_ABSTRACT_P (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4088 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4089 most distant ancestor, this should never happen. */
4090 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
4092 return DECL_ABSTRACT_ORIGIN (decl
);
4095 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4096 of a virtual function may refer to a base class, so we check the 'this'
4100 decl_class_context (tree decl
)
4102 tree context
= NULL_TREE
;
4104 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4105 context
= DECL_CONTEXT (decl
);
4107 context
= TYPE_MAIN_VARIANT
4108 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4110 if (context
&& !TYPE_P (context
))
4111 context
= NULL_TREE
;
4116 /* Add an attribute/value pair to a DIE. */
4119 add_dwarf_attr (dw_die_ref die
, dw_attr_node
*attr
)
4121 /* Maybe this should be an assert? */
4125 vec_safe_reserve (die
->die_attr
, 1);
4126 vec_safe_push (die
->die_attr
, *attr
);
4129 static inline enum dw_val_class
4130 AT_class (dw_attr_node
*a
)
4132 return a
->dw_attr_val
.val_class
;
4135 /* Return the index for any attribute that will be referenced with a
4136 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
4137 are stored in dw_attr_val.v.val_str for reference counting
4140 static inline unsigned int
4141 AT_index (dw_attr_node
*a
)
4143 if (AT_class (a
) == dw_val_class_str
)
4144 return a
->dw_attr_val
.v
.val_str
->index
;
4145 else if (a
->dw_attr_val
.val_entry
!= NULL
)
4146 return a
->dw_attr_val
.val_entry
->index
;
4150 /* Add a flag value attribute to a DIE. */
4153 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
4157 attr
.dw_attr
= attr_kind
;
4158 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
4159 attr
.dw_attr_val
.val_entry
= NULL
;
4160 attr
.dw_attr_val
.v
.val_flag
= flag
;
4161 add_dwarf_attr (die
, &attr
);
4164 static inline unsigned
4165 AT_flag (dw_attr_node
*a
)
4167 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
4168 return a
->dw_attr_val
.v
.val_flag
;
4171 /* Add a signed integer attribute value to a DIE. */
4174 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
4178 attr
.dw_attr
= attr_kind
;
4179 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
4180 attr
.dw_attr_val
.val_entry
= NULL
;
4181 attr
.dw_attr_val
.v
.val_int
= int_val
;
4182 add_dwarf_attr (die
, &attr
);
4185 static inline HOST_WIDE_INT
4186 AT_int (dw_attr_node
*a
)
4188 gcc_assert (a
&& (AT_class (a
) == dw_val_class_const
4189 || AT_class (a
) == dw_val_class_const_implicit
));
4190 return a
->dw_attr_val
.v
.val_int
;
4193 /* Add an unsigned integer attribute value to a DIE. */
4196 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4197 unsigned HOST_WIDE_INT unsigned_val
)
4201 attr
.dw_attr
= attr_kind
;
4202 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4203 attr
.dw_attr_val
.val_entry
= NULL
;
4204 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4205 add_dwarf_attr (die
, &attr
);
4208 static inline unsigned HOST_WIDE_INT
4209 AT_unsigned (dw_attr_node
*a
)
4211 gcc_assert (a
&& (AT_class (a
) == dw_val_class_unsigned_const
4212 || AT_class (a
) == dw_val_class_unsigned_const_implicit
));
4213 return a
->dw_attr_val
.v
.val_unsigned
;
4216 /* Add an unsigned wide integer attribute value to a DIE. */
4219 add_AT_wide (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4224 attr
.dw_attr
= attr_kind
;
4225 attr
.dw_attr_val
.val_class
= dw_val_class_wide_int
;
4226 attr
.dw_attr_val
.val_entry
= NULL
;
4227 attr
.dw_attr_val
.v
.val_wide
= ggc_alloc
<wide_int
> ();
4228 *attr
.dw_attr_val
.v
.val_wide
= w
;
4229 add_dwarf_attr (die
, &attr
);
4232 /* Add an unsigned double integer attribute value to a DIE. */
4235 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4236 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
4240 attr
.dw_attr
= attr_kind
;
4241 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
4242 attr
.dw_attr_val
.val_entry
= NULL
;
4243 attr
.dw_attr_val
.v
.val_double
.high
= high
;
4244 attr
.dw_attr_val
.v
.val_double
.low
= low
;
4245 add_dwarf_attr (die
, &attr
);
4248 /* Add a floating point attribute value to a DIE and return it. */
4251 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4252 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
4256 attr
.dw_attr
= attr_kind
;
4257 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
4258 attr
.dw_attr_val
.val_entry
= NULL
;
4259 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
4260 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
4261 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
4262 add_dwarf_attr (die
, &attr
);
4265 /* Add an 8-byte data attribute value to a DIE. */
4268 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4269 unsigned char data8
[8])
4273 attr
.dw_attr
= attr_kind
;
4274 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
4275 attr
.dw_attr_val
.val_entry
= NULL
;
4276 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
4277 add_dwarf_attr (die
, &attr
);
4280 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
4281 dwarf_split_debug_info, address attributes in dies destined for the
4282 final executable have force_direct set to avoid using indexed
4286 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
4292 lbl_id
= xstrdup (lbl_low
);
4293 attr
.dw_attr
= DW_AT_low_pc
;
4294 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4295 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4296 if (dwarf_split_debug_info
&& !force_direct
)
4297 attr
.dw_attr_val
.val_entry
4298 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4300 attr
.dw_attr_val
.val_entry
= NULL
;
4301 add_dwarf_attr (die
, &attr
);
4303 attr
.dw_attr
= DW_AT_high_pc
;
4304 if (dwarf_version
< 4)
4305 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4307 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
4308 lbl_id
= xstrdup (lbl_high
);
4309 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4310 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
4311 && dwarf_split_debug_info
&& !force_direct
)
4312 attr
.dw_attr_val
.val_entry
4313 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4315 attr
.dw_attr_val
.val_entry
= NULL
;
4316 add_dwarf_attr (die
, &attr
);
4319 /* Hash and equality functions for debug_str_hash. */
4322 indirect_string_hasher::hash (indirect_string_node
*x
)
4324 return htab_hash_string (x
->str
);
4328 indirect_string_hasher::equal (indirect_string_node
*x1
, const char *x2
)
4330 return strcmp (x1
->str
, x2
) == 0;
4333 /* Add STR to the given string hash table. */
4335 static struct indirect_string_node
*
4336 find_AT_string_in_table (const char *str
,
4337 hash_table
<indirect_string_hasher
> *table
)
4339 struct indirect_string_node
*node
;
4341 indirect_string_node
**slot
4342 = table
->find_slot_with_hash (str
, htab_hash_string (str
), INSERT
);
4345 node
= ggc_cleared_alloc
<indirect_string_node
> ();
4346 node
->str
= ggc_strdup (str
);
4356 /* Add STR to the indirect string hash table. */
4358 static struct indirect_string_node
*
4359 find_AT_string (const char *str
)
4361 if (! debug_str_hash
)
4362 debug_str_hash
= hash_table
<indirect_string_hasher
>::create_ggc (10);
4364 return find_AT_string_in_table (str
, debug_str_hash
);
4367 /* Add a string attribute value to a DIE. */
4370 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4373 struct indirect_string_node
*node
;
4375 node
= find_AT_string (str
);
4377 attr
.dw_attr
= attr_kind
;
4378 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4379 attr
.dw_attr_val
.val_entry
= NULL
;
4380 attr
.dw_attr_val
.v
.val_str
= node
;
4381 add_dwarf_attr (die
, &attr
);
4384 static inline const char *
4385 AT_string (dw_attr_node
*a
)
4387 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4388 return a
->dw_attr_val
.v
.val_str
->str
;
4391 /* Call this function directly to bypass AT_string_form's logic to put
4392 the string inline in the die. */
4395 set_indirect_string (struct indirect_string_node
*node
)
4397 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4398 /* Already indirect is a no op. */
4399 if (node
->form
== DW_FORM_strp
4400 || node
->form
== DW_FORM_line_strp
4401 || node
->form
== DW_FORM_GNU_str_index
)
4403 gcc_assert (node
->label
);
4406 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4407 ++dw2_string_counter
;
4408 node
->label
= xstrdup (label
);
4410 if (!dwarf_split_debug_info
)
4412 node
->form
= DW_FORM_strp
;
4413 node
->index
= NOT_INDEXED
;
4417 node
->form
= DW_FORM_GNU_str_index
;
4418 node
->index
= NO_INDEX_ASSIGNED
;
4422 /* A helper function for dwarf2out_finish, called to reset indirect
4423 string decisions done for early LTO dwarf output before fat object
4427 reset_indirect_string (indirect_string_node
**h
, void *)
4429 struct indirect_string_node
*node
= *h
;
4430 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
4434 node
->form
= (dwarf_form
) 0;
4440 /* Find out whether a string should be output inline in DIE
4441 or out-of-line in .debug_str section. */
4443 static enum dwarf_form
4444 find_string_form (struct indirect_string_node
*node
)
4451 len
= strlen (node
->str
) + 1;
4453 /* If the string is shorter or equal to the size of the reference, it is
4454 always better to put it inline. */
4455 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4456 return node
->form
= DW_FORM_string
;
4458 /* If we cannot expect the linker to merge strings in .debug_str
4459 section, only put it into .debug_str if it is worth even in this
4461 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4462 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4463 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
4464 return node
->form
= DW_FORM_string
;
4466 set_indirect_string (node
);
4471 /* Find out whether the string referenced from the attribute should be
4472 output inline in DIE or out-of-line in .debug_str section. */
4474 static enum dwarf_form
4475 AT_string_form (dw_attr_node
*a
)
4477 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4478 return find_string_form (a
->dw_attr_val
.v
.val_str
);
4481 /* Add a DIE reference attribute value to a DIE. */
4484 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4487 gcc_checking_assert (targ_die
!= NULL
);
4489 /* With LTO we can end up trying to reference something we didn't create
4490 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4491 if (targ_die
== NULL
)
4494 attr
.dw_attr
= attr_kind
;
4495 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4496 attr
.dw_attr_val
.val_entry
= NULL
;
4497 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4498 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4499 add_dwarf_attr (die
, &attr
);
4502 /* Change DIE reference REF to point to NEW_DIE instead. */
4505 change_AT_die_ref (dw_attr_node
*ref
, dw_die_ref new_die
)
4507 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4508 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4509 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4512 /* Add an AT_specification attribute to a DIE, and also make the back
4513 pointer from the specification to the definition. */
4516 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4518 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4519 gcc_assert (!targ_die
->die_definition
);
4520 targ_die
->die_definition
= die
;
4523 static inline dw_die_ref
4524 AT_ref (dw_attr_node
*a
)
4526 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4527 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4531 AT_ref_external (dw_attr_node
*a
)
4533 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4534 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4540 set_AT_ref_external (dw_attr_node
*a
, int i
)
4542 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4543 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4546 /* Add an FDE reference attribute value to a DIE. */
4549 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4553 attr
.dw_attr
= attr_kind
;
4554 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4555 attr
.dw_attr_val
.val_entry
= NULL
;
4556 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4557 add_dwarf_attr (die
, &attr
);
4560 /* Add a location description attribute value to a DIE. */
4563 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4567 attr
.dw_attr
= attr_kind
;
4568 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4569 attr
.dw_attr_val
.val_entry
= NULL
;
4570 attr
.dw_attr_val
.v
.val_loc
= loc
;
4571 add_dwarf_attr (die
, &attr
);
4574 static inline dw_loc_descr_ref
4575 AT_loc (dw_attr_node
*a
)
4577 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4578 return a
->dw_attr_val
.v
.val_loc
;
4582 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4586 if (XCOFF_DEBUGGING_INFO
&& !HAVE_XCOFF_DWARF_EXTRAS
)
4589 attr
.dw_attr
= attr_kind
;
4590 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4591 attr
.dw_attr_val
.val_entry
= NULL
;
4592 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4593 add_dwarf_attr (die
, &attr
);
4594 have_location_lists
= true;
4597 static inline dw_loc_list_ref
4598 AT_loc_list (dw_attr_node
*a
)
4600 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4601 return a
->dw_attr_val
.v
.val_loc_list
;
4604 static inline dw_loc_list_ref
*
4605 AT_loc_list_ptr (dw_attr_node
*a
)
4607 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4608 return &a
->dw_attr_val
.v
.val_loc_list
;
4611 struct addr_hasher
: ggc_ptr_hash
<addr_table_entry
>
4613 static hashval_t
hash (addr_table_entry
*);
4614 static bool equal (addr_table_entry
*, addr_table_entry
*);
4617 /* Table of entries into the .debug_addr section. */
4619 static GTY (()) hash_table
<addr_hasher
> *addr_index_table
;
4621 /* Hash an address_table_entry. */
4624 addr_hasher::hash (addr_table_entry
*a
)
4626 inchash::hash hstate
;
4632 case ate_kind_rtx_dtprel
:
4635 case ate_kind_label
:
4636 return htab_hash_string (a
->addr
.label
);
4640 inchash::add_rtx (a
->addr
.rtl
, hstate
);
4641 return hstate
.end ();
4644 /* Determine equality for two address_table_entries. */
4647 addr_hasher::equal (addr_table_entry
*a1
, addr_table_entry
*a2
)
4649 if (a1
->kind
!= a2
->kind
)
4654 case ate_kind_rtx_dtprel
:
4655 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4656 case ate_kind_label
:
4657 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4663 /* Initialize an addr_table_entry. */
4666 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4672 case ate_kind_rtx_dtprel
:
4673 e
->addr
.rtl
= (rtx
) addr
;
4675 case ate_kind_label
:
4676 e
->addr
.label
= (char *) addr
;
4680 e
->index
= NO_INDEX_ASSIGNED
;
4683 /* Add attr to the address table entry to the table. Defer setting an
4684 index until output time. */
4686 static addr_table_entry
*
4687 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4689 addr_table_entry
*node
;
4690 addr_table_entry finder
;
4692 gcc_assert (dwarf_split_debug_info
);
4693 if (! addr_index_table
)
4694 addr_index_table
= hash_table
<addr_hasher
>::create_ggc (10);
4695 init_addr_table_entry (&finder
, kind
, addr
);
4696 addr_table_entry
**slot
= addr_index_table
->find_slot (&finder
, INSERT
);
4698 if (*slot
== HTAB_EMPTY_ENTRY
)
4700 node
= ggc_cleared_alloc
<addr_table_entry
> ();
4701 init_addr_table_entry (node
, kind
, addr
);
4711 /* Remove an entry from the addr table by decrementing its refcount.
4712 Strictly, decrementing the refcount would be enough, but the
4713 assertion that the entry is actually in the table has found
4717 remove_addr_table_entry (addr_table_entry
*entry
)
4719 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4720 /* After an index is assigned, the table is frozen. */
4721 gcc_assert (entry
->refcount
> 0 && entry
->index
== NO_INDEX_ASSIGNED
);
4725 /* Given a location list, remove all addresses it refers to from the
4729 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4731 for (; descr
; descr
= descr
->dw_loc_next
)
4732 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4734 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4735 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4739 /* A helper function for dwarf2out_finish called through
4740 htab_traverse. Assign an addr_table_entry its index. All entries
4741 must be collected into the table when this function is called,
4742 because the indexing code relies on htab_traverse to traverse nodes
4743 in the same order for each run. */
4746 index_addr_table_entry (addr_table_entry
**h
, unsigned int *index
)
4748 addr_table_entry
*node
= *h
;
4750 /* Don't index unreferenced nodes. */
4751 if (node
->refcount
== 0)
4754 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
4755 node
->index
= *index
;
4761 /* Add an address constant attribute value to a DIE. When using
4762 dwarf_split_debug_info, address attributes in dies destined for the
4763 final executable should be direct references--setting the parameter
4764 force_direct ensures this behavior. */
4767 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4772 attr
.dw_attr
= attr_kind
;
4773 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4774 attr
.dw_attr_val
.v
.val_addr
= addr
;
4775 if (dwarf_split_debug_info
&& !force_direct
)
4776 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4778 attr
.dw_attr_val
.val_entry
= NULL
;
4779 add_dwarf_attr (die
, &attr
);
4782 /* Get the RTX from to an address DIE attribute. */
4785 AT_addr (dw_attr_node
*a
)
4787 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4788 return a
->dw_attr_val
.v
.val_addr
;
4791 /* Add a file attribute value to a DIE. */
4794 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4795 struct dwarf_file_data
*fd
)
4799 attr
.dw_attr
= attr_kind
;
4800 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4801 attr
.dw_attr_val
.val_entry
= NULL
;
4802 attr
.dw_attr_val
.v
.val_file
= fd
;
4803 add_dwarf_attr (die
, &attr
);
4806 /* Get the dwarf_file_data from a file DIE attribute. */
4808 static inline struct dwarf_file_data
*
4809 AT_file (dw_attr_node
*a
)
4811 gcc_assert (a
&& (AT_class (a
) == dw_val_class_file
4812 || AT_class (a
) == dw_val_class_file_implicit
));
4813 return a
->dw_attr_val
.v
.val_file
;
4816 /* Add a vms delta attribute value to a DIE. */
4819 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4820 const char *lbl1
, const char *lbl2
)
4824 attr
.dw_attr
= attr_kind
;
4825 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4826 attr
.dw_attr_val
.val_entry
= NULL
;
4827 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4828 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4829 add_dwarf_attr (die
, &attr
);
4832 /* Add a label identifier attribute value to a DIE. */
4835 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4840 attr
.dw_attr
= attr_kind
;
4841 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4842 attr
.dw_attr_val
.val_entry
= NULL
;
4843 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4844 if (dwarf_split_debug_info
)
4845 attr
.dw_attr_val
.val_entry
4846 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4848 add_dwarf_attr (die
, &attr
);
4851 /* Add a section offset attribute value to a DIE, an offset into the
4852 debug_line section. */
4855 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4860 attr
.dw_attr
= attr_kind
;
4861 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4862 attr
.dw_attr_val
.val_entry
= NULL
;
4863 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4864 add_dwarf_attr (die
, &attr
);
4867 /* Add a section offset attribute value to a DIE, an offset into the
4868 debug_loclists section. */
4871 add_AT_loclistsptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4876 attr
.dw_attr
= attr_kind
;
4877 attr
.dw_attr_val
.val_class
= dw_val_class_loclistsptr
;
4878 attr
.dw_attr_val
.val_entry
= NULL
;
4879 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4880 add_dwarf_attr (die
, &attr
);
4883 /* Add a section offset attribute value to a DIE, an offset into the
4884 debug_macinfo section. */
4887 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4892 attr
.dw_attr
= attr_kind
;
4893 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4894 attr
.dw_attr_val
.val_entry
= NULL
;
4895 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4896 add_dwarf_attr (die
, &attr
);
4899 /* Add an offset attribute value to a DIE. */
4902 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4903 unsigned HOST_WIDE_INT offset
)
4907 attr
.dw_attr
= attr_kind
;
4908 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4909 attr
.dw_attr_val
.val_entry
= NULL
;
4910 attr
.dw_attr_val
.v
.val_offset
= offset
;
4911 add_dwarf_attr (die
, &attr
);
4914 /* Add a range_list attribute value to a DIE. When using
4915 dwarf_split_debug_info, address attributes in dies destined for the
4916 final executable should be direct references--setting the parameter
4917 force_direct ensures this behavior. */
4919 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4920 #define RELOCATED_OFFSET (NULL)
4923 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4924 long unsigned int offset
, bool force_direct
)
4928 attr
.dw_attr
= attr_kind
;
4929 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4930 /* For the range_list attribute, use val_entry to store whether the
4931 offset should follow split-debug-info or normal semantics. This
4932 value is read in output_range_list_offset. */
4933 if (dwarf_split_debug_info
&& !force_direct
)
4934 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4936 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4937 attr
.dw_attr_val
.v
.val_offset
= offset
;
4938 add_dwarf_attr (die
, &attr
);
4941 /* Return the start label of a delta attribute. */
4943 static inline const char *
4944 AT_vms_delta1 (dw_attr_node
*a
)
4946 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4947 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4950 /* Return the end label of a delta attribute. */
4952 static inline const char *
4953 AT_vms_delta2 (dw_attr_node
*a
)
4955 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4956 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4959 static inline const char *
4960 AT_lbl (dw_attr_node
*a
)
4962 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4963 || AT_class (a
) == dw_val_class_lineptr
4964 || AT_class (a
) == dw_val_class_macptr
4965 || AT_class (a
) == dw_val_class_loclistsptr
4966 || AT_class (a
) == dw_val_class_high_pc
));
4967 return a
->dw_attr_val
.v
.val_lbl_id
;
4970 /* Get the attribute of type attr_kind. */
4972 static dw_attr_node
*
4973 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4977 dw_die_ref spec
= NULL
;
4982 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4983 if (a
->dw_attr
== attr_kind
)
4985 else if (a
->dw_attr
== DW_AT_specification
4986 || a
->dw_attr
== DW_AT_abstract_origin
)
4990 return get_AT (spec
, attr_kind
);
4995 /* Returns the parent of the declaration of DIE. */
4998 get_die_parent (dw_die_ref die
)
5005 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
5006 || (t
= get_AT_ref (die
, DW_AT_specification
)))
5009 return die
->die_parent
;
5012 /* Return the "low pc" attribute value, typically associated with a subprogram
5013 DIE. Return null if the "low pc" attribute is either not present, or if it
5014 cannot be represented as an assembler label identifier. */
5016 static inline const char *
5017 get_AT_low_pc (dw_die_ref die
)
5019 dw_attr_node
*a
= get_AT (die
, DW_AT_low_pc
);
5021 return a
? AT_lbl (a
) : NULL
;
5024 /* Return the "high pc" attribute value, typically associated with a subprogram
5025 DIE. Return null if the "high pc" attribute is either not present, or if it
5026 cannot be represented as an assembler label identifier. */
5028 static inline const char *
5029 get_AT_hi_pc (dw_die_ref die
)
5031 dw_attr_node
*a
= get_AT (die
, DW_AT_high_pc
);
5033 return a
? AT_lbl (a
) : NULL
;
5036 /* Return the value of the string attribute designated by ATTR_KIND, or
5037 NULL if it is not present. */
5039 static inline const char *
5040 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5042 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5044 return a
? AT_string (a
) : NULL
;
5047 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5048 if it is not present. */
5051 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5053 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5055 return a
? AT_flag (a
) : 0;
5058 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5059 if it is not present. */
5061 static inline unsigned
5062 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5064 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5066 return a
? AT_unsigned (a
) : 0;
5069 static inline dw_die_ref
5070 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5072 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5074 return a
? AT_ref (a
) : NULL
;
5077 static inline struct dwarf_file_data
*
5078 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5080 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5082 return a
? AT_file (a
) : NULL
;
5085 /* Returns the ultimate TRANSLATION_UNIT_DECL context of DECL or NULL. */
5088 get_ultimate_context (const_tree decl
)
5090 while (decl
&& TREE_CODE (decl
) != TRANSLATION_UNIT_DECL
)
5092 if (TREE_CODE (decl
) == BLOCK
)
5093 decl
= BLOCK_SUPERCONTEXT (decl
);
5095 decl
= get_containing_scope (decl
);
5100 /* Return TRUE if the language is C++. */
5105 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5107 return (lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
5108 || lang
== DW_LANG_C_plus_plus_11
|| lang
== DW_LANG_C_plus_plus_14
);
5111 /* Return TRUE if DECL was created by the C++ frontend. */
5114 is_cxx (const_tree decl
)
5118 const_tree context
= get_ultimate_context (decl
);
5119 if (context
&& TRANSLATION_UNIT_LANGUAGE (context
))
5120 return strncmp (TRANSLATION_UNIT_LANGUAGE (context
), "GNU C++", 7) == 0;
5125 /* Return TRUE if the language is Fortran. */
5130 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5132 return (lang
== DW_LANG_Fortran77
5133 || lang
== DW_LANG_Fortran90
5134 || lang
== DW_LANG_Fortran95
5135 || lang
== DW_LANG_Fortran03
5136 || lang
== DW_LANG_Fortran08
);
5140 is_fortran (const_tree decl
)
5144 const_tree context
= get_ultimate_context (decl
);
5145 if (context
&& TRANSLATION_UNIT_LANGUAGE (context
))
5146 return (strncmp (TRANSLATION_UNIT_LANGUAGE (context
),
5147 "GNU Fortran", 11) == 0
5148 || strcmp (TRANSLATION_UNIT_LANGUAGE (context
),
5151 return is_fortran ();
5154 /* Return TRUE if the language is Ada. */
5159 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5161 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
5164 /* Remove the specified attribute if present. Return TRUE if removal
5168 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5176 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5177 if (a
->dw_attr
== attr_kind
)
5179 if (AT_class (a
) == dw_val_class_str
)
5180 if (a
->dw_attr_val
.v
.val_str
->refcount
)
5181 a
->dw_attr_val
.v
.val_str
->refcount
--;
5183 /* vec::ordered_remove should help reduce the number of abbrevs
5185 die
->die_attr
->ordered_remove (ix
);
5191 /* Remove CHILD from its parent. PREV must have the property that
5192 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
5195 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
5197 gcc_assert (child
->die_parent
== prev
->die_parent
);
5198 gcc_assert (prev
->die_sib
== child
);
5201 gcc_assert (child
->die_parent
->die_child
== child
);
5205 prev
->die_sib
= child
->die_sib
;
5206 if (child
->die_parent
->die_child
== child
)
5207 child
->die_parent
->die_child
= prev
;
5208 child
->die_sib
= NULL
;
5211 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
5212 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
5215 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
5217 dw_die_ref parent
= old_child
->die_parent
;
5219 gcc_assert (parent
== prev
->die_parent
);
5220 gcc_assert (prev
->die_sib
== old_child
);
5222 new_child
->die_parent
= parent
;
5223 if (prev
== old_child
)
5225 gcc_assert (parent
->die_child
== old_child
);
5226 new_child
->die_sib
= new_child
;
5230 prev
->die_sib
= new_child
;
5231 new_child
->die_sib
= old_child
->die_sib
;
5233 if (old_child
->die_parent
->die_child
== old_child
)
5234 old_child
->die_parent
->die_child
= new_child
;
5235 old_child
->die_sib
= NULL
;
5238 /* Move all children from OLD_PARENT to NEW_PARENT. */
5241 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
5244 new_parent
->die_child
= old_parent
->die_child
;
5245 old_parent
->die_child
= NULL
;
5246 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
5249 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
5253 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
5259 dw_die_ref prev
= c
;
5261 while (c
->die_tag
== tag
)
5263 remove_child_with_prev (c
, prev
);
5264 c
->die_parent
= NULL
;
5265 /* Might have removed every child. */
5266 if (die
->die_child
== NULL
)
5270 } while (c
!= die
->die_child
);
5273 /* Add a CHILD_DIE as the last child of DIE. */
5276 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
5278 /* FIXME this should probably be an assert. */
5279 if (! die
|| ! child_die
)
5281 gcc_assert (die
!= child_die
);
5283 child_die
->die_parent
= die
;
5286 child_die
->die_sib
= die
->die_child
->die_sib
;
5287 die
->die_child
->die_sib
= child_die
;
5290 child_die
->die_sib
= child_die
;
5291 die
->die_child
= child_die
;
5294 /* Like add_child_die, but put CHILD_DIE after AFTER_DIE. */
5297 add_child_die_after (dw_die_ref die
, dw_die_ref child_die
,
5298 dw_die_ref after_die
)
5304 && die
!= child_die
);
5306 child_die
->die_parent
= die
;
5307 child_die
->die_sib
= after_die
->die_sib
;
5308 after_die
->die_sib
= child_die
;
5309 if (die
->die_child
== after_die
)
5310 die
->die_child
= child_die
;
5313 /* Unassociate CHILD from its parent, and make its parent be
5317 reparent_child (dw_die_ref child
, dw_die_ref new_parent
)
5319 for (dw_die_ref p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
5320 if (p
->die_sib
== child
)
5322 remove_child_with_prev (child
, p
);
5325 add_child_die (new_parent
, child
);
5328 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5329 is the specification, to the end of PARENT's list of children.
5330 This is done by removing and re-adding it. */
5333 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
5335 /* We want the declaration DIE from inside the class, not the
5336 specification DIE at toplevel. */
5337 if (child
->die_parent
!= parent
)
5339 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5345 gcc_assert (child
->die_parent
== parent
5346 || (child
->die_parent
5347 == get_AT_ref (parent
, DW_AT_specification
)));
5349 reparent_child (child
, parent
);
5352 /* Create and return a new die with a parent of PARENT_DIE. If
5353 PARENT_DIE is NULL, the new DIE is placed in limbo and an
5354 associated tree T must be supplied to determine parenthood
5357 static inline dw_die_ref
5358 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
5360 dw_die_ref die
= ggc_cleared_alloc
<die_node
> ();
5362 die
->die_tag
= tag_value
;
5364 if (parent_die
!= NULL
)
5365 add_child_die (parent_die
, die
);
5368 limbo_die_node
*limbo_node
;
5370 /* No DIEs created after early dwarf should end up in limbo,
5371 because the limbo list should not persist past LTO
5373 if (tag_value
!= DW_TAG_compile_unit
5374 /* These are allowed because they're generated while
5375 breaking out COMDAT units late. */
5376 && tag_value
!= DW_TAG_type_unit
5377 && tag_value
!= DW_TAG_skeleton_unit
5379 /* Allow nested functions to live in limbo because they will
5380 only temporarily live there, as decls_for_scope will fix
5382 && (TREE_CODE (t
) != FUNCTION_DECL
5383 || !decl_function_context (t
))
5384 /* Same as nested functions above but for types. Types that
5385 are local to a function will be fixed in
5387 && (!RECORD_OR_UNION_TYPE_P (t
)
5388 || !TYPE_CONTEXT (t
)
5389 || TREE_CODE (TYPE_CONTEXT (t
)) != FUNCTION_DECL
)
5390 /* FIXME debug-early: Allow late limbo DIE creation for LTO,
5391 especially in the ltrans stage, but once we implement LTO
5392 dwarf streaming, we should remove this exception. */
5395 fprintf (stderr
, "symbol ended up in limbo too late:");
5396 debug_generic_stmt (t
);
5400 limbo_node
= ggc_cleared_alloc
<limbo_die_node
> ();
5401 limbo_node
->die
= die
;
5402 limbo_node
->created_for
= t
;
5403 limbo_node
->next
= limbo_die_list
;
5404 limbo_die_list
= limbo_node
;
5410 /* Return the DIE associated with the given type specifier. */
5412 static inline dw_die_ref
5413 lookup_type_die (tree type
)
5415 dw_die_ref die
= TYPE_SYMTAB_DIE (type
);
5416 if (die
&& die
->removed
)
5418 TYPE_SYMTAB_DIE (type
) = NULL
;
5424 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
5425 anonymous type named by the typedef TYPE_DIE, return the DIE of the
5426 anonymous type instead the one of the naming typedef. */
5428 static inline dw_die_ref
5429 strip_naming_typedef (tree type
, dw_die_ref type_die
)
5432 && TREE_CODE (type
) == RECORD_TYPE
5434 && type_die
->die_tag
== DW_TAG_typedef
5435 && is_naming_typedef_decl (TYPE_NAME (type
)))
5436 type_die
= get_AT_ref (type_die
, DW_AT_type
);
5440 /* Like lookup_type_die, but if type is an anonymous type named by a
5441 typedef[1], return the DIE of the anonymous type instead the one of
5442 the naming typedef. This is because in gen_typedef_die, we did
5443 equate the anonymous struct named by the typedef with the DIE of
5444 the naming typedef. So by default, lookup_type_die on an anonymous
5445 struct yields the DIE of the naming typedef.
5447 [1]: Read the comment of is_naming_typedef_decl to learn about what
5448 a naming typedef is. */
5450 static inline dw_die_ref
5451 lookup_type_die_strip_naming_typedef (tree type
)
5453 dw_die_ref die
= lookup_type_die (type
);
5454 return strip_naming_typedef (type
, die
);
5457 /* Equate a DIE to a given type specifier. */
5460 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5462 TYPE_SYMTAB_DIE (type
) = type_die
;
5465 /* Returns a hash value for X (which really is a die_struct). */
5468 decl_die_hasher::hash (die_node
*x
)
5470 return (hashval_t
) x
->decl_id
;
5473 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5476 decl_die_hasher::equal (die_node
*x
, tree y
)
5478 return (x
->decl_id
== DECL_UID (y
));
5481 /* Return the DIE associated with a given declaration. */
5483 static inline dw_die_ref
5484 lookup_decl_die (tree decl
)
5486 dw_die_ref
*die
= decl_die_table
->find_slot_with_hash (decl
, DECL_UID (decl
),
5490 if ((*die
)->removed
)
5492 decl_die_table
->clear_slot (die
);
5499 /* For DECL which might have early dwarf output query a SYMBOL + OFFSET
5500 style reference. Return true if we found one refering to a DIE for
5501 DECL, otherwise return false. */
5504 dwarf2out_die_ref_for_decl (tree decl
, const char **sym
,
5505 unsigned HOST_WIDE_INT
*off
)
5509 if (flag_wpa
&& !decl_die_table
)
5512 if (TREE_CODE (decl
) == BLOCK
)
5513 die
= BLOCK_DIE (decl
);
5515 die
= lookup_decl_die (decl
);
5519 /* During WPA stage we currently use DIEs to store the
5520 decl <-> label + offset map. That's quite inefficient but it
5524 dw_die_ref ref
= get_AT_ref (die
, DW_AT_abstract_origin
);
5527 gcc_assert (die
== comp_unit_die ());
5530 *off
= ref
->die_offset
;
5531 *sym
= ref
->die_id
.die_symbol
;
5535 /* Similar to get_ref_die_offset_label, but using the "correct"
5537 *off
= die
->die_offset
;
5538 while (die
->die_parent
)
5539 die
= die
->die_parent
;
5540 /* For the containing CU DIE we compute a die_symbol in
5541 compute_comp_unit_symbol. */
5542 gcc_assert (die
->die_tag
== DW_TAG_compile_unit
5543 && die
->die_id
.die_symbol
!= NULL
);
5544 *sym
= die
->die_id
.die_symbol
;
5548 /* Add a reference of kind ATTR_KIND to a DIE at SYMBOL + OFFSET to DIE. */
5551 add_AT_external_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5552 const char *symbol
, HOST_WIDE_INT offset
)
5554 /* Create a fake DIE that contains the reference. Don't use
5555 new_die because we don't want to end up in the limbo list. */
5556 dw_die_ref ref
= ggc_cleared_alloc
<die_node
> ();
5557 ref
->die_tag
= die
->die_tag
;
5558 ref
->die_id
.die_symbol
= IDENTIFIER_POINTER (get_identifier (symbol
));
5559 ref
->die_offset
= offset
;
5560 ref
->with_offset
= 1;
5561 add_AT_die_ref (die
, attr_kind
, ref
);
5564 /* Create a DIE for DECL if required and add a reference to a DIE
5565 at SYMBOL + OFFSET which contains attributes dumped early. */
5568 dwarf2out_register_external_die (tree decl
, const char *sym
,
5569 unsigned HOST_WIDE_INT off
)
5571 if (debug_info_level
== DINFO_LEVEL_NONE
)
5574 if (flag_wpa
&& !decl_die_table
)
5575 decl_die_table
= hash_table
<decl_die_hasher
>::create_ggc (1000);
5578 = TREE_CODE (decl
) == BLOCK
? BLOCK_DIE (decl
) : lookup_decl_die (decl
);
5582 dw_die_ref parent
= NULL
;
5583 /* Need to lookup a DIE for the decls context - the containing
5584 function or translation unit. */
5585 if (TREE_CODE (decl
) == BLOCK
)
5587 ctx
= BLOCK_SUPERCONTEXT (decl
);
5588 /* ??? We do not output DIEs for all scopes thus skip as
5589 many DIEs as needed. */
5590 while (TREE_CODE (ctx
) == BLOCK
5591 && !BLOCK_DIE (ctx
))
5592 ctx
= BLOCK_SUPERCONTEXT (ctx
);
5595 ctx
= DECL_CONTEXT (decl
);
5596 while (ctx
&& TYPE_P (ctx
))
5597 ctx
= TYPE_CONTEXT (ctx
);
5600 if (TREE_CODE (ctx
) == BLOCK
)
5601 parent
= BLOCK_DIE (ctx
);
5602 else if (TREE_CODE (ctx
) == TRANSLATION_UNIT_DECL
5603 /* Keep the 1:1 association during WPA. */
5605 /* Otherwise all late annotations go to the main CU which
5606 imports the original CUs. */
5607 parent
= comp_unit_die ();
5608 else if (TREE_CODE (ctx
) == FUNCTION_DECL
5609 && TREE_CODE (decl
) != PARM_DECL
5610 && TREE_CODE (decl
) != BLOCK
)
5611 /* Leave function local entities parent determination to when
5612 we process scope vars. */
5615 parent
= lookup_decl_die (ctx
);
5618 /* In some cases the FEs fail to set DECL_CONTEXT properly.
5619 Handle this case gracefully by globalizing stuff. */
5620 parent
= comp_unit_die ();
5621 /* Create a DIE "stub". */
5622 switch (TREE_CODE (decl
))
5624 case TRANSLATION_UNIT_DECL
:
5627 die
= comp_unit_die ();
5628 dw_die_ref import
= new_die (DW_TAG_imported_unit
, die
, NULL_TREE
);
5629 add_AT_external_die_ref (import
, DW_AT_import
, sym
, off
);
5630 /* We re-target all CU decls to the LTRANS CU DIE, so no need
5631 to create a DIE for the original CUs. */
5634 /* Keep the 1:1 association during WPA. */
5635 die
= new_die (DW_TAG_compile_unit
, NULL
, decl
);
5637 case NAMESPACE_DECL
:
5638 if (is_fortran (decl
))
5639 die
= new_die (DW_TAG_module
, parent
, decl
);
5641 die
= new_die (DW_TAG_namespace
, parent
, decl
);
5644 die
= new_die (DW_TAG_subprogram
, parent
, decl
);
5647 die
= new_die (DW_TAG_variable
, parent
, decl
);
5650 die
= new_die (DW_TAG_variable
, parent
, decl
);
5653 die
= new_die (DW_TAG_formal_parameter
, parent
, decl
);
5656 die
= new_die (DW_TAG_constant
, parent
, decl
);
5659 die
= new_die (DW_TAG_label
, parent
, decl
);
5662 die
= new_die (DW_TAG_lexical_block
, parent
, decl
);
5667 if (TREE_CODE (decl
) == BLOCK
)
5668 BLOCK_DIE (decl
) = die
;
5670 equate_decl_number_to_die (decl
, die
);
5672 /* Add a reference to the DIE providing early debug at $sym + off. */
5673 add_AT_external_die_ref (die
, DW_AT_abstract_origin
, sym
, off
);
5676 /* Returns a hash value for X (which really is a var_loc_list). */
5679 decl_loc_hasher::hash (var_loc_list
*x
)
5681 return (hashval_t
) x
->decl_id
;
5684 /* Return nonzero if decl_id of var_loc_list X is the same as
5688 decl_loc_hasher::equal (var_loc_list
*x
, const_tree y
)
5690 return (x
->decl_id
== DECL_UID (y
));
5693 /* Return the var_loc list associated with a given declaration. */
5695 static inline var_loc_list
*
5696 lookup_decl_loc (const_tree decl
)
5698 if (!decl_loc_table
)
5700 return decl_loc_table
->find_with_hash (decl
, DECL_UID (decl
));
5703 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5706 dw_loc_list_hasher::hash (cached_dw_loc_list
*x
)
5708 return (hashval_t
) x
->decl_id
;
5711 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5715 dw_loc_list_hasher::equal (cached_dw_loc_list
*x
, const_tree y
)
5717 return (x
->decl_id
== DECL_UID (y
));
5720 /* Equate a DIE to a particular declaration. */
5723 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5725 unsigned int decl_id
= DECL_UID (decl
);
5727 *decl_die_table
->find_slot_with_hash (decl
, decl_id
, INSERT
) = decl_die
;
5728 decl_die
->decl_id
= decl_id
;
5731 /* Return how many bits covers PIECE EXPR_LIST. */
5733 static HOST_WIDE_INT
5734 decl_piece_bitsize (rtx piece
)
5736 int ret
= (int) GET_MODE (piece
);
5739 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
5740 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
5741 return INTVAL (XEXP (XEXP (piece
, 0), 0));
5744 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5747 decl_piece_varloc_ptr (rtx piece
)
5749 if ((int) GET_MODE (piece
))
5750 return &XEXP (piece
, 0);
5752 return &XEXP (XEXP (piece
, 0), 1);
5755 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5756 Next is the chain of following piece nodes. */
5758 static rtx_expr_list
*
5759 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
5761 if (bitsize
> 0 && bitsize
<= (int) MAX_MACHINE_MODE
)
5762 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
5764 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
5769 /* Return rtx that should be stored into loc field for
5770 LOC_NOTE and BITPOS/BITSIZE. */
5773 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
5774 HOST_WIDE_INT bitsize
)
5778 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
5780 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
5785 /* This function either modifies location piece list *DEST in
5786 place (if SRC and INNER is NULL), or copies location piece list
5787 *SRC to *DEST while modifying it. Location BITPOS is modified
5788 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5789 not copied and if needed some padding around it is added.
5790 When modifying in place, DEST should point to EXPR_LIST where
5791 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5792 to the start of the whole list and INNER points to the EXPR_LIST
5793 where earlier pieces cover PIECE_BITPOS bits. */
5796 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
5797 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
5798 HOST_WIDE_INT bitsize
, rtx loc_note
)
5801 bool copy
= inner
!= NULL
;
5805 /* First copy all nodes preceding the current bitpos. */
5806 while (src
!= inner
)
5808 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5809 decl_piece_bitsize (*src
), NULL_RTX
);
5810 dest
= &XEXP (*dest
, 1);
5811 src
= &XEXP (*src
, 1);
5814 /* Add padding if needed. */
5815 if (bitpos
!= piece_bitpos
)
5817 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5818 copy
? NULL_RTX
: *dest
);
5819 dest
= &XEXP (*dest
, 1);
5821 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5824 /* A piece with correct bitpos and bitsize already exist,
5825 just update the location for it and return. */
5826 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5829 /* Add the piece that changed. */
5830 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5831 dest
= &XEXP (*dest
, 1);
5832 /* Skip over pieces that overlap it. */
5833 diff
= bitpos
- piece_bitpos
+ bitsize
;
5836 while (diff
> 0 && *src
)
5839 diff
-= decl_piece_bitsize (piece
);
5841 src
= &XEXP (piece
, 1);
5844 *src
= XEXP (piece
, 1);
5845 free_EXPR_LIST_node (piece
);
5848 /* Add padding if needed. */
5849 if (diff
< 0 && *src
)
5853 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5854 dest
= &XEXP (*dest
, 1);
5858 /* Finally copy all nodes following it. */
5861 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5862 decl_piece_bitsize (*src
), NULL_RTX
);
5863 dest
= &XEXP (*dest
, 1);
5864 src
= &XEXP (*src
, 1);
5868 /* Add a variable location node to the linked list for DECL. */
5870 static struct var_loc_node
*
5871 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5873 unsigned int decl_id
;
5875 struct var_loc_node
*loc
= NULL
;
5876 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5878 if (VAR_P (decl
) && DECL_HAS_DEBUG_EXPR_P (decl
))
5880 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5881 if (handled_component_p (realdecl
)
5882 || (TREE_CODE (realdecl
) == MEM_REF
5883 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5885 HOST_WIDE_INT maxsize
;
5888 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
,
5890 if (!DECL_P (innerdecl
)
5891 || DECL_IGNORED_P (innerdecl
)
5892 || TREE_STATIC (innerdecl
)
5894 || bitpos
+ bitsize
> 256
5895 || bitsize
!= maxsize
)
5901 decl_id
= DECL_UID (decl
);
5903 = decl_loc_table
->find_slot_with_hash (decl
, decl_id
, INSERT
);
5906 temp
= ggc_cleared_alloc
<var_loc_list
> ();
5907 temp
->decl_id
= decl_id
;
5913 /* For PARM_DECLs try to keep around the original incoming value,
5914 even if that means we'll emit a zero-range .debug_loc entry. */
5916 && temp
->first
== temp
->last
5917 && TREE_CODE (decl
) == PARM_DECL
5918 && NOTE_P (temp
->first
->loc
)
5919 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5920 && DECL_INCOMING_RTL (decl
)
5921 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5922 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5923 == GET_CODE (DECL_INCOMING_RTL (decl
))
5924 && prev_real_insn (as_a
<rtx_insn
*> (temp
->first
->loc
)) == NULL_RTX
5926 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5927 NOTE_VAR_LOCATION_LOC (loc_note
))
5928 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5929 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5931 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5932 temp
->first
->next
= loc
;
5934 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5936 else if (temp
->last
)
5938 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5939 rtx
*piece_loc
= NULL
, last_loc_note
;
5940 HOST_WIDE_INT piece_bitpos
= 0;
5944 gcc_assert (last
->next
== NULL
);
5946 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5948 piece_loc
= &last
->loc
;
5951 HOST_WIDE_INT cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5952 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5954 piece_bitpos
+= cur_bitsize
;
5955 piece_loc
= &XEXP (*piece_loc
, 1);
5959 /* TEMP->LAST here is either pointer to the last but one or
5960 last element in the chained list, LAST is pointer to the
5962 if (label
&& strcmp (last
->label
, label
) == 0)
5964 /* For SRA optimized variables if there weren't any real
5965 insns since last note, just modify the last node. */
5966 if (piece_loc
!= NULL
)
5968 adjust_piece_list (piece_loc
, NULL
, NULL
,
5969 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5972 /* If the last note doesn't cover any instructions, remove it. */
5973 if (temp
->last
!= last
)
5975 temp
->last
->next
= NULL
;
5978 gcc_assert (strcmp (last
->label
, label
) != 0);
5982 gcc_assert (temp
->first
== temp
->last
5983 || (temp
->first
->next
== temp
->last
5984 && TREE_CODE (decl
) == PARM_DECL
));
5985 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5986 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5990 if (bitsize
== -1 && NOTE_P (last
->loc
))
5991 last_loc_note
= last
->loc
;
5992 else if (piece_loc
!= NULL
5993 && *piece_loc
!= NULL_RTX
5994 && piece_bitpos
== bitpos
5995 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5996 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5998 last_loc_note
= NULL_RTX
;
5999 /* If the current location is the same as the end of the list,
6000 and either both or neither of the locations is uninitialized,
6001 we have nothing to do. */
6002 if (last_loc_note
== NULL_RTX
6003 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
6004 NOTE_VAR_LOCATION_LOC (loc_note
)))
6005 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
6006 != NOTE_VAR_LOCATION_STATUS (loc_note
))
6007 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
6008 == VAR_INIT_STATUS_UNINITIALIZED
)
6009 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
6010 == VAR_INIT_STATUS_UNINITIALIZED
))))
6012 /* Add LOC to the end of list and update LAST. If the last
6013 element of the list has been removed above, reuse its
6014 memory for the new node, otherwise allocate a new one. */
6018 memset (loc
, '\0', sizeof (*loc
));
6021 loc
= ggc_cleared_alloc
<var_loc_node
> ();
6022 if (bitsize
== -1 || piece_loc
== NULL
)
6023 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
6025 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
6026 bitpos
, piece_bitpos
, bitsize
, loc_note
);
6028 /* Ensure TEMP->LAST will point either to the new last but one
6029 element of the chain, or to the last element in it. */
6030 if (last
!= temp
->last
)
6038 loc
= ggc_cleared_alloc
<var_loc_node
> ();
6041 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
6046 /* Keep track of the number of spaces used to indent the
6047 output of the debugging routines that print the structure of
6048 the DIE internal representation. */
6049 static int print_indent
;
6051 /* Indent the line the number of spaces given by print_indent. */
6054 print_spaces (FILE *outfile
)
6056 fprintf (outfile
, "%*s", print_indent
, "");
6059 /* Print a type signature in hex. */
6062 print_signature (FILE *outfile
, char *sig
)
6066 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
6067 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
6071 print_discr_value (FILE *outfile
, dw_discr_value
*discr_value
)
6073 if (discr_value
->pos
)
6074 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, discr_value
->v
.sval
);
6076 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, discr_value
->v
.uval
);
6079 static void print_loc_descr (dw_loc_descr_ref
, FILE *);
6081 /* Print the value associated to the VAL DWARF value node to OUTFILE. If
6082 RECURSE, output location descriptor operations. */
6085 print_dw_val (dw_val_node
*val
, bool recurse
, FILE *outfile
)
6087 switch (val
->val_class
)
6089 case dw_val_class_addr
:
6090 fprintf (outfile
, "address");
6092 case dw_val_class_offset
:
6093 fprintf (outfile
, "offset");
6095 case dw_val_class_loc
:
6096 fprintf (outfile
, "location descriptor");
6097 if (val
->v
.val_loc
== NULL
)
6098 fprintf (outfile
, " -> <null>\n");
6101 fprintf (outfile
, ":\n");
6103 print_loc_descr (val
->v
.val_loc
, outfile
);
6107 fprintf (outfile
, " (%p)\n", (void *) val
->v
.val_loc
);
6109 case dw_val_class_loc_list
:
6110 fprintf (outfile
, "location list -> label:%s",
6111 val
->v
.val_loc_list
->ll_symbol
);
6113 case dw_val_class_range_list
:
6114 fprintf (outfile
, "range list");
6116 case dw_val_class_const
:
6117 case dw_val_class_const_implicit
:
6118 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, val
->v
.val_int
);
6120 case dw_val_class_unsigned_const
:
6121 case dw_val_class_unsigned_const_implicit
:
6122 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, val
->v
.val_unsigned
);
6124 case dw_val_class_const_double
:
6125 fprintf (outfile
, "constant (" HOST_WIDE_INT_PRINT_DEC
","\
6126 HOST_WIDE_INT_PRINT_UNSIGNED
")",
6127 val
->v
.val_double
.high
,
6128 val
->v
.val_double
.low
);
6130 case dw_val_class_wide_int
:
6132 int i
= val
->v
.val_wide
->get_len ();
6133 fprintf (outfile
, "constant (");
6135 if (val
->v
.val_wide
->elt (i
- 1) == 0)
6136 fprintf (outfile
, "0x");
6137 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
,
6138 val
->v
.val_wide
->elt (--i
));
6140 fprintf (outfile
, HOST_WIDE_INT_PRINT_PADDED_HEX
,
6141 val
->v
.val_wide
->elt (i
));
6142 fprintf (outfile
, ")");
6145 case dw_val_class_vec
:
6146 fprintf (outfile
, "floating-point or vector constant");
6148 case dw_val_class_flag
:
6149 fprintf (outfile
, "%u", val
->v
.val_flag
);
6151 case dw_val_class_die_ref
:
6152 if (val
->v
.val_die_ref
.die
!= NULL
)
6154 dw_die_ref die
= val
->v
.val_die_ref
.die
;
6156 if (die
->comdat_type_p
)
6158 fprintf (outfile
, "die -> signature: ");
6159 print_signature (outfile
,
6160 die
->die_id
.die_type_node
->signature
);
6162 else if (die
->die_id
.die_symbol
)
6164 fprintf (outfile
, "die -> label: %s", die
->die_id
.die_symbol
);
6165 if (die
->with_offset
)
6166 fprintf (outfile
, " + %ld", die
->die_offset
);
6169 fprintf (outfile
, "die -> %ld", die
->die_offset
);
6170 fprintf (outfile
, " (%p)", (void *) die
);
6173 fprintf (outfile
, "die -> <null>");
6175 case dw_val_class_vms_delta
:
6176 fprintf (outfile
, "delta: @slotcount(%s-%s)",
6177 val
->v
.val_vms_delta
.lbl2
, val
->v
.val_vms_delta
.lbl1
);
6179 case dw_val_class_lbl_id
:
6180 case dw_val_class_lineptr
:
6181 case dw_val_class_macptr
:
6182 case dw_val_class_loclistsptr
:
6183 case dw_val_class_high_pc
:
6184 fprintf (outfile
, "label: %s", val
->v
.val_lbl_id
);
6186 case dw_val_class_str
:
6187 if (val
->v
.val_str
->str
!= NULL
)
6188 fprintf (outfile
, "\"%s\"", val
->v
.val_str
->str
);
6190 fprintf (outfile
, "<null>");
6192 case dw_val_class_file
:
6193 case dw_val_class_file_implicit
:
6194 fprintf (outfile
, "\"%s\" (%d)", val
->v
.val_file
->filename
,
6195 val
->v
.val_file
->emitted_number
);
6197 case dw_val_class_data8
:
6201 for (i
= 0; i
< 8; i
++)
6202 fprintf (outfile
, "%02x", val
->v
.val_data8
[i
]);
6205 case dw_val_class_discr_value
:
6206 print_discr_value (outfile
, &val
->v
.val_discr_value
);
6208 case dw_val_class_discr_list
:
6209 for (dw_discr_list_ref node
= val
->v
.val_discr_list
;
6211 node
= node
->dw_discr_next
)
6213 if (node
->dw_discr_range
)
6215 fprintf (outfile
, " .. ");
6216 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
6217 print_discr_value (outfile
, &node
->dw_discr_upper_bound
);
6220 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
6222 if (node
->dw_discr_next
!= NULL
)
6223 fprintf (outfile
, " | ");
6230 /* Likewise, for a DIE attribute. */
6233 print_attribute (dw_attr_node
*a
, bool recurse
, FILE *outfile
)
6235 print_dw_val (&a
->dw_attr_val
, recurse
, outfile
);
6239 /* Print the list of operands in the LOC location description to OUTFILE. This
6240 routine is a debugging aid only. */
6243 print_loc_descr (dw_loc_descr_ref loc
, FILE *outfile
)
6245 dw_loc_descr_ref l
= loc
;
6249 print_spaces (outfile
);
6250 fprintf (outfile
, "<null>\n");
6254 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
6256 print_spaces (outfile
);
6257 fprintf (outfile
, "(%p) %s",
6259 dwarf_stack_op_name (l
->dw_loc_opc
));
6260 if (l
->dw_loc_oprnd1
.val_class
!= dw_val_class_none
)
6262 fprintf (outfile
, " ");
6263 print_dw_val (&l
->dw_loc_oprnd1
, false, outfile
);
6265 if (l
->dw_loc_oprnd2
.val_class
!= dw_val_class_none
)
6267 fprintf (outfile
, ", ");
6268 print_dw_val (&l
->dw_loc_oprnd2
, false, outfile
);
6270 fprintf (outfile
, "\n");
6274 /* Print the information associated with a given DIE, and its children.
6275 This routine is a debugging aid only. */
6278 print_die (dw_die_ref die
, FILE *outfile
)
6284 print_spaces (outfile
);
6285 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
6286 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
6288 print_spaces (outfile
);
6289 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
6290 fprintf (outfile
, " offset: %ld", die
->die_offset
);
6291 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
6293 if (die
->comdat_type_p
)
6295 print_spaces (outfile
);
6296 fprintf (outfile
, " signature: ");
6297 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
6298 fprintf (outfile
, "\n");
6301 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6303 print_spaces (outfile
);
6304 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
6306 print_attribute (a
, true, outfile
);
6307 fprintf (outfile
, "\n");
6310 if (die
->die_child
!= NULL
)
6313 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
6316 if (print_indent
== 0)
6317 fprintf (outfile
, "\n");
6320 /* Print the list of operations in the LOC location description. */
6323 debug_dwarf_loc_descr (dw_loc_descr_ref loc
)
6325 print_loc_descr (loc
, stderr
);
6328 /* Print the information collected for a given DIE. */
6331 debug_dwarf_die (dw_die_ref die
)
6333 print_die (die
, stderr
);
6337 debug (die_struct
&ref
)
6339 print_die (&ref
, stderr
);
6343 debug (die_struct
*ptr
)
6348 fprintf (stderr
, "<nil>\n");
6352 /* Print all DWARF information collected for the compilation unit.
6353 This routine is a debugging aid only. */
6359 print_die (comp_unit_die (), stderr
);
6362 /* Verify the DIE tree structure. */
6365 verify_die (dw_die_ref die
)
6367 gcc_assert (!die
->die_mark
);
6368 if (die
->die_parent
== NULL
6369 && die
->die_sib
== NULL
)
6371 /* Verify the die_sib list is cyclic. */
6378 while (x
&& !x
->die_mark
);
6379 gcc_assert (x
== die
);
6383 /* Verify all dies have the same parent. */
6384 gcc_assert (x
->die_parent
== die
->die_parent
);
6387 /* Verify the child has the proper parent and recurse. */
6388 gcc_assert (x
->die_child
->die_parent
== x
);
6389 verify_die (x
->die_child
);
6394 while (x
&& x
->die_mark
);
6397 /* Sanity checks on DIEs. */
6400 check_die (dw_die_ref die
)
6404 bool inline_found
= false;
6405 int n_location
= 0, n_low_pc
= 0, n_high_pc
= 0, n_artificial
= 0;
6406 int n_decl_line
= 0, n_decl_column
= 0, n_decl_file
= 0;
6407 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6412 if (a
->dw_attr_val
.v
.val_unsigned
)
6413 inline_found
= true;
6415 case DW_AT_location
:
6424 case DW_AT_artificial
:
6427 case DW_AT_decl_column
:
6430 case DW_AT_decl_line
:
6433 case DW_AT_decl_file
:
6440 if (n_location
> 1 || n_low_pc
> 1 || n_high_pc
> 1 || n_artificial
> 1
6441 || n_decl_column
> 1 || n_decl_line
> 1 || n_decl_file
> 1)
6443 fprintf (stderr
, "Duplicate attributes in DIE:\n");
6444 debug_dwarf_die (die
);
6449 /* A debugging information entry that is a member of an abstract
6450 instance tree [that has DW_AT_inline] should not contain any
6451 attributes which describe aspects of the subroutine which vary
6452 between distinct inlined expansions or distinct out-of-line
6454 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6455 gcc_assert (a
->dw_attr
!= DW_AT_low_pc
6456 && a
->dw_attr
!= DW_AT_high_pc
6457 && a
->dw_attr
!= DW_AT_location
6458 && a
->dw_attr
!= DW_AT_frame_base
6459 && a
->dw_attr
!= DW_AT_call_all_calls
6460 && a
->dw_attr
!= DW_AT_GNU_all_call_sites
);
6464 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6465 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
6466 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
6468 /* Calculate the checksum of a location expression. */
6471 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
6474 inchash::hash hstate
;
6477 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
6479 hash_loc_operands (loc
, hstate
);
6480 hash
= hstate
.end();
6484 /* Calculate the checksum of an attribute. */
6487 attr_checksum (dw_attr_node
*at
, struct md5_ctx
*ctx
, int *mark
)
6489 dw_loc_descr_ref loc
;
6492 CHECKSUM (at
->dw_attr
);
6494 /* We don't care that this was compiled with a different compiler
6495 snapshot; if the output is the same, that's what matters. */
6496 if (at
->dw_attr
== DW_AT_producer
)
6499 switch (AT_class (at
))
6501 case dw_val_class_const
:
6502 case dw_val_class_const_implicit
:
6503 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
6505 case dw_val_class_unsigned_const
:
6506 case dw_val_class_unsigned_const_implicit
:
6507 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
6509 case dw_val_class_const_double
:
6510 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
6512 case dw_val_class_wide_int
:
6513 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
6514 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6515 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
6517 case dw_val_class_vec
:
6518 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
6519 (at
->dw_attr_val
.v
.val_vec
.length
6520 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
6522 case dw_val_class_flag
:
6523 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
6525 case dw_val_class_str
:
6526 CHECKSUM_STRING (AT_string (at
));
6529 case dw_val_class_addr
:
6531 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6532 CHECKSUM_STRING (XSTR (r
, 0));
6535 case dw_val_class_offset
:
6536 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
6539 case dw_val_class_loc
:
6540 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6541 loc_checksum (loc
, ctx
);
6544 case dw_val_class_die_ref
:
6545 die_checksum (AT_ref (at
), ctx
, mark
);
6548 case dw_val_class_fde_ref
:
6549 case dw_val_class_vms_delta
:
6550 case dw_val_class_lbl_id
:
6551 case dw_val_class_lineptr
:
6552 case dw_val_class_macptr
:
6553 case dw_val_class_loclistsptr
:
6554 case dw_val_class_high_pc
:
6557 case dw_val_class_file
:
6558 case dw_val_class_file_implicit
:
6559 CHECKSUM_STRING (AT_file (at
)->filename
);
6562 case dw_val_class_data8
:
6563 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6571 /* Calculate the checksum of a DIE. */
6574 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6580 /* To avoid infinite recursion. */
6583 CHECKSUM (die
->die_mark
);
6586 die
->die_mark
= ++(*mark
);
6588 CHECKSUM (die
->die_tag
);
6590 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6591 attr_checksum (a
, ctx
, mark
);
6593 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
6597 #undef CHECKSUM_BLOCK
6598 #undef CHECKSUM_STRING
6600 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
6601 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6602 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
6603 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
6604 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
6605 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
6606 #define CHECKSUM_ATTR(FOO) \
6607 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
6609 /* Calculate the checksum of a number in signed LEB128 format. */
6612 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
6619 byte
= (value
& 0x7f);
6621 more
= !((value
== 0 && (byte
& 0x40) == 0)
6622 || (value
== -1 && (byte
& 0x40) != 0));
6631 /* Calculate the checksum of a number in unsigned LEB128 format. */
6634 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
6638 unsigned char byte
= (value
& 0x7f);
6641 /* More bytes to follow. */
6649 /* Checksum the context of the DIE. This adds the names of any
6650 surrounding namespaces or structures to the checksum. */
6653 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
6657 int tag
= die
->die_tag
;
6659 if (tag
!= DW_TAG_namespace
6660 && tag
!= DW_TAG_structure_type
6661 && tag
!= DW_TAG_class_type
)
6664 name
= get_AT_string (die
, DW_AT_name
);
6666 spec
= get_AT_ref (die
, DW_AT_specification
);
6670 if (die
->die_parent
!= NULL
)
6671 checksum_die_context (die
->die_parent
, ctx
);
6673 CHECKSUM_ULEB128 ('C');
6674 CHECKSUM_ULEB128 (tag
);
6676 CHECKSUM_STRING (name
);
6679 /* Calculate the checksum of a location expression. */
6682 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
6684 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
6685 were emitted as a DW_FORM_sdata instead of a location expression. */
6686 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
6688 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6689 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
6693 /* Otherwise, just checksum the raw location expression. */
6696 inchash::hash hstate
;
6699 CHECKSUM_ULEB128 (loc
->dtprel
);
6700 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
6701 hash_loc_operands (loc
, hstate
);
6702 hash
= hstate
.end ();
6704 loc
= loc
->dw_loc_next
;
6708 /* Calculate the checksum of an attribute. */
6711 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_node
*at
,
6712 struct md5_ctx
*ctx
, int *mark
)
6714 dw_loc_descr_ref loc
;
6717 if (AT_class (at
) == dw_val_class_die_ref
)
6719 dw_die_ref target_die
= AT_ref (at
);
6721 /* For pointer and reference types, we checksum only the (qualified)
6722 name of the target type (if there is a name). For friend entries,
6723 we checksum only the (qualified) name of the target type or function.
6724 This allows the checksum to remain the same whether the target type
6725 is complete or not. */
6726 if ((at
->dw_attr
== DW_AT_type
6727 && (tag
== DW_TAG_pointer_type
6728 || tag
== DW_TAG_reference_type
6729 || tag
== DW_TAG_rvalue_reference_type
6730 || tag
== DW_TAG_ptr_to_member_type
))
6731 || (at
->dw_attr
== DW_AT_friend
6732 && tag
== DW_TAG_friend
))
6734 dw_attr_node
*name_attr
= get_AT (target_die
, DW_AT_name
);
6736 if (name_attr
!= NULL
)
6738 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6742 CHECKSUM_ULEB128 ('N');
6743 CHECKSUM_ULEB128 (at
->dw_attr
);
6744 if (decl
->die_parent
!= NULL
)
6745 checksum_die_context (decl
->die_parent
, ctx
);
6746 CHECKSUM_ULEB128 ('E');
6747 CHECKSUM_STRING (AT_string (name_attr
));
6752 /* For all other references to another DIE, we check to see if the
6753 target DIE has already been visited. If it has, we emit a
6754 backward reference; if not, we descend recursively. */
6755 if (target_die
->die_mark
> 0)
6757 CHECKSUM_ULEB128 ('R');
6758 CHECKSUM_ULEB128 (at
->dw_attr
);
6759 CHECKSUM_ULEB128 (target_die
->die_mark
);
6763 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6767 target_die
->die_mark
= ++(*mark
);
6768 CHECKSUM_ULEB128 ('T');
6769 CHECKSUM_ULEB128 (at
->dw_attr
);
6770 if (decl
->die_parent
!= NULL
)
6771 checksum_die_context (decl
->die_parent
, ctx
);
6772 die_checksum_ordered (target_die
, ctx
, mark
);
6777 CHECKSUM_ULEB128 ('A');
6778 CHECKSUM_ULEB128 (at
->dw_attr
);
6780 switch (AT_class (at
))
6782 case dw_val_class_const
:
6783 case dw_val_class_const_implicit
:
6784 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6785 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
6788 case dw_val_class_unsigned_const
:
6789 case dw_val_class_unsigned_const_implicit
:
6790 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6791 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
6794 case dw_val_class_const_double
:
6795 CHECKSUM_ULEB128 (DW_FORM_block
);
6796 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
6797 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
6800 case dw_val_class_wide_int
:
6801 CHECKSUM_ULEB128 (DW_FORM_block
);
6802 CHECKSUM_ULEB128 (get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6803 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
6804 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
6805 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6806 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
6809 case dw_val_class_vec
:
6810 CHECKSUM_ULEB128 (DW_FORM_block
);
6811 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
6812 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
6813 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
6814 (at
->dw_attr_val
.v
.val_vec
.length
6815 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
6818 case dw_val_class_flag
:
6819 CHECKSUM_ULEB128 (DW_FORM_flag
);
6820 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
6823 case dw_val_class_str
:
6824 CHECKSUM_ULEB128 (DW_FORM_string
);
6825 CHECKSUM_STRING (AT_string (at
));
6828 case dw_val_class_addr
:
6830 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6831 CHECKSUM_ULEB128 (DW_FORM_string
);
6832 CHECKSUM_STRING (XSTR (r
, 0));
6835 case dw_val_class_offset
:
6836 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6837 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
6840 case dw_val_class_loc
:
6841 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6842 loc_checksum_ordered (loc
, ctx
);
6845 case dw_val_class_fde_ref
:
6846 case dw_val_class_lbl_id
:
6847 case dw_val_class_lineptr
:
6848 case dw_val_class_macptr
:
6849 case dw_val_class_loclistsptr
:
6850 case dw_val_class_high_pc
:
6853 case dw_val_class_file
:
6854 case dw_val_class_file_implicit
:
6855 CHECKSUM_ULEB128 (DW_FORM_string
);
6856 CHECKSUM_STRING (AT_file (at
)->filename
);
6859 case dw_val_class_data8
:
6860 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6868 struct checksum_attributes
6870 dw_attr_node
*at_name
;
6871 dw_attr_node
*at_type
;
6872 dw_attr_node
*at_friend
;
6873 dw_attr_node
*at_accessibility
;
6874 dw_attr_node
*at_address_class
;
6875 dw_attr_node
*at_alignment
;
6876 dw_attr_node
*at_allocated
;
6877 dw_attr_node
*at_artificial
;
6878 dw_attr_node
*at_associated
;
6879 dw_attr_node
*at_binary_scale
;
6880 dw_attr_node
*at_bit_offset
;
6881 dw_attr_node
*at_bit_size
;
6882 dw_attr_node
*at_bit_stride
;
6883 dw_attr_node
*at_byte_size
;
6884 dw_attr_node
*at_byte_stride
;
6885 dw_attr_node
*at_const_value
;
6886 dw_attr_node
*at_containing_type
;
6887 dw_attr_node
*at_count
;
6888 dw_attr_node
*at_data_location
;
6889 dw_attr_node
*at_data_member_location
;
6890 dw_attr_node
*at_decimal_scale
;
6891 dw_attr_node
*at_decimal_sign
;
6892 dw_attr_node
*at_default_value
;
6893 dw_attr_node
*at_digit_count
;
6894 dw_attr_node
*at_discr
;
6895 dw_attr_node
*at_discr_list
;
6896 dw_attr_node
*at_discr_value
;
6897 dw_attr_node
*at_encoding
;
6898 dw_attr_node
*at_endianity
;
6899 dw_attr_node
*at_explicit
;
6900 dw_attr_node
*at_is_optional
;
6901 dw_attr_node
*at_location
;
6902 dw_attr_node
*at_lower_bound
;
6903 dw_attr_node
*at_mutable
;
6904 dw_attr_node
*at_ordering
;
6905 dw_attr_node
*at_picture_string
;
6906 dw_attr_node
*at_prototyped
;
6907 dw_attr_node
*at_small
;
6908 dw_attr_node
*at_segment
;
6909 dw_attr_node
*at_string_length
;
6910 dw_attr_node
*at_string_length_bit_size
;
6911 dw_attr_node
*at_string_length_byte_size
;
6912 dw_attr_node
*at_threads_scaled
;
6913 dw_attr_node
*at_upper_bound
;
6914 dw_attr_node
*at_use_location
;
6915 dw_attr_node
*at_use_UTF8
;
6916 dw_attr_node
*at_variable_parameter
;
6917 dw_attr_node
*at_virtuality
;
6918 dw_attr_node
*at_visibility
;
6919 dw_attr_node
*at_vtable_elem_location
;
6922 /* Collect the attributes that we will want to use for the checksum. */
6925 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
6930 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6941 attrs
->at_friend
= a
;
6943 case DW_AT_accessibility
:
6944 attrs
->at_accessibility
= a
;
6946 case DW_AT_address_class
:
6947 attrs
->at_address_class
= a
;
6949 case DW_AT_alignment
:
6950 attrs
->at_alignment
= a
;
6952 case DW_AT_allocated
:
6953 attrs
->at_allocated
= a
;
6955 case DW_AT_artificial
:
6956 attrs
->at_artificial
= a
;
6958 case DW_AT_associated
:
6959 attrs
->at_associated
= a
;
6961 case DW_AT_binary_scale
:
6962 attrs
->at_binary_scale
= a
;
6964 case DW_AT_bit_offset
:
6965 attrs
->at_bit_offset
= a
;
6967 case DW_AT_bit_size
:
6968 attrs
->at_bit_size
= a
;
6970 case DW_AT_bit_stride
:
6971 attrs
->at_bit_stride
= a
;
6973 case DW_AT_byte_size
:
6974 attrs
->at_byte_size
= a
;
6976 case DW_AT_byte_stride
:
6977 attrs
->at_byte_stride
= a
;
6979 case DW_AT_const_value
:
6980 attrs
->at_const_value
= a
;
6982 case DW_AT_containing_type
:
6983 attrs
->at_containing_type
= a
;
6986 attrs
->at_count
= a
;
6988 case DW_AT_data_location
:
6989 attrs
->at_data_location
= a
;
6991 case DW_AT_data_member_location
:
6992 attrs
->at_data_member_location
= a
;
6994 case DW_AT_decimal_scale
:
6995 attrs
->at_decimal_scale
= a
;
6997 case DW_AT_decimal_sign
:
6998 attrs
->at_decimal_sign
= a
;
7000 case DW_AT_default_value
:
7001 attrs
->at_default_value
= a
;
7003 case DW_AT_digit_count
:
7004 attrs
->at_digit_count
= a
;
7007 attrs
->at_discr
= a
;
7009 case DW_AT_discr_list
:
7010 attrs
->at_discr_list
= a
;
7012 case DW_AT_discr_value
:
7013 attrs
->at_discr_value
= a
;
7015 case DW_AT_encoding
:
7016 attrs
->at_encoding
= a
;
7018 case DW_AT_endianity
:
7019 attrs
->at_endianity
= a
;
7021 case DW_AT_explicit
:
7022 attrs
->at_explicit
= a
;
7024 case DW_AT_is_optional
:
7025 attrs
->at_is_optional
= a
;
7027 case DW_AT_location
:
7028 attrs
->at_location
= a
;
7030 case DW_AT_lower_bound
:
7031 attrs
->at_lower_bound
= a
;
7034 attrs
->at_mutable
= a
;
7036 case DW_AT_ordering
:
7037 attrs
->at_ordering
= a
;
7039 case DW_AT_picture_string
:
7040 attrs
->at_picture_string
= a
;
7042 case DW_AT_prototyped
:
7043 attrs
->at_prototyped
= a
;
7046 attrs
->at_small
= a
;
7049 attrs
->at_segment
= a
;
7051 case DW_AT_string_length
:
7052 attrs
->at_string_length
= a
;
7054 case DW_AT_string_length_bit_size
:
7055 attrs
->at_string_length_bit_size
= a
;
7057 case DW_AT_string_length_byte_size
:
7058 attrs
->at_string_length_byte_size
= a
;
7060 case DW_AT_threads_scaled
:
7061 attrs
->at_threads_scaled
= a
;
7063 case DW_AT_upper_bound
:
7064 attrs
->at_upper_bound
= a
;
7066 case DW_AT_use_location
:
7067 attrs
->at_use_location
= a
;
7069 case DW_AT_use_UTF8
:
7070 attrs
->at_use_UTF8
= a
;
7072 case DW_AT_variable_parameter
:
7073 attrs
->at_variable_parameter
= a
;
7075 case DW_AT_virtuality
:
7076 attrs
->at_virtuality
= a
;
7078 case DW_AT_visibility
:
7079 attrs
->at_visibility
= a
;
7081 case DW_AT_vtable_elem_location
:
7082 attrs
->at_vtable_elem_location
= a
;
7090 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
7093 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
7097 struct checksum_attributes attrs
;
7099 CHECKSUM_ULEB128 ('D');
7100 CHECKSUM_ULEB128 (die
->die_tag
);
7102 memset (&attrs
, 0, sizeof (attrs
));
7104 decl
= get_AT_ref (die
, DW_AT_specification
);
7106 collect_checksum_attributes (&attrs
, decl
);
7107 collect_checksum_attributes (&attrs
, die
);
7109 CHECKSUM_ATTR (attrs
.at_name
);
7110 CHECKSUM_ATTR (attrs
.at_accessibility
);
7111 CHECKSUM_ATTR (attrs
.at_address_class
);
7112 CHECKSUM_ATTR (attrs
.at_allocated
);
7113 CHECKSUM_ATTR (attrs
.at_artificial
);
7114 CHECKSUM_ATTR (attrs
.at_associated
);
7115 CHECKSUM_ATTR (attrs
.at_binary_scale
);
7116 CHECKSUM_ATTR (attrs
.at_bit_offset
);
7117 CHECKSUM_ATTR (attrs
.at_bit_size
);
7118 CHECKSUM_ATTR (attrs
.at_bit_stride
);
7119 CHECKSUM_ATTR (attrs
.at_byte_size
);
7120 CHECKSUM_ATTR (attrs
.at_byte_stride
);
7121 CHECKSUM_ATTR (attrs
.at_const_value
);
7122 CHECKSUM_ATTR (attrs
.at_containing_type
);
7123 CHECKSUM_ATTR (attrs
.at_count
);
7124 CHECKSUM_ATTR (attrs
.at_data_location
);
7125 CHECKSUM_ATTR (attrs
.at_data_member_location
);
7126 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
7127 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
7128 CHECKSUM_ATTR (attrs
.at_default_value
);
7129 CHECKSUM_ATTR (attrs
.at_digit_count
);
7130 CHECKSUM_ATTR (attrs
.at_discr
);
7131 CHECKSUM_ATTR (attrs
.at_discr_list
);
7132 CHECKSUM_ATTR (attrs
.at_discr_value
);
7133 CHECKSUM_ATTR (attrs
.at_encoding
);
7134 CHECKSUM_ATTR (attrs
.at_endianity
);
7135 CHECKSUM_ATTR (attrs
.at_explicit
);
7136 CHECKSUM_ATTR (attrs
.at_is_optional
);
7137 CHECKSUM_ATTR (attrs
.at_location
);
7138 CHECKSUM_ATTR (attrs
.at_lower_bound
);
7139 CHECKSUM_ATTR (attrs
.at_mutable
);
7140 CHECKSUM_ATTR (attrs
.at_ordering
);
7141 CHECKSUM_ATTR (attrs
.at_picture_string
);
7142 CHECKSUM_ATTR (attrs
.at_prototyped
);
7143 CHECKSUM_ATTR (attrs
.at_small
);
7144 CHECKSUM_ATTR (attrs
.at_segment
);
7145 CHECKSUM_ATTR (attrs
.at_string_length
);
7146 CHECKSUM_ATTR (attrs
.at_string_length_bit_size
);
7147 CHECKSUM_ATTR (attrs
.at_string_length_byte_size
);
7148 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
7149 CHECKSUM_ATTR (attrs
.at_upper_bound
);
7150 CHECKSUM_ATTR (attrs
.at_use_location
);
7151 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
7152 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
7153 CHECKSUM_ATTR (attrs
.at_virtuality
);
7154 CHECKSUM_ATTR (attrs
.at_visibility
);
7155 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
7156 CHECKSUM_ATTR (attrs
.at_type
);
7157 CHECKSUM_ATTR (attrs
.at_friend
);
7158 CHECKSUM_ATTR (attrs
.at_alignment
);
7160 /* Checksum the child DIEs. */
7163 dw_attr_node
*name_attr
;
7166 name_attr
= get_AT (c
, DW_AT_name
);
7167 if (is_template_instantiation (c
))
7169 /* Ignore instantiations of member type and function templates. */
7171 else if (name_attr
!= NULL
7172 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
7174 /* Use a shallow checksum for named nested types and member
7176 CHECKSUM_ULEB128 ('S');
7177 CHECKSUM_ULEB128 (c
->die_tag
);
7178 CHECKSUM_STRING (AT_string (name_attr
));
7182 /* Use a deep checksum for other children. */
7183 /* Mark this DIE so it gets processed when unmarking. */
7184 if (c
->die_mark
== 0)
7186 die_checksum_ordered (c
, ctx
, mark
);
7188 } while (c
!= die
->die_child
);
7190 CHECKSUM_ULEB128 (0);
7193 /* Add a type name and tag to a hash. */
7195 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
7197 CHECKSUM_ULEB128 (tag
);
7198 CHECKSUM_STRING (name
);
7202 #undef CHECKSUM_STRING
7203 #undef CHECKSUM_ATTR
7204 #undef CHECKSUM_LEB128
7205 #undef CHECKSUM_ULEB128
7207 /* Generate the type signature for DIE. This is computed by generating an
7208 MD5 checksum over the DIE's tag, its relevant attributes, and its
7209 children. Attributes that are references to other DIEs are processed
7210 by recursion, using the MARK field to prevent infinite recursion.
7211 If the DIE is nested inside a namespace or another type, we also
7212 need to include that context in the signature. The lower 64 bits
7213 of the resulting MD5 checksum comprise the signature. */
7216 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
7220 unsigned char checksum
[16];
7225 name
= get_AT_string (die
, DW_AT_name
);
7226 decl
= get_AT_ref (die
, DW_AT_specification
);
7227 parent
= get_die_parent (die
);
7229 /* First, compute a signature for just the type name (and its surrounding
7230 context, if any. This is stored in the type unit DIE for link-time
7231 ODR (one-definition rule) checking. */
7233 if (is_cxx () && name
!= NULL
)
7235 md5_init_ctx (&ctx
);
7237 /* Checksum the names of surrounding namespaces and structures. */
7239 checksum_die_context (parent
, &ctx
);
7241 /* Checksum the current DIE. */
7242 die_odr_checksum (die
->die_tag
, name
, &ctx
);
7243 md5_finish_ctx (&ctx
, checksum
);
7245 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
7248 /* Next, compute the complete type signature. */
7250 md5_init_ctx (&ctx
);
7252 die
->die_mark
= mark
;
7254 /* Checksum the names of surrounding namespaces and structures. */
7256 checksum_die_context (parent
, &ctx
);
7258 /* Checksum the DIE and its children. */
7259 die_checksum_ordered (die
, &ctx
, &mark
);
7260 unmark_all_dies (die
);
7261 md5_finish_ctx (&ctx
, checksum
);
7263 /* Store the signature in the type node and link the type DIE and the
7264 type node together. */
7265 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
7266 DWARF_TYPE_SIGNATURE_SIZE
);
7267 die
->comdat_type_p
= true;
7268 die
->die_id
.die_type_node
= type_node
;
7269 type_node
->type_die
= die
;
7271 /* If the DIE is a specification, link its declaration to the type node
7275 decl
->comdat_type_p
= true;
7276 decl
->die_id
.die_type_node
= type_node
;
7280 /* Do the location expressions look same? */
7282 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
7284 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
7285 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
7286 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
7289 /* Do the values look the same? */
7291 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
7293 dw_loc_descr_ref loc1
, loc2
;
7296 if (v1
->val_class
!= v2
->val_class
)
7299 switch (v1
->val_class
)
7301 case dw_val_class_const
:
7302 case dw_val_class_const_implicit
:
7303 return v1
->v
.val_int
== v2
->v
.val_int
;
7304 case dw_val_class_unsigned_const
:
7305 case dw_val_class_unsigned_const_implicit
:
7306 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
7307 case dw_val_class_const_double
:
7308 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
7309 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
7310 case dw_val_class_wide_int
:
7311 return *v1
->v
.val_wide
== *v2
->v
.val_wide
;
7312 case dw_val_class_vec
:
7313 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
7314 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
7316 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
7317 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
7320 case dw_val_class_flag
:
7321 return v1
->v
.val_flag
== v2
->v
.val_flag
;
7322 case dw_val_class_str
:
7323 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
7325 case dw_val_class_addr
:
7326 r1
= v1
->v
.val_addr
;
7327 r2
= v2
->v
.val_addr
;
7328 if (GET_CODE (r1
) != GET_CODE (r2
))
7330 return !rtx_equal_p (r1
, r2
);
7332 case dw_val_class_offset
:
7333 return v1
->v
.val_offset
== v2
->v
.val_offset
;
7335 case dw_val_class_loc
:
7336 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
7338 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
7339 if (!same_loc_p (loc1
, loc2
, mark
))
7341 return !loc1
&& !loc2
;
7343 case dw_val_class_die_ref
:
7344 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
7346 case dw_val_class_fde_ref
:
7347 case dw_val_class_vms_delta
:
7348 case dw_val_class_lbl_id
:
7349 case dw_val_class_lineptr
:
7350 case dw_val_class_macptr
:
7351 case dw_val_class_loclistsptr
:
7352 case dw_val_class_high_pc
:
7355 case dw_val_class_file
:
7356 case dw_val_class_file_implicit
:
7357 return v1
->v
.val_file
== v2
->v
.val_file
;
7359 case dw_val_class_data8
:
7360 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
7367 /* Do the attributes look the same? */
7370 same_attr_p (dw_attr_node
*at1
, dw_attr_node
*at2
, int *mark
)
7372 if (at1
->dw_attr
!= at2
->dw_attr
)
7375 /* We don't care that this was compiled with a different compiler
7376 snapshot; if the output is the same, that's what matters. */
7377 if (at1
->dw_attr
== DW_AT_producer
)
7380 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
7383 /* Do the dies look the same? */
7386 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
7392 /* To avoid infinite recursion. */
7394 return die1
->die_mark
== die2
->die_mark
;
7395 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
7397 if (die1
->die_tag
!= die2
->die_tag
)
7400 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
7403 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
7404 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
7407 c1
= die1
->die_child
;
7408 c2
= die2
->die_child
;
7417 if (!same_die_p (c1
, c2
, mark
))
7421 if (c1
== die1
->die_child
)
7423 if (c2
== die2
->die_child
)
7433 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
7434 children, and set die_symbol. */
7437 compute_comp_unit_symbol (dw_die_ref unit_die
)
7439 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
7440 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
7441 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
7444 unsigned char checksum
[16];
7447 /* Compute the checksum of the DIE, then append part of it as hex digits to
7448 the name filename of the unit. */
7450 md5_init_ctx (&ctx
);
7452 die_checksum (unit_die
, &ctx
, &mark
);
7453 unmark_all_dies (unit_die
);
7454 md5_finish_ctx (&ctx
, checksum
);
7456 /* When we this for comp_unit_die () we have a DW_AT_name that might
7457 not start with a letter but with anything valid for filenames and
7458 clean_symbol_name doesn't fix that up. Prepend 'g' if the first
7459 character is not a letter. */
7460 sprintf (name
, "%s%s.", ISALPHA (*base
) ? "" : "g", base
);
7461 clean_symbol_name (name
);
7463 p
= name
+ strlen (name
);
7464 for (i
= 0; i
< 4; i
++)
7466 sprintf (p
, "%.2x", checksum
[i
]);
7470 unit_die
->die_id
.die_symbol
= xstrdup (name
);
7473 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
7476 is_type_die (dw_die_ref die
)
7478 switch (die
->die_tag
)
7480 case DW_TAG_array_type
:
7481 case DW_TAG_class_type
:
7482 case DW_TAG_interface_type
:
7483 case DW_TAG_enumeration_type
:
7484 case DW_TAG_pointer_type
:
7485 case DW_TAG_reference_type
:
7486 case DW_TAG_rvalue_reference_type
:
7487 case DW_TAG_string_type
:
7488 case DW_TAG_structure_type
:
7489 case DW_TAG_subroutine_type
:
7490 case DW_TAG_union_type
:
7491 case DW_TAG_ptr_to_member_type
:
7492 case DW_TAG_set_type
:
7493 case DW_TAG_subrange_type
:
7494 case DW_TAG_base_type
:
7495 case DW_TAG_const_type
:
7496 case DW_TAG_file_type
:
7497 case DW_TAG_packed_type
:
7498 case DW_TAG_volatile_type
:
7499 case DW_TAG_typedef
:
7506 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
7507 Basically, we want to choose the bits that are likely to be shared between
7508 compilations (types) and leave out the bits that are specific to individual
7509 compilations (functions). */
7512 is_comdat_die (dw_die_ref c
)
7514 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
7515 we do for stabs. The advantage is a greater likelihood of sharing between
7516 objects that don't include headers in the same order (and therefore would
7517 put the base types in a different comdat). jason 8/28/00 */
7519 if (c
->die_tag
== DW_TAG_base_type
)
7522 if (c
->die_tag
== DW_TAG_pointer_type
7523 || c
->die_tag
== DW_TAG_reference_type
7524 || c
->die_tag
== DW_TAG_rvalue_reference_type
7525 || c
->die_tag
== DW_TAG_const_type
7526 || c
->die_tag
== DW_TAG_volatile_type
)
7528 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
7530 return t
? is_comdat_die (t
) : 0;
7533 return is_type_die (c
);
7536 /* Returns true iff C is a compile-unit DIE. */
7539 is_cu_die (dw_die_ref c
)
7541 return c
&& (c
->die_tag
== DW_TAG_compile_unit
7542 || c
->die_tag
== DW_TAG_skeleton_unit
);
7545 /* Returns true iff C is a unit DIE of some sort. */
7548 is_unit_die (dw_die_ref c
)
7550 return c
&& (c
->die_tag
== DW_TAG_compile_unit
7551 || c
->die_tag
== DW_TAG_partial_unit
7552 || c
->die_tag
== DW_TAG_type_unit
7553 || c
->die_tag
== DW_TAG_skeleton_unit
);
7556 /* Returns true iff C is a namespace DIE. */
7559 is_namespace_die (dw_die_ref c
)
7561 return c
&& c
->die_tag
== DW_TAG_namespace
;
7564 /* Returns true iff C is a class or structure DIE. */
7567 is_class_die (dw_die_ref c
)
7569 return c
&& (c
->die_tag
== DW_TAG_class_type
7570 || c
->die_tag
== DW_TAG_structure_type
);
7573 /* Return non-zero if this DIE is a template parameter. */
7576 is_template_parameter (dw_die_ref die
)
7578 switch (die
->die_tag
)
7580 case DW_TAG_template_type_param
:
7581 case DW_TAG_template_value_param
:
7582 case DW_TAG_GNU_template_template_param
:
7583 case DW_TAG_GNU_template_parameter_pack
:
7590 /* Return non-zero if this DIE represents a template instantiation. */
7593 is_template_instantiation (dw_die_ref die
)
7597 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
7599 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
7604 gen_internal_sym (const char *prefix
)
7606 char buf
[MAX_ARTIFICIAL_LABEL_BYTES
];
7608 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
7609 return xstrdup (buf
);
7612 /* Return non-zero if this DIE is a declaration. */
7615 is_declaration_die (dw_die_ref die
)
7620 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7621 if (a
->dw_attr
== DW_AT_declaration
)
7627 /* Return non-zero if this DIE is nested inside a subprogram. */
7630 is_nested_in_subprogram (dw_die_ref die
)
7632 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
7636 return local_scope_p (decl
);
7639 /* Return non-zero if this DIE contains a defining declaration of a
7643 contains_subprogram_definition (dw_die_ref die
)
7647 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
7649 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
7653 /* Return non-zero if this is a type DIE that should be moved to a
7654 COMDAT .debug_types section or .debug_info section with DW_UT_*type
7658 should_move_die_to_comdat (dw_die_ref die
)
7660 switch (die
->die_tag
)
7662 case DW_TAG_class_type
:
7663 case DW_TAG_structure_type
:
7664 case DW_TAG_enumeration_type
:
7665 case DW_TAG_union_type
:
7666 /* Don't move declarations, inlined instances, types nested in a
7667 subprogram, or types that contain subprogram definitions. */
7668 if (is_declaration_die (die
)
7669 || get_AT (die
, DW_AT_abstract_origin
)
7670 || is_nested_in_subprogram (die
)
7671 || contains_subprogram_definition (die
))
7674 case DW_TAG_array_type
:
7675 case DW_TAG_interface_type
:
7676 case DW_TAG_pointer_type
:
7677 case DW_TAG_reference_type
:
7678 case DW_TAG_rvalue_reference_type
:
7679 case DW_TAG_string_type
:
7680 case DW_TAG_subroutine_type
:
7681 case DW_TAG_ptr_to_member_type
:
7682 case DW_TAG_set_type
:
7683 case DW_TAG_subrange_type
:
7684 case DW_TAG_base_type
:
7685 case DW_TAG_const_type
:
7686 case DW_TAG_file_type
:
7687 case DW_TAG_packed_type
:
7688 case DW_TAG_volatile_type
:
7689 case DW_TAG_typedef
:
7695 /* Make a clone of DIE. */
7698 clone_die (dw_die_ref die
)
7704 clone
= ggc_cleared_alloc
<die_node
> ();
7705 clone
->die_tag
= die
->die_tag
;
7707 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7708 add_dwarf_attr (clone
, a
);
7713 /* Make a clone of the tree rooted at DIE. */
7716 clone_tree (dw_die_ref die
)
7719 dw_die_ref clone
= clone_die (die
);
7721 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
7726 /* Make a clone of DIE as a declaration. */
7729 clone_as_declaration (dw_die_ref die
)
7736 /* If the DIE is already a declaration, just clone it. */
7737 if (is_declaration_die (die
))
7738 return clone_die (die
);
7740 /* If the DIE is a specification, just clone its declaration DIE. */
7741 decl
= get_AT_ref (die
, DW_AT_specification
);
7744 clone
= clone_die (decl
);
7745 if (die
->comdat_type_p
)
7746 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7750 clone
= ggc_cleared_alloc
<die_node
> ();
7751 clone
->die_tag
= die
->die_tag
;
7753 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7755 /* We don't want to copy over all attributes.
7756 For example we don't want DW_AT_byte_size because otherwise we will no
7757 longer have a declaration and GDB will treat it as a definition. */
7761 case DW_AT_abstract_origin
:
7762 case DW_AT_artificial
:
7763 case DW_AT_containing_type
:
7764 case DW_AT_external
:
7767 case DW_AT_virtuality
:
7768 case DW_AT_linkage_name
:
7769 case DW_AT_MIPS_linkage_name
:
7770 add_dwarf_attr (clone
, a
);
7772 case DW_AT_byte_size
:
7773 case DW_AT_alignment
:
7779 if (die
->comdat_type_p
)
7780 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7782 add_AT_flag (clone
, DW_AT_declaration
, 1);
7787 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7789 struct decl_table_entry
7795 /* Helpers to manipulate hash table of copied declarations. */
7797 /* Hashtable helpers. */
7799 struct decl_table_entry_hasher
: free_ptr_hash
<decl_table_entry
>
7801 typedef die_struct
*compare_type
;
7802 static inline hashval_t
hash (const decl_table_entry
*);
7803 static inline bool equal (const decl_table_entry
*, const die_struct
*);
7807 decl_table_entry_hasher::hash (const decl_table_entry
*entry
)
7809 return htab_hash_pointer (entry
->orig
);
7813 decl_table_entry_hasher::equal (const decl_table_entry
*entry1
,
7814 const die_struct
*entry2
)
7816 return entry1
->orig
== entry2
;
7819 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
7821 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7822 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7823 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7824 to check if the ancestor has already been copied into UNIT. */
7827 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
,
7828 decl_hash_type
*decl_table
)
7830 dw_die_ref parent
= die
->die_parent
;
7831 dw_die_ref new_parent
= unit
;
7833 decl_table_entry
**slot
= NULL
;
7834 struct decl_table_entry
*entry
= NULL
;
7838 /* Check if the entry has already been copied to UNIT. */
7839 slot
= decl_table
->find_slot_with_hash (die
, htab_hash_pointer (die
),
7841 if (*slot
!= HTAB_EMPTY_ENTRY
)
7847 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7848 entry
= XCNEW (struct decl_table_entry
);
7856 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7859 if (!is_unit_die (parent
))
7860 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7863 copy
= clone_as_declaration (die
);
7864 add_child_die (new_parent
, copy
);
7868 /* Record the pointer to the copy. */
7874 /* Copy the declaration context to the new type unit DIE. This includes
7875 any surrounding namespace or type declarations. If the DIE has an
7876 AT_specification attribute, it also includes attributes and children
7877 attached to the specification, and returns a pointer to the original
7878 parent of the declaration DIE. Returns NULL otherwise. */
7881 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7884 dw_die_ref new_decl
;
7885 dw_die_ref orig_parent
= NULL
;
7887 decl
= get_AT_ref (die
, DW_AT_specification
);
7896 /* The original DIE will be changed to a declaration, and must
7897 be moved to be a child of the original declaration DIE. */
7898 orig_parent
= decl
->die_parent
;
7900 /* Copy the type node pointer from the new DIE to the original
7901 declaration DIE so we can forward references later. */
7902 decl
->comdat_type_p
= true;
7903 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7905 remove_AT (die
, DW_AT_specification
);
7907 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
7909 if (a
->dw_attr
!= DW_AT_name
7910 && a
->dw_attr
!= DW_AT_declaration
7911 && a
->dw_attr
!= DW_AT_external
)
7912 add_dwarf_attr (die
, a
);
7915 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
7918 if (decl
->die_parent
!= NULL
7919 && !is_unit_die (decl
->die_parent
))
7921 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
7922 if (new_decl
!= NULL
)
7924 remove_AT (new_decl
, DW_AT_signature
);
7925 add_AT_specification (die
, new_decl
);
7932 /* Generate the skeleton ancestor tree for the given NODE, then clone
7933 the DIE and add the clone into the tree. */
7936 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7938 if (node
->new_die
!= NULL
)
7941 node
->new_die
= clone_as_declaration (node
->old_die
);
7943 if (node
->parent
!= NULL
)
7945 generate_skeleton_ancestor_tree (node
->parent
);
7946 add_child_die (node
->parent
->new_die
, node
->new_die
);
7950 /* Generate a skeleton tree of DIEs containing any declarations that are
7951 found in the original tree. We traverse the tree looking for declaration
7952 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7955 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7957 skeleton_chain_node node
;
7960 dw_die_ref prev
= NULL
;
7961 dw_die_ref next
= NULL
;
7963 node
.parent
= parent
;
7965 first
= c
= parent
->old_die
->die_child
;
7969 if (prev
== NULL
|| prev
->die_sib
== c
)
7972 next
= (c
== first
? NULL
: c
->die_sib
);
7974 node
.new_die
= NULL
;
7975 if (is_declaration_die (c
))
7977 if (is_template_instantiation (c
))
7979 /* Instantiated templates do not need to be cloned into the
7980 type unit. Just move the DIE and its children back to
7981 the skeleton tree (in the main CU). */
7982 remove_child_with_prev (c
, prev
);
7983 add_child_die (parent
->new_die
, c
);
7986 else if (c
->comdat_type_p
)
7988 /* This is the skeleton of earlier break_out_comdat_types
7989 type. Clone the existing DIE, but keep the children
7990 under the original (which is in the main CU). */
7991 dw_die_ref clone
= clone_die (c
);
7993 replace_child (c
, clone
, prev
);
7994 generate_skeleton_ancestor_tree (parent
);
7995 add_child_die (parent
->new_die
, c
);
8001 /* Clone the existing DIE, move the original to the skeleton
8002 tree (which is in the main CU), and put the clone, with
8003 all the original's children, where the original came from
8004 (which is about to be moved to the type unit). */
8005 dw_die_ref clone
= clone_die (c
);
8006 move_all_children (c
, clone
);
8008 /* If the original has a DW_AT_object_pointer attribute,
8009 it would now point to a child DIE just moved to the
8010 cloned tree, so we need to remove that attribute from
8012 remove_AT (c
, DW_AT_object_pointer
);
8014 replace_child (c
, clone
, prev
);
8015 generate_skeleton_ancestor_tree (parent
);
8016 add_child_die (parent
->new_die
, c
);
8017 node
.old_die
= clone
;
8022 generate_skeleton_bottom_up (&node
);
8023 } while (next
!= NULL
);
8026 /* Wrapper function for generate_skeleton_bottom_up. */
8029 generate_skeleton (dw_die_ref die
)
8031 skeleton_chain_node node
;
8034 node
.new_die
= NULL
;
8037 /* If this type definition is nested inside another type,
8038 and is not an instantiation of a template, always leave
8039 at least a declaration in its place. */
8040 if (die
->die_parent
!= NULL
8041 && is_type_die (die
->die_parent
)
8042 && !is_template_instantiation (die
))
8043 node
.new_die
= clone_as_declaration (die
);
8045 generate_skeleton_bottom_up (&node
);
8046 return node
.new_die
;
8049 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
8050 declaration. The original DIE is moved to a new compile unit so that
8051 existing references to it follow it to the new location. If any of the
8052 original DIE's descendants is a declaration, we need to replace the
8053 original DIE with a skeleton tree and move the declarations back into the
8057 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
8060 dw_die_ref skeleton
, orig_parent
;
8062 /* Copy the declaration context to the type unit DIE. If the returned
8063 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
8065 orig_parent
= copy_declaration_context (unit
, child
);
8067 skeleton
= generate_skeleton (child
);
8068 if (skeleton
== NULL
)
8069 remove_child_with_prev (child
, prev
);
8072 skeleton
->comdat_type_p
= true;
8073 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
8075 /* If the original DIE was a specification, we need to put
8076 the skeleton under the parent DIE of the declaration.
8077 This leaves the original declaration in the tree, but
8078 it will be pruned later since there are no longer any
8079 references to it. */
8080 if (orig_parent
!= NULL
)
8082 remove_child_with_prev (child
, prev
);
8083 add_child_die (orig_parent
, skeleton
);
8086 replace_child (child
, skeleton
, prev
);
8093 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
8094 comdat_type_node
*type_node
,
8095 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
);
8097 /* Helper for copy_dwarf_procs_ref_in_dies. Make a copy of the DIE DWARF
8098 procedure, put it under TYPE_NODE and return the copy. Continue looking for
8099 DWARF procedure references in the DW_AT_location attribute. */
8102 copy_dwarf_procedure (dw_die_ref die
,
8103 comdat_type_node
*type_node
,
8104 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8106 gcc_assert (die
->die_tag
== DW_TAG_dwarf_procedure
);
8108 /* DWARF procedures are not supposed to have children... */
8109 gcc_assert (die
->die_child
== NULL
);
8111 /* ... and they are supposed to have only one attribute: DW_AT_location. */
8112 gcc_assert (vec_safe_length (die
->die_attr
) == 1
8113 && ((*die
->die_attr
)[0].dw_attr
== DW_AT_location
));
8115 /* Do not copy more than once DWARF procedures. */
8117 dw_die_ref
&die_copy
= copied_dwarf_procs
.get_or_insert (die
, &existed
);
8121 die_copy
= clone_die (die
);
8122 add_child_die (type_node
->root_die
, die_copy
);
8123 copy_dwarf_procs_ref_in_attrs (die_copy
, type_node
, copied_dwarf_procs
);
8127 /* Helper for copy_dwarf_procs_ref_in_dies. Look for references to DWARF
8128 procedures in DIE's attributes. */
8131 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
8132 comdat_type_node
*type_node
,
8133 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8138 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, i
, a
)
8140 dw_loc_descr_ref loc
;
8142 if (a
->dw_attr_val
.val_class
!= dw_val_class_loc
)
8145 for (loc
= a
->dw_attr_val
.v
.val_loc
; loc
!= NULL
; loc
= loc
->dw_loc_next
)
8147 switch (loc
->dw_loc_opc
)
8151 case DW_OP_call_ref
:
8152 gcc_assert (loc
->dw_loc_oprnd1
.val_class
8153 == dw_val_class_die_ref
);
8154 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
8155 = copy_dwarf_procedure (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
,
8157 copied_dwarf_procs
);
8166 /* Copy DWARF procedures that are referenced by the DIE tree to TREE_NODE and
8167 rewrite references to point to the copies.
8169 References are looked for in DIE's attributes and recursively in all its
8170 children attributes that are location descriptions. COPIED_DWARF_PROCS is a
8171 mapping from old DWARF procedures to their copy. It is used not to copy
8172 twice the same DWARF procedure under TYPE_NODE. */
8175 copy_dwarf_procs_ref_in_dies (dw_die_ref die
,
8176 comdat_type_node
*type_node
,
8177 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8181 copy_dwarf_procs_ref_in_attrs (die
, type_node
, copied_dwarf_procs
);
8182 FOR_EACH_CHILD (die
, c
, copy_dwarf_procs_ref_in_dies (c
,
8184 copied_dwarf_procs
));
8187 /* Traverse the DIE and set up additional .debug_types or .debug_info
8188 DW_UT_*type sections for each type worthy of being placed in a COMDAT
8192 break_out_comdat_types (dw_die_ref die
)
8196 dw_die_ref prev
= NULL
;
8197 dw_die_ref next
= NULL
;
8198 dw_die_ref unit
= NULL
;
8200 first
= c
= die
->die_child
;
8204 if (prev
== NULL
|| prev
->die_sib
== c
)
8207 next
= (c
== first
? NULL
: c
->die_sib
);
8208 if (should_move_die_to_comdat (c
))
8210 dw_die_ref replacement
;
8211 comdat_type_node
*type_node
;
8213 /* Break out nested types into their own type units. */
8214 break_out_comdat_types (c
);
8216 /* Create a new type unit DIE as the root for the new tree, and
8217 add it to the list of comdat types. */
8218 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8219 add_AT_unsigned (unit
, DW_AT_language
,
8220 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
8221 type_node
= ggc_cleared_alloc
<comdat_type_node
> ();
8222 type_node
->root_die
= unit
;
8223 type_node
->next
= comdat_type_list
;
8224 comdat_type_list
= type_node
;
8226 /* Generate the type signature. */
8227 generate_type_signature (c
, type_node
);
8229 /* Copy the declaration context, attributes, and children of the
8230 declaration into the new type unit DIE, then remove this DIE
8231 from the main CU (or replace it with a skeleton if necessary). */
8232 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
8233 type_node
->skeleton_die
= replacement
;
8235 /* Add the DIE to the new compunit. */
8236 add_child_die (unit
, c
);
8238 /* Types can reference DWARF procedures for type size or data location
8239 expressions. Calls in DWARF expressions cannot target procedures
8240 that are not in the same section. So we must copy DWARF procedures
8241 along with this type and then rewrite references to them. */
8242 hash_map
<dw_die_ref
, dw_die_ref
> copied_dwarf_procs
;
8243 copy_dwarf_procs_ref_in_dies (c
, type_node
, copied_dwarf_procs
);
8245 if (replacement
!= NULL
)
8248 else if (c
->die_tag
== DW_TAG_namespace
8249 || c
->die_tag
== DW_TAG_class_type
8250 || c
->die_tag
== DW_TAG_structure_type
8251 || c
->die_tag
== DW_TAG_union_type
)
8253 /* Look for nested types that can be broken out. */
8254 break_out_comdat_types (c
);
8256 } while (next
!= NULL
);
8259 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
8260 Enter all the cloned children into the hash table decl_table. */
8263 clone_tree_partial (dw_die_ref die
, decl_hash_type
*decl_table
)
8267 struct decl_table_entry
*entry
;
8268 decl_table_entry
**slot
;
8270 if (die
->die_tag
== DW_TAG_subprogram
)
8271 clone
= clone_as_declaration (die
);
8273 clone
= clone_die (die
);
8275 slot
= decl_table
->find_slot_with_hash (die
,
8276 htab_hash_pointer (die
), INSERT
);
8278 /* Assert that DIE isn't in the hash table yet. If it would be there
8279 before, the ancestors would be necessarily there as well, therefore
8280 clone_tree_partial wouldn't be called. */
8281 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
8283 entry
= XCNEW (struct decl_table_entry
);
8285 entry
->copy
= clone
;
8288 if (die
->die_tag
!= DW_TAG_subprogram
)
8289 FOR_EACH_CHILD (die
, c
,
8290 add_child_die (clone
, clone_tree_partial (c
, decl_table
)));
8295 /* Walk the DIE and its children, looking for references to incomplete
8296 or trivial types that are unmarked (i.e., that are not in the current
8300 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type
*decl_table
)
8306 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8308 if (AT_class (a
) == dw_val_class_die_ref
)
8310 dw_die_ref targ
= AT_ref (a
);
8311 decl_table_entry
**slot
;
8312 struct decl_table_entry
*entry
;
8314 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
8317 slot
= decl_table
->find_slot_with_hash (targ
,
8318 htab_hash_pointer (targ
),
8321 if (*slot
!= HTAB_EMPTY_ENTRY
)
8323 /* TARG has already been copied, so we just need to
8324 modify the reference to point to the copy. */
8326 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
8330 dw_die_ref parent
= unit
;
8331 dw_die_ref copy
= clone_die (targ
);
8333 /* Record in DECL_TABLE that TARG has been copied.
8334 Need to do this now, before the recursive call,
8335 because DECL_TABLE may be expanded and SLOT
8336 would no longer be a valid pointer. */
8337 entry
= XCNEW (struct decl_table_entry
);
8342 /* If TARG is not a declaration DIE, we need to copy its
8344 if (!is_declaration_die (targ
))
8348 add_child_die (copy
,
8349 clone_tree_partial (c
, decl_table
)));
8352 /* Make sure the cloned tree is marked as part of the
8356 /* If TARG has surrounding context, copy its ancestor tree
8357 into the new type unit. */
8358 if (targ
->die_parent
!= NULL
8359 && !is_unit_die (targ
->die_parent
))
8360 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
8363 add_child_die (parent
, copy
);
8364 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
8366 /* Make sure the newly-copied DIE is walked. If it was
8367 installed in a previously-added context, it won't
8368 get visited otherwise. */
8371 /* Find the highest point of the newly-added tree,
8372 mark each node along the way, and walk from there. */
8373 parent
->die_mark
= 1;
8374 while (parent
->die_parent
8375 && parent
->die_parent
->die_mark
== 0)
8377 parent
= parent
->die_parent
;
8378 parent
->die_mark
= 1;
8380 copy_decls_walk (unit
, parent
, decl_table
);
8386 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
8389 /* Copy declarations for "unworthy" types into the new comdat section.
8390 Incomplete types, modified types, and certain other types aren't broken
8391 out into comdat sections of their own, so they don't have a signature,
8392 and we need to copy the declaration into the same section so that we
8393 don't have an external reference. */
8396 copy_decls_for_unworthy_types (dw_die_ref unit
)
8399 decl_hash_type
decl_table (10);
8400 copy_decls_walk (unit
, unit
, &decl_table
);
8404 /* Traverse the DIE and add a sibling attribute if it may have the
8405 effect of speeding up access to siblings. To save some space,
8406 avoid generating sibling attributes for DIE's without children. */
8409 add_sibling_attributes (dw_die_ref die
)
8413 if (! die
->die_child
)
8416 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
8417 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
8419 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
8422 /* Output all location lists for the DIE and its children. */
8425 output_location_lists (dw_die_ref die
)
8431 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8432 if (AT_class (a
) == dw_val_class_loc_list
)
8433 output_loc_list (AT_loc_list (a
));
8435 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
8438 /* During assign_location_list_indexes and output_loclists_offset the
8439 current index, after it the number of assigned indexes (i.e. how
8440 large the .debug_loclists* offset table should be). */
8441 static unsigned int loc_list_idx
;
8443 /* Output all location list offsets for the DIE and its children. */
8446 output_loclists_offsets (dw_die_ref die
)
8452 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8453 if (AT_class (a
) == dw_val_class_loc_list
)
8455 dw_loc_list_ref l
= AT_loc_list (a
);
8456 if (l
->offset_emitted
)
8458 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l
->ll_symbol
,
8459 loc_section_label
, NULL
);
8460 gcc_assert (l
->hash
== loc_list_idx
);
8462 l
->offset_emitted
= true;
8465 FOR_EACH_CHILD (die
, c
, output_loclists_offsets (c
));
8468 /* Recursively set indexes of location lists. */
8471 assign_location_list_indexes (dw_die_ref die
)
8477 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8478 if (AT_class (a
) == dw_val_class_loc_list
)
8480 dw_loc_list_ref list
= AT_loc_list (a
);
8481 if (!list
->num_assigned
)
8483 list
->num_assigned
= true;
8484 list
->hash
= loc_list_idx
++;
8488 FOR_EACH_CHILD (die
, c
, assign_location_list_indexes (c
));
8491 /* We want to limit the number of external references, because they are
8492 larger than local references: a relocation takes multiple words, and
8493 even a sig8 reference is always eight bytes, whereas a local reference
8494 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
8495 So if we encounter multiple external references to the same type DIE, we
8496 make a local typedef stub for it and redirect all references there.
8498 This is the element of the hash table for keeping track of these
8508 /* Hashtable helpers. */
8510 struct external_ref_hasher
: free_ptr_hash
<external_ref
>
8512 static inline hashval_t
hash (const external_ref
*);
8513 static inline bool equal (const external_ref
*, const external_ref
*);
8517 external_ref_hasher::hash (const external_ref
*r
)
8519 dw_die_ref die
= r
->type
;
8522 /* We can't use the address of the DIE for hashing, because
8523 that will make the order of the stub DIEs non-deterministic. */
8524 if (! die
->comdat_type_p
)
8525 /* We have a symbol; use it to compute a hash. */
8526 h
= htab_hash_string (die
->die_id
.die_symbol
);
8529 /* We have a type signature; use a subset of the bits as the hash.
8530 The 8-byte signature is at least as large as hashval_t. */
8531 comdat_type_node
*type_node
= die
->die_id
.die_type_node
;
8532 memcpy (&h
, type_node
->signature
, sizeof (h
));
8538 external_ref_hasher::equal (const external_ref
*r1
, const external_ref
*r2
)
8540 return r1
->type
== r2
->type
;
8543 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
8545 /* Return a pointer to the external_ref for references to DIE. */
8547 static struct external_ref
*
8548 lookup_external_ref (external_ref_hash_type
*map
, dw_die_ref die
)
8550 struct external_ref ref
, *ref_p
;
8551 external_ref
**slot
;
8554 slot
= map
->find_slot (&ref
, INSERT
);
8555 if (*slot
!= HTAB_EMPTY_ENTRY
)
8558 ref_p
= XCNEW (struct external_ref
);
8564 /* Subroutine of optimize_external_refs, below.
8566 If we see a type skeleton, record it as our stub. If we see external
8567 references, remember how many we've seen. */
8570 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type
*map
)
8575 struct external_ref
*ref_p
;
8577 if (is_type_die (die
)
8578 && (c
= get_AT_ref (die
, DW_AT_signature
)))
8580 /* This is a local skeleton; use it for local references. */
8581 ref_p
= lookup_external_ref (map
, c
);
8585 /* Scan the DIE references, and remember any that refer to DIEs from
8586 other CUs (i.e. those which are not marked). */
8587 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8588 if (AT_class (a
) == dw_val_class_die_ref
8589 && (c
= AT_ref (a
))->die_mark
== 0
8592 ref_p
= lookup_external_ref (map
, c
);
8596 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
8599 /* htab_traverse callback function for optimize_external_refs, below. SLOT
8600 points to an external_ref, DATA is the CU we're processing. If we don't
8601 already have a local stub, and we have multiple refs, build a stub. */
8604 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
8606 struct external_ref
*ref_p
= *slot
;
8608 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
8610 /* We have multiple references to this type, so build a small stub.
8611 Both of these forms are a bit dodgy from the perspective of the
8612 DWARF standard, since technically they should have names. */
8613 dw_die_ref cu
= data
;
8614 dw_die_ref type
= ref_p
->type
;
8615 dw_die_ref stub
= NULL
;
8617 if (type
->comdat_type_p
)
8619 /* If we refer to this type via sig8, use AT_signature. */
8620 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
8621 add_AT_die_ref (stub
, DW_AT_signature
, type
);
8625 /* Otherwise, use a typedef with no name. */
8626 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
8627 add_AT_die_ref (stub
, DW_AT_type
, type
);
8636 /* DIE is a unit; look through all the DIE references to see if there are
8637 any external references to types, and if so, create local stubs for
8638 them which will be applied in build_abbrev_table. This is useful because
8639 references to local DIEs are smaller. */
8641 static external_ref_hash_type
*
8642 optimize_external_refs (dw_die_ref die
)
8644 external_ref_hash_type
*map
= new external_ref_hash_type (10);
8645 optimize_external_refs_1 (die
, map
);
8646 map
->traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
8650 /* The following 3 variables are temporaries that are computed only during the
8651 build_abbrev_table call and used and released during the following
8652 optimize_abbrev_table call. */
8654 /* First abbrev_id that can be optimized based on usage. */
8655 static unsigned int abbrev_opt_start
;
8657 /* Maximum abbrev_id of a base type plus one (we can't optimize DIEs with
8658 abbrev_id smaller than this, because they must be already sized
8659 during build_abbrev_table). */
8660 static unsigned int abbrev_opt_base_type_end
;
8662 /* Vector of usage counts during build_abbrev_table. Indexed by
8663 abbrev_id - abbrev_opt_start. */
8664 static vec
<unsigned int> abbrev_usage_count
;
8666 /* Vector of all DIEs added with die_abbrev >= abbrev_opt_start. */
8667 static vec
<dw_die_ref
> sorted_abbrev_dies
;
8669 /* The format of each DIE (and its attribute value pairs) is encoded in an
8670 abbreviation table. This routine builds the abbreviation table and assigns
8671 a unique abbreviation id for each abbreviation entry. The children of each
8672 die are visited recursively. */
8675 build_abbrev_table (dw_die_ref die
, external_ref_hash_type
*extern_map
)
8677 unsigned int abbrev_id
= 0;
8683 /* Scan the DIE references, and replace any that refer to
8684 DIEs from other CUs (i.e. those which are not marked) with
8685 the local stubs we built in optimize_external_refs. */
8686 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8687 if (AT_class (a
) == dw_val_class_die_ref
8688 && (c
= AT_ref (a
))->die_mark
== 0)
8690 struct external_ref
*ref_p
;
8691 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
8693 ref_p
= lookup_external_ref (extern_map
, c
);
8694 if (ref_p
->stub
&& ref_p
->stub
!= die
)
8695 change_AT_die_ref (a
, ref_p
->stub
);
8697 /* We aren't changing this reference, so mark it external. */
8698 set_AT_ref_external (a
, 1);
8701 FOR_EACH_VEC_SAFE_ELT (abbrev_die_table
, abbrev_id
, abbrev
)
8703 dw_attr_node
*die_a
, *abbrev_a
;
8709 if (abbrev
->die_tag
!= die
->die_tag
)
8711 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
8714 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
8717 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
8719 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
8720 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
8721 || (value_format (abbrev_a
) != value_format (die_a
)))
8731 if (abbrev_id
>= vec_safe_length (abbrev_die_table
))
8733 vec_safe_push (abbrev_die_table
, die
);
8734 if (abbrev_opt_start
)
8735 abbrev_usage_count
.safe_push (0);
8737 if (abbrev_opt_start
&& abbrev_id
>= abbrev_opt_start
)
8739 abbrev_usage_count
[abbrev_id
- abbrev_opt_start
]++;
8740 sorted_abbrev_dies
.safe_push (die
);
8743 die
->die_abbrev
= abbrev_id
;
8744 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
8747 /* Callback function for sorted_abbrev_dies vector sorting. We sort
8748 by die_abbrev's usage count, from the most commonly used
8749 abbreviation to the least. */
8752 die_abbrev_cmp (const void *p1
, const void *p2
)
8754 dw_die_ref die1
= *(const dw_die_ref
*) p1
;
8755 dw_die_ref die2
= *(const dw_die_ref
*) p2
;
8757 gcc_checking_assert (die1
->die_abbrev
>= abbrev_opt_start
);
8758 gcc_checking_assert (die2
->die_abbrev
>= abbrev_opt_start
);
8760 if (die1
->die_abbrev
>= abbrev_opt_base_type_end
8761 && die2
->die_abbrev
>= abbrev_opt_base_type_end
)
8763 if (abbrev_usage_count
[die1
->die_abbrev
- abbrev_opt_start
]
8764 > abbrev_usage_count
[die2
->die_abbrev
- abbrev_opt_start
])
8766 if (abbrev_usage_count
[die1
->die_abbrev
- abbrev_opt_start
]
8767 < abbrev_usage_count
[die2
->die_abbrev
- abbrev_opt_start
])
8771 /* Stabilize the sort. */
8772 if (die1
->die_abbrev
< die2
->die_abbrev
)
8774 if (die1
->die_abbrev
> die2
->die_abbrev
)
8780 /* Convert dw_val_class_const and dw_val_class_unsigned_const class attributes
8781 of DIEs in between sorted_abbrev_dies[first_id] and abbrev_dies[end_id - 1]
8782 into dw_val_class_const_implicit or
8783 dw_val_class_unsigned_const_implicit. */
8786 optimize_implicit_const (unsigned int first_id
, unsigned int end
,
8787 vec
<bool> &implicit_consts
)
8789 /* It never makes sense if there is just one DIE using the abbreviation. */
8790 if (end
< first_id
+ 2)
8795 dw_die_ref die
= sorted_abbrev_dies
[first_id
];
8796 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8797 if (implicit_consts
[ix
])
8799 enum dw_val_class new_class
= dw_val_class_none
;
8800 switch (AT_class (a
))
8802 case dw_val_class_unsigned_const
:
8803 if ((HOST_WIDE_INT
) AT_unsigned (a
) < 0)
8806 /* The .debug_abbrev section will grow by
8807 size_of_sleb128 (AT_unsigned (a)) and we avoid the constants
8808 in all the DIEs using that abbreviation. */
8809 if (constant_size (AT_unsigned (a
)) * (end
- first_id
)
8810 <= (unsigned) size_of_sleb128 (AT_unsigned (a
)))
8813 new_class
= dw_val_class_unsigned_const_implicit
;
8816 case dw_val_class_const
:
8817 new_class
= dw_val_class_const_implicit
;
8820 case dw_val_class_file
:
8821 new_class
= dw_val_class_file_implicit
;
8827 for (i
= first_id
; i
< end
; i
++)
8828 (*sorted_abbrev_dies
[i
]->die_attr
)[ix
].dw_attr_val
.val_class
8833 /* Attempt to optimize abbreviation table from abbrev_opt_start
8834 abbreviation above. */
8837 optimize_abbrev_table (void)
8839 if (abbrev_opt_start
8840 && vec_safe_length (abbrev_die_table
) > abbrev_opt_start
8841 && (dwarf_version
>= 5 || vec_safe_length (abbrev_die_table
) > 127))
8843 auto_vec
<bool, 32> implicit_consts
;
8844 sorted_abbrev_dies
.qsort (die_abbrev_cmp
);
8846 unsigned int abbrev_id
= abbrev_opt_start
- 1;
8847 unsigned int first_id
= ~0U;
8848 unsigned int last_abbrev_id
= 0;
8851 if (abbrev_opt_base_type_end
> abbrev_opt_start
)
8852 abbrev_id
= abbrev_opt_base_type_end
- 1;
8853 /* Reassign abbreviation ids from abbrev_opt_start above, so that
8854 most commonly used abbreviations come first. */
8855 FOR_EACH_VEC_ELT (sorted_abbrev_dies
, i
, die
)
8860 /* If calc_base_type_die_sizes has been called, the CU and
8861 base types after it can't be optimized, because we've already
8862 calculated their DIE offsets. We've sorted them first. */
8863 if (die
->die_abbrev
< abbrev_opt_base_type_end
)
8865 if (die
->die_abbrev
!= last_abbrev_id
)
8867 last_abbrev_id
= die
->die_abbrev
;
8868 if (dwarf_version
>= 5 && first_id
!= ~0U)
8869 optimize_implicit_const (first_id
, i
, implicit_consts
);
8871 (*abbrev_die_table
)[abbrev_id
] = die
;
8872 if (dwarf_version
>= 5)
8875 implicit_consts
.truncate (0);
8877 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8878 switch (AT_class (a
))
8880 case dw_val_class_const
:
8881 case dw_val_class_unsigned_const
:
8882 case dw_val_class_file
:
8883 implicit_consts
.safe_push (true);
8886 implicit_consts
.safe_push (false);
8891 else if (dwarf_version
>= 5)
8893 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8894 if (!implicit_consts
[ix
])
8898 dw_attr_node
*other_a
8899 = &(*(*abbrev_die_table
)[abbrev_id
]->die_attr
)[ix
];
8900 if (!dw_val_equal_p (&a
->dw_attr_val
,
8901 &other_a
->dw_attr_val
))
8902 implicit_consts
[ix
] = false;
8905 die
->die_abbrev
= abbrev_id
;
8907 gcc_assert (abbrev_id
== vec_safe_length (abbrev_die_table
) - 1);
8908 if (dwarf_version
>= 5 && first_id
!= ~0U)
8909 optimize_implicit_const (first_id
, i
, implicit_consts
);
8912 abbrev_opt_start
= 0;
8913 abbrev_opt_base_type_end
= 0;
8914 abbrev_usage_count
.release ();
8915 sorted_abbrev_dies
.release ();
8918 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8921 constant_size (unsigned HOST_WIDE_INT value
)
8928 log
= floor_log2 (value
);
8931 log
= 1 << (floor_log2 (log
) + 1);
8936 /* Return the size of a DIE as it is represented in the
8937 .debug_info section. */
8939 static unsigned long
8940 size_of_die (dw_die_ref die
)
8942 unsigned long size
= 0;
8945 enum dwarf_form form
;
8947 size
+= size_of_uleb128 (die
->die_abbrev
);
8948 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8950 switch (AT_class (a
))
8952 case dw_val_class_addr
:
8953 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8955 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8956 size
+= size_of_uleb128 (AT_index (a
));
8959 size
+= DWARF2_ADDR_SIZE
;
8961 case dw_val_class_offset
:
8962 size
+= DWARF_OFFSET_SIZE
;
8964 case dw_val_class_loc
:
8966 unsigned long lsize
= size_of_locs (AT_loc (a
));
8969 if (dwarf_version
>= 4)
8970 size
+= size_of_uleb128 (lsize
);
8972 size
+= constant_size (lsize
);
8976 case dw_val_class_loc_list
:
8977 if (dwarf_split_debug_info
&& dwarf_version
>= 5)
8979 gcc_assert (AT_loc_list (a
)->num_assigned
);
8980 size
+= size_of_uleb128 (AT_loc_list (a
)->hash
);
8983 size
+= DWARF_OFFSET_SIZE
;
8985 case dw_val_class_range_list
:
8986 if (value_format (a
) == DW_FORM_rnglistx
)
8988 gcc_assert (rnglist_idx
);
8989 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
8990 size
+= size_of_uleb128 (r
->idx
);
8993 size
+= DWARF_OFFSET_SIZE
;
8995 case dw_val_class_const
:
8996 size
+= size_of_sleb128 (AT_int (a
));
8998 case dw_val_class_unsigned_const
:
9000 int csize
= constant_size (AT_unsigned (a
));
9001 if (dwarf_version
== 3
9002 && a
->dw_attr
== DW_AT_data_member_location
9004 size
+= size_of_uleb128 (AT_unsigned (a
));
9009 case dw_val_class_const_implicit
:
9010 case dw_val_class_unsigned_const_implicit
:
9011 case dw_val_class_file_implicit
:
9012 /* These occupy no size in the DIE, just an extra sleb128 in
9015 case dw_val_class_const_double
:
9016 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
9017 if (HOST_BITS_PER_WIDE_INT
>= DWARF_LARGEST_DATA_FORM_BITS
)
9020 case dw_val_class_wide_int
:
9021 size
+= (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
9022 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
9023 if (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
9024 * HOST_BITS_PER_WIDE_INT
> DWARF_LARGEST_DATA_FORM_BITS
)
9027 case dw_val_class_vec
:
9028 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
9029 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
9030 + a
->dw_attr_val
.v
.val_vec
.length
9031 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
9033 case dw_val_class_flag
:
9034 if (dwarf_version
>= 4)
9035 /* Currently all add_AT_flag calls pass in 1 as last argument,
9036 so DW_FORM_flag_present can be used. If that ever changes,
9037 we'll need to use DW_FORM_flag and have some optimization
9038 in build_abbrev_table that will change those to
9039 DW_FORM_flag_present if it is set to 1 in all DIEs using
9040 the same abbrev entry. */
9041 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
9045 case dw_val_class_die_ref
:
9046 if (AT_ref_external (a
))
9048 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
9049 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
9050 is sized by target address length, whereas in DWARF3
9051 it's always sized as an offset. */
9052 if (use_debug_types
)
9053 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
9054 else if (dwarf_version
== 2)
9055 size
+= DWARF2_ADDR_SIZE
;
9057 size
+= DWARF_OFFSET_SIZE
;
9060 size
+= DWARF_OFFSET_SIZE
;
9062 case dw_val_class_fde_ref
:
9063 size
+= DWARF_OFFSET_SIZE
;
9065 case dw_val_class_lbl_id
:
9066 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
9068 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
9069 size
+= size_of_uleb128 (AT_index (a
));
9072 size
+= DWARF2_ADDR_SIZE
;
9074 case dw_val_class_lineptr
:
9075 case dw_val_class_macptr
:
9076 case dw_val_class_loclistsptr
:
9077 size
+= DWARF_OFFSET_SIZE
;
9079 case dw_val_class_str
:
9080 form
= AT_string_form (a
);
9081 if (form
== DW_FORM_strp
|| form
== DW_FORM_line_strp
)
9082 size
+= DWARF_OFFSET_SIZE
;
9083 else if (form
== DW_FORM_GNU_str_index
)
9084 size
+= size_of_uleb128 (AT_index (a
));
9086 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
9088 case dw_val_class_file
:
9089 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
9091 case dw_val_class_data8
:
9094 case dw_val_class_vms_delta
:
9095 size
+= DWARF_OFFSET_SIZE
;
9097 case dw_val_class_high_pc
:
9098 size
+= DWARF2_ADDR_SIZE
;
9100 case dw_val_class_discr_value
:
9101 size
+= size_of_discr_value (&a
->dw_attr_val
.v
.val_discr_value
);
9103 case dw_val_class_discr_list
:
9105 unsigned block_size
= size_of_discr_list (AT_discr_list (a
));
9107 /* This is a block, so we have the block length and then its
9109 size
+= constant_size (block_size
) + block_size
;
9120 /* Size the debugging information associated with a given DIE. Visits the
9121 DIE's children recursively. Updates the global variable next_die_offset, on
9122 each time through. Uses the current value of next_die_offset to update the
9123 die_offset field in each DIE. */
9126 calc_die_sizes (dw_die_ref die
)
9130 gcc_assert (die
->die_offset
== 0
9131 || (unsigned long int) die
->die_offset
== next_die_offset
);
9132 die
->die_offset
= next_die_offset
;
9133 next_die_offset
+= size_of_die (die
);
9135 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
9137 if (die
->die_child
!= NULL
)
9138 /* Count the null byte used to terminate sibling lists. */
9139 next_die_offset
+= 1;
9142 /* Size just the base type children at the start of the CU.
9143 This is needed because build_abbrev needs to size locs
9144 and sizing of type based stack ops needs to know die_offset
9145 values for the base types. */
9148 calc_base_type_die_sizes (void)
9150 unsigned long die_offset
= (dwarf_split_debug_info
9151 ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
9152 : DWARF_COMPILE_UNIT_HEADER_SIZE
);
9154 dw_die_ref base_type
;
9155 #if ENABLE_ASSERT_CHECKING
9156 dw_die_ref prev
= comp_unit_die ()->die_child
;
9159 die_offset
+= size_of_die (comp_unit_die ());
9160 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
9162 #if ENABLE_ASSERT_CHECKING
9163 gcc_assert (base_type
->die_offset
== 0
9164 && prev
->die_sib
== base_type
9165 && base_type
->die_child
== NULL
9166 && base_type
->die_abbrev
);
9169 if (abbrev_opt_start
9170 && base_type
->die_abbrev
>= abbrev_opt_base_type_end
)
9171 abbrev_opt_base_type_end
= base_type
->die_abbrev
+ 1;
9172 base_type
->die_offset
= die_offset
;
9173 die_offset
+= size_of_die (base_type
);
9177 /* Set the marks for a die and its children. We do this so
9178 that we know whether or not a reference needs to use FORM_ref_addr; only
9179 DIEs in the same CU will be marked. We used to clear out the offset
9180 and use that as the flag, but ran into ordering problems. */
9183 mark_dies (dw_die_ref die
)
9187 gcc_assert (!die
->die_mark
);
9190 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
9193 /* Clear the marks for a die and its children. */
9196 unmark_dies (dw_die_ref die
)
9200 if (! use_debug_types
)
9201 gcc_assert (die
->die_mark
);
9204 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
9207 /* Clear the marks for a die, its children and referred dies. */
9210 unmark_all_dies (dw_die_ref die
)
9220 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
9222 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9223 if (AT_class (a
) == dw_val_class_die_ref
)
9224 unmark_all_dies (AT_ref (a
));
9227 /* Calculate if the entry should appear in the final output file. It may be
9228 from a pruned a type. */
9231 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
9233 /* By limiting gnu pubnames to definitions only, gold can generate a
9234 gdb index without entries for declarations, which don't include
9235 enough information to be useful. */
9236 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
9239 if (table
== pubname_table
)
9241 /* Enumerator names are part of the pubname table, but the
9242 parent DW_TAG_enumeration_type die may have been pruned.
9243 Don't output them if that is the case. */
9244 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
9245 (p
->die
->die_parent
== NULL
9246 || !p
->die
->die_parent
->die_perennial_p
))
9249 /* Everything else in the pubname table is included. */
9253 /* The pubtypes table shouldn't include types that have been
9255 return (p
->die
->die_offset
!= 0
9256 || !flag_eliminate_unused_debug_types
);
9259 /* Return the size of the .debug_pubnames or .debug_pubtypes table
9260 generated for the compilation unit. */
9262 static unsigned long
9263 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9268 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
9270 size
= DWARF_PUBNAMES_HEADER_SIZE
;
9271 FOR_EACH_VEC_ELT (*names
, i
, p
)
9272 if (include_pubname_in_output (names
, p
))
9273 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
9275 size
+= DWARF_OFFSET_SIZE
;
9279 /* Return the size of the information in the .debug_aranges section. */
9281 static unsigned long
9282 size_of_aranges (void)
9286 size
= DWARF_ARANGES_HEADER_SIZE
;
9288 /* Count the address/length pair for this compilation unit. */
9289 if (text_section_used
)
9290 size
+= 2 * DWARF2_ADDR_SIZE
;
9291 if (cold_text_section_used
)
9292 size
+= 2 * DWARF2_ADDR_SIZE
;
9293 if (have_multiple_function_sections
)
9298 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9300 if (DECL_IGNORED_P (fde
->decl
))
9302 if (!fde
->in_std_section
)
9303 size
+= 2 * DWARF2_ADDR_SIZE
;
9304 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9305 size
+= 2 * DWARF2_ADDR_SIZE
;
9309 /* Count the two zero words used to terminated the address range table. */
9310 size
+= 2 * DWARF2_ADDR_SIZE
;
9314 /* Select the encoding of an attribute value. */
9316 static enum dwarf_form
9317 value_format (dw_attr_node
*a
)
9319 switch (AT_class (a
))
9321 case dw_val_class_addr
:
9322 /* Only very few attributes allow DW_FORM_addr. */
9327 case DW_AT_entry_pc
:
9328 case DW_AT_trampoline
:
9329 return (AT_index (a
) == NOT_INDEXED
9330 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
9334 switch (DWARF2_ADDR_SIZE
)
9337 return DW_FORM_data1
;
9339 return DW_FORM_data2
;
9341 return DW_FORM_data4
;
9343 return DW_FORM_data8
;
9347 case dw_val_class_loc_list
:
9348 if (dwarf_split_debug_info
9349 && dwarf_version
>= 5
9350 && AT_loc_list (a
)->num_assigned
)
9351 return DW_FORM_loclistx
;
9353 case dw_val_class_range_list
:
9354 /* For range lists in DWARF 5, use DW_FORM_rnglistx from .debug_info.dwo
9355 but in .debug_info use DW_FORM_sec_offset, which is shorter if we
9356 care about sizes of .debug* sections in shared libraries and
9357 executables and don't take into account relocations that affect just
9358 relocatable objects - for DW_FORM_rnglistx we'd have to emit offset
9359 table in the .debug_rnglists section. */
9360 if (dwarf_split_debug_info
9361 && dwarf_version
>= 5
9362 && AT_class (a
) == dw_val_class_range_list
9364 && a
->dw_attr_val
.val_entry
!= RELOCATED_OFFSET
)
9365 return DW_FORM_rnglistx
;
9366 if (dwarf_version
>= 4)
9367 return DW_FORM_sec_offset
;
9369 case dw_val_class_vms_delta
:
9370 case dw_val_class_offset
:
9371 switch (DWARF_OFFSET_SIZE
)
9374 return DW_FORM_data4
;
9376 return DW_FORM_data8
;
9380 case dw_val_class_loc
:
9381 if (dwarf_version
>= 4)
9382 return DW_FORM_exprloc
;
9383 switch (constant_size (size_of_locs (AT_loc (a
))))
9386 return DW_FORM_block1
;
9388 return DW_FORM_block2
;
9390 return DW_FORM_block4
;
9394 case dw_val_class_const
:
9395 return DW_FORM_sdata
;
9396 case dw_val_class_unsigned_const
:
9397 switch (constant_size (AT_unsigned (a
)))
9400 return DW_FORM_data1
;
9402 return DW_FORM_data2
;
9404 /* In DWARF3 DW_AT_data_member_location with
9405 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
9406 constant, so we need to use DW_FORM_udata if we need
9407 a large constant. */
9408 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
9409 return DW_FORM_udata
;
9410 return DW_FORM_data4
;
9412 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
9413 return DW_FORM_udata
;
9414 return DW_FORM_data8
;
9418 case dw_val_class_const_implicit
:
9419 case dw_val_class_unsigned_const_implicit
:
9420 case dw_val_class_file_implicit
:
9421 return DW_FORM_implicit_const
;
9422 case dw_val_class_const_double
:
9423 switch (HOST_BITS_PER_WIDE_INT
)
9426 return DW_FORM_data2
;
9428 return DW_FORM_data4
;
9430 return DW_FORM_data8
;
9432 if (dwarf_version
>= 5)
9433 return DW_FORM_data16
;
9436 return DW_FORM_block1
;
9438 case dw_val_class_wide_int
:
9439 switch (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
)
9442 return DW_FORM_data1
;
9444 return DW_FORM_data2
;
9446 return DW_FORM_data4
;
9448 return DW_FORM_data8
;
9450 if (dwarf_version
>= 5)
9451 return DW_FORM_data16
;
9454 return DW_FORM_block1
;
9456 case dw_val_class_vec
:
9457 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
9458 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
9461 return DW_FORM_block1
;
9463 return DW_FORM_block2
;
9465 return DW_FORM_block4
;
9469 case dw_val_class_flag
:
9470 if (dwarf_version
>= 4)
9472 /* Currently all add_AT_flag calls pass in 1 as last argument,
9473 so DW_FORM_flag_present can be used. If that ever changes,
9474 we'll need to use DW_FORM_flag and have some optimization
9475 in build_abbrev_table that will change those to
9476 DW_FORM_flag_present if it is set to 1 in all DIEs using
9477 the same abbrev entry. */
9478 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
9479 return DW_FORM_flag_present
;
9481 return DW_FORM_flag
;
9482 case dw_val_class_die_ref
:
9483 if (AT_ref_external (a
))
9484 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
9487 case dw_val_class_fde_ref
:
9488 return DW_FORM_data
;
9489 case dw_val_class_lbl_id
:
9490 return (AT_index (a
) == NOT_INDEXED
9491 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
9492 case dw_val_class_lineptr
:
9493 case dw_val_class_macptr
:
9494 case dw_val_class_loclistsptr
:
9495 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
9496 case dw_val_class_str
:
9497 return AT_string_form (a
);
9498 case dw_val_class_file
:
9499 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
9502 return DW_FORM_data1
;
9504 return DW_FORM_data2
;
9506 return DW_FORM_data4
;
9511 case dw_val_class_data8
:
9512 return DW_FORM_data8
;
9514 case dw_val_class_high_pc
:
9515 switch (DWARF2_ADDR_SIZE
)
9518 return DW_FORM_data1
;
9520 return DW_FORM_data2
;
9522 return DW_FORM_data4
;
9524 return DW_FORM_data8
;
9529 case dw_val_class_discr_value
:
9530 return (a
->dw_attr_val
.v
.val_discr_value
.pos
9533 case dw_val_class_discr_list
:
9534 switch (constant_size (size_of_discr_list (AT_discr_list (a
))))
9537 return DW_FORM_block1
;
9539 return DW_FORM_block2
;
9541 return DW_FORM_block4
;
9551 /* Output the encoding of an attribute value. */
9554 output_value_format (dw_attr_node
*a
)
9556 enum dwarf_form form
= value_format (a
);
9558 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
9561 /* Given a die and id, produce the appropriate abbreviations. */
9564 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
9567 dw_attr_node
*a_attr
;
9569 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
9570 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
9571 dwarf_tag_name (abbrev
->die_tag
));
9573 if (abbrev
->die_child
!= NULL
)
9574 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
9576 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
9578 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
9580 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
9581 dwarf_attr_name (a_attr
->dw_attr
));
9582 output_value_format (a_attr
);
9583 if (value_format (a_attr
) == DW_FORM_implicit_const
)
9585 if (AT_class (a_attr
) == dw_val_class_file_implicit
)
9587 int f
= maybe_emit_file (a_attr
->dw_attr_val
.v
.val_file
);
9588 const char *filename
= a_attr
->dw_attr_val
.v
.val_file
->filename
;
9589 dw2_asm_output_data_sleb128 (f
, "(%s)", filename
);
9592 dw2_asm_output_data_sleb128 (a_attr
->dw_attr_val
.v
.val_int
, NULL
);
9596 dw2_asm_output_data (1, 0, NULL
);
9597 dw2_asm_output_data (1, 0, NULL
);
9601 /* Output the .debug_abbrev section which defines the DIE abbreviation
9605 output_abbrev_section (void)
9607 unsigned int abbrev_id
;
9610 FOR_EACH_VEC_SAFE_ELT (abbrev_die_table
, abbrev_id
, abbrev
)
9612 output_die_abbrevs (abbrev_id
, abbrev
);
9614 /* Terminate the table. */
9615 dw2_asm_output_data (1, 0, NULL
);
9618 /* Output a symbol we can use to refer to this DIE from another CU. */
9621 output_die_symbol (dw_die_ref die
)
9623 const char *sym
= die
->die_id
.die_symbol
;
9625 gcc_assert (!die
->comdat_type_p
);
9630 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
9631 /* We make these global, not weak; if the target doesn't support
9632 .linkonce, it doesn't support combining the sections, so debugging
9634 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
9636 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
9639 /* Return a new location list, given the begin and end range, and the
9642 static inline dw_loc_list_ref
9643 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
9644 const char *section
)
9646 dw_loc_list_ref retlist
= ggc_cleared_alloc
<dw_loc_list_node
> ();
9648 retlist
->begin
= begin
;
9649 retlist
->begin_entry
= NULL
;
9651 retlist
->expr
= expr
;
9652 retlist
->section
= section
;
9657 /* Generate a new internal symbol for this location list node, if it
9658 hasn't got one yet. */
9661 gen_llsym (dw_loc_list_ref list
)
9663 gcc_assert (!list
->ll_symbol
);
9664 list
->ll_symbol
= gen_internal_sym ("LLST");
9667 /* Output the location list given to us. */
9670 output_loc_list (dw_loc_list_ref list_head
)
9672 if (list_head
->emitted
)
9674 list_head
->emitted
= true;
9676 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
9678 dw_loc_list_ref curr
= list_head
;
9679 const char *last_section
= NULL
;
9680 const char *base_label
= NULL
;
9682 /* Walk the location list, and output each range + expression. */
9683 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
9686 /* Don't output an entry that starts and ends at the same address. */
9687 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
9689 size
= size_of_locs (curr
->expr
);
9690 /* If the expression is too large, drop it on the floor. We could
9691 perhaps put it into DW_TAG_dwarf_procedure and refer to that
9692 in the expression, but >= 64KB expressions for a single value
9693 in a single range are unlikely very useful. */
9694 if (dwarf_version
< 5 && size
> 0xffff)
9696 if (dwarf_version
>= 5)
9698 if (dwarf_split_debug_info
)
9700 /* For -gsplit-dwarf, emit DW_LLE_starx_length, which has
9701 uleb128 index into .debug_addr and uleb128 length. */
9702 dw2_asm_output_data (1, DW_LLE_startx_length
,
9703 "DW_LLE_startx_length (%s)",
9704 list_head
->ll_symbol
);
9705 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
9706 "Location list range start index "
9707 "(%s)", curr
->begin
);
9708 /* FIXME: This will ICE ifndef HAVE_AS_LEB128.
9709 For that case we probably need to emit DW_LLE_startx_endx,
9710 but we'd need 2 .debug_addr entries rather than just one. */
9711 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->begin
,
9712 "Location list length (%s)",
9713 list_head
->ll_symbol
);
9715 else if (!have_multiple_function_sections
&& HAVE_AS_LEB128
)
9717 /* If all code is in .text section, the base address is
9718 already provided by the CU attributes. Use
9719 DW_LLE_offset_pair where both addresses are uleb128 encoded
9720 offsets against that base. */
9721 dw2_asm_output_data (1, DW_LLE_offset_pair
,
9722 "DW_LLE_offset_pair (%s)",
9723 list_head
->ll_symbol
);
9724 dw2_asm_output_delta_uleb128 (curr
->begin
, curr
->section
,
9725 "Location list begin address (%s)",
9726 list_head
->ll_symbol
);
9727 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->section
,
9728 "Location list end address (%s)",
9729 list_head
->ll_symbol
);
9731 else if (HAVE_AS_LEB128
)
9733 /* Otherwise, find out how many consecutive entries could share
9734 the same base entry. If just one, emit DW_LLE_start_length,
9735 otherwise emit DW_LLE_base_address for the base address
9736 followed by a series of DW_LLE_offset_pair. */
9737 if (last_section
== NULL
|| curr
->section
!= last_section
)
9739 dw_loc_list_ref curr2
;
9740 for (curr2
= curr
->dw_loc_next
; curr2
!= NULL
;
9741 curr2
= curr2
->dw_loc_next
)
9743 if (strcmp (curr2
->begin
, curr2
->end
) == 0
9748 if (curr2
== NULL
|| curr
->section
!= curr2
->section
)
9749 last_section
= NULL
;
9752 last_section
= curr
->section
;
9753 base_label
= curr
->begin
;
9754 dw2_asm_output_data (1, DW_LLE_base_address
,
9755 "DW_LLE_base_address (%s)",
9756 list_head
->ll_symbol
);
9757 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, base_label
,
9758 "Base address (%s)",
9759 list_head
->ll_symbol
);
9762 /* Only one entry with the same base address. Use
9763 DW_LLE_start_length with absolute address and uleb128
9765 if (last_section
== NULL
)
9767 dw2_asm_output_data (1, DW_LLE_start_length
,
9768 "DW_LLE_start_length (%s)",
9769 list_head
->ll_symbol
);
9770 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
9771 "Location list begin address (%s)",
9772 list_head
->ll_symbol
);
9773 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->begin
,
9774 "Location list length "
9775 "(%s)", list_head
->ll_symbol
);
9777 /* Otherwise emit DW_LLE_offset_pair, relative to above emitted
9778 DW_LLE_base_address. */
9781 dw2_asm_output_data (1, DW_LLE_offset_pair
,
9782 "DW_LLE_offset_pair (%s)",
9783 list_head
->ll_symbol
);
9784 dw2_asm_output_delta_uleb128 (curr
->begin
, base_label
,
9785 "Location list begin address "
9786 "(%s)", list_head
->ll_symbol
);
9787 dw2_asm_output_delta_uleb128 (curr
->end
, base_label
,
9788 "Location list end address "
9789 "(%s)", list_head
->ll_symbol
);
9792 /* The assembler does not support .uleb128 directive. Emit
9793 DW_LLE_start_end with a pair of absolute addresses. */
9796 dw2_asm_output_data (1, DW_LLE_start_end
,
9797 "DW_LLE_start_end (%s)",
9798 list_head
->ll_symbol
);
9799 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
9800 "Location list begin address (%s)",
9801 list_head
->ll_symbol
);
9802 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
9803 "Location list end address (%s)",
9804 list_head
->ll_symbol
);
9807 else if (dwarf_split_debug_info
)
9809 /* For -gsplit-dwarf -gdwarf-{2,3,4} emit index into .debug_addr
9810 and 4 byte length. */
9811 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
9812 "Location list start/length entry (%s)",
9813 list_head
->ll_symbol
);
9814 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
9815 "Location list range start index (%s)",
9817 /* The length field is 4 bytes. If we ever need to support
9818 an 8-byte length, we can add a new DW_LLE code or fall back
9819 to DW_LLE_GNU_start_end_entry. */
9820 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
9821 "Location list range length (%s)",
9822 list_head
->ll_symbol
);
9824 else if (!have_multiple_function_sections
)
9826 /* Pair of relative addresses against start of text section. */
9827 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
9828 "Location list begin address (%s)",
9829 list_head
->ll_symbol
);
9830 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
9831 "Location list end address (%s)",
9832 list_head
->ll_symbol
);
9836 /* Pair of absolute addresses. */
9837 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
9838 "Location list begin address (%s)",
9839 list_head
->ll_symbol
);
9840 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
9841 "Location list end address (%s)",
9842 list_head
->ll_symbol
);
9845 /* Output the block length for this list of location operations. */
9846 if (dwarf_version
>= 5)
9847 dw2_asm_output_data_uleb128 (size
, "Location expression size");
9850 gcc_assert (size
<= 0xffff);
9851 dw2_asm_output_data (2, size
, "Location expression size");
9854 output_loc_sequence (curr
->expr
, -1);
9857 /* And finally list termination. */
9858 if (dwarf_version
>= 5)
9859 dw2_asm_output_data (1, DW_LLE_end_of_list
,
9860 "DW_LLE_end_of_list (%s)", list_head
->ll_symbol
);
9861 else if (dwarf_split_debug_info
)
9862 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
9863 "Location list terminator (%s)",
9864 list_head
->ll_symbol
);
9867 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
9868 "Location list terminator begin (%s)",
9869 list_head
->ll_symbol
);
9870 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
9871 "Location list terminator end (%s)",
9872 list_head
->ll_symbol
);
9876 /* Output a range_list offset into the .debug_ranges or .debug_rnglists
9877 section. Emit a relocated reference if val_entry is NULL, otherwise,
9878 emit an indirect reference. */
9881 output_range_list_offset (dw_attr_node
*a
)
9883 const char *name
= dwarf_attr_name (a
->dw_attr
);
9885 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
9887 if (dwarf_version
>= 5)
9889 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
9890 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, r
->label
,
9891 debug_ranges_section
, "%s", name
);
9895 char *p
= strchr (ranges_section_label
, '\0');
9896 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
9897 a
->dw_attr_val
.v
.val_offset
* 2 * DWARF2_ADDR_SIZE
);
9898 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
9899 debug_ranges_section
, "%s", name
);
9903 else if (dwarf_version
>= 5)
9905 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
9906 gcc_assert (rnglist_idx
);
9907 dw2_asm_output_data_uleb128 (r
->idx
, "%s", name
);
9910 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9911 a
->dw_attr_val
.v
.val_offset
* 2 * DWARF2_ADDR_SIZE
,
9912 "%s (offset from %s)", name
, ranges_section_label
);
9915 /* Output the offset into the debug_loc section. */
9918 output_loc_list_offset (dw_attr_node
*a
)
9920 char *sym
= AT_loc_list (a
)->ll_symbol
;
9923 if (!dwarf_split_debug_info
)
9924 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
9925 "%s", dwarf_attr_name (a
->dw_attr
));
9926 else if (dwarf_version
>= 5)
9928 gcc_assert (AT_loc_list (a
)->num_assigned
);
9929 dw2_asm_output_data_uleb128 (AT_loc_list (a
)->hash
, "%s (%s)",
9930 dwarf_attr_name (a
->dw_attr
),
9934 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
9935 "%s", dwarf_attr_name (a
->dw_attr
));
9938 /* Output an attribute's index or value appropriately. */
9941 output_attr_index_or_value (dw_attr_node
*a
)
9943 const char *name
= dwarf_attr_name (a
->dw_attr
);
9945 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
9947 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
9950 switch (AT_class (a
))
9952 case dw_val_class_addr
:
9953 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
9955 case dw_val_class_high_pc
:
9956 case dw_val_class_lbl_id
:
9957 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
9964 /* Output a type signature. */
9967 output_signature (const char *sig
, const char *name
)
9971 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9972 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
9975 /* Output a discriminant value. */
9978 output_discr_value (dw_discr_value
*discr_value
, const char *name
)
9980 if (discr_value
->pos
)
9981 dw2_asm_output_data_uleb128 (discr_value
->v
.uval
, "%s", name
);
9983 dw2_asm_output_data_sleb128 (discr_value
->v
.sval
, "%s", name
);
9986 /* Output the DIE and its attributes. Called recursively to generate
9987 the definitions of each child DIE. */
9990 output_die (dw_die_ref die
)
9997 /* If someone in another CU might refer to us, set up a symbol for
9998 them to point to. */
9999 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
10000 /* Don't output the symbol twice. For LTO we want the label
10001 on the section beginning, not on the actual DIE. */
10002 && ((!flag_generate_lto
&& !flag_generate_offload
)
10003 || die
->die_tag
!= DW_TAG_compile_unit
))
10004 output_die_symbol (die
);
10006 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
10007 (unsigned long)die
->die_offset
,
10008 dwarf_tag_name (die
->die_tag
));
10010 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
10012 const char *name
= dwarf_attr_name (a
->dw_attr
);
10014 switch (AT_class (a
))
10016 case dw_val_class_addr
:
10017 output_attr_index_or_value (a
);
10020 case dw_val_class_offset
:
10021 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
10025 case dw_val_class_range_list
:
10026 output_range_list_offset (a
);
10029 case dw_val_class_loc
:
10030 size
= size_of_locs (AT_loc (a
));
10032 /* Output the block length for this list of location operations. */
10033 if (dwarf_version
>= 4)
10034 dw2_asm_output_data_uleb128 (size
, "%s", name
);
10036 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
10038 output_loc_sequence (AT_loc (a
), -1);
10041 case dw_val_class_const
:
10042 /* ??? It would be slightly more efficient to use a scheme like is
10043 used for unsigned constants below, but gdb 4.x does not sign
10044 extend. Gdb 5.x does sign extend. */
10045 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
10048 case dw_val_class_unsigned_const
:
10050 int csize
= constant_size (AT_unsigned (a
));
10051 if (dwarf_version
== 3
10052 && a
->dw_attr
== DW_AT_data_member_location
10054 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
10056 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
10060 case dw_val_class_const_implicit
:
10061 if (flag_debug_asm
)
10062 fprintf (asm_out_file
, "\t\t\t%s %s ("
10063 HOST_WIDE_INT_PRINT_DEC
")\n",
10064 ASM_COMMENT_START
, name
, AT_int (a
));
10067 case dw_val_class_unsigned_const_implicit
:
10068 if (flag_debug_asm
)
10069 fprintf (asm_out_file
, "\t\t\t%s %s ("
10070 HOST_WIDE_INT_PRINT_HEX
")\n",
10071 ASM_COMMENT_START
, name
, AT_unsigned (a
));
10074 case dw_val_class_const_double
:
10076 unsigned HOST_WIDE_INT first
, second
;
10078 if (HOST_BITS_PER_WIDE_INT
>= DWARF_LARGEST_DATA_FORM_BITS
)
10079 dw2_asm_output_data (1,
10080 HOST_BITS_PER_DOUBLE_INT
10081 / HOST_BITS_PER_CHAR
,
10084 if (WORDS_BIG_ENDIAN
)
10086 first
= a
->dw_attr_val
.v
.val_double
.high
;
10087 second
= a
->dw_attr_val
.v
.val_double
.low
;
10091 first
= a
->dw_attr_val
.v
.val_double
.low
;
10092 second
= a
->dw_attr_val
.v
.val_double
.high
;
10095 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
10096 first
, "%s", name
);
10097 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
10102 case dw_val_class_wide_int
:
10105 int len
= get_full_len (*a
->dw_attr_val
.v
.val_wide
);
10106 int l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
10107 if (len
* HOST_BITS_PER_WIDE_INT
> DWARF_LARGEST_DATA_FORM_BITS
)
10108 dw2_asm_output_data (1, get_full_len (*a
->dw_attr_val
.v
.val_wide
)
10111 if (WORDS_BIG_ENDIAN
)
10112 for (i
= len
- 1; i
>= 0; --i
)
10114 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
10119 for (i
= 0; i
< len
; ++i
)
10121 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
10128 case dw_val_class_vec
:
10130 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
10131 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
10135 dw2_asm_output_data (constant_size (len
* elt_size
),
10136 len
* elt_size
, "%s", name
);
10137 if (elt_size
> sizeof (HOST_WIDE_INT
))
10142 for (i
= 0, p
= (unsigned char *) a
->dw_attr_val
.v
.val_vec
.array
;
10144 i
++, p
+= elt_size
)
10145 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
10146 "fp or vector constant word %u", i
);
10150 case dw_val_class_flag
:
10151 if (dwarf_version
>= 4)
10153 /* Currently all add_AT_flag calls pass in 1 as last argument,
10154 so DW_FORM_flag_present can be used. If that ever changes,
10155 we'll need to use DW_FORM_flag and have some optimization
10156 in build_abbrev_table that will change those to
10157 DW_FORM_flag_present if it is set to 1 in all DIEs using
10158 the same abbrev entry. */
10159 gcc_assert (AT_flag (a
) == 1);
10160 if (flag_debug_asm
)
10161 fprintf (asm_out_file
, "\t\t\t%s %s\n",
10162 ASM_COMMENT_START
, name
);
10165 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
10168 case dw_val_class_loc_list
:
10169 output_loc_list_offset (a
);
10172 case dw_val_class_die_ref
:
10173 if (AT_ref_external (a
))
10175 if (AT_ref (a
)->comdat_type_p
)
10177 comdat_type_node
*type_node
10178 = AT_ref (a
)->die_id
.die_type_node
;
10180 gcc_assert (type_node
);
10181 output_signature (type_node
->signature
, name
);
10185 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
10189 /* In DWARF2, DW_FORM_ref_addr is sized by target address
10190 length, whereas in DWARF3 it's always sized as an
10192 if (dwarf_version
== 2)
10193 size
= DWARF2_ADDR_SIZE
;
10195 size
= DWARF_OFFSET_SIZE
;
10196 /* ??? We cannot unconditionally output die_offset if
10197 non-zero - others might create references to those
10199 And we do not clear its DIE offset after outputting it
10200 (and the label refers to the actual DIEs, not the
10201 DWARF CU unit header which is when using label + offset
10202 would be the correct thing to do).
10203 ??? This is the reason for the with_offset flag. */
10204 if (AT_ref (a
)->with_offset
)
10205 dw2_asm_output_offset (size
, sym
, AT_ref (a
)->die_offset
,
10206 debug_info_section
, "%s", name
);
10208 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
10214 gcc_assert (AT_ref (a
)->die_offset
);
10215 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
10220 case dw_val_class_fde_ref
:
10222 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
10224 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
10225 a
->dw_attr_val
.v
.val_fde_index
* 2);
10226 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
10231 case dw_val_class_vms_delta
:
10232 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
10233 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
10234 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
10237 dw2_asm_output_delta (DWARF_OFFSET_SIZE
,
10238 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
10243 case dw_val_class_lbl_id
:
10244 output_attr_index_or_value (a
);
10247 case dw_val_class_lineptr
:
10248 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
10249 debug_line_section
, "%s", name
);
10252 case dw_val_class_macptr
:
10253 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
10254 debug_macinfo_section
, "%s", name
);
10257 case dw_val_class_loclistsptr
:
10258 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
10259 debug_loc_section
, "%s", name
);
10262 case dw_val_class_str
:
10263 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
10264 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
10265 a
->dw_attr_val
.v
.val_str
->label
,
10267 "%s: \"%s\"", name
, AT_string (a
));
10268 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_line_strp
)
10269 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
10270 a
->dw_attr_val
.v
.val_str
->label
,
10271 debug_line_str_section
,
10272 "%s: \"%s\"", name
, AT_string (a
));
10273 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
10274 dw2_asm_output_data_uleb128 (AT_index (a
),
10275 "%s: \"%s\"", name
, AT_string (a
));
10277 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
10280 case dw_val_class_file
:
10282 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
10284 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
10285 a
->dw_attr_val
.v
.val_file
->filename
);
10289 case dw_val_class_file_implicit
:
10290 if (flag_debug_asm
)
10291 fprintf (asm_out_file
, "\t\t\t%s %s (%d, %s)\n",
10292 ASM_COMMENT_START
, name
,
10293 maybe_emit_file (a
->dw_attr_val
.v
.val_file
),
10294 a
->dw_attr_val
.v
.val_file
->filename
);
10297 case dw_val_class_data8
:
10301 for (i
= 0; i
< 8; i
++)
10302 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
10303 i
== 0 ? "%s" : NULL
, name
);
10307 case dw_val_class_high_pc
:
10308 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
10309 get_AT_low_pc (die
), "DW_AT_high_pc");
10312 case dw_val_class_discr_value
:
10313 output_discr_value (&a
->dw_attr_val
.v
.val_discr_value
, name
);
10316 case dw_val_class_discr_list
:
10318 dw_discr_list_ref list
= AT_discr_list (a
);
10319 const int size
= size_of_discr_list (list
);
10321 /* This is a block, so output its length first. */
10322 dw2_asm_output_data (constant_size (size
), size
,
10323 "%s: block size", name
);
10325 for (; list
!= NULL
; list
= list
->dw_discr_next
)
10327 /* One byte for the discriminant value descriptor, and then as
10328 many LEB128 numbers as required. */
10329 if (list
->dw_discr_range
)
10330 dw2_asm_output_data (1, DW_DSC_range
,
10331 "%s: DW_DSC_range", name
);
10333 dw2_asm_output_data (1, DW_DSC_label
,
10334 "%s: DW_DSC_label", name
);
10336 output_discr_value (&list
->dw_discr_lower_bound
, name
);
10337 if (list
->dw_discr_range
)
10338 output_discr_value (&list
->dw_discr_upper_bound
, name
);
10344 gcc_unreachable ();
10348 FOR_EACH_CHILD (die
, c
, output_die (c
));
10350 /* Add null byte to terminate sibling list. */
10351 if (die
->die_child
!= NULL
)
10352 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
10353 (unsigned long) die
->die_offset
);
10356 /* Output the compilation unit that appears at the beginning of the
10357 .debug_info section, and precedes the DIE descriptions. */
10360 output_compilation_unit_header (enum dwarf_unit_type ut
)
10362 if (!XCOFF_DEBUGGING_INFO
)
10364 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10365 dw2_asm_output_data (4, 0xffffffff,
10366 "Initial length escape value indicating 64-bit DWARF extension");
10367 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
10368 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
10369 "Length of Compilation Unit Info");
10372 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
10373 if (dwarf_version
>= 5)
10378 case DW_UT_compile
: name
= "DW_UT_compile"; break;
10379 case DW_UT_type
: name
= "DW_UT_type"; break;
10380 case DW_UT_split_compile
: name
= "DW_UT_split_compile"; break;
10381 case DW_UT_split_type
: name
= "DW_UT_split_type"; break;
10382 default: gcc_unreachable ();
10384 dw2_asm_output_data (1, ut
, "%s", name
);
10385 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10387 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
10388 debug_abbrev_section
,
10389 "Offset Into Abbrev. Section");
10390 if (dwarf_version
< 5)
10391 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10394 /* Output the compilation unit DIE and its children. */
10397 output_comp_unit (dw_die_ref die
, int output_if_empty
,
10398 const unsigned char *dwo_id
)
10400 const char *secname
, *oldsym
;
10403 /* Unless we are outputting main CU, we may throw away empty ones. */
10404 if (!output_if_empty
&& die
->die_child
== NULL
)
10407 /* Even if there are no children of this DIE, we must output the information
10408 about the compilation unit. Otherwise, on an empty translation unit, we
10409 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
10410 will then complain when examining the file. First mark all the DIEs in
10411 this CU so we know which get local refs. */
10414 external_ref_hash_type
*extern_map
= optimize_external_refs (die
);
10416 /* For now, optimize only the main CU, in order to optimize the rest
10417 we'd need to see all of them earlier. Leave the rest for post-linking
10419 if (die
== comp_unit_die ())
10420 abbrev_opt_start
= vec_safe_length (abbrev_die_table
);
10422 build_abbrev_table (die
, extern_map
);
10424 optimize_abbrev_table ();
10428 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
10429 next_die_offset
= (dwo_id
10430 ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
10431 : DWARF_COMPILE_UNIT_HEADER_SIZE
);
10432 calc_die_sizes (die
);
10434 oldsym
= die
->die_id
.die_symbol
;
10435 if (oldsym
&& die
->comdat_type_p
)
10437 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
10439 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
10441 die
->die_id
.die_symbol
= NULL
;
10442 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
10446 switch_to_section (debug_info_section
);
10447 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
10448 info_section_emitted
= true;
10451 /* For LTO cross unit DIE refs we want a symbol on the start of the
10452 debuginfo section, not on the CU DIE. */
10453 if ((flag_generate_lto
|| flag_generate_offload
) && oldsym
)
10455 /* ??? No way to get visibility assembled without a decl. */
10456 tree decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
,
10457 get_identifier (oldsym
), char_type_node
);
10458 TREE_PUBLIC (decl
) = true;
10459 TREE_STATIC (decl
) = true;
10460 DECL_ARTIFICIAL (decl
) = true;
10461 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
10462 DECL_VISIBILITY_SPECIFIED (decl
) = true;
10463 targetm
.asm_out
.assemble_visibility (decl
, VISIBILITY_HIDDEN
);
10464 #ifdef ASM_WEAKEN_LABEL
10465 /* We prefer a .weak because that handles duplicates from duplicate
10466 archive members in a graceful way. */
10467 ASM_WEAKEN_LABEL (asm_out_file
, oldsym
);
10469 targetm
.asm_out
.globalize_label (asm_out_file
, oldsym
);
10471 ASM_OUTPUT_LABEL (asm_out_file
, oldsym
);
10474 /* Output debugging information. */
10475 output_compilation_unit_header (dwo_id
10476 ? DW_UT_split_compile
: DW_UT_compile
);
10477 if (dwarf_version
>= 5)
10479 if (dwo_id
!= NULL
)
10480 for (int i
= 0; i
< 8; i
++)
10481 dw2_asm_output_data (1, dwo_id
[i
], i
== 0 ? "DWO id" : NULL
);
10485 /* Leave the marks on the main CU, so we can check them in
10486 output_pubnames. */
10490 die
->die_id
.die_symbol
= oldsym
;
10494 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
10495 and .debug_pubtypes. This is configured per-target, but can be
10496 overridden by the -gpubnames or -gno-pubnames options. */
10499 want_pubnames (void)
10501 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
10503 if (debug_generate_pub_sections
!= -1)
10504 return debug_generate_pub_sections
;
10505 return targetm
.want_debug_pub_sections
;
10508 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
10511 add_AT_pubnames (dw_die_ref die
)
10513 if (want_pubnames ())
10514 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
10517 /* Add a string attribute value to a skeleton DIE. */
10520 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
10524 struct indirect_string_node
*node
;
10526 if (! skeleton_debug_str_hash
)
10527 skeleton_debug_str_hash
10528 = hash_table
<indirect_string_hasher
>::create_ggc (10);
10530 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
10531 find_string_form (node
);
10532 if (node
->form
== DW_FORM_GNU_str_index
)
10533 node
->form
= DW_FORM_strp
;
10535 attr
.dw_attr
= attr_kind
;
10536 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
10537 attr
.dw_attr_val
.val_entry
= NULL
;
10538 attr
.dw_attr_val
.v
.val_str
= node
;
10539 add_dwarf_attr (die
, &attr
);
10542 /* Helper function to generate top-level dies for skeleton debug_info and
10546 add_top_level_skeleton_die_attrs (dw_die_ref die
)
10548 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
10549 const char *comp_dir
= comp_dir_string ();
10551 add_skeleton_AT_string (die
, dwarf_AT (DW_AT_dwo_name
), dwo_file_name
);
10552 if (comp_dir
!= NULL
)
10553 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
10554 add_AT_pubnames (die
);
10555 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
10558 /* Output skeleton debug sections that point to the dwo file. */
10561 output_skeleton_debug_sections (dw_die_ref comp_unit
,
10562 const unsigned char *dwo_id
)
10564 /* These attributes will be found in the full debug_info section. */
10565 remove_AT (comp_unit
, DW_AT_producer
);
10566 remove_AT (comp_unit
, DW_AT_language
);
10568 switch_to_section (debug_skeleton_info_section
);
10569 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
10571 /* Produce the skeleton compilation-unit header. This one differs enough from
10572 a normal CU header that it's better not to call output_compilation_unit
10574 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10575 dw2_asm_output_data (4, 0xffffffff,
10576 "Initial length escape value indicating 64-bit "
10577 "DWARF extension");
10579 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
10580 DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
10581 - DWARF_INITIAL_LENGTH_SIZE
10582 + size_of_die (comp_unit
),
10583 "Length of Compilation Unit Info");
10584 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
10585 if (dwarf_version
>= 5)
10587 dw2_asm_output_data (1, DW_UT_skeleton
, "DW_UT_skeleton");
10588 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10590 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
10591 debug_skeleton_abbrev_section
,
10592 "Offset Into Abbrev. Section");
10593 if (dwarf_version
< 5)
10594 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10596 for (int i
= 0; i
< 8; i
++)
10597 dw2_asm_output_data (1, dwo_id
[i
], i
== 0 ? "DWO id" : NULL
);
10599 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
10600 output_die (comp_unit
);
10602 /* Build the skeleton debug_abbrev section. */
10603 switch_to_section (debug_skeleton_abbrev_section
);
10604 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
10606 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
10608 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
10611 /* Output a comdat type unit DIE and its children. */
10614 output_comdat_type_unit (comdat_type_node
*node
)
10616 const char *secname
;
10619 #if defined (OBJECT_FORMAT_ELF)
10623 /* First mark all the DIEs in this CU so we know which get local refs. */
10624 mark_dies (node
->root_die
);
10626 external_ref_hash_type
*extern_map
= optimize_external_refs (node
->root_die
);
10628 build_abbrev_table (node
->root_die
, extern_map
);
10633 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
10634 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
10635 calc_die_sizes (node
->root_die
);
10637 #if defined (OBJECT_FORMAT_ELF)
10638 if (dwarf_version
>= 5)
10640 if (!dwarf_split_debug_info
)
10641 secname
= ".debug_info";
10643 secname
= ".debug_info.dwo";
10645 else if (!dwarf_split_debug_info
)
10646 secname
= ".debug_types";
10648 secname
= ".debug_types.dwo";
10650 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
10651 sprintf (tmp
, dwarf_version
>= 5 ? "wi." : "wt.");
10652 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
10653 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
10654 comdat_key
= get_identifier (tmp
);
10655 targetm
.asm_out
.named_section (secname
,
10656 SECTION_DEBUG
| SECTION_LINKONCE
,
10659 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
10660 sprintf (tmp
, (dwarf_version
>= 5
10661 ? ".gnu.linkonce.wi." : ".gnu.linkonce.wt."));
10662 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
10663 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
10665 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
10668 /* Output debugging information. */
10669 output_compilation_unit_header (dwarf_split_debug_info
10670 ? DW_UT_split_type
: DW_UT_type
);
10671 output_signature (node
->signature
, "Type Signature");
10672 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
10673 "Offset to Type DIE");
10674 output_die (node
->root_die
);
10676 unmark_dies (node
->root_die
);
10679 /* Return the DWARF2/3 pubname associated with a decl. */
10681 static const char *
10682 dwarf2_name (tree decl
, int scope
)
10684 if (DECL_NAMELESS (decl
))
10686 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
10689 /* Add a new entry to .debug_pubnames if appropriate. */
10692 add_pubname_string (const char *str
, dw_die_ref die
)
10697 e
.name
= xstrdup (str
);
10698 vec_safe_push (pubname_table
, e
);
10702 add_pubname (tree decl
, dw_die_ref die
)
10704 if (!want_pubnames ())
10707 /* Don't add items to the table when we expect that the consumer will have
10708 just read the enclosing die. For example, if the consumer is looking at a
10709 class_member, it will either be inside the class already, or will have just
10710 looked up the class to find the member. Either way, searching the class is
10711 faster than searching the index. */
10712 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
10713 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
10715 const char *name
= dwarf2_name (decl
, 1);
10718 add_pubname_string (name
, die
);
10722 /* Add an enumerator to the pubnames section. */
10725 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
10729 gcc_assert (scope_name
);
10730 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
10732 vec_safe_push (pubname_table
, e
);
10735 /* Add a new entry to .debug_pubtypes if appropriate. */
10738 add_pubtype (tree decl
, dw_die_ref die
)
10742 if (!want_pubnames ())
10745 if ((TREE_PUBLIC (decl
)
10746 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
10747 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
10750 const char *scope_name
= "";
10751 const char *sep
= is_cxx () ? "::" : ".";
10754 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
10755 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
10757 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
10758 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
10759 scope_name
= concat (scope_name
, sep
, NULL
);
10765 name
= type_tag (decl
);
10767 name
= lang_hooks
.dwarf_name (decl
, 1);
10769 /* If we don't have a name for the type, there's no point in adding
10770 it to the table. */
10771 if (name
!= NULL
&& name
[0] != '\0')
10774 e
.name
= concat (scope_name
, name
, NULL
);
10775 vec_safe_push (pubtype_table
, e
);
10778 /* Although it might be more consistent to add the pubinfo for the
10779 enumerators as their dies are created, they should only be added if the
10780 enum type meets the criteria above. So rather than re-check the parent
10781 enum type whenever an enumerator die is created, just output them all
10782 here. This isn't protected by the name conditional because anonymous
10783 enums don't have names. */
10784 if (die
->die_tag
== DW_TAG_enumeration_type
)
10788 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
10793 /* Output a single entry in the pubnames table. */
10796 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
10798 dw_die_ref die
= entry
->die
;
10799 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
10801 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
10803 if (debug_generate_pub_sections
== 2)
10805 /* This logic follows gdb's method for determining the value of the flag
10807 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
10808 switch (die
->die_tag
)
10810 case DW_TAG_typedef
:
10811 case DW_TAG_base_type
:
10812 case DW_TAG_subrange_type
:
10813 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
10814 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
10816 case DW_TAG_enumerator
:
10817 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10818 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
10820 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
10822 case DW_TAG_subprogram
:
10823 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10824 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
10826 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
10828 case DW_TAG_constant
:
10829 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10830 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
10831 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
10833 case DW_TAG_variable
:
10834 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10835 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
10836 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
10838 case DW_TAG_namespace
:
10839 case DW_TAG_imported_declaration
:
10840 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
10842 case DW_TAG_class_type
:
10843 case DW_TAG_interface_type
:
10844 case DW_TAG_structure_type
:
10845 case DW_TAG_union_type
:
10846 case DW_TAG_enumeration_type
:
10847 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
10849 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
10852 /* An unusual tag. Leave the flag-byte empty. */
10855 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
10856 "GDB-index flags");
10859 dw2_asm_output_nstring (entry
->name
, -1, "external name");
10863 /* Output the public names table used to speed up access to externally
10864 visible names; or the public types table used to find type definitions. */
10867 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
10870 unsigned long pubnames_length
= size_of_pubnames (names
);
10871 pubname_entry
*pub
;
10873 if (!XCOFF_DEBUGGING_INFO
)
10875 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10876 dw2_asm_output_data (4, 0xffffffff,
10877 "Initial length escape value indicating 64-bit DWARF extension");
10878 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
10879 "Pub Info Length");
10882 /* Version number for pubnames/pubtypes is independent of dwarf version. */
10883 dw2_asm_output_data (2, 2, "DWARF Version");
10885 if (dwarf_split_debug_info
)
10886 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
10887 debug_skeleton_info_section
,
10888 "Offset of Compilation Unit Info");
10890 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
10891 debug_info_section
,
10892 "Offset of Compilation Unit Info");
10893 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
10894 "Compilation Unit Length");
10896 FOR_EACH_VEC_ELT (*names
, i
, pub
)
10898 if (include_pubname_in_output (names
, pub
))
10900 dw_offset die_offset
= pub
->die
->die_offset
;
10902 /* We shouldn't see pubnames for DIEs outside of the main CU. */
10903 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
10904 gcc_assert (pub
->die
->die_mark
);
10906 /* If we're putting types in their own .debug_types sections,
10907 the .debug_pubtypes table will still point to the compile
10908 unit (not the type unit), so we want to use the offset of
10909 the skeleton DIE (if there is one). */
10910 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
10912 comdat_type_node
*type_node
= pub
->die
->die_id
.die_type_node
;
10914 if (type_node
!= NULL
)
10915 die_offset
= (type_node
->skeleton_die
!= NULL
10916 ? type_node
->skeleton_die
->die_offset
10917 : comp_unit_die ()->die_offset
);
10920 output_pubname (die_offset
, pub
);
10924 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
10927 /* Output public names and types tables if necessary. */
10930 output_pubtables (void)
10932 if (!want_pubnames () || !info_section_emitted
)
10935 switch_to_section (debug_pubnames_section
);
10936 output_pubnames (pubname_table
);
10937 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
10938 It shouldn't hurt to emit it always, since pure DWARF2 consumers
10939 simply won't look for the section. */
10940 switch_to_section (debug_pubtypes_section
);
10941 output_pubnames (pubtype_table
);
10945 /* Output the information that goes into the .debug_aranges table.
10946 Namely, define the beginning and ending address range of the
10947 text section generated for this compilation unit. */
10950 output_aranges (void)
10953 unsigned long aranges_length
= size_of_aranges ();
10955 if (!XCOFF_DEBUGGING_INFO
)
10957 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10958 dw2_asm_output_data (4, 0xffffffff,
10959 "Initial length escape value indicating 64-bit DWARF extension");
10960 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
10961 "Length of Address Ranges Info");
10964 /* Version number for aranges is still 2, even up to DWARF5. */
10965 dw2_asm_output_data (2, 2, "DWARF Version");
10966 if (dwarf_split_debug_info
)
10967 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
10968 debug_skeleton_info_section
,
10969 "Offset of Compilation Unit Info");
10971 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
10972 debug_info_section
,
10973 "Offset of Compilation Unit Info");
10974 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
10975 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
10977 /* We need to align to twice the pointer size here. */
10978 if (DWARF_ARANGES_PAD_SIZE
)
10980 /* Pad using a 2 byte words so that padding is correct for any
10982 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
10983 2 * DWARF2_ADDR_SIZE
);
10984 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
10985 dw2_asm_output_data (2, 0, NULL
);
10988 /* It is necessary not to output these entries if the sections were
10989 not used; if the sections were not used, the length will be 0 and
10990 the address may end up as 0 if the section is discarded by ld
10991 --gc-sections, leaving an invalid (0, 0) entry that can be
10992 confused with the terminator. */
10993 if (text_section_used
)
10995 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
10996 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
10997 text_section_label
, "Length");
10999 if (cold_text_section_used
)
11001 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
11003 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
11004 cold_text_section_label
, "Length");
11007 if (have_multiple_function_sections
)
11012 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
11014 if (DECL_IGNORED_P (fde
->decl
))
11016 if (!fde
->in_std_section
)
11018 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
11020 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
11021 fde
->dw_fde_begin
, "Length");
11023 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
11025 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
11027 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
11028 fde
->dw_fde_second_begin
, "Length");
11033 /* Output the terminator words. */
11034 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11035 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11038 /* Add a new entry to .debug_ranges. Return its index into
11039 ranges_table vector. */
11041 static unsigned int
11042 add_ranges_num (int num
, bool maybe_new_sec
)
11044 dw_ranges r
= { NULL
, num
, 0, maybe_new_sec
};
11045 vec_safe_push (ranges_table
, r
);
11046 return vec_safe_length (ranges_table
) - 1;
11049 /* Add a new entry to .debug_ranges corresponding to a block, or a
11050 range terminator if BLOCK is NULL. MAYBE_NEW_SEC is true if
11051 this entry might be in a different section from previous range. */
11053 static unsigned int
11054 add_ranges (const_tree block
, bool maybe_new_sec
)
11056 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0, maybe_new_sec
);
11059 /* Note that (*rnglist_table)[offset] is either a head of a rnglist
11060 chain, or middle entry of a chain that will be directly referred to. */
11063 note_rnglist_head (unsigned int offset
)
11065 if (dwarf_version
< 5 || (*ranges_table
)[offset
].label
)
11067 (*ranges_table
)[offset
].label
= gen_internal_sym ("LLRL");
11070 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
11071 When using dwarf_split_debug_info, address attributes in dies destined
11072 for the final executable should be direct references--setting the
11073 parameter force_direct ensures this behavior. */
11076 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
11077 bool *added
, bool force_direct
)
11079 unsigned int in_use
= vec_safe_length (ranges_by_label
);
11080 unsigned int offset
;
11081 dw_ranges_by_label rbl
= { begin
, end
};
11082 vec_safe_push (ranges_by_label
, rbl
);
11083 offset
= add_ranges_num (-(int)in_use
- 1, true);
11086 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
11088 note_rnglist_head (offset
);
11092 /* Emit .debug_ranges section. */
11095 output_ranges (void)
11098 static const char *const start_fmt
= "Offset %#x";
11099 const char *fmt
= start_fmt
;
11102 switch_to_section (debug_ranges_section
);
11103 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
11104 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11106 int block_num
= r
->num
;
11110 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11111 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11113 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
11114 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
11116 /* If all code is in the text section, then the compilation
11117 unit base address defaults to DW_AT_low_pc, which is the
11118 base of the text section. */
11119 if (!have_multiple_function_sections
)
11121 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
11122 text_section_label
,
11123 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11124 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
11125 text_section_label
, NULL
);
11128 /* Otherwise, the compilation unit base address is zero,
11129 which allows us to use absolute addresses, and not worry
11130 about whether the target supports cross-section
11134 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11135 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11136 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
11142 /* Negative block_num stands for an index into ranges_by_label. */
11143 else if (block_num
< 0)
11145 int lab_idx
= - block_num
- 1;
11147 if (!have_multiple_function_sections
)
11149 gcc_unreachable ();
11151 /* If we ever use add_ranges_by_labels () for a single
11152 function section, all we have to do is to take out
11153 the #if 0 above. */
11154 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11155 (*ranges_by_label
)[lab_idx
].begin
,
11156 text_section_label
,
11157 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11158 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11159 (*ranges_by_label
)[lab_idx
].end
,
11160 text_section_label
, NULL
);
11165 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11166 (*ranges_by_label
)[lab_idx
].begin
,
11167 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11168 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11169 (*ranges_by_label
)[lab_idx
].end
,
11175 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11176 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11182 /* Non-zero if .debug_line_str should be used for .debug_line section
11183 strings or strings that are likely shareable with those. */
11184 #define DWARF5_USE_DEBUG_LINE_STR \
11185 (!DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET \
11186 && (DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) != 0 \
11187 /* FIXME: there is no .debug_line_str.dwo section, \
11188 for -gsplit-dwarf we should use DW_FORM_strx instead. */ \
11189 && !dwarf_split_debug_info)
11191 /* Assign .debug_rnglists indexes. */
11194 index_rnglists (void)
11199 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11201 r
->idx
= rnglist_idx
++;
11204 /* Emit .debug_rnglists section. */
11207 output_rnglists (void)
11211 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
11212 char l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
11213 char basebuf
[MAX_ARTIFICIAL_LABEL_BYTES
];
11215 switch_to_section (debug_ranges_section
);
11216 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
11217 ASM_GENERATE_INTERNAL_LABEL (l1
, DEBUG_RANGES_SECTION_LABEL
, 2);
11218 ASM_GENERATE_INTERNAL_LABEL (l2
, DEBUG_RANGES_SECTION_LABEL
, 3);
11219 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11220 dw2_asm_output_data (4, 0xffffffff,
11221 "Initial length escape value indicating "
11222 "64-bit DWARF extension");
11223 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
11224 "Length of Range Lists");
11225 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
11226 dw2_asm_output_data (2, dwarf_version
, "DWARF Version");
11227 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
11228 dw2_asm_output_data (1, 0, "Segment Size");
11229 /* Emit the offset table only for -gsplit-dwarf. If we don't care
11230 about relocation sizes and primarily care about the size of .debug*
11231 sections in linked shared libraries and executables, then
11232 the offset table plus corresponding DW_FORM_rnglistx uleb128 indexes
11233 into it are usually larger than just DW_FORM_sec_offset offsets
11234 into the .debug_rnglists section. */
11235 dw2_asm_output_data (4, dwarf_split_debug_info
? rnglist_idx
: 0,
11236 "Offset Entry Count");
11237 if (dwarf_split_debug_info
)
11239 ASM_OUTPUT_LABEL (asm_out_file
, ranges_base_label
);
11240 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11242 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, r
->label
,
11243 ranges_base_label
, NULL
);
11246 const char *lab
= "";
11247 unsigned int len
= vec_safe_length (ranges_table
);
11248 const char *base
= NULL
;
11249 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11251 int block_num
= r
->num
;
11255 ASM_OUTPUT_LABEL (asm_out_file
, r
->label
);
11258 if (HAVE_AS_LEB128
&& (r
->label
|| r
->maybe_new_sec
))
11262 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11263 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11265 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
11266 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
11268 if (HAVE_AS_LEB128
)
11270 /* If all code is in the text section, then the compilation
11271 unit base address defaults to DW_AT_low_pc, which is the
11272 base of the text section. */
11273 if (!have_multiple_function_sections
)
11275 dw2_asm_output_data (1, DW_RLE_offset_pair
,
11276 "DW_RLE_offset_pair (%s)", lab
);
11277 dw2_asm_output_delta_uleb128 (blabel
, text_section_label
,
11278 "Range begin address (%s)", lab
);
11279 dw2_asm_output_delta_uleb128 (elabel
, text_section_label
,
11280 "Range end address (%s)", lab
);
11285 dw_ranges
*r2
= NULL
;
11287 r2
= &(*ranges_table
)[i
+ 1];
11290 && r2
->label
== NULL
11291 && !r2
->maybe_new_sec
)
11293 dw2_asm_output_data (1, DW_RLE_base_address
,
11294 "DW_RLE_base_address (%s)", lab
);
11295 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11296 "Base address (%s)", lab
);
11297 strcpy (basebuf
, blabel
);
11303 dw2_asm_output_data (1, DW_RLE_offset_pair
,
11304 "DW_RLE_offset_pair (%s)", lab
);
11305 dw2_asm_output_delta_uleb128 (blabel
, base
,
11306 "Range begin address (%s)", lab
);
11307 dw2_asm_output_delta_uleb128 (elabel
, base
,
11308 "Range end address (%s)", lab
);
11311 dw2_asm_output_data (1, DW_RLE_start_length
,
11312 "DW_RLE_start_length (%s)", lab
);
11313 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11314 "Range begin address (%s)", lab
);
11315 dw2_asm_output_delta_uleb128 (elabel
, blabel
,
11316 "Range length (%s)", lab
);
11320 dw2_asm_output_data (1, DW_RLE_start_end
,
11321 "DW_RLE_start_end (%s)", lab
);
11322 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11323 "Range begin address (%s)", lab
);
11324 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
,
11325 "Range end address (%s)", lab
);
11329 /* Negative block_num stands for an index into ranges_by_label. */
11330 else if (block_num
< 0)
11332 int lab_idx
= - block_num
- 1;
11333 const char *blabel
= (*ranges_by_label
)[lab_idx
].begin
;
11334 const char *elabel
= (*ranges_by_label
)[lab_idx
].end
;
11336 if (!have_multiple_function_sections
)
11337 gcc_unreachable ();
11338 if (HAVE_AS_LEB128
)
11340 dw2_asm_output_data (1, DW_RLE_start_length
,
11341 "DW_RLE_start_length (%s)", lab
);
11342 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11343 "Range begin address (%s)", lab
);
11344 dw2_asm_output_delta_uleb128 (elabel
, blabel
,
11345 "Range length (%s)", lab
);
11349 dw2_asm_output_data (1, DW_RLE_start_end
,
11350 "DW_RLE_start_end (%s)", lab
);
11351 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11352 "Range begin address (%s)", lab
);
11353 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
,
11354 "Range end address (%s)", lab
);
11358 dw2_asm_output_data (1, DW_RLE_end_of_list
,
11359 "DW_RLE_end_of_list (%s)", lab
);
11361 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
11364 /* Data structure containing information about input files. */
11367 const char *path
; /* Complete file name. */
11368 const char *fname
; /* File name part. */
11369 int length
; /* Length of entire string. */
11370 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
11371 int dir_idx
; /* Index in directory table. */
11374 /* Data structure containing information about directories with source
11378 const char *path
; /* Path including directory name. */
11379 int length
; /* Path length. */
11380 int prefix
; /* Index of directory entry which is a prefix. */
11381 int count
; /* Number of files in this directory. */
11382 int dir_idx
; /* Index of directory used as base. */
11385 /* Callback function for file_info comparison. We sort by looking at
11386 the directories in the path. */
11389 file_info_cmp (const void *p1
, const void *p2
)
11391 const struct file_info
*const s1
= (const struct file_info
*) p1
;
11392 const struct file_info
*const s2
= (const struct file_info
*) p2
;
11393 const unsigned char *cp1
;
11394 const unsigned char *cp2
;
11396 /* Take care of file names without directories. We need to make sure that
11397 we return consistent values to qsort since some will get confused if
11398 we return the same value when identical operands are passed in opposite
11399 orders. So if neither has a directory, return 0 and otherwise return
11400 1 or -1 depending on which one has the directory. */
11401 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
11402 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
11404 cp1
= (const unsigned char *) s1
->path
;
11405 cp2
= (const unsigned char *) s2
->path
;
11411 /* Reached the end of the first path? If so, handle like above. */
11412 if ((cp1
== (const unsigned char *) s1
->fname
)
11413 || (cp2
== (const unsigned char *) s2
->fname
))
11414 return ((cp2
== (const unsigned char *) s2
->fname
)
11415 - (cp1
== (const unsigned char *) s1
->fname
));
11417 /* Character of current path component the same? */
11418 else if (*cp1
!= *cp2
)
11419 return *cp1
- *cp2
;
11423 struct file_name_acquire_data
11425 struct file_info
*files
;
11430 /* Traversal function for the hash table. */
11433 file_name_acquire (dwarf_file_data
**slot
, file_name_acquire_data
*fnad
)
11435 struct dwarf_file_data
*d
= *slot
;
11436 struct file_info
*fi
;
11439 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
11441 if (! d
->emitted_number
)
11444 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
11446 fi
= fnad
->files
+ fnad
->used_files
++;
11448 /* Skip all leading "./". */
11450 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
11453 /* Create a new array entry. */
11455 fi
->length
= strlen (f
);
11458 /* Search for the file name part. */
11459 f
= strrchr (f
, DIR_SEPARATOR
);
11460 #if defined (DIR_SEPARATOR_2)
11462 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
11466 if (f
== NULL
|| f
< g
)
11472 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
11476 /* Helper function for output_file_names. Emit a FORM encoded
11477 string STR, with assembly comment start ENTRY_KIND and
11481 output_line_string (enum dwarf_form form
, const char *str
,
11482 const char *entry_kind
, unsigned int idx
)
11486 case DW_FORM_string
:
11487 dw2_asm_output_nstring (str
, -1, "%s: %#x", entry_kind
, idx
);
11489 case DW_FORM_line_strp
:
11490 if (!debug_line_str_hash
)
11491 debug_line_str_hash
11492 = hash_table
<indirect_string_hasher
>::create_ggc (10);
11494 struct indirect_string_node
*node
;
11495 node
= find_AT_string_in_table (str
, debug_line_str_hash
);
11496 set_indirect_string (node
);
11498 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
11499 debug_line_str_section
, "%s: %#x: \"%s\"",
11500 entry_kind
, 0, node
->str
);
11503 gcc_unreachable ();
11507 /* Output the directory table and the file name table. We try to minimize
11508 the total amount of memory needed. A heuristic is used to avoid large
11509 slowdowns with many input files. */
11512 output_file_names (void)
11514 struct file_name_acquire_data fnad
;
11516 struct file_info
*files
;
11517 struct dir_info
*dirs
;
11525 if (!last_emitted_file
)
11527 if (dwarf_version
>= 5)
11529 dw2_asm_output_data (1, 0, "Directory entry format count");
11530 dw2_asm_output_data_uleb128 (0, "Directories count");
11531 dw2_asm_output_data (1, 0, "File name entry format count");
11532 dw2_asm_output_data_uleb128 (0, "File names count");
11536 dw2_asm_output_data (1, 0, "End directory table");
11537 dw2_asm_output_data (1, 0, "End file name table");
11542 numfiles
= last_emitted_file
->emitted_number
;
11544 /* Allocate the various arrays we need. */
11545 files
= XALLOCAVEC (struct file_info
, numfiles
);
11546 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
11548 fnad
.files
= files
;
11549 fnad
.used_files
= 0;
11550 fnad
.max_files
= numfiles
;
11551 file_table
->traverse
<file_name_acquire_data
*, file_name_acquire
> (&fnad
);
11552 gcc_assert (fnad
.used_files
== fnad
.max_files
);
11554 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
11556 /* Find all the different directories used. */
11557 dirs
[0].path
= files
[0].path
;
11558 dirs
[0].length
= files
[0].fname
- files
[0].path
;
11559 dirs
[0].prefix
= -1;
11561 dirs
[0].dir_idx
= 0;
11562 files
[0].dir_idx
= 0;
11565 for (i
= 1; i
< numfiles
; i
++)
11566 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
11567 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
11568 dirs
[ndirs
- 1].length
) == 0)
11570 /* Same directory as last entry. */
11571 files
[i
].dir_idx
= ndirs
- 1;
11572 ++dirs
[ndirs
- 1].count
;
11578 /* This is a new directory. */
11579 dirs
[ndirs
].path
= files
[i
].path
;
11580 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
11581 dirs
[ndirs
].count
= 1;
11582 dirs
[ndirs
].dir_idx
= ndirs
;
11583 files
[i
].dir_idx
= ndirs
;
11585 /* Search for a prefix. */
11586 dirs
[ndirs
].prefix
= -1;
11587 for (j
= 0; j
< ndirs
; j
++)
11588 if (dirs
[j
].length
< dirs
[ndirs
].length
11589 && dirs
[j
].length
> 1
11590 && (dirs
[ndirs
].prefix
== -1
11591 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
11592 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
11593 dirs
[ndirs
].prefix
= j
;
11598 /* Now to the actual work. We have to find a subset of the directories which
11599 allow expressing the file name using references to the directory table
11600 with the least amount of characters. We do not do an exhaustive search
11601 where we would have to check out every combination of every single
11602 possible prefix. Instead we use a heuristic which provides nearly optimal
11603 results in most cases and never is much off. */
11604 saved
= XALLOCAVEC (int, ndirs
);
11605 savehere
= XALLOCAVEC (int, ndirs
);
11607 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
11608 for (i
= 0; i
< ndirs
; i
++)
11613 /* We can always save some space for the current directory. But this
11614 does not mean it will be enough to justify adding the directory. */
11615 savehere
[i
] = dirs
[i
].length
;
11616 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
11618 for (j
= i
+ 1; j
< ndirs
; j
++)
11621 if (saved
[j
] < dirs
[i
].length
)
11623 /* Determine whether the dirs[i] path is a prefix of the
11627 k
= dirs
[j
].prefix
;
11628 while (k
!= -1 && k
!= (int) i
)
11629 k
= dirs
[k
].prefix
;
11633 /* Yes it is. We can possibly save some memory by
11634 writing the filenames in dirs[j] relative to
11636 savehere
[j
] = dirs
[i
].length
;
11637 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
11642 /* Check whether we can save enough to justify adding the dirs[i]
11644 if (total
> dirs
[i
].length
+ 1)
11646 /* It's worthwhile adding. */
11647 for (j
= i
; j
< ndirs
; j
++)
11648 if (savehere
[j
] > 0)
11650 /* Remember how much we saved for this directory so far. */
11651 saved
[j
] = savehere
[j
];
11653 /* Remember the prefix directory. */
11654 dirs
[j
].dir_idx
= i
;
11659 /* Emit the directory name table. */
11660 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
11661 enum dwarf_form str_form
= DW_FORM_string
;
11662 enum dwarf_form idx_form
= DW_FORM_udata
;
11663 if (dwarf_version
>= 5)
11665 const char *comp_dir
= comp_dir_string ();
11666 if (comp_dir
== NULL
)
11668 dw2_asm_output_data (1, 1, "Directory entry format count");
11669 if (DWARF5_USE_DEBUG_LINE_STR
)
11670 str_form
= DW_FORM_line_strp
;
11671 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
11672 dw2_asm_output_data_uleb128 (str_form
, "%s",
11673 get_DW_FORM_name (str_form
));
11674 dw2_asm_output_data_uleb128 (ndirs
+ idx_offset
, "Directories count");
11675 if (str_form
== DW_FORM_string
)
11677 dw2_asm_output_nstring (comp_dir
, -1, "Directory Entry: %#x", 0);
11678 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
11679 dw2_asm_output_nstring (dirs
[i
].path
,
11681 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
11682 "Directory Entry: %#x", i
+ idx_offset
);
11686 output_line_string (str_form
, comp_dir
, "Directory Entry", 0);
11687 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
11690 = ggc_alloc_string (dirs
[i
].path
,
11692 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
);
11693 output_line_string (str_form
, str
, "Directory Entry",
11694 (unsigned) i
+ idx_offset
);
11700 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
11701 dw2_asm_output_nstring (dirs
[i
].path
,
11703 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
11704 "Directory Entry: %#x", i
+ idx_offset
);
11706 dw2_asm_output_data (1, 0, "End directory table");
11709 /* We have to emit them in the order of emitted_number since that's
11710 used in the debug info generation. To do this efficiently we
11711 generate a back-mapping of the indices first. */
11712 backmap
= XALLOCAVEC (int, numfiles
);
11713 for (i
= 0; i
< numfiles
; i
++)
11714 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
11716 if (dwarf_version
>= 5)
11718 const char *filename0
= get_AT_string (comp_unit_die (), DW_AT_name
);
11719 if (filename0
== NULL
)
11721 /* DW_LNCT_directory_index can use DW_FORM_udata, DW_FORM_data1 and
11722 DW_FORM_data2. Choose one based on the number of directories
11723 and how much space would they occupy in each encoding.
11724 If we have at most 256 directories, all indexes fit into
11725 a single byte, so DW_FORM_data1 is most compact (if there
11726 are at most 128 directories, DW_FORM_udata would be as
11727 compact as that, but not shorter and slower to decode). */
11728 if (ndirs
+ idx_offset
<= 256)
11729 idx_form
= DW_FORM_data1
;
11730 /* If there are more than 65536 directories, we have to use
11731 DW_FORM_udata, DW_FORM_data2 can't refer to them.
11732 Otherwise, compute what space would occupy if all the indexes
11733 used DW_FORM_udata - sum - and compare that to how large would
11734 be DW_FORM_data2 encoding, and pick the more efficient one. */
11735 else if (ndirs
+ idx_offset
<= 65536)
11737 unsigned HOST_WIDE_INT sum
= 1;
11738 for (i
= 0; i
< numfiles
; i
++)
11740 int file_idx
= backmap
[i
];
11741 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
11742 sum
+= size_of_uleb128 (dir_idx
);
11744 if (sum
>= HOST_WIDE_INT_UC (2) * (numfiles
+ 1))
11745 idx_form
= DW_FORM_data2
;
11747 #ifdef VMS_DEBUGGING_INFO
11748 dw2_asm_output_data (1, 4, "File name entry format count");
11750 dw2_asm_output_data (1, 2, "File name entry format count");
11752 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
11753 dw2_asm_output_data_uleb128 (str_form
, "%s",
11754 get_DW_FORM_name (str_form
));
11755 dw2_asm_output_data_uleb128 (DW_LNCT_directory_index
,
11756 "DW_LNCT_directory_index");
11757 dw2_asm_output_data_uleb128 (idx_form
, "%s",
11758 get_DW_FORM_name (idx_form
));
11759 #ifdef VMS_DEBUGGING_INFO
11760 dw2_asm_output_data_uleb128 (DW_LNCT_timestamp
, "DW_LNCT_timestamp");
11761 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
11762 dw2_asm_output_data_uleb128 (DW_LNCT_size
, "DW_LNCT_size");
11763 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
11765 dw2_asm_output_data_uleb128 (numfiles
+ 1, "File names count");
11767 output_line_string (str_form
, filename0
, "File Entry", 0);
11769 /* Include directory index. */
11770 if (idx_form
!= DW_FORM_udata
)
11771 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
11774 dw2_asm_output_data_uleb128 (0, NULL
);
11776 #ifdef VMS_DEBUGGING_INFO
11777 dw2_asm_output_data_uleb128 (0, NULL
);
11778 dw2_asm_output_data_uleb128 (0, NULL
);
11782 /* Now write all the file names. */
11783 for (i
= 0; i
< numfiles
; i
++)
11785 int file_idx
= backmap
[i
];
11786 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
11788 #ifdef VMS_DEBUGGING_INFO
11789 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
11791 /* Setting these fields can lead to debugger miscomparisons,
11792 but VMS Debug requires them to be set correctly. */
11797 int maxfilelen
= (strlen (files
[file_idx
].path
)
11798 + dirs
[dir_idx
].length
11799 + MAX_VMS_VERSION_LEN
+ 1);
11800 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
11802 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
11803 snprintf (filebuf
, maxfilelen
, "%s;%d",
11804 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
11806 output_line_string (str_form
, filebuf
, "File Entry", (unsigned) i
+ 1);
11808 /* Include directory index. */
11809 if (dwarf_version
>= 5 && idx_form
!= DW_FORM_udata
)
11810 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
11811 dir_idx
+ idx_offset
, NULL
);
11813 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
11815 /* Modification time. */
11816 dw2_asm_output_data_uleb128 ((vms_file_stats_name (files
[file_idx
].path
,
11817 &cdt
, 0, 0, 0) == 0)
11820 /* File length in bytes. */
11821 dw2_asm_output_data_uleb128 ((vms_file_stats_name (files
[file_idx
].path
,
11822 0, &siz
, 0, 0) == 0)
11825 output_line_string (str_form
,
11826 files
[file_idx
].path
+ dirs
[dir_idx
].length
,
11827 "File Entry", (unsigned) i
+ 1);
11829 /* Include directory index. */
11830 if (dwarf_version
>= 5 && idx_form
!= DW_FORM_udata
)
11831 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
11832 dir_idx
+ idx_offset
, NULL
);
11834 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
11836 if (dwarf_version
>= 5)
11839 /* Modification time. */
11840 dw2_asm_output_data_uleb128 (0, NULL
);
11842 /* File length in bytes. */
11843 dw2_asm_output_data_uleb128 (0, NULL
);
11844 #endif /* VMS_DEBUGGING_INFO */
11847 if (dwarf_version
< 5)
11848 dw2_asm_output_data (1, 0, "End file name table");
11852 /* Output one line number table into the .debug_line section. */
11855 output_one_line_info_table (dw_line_info_table
*table
)
11857 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
11858 unsigned int current_line
= 1;
11859 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
11860 dw_line_info_entry
*ent
;
11863 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
11865 switch (ent
->opcode
)
11867 case LI_set_address
:
11868 /* ??? Unfortunately, we have little choice here currently, and
11869 must always use the most general form. GCC does not know the
11870 address delta itself, so we can't use DW_LNS_advance_pc. Many
11871 ports do have length attributes which will give an upper bound
11872 on the address range. We could perhaps use length attributes
11873 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
11874 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
11876 /* This can handle any delta. This takes
11877 4+DWARF2_ADDR_SIZE bytes. */
11878 dw2_asm_output_data (1, 0, "set address %s", line_label
);
11879 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
11880 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
11881 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
11885 if (ent
->val
== current_line
)
11887 /* We still need to start a new row, so output a copy insn. */
11888 dw2_asm_output_data (1, DW_LNS_copy
,
11889 "copy line %u", current_line
);
11893 int line_offset
= ent
->val
- current_line
;
11894 int line_delta
= line_offset
- DWARF_LINE_BASE
;
11896 current_line
= ent
->val
;
11897 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
11899 /* This can handle deltas from -10 to 234, using the current
11900 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
11901 This takes 1 byte. */
11902 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
11903 "line %u", current_line
);
11907 /* This can handle any delta. This takes at least 4 bytes,
11908 depending on the value being encoded. */
11909 dw2_asm_output_data (1, DW_LNS_advance_line
,
11910 "advance to line %u", current_line
);
11911 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
11912 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
11918 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
11919 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
11922 case LI_set_column
:
11923 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
11924 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
11927 case LI_negate_stmt
:
11928 current_is_stmt
= !current_is_stmt
;
11929 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
11930 "is_stmt %d", current_is_stmt
);
11933 case LI_set_prologue_end
:
11934 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
11935 "set prologue end");
11938 case LI_set_epilogue_begin
:
11939 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
11940 "set epilogue begin");
11943 case LI_set_discriminator
:
11944 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
11945 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
11946 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
11947 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
11952 /* Emit debug info for the address of the end of the table. */
11953 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
11954 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
11955 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
11956 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
11958 dw2_asm_output_data (1, 0, "end sequence");
11959 dw2_asm_output_data_uleb128 (1, NULL
);
11960 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
11963 /* Output the source line number correspondence information. This
11964 information goes into the .debug_line section. */
11967 output_line_info (bool prologue_only
)
11969 static unsigned int generation
;
11970 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
11971 char p1
[MAX_ARTIFICIAL_LABEL_BYTES
], p2
[MAX_ARTIFICIAL_LABEL_BYTES
];
11972 bool saw_one
= false;
11975 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, generation
);
11976 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, generation
);
11977 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, generation
);
11978 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, generation
++);
11980 if (!XCOFF_DEBUGGING_INFO
)
11982 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11983 dw2_asm_output_data (4, 0xffffffff,
11984 "Initial length escape value indicating 64-bit DWARF extension");
11985 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
11986 "Length of Source Line Info");
11989 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
11991 dw2_asm_output_data (2, dwarf_version
, "DWARF Version");
11992 if (dwarf_version
>= 5)
11994 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
11995 dw2_asm_output_data (1, 0, "Segment Size");
11997 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
11998 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
12000 /* Define the architecture-dependent minimum instruction length (in bytes).
12001 In this implementation of DWARF, this field is used for information
12002 purposes only. Since GCC generates assembly language, we have no
12003 a priori knowledge of how many instruction bytes are generated for each
12004 source line, and therefore can use only the DW_LNE_set_address and
12005 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
12006 this as '1', which is "correct enough" for all architectures,
12007 and don't let the target override. */
12008 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
12010 if (dwarf_version
>= 4)
12011 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
12012 "Maximum Operations Per Instruction");
12013 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
12014 "Default is_stmt_start flag");
12015 dw2_asm_output_data (1, DWARF_LINE_BASE
,
12016 "Line Base Value (Special Opcodes)");
12017 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
12018 "Line Range Value (Special Opcodes)");
12019 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
12020 "Special Opcode Base");
12022 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
12027 case DW_LNS_advance_pc
:
12028 case DW_LNS_advance_line
:
12029 case DW_LNS_set_file
:
12030 case DW_LNS_set_column
:
12031 case DW_LNS_fixed_advance_pc
:
12032 case DW_LNS_set_isa
:
12040 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
12044 /* Write out the information about the files we use. */
12045 output_file_names ();
12046 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
12049 /* Output the marker for the end of the line number info. */
12050 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
12054 if (separate_line_info
)
12056 dw_line_info_table
*table
;
12059 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
12062 output_one_line_info_table (table
);
12066 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
12068 output_one_line_info_table (cold_text_section_line_info
);
12072 /* ??? Some Darwin linkers crash on a .debug_line section with no
12073 sequences. Further, merely a DW_LNE_end_sequence entry is not
12074 sufficient -- the address column must also be initialized.
12075 Make sure to output at least one set_address/end_sequence pair,
12076 choosing .text since that section is always present. */
12077 if (text_section_line_info
->in_use
|| !saw_one
)
12078 output_one_line_info_table (text_section_line_info
);
12080 /* Output the marker for the end of the line number info. */
12081 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
12084 /* Return true if DW_AT_endianity should be emitted according to REVERSE. */
12087 need_endianity_attribute_p (bool reverse
)
12089 return reverse
&& (dwarf_version
>= 3 || !dwarf_strict
);
12092 /* Given a pointer to a tree node for some base type, return a pointer to
12093 a DIE that describes the given type. REVERSE is true if the type is
12094 to be interpreted in the reverse storage order wrt the target order.
12096 This routine must only be called for GCC type nodes that correspond to
12097 Dwarf base (fundamental) types. */
12100 base_type_die (tree type
, bool reverse
)
12102 dw_die_ref base_type_result
;
12103 enum dwarf_type encoding
;
12104 bool fpt_used
= false;
12105 struct fixed_point_type_info fpt_info
;
12106 tree type_bias
= NULL_TREE
;
12108 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
12111 /* If this is a subtype that should not be emitted as a subrange type,
12112 use the base type. See subrange_type_for_debug_p. */
12113 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
12114 type
= TREE_TYPE (type
);
12116 switch (TREE_CODE (type
))
12119 if ((dwarf_version
>= 4 || !dwarf_strict
)
12120 && TYPE_NAME (type
)
12121 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
12122 && DECL_IS_BUILTIN (TYPE_NAME (type
))
12123 && DECL_NAME (TYPE_NAME (type
)))
12125 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
12126 if (strcmp (name
, "char16_t") == 0
12127 || strcmp (name
, "char32_t") == 0)
12129 encoding
= DW_ATE_UTF
;
12133 if ((dwarf_version
>= 3 || !dwarf_strict
)
12134 && lang_hooks
.types
.get_fixed_point_type_info
)
12136 memset (&fpt_info
, 0, sizeof (fpt_info
));
12137 if (lang_hooks
.types
.get_fixed_point_type_info (type
, &fpt_info
))
12140 encoding
= ((TYPE_UNSIGNED (type
))
12141 ? DW_ATE_unsigned_fixed
12142 : DW_ATE_signed_fixed
);
12146 if (TYPE_STRING_FLAG (type
))
12148 if (TYPE_UNSIGNED (type
))
12149 encoding
= DW_ATE_unsigned_char
;
12151 encoding
= DW_ATE_signed_char
;
12153 else if (TYPE_UNSIGNED (type
))
12154 encoding
= DW_ATE_unsigned
;
12156 encoding
= DW_ATE_signed
;
12159 && lang_hooks
.types
.get_type_bias
)
12160 type_bias
= lang_hooks
.types
.get_type_bias (type
);
12164 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
12166 if (dwarf_version
>= 3 || !dwarf_strict
)
12167 encoding
= DW_ATE_decimal_float
;
12169 encoding
= DW_ATE_lo_user
;
12172 encoding
= DW_ATE_float
;
12175 case FIXED_POINT_TYPE
:
12176 if (!(dwarf_version
>= 3 || !dwarf_strict
))
12177 encoding
= DW_ATE_lo_user
;
12178 else if (TYPE_UNSIGNED (type
))
12179 encoding
= DW_ATE_unsigned_fixed
;
12181 encoding
= DW_ATE_signed_fixed
;
12184 /* Dwarf2 doesn't know anything about complex ints, so use
12185 a user defined type for it. */
12187 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
12188 encoding
= DW_ATE_complex_float
;
12190 encoding
= DW_ATE_lo_user
;
12194 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12195 encoding
= DW_ATE_boolean
;
12199 /* No other TREE_CODEs are Dwarf fundamental types. */
12200 gcc_unreachable ();
12203 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
12205 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
12206 int_size_in_bytes (type
));
12207 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
12209 if (need_endianity_attribute_p (reverse
))
12210 add_AT_unsigned (base_type_result
, DW_AT_endianity
,
12211 BYTES_BIG_ENDIAN
? DW_END_little
: DW_END_big
);
12213 add_alignment_attribute (base_type_result
, type
);
12217 switch (fpt_info
.scale_factor_kind
)
12219 case fixed_point_scale_factor_binary
:
12220 add_AT_int (base_type_result
, DW_AT_binary_scale
,
12221 fpt_info
.scale_factor
.binary
);
12224 case fixed_point_scale_factor_decimal
:
12225 add_AT_int (base_type_result
, DW_AT_decimal_scale
,
12226 fpt_info
.scale_factor
.decimal
);
12229 case fixed_point_scale_factor_arbitrary
:
12230 /* Arbitrary scale factors cannot be described in standard DWARF,
12234 /* Describe the scale factor as a rational constant. */
12235 const dw_die_ref scale_factor
12236 = new_die (DW_TAG_constant
, comp_unit_die (), type
);
12238 add_AT_unsigned (scale_factor
, DW_AT_GNU_numerator
,
12239 fpt_info
.scale_factor
.arbitrary
.numerator
);
12240 add_AT_int (scale_factor
, DW_AT_GNU_denominator
,
12241 fpt_info
.scale_factor
.arbitrary
.denominator
);
12243 add_AT_die_ref (base_type_result
, DW_AT_small
, scale_factor
);
12248 gcc_unreachable ();
12253 add_scalar_info (base_type_result
, DW_AT_GNU_bias
, type_bias
,
12254 dw_scalar_form_constant
12255 | dw_scalar_form_exprloc
12256 | dw_scalar_form_reference
,
12259 add_pubtype (type
, base_type_result
);
12261 return base_type_result
;
12264 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
12265 named 'auto' in its type: return true for it, false otherwise. */
12268 is_cxx_auto (tree type
)
12272 tree name
= TYPE_IDENTIFIER (type
);
12273 if (name
== get_identifier ("auto")
12274 || name
== get_identifier ("decltype(auto)"))
12280 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12281 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12284 is_base_type (tree type
)
12286 switch (TREE_CODE (type
))
12292 case FIXED_POINT_TYPE
:
12295 case POINTER_BOUNDS_TYPE
:
12301 case QUAL_UNION_TYPE
:
12302 case ENUMERAL_TYPE
:
12303 case FUNCTION_TYPE
:
12306 case REFERENCE_TYPE
:
12314 if (is_cxx_auto (type
))
12316 gcc_unreachable ();
12322 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12323 node, return the size in bits for the type if it is a constant, or else
12324 return the alignment for the type if the type's size is not constant, or
12325 else return BITS_PER_WORD if the type actually turns out to be an
12326 ERROR_MARK node. */
12328 static inline unsigned HOST_WIDE_INT
12329 simple_type_size_in_bits (const_tree type
)
12331 if (TREE_CODE (type
) == ERROR_MARK
)
12332 return BITS_PER_WORD
;
12333 else if (TYPE_SIZE (type
) == NULL_TREE
)
12335 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
12336 return tree_to_uhwi (TYPE_SIZE (type
));
12338 return TYPE_ALIGN (type
);
12341 /* Similarly, but return an offset_int instead of UHWI. */
12343 static inline offset_int
12344 offset_int_type_size_in_bits (const_tree type
)
12346 if (TREE_CODE (type
) == ERROR_MARK
)
12347 return BITS_PER_WORD
;
12348 else if (TYPE_SIZE (type
) == NULL_TREE
)
12350 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
12351 return wi::to_offset (TYPE_SIZE (type
));
12353 return TYPE_ALIGN (type
);
12356 /* Given a pointer to a tree node for a subrange type, return a pointer
12357 to a DIE that describes the given type. */
12360 subrange_type_die (tree type
, tree low
, tree high
, tree bias
,
12361 dw_die_ref context_die
)
12363 dw_die_ref subrange_die
;
12364 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
12366 if (context_die
== NULL
)
12367 context_die
= comp_unit_die ();
12369 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
12371 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
12373 /* The size of the subrange type and its base type do not match,
12374 so we need to generate a size attribute for the subrange type. */
12375 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
12378 add_alignment_attribute (subrange_die
, type
);
12381 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
, NULL
);
12383 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
, NULL
);
12384 if (bias
&& !dwarf_strict
)
12385 add_scalar_info (subrange_die
, DW_AT_GNU_bias
, bias
,
12386 dw_scalar_form_constant
12387 | dw_scalar_form_exprloc
12388 | dw_scalar_form_reference
,
12391 return subrange_die
;
12394 /* Returns the (const and/or volatile) cv_qualifiers associated with
12395 the decl node. This will normally be augmented with the
12396 cv_qualifiers of the underlying type in add_type_attribute. */
12399 decl_quals (const_tree decl
)
12401 return ((TREE_READONLY (decl
)
12402 /* The C++ front-end correctly marks reference-typed
12403 variables as readonly, but from a language (and debug
12404 info) standpoint they are not const-qualified. */
12405 && TREE_CODE (TREE_TYPE (decl
)) != REFERENCE_TYPE
12406 ? TYPE_QUAL_CONST
: TYPE_UNQUALIFIED
)
12407 | (TREE_THIS_VOLATILE (decl
)
12408 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
));
12411 /* Determine the TYPE whose qualifiers match the largest strict subset
12412 of the given TYPE_QUALS, and return its qualifiers. Ignore all
12413 qualifiers outside QUAL_MASK. */
12416 get_nearest_type_subqualifiers (tree type
, int type_quals
, int qual_mask
)
12419 int best_rank
= 0, best_qual
= 0, max_rank
;
12421 type_quals
&= qual_mask
;
12422 max_rank
= popcount_hwi (type_quals
) - 1;
12424 for (t
= TYPE_MAIN_VARIANT (type
); t
&& best_rank
< max_rank
;
12425 t
= TYPE_NEXT_VARIANT (t
))
12427 int q
= TYPE_QUALS (t
) & qual_mask
;
12429 if ((q
& type_quals
) == q
&& q
!= type_quals
12430 && check_base_type (t
, type
))
12432 int rank
= popcount_hwi (q
);
12434 if (rank
> best_rank
)
12445 struct dwarf_qual_info_t
{ int q
; enum dwarf_tag t
; };
12446 static const dwarf_qual_info_t dwarf_qual_info
[] =
12448 { TYPE_QUAL_CONST
, DW_TAG_const_type
},
12449 { TYPE_QUAL_VOLATILE
, DW_TAG_volatile_type
},
12450 { TYPE_QUAL_RESTRICT
, DW_TAG_restrict_type
},
12451 { TYPE_QUAL_ATOMIC
, DW_TAG_atomic_type
}
12453 static const unsigned int dwarf_qual_info_size
12454 = sizeof (dwarf_qual_info
) / sizeof (dwarf_qual_info
[0]);
12456 /* If DIE is a qualified DIE of some base DIE with the same parent,
12457 return the base DIE, otherwise return NULL. Set MASK to the
12458 qualifiers added compared to the returned DIE. */
12461 qualified_die_p (dw_die_ref die
, int *mask
, unsigned int depth
)
12464 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
12465 if (die
->die_tag
== dwarf_qual_info
[i
].t
)
12467 if (i
== dwarf_qual_info_size
)
12469 if (vec_safe_length (die
->die_attr
) != 1)
12471 dw_die_ref type
= get_AT_ref (die
, DW_AT_type
);
12472 if (type
== NULL
|| type
->die_parent
!= die
->die_parent
)
12474 *mask
|= dwarf_qual_info
[i
].q
;
12477 dw_die_ref ret
= qualified_die_p (type
, mask
, depth
- 1);
12484 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12485 entry that chains the modifiers specified by CV_QUALS in front of the
12486 given type. REVERSE is true if the type is to be interpreted in the
12487 reverse storage order wrt the target order. */
12490 modified_type_die (tree type
, int cv_quals
, bool reverse
,
12491 dw_die_ref context_die
)
12493 enum tree_code code
= TREE_CODE (type
);
12494 dw_die_ref mod_type_die
;
12495 dw_die_ref sub_die
= NULL
;
12496 tree item_type
= NULL
;
12497 tree qualified_type
;
12498 tree name
, low
, high
;
12499 dw_die_ref mod_scope
;
12500 /* Only these cv-qualifiers are currently handled. */
12501 const int cv_qual_mask
= (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
12502 | TYPE_QUAL_RESTRICT
| TYPE_QUAL_ATOMIC
);
12504 if (code
== ERROR_MARK
)
12507 if (lang_hooks
.types
.get_debug_type
)
12509 tree debug_type
= lang_hooks
.types
.get_debug_type (type
);
12511 if (debug_type
!= NULL_TREE
&& debug_type
!= type
)
12512 return modified_type_die (debug_type
, cv_quals
, reverse
, context_die
);
12515 cv_quals
&= cv_qual_mask
;
12517 /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
12518 tag modifier (and not an attribute) old consumers won't be able
12520 if (dwarf_version
< 3)
12521 cv_quals
&= ~TYPE_QUAL_RESTRICT
;
12523 /* Likewise for DW_TAG_atomic_type for DWARFv5. */
12524 if (dwarf_version
< 5)
12525 cv_quals
&= ~TYPE_QUAL_ATOMIC
;
12527 /* See if we already have the appropriately qualified variant of
12529 qualified_type
= get_qualified_type (type
, cv_quals
);
12531 if (qualified_type
== sizetype
)
12533 /* Try not to expose the internal sizetype type's name. */
12534 if (TYPE_NAME (qualified_type
)
12535 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
12537 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
12539 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
12540 && (TYPE_PRECISION (t
)
12541 == TYPE_PRECISION (qualified_type
))
12542 && (TYPE_UNSIGNED (t
)
12543 == TYPE_UNSIGNED (qualified_type
)));
12544 qualified_type
= t
;
12546 else if (qualified_type
== sizetype
12547 && TREE_CODE (sizetype
) == TREE_CODE (size_type_node
)
12548 && TYPE_PRECISION (sizetype
) == TYPE_PRECISION (size_type_node
)
12549 && TYPE_UNSIGNED (sizetype
) == TYPE_UNSIGNED (size_type_node
))
12550 qualified_type
= size_type_node
;
12554 /* If we do, then we can just use its DIE, if it exists. */
12555 if (qualified_type
)
12557 mod_type_die
= lookup_type_die (qualified_type
);
12559 /* DW_AT_endianity doesn't come from a qualifier on the type. */
12561 && (!need_endianity_attribute_p (reverse
)
12562 || !is_base_type (type
)
12563 || get_AT_unsigned (mod_type_die
, DW_AT_endianity
)))
12564 return mod_type_die
;
12567 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
12569 /* Handle C typedef types. */
12570 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
12571 && !DECL_ARTIFICIAL (name
))
12573 tree dtype
= TREE_TYPE (name
);
12575 if (qualified_type
== dtype
)
12577 tree origin
= decl_ultimate_origin (name
);
12579 /* Typedef variants that have an abstract origin don't get their own
12580 type DIE (see gen_typedef_die), so fall back on the ultimate
12581 abstract origin instead. */
12582 if (origin
!= NULL
&& origin
!= name
)
12583 return modified_type_die (TREE_TYPE (origin
), cv_quals
, reverse
,
12586 /* For a named type, use the typedef. */
12587 gen_type_die (qualified_type
, context_die
);
12588 return lookup_type_die (qualified_type
);
12592 int dquals
= TYPE_QUALS_NO_ADDR_SPACE (dtype
);
12593 dquals
&= cv_qual_mask
;
12594 if ((dquals
& ~cv_quals
) != TYPE_UNQUALIFIED
12595 || (cv_quals
== dquals
&& DECL_ORIGINAL_TYPE (name
) != type
))
12596 /* cv-unqualified version of named type. Just use
12597 the unnamed type to which it refers. */
12598 return modified_type_die (DECL_ORIGINAL_TYPE (name
), cv_quals
,
12599 reverse
, context_die
);
12600 /* Else cv-qualified version of named type; fall through. */
12604 mod_scope
= scope_die_for (type
, context_die
);
12608 int sub_quals
= 0, first_quals
= 0;
12610 dw_die_ref first
= NULL
, last
= NULL
;
12612 /* Determine a lesser qualified type that most closely matches
12613 this one. Then generate DW_TAG_* entries for the remaining
12615 sub_quals
= get_nearest_type_subqualifiers (type
, cv_quals
,
12617 if (sub_quals
&& use_debug_types
)
12619 bool needed
= false;
12620 /* If emitting type units, make sure the order of qualifiers
12621 is canonical. Thus, start from unqualified type if
12622 an earlier qualifier is missing in sub_quals, but some later
12623 one is present there. */
12624 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
12625 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
12627 else if (needed
&& (dwarf_qual_info
[i
].q
& cv_quals
))
12633 mod_type_die
= modified_type_die (type
, sub_quals
, reverse
, context_die
);
12634 if (mod_scope
&& mod_type_die
&& mod_type_die
->die_parent
== mod_scope
)
12636 /* As not all intermediate qualified DIEs have corresponding
12637 tree types, ensure that qualified DIEs in the same scope
12638 as their DW_AT_type are emitted after their DW_AT_type,
12639 only with other qualified DIEs for the same type possibly
12640 in between them. Determine the range of such qualified
12641 DIEs now (first being the base type, last being corresponding
12642 last qualified DIE for it). */
12643 unsigned int count
= 0;
12644 first
= qualified_die_p (mod_type_die
, &first_quals
,
12645 dwarf_qual_info_size
);
12647 first
= mod_type_die
;
12648 gcc_assert ((first_quals
& ~sub_quals
) == 0);
12649 for (count
= 0, last
= first
;
12650 count
< (1U << dwarf_qual_info_size
);
12651 count
++, last
= last
->die_sib
)
12654 if (last
== mod_scope
->die_child
)
12656 if (qualified_die_p (last
->die_sib
, &quals
, dwarf_qual_info_size
)
12662 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
12663 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
12666 if (first
&& first
!= last
)
12668 for (d
= first
->die_sib
; ; d
= d
->die_sib
)
12671 qualified_die_p (d
, &quals
, dwarf_qual_info_size
);
12672 if (quals
== (first_quals
| dwarf_qual_info
[i
].q
))
12688 d
= ggc_cleared_alloc
<die_node
> ();
12689 d
->die_tag
= dwarf_qual_info
[i
].t
;
12690 add_child_die_after (mod_scope
, d
, last
);
12694 d
= new_die (dwarf_qual_info
[i
].t
, mod_scope
, type
);
12696 add_AT_die_ref (d
, DW_AT_type
, mod_type_die
);
12698 first_quals
|= dwarf_qual_info
[i
].q
;
12701 else if (code
== POINTER_TYPE
|| code
== REFERENCE_TYPE
)
12703 dwarf_tag tag
= DW_TAG_pointer_type
;
12704 if (code
== REFERENCE_TYPE
)
12706 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
12707 tag
= DW_TAG_rvalue_reference_type
;
12709 tag
= DW_TAG_reference_type
;
12711 mod_type_die
= new_die (tag
, mod_scope
, type
);
12713 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
12714 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
12715 add_alignment_attribute (mod_type_die
, type
);
12716 item_type
= TREE_TYPE (type
);
12718 addr_space_t as
= TYPE_ADDR_SPACE (item_type
);
12719 if (!ADDR_SPACE_GENERIC_P (as
))
12721 int action
= targetm
.addr_space
.debug (as
);
12724 /* Positive values indicate an address_class. */
12725 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, action
);
12729 /* Negative values indicate an (inverted) segment base reg. */
12731 = one_reg_loc_descriptor (~action
, VAR_INIT_STATUS_INITIALIZED
);
12732 add_AT_loc (mod_type_die
, DW_AT_segment
, d
);
12736 else if (code
== INTEGER_TYPE
12737 && TREE_TYPE (type
) != NULL_TREE
12738 && subrange_type_for_debug_p (type
, &low
, &high
))
12740 tree bias
= NULL_TREE
;
12741 if (lang_hooks
.types
.get_type_bias
)
12742 bias
= lang_hooks
.types
.get_type_bias (type
);
12743 mod_type_die
= subrange_type_die (type
, low
, high
, bias
, context_die
);
12744 item_type
= TREE_TYPE (type
);
12746 else if (is_base_type (type
))
12747 mod_type_die
= base_type_die (type
, reverse
);
12750 gen_type_die (type
, context_die
);
12752 /* We have to get the type_main_variant here (and pass that to the
12753 `lookup_type_die' routine) because the ..._TYPE node we have
12754 might simply be a *copy* of some original type node (where the
12755 copy was created to help us keep track of typedef names) and
12756 that copy might have a different TYPE_UID from the original
12758 if (TREE_CODE (type
) == FUNCTION_TYPE
12759 || TREE_CODE (type
) == METHOD_TYPE
)
12761 /* For function/method types, can't just use type_main_variant here,
12762 because that can have different ref-qualifiers for C++,
12763 but try to canonicalize. */
12764 tree main
= TYPE_MAIN_VARIANT (type
);
12765 for (tree t
= main
; t
; t
= TYPE_NEXT_VARIANT (t
))
12766 if (TYPE_QUALS_NO_ADDR_SPACE (t
) == 0
12767 && check_base_type (t
, main
)
12768 && check_lang_type (t
, type
))
12769 return lookup_type_die (t
);
12770 return lookup_type_die (type
);
12772 else if (TREE_CODE (type
) != VECTOR_TYPE
12773 && TREE_CODE (type
) != ARRAY_TYPE
)
12774 return lookup_type_die (type_main_variant (type
));
12776 /* Vectors have the debugging information in the type,
12777 not the main variant. */
12778 return lookup_type_die (type
);
12781 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
12782 don't output a DW_TAG_typedef, since there isn't one in the
12783 user's program; just attach a DW_AT_name to the type.
12784 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
12785 if the base type already has the same name. */
12787 && ((TREE_CODE (name
) != TYPE_DECL
12788 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
12789 || (cv_quals
== TYPE_UNQUALIFIED
)))
12790 || (TREE_CODE (name
) == TYPE_DECL
12791 && TREE_TYPE (name
) == qualified_type
12792 && DECL_NAME (name
))))
12794 if (TREE_CODE (name
) == TYPE_DECL
)
12795 /* Could just call add_name_and_src_coords_attributes here,
12796 but since this is a builtin type it doesn't have any
12797 useful source coordinates anyway. */
12798 name
= DECL_NAME (name
);
12799 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
12801 /* This probably indicates a bug. */
12802 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
12804 name
= TYPE_IDENTIFIER (type
);
12805 add_name_attribute (mod_type_die
,
12806 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
12809 if (qualified_type
)
12810 equate_type_number_to_die (qualified_type
, mod_type_die
);
12813 /* We must do this after the equate_type_number_to_die call, in case
12814 this is a recursive type. This ensures that the modified_type_die
12815 recursion will terminate even if the type is recursive. Recursive
12816 types are possible in Ada. */
12817 sub_die
= modified_type_die (item_type
,
12818 TYPE_QUALS_NO_ADDR_SPACE (item_type
),
12822 if (sub_die
!= NULL
)
12823 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
12825 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
12826 if (TYPE_ARTIFICIAL (type
))
12827 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
12829 return mod_type_die
;
12832 /* Generate DIEs for the generic parameters of T.
12833 T must be either a generic type or a generic function.
12834 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
12837 gen_generic_params_dies (tree t
)
12841 dw_die_ref die
= NULL
;
12844 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
12848 die
= lookup_type_die (t
);
12849 else if (DECL_P (t
))
12850 die
= lookup_decl_die (t
);
12854 parms
= lang_hooks
.get_innermost_generic_parms (t
);
12856 /* T has no generic parameter. It means T is neither a generic type
12857 or function. End of story. */
12860 parms_num
= TREE_VEC_LENGTH (parms
);
12861 args
= lang_hooks
.get_innermost_generic_args (t
);
12862 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
12863 non_default
= int_cst_value (TREE_CHAIN (args
));
12865 non_default
= TREE_VEC_LENGTH (args
);
12866 for (i
= 0; i
< parms_num
; i
++)
12868 tree parm
, arg
, arg_pack_elems
;
12869 dw_die_ref parm_die
;
12871 parm
= TREE_VEC_ELT (parms
, i
);
12872 arg
= TREE_VEC_ELT (args
, i
);
12873 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
12874 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
12876 if (parm
&& TREE_VALUE (parm
) && arg
)
12878 /* If PARM represents a template parameter pack,
12879 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
12880 by DW_TAG_template_*_parameter DIEs for the argument
12881 pack elements of ARG. Note that ARG would then be
12882 an argument pack. */
12883 if (arg_pack_elems
)
12884 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
12888 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
12889 true /* emit name */, die
);
12890 if (i
>= non_default
)
12891 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
12896 /* Create and return a DIE for PARM which should be
12897 the representation of a generic type parameter.
12898 For instance, in the C++ front end, PARM would be a template parameter.
12899 ARG is the argument to PARM.
12900 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
12902 PARENT_DIE is the parent DIE which the new created DIE should be added to,
12903 as a child node. */
12906 generic_parameter_die (tree parm
, tree arg
,
12908 dw_die_ref parent_die
)
12910 dw_die_ref tmpl_die
= NULL
;
12911 const char *name
= NULL
;
12913 if (!parm
|| !DECL_NAME (parm
) || !arg
)
12916 /* We support non-type generic parameters and arguments,
12917 type generic parameters and arguments, as well as
12918 generic generic parameters (a.k.a. template template parameters in C++)
12920 if (TREE_CODE (parm
) == PARM_DECL
)
12921 /* PARM is a nontype generic parameter */
12922 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
12923 else if (TREE_CODE (parm
) == TYPE_DECL
)
12924 /* PARM is a type generic parameter. */
12925 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
12926 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
12927 /* PARM is a generic generic parameter.
12928 Its DIE is a GNU extension. It shall have a
12929 DW_AT_name attribute to represent the name of the template template
12930 parameter, and a DW_AT_GNU_template_name attribute to represent the
12931 name of the template template argument. */
12932 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
12935 gcc_unreachable ();
12941 /* If PARM is a generic parameter pack, it means we are
12942 emitting debug info for a template argument pack element.
12943 In other terms, ARG is a template argument pack element.
12944 In that case, we don't emit any DW_AT_name attribute for
12948 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
12950 add_AT_string (tmpl_die
, DW_AT_name
, name
);
12953 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
12955 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
12956 TMPL_DIE should have a child DW_AT_type attribute that is set
12957 to the type of the argument to PARM, which is ARG.
12958 If PARM is a type generic parameter, TMPL_DIE should have a
12959 child DW_AT_type that is set to ARG. */
12960 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
12961 add_type_attribute (tmpl_die
, tmpl_type
,
12962 (TREE_THIS_VOLATILE (tmpl_type
)
12963 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
),
12964 false, parent_die
);
12968 /* So TMPL_DIE is a DIE representing a
12969 a generic generic template parameter, a.k.a template template
12970 parameter in C++ and arg is a template. */
12972 /* The DW_AT_GNU_template_name attribute of the DIE must be set
12973 to the name of the argument. */
12974 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
12976 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
12979 if (TREE_CODE (parm
) == PARM_DECL
)
12980 /* So PARM is a non-type generic parameter.
12981 DWARF3 5.6.8 says we must set a DW_AT_const_value child
12982 attribute of TMPL_DIE which value represents the value
12984 We must be careful here:
12985 The value of ARG might reference some function decls.
12986 We might currently be emitting debug info for a generic
12987 type and types are emitted before function decls, we don't
12988 know if the function decls referenced by ARG will actually be
12989 emitted after cgraph computations.
12990 So must defer the generation of the DW_AT_const_value to
12991 after cgraph is ready. */
12992 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
12998 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
12999 PARM_PACK must be a template parameter pack. The returned DIE
13000 will be child DIE of PARENT_DIE. */
13003 template_parameter_pack_die (tree parm_pack
,
13004 tree parm_pack_args
,
13005 dw_die_ref parent_die
)
13010 gcc_assert (parent_die
&& parm_pack
);
13012 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
13013 add_name_and_src_coords_attributes (die
, parm_pack
);
13014 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
13015 generic_parameter_die (parm_pack
,
13016 TREE_VEC_ELT (parm_pack_args
, j
),
13017 false /* Don't emit DW_AT_name */,
13022 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
13023 an enumerated type. */
13026 type_is_enum (const_tree type
)
13028 return TREE_CODE (type
) == ENUMERAL_TYPE
;
13031 /* Return the DBX register number described by a given RTL node. */
13033 static unsigned int
13034 dbx_reg_number (const_rtx rtl
)
13036 unsigned regno
= REGNO (rtl
);
13038 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
13040 #ifdef LEAF_REG_REMAP
13041 if (crtl
->uses_only_leaf_regs
)
13043 int leaf_reg
= LEAF_REG_REMAP (regno
);
13044 if (leaf_reg
!= -1)
13045 regno
= (unsigned) leaf_reg
;
13049 regno
= DBX_REGISTER_NUMBER (regno
);
13050 gcc_assert (regno
!= INVALID_REGNUM
);
13054 /* Optionally add a DW_OP_piece term to a location description expression.
13055 DW_OP_piece is only added if the location description expression already
13056 doesn't end with DW_OP_piece. */
13059 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
13061 dw_loc_descr_ref loc
;
13063 if (*list_head
!= NULL
)
13065 /* Find the end of the chain. */
13066 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
13069 if (loc
->dw_loc_opc
!= DW_OP_piece
)
13070 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
13074 /* Return a location descriptor that designates a machine register or
13075 zero if there is none. */
13077 static dw_loc_descr_ref
13078 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
13082 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
13085 /* We only use "frame base" when we're sure we're talking about the
13086 post-prologue local stack frame. We do this by *not* running
13087 register elimination until this point, and recognizing the special
13088 argument pointer and soft frame pointer rtx's.
13089 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
13090 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
13091 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
13093 dw_loc_descr_ref result
= NULL
;
13095 if (dwarf_version
>= 4 || !dwarf_strict
)
13097 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
13100 add_loc_descr (&result
,
13101 new_loc_descr (DW_OP_stack_value
, 0, 0));
13106 regs
= targetm
.dwarf_register_span (rtl
);
13108 if (REG_NREGS (rtl
) > 1 || regs
)
13109 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
13112 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
13113 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
13115 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
13119 /* Return a location descriptor that designates a machine register for
13120 a given hard register number. */
13122 static dw_loc_descr_ref
13123 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
13125 dw_loc_descr_ref reg_loc_descr
;
13129 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
13131 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
13133 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13134 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13136 return reg_loc_descr
;
13139 /* Given an RTL of a register, return a location descriptor that
13140 designates a value that spans more than one register. */
13142 static dw_loc_descr_ref
13143 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
13144 enum var_init_status initialized
)
13147 dw_loc_descr_ref loc_result
= NULL
;
13149 /* Simple, contiguous registers. */
13150 if (regs
== NULL_RTX
)
13152 unsigned reg
= REGNO (rtl
);
13155 #ifdef LEAF_REG_REMAP
13156 if (crtl
->uses_only_leaf_regs
)
13158 int leaf_reg
= LEAF_REG_REMAP (reg
);
13159 if (leaf_reg
!= -1)
13160 reg
= (unsigned) leaf_reg
;
13164 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
13165 nregs
= REG_NREGS (rtl
);
13167 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
13172 dw_loc_descr_ref t
;
13174 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
13175 VAR_INIT_STATUS_INITIALIZED
);
13176 add_loc_descr (&loc_result
, t
);
13177 add_loc_descr_op_piece (&loc_result
, size
);
13183 /* Now onto stupid register sets in non contiguous locations. */
13185 gcc_assert (GET_CODE (regs
) == PARALLEL
);
13187 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
13190 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
13192 dw_loc_descr_ref t
;
13194 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
13195 VAR_INIT_STATUS_INITIALIZED
);
13196 add_loc_descr (&loc_result
, t
);
13197 add_loc_descr_op_piece (&loc_result
, size
);
13200 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13201 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13205 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
13207 /* Return a location descriptor that designates a constant i,
13208 as a compound operation from constant (i >> shift), constant shift
13211 static dw_loc_descr_ref
13212 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
13214 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
13215 add_loc_descr (&ret
, int_loc_descriptor (shift
));
13216 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
13220 /* Return a location descriptor that designates a constant. */
13222 static dw_loc_descr_ref
13223 int_loc_descriptor (HOST_WIDE_INT i
)
13225 enum dwarf_location_atom op
;
13227 /* Pick the smallest representation of a constant, rather than just
13228 defaulting to the LEB encoding. */
13231 int clz
= clz_hwi (i
);
13232 int ctz
= ctz_hwi (i
);
13234 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
13235 else if (i
<= 0xff)
13236 op
= DW_OP_const1u
;
13237 else if (i
<= 0xffff)
13238 op
= DW_OP_const2u
;
13239 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
13240 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
13241 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
13242 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
13243 while DW_OP_const4u is 5 bytes. */
13244 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
13245 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13246 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
13247 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
13248 while DW_OP_const4u is 5 bytes. */
13249 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
13251 else if (DWARF2_ADDR_SIZE
== 4 && i
> 0x7fffffff
13252 && size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
)
13255 /* As i >= 2**31, the double cast above will yield a negative number.
13256 Since wrapping is defined in DWARF expressions we can output big
13257 positive integers as small negative ones, regardless of the size
13260 Here, since the evaluator will handle 32-bit values and since i >=
13261 2**31, we know it's going to be interpreted as a negative literal:
13262 store it this way if we can do better than 5 bytes this way. */
13263 return int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
);
13265 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
13266 op
= DW_OP_const4u
;
13268 /* Past this point, i >= 0x100000000 and thus DW_OP_constu will take at
13269 least 6 bytes: see if we can do better before falling back to it. */
13270 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13271 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
13272 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes. */
13273 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
13274 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
13275 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
13276 >= HOST_BITS_PER_WIDE_INT
)
13277 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
13278 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes. */
13279 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
13280 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
13281 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
13282 && size_of_uleb128 (i
) > 6)
13283 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
13284 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
13291 op
= DW_OP_const1s
;
13292 else if (i
>= -0x8000)
13293 op
= DW_OP_const2s
;
13294 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
13296 if (size_of_int_loc_descriptor (i
) < 5)
13298 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
13299 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
13302 op
= DW_OP_const4s
;
13306 if (size_of_int_loc_descriptor (i
)
13307 < (unsigned long) 1 + size_of_sleb128 (i
))
13309 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
13310 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
13317 return new_loc_descr (op
, i
, 0);
13320 /* Likewise, for unsigned constants. */
13322 static dw_loc_descr_ref
13323 uint_loc_descriptor (unsigned HOST_WIDE_INT i
)
13325 const unsigned HOST_WIDE_INT max_int
= INTTYPE_MAXIMUM (HOST_WIDE_INT
);
13326 const unsigned HOST_WIDE_INT max_uint
13327 = INTTYPE_MAXIMUM (unsigned HOST_WIDE_INT
);
13329 /* If possible, use the clever signed constants handling. */
13331 return int_loc_descriptor ((HOST_WIDE_INT
) i
);
13333 /* Here, we are left with positive numbers that cannot be represented as
13334 HOST_WIDE_INT, i.e.:
13335 max (HOST_WIDE_INT) < i <= max (unsigned HOST_WIDE_INT)
13337 Using DW_OP_const4/8/./u operation to encode them consumes a lot of bytes
13338 whereas may be better to output a negative integer: thanks to integer
13339 wrapping, we know that:
13340 x = x - 2 ** DWARF2_ADDR_SIZE
13341 = x - 2 * (max (HOST_WIDE_INT) + 1)
13342 So numbers close to max (unsigned HOST_WIDE_INT) could be represented as
13343 small negative integers. Let's try that in cases it will clearly improve
13344 the encoding: there is no gain turning DW_OP_const4u into
13346 if (DWARF2_ADDR_SIZE
* 8 == HOST_BITS_PER_WIDE_INT
13347 && ((DWARF2_ADDR_SIZE
== 4 && i
> max_uint
- 0x8000)
13348 || (DWARF2_ADDR_SIZE
== 8 && i
> max_uint
- 0x80000000)))
13350 const unsigned HOST_WIDE_INT first_shift
= i
- max_int
- 1;
13352 /* Now, -1 < first_shift <= max (HOST_WIDE_INT)
13353 i.e. 0 <= first_shift <= max (HOST_WIDE_INT). */
13354 const HOST_WIDE_INT second_shift
13355 = (HOST_WIDE_INT
) first_shift
- (HOST_WIDE_INT
) max_int
- 1;
13357 /* So we finally have:
13358 -max (HOST_WIDE_INT) - 1 <= second_shift <= -1.
13359 i.e. min (HOST_WIDE_INT) <= second_shift < 0. */
13360 return int_loc_descriptor (second_shift
);
13363 /* Last chance: fallback to a simple constant operation. */
13364 return new_loc_descr
13365 ((HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
13371 /* Generate and return a location description that computes the unsigned
13372 comparison of the two stack top entries (a OP b where b is the top-most
13373 entry and a is the second one). The KIND of comparison can be LT_EXPR,
13374 LE_EXPR, GT_EXPR or GE_EXPR. */
13376 static dw_loc_descr_ref
13377 uint_comparison_loc_list (enum tree_code kind
)
13379 enum dwarf_location_atom op
, flip_op
;
13380 dw_loc_descr_ref ret
, bra_node
, jmp_node
, tmp
;
13397 gcc_unreachable ();
13400 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
13401 jmp_node
= new_loc_descr (DW_OP_skip
, 0, 0);
13403 /* Until DWARFv4, operations all work on signed integers. It is nevertheless
13404 possible to perform unsigned comparisons: we just have to distinguish
13407 1. when a and b have the same sign (as signed integers); then we should
13408 return: a OP(signed) b;
13410 2. when a is a negative signed integer while b is a positive one, then a
13411 is a greater unsigned integer than b; likewise when a and b's roles
13414 So first, compare the sign of the two operands. */
13415 ret
= new_loc_descr (DW_OP_over
, 0, 0);
13416 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
13417 add_loc_descr (&ret
, new_loc_descr (DW_OP_xor
, 0, 0));
13418 /* If they have different signs (i.e. they have different sign bits), then
13419 the stack top value has now the sign bit set and thus it's smaller than
13421 add_loc_descr (&ret
, new_loc_descr (DW_OP_lit0
, 0, 0));
13422 add_loc_descr (&ret
, new_loc_descr (DW_OP_lt
, 0, 0));
13423 add_loc_descr (&ret
, bra_node
);
13425 /* We are in case 1. At this point, we know both operands have the same
13426 sign, to it's safe to use the built-in signed comparison. */
13427 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
13428 add_loc_descr (&ret
, jmp_node
);
13430 /* We are in case 2. Here, we know both operands do not have the same sign,
13431 so we have to flip the signed comparison. */
13432 flip_op
= (kind
== LT_EXPR
|| kind
== LE_EXPR
) ? DW_OP_gt
: DW_OP_lt
;
13433 tmp
= new_loc_descr (flip_op
, 0, 0);
13434 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13435 bra_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
13436 add_loc_descr (&ret
, tmp
);
13438 /* This dummy operation is necessary to make the two branches join. */
13439 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
13440 jmp_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13441 jmp_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
13442 add_loc_descr (&ret
, tmp
);
13447 /* Likewise, but takes the location description lists (might be destructive on
13448 them). Return NULL if either is NULL or if concatenation fails. */
13450 static dw_loc_list_ref
13451 loc_list_from_uint_comparison (dw_loc_list_ref left
, dw_loc_list_ref right
,
13452 enum tree_code kind
)
13454 if (left
== NULL
|| right
== NULL
)
13457 add_loc_list (&left
, right
);
13461 add_loc_descr_to_each (left
, uint_comparison_loc_list (kind
));
13465 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
13466 without actually allocating it. */
13468 static unsigned long
13469 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
13471 return size_of_int_loc_descriptor (i
>> shift
)
13472 + size_of_int_loc_descriptor (shift
)
13476 /* Return size_of_locs (int_loc_descriptor (i)) without
13477 actually allocating it. */
13479 static unsigned long
13480 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
13489 else if (i
<= 0xff)
13491 else if (i
<= 0xffff)
13495 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
13496 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
13497 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13499 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13500 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
13501 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13503 else if (DWARF2_ADDR_SIZE
== 4 && i
> 0x7fffffff
13504 && size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
)
13506 return size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
);
13507 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
13509 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
13510 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13511 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
13512 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13514 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
13515 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
13516 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13518 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
13519 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
13521 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13530 else if (i
>= -0x8000)
13532 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
13534 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
13536 s
= size_of_int_loc_descriptor (-i
) + 1;
13544 unsigned long r
= 1 + size_of_sleb128 (i
);
13545 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
13547 s
= size_of_int_loc_descriptor (-i
) + 1;
13556 /* Return loc description representing "address" of integer value.
13557 This can appear only as toplevel expression. */
13559 static dw_loc_descr_ref
13560 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
13563 dw_loc_descr_ref loc_result
= NULL
;
13565 if (!(dwarf_version
>= 4 || !dwarf_strict
))
13568 litsize
= size_of_int_loc_descriptor (i
);
13569 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13570 is more compact. For DW_OP_stack_value we need:
13571 litsize + 1 (DW_OP_stack_value)
13572 and for DW_OP_implicit_value:
13573 1 (DW_OP_implicit_value) + 1 (length) + size. */
13574 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
13576 loc_result
= int_loc_descriptor (i
);
13577 add_loc_descr (&loc_result
,
13578 new_loc_descr (DW_OP_stack_value
, 0, 0));
13582 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13584 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13585 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
13589 /* Return a location descriptor that designates a base+offset location. */
13591 static dw_loc_descr_ref
13592 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
13593 enum var_init_status initialized
)
13595 unsigned int regno
;
13596 dw_loc_descr_ref result
;
13597 dw_fde_ref fde
= cfun
->fde
;
13599 /* We only use "frame base" when we're sure we're talking about the
13600 post-prologue local stack frame. We do this by *not* running
13601 register elimination until this point, and recognizing the special
13602 argument pointer and soft frame pointer rtx's. */
13603 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
13605 rtx elim
= (ira_use_lra_p
13606 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
13607 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
13611 if (GET_CODE (elim
) == PLUS
)
13613 offset
+= INTVAL (XEXP (elim
, 1));
13614 elim
= XEXP (elim
, 0);
13616 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13617 && (elim
== hard_frame_pointer_rtx
13618 || elim
== stack_pointer_rtx
))
13619 || elim
== (frame_pointer_needed
13620 ? hard_frame_pointer_rtx
13621 : stack_pointer_rtx
));
13623 /* If drap register is used to align stack, use frame
13624 pointer + offset to access stack variables. If stack
13625 is aligned without drap, use stack pointer + offset to
13626 access stack variables. */
13627 if (crtl
->stack_realign_tried
13628 && reg
== frame_pointer_rtx
)
13631 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
13632 ? HARD_FRAME_POINTER_REGNUM
13634 return new_reg_loc_descr (base_reg
, offset
);
13637 gcc_assert (frame_pointer_fb_offset_valid
);
13638 offset
+= frame_pointer_fb_offset
;
13639 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
13643 regno
= REGNO (reg
);
13644 #ifdef LEAF_REG_REMAP
13645 if (crtl
->uses_only_leaf_regs
)
13647 int leaf_reg
= LEAF_REG_REMAP (regno
);
13648 if (leaf_reg
!= -1)
13649 regno
= (unsigned) leaf_reg
;
13652 regno
= DWARF_FRAME_REGNUM (regno
);
13654 if (!optimize
&& fde
13655 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
13657 /* Use cfa+offset to represent the location of arguments passed
13658 on the stack when drap is used to align stack.
13659 Only do this when not optimizing, for optimized code var-tracking
13660 is supposed to track where the arguments live and the register
13661 used as vdrap or drap in some spot might be used for something
13662 else in other part of the routine. */
13663 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
13667 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
13670 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
13672 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13673 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13678 /* Return true if this RTL expression describes a base+offset calculation. */
13681 is_based_loc (const_rtx rtl
)
13683 return (GET_CODE (rtl
) == PLUS
13684 && ((REG_P (XEXP (rtl
, 0))
13685 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
13686 && CONST_INT_P (XEXP (rtl
, 1)))));
13689 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13692 static dw_loc_descr_ref
13693 tls_mem_loc_descriptor (rtx mem
)
13696 dw_loc_descr_ref loc_result
;
13698 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
13701 base
= get_base_address (MEM_EXPR (mem
));
13704 || !DECL_THREAD_LOCAL_P (base
))
13707 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1, NULL
);
13708 if (loc_result
== NULL
)
13711 if (MEM_OFFSET (mem
))
13712 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
13717 /* Output debug info about reason why we failed to expand expression as dwarf
13721 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
13723 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
13725 fprintf (dump_file
, "Failed to expand as dwarf: ");
13727 print_generic_expr (dump_file
, expr
, dump_flags
);
13730 fprintf (dump_file
, "\n");
13731 print_rtl (dump_file
, rtl
);
13733 fprintf (dump_file
, "\nReason: %s\n", reason
);
13737 /* Helper function for const_ok_for_output. */
13740 const_ok_for_output_1 (rtx rtl
)
13742 if (GET_CODE (rtl
) == UNSPEC
)
13744 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
13745 we can't express it in the debug info. */
13746 /* Don't complain about TLS UNSPECs, those are just too hard to
13747 delegitimize. Note this could be a non-decl SYMBOL_REF such as
13748 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
13749 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
13751 && (XVECLEN (rtl
, 0) == 0
13752 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
13753 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
))
13754 inform (current_function_decl
13755 ? DECL_SOURCE_LOCATION (current_function_decl
)
13756 : UNKNOWN_LOCATION
,
13757 #if NUM_UNSPEC_VALUES > 0
13758 "non-delegitimized UNSPEC %s (%d) found in variable location",
13759 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
13760 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
13763 "non-delegitimized UNSPEC %d found in variable location",
13766 expansion_failed (NULL_TREE
, rtl
,
13767 "UNSPEC hasn't been delegitimized.\n");
13771 if (targetm
.const_not_ok_for_debug_p (rtl
))
13773 expansion_failed (NULL_TREE
, rtl
,
13774 "Expression rejected for debug by the backend.\n");
13778 /* FIXME: Refer to PR60655. It is possible for simplification
13779 of rtl expressions in var tracking to produce such expressions.
13780 We should really identify / validate expressions
13781 enclosed in CONST that can be handled by assemblers on various
13782 targets and only handle legitimate cases here. */
13783 if (GET_CODE (rtl
) != SYMBOL_REF
)
13785 if (GET_CODE (rtl
) == NOT
)
13790 if (CONSTANT_POOL_ADDRESS_P (rtl
))
13793 get_pool_constant_mark (rtl
, &marked
);
13794 /* If all references to this pool constant were optimized away,
13795 it was not output and thus we can't represent it. */
13798 expansion_failed (NULL_TREE
, rtl
,
13799 "Constant was removed from constant pool.\n");
13804 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
13807 /* Avoid references to external symbols in debug info, on several targets
13808 the linker might even refuse to link when linking a shared library,
13809 and in many other cases the relocations for .debug_info/.debug_loc are
13810 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13811 to be defined within the same shared library or executable are fine. */
13812 if (SYMBOL_REF_EXTERNAL_P (rtl
))
13814 tree decl
= SYMBOL_REF_DECL (rtl
);
13816 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
13818 expansion_failed (NULL_TREE
, rtl
,
13819 "Symbol not defined in current TU.\n");
13827 /* Return true if constant RTL can be emitted in DW_OP_addr or
13828 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13829 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13832 const_ok_for_output (rtx rtl
)
13834 if (GET_CODE (rtl
) == SYMBOL_REF
)
13835 return const_ok_for_output_1 (rtl
);
13837 if (GET_CODE (rtl
) == CONST
)
13839 subrtx_var_iterator::array_type array
;
13840 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 0), ALL
)
13841 if (!const_ok_for_output_1 (*iter
))
13849 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
13850 if possible, NULL otherwise. */
13853 base_type_for_mode (machine_mode mode
, bool unsignedp
)
13855 dw_die_ref type_die
;
13856 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
13860 switch (TREE_CODE (type
))
13868 type_die
= lookup_type_die (type
);
13870 type_die
= modified_type_die (type
, TYPE_UNQUALIFIED
, false,
13872 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
13877 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
13878 type matching MODE, or, if MODE is narrower than or as wide as
13879 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
13882 static dw_loc_descr_ref
13883 convert_descriptor_to_mode (machine_mode mode
, dw_loc_descr_ref op
)
13885 machine_mode outer_mode
= mode
;
13886 dw_die_ref type_die
;
13887 dw_loc_descr_ref cvt
;
13889 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
13891 add_loc_descr (&op
, new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0));
13894 type_die
= base_type_for_mode (outer_mode
, 1);
13895 if (type_die
== NULL
)
13897 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
13898 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13899 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13900 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13901 add_loc_descr (&op
, cvt
);
13905 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
13907 static dw_loc_descr_ref
13908 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
13909 dw_loc_descr_ref op1
)
13911 dw_loc_descr_ref ret
= op0
;
13912 add_loc_descr (&ret
, op1
);
13913 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
13914 if (STORE_FLAG_VALUE
!= 1)
13916 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
13917 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
13922 /* Return location descriptor for signed comparison OP RTL. */
13924 static dw_loc_descr_ref
13925 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
13926 machine_mode mem_mode
)
13928 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
13929 dw_loc_descr_ref op0
, op1
;
13932 if (op_mode
== VOIDmode
)
13933 op_mode
= GET_MODE (XEXP (rtl
, 1));
13934 if (op_mode
== VOIDmode
)
13938 && dwarf_version
< 5
13939 && (!SCALAR_INT_MODE_P (op_mode
)
13940 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
13943 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
13944 VAR_INIT_STATUS_INITIALIZED
);
13945 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
13946 VAR_INIT_STATUS_INITIALIZED
);
13948 if (op0
== NULL
|| op1
== NULL
)
13951 if (!SCALAR_INT_MODE_P (op_mode
)
13952 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
13953 return compare_loc_descriptor (op
, op0
, op1
);
13955 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
13957 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
13958 dw_loc_descr_ref cvt
;
13960 if (type_die
== NULL
)
13962 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
13963 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13964 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13965 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13966 add_loc_descr (&op0
, cvt
);
13967 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
13968 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13969 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13970 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13971 add_loc_descr (&op1
, cvt
);
13972 return compare_loc_descriptor (op
, op0
, op1
);
13975 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
13976 /* For eq/ne, if the operands are known to be zero-extended,
13977 there is no need to do the fancy shifting up. */
13978 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
13980 dw_loc_descr_ref last0
, last1
;
13981 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
13983 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
13985 /* deref_size zero extends, and for constants we can check
13986 whether they are zero extended or not. */
13987 if (((last0
->dw_loc_opc
== DW_OP_deref_size
13988 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
13989 || (CONST_INT_P (XEXP (rtl
, 0))
13990 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
13991 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
13992 && ((last1
->dw_loc_opc
== DW_OP_deref_size
13993 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
13994 || (CONST_INT_P (XEXP (rtl
, 1))
13995 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
13996 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
13997 return compare_loc_descriptor (op
, op0
, op1
);
13999 /* EQ/NE comparison against constant in narrower type than
14000 DWARF2_ADDR_SIZE can be performed either as
14001 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
14004 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
14005 DW_OP_{eq,ne}. Pick whatever is shorter. */
14006 if (CONST_INT_P (XEXP (rtl
, 1))
14007 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
14008 && (size_of_int_loc_descriptor (shift
) + 1
14009 + size_of_int_loc_descriptor (UINTVAL (XEXP (rtl
, 1)) << shift
)
14010 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
14011 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
14012 & GET_MODE_MASK (op_mode
))))
14014 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
14015 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
14016 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
14017 & GET_MODE_MASK (op_mode
));
14018 return compare_loc_descriptor (op
, op0
, op1
);
14021 add_loc_descr (&op0
, int_loc_descriptor (shift
));
14022 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
14023 if (CONST_INT_P (XEXP (rtl
, 1)))
14024 op1
= int_loc_descriptor (UINTVAL (XEXP (rtl
, 1)) << shift
);
14027 add_loc_descr (&op1
, int_loc_descriptor (shift
));
14028 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
14030 return compare_loc_descriptor (op
, op0
, op1
);
14033 /* Return location descriptor for unsigned comparison OP RTL. */
14035 static dw_loc_descr_ref
14036 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
14037 machine_mode mem_mode
)
14039 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
14040 dw_loc_descr_ref op0
, op1
;
14042 if (op_mode
== VOIDmode
)
14043 op_mode
= GET_MODE (XEXP (rtl
, 1));
14044 if (op_mode
== VOIDmode
)
14046 if (!SCALAR_INT_MODE_P (op_mode
))
14050 && dwarf_version
< 5
14051 && GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
14054 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
14055 VAR_INIT_STATUS_INITIALIZED
);
14056 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
14057 VAR_INIT_STATUS_INITIALIZED
);
14059 if (op0
== NULL
|| op1
== NULL
)
14062 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
14064 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
14065 dw_loc_descr_ref last0
, last1
;
14066 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
14068 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
14070 if (CONST_INT_P (XEXP (rtl
, 0)))
14071 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
14072 /* deref_size zero extends, so no need to mask it again. */
14073 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
14074 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
14076 add_loc_descr (&op0
, int_loc_descriptor (mask
));
14077 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
14079 if (CONST_INT_P (XEXP (rtl
, 1)))
14080 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
14081 /* deref_size zero extends, so no need to mask it again. */
14082 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
14083 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
14085 add_loc_descr (&op1
, int_loc_descriptor (mask
));
14086 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
14089 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
14091 HOST_WIDE_INT bias
= 1;
14092 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
14093 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14094 if (CONST_INT_P (XEXP (rtl
, 1)))
14095 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
14096 + INTVAL (XEXP (rtl
, 1)));
14098 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
14101 return compare_loc_descriptor (op
, op0
, op1
);
14104 /* Return location descriptor for {U,S}{MIN,MAX}. */
14106 static dw_loc_descr_ref
14107 minmax_loc_descriptor (rtx rtl
, machine_mode mode
,
14108 machine_mode mem_mode
)
14110 enum dwarf_location_atom op
;
14111 dw_loc_descr_ref op0
, op1
, ret
;
14112 dw_loc_descr_ref bra_node
, drop_node
;
14115 && dwarf_version
< 5
14116 && (!SCALAR_INT_MODE_P (mode
)
14117 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
14120 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14121 VAR_INIT_STATUS_INITIALIZED
);
14122 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
14123 VAR_INIT_STATUS_INITIALIZED
);
14125 if (op0
== NULL
|| op1
== NULL
)
14128 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
14129 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
14130 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
14131 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
14133 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
14135 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
14136 add_loc_descr (&op0
, int_loc_descriptor (mask
));
14137 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
14138 add_loc_descr (&op1
, int_loc_descriptor (mask
));
14139 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
14141 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
14143 HOST_WIDE_INT bias
= 1;
14144 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
14145 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14146 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14149 else if (!SCALAR_INT_MODE_P (mode
)
14150 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
14152 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
14153 add_loc_descr (&op0
, int_loc_descriptor (shift
));
14154 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
14155 add_loc_descr (&op1
, int_loc_descriptor (shift
));
14156 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
14158 else if (SCALAR_INT_MODE_P (mode
)
14159 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
14161 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
14162 dw_loc_descr_ref cvt
;
14163 if (type_die
== NULL
)
14165 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14166 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14167 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14168 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14169 add_loc_descr (&op0
, cvt
);
14170 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14171 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14172 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14173 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14174 add_loc_descr (&op1
, cvt
);
14177 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
14182 add_loc_descr (&ret
, op1
);
14183 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
14184 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14185 add_loc_descr (&ret
, bra_node
);
14186 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14187 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
14188 add_loc_descr (&ret
, drop_node
);
14189 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14190 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
14191 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
14192 && SCALAR_INT_MODE_P (mode
)
14193 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
14194 ret
= convert_descriptor_to_mode (mode
, ret
);
14198 /* Helper function for mem_loc_descriptor. Perform OP binary op,
14199 but after converting arguments to type_die, afterwards
14200 convert back to unsigned. */
14202 static dw_loc_descr_ref
14203 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
14204 machine_mode mode
, machine_mode mem_mode
)
14206 dw_loc_descr_ref cvt
, op0
, op1
;
14208 if (type_die
== NULL
)
14210 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14211 VAR_INIT_STATUS_INITIALIZED
);
14212 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
14213 VAR_INIT_STATUS_INITIALIZED
);
14214 if (op0
== NULL
|| op1
== NULL
)
14216 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14217 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14218 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14219 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14220 add_loc_descr (&op0
, cvt
);
14221 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14222 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14223 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14224 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14225 add_loc_descr (&op1
, cvt
);
14226 add_loc_descr (&op0
, op1
);
14227 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
14228 return convert_descriptor_to_mode (mode
, op0
);
14231 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
14232 const0 is DW_OP_lit0 or corresponding typed constant,
14233 const1 is DW_OP_lit1 or corresponding typed constant
14234 and constMSB is constant with just the MSB bit set
14236 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
14237 L1: const0 DW_OP_swap
14238 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
14239 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14244 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
14245 L1: const0 DW_OP_swap
14246 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
14247 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14252 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
14253 L1: const1 DW_OP_swap
14254 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
14255 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14259 static dw_loc_descr_ref
14260 clz_loc_descriptor (rtx rtl
, machine_mode mode
,
14261 machine_mode mem_mode
)
14263 dw_loc_descr_ref op0
, ret
, tmp
;
14264 HOST_WIDE_INT valv
;
14265 dw_loc_descr_ref l1jump
, l1label
;
14266 dw_loc_descr_ref l2jump
, l2label
;
14267 dw_loc_descr_ref l3jump
, l3label
;
14268 dw_loc_descr_ref l4jump
, l4label
;
14271 if (!SCALAR_INT_MODE_P (mode
)
14272 || GET_MODE (XEXP (rtl
, 0)) != mode
)
14275 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14276 VAR_INIT_STATUS_INITIALIZED
);
14280 if (GET_CODE (rtl
) == CLZ
)
14282 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
14283 valv
= GET_MODE_BITSIZE (mode
);
14285 else if (GET_CODE (rtl
) == FFS
)
14287 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
14288 valv
= GET_MODE_BITSIZE (mode
);
14289 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
14290 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14291 add_loc_descr (&ret
, l1jump
);
14292 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
14293 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
14294 VAR_INIT_STATUS_INITIALIZED
);
14297 add_loc_descr (&ret
, tmp
);
14298 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14299 add_loc_descr (&ret
, l4jump
);
14300 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
14301 ? const1_rtx
: const0_rtx
,
14303 VAR_INIT_STATUS_INITIALIZED
);
14304 if (l1label
== NULL
)
14306 add_loc_descr (&ret
, l1label
);
14307 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14308 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
14309 add_loc_descr (&ret
, l2label
);
14310 if (GET_CODE (rtl
) != CLZ
)
14312 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
14313 msb
= GEN_INT (HOST_WIDE_INT_1U
14314 << (GET_MODE_BITSIZE (mode
) - 1));
14316 msb
= immed_wide_int_const
14317 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode
) - 1,
14318 GET_MODE_PRECISION (mode
)), mode
);
14319 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
14320 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
14321 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
14322 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
14324 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
14325 VAR_INIT_STATUS_INITIALIZED
);
14328 add_loc_descr (&ret
, tmp
);
14329 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
14330 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14331 add_loc_descr (&ret
, l3jump
);
14332 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
14333 VAR_INIT_STATUS_INITIALIZED
);
14336 add_loc_descr (&ret
, tmp
);
14337 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
14338 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
14339 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14340 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
14341 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14342 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14343 add_loc_descr (&ret
, l2jump
);
14344 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
14345 add_loc_descr (&ret
, l3label
);
14346 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
14347 add_loc_descr (&ret
, l4label
);
14348 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14349 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
14350 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14351 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
14352 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14353 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
14354 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14355 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
14359 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
14360 const1 is DW_OP_lit1 or corresponding typed constant):
14362 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
14363 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
14367 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
14368 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
14371 static dw_loc_descr_ref
14372 popcount_loc_descriptor (rtx rtl
, machine_mode mode
,
14373 machine_mode mem_mode
)
14375 dw_loc_descr_ref op0
, ret
, tmp
;
14376 dw_loc_descr_ref l1jump
, l1label
;
14377 dw_loc_descr_ref l2jump
, l2label
;
14379 if (!SCALAR_INT_MODE_P (mode
)
14380 || GET_MODE (XEXP (rtl
, 0)) != mode
)
14383 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14384 VAR_INIT_STATUS_INITIALIZED
);
14388 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
14389 VAR_INIT_STATUS_INITIALIZED
);
14392 add_loc_descr (&ret
, tmp
);
14393 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14394 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
14395 add_loc_descr (&ret
, l1label
);
14396 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14397 add_loc_descr (&ret
, l2jump
);
14398 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
14399 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
14400 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
14401 VAR_INIT_STATUS_INITIALIZED
);
14404 add_loc_descr (&ret
, tmp
);
14405 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
14406 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
14407 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
14408 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14409 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
14410 VAR_INIT_STATUS_INITIALIZED
);
14411 add_loc_descr (&ret
, tmp
);
14412 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
14413 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14414 add_loc_descr (&ret
, l1jump
);
14415 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
14416 add_loc_descr (&ret
, l2label
);
14417 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14418 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
14419 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14420 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
14424 /* BSWAP (constS is initial shift count, either 56 or 24):
14426 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
14427 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
14428 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
14429 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
14430 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
14432 static dw_loc_descr_ref
14433 bswap_loc_descriptor (rtx rtl
, machine_mode mode
,
14434 machine_mode mem_mode
)
14436 dw_loc_descr_ref op0
, ret
, tmp
;
14437 dw_loc_descr_ref l1jump
, l1label
;
14438 dw_loc_descr_ref l2jump
, l2label
;
14440 if (!SCALAR_INT_MODE_P (mode
)
14441 || BITS_PER_UNIT
!= 8
14442 || (GET_MODE_BITSIZE (mode
) != 32
14443 && GET_MODE_BITSIZE (mode
) != 64))
14446 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14447 VAR_INIT_STATUS_INITIALIZED
);
14452 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
14454 VAR_INIT_STATUS_INITIALIZED
);
14457 add_loc_descr (&ret
, tmp
);
14458 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
14459 VAR_INIT_STATUS_INITIALIZED
);
14462 add_loc_descr (&ret
, tmp
);
14463 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
14464 add_loc_descr (&ret
, l1label
);
14465 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
14467 VAR_INIT_STATUS_INITIALIZED
);
14468 add_loc_descr (&ret
, tmp
);
14469 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
14470 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14471 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
14472 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
14473 VAR_INIT_STATUS_INITIALIZED
);
14476 add_loc_descr (&ret
, tmp
);
14477 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
14478 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
14479 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
14480 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
14481 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14482 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
14483 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
14484 VAR_INIT_STATUS_INITIALIZED
);
14485 add_loc_descr (&ret
, tmp
);
14486 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
14487 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14488 add_loc_descr (&ret
, l2jump
);
14489 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
14490 VAR_INIT_STATUS_INITIALIZED
);
14491 add_loc_descr (&ret
, tmp
);
14492 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14493 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14494 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14495 add_loc_descr (&ret
, l1jump
);
14496 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
14497 add_loc_descr (&ret
, l2label
);
14498 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14499 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
14500 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14501 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
14502 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14503 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
14507 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
14508 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
14509 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
14510 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
14512 ROTATERT is similar:
14513 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
14514 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
14515 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
14517 static dw_loc_descr_ref
14518 rotate_loc_descriptor (rtx rtl
, machine_mode mode
,
14519 machine_mode mem_mode
)
14521 rtx rtlop1
= XEXP (rtl
, 1);
14522 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
14525 if (!SCALAR_INT_MODE_P (mode
))
14528 if (GET_MODE (rtlop1
) != VOIDmode
14529 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
14530 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
14531 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14532 VAR_INIT_STATUS_INITIALIZED
);
14533 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
14534 VAR_INIT_STATUS_INITIALIZED
);
14535 if (op0
== NULL
|| op1
== NULL
)
14537 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
14538 for (i
= 0; i
< 2; i
++)
14540 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
14541 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
14543 VAR_INIT_STATUS_INITIALIZED
);
14544 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
14545 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
14547 : HOST_BITS_PER_WIDE_INT
== 64
14548 ? DW_OP_const8u
: DW_OP_constu
,
14549 GET_MODE_MASK (mode
), 0);
14552 if (mask
[i
] == NULL
)
14554 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
14557 add_loc_descr (&ret
, op1
);
14558 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
14559 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
14560 if (GET_CODE (rtl
) == ROTATERT
)
14562 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
14563 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
14564 GET_MODE_BITSIZE (mode
), 0));
14566 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
14567 if (mask
[0] != NULL
)
14568 add_loc_descr (&ret
, mask
[0]);
14569 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
14570 if (mask
[1] != NULL
)
14572 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14573 add_loc_descr (&ret
, mask
[1]);
14574 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14576 if (GET_CODE (rtl
) == ROTATE
)
14578 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
14579 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
14580 GET_MODE_BITSIZE (mode
), 0));
14582 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
14583 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
14587 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
14588 for DEBUG_PARAMETER_REF RTL. */
14590 static dw_loc_descr_ref
14591 parameter_ref_descriptor (rtx rtl
)
14593 dw_loc_descr_ref ret
;
14598 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
14599 /* With LTO during LTRANS we get the late DIE that refers to the early
14600 DIE, thus we add another indirection here. This seems to confuse
14601 gdb enough to make gcc.dg/guality/pr68860-1.c FAIL with LTO. */
14602 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
14603 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
14606 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14607 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
14608 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14612 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
14613 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
14618 /* The following routine converts the RTL for a variable or parameter
14619 (resident in memory) into an equivalent Dwarf representation of a
14620 mechanism for getting the address of that same variable onto the top of a
14621 hypothetical "address evaluation" stack.
14623 When creating memory location descriptors, we are effectively transforming
14624 the RTL for a memory-resident object into its Dwarf postfix expression
14625 equivalent. This routine recursively descends an RTL tree, turning
14626 it into Dwarf postfix code as it goes.
14628 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
14630 MEM_MODE is the mode of the memory reference, needed to handle some
14631 autoincrement addressing modes.
14633 Return 0 if we can't represent the location. */
14636 mem_loc_descriptor (rtx rtl
, machine_mode mode
,
14637 machine_mode mem_mode
,
14638 enum var_init_status initialized
)
14640 dw_loc_descr_ref mem_loc_result
= NULL
;
14641 enum dwarf_location_atom op
;
14642 dw_loc_descr_ref op0
, op1
;
14643 rtx inner
= NULL_RTX
;
14645 if (mode
== VOIDmode
)
14646 mode
= GET_MODE (rtl
);
14648 /* Note that for a dynamically sized array, the location we will generate a
14649 description of here will be the lowest numbered location which is
14650 actually within the array. That's *not* necessarily the same as the
14651 zeroth element of the array. */
14653 rtl
= targetm
.delegitimize_address (rtl
);
14655 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
14658 switch (GET_CODE (rtl
))
14663 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
14666 /* The case of a subreg may arise when we have a local (register)
14667 variable or a formal (register) parameter which doesn't quite fill
14668 up an entire register. For now, just assume that it is
14669 legitimate to make the Dwarf info refer to the whole register which
14670 contains the given subreg. */
14671 if (!subreg_lowpart_p (rtl
))
14673 inner
= SUBREG_REG (rtl
);
14676 if (inner
== NULL_RTX
)
14677 inner
= XEXP (rtl
, 0);
14678 if (SCALAR_INT_MODE_P (mode
)
14679 && SCALAR_INT_MODE_P (GET_MODE (inner
))
14680 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
14681 #ifdef POINTERS_EXTEND_UNSIGNED
14682 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
14685 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
14687 mem_loc_result
= mem_loc_descriptor (inner
,
14689 mem_mode
, initialized
);
14692 if (dwarf_strict
&& dwarf_version
< 5)
14694 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
14696 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
14697 && (!SCALAR_INT_MODE_P (mode
)
14698 || !SCALAR_INT_MODE_P (GET_MODE (inner
))))
14702 dw_die_ref type_die
;
14703 dw_loc_descr_ref cvt
;
14705 mem_loc_result
= mem_loc_descriptor (inner
,
14707 mem_mode
, initialized
);
14708 if (mem_loc_result
== NULL
)
14710 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
14711 if (type_die
== NULL
)
14713 mem_loc_result
= NULL
;
14716 if (GET_MODE_SIZE (mode
)
14717 != GET_MODE_SIZE (GET_MODE (inner
)))
14718 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14720 cvt
= new_loc_descr (dwarf_OP (DW_OP_reinterpret
), 0, 0);
14721 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14722 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14723 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14724 add_loc_descr (&mem_loc_result
, cvt
);
14725 if (SCALAR_INT_MODE_P (mode
)
14726 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
14728 /* Convert it to untyped afterwards. */
14729 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14730 add_loc_descr (&mem_loc_result
, cvt
);
14736 if (! SCALAR_INT_MODE_P (mode
)
14737 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
14738 && rtl
!= arg_pointer_rtx
14739 && rtl
!= frame_pointer_rtx
14740 #ifdef POINTERS_EXTEND_UNSIGNED
14741 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
14745 dw_die_ref type_die
;
14746 unsigned int dbx_regnum
;
14748 if (dwarf_strict
&& dwarf_version
< 5)
14750 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
14752 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
14753 if (type_die
== NULL
)
14756 dbx_regnum
= dbx_reg_number (rtl
);
14757 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
14759 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_regval_type
),
14761 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
14762 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
14763 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
14766 /* Whenever a register number forms a part of the description of the
14767 method for calculating the (dynamic) address of a memory resident
14768 object, DWARF rules require the register number be referred to as
14769 a "base register". This distinction is not based in any way upon
14770 what category of register the hardware believes the given register
14771 belongs to. This is strictly DWARF terminology we're dealing with
14772 here. Note that in cases where the location of a memory-resident
14773 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
14774 OP_CONST (0)) the actual DWARF location descriptor that we generate
14775 may just be OP_BASEREG (basereg). This may look deceptively like
14776 the object in question was allocated to a register (rather than in
14777 memory) so DWARF consumers need to be aware of the subtle
14778 distinction between OP_REG and OP_BASEREG. */
14779 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
14780 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
14781 else if (stack_realign_drap
14783 && crtl
->args
.internal_arg_pointer
== rtl
14784 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
14786 /* If RTL is internal_arg_pointer, which has been optimized
14787 out, use DRAP instead. */
14788 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
14789 VAR_INIT_STATUS_INITIALIZED
);
14795 if (!SCALAR_INT_MODE_P (mode
))
14797 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
14798 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
14801 else if (GET_CODE (rtl
) == ZERO_EXTEND
14802 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
14803 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
14804 < HOST_BITS_PER_WIDE_INT
14805 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
14806 to expand zero extend as two shifts instead of
14808 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
14810 machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
14811 mem_loc_result
= op0
;
14812 add_loc_descr (&mem_loc_result
,
14813 int_loc_descriptor (GET_MODE_MASK (imode
)));
14814 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
14816 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
14818 int shift
= DWARF2_ADDR_SIZE
14819 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
14820 shift
*= BITS_PER_UNIT
;
14821 if (GET_CODE (rtl
) == SIGN_EXTEND
)
14825 mem_loc_result
= op0
;
14826 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
14827 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
14828 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
14829 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
14831 else if (!dwarf_strict
|| dwarf_version
>= 5)
14833 dw_die_ref type_die1
, type_die2
;
14834 dw_loc_descr_ref cvt
;
14836 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
14837 GET_CODE (rtl
) == ZERO_EXTEND
);
14838 if (type_die1
== NULL
)
14840 type_die2
= base_type_for_mode (mode
, 1);
14841 if (type_die2
== NULL
)
14843 mem_loc_result
= op0
;
14844 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14845 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14846 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
14847 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14848 add_loc_descr (&mem_loc_result
, cvt
);
14849 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14850 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14851 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
14852 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14853 add_loc_descr (&mem_loc_result
, cvt
);
14859 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
14860 if (new_rtl
!= rtl
)
14862 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
14864 if (mem_loc_result
!= NULL
)
14865 return mem_loc_result
;
14868 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
14869 get_address_mode (rtl
), mode
,
14870 VAR_INIT_STATUS_INITIALIZED
);
14871 if (mem_loc_result
== NULL
)
14872 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
14873 if (mem_loc_result
!= NULL
)
14875 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
14876 || !SCALAR_INT_MODE_P(mode
))
14878 dw_die_ref type_die
;
14879 dw_loc_descr_ref deref
;
14881 if (dwarf_strict
&& dwarf_version
< 5)
14884 = base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
14885 if (type_die
== NULL
)
14887 deref
= new_loc_descr (dwarf_OP (DW_OP_deref_type
),
14888 GET_MODE_SIZE (mode
), 0);
14889 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
14890 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
14891 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
14892 add_loc_descr (&mem_loc_result
, deref
);
14894 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
14895 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
14897 add_loc_descr (&mem_loc_result
,
14898 new_loc_descr (DW_OP_deref_size
,
14899 GET_MODE_SIZE (mode
), 0));
14904 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
14907 /* Some ports can transform a symbol ref into a label ref, because
14908 the symbol ref is too far away and has to be dumped into a constant
14912 if (!SCALAR_INT_MODE_P (mode
)
14913 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
14914 #ifdef POINTERS_EXTEND_UNSIGNED
14915 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
14919 if (GET_CODE (rtl
) == SYMBOL_REF
14920 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
14922 dw_loc_descr_ref temp
;
14924 /* If this is not defined, we have no way to emit the data. */
14925 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
14928 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
14930 /* We check for DWARF 5 here because gdb did not implement
14931 DW_OP_form_tls_address until after 7.12. */
14932 mem_loc_result
= new_loc_descr ((dwarf_version
>= 5
14933 ? DW_OP_form_tls_address
14934 : DW_OP_GNU_push_tls_address
),
14936 add_loc_descr (&mem_loc_result
, temp
);
14941 if (!const_ok_for_output (rtl
))
14943 if (GET_CODE (rtl
) == CONST
)
14944 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14950 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
14951 vec_safe_push (used_rtx_array
, rtl
);
14957 case DEBUG_IMPLICIT_PTR
:
14958 expansion_failed (NULL_TREE
, rtl
,
14959 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
14963 if (dwarf_strict
&& dwarf_version
< 5)
14965 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
14967 if (!SCALAR_INT_MODE_P (mode
)
14968 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
14969 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
14970 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14973 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
14974 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
14976 op0
= one_reg_loc_descriptor (dbx_regnum
,
14977 VAR_INIT_STATUS_INITIALIZED
);
14980 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
14981 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
14983 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
14984 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14985 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
14989 gcc_unreachable ();
14992 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_entry_value
), 0, 0);
14993 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14994 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
14997 case DEBUG_PARAMETER_REF
:
14998 mem_loc_result
= parameter_ref_descriptor (rtl
);
15002 /* Extract the PLUS expression nested inside and fall into
15003 PLUS code below. */
15004 rtl
= XEXP (rtl
, 1);
15009 /* Turn these into a PLUS expression and fall into the PLUS code
15011 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
15012 gen_int_mode (GET_CODE (rtl
) == PRE_INC
15013 ? GET_MODE_UNIT_SIZE (mem_mode
)
15014 : -GET_MODE_UNIT_SIZE (mem_mode
),
15021 if (is_based_loc (rtl
)
15022 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
15023 || XEXP (rtl
, 0) == arg_pointer_rtx
15024 || XEXP (rtl
, 0) == frame_pointer_rtx
)
15025 && SCALAR_INT_MODE_P (mode
))
15026 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
15027 INTVAL (XEXP (rtl
, 1)),
15028 VAR_INIT_STATUS_INITIALIZED
);
15031 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15032 VAR_INIT_STATUS_INITIALIZED
);
15033 if (mem_loc_result
== 0)
15036 if (CONST_INT_P (XEXP (rtl
, 1))
15037 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
15038 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
15041 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15042 VAR_INIT_STATUS_INITIALIZED
);
15045 add_loc_descr (&mem_loc_result
, op1
);
15046 add_loc_descr (&mem_loc_result
,
15047 new_loc_descr (DW_OP_plus
, 0, 0));
15052 /* If a pseudo-reg is optimized away, it is possible for it to
15053 be replaced with a MEM containing a multiply or shift. */
15063 if ((!dwarf_strict
|| dwarf_version
>= 5)
15064 && SCALAR_INT_MODE_P (mode
)
15065 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
15067 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
15068 base_type_for_mode (mode
, 0),
15092 if (!SCALAR_INT_MODE_P (mode
))
15094 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15095 VAR_INIT_STATUS_INITIALIZED
);
15097 rtx rtlop1
= XEXP (rtl
, 1);
15098 if (GET_MODE (rtlop1
) != VOIDmode
15099 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
15100 < GET_MODE_BITSIZE (mode
))
15101 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
15102 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
15103 VAR_INIT_STATUS_INITIALIZED
);
15106 if (op0
== 0 || op1
== 0)
15109 mem_loc_result
= op0
;
15110 add_loc_descr (&mem_loc_result
, op1
);
15111 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15127 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15128 VAR_INIT_STATUS_INITIALIZED
);
15129 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15130 VAR_INIT_STATUS_INITIALIZED
);
15132 if (op0
== 0 || op1
== 0)
15135 mem_loc_result
= op0
;
15136 add_loc_descr (&mem_loc_result
, op1
);
15137 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15141 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
15142 && (!dwarf_strict
|| dwarf_version
>= 5))
15144 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
15145 base_type_for_mode (mode
, 0),
15150 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15151 VAR_INIT_STATUS_INITIALIZED
);
15152 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15153 VAR_INIT_STATUS_INITIALIZED
);
15155 if (op0
== 0 || op1
== 0)
15158 mem_loc_result
= op0
;
15159 add_loc_descr (&mem_loc_result
, op1
);
15160 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
15161 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
15162 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
15163 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
15164 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
15168 if ((!dwarf_strict
|| dwarf_version
>= 5)
15169 && SCALAR_INT_MODE_P (mode
))
15171 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
15176 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
15177 base_type_for_mode (mode
, 1),
15195 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15196 VAR_INIT_STATUS_INITIALIZED
);
15201 mem_loc_result
= op0
;
15202 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15206 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
15207 #ifdef POINTERS_EXTEND_UNSIGNED
15209 && mem_mode
!= VOIDmode
15210 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
15214 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
15217 if ((!dwarf_strict
|| dwarf_version
>= 5)
15218 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
15219 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
15221 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
15222 machine_mode amode
;
15223 if (type_die
== NULL
)
15225 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
15227 if (INTVAL (rtl
) >= 0
15228 && amode
!= BLKmode
15229 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
15230 /* const DW_OP_convert <XXX> vs.
15231 DW_OP_const_type <XXX, 1, const>. */
15232 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
15233 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
15235 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
15236 op0
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15237 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15238 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15239 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15240 add_loc_descr (&mem_loc_result
, op0
);
15241 return mem_loc_result
;
15243 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0,
15245 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15246 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15247 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15248 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
15249 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
15252 mem_loc_result
->dw_loc_oprnd2
.val_class
15253 = dw_val_class_const_double
;
15254 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
15255 = double_int::from_shwi (INTVAL (rtl
));
15261 if (!dwarf_strict
|| dwarf_version
>= 5)
15263 dw_die_ref type_die
;
15265 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
15266 CONST_DOUBLE rtx could represent either a large integer
15267 or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
15268 the value is always a floating point constant.
15270 When it is an integer, a CONST_DOUBLE is used whenever
15271 the constant requires 2 HWIs to be adequately represented.
15272 We output CONST_DOUBLEs as blocks. */
15273 if (mode
== VOIDmode
15274 || (GET_MODE (rtl
) == VOIDmode
15275 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
15277 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
15278 if (type_die
== NULL
)
15280 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0, 0);
15281 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15282 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15283 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15284 #if TARGET_SUPPORTS_WIDE_INT == 0
15285 if (!SCALAR_FLOAT_MODE_P (mode
))
15287 mem_loc_result
->dw_loc_oprnd2
.val_class
15288 = dw_val_class_const_double
;
15289 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
15290 = rtx_to_double_int (rtl
);
15295 unsigned int length
= GET_MODE_SIZE (mode
);
15296 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
15298 insert_float (rtl
, array
);
15299 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
15300 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
15301 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
15302 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
15307 case CONST_WIDE_INT
:
15308 if (!dwarf_strict
|| dwarf_version
>= 5)
15310 dw_die_ref type_die
;
15312 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
15313 if (type_die
== NULL
)
15315 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0, 0);
15316 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15317 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15318 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15319 mem_loc_result
->dw_loc_oprnd2
.val_class
15320 = dw_val_class_wide_int
;
15321 mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
15322 *mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= rtx_mode_t (rtl
, mode
);
15327 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
15331 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
15335 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
15339 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
15343 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
15347 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
15351 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
15355 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
15359 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
15363 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
15368 if (!SCALAR_INT_MODE_P (mode
))
15373 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
15378 if (CONST_INT_P (XEXP (rtl
, 1))
15379 && CONST_INT_P (XEXP (rtl
, 2))
15380 && ((unsigned) INTVAL (XEXP (rtl
, 1))
15381 + (unsigned) INTVAL (XEXP (rtl
, 2))
15382 <= GET_MODE_BITSIZE (mode
))
15383 && SCALAR_INT_MODE_P (mode
)
15384 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
15385 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
15388 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
15389 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
15392 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
15396 mem_loc_result
= op0
;
15397 size
= INTVAL (XEXP (rtl
, 1));
15398 shift
= INTVAL (XEXP (rtl
, 2));
15399 if (BITS_BIG_ENDIAN
)
15400 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
15402 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
15404 add_loc_descr (&mem_loc_result
,
15405 int_loc_descriptor (DWARF2_ADDR_SIZE
15407 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
15409 if (size
!= (int) DWARF2_ADDR_SIZE
)
15411 add_loc_descr (&mem_loc_result
,
15412 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
15413 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15420 dw_loc_descr_ref op2
, bra_node
, drop_node
;
15421 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
15422 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
15423 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
15424 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
15425 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15426 VAR_INIT_STATUS_INITIALIZED
);
15427 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
15428 VAR_INIT_STATUS_INITIALIZED
);
15429 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
15432 mem_loc_result
= op1
;
15433 add_loc_descr (&mem_loc_result
, op2
);
15434 add_loc_descr (&mem_loc_result
, op0
);
15435 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
15436 add_loc_descr (&mem_loc_result
, bra_node
);
15437 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
15438 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
15439 add_loc_descr (&mem_loc_result
, drop_node
);
15440 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15441 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
15446 case FLOAT_TRUNCATE
:
15448 case UNSIGNED_FLOAT
:
15451 if (!dwarf_strict
|| dwarf_version
>= 5)
15453 dw_die_ref type_die
;
15454 dw_loc_descr_ref cvt
;
15456 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
15457 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
15460 if (SCALAR_INT_MODE_P (GET_MODE (XEXP (rtl
, 0)))
15461 && (GET_CODE (rtl
) == FLOAT
15462 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
15463 <= DWARF2_ADDR_SIZE
))
15465 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
15466 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
15467 if (type_die
== NULL
)
15469 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15470 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15471 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15472 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15473 add_loc_descr (&op0
, cvt
);
15475 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
15476 if (type_die
== NULL
)
15478 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15479 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15480 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15481 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15482 add_loc_descr (&op0
, cvt
);
15483 if (SCALAR_INT_MODE_P (mode
)
15484 && (GET_CODE (rtl
) == FIX
15485 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
15487 op0
= convert_descriptor_to_mode (mode
, op0
);
15491 mem_loc_result
= op0
;
15498 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
15503 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
15507 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
15512 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
15516 /* In theory, we could implement the above. */
15517 /* DWARF cannot represent the unsigned compare operations
15542 case FRACT_CONVERT
:
15543 case UNSIGNED_FRACT_CONVERT
:
15545 case UNSIGNED_SAT_FRACT
:
15551 case VEC_DUPLICATE
:
15555 case STRICT_LOW_PART
:
15560 /* If delegitimize_address couldn't do anything with the UNSPEC, we
15561 can't express it in the debug info. This can happen e.g. with some
15566 resolve_one_addr (&rtl
);
15569 /* RTL sequences inside PARALLEL record a series of DWARF operations for
15570 the expression. An UNSPEC rtx represents a raw DWARF operation,
15571 new_loc_descr is called for it to build the operation directly.
15572 Otherwise mem_loc_descriptor is called recursively. */
15576 dw_loc_descr_ref exp_result
= NULL
;
15578 for (; index
< XVECLEN (rtl
, 0); index
++)
15580 rtx elem
= XVECEXP (rtl
, 0, index
);
15581 if (GET_CODE (elem
) == UNSPEC
)
15583 /* Each DWARF operation UNSPEC contain two operands, if
15584 one operand is not used for the operation, const0_rtx is
15586 gcc_assert (XVECLEN (elem
, 0) == 2);
15588 HOST_WIDE_INT dw_op
= XINT (elem
, 1);
15589 HOST_WIDE_INT oprnd1
= INTVAL (XVECEXP (elem
, 0, 0));
15590 HOST_WIDE_INT oprnd2
= INTVAL (XVECEXP (elem
, 0, 1));
15592 = new_loc_descr ((enum dwarf_location_atom
) dw_op
, oprnd1
,
15597 = mem_loc_descriptor (elem
, mode
, mem_mode
,
15598 VAR_INIT_STATUS_INITIALIZED
);
15600 if (!mem_loc_result
)
15601 mem_loc_result
= exp_result
;
15603 add_loc_descr (&mem_loc_result
, exp_result
);
15612 print_rtl (stderr
, rtl
);
15613 gcc_unreachable ();
15618 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
15619 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
15621 return mem_loc_result
;
15624 /* Return a descriptor that describes the concatenation of two locations.
15625 This is typically a complex variable. */
15627 static dw_loc_descr_ref
15628 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
15630 dw_loc_descr_ref cc_loc_result
= NULL
;
15631 dw_loc_descr_ref x0_ref
15632 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15633 dw_loc_descr_ref x1_ref
15634 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15636 if (x0_ref
== 0 || x1_ref
== 0)
15639 cc_loc_result
= x0_ref
;
15640 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
15642 add_loc_descr (&cc_loc_result
, x1_ref
);
15643 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
15645 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
15646 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
15648 return cc_loc_result
;
15651 /* Return a descriptor that describes the concatenation of N
15654 static dw_loc_descr_ref
15655 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
15658 dw_loc_descr_ref cc_loc_result
= NULL
;
15659 unsigned int n
= XVECLEN (concatn
, 0);
15661 for (i
= 0; i
< n
; ++i
)
15663 dw_loc_descr_ref ref
;
15664 rtx x
= XVECEXP (concatn
, 0, i
);
15666 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15670 add_loc_descr (&cc_loc_result
, ref
);
15671 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
15674 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
15675 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
15677 return cc_loc_result
;
15680 /* Helper function for loc_descriptor. Return DW_OP_implicit_pointer
15681 for DEBUG_IMPLICIT_PTR RTL. */
15683 static dw_loc_descr_ref
15684 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
15686 dw_loc_descr_ref ret
;
15689 if (dwarf_strict
&& dwarf_version
< 5)
15691 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
15692 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
15693 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
15694 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
15695 ret
= new_loc_descr (dwarf_OP (DW_OP_implicit_pointer
), 0, offset
);
15696 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
15699 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15700 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
15701 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15705 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
15706 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
15711 /* Output a proper Dwarf location descriptor for a variable or parameter
15712 which is either allocated in a register or in a memory location. For a
15713 register, we just generate an OP_REG and the register number. For a
15714 memory location we provide a Dwarf postfix expression describing how to
15715 generate the (dynamic) address of the object onto the address stack.
15717 MODE is mode of the decl if this loc_descriptor is going to be used in
15718 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
15719 allowed, VOIDmode otherwise.
15721 If we don't know how to describe it, return 0. */
15723 static dw_loc_descr_ref
15724 loc_descriptor (rtx rtl
, machine_mode mode
,
15725 enum var_init_status initialized
)
15727 dw_loc_descr_ref loc_result
= NULL
;
15729 switch (GET_CODE (rtl
))
15732 /* The case of a subreg may arise when we have a local (register)
15733 variable or a formal (register) parameter which doesn't quite fill
15734 up an entire register. For now, just assume that it is
15735 legitimate to make the Dwarf info refer to the whole register which
15736 contains the given subreg. */
15737 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
15738 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
15739 GET_MODE (SUBREG_REG (rtl
)), initialized
);
15745 loc_result
= reg_loc_descriptor (rtl
, initialized
);
15749 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
15750 GET_MODE (rtl
), initialized
);
15751 if (loc_result
== NULL
)
15752 loc_result
= tls_mem_loc_descriptor (rtl
);
15753 if (loc_result
== NULL
)
15755 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
15756 if (new_rtl
!= rtl
)
15757 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
15762 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
15767 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
15772 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
15774 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
15775 if (GET_CODE (loc
) == EXPR_LIST
)
15776 loc
= XEXP (loc
, 0);
15777 loc_result
= loc_descriptor (loc
, mode
, initialized
);
15781 rtl
= XEXP (rtl
, 1);
15786 rtvec par_elems
= XVEC (rtl
, 0);
15787 int num_elem
= GET_NUM_ELEM (par_elems
);
15791 /* Create the first one, so we have something to add to. */
15792 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
15793 VOIDmode
, initialized
);
15794 if (loc_result
== NULL
)
15796 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
15797 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
15798 for (i
= 1; i
< num_elem
; i
++)
15800 dw_loc_descr_ref temp
;
15802 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
15803 VOIDmode
, initialized
);
15806 add_loc_descr (&loc_result
, temp
);
15807 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
15808 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
15814 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
15815 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
15820 if (mode
== VOIDmode
)
15821 mode
= GET_MODE (rtl
);
15823 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
15825 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
15827 /* Note that a CONST_DOUBLE rtx could represent either an integer
15828 or a floating-point constant. A CONST_DOUBLE is used whenever
15829 the constant requires more than one word in order to be
15830 adequately represented. We output CONST_DOUBLEs as blocks. */
15831 loc_result
= new_loc_descr (DW_OP_implicit_value
,
15832 GET_MODE_SIZE (mode
), 0);
15833 #if TARGET_SUPPORTS_WIDE_INT == 0
15834 if (!SCALAR_FLOAT_MODE_P (mode
))
15836 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
15837 loc_result
->dw_loc_oprnd2
.v
.val_double
15838 = rtx_to_double_int (rtl
);
15843 unsigned int length
= GET_MODE_SIZE (mode
);
15844 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
15846 insert_float (rtl
, array
);
15847 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
15848 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
15849 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
15850 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
15855 case CONST_WIDE_INT
:
15856 if (mode
== VOIDmode
)
15857 mode
= GET_MODE (rtl
);
15859 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
15861 loc_result
= new_loc_descr (DW_OP_implicit_value
,
15862 GET_MODE_SIZE (mode
), 0);
15863 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_wide_int
;
15864 loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
15865 *loc_result
->dw_loc_oprnd2
.v
.val_wide
= rtx_mode_t (rtl
, mode
);
15870 if (mode
== VOIDmode
)
15871 mode
= GET_MODE (rtl
);
15873 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
15875 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
15876 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
15877 unsigned char *array
15878 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
15881 machine_mode imode
= GET_MODE_INNER (mode
);
15883 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
15884 switch (GET_MODE_CLASS (mode
))
15886 case MODE_VECTOR_INT
:
15887 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15889 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15890 insert_wide_int (rtx_mode_t (elt
, imode
), p
, elt_size
);
15894 case MODE_VECTOR_FLOAT
:
15895 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15897 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15898 insert_float (elt
, p
);
15903 gcc_unreachable ();
15906 loc_result
= new_loc_descr (DW_OP_implicit_value
,
15907 length
* elt_size
, 0);
15908 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
15909 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
15910 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
15911 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
15916 if (mode
== VOIDmode
15917 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
15918 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
15919 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
15921 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
15926 if (!const_ok_for_output (rtl
))
15930 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
15931 && (dwarf_version
>= 4 || !dwarf_strict
))
15933 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
15934 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15935 vec_safe_push (used_rtx_array
, rtl
);
15939 case DEBUG_IMPLICIT_PTR
:
15940 loc_result
= implicit_ptr_descriptor (rtl
, 0);
15944 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
15945 && CONST_INT_P (XEXP (rtl
, 1)))
15948 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
15954 if ((SCALAR_INT_MODE_P (mode
)
15955 && GET_MODE (rtl
) == mode
15956 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
15957 && dwarf_version
>= 4)
15958 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
15960 /* Value expression. */
15961 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
15963 add_loc_descr (&loc_result
,
15964 new_loc_descr (DW_OP_stack_value
, 0, 0));
15972 /* We need to figure out what section we should use as the base for the
15973 address ranges where a given location is valid.
15974 1. If this particular DECL has a section associated with it, use that.
15975 2. If this function has a section associated with it, use that.
15976 3. Otherwise, use the text section.
15977 XXX: If you split a variable across multiple sections, we won't notice. */
15979 static const char *
15980 secname_for_decl (const_tree decl
)
15982 const char *secname
;
15984 if (VAR_OR_FUNCTION_DECL_P (decl
)
15985 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
) || TREE_STATIC (decl
))
15986 && DECL_SECTION_NAME (decl
))
15987 secname
= DECL_SECTION_NAME (decl
);
15988 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
15989 secname
= DECL_SECTION_NAME (current_function_decl
);
15990 else if (cfun
&& in_cold_section_p
)
15991 secname
= crtl
->subsections
.cold_section_label
;
15993 secname
= text_section_label
;
15998 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
16001 decl_by_reference_p (tree decl
)
16003 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
16005 && DECL_BY_REFERENCE (decl
));
16008 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
16011 static dw_loc_descr_ref
16012 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
16013 enum var_init_status initialized
)
16015 int have_address
= 0;
16016 dw_loc_descr_ref descr
;
16019 if (want_address
!= 2)
16021 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
16023 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
16025 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
16026 if (GET_CODE (varloc
) == EXPR_LIST
)
16027 varloc
= XEXP (varloc
, 0);
16028 mode
= GET_MODE (varloc
);
16029 if (MEM_P (varloc
))
16031 rtx addr
= XEXP (varloc
, 0);
16032 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
16033 mode
, initialized
);
16038 rtx x
= avoid_constant_pool_reference (varloc
);
16040 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
16045 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
16052 if (GET_CODE (varloc
) == VAR_LOCATION
)
16053 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
16055 mode
= DECL_MODE (loc
);
16056 descr
= loc_descriptor (varloc
, mode
, initialized
);
16063 if (want_address
== 2 && !have_address
16064 && (dwarf_version
>= 4 || !dwarf_strict
))
16066 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
16068 expansion_failed (loc
, NULL_RTX
,
16069 "DWARF address size mismatch");
16072 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
16075 /* Show if we can't fill the request for an address. */
16076 if (want_address
&& !have_address
)
16078 expansion_failed (loc
, NULL_RTX
,
16079 "Want address and only have value");
16083 /* If we've got an address and don't want one, dereference. */
16084 if (!want_address
&& have_address
)
16086 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
16087 enum dwarf_location_atom op
;
16089 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
16091 expansion_failed (loc
, NULL_RTX
,
16092 "DWARF address size mismatch");
16095 else if (size
== DWARF2_ADDR_SIZE
)
16098 op
= DW_OP_deref_size
;
16100 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
16106 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
16107 if it is not possible. */
16109 static dw_loc_descr_ref
16110 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
16112 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
16113 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
16114 else if (dwarf_version
>= 3 || !dwarf_strict
)
16115 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
16120 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
16121 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
16123 static dw_loc_descr_ref
16124 dw_sra_loc_expr (tree decl
, rtx loc
)
16127 unsigned HOST_WIDE_INT padsize
= 0;
16128 dw_loc_descr_ref descr
, *descr_tail
;
16129 unsigned HOST_WIDE_INT decl_size
;
16131 enum var_init_status initialized
;
16133 if (DECL_SIZE (decl
) == NULL
16134 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
16137 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
16139 descr_tail
= &descr
;
16141 for (p
= loc
; p
; p
= XEXP (p
, 1))
16143 unsigned HOST_WIDE_INT bitsize
= decl_piece_bitsize (p
);
16144 rtx loc_note
= *decl_piece_varloc_ptr (p
);
16145 dw_loc_descr_ref cur_descr
;
16146 dw_loc_descr_ref
*tail
, last
= NULL
;
16147 unsigned HOST_WIDE_INT opsize
= 0;
16149 if (loc_note
== NULL_RTX
16150 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
16152 padsize
+= bitsize
;
16155 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
16156 varloc
= NOTE_VAR_LOCATION (loc_note
);
16157 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
16158 if (cur_descr
== NULL
)
16160 padsize
+= bitsize
;
16164 /* Check that cur_descr either doesn't use
16165 DW_OP_*piece operations, or their sum is equal
16166 to bitsize. Otherwise we can't embed it. */
16167 for (tail
= &cur_descr
; *tail
!= NULL
;
16168 tail
= &(*tail
)->dw_loc_next
)
16169 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
16171 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
16175 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
16177 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
16181 if (last
!= NULL
&& opsize
!= bitsize
)
16183 padsize
+= bitsize
;
16184 /* Discard the current piece of the descriptor and release any
16185 addr_table entries it uses. */
16186 remove_loc_list_addr_table_entries (cur_descr
);
16190 /* If there is a hole, add DW_OP_*piece after empty DWARF
16191 expression, which means that those bits are optimized out. */
16194 if (padsize
> decl_size
)
16196 remove_loc_list_addr_table_entries (cur_descr
);
16197 goto discard_descr
;
16199 decl_size
-= padsize
;
16200 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
16201 if (*descr_tail
== NULL
)
16203 remove_loc_list_addr_table_entries (cur_descr
);
16204 goto discard_descr
;
16206 descr_tail
= &(*descr_tail
)->dw_loc_next
;
16209 *descr_tail
= cur_descr
;
16211 if (bitsize
> decl_size
)
16212 goto discard_descr
;
16213 decl_size
-= bitsize
;
16216 HOST_WIDE_INT offset
= 0;
16217 if (GET_CODE (varloc
) == VAR_LOCATION
16218 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
16220 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
16221 if (GET_CODE (varloc
) == EXPR_LIST
)
16222 varloc
= XEXP (varloc
, 0);
16226 if (GET_CODE (varloc
) == CONST
16227 || GET_CODE (varloc
) == SIGN_EXTEND
16228 || GET_CODE (varloc
) == ZERO_EXTEND
)
16229 varloc
= XEXP (varloc
, 0);
16230 else if (GET_CODE (varloc
) == SUBREG
)
16231 varloc
= SUBREG_REG (varloc
);
16236 /* DW_OP_bit_size offset should be zero for register
16237 or implicit location descriptions and empty location
16238 descriptions, but for memory addresses needs big endian
16240 if (MEM_P (varloc
))
16242 unsigned HOST_WIDE_INT memsize
16243 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
16244 if (memsize
!= bitsize
)
16246 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
16247 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
16248 goto discard_descr
;
16249 if (memsize
< bitsize
)
16250 goto discard_descr
;
16251 if (BITS_BIG_ENDIAN
)
16252 offset
= memsize
- bitsize
;
16256 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
16257 if (*descr_tail
== NULL
)
16258 goto discard_descr
;
16259 descr_tail
= &(*descr_tail
)->dw_loc_next
;
16263 /* If there were any non-empty expressions, add padding till the end of
16265 if (descr
!= NULL
&& decl_size
!= 0)
16267 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
16268 if (*descr_tail
== NULL
)
16269 goto discard_descr
;
16274 /* Discard the descriptor and release any addr_table entries it uses. */
16275 remove_loc_list_addr_table_entries (descr
);
16279 /* Return the dwarf representation of the location list LOC_LIST of
16280 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
16283 static dw_loc_list_ref
16284 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
16286 const char *endname
, *secname
;
16288 enum var_init_status initialized
;
16289 struct var_loc_node
*node
;
16290 dw_loc_descr_ref descr
;
16291 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
16292 dw_loc_list_ref list
= NULL
;
16293 dw_loc_list_ref
*listp
= &list
;
16295 /* Now that we know what section we are using for a base,
16296 actually construct the list of locations.
16297 The first location information is what is passed to the
16298 function that creates the location list, and the remaining
16299 locations just get added on to that list.
16300 Note that we only know the start address for a location
16301 (IE location changes), so to build the range, we use
16302 the range [current location start, next location start].
16303 This means we have to special case the last node, and generate
16304 a range of [last location start, end of function label]. */
16306 secname
= secname_for_decl (decl
);
16308 for (node
= loc_list
->first
; node
; node
= node
->next
)
16309 if (GET_CODE (node
->loc
) == EXPR_LIST
16310 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
16312 if (GET_CODE (node
->loc
) == EXPR_LIST
)
16314 /* This requires DW_OP_{,bit_}piece, which is not usable
16315 inside DWARF expressions. */
16316 if (want_address
!= 2)
16318 descr
= dw_sra_loc_expr (decl
, node
->loc
);
16324 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
16325 varloc
= NOTE_VAR_LOCATION (node
->loc
);
16326 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
16330 bool range_across_switch
= false;
16331 /* If section switch happens in between node->label
16332 and node->next->label (or end of function) and
16333 we can't emit it as a single entry list,
16334 emit two ranges, first one ending at the end
16335 of first partition and second one starting at the
16336 beginning of second partition. */
16337 if (node
== loc_list
->last_before_switch
16338 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
16339 && current_function_decl
)
16341 endname
= cfun
->fde
->dw_fde_end
;
16342 range_across_switch
= true;
16344 /* The variable has a location between NODE->LABEL and
16345 NODE->NEXT->LABEL. */
16346 else if (node
->next
)
16347 endname
= node
->next
->label
;
16348 /* If the variable has a location at the last label
16349 it keeps its location until the end of function. */
16350 else if (!current_function_decl
)
16351 endname
= text_end_label
;
16354 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
16355 current_function_funcdef_no
);
16356 endname
= ggc_strdup (label_id
);
16359 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
16360 if (TREE_CODE (decl
) == PARM_DECL
16361 && node
== loc_list
->first
16362 && NOTE_P (node
->loc
)
16363 && strcmp (node
->label
, endname
) == 0)
16364 (*listp
)->force
= true;
16365 listp
= &(*listp
)->dw_loc_next
;
16367 if (range_across_switch
)
16369 if (GET_CODE (node
->loc
) == EXPR_LIST
)
16370 descr
= dw_sra_loc_expr (decl
, node
->loc
);
16373 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
16374 varloc
= NOTE_VAR_LOCATION (node
->loc
);
16375 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
16378 gcc_assert (descr
);
16379 /* The variable has a location between NODE->LABEL and
16380 NODE->NEXT->LABEL. */
16382 endname
= node
->next
->label
;
16384 endname
= cfun
->fde
->dw_fde_second_end
;
16385 *listp
= new_loc_list (descr
,
16386 cfun
->fde
->dw_fde_second_begin
,
16388 listp
= &(*listp
)->dw_loc_next
;
16393 /* Try to avoid the overhead of a location list emitting a location
16394 expression instead, but only if we didn't have more than one
16395 location entry in the first place. If some entries were not
16396 representable, we don't want to pretend a single entry that was
16397 applies to the entire scope in which the variable is
16399 if (list
&& loc_list
->first
->next
)
16405 /* Return if the loc_list has only single element and thus can be represented
16406 as location description. */
16409 single_element_loc_list_p (dw_loc_list_ref list
)
16411 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
16412 return !list
->ll_symbol
;
16415 /* Duplicate a single element of location list. */
16417 static inline dw_loc_descr_ref
16418 copy_loc_descr (dw_loc_descr_ref ref
)
16420 dw_loc_descr_ref copy
= ggc_alloc
<dw_loc_descr_node
> ();
16421 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
16425 /* To each location in list LIST append loc descr REF. */
16428 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
16430 dw_loc_descr_ref copy
;
16431 add_loc_descr (&list
->expr
, ref
);
16432 list
= list
->dw_loc_next
;
16435 copy
= copy_loc_descr (ref
);
16436 add_loc_descr (&list
->expr
, copy
);
16437 while (copy
->dw_loc_next
)
16438 copy
= copy
->dw_loc_next
= copy_loc_descr (copy
->dw_loc_next
);
16439 list
= list
->dw_loc_next
;
16443 /* To each location in list LIST prepend loc descr REF. */
16446 prepend_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
16448 dw_loc_descr_ref copy
;
16449 dw_loc_descr_ref ref_end
= list
->expr
;
16450 add_loc_descr (&ref
, list
->expr
);
16452 list
= list
->dw_loc_next
;
16455 dw_loc_descr_ref end
= list
->expr
;
16456 list
->expr
= copy
= copy_loc_descr (ref
);
16457 while (copy
->dw_loc_next
!= ref_end
)
16458 copy
= copy
->dw_loc_next
= copy_loc_descr (copy
->dw_loc_next
);
16459 copy
->dw_loc_next
= end
;
16460 list
= list
->dw_loc_next
;
16464 /* Given two lists RET and LIST
16465 produce location list that is result of adding expression in LIST
16466 to expression in RET on each position in program.
16467 Might be destructive on both RET and LIST.
16469 TODO: We handle only simple cases of RET or LIST having at most one
16470 element. General case would involve sorting the lists in program order
16471 and merging them that will need some additional work.
16472 Adding that will improve quality of debug info especially for SRA-ed
16476 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
16485 if (!list
->dw_loc_next
)
16487 add_loc_descr_to_each (*ret
, list
->expr
);
16490 if (!(*ret
)->dw_loc_next
)
16492 prepend_loc_descr_to_each (list
, (*ret
)->expr
);
16496 expansion_failed (NULL_TREE
, NULL_RTX
,
16497 "Don't know how to merge two non-trivial"
16498 " location lists.\n");
16503 /* LOC is constant expression. Try a luck, look it up in constant
16504 pool and return its loc_descr of its address. */
16506 static dw_loc_descr_ref
16507 cst_pool_loc_descr (tree loc
)
16509 /* Get an RTL for this, if something has been emitted. */
16510 rtx rtl
= lookup_constant_def (loc
);
16512 if (!rtl
|| !MEM_P (rtl
))
16517 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
16519 /* TODO: We might get more coverage if we was actually delaying expansion
16520 of all expressions till end of compilation when constant pools are fully
16522 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
16524 expansion_failed (loc
, NULL_RTX
,
16525 "CST value in contant pool but not marked.");
16528 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
16529 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
16532 /* Return dw_loc_list representing address of addr_expr LOC
16533 by looking for inner INDIRECT_REF expression and turning
16534 it into simple arithmetics.
16536 See loc_list_from_tree for the meaning of CONTEXT. */
16538 static dw_loc_list_ref
16539 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
,
16540 loc_descr_context
*context
)
16543 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
16545 int unsignedp
, reversep
, volatilep
= 0;
16546 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
16548 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
16549 &bitsize
, &bitpos
, &offset
, &mode
,
16550 &unsignedp
, &reversep
, &volatilep
);
16552 if (bitpos
% BITS_PER_UNIT
)
16554 expansion_failed (loc
, NULL_RTX
, "bitfield access");
16557 if (!INDIRECT_REF_P (obj
))
16559 expansion_failed (obj
,
16560 NULL_RTX
, "no indirect ref in inner refrence");
16563 if (!offset
&& !bitpos
)
16564 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1,
16567 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
16568 && (dwarf_version
>= 4 || !dwarf_strict
))
16570 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0, context
);
16575 /* Variable offset. */
16576 list_ret1
= loc_list_from_tree (offset
, 0, context
);
16577 if (list_ret1
== 0)
16579 add_loc_list (&list_ret
, list_ret1
);
16582 add_loc_descr_to_each (list_ret
,
16583 new_loc_descr (DW_OP_plus
, 0, 0));
16585 bytepos
= bitpos
/ BITS_PER_UNIT
;
16587 add_loc_descr_to_each (list_ret
,
16588 new_loc_descr (DW_OP_plus_uconst
,
16590 else if (bytepos
< 0)
16591 loc_list_plus_const (list_ret
, bytepos
);
16592 add_loc_descr_to_each (list_ret
,
16593 new_loc_descr (DW_OP_stack_value
, 0, 0));
16598 /* Set LOC to the next operation that is not a DW_OP_nop operation. In the case
16599 all operations from LOC are nops, move to the last one. Insert in NOPS all
16600 operations that are skipped. */
16603 loc_descr_to_next_no_nop (dw_loc_descr_ref
&loc
,
16604 hash_set
<dw_loc_descr_ref
> &nops
)
16606 while (loc
->dw_loc_next
!= NULL
&& loc
->dw_loc_opc
== DW_OP_nop
)
16609 loc
= loc
->dw_loc_next
;
16613 /* Helper for loc_descr_without_nops: free the location description operation
16617 free_loc_descr (const dw_loc_descr_ref
&loc
, void *data ATTRIBUTE_UNUSED
)
16623 /* Remove all DW_OP_nop operations from LOC except, if it exists, the one that
16627 loc_descr_without_nops (dw_loc_descr_ref
&loc
)
16629 if (loc
->dw_loc_opc
== DW_OP_nop
&& loc
->dw_loc_next
== NULL
)
16632 /* Set of all DW_OP_nop operations we remove. */
16633 hash_set
<dw_loc_descr_ref
> nops
;
16635 /* First, strip all prefix NOP operations in order to keep the head of the
16636 operations list. */
16637 loc_descr_to_next_no_nop (loc
, nops
);
16639 for (dw_loc_descr_ref cur
= loc
; cur
!= NULL
;)
16641 /* For control flow operations: strip "prefix" nops in destination
16643 if (cur
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
)
16644 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd1
.v
.val_loc
, nops
);
16645 if (cur
->dw_loc_oprnd2
.val_class
== dw_val_class_loc
)
16646 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd2
.v
.val_loc
, nops
);
16648 /* Do the same for the operations that follow, then move to the next
16650 if (cur
->dw_loc_next
!= NULL
)
16651 loc_descr_to_next_no_nop (cur
->dw_loc_next
, nops
);
16652 cur
= cur
->dw_loc_next
;
16655 nops
.traverse
<void *, free_loc_descr
> (NULL
);
16659 struct dwarf_procedure_info
;
16661 /* Helper structure for location descriptions generation. */
16662 struct loc_descr_context
16664 /* The type that is implicitly referenced by DW_OP_push_object_address, or
16665 NULL_TREE if DW_OP_push_object_address in invalid for this location
16666 description. This is used when processing PLACEHOLDER_EXPR nodes. */
16668 /* The ..._DECL node that should be translated as a
16669 DW_OP_push_object_address operation. */
16671 /* Information about the DWARF procedure we are currently generating. NULL if
16672 we are not generating a DWARF procedure. */
16673 struct dwarf_procedure_info
*dpi
;
16674 /* True if integral PLACEHOLDER_EXPR stands for the first argument passed
16675 by consumer. Used for DW_TAG_generic_subrange attributes. */
16676 bool placeholder_arg
;
16677 /* True if PLACEHOLDER_EXPR has been seen. */
16678 bool placeholder_seen
;
16681 /* DWARF procedures generation
16683 DWARF expressions (aka. location descriptions) are used to encode variable
16684 things such as sizes or offsets. Such computations can have redundant parts
16685 that can be factorized in order to reduce the size of the output debug
16686 information. This is the whole point of DWARF procedures.
16688 Thanks to stor-layout.c, size and offset expressions in GENERIC trees are
16689 already factorized into functions ("size functions") in order to handle very
16690 big and complex types. Such functions are quite simple: they have integral
16691 arguments, they return an integral result and their body contains only a
16692 return statement with arithmetic expressions. This is the only kind of
16693 function we are interested in translating into DWARF procedures, here.
16695 DWARF expressions and DWARF procedure are executed using a stack, so we have
16696 to define some calling convention for them to interact. Let's say that:
16698 - Before calling a DWARF procedure, DWARF expressions must push on the stack
16699 all arguments in reverse order (right-to-left) so that when the DWARF
16700 procedure execution starts, the first argument is the top of the stack.
16702 - Then, when returning, the DWARF procedure must have consumed all arguments
16703 on the stack, must have pushed the result and touched nothing else.
16705 - Each integral argument and the result are integral types can be hold in a
16708 - We call "frame offset" the number of stack slots that are "under DWARF
16709 procedure control": it includes the arguments slots, the temporaries and
16710 the result slot. Thus, it is equal to the number of arguments when the
16711 procedure execution starts and must be equal to one (the result) when it
16714 /* Helper structure used when generating operations for a DWARF procedure. */
16715 struct dwarf_procedure_info
16717 /* The FUNCTION_DECL node corresponding to the DWARF procedure that is
16718 currently translated. */
16720 /* The number of arguments FNDECL takes. */
16721 unsigned args_count
;
16724 /* Return a pointer to a newly created DIE node for a DWARF procedure. Add
16725 LOCATION as its DW_AT_location attribute. If FNDECL is not NULL_TREE,
16726 equate it to this DIE. */
16729 new_dwarf_proc_die (dw_loc_descr_ref location
, tree fndecl
,
16730 dw_die_ref parent_die
)
16732 dw_die_ref dwarf_proc_die
;
16734 if ((dwarf_version
< 3 && dwarf_strict
)
16735 || location
== NULL
)
16738 dwarf_proc_die
= new_die (DW_TAG_dwarf_procedure
, parent_die
, fndecl
);
16740 equate_decl_number_to_die (fndecl
, dwarf_proc_die
);
16741 add_AT_loc (dwarf_proc_die
, DW_AT_location
, location
);
16742 return dwarf_proc_die
;
16745 /* Return whether TYPE is a supported type as a DWARF procedure argument
16746 type or return type (we handle only scalar types and pointer types that
16747 aren't wider than the DWARF expression evaluation stack. */
16750 is_handled_procedure_type (tree type
)
16752 return ((INTEGRAL_TYPE_P (type
)
16753 || TREE_CODE (type
) == OFFSET_TYPE
16754 || TREE_CODE (type
) == POINTER_TYPE
)
16755 && int_size_in_bytes (type
) <= DWARF2_ADDR_SIZE
);
16758 /* Helper for resolve_args_picking: do the same but stop when coming across
16759 visited nodes. For each node we visit, register in FRAME_OFFSETS the frame
16760 offset *before* evaluating the corresponding operation. */
16763 resolve_args_picking_1 (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
16764 struct dwarf_procedure_info
*dpi
,
16765 hash_map
<dw_loc_descr_ref
, unsigned> &frame_offsets
)
16767 /* The "frame_offset" identifier is already used to name a macro... */
16768 unsigned frame_offset_
= initial_frame_offset
;
16769 dw_loc_descr_ref l
;
16771 for (l
= loc
; l
!= NULL
;)
16774 unsigned &l_frame_offset
= frame_offsets
.get_or_insert (l
, &existed
);
16776 /* If we already met this node, there is nothing to compute anymore. */
16779 /* Make sure that the stack size is consistent wherever the execution
16780 flow comes from. */
16781 gcc_assert ((unsigned) l_frame_offset
== frame_offset_
);
16784 l_frame_offset
= frame_offset_
;
16786 /* If needed, relocate the picking offset with respect to the frame
16788 if (l
->frame_offset_rel
)
16790 unsigned HOST_WIDE_INT off
;
16791 switch (l
->dw_loc_opc
)
16794 off
= l
->dw_loc_oprnd1
.v
.val_unsigned
;
16803 gcc_unreachable ();
16805 /* frame_offset_ is the size of the current stack frame, including
16806 incoming arguments. Besides, the arguments are pushed
16807 right-to-left. Thus, in order to access the Nth argument from
16808 this operation node, the picking has to skip temporaries *plus*
16809 one stack slot per argument (0 for the first one, 1 for the second
16812 The targetted argument number (N) is already set as the operand,
16813 and the number of temporaries can be computed with:
16814 frame_offsets_ - dpi->args_count */
16815 off
+= frame_offset_
- dpi
->args_count
;
16817 /* DW_OP_pick handles only offsets from 0 to 255 (inclusive)... */
16823 l
->dw_loc_opc
= DW_OP_dup
;
16824 l
->dw_loc_oprnd1
.v
.val_unsigned
= 0;
16828 l
->dw_loc_opc
= DW_OP_over
;
16829 l
->dw_loc_oprnd1
.v
.val_unsigned
= 0;
16833 l
->dw_loc_opc
= DW_OP_pick
;
16834 l
->dw_loc_oprnd1
.v
.val_unsigned
= off
;
16838 /* Update frame_offset according to the effect the current operation has
16840 switch (l
->dw_loc_opc
)
16848 case DW_OP_plus_uconst
:
16884 case DW_OP_deref_size
:
16886 case DW_OP_bit_piece
:
16887 case DW_OP_implicit_value
:
16888 case DW_OP_stack_value
:
16892 case DW_OP_const1u
:
16893 case DW_OP_const1s
:
16894 case DW_OP_const2u
:
16895 case DW_OP_const2s
:
16896 case DW_OP_const4u
:
16897 case DW_OP_const4s
:
16898 case DW_OP_const8u
:
16899 case DW_OP_const8s
:
16970 case DW_OP_push_object_address
:
16971 case DW_OP_call_frame_cfa
:
16972 case DW_OP_GNU_variable_value
:
16997 case DW_OP_xderef_size
:
17003 case DW_OP_call_ref
:
17005 dw_die_ref dwarf_proc
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
17006 int *stack_usage
= dwarf_proc_stack_usage_map
->get (dwarf_proc
);
17008 if (stack_usage
== NULL
)
17010 frame_offset_
+= *stack_usage
;
17014 case DW_OP_implicit_pointer
:
17015 case DW_OP_entry_value
:
17016 case DW_OP_const_type
:
17017 case DW_OP_regval_type
:
17018 case DW_OP_deref_type
:
17019 case DW_OP_convert
:
17020 case DW_OP_reinterpret
:
17021 case DW_OP_form_tls_address
:
17022 case DW_OP_GNU_push_tls_address
:
17023 case DW_OP_GNU_uninit
:
17024 case DW_OP_GNU_encoded_addr
:
17025 case DW_OP_GNU_implicit_pointer
:
17026 case DW_OP_GNU_entry_value
:
17027 case DW_OP_GNU_const_type
:
17028 case DW_OP_GNU_regval_type
:
17029 case DW_OP_GNU_deref_type
:
17030 case DW_OP_GNU_convert
:
17031 case DW_OP_GNU_reinterpret
:
17032 case DW_OP_GNU_parameter_ref
:
17033 /* loc_list_from_tree will probably not output these operations for
17034 size functions, so assume they will not appear here. */
17035 /* Fall through... */
17038 gcc_unreachable ();
17041 /* Now, follow the control flow (except subroutine calls). */
17042 switch (l
->dw_loc_opc
)
17045 if (!resolve_args_picking_1 (l
->dw_loc_next
, frame_offset_
, dpi
,
17048 /* Fall through. */
17051 l
= l
->dw_loc_oprnd1
.v
.val_loc
;
17054 case DW_OP_stack_value
:
17058 l
= l
->dw_loc_next
;
17066 /* Make a DFS over operations reachable through LOC (i.e. follow branch
17067 operations) in order to resolve the operand of DW_OP_pick operations that
17068 target DWARF procedure arguments (DPI). INITIAL_FRAME_OFFSET is the frame
17069 offset *before* LOC is executed. Return if all relocations were
17073 resolve_args_picking (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
17074 struct dwarf_procedure_info
*dpi
)
17076 /* Associate to all visited operations the frame offset *before* evaluating
17078 hash_map
<dw_loc_descr_ref
, unsigned> frame_offsets
;
17080 return resolve_args_picking_1 (loc
, initial_frame_offset
, dpi
,
17084 /* Try to generate a DWARF procedure that computes the same result as FNDECL.
17085 Return NULL if it is not possible. */
17088 function_to_dwarf_procedure (tree fndecl
)
17090 struct loc_descr_context ctx
;
17091 struct dwarf_procedure_info dpi
;
17092 dw_die_ref dwarf_proc_die
;
17093 tree tree_body
= DECL_SAVED_TREE (fndecl
);
17094 dw_loc_descr_ref loc_body
, epilogue
;
17099 /* Do not generate multiple DWARF procedures for the same function
17101 dwarf_proc_die
= lookup_decl_die (fndecl
);
17102 if (dwarf_proc_die
!= NULL
)
17103 return dwarf_proc_die
;
17105 /* DWARF procedures are available starting with the DWARFv3 standard. */
17106 if (dwarf_version
< 3 && dwarf_strict
)
17109 /* We handle only functions for which we still have a body, that return a
17110 supported type and that takes arguments with supported types. Note that
17111 there is no point translating functions that return nothing. */
17112 if (tree_body
== NULL_TREE
17113 || DECL_RESULT (fndecl
) == NULL_TREE
17114 || !is_handled_procedure_type (TREE_TYPE (DECL_RESULT (fndecl
))))
17117 for (cursor
= DECL_ARGUMENTS (fndecl
);
17118 cursor
!= NULL_TREE
;
17119 cursor
= TREE_CHAIN (cursor
))
17120 if (!is_handled_procedure_type (TREE_TYPE (cursor
)))
17123 /* Match only "expr" in: RETURN_EXPR (MODIFY_EXPR (RESULT_DECL, expr)). */
17124 if (TREE_CODE (tree_body
) != RETURN_EXPR
)
17126 tree_body
= TREE_OPERAND (tree_body
, 0);
17127 if (TREE_CODE (tree_body
) != MODIFY_EXPR
17128 || TREE_OPERAND (tree_body
, 0) != DECL_RESULT (fndecl
))
17130 tree_body
= TREE_OPERAND (tree_body
, 1);
17132 /* Try to translate the body expression itself. Note that this will probably
17133 cause an infinite recursion if its call graph has a cycle. This is very
17134 unlikely for size functions, however, so don't bother with such things at
17136 ctx
.context_type
= NULL_TREE
;
17137 ctx
.base_decl
= NULL_TREE
;
17139 ctx
.placeholder_arg
= false;
17140 ctx
.placeholder_seen
= false;
17141 dpi
.fndecl
= fndecl
;
17142 dpi
.args_count
= list_length (DECL_ARGUMENTS (fndecl
));
17143 loc_body
= loc_descriptor_from_tree (tree_body
, 0, &ctx
);
17147 /* After evaluating all operands in "loc_body", we should still have on the
17148 stack all arguments plus the desired function result (top of the stack).
17149 Generate code in order to keep only the result in our stack frame. */
17151 for (i
= 0; i
< dpi
.args_count
; ++i
)
17153 dw_loc_descr_ref op_couple
= new_loc_descr (DW_OP_swap
, 0, 0);
17154 op_couple
->dw_loc_next
= new_loc_descr (DW_OP_drop
, 0, 0);
17155 op_couple
->dw_loc_next
->dw_loc_next
= epilogue
;
17156 epilogue
= op_couple
;
17158 add_loc_descr (&loc_body
, epilogue
);
17159 if (!resolve_args_picking (loc_body
, dpi
.args_count
, &dpi
))
17162 /* Trailing nops from loc_descriptor_from_tree (if any) cannot be removed
17163 because they are considered useful. Now there is an epilogue, they are
17164 not anymore, so give it another try. */
17165 loc_descr_without_nops (loc_body
);
17167 /* fndecl may be used both as a regular DW_TAG_subprogram DIE and as
17168 a DW_TAG_dwarf_procedure, so we may have a conflict, here. It's unlikely,
17169 though, given that size functions do not come from source, so they should
17170 not have a dedicated DW_TAG_subprogram DIE. */
17172 = new_dwarf_proc_die (loc_body
, fndecl
,
17173 get_context_die (DECL_CONTEXT (fndecl
)));
17175 /* The called DWARF procedure consumes one stack slot per argument and
17176 returns one stack slot. */
17177 dwarf_proc_stack_usage_map
->put (dwarf_proc_die
, 1 - dpi
.args_count
);
17179 return dwarf_proc_die
;
17183 /* Generate Dwarf location list representing LOC.
17184 If WANT_ADDRESS is false, expression computing LOC will be computed
17185 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
17186 if WANT_ADDRESS is 2, expression computing address useable in location
17187 will be returned (i.e. DW_OP_reg can be used
17188 to refer to register values).
17190 CONTEXT provides information to customize the location descriptions
17191 generation. Its context_type field specifies what type is implicitly
17192 referenced by DW_OP_push_object_address. If it is NULL_TREE, this operation
17193 will not be generated.
17195 Its DPI field determines whether we are generating a DWARF expression for a
17196 DWARF procedure, so PARM_DECL references are processed specifically.
17198 If CONTEXT is NULL, the behavior is the same as if context_type, base_decl
17199 and dpi fields were null. */
17201 static dw_loc_list_ref
17202 loc_list_from_tree_1 (tree loc
, int want_address
,
17203 struct loc_descr_context
*context
)
17205 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
17206 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
17207 int have_address
= 0;
17208 enum dwarf_location_atom op
;
17210 /* ??? Most of the time we do not take proper care for sign/zero
17211 extending the values properly. Hopefully this won't be a real
17214 if (context
!= NULL
17215 && context
->base_decl
== loc
17216 && want_address
== 0)
17218 if (dwarf_version
>= 3 || !dwarf_strict
)
17219 return new_loc_list (new_loc_descr (DW_OP_push_object_address
, 0, 0),
17225 switch (TREE_CODE (loc
))
17228 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
17231 case PLACEHOLDER_EXPR
:
17232 /* This case involves extracting fields from an object to determine the
17233 position of other fields. It is supposed to appear only as the first
17234 operand of COMPONENT_REF nodes and to reference precisely the type
17235 that the context allows. */
17236 if (context
!= NULL
17237 && TREE_TYPE (loc
) == context
->context_type
17238 && want_address
>= 1)
17240 if (dwarf_version
>= 3 || !dwarf_strict
)
17242 ret
= new_loc_descr (DW_OP_push_object_address
, 0, 0);
17249 /* For DW_TAG_generic_subrange attributes, PLACEHOLDER_EXPR stands for
17250 the single argument passed by consumer. */
17251 else if (context
!= NULL
17252 && context
->placeholder_arg
17253 && INTEGRAL_TYPE_P (TREE_TYPE (loc
))
17254 && want_address
== 0)
17256 ret
= new_loc_descr (DW_OP_pick
, 0, 0);
17257 ret
->frame_offset_rel
= 1;
17258 context
->placeholder_seen
= true;
17262 expansion_failed (loc
, NULL_RTX
,
17263 "PLACEHOLDER_EXPR for an unexpected type");
17268 const int nargs
= call_expr_nargs (loc
);
17269 tree callee
= get_callee_fndecl (loc
);
17271 dw_die_ref dwarf_proc
;
17273 if (callee
== NULL_TREE
)
17274 goto call_expansion_failed
;
17276 /* We handle only functions that return an integer. */
17277 if (!is_handled_procedure_type (TREE_TYPE (TREE_TYPE (callee
))))
17278 goto call_expansion_failed
;
17280 dwarf_proc
= function_to_dwarf_procedure (callee
);
17281 if (dwarf_proc
== NULL
)
17282 goto call_expansion_failed
;
17284 /* Evaluate arguments right-to-left so that the first argument will
17285 be the top-most one on the stack. */
17286 for (i
= nargs
- 1; i
>= 0; --i
)
17288 dw_loc_descr_ref loc_descr
17289 = loc_descriptor_from_tree (CALL_EXPR_ARG (loc
, i
), 0,
17292 if (loc_descr
== NULL
)
17293 goto call_expansion_failed
;
17295 add_loc_descr (&ret
, loc_descr
);
17298 ret1
= new_loc_descr (DW_OP_call4
, 0, 0);
17299 ret1
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
17300 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.die
= dwarf_proc
;
17301 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
17302 add_loc_descr (&ret
, ret1
);
17305 call_expansion_failed
:
17306 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
17307 /* There are no opcodes for these operations. */
17311 case PREINCREMENT_EXPR
:
17312 case PREDECREMENT_EXPR
:
17313 case POSTINCREMENT_EXPR
:
17314 case POSTDECREMENT_EXPR
:
17315 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
17316 /* There are no opcodes for these operations. */
17320 /* If we already want an address, see if there is INDIRECT_REF inside
17321 e.g. for &this->field. */
17324 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
17325 (loc
, want_address
== 2, context
);
17328 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
17329 && (ret
= cst_pool_loc_descr (loc
)))
17332 /* Otherwise, process the argument and look for the address. */
17333 if (!list_ret
&& !ret
)
17334 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 1, context
);
17338 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
17344 if (DECL_THREAD_LOCAL_P (loc
))
17347 enum dwarf_location_atom tls_op
;
17348 enum dtprel_bool dtprel
= dtprel_false
;
17350 if (targetm
.have_tls
)
17352 /* If this is not defined, we have no way to emit the
17354 if (!targetm
.asm_out
.output_dwarf_dtprel
)
17357 /* The way DW_OP_GNU_push_tls_address is specified, we
17358 can only look up addresses of objects in the current
17359 module. We used DW_OP_addr as first op, but that's
17360 wrong, because DW_OP_addr is relocated by the debug
17361 info consumer, while DW_OP_GNU_push_tls_address
17362 operand shouldn't be. */
17363 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
17365 dtprel
= dtprel_true
;
17366 /* We check for DWARF 5 here because gdb did not implement
17367 DW_OP_form_tls_address until after 7.12. */
17368 tls_op
= (dwarf_version
>= 5 ? DW_OP_form_tls_address
17369 : DW_OP_GNU_push_tls_address
);
17373 if (!targetm
.emutls
.debug_form_tls_address
17374 || !(dwarf_version
>= 3 || !dwarf_strict
))
17376 /* We stuffed the control variable into the DECL_VALUE_EXPR
17377 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
17378 no longer appear in gimple code. We used the control
17379 variable in specific so that we could pick it up here. */
17380 loc
= DECL_VALUE_EXPR (loc
);
17381 tls_op
= DW_OP_form_tls_address
;
17384 rtl
= rtl_for_decl_location (loc
);
17385 if (rtl
== NULL_RTX
)
17390 rtl
= XEXP (rtl
, 0);
17391 if (! CONSTANT_P (rtl
))
17394 ret
= new_addr_loc_descr (rtl
, dtprel
);
17395 ret1
= new_loc_descr (tls_op
, 0, 0);
17396 add_loc_descr (&ret
, ret1
);
17404 if (context
!= NULL
&& context
->dpi
!= NULL
17405 && DECL_CONTEXT (loc
) == context
->dpi
->fndecl
)
17407 /* We are generating code for a DWARF procedure and we want to access
17408 one of its arguments: find the appropriate argument offset and let
17409 the resolve_args_picking pass compute the offset that complies
17410 with the stack frame size. */
17414 for (cursor
= DECL_ARGUMENTS (context
->dpi
->fndecl
);
17415 cursor
!= NULL_TREE
&& cursor
!= loc
;
17416 cursor
= TREE_CHAIN (cursor
), ++i
)
17418 /* If we are translating a DWARF procedure, all referenced parameters
17419 must belong to the current function. */
17420 gcc_assert (cursor
!= NULL_TREE
);
17422 ret
= new_loc_descr (DW_OP_pick
, i
, 0);
17423 ret
->frame_offset_rel
= 1;
17429 if (DECL_HAS_VALUE_EXPR_P (loc
))
17430 return loc_list_from_tree_1 (DECL_VALUE_EXPR (loc
),
17431 want_address
, context
);
17434 case FUNCTION_DECL
:
17437 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
17439 if (loc_list
&& loc_list
->first
)
17441 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
17442 have_address
= want_address
!= 0;
17445 rtl
= rtl_for_decl_location (loc
);
17446 if (rtl
== NULL_RTX
)
17448 if (TREE_CODE (loc
) != FUNCTION_DECL
17450 && current_function_decl
17451 && want_address
!= 1
17452 && ! DECL_IGNORED_P (loc
)
17453 && (INTEGRAL_TYPE_P (TREE_TYPE (loc
))
17454 || POINTER_TYPE_P (TREE_TYPE (loc
)))
17455 && DECL_CONTEXT (loc
) == current_function_decl
17456 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc
)))
17457 <= DWARF2_ADDR_SIZE
))
17459 dw_die_ref ref
= lookup_decl_die (loc
);
17460 ret
= new_loc_descr (DW_OP_GNU_variable_value
, 0, 0);
17463 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
17464 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
17465 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
17469 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
17470 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= loc
;
17474 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
17477 else if (CONST_INT_P (rtl
))
17479 HOST_WIDE_INT val
= INTVAL (rtl
);
17480 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
17481 val
&= GET_MODE_MASK (DECL_MODE (loc
));
17482 ret
= int_loc_descriptor (val
);
17484 else if (GET_CODE (rtl
) == CONST_STRING
)
17486 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
17489 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
17490 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
17493 machine_mode mode
, mem_mode
;
17495 /* Certain constructs can only be represented at top-level. */
17496 if (want_address
== 2)
17498 ret
= loc_descriptor (rtl
, VOIDmode
,
17499 VAR_INIT_STATUS_INITIALIZED
);
17504 mode
= GET_MODE (rtl
);
17505 mem_mode
= VOIDmode
;
17509 mode
= get_address_mode (rtl
);
17510 rtl
= XEXP (rtl
, 0);
17513 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
17514 VAR_INIT_STATUS_INITIALIZED
);
17517 expansion_failed (loc
, rtl
,
17518 "failed to produce loc descriptor for rtl");
17524 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
17531 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17535 case TARGET_MEM_REF
:
17537 case DEBUG_EXPR_DECL
:
17540 case COMPOUND_EXPR
:
17541 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), want_address
,
17545 case VIEW_CONVERT_EXPR
:
17548 case NON_LVALUE_EXPR
:
17549 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), want_address
,
17552 case COMPONENT_REF
:
17553 case BIT_FIELD_REF
:
17555 case ARRAY_RANGE_REF
:
17556 case REALPART_EXPR
:
17557 case IMAGPART_EXPR
:
17560 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
17562 int unsignedp
, reversep
, volatilep
= 0;
17564 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
17565 &unsignedp
, &reversep
, &volatilep
);
17567 gcc_assert (obj
!= loc
);
17569 list_ret
= loc_list_from_tree_1 (obj
,
17571 && !bitpos
&& !offset
? 2 : 1,
17573 /* TODO: We can extract value of the small expression via shifting even
17574 for nonzero bitpos. */
17577 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
17579 expansion_failed (loc
, NULL_RTX
,
17580 "bitfield access");
17584 if (offset
!= NULL_TREE
)
17586 /* Variable offset. */
17587 list_ret1
= loc_list_from_tree_1 (offset
, 0, context
);
17588 if (list_ret1
== 0)
17590 add_loc_list (&list_ret
, list_ret1
);
17593 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
17596 bytepos
= bitpos
/ BITS_PER_UNIT
;
17598 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
17599 else if (bytepos
< 0)
17600 loc_list_plus_const (list_ret
, bytepos
);
17607 if ((want_address
|| !tree_fits_shwi_p (loc
))
17608 && (ret
= cst_pool_loc_descr (loc
)))
17610 else if (want_address
== 2
17611 && tree_fits_shwi_p (loc
)
17612 && (ret
= address_of_int_loc_descriptor
17613 (int_size_in_bytes (TREE_TYPE (loc
)),
17614 tree_to_shwi (loc
))))
17616 else if (tree_fits_shwi_p (loc
))
17617 ret
= int_loc_descriptor (tree_to_shwi (loc
));
17618 else if (tree_fits_uhwi_p (loc
))
17619 ret
= uint_loc_descriptor (tree_to_uhwi (loc
));
17622 expansion_failed (loc
, NULL_RTX
,
17623 "Integer operand is not host integer");
17632 if ((ret
= cst_pool_loc_descr (loc
)))
17634 else if (TREE_CODE (loc
) == CONSTRUCTOR
)
17636 tree type
= TREE_TYPE (loc
);
17637 unsigned HOST_WIDE_INT size
= int_size_in_bytes (type
);
17638 unsigned HOST_WIDE_INT offset
= 0;
17639 unsigned HOST_WIDE_INT cnt
;
17640 constructor_elt
*ce
;
17642 if (TREE_CODE (type
) == RECORD_TYPE
)
17644 /* This is very limited, but it's enough to output
17645 pointers to member functions, as long as the
17646 referenced function is defined in the current
17647 translation unit. */
17648 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (loc
), cnt
, ce
)
17650 tree val
= ce
->value
;
17652 tree field
= ce
->index
;
17657 if (!field
|| DECL_BIT_FIELD (field
))
17659 expansion_failed (loc
, NULL_RTX
,
17660 "bitfield in record type constructor");
17661 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
17666 HOST_WIDE_INT fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
17667 unsigned HOST_WIDE_INT pos
= int_byte_position (field
);
17668 gcc_assert (pos
+ fieldsize
<= size
);
17671 expansion_failed (loc
, NULL_RTX
,
17672 "out-of-order fields in record constructor");
17673 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
17679 ret1
= new_loc_descr (DW_OP_piece
, pos
- offset
, 0);
17680 add_loc_descr (&ret
, ret1
);
17683 if (val
&& fieldsize
!= 0)
17685 ret1
= loc_descriptor_from_tree (val
, want_address
, context
);
17688 expansion_failed (loc
, NULL_RTX
,
17689 "unsupported expression in field");
17690 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
17694 add_loc_descr (&ret
, ret1
);
17698 ret1
= new_loc_descr (DW_OP_piece
, fieldsize
, 0);
17699 add_loc_descr (&ret
, ret1
);
17700 offset
= pos
+ fieldsize
;
17704 if (offset
!= size
)
17706 ret1
= new_loc_descr (DW_OP_piece
, size
- offset
, 0);
17707 add_loc_descr (&ret
, ret1
);
17711 have_address
= !!want_address
;
17714 expansion_failed (loc
, NULL_RTX
,
17715 "constructor of non-record type");
17718 /* We can construct small constants here using int_loc_descriptor. */
17719 expansion_failed (loc
, NULL_RTX
,
17720 "constructor or constant not in constant pool");
17723 case TRUTH_AND_EXPR
:
17724 case TRUTH_ANDIF_EXPR
:
17729 case TRUTH_XOR_EXPR
:
17734 case TRUTH_OR_EXPR
:
17735 case TRUTH_ORIF_EXPR
:
17740 case FLOOR_DIV_EXPR
:
17741 case CEIL_DIV_EXPR
:
17742 case ROUND_DIV_EXPR
:
17743 case TRUNC_DIV_EXPR
:
17744 case EXACT_DIV_EXPR
:
17745 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
17754 case FLOOR_MOD_EXPR
:
17755 case CEIL_MOD_EXPR
:
17756 case ROUND_MOD_EXPR
:
17757 case TRUNC_MOD_EXPR
:
17758 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
17763 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17764 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
17765 if (list_ret
== 0 || list_ret1
== 0)
17768 add_loc_list (&list_ret
, list_ret1
);
17771 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
17772 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
17773 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
17774 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
17775 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
17787 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
17790 case POINTER_PLUS_EXPR
:
17793 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
17795 /* Big unsigned numbers can fit in HOST_WIDE_INT but it may be
17796 smarter to encode their opposite. The DW_OP_plus_uconst operation
17797 takes 1 + X bytes, X being the size of the ULEB128 addend. On the
17798 other hand, a "<push literal>; DW_OP_minus" pattern takes 1 + Y
17799 bytes, Y being the size of the operation that pushes the opposite
17800 of the addend. So let's choose the smallest representation. */
17801 const tree tree_addend
= TREE_OPERAND (loc
, 1);
17802 offset_int wi_addend
;
17803 HOST_WIDE_INT shwi_addend
;
17804 dw_loc_descr_ref loc_naddend
;
17806 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17810 /* Try to get the literal to push. It is the opposite of the addend,
17811 so as we rely on wrapping during DWARF evaluation, first decode
17812 the literal as a "DWARF-sized" signed number. */
17813 wi_addend
= wi::to_offset (tree_addend
);
17814 wi_addend
= wi::sext (wi_addend
, DWARF2_ADDR_SIZE
* 8);
17815 shwi_addend
= wi_addend
.to_shwi ();
17816 loc_naddend
= (shwi_addend
!= INTTYPE_MINIMUM (HOST_WIDE_INT
))
17817 ? int_loc_descriptor (-shwi_addend
)
17820 if (loc_naddend
!= NULL
17821 && ((unsigned) size_of_uleb128 (shwi_addend
)
17822 > size_of_loc_descr (loc_naddend
)))
17824 add_loc_descr_to_each (list_ret
, loc_naddend
);
17825 add_loc_descr_to_each (list_ret
,
17826 new_loc_descr (DW_OP_minus
, 0, 0));
17830 for (dw_loc_descr_ref loc_cur
= loc_naddend
; loc_cur
!= NULL
; )
17832 loc_naddend
= loc_cur
;
17833 loc_cur
= loc_cur
->dw_loc_next
;
17834 ggc_free (loc_naddend
);
17836 loc_list_plus_const (list_ret
, wi_addend
.to_shwi ());
17846 goto do_comp_binop
;
17850 goto do_comp_binop
;
17854 goto do_comp_binop
;
17858 goto do_comp_binop
;
17861 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
17863 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
17864 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
17865 list_ret
= loc_list_from_uint_comparison (list_ret
, list_ret1
,
17881 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17882 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
17883 if (list_ret
== 0 || list_ret1
== 0)
17886 add_loc_list (&list_ret
, list_ret1
);
17889 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
17892 case TRUTH_NOT_EXPR
:
17906 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17910 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
17916 const enum tree_code code
=
17917 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
17919 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
17920 build2 (code
, integer_type_node
,
17921 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
17922 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
17929 dw_loc_descr_ref lhs
17930 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
17931 dw_loc_list_ref rhs
17932 = loc_list_from_tree_1 (TREE_OPERAND (loc
, 2), 0, context
);
17933 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
17935 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17936 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
17939 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
17940 add_loc_descr_to_each (list_ret
, bra_node
);
17942 add_loc_list (&list_ret
, rhs
);
17943 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
17944 add_loc_descr_to_each (list_ret
, jump_node
);
17946 add_loc_descr_to_each (list_ret
, lhs
);
17947 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
17948 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
17950 /* ??? Need a node to point the skip at. Use a nop. */
17951 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
17952 add_loc_descr_to_each (list_ret
, tmp
);
17953 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
17954 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
17958 case FIX_TRUNC_EXPR
:
17962 /* Leave front-end specific codes as simply unknown. This comes
17963 up, for instance, with the C STMT_EXPR. */
17964 if ((unsigned int) TREE_CODE (loc
)
17965 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
17967 expansion_failed (loc
, NULL_RTX
,
17968 "language specific tree node");
17972 /* Otherwise this is a generic code; we should just lists all of
17973 these explicitly. We forgot one. */
17975 gcc_unreachable ();
17977 /* In a release build, we want to degrade gracefully: better to
17978 generate incomplete debugging information than to crash. */
17982 if (!ret
&& !list_ret
)
17985 if (want_address
== 2 && !have_address
17986 && (dwarf_version
>= 4 || !dwarf_strict
))
17988 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
17990 expansion_failed (loc
, NULL_RTX
,
17991 "DWARF address size mismatch");
17995 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
17997 add_loc_descr_to_each (list_ret
,
17998 new_loc_descr (DW_OP_stack_value
, 0, 0));
18001 /* Show if we can't fill the request for an address. */
18002 if (want_address
&& !have_address
)
18004 expansion_failed (loc
, NULL_RTX
,
18005 "Want address and only have value");
18009 gcc_assert (!ret
|| !list_ret
);
18011 /* If we've got an address and don't want one, dereference. */
18012 if (!want_address
&& have_address
)
18014 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
18016 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
18018 expansion_failed (loc
, NULL_RTX
,
18019 "DWARF address size mismatch");
18022 else if (size
== DWARF2_ADDR_SIZE
)
18025 op
= DW_OP_deref_size
;
18028 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
18030 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
18033 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
18038 /* Likewise, but strip useless DW_OP_nop operations in the resulting
18041 static dw_loc_list_ref
18042 loc_list_from_tree (tree loc
, int want_address
,
18043 struct loc_descr_context
*context
)
18045 dw_loc_list_ref result
= loc_list_from_tree_1 (loc
, want_address
, context
);
18047 for (dw_loc_list_ref loc_cur
= result
;
18048 loc_cur
!= NULL
; loc_cur
= loc_cur
->dw_loc_next
)
18049 loc_descr_without_nops (loc_cur
->expr
);
18053 /* Same as above but return only single location expression. */
18054 static dw_loc_descr_ref
18055 loc_descriptor_from_tree (tree loc
, int want_address
,
18056 struct loc_descr_context
*context
)
18058 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
, context
);
18061 if (ret
->dw_loc_next
)
18063 expansion_failed (loc
, NULL_RTX
,
18064 "Location list where only loc descriptor needed");
18070 /* Given a value, round it up to the lowest multiple of `boundary'
18071 which is not less than the value itself. */
18073 static inline HOST_WIDE_INT
18074 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
18076 return (((value
+ boundary
- 1) / boundary
) * boundary
);
18079 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
18080 pointer to the declared type for the relevant field variable, or return
18081 `integer_type_node' if the given node turns out to be an
18082 ERROR_MARK node. */
18085 field_type (const_tree decl
)
18089 if (TREE_CODE (decl
) == ERROR_MARK
)
18090 return integer_type_node
;
18092 type
= DECL_BIT_FIELD_TYPE (decl
);
18093 if (type
== NULL_TREE
)
18094 type
= TREE_TYPE (decl
);
18099 /* Given a pointer to a tree node, return the alignment in bits for
18100 it, or else return BITS_PER_WORD if the node actually turns out to
18101 be an ERROR_MARK node. */
18103 static inline unsigned
18104 simple_type_align_in_bits (const_tree type
)
18106 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
18109 static inline unsigned
18110 simple_decl_align_in_bits (const_tree decl
)
18112 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
18115 /* Return the result of rounding T up to ALIGN. */
18117 static inline offset_int
18118 round_up_to_align (const offset_int
&t
, unsigned int align
)
18120 return wi::udiv_trunc (t
+ align
- 1, align
) * align
;
18123 /* Compute the size of TYPE in bytes. If possible, return NULL and store the
18124 size as an integer constant in CST_SIZE. Otherwise, if possible, return a
18125 DWARF expression that computes the size. Return NULL and set CST_SIZE to -1
18126 if we fail to return the size in one of these two forms. */
18128 static dw_loc_descr_ref
18129 type_byte_size (const_tree type
, HOST_WIDE_INT
*cst_size
)
18132 struct loc_descr_context ctx
;
18134 /* Return a constant integer in priority, if possible. */
18135 *cst_size
= int_size_in_bytes (type
);
18136 if (*cst_size
!= -1)
18139 ctx
.context_type
= const_cast<tree
> (type
);
18140 ctx
.base_decl
= NULL_TREE
;
18142 ctx
.placeholder_arg
= false;
18143 ctx
.placeholder_seen
= false;
18145 type
= TYPE_MAIN_VARIANT (type
);
18146 tree_size
= TYPE_SIZE_UNIT (type
);
18147 return ((tree_size
!= NULL_TREE
)
18148 ? loc_descriptor_from_tree (tree_size
, 0, &ctx
)
18152 /* Helper structure for RECORD_TYPE processing. */
18155 /* Root RECORD_TYPE. It is needed to generate data member location
18156 descriptions in variable-length records (VLR), but also to cope with
18157 variants, which are composed of nested structures multiplexed with
18158 QUAL_UNION_TYPE nodes. Each time such a structure is passed to a
18159 function processing a FIELD_DECL, it is required to be non null. */
18161 /* When generating a variant part in a RECORD_TYPE (i.e. a nested
18162 QUAL_UNION_TYPE), this holds an expression that computes the offset for
18163 this variant part as part of the root record (in storage units). For
18164 regular records, it must be NULL_TREE. */
18165 tree variant_part_offset
;
18168 /* Given a pointer to a FIELD_DECL, compute the byte offset of the lowest
18169 addressed byte of the "containing object" for the given FIELD_DECL. If
18170 possible, return a native constant through CST_OFFSET (in which case NULL is
18171 returned); otherwise return a DWARF expression that computes the offset.
18173 Set *CST_OFFSET to 0 and return NULL if we are unable to determine what
18174 that offset is, either because the argument turns out to be a pointer to an
18175 ERROR_MARK node, or because the offset expression is too complex for us.
18177 CTX is required: see the comment for VLR_CONTEXT. */
18179 static dw_loc_descr_ref
18180 field_byte_offset (const_tree decl
, struct vlr_context
*ctx
,
18181 HOST_WIDE_INT
*cst_offset
)
18184 dw_loc_list_ref loc_result
;
18188 if (TREE_CODE (decl
) == ERROR_MARK
)
18191 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
18193 /* We cannot handle variable bit offsets at the moment, so abort if it's the
18195 if (TREE_CODE (DECL_FIELD_BIT_OFFSET (decl
)) != INTEGER_CST
)
18198 #ifdef PCC_BITFIELD_TYPE_MATTERS
18199 /* We used to handle only constant offsets in all cases. Now, we handle
18200 properly dynamic byte offsets only when PCC bitfield type doesn't
18202 if (PCC_BITFIELD_TYPE_MATTERS
18203 && TREE_CODE (DECL_FIELD_OFFSET (decl
)) == INTEGER_CST
)
18205 offset_int object_offset_in_bits
;
18206 offset_int object_offset_in_bytes
;
18207 offset_int bitpos_int
;
18209 tree field_size_tree
;
18210 offset_int deepest_bitpos
;
18211 offset_int field_size_in_bits
;
18212 unsigned int type_align_in_bits
;
18213 unsigned int decl_align_in_bits
;
18214 offset_int type_size_in_bits
;
18216 bitpos_int
= wi::to_offset (bit_position (decl
));
18217 type
= field_type (decl
);
18218 type_size_in_bits
= offset_int_type_size_in_bits (type
);
18219 type_align_in_bits
= simple_type_align_in_bits (type
);
18221 field_size_tree
= DECL_SIZE (decl
);
18223 /* The size could be unspecified if there was an error, or for
18224 a flexible array member. */
18225 if (!field_size_tree
)
18226 field_size_tree
= bitsize_zero_node
;
18228 /* If the size of the field is not constant, use the type size. */
18229 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
18230 field_size_in_bits
= wi::to_offset (field_size_tree
);
18232 field_size_in_bits
= type_size_in_bits
;
18234 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
18236 /* The GCC front-end doesn't make any attempt to keep track of the
18237 starting bit offset (relative to the start of the containing
18238 structure type) of the hypothetical "containing object" for a
18239 bit-field. Thus, when computing the byte offset value for the
18240 start of the "containing object" of a bit-field, we must deduce
18241 this information on our own. This can be rather tricky to do in
18242 some cases. For example, handling the following structure type
18243 definition when compiling for an i386/i486 target (which only
18244 aligns long long's to 32-bit boundaries) can be very tricky:
18246 struct S { int field1; long long field2:31; };
18248 Fortunately, there is a simple rule-of-thumb which can be used
18249 in such cases. When compiling for an i386/i486, GCC will
18250 allocate 8 bytes for the structure shown above. It decides to
18251 do this based upon one simple rule for bit-field allocation.
18252 GCC allocates each "containing object" for each bit-field at
18253 the first (i.e. lowest addressed) legitimate alignment boundary
18254 (based upon the required minimum alignment for the declared
18255 type of the field) which it can possibly use, subject to the
18256 condition that there is still enough available space remaining
18257 in the containing object (when allocated at the selected point)
18258 to fully accommodate all of the bits of the bit-field itself.
18260 This simple rule makes it obvious why GCC allocates 8 bytes for
18261 each object of the structure type shown above. When looking
18262 for a place to allocate the "containing object" for `field2',
18263 the compiler simply tries to allocate a 64-bit "containing
18264 object" at each successive 32-bit boundary (starting at zero)
18265 until it finds a place to allocate that 64- bit field such that
18266 at least 31 contiguous (and previously unallocated) bits remain
18267 within that selected 64 bit field. (As it turns out, for the
18268 example above, the compiler finds it is OK to allocate the
18269 "containing object" 64-bit field at bit-offset zero within the
18272 Here we attempt to work backwards from the limited set of facts
18273 we're given, and we try to deduce from those facts, where GCC
18274 must have believed that the containing object started (within
18275 the structure type). The value we deduce is then used (by the
18276 callers of this routine) to generate DW_AT_location and
18277 DW_AT_bit_offset attributes for fields (both bit-fields and, in
18278 the case of DW_AT_location, regular fields as well). */
18280 /* Figure out the bit-distance from the start of the structure to
18281 the "deepest" bit of the bit-field. */
18282 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
18284 /* This is the tricky part. Use some fancy footwork to deduce
18285 where the lowest addressed bit of the containing object must
18287 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
18289 /* Round up to type_align by default. This works best for
18291 object_offset_in_bits
18292 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
18294 if (wi::gtu_p (object_offset_in_bits
, bitpos_int
))
18296 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
18298 /* Round up to decl_align instead. */
18299 object_offset_in_bits
18300 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
18303 object_offset_in_bytes
18304 = wi::lrshift (object_offset_in_bits
, LOG2_BITS_PER_UNIT
);
18305 if (ctx
->variant_part_offset
== NULL_TREE
)
18307 *cst_offset
= object_offset_in_bytes
.to_shwi ();
18310 tree_result
= wide_int_to_tree (sizetype
, object_offset_in_bytes
);
18313 #endif /* PCC_BITFIELD_TYPE_MATTERS */
18314 tree_result
= byte_position (decl
);
18316 if (ctx
->variant_part_offset
!= NULL_TREE
)
18317 tree_result
= fold_build2 (PLUS_EXPR
, TREE_TYPE (tree_result
),
18318 ctx
->variant_part_offset
, tree_result
);
18320 /* If the byte offset is a constant, it's simplier to handle a native
18321 constant rather than a DWARF expression. */
18322 if (TREE_CODE (tree_result
) == INTEGER_CST
)
18324 *cst_offset
= wi::to_offset (tree_result
).to_shwi ();
18327 struct loc_descr_context loc_ctx
= {
18328 ctx
->struct_type
, /* context_type */
18329 NULL_TREE
, /* base_decl */
18331 false, /* placeholder_arg */
18332 false /* placeholder_seen */
18334 loc_result
= loc_list_from_tree (tree_result
, 0, &loc_ctx
);
18336 /* We want a DWARF expression: abort if we only have a location list with
18337 multiple elements. */
18338 if (!loc_result
|| !single_element_loc_list_p (loc_result
))
18341 return loc_result
->expr
;
18344 /* The following routines define various Dwarf attributes and any data
18345 associated with them. */
18347 /* Add a location description attribute value to a DIE.
18349 This emits location attributes suitable for whole variables and
18350 whole parameters. Note that the location attributes for struct fields are
18351 generated by the routine `data_member_location_attribute' below. */
18354 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
18355 dw_loc_list_ref descr
)
18359 if (single_element_loc_list_p (descr
))
18360 add_AT_loc (die
, attr_kind
, descr
->expr
);
18362 add_AT_loc_list (die
, attr_kind
, descr
);
18365 /* Add DW_AT_accessibility attribute to DIE if needed. */
18368 add_accessibility_attribute (dw_die_ref die
, tree decl
)
18370 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
18371 children, otherwise the default is DW_ACCESS_public. In DWARF2
18372 the default has always been DW_ACCESS_public. */
18373 if (TREE_PROTECTED (decl
))
18374 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
18375 else if (TREE_PRIVATE (decl
))
18377 if (dwarf_version
== 2
18378 || die
->die_parent
== NULL
18379 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
18380 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
18382 else if (dwarf_version
> 2
18384 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
18385 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
18388 /* Attach the specialized form of location attribute used for data members of
18389 struct and union types. In the special case of a FIELD_DECL node which
18390 represents a bit-field, the "offset" part of this special location
18391 descriptor must indicate the distance in bytes from the lowest-addressed
18392 byte of the containing struct or union type to the lowest-addressed byte of
18393 the "containing object" for the bit-field. (See the `field_byte_offset'
18396 For any given bit-field, the "containing object" is a hypothetical object
18397 (of some integral or enum type) within which the given bit-field lives. The
18398 type of this hypothetical "containing object" is always the same as the
18399 declared type of the individual bit-field itself (for GCC anyway... the
18400 DWARF spec doesn't actually mandate this). Note that it is the size (in
18401 bytes) of the hypothetical "containing object" which will be given in the
18402 DW_AT_byte_size attribute for this bit-field. (See the
18403 `byte_size_attribute' function below.) It is also used when calculating the
18404 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
18407 CTX is required: see the comment for VLR_CONTEXT. */
18410 add_data_member_location_attribute (dw_die_ref die
,
18412 struct vlr_context
*ctx
)
18414 HOST_WIDE_INT offset
;
18415 dw_loc_descr_ref loc_descr
= 0;
18417 if (TREE_CODE (decl
) == TREE_BINFO
)
18419 /* We're working on the TAG_inheritance for a base class. */
18420 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
18422 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
18423 aren't at a fixed offset from all (sub)objects of the same
18424 type. We need to extract the appropriate offset from our
18425 vtable. The following dwarf expression means
18427 BaseAddr = ObAddr + *((*ObAddr) - Offset)
18429 This is specific to the V3 ABI, of course. */
18431 dw_loc_descr_ref tmp
;
18433 /* Make a copy of the object address. */
18434 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
18435 add_loc_descr (&loc_descr
, tmp
);
18437 /* Extract the vtable address. */
18438 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
18439 add_loc_descr (&loc_descr
, tmp
);
18441 /* Calculate the address of the offset. */
18442 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
18443 gcc_assert (offset
< 0);
18445 tmp
= int_loc_descriptor (-offset
);
18446 add_loc_descr (&loc_descr
, tmp
);
18447 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
18448 add_loc_descr (&loc_descr
, tmp
);
18450 /* Extract the offset. */
18451 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
18452 add_loc_descr (&loc_descr
, tmp
);
18454 /* Add it to the object address. */
18455 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
18456 add_loc_descr (&loc_descr
, tmp
);
18459 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
18463 loc_descr
= field_byte_offset (decl
, ctx
, &offset
);
18465 /* If loc_descr is available then we know the field offset is dynamic.
18466 However, GDB does not handle dynamic field offsets very well at the
18468 if (loc_descr
!= NULL
&& gnat_encodings
!= DWARF_GNAT_ENCODINGS_MINIMAL
)
18474 /* Data member location evalutation starts with the base address on the
18475 stack. Compute the field offset and add it to this base address. */
18476 else if (loc_descr
!= NULL
)
18477 add_loc_descr (&loc_descr
, new_loc_descr (DW_OP_plus
, 0, 0));
18482 /* While DW_AT_data_bit_offset has been added already in DWARF4,
18483 e.g. GDB only added support to it in November 2016. For DWARF5
18484 we need newer debug info consumers anyway. We might change this
18485 to dwarf_version >= 4 once most consumers catched up. */
18486 if (dwarf_version
>= 5
18487 && TREE_CODE (decl
) == FIELD_DECL
18488 && DECL_BIT_FIELD_TYPE (decl
))
18490 tree off
= bit_position (decl
);
18491 if (tree_fits_uhwi_p (off
) && get_AT (die
, DW_AT_bit_size
))
18493 remove_AT (die
, DW_AT_byte_size
);
18494 remove_AT (die
, DW_AT_bit_offset
);
18495 add_AT_unsigned (die
, DW_AT_data_bit_offset
, tree_to_uhwi (off
));
18499 if (dwarf_version
> 2)
18501 /* Don't need to output a location expression, just the constant. */
18503 add_AT_int (die
, DW_AT_data_member_location
, offset
);
18505 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
18510 enum dwarf_location_atom op
;
18512 /* The DWARF2 standard says that we should assume that the structure
18513 address is already on the stack, so we can specify a structure
18514 field address by using DW_OP_plus_uconst. */
18515 op
= DW_OP_plus_uconst
;
18516 loc_descr
= new_loc_descr (op
, offset
, 0);
18520 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
18523 /* Writes integer values to dw_vec_const array. */
18526 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
18530 *dest
++ = val
& 0xff;
18536 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
18538 static HOST_WIDE_INT
18539 extract_int (const unsigned char *src
, unsigned int size
)
18541 HOST_WIDE_INT val
= 0;
18547 val
|= *--src
& 0xff;
18553 /* Writes wide_int values to dw_vec_const array. */
18556 insert_wide_int (const wide_int
&val
, unsigned char *dest
, int elt_size
)
18560 if (elt_size
<= HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
)
18562 insert_int ((HOST_WIDE_INT
) val
.elt (0), elt_size
, dest
);
18566 /* We'd have to extend this code to support odd sizes. */
18567 gcc_assert (elt_size
% (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
) == 0);
18569 int n
= elt_size
/ (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
18571 if (WORDS_BIG_ENDIAN
)
18572 for (i
= n
- 1; i
>= 0; i
--)
18574 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
18575 dest
+= sizeof (HOST_WIDE_INT
);
18578 for (i
= 0; i
< n
; i
++)
18580 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
18581 dest
+= sizeof (HOST_WIDE_INT
);
18585 /* Writes floating point values to dw_vec_const array. */
18588 insert_float (const_rtx rtl
, unsigned char *array
)
18593 real_to_target (val
, CONST_DOUBLE_REAL_VALUE (rtl
), GET_MODE (rtl
));
18595 /* real_to_target puts 32-bit pieces in each long. Pack them. */
18596 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
18598 insert_int (val
[i
], 4, array
);
18603 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
18604 does not have a "location" either in memory or in a register. These
18605 things can arise in GNU C when a constant is passed as an actual parameter
18606 to an inlined function. They can also arise in C++ where declared
18607 constants do not necessarily get memory "homes". */
18610 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
18612 switch (GET_CODE (rtl
))
18616 HOST_WIDE_INT val
= INTVAL (rtl
);
18619 add_AT_int (die
, DW_AT_const_value
, val
);
18621 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
18625 case CONST_WIDE_INT
:
18627 wide_int w1
= rtx_mode_t (rtl
, MAX_MODE_INT
);
18628 unsigned int prec
= MIN (wi::min_precision (w1
, UNSIGNED
),
18629 (unsigned int)CONST_WIDE_INT_NUNITS (rtl
) * HOST_BITS_PER_WIDE_INT
);
18630 wide_int w
= wi::zext (w1
, prec
);
18631 add_AT_wide (die
, DW_AT_const_value
, w
);
18636 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
18637 floating-point constant. A CONST_DOUBLE is used whenever the
18638 constant requires more than one word in order to be adequately
18641 machine_mode mode
= GET_MODE (rtl
);
18643 if (TARGET_SUPPORTS_WIDE_INT
== 0 && !SCALAR_FLOAT_MODE_P (mode
))
18644 add_AT_double (die
, DW_AT_const_value
,
18645 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
18648 unsigned int length
= GET_MODE_SIZE (mode
);
18649 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
18651 insert_float (rtl
, array
);
18652 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
18659 machine_mode mode
= GET_MODE (rtl
);
18660 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
18661 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
18662 unsigned char *array
18663 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
18666 machine_mode imode
= GET_MODE_INNER (mode
);
18668 switch (GET_MODE_CLASS (mode
))
18670 case MODE_VECTOR_INT
:
18671 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
18673 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
18674 insert_wide_int (rtx_mode_t (elt
, imode
), p
, elt_size
);
18678 case MODE_VECTOR_FLOAT
:
18679 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
18681 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
18682 insert_float (elt
, p
);
18687 gcc_unreachable ();
18690 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
18695 if (dwarf_version
>= 4 || !dwarf_strict
)
18697 dw_loc_descr_ref loc_result
;
18698 resolve_one_addr (&rtl
);
18700 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
18701 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
18702 add_AT_loc (die
, DW_AT_location
, loc_result
);
18703 vec_safe_push (used_rtx_array
, rtl
);
18709 if (CONSTANT_P (XEXP (rtl
, 0)))
18710 return add_const_value_attribute (die
, XEXP (rtl
, 0));
18713 if (!const_ok_for_output (rtl
))
18717 if (dwarf_version
>= 4 || !dwarf_strict
)
18722 /* In cases where an inlined instance of an inline function is passed
18723 the address of an `auto' variable (which is local to the caller) we
18724 can get a situation where the DECL_RTL of the artificial local
18725 variable (for the inlining) which acts as a stand-in for the
18726 corresponding formal parameter (of the inline function) will look
18727 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
18728 exactly a compile-time constant expression, but it isn't the address
18729 of the (artificial) local variable either. Rather, it represents the
18730 *value* which the artificial local variable always has during its
18731 lifetime. We currently have no way to represent such quasi-constant
18732 values in Dwarf, so for now we just punt and generate nothing. */
18740 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
18741 && MEM_READONLY_P (rtl
)
18742 && GET_MODE (rtl
) == BLKmode
)
18744 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
18750 /* No other kinds of rtx should be possible here. */
18751 gcc_unreachable ();
18756 /* Determine whether the evaluation of EXPR references any variables
18757 or functions which aren't otherwise used (and therefore may not be
18760 reference_to_unused (tree
* tp
, int * walk_subtrees
,
18761 void * data ATTRIBUTE_UNUSED
)
18763 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
18764 *walk_subtrees
= 0;
18766 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
18767 && ! TREE_ASM_WRITTEN (*tp
))
18769 /* ??? The C++ FE emits debug information for using decls, so
18770 putting gcc_unreachable here falls over. See PR31899. For now
18771 be conservative. */
18772 else if (!symtab
->global_info_ready
&& VAR_OR_FUNCTION_DECL_P (*tp
))
18774 else if (VAR_P (*tp
))
18776 varpool_node
*node
= varpool_node::get (*tp
);
18777 if (!node
|| !node
->definition
)
18780 else if (TREE_CODE (*tp
) == FUNCTION_DECL
18781 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
18783 /* The call graph machinery must have finished analyzing,
18784 optimizing and gimplifying the CU by now.
18785 So if *TP has no call graph node associated
18786 to it, it means *TP will not be emitted. */
18787 if (!cgraph_node::get (*tp
))
18790 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
18796 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
18797 for use in a later add_const_value_attribute call. */
18800 rtl_for_decl_init (tree init
, tree type
)
18802 rtx rtl
= NULL_RTX
;
18806 /* If a variable is initialized with a string constant without embedded
18807 zeros, build CONST_STRING. */
18808 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
18810 tree enttype
= TREE_TYPE (type
);
18811 tree domain
= TYPE_DOMAIN (type
);
18812 machine_mode mode
= TYPE_MODE (enttype
);
18814 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
18816 && integer_zerop (TYPE_MIN_VALUE (domain
))
18817 && compare_tree_int (TYPE_MAX_VALUE (domain
),
18818 TREE_STRING_LENGTH (init
) - 1) == 0
18819 && ((size_t) TREE_STRING_LENGTH (init
)
18820 == strlen (TREE_STRING_POINTER (init
)) + 1))
18822 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
18823 ggc_strdup (TREE_STRING_POINTER (init
)));
18824 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
18825 MEM_READONLY_P (rtl
) = 1;
18828 /* Other aggregates, and complex values, could be represented using
18830 else if (AGGREGATE_TYPE_P (type
)
18831 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
18832 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
18833 || TREE_CODE (type
) == COMPLEX_TYPE
)
18835 /* Vectors only work if their mode is supported by the target.
18836 FIXME: generic vectors ought to work too. */
18837 else if (TREE_CODE (type
) == VECTOR_TYPE
18838 && !VECTOR_MODE_P (TYPE_MODE (type
)))
18840 /* If the initializer is something that we know will expand into an
18841 immediate RTL constant, expand it now. We must be careful not to
18842 reference variables which won't be output. */
18843 else if (initializer_constant_valid_p (init
, type
)
18844 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
18846 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
18848 if (TREE_CODE (type
) == VECTOR_TYPE
)
18849 switch (TREE_CODE (init
))
18854 if (TREE_CONSTANT (init
))
18856 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
18857 bool constant_p
= true;
18859 unsigned HOST_WIDE_INT ix
;
18861 /* Even when ctor is constant, it might contain non-*_CST
18862 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
18863 belong into VECTOR_CST nodes. */
18864 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
18865 if (!CONSTANT_CLASS_P (value
))
18867 constant_p
= false;
18873 init
= build_vector_from_ctor (type
, elts
);
18883 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
18885 /* If expand_expr returns a MEM, it wasn't immediate. */
18886 gcc_assert (!rtl
|| !MEM_P (rtl
));
18892 /* Generate RTL for the variable DECL to represent its location. */
18895 rtl_for_decl_location (tree decl
)
18899 /* Here we have to decide where we are going to say the parameter "lives"
18900 (as far as the debugger is concerned). We only have a couple of
18901 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
18903 DECL_RTL normally indicates where the parameter lives during most of the
18904 activation of the function. If optimization is enabled however, this
18905 could be either NULL or else a pseudo-reg. Both of those cases indicate
18906 that the parameter doesn't really live anywhere (as far as the code
18907 generation parts of GCC are concerned) during most of the function's
18908 activation. That will happen (for example) if the parameter is never
18909 referenced within the function.
18911 We could just generate a location descriptor here for all non-NULL
18912 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
18913 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
18914 where DECL_RTL is NULL or is a pseudo-reg.
18916 Note however that we can only get away with using DECL_INCOMING_RTL as
18917 a backup substitute for DECL_RTL in certain limited cases. In cases
18918 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
18919 we can be sure that the parameter was passed using the same type as it is
18920 declared to have within the function, and that its DECL_INCOMING_RTL
18921 points us to a place where a value of that type is passed.
18923 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
18924 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
18925 because in these cases DECL_INCOMING_RTL points us to a value of some
18926 type which is *different* from the type of the parameter itself. Thus,
18927 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
18928 such cases, the debugger would end up (for example) trying to fetch a
18929 `float' from a place which actually contains the first part of a
18930 `double'. That would lead to really incorrect and confusing
18931 output at debug-time.
18933 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
18934 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
18935 are a couple of exceptions however. On little-endian machines we can
18936 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
18937 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
18938 an integral type that is smaller than TREE_TYPE (decl). These cases arise
18939 when (on a little-endian machine) a non-prototyped function has a
18940 parameter declared to be of type `short' or `char'. In such cases,
18941 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
18942 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
18943 passed `int' value. If the debugger then uses that address to fetch
18944 a `short' or a `char' (on a little-endian machine) the result will be
18945 the correct data, so we allow for such exceptional cases below.
18947 Note that our goal here is to describe the place where the given formal
18948 parameter lives during most of the function's activation (i.e. between the
18949 end of the prologue and the start of the epilogue). We'll do that as best
18950 as we can. Note however that if the given formal parameter is modified
18951 sometime during the execution of the function, then a stack backtrace (at
18952 debug-time) will show the function as having been called with the *new*
18953 value rather than the value which was originally passed in. This happens
18954 rarely enough that it is not a major problem, but it *is* a problem, and
18955 I'd like to fix it.
18957 A future version of dwarf2out.c may generate two additional attributes for
18958 any given DW_TAG_formal_parameter DIE which will describe the "passed
18959 type" and the "passed location" for the given formal parameter in addition
18960 to the attributes we now generate to indicate the "declared type" and the
18961 "active location" for each parameter. This additional set of attributes
18962 could be used by debuggers for stack backtraces. Separately, note that
18963 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
18964 This happens (for example) for inlined-instances of inline function formal
18965 parameters which are never referenced. This really shouldn't be
18966 happening. All PARM_DECL nodes should get valid non-NULL
18967 DECL_INCOMING_RTL values. FIXME. */
18969 /* Use DECL_RTL as the "location" unless we find something better. */
18970 rtl
= DECL_RTL_IF_SET (decl
);
18972 /* When generating abstract instances, ignore everything except
18973 constants, symbols living in memory, and symbols living in
18974 fixed registers. */
18975 if (! reload_completed
)
18978 && (CONSTANT_P (rtl
)
18980 && CONSTANT_P (XEXP (rtl
, 0)))
18983 && TREE_STATIC (decl
))))
18985 rtl
= targetm
.delegitimize_address (rtl
);
18990 else if (TREE_CODE (decl
) == PARM_DECL
)
18992 if (rtl
== NULL_RTX
18993 || is_pseudo_reg (rtl
)
18995 && is_pseudo_reg (XEXP (rtl
, 0))
18996 && DECL_INCOMING_RTL (decl
)
18997 && MEM_P (DECL_INCOMING_RTL (decl
))
18998 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
19000 tree declared_type
= TREE_TYPE (decl
);
19001 tree passed_type
= DECL_ARG_TYPE (decl
);
19002 machine_mode dmode
= TYPE_MODE (declared_type
);
19003 machine_mode pmode
= TYPE_MODE (passed_type
);
19005 /* This decl represents a formal parameter which was optimized out.
19006 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
19007 all cases where (rtl == NULL_RTX) just below. */
19008 if (dmode
== pmode
)
19009 rtl
= DECL_INCOMING_RTL (decl
);
19010 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
19011 && SCALAR_INT_MODE_P (dmode
)
19012 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
19013 && DECL_INCOMING_RTL (decl
))
19015 rtx inc
= DECL_INCOMING_RTL (decl
);
19018 else if (MEM_P (inc
))
19020 if (BYTES_BIG_ENDIAN
)
19021 rtl
= adjust_address_nv (inc
, dmode
,
19022 GET_MODE_SIZE (pmode
)
19023 - GET_MODE_SIZE (dmode
));
19030 /* If the parm was passed in registers, but lives on the stack, then
19031 make a big endian correction if the mode of the type of the
19032 parameter is not the same as the mode of the rtl. */
19033 /* ??? This is the same series of checks that are made in dbxout.c before
19034 we reach the big endian correction code there. It isn't clear if all
19035 of these checks are necessary here, but keeping them all is the safe
19037 else if (MEM_P (rtl
)
19038 && XEXP (rtl
, 0) != const0_rtx
19039 && ! CONSTANT_P (XEXP (rtl
, 0))
19040 /* Not passed in memory. */
19041 && !MEM_P (DECL_INCOMING_RTL (decl
))
19042 /* Not passed by invisible reference. */
19043 && (!REG_P (XEXP (rtl
, 0))
19044 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
19045 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
19046 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
19047 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
19050 /* Big endian correction check. */
19051 && BYTES_BIG_ENDIAN
19052 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
19053 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
19056 machine_mode addr_mode
= get_address_mode (rtl
);
19057 int offset
= (UNITS_PER_WORD
19058 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
19060 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
19061 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
19064 else if (VAR_P (decl
)
19067 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
19068 && BYTES_BIG_ENDIAN
)
19070 machine_mode addr_mode
= get_address_mode (rtl
);
19071 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
19072 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
19074 /* If a variable is declared "register" yet is smaller than
19075 a register, then if we store the variable to memory, it
19076 looks like we're storing a register-sized value, when in
19077 fact we are not. We need to adjust the offset of the
19078 storage location to reflect the actual value's bytes,
19079 else gdb will not be able to display it. */
19081 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
19082 plus_constant (addr_mode
, XEXP (rtl
, 0),
19086 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
19087 and will have been substituted directly into all expressions that use it.
19088 C does not have such a concept, but C++ and other languages do. */
19089 if (!rtl
&& VAR_P (decl
) && DECL_INITIAL (decl
))
19090 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
19093 rtl
= targetm
.delegitimize_address (rtl
);
19095 /* If we don't look past the constant pool, we risk emitting a
19096 reference to a constant pool entry that isn't referenced from
19097 code, and thus is not emitted. */
19099 rtl
= avoid_constant_pool_reference (rtl
);
19101 /* Try harder to get a rtl. If this symbol ends up not being emitted
19102 in the current CU, resolve_addr will remove the expression referencing
19104 if (rtl
== NULL_RTX
19106 && !DECL_EXTERNAL (decl
)
19107 && TREE_STATIC (decl
)
19108 && DECL_NAME (decl
)
19109 && !DECL_HARD_REGISTER (decl
)
19110 && DECL_MODE (decl
) != VOIDmode
)
19112 rtl
= make_decl_rtl_for_debug (decl
);
19114 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
19115 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
19122 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
19123 returned. If so, the decl for the COMMON block is returned, and the
19124 value is the offset into the common block for the symbol. */
19127 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
19129 tree val_expr
, cvar
;
19131 HOST_WIDE_INT bitsize
, bitpos
;
19133 int unsignedp
, reversep
, volatilep
= 0;
19135 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
19136 it does not have a value (the offset into the common area), or if it
19137 is thread local (as opposed to global) then it isn't common, and shouldn't
19138 be handled as such. */
19140 || !TREE_STATIC (decl
)
19141 || !DECL_HAS_VALUE_EXPR_P (decl
)
19145 val_expr
= DECL_VALUE_EXPR (decl
);
19146 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
19149 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
, &mode
,
19150 &unsignedp
, &reversep
, &volatilep
);
19152 if (cvar
== NULL_TREE
19154 || DECL_ARTIFICIAL (cvar
)
19155 || !TREE_PUBLIC (cvar
))
19159 if (offset
!= NULL
)
19161 if (!tree_fits_shwi_p (offset
))
19163 *value
= tree_to_shwi (offset
);
19166 *value
+= bitpos
/ BITS_PER_UNIT
;
19171 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
19172 data attribute for a variable or a parameter. We generate the
19173 DW_AT_const_value attribute only in those cases where the given variable
19174 or parameter does not have a true "location" either in memory or in a
19175 register. This can happen (for example) when a constant is passed as an
19176 actual argument in a call to an inline function. (It's possible that
19177 these things can crop up in other ways also.) Note that one type of
19178 constant value which can be passed into an inlined function is a constant
19179 pointer. This can happen for example if an actual argument in an inlined
19180 function call evaluates to a compile-time constant address.
19182 CACHE_P is true if it is worth caching the location list for DECL,
19183 so that future calls can reuse it rather than regenerate it from scratch.
19184 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
19185 since we will need to refer to them each time the function is inlined. */
19188 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
)
19191 dw_loc_list_ref list
;
19192 var_loc_list
*loc_list
;
19193 cached_dw_loc_list
*cache
;
19198 if (TREE_CODE (decl
) == ERROR_MARK
)
19201 if (get_AT (die
, DW_AT_location
)
19202 || get_AT (die
, DW_AT_const_value
))
19205 gcc_assert (VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
19206 || TREE_CODE (decl
) == RESULT_DECL
);
19208 /* Try to get some constant RTL for this decl, and use that as the value of
19211 rtl
= rtl_for_decl_location (decl
);
19212 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
19213 && add_const_value_attribute (die
, rtl
))
19216 /* See if we have single element location list that is equivalent to
19217 a constant value. That way we are better to use add_const_value_attribute
19218 rather than expanding constant value equivalent. */
19219 loc_list
= lookup_decl_loc (decl
);
19222 && loc_list
->first
->next
== NULL
19223 && NOTE_P (loc_list
->first
->loc
)
19224 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
19225 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
19227 struct var_loc_node
*node
;
19229 node
= loc_list
->first
;
19230 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
19231 if (GET_CODE (rtl
) == EXPR_LIST
)
19232 rtl
= XEXP (rtl
, 0);
19233 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
19234 && add_const_value_attribute (die
, rtl
))
19237 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
19238 list several times. See if we've already cached the contents. */
19240 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
19244 cache
= cached_dw_loc_list_table
->find_with_hash (decl
, DECL_UID (decl
));
19246 list
= cache
->loc_list
;
19250 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2,
19252 /* It is usually worth caching this result if the decl is from
19253 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
19254 if (cache_p
&& list
&& list
->dw_loc_next
)
19256 cached_dw_loc_list
**slot
19257 = cached_dw_loc_list_table
->find_slot_with_hash (decl
,
19260 cache
= ggc_cleared_alloc
<cached_dw_loc_list
> ();
19261 cache
->decl_id
= DECL_UID (decl
);
19262 cache
->loc_list
= list
;
19268 add_AT_location_description (die
, DW_AT_location
, list
);
19271 /* None of that worked, so it must not really have a location;
19272 try adding a constant value attribute from the DECL_INITIAL. */
19273 return tree_add_const_value_attribute_for_decl (die
, decl
);
19276 /* Helper function for tree_add_const_value_attribute. Natively encode
19277 initializer INIT into an array. Return true if successful. */
19280 native_encode_initializer (tree init
, unsigned char *array
, int size
)
19284 if (init
== NULL_TREE
)
19288 switch (TREE_CODE (init
))
19291 type
= TREE_TYPE (init
);
19292 if (TREE_CODE (type
) == ARRAY_TYPE
)
19294 tree enttype
= TREE_TYPE (type
);
19295 machine_mode mode
= TYPE_MODE (enttype
);
19297 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
19299 if (int_size_in_bytes (type
) != size
)
19301 if (size
> TREE_STRING_LENGTH (init
))
19303 memcpy (array
, TREE_STRING_POINTER (init
),
19304 TREE_STRING_LENGTH (init
));
19305 memset (array
+ TREE_STRING_LENGTH (init
),
19306 '\0', size
- TREE_STRING_LENGTH (init
));
19309 memcpy (array
, TREE_STRING_POINTER (init
), size
);
19314 type
= TREE_TYPE (init
);
19315 if (int_size_in_bytes (type
) != size
)
19317 if (TREE_CODE (type
) == ARRAY_TYPE
)
19319 HOST_WIDE_INT min_index
;
19320 unsigned HOST_WIDE_INT cnt
;
19321 int curpos
= 0, fieldsize
;
19322 constructor_elt
*ce
;
19324 if (TYPE_DOMAIN (type
) == NULL_TREE
19325 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))))
19328 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
19329 if (fieldsize
<= 0)
19332 min_index
= tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)));
19333 memset (array
, '\0', size
);
19334 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
19336 tree val
= ce
->value
;
19337 tree index
= ce
->index
;
19339 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
19340 pos
= (tree_to_shwi (TREE_OPERAND (index
, 0)) - min_index
)
19343 pos
= (tree_to_shwi (index
) - min_index
) * fieldsize
;
19348 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
19351 curpos
= pos
+ fieldsize
;
19352 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
19354 int count
= tree_to_shwi (TREE_OPERAND (index
, 1))
19355 - tree_to_shwi (TREE_OPERAND (index
, 0));
19356 while (count
-- > 0)
19359 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
19360 curpos
+= fieldsize
;
19363 gcc_assert (curpos
<= size
);
19367 else if (TREE_CODE (type
) == RECORD_TYPE
19368 || TREE_CODE (type
) == UNION_TYPE
)
19370 tree field
= NULL_TREE
;
19371 unsigned HOST_WIDE_INT cnt
;
19372 constructor_elt
*ce
;
19374 if (int_size_in_bytes (type
) != size
)
19377 if (TREE_CODE (type
) == RECORD_TYPE
)
19378 field
= TYPE_FIELDS (type
);
19380 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
19382 tree val
= ce
->value
;
19383 int pos
, fieldsize
;
19385 if (ce
->index
!= 0)
19391 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
19394 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
19395 && TYPE_DOMAIN (TREE_TYPE (field
))
19396 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
19398 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
19399 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field
)))
19401 fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
19402 pos
= int_byte_position (field
);
19403 gcc_assert (pos
+ fieldsize
<= size
);
19404 if (val
&& fieldsize
!= 0
19405 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
19411 case VIEW_CONVERT_EXPR
:
19412 case NON_LVALUE_EXPR
:
19413 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
19415 return native_encode_expr (init
, array
, size
) == size
;
19419 /* Attach a DW_AT_const_value attribute to DIE. The value of the
19420 attribute is the const value T. */
19423 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
19426 tree type
= TREE_TYPE (t
);
19429 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
19433 gcc_assert (!DECL_P (init
));
19437 rtl
= rtl_for_decl_init (init
, type
);
19439 return add_const_value_attribute (die
, rtl
);
19441 /* If the host and target are sane, try harder. */
19442 if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
19443 && initializer_constant_valid_p (init
, type
))
19445 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
19446 if (size
> 0 && (int) size
== size
)
19448 unsigned char *array
= ggc_cleared_vec_alloc
<unsigned char> (size
);
19450 if (native_encode_initializer (init
, array
, size
))
19452 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
19461 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
19462 attribute is the const value of T, where T is an integral constant
19463 variable with static storage duration
19464 (so it can't be a PARM_DECL or a RESULT_DECL). */
19467 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
19471 || (!VAR_P (decl
) && TREE_CODE (decl
) != CONST_DECL
)
19472 || (VAR_P (decl
) && !TREE_STATIC (decl
)))
19475 if (TREE_READONLY (decl
)
19476 && ! TREE_THIS_VOLATILE (decl
)
19477 && DECL_INITIAL (decl
))
19482 /* Don't add DW_AT_const_value if abstract origin already has one. */
19483 if (get_AT (var_die
, DW_AT_const_value
))
19486 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
19489 /* Convert the CFI instructions for the current function into a
19490 location list. This is used for DW_AT_frame_base when we targeting
19491 a dwarf2 consumer that does not support the dwarf3
19492 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
19495 static dw_loc_list_ref
19496 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
19500 dw_loc_list_ref list
, *list_tail
;
19502 dw_cfa_location last_cfa
, next_cfa
;
19503 const char *start_label
, *last_label
, *section
;
19504 dw_cfa_location remember
;
19507 gcc_assert (fde
!= NULL
);
19509 section
= secname_for_decl (current_function_decl
);
19513 memset (&next_cfa
, 0, sizeof (next_cfa
));
19514 next_cfa
.reg
= INVALID_REGNUM
;
19515 remember
= next_cfa
;
19517 start_label
= fde
->dw_fde_begin
;
19519 /* ??? Bald assumption that the CIE opcode list does not contain
19520 advance opcodes. */
19521 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
19522 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
19524 last_cfa
= next_cfa
;
19525 last_label
= start_label
;
19527 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
19529 /* If the first partition contained no CFI adjustments, the
19530 CIE opcodes apply to the whole first partition. */
19531 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19532 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
19533 list_tail
=&(*list_tail
)->dw_loc_next
;
19534 start_label
= last_label
= fde
->dw_fde_second_begin
;
19537 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
19539 switch (cfi
->dw_cfi_opc
)
19541 case DW_CFA_set_loc
:
19542 case DW_CFA_advance_loc1
:
19543 case DW_CFA_advance_loc2
:
19544 case DW_CFA_advance_loc4
:
19545 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
19547 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19548 start_label
, last_label
, section
);
19550 list_tail
= &(*list_tail
)->dw_loc_next
;
19551 last_cfa
= next_cfa
;
19552 start_label
= last_label
;
19554 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
19557 case DW_CFA_advance_loc
:
19558 /* The encoding is complex enough that we should never emit this. */
19559 gcc_unreachable ();
19562 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
19565 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
19567 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
19569 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19570 start_label
, last_label
, section
);
19572 list_tail
= &(*list_tail
)->dw_loc_next
;
19573 last_cfa
= next_cfa
;
19574 start_label
= last_label
;
19576 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19577 start_label
, fde
->dw_fde_end
, section
);
19578 list_tail
= &(*list_tail
)->dw_loc_next
;
19579 start_label
= last_label
= fde
->dw_fde_second_begin
;
19583 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
19585 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19586 start_label
, last_label
, section
);
19587 list_tail
= &(*list_tail
)->dw_loc_next
;
19588 start_label
= last_label
;
19591 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
19593 fde
->dw_fde_second_begin
19594 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
19597 if (list
&& list
->dw_loc_next
)
19603 /* Compute a displacement from the "steady-state frame pointer" to the
19604 frame base (often the same as the CFA), and store it in
19605 frame_pointer_fb_offset. OFFSET is added to the displacement
19606 before the latter is negated. */
19609 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
19613 #ifdef FRAME_POINTER_CFA_OFFSET
19614 reg
= frame_pointer_rtx
;
19615 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
19617 reg
= arg_pointer_rtx
;
19618 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
19621 elim
= (ira_use_lra_p
19622 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
19623 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
19624 if (GET_CODE (elim
) == PLUS
)
19626 offset
+= INTVAL (XEXP (elim
, 1));
19627 elim
= XEXP (elim
, 0);
19630 frame_pointer_fb_offset
= -offset
;
19632 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
19633 in which to eliminate. This is because it's stack pointer isn't
19634 directly accessible as a register within the ISA. To work around
19635 this, assume that while we cannot provide a proper value for
19636 frame_pointer_fb_offset, we won't need one either. */
19637 frame_pointer_fb_offset_valid
19638 = ((SUPPORTS_STACK_ALIGNMENT
19639 && (elim
== hard_frame_pointer_rtx
19640 || elim
== stack_pointer_rtx
))
19641 || elim
== (frame_pointer_needed
19642 ? hard_frame_pointer_rtx
19643 : stack_pointer_rtx
));
19646 /* Generate a DW_AT_name attribute given some string value to be included as
19647 the value of the attribute. */
19650 add_name_attribute (dw_die_ref die
, const char *name_string
)
19652 if (name_string
!= NULL
&& *name_string
!= 0)
19654 if (demangle_name_func
)
19655 name_string
= (*demangle_name_func
) (name_string
);
19657 add_AT_string (die
, DW_AT_name
, name_string
);
19661 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
19662 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
19663 of TYPE accordingly.
19665 ??? This is a temporary measure until after we're able to generate
19666 regular DWARF for the complex Ada type system. */
19669 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
19670 dw_die_ref context_die
)
19673 dw_die_ref dtype_die
;
19675 if (!lang_hooks
.types
.descriptive_type
)
19678 dtype
= lang_hooks
.types
.descriptive_type (type
);
19682 dtype_die
= lookup_type_die (dtype
);
19685 gen_type_die (dtype
, context_die
);
19686 dtype_die
= lookup_type_die (dtype
);
19687 gcc_assert (dtype_die
);
19690 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
19693 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
19695 static const char *
19696 comp_dir_string (void)
19700 static const char *cached_wd
= NULL
;
19702 if (cached_wd
!= NULL
)
19705 wd
= get_src_pwd ();
19709 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
19713 wdlen
= strlen (wd
);
19714 wd1
= ggc_vec_alloc
<char> (wdlen
+ 2);
19716 wd1
[wdlen
] = DIR_SEPARATOR
;
19717 wd1
[wdlen
+ 1] = 0;
19721 cached_wd
= remap_debug_filename (wd
);
19725 /* Generate a DW_AT_comp_dir attribute for DIE. */
19728 add_comp_dir_attribute (dw_die_ref die
)
19730 const char * wd
= comp_dir_string ();
19732 add_AT_string (die
, DW_AT_comp_dir
, wd
);
19735 /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
19736 pointer computation, ...), output a representation for that bound according
19737 to the accepted FORMS (see enum dw_scalar_form) and add it to DIE. See
19738 loc_list_from_tree for the meaning of CONTEXT. */
19741 add_scalar_info (dw_die_ref die
, enum dwarf_attribute attr
, tree value
,
19742 int forms
, struct loc_descr_context
*context
)
19744 dw_die_ref context_die
, decl_die
;
19745 dw_loc_list_ref list
;
19746 bool strip_conversions
= true;
19747 bool placeholder_seen
= false;
19749 while (strip_conversions
)
19750 switch (TREE_CODE (value
))
19757 case VIEW_CONVERT_EXPR
:
19758 value
= TREE_OPERAND (value
, 0);
19762 strip_conversions
= false;
19766 /* If possible and permitted, output the attribute as a constant. */
19767 if ((forms
& dw_scalar_form_constant
) != 0
19768 && TREE_CODE (value
) == INTEGER_CST
)
19770 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (value
));
19772 /* If HOST_WIDE_INT is big enough then represent the bound as
19773 a constant value. We need to choose a form based on
19774 whether the type is signed or unsigned. We cannot just
19775 call add_AT_unsigned if the value itself is positive
19776 (add_AT_unsigned might add the unsigned value encoded as
19777 DW_FORM_data[1248]). Some DWARF consumers will lookup the
19778 bounds type and then sign extend any unsigned values found
19779 for signed types. This is needed only for
19780 DW_AT_{lower,upper}_bound, since for most other attributes,
19781 consumers will treat DW_FORM_data[1248] as unsigned values,
19782 regardless of the underlying type. */
19783 if (prec
<= HOST_BITS_PER_WIDE_INT
19784 || tree_fits_uhwi_p (value
))
19786 if (TYPE_UNSIGNED (TREE_TYPE (value
)))
19787 add_AT_unsigned (die
, attr
, TREE_INT_CST_LOW (value
));
19789 add_AT_int (die
, attr
, TREE_INT_CST_LOW (value
));
19792 /* Otherwise represent the bound as an unsigned value with
19793 the precision of its type. The precision and signedness
19794 of the type will be necessary to re-interpret it
19796 add_AT_wide (die
, attr
, value
);
19800 /* Otherwise, if it's possible and permitted too, output a reference to
19802 if ((forms
& dw_scalar_form_reference
) != 0)
19804 tree decl
= NULL_TREE
;
19806 /* Some type attributes reference an outer type. For instance, the upper
19807 bound of an array may reference an embedding record (this happens in
19809 if (TREE_CODE (value
) == COMPONENT_REF
19810 && TREE_CODE (TREE_OPERAND (value
, 0)) == PLACEHOLDER_EXPR
19811 && TREE_CODE (TREE_OPERAND (value
, 1)) == FIELD_DECL
)
19812 decl
= TREE_OPERAND (value
, 1);
19814 else if (VAR_P (value
)
19815 || TREE_CODE (value
) == PARM_DECL
19816 || TREE_CODE (value
) == RESULT_DECL
)
19819 if (decl
!= NULL_TREE
)
19821 dw_die_ref decl_die
= lookup_decl_die (decl
);
19823 /* ??? Can this happen, or should the variable have been bound
19824 first? Probably it can, since I imagine that we try to create
19825 the types of parameters in the order in which they exist in
19826 the list, and won't have created a forward reference to a
19827 later parameter. */
19828 if (decl_die
!= NULL
)
19830 add_AT_die_ref (die
, attr
, decl_die
);
19836 /* Last chance: try to create a stack operation procedure to evaluate the
19837 value. Do nothing if even that is not possible or permitted. */
19838 if ((forms
& dw_scalar_form_exprloc
) == 0)
19841 list
= loc_list_from_tree (value
, 2, context
);
19842 if (context
&& context
->placeholder_arg
)
19844 placeholder_seen
= context
->placeholder_seen
;
19845 context
->placeholder_seen
= false;
19847 if (list
== NULL
|| single_element_loc_list_p (list
))
19849 /* If this attribute is not a reference nor constant, it is
19850 a DWARF expression rather than location description. For that
19851 loc_list_from_tree (value, 0, &context) is needed. */
19852 dw_loc_list_ref list2
= loc_list_from_tree (value
, 0, context
);
19853 if (list2
&& single_element_loc_list_p (list2
))
19855 if (placeholder_seen
)
19857 struct dwarf_procedure_info dpi
;
19858 dpi
.fndecl
= NULL_TREE
;
19859 dpi
.args_count
= 1;
19860 if (!resolve_args_picking (list2
->expr
, 1, &dpi
))
19863 add_AT_loc (die
, attr
, list2
->expr
);
19868 /* If that failed to give a single element location list, fall back to
19869 outputting this as a reference... still if permitted. */
19871 || (forms
& dw_scalar_form_reference
) == 0
19872 || placeholder_seen
)
19875 if (current_function_decl
== 0)
19876 context_die
= comp_unit_die ();
19878 context_die
= lookup_decl_die (current_function_decl
);
19880 decl_die
= new_die (DW_TAG_variable
, context_die
, value
);
19881 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
19882 add_type_attribute (decl_die
, TREE_TYPE (value
), TYPE_QUAL_CONST
, false,
19884 add_AT_location_description (decl_die
, DW_AT_location
, list
);
19885 add_AT_die_ref (die
, attr
, decl_die
);
19888 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
19892 lower_bound_default (void)
19894 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
19900 case DW_LANG_C_plus_plus
:
19901 case DW_LANG_C_plus_plus_11
:
19902 case DW_LANG_C_plus_plus_14
:
19904 case DW_LANG_ObjC_plus_plus
:
19906 case DW_LANG_Fortran77
:
19907 case DW_LANG_Fortran90
:
19908 case DW_LANG_Fortran95
:
19909 case DW_LANG_Fortran03
:
19910 case DW_LANG_Fortran08
:
19914 case DW_LANG_Python
:
19915 return dwarf_version
>= 4 ? 0 : -1;
19916 case DW_LANG_Ada95
:
19917 case DW_LANG_Ada83
:
19918 case DW_LANG_Cobol74
:
19919 case DW_LANG_Cobol85
:
19920 case DW_LANG_Modula2
:
19922 return dwarf_version
>= 4 ? 1 : -1;
19928 /* Given a tree node describing an array bound (either lower or upper) output
19929 a representation for that bound. */
19932 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
,
19933 tree bound
, struct loc_descr_context
*context
)
19938 switch (TREE_CODE (bound
))
19940 /* Strip all conversions. */
19942 case VIEW_CONVERT_EXPR
:
19943 bound
= TREE_OPERAND (bound
, 0);
19946 /* All fixed-bounds are represented by INTEGER_CST nodes. Lower bounds
19947 are even omitted when they are the default. */
19949 /* If the value for this bound is the default one, we can even omit the
19951 if (bound_attr
== DW_AT_lower_bound
19952 && tree_fits_shwi_p (bound
)
19953 && (dflt
= lower_bound_default ()) != -1
19954 && tree_to_shwi (bound
) == dflt
)
19960 /* Because of the complex interaction there can be with other GNAT
19961 encodings, GDB isn't ready yet to handle proper DWARF description
19962 for self-referencial subrange bounds: let GNAT encodings do the
19963 magic in such a case. */
19965 && gnat_encodings
!= DWARF_GNAT_ENCODINGS_MINIMAL
19966 && contains_placeholder_p (bound
))
19969 add_scalar_info (subrange_die
, bound_attr
, bound
,
19970 dw_scalar_form_constant
19971 | dw_scalar_form_exprloc
19972 | dw_scalar_form_reference
,
19978 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
19979 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
19980 Note that the block of subscript information for an array type also
19981 includes information about the element type of the given array type.
19983 This function reuses previously set type and bound information if
19987 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
19989 unsigned dimension_number
;
19991 dw_die_ref child
= type_die
->die_child
;
19993 for (dimension_number
= 0;
19994 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
19995 type
= TREE_TYPE (type
), dimension_number
++)
19997 tree domain
= TYPE_DOMAIN (type
);
19999 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
20002 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
20003 and (in GNU C only) variable bounds. Handle all three forms
20006 /* Find and reuse a previously generated DW_TAG_subrange_type if
20009 For multi-dimensional arrays, as we iterate through the
20010 various dimensions in the enclosing for loop above, we also
20011 iterate through the DIE children and pick at each
20012 DW_TAG_subrange_type previously generated (if available).
20013 Each child DW_TAG_subrange_type DIE describes the range of
20014 the current dimension. At this point we should have as many
20015 DW_TAG_subrange_type's as we have dimensions in the
20017 dw_die_ref subrange_die
= NULL
;
20021 child
= child
->die_sib
;
20022 if (child
->die_tag
== DW_TAG_subrange_type
)
20023 subrange_die
= child
;
20024 if (child
== type_die
->die_child
)
20026 /* If we wrapped around, stop looking next time. */
20030 if (child
->die_tag
== DW_TAG_subrange_type
)
20034 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
20038 /* We have an array type with specified bounds. */
20039 lower
= TYPE_MIN_VALUE (domain
);
20040 upper
= TYPE_MAX_VALUE (domain
);
20042 /* Define the index type. */
20043 if (TREE_TYPE (domain
)
20044 && !get_AT (subrange_die
, DW_AT_type
))
20046 /* ??? This is probably an Ada unnamed subrange type. Ignore the
20047 TREE_TYPE field. We can't emit debug info for this
20048 because it is an unnamed integral type. */
20049 if (TREE_CODE (domain
) == INTEGER_TYPE
20050 && TYPE_NAME (domain
) == NULL_TREE
20051 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
20052 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
20055 add_type_attribute (subrange_die
, TREE_TYPE (domain
),
20056 TYPE_UNQUALIFIED
, false, type_die
);
20059 /* ??? If upper is NULL, the array has unspecified length,
20060 but it does have a lower bound. This happens with Fortran
20062 Since the debugger is definitely going to need to know N
20063 to produce useful results, go ahead and output the lower
20064 bound solo, and hope the debugger can cope. */
20066 if (!get_AT (subrange_die
, DW_AT_lower_bound
))
20067 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
, NULL
);
20068 if (upper
&& !get_AT (subrange_die
, DW_AT_upper_bound
))
20069 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
, NULL
);
20072 /* Otherwise we have an array type with an unspecified length. The
20073 DWARF-2 spec does not say how to handle this; let's just leave out the
20078 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
20081 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
20083 dw_die_ref decl_die
;
20084 HOST_WIDE_INT size
;
20085 dw_loc_descr_ref size_expr
= NULL
;
20087 switch (TREE_CODE (tree_node
))
20092 case ENUMERAL_TYPE
:
20095 case QUAL_UNION_TYPE
:
20096 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
20097 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
20099 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
20102 size_expr
= type_byte_size (tree_node
, &size
);
20105 /* For a data member of a struct or union, the DW_AT_byte_size is
20106 generally given as the number of bytes normally allocated for an
20107 object of the *declared* type of the member itself. This is true
20108 even for bit-fields. */
20109 size
= int_size_in_bytes (field_type (tree_node
));
20112 gcc_unreachable ();
20115 /* Support for dynamically-sized objects was introduced by DWARFv3.
20116 At the moment, GDB does not handle variable byte sizes very well,
20118 if ((dwarf_version
>= 3 || !dwarf_strict
)
20119 && gnat_encodings
== DWARF_GNAT_ENCODINGS_MINIMAL
20120 && size_expr
!= NULL
)
20121 add_AT_loc (die
, DW_AT_byte_size
, size_expr
);
20123 /* Note that `size' might be -1 when we get to this point. If it is, that
20124 indicates that the byte size of the entity in question is variable and
20125 that we could not generate a DWARF expression that computes it. */
20127 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
20130 /* Add a DW_AT_alignment attribute to DIE with TREE_NODE's non-default
20134 add_alignment_attribute (dw_die_ref die
, tree tree_node
)
20136 if (dwarf_version
< 5 && dwarf_strict
)
20141 if (DECL_P (tree_node
))
20143 if (!DECL_USER_ALIGN (tree_node
))
20146 align
= DECL_ALIGN_UNIT (tree_node
);
20148 else if (TYPE_P (tree_node
))
20150 if (!TYPE_USER_ALIGN (tree_node
))
20153 align
= TYPE_ALIGN_UNIT (tree_node
);
20156 gcc_unreachable ();
20158 add_AT_unsigned (die
, DW_AT_alignment
, align
);
20161 /* For a FIELD_DECL node which represents a bit-field, output an attribute
20162 which specifies the distance in bits from the highest order bit of the
20163 "containing object" for the bit-field to the highest order bit of the
20166 For any given bit-field, the "containing object" is a hypothetical object
20167 (of some integral or enum type) within which the given bit-field lives. The
20168 type of this hypothetical "containing object" is always the same as the
20169 declared type of the individual bit-field itself. The determination of the
20170 exact location of the "containing object" for a bit-field is rather
20171 complicated. It's handled by the `field_byte_offset' function (above).
20173 CTX is required: see the comment for VLR_CONTEXT.
20175 Note that it is the size (in bytes) of the hypothetical "containing object"
20176 which will be given in the DW_AT_byte_size attribute for this bit-field.
20177 (See `byte_size_attribute' above). */
20180 add_bit_offset_attribute (dw_die_ref die
, tree decl
, struct vlr_context
*ctx
)
20182 HOST_WIDE_INT object_offset_in_bytes
;
20183 tree original_type
= DECL_BIT_FIELD_TYPE (decl
);
20184 HOST_WIDE_INT bitpos_int
;
20185 HOST_WIDE_INT highest_order_object_bit_offset
;
20186 HOST_WIDE_INT highest_order_field_bit_offset
;
20187 HOST_WIDE_INT bit_offset
;
20189 field_byte_offset (decl
, ctx
, &object_offset_in_bytes
);
20191 /* Must be a field and a bit field. */
20192 gcc_assert (original_type
&& TREE_CODE (decl
) == FIELD_DECL
);
20194 /* We can't yet handle bit-fields whose offsets are variable, so if we
20195 encounter such things, just return without generating any attribute
20196 whatsoever. Likewise for variable or too large size. */
20197 if (! tree_fits_shwi_p (bit_position (decl
))
20198 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
20201 bitpos_int
= int_bit_position (decl
);
20203 /* Note that the bit offset is always the distance (in bits) from the
20204 highest-order bit of the "containing object" to the highest-order bit of
20205 the bit-field itself. Since the "high-order end" of any object or field
20206 is different on big-endian and little-endian machines, the computation
20207 below must take account of these differences. */
20208 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
20209 highest_order_field_bit_offset
= bitpos_int
;
20211 if (! BYTES_BIG_ENDIAN
)
20213 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
20214 highest_order_object_bit_offset
+=
20215 simple_type_size_in_bits (original_type
);
20219 = (! BYTES_BIG_ENDIAN
20220 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
20221 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
20223 if (bit_offset
< 0)
20224 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
20226 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
20229 /* For a FIELD_DECL node which represents a bit field, output an attribute
20230 which specifies the length in bits of the given field. */
20233 add_bit_size_attribute (dw_die_ref die
, tree decl
)
20235 /* Must be a field and a bit field. */
20236 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
20237 && DECL_BIT_FIELD_TYPE (decl
));
20239 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
20240 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
20243 /* If the compiled language is ANSI C, then add a 'prototyped'
20244 attribute, if arg types are given for the parameters of a function. */
20247 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
20249 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
20256 if (prototype_p (func_type
))
20257 add_AT_flag (die
, DW_AT_prototyped
, 1);
20264 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
20265 by looking in the type declaration, the object declaration equate table or
20266 the block mapping. */
20268 static inline dw_die_ref
20269 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
20271 dw_die_ref origin_die
= NULL
;
20273 if (DECL_P (origin
))
20276 origin_die
= lookup_decl_die (origin
);
20277 /* "Unwrap" the decls DIE which we put in the imported unit context.
20278 We are looking for the abstract copy here. */
20281 && (c
= get_AT_ref (origin_die
, DW_AT_abstract_origin
))
20282 /* ??? Identify this better. */
20286 else if (TYPE_P (origin
))
20287 origin_die
= lookup_type_die (origin
);
20288 else if (TREE_CODE (origin
) == BLOCK
)
20289 origin_die
= BLOCK_DIE (origin
);
20291 /* XXX: Functions that are never lowered don't always have correct block
20292 trees (in the case of java, they simply have no block tree, in some other
20293 languages). For these functions, there is nothing we can really do to
20294 output correct debug info for inlined functions in all cases. Rather
20295 than die, we'll just produce deficient debug info now, in that we will
20296 have variables without a proper abstract origin. In the future, when all
20297 functions are lowered, we should re-add a gcc_assert (origin_die)
20301 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
20305 /* We do not currently support the pure_virtual attribute. */
20308 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
20310 if (DECL_VINDEX (func_decl
))
20312 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
20314 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
20315 add_AT_loc (die
, DW_AT_vtable_elem_location
,
20316 new_loc_descr (DW_OP_constu
,
20317 tree_to_shwi (DECL_VINDEX (func_decl
)),
20320 /* GNU extension: Record what type this method came from originally. */
20321 if (debug_info_level
> DINFO_LEVEL_TERSE
20322 && DECL_CONTEXT (func_decl
))
20323 add_AT_die_ref (die
, DW_AT_containing_type
,
20324 lookup_type_die (DECL_CONTEXT (func_decl
)));
20328 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
20329 given decl. This used to be a vendor extension until after DWARF 4
20330 standardized it. */
20333 add_linkage_attr (dw_die_ref die
, tree decl
)
20335 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
20337 /* Mimic what assemble_name_raw does with a leading '*'. */
20338 if (name
[0] == '*')
20341 if (dwarf_version
>= 4)
20342 add_AT_string (die
, DW_AT_linkage_name
, name
);
20344 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
20347 /* Add source coordinate attributes for the given decl. */
20350 add_src_coords_attributes (dw_die_ref die
, tree decl
)
20352 expanded_location s
;
20354 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
20356 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
20357 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
20358 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
20359 if (debug_column_info
&& s
.column
)
20360 add_AT_unsigned (die
, DW_AT_decl_column
, s
.column
);
20363 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
20366 add_linkage_name_raw (dw_die_ref die
, tree decl
)
20368 /* Defer until we have an assembler name set. */
20369 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
20371 limbo_die_node
*asm_name
;
20373 asm_name
= ggc_cleared_alloc
<limbo_die_node
> ();
20374 asm_name
->die
= die
;
20375 asm_name
->created_for
= decl
;
20376 asm_name
->next
= deferred_asm_name
;
20377 deferred_asm_name
= asm_name
;
20379 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
20380 add_linkage_attr (die
, decl
);
20383 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl if desired. */
20386 add_linkage_name (dw_die_ref die
, tree decl
)
20388 if (debug_info_level
> DINFO_LEVEL_NONE
20389 && VAR_OR_FUNCTION_DECL_P (decl
)
20390 && TREE_PUBLIC (decl
)
20391 && !(VAR_P (decl
) && DECL_REGISTER (decl
))
20392 && die
->die_tag
!= DW_TAG_member
)
20393 add_linkage_name_raw (die
, decl
);
20396 /* Add a DW_AT_name attribute and source coordinate attribute for the
20397 given decl, but only if it actually has a name. */
20400 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
,
20401 bool no_linkage_name
)
20405 decl_name
= DECL_NAME (decl
);
20406 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
20408 const char *name
= dwarf2_name (decl
, 0);
20410 add_name_attribute (die
, name
);
20411 if (! DECL_ARTIFICIAL (decl
))
20412 add_src_coords_attributes (die
, decl
);
20414 if (!no_linkage_name
)
20415 add_linkage_name (die
, decl
);
20418 #ifdef VMS_DEBUGGING_INFO
20419 /* Get the function's name, as described by its RTL. This may be different
20420 from the DECL_NAME name used in the source file. */
20421 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
20423 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
20424 XEXP (DECL_RTL (decl
), 0), false);
20425 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
20427 #endif /* VMS_DEBUGGING_INFO */
20430 /* Add VALUE as a DW_AT_discr_value attribute to DIE. */
20433 add_discr_value (dw_die_ref die
, dw_discr_value
*value
)
20437 attr
.dw_attr
= DW_AT_discr_value
;
20438 attr
.dw_attr_val
.val_class
= dw_val_class_discr_value
;
20439 attr
.dw_attr_val
.val_entry
= NULL
;
20440 attr
.dw_attr_val
.v
.val_discr_value
.pos
= value
->pos
;
20442 attr
.dw_attr_val
.v
.val_discr_value
.v
.uval
= value
->v
.uval
;
20444 attr
.dw_attr_val
.v
.val_discr_value
.v
.sval
= value
->v
.sval
;
20445 add_dwarf_attr (die
, &attr
);
20448 /* Add DISCR_LIST as a DW_AT_discr_list to DIE. */
20451 add_discr_list (dw_die_ref die
, dw_discr_list_ref discr_list
)
20455 attr
.dw_attr
= DW_AT_discr_list
;
20456 attr
.dw_attr_val
.val_class
= dw_val_class_discr_list
;
20457 attr
.dw_attr_val
.val_entry
= NULL
;
20458 attr
.dw_attr_val
.v
.val_discr_list
= discr_list
;
20459 add_dwarf_attr (die
, &attr
);
20462 static inline dw_discr_list_ref
20463 AT_discr_list (dw_attr_node
*attr
)
20465 return attr
->dw_attr_val
.v
.val_discr_list
;
20468 #ifdef VMS_DEBUGGING_INFO
20469 /* Output the debug main pointer die for VMS */
20472 dwarf2out_vms_debug_main_pointer (void)
20474 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20477 /* Allocate the VMS debug main subprogram die. */
20478 die
= ggc_cleared_alloc
<die_node
> ();
20479 die
->die_tag
= DW_TAG_subprogram
;
20480 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
20481 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
20482 current_function_funcdef_no
);
20483 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
20485 /* Make it the first child of comp_unit_die (). */
20486 die
->die_parent
= comp_unit_die ();
20487 if (comp_unit_die ()->die_child
)
20489 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
20490 comp_unit_die ()->die_child
->die_sib
= die
;
20494 die
->die_sib
= die
;
20495 comp_unit_die ()->die_child
= die
;
20498 #endif /* VMS_DEBUGGING_INFO */
20500 /* Push a new declaration scope. */
20503 push_decl_scope (tree scope
)
20505 vec_safe_push (decl_scope_table
, scope
);
20508 /* Pop a declaration scope. */
20511 pop_decl_scope (void)
20513 decl_scope_table
->pop ();
20516 /* walk_tree helper function for uses_local_type, below. */
20519 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
20522 *walk_subtrees
= 0;
20525 tree name
= TYPE_NAME (*tp
);
20526 if (name
&& DECL_P (name
) && decl_function_context (name
))
20532 /* If TYPE involves a function-local type (including a local typedef to a
20533 non-local type), returns that type; otherwise returns NULL_TREE. */
20536 uses_local_type (tree type
)
20538 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
20542 /* Return the DIE for the scope that immediately contains this type.
20543 Non-named types that do not involve a function-local type get global
20544 scope. Named types nested in namespaces or other types get their
20545 containing scope. All other types (i.e. function-local named types) get
20546 the current active scope. */
20549 scope_die_for (tree t
, dw_die_ref context_die
)
20551 dw_die_ref scope_die
= NULL
;
20552 tree containing_scope
;
20554 /* Non-types always go in the current scope. */
20555 gcc_assert (TYPE_P (t
));
20557 /* Use the scope of the typedef, rather than the scope of the type
20559 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
20560 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
20562 containing_scope
= TYPE_CONTEXT (t
);
20564 /* Use the containing namespace if there is one. */
20565 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
20567 if (context_die
== lookup_decl_die (containing_scope
))
20569 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
20570 context_die
= get_context_die (containing_scope
);
20572 containing_scope
= NULL_TREE
;
20575 /* Ignore function type "scopes" from the C frontend. They mean that
20576 a tagged type is local to a parmlist of a function declarator, but
20577 that isn't useful to DWARF. */
20578 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
20579 containing_scope
= NULL_TREE
;
20581 if (SCOPE_FILE_SCOPE_P (containing_scope
))
20583 /* If T uses a local type keep it local as well, to avoid references
20584 to function-local DIEs from outside the function. */
20585 if (current_function_decl
&& uses_local_type (t
))
20586 scope_die
= context_die
;
20588 scope_die
= comp_unit_die ();
20590 else if (TYPE_P (containing_scope
))
20592 /* For types, we can just look up the appropriate DIE. */
20593 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20594 scope_die
= get_context_die (containing_scope
);
20597 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
20598 if (scope_die
== NULL
)
20599 scope_die
= comp_unit_die ();
20603 scope_die
= context_die
;
20608 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
20611 local_scope_p (dw_die_ref context_die
)
20613 for (; context_die
; context_die
= context_die
->die_parent
)
20614 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
20615 || context_die
->die_tag
== DW_TAG_subprogram
)
20621 /* Returns nonzero if CONTEXT_DIE is a class. */
20624 class_scope_p (dw_die_ref context_die
)
20626 return (context_die
20627 && (context_die
->die_tag
== DW_TAG_structure_type
20628 || context_die
->die_tag
== DW_TAG_class_type
20629 || context_die
->die_tag
== DW_TAG_interface_type
20630 || context_die
->die_tag
== DW_TAG_union_type
));
20633 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
20634 whether or not to treat a DIE in this context as a declaration. */
20637 class_or_namespace_scope_p (dw_die_ref context_die
)
20639 return (class_scope_p (context_die
)
20640 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
20643 /* Many forms of DIEs require a "type description" attribute. This
20644 routine locates the proper "type descriptor" die for the type given
20645 by 'type' plus any additional qualifiers given by 'cv_quals', and
20646 adds a DW_AT_type attribute below the given die. */
20649 add_type_attribute (dw_die_ref object_die
, tree type
, int cv_quals
,
20650 bool reverse
, dw_die_ref context_die
)
20652 enum tree_code code
= TREE_CODE (type
);
20653 dw_die_ref type_die
= NULL
;
20655 /* ??? If this type is an unnamed subrange type of an integral, floating-point
20656 or fixed-point type, use the inner type. This is because we have no
20657 support for unnamed types in base_type_die. This can happen if this is
20658 an Ada subrange type. Correct solution is emit a subrange type die. */
20659 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
20660 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
20661 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
20663 if (code
== ERROR_MARK
20664 /* Handle a special case. For functions whose return type is void, we
20665 generate *no* type attribute. (Note that no object may have type
20666 `void', so this only applies to function return types). */
20667 || code
== VOID_TYPE
)
20670 type_die
= modified_type_die (type
,
20671 cv_quals
| TYPE_QUALS_NO_ADDR_SPACE (type
),
20675 if (type_die
!= NULL
)
20676 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
20679 /* Given an object die, add the calling convention attribute for the
20680 function call type. */
20682 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
20684 enum dwarf_calling_convention value
= DW_CC_normal
;
20686 value
= ((enum dwarf_calling_convention
)
20687 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
20690 && id_equal (DECL_ASSEMBLER_NAME (decl
), "MAIN__"))
20692 /* DWARF 2 doesn't provide a way to identify a program's source-level
20693 entry point. DW_AT_calling_convention attributes are only meant
20694 to describe functions' calling conventions. However, lacking a
20695 better way to signal the Fortran main program, we used this for
20696 a long time, following existing custom. Now, DWARF 4 has
20697 DW_AT_main_subprogram, which we add below, but some tools still
20698 rely on the old way, which we thus keep. */
20699 value
= DW_CC_program
;
20701 if (dwarf_version
>= 4 || !dwarf_strict
)
20702 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
20705 /* Only add the attribute if the backend requests it, and
20706 is not DW_CC_normal. */
20707 if (value
&& (value
!= DW_CC_normal
))
20708 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
20711 /* Given a tree pointer to a struct, class, union, or enum type node, return
20712 a pointer to the (string) tag name for the given type, or zero if the type
20713 was declared without a tag. */
20715 static const char *
20716 type_tag (const_tree type
)
20718 const char *name
= 0;
20720 if (TYPE_NAME (type
) != 0)
20724 /* Find the IDENTIFIER_NODE for the type name. */
20725 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
20726 && !TYPE_NAMELESS (type
))
20727 t
= TYPE_NAME (type
);
20729 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
20730 a TYPE_DECL node, regardless of whether or not a `typedef' was
20732 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
20733 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
20735 /* We want to be extra verbose. Don't call dwarf_name if
20736 DECL_NAME isn't set. The default hook for decl_printable_name
20737 doesn't like that, and in this context it's correct to return
20738 0, instead of "<anonymous>" or the like. */
20739 if (DECL_NAME (TYPE_NAME (type
))
20740 && !DECL_NAMELESS (TYPE_NAME (type
)))
20741 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
20744 /* Now get the name as a string, or invent one. */
20745 if (!name
&& t
!= 0)
20746 name
= IDENTIFIER_POINTER (t
);
20749 return (name
== 0 || *name
== '\0') ? 0 : name
;
20752 /* Return the type associated with a data member, make a special check
20753 for bit field types. */
20756 member_declared_type (const_tree member
)
20758 return (DECL_BIT_FIELD_TYPE (member
)
20759 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
20762 /* Get the decl's label, as described by its RTL. This may be different
20763 from the DECL_NAME name used in the source file. */
20766 static const char *
20767 decl_start_label (tree decl
)
20770 const char *fnname
;
20772 x
= DECL_RTL (decl
);
20773 gcc_assert (MEM_P (x
));
20776 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
20778 fnname
= XSTR (x
, 0);
20783 /* For variable-length arrays that have been previously generated, but
20784 may be incomplete due to missing subscript info, fill the subscript
20785 info. Return TRUE if this is one of those cases. */
20787 fill_variable_array_bounds (tree type
)
20789 if (TREE_ASM_WRITTEN (type
)
20790 && TREE_CODE (type
) == ARRAY_TYPE
20791 && variably_modified_type_p (type
, NULL
))
20793 dw_die_ref array_die
= lookup_type_die (type
);
20796 add_subscript_info (array_die
, type
, !is_ada ());
20802 /* These routines generate the internal representation of the DIE's for
20803 the compilation unit. Debugging information is collected by walking
20804 the declaration trees passed in from dwarf2out_decl(). */
20807 gen_array_type_die (tree type
, dw_die_ref context_die
)
20809 dw_die_ref array_die
;
20811 /* GNU compilers represent multidimensional array types as sequences of one
20812 dimensional array types whose element types are themselves array types.
20813 We sometimes squish that down to a single array_type DIE with multiple
20814 subscripts in the Dwarf debugging info. The draft Dwarf specification
20815 say that we are allowed to do this kind of compression in C, because
20816 there is no difference between an array of arrays and a multidimensional
20817 array. We don't do this for Ada to remain as close as possible to the
20818 actual representation, which is especially important against the language
20819 flexibilty wrt arrays of variable size. */
20821 bool collapse_nested_arrays
= !is_ada ();
20823 if (fill_variable_array_bounds (type
))
20826 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
20829 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
20830 DW_TAG_string_type doesn't have DW_AT_type attribute). */
20831 if (TYPE_STRING_FLAG (type
)
20832 && TREE_CODE (type
) == ARRAY_TYPE
20834 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
20836 HOST_WIDE_INT size
;
20838 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
20839 add_name_attribute (array_die
, type_tag (type
));
20840 equate_type_number_to_die (type
, array_die
);
20841 size
= int_size_in_bytes (type
);
20843 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
20844 /* ??? We can't annotate types late, but for LTO we may not
20845 generate a location early either (gfortran.dg/save_6.f90). */
20846 else if (! (early_dwarf
&& (flag_generate_lto
|| flag_generate_offload
))
20847 && TYPE_DOMAIN (type
) != NULL_TREE
20848 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
)
20850 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
20851 tree rszdecl
= szdecl
;
20853 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
20854 if (!DECL_P (szdecl
))
20856 if (TREE_CODE (szdecl
) == INDIRECT_REF
20857 && DECL_P (TREE_OPERAND (szdecl
, 0)))
20859 rszdecl
= TREE_OPERAND (szdecl
, 0);
20860 if (int_size_in_bytes (TREE_TYPE (rszdecl
))
20861 != DWARF2_ADDR_SIZE
)
20869 dw_loc_list_ref loc
20870 = loc_list_from_tree (rszdecl
, szdecl
== rszdecl
? 2 : 0,
20874 add_AT_location_description (array_die
, DW_AT_string_length
,
20876 if (size
!= DWARF2_ADDR_SIZE
)
20877 add_AT_unsigned (array_die
, dwarf_version
>= 5
20878 ? DW_AT_string_length_byte_size
20879 : DW_AT_byte_size
, size
);
20886 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
20887 add_name_attribute (array_die
, type_tag (type
));
20888 equate_type_number_to_die (type
, array_die
);
20890 if (TREE_CODE (type
) == VECTOR_TYPE
)
20891 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
20893 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
20895 && TREE_CODE (type
) == ARRAY_TYPE
20896 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
20897 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
20898 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
20901 /* We default the array ordering. SDB will probably do
20902 the right things even if DW_AT_ordering is not present. It's not even
20903 an issue until we start to get into multidimensional arrays anyway. If
20904 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
20905 then we'll have to put the DW_AT_ordering attribute back in. (But if
20906 and when we find out that we need to put these in, we will only do so
20907 for multidimensional arrays. */
20908 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
20911 if (TREE_CODE (type
) == VECTOR_TYPE
)
20913 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
20914 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
20915 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
, NULL
);
20916 add_bound_info (subrange_die
, DW_AT_upper_bound
,
20917 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1), NULL
);
20920 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
20922 /* Add representation of the type of the elements of this array type and
20923 emit the corresponding DIE if we haven't done it already. */
20924 element_type
= TREE_TYPE (type
);
20925 if (collapse_nested_arrays
)
20926 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
20928 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
20930 element_type
= TREE_TYPE (element_type
);
20933 add_type_attribute (array_die
, element_type
, TYPE_UNQUALIFIED
,
20934 TREE_CODE (type
) == ARRAY_TYPE
20935 && TYPE_REVERSE_STORAGE_ORDER (type
),
20938 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
20939 if (TYPE_ARTIFICIAL (type
))
20940 add_AT_flag (array_die
, DW_AT_artificial
, 1);
20942 if (get_AT (array_die
, DW_AT_name
))
20943 add_pubtype (type
, array_die
);
20945 add_alignment_attribute (array_die
, type
);
20948 /* This routine generates DIE for array with hidden descriptor, details
20949 are filled into *info by a langhook. */
20952 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
20953 dw_die_ref context_die
)
20955 const dw_die_ref scope_die
= scope_die_for (type
, context_die
);
20956 const dw_die_ref array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
20957 struct loc_descr_context context
= { type
, info
->base_decl
, NULL
,
20959 enum dwarf_tag subrange_tag
= DW_TAG_subrange_type
;
20962 add_name_attribute (array_die
, type_tag (type
));
20963 equate_type_number_to_die (type
, array_die
);
20965 if (info
->ndimensions
> 1)
20966 switch (info
->ordering
)
20968 case array_descr_ordering_row_major
:
20969 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
20971 case array_descr_ordering_column_major
:
20972 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
20978 if (dwarf_version
>= 3 || !dwarf_strict
)
20980 if (info
->data_location
)
20981 add_scalar_info (array_die
, DW_AT_data_location
, info
->data_location
,
20982 dw_scalar_form_exprloc
, &context
);
20983 if (info
->associated
)
20984 add_scalar_info (array_die
, DW_AT_associated
, info
->associated
,
20985 dw_scalar_form_constant
20986 | dw_scalar_form_exprloc
20987 | dw_scalar_form_reference
, &context
);
20988 if (info
->allocated
)
20989 add_scalar_info (array_die
, DW_AT_allocated
, info
->allocated
,
20990 dw_scalar_form_constant
20991 | dw_scalar_form_exprloc
20992 | dw_scalar_form_reference
, &context
);
20995 const enum dwarf_attribute attr
20996 = (info
->stride_in_bits
) ? DW_AT_bit_stride
: DW_AT_byte_stride
;
20998 = (info
->stride_in_bits
)
20999 ? dw_scalar_form_constant
21000 : (dw_scalar_form_constant
21001 | dw_scalar_form_exprloc
21002 | dw_scalar_form_reference
);
21004 add_scalar_info (array_die
, attr
, info
->stride
, forms
, &context
);
21007 if (dwarf_version
>= 5)
21011 add_scalar_info (array_die
, DW_AT_rank
, info
->rank
,
21012 dw_scalar_form_constant
21013 | dw_scalar_form_exprloc
, &context
);
21014 subrange_tag
= DW_TAG_generic_subrange
;
21015 context
.placeholder_arg
= true;
21019 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
21021 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
21023 dw_die_ref subrange_die
= new_die (subrange_tag
, array_die
, NULL
);
21025 if (info
->dimen
[dim
].bounds_type
)
21026 add_type_attribute (subrange_die
,
21027 info
->dimen
[dim
].bounds_type
, TYPE_UNQUALIFIED
,
21028 false, context_die
);
21029 if (info
->dimen
[dim
].lower_bound
)
21030 add_bound_info (subrange_die
, DW_AT_lower_bound
,
21031 info
->dimen
[dim
].lower_bound
, &context
);
21032 if (info
->dimen
[dim
].upper_bound
)
21033 add_bound_info (subrange_die
, DW_AT_upper_bound
,
21034 info
->dimen
[dim
].upper_bound
, &context
);
21035 if ((dwarf_version
>= 3 || !dwarf_strict
) && info
->dimen
[dim
].stride
)
21036 add_scalar_info (subrange_die
, DW_AT_byte_stride
,
21037 info
->dimen
[dim
].stride
,
21038 dw_scalar_form_constant
21039 | dw_scalar_form_exprloc
21040 | dw_scalar_form_reference
,
21044 gen_type_die (info
->element_type
, context_die
);
21045 add_type_attribute (array_die
, info
->element_type
, TYPE_UNQUALIFIED
,
21046 TREE_CODE (type
) == ARRAY_TYPE
21047 && TYPE_REVERSE_STORAGE_ORDER (type
),
21050 if (get_AT (array_die
, DW_AT_name
))
21051 add_pubtype (type
, array_die
);
21053 add_alignment_attribute (array_die
, type
);
21058 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
21060 tree origin
= decl_ultimate_origin (decl
);
21061 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
21063 if (origin
!= NULL
)
21064 add_abstract_origin_attribute (decl_die
, origin
);
21067 add_name_and_src_coords_attributes (decl_die
, decl
);
21068 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
21069 TYPE_UNQUALIFIED
, false, context_die
);
21072 if (DECL_ABSTRACT_P (decl
))
21073 equate_decl_number_to_die (decl
, decl_die
);
21075 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
21079 /* Walk through the list of incomplete types again, trying once more to
21080 emit full debugging info for them. */
21083 retry_incomplete_types (void)
21088 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
21089 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
21090 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
21091 vec_safe_truncate (incomplete_types
, 0);
21094 /* Determine what tag to use for a record type. */
21096 static enum dwarf_tag
21097 record_type_tag (tree type
)
21099 if (! lang_hooks
.types
.classify_record
)
21100 return DW_TAG_structure_type
;
21102 switch (lang_hooks
.types
.classify_record (type
))
21104 case RECORD_IS_STRUCT
:
21105 return DW_TAG_structure_type
;
21107 case RECORD_IS_CLASS
:
21108 return DW_TAG_class_type
;
21110 case RECORD_IS_INTERFACE
:
21111 if (dwarf_version
>= 3 || !dwarf_strict
)
21112 return DW_TAG_interface_type
;
21113 return DW_TAG_structure_type
;
21116 gcc_unreachable ();
21120 /* Generate a DIE to represent an enumeration type. Note that these DIEs
21121 include all of the information about the enumeration values also. Each
21122 enumerated type name/value is listed as a child of the enumerated type
21126 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
21128 dw_die_ref type_die
= lookup_type_die (type
);
21130 if (type_die
== NULL
)
21132 type_die
= new_die (DW_TAG_enumeration_type
,
21133 scope_die_for (type
, context_die
), type
);
21134 equate_type_number_to_die (type
, type_die
);
21135 add_name_attribute (type_die
, type_tag (type
));
21136 if (dwarf_version
>= 4 || !dwarf_strict
)
21138 if (ENUM_IS_SCOPED (type
))
21139 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
21140 if (ENUM_IS_OPAQUE (type
))
21141 add_AT_flag (type_die
, DW_AT_declaration
, 1);
21144 add_AT_unsigned (type_die
, DW_AT_encoding
,
21145 TYPE_UNSIGNED (type
)
21149 else if (! TYPE_SIZE (type
))
21152 remove_AT (type_die
, DW_AT_declaration
);
21154 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
21155 given enum type is incomplete, do not generate the DW_AT_byte_size
21156 attribute or the DW_AT_element_list attribute. */
21157 if (TYPE_SIZE (type
))
21161 TREE_ASM_WRITTEN (type
) = 1;
21162 add_byte_size_attribute (type_die
, type
);
21163 add_alignment_attribute (type_die
, type
);
21164 if (dwarf_version
>= 3 || !dwarf_strict
)
21166 tree underlying
= lang_hooks
.types
.enum_underlying_base_type (type
);
21167 add_type_attribute (type_die
, underlying
, TYPE_UNQUALIFIED
, false,
21170 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
21172 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
21173 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
21176 /* If the first reference to this type was as the return type of an
21177 inline function, then it may not have a parent. Fix this now. */
21178 if (type_die
->die_parent
== NULL
)
21179 add_child_die (scope_die_for (type
, context_die
), type_die
);
21181 for (link
= TYPE_VALUES (type
);
21182 link
!= NULL
; link
= TREE_CHAIN (link
))
21184 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
21185 tree value
= TREE_VALUE (link
);
21187 add_name_attribute (enum_die
,
21188 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
21190 if (TREE_CODE (value
) == CONST_DECL
)
21191 value
= DECL_INITIAL (value
);
21193 if (simple_type_size_in_bits (TREE_TYPE (value
))
21194 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
21196 /* For constant forms created by add_AT_unsigned DWARF
21197 consumers (GDB, elfutils, etc.) always zero extend
21198 the value. Only when the actual value is negative
21199 do we need to use add_AT_int to generate a constant
21200 form that can represent negative values. */
21201 HOST_WIDE_INT val
= TREE_INT_CST_LOW (value
);
21202 if (TYPE_UNSIGNED (TREE_TYPE (value
)) || val
>= 0)
21203 add_AT_unsigned (enum_die
, DW_AT_const_value
,
21204 (unsigned HOST_WIDE_INT
) val
);
21206 add_AT_int (enum_die
, DW_AT_const_value
, val
);
21209 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
21210 that here. TODO: This should be re-worked to use correct
21211 signed/unsigned double tags for all cases. */
21212 add_AT_wide (enum_die
, DW_AT_const_value
, value
);
21215 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
21216 if (TYPE_ARTIFICIAL (type
))
21217 add_AT_flag (type_die
, DW_AT_artificial
, 1);
21220 add_AT_flag (type_die
, DW_AT_declaration
, 1);
21222 add_alignment_attribute (type_die
, type
);
21224 add_pubtype (type
, type_die
);
21229 /* Generate a DIE to represent either a real live formal parameter decl or to
21230 represent just the type of some formal parameter position in some function
21233 Note that this routine is a bit unusual because its argument may be a
21234 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
21235 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
21236 node. If it's the former then this function is being called to output a
21237 DIE to represent a formal parameter object (or some inlining thereof). If
21238 it's the latter, then this function is only being called to output a
21239 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
21240 argument type of some subprogram type.
21241 If EMIT_NAME_P is true, name and source coordinate attributes
21245 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
21246 dw_die_ref context_die
)
21248 tree node_or_origin
= node
? node
: origin
;
21249 tree ultimate_origin
;
21250 dw_die_ref parm_die
= NULL
;
21252 if (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)) == tcc_declaration
)
21254 parm_die
= lookup_decl_die (node
);
21256 /* If the contexts differ, we may not be talking about the same
21258 ??? When in LTO the DIE parent is the "abstract" copy and the
21259 context_die is the specification "copy". But this whole block
21260 should eventually be no longer needed. */
21261 if (parm_die
&& parm_die
->die_parent
!= context_die
&& !in_lto_p
)
21263 if (!DECL_ABSTRACT_P (node
))
21265 /* This can happen when creating an inlined instance, in
21266 which case we need to create a new DIE that will get
21267 annotated with DW_AT_abstract_origin. */
21271 gcc_unreachable ();
21274 if (parm_die
&& parm_die
->die_parent
== NULL
)
21276 /* Check that parm_die already has the right attributes that
21277 we would have added below. If any attributes are
21278 missing, fall through to add them. */
21279 if (! DECL_ABSTRACT_P (node_or_origin
)
21280 && !get_AT (parm_die
, DW_AT_location
)
21281 && !get_AT (parm_die
, DW_AT_const_value
))
21282 /* We are missing location info, and are about to add it. */
21286 add_child_die (context_die
, parm_die
);
21292 /* If we have a previously generated DIE, use it, unless this is an
21293 concrete instance (origin != NULL), in which case we need a new
21294 DIE with a corresponding DW_AT_abstract_origin. */
21296 if (parm_die
&& origin
== NULL
)
21297 reusing_die
= true;
21300 parm_die
= new_die (DW_TAG_formal_parameter
, context_die
, node
);
21301 reusing_die
= false;
21304 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
21306 case tcc_declaration
:
21307 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
21308 if (node
|| ultimate_origin
)
21309 origin
= ultimate_origin
;
21314 if (origin
!= NULL
)
21315 add_abstract_origin_attribute (parm_die
, origin
);
21316 else if (emit_name_p
)
21317 add_name_and_src_coords_attributes (parm_die
, node
);
21319 || (! DECL_ABSTRACT_P (node_or_origin
)
21320 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
21321 decl_function_context
21322 (node_or_origin
))))
21324 tree type
= TREE_TYPE (node_or_origin
);
21325 if (decl_by_reference_p (node_or_origin
))
21326 add_type_attribute (parm_die
, TREE_TYPE (type
),
21328 false, context_die
);
21330 add_type_attribute (parm_die
, type
,
21331 decl_quals (node_or_origin
),
21332 false, context_die
);
21334 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
21335 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
21337 if (node
&& node
!= origin
)
21338 equate_decl_number_to_die (node
, parm_die
);
21339 if (! DECL_ABSTRACT_P (node_or_origin
))
21340 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
21346 /* We were called with some kind of a ..._TYPE node. */
21347 add_type_attribute (parm_die
, node_or_origin
, TYPE_UNQUALIFIED
, false,
21352 gcc_unreachable ();
21358 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
21359 children DW_TAG_formal_parameter DIEs representing the arguments of the
21362 PARM_PACK must be a function parameter pack.
21363 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
21364 must point to the subsequent arguments of the function PACK_ARG belongs to.
21365 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
21366 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
21367 following the last one for which a DIE was generated. */
21370 gen_formal_parameter_pack_die (tree parm_pack
,
21372 dw_die_ref subr_die
,
21376 dw_die_ref parm_pack_die
;
21378 gcc_assert (parm_pack
21379 && lang_hooks
.function_parameter_pack_p (parm_pack
)
21382 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
21383 add_src_coords_attributes (parm_pack_die
, parm_pack
);
21385 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
21387 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
21390 gen_formal_parameter_die (arg
, NULL
,
21391 false /* Don't emit name attribute. */,
21396 return parm_pack_die
;
21399 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
21400 at the end of an (ANSI prototyped) formal parameters list. */
21403 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
21405 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
21408 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
21409 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
21410 parameters as specified in some function type specification (except for
21411 those which appear as part of a function *definition*). */
21414 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
21417 tree formal_type
= NULL
;
21418 tree first_parm_type
;
21421 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
21423 arg
= DECL_ARGUMENTS (function_or_method_type
);
21424 function_or_method_type
= TREE_TYPE (function_or_method_type
);
21429 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
21431 /* Make our first pass over the list of formal parameter types and output a
21432 DW_TAG_formal_parameter DIE for each one. */
21433 for (link
= first_parm_type
; link
; )
21435 dw_die_ref parm_die
;
21437 formal_type
= TREE_VALUE (link
);
21438 if (formal_type
== void_type_node
)
21441 /* Output a (nameless) DIE to represent the formal parameter itself. */
21442 if (!POINTER_BOUNDS_TYPE_P (formal_type
))
21444 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
21445 true /* Emit name attribute. */,
21447 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
21448 && link
== first_parm_type
)
21450 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
21451 if (dwarf_version
>= 3 || !dwarf_strict
)
21452 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
21454 else if (arg
&& DECL_ARTIFICIAL (arg
))
21455 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
21458 link
= TREE_CHAIN (link
);
21460 arg
= DECL_CHAIN (arg
);
21463 /* If this function type has an ellipsis, add a
21464 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
21465 if (formal_type
!= void_type_node
)
21466 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
21468 /* Make our second (and final) pass over the list of formal parameter types
21469 and output DIEs to represent those types (as necessary). */
21470 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
21471 link
&& TREE_VALUE (link
);
21472 link
= TREE_CHAIN (link
))
21473 gen_type_die (TREE_VALUE (link
), context_die
);
21476 /* We want to generate the DIE for TYPE so that we can generate the
21477 die for MEMBER, which has been defined; we will need to refer back
21478 to the member declaration nested within TYPE. If we're trying to
21479 generate minimal debug info for TYPE, processing TYPE won't do the
21480 trick; we need to attach the member declaration by hand. */
21483 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
21485 gen_type_die (type
, context_die
);
21487 /* If we're trying to avoid duplicate debug info, we may not have
21488 emitted the member decl for this function. Emit it now. */
21489 if (TYPE_STUB_DECL (type
)
21490 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
21491 && ! lookup_decl_die (member
))
21493 dw_die_ref type_die
;
21494 gcc_assert (!decl_ultimate_origin (member
));
21496 push_decl_scope (type
);
21497 type_die
= lookup_type_die_strip_naming_typedef (type
);
21498 if (TREE_CODE (member
) == FUNCTION_DECL
)
21499 gen_subprogram_die (member
, type_die
);
21500 else if (TREE_CODE (member
) == FIELD_DECL
)
21502 /* Ignore the nameless fields that are used to skip bits but handle
21503 C++ anonymous unions and structs. */
21504 if (DECL_NAME (member
) != NULL_TREE
21505 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
21506 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
21508 struct vlr_context vlr_ctx
= {
21509 DECL_CONTEXT (member
), /* struct_type */
21510 NULL_TREE
/* variant_part_offset */
21512 gen_type_die (member_declared_type (member
), type_die
);
21513 gen_field_die (member
, &vlr_ctx
, type_die
);
21517 gen_variable_die (member
, NULL_TREE
, type_die
);
21523 /* Forward declare these functions, because they are mutually recursive
21524 with their set_block_* pairing functions. */
21525 static void set_decl_origin_self (tree
);
21527 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
21528 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
21529 that it points to the node itself, thus indicating that the node is its
21530 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
21531 the given node is NULL, recursively descend the decl/block tree which
21532 it is the root of, and for each other ..._DECL or BLOCK node contained
21533 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
21534 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
21535 values to point to themselves. */
21538 set_block_origin_self (tree stmt
)
21540 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
21542 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
21547 for (local_decl
= BLOCK_VARS (stmt
);
21548 local_decl
!= NULL_TREE
;
21549 local_decl
= DECL_CHAIN (local_decl
))
21550 /* Do not recurse on nested functions since the inlining status
21551 of parent and child can be different as per the DWARF spec. */
21552 if (TREE_CODE (local_decl
) != FUNCTION_DECL
21553 && !DECL_EXTERNAL (local_decl
))
21554 set_decl_origin_self (local_decl
);
21560 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
21561 subblock
!= NULL_TREE
;
21562 subblock
= BLOCK_CHAIN (subblock
))
21563 set_block_origin_self (subblock
); /* Recurse. */
21568 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
21569 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
21570 node to so that it points to the node itself, thus indicating that the
21571 node represents its own (abstract) origin. Additionally, if the
21572 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
21573 the decl/block tree of which the given node is the root of, and for
21574 each other ..._DECL or BLOCK node contained therein whose
21575 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
21576 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
21577 point to themselves. */
21580 set_decl_origin_self (tree decl
)
21582 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
21584 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
21585 if (TREE_CODE (decl
) == FUNCTION_DECL
)
21589 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
21590 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
21591 if (DECL_INITIAL (decl
) != NULL_TREE
21592 && DECL_INITIAL (decl
) != error_mark_node
)
21593 set_block_origin_self (DECL_INITIAL (decl
));
21598 /* Mark the early DIE for DECL as the abstract instance. */
21601 dwarf2out_abstract_function (tree decl
)
21603 dw_die_ref old_die
;
21605 /* Make sure we have the actual abstract inline, not a clone. */
21606 decl
= DECL_ORIGIN (decl
);
21608 if (DECL_IGNORED_P (decl
))
21611 old_die
= lookup_decl_die (decl
);
21612 /* With early debug we always have an old DIE unless we are in LTO
21613 and the user did not compile but only link with debug. */
21614 if (in_lto_p
&& ! old_die
)
21616 gcc_assert (old_die
!= NULL
);
21617 if (get_AT (old_die
, DW_AT_inline
)
21618 || get_AT (old_die
, DW_AT_abstract_origin
))
21619 /* We've already generated the abstract instance. */
21622 /* Go ahead and put DW_AT_inline on the DIE. */
21623 if (DECL_DECLARED_INLINE_P (decl
))
21625 if (cgraph_function_possibly_inlined_p (decl
))
21626 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_declared_inlined
);
21628 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
21632 if (cgraph_function_possibly_inlined_p (decl
))
21633 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_inlined
);
21635 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_not_inlined
);
21638 if (DECL_DECLARED_INLINE_P (decl
)
21639 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
21640 add_AT_flag (old_die
, DW_AT_artificial
, 1);
21642 set_decl_origin_self (decl
);
21645 /* Helper function of premark_used_types() which gets called through
21648 Marks the DIE of a given type in *SLOT as perennial, so it never gets
21649 marked as unused by prune_unused_types. */
21652 premark_used_types_helper (tree
const &type
, void *)
21656 die
= lookup_type_die (type
);
21658 die
->die_perennial_p
= 1;
21662 /* Helper function of premark_types_used_by_global_vars which gets called
21663 through htab_traverse.
21665 Marks the DIE of a given type in *SLOT as perennial, so it never gets
21666 marked as unused by prune_unused_types. The DIE of the type is marked
21667 only if the global variable using the type will actually be emitted. */
21670 premark_types_used_by_global_vars_helper (types_used_by_vars_entry
**slot
,
21673 struct types_used_by_vars_entry
*entry
;
21676 entry
= (struct types_used_by_vars_entry
*) *slot
;
21677 gcc_assert (entry
->type
!= NULL
21678 && entry
->var_decl
!= NULL
);
21679 die
= lookup_type_die (entry
->type
);
21682 /* Ask cgraph if the global variable really is to be emitted.
21683 If yes, then we'll keep the DIE of ENTRY->TYPE. */
21684 varpool_node
*node
= varpool_node::get (entry
->var_decl
);
21685 if (node
&& node
->definition
)
21687 die
->die_perennial_p
= 1;
21688 /* Keep the parent DIEs as well. */
21689 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
21690 die
->die_perennial_p
= 1;
21696 /* Mark all members of used_types_hash as perennial. */
21699 premark_used_types (struct function
*fun
)
21701 if (fun
&& fun
->used_types_hash
)
21702 fun
->used_types_hash
->traverse
<void *, premark_used_types_helper
> (NULL
);
21705 /* Mark all members of types_used_by_vars_entry as perennial. */
21708 premark_types_used_by_global_vars (void)
21710 if (types_used_by_vars_hash
)
21711 types_used_by_vars_hash
21712 ->traverse
<void *, premark_types_used_by_global_vars_helper
> (NULL
);
21715 /* Generate a DW_TAG_call_site DIE in function DECL under SUBR_DIE
21716 for CA_LOC call arg loc node. */
21719 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
21720 struct call_arg_loc_node
*ca_loc
)
21722 dw_die_ref stmt_die
= NULL
, die
;
21723 tree block
= ca_loc
->block
;
21726 && block
!= DECL_INITIAL (decl
)
21727 && TREE_CODE (block
) == BLOCK
)
21729 stmt_die
= BLOCK_DIE (block
);
21732 block
= BLOCK_SUPERCONTEXT (block
);
21734 if (stmt_die
== NULL
)
21735 stmt_die
= subr_die
;
21736 die
= new_die (dwarf_TAG (DW_TAG_call_site
), stmt_die
, NULL_TREE
);
21737 add_AT_lbl_id (die
, dwarf_AT (DW_AT_call_return_pc
), ca_loc
->label
);
21738 if (ca_loc
->tail_call_p
)
21739 add_AT_flag (die
, dwarf_AT (DW_AT_call_tail_call
), 1);
21740 if (ca_loc
->symbol_ref
)
21742 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
21744 add_AT_die_ref (die
, dwarf_AT (DW_AT_call_origin
), tdie
);
21746 add_AT_addr (die
, dwarf_AT (DW_AT_call_origin
), ca_loc
->symbol_ref
,
21752 /* Generate a DIE to represent a declared function (either file-scope or
21756 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
21758 tree origin
= decl_ultimate_origin (decl
);
21759 dw_die_ref subr_die
;
21760 dw_die_ref old_die
= lookup_decl_die (decl
);
21762 /* This function gets called multiple times for different stages of
21763 the debug process. For example, for func() in this code:
21767 void func() { ... }
21770 ...we get called 4 times. Twice in early debug and twice in
21776 1. Once while generating func() within the namespace. This is
21777 the declaration. The declaration bit below is set, as the
21778 context is the namespace.
21780 A new DIE will be generated with DW_AT_declaration set.
21782 2. Once for func() itself. This is the specification. The
21783 declaration bit below is clear as the context is the CU.
21785 We will use the cached DIE from (1) to create a new DIE with
21786 DW_AT_specification pointing to the declaration in (1).
21788 Late debug via rest_of_handle_final()
21789 -------------------------------------
21791 3. Once generating func() within the namespace. This is also the
21792 declaration, as in (1), but this time we will early exit below
21793 as we have a cached DIE and a declaration needs no additional
21794 annotations (no locations), as the source declaration line
21797 4. Once for func() itself. As in (2), this is the specification,
21798 but this time we will re-use the cached DIE, and just annotate
21799 it with the location information that should now be available.
21801 For something without namespaces, but with abstract instances, we
21802 are also called a multiple times:
21807 Base (); // constructor declaration (1)
21810 Base::Base () { } // constructor specification (2)
21815 1. Once for the Base() constructor by virtue of it being a
21816 member of the Base class. This is done via
21817 rest_of_type_compilation.
21819 This is a declaration, so a new DIE will be created with
21822 2. Once for the Base() constructor definition, but this time
21823 while generating the abstract instance of the base
21824 constructor (__base_ctor) which is being generated via early
21825 debug of reachable functions.
21827 Even though we have a cached version of the declaration (1),
21828 we will create a DW_AT_specification of the declaration DIE
21831 3. Once for the __base_ctor itself, but this time, we generate
21832 an DW_AT_abstract_origin version of the DW_AT_specification in
21835 Late debug via rest_of_handle_final
21836 -----------------------------------
21838 4. One final time for the __base_ctor (which will have a cached
21839 DIE with DW_AT_abstract_origin created in (3). This time,
21840 we will just annotate the location information now
21843 int declaration
= (current_function_decl
!= decl
21844 || class_or_namespace_scope_p (context_die
));
21846 /* Now that the C++ front end lazily declares artificial member fns, we
21847 might need to retrofit the declaration into its class. */
21848 if (!declaration
&& !origin
&& !old_die
21849 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
21850 && !class_or_namespace_scope_p (context_die
)
21851 && debug_info_level
> DINFO_LEVEL_TERSE
)
21852 old_die
= force_decl_die (decl
);
21854 /* A concrete instance, tag a new DIE with DW_AT_abstract_origin. */
21855 if (origin
!= NULL
)
21857 gcc_assert (!declaration
|| local_scope_p (context_die
));
21859 /* Fixup die_parent for the abstract instance of a nested
21860 inline function. */
21861 if (old_die
&& old_die
->die_parent
== NULL
)
21862 add_child_die (context_die
, old_die
);
21864 if (old_die
&& get_AT_ref (old_die
, DW_AT_abstract_origin
))
21866 /* If we have a DW_AT_abstract_origin we have a working
21868 subr_die
= old_die
;
21872 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
21873 add_abstract_origin_attribute (subr_die
, origin
);
21874 /* This is where the actual code for a cloned function is.
21875 Let's emit linkage name attribute for it. This helps
21876 debuggers to e.g, set breakpoints into
21877 constructors/destructors when the user asks "break
21879 add_linkage_name (subr_die
, decl
);
21882 /* A cached copy, possibly from early dwarf generation. Reuse as
21883 much as possible. */
21886 /* A declaration that has been previously dumped needs no
21887 additional information. */
21891 if (!get_AT_flag (old_die
, DW_AT_declaration
)
21892 /* We can have a normal definition following an inline one in the
21893 case of redefinition of GNU C extern inlines.
21894 It seems reasonable to use AT_specification in this case. */
21895 && !get_AT (old_die
, DW_AT_inline
))
21897 /* Detect and ignore this case, where we are trying to output
21898 something we have already output. */
21899 if (get_AT (old_die
, DW_AT_low_pc
)
21900 || get_AT (old_die
, DW_AT_ranges
))
21903 /* If we have no location information, this must be a
21904 partially generated DIE from early dwarf generation.
21905 Fall through and generate it. */
21908 /* If the definition comes from the same place as the declaration,
21909 maybe use the old DIE. We always want the DIE for this function
21910 that has the *_pc attributes to be under comp_unit_die so the
21911 debugger can find it. We also need to do this for abstract
21912 instances of inlines, since the spec requires the out-of-line copy
21913 to have the same parent. For local class methods, this doesn't
21914 apply; we just use the old DIE. */
21915 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
21916 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
21917 if ((is_cu_die (old_die
->die_parent
)
21918 /* This condition fixes the inconsistency/ICE with the
21919 following Fortran test (or some derivative thereof) while
21920 building libgfortran:
21924 logical function funky (FLAG)
21929 || (old_die
->die_parent
21930 && old_die
->die_parent
->die_tag
== DW_TAG_module
)
21931 || context_die
== NULL
)
21932 && (DECL_ARTIFICIAL (decl
)
21933 /* The location attributes may be in the abstract origin
21934 which in the case of LTO might be not available to
21936 || get_AT (old_die
, DW_AT_abstract_origin
)
21937 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
21938 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
21939 == (unsigned) s
.line
)
21940 && (!debug_column_info
21942 || (get_AT_unsigned (old_die
, DW_AT_decl_column
)
21943 == (unsigned) s
.column
)))))
21945 subr_die
= old_die
;
21947 /* Clear out the declaration attribute, but leave the
21948 parameters so they can be augmented with location
21949 information later. Unless this was a declaration, in
21950 which case, wipe out the nameless parameters and recreate
21951 them further down. */
21952 if (remove_AT (subr_die
, DW_AT_declaration
))
21955 remove_AT (subr_die
, DW_AT_object_pointer
);
21956 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
21959 /* Make a specification pointing to the previously built
21963 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
21964 add_AT_specification (subr_die
, old_die
);
21965 add_pubname (decl
, subr_die
);
21966 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
21967 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
21968 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
21969 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
21970 if (debug_column_info
21972 && (get_AT_unsigned (old_die
, DW_AT_decl_column
)
21973 != (unsigned) s
.column
))
21974 add_AT_unsigned (subr_die
, DW_AT_decl_column
, s
.column
);
21976 /* If the prototype had an 'auto' or 'decltype(auto)' return type,
21977 emit the real type on the definition die. */
21978 if (is_cxx () && debug_info_level
> DINFO_LEVEL_TERSE
)
21980 dw_die_ref die
= get_AT_ref (old_die
, DW_AT_type
);
21981 if (die
== auto_die
|| die
== decltype_auto_die
)
21982 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
21983 TYPE_UNQUALIFIED
, false, context_die
);
21986 /* When we process the method declaration, we haven't seen
21987 the out-of-class defaulted definition yet, so we have to
21989 if ((dwarf_version
>= 5 || ! dwarf_strict
)
21990 && !get_AT (subr_die
, DW_AT_defaulted
))
21993 = lang_hooks
.decls
.decl_dwarf_attribute (decl
,
21995 if (defaulted
!= -1)
21997 /* Other values must have been handled before. */
21998 gcc_assert (defaulted
== DW_DEFAULTED_out_of_class
);
21999 add_AT_unsigned (subr_die
, DW_AT_defaulted
, defaulted
);
22004 /* Create a fresh DIE for anything else. */
22007 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
22009 if (TREE_PUBLIC (decl
))
22010 add_AT_flag (subr_die
, DW_AT_external
, 1);
22012 add_name_and_src_coords_attributes (subr_die
, decl
);
22013 add_pubname (decl
, subr_die
);
22014 if (debug_info_level
> DINFO_LEVEL_TERSE
)
22016 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
22017 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
22018 TYPE_UNQUALIFIED
, false, context_die
);
22021 add_pure_or_virtual_attribute (subr_die
, decl
);
22022 if (DECL_ARTIFICIAL (decl
))
22023 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
22025 if (TREE_THIS_VOLATILE (decl
) && (dwarf_version
>= 5 || !dwarf_strict
))
22026 add_AT_flag (subr_die
, DW_AT_noreturn
, 1);
22028 add_alignment_attribute (subr_die
, decl
);
22030 add_accessibility_attribute (subr_die
, decl
);
22033 /* Unless we have an existing non-declaration DIE, equate the new
22035 if (!old_die
|| is_declaration_die (old_die
))
22036 equate_decl_number_to_die (decl
, subr_die
);
22040 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
22042 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
22044 /* If this is an explicit function declaration then generate
22045 a DW_AT_explicit attribute. */
22046 if ((dwarf_version
>= 3 || !dwarf_strict
)
22047 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22048 DW_AT_explicit
) == 1)
22049 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
22051 /* If this is a C++11 deleted special function member then generate
22052 a DW_AT_deleted attribute. */
22053 if ((dwarf_version
>= 5 || !dwarf_strict
)
22054 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22055 DW_AT_deleted
) == 1)
22056 add_AT_flag (subr_die
, DW_AT_deleted
, 1);
22058 /* If this is a C++11 defaulted special function member then
22059 generate a DW_AT_defaulted attribute. */
22060 if (dwarf_version
>= 5 || !dwarf_strict
)
22063 = lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22065 if (defaulted
!= -1)
22066 add_AT_unsigned (subr_die
, DW_AT_defaulted
, defaulted
);
22069 /* If this is a C++11 non-static member function with & ref-qualifier
22070 then generate a DW_AT_reference attribute. */
22071 if ((dwarf_version
>= 5 || !dwarf_strict
)
22072 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22073 DW_AT_reference
) == 1)
22074 add_AT_flag (subr_die
, DW_AT_reference
, 1);
22076 /* If this is a C++11 non-static member function with &&
22077 ref-qualifier then generate a DW_AT_reference attribute. */
22078 if ((dwarf_version
>= 5 || !dwarf_strict
)
22079 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22080 DW_AT_rvalue_reference
)
22082 add_AT_flag (subr_die
, DW_AT_rvalue_reference
, 1);
22085 /* Tag abstract instances with DW_AT_inline. */
22086 else if (DECL_ABSTRACT_P (decl
))
22088 if (DECL_DECLARED_INLINE_P (decl
))
22090 if (cgraph_function_possibly_inlined_p (decl
))
22091 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
22093 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
22097 if (cgraph_function_possibly_inlined_p (decl
))
22098 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
22100 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
22103 if (DECL_DECLARED_INLINE_P (decl
)
22104 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
22105 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
22107 /* For non DECL_EXTERNALs, if range information is available, fill
22108 the DIE with it. */
22109 else if (!DECL_EXTERNAL (decl
) && !early_dwarf
)
22111 HOST_WIDE_INT cfa_fb_offset
;
22113 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
22115 if (!crtl
->has_bb_partition
)
22117 dw_fde_ref fde
= fun
->fde
;
22118 if (fde
->dw_fde_begin
)
22120 /* We have already generated the labels. */
22121 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
22122 fde
->dw_fde_end
, false);
22126 /* Create start/end labels and add the range. */
22127 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
22128 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
22129 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
22130 current_function_funcdef_no
);
22131 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
22132 current_function_funcdef_no
);
22133 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
22137 #if VMS_DEBUGGING_INFO
22138 /* HP OpenVMS Industry Standard 64: DWARF Extensions
22139 Section 2.3 Prologue and Epilogue Attributes:
22140 When a breakpoint is set on entry to a function, it is generally
22141 desirable for execution to be suspended, not on the very first
22142 instruction of the function, but rather at a point after the
22143 function's frame has been set up, after any language defined local
22144 declaration processing has been completed, and before execution of
22145 the first statement of the function begins. Debuggers generally
22146 cannot properly determine where this point is. Similarly for a
22147 breakpoint set on exit from a function. The prologue and epilogue
22148 attributes allow a compiler to communicate the location(s) to use. */
22151 if (fde
->dw_fde_vms_end_prologue
)
22152 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
22153 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
22155 if (fde
->dw_fde_vms_begin_epilogue
)
22156 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
22157 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
22164 /* Generate pubnames entries for the split function code ranges. */
22165 dw_fde_ref fde
= fun
->fde
;
22167 if (fde
->dw_fde_second_begin
)
22169 if (dwarf_version
>= 3 || !dwarf_strict
)
22171 /* We should use ranges for non-contiguous code section
22172 addresses. Use the actual code range for the initial
22173 section, since the HOT/COLD labels might precede an
22174 alignment offset. */
22175 bool range_list_added
= false;
22176 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
22177 fde
->dw_fde_end
, &range_list_added
,
22179 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
22180 fde
->dw_fde_second_end
,
22181 &range_list_added
, false);
22182 if (range_list_added
)
22187 /* There is no real support in DW2 for this .. so we make
22188 a work-around. First, emit the pub name for the segment
22189 containing the function label. Then make and emit a
22190 simplified subprogram DIE for the second segment with the
22191 name pre-fixed by __hot/cold_sect_of_. We use the same
22192 linkage name for the second die so that gdb will find both
22193 sections when given "b foo". */
22194 const char *name
= NULL
;
22195 tree decl_name
= DECL_NAME (decl
);
22196 dw_die_ref seg_die
;
22198 /* Do the 'primary' section. */
22199 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
22200 fde
->dw_fde_end
, false);
22202 /* Build a minimal DIE for the secondary section. */
22203 seg_die
= new_die (DW_TAG_subprogram
,
22204 subr_die
->die_parent
, decl
);
22206 if (TREE_PUBLIC (decl
))
22207 add_AT_flag (seg_die
, DW_AT_external
, 1);
22209 if (decl_name
!= NULL
22210 && IDENTIFIER_POINTER (decl_name
) != NULL
)
22212 name
= dwarf2_name (decl
, 1);
22213 if (! DECL_ARTIFICIAL (decl
))
22214 add_src_coords_attributes (seg_die
, decl
);
22216 add_linkage_name (seg_die
, decl
);
22218 gcc_assert (name
!= NULL
);
22219 add_pure_or_virtual_attribute (seg_die
, decl
);
22220 if (DECL_ARTIFICIAL (decl
))
22221 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
22223 name
= concat ("__second_sect_of_", name
, NULL
);
22224 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
22225 fde
->dw_fde_second_end
, false);
22226 add_name_attribute (seg_die
, name
);
22227 if (want_pubnames ())
22228 add_pubname_string (name
, seg_die
);
22232 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
22236 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
22238 /* We define the "frame base" as the function's CFA. This is more
22239 convenient for several reasons: (1) It's stable across the prologue
22240 and epilogue, which makes it better than just a frame pointer,
22241 (2) With dwarf3, there exists a one-byte encoding that allows us
22242 to reference the .debug_frame data by proxy, but failing that,
22243 (3) We can at least reuse the code inspection and interpretation
22244 code that determines the CFA position at various points in the
22246 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
22248 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
22249 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
22253 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
22254 if (list
->dw_loc_next
)
22255 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
22257 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
22260 /* Compute a displacement from the "steady-state frame pointer" to
22261 the CFA. The former is what all stack slots and argument slots
22262 will reference in the rtl; the latter is what we've told the
22263 debugger about. We'll need to adjust all frame_base references
22264 by this displacement. */
22265 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
22267 if (fun
->static_chain_decl
)
22269 /* DWARF requires here a location expression that computes the
22270 address of the enclosing subprogram's frame base. The machinery
22271 in tree-nested.c is supposed to store this specific address in the
22272 last field of the FRAME record. */
22273 const tree frame_type
22274 = TREE_TYPE (TREE_TYPE (fun
->static_chain_decl
));
22275 const tree fb_decl
= tree_last (TYPE_FIELDS (frame_type
));
22278 = build1 (INDIRECT_REF
, frame_type
, fun
->static_chain_decl
);
22279 fb_expr
= build3 (COMPONENT_REF
, TREE_TYPE (fb_decl
),
22280 fb_expr
, fb_decl
, NULL_TREE
);
22282 add_AT_location_description (subr_die
, DW_AT_static_link
,
22283 loc_list_from_tree (fb_expr
, 0, NULL
));
22286 resolve_variable_values ();
22289 /* Generate child dies for template paramaters. */
22290 if (early_dwarf
&& debug_info_level
> DINFO_LEVEL_TERSE
)
22291 gen_generic_params_dies (decl
);
22293 /* Now output descriptions of the arguments for this function. This gets
22294 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
22295 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
22296 `...' at the end of the formal parameter list. In order to find out if
22297 there was a trailing ellipsis or not, we must instead look at the type
22298 associated with the FUNCTION_DECL. This will be a node of type
22299 FUNCTION_TYPE. If the chain of type nodes hanging off of this
22300 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
22301 an ellipsis at the end. */
22303 /* In the case where we are describing a mere function declaration, all we
22304 need to do here (and all we *can* do here) is to describe the *types* of
22305 its formal parameters. */
22306 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
22308 else if (declaration
)
22309 gen_formal_types_die (decl
, subr_die
);
22312 /* Generate DIEs to represent all known formal parameters. */
22313 tree parm
= DECL_ARGUMENTS (decl
);
22314 tree generic_decl
= early_dwarf
22315 ? lang_hooks
.decls
.get_generic_function_decl (decl
) : NULL
;
22316 tree generic_decl_parm
= generic_decl
22317 ? DECL_ARGUMENTS (generic_decl
)
22320 /* Now we want to walk the list of parameters of the function and
22321 emit their relevant DIEs.
22323 We consider the case of DECL being an instance of a generic function
22324 as well as it being a normal function.
22326 If DECL is an instance of a generic function we walk the
22327 parameters of the generic function declaration _and_ the parameters of
22328 DECL itself. This is useful because we want to emit specific DIEs for
22329 function parameter packs and those are declared as part of the
22330 generic function declaration. In that particular case,
22331 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
22332 That DIE has children DIEs representing the set of arguments
22333 of the pack. Note that the set of pack arguments can be empty.
22334 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
22337 Otherwise, we just consider the parameters of DECL. */
22338 while (generic_decl_parm
|| parm
)
22340 if (generic_decl_parm
22341 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
22342 gen_formal_parameter_pack_die (generic_decl_parm
,
22345 else if (parm
&& !POINTER_BOUNDS_P (parm
))
22347 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, NULL
, subr_die
);
22349 if (parm
== DECL_ARGUMENTS (decl
)
22350 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
22352 && (dwarf_version
>= 3 || !dwarf_strict
))
22353 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
22355 parm
= DECL_CHAIN (parm
);
22358 parm
= DECL_CHAIN (parm
);
22360 if (generic_decl_parm
)
22361 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
22364 /* Decide whether we need an unspecified_parameters DIE at the end.
22365 There are 2 more cases to do this for: 1) the ansi ... declaration -
22366 this is detectable when the end of the arg list is not a
22367 void_type_node 2) an unprototyped function declaration (not a
22368 definition). This just means that we have no info about the
22369 parameters at all. */
22372 if (prototype_p (TREE_TYPE (decl
)))
22374 /* This is the prototyped case, check for.... */
22375 if (stdarg_p (TREE_TYPE (decl
)))
22376 gen_unspecified_parameters_die (decl
, subr_die
);
22378 else if (DECL_INITIAL (decl
) == NULL_TREE
)
22379 gen_unspecified_parameters_die (decl
, subr_die
);
22383 if (subr_die
!= old_die
)
22384 /* Add the calling convention attribute if requested. */
22385 add_calling_convention_attribute (subr_die
, decl
);
22387 /* Output Dwarf info for all of the stuff within the body of the function
22388 (if it has one - it may be just a declaration).
22390 OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
22391 a function. This BLOCK actually represents the outermost binding contour
22392 for the function, i.e. the contour in which the function's formal
22393 parameters and labels get declared. Curiously, it appears that the front
22394 end doesn't actually put the PARM_DECL nodes for the current function onto
22395 the BLOCK_VARS list for this outer scope, but are strung off of the
22396 DECL_ARGUMENTS list for the function instead.
22398 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
22399 the LABEL_DECL nodes for the function however, and we output DWARF info
22400 for those in decls_for_scope. Just within the `outer_scope' there will be
22401 a BLOCK node representing the function's outermost pair of curly braces,
22402 and any blocks used for the base and member initializers of a C++
22403 constructor function. */
22404 tree outer_scope
= DECL_INITIAL (decl
);
22405 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
22407 int call_site_note_count
= 0;
22408 int tail_call_site_note_count
= 0;
22410 /* Emit a DW_TAG_variable DIE for a named return value. */
22411 if (DECL_NAME (DECL_RESULT (decl
)))
22412 gen_decl_die (DECL_RESULT (decl
), NULL
, NULL
, subr_die
);
22414 /* The first time through decls_for_scope we will generate the
22415 DIEs for the locals. The second time, we fill in the
22417 decls_for_scope (outer_scope
, subr_die
);
22419 if (call_arg_locations
&& (!dwarf_strict
|| dwarf_version
>= 5))
22421 struct call_arg_loc_node
*ca_loc
;
22422 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
22424 dw_die_ref die
= NULL
;
22425 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
22428 for (arg
= (ca_loc
->call_arg_loc_note
!= NULL_RTX
22429 ? NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
)
22431 arg
; arg
= next_arg
)
22433 dw_loc_descr_ref reg
, val
;
22434 machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
22435 dw_die_ref cdie
, tdie
= NULL
;
22437 next_arg
= XEXP (arg
, 1);
22438 if (REG_P (XEXP (XEXP (arg
, 0), 0))
22440 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
22441 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
22442 && REGNO (XEXP (XEXP (arg
, 0), 0))
22443 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
22444 next_arg
= XEXP (next_arg
, 1);
22445 if (mode
== VOIDmode
)
22447 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
22448 if (mode
== VOIDmode
)
22449 mode
= GET_MODE (XEXP (arg
, 0));
22451 if (mode
== VOIDmode
|| mode
== BLKmode
)
22453 /* Get dynamic information about call target only if we
22454 have no static information: we cannot generate both
22455 DW_AT_call_origin and DW_AT_call_target
22457 if (ca_loc
->symbol_ref
== NULL_RTX
)
22459 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
22461 tloc
= XEXP (XEXP (arg
, 0), 1);
22464 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
22465 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
22467 tlocc
= XEXP (XEXP (arg
, 0), 1);
22472 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
22473 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
22474 VAR_INIT_STATUS_INITIALIZED
);
22475 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
22477 rtx mem
= XEXP (XEXP (arg
, 0), 0);
22478 reg
= mem_loc_descriptor (XEXP (mem
, 0),
22479 get_address_mode (mem
),
22481 VAR_INIT_STATUS_INITIALIZED
);
22483 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
22484 == DEBUG_PARAMETER_REF
)
22487 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
22488 tdie
= lookup_decl_die (tdecl
);
22495 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
22496 != DEBUG_PARAMETER_REF
)
22498 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
22500 VAR_INIT_STATUS_INITIALIZED
);
22504 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
22505 cdie
= new_die (dwarf_TAG (DW_TAG_call_site_parameter
), die
,
22508 add_AT_loc (cdie
, DW_AT_location
, reg
);
22509 else if (tdie
!= NULL
)
22510 add_AT_die_ref (cdie
, dwarf_AT (DW_AT_call_parameter
),
22512 add_AT_loc (cdie
, dwarf_AT (DW_AT_call_value
), val
);
22513 if (next_arg
!= XEXP (arg
, 1))
22515 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
22516 if (mode
== VOIDmode
)
22517 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
22518 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
22521 VAR_INIT_STATUS_INITIALIZED
);
22523 add_AT_loc (cdie
, dwarf_AT (DW_AT_call_data_value
),
22528 && (ca_loc
->symbol_ref
|| tloc
))
22529 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
22530 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
22532 dw_loc_descr_ref tval
= NULL
;
22534 if (tloc
!= NULL_RTX
)
22535 tval
= mem_loc_descriptor (tloc
,
22536 GET_MODE (tloc
) == VOIDmode
22537 ? Pmode
: GET_MODE (tloc
),
22539 VAR_INIT_STATUS_INITIALIZED
);
22541 add_AT_loc (die
, dwarf_AT (DW_AT_call_target
), tval
);
22542 else if (tlocc
!= NULL_RTX
)
22544 tval
= mem_loc_descriptor (tlocc
,
22545 GET_MODE (tlocc
) == VOIDmode
22546 ? Pmode
: GET_MODE (tlocc
),
22548 VAR_INIT_STATUS_INITIALIZED
);
22551 dwarf_AT (DW_AT_call_target_clobbered
),
22557 call_site_note_count
++;
22558 if (ca_loc
->tail_call_p
)
22559 tail_call_site_note_count
++;
22563 call_arg_locations
= NULL
;
22564 call_arg_loc_last
= NULL
;
22565 if (tail_call_site_count
>= 0
22566 && tail_call_site_count
== tail_call_site_note_count
22567 && (!dwarf_strict
|| dwarf_version
>= 5))
22569 if (call_site_count
>= 0
22570 && call_site_count
== call_site_note_count
)
22571 add_AT_flag (subr_die
, dwarf_AT (DW_AT_call_all_calls
), 1);
22573 add_AT_flag (subr_die
, dwarf_AT (DW_AT_call_all_tail_calls
), 1);
22575 call_site_count
= -1;
22576 tail_call_site_count
= -1;
22579 /* Mark used types after we have created DIEs for the functions scopes. */
22580 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
22583 /* Returns a hash value for X (which really is a die_struct). */
22586 block_die_hasher::hash (die_struct
*d
)
22588 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
22591 /* Return nonzero if decl_id and die_parent of die_struct X is the same
22592 as decl_id and die_parent of die_struct Y. */
22595 block_die_hasher::equal (die_struct
*x
, die_struct
*y
)
22597 return x
->decl_id
== y
->decl_id
&& x
->die_parent
== y
->die_parent
;
22600 /* Return TRUE if DECL, which may have been previously generated as
22601 OLD_DIE, is a candidate for a DW_AT_specification. DECLARATION is
22602 true if decl (or its origin) is either an extern declaration or a
22603 class/namespace scoped declaration.
22605 The declare_in_namespace support causes us to get two DIEs for one
22606 variable, both of which are declarations. We want to avoid
22607 considering one to be a specification, so we must test for
22608 DECLARATION and DW_AT_declaration. */
22610 decl_will_get_specification_p (dw_die_ref old_die
, tree decl
, bool declaration
)
22612 return (old_die
&& TREE_STATIC (decl
) && !declaration
22613 && get_AT_flag (old_die
, DW_AT_declaration
) == 1);
22616 /* Return true if DECL is a local static. */
22619 local_function_static (tree decl
)
22621 gcc_assert (VAR_P (decl
));
22622 return TREE_STATIC (decl
)
22623 && DECL_CONTEXT (decl
)
22624 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
;
22627 /* Generate a DIE to represent a declared data object.
22628 Either DECL or ORIGIN must be non-null. */
22631 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
22633 HOST_WIDE_INT off
= 0;
22635 tree decl_or_origin
= decl
? decl
: origin
;
22636 tree ultimate_origin
;
22637 dw_die_ref var_die
;
22638 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
22639 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
22640 || class_or_namespace_scope_p (context_die
));
22641 bool specialization_p
= false;
22642 bool no_linkage_name
= false;
22644 /* While C++ inline static data members have definitions inside of the
22645 class, force the first DIE to be a declaration, then let gen_member_die
22646 reparent it to the class context and call gen_variable_die again
22647 to create the outside of the class DIE for the definition. */
22651 && DECL_CONTEXT (decl
)
22652 && TYPE_P (DECL_CONTEXT (decl
))
22653 && lang_hooks
.decls
.decl_dwarf_attribute (decl
, DW_AT_inline
) != -1)
22655 declaration
= true;
22656 if (dwarf_version
< 5)
22657 no_linkage_name
= true;
22660 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
22661 if (decl
|| ultimate_origin
)
22662 origin
= ultimate_origin
;
22663 com_decl
= fortran_common (decl_or_origin
, &off
);
22665 /* Symbol in common gets emitted as a child of the common block, in the form
22666 of a data member. */
22669 dw_die_ref com_die
;
22670 dw_loc_list_ref loc
= NULL
;
22671 die_node com_die_arg
;
22673 var_die
= lookup_decl_die (decl_or_origin
);
22676 if (! early_dwarf
&& get_AT (var_die
, DW_AT_location
) == NULL
)
22678 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2, NULL
);
22683 /* Optimize the common case. */
22684 if (single_element_loc_list_p (loc
)
22685 && loc
->expr
->dw_loc_opc
== DW_OP_addr
22686 && loc
->expr
->dw_loc_next
== NULL
22687 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
22690 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
22691 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
22692 = plus_constant (GET_MODE (x
), x
, off
);
22695 loc_list_plus_const (loc
, off
);
22697 add_AT_location_description (var_die
, DW_AT_location
, loc
);
22698 remove_AT (var_die
, DW_AT_declaration
);
22704 if (common_block_die_table
== NULL
)
22705 common_block_die_table
= hash_table
<block_die_hasher
>::create_ggc (10);
22707 com_die_arg
.decl_id
= DECL_UID (com_decl
);
22708 com_die_arg
.die_parent
= context_die
;
22709 com_die
= common_block_die_table
->find (&com_die_arg
);
22711 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
22712 if (com_die
== NULL
)
22715 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
22718 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
22719 add_name_and_src_coords_attributes (com_die
, com_decl
);
22722 add_AT_location_description (com_die
, DW_AT_location
, loc
);
22723 /* Avoid sharing the same loc descriptor between
22724 DW_TAG_common_block and DW_TAG_variable. */
22725 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
22727 else if (DECL_EXTERNAL (decl_or_origin
))
22728 add_AT_flag (com_die
, DW_AT_declaration
, 1);
22729 if (want_pubnames ())
22730 add_pubname_string (cnam
, com_die
); /* ??? needed? */
22731 com_die
->decl_id
= DECL_UID (com_decl
);
22732 slot
= common_block_die_table
->find_slot (com_die
, INSERT
);
22735 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
22737 add_AT_location_description (com_die
, DW_AT_location
, loc
);
22738 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
22739 remove_AT (com_die
, DW_AT_declaration
);
22741 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
22742 add_name_and_src_coords_attributes (var_die
, decl_or_origin
);
22743 add_type_attribute (var_die
, TREE_TYPE (decl_or_origin
),
22744 decl_quals (decl_or_origin
), false,
22746 add_alignment_attribute (var_die
, decl
);
22747 add_AT_flag (var_die
, DW_AT_external
, 1);
22752 /* Optimize the common case. */
22753 if (single_element_loc_list_p (loc
)
22754 && loc
->expr
->dw_loc_opc
== DW_OP_addr
22755 && loc
->expr
->dw_loc_next
== NULL
22756 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
22758 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
22759 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
22760 = plus_constant (GET_MODE (x
), x
, off
);
22763 loc_list_plus_const (loc
, off
);
22765 add_AT_location_description (var_die
, DW_AT_location
, loc
);
22767 else if (DECL_EXTERNAL (decl_or_origin
))
22768 add_AT_flag (var_die
, DW_AT_declaration
, 1);
22770 equate_decl_number_to_die (decl
, var_die
);
22778 /* A declaration that has been previously dumped, needs no
22779 further annotations, since it doesn't need location on
22780 the second pass. */
22783 else if (decl_will_get_specification_p (old_die
, decl
, declaration
)
22784 && !get_AT (old_die
, DW_AT_specification
))
22786 /* Fall-thru so we can make a new variable die along with a
22787 DW_AT_specification. */
22789 else if (origin
&& old_die
->die_parent
!= context_die
)
22791 /* If we will be creating an inlined instance, we need a
22792 new DIE that will get annotated with
22793 DW_AT_abstract_origin. Clear things so we can get a
22795 gcc_assert (!DECL_ABSTRACT_P (decl
));
22800 /* If a DIE was dumped early, it still needs location info.
22801 Skip to where we fill the location bits. */
22804 /* ??? In LTRANS we cannot annotate early created variably
22805 modified type DIEs without copying them and adjusting all
22806 references to them. Thus we dumped them again, also add a
22807 reference to them. */
22808 tree type
= TREE_TYPE (decl_or_origin
);
22810 && variably_modified_type_p
22811 (type
, decl_function_context (decl_or_origin
)))
22813 if (decl_by_reference_p (decl_or_origin
))
22814 add_type_attribute (var_die
, TREE_TYPE (type
),
22815 TYPE_UNQUALIFIED
, false, context_die
);
22817 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
),
22818 false, context_die
);
22821 goto gen_variable_die_location
;
22825 /* For static data members, the declaration in the class is supposed
22826 to have DW_TAG_member tag in DWARF{3,4} and we emit it for compatibility
22827 also in DWARF2; the specification should still be DW_TAG_variable
22828 referencing the DW_TAG_member DIE. */
22829 if (declaration
&& class_scope_p (context_die
) && dwarf_version
< 5)
22830 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
22832 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
22834 if (origin
!= NULL
)
22835 add_abstract_origin_attribute (var_die
, origin
);
22837 /* Loop unrolling can create multiple blocks that refer to the same
22838 static variable, so we must test for the DW_AT_declaration flag.
22840 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
22841 copy decls and set the DECL_ABSTRACT_P flag on them instead of
22844 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
22845 else if (decl_will_get_specification_p (old_die
, decl
, declaration
))
22847 /* This is a definition of a C++ class level static. */
22848 add_AT_specification (var_die
, old_die
);
22849 specialization_p
= true;
22850 if (DECL_NAME (decl
))
22852 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
22853 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
22855 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
22856 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
22858 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
22859 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
22861 if (debug_column_info
22863 && (get_AT_unsigned (old_die
, DW_AT_decl_column
)
22864 != (unsigned) s
.column
))
22865 add_AT_unsigned (var_die
, DW_AT_decl_column
, s
.column
);
22867 if (old_die
->die_tag
== DW_TAG_member
)
22868 add_linkage_name (var_die
, decl
);
22872 add_name_and_src_coords_attributes (var_die
, decl
, no_linkage_name
);
22874 if ((origin
== NULL
&& !specialization_p
)
22876 && !DECL_ABSTRACT_P (decl_or_origin
)
22877 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
22878 decl_function_context
22879 (decl_or_origin
))))
22881 tree type
= TREE_TYPE (decl_or_origin
);
22883 if (decl_by_reference_p (decl_or_origin
))
22884 add_type_attribute (var_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
22887 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
), false,
22891 if (origin
== NULL
&& !specialization_p
)
22893 if (TREE_PUBLIC (decl
))
22894 add_AT_flag (var_die
, DW_AT_external
, 1);
22896 if (DECL_ARTIFICIAL (decl
))
22897 add_AT_flag (var_die
, DW_AT_artificial
, 1);
22899 add_alignment_attribute (var_die
, decl
);
22901 add_accessibility_attribute (var_die
, decl
);
22905 add_AT_flag (var_die
, DW_AT_declaration
, 1);
22907 if (decl
&& (DECL_ABSTRACT_P (decl
)
22908 || !old_die
|| is_declaration_die (old_die
)))
22909 equate_decl_number_to_die (decl
, var_die
);
22911 gen_variable_die_location
:
22913 && (! DECL_ABSTRACT_P (decl_or_origin
)
22914 /* Local static vars are shared between all clones/inlines,
22915 so emit DW_AT_location on the abstract DIE if DECL_RTL is
22917 || (VAR_P (decl_or_origin
)
22918 && TREE_STATIC (decl_or_origin
)
22919 && DECL_RTL_SET_P (decl_or_origin
))))
22922 add_pubname (decl_or_origin
, var_die
);
22924 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
22928 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
22930 if ((dwarf_version
>= 4 || !dwarf_strict
)
22931 && lang_hooks
.decls
.decl_dwarf_attribute (decl_or_origin
,
22932 DW_AT_const_expr
) == 1
22933 && !get_AT (var_die
, DW_AT_const_expr
)
22934 && !specialization_p
)
22935 add_AT_flag (var_die
, DW_AT_const_expr
, 1);
22939 int inl
= lang_hooks
.decls
.decl_dwarf_attribute (decl_or_origin
,
22942 && !get_AT (var_die
, DW_AT_inline
)
22943 && !specialization_p
)
22944 add_AT_unsigned (var_die
, DW_AT_inline
, inl
);
22948 /* Generate a DIE to represent a named constant. */
22951 gen_const_die (tree decl
, dw_die_ref context_die
)
22953 dw_die_ref const_die
;
22954 tree type
= TREE_TYPE (decl
);
22956 const_die
= lookup_decl_die (decl
);
22960 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
22961 equate_decl_number_to_die (decl
, const_die
);
22962 add_name_and_src_coords_attributes (const_die
, decl
);
22963 add_type_attribute (const_die
, type
, TYPE_QUAL_CONST
, false, context_die
);
22964 if (TREE_PUBLIC (decl
))
22965 add_AT_flag (const_die
, DW_AT_external
, 1);
22966 if (DECL_ARTIFICIAL (decl
))
22967 add_AT_flag (const_die
, DW_AT_artificial
, 1);
22968 tree_add_const_value_attribute_for_decl (const_die
, decl
);
22971 /* Generate a DIE to represent a label identifier. */
22974 gen_label_die (tree decl
, dw_die_ref context_die
)
22976 tree origin
= decl_ultimate_origin (decl
);
22977 dw_die_ref lbl_die
= lookup_decl_die (decl
);
22979 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
22983 lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
22984 equate_decl_number_to_die (decl
, lbl_die
);
22986 if (origin
!= NULL
)
22987 add_abstract_origin_attribute (lbl_die
, origin
);
22989 add_name_and_src_coords_attributes (lbl_die
, decl
);
22992 if (DECL_ABSTRACT_P (decl
))
22993 equate_decl_number_to_die (decl
, lbl_die
);
22994 else if (! early_dwarf
)
22996 insn
= DECL_RTL_IF_SET (decl
);
22998 /* Deleted labels are programmer specified labels which have been
22999 eliminated because of various optimizations. We still emit them
23000 here so that it is possible to put breakpoints on them. */
23004 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
23006 /* When optimization is enabled (via -O) some parts of the compiler
23007 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
23008 represent source-level labels which were explicitly declared by
23009 the user. This really shouldn't be happening though, so catch
23010 it if it ever does happen. */
23011 gcc_assert (!as_a
<rtx_insn
*> (insn
)->deleted ());
23013 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
23014 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
23018 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
23019 && CODE_LABEL_NUMBER (insn
) != -1)
23021 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
23022 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
23027 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
23028 attributes to the DIE for a block STMT, to describe where the inlined
23029 function was called from. This is similar to add_src_coords_attributes. */
23032 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
23034 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
23036 if (dwarf_version
>= 3 || !dwarf_strict
)
23038 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
23039 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
23040 if (debug_column_info
&& s
.column
)
23041 add_AT_unsigned (die
, DW_AT_call_column
, s
.column
);
23046 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
23047 Add low_pc and high_pc attributes to the DIE for a block STMT. */
23050 add_high_low_attributes (tree stmt
, dw_die_ref die
)
23052 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
23054 if (BLOCK_FRAGMENT_CHAIN (stmt
)
23055 && (dwarf_version
>= 3 || !dwarf_strict
))
23057 tree chain
, superblock
= NULL_TREE
;
23059 dw_attr_node
*attr
= NULL
;
23061 if (inlined_function_outer_scope_p (stmt
))
23063 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
23064 BLOCK_NUMBER (stmt
));
23065 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
23068 /* Optimize duplicate .debug_ranges lists or even tails of
23069 lists. If this BLOCK has same ranges as its supercontext,
23070 lookup DW_AT_ranges attribute in the supercontext (and
23071 recursively so), verify that the ranges_table contains the
23072 right values and use it instead of adding a new .debug_range. */
23073 for (chain
= stmt
, pdie
= die
;
23074 BLOCK_SAME_RANGE (chain
);
23075 chain
= BLOCK_SUPERCONTEXT (chain
))
23077 dw_attr_node
*new_attr
;
23079 pdie
= pdie
->die_parent
;
23082 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
23084 new_attr
= get_AT (pdie
, DW_AT_ranges
);
23085 if (new_attr
== NULL
23086 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
23089 superblock
= BLOCK_SUPERCONTEXT (chain
);
23092 && ((*ranges_table
)[attr
->dw_attr_val
.v
.val_offset
].num
23093 == BLOCK_NUMBER (superblock
))
23094 && BLOCK_FRAGMENT_CHAIN (superblock
))
23096 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
;
23097 unsigned long supercnt
= 0, thiscnt
= 0;
23098 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
23099 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
23102 gcc_checking_assert ((*ranges_table
)[off
+ supercnt
].num
23103 == BLOCK_NUMBER (chain
));
23105 gcc_checking_assert ((*ranges_table
)[off
+ supercnt
+ 1].num
== 0);
23106 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
23107 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
23109 gcc_assert (supercnt
>= thiscnt
);
23110 add_AT_range_list (die
, DW_AT_ranges
, off
+ supercnt
- thiscnt
,
23112 note_rnglist_head (off
+ supercnt
- thiscnt
);
23116 unsigned int offset
= add_ranges (stmt
, true);
23117 add_AT_range_list (die
, DW_AT_ranges
, offset
, false);
23118 note_rnglist_head (offset
);
23120 bool prev_in_cold
= BLOCK_IN_COLD_SECTION_P (stmt
);
23121 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
23124 add_ranges (chain
, prev_in_cold
!= BLOCK_IN_COLD_SECTION_P (chain
));
23125 prev_in_cold
= BLOCK_IN_COLD_SECTION_P (chain
);
23126 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
23133 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
23134 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
23135 BLOCK_NUMBER (stmt
));
23136 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
23137 BLOCK_NUMBER (stmt
));
23138 add_AT_low_high_pc (die
, label
, label_high
, false);
23142 /* Generate a DIE for a lexical block. */
23145 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
)
23147 dw_die_ref old_die
= BLOCK_DIE (stmt
);
23148 dw_die_ref stmt_die
= NULL
;
23151 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
23152 BLOCK_DIE (stmt
) = stmt_die
;
23155 if (BLOCK_ABSTRACT (stmt
))
23159 /* This must have been generated early and it won't even
23160 need location information since it's a DW_AT_inline
23163 for (dw_die_ref c
= context_die
; c
; c
= c
->die_parent
)
23164 if (c
->die_tag
== DW_TAG_inlined_subroutine
23165 || c
->die_tag
== DW_TAG_subprogram
)
23167 gcc_assert (get_AT (c
, DW_AT_inline
));
23173 else if (BLOCK_ABSTRACT_ORIGIN (stmt
))
23175 /* If this is an inlined instance, create a new lexical die for
23176 anything below to attach DW_AT_abstract_origin to. */
23179 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
23180 BLOCK_DIE (stmt
) = stmt_die
;
23184 tree origin
= block_ultimate_origin (stmt
);
23185 if (origin
!= NULL_TREE
&& origin
!= stmt
)
23186 add_abstract_origin_attribute (stmt_die
, origin
);
23190 stmt_die
= old_die
;
23192 /* A non abstract block whose blocks have already been reordered
23193 should have the instruction range for this block. If so, set the
23194 high/low attributes. */
23195 if (!early_dwarf
&& !BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
23197 gcc_assert (stmt_die
);
23198 add_high_low_attributes (stmt
, stmt_die
);
23201 decls_for_scope (stmt
, stmt_die
);
23204 /* Generate a DIE for an inlined subprogram. */
23207 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
)
23211 /* The instance of function that is effectively being inlined shall not
23213 gcc_assert (! BLOCK_ABSTRACT (stmt
));
23215 decl
= block_ultimate_origin (stmt
);
23217 /* Make sure any inlined functions are known to be inlineable. */
23218 gcc_checking_assert (DECL_ABSTRACT_P (decl
)
23219 || cgraph_function_possibly_inlined_p (decl
));
23221 if (! BLOCK_ABSTRACT (stmt
))
23223 dw_die_ref subr_die
23224 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
23226 if (call_arg_locations
)
23227 BLOCK_DIE (stmt
) = subr_die
;
23228 add_abstract_origin_attribute (subr_die
, decl
);
23229 if (TREE_ASM_WRITTEN (stmt
))
23230 add_high_low_attributes (stmt
, subr_die
);
23231 add_call_src_coords_attributes (stmt
, subr_die
);
23233 decls_for_scope (stmt
, subr_die
);
23237 /* Generate a DIE for a field in a record, or structure. CTX is required: see
23238 the comment for VLR_CONTEXT. */
23241 gen_field_die (tree decl
, struct vlr_context
*ctx
, dw_die_ref context_die
)
23243 dw_die_ref decl_die
;
23245 if (TREE_TYPE (decl
) == error_mark_node
)
23248 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
23249 add_name_and_src_coords_attributes (decl_die
, decl
);
23250 add_type_attribute (decl_die
, member_declared_type (decl
), decl_quals (decl
),
23251 TYPE_REVERSE_STORAGE_ORDER (DECL_FIELD_CONTEXT (decl
)),
23254 if (DECL_BIT_FIELD_TYPE (decl
))
23256 add_byte_size_attribute (decl_die
, decl
);
23257 add_bit_size_attribute (decl_die
, decl
);
23258 add_bit_offset_attribute (decl_die
, decl
, ctx
);
23261 add_alignment_attribute (decl_die
, decl
);
23263 /* If we have a variant part offset, then we are supposed to process a member
23264 of a QUAL_UNION_TYPE, which is how we represent variant parts in
23266 gcc_assert (ctx
->variant_part_offset
== NULL_TREE
23267 || TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != QUAL_UNION_TYPE
);
23268 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
23269 add_data_member_location_attribute (decl_die
, decl
, ctx
);
23271 if (DECL_ARTIFICIAL (decl
))
23272 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
23274 add_accessibility_attribute (decl_die
, decl
);
23276 /* Equate decl number to die, so that we can look up this decl later on. */
23277 equate_decl_number_to_die (decl
, decl_die
);
23280 /* Generate a DIE for a pointer to a member type. TYPE can be an
23281 OFFSET_TYPE, for a pointer to data member, or a RECORD_TYPE, for a
23282 pointer to member function. */
23285 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
23287 if (lookup_type_die (type
))
23290 dw_die_ref ptr_die
= new_die (DW_TAG_ptr_to_member_type
,
23291 scope_die_for (type
, context_die
), type
);
23293 equate_type_number_to_die (type
, ptr_die
);
23294 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
23295 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
23296 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
23298 add_alignment_attribute (ptr_die
, type
);
23300 if (TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
23301 && TREE_CODE (TREE_TYPE (type
)) != METHOD_TYPE
)
23303 dw_loc_descr_ref op
= new_loc_descr (DW_OP_plus
, 0, 0);
23304 add_AT_loc (ptr_die
, DW_AT_use_location
, op
);
23308 static char *producer_string
;
23310 /* Return a heap allocated producer string including command line options
23311 if -grecord-gcc-switches. */
23314 gen_producer_string (void)
23317 auto_vec
<const char *> switches
;
23318 const char *language_string
= lang_hooks
.name
;
23319 char *producer
, *tail
;
23321 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
23322 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
23324 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
23325 switch (save_decoded_options
[j
].opt_index
)
23332 case OPT_auxbase_strip
:
23341 case OPT_SPECIAL_unknown
:
23342 case OPT_SPECIAL_ignore
:
23343 case OPT_SPECIAL_program_name
:
23344 case OPT_SPECIAL_input_file
:
23345 case OPT_grecord_gcc_switches
:
23346 case OPT_gno_record_gcc_switches
:
23347 case OPT__output_pch_
:
23348 case OPT_fdiagnostics_show_location_
:
23349 case OPT_fdiagnostics_show_option
:
23350 case OPT_fdiagnostics_show_caret
:
23351 case OPT_fdiagnostics_color_
:
23352 case OPT_fverbose_asm
:
23354 case OPT__sysroot_
:
23356 case OPT_nostdinc__
:
23357 case OPT_fpreprocessed
:
23358 case OPT_fltrans_output_list_
:
23359 case OPT_fresolution_
:
23360 case OPT_fdebug_prefix_map_
:
23361 /* Ignore these. */
23364 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
23365 & CL_NO_DWARF_RECORD
)
23367 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
23369 switch (save_decoded_options
[j
].canonical_option
[0][1])
23376 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
23383 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
23384 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
23388 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
23390 sprintf (tail
, "%s %s", language_string
, version_string
);
23393 FOR_EACH_VEC_ELT (switches
, j
, p
)
23397 memcpy (tail
+ 1, p
, len
);
23405 /* Given a C and/or C++ language/version string return the "highest".
23406 C++ is assumed to be "higher" than C in this case. Used for merging
23407 LTO translation unit languages. */
23408 static const char *
23409 highest_c_language (const char *lang1
, const char *lang2
)
23411 if (strcmp ("GNU C++14", lang1
) == 0 || strcmp ("GNU C++14", lang2
) == 0)
23412 return "GNU C++14";
23413 if (strcmp ("GNU C++11", lang1
) == 0 || strcmp ("GNU C++11", lang2
) == 0)
23414 return "GNU C++11";
23415 if (strcmp ("GNU C++98", lang1
) == 0 || strcmp ("GNU C++98", lang2
) == 0)
23416 return "GNU C++98";
23418 if (strcmp ("GNU C11", lang1
) == 0 || strcmp ("GNU C11", lang2
) == 0)
23420 if (strcmp ("GNU C99", lang1
) == 0 || strcmp ("GNU C99", lang2
) == 0)
23422 if (strcmp ("GNU C89", lang1
) == 0 || strcmp ("GNU C89", lang2
) == 0)
23425 gcc_unreachable ();
23429 /* Generate the DIE for the compilation unit. */
23432 gen_compile_unit_die (const char *filename
)
23435 const char *language_string
= lang_hooks
.name
;
23438 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
23442 add_name_attribute (die
, filename
);
23443 /* Don't add cwd for <built-in>. */
23444 if (filename
[0] != '<')
23445 add_comp_dir_attribute (die
);
23448 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
23450 /* If our producer is LTO try to figure out a common language to use
23451 from the global list of translation units. */
23452 if (strcmp (language_string
, "GNU GIMPLE") == 0)
23456 const char *common_lang
= NULL
;
23458 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
23460 if (!TRANSLATION_UNIT_LANGUAGE (t
))
23463 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
23464 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
23466 else if (strncmp (common_lang
, "GNU C", 5) == 0
23467 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
23468 /* Mixing C and C++ is ok, use C++ in that case. */
23469 common_lang
= highest_c_language (common_lang
,
23470 TRANSLATION_UNIT_LANGUAGE (t
));
23473 /* Fall back to C. */
23474 common_lang
= NULL
;
23480 language_string
= common_lang
;
23483 language
= DW_LANG_C
;
23484 if (strncmp (language_string
, "GNU C", 5) == 0
23485 && ISDIGIT (language_string
[5]))
23487 language
= DW_LANG_C89
;
23488 if (dwarf_version
>= 3 || !dwarf_strict
)
23490 if (strcmp (language_string
, "GNU C89") != 0)
23491 language
= DW_LANG_C99
;
23493 if (dwarf_version
>= 5 /* || !dwarf_strict */)
23494 if (strcmp (language_string
, "GNU C11") == 0)
23495 language
= DW_LANG_C11
;
23498 else if (strncmp (language_string
, "GNU C++", 7) == 0)
23500 language
= DW_LANG_C_plus_plus
;
23501 if (dwarf_version
>= 5 /* || !dwarf_strict */)
23503 if (strcmp (language_string
, "GNU C++11") == 0)
23504 language
= DW_LANG_C_plus_plus_11
;
23505 else if (strcmp (language_string
, "GNU C++14") == 0)
23506 language
= DW_LANG_C_plus_plus_14
;
23509 else if (strcmp (language_string
, "GNU F77") == 0)
23510 language
= DW_LANG_Fortran77
;
23511 else if (dwarf_version
>= 3 || !dwarf_strict
)
23513 if (strcmp (language_string
, "GNU Ada") == 0)
23514 language
= DW_LANG_Ada95
;
23515 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
23517 language
= DW_LANG_Fortran95
;
23518 if (dwarf_version
>= 5 /* || !dwarf_strict */)
23520 if (strcmp (language_string
, "GNU Fortran2003") == 0)
23521 language
= DW_LANG_Fortran03
;
23522 else if (strcmp (language_string
, "GNU Fortran2008") == 0)
23523 language
= DW_LANG_Fortran08
;
23526 else if (strcmp (language_string
, "GNU Objective-C") == 0)
23527 language
= DW_LANG_ObjC
;
23528 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
23529 language
= DW_LANG_ObjC_plus_plus
;
23530 else if (dwarf_version
>= 5 || !dwarf_strict
)
23532 if (strcmp (language_string
, "GNU Go") == 0)
23533 language
= DW_LANG_Go
;
23536 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
23537 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
23538 language
= DW_LANG_Fortran90
;
23540 add_AT_unsigned (die
, DW_AT_language
, language
);
23544 case DW_LANG_Fortran77
:
23545 case DW_LANG_Fortran90
:
23546 case DW_LANG_Fortran95
:
23547 case DW_LANG_Fortran03
:
23548 case DW_LANG_Fortran08
:
23549 /* Fortran has case insensitive identifiers and the front-end
23550 lowercases everything. */
23551 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
23554 /* The default DW_ID_case_sensitive doesn't need to be specified. */
23560 /* Generate the DIE for a base class. */
23563 gen_inheritance_die (tree binfo
, tree access
, tree type
,
23564 dw_die_ref context_die
)
23566 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
23567 struct vlr_context ctx
= { type
, NULL
};
23569 add_type_attribute (die
, BINFO_TYPE (binfo
), TYPE_UNQUALIFIED
, false,
23571 add_data_member_location_attribute (die
, binfo
, &ctx
);
23573 if (BINFO_VIRTUAL_P (binfo
))
23574 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
23576 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
23577 children, otherwise the default is DW_ACCESS_public. In DWARF2
23578 the default has always been DW_ACCESS_private. */
23579 if (access
== access_public_node
)
23581 if (dwarf_version
== 2
23582 || context_die
->die_tag
== DW_TAG_class_type
)
23583 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
23585 else if (access
== access_protected_node
)
23586 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
23587 else if (dwarf_version
> 2
23588 && context_die
->die_tag
!= DW_TAG_class_type
)
23589 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
23592 /* Return whether DECL is a FIELD_DECL that represents the variant part of a
23595 is_variant_part (tree decl
)
23597 return (TREE_CODE (decl
) == FIELD_DECL
23598 && TREE_CODE (TREE_TYPE (decl
)) == QUAL_UNION_TYPE
);
23601 /* Check that OPERAND is a reference to a field in STRUCT_TYPE. If it is,
23602 return the FIELD_DECL. Return NULL_TREE otherwise. */
23605 analyze_discr_in_predicate (tree operand
, tree struct_type
)
23607 bool continue_stripping
= true;
23608 while (continue_stripping
)
23609 switch (TREE_CODE (operand
))
23612 operand
= TREE_OPERAND (operand
, 0);
23615 continue_stripping
= false;
23619 /* Match field access to members of struct_type only. */
23620 if (TREE_CODE (operand
) == COMPONENT_REF
23621 && TREE_CODE (TREE_OPERAND (operand
, 0)) == PLACEHOLDER_EXPR
23622 && TREE_TYPE (TREE_OPERAND (operand
, 0)) == struct_type
23623 && TREE_CODE (TREE_OPERAND (operand
, 1)) == FIELD_DECL
)
23624 return TREE_OPERAND (operand
, 1);
23629 /* Check that SRC is a constant integer that can be represented as a native
23630 integer constant (either signed or unsigned). If so, store it into DEST and
23631 return true. Return false otherwise. */
23634 get_discr_value (tree src
, dw_discr_value
*dest
)
23636 tree discr_type
= TREE_TYPE (src
);
23638 if (lang_hooks
.types
.get_debug_type
)
23640 tree debug_type
= lang_hooks
.types
.get_debug_type (discr_type
);
23641 if (debug_type
!= NULL
)
23642 discr_type
= debug_type
;
23645 if (TREE_CODE (src
) != INTEGER_CST
|| !INTEGRAL_TYPE_P (discr_type
))
23648 /* Signedness can vary between the original type and the debug type. This
23649 can happen for character types in Ada for instance: the character type
23650 used for code generation can be signed, to be compatible with the C one,
23651 but from a debugger point of view, it must be unsigned. */
23652 bool is_orig_unsigned
= TYPE_UNSIGNED (TREE_TYPE (src
));
23653 bool is_debug_unsigned
= TYPE_UNSIGNED (discr_type
);
23655 if (is_orig_unsigned
!= is_debug_unsigned
)
23656 src
= fold_convert (discr_type
, src
);
23658 if (!(is_debug_unsigned
? tree_fits_uhwi_p (src
) : tree_fits_shwi_p (src
)))
23661 dest
->pos
= is_debug_unsigned
;
23662 if (is_debug_unsigned
)
23663 dest
->v
.uval
= tree_to_uhwi (src
);
23665 dest
->v
.sval
= tree_to_shwi (src
);
23670 /* Try to extract synthetic properties out of VARIANT_PART_DECL, which is a
23671 FIELD_DECL in STRUCT_TYPE that represents a variant part. If unsuccessful,
23672 store NULL_TREE in DISCR_DECL. Otherwise:
23674 - store the discriminant field in STRUCT_TYPE that controls the variant
23675 part to *DISCR_DECL
23677 - put in *DISCR_LISTS_P an array where for each variant, the item
23678 represents the corresponding matching list of discriminant values.
23680 - put in *DISCR_LISTS_LENGTH the number of variants, which is the size of
23683 Note that when the array is allocated (i.e. when the analysis is
23684 successful), it is up to the caller to free the array. */
23687 analyze_variants_discr (tree variant_part_decl
,
23690 dw_discr_list_ref
**discr_lists_p
,
23691 unsigned *discr_lists_length
)
23693 tree variant_part_type
= TREE_TYPE (variant_part_decl
);
23695 dw_discr_list_ref
*discr_lists
;
23698 /* Compute how many variants there are in this variant part. */
23699 *discr_lists_length
= 0;
23700 for (variant
= TYPE_FIELDS (variant_part_type
);
23701 variant
!= NULL_TREE
;
23702 variant
= DECL_CHAIN (variant
))
23703 ++*discr_lists_length
;
23705 *discr_decl
= NULL_TREE
;
23707 = (dw_discr_list_ref
*) xcalloc (*discr_lists_length
,
23708 sizeof (**discr_lists_p
));
23709 discr_lists
= *discr_lists_p
;
23711 /* And then analyze all variants to extract discriminant information for all
23712 of them. This analysis is conservative: as soon as we detect something we
23713 do not support, abort everything and pretend we found nothing. */
23714 for (variant
= TYPE_FIELDS (variant_part_type
), i
= 0;
23715 variant
!= NULL_TREE
;
23716 variant
= DECL_CHAIN (variant
), ++i
)
23718 tree match_expr
= DECL_QUALIFIER (variant
);
23720 /* Now, try to analyze the predicate and deduce a discriminant for
23722 if (match_expr
== boolean_true_node
)
23723 /* Typically happens for the default variant: it matches all cases that
23724 previous variants rejected. Don't output any matching value for
23728 /* The following loop tries to iterate over each discriminant
23729 possibility: single values or ranges. */
23730 while (match_expr
!= NULL_TREE
)
23732 tree next_round_match_expr
;
23733 tree candidate_discr
= NULL_TREE
;
23734 dw_discr_list_ref new_node
= NULL
;
23736 /* Possibilities are matched one after the other by nested
23737 TRUTH_ORIF_EXPR expressions. Process the current possibility and
23738 continue with the rest at next iteration. */
23739 if (TREE_CODE (match_expr
) == TRUTH_ORIF_EXPR
)
23741 next_round_match_expr
= TREE_OPERAND (match_expr
, 0);
23742 match_expr
= TREE_OPERAND (match_expr
, 1);
23745 next_round_match_expr
= NULL_TREE
;
23747 if (match_expr
== boolean_false_node
)
23748 /* This sub-expression matches nothing: just wait for the next
23752 else if (TREE_CODE (match_expr
) == EQ_EXPR
)
23754 /* We are matching: <discr_field> == <integer_cst>
23755 This sub-expression matches a single value. */
23756 tree integer_cst
= TREE_OPERAND (match_expr
, 1);
23759 = analyze_discr_in_predicate (TREE_OPERAND (match_expr
, 0),
23762 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
23763 if (!get_discr_value (integer_cst
,
23764 &new_node
->dw_discr_lower_bound
))
23766 new_node
->dw_discr_range
= false;
23769 else if (TREE_CODE (match_expr
) == TRUTH_ANDIF_EXPR
)
23771 /* We are matching:
23772 <discr_field> > <integer_cst>
23773 && <discr_field> < <integer_cst>.
23774 This sub-expression matches the range of values between the
23775 two matched integer constants. Note that comparisons can be
23776 inclusive or exclusive. */
23777 tree candidate_discr_1
, candidate_discr_2
;
23778 tree lower_cst
, upper_cst
;
23779 bool lower_cst_included
, upper_cst_included
;
23780 tree lower_op
= TREE_OPERAND (match_expr
, 0);
23781 tree upper_op
= TREE_OPERAND (match_expr
, 1);
23783 /* When the comparison is exclusive, the integer constant is not
23784 the discriminant range bound we are looking for: we will have
23785 to increment or decrement it. */
23786 if (TREE_CODE (lower_op
) == GE_EXPR
)
23787 lower_cst_included
= true;
23788 else if (TREE_CODE (lower_op
) == GT_EXPR
)
23789 lower_cst_included
= false;
23793 if (TREE_CODE (upper_op
) == LE_EXPR
)
23794 upper_cst_included
= true;
23795 else if (TREE_CODE (upper_op
) == LT_EXPR
)
23796 upper_cst_included
= false;
23800 /* Extract the discriminant from the first operand and check it
23801 is consistant with the same analysis in the second
23804 = analyze_discr_in_predicate (TREE_OPERAND (lower_op
, 0),
23807 = analyze_discr_in_predicate (TREE_OPERAND (upper_op
, 0),
23809 if (candidate_discr_1
== candidate_discr_2
)
23810 candidate_discr
= candidate_discr_1
;
23814 /* Extract bounds from both. */
23815 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
23816 lower_cst
= TREE_OPERAND (lower_op
, 1);
23817 upper_cst
= TREE_OPERAND (upper_op
, 1);
23819 if (!lower_cst_included
)
23821 = fold_build2 (PLUS_EXPR
, TREE_TYPE (lower_cst
), lower_cst
,
23822 build_int_cst (TREE_TYPE (lower_cst
), 1));
23823 if (!upper_cst_included
)
23825 = fold_build2 (MINUS_EXPR
, TREE_TYPE (upper_cst
), upper_cst
,
23826 build_int_cst (TREE_TYPE (upper_cst
), 1));
23828 if (!get_discr_value (lower_cst
,
23829 &new_node
->dw_discr_lower_bound
)
23830 || !get_discr_value (upper_cst
,
23831 &new_node
->dw_discr_upper_bound
))
23834 new_node
->dw_discr_range
= true;
23838 /* Unsupported sub-expression: we cannot determine the set of
23839 matching discriminant values. Abort everything. */
23842 /* If the discriminant info is not consistant with what we saw so
23843 far, consider the analysis failed and abort everything. */
23844 if (candidate_discr
== NULL_TREE
23845 || (*discr_decl
!= NULL_TREE
&& candidate_discr
!= *discr_decl
))
23848 *discr_decl
= candidate_discr
;
23850 if (new_node
!= NULL
)
23852 new_node
->dw_discr_next
= discr_lists
[i
];
23853 discr_lists
[i
] = new_node
;
23855 match_expr
= next_round_match_expr
;
23859 /* If we reach this point, we could match everything we were interested
23864 /* Clean all data structure and return no result. */
23865 free (*discr_lists_p
);
23866 *discr_lists_p
= NULL
;
23867 *discr_decl
= NULL_TREE
;
23870 /* Generate a DIE to represent VARIANT_PART_DECL, a variant part that is part
23871 of STRUCT_TYPE, a record type. This new DIE is emitted as the next child
23874 Variant parts are supposed to be implemented as a FIELD_DECL whose type is a
23875 QUAL_UNION_TYPE: this is the VARIANT_PART_DECL parameter. The members for
23876 this type, which are record types, represent the available variants and each
23877 has a DECL_QUALIFIER attribute. The discriminant and the discriminant
23878 values are inferred from these attributes.
23880 In trees, the offsets for the fields inside these sub-records are relative
23881 to the variant part itself, whereas the corresponding DIEs should have
23882 offset attributes that are relative to the embedding record base address.
23883 This is why the caller must provide a VARIANT_PART_OFFSET expression: it
23884 must be an expression that computes the offset of the variant part to
23885 describe in DWARF. */
23888 gen_variant_part (tree variant_part_decl
, struct vlr_context
*vlr_ctx
,
23889 dw_die_ref context_die
)
23891 const tree variant_part_type
= TREE_TYPE (variant_part_decl
);
23892 tree variant_part_offset
= vlr_ctx
->variant_part_offset
;
23893 struct loc_descr_context ctx
= {
23894 vlr_ctx
->struct_type
, /* context_type */
23895 NULL_TREE
, /* base_decl */
23897 false, /* placeholder_arg */
23898 false /* placeholder_seen */
23901 /* The FIELD_DECL node in STRUCT_TYPE that acts as the discriminant, or
23902 NULL_TREE if there is no such field. */
23903 tree discr_decl
= NULL_TREE
;
23904 dw_discr_list_ref
*discr_lists
;
23905 unsigned discr_lists_length
= 0;
23908 dw_die_ref dwarf_proc_die
= NULL
;
23909 dw_die_ref variant_part_die
23910 = new_die (DW_TAG_variant_part
, context_die
, variant_part_type
);
23912 equate_decl_number_to_die (variant_part_decl
, variant_part_die
);
23914 analyze_variants_discr (variant_part_decl
, vlr_ctx
->struct_type
,
23915 &discr_decl
, &discr_lists
, &discr_lists_length
);
23917 if (discr_decl
!= NULL_TREE
)
23919 dw_die_ref discr_die
= lookup_decl_die (discr_decl
);
23922 add_AT_die_ref (variant_part_die
, DW_AT_discr
, discr_die
);
23924 /* We have no DIE for the discriminant, so just discard all
23925 discrimimant information in the output. */
23926 discr_decl
= NULL_TREE
;
23929 /* If the offset for this variant part is more complex than a constant,
23930 create a DWARF procedure for it so that we will not have to generate DWARF
23931 expressions for it for each member. */
23932 if (TREE_CODE (variant_part_offset
) != INTEGER_CST
23933 && (dwarf_version
>= 3 || !dwarf_strict
))
23935 const tree dwarf_proc_fndecl
23936 = build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, NULL_TREE
,
23937 build_function_type (TREE_TYPE (variant_part_offset
),
23939 const tree dwarf_proc_call
= build_call_expr (dwarf_proc_fndecl
, 0);
23940 const dw_loc_descr_ref dwarf_proc_body
23941 = loc_descriptor_from_tree (variant_part_offset
, 0, &ctx
);
23943 dwarf_proc_die
= new_dwarf_proc_die (dwarf_proc_body
,
23944 dwarf_proc_fndecl
, context_die
);
23945 if (dwarf_proc_die
!= NULL
)
23946 variant_part_offset
= dwarf_proc_call
;
23949 /* Output DIEs for all variants. */
23951 for (tree variant
= TYPE_FIELDS (variant_part_type
);
23952 variant
!= NULL_TREE
;
23953 variant
= DECL_CHAIN (variant
), ++i
)
23955 tree variant_type
= TREE_TYPE (variant
);
23956 dw_die_ref variant_die
;
23958 /* All variants (i.e. members of a variant part) are supposed to be
23959 encoded as structures. Sub-variant parts are QUAL_UNION_TYPE fields
23960 under these records. */
23961 gcc_assert (TREE_CODE (variant_type
) == RECORD_TYPE
);
23963 variant_die
= new_die (DW_TAG_variant
, variant_part_die
, variant_type
);
23964 equate_decl_number_to_die (variant
, variant_die
);
23966 /* Output discriminant values this variant matches, if any. */
23967 if (discr_decl
== NULL
|| discr_lists
[i
] == NULL
)
23968 /* In the case we have discriminant information at all, this is
23969 probably the default variant: as the standard says, don't
23970 output any discriminant value/list attribute. */
23972 else if (discr_lists
[i
]->dw_discr_next
== NULL
23973 && !discr_lists
[i
]->dw_discr_range
)
23974 /* If there is only one accepted value, don't bother outputting a
23976 add_discr_value (variant_die
, &discr_lists
[i
]->dw_discr_lower_bound
);
23978 add_discr_list (variant_die
, discr_lists
[i
]);
23980 for (tree member
= TYPE_FIELDS (variant_type
);
23981 member
!= NULL_TREE
;
23982 member
= DECL_CHAIN (member
))
23984 struct vlr_context vlr_sub_ctx
= {
23985 vlr_ctx
->struct_type
, /* struct_type */
23986 NULL
/* variant_part_offset */
23988 if (is_variant_part (member
))
23990 /* All offsets for fields inside variant parts are relative to
23991 the top-level embedding RECORD_TYPE's base address. On the
23992 other hand, offsets in GCC's types are relative to the
23993 nested-most variant part. So we have to sum offsets each time
23996 vlr_sub_ctx
.variant_part_offset
23997 = fold_build2 (PLUS_EXPR
, TREE_TYPE (variant_part_offset
),
23998 variant_part_offset
, byte_position (member
));
23999 gen_variant_part (member
, &vlr_sub_ctx
, variant_die
);
24003 vlr_sub_ctx
.variant_part_offset
= variant_part_offset
;
24004 gen_decl_die (member
, NULL
, &vlr_sub_ctx
, variant_die
);
24009 free (discr_lists
);
24012 /* Generate a DIE for a class member. */
24015 gen_member_die (tree type
, dw_die_ref context_die
)
24018 tree binfo
= TYPE_BINFO (type
);
24020 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
24022 /* If this is not an incomplete type, output descriptions of each of its
24023 members. Note that as we output the DIEs necessary to represent the
24024 members of this record or union type, we will also be trying to output
24025 DIEs to represent the *types* of those members. However the `type'
24026 function (above) will specifically avoid generating type DIEs for member
24027 types *within* the list of member DIEs for this (containing) type except
24028 for those types (of members) which are explicitly marked as also being
24029 members of this (containing) type themselves. The g++ front- end can
24030 force any given type to be treated as a member of some other (containing)
24031 type by setting the TYPE_CONTEXT of the given (member) type to point to
24032 the TREE node representing the appropriate (containing) type. */
24034 /* First output info about the base classes. */
24037 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
24041 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
24042 gen_inheritance_die (base
,
24043 (accesses
? (*accesses
)[i
] : access_public_node
),
24048 /* Now output info about the data members and type members. */
24049 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
24051 struct vlr_context vlr_ctx
= { type
, NULL_TREE
};
24052 bool static_inline_p
24053 = (TREE_STATIC (member
)
24054 && (lang_hooks
.decls
.decl_dwarf_attribute (member
, DW_AT_inline
)
24057 /* Ignore clones. */
24058 if (DECL_ABSTRACT_ORIGIN (member
))
24061 /* If we thought we were generating minimal debug info for TYPE
24062 and then changed our minds, some of the member declarations
24063 may have already been defined. Don't define them again, but
24064 do put them in the right order. */
24066 if (dw_die_ref child
= lookup_decl_die (member
))
24068 /* Handle inline static data members, which only have in-class
24070 dw_die_ref ref
= NULL
;
24071 if (child
->die_tag
== DW_TAG_variable
24072 && child
->die_parent
== comp_unit_die ())
24074 ref
= get_AT_ref (child
, DW_AT_specification
);
24075 /* For C++17 inline static data members followed by redundant
24076 out of class redeclaration, we might get here with
24077 child being the DIE created for the out of class
24078 redeclaration and with its DW_AT_specification being
24079 the DIE created for in-class definition. We want to
24080 reparent the latter, and don't want to create another
24081 DIE with DW_AT_specification in that case, because
24082 we already have one. */
24085 && ref
->die_tag
== DW_TAG_variable
24086 && ref
->die_parent
== comp_unit_die ()
24087 && get_AT (ref
, DW_AT_specification
) == NULL
)
24091 static_inline_p
= false;
24095 if (child
->die_tag
== DW_TAG_variable
24096 && child
->die_parent
== comp_unit_die ()
24099 reparent_child (child
, context_die
);
24100 if (dwarf_version
< 5)
24101 child
->die_tag
= DW_TAG_member
;
24104 splice_child_die (context_die
, child
);
24107 /* Do not generate standard DWARF for variant parts if we are generating
24108 the corresponding GNAT encodings: DIEs generated for both would
24109 conflict in our mappings. */
24110 else if (is_variant_part (member
)
24111 && gnat_encodings
== DWARF_GNAT_ENCODINGS_MINIMAL
)
24113 vlr_ctx
.variant_part_offset
= byte_position (member
);
24114 gen_variant_part (member
, &vlr_ctx
, context_die
);
24118 vlr_ctx
.variant_part_offset
= NULL_TREE
;
24119 gen_decl_die (member
, NULL
, &vlr_ctx
, context_die
);
24122 /* For C++ inline static data members emit immediately a DW_TAG_variable
24123 DIE that will refer to that DW_TAG_member/DW_TAG_variable through
24124 DW_AT_specification. */
24125 if (static_inline_p
)
24127 int old_extern
= DECL_EXTERNAL (member
);
24128 DECL_EXTERNAL (member
) = 0;
24129 gen_decl_die (member
, NULL
, NULL
, comp_unit_die ());
24130 DECL_EXTERNAL (member
) = old_extern
;
24135 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
24136 is set, we pretend that the type was never defined, so we only get the
24137 member DIEs needed by later specification DIEs. */
24140 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
24141 enum debug_info_usage usage
)
24143 if (TREE_ASM_WRITTEN (type
))
24145 /* Fill in the bound of variable-length fields in late dwarf if
24146 still incomplete. */
24147 if (!early_dwarf
&& variably_modified_type_p (type
, NULL
))
24148 for (tree member
= TYPE_FIELDS (type
);
24150 member
= DECL_CHAIN (member
))
24151 fill_variable_array_bounds (TREE_TYPE (member
));
24155 dw_die_ref type_die
= lookup_type_die (type
);
24156 dw_die_ref scope_die
= 0;
24158 int complete
= (TYPE_SIZE (type
)
24159 && (! TYPE_STUB_DECL (type
)
24160 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
24161 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
24162 complete
= complete
&& should_emit_struct_debug (type
, usage
);
24164 if (type_die
&& ! complete
)
24167 if (TYPE_CONTEXT (type
) != NULL_TREE
24168 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
24169 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
24172 scope_die
= scope_die_for (type
, context_die
);
24174 /* Generate child dies for template paramaters. */
24175 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
24176 schedule_generic_params_dies_gen (type
);
24178 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
24179 /* First occurrence of type or toplevel definition of nested class. */
24181 dw_die_ref old_die
= type_die
;
24183 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
24184 ? record_type_tag (type
) : DW_TAG_union_type
,
24186 equate_type_number_to_die (type
, type_die
);
24188 add_AT_specification (type_die
, old_die
);
24190 add_name_attribute (type_die
, type_tag (type
));
24193 remove_AT (type_die
, DW_AT_declaration
);
24195 /* If this type has been completed, then give it a byte_size attribute and
24196 then give a list of members. */
24197 if (complete
&& !ns_decl
)
24199 /* Prevent infinite recursion in cases where the type of some member of
24200 this type is expressed in terms of this type itself. */
24201 TREE_ASM_WRITTEN (type
) = 1;
24202 add_byte_size_attribute (type_die
, type
);
24203 add_alignment_attribute (type_die
, type
);
24204 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
24206 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
24207 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
24210 /* If the first reference to this type was as the return type of an
24211 inline function, then it may not have a parent. Fix this now. */
24212 if (type_die
->die_parent
== NULL
)
24213 add_child_die (scope_die
, type_die
);
24215 push_decl_scope (type
);
24216 gen_member_die (type
, type_die
);
24219 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
24220 if (TYPE_ARTIFICIAL (type
))
24221 add_AT_flag (type_die
, DW_AT_artificial
, 1);
24223 /* GNU extension: Record what type our vtable lives in. */
24224 if (TYPE_VFIELD (type
))
24226 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
24228 gen_type_die (vtype
, context_die
);
24229 add_AT_die_ref (type_die
, DW_AT_containing_type
,
24230 lookup_type_die (vtype
));
24235 add_AT_flag (type_die
, DW_AT_declaration
, 1);
24237 /* We don't need to do this for function-local types. */
24238 if (TYPE_STUB_DECL (type
)
24239 && ! decl_function_context (TYPE_STUB_DECL (type
)))
24240 vec_safe_push (incomplete_types
, type
);
24243 if (get_AT (type_die
, DW_AT_name
))
24244 add_pubtype (type
, type_die
);
24247 /* Generate a DIE for a subroutine _type_. */
24250 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
24252 tree return_type
= TREE_TYPE (type
);
24253 dw_die_ref subr_die
24254 = new_die (DW_TAG_subroutine_type
,
24255 scope_die_for (type
, context_die
), type
);
24257 equate_type_number_to_die (type
, subr_die
);
24258 add_prototyped_attribute (subr_die
, type
);
24259 add_type_attribute (subr_die
, return_type
, TYPE_UNQUALIFIED
, false,
24261 add_alignment_attribute (subr_die
, type
);
24262 gen_formal_types_die (type
, subr_die
);
24264 if (get_AT (subr_die
, DW_AT_name
))
24265 add_pubtype (type
, subr_die
);
24266 if ((dwarf_version
>= 5 || !dwarf_strict
)
24267 && lang_hooks
.types
.type_dwarf_attribute (type
, DW_AT_reference
) != -1)
24268 add_AT_flag (subr_die
, DW_AT_reference
, 1);
24269 if ((dwarf_version
>= 5 || !dwarf_strict
)
24270 && lang_hooks
.types
.type_dwarf_attribute (type
,
24271 DW_AT_rvalue_reference
) != -1)
24272 add_AT_flag (subr_die
, DW_AT_rvalue_reference
, 1);
24275 /* Generate a DIE for a type definition. */
24278 gen_typedef_die (tree decl
, dw_die_ref context_die
)
24280 dw_die_ref type_die
;
24283 if (TREE_ASM_WRITTEN (decl
))
24285 if (DECL_ORIGINAL_TYPE (decl
))
24286 fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl
));
24290 /* As we avoid creating DIEs for local typedefs (see decl_ultimate_origin
24291 checks in process_scope_var and modified_type_die), this should be called
24292 only for original types. */
24293 gcc_assert (decl_ultimate_origin (decl
) == NULL
24294 || decl_ultimate_origin (decl
) == decl
);
24296 TREE_ASM_WRITTEN (decl
) = 1;
24297 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
24299 add_name_and_src_coords_attributes (type_die
, decl
);
24300 if (DECL_ORIGINAL_TYPE (decl
))
24302 type
= DECL_ORIGINAL_TYPE (decl
);
24303 if (type
== error_mark_node
)
24306 gcc_assert (type
!= TREE_TYPE (decl
));
24307 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
24311 type
= TREE_TYPE (decl
);
24312 if (type
== error_mark_node
)
24315 if (is_naming_typedef_decl (TYPE_NAME (type
)))
24317 /* Here, we are in the case of decl being a typedef naming
24318 an anonymous type, e.g:
24319 typedef struct {...} foo;
24320 In that case TREE_TYPE (decl) is not a typedef variant
24321 type and TYPE_NAME of the anonymous type is set to the
24322 TYPE_DECL of the typedef. This construct is emitted by
24325 TYPE is the anonymous struct named by the typedef
24326 DECL. As we need the DW_AT_type attribute of the
24327 DW_TAG_typedef to point to the DIE of TYPE, let's
24328 generate that DIE right away. add_type_attribute
24329 called below will then pick (via lookup_type_die) that
24330 anonymous struct DIE. */
24331 if (!TREE_ASM_WRITTEN (type
))
24332 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
24334 /* This is a GNU Extension. We are adding a
24335 DW_AT_linkage_name attribute to the DIE of the
24336 anonymous struct TYPE. The value of that attribute
24337 is the name of the typedef decl naming the anonymous
24338 struct. This greatly eases the work of consumers of
24339 this debug info. */
24340 add_linkage_name_raw (lookup_type_die (type
), decl
);
24344 add_type_attribute (type_die
, type
, decl_quals (decl
), false,
24347 if (is_naming_typedef_decl (decl
))
24348 /* We want that all subsequent calls to lookup_type_die with
24349 TYPE in argument yield the DW_TAG_typedef we have just
24351 equate_type_number_to_die (type
, type_die
);
24353 add_alignment_attribute (type_die
, TREE_TYPE (decl
));
24355 add_accessibility_attribute (type_die
, decl
);
24357 if (DECL_ABSTRACT_P (decl
))
24358 equate_decl_number_to_die (decl
, type_die
);
24360 if (get_AT (type_die
, DW_AT_name
))
24361 add_pubtype (decl
, type_die
);
24364 /* Generate a DIE for a struct, class, enum or union type. */
24367 gen_tagged_type_die (tree type
,
24368 dw_die_ref context_die
,
24369 enum debug_info_usage usage
)
24373 if (type
== NULL_TREE
24374 || !is_tagged_type (type
))
24377 if (TREE_ASM_WRITTEN (type
))
24379 /* If this is a nested type whose containing class hasn't been written
24380 out yet, writing it out will cover this one, too. This does not apply
24381 to instantiations of member class templates; they need to be added to
24382 the containing class as they are generated. FIXME: This hurts the
24383 idea of combining type decls from multiple TUs, since we can't predict
24384 what set of template instantiations we'll get. */
24385 else if (TYPE_CONTEXT (type
)
24386 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
24387 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
24389 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
24391 if (TREE_ASM_WRITTEN (type
))
24394 /* If that failed, attach ourselves to the stub. */
24395 push_decl_scope (TYPE_CONTEXT (type
));
24396 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
24399 else if (TYPE_CONTEXT (type
) != NULL_TREE
24400 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
24402 /* If this type is local to a function that hasn't been written
24403 out yet, use a NULL context for now; it will be fixed up in
24404 decls_for_scope. */
24405 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
24406 /* A declaration DIE doesn't count; nested types need to go in the
24408 if (context_die
&& is_declaration_die (context_die
))
24409 context_die
= NULL
;
24414 context_die
= declare_in_namespace (type
, context_die
);
24418 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
24420 /* This might have been written out by the call to
24421 declare_in_namespace. */
24422 if (!TREE_ASM_WRITTEN (type
))
24423 gen_enumeration_type_die (type
, context_die
);
24426 gen_struct_or_union_type_die (type
, context_die
, usage
);
24431 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
24432 it up if it is ever completed. gen_*_type_die will set it for us
24433 when appropriate. */
24436 /* Generate a type description DIE. */
24439 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
24440 enum debug_info_usage usage
)
24442 struct array_descr_info info
;
24444 if (type
== NULL_TREE
|| type
== error_mark_node
)
24447 if (flag_checking
&& type
)
24448 verify_type (type
);
24450 if (TYPE_NAME (type
) != NULL_TREE
24451 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
24452 && is_redundant_typedef (TYPE_NAME (type
))
24453 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
24454 /* The DECL of this type is a typedef we don't want to emit debug
24455 info for but we want debug info for its underlying typedef.
24456 This can happen for e.g, the injected-class-name of a C++
24458 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
24460 /* If TYPE is a typedef type variant, let's generate debug info
24461 for the parent typedef which TYPE is a type of. */
24462 if (typedef_variant_p (type
))
24464 if (TREE_ASM_WRITTEN (type
))
24467 tree name
= TYPE_NAME (type
);
24468 tree origin
= decl_ultimate_origin (name
);
24469 if (origin
!= NULL
&& origin
!= name
)
24471 gen_decl_die (origin
, NULL
, NULL
, context_die
);
24475 /* Prevent broken recursion; we can't hand off to the same type. */
24476 gcc_assert (DECL_ORIGINAL_TYPE (name
) != type
);
24478 /* Give typedefs the right scope. */
24479 context_die
= scope_die_for (type
, context_die
);
24481 TREE_ASM_WRITTEN (type
) = 1;
24483 gen_decl_die (name
, NULL
, NULL
, context_die
);
24487 /* If type is an anonymous tagged type named by a typedef, let's
24488 generate debug info for the typedef. */
24489 if (is_naming_typedef_decl (TYPE_NAME (type
)))
24491 /* Use the DIE of the containing namespace as the parent DIE of
24492 the type description DIE we want to generate. */
24493 if (DECL_CONTEXT (TYPE_NAME (type
))
24494 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
24495 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
24497 gen_decl_die (TYPE_NAME (type
), NULL
, NULL
, context_die
);
24501 if (lang_hooks
.types
.get_debug_type
)
24503 tree debug_type
= lang_hooks
.types
.get_debug_type (type
);
24505 if (debug_type
!= NULL_TREE
&& debug_type
!= type
)
24507 gen_type_die_with_usage (debug_type
, context_die
, usage
);
24512 /* We are going to output a DIE to represent the unqualified version
24513 of this type (i.e. without any const or volatile qualifiers) so
24514 get the main variant (i.e. the unqualified version) of this type
24515 now. (Vectors and arrays are special because the debugging info is in the
24516 cloned type itself. Similarly function/method types can contain extra
24517 ref-qualification). */
24518 if (TREE_CODE (type
) == FUNCTION_TYPE
24519 || TREE_CODE (type
) == METHOD_TYPE
)
24521 /* For function/method types, can't use type_main_variant here,
24522 because that can have different ref-qualifiers for C++,
24523 but try to canonicalize. */
24524 tree main
= TYPE_MAIN_VARIANT (type
);
24525 for (tree t
= main
; t
; t
= TYPE_NEXT_VARIANT (t
))
24526 if (TYPE_QUALS_NO_ADDR_SPACE (t
) == 0
24527 && check_base_type (t
, main
)
24528 && check_lang_type (t
, type
))
24534 else if (TREE_CODE (type
) != VECTOR_TYPE
24535 && TREE_CODE (type
) != ARRAY_TYPE
)
24536 type
= type_main_variant (type
);
24538 /* If this is an array type with hidden descriptor, handle it first. */
24539 if (!TREE_ASM_WRITTEN (type
)
24540 && lang_hooks
.types
.get_array_descr_info
)
24542 memset (&info
, 0, sizeof (info
));
24543 if (lang_hooks
.types
.get_array_descr_info (type
, &info
))
24545 /* Fortran sometimes emits array types with no dimension. */
24546 gcc_assert (info
.ndimensions
>= 0
24547 && (info
.ndimensions
24548 <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN
));
24549 gen_descr_array_type_die (type
, &info
, context_die
);
24550 TREE_ASM_WRITTEN (type
) = 1;
24555 if (TREE_ASM_WRITTEN (type
))
24557 /* Variable-length types may be incomplete even if
24558 TREE_ASM_WRITTEN. For such types, fall through to
24559 gen_array_type_die() and possibly fill in
24560 DW_AT_{upper,lower}_bound attributes. */
24561 if ((TREE_CODE (type
) != ARRAY_TYPE
24562 && TREE_CODE (type
) != RECORD_TYPE
24563 && TREE_CODE (type
) != UNION_TYPE
24564 && TREE_CODE (type
) != QUAL_UNION_TYPE
)
24565 || !variably_modified_type_p (type
, NULL
))
24569 switch (TREE_CODE (type
))
24575 case REFERENCE_TYPE
:
24576 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
24577 ensures that the gen_type_die recursion will terminate even if the
24578 type is recursive. Recursive types are possible in Ada. */
24579 /* ??? We could perhaps do this for all types before the switch
24581 TREE_ASM_WRITTEN (type
) = 1;
24583 /* For these types, all that is required is that we output a DIE (or a
24584 set of DIEs) to represent the "basis" type. */
24585 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24586 DINFO_USAGE_IND_USE
);
24590 /* This code is used for C++ pointer-to-data-member types.
24591 Output a description of the relevant class type. */
24592 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
24593 DINFO_USAGE_IND_USE
);
24595 /* Output a description of the type of the object pointed to. */
24596 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24597 DINFO_USAGE_IND_USE
);
24599 /* Now output a DIE to represent this pointer-to-data-member type
24601 gen_ptr_to_mbr_type_die (type
, context_die
);
24604 case FUNCTION_TYPE
:
24605 /* Force out return type (in case it wasn't forced out already). */
24606 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24607 DINFO_USAGE_DIR_USE
);
24608 gen_subroutine_type_die (type
, context_die
);
24612 /* Force out return type (in case it wasn't forced out already). */
24613 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24614 DINFO_USAGE_DIR_USE
);
24615 gen_subroutine_type_die (type
, context_die
);
24620 gen_array_type_die (type
, context_die
);
24623 case ENUMERAL_TYPE
:
24626 case QUAL_UNION_TYPE
:
24627 gen_tagged_type_die (type
, context_die
, usage
);
24633 case FIXED_POINT_TYPE
:
24636 case POINTER_BOUNDS_TYPE
:
24637 /* No DIEs needed for fundamental types. */
24642 /* Just use DW_TAG_unspecified_type. */
24644 dw_die_ref type_die
= lookup_type_die (type
);
24645 if (type_die
== NULL
)
24647 tree name
= TYPE_IDENTIFIER (type
);
24648 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (),
24650 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
24651 equate_type_number_to_die (type
, type_die
);
24657 if (is_cxx_auto (type
))
24659 tree name
= TYPE_IDENTIFIER (type
);
24660 dw_die_ref
*die
= (name
== get_identifier ("auto")
24661 ? &auto_die
: &decltype_auto_die
);
24664 *die
= new_die (DW_TAG_unspecified_type
,
24665 comp_unit_die (), NULL_TREE
);
24666 add_name_attribute (*die
, IDENTIFIER_POINTER (name
));
24668 equate_type_number_to_die (type
, *die
);
24671 gcc_unreachable ();
24674 TREE_ASM_WRITTEN (type
) = 1;
24678 gen_type_die (tree type
, dw_die_ref context_die
)
24680 if (type
!= error_mark_node
)
24682 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
24685 dw_die_ref die
= lookup_type_die (type
);
24692 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
24693 things which are local to the given block. */
24696 gen_block_die (tree stmt
, dw_die_ref context_die
)
24698 int must_output_die
= 0;
24701 /* Ignore blocks that are NULL. */
24702 if (stmt
== NULL_TREE
)
24705 inlined_func
= inlined_function_outer_scope_p (stmt
);
24707 /* If the block is one fragment of a non-contiguous block, do not
24708 process the variables, since they will have been done by the
24709 origin block. Do process subblocks. */
24710 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
24714 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
24715 gen_block_die (sub
, context_die
);
24720 /* Determine if we need to output any Dwarf DIEs at all to represent this
24723 /* The outer scopes for inlinings *must* always be represented. We
24724 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
24725 must_output_die
= 1;
24728 /* Determine if this block directly contains any "significant"
24729 local declarations which we will need to output DIEs for. */
24730 if (debug_info_level
> DINFO_LEVEL_TERSE
)
24731 /* We are not in terse mode so *any* local declaration counts
24732 as being a "significant" one. */
24733 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
24734 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
24735 && (TREE_USED (stmt
)
24736 || TREE_ASM_WRITTEN (stmt
)
24737 || BLOCK_ABSTRACT (stmt
)));
24738 else if ((TREE_USED (stmt
)
24739 || TREE_ASM_WRITTEN (stmt
)
24740 || BLOCK_ABSTRACT (stmt
))
24741 && !dwarf2out_ignore_block (stmt
))
24742 must_output_die
= 1;
24745 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
24746 DIE for any block which contains no significant local declarations at
24747 all. Rather, in such cases we just call `decls_for_scope' so that any
24748 needed Dwarf info for any sub-blocks will get properly generated. Note
24749 that in terse mode, our definition of what constitutes a "significant"
24750 local declaration gets restricted to include only inlined function
24751 instances and local (nested) function definitions. */
24752 if (must_output_die
)
24756 /* If STMT block is abstract, that means we have been called
24757 indirectly from dwarf2out_abstract_function.
24758 That function rightfully marks the descendent blocks (of
24759 the abstract function it is dealing with) as being abstract,
24760 precisely to prevent us from emitting any
24761 DW_TAG_inlined_subroutine DIE as a descendent
24762 of an abstract function instance. So in that case, we should
24763 not call gen_inlined_subroutine_die.
24765 Later though, when cgraph asks dwarf2out to emit info
24766 for the concrete instance of the function decl into which
24767 the concrete instance of STMT got inlined, the later will lead
24768 to the generation of a DW_TAG_inlined_subroutine DIE. */
24769 if (! BLOCK_ABSTRACT (stmt
))
24770 gen_inlined_subroutine_die (stmt
, context_die
);
24773 gen_lexical_block_die (stmt
, context_die
);
24776 decls_for_scope (stmt
, context_die
);
24779 /* Process variable DECL (or variable with origin ORIGIN) within
24780 block STMT and add it to CONTEXT_DIE. */
24782 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
24785 tree decl_or_origin
= decl
? decl
: origin
;
24787 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
24788 die
= lookup_decl_die (decl_or_origin
);
24789 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
)
24791 if (TYPE_DECL_IS_STUB (decl_or_origin
))
24792 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
24794 die
= lookup_decl_die (decl_or_origin
);
24795 /* Avoid re-creating the DIE late if it was optimized as unused early. */
24796 if (! die
&& ! early_dwarf
)
24802 /* Avoid creating DIEs for local typedefs and concrete static variables that
24803 will only be pruned later. */
24804 if ((origin
|| decl_ultimate_origin (decl
))
24805 && (TREE_CODE (decl_or_origin
) == TYPE_DECL
24806 || (VAR_P (decl_or_origin
) && TREE_STATIC (decl_or_origin
))))
24808 origin
= decl_ultimate_origin (decl_or_origin
);
24809 if (decl
&& VAR_P (decl
) && die
!= NULL
)
24811 die
= lookup_decl_die (origin
);
24813 equate_decl_number_to_die (decl
, die
);
24818 if (die
!= NULL
&& die
->die_parent
== NULL
)
24819 add_child_die (context_die
, die
);
24820 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
24823 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
24824 stmt
, context_die
);
24828 if (decl
&& DECL_P (decl
))
24830 die
= lookup_decl_die (decl
);
24832 /* Early created DIEs do not have a parent as the decls refer
24833 to the function as DECL_CONTEXT rather than the BLOCK. */
24834 if (die
&& die
->die_parent
== NULL
)
24836 gcc_assert (in_lto_p
);
24837 add_child_die (context_die
, die
);
24841 gen_decl_die (decl
, origin
, NULL
, context_die
);
24845 /* Generate all of the decls declared within a given scope and (recursively)
24846 all of its sub-blocks. */
24849 decls_for_scope (tree stmt
, dw_die_ref context_die
)
24855 /* Ignore NULL blocks. */
24856 if (stmt
== NULL_TREE
)
24859 /* Output the DIEs to represent all of the data objects and typedefs
24860 declared directly within this block but not within any nested
24861 sub-blocks. Also, nested function and tag DIEs have been
24862 generated with a parent of NULL; fix that up now. We don't
24863 have to do this if we're at -g1. */
24864 if (debug_info_level
> DINFO_LEVEL_TERSE
)
24866 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
24867 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
24868 /* BLOCK_NONLOCALIZED_VARs simply generate DIE stubs with abstract
24869 origin - avoid doing this twice as we have no good way to see
24870 if we've done it once already. */
24872 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
24874 decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
24875 if (decl
== current_function_decl
)
24876 /* Ignore declarations of the current function, while they
24877 are declarations, gen_subprogram_die would treat them
24878 as definitions again, because they are equal to
24879 current_function_decl and endlessly recurse. */;
24880 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
24881 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
24883 process_scope_var (stmt
, NULL_TREE
, decl
, context_die
);
24887 /* Even if we're at -g1, we need to process the subblocks in order to get
24888 inlined call information. */
24890 /* Output the DIEs to represent all sub-blocks (and the items declared
24891 therein) of this block. */
24892 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
24894 subblocks
= BLOCK_CHAIN (subblocks
))
24895 gen_block_die (subblocks
, context_die
);
24898 /* Is this a typedef we can avoid emitting? */
24901 is_redundant_typedef (const_tree decl
)
24903 if (TYPE_DECL_IS_STUB (decl
))
24906 if (DECL_ARTIFICIAL (decl
)
24907 && DECL_CONTEXT (decl
)
24908 && is_tagged_type (DECL_CONTEXT (decl
))
24909 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
24910 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
24911 /* Also ignore the artificial member typedef for the class name. */
24917 /* Return TRUE if TYPE is a typedef that names a type for linkage
24918 purposes. This kind of typedefs is produced by the C++ FE for
24921 typedef struct {...} foo;
24923 In that case, there is no typedef variant type produced for foo.
24924 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
24928 is_naming_typedef_decl (const_tree decl
)
24930 if (decl
== NULL_TREE
24931 || TREE_CODE (decl
) != TYPE_DECL
24932 || DECL_NAMELESS (decl
)
24933 || !is_tagged_type (TREE_TYPE (decl
))
24934 || DECL_IS_BUILTIN (decl
)
24935 || is_redundant_typedef (decl
)
24936 /* It looks like Ada produces TYPE_DECLs that are very similar
24937 to C++ naming typedefs but that have different
24938 semantics. Let's be specific to c++ for now. */
24942 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
24943 && TYPE_NAME (TREE_TYPE (decl
)) == decl
24944 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
24945 != TYPE_NAME (TREE_TYPE (decl
))));
24948 /* Looks up the DIE for a context. */
24950 static inline dw_die_ref
24951 lookup_context_die (tree context
)
24955 /* Find die that represents this context. */
24956 if (TYPE_P (context
))
24958 context
= TYPE_MAIN_VARIANT (context
);
24959 dw_die_ref ctx
= lookup_type_die (context
);
24962 return strip_naming_typedef (context
, ctx
);
24965 return lookup_decl_die (context
);
24967 return comp_unit_die ();
24970 /* Returns the DIE for a context. */
24972 static inline dw_die_ref
24973 get_context_die (tree context
)
24977 /* Find die that represents this context. */
24978 if (TYPE_P (context
))
24980 context
= TYPE_MAIN_VARIANT (context
);
24981 return strip_naming_typedef (context
, force_type_die (context
));
24984 return force_decl_die (context
);
24986 return comp_unit_die ();
24989 /* Returns the DIE for decl. A DIE will always be returned. */
24992 force_decl_die (tree decl
)
24994 dw_die_ref decl_die
;
24995 unsigned saved_external_flag
;
24996 tree save_fn
= NULL_TREE
;
24997 decl_die
= lookup_decl_die (decl
);
25000 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
25002 decl_die
= lookup_decl_die (decl
);
25006 switch (TREE_CODE (decl
))
25008 case FUNCTION_DECL
:
25009 /* Clear current_function_decl, so that gen_subprogram_die thinks
25010 that this is a declaration. At this point, we just want to force
25011 declaration die. */
25012 save_fn
= current_function_decl
;
25013 current_function_decl
= NULL_TREE
;
25014 gen_subprogram_die (decl
, context_die
);
25015 current_function_decl
= save_fn
;
25019 /* Set external flag to force declaration die. Restore it after
25020 gen_decl_die() call. */
25021 saved_external_flag
= DECL_EXTERNAL (decl
);
25022 DECL_EXTERNAL (decl
) = 1;
25023 gen_decl_die (decl
, NULL
, NULL
, context_die
);
25024 DECL_EXTERNAL (decl
) = saved_external_flag
;
25027 case NAMESPACE_DECL
:
25028 if (dwarf_version
>= 3 || !dwarf_strict
)
25029 dwarf2out_decl (decl
);
25031 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
25032 decl_die
= comp_unit_die ();
25035 case TRANSLATION_UNIT_DECL
:
25036 decl_die
= comp_unit_die ();
25040 gcc_unreachable ();
25043 /* We should be able to find the DIE now. */
25045 decl_die
= lookup_decl_die (decl
);
25046 gcc_assert (decl_die
);
25052 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
25053 always returned. */
25056 force_type_die (tree type
)
25058 dw_die_ref type_die
;
25060 type_die
= lookup_type_die (type
);
25063 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
25065 type_die
= modified_type_die (type
, TYPE_QUALS_NO_ADDR_SPACE (type
),
25066 false, context_die
);
25067 gcc_assert (type_die
);
25072 /* Force out any required namespaces to be able to output DECL,
25073 and return the new context_die for it, if it's changed. */
25076 setup_namespace_context (tree thing
, dw_die_ref context_die
)
25078 tree context
= (DECL_P (thing
)
25079 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
25080 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
25081 /* Force out the namespace. */
25082 context_die
= force_decl_die (context
);
25084 return context_die
;
25087 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
25088 type) within its namespace, if appropriate.
25090 For compatibility with older debuggers, namespace DIEs only contain
25091 declarations; all definitions are emitted at CU scope, with
25092 DW_AT_specification pointing to the declaration (like with class
25096 declare_in_namespace (tree thing
, dw_die_ref context_die
)
25098 dw_die_ref ns_context
;
25100 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25101 return context_die
;
25103 /* External declarations in the local scope only need to be emitted
25104 once, not once in the namespace and once in the scope.
25106 This avoids declaring the `extern' below in the
25107 namespace DIE as well as in the innermost scope:
25120 if (DECL_P (thing
) && DECL_EXTERNAL (thing
) && local_scope_p (context_die
))
25121 return context_die
;
25123 /* If this decl is from an inlined function, then don't try to emit it in its
25124 namespace, as we will get confused. It would have already been emitted
25125 when the abstract instance of the inline function was emitted anyways. */
25126 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
25127 return context_die
;
25129 ns_context
= setup_namespace_context (thing
, context_die
);
25131 if (ns_context
!= context_die
)
25135 if (DECL_P (thing
))
25136 gen_decl_die (thing
, NULL
, NULL
, ns_context
);
25138 gen_type_die (thing
, ns_context
);
25140 return context_die
;
25143 /* Generate a DIE for a namespace or namespace alias. */
25146 gen_namespace_die (tree decl
, dw_die_ref context_die
)
25148 dw_die_ref namespace_die
;
25150 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
25151 they are an alias of. */
25152 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
25154 /* Output a real namespace or module. */
25155 context_die
= setup_namespace_context (decl
, comp_unit_die ());
25156 namespace_die
= new_die (is_fortran ()
25157 ? DW_TAG_module
: DW_TAG_namespace
,
25158 context_die
, decl
);
25159 /* For Fortran modules defined in different CU don't add src coords. */
25160 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
25162 const char *name
= dwarf2_name (decl
, 0);
25164 add_name_attribute (namespace_die
, name
);
25167 add_name_and_src_coords_attributes (namespace_die
, decl
);
25168 if (DECL_EXTERNAL (decl
))
25169 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
25170 equate_decl_number_to_die (decl
, namespace_die
);
25174 /* Output a namespace alias. */
25176 /* Force out the namespace we are an alias of, if necessary. */
25177 dw_die_ref origin_die
25178 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
25180 if (DECL_FILE_SCOPE_P (decl
)
25181 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
25182 context_die
= setup_namespace_context (decl
, comp_unit_die ());
25183 /* Now create the namespace alias DIE. */
25184 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
25185 add_name_and_src_coords_attributes (namespace_die
, decl
);
25186 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
25187 equate_decl_number_to_die (decl
, namespace_die
);
25189 if ((dwarf_version
>= 5 || !dwarf_strict
)
25190 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
25191 DW_AT_export_symbols
) == 1)
25192 add_AT_flag (namespace_die
, DW_AT_export_symbols
, 1);
25194 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
25195 if (want_pubnames ())
25196 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
25199 /* Generate Dwarf debug information for a decl described by DECL.
25200 The return value is currently only meaningful for PARM_DECLs,
25201 for all other decls it returns NULL.
25203 If DECL is a FIELD_DECL, CTX is required: see the comment for VLR_CONTEXT.
25204 It can be NULL otherwise. */
25207 gen_decl_die (tree decl
, tree origin
, struct vlr_context
*ctx
,
25208 dw_die_ref context_die
)
25210 tree decl_or_origin
= decl
? decl
: origin
;
25211 tree class_origin
= NULL
, ultimate_origin
;
25213 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
25216 /* Ignore pointer bounds decls. */
25217 if (DECL_P (decl_or_origin
)
25218 && TREE_TYPE (decl_or_origin
)
25219 && POINTER_BOUNDS_P (decl_or_origin
))
25222 switch (TREE_CODE (decl_or_origin
))
25228 if (!is_fortran () && !is_ada ())
25230 /* The individual enumerators of an enum type get output when we output
25231 the Dwarf representation of the relevant enum type itself. */
25235 /* Emit its type. */
25236 gen_type_die (TREE_TYPE (decl
), context_die
);
25238 /* And its containing namespace. */
25239 context_die
= declare_in_namespace (decl
, context_die
);
25241 gen_const_die (decl
, context_die
);
25244 case FUNCTION_DECL
:
25247 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
25248 on local redeclarations of global functions. That seems broken. */
25249 if (current_function_decl
!= decl
)
25250 /* This is only a declaration. */;
25253 /* We should have abstract copies already and should not generate
25254 stray type DIEs in late LTO dumping. */
25258 /* If we're emitting a clone, emit info for the abstract instance. */
25259 else if (origin
|| DECL_ORIGIN (decl
) != decl
)
25260 dwarf2out_abstract_function (origin
25261 ? DECL_ORIGIN (origin
)
25262 : DECL_ABSTRACT_ORIGIN (decl
));
25264 /* If we're emitting a possibly inlined function emit it as
25265 abstract instance. */
25266 else if (cgraph_function_possibly_inlined_p (decl
)
25267 && ! DECL_ABSTRACT_P (decl
)
25268 && ! class_or_namespace_scope_p (context_die
)
25269 /* dwarf2out_abstract_function won't emit a die if this is just
25270 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
25271 that case, because that works only if we have a die. */
25272 && DECL_INITIAL (decl
) != NULL_TREE
)
25273 dwarf2out_abstract_function (decl
);
25275 /* Otherwise we're emitting the primary DIE for this decl. */
25276 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
25278 /* Before we describe the FUNCTION_DECL itself, make sure that we
25279 have its containing type. */
25281 origin
= decl_class_context (decl
);
25282 if (origin
!= NULL_TREE
)
25283 gen_type_die (origin
, context_die
);
25285 /* And its return type. */
25286 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
25288 /* And its virtual context. */
25289 if (DECL_VINDEX (decl
) != NULL_TREE
)
25290 gen_type_die (DECL_CONTEXT (decl
), context_die
);
25292 /* Make sure we have a member DIE for decl. */
25293 if (origin
!= NULL_TREE
)
25294 gen_type_die_for_member (origin
, decl
, context_die
);
25296 /* And its containing namespace. */
25297 context_die
= declare_in_namespace (decl
, context_die
);
25300 /* Now output a DIE to represent the function itself. */
25302 gen_subprogram_die (decl
, context_die
);
25306 /* If we are in terse mode, don't generate any DIEs to represent any
25307 actual typedefs. */
25308 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25311 /* In the special case of a TYPE_DECL node representing the declaration
25312 of some type tag, if the given TYPE_DECL is marked as having been
25313 instantiated from some other (original) TYPE_DECL node (e.g. one which
25314 was generated within the original definition of an inline function) we
25315 used to generate a special (abbreviated) DW_TAG_structure_type,
25316 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
25317 should be actually referencing those DIEs, as variable DIEs with that
25318 type would be emitted already in the abstract origin, so it was always
25319 removed during unused type prunning. Don't add anything in this
25321 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
25324 if (is_redundant_typedef (decl
))
25325 gen_type_die (TREE_TYPE (decl
), context_die
);
25327 /* Output a DIE to represent the typedef itself. */
25328 gen_typedef_die (decl
, context_die
);
25332 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
25333 gen_label_die (decl
, context_die
);
25338 /* If we are in terse mode, don't generate any DIEs to represent any
25339 variable declarations or definitions. */
25340 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25343 /* Avoid generating stray type DIEs during late dwarf dumping.
25344 All types have been dumped early. */
25346 /* ??? But in LTRANS we cannot annotate early created variably
25347 modified type DIEs without copying them and adjusting all
25348 references to them. Dump them again as happens for inlining
25349 which copies both the decl and the types. */
25350 /* ??? And even non-LTO needs to re-visit type DIEs to fill
25351 in VLA bound information for example. */
25352 || (decl
&& variably_modified_type_p (TREE_TYPE (decl
),
25353 current_function_decl
)))
25355 /* Output any DIEs that are needed to specify the type of this data
25357 if (decl_by_reference_p (decl_or_origin
))
25358 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
25360 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
25365 /* And its containing type. */
25366 class_origin
= decl_class_context (decl_or_origin
);
25367 if (class_origin
!= NULL_TREE
)
25368 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
25370 /* And its containing namespace. */
25371 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
25374 /* Now output the DIE to represent the data object itself. This gets
25375 complicated because of the possibility that the VAR_DECL really
25376 represents an inlined instance of a formal parameter for an inline
25378 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
25379 if (ultimate_origin
!= NULL_TREE
25380 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
25381 gen_formal_parameter_die (decl
, origin
,
25382 true /* Emit name attribute. */,
25385 gen_variable_die (decl
, origin
, context_die
);
25389 gcc_assert (ctx
!= NULL
&& ctx
->struct_type
!= NULL
);
25390 /* Ignore the nameless fields that are used to skip bits but handle C++
25391 anonymous unions and structs. */
25392 if (DECL_NAME (decl
) != NULL_TREE
25393 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
25394 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
25396 gen_type_die (member_declared_type (decl
), context_die
);
25397 gen_field_die (decl
, ctx
, context_die
);
25402 /* Avoid generating stray type DIEs during late dwarf dumping.
25403 All types have been dumped early. */
25405 /* ??? But in LTRANS we cannot annotate early created variably
25406 modified type DIEs without copying them and adjusting all
25407 references to them. Dump them again as happens for inlining
25408 which copies both the decl and the types. */
25409 /* ??? And even non-LTO needs to re-visit type DIEs to fill
25410 in VLA bound information for example. */
25411 || (decl
&& variably_modified_type_p (TREE_TYPE (decl
),
25412 current_function_decl
)))
25414 if (DECL_BY_REFERENCE (decl_or_origin
))
25415 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
25417 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
25419 return gen_formal_parameter_die (decl
, origin
,
25420 true /* Emit name attribute. */,
25423 case NAMESPACE_DECL
:
25424 if (dwarf_version
>= 3 || !dwarf_strict
)
25425 gen_namespace_die (decl
, context_die
);
25428 case IMPORTED_DECL
:
25429 dwarf2out_imported_module_or_decl_1 (decl
, DECL_NAME (decl
),
25430 DECL_CONTEXT (decl
), context_die
);
25433 case NAMELIST_DECL
:
25434 gen_namelist_decl (DECL_NAME (decl
), context_die
,
25435 NAMELIST_DECL_ASSOCIATED_DECL (decl
));
25439 /* Probably some frontend-internal decl. Assume we don't care. */
25440 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
25447 /* Output initial debug information for global DECL. Called at the
25448 end of the parsing process.
25450 This is the initial debug generation process. As such, the DIEs
25451 generated may be incomplete. A later debug generation pass
25452 (dwarf2out_late_global_decl) will augment the information generated
25453 in this pass (e.g., with complete location info). */
25456 dwarf2out_early_global_decl (tree decl
)
25460 /* gen_decl_die() will set DECL_ABSTRACT because
25461 cgraph_function_possibly_inlined_p() returns true. This is in
25462 turn will cause DW_AT_inline attributes to be set.
25464 This happens because at early dwarf generation, there is no
25465 cgraph information, causing cgraph_function_possibly_inlined_p()
25466 to return true. Trick cgraph_function_possibly_inlined_p()
25467 while we generate dwarf early. */
25468 bool save
= symtab
->global_info_ready
;
25469 symtab
->global_info_ready
= true;
25471 /* We don't handle TYPE_DECLs. If required, they'll be reached via
25472 other DECLs and they can point to template types or other things
25473 that dwarf2out can't handle when done via dwarf2out_decl. */
25474 if (TREE_CODE (decl
) != TYPE_DECL
25475 && TREE_CODE (decl
) != PARM_DECL
)
25477 tree save_fndecl
= current_function_decl
;
25478 if (TREE_CODE (decl
) == FUNCTION_DECL
)
25480 /* For nested functions, make sure we have DIEs for the parents first
25481 so that all nested DIEs are generated at the proper scope in the
25483 tree context
= decl_function_context (decl
);
25484 if (context
!= NULL
&& lookup_decl_die (context
) == NULL
)
25486 current_function_decl
= context
;
25487 dwarf2out_decl (context
);
25490 /* Emit an abstract origin of a function first. This happens
25491 with C++ constructor clones for example and makes
25492 dwarf2out_abstract_function happy which requires the early
25493 DIE of the abstract instance to be present. */
25494 if (DECL_ABSTRACT_ORIGIN (decl
))
25496 current_function_decl
= DECL_ABSTRACT_ORIGIN (decl
);
25497 dwarf2out_decl (DECL_ABSTRACT_ORIGIN (decl
));
25500 current_function_decl
= decl
;
25502 dwarf2out_decl (decl
);
25503 if (TREE_CODE (decl
) == FUNCTION_DECL
)
25504 current_function_decl
= save_fndecl
;
25506 symtab
->global_info_ready
= save
;
25509 /* Output debug information for global decl DECL. Called from
25510 toplev.c after compilation proper has finished. */
25513 dwarf2out_late_global_decl (tree decl
)
25515 /* Fill-in any location information we were unable to determine
25516 on the first pass. */
25517 if (VAR_P (decl
) && !POINTER_BOUNDS_P (decl
))
25519 dw_die_ref die
= lookup_decl_die (decl
);
25521 /* We may have to generate early debug late for LTO in case debug
25522 was not enabled at compile-time or the target doesn't support
25523 the LTO early debug scheme. */
25524 if (! die
&& in_lto_p
)
25526 dwarf2out_decl (decl
);
25527 die
= lookup_decl_die (decl
);
25532 /* We get called via the symtab code invoking late_global_decl
25533 for symbols that are optimized out. Do not add locations
25534 for those, except if they have a DECL_VALUE_EXPR, in which case
25535 they are relevant for debuggers. */
25536 varpool_node
*node
= varpool_node::get (decl
);
25537 if ((! node
|| ! node
->definition
) && ! DECL_HAS_VALUE_EXPR_P (decl
))
25538 tree_add_const_value_attribute_for_decl (die
, decl
);
25540 add_location_or_const_value_attribute (die
, decl
, false);
25545 /* Output debug information for type decl DECL. Called from toplev.c
25546 and from language front ends (to record built-in types). */
25548 dwarf2out_type_decl (tree decl
, int local
)
25553 dwarf2out_decl (decl
);
25557 /* Output debug information for imported module or decl DECL.
25558 NAME is non-NULL name in the lexical block if the decl has been renamed.
25559 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
25560 that DECL belongs to.
25561 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
25563 dwarf2out_imported_module_or_decl_1 (tree decl
,
25565 tree lexical_block
,
25566 dw_die_ref lexical_block_die
)
25568 expanded_location xloc
;
25569 dw_die_ref imported_die
= NULL
;
25570 dw_die_ref at_import_die
;
25572 if (TREE_CODE (decl
) == IMPORTED_DECL
)
25574 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
25575 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
25579 xloc
= expand_location (input_location
);
25581 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
25583 at_import_die
= force_type_die (TREE_TYPE (decl
));
25584 /* For namespace N { typedef void T; } using N::T; base_type_die
25585 returns NULL, but DW_TAG_imported_declaration requires
25586 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
25587 if (!at_import_die
)
25589 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
25590 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
25591 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
25592 gcc_assert (at_import_die
);
25597 at_import_die
= lookup_decl_die (decl
);
25598 if (!at_import_die
)
25600 /* If we're trying to avoid duplicate debug info, we may not have
25601 emitted the member decl for this field. Emit it now. */
25602 if (TREE_CODE (decl
) == FIELD_DECL
)
25604 tree type
= DECL_CONTEXT (decl
);
25606 if (TYPE_CONTEXT (type
)
25607 && TYPE_P (TYPE_CONTEXT (type
))
25608 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
25609 DINFO_USAGE_DIR_USE
))
25611 gen_type_die_for_member (type
, decl
,
25612 get_context_die (TYPE_CONTEXT (type
)));
25614 if (TREE_CODE (decl
) == NAMELIST_DECL
)
25615 at_import_die
= gen_namelist_decl (DECL_NAME (decl
),
25616 get_context_die (DECL_CONTEXT (decl
)),
25619 at_import_die
= force_decl_die (decl
);
25623 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
25625 if (dwarf_version
>= 3 || !dwarf_strict
)
25626 imported_die
= new_die (DW_TAG_imported_module
,
25633 imported_die
= new_die (DW_TAG_imported_declaration
,
25637 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
25638 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
25639 if (debug_column_info
&& xloc
.column
)
25640 add_AT_unsigned (imported_die
, DW_AT_decl_column
, xloc
.column
);
25642 add_AT_string (imported_die
, DW_AT_name
,
25643 IDENTIFIER_POINTER (name
));
25644 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
25647 /* Output debug information for imported module or decl DECL.
25648 NAME is non-NULL name in context if the decl has been renamed.
25649 CHILD is true if decl is one of the renamed decls as part of
25650 importing whole module.
25651 IMPLICIT is set if this hook is called for an implicit import
25652 such as inline namespace. */
25655 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
25656 bool child
, bool implicit
)
25658 /* dw_die_ref at_import_die; */
25659 dw_die_ref scope_die
;
25661 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25666 /* For DWARF5, just DW_AT_export_symbols on the DW_TAG_namespace
25667 should be enough, for DWARF4 and older even if we emit as extension
25668 DW_AT_export_symbols add the implicit DW_TAG_imported_module anyway
25669 for the benefit of consumers unaware of DW_AT_export_symbols. */
25671 && dwarf_version
>= 5
25672 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
25673 DW_AT_export_symbols
) == 1)
25678 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
25679 We need decl DIE for reference and scope die. First, get DIE for the decl
25682 /* Get the scope die for decl context. Use comp_unit_die for global module
25683 or decl. If die is not found for non globals, force new die. */
25685 && TYPE_P (context
)
25686 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
25689 scope_die
= get_context_die (context
);
25693 /* DW_TAG_imported_module was introduced in the DWARFv3 specification, so
25694 there is nothing we can do, here. */
25695 if (dwarf_version
< 3 && dwarf_strict
)
25698 gcc_assert (scope_die
->die_child
);
25699 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
25700 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
25701 scope_die
= scope_die
->die_child
;
25704 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
25705 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
25708 /* Output debug information for namelists. */
25711 gen_namelist_decl (tree name
, dw_die_ref scope_die
, tree item_decls
)
25713 dw_die_ref nml_die
, nml_item_die
, nml_item_ref_die
;
25717 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25720 gcc_assert (scope_die
!= NULL
);
25721 nml_die
= new_die (DW_TAG_namelist
, scope_die
, NULL
);
25722 add_AT_string (nml_die
, DW_AT_name
, IDENTIFIER_POINTER (name
));
25724 /* If there are no item_decls, we have a nondefining namelist, e.g.
25725 with USE association; hence, set DW_AT_declaration. */
25726 if (item_decls
== NULL_TREE
)
25728 add_AT_flag (nml_die
, DW_AT_declaration
, 1);
25732 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls
), i
, value
)
25734 nml_item_ref_die
= lookup_decl_die (value
);
25735 if (!nml_item_ref_die
)
25736 nml_item_ref_die
= force_decl_die (value
);
25738 nml_item_die
= new_die (DW_TAG_namelist_item
, nml_die
, NULL
);
25739 add_AT_die_ref (nml_item_die
, DW_AT_namelist_items
, nml_item_ref_die
);
25745 /* Write the debugging output for DECL and return the DIE. */
25748 dwarf2out_decl (tree decl
)
25750 dw_die_ref context_die
= comp_unit_die ();
25752 switch (TREE_CODE (decl
))
25757 case FUNCTION_DECL
:
25758 /* If we're a nested function, initially use a parent of NULL; if we're
25759 a plain function, this will be fixed up in decls_for_scope. If
25760 we're a method, it will be ignored, since we already have a DIE. */
25761 if (decl_function_context (decl
)
25762 /* But if we're in terse mode, we don't care about scope. */
25763 && debug_info_level
> DINFO_LEVEL_TERSE
)
25764 context_die
= NULL
;
25768 /* For local statics lookup proper context die. */
25769 if (local_function_static (decl
))
25770 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
25772 /* If we are in terse mode, don't generate any DIEs to represent any
25773 variable declarations or definitions. */
25774 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25779 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25781 if (!is_fortran () && !is_ada ())
25783 if (TREE_STATIC (decl
) && decl_function_context (decl
))
25784 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
25787 case NAMESPACE_DECL
:
25788 case IMPORTED_DECL
:
25789 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25791 if (lookup_decl_die (decl
) != NULL
)
25796 /* Don't emit stubs for types unless they are needed by other DIEs. */
25797 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
25800 /* Don't bother trying to generate any DIEs to represent any of the
25801 normal built-in types for the language we are compiling. */
25802 if (DECL_IS_BUILTIN (decl
))
25805 /* If we are in terse mode, don't generate any DIEs for types. */
25806 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25809 /* If we're a function-scope tag, initially use a parent of NULL;
25810 this will be fixed up in decls_for_scope. */
25811 if (decl_function_context (decl
))
25812 context_die
= NULL
;
25816 case NAMELIST_DECL
:
25823 gen_decl_die (decl
, NULL
, NULL
, context_die
);
25827 dw_die_ref die
= lookup_decl_die (decl
);
25833 /* Write the debugging output for DECL. */
25836 dwarf2out_function_decl (tree decl
)
25838 dwarf2out_decl (decl
);
25839 call_arg_locations
= NULL
;
25840 call_arg_loc_last
= NULL
;
25841 call_site_count
= -1;
25842 tail_call_site_count
= -1;
25843 decl_loc_table
->empty ();
25844 cached_dw_loc_list_table
->empty ();
25847 /* Output a marker (i.e. a label) for the beginning of the generated code for
25848 a lexical block. */
25851 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
25852 unsigned int blocknum
)
25854 switch_to_section (current_function_section ());
25855 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
25858 /* Output a marker (i.e. a label) for the end of the generated code for a
25862 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
25864 switch_to_section (current_function_section ());
25865 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
25868 /* Returns nonzero if it is appropriate not to emit any debugging
25869 information for BLOCK, because it doesn't contain any instructions.
25871 Don't allow this for blocks with nested functions or local classes
25872 as we would end up with orphans, and in the presence of scheduling
25873 we may end up calling them anyway. */
25876 dwarf2out_ignore_block (const_tree block
)
25881 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
25882 if (TREE_CODE (decl
) == FUNCTION_DECL
25883 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
25885 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
25887 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
25888 if (TREE_CODE (decl
) == FUNCTION_DECL
25889 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
25896 /* Hash table routines for file_hash. */
25899 dwarf_file_hasher::equal (dwarf_file_data
*p1
, const char *p2
)
25901 return filename_cmp (p1
->filename
, p2
) == 0;
25905 dwarf_file_hasher::hash (dwarf_file_data
*p
)
25907 return htab_hash_string (p
->filename
);
25910 /* Lookup FILE_NAME (in the list of filenames that we know about here in
25911 dwarf2out.c) and return its "index". The index of each (known) filename is
25912 just a unique number which is associated with only that one filename. We
25913 need such numbers for the sake of generating labels (in the .debug_sfnames
25914 section) and references to those files numbers (in the .debug_srcinfo
25915 and .debug_macinfo sections). If the filename given as an argument is not
25916 found in our current list, add it to the list and assign it the next
25917 available unique index number. */
25919 static struct dwarf_file_data
*
25920 lookup_filename (const char *file_name
)
25922 struct dwarf_file_data
* created
;
25927 dwarf_file_data
**slot
25928 = file_table
->find_slot_with_hash (file_name
, htab_hash_string (file_name
),
25933 created
= ggc_alloc
<dwarf_file_data
> ();
25934 created
->filename
= file_name
;
25935 created
->emitted_number
= 0;
25940 /* If the assembler will construct the file table, then translate the compiler
25941 internal file table number into the assembler file table number, and emit
25942 a .file directive if we haven't already emitted one yet. The file table
25943 numbers are different because we prune debug info for unused variables and
25944 types, which may include filenames. */
25947 maybe_emit_file (struct dwarf_file_data
* fd
)
25949 if (! fd
->emitted_number
)
25951 if (last_emitted_file
)
25952 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
25954 fd
->emitted_number
= 1;
25955 last_emitted_file
= fd
;
25957 if (DWARF2_ASM_LINE_DEBUG_INFO
)
25959 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
25960 output_quoted_string (asm_out_file
,
25961 remap_debug_filename (fd
->filename
));
25962 fputc ('\n', asm_out_file
);
25966 return fd
->emitted_number
;
25969 /* Schedule generation of a DW_AT_const_value attribute to DIE.
25970 That generation should happen after function debug info has been
25971 generated. The value of the attribute is the constant value of ARG. */
25974 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
25976 die_arg_entry entry
;
25981 gcc_assert (early_dwarf
);
25983 if (!tmpl_value_parm_die_table
)
25984 vec_alloc (tmpl_value_parm_die_table
, 32);
25988 vec_safe_push (tmpl_value_parm_die_table
, entry
);
25991 /* Return TRUE if T is an instance of generic type, FALSE
25995 generic_type_p (tree t
)
25997 if (t
== NULL_TREE
|| !TYPE_P (t
))
25999 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
26002 /* Schedule the generation of the generic parameter dies for the
26003 instance of generic type T. The proper generation itself is later
26004 done by gen_scheduled_generic_parms_dies. */
26007 schedule_generic_params_dies_gen (tree t
)
26009 if (!generic_type_p (t
))
26012 gcc_assert (early_dwarf
);
26014 if (!generic_type_instances
)
26015 vec_alloc (generic_type_instances
, 256);
26017 vec_safe_push (generic_type_instances
, t
);
26020 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
26021 by append_entry_to_tmpl_value_parm_die_table. This function must
26022 be called after function DIEs have been generated. */
26025 gen_remaining_tmpl_value_param_die_attribute (void)
26027 if (tmpl_value_parm_die_table
)
26032 /* We do this in two phases - first get the cases we can
26033 handle during early-finish, preserving those we cannot
26034 (containing symbolic constants where we don't yet know
26035 whether we are going to output the referenced symbols).
26036 For those we try again at late-finish. */
26038 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
26040 if (!tree_add_const_value_attribute (e
->die
, e
->arg
))
26042 dw_loc_descr_ref loc
= NULL
;
26044 && (dwarf_version
>= 5 || !dwarf_strict
))
26045 loc
= loc_descriptor_from_tree (e
->arg
, 2, NULL
);
26047 add_AT_loc (e
->die
, DW_AT_location
, loc
);
26049 (*tmpl_value_parm_die_table
)[j
++] = *e
;
26052 tmpl_value_parm_die_table
->truncate (j
);
26056 /* Generate generic parameters DIEs for instances of generic types
26057 that have been previously scheduled by
26058 schedule_generic_params_dies_gen. This function must be called
26059 after all the types of the CU have been laid out. */
26062 gen_scheduled_generic_parms_dies (void)
26067 if (!generic_type_instances
)
26070 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
26071 if (COMPLETE_TYPE_P (t
))
26072 gen_generic_params_dies (t
);
26074 generic_type_instances
= NULL
;
26078 /* Replace DW_AT_name for the decl with name. */
26081 dwarf2out_set_name (tree decl
, tree name
)
26084 dw_attr_node
*attr
;
26087 die
= TYPE_SYMTAB_DIE (decl
);
26091 dname
= dwarf2_name (name
, 0);
26095 attr
= get_AT (die
, DW_AT_name
);
26098 struct indirect_string_node
*node
;
26100 node
= find_AT_string (dname
);
26101 /* replace the string. */
26102 attr
->dw_attr_val
.v
.val_str
= node
;
26106 add_name_attribute (die
, dname
);
26109 /* True if before or during processing of the first function being emitted. */
26110 static bool in_first_function_p
= true;
26111 /* True if loc_note during dwarf2out_var_location call might still be
26112 before first real instruction at address equal to .Ltext0. */
26113 static bool maybe_at_text_label_p
= true;
26114 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
26115 static unsigned int first_loclabel_num_not_at_text_label
;
26117 /* Called by the final INSN scan whenever we see a var location. We
26118 use it to drop labels in the right places, and throw the location in
26119 our lookup table. */
26122 dwarf2out_var_location (rtx_insn
*loc_note
)
26124 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
26125 struct var_loc_node
*newloc
;
26126 rtx_insn
*next_real
, *next_note
;
26127 rtx_insn
*call_insn
= NULL
;
26128 static const char *last_label
;
26129 static const char *last_postcall_label
;
26130 static bool last_in_cold_section_p
;
26131 static rtx_insn
*expected_next_loc_note
;
26135 if (!NOTE_P (loc_note
))
26137 if (CALL_P (loc_note
))
26140 if (SIBLING_CALL_P (loc_note
))
26141 tail_call_site_count
++;
26142 if (optimize
== 0 && !flag_var_tracking
)
26144 /* When the var-tracking pass is not running, there is no note
26145 for indirect calls whose target is compile-time known. In this
26146 case, process such calls specifically so that we generate call
26147 sites for them anyway. */
26148 rtx x
= PATTERN (loc_note
);
26149 if (GET_CODE (x
) == PARALLEL
)
26150 x
= XVECEXP (x
, 0, 0);
26151 if (GET_CODE (x
) == SET
)
26153 if (GET_CODE (x
) == CALL
)
26156 || GET_CODE (XEXP (x
, 0)) != SYMBOL_REF
26157 || !SYMBOL_REF_DECL (XEXP (x
, 0))
26158 || (TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0)))
26161 call_insn
= loc_note
;
26165 next_real
= next_real_insn (call_insn
);
26167 cached_next_real_insn
= NULL
;
26175 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
26176 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
26179 /* Optimize processing a large consecutive sequence of location
26180 notes so we don't spend too much time in next_real_insn. If the
26181 next insn is another location note, remember the next_real_insn
26182 calculation for next time. */
26183 next_real
= cached_next_real_insn
;
26186 if (expected_next_loc_note
!= loc_note
)
26190 next_note
= NEXT_INSN (loc_note
);
26192 || next_note
->deleted ()
26193 || ! NOTE_P (next_note
)
26194 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
26195 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
26199 next_real
= next_real_insn (loc_note
);
26203 expected_next_loc_note
= next_note
;
26204 cached_next_real_insn
= next_real
;
26207 cached_next_real_insn
= NULL
;
26209 /* If there are no instructions which would be affected by this note,
26210 don't do anything. */
26212 && next_real
== NULL_RTX
26213 && !NOTE_DURING_CALL_P (loc_note
))
26218 if (next_real
== NULL_RTX
)
26219 next_real
= get_last_insn ();
26221 /* If there were any real insns between note we processed last time
26222 and this note (or if it is the first note), clear
26223 last_{,postcall_}label so that they are not reused this time. */
26224 if (last_var_location_insn
== NULL_RTX
26225 || last_var_location_insn
!= next_real
26226 || last_in_cold_section_p
!= in_cold_section_p
)
26229 last_postcall_label
= NULL
;
26234 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
26235 newloc
= add_var_loc_to_decl (decl
, loc_note
,
26236 NOTE_DURING_CALL_P (loc_note
)
26237 ? last_postcall_label
: last_label
);
26238 if (newloc
== NULL
)
26247 /* If there were no real insns between note we processed last time
26248 and this note, use the label we emitted last time. Otherwise
26249 create a new label and emit it. */
26250 if (last_label
== NULL
)
26252 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
26253 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
26255 last_label
= ggc_strdup (loclabel
);
26256 /* See if loclabel might be equal to .Ltext0. If yes,
26257 bump first_loclabel_num_not_at_text_label. */
26258 if (!have_multiple_function_sections
26259 && in_first_function_p
26260 && maybe_at_text_label_p
)
26262 static rtx_insn
*last_start
;
26264 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
26265 if (insn
== last_start
)
26267 else if (!NONDEBUG_INSN_P (insn
))
26271 rtx body
= PATTERN (insn
);
26272 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
26274 /* Inline asm could occupy zero bytes. */
26275 else if (GET_CODE (body
) == ASM_INPUT
26276 || asm_noperands (body
) >= 0)
26278 #ifdef HAVE_attr_length
26279 else if (get_attr_min_length (insn
) == 0)
26284 /* Assume insn has non-zero length. */
26285 maybe_at_text_label_p
= false;
26289 if (maybe_at_text_label_p
)
26291 last_start
= loc_note
;
26292 first_loclabel_num_not_at_text_label
= loclabel_num
;
26297 gcc_assert ((loc_note
== NULL_RTX
&& call_insn
!= NULL_RTX
)
26298 || (loc_note
!= NULL_RTX
&& call_insn
== NULL_RTX
));
26302 struct call_arg_loc_node
*ca_loc
26303 = ggc_cleared_alloc
<call_arg_loc_node
> ();
26305 = loc_note
!= NULL_RTX
? prev_real_insn (loc_note
) : call_insn
;
26307 ca_loc
->call_arg_loc_note
= loc_note
;
26308 ca_loc
->next
= NULL
;
26309 ca_loc
->label
= last_label
;
26312 || (NONJUMP_INSN_P (prev
)
26313 && GET_CODE (PATTERN (prev
)) == SEQUENCE
26314 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
26315 if (!CALL_P (prev
))
26316 prev
= as_a
<rtx_sequence
*> (PATTERN (prev
))->insn (0);
26317 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
26319 /* Look for a SYMBOL_REF in the "prev" instruction. */
26320 rtx x
= get_call_rtx_from (PATTERN (prev
));
26323 /* Try to get the call symbol, if any. */
26324 if (MEM_P (XEXP (x
, 0)))
26326 /* First, look for a memory access to a symbol_ref. */
26327 if (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
26328 && SYMBOL_REF_DECL (XEXP (x
, 0))
26329 && TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0))) == FUNCTION_DECL
)
26330 ca_loc
->symbol_ref
= XEXP (x
, 0);
26331 /* Otherwise, look at a compile-time known user-level function
26335 && TREE_CODE (MEM_EXPR (x
)) == FUNCTION_DECL
)
26336 ca_loc
->symbol_ref
= XEXP (DECL_RTL (MEM_EXPR (x
)), 0);
26339 ca_loc
->block
= insn_scope (prev
);
26340 if (call_arg_locations
)
26341 call_arg_loc_last
->next
= ca_loc
;
26343 call_arg_locations
= ca_loc
;
26344 call_arg_loc_last
= ca_loc
;
26346 else if (loc_note
!= NULL_RTX
&& !NOTE_DURING_CALL_P (loc_note
))
26347 newloc
->label
= last_label
;
26350 if (!last_postcall_label
)
26352 sprintf (loclabel
, "%s-1", last_label
);
26353 last_postcall_label
= ggc_strdup (loclabel
);
26355 newloc
->label
= last_postcall_label
;
26358 last_var_location_insn
= next_real
;
26359 last_in_cold_section_p
= in_cold_section_p
;
26362 /* Called from finalize_size_functions for size functions so that their body
26363 can be encoded in the debug info to describe the layout of variable-length
26367 dwarf2out_size_function (tree decl
)
26369 function_to_dwarf_procedure (decl
);
26372 /* Note in one location list that text section has changed. */
26375 var_location_switch_text_section_1 (var_loc_list
**slot
, void *)
26377 var_loc_list
*list
= *slot
;
26379 list
->last_before_switch
26380 = list
->last
->next
? list
->last
->next
: list
->last
;
26384 /* Note in all location lists that text section has changed. */
26387 var_location_switch_text_section (void)
26389 if (decl_loc_table
== NULL
)
26392 decl_loc_table
->traverse
<void *, var_location_switch_text_section_1
> (NULL
);
26395 /* Create a new line number table. */
26397 static dw_line_info_table
*
26398 new_line_info_table (void)
26400 dw_line_info_table
*table
;
26402 table
= ggc_cleared_alloc
<dw_line_info_table
> ();
26403 table
->file_num
= 1;
26404 table
->line_num
= 1;
26405 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
26410 /* Lookup the "current" table into which we emit line info, so
26411 that we don't have to do it for every source line. */
26414 set_cur_line_info_table (section
*sec
)
26416 dw_line_info_table
*table
;
26418 if (sec
== text_section
)
26419 table
= text_section_line_info
;
26420 else if (sec
== cold_text_section
)
26422 table
= cold_text_section_line_info
;
26425 cold_text_section_line_info
= table
= new_line_info_table ();
26426 table
->end_label
= cold_end_label
;
26431 const char *end_label
;
26433 if (crtl
->has_bb_partition
)
26435 if (in_cold_section_p
)
26436 end_label
= crtl
->subsections
.cold_section_end_label
;
26438 end_label
= crtl
->subsections
.hot_section_end_label
;
26442 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
26443 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
26444 current_function_funcdef_no
);
26445 end_label
= ggc_strdup (label
);
26448 table
= new_line_info_table ();
26449 table
->end_label
= end_label
;
26451 vec_safe_push (separate_line_info
, table
);
26454 if (DWARF2_ASM_LINE_DEBUG_INFO
)
26455 table
->is_stmt
= (cur_line_info_table
26456 ? cur_line_info_table
->is_stmt
26457 : DWARF_LINE_DEFAULT_IS_STMT_START
);
26458 cur_line_info_table
= table
;
26462 /* We need to reset the locations at the beginning of each
26463 function. We can't do this in the end_function hook, because the
26464 declarations that use the locations won't have been output when
26465 that hook is called. Also compute have_multiple_function_sections here. */
26468 dwarf2out_begin_function (tree fun
)
26470 section
*sec
= function_section (fun
);
26472 if (sec
!= text_section
)
26473 have_multiple_function_sections
= true;
26475 if (crtl
->has_bb_partition
&& !cold_text_section
)
26477 gcc_assert (current_function_decl
== fun
);
26478 cold_text_section
= unlikely_text_section ();
26479 switch_to_section (cold_text_section
);
26480 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
26481 switch_to_section (sec
);
26484 dwarf2out_note_section_used ();
26485 call_site_count
= 0;
26486 tail_call_site_count
= 0;
26488 set_cur_line_info_table (sec
);
26491 /* Helper function of dwarf2out_end_function, called only after emitting
26492 the very first function into assembly. Check if some .debug_loc range
26493 might end with a .LVL* label that could be equal to .Ltext0.
26494 In that case we must force using absolute addresses in .debug_loc ranges,
26495 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
26496 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
26498 Set have_multiple_function_sections to true in that case and
26499 terminate htab traversal. */
26502 find_empty_loc_ranges_at_text_label (var_loc_list
**slot
, int)
26504 var_loc_list
*entry
= *slot
;
26505 struct var_loc_node
*node
;
26507 node
= entry
->first
;
26508 if (node
&& node
->next
&& node
->next
->label
)
26511 const char *label
= node
->next
->label
;
26512 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
26514 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
26516 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
26517 if (strcmp (label
, loclabel
) == 0)
26519 have_multiple_function_sections
= true;
26527 /* Hook called after emitting a function into assembly.
26528 This does something only for the very first function emitted. */
26531 dwarf2out_end_function (unsigned int)
26533 if (in_first_function_p
26534 && !have_multiple_function_sections
26535 && first_loclabel_num_not_at_text_label
26537 decl_loc_table
->traverse
<int, find_empty_loc_ranges_at_text_label
> (0);
26538 in_first_function_p
= false;
26539 maybe_at_text_label_p
= false;
26542 /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
26543 front-ends register a translation unit even before dwarf2out_init is
26545 static tree main_translation_unit
= NULL_TREE
;
26547 /* Hook called by front-ends after they built their main translation unit.
26548 Associate comp_unit_die to UNIT. */
26551 dwarf2out_register_main_translation_unit (tree unit
)
26553 gcc_assert (TREE_CODE (unit
) == TRANSLATION_UNIT_DECL
26554 && main_translation_unit
== NULL_TREE
);
26555 main_translation_unit
= unit
;
26556 /* If dwarf2out_init has not been called yet, it will perform the association
26557 itself looking at main_translation_unit. */
26558 if (decl_die_table
!= NULL
)
26559 equate_decl_number_to_die (unit
, comp_unit_die ());
26562 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
26565 push_dw_line_info_entry (dw_line_info_table
*table
,
26566 enum dw_line_info_opcode opcode
, unsigned int val
)
26568 dw_line_info_entry e
;
26571 vec_safe_push (table
->entries
, e
);
26574 /* Output a label to mark the beginning of a source code line entry
26575 and record information relating to this source line, in
26576 'line_info_table' for later output of the .debug_line section. */
26577 /* ??? The discriminator parameter ought to be unsigned. */
26580 dwarf2out_source_line (unsigned int line
, unsigned int column
,
26581 const char *filename
,
26582 int discriminator
, bool is_stmt
)
26584 unsigned int file_num
;
26585 dw_line_info_table
*table
;
26587 if (debug_info_level
< DINFO_LEVEL_TERSE
|| line
== 0)
26590 /* The discriminator column was added in dwarf4. Simplify the below
26591 by simply removing it if we're not supposed to output it. */
26592 if (dwarf_version
< 4 && dwarf_strict
)
26595 if (!debug_column_info
)
26598 table
= cur_line_info_table
;
26599 file_num
= maybe_emit_file (lookup_filename (filename
));
26601 /* ??? TODO: Elide duplicate line number entries. Traditionally,
26602 the debugger has used the second (possibly duplicate) line number
26603 at the beginning of the function to mark the end of the prologue.
26604 We could eliminate any other duplicates within the function. For
26605 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
26606 that second line number entry. */
26607 /* Recall that this end-of-prologue indication is *not* the same thing
26608 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
26609 to which the hook corresponds, follows the last insn that was
26610 emitted by gen_prologue. What we need is to precede the first insn
26611 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
26612 insn that corresponds to something the user wrote. These may be
26613 very different locations once scheduling is enabled. */
26615 if (0 && file_num
== table
->file_num
26616 && line
== table
->line_num
26617 && column
== table
->column_num
26618 && discriminator
== table
->discrim_num
26619 && is_stmt
== table
->is_stmt
)
26622 switch_to_section (current_function_section ());
26624 /* If requested, emit something human-readable. */
26625 if (flag_debug_asm
)
26627 if (debug_column_info
)
26628 fprintf (asm_out_file
, "\t%s %s:%d:%d\n", ASM_COMMENT_START
,
26629 filename
, line
, column
);
26631 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
26635 if (DWARF2_ASM_LINE_DEBUG_INFO
)
26637 /* Emit the .loc directive understood by GNU as. */
26638 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
26639 file_num, line, is_stmt, discriminator */
26640 fputs ("\t.loc ", asm_out_file
);
26641 fprint_ul (asm_out_file
, file_num
);
26642 putc (' ', asm_out_file
);
26643 fprint_ul (asm_out_file
, line
);
26644 putc (' ', asm_out_file
);
26645 if (debug_column_info
)
26646 fprint_ul (asm_out_file
, column
);
26648 putc ('0', asm_out_file
);
26650 if (is_stmt
!= table
->is_stmt
)
26652 fputs (" is_stmt ", asm_out_file
);
26653 putc (is_stmt
? '1' : '0', asm_out_file
);
26655 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
26657 gcc_assert (discriminator
> 0);
26658 fputs (" discriminator ", asm_out_file
);
26659 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
26661 putc ('\n', asm_out_file
);
26665 unsigned int label_num
= ++line_info_label_num
;
26667 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
26669 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
26670 if (file_num
!= table
->file_num
)
26671 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
26672 if (discriminator
!= table
->discrim_num
)
26673 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
26674 if (is_stmt
!= table
->is_stmt
)
26675 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
26676 push_dw_line_info_entry (table
, LI_set_line
, line
);
26677 if (debug_column_info
)
26678 push_dw_line_info_entry (table
, LI_set_column
, column
);
26681 table
->file_num
= file_num
;
26682 table
->line_num
= line
;
26683 table
->column_num
= column
;
26684 table
->discrim_num
= discriminator
;
26685 table
->is_stmt
= is_stmt
;
26686 table
->in_use
= true;
26689 /* Record the beginning of a new source file. */
26692 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
26694 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26697 e
.code
= DW_MACINFO_start_file
;
26699 e
.info
= ggc_strdup (filename
);
26700 vec_safe_push (macinfo_table
, e
);
26704 /* Record the end of a source file. */
26707 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
26709 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26712 e
.code
= DW_MACINFO_end_file
;
26715 vec_safe_push (macinfo_table
, e
);
26719 /* Called from debug_define in toplev.c. The `buffer' parameter contains
26720 the tail part of the directive line, i.e. the part which is past the
26721 initial whitespace, #, whitespace, directive-name, whitespace part. */
26724 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
26725 const char *buffer ATTRIBUTE_UNUSED
)
26727 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26730 /* Insert a dummy first entry to be able to optimize the whole
26731 predefined macro block using DW_MACRO_import. */
26732 if (macinfo_table
->is_empty () && lineno
<= 1)
26737 vec_safe_push (macinfo_table
, e
);
26739 e
.code
= DW_MACINFO_define
;
26741 e
.info
= ggc_strdup (buffer
);
26742 vec_safe_push (macinfo_table
, e
);
26746 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
26747 the tail part of the directive line, i.e. the part which is past the
26748 initial whitespace, #, whitespace, directive-name, whitespace part. */
26751 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
26752 const char *buffer ATTRIBUTE_UNUSED
)
26754 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26757 /* Insert a dummy first entry to be able to optimize the whole
26758 predefined macro block using DW_MACRO_import. */
26759 if (macinfo_table
->is_empty () && lineno
<= 1)
26764 vec_safe_push (macinfo_table
, e
);
26766 e
.code
= DW_MACINFO_undef
;
26768 e
.info
= ggc_strdup (buffer
);
26769 vec_safe_push (macinfo_table
, e
);
26773 /* Helpers to manipulate hash table of CUs. */
26775 struct macinfo_entry_hasher
: nofree_ptr_hash
<macinfo_entry
>
26777 static inline hashval_t
hash (const macinfo_entry
*);
26778 static inline bool equal (const macinfo_entry
*, const macinfo_entry
*);
26782 macinfo_entry_hasher::hash (const macinfo_entry
*entry
)
26784 return htab_hash_string (entry
->info
);
26788 macinfo_entry_hasher::equal (const macinfo_entry
*entry1
,
26789 const macinfo_entry
*entry2
)
26791 return !strcmp (entry1
->info
, entry2
->info
);
26794 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
26796 /* Output a single .debug_macinfo entry. */
26799 output_macinfo_op (macinfo_entry
*ref
)
26803 struct indirect_string_node
*node
;
26804 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
26805 struct dwarf_file_data
*fd
;
26809 case DW_MACINFO_start_file
:
26810 fd
= lookup_filename (ref
->info
);
26811 file_num
= maybe_emit_file (fd
);
26812 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
26813 dw2_asm_output_data_uleb128 (ref
->lineno
,
26814 "Included from line number %lu",
26815 (unsigned long) ref
->lineno
);
26816 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
26818 case DW_MACINFO_end_file
:
26819 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
26821 case DW_MACINFO_define
:
26822 case DW_MACINFO_undef
:
26823 len
= strlen (ref
->info
) + 1;
26825 && len
> DWARF_OFFSET_SIZE
26826 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
26827 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
26829 ref
->code
= ref
->code
== DW_MACINFO_define
26830 ? DW_MACRO_define_strp
: DW_MACRO_undef_strp
;
26831 output_macinfo_op (ref
);
26834 dw2_asm_output_data (1, ref
->code
,
26835 ref
->code
== DW_MACINFO_define
26836 ? "Define macro" : "Undefine macro");
26837 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
26838 (unsigned long) ref
->lineno
);
26839 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
26841 case DW_MACRO_define_strp
:
26842 case DW_MACRO_undef_strp
:
26843 node
= find_AT_string (ref
->info
);
26845 && (node
->form
== DW_FORM_strp
26846 || node
->form
== DW_FORM_GNU_str_index
));
26847 dw2_asm_output_data (1, ref
->code
,
26848 ref
->code
== DW_MACRO_define_strp
26849 ? "Define macro strp"
26850 : "Undefine macro strp");
26851 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
26852 (unsigned long) ref
->lineno
);
26853 if (node
->form
== DW_FORM_strp
)
26854 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
26855 debug_str_section
, "The macro: \"%s\"",
26858 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
26861 case DW_MACRO_import
:
26862 dw2_asm_output_data (1, ref
->code
, "Import");
26863 ASM_GENERATE_INTERNAL_LABEL (label
,
26864 DEBUG_MACRO_SECTION_LABEL
,
26865 ref
->lineno
+ macinfo_label_base
);
26866 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
26869 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
26870 ASM_COMMENT_START
, (unsigned long) ref
->code
);
26875 /* Attempt to make a sequence of define/undef macinfo ops shareable with
26876 other compilation unit .debug_macinfo sections. IDX is the first
26877 index of a define/undef, return the number of ops that should be
26878 emitted in a comdat .debug_macinfo section and emit
26879 a DW_MACRO_import entry referencing it.
26880 If the define/undef entry should be emitted normally, return 0. */
26883 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
26884 macinfo_hash_type
**macinfo_htab
)
26886 macinfo_entry
*first
, *second
, *cur
, *inc
;
26887 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
26888 unsigned char checksum
[16];
26889 struct md5_ctx ctx
;
26890 char *grp_name
, *tail
;
26892 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
26893 macinfo_entry
**slot
;
26895 first
= &(*macinfo_table
)[idx
];
26896 second
= &(*macinfo_table
)[idx
+ 1];
26898 /* Optimize only if there are at least two consecutive define/undef ops,
26899 and either all of them are before first DW_MACINFO_start_file
26900 with lineno {0,1} (i.e. predefined macro block), or all of them are
26901 in some included header file. */
26902 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
26904 if (vec_safe_is_empty (files
))
26906 if (first
->lineno
> 1 || second
->lineno
> 1)
26909 else if (first
->lineno
== 0)
26912 /* Find the last define/undef entry that can be grouped together
26913 with first and at the same time compute md5 checksum of their
26914 codes, linenumbers and strings. */
26915 md5_init_ctx (&ctx
);
26916 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
26917 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
26919 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
26923 unsigned char code
= cur
->code
;
26924 md5_process_bytes (&code
, 1, &ctx
);
26925 checksum_uleb128 (cur
->lineno
, &ctx
);
26926 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
26928 md5_finish_ctx (&ctx
, checksum
);
26931 /* From the containing include filename (if any) pick up just
26932 usable characters from its basename. */
26933 if (vec_safe_is_empty (files
))
26936 base
= lbasename (files
->last ().info
);
26937 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
26938 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
26939 encoded_filename_len
++;
26940 /* Count . at the end. */
26941 if (encoded_filename_len
)
26942 encoded_filename_len
++;
26944 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
26945 linebuf_len
= strlen (linebuf
);
26947 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
26948 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
26950 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
26951 tail
= grp_name
+ 4;
26952 if (encoded_filename_len
)
26954 for (i
= 0; base
[i
]; i
++)
26955 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
26959 memcpy (tail
, linebuf
, linebuf_len
);
26960 tail
+= linebuf_len
;
26962 for (i
= 0; i
< 16; i
++)
26963 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
26965 /* Construct a macinfo_entry for DW_MACRO_import
26966 in the empty vector entry before the first define/undef. */
26967 inc
= &(*macinfo_table
)[idx
- 1];
26968 inc
->code
= DW_MACRO_import
;
26970 inc
->info
= ggc_strdup (grp_name
);
26971 if (!*macinfo_htab
)
26972 *macinfo_htab
= new macinfo_hash_type (10);
26973 /* Avoid emitting duplicates. */
26974 slot
= (*macinfo_htab
)->find_slot (inc
, INSERT
);
26979 /* If such an entry has been used before, just emit
26980 a DW_MACRO_import op. */
26982 output_macinfo_op (inc
);
26983 /* And clear all macinfo_entry in the range to avoid emitting them
26984 in the second pass. */
26985 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
26994 inc
->lineno
= (*macinfo_htab
)->elements ();
26995 output_macinfo_op (inc
);
27000 /* Save any strings needed by the macinfo table in the debug str
27001 table. All strings must be collected into the table by the time
27002 index_string is called. */
27005 save_macinfo_strings (void)
27009 macinfo_entry
*ref
;
27011 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
27015 /* Match the logic in output_macinfo_op to decide on
27016 indirect strings. */
27017 case DW_MACINFO_define
:
27018 case DW_MACINFO_undef
:
27019 len
= strlen (ref
->info
) + 1;
27021 && len
> DWARF_OFFSET_SIZE
27022 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
27023 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
27024 set_indirect_string (find_AT_string (ref
->info
));
27026 case DW_MACRO_define_strp
:
27027 case DW_MACRO_undef_strp
:
27028 set_indirect_string (find_AT_string (ref
->info
));
27036 /* Output macinfo section(s). */
27039 output_macinfo (const char *debug_line_label
, bool early_lto_debug
)
27042 unsigned long length
= vec_safe_length (macinfo_table
);
27043 macinfo_entry
*ref
;
27044 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
27045 macinfo_hash_type
*macinfo_htab
= NULL
;
27046 char dl_section_ref
[MAX_ARTIFICIAL_LABEL_BYTES
];
27051 /* output_macinfo* uses these interchangeably. */
27052 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_define
27053 && (int) DW_MACINFO_undef
== (int) DW_MACRO_undef
27054 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_start_file
27055 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_end_file
);
27057 /* AIX Assembler inserts the length, so adjust the reference to match the
27058 offset expected by debuggers. */
27059 strcpy (dl_section_ref
, debug_line_label
);
27060 if (XCOFF_DEBUGGING_INFO
)
27061 strcat (dl_section_ref
, DWARF_INITIAL_LENGTH_SIZE_STR
);
27063 /* For .debug_macro emit the section header. */
27064 if (!dwarf_strict
|| dwarf_version
>= 5)
27066 dw2_asm_output_data (2, dwarf_version
>= 5 ? 5 : 4,
27067 "DWARF macro version number");
27068 if (DWARF_OFFSET_SIZE
== 8)
27069 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
27071 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
27072 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_line_label
,
27073 debug_line_section
, NULL
);
27076 /* In the first loop, it emits the primary .debug_macinfo section
27077 and after each emitted op the macinfo_entry is cleared.
27078 If a longer range of define/undef ops can be optimized using
27079 DW_MACRO_import, the DW_MACRO_import op is emitted and kept in
27080 the vector before the first define/undef in the range and the
27081 whole range of define/undef ops is not emitted and kept. */
27082 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
27086 case DW_MACINFO_start_file
:
27087 vec_safe_push (files
, *ref
);
27089 case DW_MACINFO_end_file
:
27090 if (!vec_safe_is_empty (files
))
27093 case DW_MACINFO_define
:
27094 case DW_MACINFO_undef
:
27095 if ((!dwarf_strict
|| dwarf_version
>= 5)
27096 && HAVE_COMDAT_GROUP
27097 && vec_safe_length (files
) != 1
27100 && (*macinfo_table
)[i
- 1].code
== 0)
27102 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
27111 /* A dummy entry may be inserted at the beginning to be able
27112 to optimize the whole block of predefined macros. */
27118 output_macinfo_op (ref
);
27126 /* Save the number of transparent includes so we can adjust the
27127 label number for the fat LTO object DWARF. */
27128 unsigned macinfo_label_base_adj
= macinfo_htab
->elements ();
27130 delete macinfo_htab
;
27131 macinfo_htab
= NULL
;
27133 /* If any DW_MACRO_import were used, on those DW_MACRO_import entries
27134 terminate the current chain and switch to a new comdat .debug_macinfo
27135 section and emit the define/undef entries within it. */
27136 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
27141 case DW_MACRO_import
:
27143 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
27144 tree comdat_key
= get_identifier (ref
->info
);
27145 /* Terminate the previous .debug_macinfo section. */
27146 dw2_asm_output_data (1, 0, "End compilation unit");
27147 targetm
.asm_out
.named_section (debug_macinfo_section_name
,
27151 ? SECTION_EXCLUDE
: 0),
27153 ASM_GENERATE_INTERNAL_LABEL (label
,
27154 DEBUG_MACRO_SECTION_LABEL
,
27155 ref
->lineno
+ macinfo_label_base
);
27156 ASM_OUTPUT_LABEL (asm_out_file
, label
);
27159 dw2_asm_output_data (2, dwarf_version
>= 5 ? 5 : 4,
27160 "DWARF macro version number");
27161 if (DWARF_OFFSET_SIZE
== 8)
27162 dw2_asm_output_data (1, 1, "Flags: 64-bit");
27164 dw2_asm_output_data (1, 0, "Flags: 32-bit");
27167 case DW_MACINFO_define
:
27168 case DW_MACINFO_undef
:
27169 output_macinfo_op (ref
);
27174 gcc_unreachable ();
27177 macinfo_label_base
+= macinfo_label_base_adj
;
27180 /* Initialize the various sections and labels for dwarf output and prefix
27181 them with PREFIX if non-NULL. */
27184 init_sections_and_labels (bool early_lto_debug
)
27186 /* As we may get called multiple times have a generation count for labels. */
27187 static unsigned generation
= 0;
27189 if (early_lto_debug
)
27191 if (!dwarf_split_debug_info
)
27193 debug_info_section
= get_section (DEBUG_LTO_INFO_SECTION
,
27194 SECTION_DEBUG
| SECTION_EXCLUDE
,
27196 debug_abbrev_section
= get_section (DEBUG_LTO_ABBREV_SECTION
,
27197 SECTION_DEBUG
| SECTION_EXCLUDE
,
27199 debug_macinfo_section_name
= ((dwarf_strict
&& dwarf_version
< 5)
27200 ? DEBUG_LTO_MACINFO_SECTION
27201 : DEBUG_LTO_MACRO_SECTION
);
27202 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
27204 | SECTION_EXCLUDE
, NULL
);
27205 /* For macro info we have to refer to a debug_line section, so similar
27206 to split-dwarf emit a skeleton one for early debug. */
27207 debug_skeleton_line_section
27208 = get_section (DEBUG_LTO_LINE_SECTION
,
27209 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27210 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
27211 DEBUG_SKELETON_LINE_SECTION_LABEL
,
27216 /* ??? Which of the following do we need early? */
27217 debug_info_section
= get_section (DEBUG_LTO_DWO_INFO_SECTION
,
27218 SECTION_DEBUG
| SECTION_EXCLUDE
,
27220 debug_abbrev_section
= get_section (DEBUG_LTO_DWO_ABBREV_SECTION
,
27221 SECTION_DEBUG
| SECTION_EXCLUDE
,
27223 debug_skeleton_info_section
= get_section (DEBUG_LTO_INFO_SECTION
,
27225 | SECTION_EXCLUDE
, NULL
);
27226 debug_skeleton_abbrev_section
= get_section (DEBUG_LTO_ABBREV_SECTION
,
27228 | SECTION_EXCLUDE
, NULL
);
27229 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
27230 DEBUG_SKELETON_ABBREV_SECTION_LABEL
,
27233 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
27234 the main .o, but the skeleton_line goes into the split off dwo. */
27235 debug_skeleton_line_section
27236 = get_section (DEBUG_LTO_LINE_SECTION
,
27237 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27238 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
27239 DEBUG_SKELETON_LINE_SECTION_LABEL
,
27241 debug_str_offsets_section
27242 = get_section (DEBUG_LTO_DWO_STR_OFFSETS_SECTION
,
27243 SECTION_DEBUG
| SECTION_EXCLUDE
,
27245 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
27246 DEBUG_SKELETON_INFO_SECTION_LABEL
,
27248 debug_str_dwo_section
= get_section (DEBUG_LTO_STR_DWO_SECTION
,
27249 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
27250 debug_macinfo_section_name
27252 ? DEBUG_LTO_DWO_MACINFO_SECTION
: DEBUG_LTO_DWO_MACRO_SECTION
);
27253 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
27254 SECTION_DEBUG
| SECTION_EXCLUDE
,
27257 debug_str_section
= get_section (DEBUG_LTO_STR_SECTION
,
27258 DEBUG_STR_SECTION_FLAGS
27259 | SECTION_EXCLUDE
, NULL
);
27263 if (!dwarf_split_debug_info
)
27265 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
27266 SECTION_DEBUG
, NULL
);
27267 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
27268 SECTION_DEBUG
, NULL
);
27269 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
27270 SECTION_DEBUG
, NULL
);
27271 debug_macinfo_section_name
27272 = dwarf_strict
? DEBUG_MACINFO_SECTION
: DEBUG_MACRO_SECTION
;
27273 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
27274 SECTION_DEBUG
, NULL
);
27278 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
27279 SECTION_DEBUG
| SECTION_EXCLUDE
,
27281 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
27282 SECTION_DEBUG
| SECTION_EXCLUDE
,
27284 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
27285 SECTION_DEBUG
, NULL
);
27286 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
27287 SECTION_DEBUG
, NULL
);
27288 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
27289 SECTION_DEBUG
, NULL
);
27290 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
27291 DEBUG_SKELETON_ABBREV_SECTION_LABEL
,
27294 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections
27295 stay in the main .o, but the skeleton_line goes into the
27297 debug_skeleton_line_section
27298 = get_section (DEBUG_DWO_LINE_SECTION
,
27299 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27300 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
27301 DEBUG_SKELETON_LINE_SECTION_LABEL
,
27303 debug_str_offsets_section
27304 = get_section (DEBUG_DWO_STR_OFFSETS_SECTION
,
27305 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27306 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
27307 DEBUG_SKELETON_INFO_SECTION_LABEL
,
27309 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
27310 SECTION_DEBUG
| SECTION_EXCLUDE
,
27312 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
27313 DEBUG_STR_DWO_SECTION_FLAGS
,
27315 debug_macinfo_section_name
27316 = (dwarf_strict
&& dwarf_version
< 5)
27317 ? DEBUG_DWO_MACINFO_SECTION
: DEBUG_DWO_MACRO_SECTION
;
27318 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
27319 SECTION_DEBUG
| SECTION_EXCLUDE
,
27322 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
27323 SECTION_DEBUG
, NULL
);
27324 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
27325 SECTION_DEBUG
, NULL
);
27326 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
27327 SECTION_DEBUG
, NULL
);
27328 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
27329 SECTION_DEBUG
, NULL
);
27330 debug_str_section
= get_section (DEBUG_STR_SECTION
,
27331 DEBUG_STR_SECTION_FLAGS
, NULL
);
27332 debug_ranges_section
= get_section (dwarf_version
>= 5
27333 ? DEBUG_RNGLISTS_SECTION
27334 : DEBUG_RANGES_SECTION
,
27335 SECTION_DEBUG
, NULL
);
27336 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
27337 SECTION_DEBUG
, NULL
);
27340 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
27341 DEBUG_ABBREV_SECTION_LABEL
, generation
);
27342 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
27343 DEBUG_INFO_SECTION_LABEL
, generation
);
27344 info_section_emitted
= false;
27345 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
27346 DEBUG_LINE_SECTION_LABEL
, generation
);
27347 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
27348 DEBUG_RANGES_SECTION_LABEL
, generation
);
27349 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
27350 ASM_GENERATE_INTERNAL_LABEL (ranges_base_label
,
27351 DEBUG_RANGES_SECTION_LABEL
, 2 + generation
);
27352 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
27353 DEBUG_ADDR_SECTION_LABEL
, generation
);
27354 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
27355 (dwarf_strict
&& dwarf_version
< 5)
27356 ? DEBUG_MACINFO_SECTION_LABEL
27357 : DEBUG_MACRO_SECTION_LABEL
, generation
);
27358 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
,
27364 /* Set up for Dwarf output at the start of compilation. */
27367 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
27369 /* Allocate the file_table. */
27370 file_table
= hash_table
<dwarf_file_hasher
>::create_ggc (50);
27372 #ifndef DWARF2_LINENO_DEBUGGING_INFO
27373 /* Allocate the decl_die_table. */
27374 decl_die_table
= hash_table
<decl_die_hasher
>::create_ggc (10);
27376 /* Allocate the decl_loc_table. */
27377 decl_loc_table
= hash_table
<decl_loc_hasher
>::create_ggc (10);
27379 /* Allocate the cached_dw_loc_list_table. */
27380 cached_dw_loc_list_table
= hash_table
<dw_loc_list_hasher
>::create_ggc (10);
27382 /* Allocate the initial hunk of the decl_scope_table. */
27383 vec_alloc (decl_scope_table
, 256);
27385 /* Allocate the initial hunk of the abbrev_die_table. */
27386 vec_alloc (abbrev_die_table
, 256);
27387 /* Zero-th entry is allocated, but unused. */
27388 abbrev_die_table
->quick_push (NULL
);
27390 /* Allocate the dwarf_proc_stack_usage_map. */
27391 dwarf_proc_stack_usage_map
= new hash_map
<dw_die_ref
, int>;
27393 /* Allocate the pubtypes and pubnames vectors. */
27394 vec_alloc (pubname_table
, 32);
27395 vec_alloc (pubtype_table
, 32);
27397 vec_alloc (incomplete_types
, 64);
27399 vec_alloc (used_rtx_array
, 32);
27401 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
27402 vec_alloc (macinfo_table
, 64);
27405 /* If front-ends already registered a main translation unit but we were not
27406 ready to perform the association, do this now. */
27407 if (main_translation_unit
!= NULL_TREE
)
27408 equate_decl_number_to_die (main_translation_unit
, comp_unit_die ());
27411 /* Called before compile () starts outputtting functions, variables
27412 and toplevel asms into assembly. */
27415 dwarf2out_assembly_start (void)
27417 #ifndef DWARF2_LINENO_DEBUGGING_INFO
27418 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
27419 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
27420 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
27421 COLD_TEXT_SECTION_LABEL
, 0);
27422 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
27424 switch_to_section (text_section
);
27425 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
27428 /* Make sure the line number table for .text always exists. */
27429 text_section_line_info
= new_line_info_table ();
27430 text_section_line_info
->end_label
= text_end_label
;
27432 #ifdef DWARF2_LINENO_DEBUGGING_INFO
27433 cur_line_info_table
= text_section_line_info
;
27436 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
27437 && dwarf2out_do_cfi_asm ()
27438 && (!(flag_unwind_tables
|| flag_exceptions
)
27439 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
27440 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
27443 /* A helper function for dwarf2out_finish called through
27444 htab_traverse. Assign a string its index. All strings must be
27445 collected into the table by the time index_string is called,
27446 because the indexing code relies on htab_traverse to traverse nodes
27447 in the same order for each run. */
27450 index_string (indirect_string_node
**h
, unsigned int *index
)
27452 indirect_string_node
*node
= *h
;
27454 find_string_form (node
);
27455 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
27457 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
27458 node
->index
= *index
;
27464 /* A helper function for output_indirect_strings called through
27465 htab_traverse. Output the offset to a string and update the
27469 output_index_string_offset (indirect_string_node
**h
, unsigned int *offset
)
27471 indirect_string_node
*node
= *h
;
27473 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
27475 /* Assert that this node has been assigned an index. */
27476 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
27477 && node
->index
!= NOT_INDEXED
);
27478 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
27479 "indexed string 0x%x: %s", node
->index
, node
->str
);
27480 *offset
+= strlen (node
->str
) + 1;
27485 /* A helper function for dwarf2out_finish called through
27486 htab_traverse. Output the indexed string. */
27489 output_index_string (indirect_string_node
**h
, unsigned int *cur_idx
)
27491 struct indirect_string_node
*node
= *h
;
27493 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
27495 /* Assert that the strings are output in the same order as their
27496 indexes were assigned. */
27497 gcc_assert (*cur_idx
== node
->index
);
27498 assemble_string (node
->str
, strlen (node
->str
) + 1);
27504 /* A helper function for dwarf2out_finish called through
27505 htab_traverse. Emit one queued .debug_str string. */
27508 output_indirect_string (indirect_string_node
**h
, enum dwarf_form form
)
27510 struct indirect_string_node
*node
= *h
;
27512 node
->form
= find_string_form (node
);
27513 if (node
->form
== form
&& node
->refcount
> 0)
27515 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
27516 assemble_string (node
->str
, strlen (node
->str
) + 1);
27522 /* Output the indexed string table. */
27525 output_indirect_strings (void)
27527 switch_to_section (debug_str_section
);
27528 if (!dwarf_split_debug_info
)
27529 debug_str_hash
->traverse
<enum dwarf_form
,
27530 output_indirect_string
> (DW_FORM_strp
);
27533 unsigned int offset
= 0;
27534 unsigned int cur_idx
= 0;
27536 skeleton_debug_str_hash
->traverse
<enum dwarf_form
,
27537 output_indirect_string
> (DW_FORM_strp
);
27539 switch_to_section (debug_str_offsets_section
);
27540 debug_str_hash
->traverse_noresize
27541 <unsigned int *, output_index_string_offset
> (&offset
);
27542 switch_to_section (debug_str_dwo_section
);
27543 debug_str_hash
->traverse_noresize
<unsigned int *, output_index_string
>
27548 /* Callback for htab_traverse to assign an index to an entry in the
27549 table, and to write that entry to the .debug_addr section. */
27552 output_addr_table_entry (addr_table_entry
**slot
, unsigned int *cur_index
)
27554 addr_table_entry
*entry
= *slot
;
27556 if (entry
->refcount
== 0)
27558 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
27559 || entry
->index
== NOT_INDEXED
);
27563 gcc_assert (entry
->index
== *cur_index
);
27566 switch (entry
->kind
)
27569 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
27570 "0x%x", entry
->index
);
27572 case ate_kind_rtx_dtprel
:
27573 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
27574 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
27577 fputc ('\n', asm_out_file
);
27579 case ate_kind_label
:
27580 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
27581 "0x%x", entry
->index
);
27584 gcc_unreachable ();
27589 /* Produce the .debug_addr section. */
27592 output_addr_table (void)
27594 unsigned int index
= 0;
27595 if (addr_index_table
== NULL
|| addr_index_table
->size () == 0)
27598 switch_to_section (debug_addr_section
);
27600 ->traverse_noresize
<unsigned int *, output_addr_table_entry
> (&index
);
27603 #if ENABLE_ASSERT_CHECKING
27604 /* Verify that all marks are clear. */
27607 verify_marks_clear (dw_die_ref die
)
27611 gcc_assert (! die
->die_mark
);
27612 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
27614 #endif /* ENABLE_ASSERT_CHECKING */
27616 /* Clear the marks for a die and its children.
27617 Be cool if the mark isn't set. */
27620 prune_unmark_dies (dw_die_ref die
)
27626 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
27629 /* Given LOC that is referenced by a DIE we're marking as used, find all
27630 referenced DWARF procedures it references and mark them as used. */
27633 prune_unused_types_walk_loc_descr (dw_loc_descr_ref loc
)
27635 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
27636 switch (loc
->dw_loc_opc
)
27638 case DW_OP_implicit_pointer
:
27639 case DW_OP_convert
:
27640 case DW_OP_reinterpret
:
27641 case DW_OP_GNU_implicit_pointer
:
27642 case DW_OP_GNU_convert
:
27643 case DW_OP_GNU_reinterpret
:
27644 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
)
27645 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
27647 case DW_OP_GNU_variable_value
:
27648 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
27651 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
27654 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
27655 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
27656 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
27661 case DW_OP_call_ref
:
27662 case DW_OP_const_type
:
27663 case DW_OP_GNU_const_type
:
27664 case DW_OP_GNU_parameter_ref
:
27665 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
);
27666 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
27668 case DW_OP_regval_type
:
27669 case DW_OP_deref_type
:
27670 case DW_OP_GNU_regval_type
:
27671 case DW_OP_GNU_deref_type
:
27672 gcc_assert (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_die_ref
);
27673 prune_unused_types_mark (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
, 1);
27675 case DW_OP_entry_value
:
27676 case DW_OP_GNU_entry_value
:
27677 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
);
27678 prune_unused_types_walk_loc_descr (loc
->dw_loc_oprnd1
.v
.val_loc
);
27685 /* Given DIE that we're marking as used, find any other dies
27686 it references as attributes and mark them as used. */
27689 prune_unused_types_walk_attribs (dw_die_ref die
)
27694 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
27696 switch (AT_class (a
))
27698 /* Make sure DWARF procedures referenced by location descriptions will
27700 case dw_val_class_loc
:
27701 prune_unused_types_walk_loc_descr (AT_loc (a
));
27703 case dw_val_class_loc_list
:
27704 for (dw_loc_list_ref list
= AT_loc_list (a
);
27706 list
= list
->dw_loc_next
)
27707 prune_unused_types_walk_loc_descr (list
->expr
);
27710 case dw_val_class_die_ref
:
27711 /* A reference to another DIE.
27712 Make sure that it will get emitted.
27713 If it was broken out into a comdat group, don't follow it. */
27714 if (! AT_ref (a
)->comdat_type_p
27715 || a
->dw_attr
== DW_AT_specification
)
27716 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
27719 case dw_val_class_str
:
27720 /* Set the string's refcount to 0 so that prune_unused_types_mark
27721 accounts properly for it. */
27722 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
27731 /* Mark the generic parameters and arguments children DIEs of DIE. */
27734 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
27738 if (die
== NULL
|| die
->die_child
== NULL
)
27740 c
= die
->die_child
;
27743 if (is_template_parameter (c
))
27744 prune_unused_types_mark (c
, 1);
27746 } while (c
&& c
!= die
->die_child
);
27749 /* Mark DIE as being used. If DOKIDS is true, then walk down
27750 to DIE's children. */
27753 prune_unused_types_mark (dw_die_ref die
, int dokids
)
27757 if (die
->die_mark
== 0)
27759 /* We haven't done this node yet. Mark it as used. */
27761 /* If this is the DIE of a generic type instantiation,
27762 mark the children DIEs that describe its generic parms and
27764 prune_unused_types_mark_generic_parms_dies (die
);
27766 /* We also have to mark its parents as used.
27767 (But we don't want to mark our parent's kids due to this,
27768 unless it is a class.) */
27769 if (die
->die_parent
)
27770 prune_unused_types_mark (die
->die_parent
,
27771 class_scope_p (die
->die_parent
));
27773 /* Mark any referenced nodes. */
27774 prune_unused_types_walk_attribs (die
);
27776 /* If this node is a specification,
27777 also mark the definition, if it exists. */
27778 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
27779 prune_unused_types_mark (die
->die_definition
, 1);
27782 if (dokids
&& die
->die_mark
!= 2)
27784 /* We need to walk the children, but haven't done so yet.
27785 Remember that we've walked the kids. */
27788 /* If this is an array type, we need to make sure our
27789 kids get marked, even if they're types. If we're
27790 breaking out types into comdat sections, do this
27791 for all type definitions. */
27792 if (die
->die_tag
== DW_TAG_array_type
27793 || (use_debug_types
27794 && is_type_die (die
) && ! is_declaration_die (die
)))
27795 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
27797 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
27801 /* For local classes, look if any static member functions were emitted
27802 and if so, mark them. */
27805 prune_unused_types_walk_local_classes (dw_die_ref die
)
27809 if (die
->die_mark
== 2)
27812 switch (die
->die_tag
)
27814 case DW_TAG_structure_type
:
27815 case DW_TAG_union_type
:
27816 case DW_TAG_class_type
:
27819 case DW_TAG_subprogram
:
27820 if (!get_AT_flag (die
, DW_AT_declaration
)
27821 || die
->die_definition
!= NULL
)
27822 prune_unused_types_mark (die
, 1);
27829 /* Mark children. */
27830 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
27833 /* Walk the tree DIE and mark types that we actually use. */
27836 prune_unused_types_walk (dw_die_ref die
)
27840 /* Don't do anything if this node is already marked and
27841 children have been marked as well. */
27842 if (die
->die_mark
== 2)
27845 switch (die
->die_tag
)
27847 case DW_TAG_structure_type
:
27848 case DW_TAG_union_type
:
27849 case DW_TAG_class_type
:
27850 if (die
->die_perennial_p
)
27853 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
27854 if (c
->die_tag
== DW_TAG_subprogram
)
27857 /* Finding used static member functions inside of classes
27858 is needed just for local classes, because for other classes
27859 static member function DIEs with DW_AT_specification
27860 are emitted outside of the DW_TAG_*_type. If we ever change
27861 it, we'd need to call this even for non-local classes. */
27863 prune_unused_types_walk_local_classes (die
);
27865 /* It's a type node --- don't mark it. */
27868 case DW_TAG_const_type
:
27869 case DW_TAG_packed_type
:
27870 case DW_TAG_pointer_type
:
27871 case DW_TAG_reference_type
:
27872 case DW_TAG_rvalue_reference_type
:
27873 case DW_TAG_volatile_type
:
27874 case DW_TAG_typedef
:
27875 case DW_TAG_array_type
:
27876 case DW_TAG_interface_type
:
27877 case DW_TAG_friend
:
27878 case DW_TAG_enumeration_type
:
27879 case DW_TAG_subroutine_type
:
27880 case DW_TAG_string_type
:
27881 case DW_TAG_set_type
:
27882 case DW_TAG_subrange_type
:
27883 case DW_TAG_ptr_to_member_type
:
27884 case DW_TAG_file_type
:
27885 /* Type nodes are useful only when other DIEs reference them --- don't
27889 case DW_TAG_dwarf_procedure
:
27890 /* Likewise for DWARF procedures. */
27892 if (die
->die_perennial_p
)
27898 /* Mark everything else. */
27902 if (die
->die_mark
== 0)
27906 /* Now, mark any dies referenced from here. */
27907 prune_unused_types_walk_attribs (die
);
27912 /* Mark children. */
27913 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
27916 /* Increment the string counts on strings referred to from DIE's
27920 prune_unused_types_update_strings (dw_die_ref die
)
27925 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
27926 if (AT_class (a
) == dw_val_class_str
)
27928 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
27930 /* Avoid unnecessarily putting strings that are used less than
27931 twice in the hash table. */
27933 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
27935 indirect_string_node
**slot
27936 = debug_str_hash
->find_slot_with_hash (s
->str
,
27937 htab_hash_string (s
->str
),
27939 gcc_assert (*slot
== NULL
);
27945 /* Mark DIE and its children as removed. */
27948 mark_removed (dw_die_ref die
)
27951 die
->removed
= true;
27952 FOR_EACH_CHILD (die
, c
, mark_removed (c
));
27955 /* Remove from the tree DIE any dies that aren't marked. */
27958 prune_unused_types_prune (dw_die_ref die
)
27962 gcc_assert (die
->die_mark
);
27963 prune_unused_types_update_strings (die
);
27965 if (! die
->die_child
)
27968 c
= die
->die_child
;
27970 dw_die_ref prev
= c
, next
;
27971 for (c
= c
->die_sib
; ! c
->die_mark
; c
= next
)
27972 if (c
== die
->die_child
)
27974 /* No marked children between 'prev' and the end of the list. */
27976 /* No marked children at all. */
27977 die
->die_child
= NULL
;
27980 prev
->die_sib
= c
->die_sib
;
27981 die
->die_child
= prev
;
27994 if (c
!= prev
->die_sib
)
27996 prune_unused_types_prune (c
);
27997 } while (c
!= die
->die_child
);
28000 /* Remove dies representing declarations that we never use. */
28003 prune_unused_types (void)
28006 limbo_die_node
*node
;
28007 comdat_type_node
*ctnode
;
28008 pubname_entry
*pub
;
28009 dw_die_ref base_type
;
28011 #if ENABLE_ASSERT_CHECKING
28012 /* All the marks should already be clear. */
28013 verify_marks_clear (comp_unit_die ());
28014 for (node
= limbo_die_list
; node
; node
= node
->next
)
28015 verify_marks_clear (node
->die
);
28016 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
28017 verify_marks_clear (ctnode
->root_die
);
28018 #endif /* ENABLE_ASSERT_CHECKING */
28020 /* Mark types that are used in global variables. */
28021 premark_types_used_by_global_vars ();
28023 /* Set the mark on nodes that are actually used. */
28024 prune_unused_types_walk (comp_unit_die ());
28025 for (node
= limbo_die_list
; node
; node
= node
->next
)
28026 prune_unused_types_walk (node
->die
);
28027 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
28029 prune_unused_types_walk (ctnode
->root_die
);
28030 prune_unused_types_mark (ctnode
->type_die
, 1);
28033 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
28034 are unusual in that they are pubnames that are the children of pubtypes.
28035 They should only be marked via their parent DW_TAG_enumeration_type die,
28036 not as roots in themselves. */
28037 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
28038 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
28039 prune_unused_types_mark (pub
->die
, 1);
28040 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
28041 prune_unused_types_mark (base_type
, 1);
28043 /* For -fvar-tracking-assignments, also set the mark on nodes that could be
28044 referenced by DW_TAG_call_site DW_AT_call_origin (i.e. direct call
28046 cgraph_node
*cnode
;
28047 FOR_EACH_FUNCTION (cnode
)
28048 if (cnode
->referred_to_p (false))
28050 dw_die_ref die
= lookup_decl_die (cnode
->decl
);
28051 if (die
== NULL
|| die
->die_mark
)
28053 for (cgraph_edge
*e
= cnode
->callers
; e
; e
= e
->next_caller
)
28054 if (e
->caller
!= cnode
28055 && opt_for_fn (e
->caller
->decl
, flag_var_tracking_assignments
))
28057 prune_unused_types_mark (die
, 1);
28062 if (debug_str_hash
)
28063 debug_str_hash
->empty ();
28064 if (skeleton_debug_str_hash
)
28065 skeleton_debug_str_hash
->empty ();
28066 prune_unused_types_prune (comp_unit_die ());
28067 for (limbo_die_node
**pnode
= &limbo_die_list
; *pnode
; )
28070 if (!node
->die
->die_mark
)
28071 *pnode
= node
->next
;
28074 prune_unused_types_prune (node
->die
);
28075 pnode
= &node
->next
;
28078 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
28079 prune_unused_types_prune (ctnode
->root_die
);
28081 /* Leave the marks clear. */
28082 prune_unmark_dies (comp_unit_die ());
28083 for (node
= limbo_die_list
; node
; node
= node
->next
)
28084 prune_unmark_dies (node
->die
);
28085 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
28086 prune_unmark_dies (ctnode
->root_die
);
28089 /* Helpers to manipulate hash table of comdat type units. */
28091 struct comdat_type_hasher
: nofree_ptr_hash
<comdat_type_node
>
28093 static inline hashval_t
hash (const comdat_type_node
*);
28094 static inline bool equal (const comdat_type_node
*, const comdat_type_node
*);
28098 comdat_type_hasher::hash (const comdat_type_node
*type_node
)
28101 memcpy (&h
, type_node
->signature
, sizeof (h
));
28106 comdat_type_hasher::equal (const comdat_type_node
*type_node_1
,
28107 const comdat_type_node
*type_node_2
)
28109 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
28110 DWARF_TYPE_SIGNATURE_SIZE
));
28113 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
28114 to the location it would have been added, should we know its
28115 DECL_ASSEMBLER_NAME when we added other attributes. This will
28116 probably improve compactness of debug info, removing equivalent
28117 abbrevs, and hide any differences caused by deferring the
28118 computation of the assembler name, triggered by e.g. PCH. */
28121 move_linkage_attr (dw_die_ref die
)
28123 unsigned ix
= vec_safe_length (die
->die_attr
);
28124 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
28126 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
28127 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
28131 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
28133 if (prev
->dw_attr
== DW_AT_decl_line
28134 || prev
->dw_attr
== DW_AT_decl_column
28135 || prev
->dw_attr
== DW_AT_name
)
28139 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
28141 die
->die_attr
->pop ();
28142 die
->die_attr
->quick_insert (ix
, linkage
);
28146 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
28147 referenced from typed stack ops and count how often they are used. */
28150 mark_base_types (dw_loc_descr_ref loc
)
28152 dw_die_ref base_type
= NULL
;
28154 for (; loc
; loc
= loc
->dw_loc_next
)
28156 switch (loc
->dw_loc_opc
)
28158 case DW_OP_regval_type
:
28159 case DW_OP_deref_type
:
28160 case DW_OP_GNU_regval_type
:
28161 case DW_OP_GNU_deref_type
:
28162 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
28164 case DW_OP_convert
:
28165 case DW_OP_reinterpret
:
28166 case DW_OP_GNU_convert
:
28167 case DW_OP_GNU_reinterpret
:
28168 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
28171 case DW_OP_const_type
:
28172 case DW_OP_GNU_const_type
:
28173 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28175 case DW_OP_entry_value
:
28176 case DW_OP_GNU_entry_value
:
28177 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
28182 gcc_assert (base_type
->die_parent
== comp_unit_die ());
28183 if (base_type
->die_mark
)
28184 base_type
->die_mark
++;
28187 base_types
.safe_push (base_type
);
28188 base_type
->die_mark
= 1;
28193 /* Comparison function for sorting marked base types. */
28196 base_type_cmp (const void *x
, const void *y
)
28198 dw_die_ref dx
= *(const dw_die_ref
*) x
;
28199 dw_die_ref dy
= *(const dw_die_ref
*) y
;
28200 unsigned int byte_size1
, byte_size2
;
28201 unsigned int encoding1
, encoding2
;
28202 unsigned int align1
, align2
;
28203 if (dx
->die_mark
> dy
->die_mark
)
28205 if (dx
->die_mark
< dy
->die_mark
)
28207 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
28208 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
28209 if (byte_size1
< byte_size2
)
28211 if (byte_size1
> byte_size2
)
28213 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
28214 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
28215 if (encoding1
< encoding2
)
28217 if (encoding1
> encoding2
)
28219 align1
= get_AT_unsigned (dx
, DW_AT_alignment
);
28220 align2
= get_AT_unsigned (dy
, DW_AT_alignment
);
28221 if (align1
< align2
)
28223 if (align1
> align2
)
28228 /* Move base types marked by mark_base_types as early as possible
28229 in the CU, sorted by decreasing usage count both to make the
28230 uleb128 references as small as possible and to make sure they
28231 will have die_offset already computed by calc_die_sizes when
28232 sizes of typed stack loc ops is computed. */
28235 move_marked_base_types (void)
28238 dw_die_ref base_type
, die
, c
;
28240 if (base_types
.is_empty ())
28243 /* Sort by decreasing usage count, they will be added again in that
28245 base_types
.qsort (base_type_cmp
);
28246 die
= comp_unit_die ();
28247 c
= die
->die_child
;
28250 dw_die_ref prev
= c
;
28252 while (c
->die_mark
)
28254 remove_child_with_prev (c
, prev
);
28255 /* As base types got marked, there must be at least
28256 one node other than DW_TAG_base_type. */
28257 gcc_assert (die
->die_child
!= NULL
);
28261 while (c
!= die
->die_child
);
28262 gcc_assert (die
->die_child
);
28263 c
= die
->die_child
;
28264 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
28266 base_type
->die_mark
= 0;
28267 base_type
->die_sib
= c
->die_sib
;
28268 c
->die_sib
= base_type
;
28273 /* Helper function for resolve_addr, attempt to resolve
28274 one CONST_STRING, return true if successful. Similarly verify that
28275 SYMBOL_REFs refer to variables emitted in the current CU. */
28278 resolve_one_addr (rtx
*addr
)
28282 if (GET_CODE (rtl
) == CONST_STRING
)
28284 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
28285 tree t
= build_string (len
, XSTR (rtl
, 0));
28286 tree tlen
= size_int (len
- 1);
28288 = build_array_type (char_type_node
, build_index_type (tlen
));
28289 rtl
= lookup_constant_def (t
);
28290 if (!rtl
|| !MEM_P (rtl
))
28292 rtl
= XEXP (rtl
, 0);
28293 if (GET_CODE (rtl
) == SYMBOL_REF
28294 && SYMBOL_REF_DECL (rtl
)
28295 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
28297 vec_safe_push (used_rtx_array
, rtl
);
28302 if (GET_CODE (rtl
) == SYMBOL_REF
28303 && SYMBOL_REF_DECL (rtl
))
28305 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
28307 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
28310 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
28314 if (GET_CODE (rtl
) == CONST
)
28316 subrtx_ptr_iterator::array_type array
;
28317 FOR_EACH_SUBRTX_PTR (iter
, array
, &XEXP (rtl
, 0), ALL
)
28318 if (!resolve_one_addr (*iter
))
28325 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
28326 if possible, and create DW_TAG_dwarf_procedure that can be referenced
28327 from DW_OP_implicit_pointer if the string hasn't been seen yet. */
28330 string_cst_pool_decl (tree t
)
28332 rtx rtl
= output_constant_def (t
, 1);
28333 unsigned char *array
;
28334 dw_loc_descr_ref l
;
28339 if (!rtl
|| !MEM_P (rtl
))
28341 rtl
= XEXP (rtl
, 0);
28342 if (GET_CODE (rtl
) != SYMBOL_REF
28343 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
28346 decl
= SYMBOL_REF_DECL (rtl
);
28347 if (!lookup_decl_die (decl
))
28349 len
= TREE_STRING_LENGTH (t
);
28350 vec_safe_push (used_rtx_array
, rtl
);
28351 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
28352 array
= ggc_vec_alloc
<unsigned char> (len
);
28353 memcpy (array
, TREE_STRING_POINTER (t
), len
);
28354 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
28355 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
28356 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
28357 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
28358 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
28359 add_AT_loc (ref
, DW_AT_location
, l
);
28360 equate_decl_number_to_die (decl
, ref
);
28365 /* Helper function of resolve_addr_in_expr. LOC is
28366 a DW_OP_addr followed by DW_OP_stack_value, either at the start
28367 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
28368 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
28369 with DW_OP_implicit_pointer if possible
28370 and return true, if unsuccessful, return false. */
28373 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
28375 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
28376 HOST_WIDE_INT offset
= 0;
28377 dw_die_ref ref
= NULL
;
28380 if (GET_CODE (rtl
) == CONST
28381 && GET_CODE (XEXP (rtl
, 0)) == PLUS
28382 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
28384 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
28385 rtl
= XEXP (XEXP (rtl
, 0), 0);
28387 if (GET_CODE (rtl
) == CONST_STRING
)
28389 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
28390 tree t
= build_string (len
, XSTR (rtl
, 0));
28391 tree tlen
= size_int (len
- 1);
28394 = build_array_type (char_type_node
, build_index_type (tlen
));
28395 rtl
= string_cst_pool_decl (t
);
28399 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
28401 decl
= SYMBOL_REF_DECL (rtl
);
28402 if (VAR_P (decl
) && !DECL_EXTERNAL (decl
))
28404 ref
= lookup_decl_die (decl
);
28405 if (ref
&& (get_AT (ref
, DW_AT_location
)
28406 || get_AT (ref
, DW_AT_const_value
)))
28408 loc
->dw_loc_opc
= dwarf_OP (DW_OP_implicit_pointer
);
28409 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28410 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
28411 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
28412 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28413 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
28414 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
28422 /* Helper function for resolve_addr, handle one location
28423 expression, return false if at least one CONST_STRING or SYMBOL_REF in
28424 the location list couldn't be resolved. */
28427 resolve_addr_in_expr (dw_attr_node
*a
, dw_loc_descr_ref loc
)
28429 dw_loc_descr_ref keep
= NULL
;
28430 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
28431 switch (loc
->dw_loc_opc
)
28434 if (!resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
28437 || prev
->dw_loc_opc
== DW_OP_piece
28438 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
28439 && loc
->dw_loc_next
28440 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
28441 && (!dwarf_strict
|| dwarf_version
>= 5)
28442 && optimize_one_addr_into_implicit_ptr (loc
))
28447 case DW_OP_GNU_addr_index
:
28448 case DW_OP_GNU_const_index
:
28449 if (loc
->dw_loc_opc
== DW_OP_GNU_addr_index
28450 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
28452 rtx rtl
= loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
;
28453 if (!resolve_one_addr (&rtl
))
28455 remove_addr_table_entry (loc
->dw_loc_oprnd1
.val_entry
);
28456 loc
->dw_loc_oprnd1
.val_entry
28457 = add_addr_table_entry (rtl
, ate_kind_rtx
);
28460 case DW_OP_const4u
:
28461 case DW_OP_const8u
:
28463 && !resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
28466 case DW_OP_plus_uconst
:
28467 if (size_of_loc_descr (loc
)
28468 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
28470 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
28472 dw_loc_descr_ref repl
28473 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
28474 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
28475 add_loc_descr (&repl
, loc
->dw_loc_next
);
28479 case DW_OP_implicit_value
:
28480 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
28481 && !resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
))
28484 case DW_OP_implicit_pointer
:
28485 case DW_OP_GNU_implicit_pointer
:
28486 case DW_OP_GNU_parameter_ref
:
28487 case DW_OP_GNU_variable_value
:
28488 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
28491 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
28494 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28495 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
28496 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28498 if (loc
->dw_loc_opc
== DW_OP_GNU_variable_value
)
28501 && loc
->dw_loc_next
== NULL
28502 && AT_class (a
) == dw_val_class_loc
)
28503 switch (a
->dw_attr
)
28505 /* Following attributes allow both exprloc and reference,
28506 so if the whole expression is DW_OP_GNU_variable_value
28507 alone we could transform it into reference. */
28508 case DW_AT_byte_size
:
28509 case DW_AT_bit_size
:
28510 case DW_AT_lower_bound
:
28511 case DW_AT_upper_bound
:
28512 case DW_AT_bit_stride
:
28514 case DW_AT_allocated
:
28515 case DW_AT_associated
:
28516 case DW_AT_byte_stride
:
28517 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
28518 a
->dw_attr_val
.val_entry
= NULL
;
28519 a
->dw_attr_val
.v
.val_die_ref
.die
28520 = loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28521 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
28530 case DW_OP_const_type
:
28531 case DW_OP_regval_type
:
28532 case DW_OP_deref_type
:
28533 case DW_OP_convert
:
28534 case DW_OP_reinterpret
:
28535 case DW_OP_GNU_const_type
:
28536 case DW_OP_GNU_regval_type
:
28537 case DW_OP_GNU_deref_type
:
28538 case DW_OP_GNU_convert
:
28539 case DW_OP_GNU_reinterpret
:
28540 while (loc
->dw_loc_next
28541 && (loc
->dw_loc_next
->dw_loc_opc
== DW_OP_convert
28542 || loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
))
28544 dw_die_ref base1
, base2
;
28545 unsigned enc1
, enc2
, size1
, size2
;
28546 if (loc
->dw_loc_opc
== DW_OP_regval_type
28547 || loc
->dw_loc_opc
== DW_OP_deref_type
28548 || loc
->dw_loc_opc
== DW_OP_GNU_regval_type
28549 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
28550 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
28551 else if (loc
->dw_loc_oprnd1
.val_class
28552 == dw_val_class_unsigned_const
)
28555 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28556 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
28557 == dw_val_class_unsigned_const
)
28559 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28560 gcc_assert (base1
->die_tag
== DW_TAG_base_type
28561 && base2
->die_tag
== DW_TAG_base_type
);
28562 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
28563 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
28564 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
28565 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
28567 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
28568 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
28572 /* Optimize away next DW_OP_convert after
28573 adjusting LOC's base type die reference. */
28574 if (loc
->dw_loc_opc
== DW_OP_regval_type
28575 || loc
->dw_loc_opc
== DW_OP_deref_type
28576 || loc
->dw_loc_opc
== DW_OP_GNU_regval_type
28577 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
28578 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
28580 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
28581 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
28584 /* Don't change integer DW_OP_convert after e.g. floating
28585 point typed stack entry. */
28586 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
28587 keep
= loc
->dw_loc_next
;
28597 /* Helper function of resolve_addr. DIE had DW_AT_location of
28598 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
28599 and DW_OP_addr couldn't be resolved. resolve_addr has already
28600 removed the DW_AT_location attribute. This function attempts to
28601 add a new DW_AT_location attribute with DW_OP_implicit_pointer
28602 to it or DW_AT_const_value attribute, if possible. */
28605 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
28608 || lookup_decl_die (decl
) != die
28609 || DECL_EXTERNAL (decl
)
28610 || !TREE_STATIC (decl
)
28611 || DECL_INITIAL (decl
) == NULL_TREE
28612 || DECL_P (DECL_INITIAL (decl
))
28613 || get_AT (die
, DW_AT_const_value
))
28616 tree init
= DECL_INITIAL (decl
);
28617 HOST_WIDE_INT offset
= 0;
28618 /* For variables that have been optimized away and thus
28619 don't have a memory location, see if we can emit
28620 DW_AT_const_value instead. */
28621 if (tree_add_const_value_attribute (die
, init
))
28623 if (dwarf_strict
&& dwarf_version
< 5)
28625 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
28626 and ADDR_EXPR refers to a decl that has DW_AT_location or
28627 DW_AT_const_value (but isn't addressable, otherwise
28628 resolving the original DW_OP_addr wouldn't fail), see if
28629 we can add DW_OP_implicit_pointer. */
28631 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
28632 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
28634 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
28635 init
= TREE_OPERAND (init
, 0);
28638 if (TREE_CODE (init
) != ADDR_EXPR
)
28640 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
28641 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
28642 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
28643 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
28644 && TREE_OPERAND (init
, 0) != decl
))
28647 dw_loc_descr_ref l
;
28649 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
28651 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
28654 decl
= SYMBOL_REF_DECL (rtl
);
28657 decl
= TREE_OPERAND (init
, 0);
28658 ref
= lookup_decl_die (decl
);
28660 || (!get_AT (ref
, DW_AT_location
)
28661 && !get_AT (ref
, DW_AT_const_value
)))
28663 l
= new_loc_descr (dwarf_OP (DW_OP_implicit_pointer
), 0, offset
);
28664 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28665 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
28666 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28667 add_AT_loc (die
, DW_AT_location
, l
);
28671 /* Return NULL if l is a DWARF expression, or first op that is not
28672 valid DWARF expression. */
28674 static dw_loc_descr_ref
28675 non_dwarf_expression (dw_loc_descr_ref l
)
28679 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
28681 switch (l
->dw_loc_opc
)
28684 case DW_OP_implicit_value
:
28685 case DW_OP_stack_value
:
28686 case DW_OP_implicit_pointer
:
28687 case DW_OP_GNU_implicit_pointer
:
28688 case DW_OP_GNU_parameter_ref
:
28690 case DW_OP_bit_piece
:
28695 l
= l
->dw_loc_next
;
28700 /* Return adjusted copy of EXPR:
28701 If it is empty DWARF expression, return it.
28702 If it is valid non-empty DWARF expression,
28703 return copy of EXPR with DW_OP_deref appended to it.
28704 If it is DWARF expression followed by DW_OP_reg{N,x}, return
28705 copy of the DWARF expression with DW_OP_breg{N,x} <0> appended.
28706 If it is DWARF expression followed by DW_OP_stack_value, return
28707 copy of the DWARF expression without anything appended.
28708 Otherwise, return NULL. */
28710 static dw_loc_descr_ref
28711 copy_deref_exprloc (dw_loc_descr_ref expr
)
28713 dw_loc_descr_ref tail
= NULL
;
28718 dw_loc_descr_ref l
= non_dwarf_expression (expr
);
28719 if (l
&& l
->dw_loc_next
)
28724 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
28725 tail
= new_loc_descr ((enum dwarf_location_atom
)
28726 (DW_OP_breg0
+ (l
->dw_loc_opc
- DW_OP_reg0
)),
28729 switch (l
->dw_loc_opc
)
28732 tail
= new_loc_descr (DW_OP_bregx
,
28733 l
->dw_loc_oprnd1
.v
.val_unsigned
, 0);
28735 case DW_OP_stack_value
:
28742 tail
= new_loc_descr (DW_OP_deref
, 0, 0);
28744 dw_loc_descr_ref ret
= NULL
, *p
= &ret
;
28747 *p
= new_loc_descr (expr
->dw_loc_opc
, 0, 0);
28748 (*p
)->dw_loc_oprnd1
= expr
->dw_loc_oprnd1
;
28749 (*p
)->dw_loc_oprnd2
= expr
->dw_loc_oprnd2
;
28750 p
= &(*p
)->dw_loc_next
;
28751 expr
= expr
->dw_loc_next
;
28757 /* For DW_AT_string_length attribute with DW_OP_GNU_variable_value
28758 reference to a variable or argument, adjust it if needed and return:
28759 -1 if the DW_AT_string_length attribute and DW_AT_{string_length_,}byte_size
28760 attribute if present should be removed
28761 0 keep the attribute perhaps with minor modifications, no need to rescan
28762 1 if the attribute has been successfully adjusted. */
28765 optimize_string_length (dw_attr_node
*a
)
28767 dw_loc_descr_ref l
= AT_loc (a
), lv
;
28769 if (l
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
28771 tree decl
= l
->dw_loc_oprnd1
.v
.val_decl_ref
;
28772 die
= lookup_decl_die (decl
);
28775 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28776 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= die
;
28777 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28783 die
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28785 /* DWARF5 allows reference class, so we can then reference the DIE.
28786 Only do this for DW_OP_GNU_variable_value DW_OP_stack_value. */
28787 if (l
->dw_loc_next
!= NULL
&& dwarf_version
>= 5)
28789 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
28790 a
->dw_attr_val
.val_entry
= NULL
;
28791 a
->dw_attr_val
.v
.val_die_ref
.die
= die
;
28792 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
28796 dw_attr_node
*av
= get_AT (die
, DW_AT_location
);
28798 bool non_dwarf_expr
= false;
28801 return dwarf_strict
? -1 : 0;
28802 switch (AT_class (av
))
28804 case dw_val_class_loc_list
:
28805 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
28806 if (d
->expr
&& non_dwarf_expression (d
->expr
))
28807 non_dwarf_expr
= true;
28809 case dw_val_class_loc
:
28812 return dwarf_strict
? -1 : 0;
28813 if (non_dwarf_expression (lv
))
28814 non_dwarf_expr
= true;
28817 return dwarf_strict
? -1 : 0;
28820 /* If it is safe to transform DW_OP_GNU_variable_value DW_OP_stack_value
28821 into DW_OP_call4 or DW_OP_GNU_variable_value into
28822 DW_OP_call4 DW_OP_deref, do so. */
28823 if (!non_dwarf_expr
28824 && (l
->dw_loc_next
!= NULL
|| AT_class (av
) == dw_val_class_loc
))
28826 l
->dw_loc_opc
= DW_OP_call4
;
28827 if (l
->dw_loc_next
)
28828 l
->dw_loc_next
= NULL
;
28830 l
->dw_loc_next
= new_loc_descr (DW_OP_deref
, 0, 0);
28834 /* For DW_OP_GNU_variable_value DW_OP_stack_value, we can just
28835 copy over the DW_AT_location attribute from die to a. */
28836 if (l
->dw_loc_next
!= NULL
)
28838 a
->dw_attr_val
= av
->dw_attr_val
;
28842 dw_loc_list_ref list
, *p
;
28843 switch (AT_class (av
))
28845 case dw_val_class_loc_list
:
28848 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
28850 lv
= copy_deref_exprloc (d
->expr
);
28853 *p
= new_loc_list (lv
, d
->begin
, d
->end
, d
->section
);
28854 p
= &(*p
)->dw_loc_next
;
28856 else if (!dwarf_strict
&& d
->expr
)
28860 return dwarf_strict
? -1 : 0;
28861 a
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
28863 *AT_loc_list_ptr (a
) = list
;
28865 case dw_val_class_loc
:
28866 lv
= copy_deref_exprloc (AT_loc (av
));
28868 return dwarf_strict
? -1 : 0;
28869 a
->dw_attr_val
.v
.val_loc
= lv
;
28872 gcc_unreachable ();
28876 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
28877 an address in .rodata section if the string literal is emitted there,
28878 or remove the containing location list or replace DW_AT_const_value
28879 with DW_AT_location and empty location expression, if it isn't found
28880 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
28881 to something that has been emitted in the current CU. */
28884 resolve_addr (dw_die_ref die
)
28888 dw_loc_list_ref
*curr
, *start
, loc
;
28890 bool remove_AT_byte_size
= false;
28892 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
28893 switch (AT_class (a
))
28895 case dw_val_class_loc_list
:
28896 start
= curr
= AT_loc_list_ptr (a
);
28899 /* The same list can be referenced more than once. See if we have
28900 already recorded the result from a previous pass. */
28902 *curr
= loc
->dw_loc_next
;
28903 else if (!loc
->resolved_addr
)
28905 /* As things stand, we do not expect or allow one die to
28906 reference a suffix of another die's location list chain.
28907 References must be identical or completely separate.
28908 There is therefore no need to cache the result of this
28909 pass on any list other than the first; doing so
28910 would lead to unnecessary writes. */
28913 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
28914 if (!resolve_addr_in_expr (a
, (*curr
)->expr
))
28916 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
28917 dw_loc_descr_ref l
= (*curr
)->expr
;
28919 if (next
&& (*curr
)->ll_symbol
)
28921 gcc_assert (!next
->ll_symbol
);
28922 next
->ll_symbol
= (*curr
)->ll_symbol
;
28924 if (dwarf_split_debug_info
)
28925 remove_loc_list_addr_table_entries (l
);
28930 mark_base_types ((*curr
)->expr
);
28931 curr
= &(*curr
)->dw_loc_next
;
28935 loc
->resolved_addr
= 1;
28939 loc
->dw_loc_next
= *start
;
28944 remove_AT (die
, a
->dw_attr
);
28948 case dw_val_class_loc
:
28950 dw_loc_descr_ref l
= AT_loc (a
);
28951 /* DW_OP_GNU_variable_value DW_OP_stack_value or
28952 DW_OP_GNU_variable_value in DW_AT_string_length can be converted
28953 into DW_OP_call4 or DW_OP_call4 DW_OP_deref, which is standard
28954 DWARF4 unlike DW_OP_GNU_variable_value. Or for DWARF5
28955 DW_OP_GNU_variable_value DW_OP_stack_value can be replaced
28956 with DW_FORM_ref referencing the same DIE as
28957 DW_OP_GNU_variable_value used to reference. */
28958 if (a
->dw_attr
== DW_AT_string_length
28960 && l
->dw_loc_opc
== DW_OP_GNU_variable_value
28961 && (l
->dw_loc_next
== NULL
28962 || (l
->dw_loc_next
->dw_loc_next
== NULL
28963 && l
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
)))
28965 switch (optimize_string_length (a
))
28968 remove_AT (die
, a
->dw_attr
);
28970 /* If we drop DW_AT_string_length, we need to drop also
28971 DW_AT_{string_length_,}byte_size. */
28972 remove_AT_byte_size
= true;
28977 /* Even if we keep the optimized DW_AT_string_length,
28978 it might have changed AT_class, so process it again. */
28983 /* For -gdwarf-2 don't attempt to optimize
28984 DW_AT_data_member_location containing
28985 DW_OP_plus_uconst - older consumers might
28986 rely on it being that op instead of a more complex,
28987 but shorter, location description. */
28988 if ((dwarf_version
> 2
28989 || a
->dw_attr
!= DW_AT_data_member_location
28991 || l
->dw_loc_opc
!= DW_OP_plus_uconst
28992 || l
->dw_loc_next
!= NULL
)
28993 && !resolve_addr_in_expr (a
, l
))
28995 if (dwarf_split_debug_info
)
28996 remove_loc_list_addr_table_entries (l
);
28998 && l
->dw_loc_next
== NULL
28999 && l
->dw_loc_opc
== DW_OP_addr
29000 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
29001 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
29002 && a
->dw_attr
== DW_AT_location
)
29004 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
29005 remove_AT (die
, a
->dw_attr
);
29007 optimize_location_into_implicit_ptr (die
, decl
);
29010 if (a
->dw_attr
== DW_AT_string_length
)
29011 /* If we drop DW_AT_string_length, we need to drop also
29012 DW_AT_{string_length_,}byte_size. */
29013 remove_AT_byte_size
= true;
29014 remove_AT (die
, a
->dw_attr
);
29018 mark_base_types (l
);
29021 case dw_val_class_addr
:
29022 if (a
->dw_attr
== DW_AT_const_value
29023 && !resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
))
29025 if (AT_index (a
) != NOT_INDEXED
)
29026 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
29027 remove_AT (die
, a
->dw_attr
);
29030 if ((die
->die_tag
== DW_TAG_call_site
29031 && a
->dw_attr
== DW_AT_call_origin
)
29032 || (die
->die_tag
== DW_TAG_GNU_call_site
29033 && a
->dw_attr
== DW_AT_abstract_origin
))
29035 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
29036 dw_die_ref tdie
= lookup_decl_die (tdecl
);
29039 && DECL_EXTERNAL (tdecl
)
29040 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
29041 && (cdie
= lookup_context_die (DECL_CONTEXT (tdecl
))))
29043 dw_die_ref pdie
= cdie
;
29044 /* Make sure we don't add these DIEs into type units.
29045 We could emit skeleton DIEs for context (namespaces,
29046 outer structs/classes) and a skeleton DIE for the
29047 innermost context with DW_AT_signature pointing to the
29048 type unit. See PR78835. */
29049 while (pdie
&& pdie
->die_tag
!= DW_TAG_type_unit
)
29050 pdie
= pdie
->die_parent
;
29053 /* Creating a full DIE for tdecl is overly expensive and
29054 at this point even wrong when in the LTO phase
29055 as it can end up generating new type DIEs we didn't
29056 output and thus optimize_external_refs will crash. */
29057 tdie
= new_die (DW_TAG_subprogram
, cdie
, NULL_TREE
);
29058 add_AT_flag (tdie
, DW_AT_external
, 1);
29059 add_AT_flag (tdie
, DW_AT_declaration
, 1);
29060 add_linkage_attr (tdie
, tdecl
);
29061 add_name_and_src_coords_attributes (tdie
, tdecl
);
29062 equate_decl_number_to_die (tdecl
, tdie
);
29067 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
29068 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
29069 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
29073 if (AT_index (a
) != NOT_INDEXED
)
29074 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
29075 remove_AT (die
, a
->dw_attr
);
29084 if (remove_AT_byte_size
)
29085 remove_AT (die
, dwarf_version
>= 5
29086 ? DW_AT_string_length_byte_size
29087 : DW_AT_byte_size
);
29089 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
29092 /* Helper routines for optimize_location_lists.
29093 This pass tries to share identical local lists in .debug_loc
29096 /* Iteratively hash operands of LOC opcode into HSTATE. */
29099 hash_loc_operands (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
29101 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
29102 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
29104 switch (loc
->dw_loc_opc
)
29106 case DW_OP_const4u
:
29107 case DW_OP_const8u
:
29111 case DW_OP_const1u
:
29112 case DW_OP_const1s
:
29113 case DW_OP_const2u
:
29114 case DW_OP_const2s
:
29115 case DW_OP_const4s
:
29116 case DW_OP_const8s
:
29120 case DW_OP_plus_uconst
:
29156 case DW_OP_deref_size
:
29157 case DW_OP_xderef_size
:
29158 hstate
.add_object (val1
->v
.val_int
);
29165 gcc_assert (val1
->val_class
== dw_val_class_loc
);
29166 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
29167 hstate
.add_object (offset
);
29170 case DW_OP_implicit_value
:
29171 hstate
.add_object (val1
->v
.val_unsigned
);
29172 switch (val2
->val_class
)
29174 case dw_val_class_const
:
29175 hstate
.add_object (val2
->v
.val_int
);
29177 case dw_val_class_vec
:
29179 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
29180 unsigned int len
= val2
->v
.val_vec
.length
;
29182 hstate
.add_int (elt_size
);
29183 hstate
.add_int (len
);
29184 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
29187 case dw_val_class_const_double
:
29188 hstate
.add_object (val2
->v
.val_double
.low
);
29189 hstate
.add_object (val2
->v
.val_double
.high
);
29191 case dw_val_class_wide_int
:
29192 hstate
.add (val2
->v
.val_wide
->get_val (),
29193 get_full_len (*val2
->v
.val_wide
)
29194 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
29196 case dw_val_class_addr
:
29197 inchash::add_rtx (val2
->v
.val_addr
, hstate
);
29200 gcc_unreachable ();
29204 case DW_OP_bit_piece
:
29205 hstate
.add_object (val1
->v
.val_int
);
29206 hstate
.add_object (val2
->v
.val_int
);
29212 unsigned char dtprel
= 0xd1;
29213 hstate
.add_object (dtprel
);
29215 inchash::add_rtx (val1
->v
.val_addr
, hstate
);
29217 case DW_OP_GNU_addr_index
:
29218 case DW_OP_GNU_const_index
:
29222 unsigned char dtprel
= 0xd1;
29223 hstate
.add_object (dtprel
);
29225 inchash::add_rtx (val1
->val_entry
->addr
.rtl
, hstate
);
29228 case DW_OP_implicit_pointer
:
29229 case DW_OP_GNU_implicit_pointer
:
29230 hstate
.add_int (val2
->v
.val_int
);
29232 case DW_OP_entry_value
:
29233 case DW_OP_GNU_entry_value
:
29234 hstate
.add_object (val1
->v
.val_loc
);
29236 case DW_OP_regval_type
:
29237 case DW_OP_deref_type
:
29238 case DW_OP_GNU_regval_type
:
29239 case DW_OP_GNU_deref_type
:
29241 unsigned int byte_size
29242 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
29243 unsigned int encoding
29244 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
29245 hstate
.add_object (val1
->v
.val_int
);
29246 hstate
.add_object (byte_size
);
29247 hstate
.add_object (encoding
);
29250 case DW_OP_convert
:
29251 case DW_OP_reinterpret
:
29252 case DW_OP_GNU_convert
:
29253 case DW_OP_GNU_reinterpret
:
29254 if (val1
->val_class
== dw_val_class_unsigned_const
)
29256 hstate
.add_object (val1
->v
.val_unsigned
);
29260 case DW_OP_const_type
:
29261 case DW_OP_GNU_const_type
:
29263 unsigned int byte_size
29264 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
29265 unsigned int encoding
29266 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
29267 hstate
.add_object (byte_size
);
29268 hstate
.add_object (encoding
);
29269 if (loc
->dw_loc_opc
!= DW_OP_const_type
29270 && loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
29272 hstate
.add_object (val2
->val_class
);
29273 switch (val2
->val_class
)
29275 case dw_val_class_const
:
29276 hstate
.add_object (val2
->v
.val_int
);
29278 case dw_val_class_vec
:
29280 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
29281 unsigned int len
= val2
->v
.val_vec
.length
;
29283 hstate
.add_object (elt_size
);
29284 hstate
.add_object (len
);
29285 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
29288 case dw_val_class_const_double
:
29289 hstate
.add_object (val2
->v
.val_double
.low
);
29290 hstate
.add_object (val2
->v
.val_double
.high
);
29292 case dw_val_class_wide_int
:
29293 hstate
.add (val2
->v
.val_wide
->get_val (),
29294 get_full_len (*val2
->v
.val_wide
)
29295 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
29298 gcc_unreachable ();
29304 /* Other codes have no operands. */
29309 /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
29312 hash_locs (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
29314 dw_loc_descr_ref l
;
29315 bool sizes_computed
= false;
29316 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
29317 size_of_locs (loc
);
29319 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
29321 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
29322 hstate
.add_object (opc
);
29323 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
29325 size_of_locs (loc
);
29326 sizes_computed
= true;
29328 hash_loc_operands (l
, hstate
);
29332 /* Compute hash of the whole location list LIST_HEAD. */
29335 hash_loc_list (dw_loc_list_ref list_head
)
29337 dw_loc_list_ref curr
= list_head
;
29338 inchash::hash hstate
;
29340 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
29342 hstate
.add (curr
->begin
, strlen (curr
->begin
) + 1);
29343 hstate
.add (curr
->end
, strlen (curr
->end
) + 1);
29345 hstate
.add (curr
->section
, strlen (curr
->section
) + 1);
29346 hash_locs (curr
->expr
, hstate
);
29348 list_head
->hash
= hstate
.end ();
29351 /* Return true if X and Y opcodes have the same operands. */
29354 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
29356 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
29357 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
29358 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
29359 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
29361 switch (x
->dw_loc_opc
)
29363 case DW_OP_const4u
:
29364 case DW_OP_const8u
:
29368 case DW_OP_const1u
:
29369 case DW_OP_const1s
:
29370 case DW_OP_const2u
:
29371 case DW_OP_const2s
:
29372 case DW_OP_const4s
:
29373 case DW_OP_const8s
:
29377 case DW_OP_plus_uconst
:
29413 case DW_OP_deref_size
:
29414 case DW_OP_xderef_size
:
29415 return valx1
->v
.val_int
== valy1
->v
.val_int
;
29418 /* If splitting debug info, the use of DW_OP_GNU_addr_index
29419 can cause irrelevant differences in dw_loc_addr. */
29420 gcc_assert (valx1
->val_class
== dw_val_class_loc
29421 && valy1
->val_class
== dw_val_class_loc
29422 && (dwarf_split_debug_info
29423 || x
->dw_loc_addr
== y
->dw_loc_addr
));
29424 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
29425 case DW_OP_implicit_value
:
29426 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
29427 || valx2
->val_class
!= valy2
->val_class
)
29429 switch (valx2
->val_class
)
29431 case dw_val_class_const
:
29432 return valx2
->v
.val_int
== valy2
->v
.val_int
;
29433 case dw_val_class_vec
:
29434 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
29435 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
29436 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
29437 valx2
->v
.val_vec
.elt_size
29438 * valx2
->v
.val_vec
.length
) == 0;
29439 case dw_val_class_const_double
:
29440 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
29441 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
29442 case dw_val_class_wide_int
:
29443 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
29444 case dw_val_class_addr
:
29445 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
29447 gcc_unreachable ();
29450 case DW_OP_bit_piece
:
29451 return valx1
->v
.val_int
== valy1
->v
.val_int
29452 && valx2
->v
.val_int
== valy2
->v
.val_int
;
29455 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
29456 case DW_OP_GNU_addr_index
:
29457 case DW_OP_GNU_const_index
:
29459 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
29460 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
29461 return rtx_equal_p (ax1
, ay1
);
29463 case DW_OP_implicit_pointer
:
29464 case DW_OP_GNU_implicit_pointer
:
29465 return valx1
->val_class
== dw_val_class_die_ref
29466 && valx1
->val_class
== valy1
->val_class
29467 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
29468 && valx2
->v
.val_int
== valy2
->v
.val_int
;
29469 case DW_OP_entry_value
:
29470 case DW_OP_GNU_entry_value
:
29471 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
29472 case DW_OP_const_type
:
29473 case DW_OP_GNU_const_type
:
29474 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
29475 || valx2
->val_class
!= valy2
->val_class
)
29477 switch (valx2
->val_class
)
29479 case dw_val_class_const
:
29480 return valx2
->v
.val_int
== valy2
->v
.val_int
;
29481 case dw_val_class_vec
:
29482 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
29483 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
29484 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
29485 valx2
->v
.val_vec
.elt_size
29486 * valx2
->v
.val_vec
.length
) == 0;
29487 case dw_val_class_const_double
:
29488 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
29489 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
29490 case dw_val_class_wide_int
:
29491 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
29493 gcc_unreachable ();
29495 case DW_OP_regval_type
:
29496 case DW_OP_deref_type
:
29497 case DW_OP_GNU_regval_type
:
29498 case DW_OP_GNU_deref_type
:
29499 return valx1
->v
.val_int
== valy1
->v
.val_int
29500 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
29501 case DW_OP_convert
:
29502 case DW_OP_reinterpret
:
29503 case DW_OP_GNU_convert
:
29504 case DW_OP_GNU_reinterpret
:
29505 if (valx1
->val_class
!= valy1
->val_class
)
29507 if (valx1
->val_class
== dw_val_class_unsigned_const
)
29508 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
29509 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
29510 case DW_OP_GNU_parameter_ref
:
29511 return valx1
->val_class
== dw_val_class_die_ref
29512 && valx1
->val_class
== valy1
->val_class
29513 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
29515 /* Other codes have no operands. */
29520 /* Return true if DWARF location expressions X and Y are the same. */
29523 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
29525 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
29526 if (x
->dw_loc_opc
!= y
->dw_loc_opc
29527 || x
->dtprel
!= y
->dtprel
29528 || !compare_loc_operands (x
, y
))
29530 return x
== NULL
&& y
== NULL
;
29533 /* Hashtable helpers. */
29535 struct loc_list_hasher
: nofree_ptr_hash
<dw_loc_list_struct
>
29537 static inline hashval_t
hash (const dw_loc_list_struct
*);
29538 static inline bool equal (const dw_loc_list_struct
*,
29539 const dw_loc_list_struct
*);
29542 /* Return precomputed hash of location list X. */
29545 loc_list_hasher::hash (const dw_loc_list_struct
*x
)
29550 /* Return true if location lists A and B are the same. */
29553 loc_list_hasher::equal (const dw_loc_list_struct
*a
,
29554 const dw_loc_list_struct
*b
)
29558 if (a
->hash
!= b
->hash
)
29560 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
29561 if (strcmp (a
->begin
, b
->begin
) != 0
29562 || strcmp (a
->end
, b
->end
) != 0
29563 || (a
->section
== NULL
) != (b
->section
== NULL
)
29564 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
29565 || !compare_locs (a
->expr
, b
->expr
))
29567 return a
== NULL
&& b
== NULL
;
29570 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
29573 /* Recursively optimize location lists referenced from DIE
29574 children and share them whenever possible. */
29577 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type
*htab
)
29582 dw_loc_list_struct
**slot
;
29584 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
29585 if (AT_class (a
) == dw_val_class_loc_list
)
29587 dw_loc_list_ref list
= AT_loc_list (a
);
29588 /* TODO: perform some optimizations here, before hashing
29589 it and storing into the hash table. */
29590 hash_loc_list (list
);
29591 slot
= htab
->find_slot_with_hash (list
, list
->hash
, INSERT
);
29595 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
29598 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
29602 /* Recursively assign each location list a unique index into the debug_addr
29606 index_location_lists (dw_die_ref die
)
29612 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
29613 if (AT_class (a
) == dw_val_class_loc_list
)
29615 dw_loc_list_ref list
= AT_loc_list (a
);
29616 dw_loc_list_ref curr
;
29617 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
29619 /* Don't index an entry that has already been indexed
29620 or won't be output. */
29621 if (curr
->begin_entry
!= NULL
29622 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
29626 = add_addr_table_entry (xstrdup (curr
->begin
), ate_kind_label
);
29630 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
29633 /* Optimize location lists referenced from DIE
29634 children and share them whenever possible. */
29637 optimize_location_lists (dw_die_ref die
)
29639 loc_list_hash_type
htab (500);
29640 optimize_location_lists_1 (die
, &htab
);
29643 /* Traverse the limbo die list, and add parent/child links. The only
29644 dies without parents that should be here are concrete instances of
29645 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
29646 For concrete instances, we can get the parent die from the abstract
29650 flush_limbo_die_list (void)
29652 limbo_die_node
*node
;
29654 /* get_context_die calls force_decl_die, which can put new DIEs on the
29655 limbo list in LTO mode when nested functions are put in a different
29656 partition than that of their parent function. */
29657 while ((node
= limbo_die_list
))
29659 dw_die_ref die
= node
->die
;
29660 limbo_die_list
= node
->next
;
29662 if (die
->die_parent
== NULL
)
29664 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
29666 if (origin
&& origin
->die_parent
)
29667 add_child_die (origin
->die_parent
, die
);
29668 else if (is_cu_die (die
))
29670 else if (seen_error ())
29671 /* It's OK to be confused by errors in the input. */
29672 add_child_die (comp_unit_die (), die
);
29675 /* In certain situations, the lexical block containing a
29676 nested function can be optimized away, which results
29677 in the nested function die being orphaned. Likewise
29678 with the return type of that nested function. Force
29679 this to be a child of the containing function.
29681 It may happen that even the containing function got fully
29682 inlined and optimized out. In that case we are lost and
29683 assign the empty child. This should not be big issue as
29684 the function is likely unreachable too. */
29685 gcc_assert (node
->created_for
);
29687 if (DECL_P (node
->created_for
))
29688 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
29689 else if (TYPE_P (node
->created_for
))
29690 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
29692 origin
= comp_unit_die ();
29694 add_child_die (origin
, die
);
29700 /* Reset DIEs so we can output them again. */
29703 reset_dies (dw_die_ref die
)
29707 /* Remove stuff we re-generate. */
29709 die
->die_offset
= 0;
29710 die
->die_abbrev
= 0;
29711 remove_AT (die
, DW_AT_sibling
);
29713 FOR_EACH_CHILD (die
, c
, reset_dies (c
));
29716 /* Output stuff that dwarf requires at the end of every file,
29717 and generate the DWARF-2 debugging info. */
29720 dwarf2out_finish (const char *)
29722 comdat_type_node
*ctnode
;
29723 dw_die_ref main_comp_unit_die
;
29724 unsigned char checksum
[16];
29725 char dl_section_ref
[MAX_ARTIFICIAL_LABEL_BYTES
];
29727 /* Flush out any latecomers to the limbo party. */
29728 flush_limbo_die_list ();
29732 verify_die (comp_unit_die ());
29733 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
29734 verify_die (node
->die
);
29737 /* We shouldn't have any symbols with delayed asm names for
29738 DIEs generated after early finish. */
29739 gcc_assert (deferred_asm_name
== NULL
);
29741 gen_remaining_tmpl_value_param_die_attribute ();
29743 if (flag_generate_lto
|| flag_generate_offload
)
29745 gcc_assert (flag_fat_lto_objects
|| flag_generate_offload
);
29747 /* Prune stuff so that dwarf2out_finish runs successfully
29748 for the fat part of the object. */
29749 reset_dies (comp_unit_die ());
29750 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
29751 reset_dies (node
->die
);
29753 hash_table
<comdat_type_hasher
> comdat_type_table (100);
29754 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
29756 comdat_type_node
**slot
29757 = comdat_type_table
.find_slot (ctnode
, INSERT
);
29759 /* Don't reset types twice. */
29760 if (*slot
!= HTAB_EMPTY_ENTRY
)
29763 /* Add a pointer to the line table for the main compilation unit
29764 so that the debugger can make sense of DW_AT_decl_file
29766 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
29767 reset_dies (ctnode
->root_die
);
29772 /* Reset die CU symbol so we don't output it twice. */
29773 comp_unit_die ()->die_id
.die_symbol
= NULL
;
29775 /* Remove DW_AT_macro from the early output. */
29777 remove_AT (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE
);
29779 /* Remove indirect string decisions. */
29780 debug_str_hash
->traverse
<void *, reset_indirect_string
> (NULL
);
29783 #if ENABLE_ASSERT_CHECKING
29785 dw_die_ref die
= comp_unit_die (), c
;
29786 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
29789 resolve_addr (comp_unit_die ());
29790 move_marked_base_types ();
29792 /* Initialize sections and labels used for actual assembler output. */
29793 init_sections_and_labels (false);
29795 /* Traverse the DIE's and add sibling attributes to those DIE's that
29797 add_sibling_attributes (comp_unit_die ());
29798 limbo_die_node
*node
;
29799 for (node
= cu_die_list
; node
; node
= node
->next
)
29800 add_sibling_attributes (node
->die
);
29801 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
29802 add_sibling_attributes (ctnode
->root_die
);
29804 /* When splitting DWARF info, we put some attributes in the
29805 skeleton compile_unit DIE that remains in the .o, while
29806 most attributes go in the DWO compile_unit_die. */
29807 if (dwarf_split_debug_info
)
29809 limbo_die_node
*cu
;
29810 main_comp_unit_die
= gen_compile_unit_die (NULL
);
29811 if (dwarf_version
>= 5)
29812 main_comp_unit_die
->die_tag
= DW_TAG_skeleton_unit
;
29813 cu
= limbo_die_list
;
29814 gcc_assert (cu
->die
== main_comp_unit_die
);
29815 limbo_die_list
= limbo_die_list
->next
;
29816 cu
->next
= cu_die_list
;
29820 main_comp_unit_die
= comp_unit_die ();
29822 /* Output a terminator label for the .text section. */
29823 switch_to_section (text_section
);
29824 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
29825 if (cold_text_section
)
29827 switch_to_section (cold_text_section
);
29828 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
29831 /* We can only use the low/high_pc attributes if all of the code was
29833 if (!have_multiple_function_sections
29834 || (dwarf_version
< 3 && dwarf_strict
))
29836 /* Don't add if the CU has no associated code. */
29837 if (text_section_used
)
29838 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
29839 text_end_label
, true);
29845 bool range_list_added
= false;
29847 if (text_section_used
)
29848 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
29849 text_end_label
, &range_list_added
, true);
29850 if (cold_text_section_used
)
29851 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
29852 cold_end_label
, &range_list_added
, true);
29854 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
29856 if (DECL_IGNORED_P (fde
->decl
))
29858 if (!fde
->in_std_section
)
29859 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
29860 fde
->dw_fde_end
, &range_list_added
,
29862 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
29863 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
29864 fde
->dw_fde_second_end
, &range_list_added
,
29868 if (range_list_added
)
29870 /* We need to give .debug_loc and .debug_ranges an appropriate
29871 "base address". Use zero so that these addresses become
29872 absolute. Historically, we've emitted the unexpected
29873 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
29874 Emit both to give time for other tools to adapt. */
29875 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
29876 if (! dwarf_strict
&& dwarf_version
< 4)
29877 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
29883 /* AIX Assembler inserts the length, so adjust the reference to match the
29884 offset expected by debuggers. */
29885 strcpy (dl_section_ref
, debug_line_section_label
);
29886 if (XCOFF_DEBUGGING_INFO
)
29887 strcat (dl_section_ref
, DWARF_INITIAL_LENGTH_SIZE_STR
);
29889 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
29890 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
29894 add_AT_macptr (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE
,
29895 macinfo_section_label
);
29897 if (dwarf_split_debug_info
)
29899 if (have_location_lists
)
29901 if (dwarf_version
>= 5)
29902 add_AT_loclistsptr (comp_unit_die (), DW_AT_loclists_base
,
29903 loc_section_label
);
29904 /* optimize_location_lists calculates the size of the lists,
29905 so index them first, and assign indices to the entries.
29906 Although optimize_location_lists will remove entries from
29907 the table, it only does so for duplicates, and therefore
29908 only reduces ref_counts to 1. */
29909 index_location_lists (comp_unit_die ());
29912 if (addr_index_table
!= NULL
)
29914 unsigned int index
= 0;
29916 ->traverse_noresize
<unsigned int *, index_addr_table_entry
>
29922 if (have_location_lists
)
29924 optimize_location_lists (comp_unit_die ());
29925 /* And finally assign indexes to the entries for -gsplit-dwarf. */
29926 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
29927 assign_location_list_indexes (comp_unit_die ());
29930 save_macinfo_strings ();
29932 if (dwarf_split_debug_info
)
29934 unsigned int index
= 0;
29936 /* Add attributes common to skeleton compile_units and
29937 type_units. Because these attributes include strings, it
29938 must be done before freezing the string table. Top-level
29939 skeleton die attrs are added when the skeleton type unit is
29940 created, so ensure it is created by this point. */
29941 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
29942 debug_str_hash
->traverse_noresize
<unsigned int *, index_string
> (&index
);
29945 /* Output all of the compilation units. We put the main one last so that
29946 the offsets are available to output_pubnames. */
29947 for (node
= cu_die_list
; node
; node
= node
->next
)
29948 output_comp_unit (node
->die
, 0, NULL
);
29950 hash_table
<comdat_type_hasher
> comdat_type_table (100);
29951 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
29953 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
29955 /* Don't output duplicate types. */
29956 if (*slot
!= HTAB_EMPTY_ENTRY
)
29959 /* Add a pointer to the line table for the main compilation unit
29960 so that the debugger can make sense of DW_AT_decl_file
29962 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
29963 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
29964 (!dwarf_split_debug_info
29966 : debug_skeleton_line_section_label
));
29968 output_comdat_type_unit (ctnode
);
29972 /* The AT_pubnames attribute needs to go in all skeleton dies, including
29973 both the main_cu and all skeleton TUs. Making this call unconditional
29974 would end up either adding a second copy of the AT_pubnames attribute, or
29975 requiring a special case in add_top_level_skeleton_die_attrs. */
29976 if (!dwarf_split_debug_info
)
29977 add_AT_pubnames (comp_unit_die ());
29979 if (dwarf_split_debug_info
)
29982 struct md5_ctx ctx
;
29984 if (dwarf_version
>= 5 && !vec_safe_is_empty (ranges_table
))
29987 /* Compute a checksum of the comp_unit to use as the dwo_id. */
29988 md5_init_ctx (&ctx
);
29990 die_checksum (comp_unit_die (), &ctx
, &mark
);
29991 unmark_all_dies (comp_unit_die ());
29992 md5_finish_ctx (&ctx
, checksum
);
29994 if (dwarf_version
< 5)
29996 /* Use the first 8 bytes of the checksum as the dwo_id,
29997 and add it to both comp-unit DIEs. */
29998 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
29999 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
30002 /* Add the base offset of the ranges table to the skeleton
30004 if (!vec_safe_is_empty (ranges_table
))
30006 if (dwarf_version
>= 5)
30007 add_AT_lineptr (main_comp_unit_die
, DW_AT_rnglists_base
,
30008 ranges_base_label
);
30010 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
30011 ranges_section_label
);
30014 switch_to_section (debug_addr_section
);
30015 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
30016 output_addr_table ();
30019 /* Output the main compilation unit if non-empty or if .debug_macinfo
30020 or .debug_macro will be emitted. */
30021 output_comp_unit (comp_unit_die (), have_macinfo
,
30022 dwarf_split_debug_info
? checksum
: NULL
);
30024 if (dwarf_split_debug_info
&& info_section_emitted
)
30025 output_skeleton_debug_sections (main_comp_unit_die
, checksum
);
30027 /* Output the abbreviation table. */
30028 if (vec_safe_length (abbrev_die_table
) != 1)
30030 switch_to_section (debug_abbrev_section
);
30031 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
30032 output_abbrev_section ();
30035 /* Output location list section if necessary. */
30036 if (have_location_lists
)
30038 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
30039 char l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
30040 /* Output the location lists info. */
30041 switch_to_section (debug_loc_section
);
30042 if (dwarf_version
>= 5)
30044 ASM_GENERATE_INTERNAL_LABEL (l1
, DEBUG_LOC_SECTION_LABEL
, 1);
30045 ASM_GENERATE_INTERNAL_LABEL (l2
, DEBUG_LOC_SECTION_LABEL
, 2);
30046 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
30047 dw2_asm_output_data (4, 0xffffffff,
30048 "Initial length escape value indicating "
30049 "64-bit DWARF extension");
30050 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
30051 "Length of Location Lists");
30052 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
30053 dw2_asm_output_data (2, dwarf_version
, "DWARF Version");
30054 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
30055 dw2_asm_output_data (1, 0, "Segment Size");
30056 dw2_asm_output_data (4, dwarf_split_debug_info
? loc_list_idx
: 0,
30057 "Offset Entry Count");
30059 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
30060 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
30062 unsigned int save_loc_list_idx
= loc_list_idx
;
30064 output_loclists_offsets (comp_unit_die ());
30065 gcc_assert (save_loc_list_idx
== loc_list_idx
);
30067 output_location_lists (comp_unit_die ());
30068 if (dwarf_version
>= 5)
30069 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
30072 output_pubtables ();
30074 /* Output the address range information if a CU (.debug_info section)
30075 was emitted. We output an empty table even if we had no functions
30076 to put in it. This because the consumer has no way to tell the
30077 difference between an empty table that we omitted and failure to
30078 generate a table that would have contained data. */
30079 if (info_section_emitted
)
30081 switch_to_section (debug_aranges_section
);
30085 /* Output ranges section if necessary. */
30086 if (!vec_safe_is_empty (ranges_table
))
30088 if (dwarf_version
>= 5)
30089 output_rnglists ();
30094 /* Have to end the macro section. */
30097 switch_to_section (debug_macinfo_section
);
30098 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
30099 output_macinfo (!dwarf_split_debug_info
? debug_line_section_label
30100 : debug_skeleton_line_section_label
, false);
30101 dw2_asm_output_data (1, 0, "End compilation unit");
30104 /* Output the source line correspondence table. We must do this
30105 even if there is no line information. Otherwise, on an empty
30106 translation unit, we will generate a present, but empty,
30107 .debug_info section. IRIX 6.5 `nm' will then complain when
30108 examining the file. This is done late so that any filenames
30109 used by the debug_info section are marked as 'used'. */
30110 switch_to_section (debug_line_section
);
30111 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
30112 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
30113 output_line_info (false);
30115 if (dwarf_split_debug_info
&& info_section_emitted
)
30117 switch_to_section (debug_skeleton_line_section
);
30118 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
30119 output_line_info (true);
30122 /* If we emitted any indirect strings, output the string table too. */
30123 if (debug_str_hash
|| skeleton_debug_str_hash
)
30124 output_indirect_strings ();
30125 if (debug_line_str_hash
)
30127 switch_to_section (debug_line_str_section
);
30128 const enum dwarf_form form
= DW_FORM_line_strp
;
30129 debug_line_str_hash
->traverse
<enum dwarf_form
,
30130 output_indirect_string
> (form
);
30134 /* Returns a hash value for X (which really is a variable_value_struct). */
30137 variable_value_hasher::hash (variable_value_struct
*x
)
30139 return (hashval_t
) x
->decl_id
;
30142 /* Return nonzero if decl_id of variable_value_struct X is the same as
30146 variable_value_hasher::equal (variable_value_struct
*x
, tree y
)
30148 return x
->decl_id
== DECL_UID (y
);
30151 /* Helper function for resolve_variable_value, handle
30152 DW_OP_GNU_variable_value in one location expression.
30153 Return true if exprloc has been changed into loclist. */
30156 resolve_variable_value_in_expr (dw_attr_node
*a
, dw_loc_descr_ref loc
)
30158 dw_loc_descr_ref next
;
30159 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= next
)
30161 next
= loc
->dw_loc_next
;
30162 if (loc
->dw_loc_opc
!= DW_OP_GNU_variable_value
30163 || loc
->dw_loc_oprnd1
.val_class
!= dw_val_class_decl_ref
)
30166 tree decl
= loc
->dw_loc_oprnd1
.v
.val_decl_ref
;
30167 if (DECL_CONTEXT (decl
) != current_function_decl
)
30170 dw_die_ref ref
= lookup_decl_die (decl
);
30173 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
30174 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
30175 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
30178 dw_loc_list_ref l
= loc_list_from_tree (decl
, 0, NULL
);
30181 if (l
->dw_loc_next
)
30183 if (AT_class (a
) != dw_val_class_loc
)
30185 switch (a
->dw_attr
)
30187 /* Following attributes allow both exprloc and loclist
30188 classes, so we can change them into a loclist. */
30189 case DW_AT_location
:
30190 case DW_AT_string_length
:
30191 case DW_AT_return_addr
:
30192 case DW_AT_data_member_location
:
30193 case DW_AT_frame_base
:
30194 case DW_AT_segment
:
30195 case DW_AT_static_link
:
30196 case DW_AT_use_location
:
30197 case DW_AT_vtable_elem_location
:
30200 prev
->dw_loc_next
= NULL
;
30201 prepend_loc_descr_to_each (l
, AT_loc (a
));
30204 add_loc_descr_to_each (l
, next
);
30205 a
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
30206 a
->dw_attr_val
.val_entry
= NULL
;
30207 a
->dw_attr_val
.v
.val_loc_list
= l
;
30208 have_location_lists
= true;
30210 /* Following attributes allow both exprloc and reference,
30211 so if the whole expression is DW_OP_GNU_variable_value alone
30212 we could transform it into reference. */
30213 case DW_AT_byte_size
:
30214 case DW_AT_bit_size
:
30215 case DW_AT_lower_bound
:
30216 case DW_AT_upper_bound
:
30217 case DW_AT_bit_stride
:
30219 case DW_AT_allocated
:
30220 case DW_AT_associated
:
30221 case DW_AT_byte_stride
:
30222 if (prev
== NULL
&& next
== NULL
)
30230 /* Create DW_TAG_variable that we can refer to. */
30231 gen_decl_die (decl
, NULL_TREE
, NULL
,
30232 lookup_decl_die (current_function_decl
));
30233 ref
= lookup_decl_die (decl
);
30236 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
30237 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
30238 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
30244 prev
->dw_loc_next
= l
->expr
;
30245 add_loc_descr (&prev
->dw_loc_next
, next
);
30246 free_loc_descr (loc
, NULL
);
30247 next
= prev
->dw_loc_next
;
30251 memcpy (loc
, l
->expr
, sizeof (dw_loc_descr_node
));
30252 add_loc_descr (&loc
, next
);
30260 /* Attempt to resolve DW_OP_GNU_variable_value using loc_list_from_tree. */
30263 resolve_variable_value (dw_die_ref die
)
30266 dw_loc_list_ref loc
;
30269 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
30270 switch (AT_class (a
))
30272 case dw_val_class_loc
:
30273 if (!resolve_variable_value_in_expr (a
, AT_loc (a
)))
30276 case dw_val_class_loc_list
:
30277 loc
= AT_loc_list (a
);
30279 for (; loc
; loc
= loc
->dw_loc_next
)
30280 resolve_variable_value_in_expr (a
, loc
->expr
);
30287 /* Attempt to optimize DW_OP_GNU_variable_value refering to
30288 temporaries in the current function. */
30291 resolve_variable_values (void)
30293 if (!variable_value_hash
|| !current_function_decl
)
30296 struct variable_value_struct
*node
30297 = variable_value_hash
->find_with_hash (current_function_decl
,
30298 DECL_UID (current_function_decl
));
30305 FOR_EACH_VEC_SAFE_ELT (node
->dies
, i
, die
)
30306 resolve_variable_value (die
);
30309 /* Helper function for note_variable_value, handle one location
30313 note_variable_value_in_expr (dw_die_ref die
, dw_loc_descr_ref loc
)
30315 for (; loc
; loc
= loc
->dw_loc_next
)
30316 if (loc
->dw_loc_opc
== DW_OP_GNU_variable_value
30317 && loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
30319 tree decl
= loc
->dw_loc_oprnd1
.v
.val_decl_ref
;
30320 dw_die_ref ref
= lookup_decl_die (decl
);
30321 if (! ref
&& (flag_generate_lto
|| flag_generate_offload
))
30323 /* ??? This is somewhat a hack because we do not create DIEs
30324 for variables not in BLOCK trees early but when generating
30325 early LTO output we need the dw_val_class_decl_ref to be
30326 fully resolved. For fat LTO objects we'd also like to
30327 undo this after LTO dwarf output. */
30328 gcc_assert (DECL_CONTEXT (decl
));
30329 dw_die_ref ctx
= lookup_decl_die (DECL_CONTEXT (decl
));
30330 gcc_assert (ctx
!= NULL
);
30331 gen_decl_die (decl
, NULL_TREE
, NULL
, ctx
);
30332 ref
= lookup_decl_die (decl
);
30333 gcc_assert (ref
!= NULL
);
30337 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
30338 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
30339 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
30343 && DECL_CONTEXT (decl
)
30344 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
30345 && lookup_decl_die (DECL_CONTEXT (decl
)))
30347 if (!variable_value_hash
)
30348 variable_value_hash
30349 = hash_table
<variable_value_hasher
>::create_ggc (10);
30351 tree fndecl
= DECL_CONTEXT (decl
);
30352 struct variable_value_struct
*node
;
30353 struct variable_value_struct
**slot
30354 = variable_value_hash
->find_slot_with_hash (fndecl
,
30359 node
= ggc_cleared_alloc
<variable_value_struct
> ();
30360 node
->decl_id
= DECL_UID (fndecl
);
30366 vec_safe_push (node
->dies
, die
);
30371 /* Walk the tree DIE and note DIEs with DW_OP_GNU_variable_value still
30372 with dw_val_class_decl_ref operand. */
30375 note_variable_value (dw_die_ref die
)
30379 dw_loc_list_ref loc
;
30382 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
30383 switch (AT_class (a
))
30385 case dw_val_class_loc_list
:
30386 loc
= AT_loc_list (a
);
30388 if (!loc
->noted_variable_value
)
30390 loc
->noted_variable_value
= 1;
30391 for (; loc
; loc
= loc
->dw_loc_next
)
30392 note_variable_value_in_expr (die
, loc
->expr
);
30395 case dw_val_class_loc
:
30396 note_variable_value_in_expr (die
, AT_loc (a
));
30402 /* Mark children. */
30403 FOR_EACH_CHILD (die
, c
, note_variable_value (c
));
30406 /* Perform any cleanups needed after the early debug generation pass
30410 dwarf2out_early_finish (const char *filename
)
30414 /* PCH might result in DW_AT_producer string being restored from the
30415 header compilation, so always fill it with empty string initially
30416 and overwrite only here. */
30417 dw_attr_node
*producer
= get_AT (comp_unit_die (), DW_AT_producer
);
30418 producer_string
= gen_producer_string ();
30419 producer
->dw_attr_val
.v
.val_str
->refcount
--;
30420 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
30422 /* Add the name for the main input file now. We delayed this from
30423 dwarf2out_init to avoid complications with PCH. */
30424 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
30425 add_comp_dir_attribute (comp_unit_die ());
30427 /* When emitting DWARF5 .debug_line_str, move DW_AT_name and
30428 DW_AT_comp_dir into .debug_line_str section. */
30429 if (!DWARF2_ASM_LINE_DEBUG_INFO
30430 && dwarf_version
>= 5
30431 && DWARF5_USE_DEBUG_LINE_STR
)
30433 for (int i
= 0; i
< 2; i
++)
30435 dw_attr_node
*a
= get_AT (comp_unit_die (),
30436 i
? DW_AT_comp_dir
: DW_AT_name
);
30438 || AT_class (a
) != dw_val_class_str
30439 || strlen (AT_string (a
)) + 1 <= DWARF_OFFSET_SIZE
)
30442 if (! debug_line_str_hash
)
30443 debug_line_str_hash
30444 = hash_table
<indirect_string_hasher
>::create_ggc (10);
30446 struct indirect_string_node
*node
30447 = find_AT_string_in_table (AT_string (a
), debug_line_str_hash
);
30448 set_indirect_string (node
);
30449 node
->form
= DW_FORM_line_strp
;
30450 a
->dw_attr_val
.v
.val_str
->refcount
--;
30451 a
->dw_attr_val
.v
.val_str
= node
;
30455 /* With LTO early dwarf was really finished at compile-time, so make
30456 sure to adjust the phase after annotating the LTRANS CU DIE. */
30459 early_dwarf_finished
= true;
30463 /* Walk through the list of incomplete types again, trying once more to
30464 emit full debugging info for them. */
30465 retry_incomplete_types ();
30467 /* The point here is to flush out the limbo list so that it is empty
30468 and we don't need to stream it for LTO. */
30469 flush_limbo_die_list ();
30471 gen_scheduled_generic_parms_dies ();
30472 gen_remaining_tmpl_value_param_die_attribute ();
30474 /* Add DW_AT_linkage_name for all deferred DIEs. */
30475 for (limbo_die_node
*node
= deferred_asm_name
; node
; node
= node
->next
)
30477 tree decl
= node
->created_for
;
30478 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
30479 /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
30480 ended up in deferred_asm_name before we knew it was
30481 constant and never written to disk. */
30482 && DECL_ASSEMBLER_NAME (decl
))
30484 add_linkage_attr (node
->die
, decl
);
30485 move_linkage_attr (node
->die
);
30488 deferred_asm_name
= NULL
;
30490 if (flag_eliminate_unused_debug_types
)
30491 prune_unused_types ();
30493 /* Generate separate COMDAT sections for type DIEs. */
30494 if (use_debug_types
)
30496 break_out_comdat_types (comp_unit_die ());
30498 /* Each new type_unit DIE was added to the limbo die list when created.
30499 Since these have all been added to comdat_type_list, clear the
30501 limbo_die_list
= NULL
;
30503 /* For each new comdat type unit, copy declarations for incomplete
30504 types to make the new unit self-contained (i.e., no direct
30505 references to the main compile unit). */
30506 for (comdat_type_node
*ctnode
= comdat_type_list
;
30507 ctnode
!= NULL
; ctnode
= ctnode
->next
)
30508 copy_decls_for_unworthy_types (ctnode
->root_die
);
30509 copy_decls_for_unworthy_types (comp_unit_die ());
30511 /* In the process of copying declarations from one unit to another,
30512 we may have left some declarations behind that are no longer
30513 referenced. Prune them. */
30514 prune_unused_types ();
30517 /* Traverse the DIE's and note DIEs with DW_OP_GNU_variable_value still
30518 with dw_val_class_decl_ref operand. */
30519 note_variable_value (comp_unit_die ());
30520 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
30521 note_variable_value (node
->die
);
30522 for (comdat_type_node
*ctnode
= comdat_type_list
; ctnode
!= NULL
;
30523 ctnode
= ctnode
->next
)
30524 note_variable_value (ctnode
->root_die
);
30525 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
30526 note_variable_value (node
->die
);
30528 /* The early debug phase is now finished. */
30529 early_dwarf_finished
= true;
30531 /* Do not generate DWARF assembler now when not producing LTO bytecode. */
30532 if (!flag_generate_lto
&& !flag_generate_offload
)
30535 /* Now as we are going to output for LTO initialize sections and labels
30536 to the LTO variants. We don't need a random-seed postfix as other
30537 LTO sections as linking the LTO debug sections into one in a partial
30539 init_sections_and_labels (true);
30541 /* The output below is modeled after dwarf2out_finish with all
30542 location related output removed and some LTO specific changes.
30543 Some refactoring might make both smaller and easier to match up. */
30545 /* Traverse the DIE's and add add sibling attributes to those DIE's
30546 that have children. */
30547 add_sibling_attributes (comp_unit_die ());
30548 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
30549 add_sibling_attributes (node
->die
);
30550 for (comdat_type_node
*ctnode
= comdat_type_list
;
30551 ctnode
!= NULL
; ctnode
= ctnode
->next
)
30552 add_sibling_attributes (ctnode
->root_die
);
30555 add_AT_macptr (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE
,
30556 macinfo_section_label
);
30558 save_macinfo_strings ();
30560 /* Output all of the compilation units. We put the main one last so that
30561 the offsets are available to output_pubnames. */
30562 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
30563 output_comp_unit (node
->die
, 0, NULL
);
30565 hash_table
<comdat_type_hasher
> comdat_type_table (100);
30566 for (comdat_type_node
*ctnode
= comdat_type_list
;
30567 ctnode
!= NULL
; ctnode
= ctnode
->next
)
30569 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
30571 /* Don't output duplicate types. */
30572 if (*slot
!= HTAB_EMPTY_ENTRY
)
30575 /* Add a pointer to the line table for the main compilation unit
30576 so that the debugger can make sense of DW_AT_decl_file
30578 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
30579 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
30580 (!dwarf_split_debug_info
30581 ? debug_line_section_label
30582 : debug_skeleton_line_section_label
));
30584 output_comdat_type_unit (ctnode
);
30588 /* The AT_pubnames attribute needs to go in all skeleton dies, including
30589 both the main_cu and all skeleton TUs. Making this call unconditional
30590 would end up either adding a second copy of the AT_pubnames attribute, or
30591 requiring a special case in add_top_level_skeleton_die_attrs. */
30592 if (!dwarf_split_debug_info
)
30593 add_AT_pubnames (comp_unit_die ());
30595 /* Stick a unique symbol to the main debuginfo section. */
30596 compute_comp_unit_symbol (comp_unit_die ());
30598 /* Output the main compilation unit. We always need it if only for
30600 output_comp_unit (comp_unit_die (), true, NULL
);
30602 /* Output the abbreviation table. */
30603 if (vec_safe_length (abbrev_die_table
) != 1)
30605 switch_to_section (debug_abbrev_section
);
30606 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
30607 output_abbrev_section ();
30610 /* Have to end the macro section. */
30613 /* We have to save macinfo state if we need to output it again
30614 for the FAT part of the object. */
30615 vec
<macinfo_entry
, va_gc
> *saved_macinfo_table
= macinfo_table
;
30616 if (flag_fat_lto_objects
)
30617 macinfo_table
= macinfo_table
->copy ();
30619 switch_to_section (debug_macinfo_section
);
30620 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
30621 output_macinfo (debug_skeleton_line_section_label
, true);
30622 dw2_asm_output_data (1, 0, "End compilation unit");
30624 /* Emit a skeleton debug_line section. */
30625 switch_to_section (debug_skeleton_line_section
);
30626 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
30627 output_line_info (true);
30629 if (flag_fat_lto_objects
)
30631 vec_free (macinfo_table
);
30632 macinfo_table
= saved_macinfo_table
;
30637 /* If we emitted any indirect strings, output the string table too. */
30638 if (debug_str_hash
|| skeleton_debug_str_hash
)
30639 output_indirect_strings ();
30641 /* Switch back to the text section. */
30642 switch_to_section (text_section
);
30645 /* Reset all state within dwarf2out.c so that we can rerun the compiler
30646 within the same process. For use by toplev::finalize. */
30649 dwarf2out_c_finalize (void)
30651 last_var_location_insn
= NULL
;
30652 cached_next_real_insn
= NULL
;
30653 used_rtx_array
= NULL
;
30654 incomplete_types
= NULL
;
30655 decl_scope_table
= NULL
;
30656 debug_info_section
= NULL
;
30657 debug_skeleton_info_section
= NULL
;
30658 debug_abbrev_section
= NULL
;
30659 debug_skeleton_abbrev_section
= NULL
;
30660 debug_aranges_section
= NULL
;
30661 debug_addr_section
= NULL
;
30662 debug_macinfo_section
= NULL
;
30663 debug_line_section
= NULL
;
30664 debug_skeleton_line_section
= NULL
;
30665 debug_loc_section
= NULL
;
30666 debug_pubnames_section
= NULL
;
30667 debug_pubtypes_section
= NULL
;
30668 debug_str_section
= NULL
;
30669 debug_line_str_section
= NULL
;
30670 debug_str_dwo_section
= NULL
;
30671 debug_str_offsets_section
= NULL
;
30672 debug_ranges_section
= NULL
;
30673 debug_frame_section
= NULL
;
30675 debug_str_hash
= NULL
;
30676 debug_line_str_hash
= NULL
;
30677 skeleton_debug_str_hash
= NULL
;
30678 dw2_string_counter
= 0;
30679 have_multiple_function_sections
= false;
30680 text_section_used
= false;
30681 cold_text_section_used
= false;
30682 cold_text_section
= NULL
;
30683 current_unit_personality
= NULL
;
30685 early_dwarf
= false;
30686 early_dwarf_finished
= false;
30688 next_die_offset
= 0;
30689 single_comp_unit_die
= NULL
;
30690 comdat_type_list
= NULL
;
30691 limbo_die_list
= NULL
;
30693 decl_die_table
= NULL
;
30694 common_block_die_table
= NULL
;
30695 decl_loc_table
= NULL
;
30696 call_arg_locations
= NULL
;
30697 call_arg_loc_last
= NULL
;
30698 call_site_count
= -1;
30699 tail_call_site_count
= -1;
30700 cached_dw_loc_list_table
= NULL
;
30701 abbrev_die_table
= NULL
;
30702 delete dwarf_proc_stack_usage_map
;
30703 dwarf_proc_stack_usage_map
= NULL
;
30704 line_info_label_num
= 0;
30705 cur_line_info_table
= NULL
;
30706 text_section_line_info
= NULL
;
30707 cold_text_section_line_info
= NULL
;
30708 separate_line_info
= NULL
;
30709 info_section_emitted
= false;
30710 pubname_table
= NULL
;
30711 pubtype_table
= NULL
;
30712 macinfo_table
= NULL
;
30713 ranges_table
= NULL
;
30714 ranges_by_label
= NULL
;
30716 have_location_lists
= false;
30719 last_emitted_file
= NULL
;
30721 tmpl_value_parm_die_table
= NULL
;
30722 generic_type_instances
= NULL
;
30723 frame_pointer_fb_offset
= 0;
30724 frame_pointer_fb_offset_valid
= false;
30725 base_types
.release ();
30726 XDELETEVEC (producer_string
);
30727 producer_string
= NULL
;
30730 #include "gt-dwarf2out.h"