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 40
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. */
266 static GTY(()) bool text_section_used
= false;
267 static GTY(()) bool cold_text_section_used
= false;
269 /* The default cold text section. */
270 static GTY(()) section
*cold_text_section
;
272 /* The DIE for C++14 'auto' in a function return type. */
273 static GTY(()) dw_die_ref auto_die
;
275 /* The DIE for C++14 'decltype(auto)' in a function return type. */
276 static GTY(()) dw_die_ref decltype_auto_die
;
278 /* Forward declarations for functions defined in this file. */
280 static void output_call_frame_info (int);
281 static void dwarf2out_note_section_used (void);
283 /* Personality decl of current unit. Used only when assembler does not support
285 static GTY(()) rtx current_unit_personality
;
287 /* Whether an eh_frame section is required. */
288 static GTY(()) bool do_eh_frame
= false;
290 /* .debug_rnglists next index. */
291 static unsigned int rnglist_idx
;
293 /* Data and reference forms for relocatable data. */
294 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
295 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
297 #ifndef DEBUG_FRAME_SECTION
298 #define DEBUG_FRAME_SECTION ".debug_frame"
301 #ifndef FUNC_BEGIN_LABEL
302 #define FUNC_BEGIN_LABEL "LFB"
305 #ifndef FUNC_END_LABEL
306 #define FUNC_END_LABEL "LFE"
309 #ifndef PROLOGUE_END_LABEL
310 #define PROLOGUE_END_LABEL "LPE"
313 #ifndef EPILOGUE_BEGIN_LABEL
314 #define EPILOGUE_BEGIN_LABEL "LEB"
317 #ifndef FRAME_BEGIN_LABEL
318 #define FRAME_BEGIN_LABEL "Lframe"
320 #define CIE_AFTER_SIZE_LABEL "LSCIE"
321 #define CIE_END_LABEL "LECIE"
322 #define FDE_LABEL "LSFDE"
323 #define FDE_AFTER_SIZE_LABEL "LASFDE"
324 #define FDE_END_LABEL "LEFDE"
325 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
326 #define LINE_NUMBER_END_LABEL "LELT"
327 #define LN_PROLOG_AS_LABEL "LASLTP"
328 #define LN_PROLOG_END_LABEL "LELTP"
329 #define DIE_LABEL_PREFIX "DW"
331 /* Match the base name of a file to the base name of a compilation unit. */
334 matches_main_base (const char *path
)
336 /* Cache the last query. */
337 static const char *last_path
= NULL
;
338 static int last_match
= 0;
339 if (path
!= last_path
)
342 int length
= base_of_path (path
, &base
);
344 last_match
= (length
== main_input_baselength
345 && memcmp (base
, main_input_basename
, length
) == 0);
350 #ifdef DEBUG_DEBUG_STRUCT
353 dump_struct_debug (tree type
, enum debug_info_usage usage
,
354 enum debug_struct_file criterion
, int generic
,
355 int matches
, int result
)
357 /* Find the type name. */
358 tree type_decl
= TYPE_STUB_DECL (type
);
360 const char *name
= 0;
361 if (TREE_CODE (t
) == TYPE_DECL
)
364 name
= IDENTIFIER_POINTER (t
);
366 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
368 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
369 matches
? "bas" : "hdr",
370 generic
? "gen" : "ord",
371 usage
== DINFO_USAGE_DFN
? ";" :
372 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
374 (void*) type_decl
, name
);
377 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
378 dump_struct_debug (type, usage, criterion, generic, matches, result)
382 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
387 /* Get the number of HOST_WIDE_INTs needed to represent the precision
388 of the number. Some constants have a large uniform precision, so
389 we get the precision needed for the actual value of the number. */
392 get_full_len (const wide_int
&op
)
394 int prec
= wi::min_precision (op
, UNSIGNED
);
395 return ((prec
+ HOST_BITS_PER_WIDE_INT
- 1)
396 / HOST_BITS_PER_WIDE_INT
);
400 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
402 enum debug_struct_file criterion
;
404 bool generic
= lang_hooks
.types
.generic_p (type
);
407 criterion
= debug_struct_generic
[usage
];
409 criterion
= debug_struct_ordinary
[usage
];
411 if (criterion
== DINFO_STRUCT_FILE_NONE
)
412 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
413 if (criterion
== DINFO_STRUCT_FILE_ANY
)
414 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
416 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
418 if (type_decl
!= NULL
)
420 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
421 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
423 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
424 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
427 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
430 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
431 switch to the data section instead, and write out a synthetic start label
432 for collect2 the first time around. */
435 switch_to_eh_frame_section (bool back ATTRIBUTE_UNUSED
)
437 if (eh_frame_section
== 0)
441 if (EH_TABLES_CAN_BE_READ_ONLY
)
447 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
449 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
451 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
454 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
455 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
456 && (per_encoding
& 0x70) != DW_EH_PE_absptr
457 && (per_encoding
& 0x70) != DW_EH_PE_aligned
458 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
459 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
460 ? 0 : SECTION_WRITE
);
463 flags
= SECTION_WRITE
;
465 #ifdef EH_FRAME_SECTION_NAME
466 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
468 eh_frame_section
= ((flags
== SECTION_WRITE
)
469 ? data_section
: readonly_data_section
);
470 #endif /* EH_FRAME_SECTION_NAME */
473 switch_to_section (eh_frame_section
);
475 #ifdef EH_FRAME_THROUGH_COLLECT2
476 /* We have no special eh_frame section. Emit special labels to guide
480 tree label
= get_file_function_name ("F");
481 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
482 targetm
.asm_out
.globalize_label (asm_out_file
,
483 IDENTIFIER_POINTER (label
));
484 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
489 /* Switch [BACK] to the eh or debug frame table section, depending on
493 switch_to_frame_table_section (int for_eh
, bool back
)
496 switch_to_eh_frame_section (back
);
499 if (!debug_frame_section
)
500 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
501 SECTION_DEBUG
, NULL
);
502 switch_to_section (debug_frame_section
);
506 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
508 enum dw_cfi_oprnd_type
509 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
514 case DW_CFA_GNU_window_save
:
515 case DW_CFA_remember_state
:
516 case DW_CFA_restore_state
:
517 return dw_cfi_oprnd_unused
;
520 case DW_CFA_advance_loc1
:
521 case DW_CFA_advance_loc2
:
522 case DW_CFA_advance_loc4
:
523 case DW_CFA_MIPS_advance_loc8
:
524 return dw_cfi_oprnd_addr
;
527 case DW_CFA_offset_extended
:
529 case DW_CFA_offset_extended_sf
:
530 case DW_CFA_def_cfa_sf
:
532 case DW_CFA_restore_extended
:
533 case DW_CFA_undefined
:
534 case DW_CFA_same_value
:
535 case DW_CFA_def_cfa_register
:
536 case DW_CFA_register
:
537 case DW_CFA_expression
:
538 case DW_CFA_val_expression
:
539 return dw_cfi_oprnd_reg_num
;
541 case DW_CFA_def_cfa_offset
:
542 case DW_CFA_GNU_args_size
:
543 case DW_CFA_def_cfa_offset_sf
:
544 return dw_cfi_oprnd_offset
;
546 case DW_CFA_def_cfa_expression
:
547 return dw_cfi_oprnd_loc
;
554 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
556 enum dw_cfi_oprnd_type
557 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
562 case DW_CFA_def_cfa_sf
:
564 case DW_CFA_offset_extended_sf
:
565 case DW_CFA_offset_extended
:
566 return dw_cfi_oprnd_offset
;
568 case DW_CFA_register
:
569 return dw_cfi_oprnd_reg_num
;
571 case DW_CFA_expression
:
572 case DW_CFA_val_expression
:
573 return dw_cfi_oprnd_loc
;
576 return dw_cfi_oprnd_unused
;
580 /* Output one FDE. */
583 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
584 char *section_start_label
, int fde_encoding
, char *augmentation
,
585 bool any_lsda_needed
, int lsda_encoding
)
587 const char *begin
, *end
;
588 static unsigned int j
;
589 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
591 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
593 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
595 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
596 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
597 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
599 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
600 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
601 " indicating 64-bit DWARF extension");
602 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
605 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
608 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
610 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
611 debug_frame_section
, "FDE CIE offset");
613 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
614 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
618 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
619 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
620 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
621 "FDE initial location");
622 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
623 end
, begin
, "FDE address range");
627 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
628 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
635 int size
= size_of_encoded_value (lsda_encoding
);
637 if (lsda_encoding
== DW_EH_PE_aligned
)
639 int offset
= ( 4 /* Length */
641 + 2 * size_of_encoded_value (fde_encoding
)
642 + 1 /* Augmentation size */ );
643 int pad
= -offset
& (PTR_SIZE
- 1);
646 gcc_assert (size_of_uleb128 (size
) == 1);
649 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
651 if (fde
->uses_eh_lsda
)
653 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
654 fde
->funcdef_number
);
655 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
656 gen_rtx_SYMBOL_REF (Pmode
, l1
),
658 "Language Specific Data Area");
662 if (lsda_encoding
== DW_EH_PE_aligned
)
663 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
664 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
665 "Language Specific Data Area (none)");
669 dw2_asm_output_data_uleb128 (0, "Augmentation size");
672 /* Loop through the Call Frame Instructions associated with this FDE. */
673 fde
->dw_fde_current_label
= begin
;
675 size_t from
, until
, i
;
678 until
= vec_safe_length (fde
->dw_fde_cfi
);
680 if (fde
->dw_fde_second_begin
== NULL
)
683 until
= fde
->dw_fde_switch_cfi_index
;
685 from
= fde
->dw_fde_switch_cfi_index
;
687 for (i
= from
; i
< until
; i
++)
688 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
691 /* If we are to emit a ref/link from function bodies to their frame tables,
692 do it now. This is typically performed to make sure that tables
693 associated with functions are dragged with them and not discarded in
694 garbage collecting links. We need to do this on a per function basis to
695 cope with -ffunction-sections. */
697 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
698 /* Switch to the function section, emit the ref to the tables, and
699 switch *back* into the table section. */
700 switch_to_section (function_section (fde
->decl
));
701 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
702 switch_to_frame_table_section (for_eh
, true);
705 /* Pad the FDE out to an address sized boundary. */
706 ASM_OUTPUT_ALIGN (asm_out_file
,
707 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
708 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
713 /* Return true if frame description entry FDE is needed for EH. */
716 fde_needed_for_eh_p (dw_fde_ref fde
)
718 if (flag_asynchronous_unwind_tables
)
721 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
724 if (fde
->uses_eh_lsda
)
727 /* If exceptions are enabled, we have collected nothrow info. */
728 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
734 /* Output the call frame information used to record information
735 that relates to calculating the frame pointer, and records the
736 location of saved registers. */
739 output_call_frame_info (int for_eh
)
744 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
745 char section_start_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
746 bool any_lsda_needed
= false;
747 char augmentation
[6];
748 int augmentation_size
;
749 int fde_encoding
= DW_EH_PE_absptr
;
750 int per_encoding
= DW_EH_PE_absptr
;
751 int lsda_encoding
= DW_EH_PE_absptr
;
753 rtx personality
= NULL
;
756 /* Don't emit a CIE if there won't be any FDEs. */
760 /* Nothing to do if the assembler's doing it all. */
761 if (dwarf2out_do_cfi_asm ())
764 /* If we don't have any functions we'll want to unwind out of, don't emit
765 any EH unwind information. If we make FDEs linkonce, we may have to
766 emit an empty label for an FDE that wouldn't otherwise be emitted. We
767 want to avoid having an FDE kept around when the function it refers to
768 is discarded. Example where this matters: a primary function template
769 in C++ requires EH information, an explicit specialization doesn't. */
772 bool any_eh_needed
= false;
774 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
776 if (fde
->uses_eh_lsda
)
777 any_eh_needed
= any_lsda_needed
= true;
778 else if (fde_needed_for_eh_p (fde
))
779 any_eh_needed
= true;
780 else if (TARGET_USES_WEAK_UNWIND_INFO
)
781 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
788 /* We're going to be generating comments, so turn on app. */
792 /* Switch to the proper frame section, first time. */
793 switch_to_frame_table_section (for_eh
, false);
795 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
796 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
798 /* Output the CIE. */
799 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
800 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
801 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
803 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
804 dw2_asm_output_data (4, 0xffffffff,
805 "Initial length escape value indicating 64-bit DWARF extension");
806 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
807 "Length of Common Information Entry");
809 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
811 /* Now that the CIE pointer is PC-relative for EH,
812 use 0 to identify the CIE. */
813 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
814 (for_eh
? 0 : DWARF_CIE_ID
),
815 "CIE Identifier Tag");
817 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
818 use CIE version 1, unless that would produce incorrect results
819 due to overflowing the return register column. */
820 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
822 if (return_reg
>= 256 || dwarf_version
> 2)
824 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
827 augmentation_size
= 0;
829 personality
= current_unit_personality
;
835 z Indicates that a uleb128 is present to size the
836 augmentation section.
837 L Indicates the encoding (and thus presence) of
838 an LSDA pointer in the FDE augmentation.
839 R Indicates a non-default pointer encoding for
841 P Indicates the presence of an encoding + language
842 personality routine in the CIE augmentation. */
844 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
845 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
846 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
848 p
= augmentation
+ 1;
852 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
853 assemble_external_libcall (personality
);
858 augmentation_size
+= 1;
860 if (fde_encoding
!= DW_EH_PE_absptr
)
863 augmentation_size
+= 1;
865 if (p
> augmentation
+ 1)
867 augmentation
[0] = 'z';
871 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
872 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
874 int offset
= ( 4 /* Length */
876 + 1 /* CIE version */
877 + strlen (augmentation
) + 1 /* Augmentation */
878 + size_of_uleb128 (1) /* Code alignment */
879 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
881 + 1 /* Augmentation size */
882 + 1 /* Personality encoding */ );
883 int pad
= -offset
& (PTR_SIZE
- 1);
885 augmentation_size
+= pad
;
887 /* Augmentations should be small, so there's scarce need to
888 iterate for a solution. Die if we exceed one uleb128 byte. */
889 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
893 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
894 if (dw_cie_version
>= 4)
896 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
897 dw2_asm_output_data (1, 0, "CIE Segment Size");
899 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
900 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
901 "CIE Data Alignment Factor");
903 if (dw_cie_version
== 1)
904 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
906 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
910 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
913 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
914 eh_data_format_name (per_encoding
));
915 dw2_asm_output_encoded_addr_rtx (per_encoding
,
921 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
922 eh_data_format_name (lsda_encoding
));
924 if (fde_encoding
!= DW_EH_PE_absptr
)
925 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
926 eh_data_format_name (fde_encoding
));
929 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
930 output_cfi (cfi
, NULL
, for_eh
);
932 /* Pad the CIE out to an address sized boundary. */
933 ASM_OUTPUT_ALIGN (asm_out_file
,
934 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
935 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
937 /* Loop through all of the FDE's. */
938 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
942 /* Don't emit EH unwind info for leaf functions that don't need it. */
943 if (for_eh
&& !fde_needed_for_eh_p (fde
))
946 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
947 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
948 augmentation
, any_lsda_needed
, lsda_encoding
);
951 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
952 dw2_asm_output_data (4, 0, "End of Table");
954 /* Turn off app to make assembly quicker. */
959 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
962 dwarf2out_do_cfi_startproc (bool second
)
966 rtx personality
= get_personality_function (current_function_decl
);
968 fprintf (asm_out_file
, "\t.cfi_startproc\n");
972 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
975 /* ??? The GAS support isn't entirely consistent. We have to
976 handle indirect support ourselves, but PC-relative is done
977 in the assembler. Further, the assembler can't handle any
978 of the weirder relocation types. */
979 if (enc
& DW_EH_PE_indirect
)
980 ref
= dw2_force_const_mem (ref
, true);
982 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
983 output_addr_const (asm_out_file
, ref
);
984 fputc ('\n', asm_out_file
);
987 if (crtl
->uses_eh_lsda
)
989 char lab
[MAX_ARTIFICIAL_LABEL_BYTES
];
991 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
992 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
993 current_function_funcdef_no
);
994 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
995 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
997 if (enc
& DW_EH_PE_indirect
)
998 ref
= dw2_force_const_mem (ref
, true);
1000 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
1001 output_addr_const (asm_out_file
, ref
);
1002 fputc ('\n', asm_out_file
);
1006 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
1007 this allocation may be done before pass_final. */
1010 dwarf2out_alloc_current_fde (void)
1014 fde
= ggc_cleared_alloc
<dw_fde_node
> ();
1015 fde
->decl
= current_function_decl
;
1016 fde
->funcdef_number
= current_function_funcdef_no
;
1017 fde
->fde_index
= vec_safe_length (fde_vec
);
1018 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
1019 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
1020 fde
->nothrow
= crtl
->nothrow
;
1021 fde
->drap_reg
= INVALID_REGNUM
;
1022 fde
->vdrap_reg
= INVALID_REGNUM
;
1024 /* Record the FDE associated with this function. */
1026 vec_safe_push (fde_vec
, fde
);
1031 /* Output a marker (i.e. a label) for the beginning of a function, before
1035 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1036 unsigned int column ATTRIBUTE_UNUSED
,
1037 const char *file ATTRIBUTE_UNUSED
)
1039 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1045 current_function_func_begin_label
= NULL
;
1047 do_frame
= dwarf2out_do_frame ();
1049 /* ??? current_function_func_begin_label is also used by except.c for
1050 call-site information. We must emit this label if it might be used. */
1052 && (!flag_exceptions
1053 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1056 fnsec
= function_section (current_function_decl
);
1057 switch_to_section (fnsec
);
1058 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1059 current_function_funcdef_no
);
1060 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1061 current_function_funcdef_no
);
1062 dup_label
= xstrdup (label
);
1063 current_function_func_begin_label
= dup_label
;
1065 /* We can elide FDE allocation if we're not emitting frame unwind info. */
1069 /* Unlike the debug version, the EH version of frame unwind info is a per-
1070 function setting so we need to record whether we need it for the unit. */
1071 do_eh_frame
|= dwarf2out_do_eh_frame ();
1073 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1074 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1075 would include pass_dwarf2_frame. If we've not created the FDE yet,
1079 fde
= dwarf2out_alloc_current_fde ();
1081 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1082 fde
->dw_fde_begin
= dup_label
;
1083 fde
->dw_fde_current_label
= dup_label
;
1084 fde
->in_std_section
= (fnsec
== text_section
1085 || (cold_text_section
&& fnsec
== cold_text_section
));
1087 /* We only want to output line number information for the genuine dwarf2
1088 prologue case, not the eh frame case. */
1089 #ifdef DWARF2_DEBUGGING_INFO
1091 dwarf2out_source_line (line
, column
, file
, 0, true);
1094 if (dwarf2out_do_cfi_asm ())
1095 dwarf2out_do_cfi_startproc (false);
1098 rtx personality
= get_personality_function (current_function_decl
);
1099 if (!current_unit_personality
)
1100 current_unit_personality
= personality
;
1102 /* We cannot keep a current personality per function as without CFI
1103 asm, at the point where we emit the CFI data, there is no current
1104 function anymore. */
1105 if (personality
&& current_unit_personality
!= personality
)
1106 sorry ("multiple EH personalities are supported only with assemblers "
1107 "supporting .cfi_personality directive");
1111 /* Output a marker (i.e. a label) for the end of the generated code
1112 for a function prologue. This gets called *after* the prologue code has
1116 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1117 const char *file ATTRIBUTE_UNUSED
)
1119 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1121 /* Output a label to mark the endpoint of the code generated for this
1123 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1124 current_function_funcdef_no
);
1125 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1126 current_function_funcdef_no
);
1127 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1130 /* Output a marker (i.e. a label) for the beginning of the generated code
1131 for a function epilogue. This gets called *before* the prologue code has
1135 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1136 const char *file ATTRIBUTE_UNUSED
)
1138 dw_fde_ref fde
= cfun
->fde
;
1139 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1141 if (fde
->dw_fde_vms_begin_epilogue
)
1144 /* Output a label to mark the endpoint of the code generated for this
1146 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1147 current_function_funcdef_no
);
1148 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1149 current_function_funcdef_no
);
1150 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1153 /* Output a marker (i.e. a label) for the absolute end of the generated code
1154 for a function definition. This gets called *after* the epilogue code has
1158 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1159 const char *file ATTRIBUTE_UNUSED
)
1162 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1164 last_var_location_insn
= NULL
;
1165 cached_next_real_insn
= NULL
;
1167 if (dwarf2out_do_cfi_asm ())
1168 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1170 /* Output a label to mark the endpoint of the code generated for this
1172 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1173 current_function_funcdef_no
);
1174 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1176 gcc_assert (fde
!= NULL
);
1177 if (fde
->dw_fde_second_begin
== NULL
)
1178 fde
->dw_fde_end
= xstrdup (label
);
1182 dwarf2out_frame_finish (void)
1184 /* Output call frame information. */
1185 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1186 output_call_frame_info (0);
1188 /* Output another copy for the unwinder. */
1190 output_call_frame_info (1);
1193 /* Note that the current function section is being used for code. */
1196 dwarf2out_note_section_used (void)
1198 section
*sec
= current_function_section ();
1199 if (sec
== text_section
)
1200 text_section_used
= true;
1201 else if (sec
== cold_text_section
)
1202 cold_text_section_used
= true;
1205 static void var_location_switch_text_section (void);
1206 static void set_cur_line_info_table (section
*);
1209 dwarf2out_switch_text_section (void)
1212 dw_fde_ref fde
= cfun
->fde
;
1214 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1216 if (!in_cold_section_p
)
1218 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1219 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1220 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1224 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1225 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1226 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1228 have_multiple_function_sections
= true;
1230 /* There is no need to mark used sections when not debugging. */
1231 if (cold_text_section
!= NULL
)
1232 dwarf2out_note_section_used ();
1234 if (dwarf2out_do_cfi_asm ())
1235 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1237 /* Now do the real section switch. */
1238 sect
= current_function_section ();
1239 switch_to_section (sect
);
1241 fde
->second_in_std_section
1242 = (sect
== text_section
1243 || (cold_text_section
&& sect
== cold_text_section
));
1245 if (dwarf2out_do_cfi_asm ())
1246 dwarf2out_do_cfi_startproc (true);
1248 var_location_switch_text_section ();
1250 if (cold_text_section
!= NULL
)
1251 set_cur_line_info_table (sect
);
1254 /* And now, the subset of the debugging information support code necessary
1255 for emitting location expressions. */
1257 /* Data about a single source file. */
1258 struct GTY((for_user
)) dwarf_file_data
{
1259 const char * filename
;
1263 /* Describe an entry into the .debug_addr section. */
1267 ate_kind_rtx_dtprel
,
1271 struct GTY((for_user
)) addr_table_entry
{
1273 unsigned int refcount
;
1275 union addr_table_entry_struct_union
1277 rtx
GTY ((tag ("0"))) rtl
;
1278 char * GTY ((tag ("1"))) label
;
1280 GTY ((desc ("%1.kind"))) addr
;
1283 /* Location lists are ranges + location descriptions for that range,
1284 so you can track variables that are in different places over
1285 their entire life. */
1286 typedef struct GTY(()) dw_loc_list_struct
{
1287 dw_loc_list_ref dw_loc_next
;
1288 const char *begin
; /* Label and addr_entry for start of range */
1289 addr_table_entry
*begin_entry
;
1290 const char *end
; /* Label for end of range */
1291 char *ll_symbol
; /* Label for beginning of location list.
1292 Only on head of list */
1293 const char *section
; /* Section this loclist is relative to */
1294 dw_loc_descr_ref expr
;
1296 /* True if all addresses in this and subsequent lists are known to be
1299 /* True if this list has been replaced by dw_loc_next. */
1301 /* True if it has been emitted into .debug_loc* / .debug_loclists*
1303 unsigned char emitted
: 1;
1304 /* True if hash field is index rather than hash value. */
1305 unsigned char num_assigned
: 1;
1306 /* True if .debug_loclists.dwo offset has been emitted for it already. */
1307 unsigned char offset_emitted
: 1;
1308 /* True if note_variable_value_in_expr has been called on it. */
1309 unsigned char noted_variable_value
: 1;
1310 /* True if the range should be emitted even if begin and end
1315 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1316 static dw_loc_descr_ref
uint_loc_descriptor (unsigned HOST_WIDE_INT
);
1318 /* Convert a DWARF stack opcode into its string name. */
1321 dwarf_stack_op_name (unsigned int op
)
1323 const char *name
= get_DW_OP_name (op
);
1328 return "OP_<unknown>";
1331 /* Return a pointer to a newly allocated location description. Location
1332 descriptions are simple expression terms that can be strung
1333 together to form more complicated location (address) descriptions. */
1335 static inline dw_loc_descr_ref
1336 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1337 unsigned HOST_WIDE_INT oprnd2
)
1339 dw_loc_descr_ref descr
= ggc_cleared_alloc
<dw_loc_descr_node
> ();
1341 descr
->dw_loc_opc
= op
;
1342 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1343 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1344 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1345 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1346 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1347 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1352 /* Return a pointer to a newly allocated location description for
1355 static inline dw_loc_descr_ref
1356 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1359 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1362 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1365 /* Add a location description term to a location description expression. */
1368 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1370 dw_loc_descr_ref
*d
;
1372 /* Find the end of the chain. */
1373 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1379 /* Compare two location operands for exact equality. */
1382 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1384 if (a
->val_class
!= b
->val_class
)
1386 switch (a
->val_class
)
1388 case dw_val_class_none
:
1390 case dw_val_class_addr
:
1391 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1393 case dw_val_class_offset
:
1394 case dw_val_class_unsigned_const
:
1395 case dw_val_class_const
:
1396 case dw_val_class_unsigned_const_implicit
:
1397 case dw_val_class_const_implicit
:
1398 case dw_val_class_range_list
:
1399 /* These are all HOST_WIDE_INT, signed or unsigned. */
1400 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1402 case dw_val_class_loc
:
1403 return a
->v
.val_loc
== b
->v
.val_loc
;
1404 case dw_val_class_loc_list
:
1405 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1406 case dw_val_class_die_ref
:
1407 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1408 case dw_val_class_fde_ref
:
1409 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1410 case dw_val_class_lbl_id
:
1411 case dw_val_class_lineptr
:
1412 case dw_val_class_macptr
:
1413 case dw_val_class_loclistsptr
:
1414 case dw_val_class_high_pc
:
1415 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1416 case dw_val_class_str
:
1417 return a
->v
.val_str
== b
->v
.val_str
;
1418 case dw_val_class_flag
:
1419 return a
->v
.val_flag
== b
->v
.val_flag
;
1420 case dw_val_class_file
:
1421 case dw_val_class_file_implicit
:
1422 return a
->v
.val_file
== b
->v
.val_file
;
1423 case dw_val_class_decl_ref
:
1424 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1426 case dw_val_class_const_double
:
1427 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1428 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1430 case dw_val_class_wide_int
:
1431 return *a
->v
.val_wide
== *b
->v
.val_wide
;
1433 case dw_val_class_vec
:
1435 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1436 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1438 return (a_len
== b_len
1439 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1442 case dw_val_class_data8
:
1443 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1445 case dw_val_class_vms_delta
:
1446 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1447 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1449 case dw_val_class_discr_value
:
1450 return (a
->v
.val_discr_value
.pos
== b
->v
.val_discr_value
.pos
1451 && a
->v
.val_discr_value
.v
.uval
== b
->v
.val_discr_value
.v
.uval
);
1452 case dw_val_class_discr_list
:
1453 /* It makes no sense comparing two discriminant value lists. */
1459 /* Compare two location atoms for exact equality. */
1462 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1464 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1467 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1468 address size, but since we always allocate cleared storage it
1469 should be zero for other types of locations. */
1470 if (a
->dtprel
!= b
->dtprel
)
1473 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1474 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1477 /* Compare two complete location expressions for exact equality. */
1480 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1486 if (a
== NULL
|| b
== NULL
)
1488 if (!loc_descr_equal_p_1 (a
, b
))
1497 /* Add a constant OFFSET to a location expression. */
1500 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1502 dw_loc_descr_ref loc
;
1505 gcc_assert (*list_head
!= NULL
);
1510 /* Find the end of the chain. */
1511 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1515 if (loc
->dw_loc_opc
== DW_OP_fbreg
1516 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1517 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1518 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1519 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1521 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1522 offset. Don't optimize if an signed integer overflow would happen. */
1524 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1525 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1528 else if (offset
> 0)
1529 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1534 = uint_loc_descriptor (-(unsigned HOST_WIDE_INT
) offset
);
1535 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1539 /* Add a constant OFFSET to a location list. */
1542 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1545 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1546 loc_descr_plus_const (&d
->expr
, offset
);
1549 #define DWARF_REF_SIZE \
1550 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1552 /* The number of bits that can be encoded by largest DW_FORM_dataN.
1553 In DWARF4 and earlier it is DW_FORM_data8 with 64 bits, in DWARF5
1554 DW_FORM_data16 with 128 bits. */
1555 #define DWARF_LARGEST_DATA_FORM_BITS \
1556 (dwarf_version >= 5 ? 128 : 64)
1558 /* Utility inline function for construction of ops that were GNU extension
1560 static inline enum dwarf_location_atom
1561 dwarf_OP (enum dwarf_location_atom op
)
1565 case DW_OP_implicit_pointer
:
1566 if (dwarf_version
< 5)
1567 return DW_OP_GNU_implicit_pointer
;
1570 case DW_OP_entry_value
:
1571 if (dwarf_version
< 5)
1572 return DW_OP_GNU_entry_value
;
1575 case DW_OP_const_type
:
1576 if (dwarf_version
< 5)
1577 return DW_OP_GNU_const_type
;
1580 case DW_OP_regval_type
:
1581 if (dwarf_version
< 5)
1582 return DW_OP_GNU_regval_type
;
1585 case DW_OP_deref_type
:
1586 if (dwarf_version
< 5)
1587 return DW_OP_GNU_deref_type
;
1591 if (dwarf_version
< 5)
1592 return DW_OP_GNU_convert
;
1595 case DW_OP_reinterpret
:
1596 if (dwarf_version
< 5)
1597 return DW_OP_GNU_reinterpret
;
1606 /* Similarly for attributes. */
1607 static inline enum dwarf_attribute
1608 dwarf_AT (enum dwarf_attribute at
)
1612 case DW_AT_call_return_pc
:
1613 if (dwarf_version
< 5)
1614 return DW_AT_low_pc
;
1617 case DW_AT_call_tail_call
:
1618 if (dwarf_version
< 5)
1619 return DW_AT_GNU_tail_call
;
1622 case DW_AT_call_origin
:
1623 if (dwarf_version
< 5)
1624 return DW_AT_abstract_origin
;
1627 case DW_AT_call_target
:
1628 if (dwarf_version
< 5)
1629 return DW_AT_GNU_call_site_target
;
1632 case DW_AT_call_target_clobbered
:
1633 if (dwarf_version
< 5)
1634 return DW_AT_GNU_call_site_target_clobbered
;
1637 case DW_AT_call_parameter
:
1638 if (dwarf_version
< 5)
1639 return DW_AT_abstract_origin
;
1642 case DW_AT_call_value
:
1643 if (dwarf_version
< 5)
1644 return DW_AT_GNU_call_site_value
;
1647 case DW_AT_call_data_value
:
1648 if (dwarf_version
< 5)
1649 return DW_AT_GNU_call_site_data_value
;
1652 case DW_AT_call_all_calls
:
1653 if (dwarf_version
< 5)
1654 return DW_AT_GNU_all_call_sites
;
1657 case DW_AT_call_all_tail_calls
:
1658 if (dwarf_version
< 5)
1659 return DW_AT_GNU_all_tail_call_sites
;
1662 case DW_AT_dwo_name
:
1663 if (dwarf_version
< 5)
1664 return DW_AT_GNU_dwo_name
;
1673 /* And similarly for tags. */
1674 static inline enum dwarf_tag
1675 dwarf_TAG (enum dwarf_tag tag
)
1679 case DW_TAG_call_site
:
1680 if (dwarf_version
< 5)
1681 return DW_TAG_GNU_call_site
;
1684 case DW_TAG_call_site_parameter
:
1685 if (dwarf_version
< 5)
1686 return DW_TAG_GNU_call_site_parameter
;
1695 static unsigned long int get_base_type_offset (dw_die_ref
);
1697 /* Return the size of a location descriptor. */
1699 static unsigned long
1700 size_of_loc_descr (dw_loc_descr_ref loc
)
1702 unsigned long size
= 1;
1704 switch (loc
->dw_loc_opc
)
1707 size
+= DWARF2_ADDR_SIZE
;
1709 case DW_OP_GNU_addr_index
:
1710 case DW_OP_GNU_const_index
:
1711 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1712 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1731 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1734 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1739 case DW_OP_plus_uconst
:
1740 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1778 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1781 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1784 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1787 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1788 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1791 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1793 case DW_OP_bit_piece
:
1794 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1795 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1797 case DW_OP_deref_size
:
1798 case DW_OP_xderef_size
:
1807 case DW_OP_call_ref
:
1808 case DW_OP_GNU_variable_value
:
1809 size
+= DWARF_REF_SIZE
;
1811 case DW_OP_implicit_value
:
1812 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1813 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1815 case DW_OP_implicit_pointer
:
1816 case DW_OP_GNU_implicit_pointer
:
1817 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1819 case DW_OP_entry_value
:
1820 case DW_OP_GNU_entry_value
:
1822 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1823 size
+= size_of_uleb128 (op_size
) + op_size
;
1826 case DW_OP_const_type
:
1827 case DW_OP_GNU_const_type
:
1830 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1831 size
+= size_of_uleb128 (o
) + 1;
1832 switch (loc
->dw_loc_oprnd2
.val_class
)
1834 case dw_val_class_vec
:
1835 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1836 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1838 case dw_val_class_const
:
1839 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1841 case dw_val_class_const_double
:
1842 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1844 case dw_val_class_wide_int
:
1845 size
+= (get_full_len (*loc
->dw_loc_oprnd2
.v
.val_wide
)
1846 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
1853 case DW_OP_regval_type
:
1854 case DW_OP_GNU_regval_type
:
1857 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1858 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1859 + size_of_uleb128 (o
);
1862 case DW_OP_deref_type
:
1863 case DW_OP_GNU_deref_type
:
1866 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1867 size
+= 1 + size_of_uleb128 (o
);
1871 case DW_OP_reinterpret
:
1872 case DW_OP_GNU_convert
:
1873 case DW_OP_GNU_reinterpret
:
1874 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1875 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1879 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1880 size
+= size_of_uleb128 (o
);
1883 case DW_OP_GNU_parameter_ref
:
1893 /* Return the size of a series of location descriptors. */
1896 size_of_locs (dw_loc_descr_ref loc
)
1901 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1902 field, to avoid writing to a PCH file. */
1903 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1905 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1907 size
+= size_of_loc_descr (l
);
1912 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1914 l
->dw_loc_addr
= size
;
1915 size
+= size_of_loc_descr (l
);
1921 /* Return the size of the value in a DW_AT_discr_value attribute. */
1924 size_of_discr_value (dw_discr_value
*discr_value
)
1926 if (discr_value
->pos
)
1927 return size_of_uleb128 (discr_value
->v
.uval
);
1929 return size_of_sleb128 (discr_value
->v
.sval
);
1932 /* Return the size of the value in a DW_AT_discr_list attribute. */
1935 size_of_discr_list (dw_discr_list_ref discr_list
)
1939 for (dw_discr_list_ref list
= discr_list
;
1941 list
= list
->dw_discr_next
)
1943 /* One byte for the discriminant value descriptor, and then one or two
1944 LEB128 numbers, depending on whether it's a single case label or a
1947 size
+= size_of_discr_value (&list
->dw_discr_lower_bound
);
1948 if (list
->dw_discr_range
!= 0)
1949 size
+= size_of_discr_value (&list
->dw_discr_upper_bound
);
1954 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1955 static void get_ref_die_offset_label (char *, dw_die_ref
);
1956 static unsigned long int get_ref_die_offset (dw_die_ref
);
1958 /* Output location description stack opcode's operands (if any).
1959 The for_eh_or_skip parameter controls whether register numbers are
1960 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1961 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1962 info). This should be suppressed for the cases that have not been converted
1963 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1966 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1968 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1969 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1971 switch (loc
->dw_loc_opc
)
1973 #ifdef DWARF2_DEBUGGING_INFO
1976 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1981 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1982 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1984 fputc ('\n', asm_out_file
);
1989 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1994 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1995 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1997 fputc ('\n', asm_out_file
);
2002 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2003 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
2010 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2011 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2013 dw2_asm_output_data (2, offset
, NULL
);
2016 case DW_OP_implicit_value
:
2017 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2018 switch (val2
->val_class
)
2020 case dw_val_class_const
:
2021 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
2023 case dw_val_class_vec
:
2025 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2026 unsigned int len
= val2
->v
.val_vec
.length
;
2030 if (elt_size
> sizeof (HOST_WIDE_INT
))
2035 for (i
= 0, p
= (unsigned char *) val2
->v
.val_vec
.array
;
2038 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2039 "fp or vector constant word %u", i
);
2042 case dw_val_class_const_double
:
2044 unsigned HOST_WIDE_INT first
, second
;
2046 if (WORDS_BIG_ENDIAN
)
2048 first
= val2
->v
.val_double
.high
;
2049 second
= val2
->v
.val_double
.low
;
2053 first
= val2
->v
.val_double
.low
;
2054 second
= val2
->v
.val_double
.high
;
2056 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2058 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2062 case dw_val_class_wide_int
:
2065 int len
= get_full_len (*val2
->v
.val_wide
);
2066 if (WORDS_BIG_ENDIAN
)
2067 for (i
= len
- 1; i
>= 0; --i
)
2068 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2069 val2
->v
.val_wide
->elt (i
), NULL
);
2071 for (i
= 0; i
< len
; ++i
)
2072 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2073 val2
->v
.val_wide
->elt (i
), NULL
);
2076 case dw_val_class_addr
:
2077 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
2078 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
2093 case DW_OP_implicit_value
:
2094 /* We currently don't make any attempt to make sure these are
2095 aligned properly like we do for the main unwind info, so
2096 don't support emitting things larger than a byte if we're
2097 only doing unwinding. */
2102 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2105 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2108 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2111 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2113 case DW_OP_plus_uconst
:
2114 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2148 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2152 unsigned r
= val1
->v
.val_unsigned
;
2153 if (for_eh_or_skip
>= 0)
2154 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2155 gcc_assert (size_of_uleb128 (r
)
2156 == size_of_uleb128 (val1
->v
.val_unsigned
));
2157 dw2_asm_output_data_uleb128 (r
, NULL
);
2161 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2165 unsigned r
= val1
->v
.val_unsigned
;
2166 if (for_eh_or_skip
>= 0)
2167 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2168 gcc_assert (size_of_uleb128 (r
)
2169 == size_of_uleb128 (val1
->v
.val_unsigned
));
2170 dw2_asm_output_data_uleb128 (r
, NULL
);
2171 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2175 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2177 case DW_OP_bit_piece
:
2178 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2179 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
2181 case DW_OP_deref_size
:
2182 case DW_OP_xderef_size
:
2183 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2189 if (targetm
.asm_out
.output_dwarf_dtprel
)
2191 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
2194 fputc ('\n', asm_out_file
);
2201 #ifdef DWARF2_DEBUGGING_INFO
2202 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2209 case DW_OP_GNU_addr_index
:
2210 case DW_OP_GNU_const_index
:
2211 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
2212 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
2213 "(index into .debug_addr)");
2219 unsigned long die_offset
2220 = get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2221 /* Make sure the offset has been computed and that we can encode it as
2223 gcc_assert (die_offset
> 0
2224 && die_offset
<= (loc
->dw_loc_opc
== DW_OP_call2
2227 dw2_asm_output_data ((loc
->dw_loc_opc
== DW_OP_call2
) ? 2 : 4,
2232 case DW_OP_call_ref
:
2233 case DW_OP_GNU_variable_value
:
2235 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2236 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2237 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2238 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2239 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2243 case DW_OP_implicit_pointer
:
2244 case DW_OP_GNU_implicit_pointer
:
2246 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2247 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2248 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2249 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2250 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2251 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2255 case DW_OP_entry_value
:
2256 case DW_OP_GNU_entry_value
:
2257 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
2258 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
2261 case DW_OP_const_type
:
2262 case DW_OP_GNU_const_type
:
2264 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
2266 dw2_asm_output_data_uleb128 (o
, NULL
);
2267 switch (val2
->val_class
)
2269 case dw_val_class_const
:
2270 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2271 dw2_asm_output_data (1, l
, NULL
);
2272 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
2274 case dw_val_class_vec
:
2276 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2277 unsigned int len
= val2
->v
.val_vec
.length
;
2282 dw2_asm_output_data (1, l
, NULL
);
2283 if (elt_size
> sizeof (HOST_WIDE_INT
))
2288 for (i
= 0, p
= (unsigned char *) val2
->v
.val_vec
.array
;
2291 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2292 "fp or vector constant word %u", i
);
2295 case dw_val_class_const_double
:
2297 unsigned HOST_WIDE_INT first
, second
;
2298 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2300 dw2_asm_output_data (1, 2 * l
, NULL
);
2301 if (WORDS_BIG_ENDIAN
)
2303 first
= val2
->v
.val_double
.high
;
2304 second
= val2
->v
.val_double
.low
;
2308 first
= val2
->v
.val_double
.low
;
2309 second
= val2
->v
.val_double
.high
;
2311 dw2_asm_output_data (l
, first
, NULL
);
2312 dw2_asm_output_data (l
, second
, NULL
);
2315 case dw_val_class_wide_int
:
2318 int len
= get_full_len (*val2
->v
.val_wide
);
2319 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2321 dw2_asm_output_data (1, len
* l
, NULL
);
2322 if (WORDS_BIG_ENDIAN
)
2323 for (i
= len
- 1; i
>= 0; --i
)
2324 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2326 for (i
= 0; i
< len
; ++i
)
2327 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2335 case DW_OP_regval_type
:
2336 case DW_OP_GNU_regval_type
:
2338 unsigned r
= val1
->v
.val_unsigned
;
2339 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2341 if (for_eh_or_skip
>= 0)
2343 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2344 gcc_assert (size_of_uleb128 (r
)
2345 == size_of_uleb128 (val1
->v
.val_unsigned
));
2347 dw2_asm_output_data_uleb128 (r
, NULL
);
2348 dw2_asm_output_data_uleb128 (o
, NULL
);
2351 case DW_OP_deref_type
:
2352 case DW_OP_GNU_deref_type
:
2354 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2356 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2357 dw2_asm_output_data_uleb128 (o
, NULL
);
2361 case DW_OP_reinterpret
:
2362 case DW_OP_GNU_convert
:
2363 case DW_OP_GNU_reinterpret
:
2364 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2365 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2368 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2370 dw2_asm_output_data_uleb128 (o
, NULL
);
2374 case DW_OP_GNU_parameter_ref
:
2377 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2378 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2379 dw2_asm_output_data (4, o
, NULL
);
2384 /* Other codes have no operands. */
2389 /* Output a sequence of location operations.
2390 The for_eh_or_skip parameter controls whether register numbers are
2391 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2392 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2393 info). This should be suppressed for the cases that have not been converted
2394 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2397 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2399 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2401 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2402 /* Output the opcode. */
2403 if (for_eh_or_skip
>= 0
2404 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2406 unsigned r
= (opc
- DW_OP_breg0
);
2407 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2408 gcc_assert (r
<= 31);
2409 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2411 else if (for_eh_or_skip
>= 0
2412 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2414 unsigned r
= (opc
- DW_OP_reg0
);
2415 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2416 gcc_assert (r
<= 31);
2417 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2420 dw2_asm_output_data (1, opc
,
2421 "%s", dwarf_stack_op_name (opc
));
2423 /* Output the operand(s) (if any). */
2424 output_loc_operands (loc
, for_eh_or_skip
);
2428 /* Output location description stack opcode's operands (if any).
2429 The output is single bytes on a line, suitable for .cfi_escape. */
2432 output_loc_operands_raw (dw_loc_descr_ref loc
)
2434 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2435 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2437 switch (loc
->dw_loc_opc
)
2440 case DW_OP_GNU_addr_index
:
2441 case DW_OP_GNU_const_index
:
2442 case DW_OP_implicit_value
:
2443 /* We cannot output addresses in .cfi_escape, only bytes. */
2449 case DW_OP_deref_size
:
2450 case DW_OP_xderef_size
:
2451 fputc (',', asm_out_file
);
2452 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2457 fputc (',', asm_out_file
);
2458 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2463 fputc (',', asm_out_file
);
2464 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2469 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2470 fputc (',', asm_out_file
);
2471 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2479 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2480 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2482 fputc (',', asm_out_file
);
2483 dw2_asm_output_data_raw (2, offset
);
2489 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2490 gcc_assert (size_of_uleb128 (r
)
2491 == size_of_uleb128 (val1
->v
.val_unsigned
));
2492 fputc (',', asm_out_file
);
2493 dw2_asm_output_data_uleb128_raw (r
);
2498 case DW_OP_plus_uconst
:
2500 fputc (',', asm_out_file
);
2501 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2504 case DW_OP_bit_piece
:
2505 fputc (',', asm_out_file
);
2506 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2507 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2544 fputc (',', asm_out_file
);
2545 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2550 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2551 gcc_assert (size_of_uleb128 (r
)
2552 == size_of_uleb128 (val1
->v
.val_unsigned
));
2553 fputc (',', asm_out_file
);
2554 dw2_asm_output_data_uleb128_raw (r
);
2555 fputc (',', asm_out_file
);
2556 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2560 case DW_OP_implicit_pointer
:
2561 case DW_OP_entry_value
:
2562 case DW_OP_const_type
:
2563 case DW_OP_regval_type
:
2564 case DW_OP_deref_type
:
2566 case DW_OP_reinterpret
:
2567 case DW_OP_GNU_implicit_pointer
:
2568 case DW_OP_GNU_entry_value
:
2569 case DW_OP_GNU_const_type
:
2570 case DW_OP_GNU_regval_type
:
2571 case DW_OP_GNU_deref_type
:
2572 case DW_OP_GNU_convert
:
2573 case DW_OP_GNU_reinterpret
:
2574 case DW_OP_GNU_parameter_ref
:
2579 /* Other codes have no operands. */
2585 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2589 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2590 /* Output the opcode. */
2591 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2593 unsigned r
= (opc
- DW_OP_breg0
);
2594 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2595 gcc_assert (r
<= 31);
2596 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2598 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2600 unsigned r
= (opc
- DW_OP_reg0
);
2601 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2602 gcc_assert (r
<= 31);
2603 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2605 /* Output the opcode. */
2606 fprintf (asm_out_file
, "%#x", opc
);
2607 output_loc_operands_raw (loc
);
2609 if (!loc
->dw_loc_next
)
2611 loc
= loc
->dw_loc_next
;
2613 fputc (',', asm_out_file
);
2617 /* This function builds a dwarf location descriptor sequence from a
2618 dw_cfa_location, adding the given OFFSET to the result of the
2621 struct dw_loc_descr_node
*
2622 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2624 struct dw_loc_descr_node
*head
, *tmp
;
2626 offset
+= cfa
->offset
;
2630 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2631 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2632 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2633 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2634 add_loc_descr (&head
, tmp
);
2637 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2638 add_loc_descr (&head
, tmp
);
2642 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2647 /* This function builds a dwarf location descriptor sequence for
2648 the address at OFFSET from the CFA when stack is aligned to
2651 struct dw_loc_descr_node
*
2652 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2653 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2655 struct dw_loc_descr_node
*head
;
2656 unsigned int dwarf_fp
2657 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2659 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2660 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2662 head
= new_reg_loc_descr (dwarf_fp
, 0);
2663 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2664 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2665 loc_descr_plus_const (&head
, offset
);
2668 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2672 /* And now, the support for symbolic debugging information. */
2674 /* .debug_str support. */
2676 static void dwarf2out_init (const char *);
2677 static void dwarf2out_finish (const char *);
2678 static void dwarf2out_early_finish (const char *);
2679 static void dwarf2out_assembly_start (void);
2680 static void dwarf2out_define (unsigned int, const char *);
2681 static void dwarf2out_undef (unsigned int, const char *);
2682 static void dwarf2out_start_source_file (unsigned, const char *);
2683 static void dwarf2out_end_source_file (unsigned);
2684 static void dwarf2out_function_decl (tree
);
2685 static void dwarf2out_begin_block (unsigned, unsigned);
2686 static void dwarf2out_end_block (unsigned, unsigned);
2687 static bool dwarf2out_ignore_block (const_tree
);
2688 static void dwarf2out_early_global_decl (tree
);
2689 static void dwarf2out_late_global_decl (tree
);
2690 static void dwarf2out_type_decl (tree
, int);
2691 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool, bool);
2692 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2694 static void dwarf2out_abstract_function (tree
);
2695 static void dwarf2out_var_location (rtx_insn
*);
2696 static void dwarf2out_size_function (tree
);
2697 static void dwarf2out_begin_function (tree
);
2698 static void dwarf2out_end_function (unsigned int);
2699 static void dwarf2out_register_main_translation_unit (tree unit
);
2700 static void dwarf2out_set_name (tree
, tree
);
2701 static void dwarf2out_register_external_die (tree decl
, const char *sym
,
2702 unsigned HOST_WIDE_INT off
);
2703 static bool dwarf2out_die_ref_for_decl (tree decl
, const char **sym
,
2704 unsigned HOST_WIDE_INT
*off
);
2706 /* The debug hooks structure. */
2708 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2712 dwarf2out_early_finish
,
2713 dwarf2out_assembly_start
,
2716 dwarf2out_start_source_file
,
2717 dwarf2out_end_source_file
,
2718 dwarf2out_begin_block
,
2719 dwarf2out_end_block
,
2720 dwarf2out_ignore_block
,
2721 dwarf2out_source_line
,
2722 dwarf2out_begin_prologue
,
2723 #if VMS_DEBUGGING_INFO
2724 dwarf2out_vms_end_prologue
,
2725 dwarf2out_vms_begin_epilogue
,
2727 debug_nothing_int_charstar
,
2728 debug_nothing_int_charstar
,
2730 dwarf2out_end_epilogue
,
2731 dwarf2out_begin_function
,
2732 dwarf2out_end_function
, /* end_function */
2733 dwarf2out_register_main_translation_unit
,
2734 dwarf2out_function_decl
, /* function_decl */
2735 dwarf2out_early_global_decl
,
2736 dwarf2out_late_global_decl
,
2737 dwarf2out_type_decl
, /* type_decl */
2738 dwarf2out_imported_module_or_decl
,
2739 dwarf2out_die_ref_for_decl
,
2740 dwarf2out_register_external_die
,
2741 debug_nothing_tree
, /* deferred_inline_function */
2742 /* The DWARF 2 backend tries to reduce debugging bloat by not
2743 emitting the abstract description of inline functions until
2744 something tries to reference them. */
2745 dwarf2out_abstract_function
, /* outlining_inline_function */
2746 debug_nothing_rtx_code_label
, /* label */
2747 debug_nothing_int
, /* handle_pch */
2748 dwarf2out_var_location
,
2749 dwarf2out_size_function
, /* size_function */
2750 dwarf2out_switch_text_section
,
2752 1, /* start_end_main_source_file */
2753 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2756 const struct gcc_debug_hooks dwarf2_lineno_debug_hooks
=
2759 debug_nothing_charstar
,
2760 debug_nothing_charstar
,
2761 dwarf2out_assembly_start
,
2762 debug_nothing_int_charstar
,
2763 debug_nothing_int_charstar
,
2764 debug_nothing_int_charstar
,
2766 debug_nothing_int_int
, /* begin_block */
2767 debug_nothing_int_int
, /* end_block */
2768 debug_true_const_tree
, /* ignore_block */
2769 dwarf2out_source_line
, /* source_line */
2770 debug_nothing_int_int_charstar
, /* begin_prologue */
2771 debug_nothing_int_charstar
, /* end_prologue */
2772 debug_nothing_int_charstar
, /* begin_epilogue */
2773 debug_nothing_int_charstar
, /* end_epilogue */
2774 debug_nothing_tree
, /* begin_function */
2775 debug_nothing_int
, /* end_function */
2776 debug_nothing_tree
, /* register_main_translation_unit */
2777 debug_nothing_tree
, /* function_decl */
2778 debug_nothing_tree
, /* early_global_decl */
2779 debug_nothing_tree
, /* late_global_decl */
2780 debug_nothing_tree_int
, /* type_decl */
2781 debug_nothing_tree_tree_tree_bool_bool
,/* imported_module_or_decl */
2782 debug_false_tree_charstarstar_uhwistar
,/* die_ref_for_decl */
2783 debug_nothing_tree_charstar_uhwi
, /* register_external_die */
2784 debug_nothing_tree
, /* deferred_inline_function */
2785 debug_nothing_tree
, /* outlining_inline_function */
2786 debug_nothing_rtx_code_label
, /* label */
2787 debug_nothing_int
, /* handle_pch */
2788 debug_nothing_rtx_insn
, /* var_location */
2789 debug_nothing_tree
, /* size_function */
2790 debug_nothing_void
, /* switch_text_section */
2791 debug_nothing_tree_tree
, /* set_name */
2792 0, /* start_end_main_source_file */
2793 TYPE_SYMTAB_IS_ADDRESS
/* tree_type_symtab_field */
2796 /* NOTE: In the comments in this file, many references are made to
2797 "Debugging Information Entries". This term is abbreviated as `DIE'
2798 throughout the remainder of this file. */
2800 /* An internal representation of the DWARF output is built, and then
2801 walked to generate the DWARF debugging info. The walk of the internal
2802 representation is done after the entire program has been compiled.
2803 The types below are used to describe the internal representation. */
2805 /* Whether to put type DIEs into their own section .debug_types instead
2806 of making them part of the .debug_info section. Only supported for
2807 Dwarf V4 or higher and the user didn't disable them through
2808 -fno-debug-types-section. It is more efficient to put them in a
2809 separate comdat sections since the linker will then be able to
2810 remove duplicates. But not all tools support .debug_types sections
2811 yet. For Dwarf V5 or higher .debug_types doesn't exist any more,
2812 it is DW_UT_type unit type in .debug_info section. */
2814 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2816 /* Various DIE's use offsets relative to the beginning of the
2817 .debug_info section to refer to each other. */
2819 typedef long int dw_offset
;
2821 struct comdat_type_node
;
2823 /* The entries in the line_info table more-or-less mirror the opcodes
2824 that are used in the real dwarf line table. Arrays of these entries
2825 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2828 enum dw_line_info_opcode
{
2829 /* Emit DW_LNE_set_address; the operand is the label index. */
2832 /* Emit a row to the matrix with the given line. This may be done
2833 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2837 /* Emit a DW_LNS_set_file. */
2840 /* Emit a DW_LNS_set_column. */
2843 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2846 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2847 LI_set_prologue_end
,
2848 LI_set_epilogue_begin
,
2850 /* Emit a DW_LNE_set_discriminator. */
2851 LI_set_discriminator
2854 typedef struct GTY(()) dw_line_info_struct
{
2855 enum dw_line_info_opcode opcode
;
2857 } dw_line_info_entry
;
2860 struct GTY(()) dw_line_info_table
{
2861 /* The label that marks the end of this section. */
2862 const char *end_label
;
2864 /* The values for the last row of the matrix, as collected in the table.
2865 These are used to minimize the changes to the next row. */
2866 unsigned int file_num
;
2867 unsigned int line_num
;
2868 unsigned int column_num
;
2873 vec
<dw_line_info_entry
, va_gc
> *entries
;
2877 /* Each DIE attribute has a field specifying the attribute kind,
2878 a link to the next attribute in the chain, and an attribute value.
2879 Attributes are typically linked below the DIE they modify. */
2881 typedef struct GTY(()) dw_attr_struct
{
2882 enum dwarf_attribute dw_attr
;
2883 dw_val_node dw_attr_val
;
2888 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2889 The children of each node form a circular list linked by
2890 die_sib. die_child points to the node *before* the "first" child node. */
2892 typedef struct GTY((chain_circular ("%h.die_sib"), for_user
)) die_struct
{
2893 union die_symbol_or_type_node
2895 const char * GTY ((tag ("0"))) die_symbol
;
2896 comdat_type_node
*GTY ((tag ("1"))) die_type_node
;
2898 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2899 vec
<dw_attr_node
, va_gc
> *die_attr
;
2900 dw_die_ref die_parent
;
2901 dw_die_ref die_child
;
2903 dw_die_ref die_definition
; /* ref from a specification to its definition */
2904 dw_offset die_offset
;
2905 unsigned long die_abbrev
;
2907 unsigned int decl_id
;
2908 enum dwarf_tag die_tag
;
2909 /* Die is used and must not be pruned as unused. */
2910 BOOL_BITFIELD die_perennial_p
: 1;
2911 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2912 /* For an external ref to die_symbol if die_offset contains an extra
2913 offset to that symbol. */
2914 BOOL_BITFIELD with_offset
: 1;
2915 /* Whether this DIE was removed from the DIE tree, for example via
2916 prune_unused_types. We don't consider those present from the
2917 DIE lookup routines. */
2918 BOOL_BITFIELD removed
: 1;
2919 /* Lots of spare bits. */
2923 /* Set to TRUE while dwarf2out_early_global_decl is running. */
2924 static bool early_dwarf
;
2925 static bool early_dwarf_finished
;
2926 struct set_early_dwarf
{
2928 set_early_dwarf () : saved(early_dwarf
)
2930 gcc_assert (! early_dwarf_finished
);
2933 ~set_early_dwarf () { early_dwarf
= saved
; }
2936 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2937 #define FOR_EACH_CHILD(die, c, expr) do { \
2938 c = die->die_child; \
2942 } while (c != die->die_child); \
2945 /* The pubname structure */
2947 typedef struct GTY(()) pubname_struct
{
2954 struct GTY(()) dw_ranges
{
2956 /* If this is positive, it's a block number, otherwise it's a
2957 bitwise-negated index into dw_ranges_by_label. */
2959 /* Index for the range list for DW_FORM_rnglistx. */
2960 unsigned int idx
: 31;
2961 /* True if this range might be possibly in a different section
2962 from previous entry. */
2963 unsigned int maybe_new_sec
: 1;
2966 /* A structure to hold a macinfo entry. */
2968 typedef struct GTY(()) macinfo_struct
{
2970 unsigned HOST_WIDE_INT lineno
;
2976 struct GTY(()) dw_ranges_by_label
{
2981 /* The comdat type node structure. */
2982 struct GTY(()) comdat_type_node
2984 dw_die_ref root_die
;
2985 dw_die_ref type_die
;
2986 dw_die_ref skeleton_die
;
2987 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2988 comdat_type_node
*next
;
2991 /* A list of DIEs for which we can't determine ancestry (parent_die
2992 field) just yet. Later in dwarf2out_finish we will fill in the
2994 typedef struct GTY(()) limbo_die_struct
{
2996 /* The tree for which this DIE was created. We use this to
2997 determine ancestry later. */
2999 struct limbo_die_struct
*next
;
3003 typedef struct skeleton_chain_struct
3007 struct skeleton_chain_struct
*parent
;
3009 skeleton_chain_node
;
3011 /* Define a macro which returns nonzero for a TYPE_DECL which was
3012 implicitly generated for a type.
3014 Note that, unlike the C front-end (which generates a NULL named
3015 TYPE_DECL node for each complete tagged type, each array type,
3016 and each function type node created) the C++ front-end generates
3017 a _named_ TYPE_DECL node for each tagged type node created.
3018 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3019 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
3020 front-end, but for each type, tagged or not. */
3022 #define TYPE_DECL_IS_STUB(decl) \
3023 (DECL_NAME (decl) == NULL_TREE \
3024 || (DECL_ARTIFICIAL (decl) \
3025 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3026 /* This is necessary for stub decls that \
3027 appear in nested inline functions. */ \
3028 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3029 && (decl_ultimate_origin (decl) \
3030 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3032 /* Information concerning the compilation unit's programming
3033 language, and compiler version. */
3035 /* Fixed size portion of the DWARF compilation unit header. */
3036 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3037 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE \
3038 + (dwarf_version >= 5 ? 4 : 3))
3040 /* Fixed size portion of the DWARF comdat type unit header. */
3041 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
3042 (DWARF_COMPILE_UNIT_HEADER_SIZE \
3043 + DWARF_TYPE_SIGNATURE_SIZE + DWARF_OFFSET_SIZE)
3045 /* Fixed size portion of the DWARF skeleton compilation unit header. */
3046 #define DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE \
3047 (DWARF_COMPILE_UNIT_HEADER_SIZE + (dwarf_version >= 5 ? 8 : 0))
3049 /* Fixed size portion of public names info. */
3050 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3052 /* Fixed size portion of the address range info. */
3053 #define DWARF_ARANGES_HEADER_SIZE \
3054 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3055 DWARF2_ADDR_SIZE * 2) \
3056 - DWARF_INITIAL_LENGTH_SIZE)
3058 /* Size of padding portion in the address range info. It must be
3059 aligned to twice the pointer size. */
3060 #define DWARF_ARANGES_PAD_SIZE \
3061 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3062 DWARF2_ADDR_SIZE * 2) \
3063 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3065 /* Use assembler line directives if available. */
3066 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3067 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3068 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3070 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3074 /* Minimum line offset in a special line info. opcode.
3075 This value was chosen to give a reasonable range of values. */
3076 #define DWARF_LINE_BASE -10
3078 /* First special line opcode - leave room for the standard opcodes. */
3079 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
3081 /* Range of line offsets in a special line info. opcode. */
3082 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3084 /* Flag that indicates the initial value of the is_stmt_start flag.
3085 In the present implementation, we do not mark any lines as
3086 the beginning of a source statement, because that information
3087 is not made available by the GCC front-end. */
3088 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3090 /* Maximum number of operations per instruction bundle. */
3091 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
3092 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
3095 /* This location is used by calc_die_sizes() to keep track
3096 the offset of each DIE within the .debug_info section. */
3097 static unsigned long next_die_offset
;
3099 /* Record the root of the DIE's built for the current compilation unit. */
3100 static GTY(()) dw_die_ref single_comp_unit_die
;
3102 /* A list of type DIEs that have been separated into comdat sections. */
3103 static GTY(()) comdat_type_node
*comdat_type_list
;
3105 /* A list of CU DIEs that have been separated. */
3106 static GTY(()) limbo_die_node
*cu_die_list
;
3108 /* A list of DIEs with a NULL parent waiting to be relocated. */
3109 static GTY(()) limbo_die_node
*limbo_die_list
;
3111 /* A list of DIEs for which we may have to generate
3112 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
3113 static GTY(()) limbo_die_node
*deferred_asm_name
;
3115 struct dwarf_file_hasher
: ggc_ptr_hash
<dwarf_file_data
>
3117 typedef const char *compare_type
;
3119 static hashval_t
hash (dwarf_file_data
*);
3120 static bool equal (dwarf_file_data
*, const char *);
3123 /* Filenames referenced by this compilation unit. */
3124 static GTY(()) hash_table
<dwarf_file_hasher
> *file_table
;
3126 struct decl_die_hasher
: ggc_ptr_hash
<die_node
>
3128 typedef tree compare_type
;
3130 static hashval_t
hash (die_node
*);
3131 static bool equal (die_node
*, tree
);
3133 /* A hash table of references to DIE's that describe declarations.
3134 The key is a DECL_UID() which is a unique number identifying each decl. */
3135 static GTY (()) hash_table
<decl_die_hasher
> *decl_die_table
;
3137 struct GTY ((for_user
)) variable_value_struct
{
3138 unsigned int decl_id
;
3139 vec
<dw_die_ref
, va_gc
> *dies
;
3142 struct variable_value_hasher
: ggc_ptr_hash
<variable_value_struct
>
3144 typedef tree compare_type
;
3146 static hashval_t
hash (variable_value_struct
*);
3147 static bool equal (variable_value_struct
*, tree
);
3149 /* A hash table of DIEs that contain DW_OP_GNU_variable_value with
3150 dw_val_class_decl_ref class, indexed by FUNCTION_DECLs which is
3151 DECL_CONTEXT of the referenced VAR_DECLs. */
3152 static GTY (()) hash_table
<variable_value_hasher
> *variable_value_hash
;
3154 struct block_die_hasher
: ggc_ptr_hash
<die_struct
>
3156 static hashval_t
hash (die_struct
*);
3157 static bool equal (die_struct
*, die_struct
*);
3160 /* A hash table of references to DIE's that describe COMMON blocks.
3161 The key is DECL_UID() ^ die_parent. */
3162 static GTY (()) hash_table
<block_die_hasher
> *common_block_die_table
;
3164 typedef struct GTY(()) die_arg_entry_struct
{
3170 /* Node of the variable location list. */
3171 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
3172 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
3173 EXPR_LIST chain. For small bitsizes, bitsize is encoded
3174 in mode of the EXPR_LIST node and first EXPR_LIST operand
3175 is either NOTE_INSN_VAR_LOCATION for a piece with a known
3176 location or NULL for padding. For larger bitsizes,
3177 mode is 0 and first operand is a CONCAT with bitsize
3178 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
3179 NULL as second operand. */
3181 const char * GTY (()) label
;
3182 struct var_loc_node
* GTY (()) next
;
3185 /* Variable location list. */
3186 struct GTY ((for_user
)) var_loc_list_def
{
3187 struct var_loc_node
* GTY (()) first
;
3189 /* Pointer to the last but one or last element of the
3190 chained list. If the list is empty, both first and
3191 last are NULL, if the list contains just one node
3192 or the last node certainly is not redundant, it points
3193 to the last node, otherwise points to the last but one.
3194 Do not mark it for GC because it is marked through the chain. */
3195 struct var_loc_node
* GTY ((skip ("%h"))) last
;
3197 /* Pointer to the last element before section switch,
3198 if NULL, either sections weren't switched or first
3199 is after section switch. */
3200 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
3202 /* DECL_UID of the variable decl. */
3203 unsigned int decl_id
;
3205 typedef struct var_loc_list_def var_loc_list
;
3207 /* Call argument location list. */
3208 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
3209 rtx
GTY (()) call_arg_loc_note
;
3210 const char * GTY (()) label
;
3211 tree
GTY (()) block
;
3213 rtx
GTY (()) symbol_ref
;
3214 struct call_arg_loc_node
* GTY (()) next
;
3218 struct decl_loc_hasher
: ggc_ptr_hash
<var_loc_list
>
3220 typedef const_tree compare_type
;
3222 static hashval_t
hash (var_loc_list
*);
3223 static bool equal (var_loc_list
*, const_tree
);
3226 /* Table of decl location linked lists. */
3227 static GTY (()) hash_table
<decl_loc_hasher
> *decl_loc_table
;
3229 /* Head and tail of call_arg_loc chain. */
3230 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
3231 static struct call_arg_loc_node
*call_arg_loc_last
;
3233 /* Number of call sites in the current function. */
3234 static int call_site_count
= -1;
3235 /* Number of tail call sites in the current function. */
3236 static int tail_call_site_count
= -1;
3238 /* A cached location list. */
3239 struct GTY ((for_user
)) cached_dw_loc_list_def
{
3240 /* The DECL_UID of the decl that this entry describes. */
3241 unsigned int decl_id
;
3243 /* The cached location list. */
3244 dw_loc_list_ref loc_list
;
3246 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
3248 struct dw_loc_list_hasher
: ggc_ptr_hash
<cached_dw_loc_list
>
3251 typedef const_tree compare_type
;
3253 static hashval_t
hash (cached_dw_loc_list
*);
3254 static bool equal (cached_dw_loc_list
*, const_tree
);
3257 /* Table of cached location lists. */
3258 static GTY (()) hash_table
<dw_loc_list_hasher
> *cached_dw_loc_list_table
;
3260 /* A vector of references to DIE's that are uniquely identified by their tag,
3261 presence/absence of children DIE's, and list of attribute/value pairs. */
3262 static GTY(()) vec
<dw_die_ref
, va_gc
> *abbrev_die_table
;
3264 /* A hash map to remember the stack usage for DWARF procedures. The value
3265 stored is the stack size difference between before the DWARF procedure
3266 invokation and after it returned. In other words, for a DWARF procedure
3267 that consumes N stack slots and that pushes M ones, this stores M - N. */
3268 static hash_map
<dw_die_ref
, int> *dwarf_proc_stack_usage_map
;
3270 /* A global counter for generating labels for line number data. */
3271 static unsigned int line_info_label_num
;
3273 /* The current table to which we should emit line number information
3274 for the current function. This will be set up at the beginning of
3275 assembly for the function. */
3276 static GTY(()) dw_line_info_table
*cur_line_info_table
;
3278 /* The two default tables of line number info. */
3279 static GTY(()) dw_line_info_table
*text_section_line_info
;
3280 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
3282 /* The set of all non-default tables of line number info. */
3283 static GTY(()) vec
<dw_line_info_table
*, va_gc
> *separate_line_info
;
3285 /* A flag to tell pubnames/types export if there is an info section to
3287 static bool info_section_emitted
;
3289 /* A pointer to the base of a table that contains a list of publicly
3290 accessible names. */
3291 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
3293 /* A pointer to the base of a table that contains a list of publicly
3294 accessible types. */
3295 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
3297 /* A pointer to the base of a table that contains a list of macro
3298 defines/undefines (and file start/end markers). */
3299 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
3301 /* True if .debug_macinfo or .debug_macros section is going to be
3303 #define have_macinfo \
3304 ((!XCOFF_DEBUGGING_INFO || HAVE_XCOFF_DWARF_EXTRAS) \
3305 && debug_info_level >= DINFO_LEVEL_VERBOSE \
3306 && !macinfo_table->is_empty ())
3308 /* Vector of dies for which we should generate .debug_ranges info. */
3309 static GTY (()) vec
<dw_ranges
, va_gc
> *ranges_table
;
3311 /* Vector of pairs of labels referenced in ranges_table. */
3312 static GTY (()) vec
<dw_ranges_by_label
, va_gc
> *ranges_by_label
;
3314 /* Whether we have location lists that need outputting */
3315 static GTY(()) bool have_location_lists
;
3317 /* Unique label counter. */
3318 static GTY(()) unsigned int loclabel_num
;
3320 /* Unique label counter for point-of-call tables. */
3321 static GTY(()) unsigned int poc_label_num
;
3323 /* The last file entry emitted by maybe_emit_file(). */
3324 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
3326 /* Number of internal labels generated by gen_internal_sym(). */
3327 static GTY(()) int label_num
;
3329 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
3331 /* Instances of generic types for which we need to generate debug
3332 info that describe their generic parameters and arguments. That
3333 generation needs to happen once all types are properly laid out so
3334 we do it at the end of compilation. */
3335 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
3337 /* Offset from the "steady-state frame pointer" to the frame base,
3338 within the current function. */
3339 static HOST_WIDE_INT frame_pointer_fb_offset
;
3340 static bool frame_pointer_fb_offset_valid
;
3342 static vec
<dw_die_ref
> base_types
;
3344 /* Flags to represent a set of attribute classes for attributes that represent
3345 a scalar value (bounds, pointers, ...). */
3348 dw_scalar_form_constant
= 0x01,
3349 dw_scalar_form_exprloc
= 0x02,
3350 dw_scalar_form_reference
= 0x04
3353 /* Forward declarations for functions defined in this file. */
3355 static int is_pseudo_reg (const_rtx
);
3356 static tree
type_main_variant (tree
);
3357 static int is_tagged_type (const_tree
);
3358 static const char *dwarf_tag_name (unsigned);
3359 static const char *dwarf_attr_name (unsigned);
3360 static const char *dwarf_form_name (unsigned);
3361 static tree
decl_ultimate_origin (const_tree
);
3362 static tree
decl_class_context (tree
);
3363 static void add_dwarf_attr (dw_die_ref
, dw_attr_node
*);
3364 static inline enum dw_val_class
AT_class (dw_attr_node
*);
3365 static inline unsigned int AT_index (dw_attr_node
*);
3366 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3367 static inline unsigned AT_flag (dw_attr_node
*);
3368 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3369 static inline HOST_WIDE_INT
AT_int (dw_attr_node
*);
3370 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3371 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_node
*);
3372 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
3373 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
3374 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3375 unsigned int, unsigned char *);
3376 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
3377 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3378 static inline const char *AT_string (dw_attr_node
*);
3379 static enum dwarf_form
AT_string_form (dw_attr_node
*);
3380 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3381 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3382 static inline dw_die_ref
AT_ref (dw_attr_node
*);
3383 static inline int AT_ref_external (dw_attr_node
*);
3384 static inline void set_AT_ref_external (dw_attr_node
*, int);
3385 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3386 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3387 static inline dw_loc_descr_ref
AT_loc (dw_attr_node
*);
3388 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3390 static inline dw_loc_list_ref
AT_loc_list (dw_attr_node
*);
3391 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
3392 static void remove_addr_table_entry (addr_table_entry
*);
3393 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
3394 static inline rtx
AT_addr (dw_attr_node
*);
3395 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3396 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3397 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3398 static void add_AT_loclistsptr (dw_die_ref
, enum dwarf_attribute
,
3400 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3401 unsigned HOST_WIDE_INT
);
3402 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3403 unsigned long, bool);
3404 static inline const char *AT_lbl (dw_attr_node
*);
3405 static dw_attr_node
*get_AT (dw_die_ref
, enum dwarf_attribute
);
3406 static const char *get_AT_low_pc (dw_die_ref
);
3407 static const char *get_AT_hi_pc (dw_die_ref
);
3408 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3409 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3410 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3411 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3412 static bool is_cxx (void);
3413 static bool is_cxx (const_tree
);
3414 static bool is_fortran (void);
3415 static bool is_ada (void);
3416 static bool remove_AT (dw_die_ref
, enum dwarf_attribute
);
3417 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3418 static void add_child_die (dw_die_ref
, dw_die_ref
);
3419 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3420 static dw_die_ref
lookup_type_die (tree
);
3421 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3422 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3423 static void equate_type_number_to_die (tree
, dw_die_ref
);
3424 static dw_die_ref
lookup_decl_die (tree
);
3425 static var_loc_list
*lookup_decl_loc (const_tree
);
3426 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3427 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3428 static void print_spaces (FILE *);
3429 static void print_die (dw_die_ref
, FILE *);
3430 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3431 static void attr_checksum (dw_attr_node
*, struct md5_ctx
*, int *);
3432 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3433 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3434 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3435 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3436 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_node
*,
3437 struct md5_ctx
*, int *);
3438 struct checksum_attributes
;
3439 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3440 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3441 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3442 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3443 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3444 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3445 static int same_attr_p (dw_attr_node
*, dw_attr_node
*, int *);
3446 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3447 static int is_type_die (dw_die_ref
);
3448 static int is_comdat_die (dw_die_ref
);
3449 static inline bool is_template_instantiation (dw_die_ref
);
3450 static int is_declaration_die (dw_die_ref
);
3451 static int should_move_die_to_comdat (dw_die_ref
);
3452 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3453 static dw_die_ref
clone_die (dw_die_ref
);
3454 static dw_die_ref
clone_tree (dw_die_ref
);
3455 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3456 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3457 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3458 static dw_die_ref
generate_skeleton (dw_die_ref
);
3459 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3462 static void break_out_comdat_types (dw_die_ref
);
3463 static void copy_decls_for_unworthy_types (dw_die_ref
);
3465 static void add_sibling_attributes (dw_die_ref
);
3466 static void output_location_lists (dw_die_ref
);
3467 static int constant_size (unsigned HOST_WIDE_INT
);
3468 static unsigned long size_of_die (dw_die_ref
);
3469 static void calc_die_sizes (dw_die_ref
);
3470 static void calc_base_type_die_sizes (void);
3471 static void mark_dies (dw_die_ref
);
3472 static void unmark_dies (dw_die_ref
);
3473 static void unmark_all_dies (dw_die_ref
);
3474 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3475 static unsigned long size_of_aranges (void);
3476 static enum dwarf_form
value_format (dw_attr_node
*);
3477 static void output_value_format (dw_attr_node
*);
3478 static void output_abbrev_section (void);
3479 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3480 static void output_die (dw_die_ref
);
3481 static void output_compilation_unit_header (enum dwarf_unit_type
);
3482 static void output_comp_unit (dw_die_ref
, int, const unsigned char *);
3483 static void output_comdat_type_unit (comdat_type_node
*);
3484 static const char *dwarf2_name (tree
, int);
3485 static void add_pubname (tree
, dw_die_ref
);
3486 static void add_enumerator_pubname (const char *, dw_die_ref
);
3487 static void add_pubname_string (const char *, dw_die_ref
);
3488 static void add_pubtype (tree
, dw_die_ref
);
3489 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3490 static void output_aranges (void);
3491 static unsigned int add_ranges (const_tree
, bool = false);
3492 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3494 static void output_ranges (void);
3495 static dw_line_info_table
*new_line_info_table (void);
3496 static void output_line_info (bool);
3497 static void output_file_names (void);
3498 static dw_die_ref
base_type_die (tree
, bool);
3499 static int is_base_type (tree
);
3500 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, tree
, dw_die_ref
);
3501 static int decl_quals (const_tree
);
3502 static dw_die_ref
modified_type_die (tree
, int, bool, dw_die_ref
);
3503 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3504 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3505 static int type_is_enum (const_tree
);
3506 static unsigned int dbx_reg_number (const_rtx
);
3507 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3508 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3509 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3510 enum var_init_status
);
3511 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3512 enum var_init_status
);
3513 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3514 enum var_init_status
);
3515 static int is_based_loc (const_rtx
);
3516 static bool resolve_one_addr (rtx
*);
3517 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3518 enum var_init_status
);
3519 static dw_loc_descr_ref
loc_descriptor (rtx
, machine_mode mode
,
3520 enum var_init_status
);
3521 struct loc_descr_context
;
3522 static void add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
);
3523 static void add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
);
3524 static dw_loc_list_ref
loc_list_from_tree (tree
, int,
3525 struct loc_descr_context
*);
3526 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int,
3527 struct loc_descr_context
*);
3528 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3529 static tree
field_type (const_tree
);
3530 static unsigned int simple_type_align_in_bits (const_tree
);
3531 static unsigned int simple_decl_align_in_bits (const_tree
);
3532 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3534 static dw_loc_descr_ref
field_byte_offset (const_tree
, struct vlr_context
*,
3536 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3538 static void add_data_member_location_attribute (dw_die_ref
, tree
,
3539 struct vlr_context
*);
3540 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3541 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3542 static void insert_wide_int (const wide_int
&, unsigned char *, int);
3543 static void insert_float (const_rtx
, unsigned char *);
3544 static rtx
rtl_for_decl_location (tree
);
3545 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool);
3546 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3547 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3548 static void add_name_attribute (dw_die_ref
, const char *);
3549 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3550 static void add_comp_dir_attribute (dw_die_ref
);
3551 static void add_scalar_info (dw_die_ref
, enum dwarf_attribute
, tree
, int,
3552 struct loc_descr_context
*);
3553 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
,
3554 struct loc_descr_context
*);
3555 static void add_subscript_info (dw_die_ref
, tree
, bool);
3556 static void add_byte_size_attribute (dw_die_ref
, tree
);
3557 static void add_alignment_attribute (dw_die_ref
, tree
);
3558 static inline void add_bit_offset_attribute (dw_die_ref
, tree
,
3559 struct vlr_context
*);
3560 static void add_bit_size_attribute (dw_die_ref
, tree
);
3561 static void add_prototyped_attribute (dw_die_ref
, tree
);
3562 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3563 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3564 static void add_src_coords_attributes (dw_die_ref
, tree
);
3565 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
, bool = false);
3566 static void add_discr_value (dw_die_ref
, dw_discr_value
*);
3567 static void add_discr_list (dw_die_ref
, dw_discr_list_ref
);
3568 static inline dw_discr_list_ref
AT_discr_list (dw_attr_node
*);
3569 static void push_decl_scope (tree
);
3570 static void pop_decl_scope (void);
3571 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3572 static inline int local_scope_p (dw_die_ref
);
3573 static inline int class_scope_p (dw_die_ref
);
3574 static inline int class_or_namespace_scope_p (dw_die_ref
);
3575 static void add_type_attribute (dw_die_ref
, tree
, int, bool, dw_die_ref
);
3576 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3577 static const char *type_tag (const_tree
);
3578 static tree
member_declared_type (const_tree
);
3580 static const char *decl_start_label (tree
);
3582 static void gen_array_type_die (tree
, dw_die_ref
);
3583 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3585 static void gen_entry_point_die (tree
, dw_die_ref
);
3587 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3588 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3589 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3590 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3591 static void gen_formal_types_die (tree
, dw_die_ref
);
3592 static void gen_subprogram_die (tree
, dw_die_ref
);
3593 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3594 static void gen_const_die (tree
, dw_die_ref
);
3595 static void gen_label_die (tree
, dw_die_ref
);
3596 static void gen_lexical_block_die (tree
, dw_die_ref
);
3597 static void gen_inlined_subroutine_die (tree
, dw_die_ref
);
3598 static void gen_field_die (tree
, struct vlr_context
*, dw_die_ref
);
3599 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3600 static dw_die_ref
gen_compile_unit_die (const char *);
3601 static void gen_inheritance_die (tree
, tree
, tree
, dw_die_ref
);
3602 static void gen_member_die (tree
, dw_die_ref
);
3603 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3604 enum debug_info_usage
);
3605 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3606 static void gen_typedef_die (tree
, dw_die_ref
);
3607 static void gen_type_die (tree
, dw_die_ref
);
3608 static void gen_block_die (tree
, dw_die_ref
);
3609 static void decls_for_scope (tree
, dw_die_ref
);
3610 static bool is_naming_typedef_decl (const_tree
);
3611 static inline dw_die_ref
get_context_die (tree
);
3612 static void gen_namespace_die (tree
, dw_die_ref
);
3613 static dw_die_ref
gen_namelist_decl (tree
, dw_die_ref
, tree
);
3614 static dw_die_ref
gen_decl_die (tree
, tree
, struct vlr_context
*, dw_die_ref
);
3615 static dw_die_ref
force_decl_die (tree
);
3616 static dw_die_ref
force_type_die (tree
);
3617 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3618 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3619 static struct dwarf_file_data
* lookup_filename (const char *);
3620 static void retry_incomplete_types (void);
3621 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3622 static void gen_generic_params_dies (tree
);
3623 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3624 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3625 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3626 static int file_info_cmp (const void *, const void *);
3627 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3628 const char *, const char *);
3629 static void output_loc_list (dw_loc_list_ref
);
3630 static char *gen_internal_sym (const char *);
3631 static bool want_pubnames (void);
3633 static void prune_unmark_dies (dw_die_ref
);
3634 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3635 static void prune_unused_types_mark (dw_die_ref
, int);
3636 static void prune_unused_types_walk (dw_die_ref
);
3637 static void prune_unused_types_walk_attribs (dw_die_ref
);
3638 static void prune_unused_types_prune (dw_die_ref
);
3639 static void prune_unused_types (void);
3640 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3641 static inline const char *AT_vms_delta1 (dw_attr_node
*);
3642 static inline const char *AT_vms_delta2 (dw_attr_node
*);
3643 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3644 const char *, const char *);
3645 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3646 static void gen_remaining_tmpl_value_param_die_attribute (void);
3647 static bool generic_type_p (tree
);
3648 static void schedule_generic_params_dies_gen (tree t
);
3649 static void gen_scheduled_generic_parms_dies (void);
3650 static void resolve_variable_values (void);
3652 static const char *comp_dir_string (void);
3654 static void hash_loc_operands (dw_loc_descr_ref
, inchash::hash
&);
3656 /* enum for tracking thread-local variables whose address is really an offset
3657 relative to the TLS pointer, which will need link-time relocation, but will
3658 not need relocation by the DWARF consumer. */
3666 /* Return the operator to use for an address of a variable. For dtprel_true, we
3667 use DW_OP_const*. For regular variables, which need both link-time
3668 relocation and consumer-level relocation (e.g., to account for shared objects
3669 loaded at a random address), we use DW_OP_addr*. */
3671 static inline enum dwarf_location_atom
3672 dw_addr_op (enum dtprel_bool dtprel
)
3674 if (dtprel
== dtprel_true
)
3675 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3676 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3678 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3681 /* Return a pointer to a newly allocated address location description. If
3682 dwarf_split_debug_info is true, then record the address with the appropriate
3684 static inline dw_loc_descr_ref
3685 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3687 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3689 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3690 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3691 ref
->dtprel
= dtprel
;
3692 if (dwarf_split_debug_info
)
3693 ref
->dw_loc_oprnd1
.val_entry
3694 = add_addr_table_entry (addr
,
3695 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3697 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3702 /* Section names used to hold DWARF debugging information. */
3704 #ifndef DEBUG_INFO_SECTION
3705 #define DEBUG_INFO_SECTION ".debug_info"
3707 #ifndef DEBUG_DWO_INFO_SECTION
3708 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3710 #ifndef DEBUG_LTO_INFO_SECTION
3711 #define DEBUG_LTO_INFO_SECTION ".gnu.debuglto_.debug_info"
3713 #ifndef DEBUG_LTO_DWO_INFO_SECTION
3714 #define DEBUG_LTO_DWO_INFO_SECTION ".gnu.debuglto_.debug_info.dwo"
3716 #ifndef DEBUG_ABBREV_SECTION
3717 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3719 #ifndef DEBUG_LTO_ABBREV_SECTION
3720 #define DEBUG_LTO_ABBREV_SECTION ".gnu.debuglto_.debug_abbrev"
3722 #ifndef DEBUG_DWO_ABBREV_SECTION
3723 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3725 #ifndef DEBUG_LTO_DWO_ABBREV_SECTION
3726 #define DEBUG_LTO_DWO_ABBREV_SECTION ".gnu.debuglto_.debug_abbrev.dwo"
3728 #ifndef DEBUG_ARANGES_SECTION
3729 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3731 #ifndef DEBUG_ADDR_SECTION
3732 #define DEBUG_ADDR_SECTION ".debug_addr"
3734 #ifndef DEBUG_MACINFO_SECTION
3735 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3737 #ifndef DEBUG_LTO_MACINFO_SECTION
3738 #define DEBUG_LTO_MACINFO_SECTION ".gnu.debuglto_.debug_macinfo"
3740 #ifndef DEBUG_DWO_MACINFO_SECTION
3741 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3743 #ifndef DEBUG_LTO_DWO_MACINFO_SECTION
3744 #define DEBUG_LTO_DWO_MACINFO_SECTION ".gnu.debuglto_.debug_macinfo.dwo"
3746 #ifndef DEBUG_MACRO_SECTION
3747 #define DEBUG_MACRO_SECTION ".debug_macro"
3749 #ifndef DEBUG_LTO_MACRO_SECTION
3750 #define DEBUG_LTO_MACRO_SECTION ".gnu.debuglto_.debug_macro"
3752 #ifndef DEBUG_DWO_MACRO_SECTION
3753 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3755 #ifndef DEBUG_LTO_DWO_MACRO_SECTION
3756 #define DEBUG_LTO_DWO_MACRO_SECTION ".gnu.debuglto_.debug_macro.dwo"
3758 #ifndef DEBUG_LINE_SECTION
3759 #define DEBUG_LINE_SECTION ".debug_line"
3761 #ifndef DEBUG_LTO_LINE_SECTION
3762 #define DEBUG_LTO_LINE_SECTION ".gnu.debuglto_.debug_line"
3764 #ifndef DEBUG_DWO_LINE_SECTION
3765 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3767 #ifndef DEBUG_LTO_DWO_LINE_SECTION
3768 #define DEBUG_LTO_DWO_LINE_SECTION ".gnu.debuglto_.debug_line.dwo"
3770 #ifndef DEBUG_LOC_SECTION
3771 #define DEBUG_LOC_SECTION ".debug_loc"
3773 #ifndef DEBUG_DWO_LOC_SECTION
3774 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3776 #ifndef DEBUG_LOCLISTS_SECTION
3777 #define DEBUG_LOCLISTS_SECTION ".debug_loclists"
3779 #ifndef DEBUG_DWO_LOCLISTS_SECTION
3780 #define DEBUG_DWO_LOCLISTS_SECTION ".debug_loclists.dwo"
3782 #ifndef DEBUG_PUBNAMES_SECTION
3783 #define DEBUG_PUBNAMES_SECTION \
3784 ((debug_generate_pub_sections == 2) \
3785 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3787 #ifndef DEBUG_PUBTYPES_SECTION
3788 #define DEBUG_PUBTYPES_SECTION \
3789 ((debug_generate_pub_sections == 2) \
3790 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3792 #ifndef DEBUG_STR_OFFSETS_SECTION
3793 #define DEBUG_STR_OFFSETS_SECTION ".debug_str_offsets"
3795 #ifndef DEBUG_DWO_STR_OFFSETS_SECTION
3796 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3798 #ifndef DEBUG_LTO_DWO_STR_OFFSETS_SECTION
3799 #define DEBUG_LTO_DWO_STR_OFFSETS_SECTION ".gnu.debuglto_.debug_str_offsets.dwo"
3801 #ifndef DEBUG_STR_SECTION
3802 #define DEBUG_STR_SECTION ".debug_str"
3804 #ifndef DEBUG_LTO_STR_SECTION
3805 #define DEBUG_LTO_STR_SECTION ".gnu.debuglto_.debug_str"
3807 #ifndef DEBUG_STR_DWO_SECTION
3808 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3810 #ifndef DEBUG_LTO_STR_DWO_SECTION
3811 #define DEBUG_LTO_STR_DWO_SECTION ".gnu.debuglto_.debug_str.dwo"
3813 #ifndef DEBUG_RANGES_SECTION
3814 #define DEBUG_RANGES_SECTION ".debug_ranges"
3816 #ifndef DEBUG_RNGLISTS_SECTION
3817 #define DEBUG_RNGLISTS_SECTION ".debug_rnglists"
3819 #ifndef DEBUG_LINE_STR_SECTION
3820 #define DEBUG_LINE_STR_SECTION ".debug_line_str"
3822 #ifndef DEBUG_LTO_LINE_STR_SECTION
3823 #define DEBUG_LTO_LINE_STR_SECTION ".gnu.debuglto_.debug_line_str"
3826 /* Standard ELF section names for compiled code and data. */
3827 #ifndef TEXT_SECTION_NAME
3828 #define TEXT_SECTION_NAME ".text"
3831 /* Section flags for .debug_str section. */
3832 #define DEBUG_STR_SECTION_FLAGS \
3833 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3834 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3837 /* Section flags for .debug_str.dwo section. */
3838 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3840 /* Attribute used to refer to the macro section. */
3841 #define DEBUG_MACRO_ATTRIBUTE (dwarf_version >= 5 ? DW_AT_macros \
3842 : dwarf_strict ? DW_AT_macro_info : DW_AT_GNU_macros)
3844 /* Labels we insert at beginning sections we can reference instead of
3845 the section names themselves. */
3847 #ifndef TEXT_SECTION_LABEL
3848 #define TEXT_SECTION_LABEL "Ltext"
3850 #ifndef COLD_TEXT_SECTION_LABEL
3851 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3853 #ifndef DEBUG_LINE_SECTION_LABEL
3854 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3856 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3857 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3859 #ifndef DEBUG_INFO_SECTION_LABEL
3860 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3862 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3863 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3865 #ifndef DEBUG_ABBREV_SECTION_LABEL
3866 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3868 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3869 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3871 #ifndef DEBUG_ADDR_SECTION_LABEL
3872 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3874 #ifndef DEBUG_LOC_SECTION_LABEL
3875 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3877 #ifndef DEBUG_RANGES_SECTION_LABEL
3878 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3880 #ifndef DEBUG_MACINFO_SECTION_LABEL
3881 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3883 #ifndef DEBUG_MACRO_SECTION_LABEL
3884 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3886 #define SKELETON_COMP_DIE_ABBREV 1
3887 #define SKELETON_TYPE_DIE_ABBREV 2
3889 /* Definitions of defaults for formats and names of various special
3890 (artificial) labels which may be generated within this file (when the -g
3891 options is used and DWARF2_DEBUGGING_INFO is in effect.
3892 If necessary, these may be overridden from within the tm.h file, but
3893 typically, overriding these defaults is unnecessary. */
3895 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3896 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3897 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3898 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3899 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3900 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3901 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3902 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3903 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3904 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3905 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3906 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3907 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3908 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3909 static char ranges_base_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3911 #ifndef TEXT_END_LABEL
3912 #define TEXT_END_LABEL "Letext"
3914 #ifndef COLD_END_LABEL
3915 #define COLD_END_LABEL "Letext_cold"
3917 #ifndef BLOCK_BEGIN_LABEL
3918 #define BLOCK_BEGIN_LABEL "LBB"
3920 #ifndef BLOCK_END_LABEL
3921 #define BLOCK_END_LABEL "LBE"
3923 #ifndef LINE_CODE_LABEL
3924 #define LINE_CODE_LABEL "LM"
3928 /* Return the root of the DIE's built for the current compilation unit. */
3930 comp_unit_die (void)
3932 if (!single_comp_unit_die
)
3933 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3934 return single_comp_unit_die
;
3937 /* We allow a language front-end to designate a function that is to be
3938 called to "demangle" any name before it is put into a DIE. */
3940 static const char *(*demangle_name_func
) (const char *);
3943 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3945 demangle_name_func
= func
;
3948 /* Test if rtl node points to a pseudo register. */
3951 is_pseudo_reg (const_rtx rtl
)
3953 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3954 || (GET_CODE (rtl
) == SUBREG
3955 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3958 /* Return a reference to a type, with its const and volatile qualifiers
3962 type_main_variant (tree type
)
3964 type
= TYPE_MAIN_VARIANT (type
);
3966 /* ??? There really should be only one main variant among any group of
3967 variants of a given type (and all of the MAIN_VARIANT values for all
3968 members of the group should point to that one type) but sometimes the C
3969 front-end messes this up for array types, so we work around that bug
3971 if (TREE_CODE (type
) == ARRAY_TYPE
)
3972 while (type
!= TYPE_MAIN_VARIANT (type
))
3973 type
= TYPE_MAIN_VARIANT (type
);
3978 /* Return nonzero if the given type node represents a tagged type. */
3981 is_tagged_type (const_tree type
)
3983 enum tree_code code
= TREE_CODE (type
);
3985 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3986 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3989 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3992 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3994 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3997 /* Return die_offset of a DIE reference to a base type. */
3999 static unsigned long int
4000 get_base_type_offset (dw_die_ref ref
)
4002 if (ref
->die_offset
)
4003 return ref
->die_offset
;
4004 if (comp_unit_die ()->die_abbrev
)
4006 calc_base_type_die_sizes ();
4007 gcc_assert (ref
->die_offset
);
4009 return ref
->die_offset
;
4012 /* Return die_offset of a DIE reference other than base type. */
4014 static unsigned long int
4015 get_ref_die_offset (dw_die_ref ref
)
4017 gcc_assert (ref
->die_offset
);
4018 return ref
->die_offset
;
4021 /* Convert a DIE tag into its string name. */
4024 dwarf_tag_name (unsigned int tag
)
4026 const char *name
= get_DW_TAG_name (tag
);
4031 return "DW_TAG_<unknown>";
4034 /* Convert a DWARF attribute code into its string name. */
4037 dwarf_attr_name (unsigned int attr
)
4043 #if VMS_DEBUGGING_INFO
4044 case DW_AT_HP_prologue
:
4045 return "DW_AT_HP_prologue";
4047 case DW_AT_MIPS_loop_unroll_factor
:
4048 return "DW_AT_MIPS_loop_unroll_factor";
4051 #if VMS_DEBUGGING_INFO
4052 case DW_AT_HP_epilogue
:
4053 return "DW_AT_HP_epilogue";
4055 case DW_AT_MIPS_stride
:
4056 return "DW_AT_MIPS_stride";
4060 name
= get_DW_AT_name (attr
);
4065 return "DW_AT_<unknown>";
4068 /* Convert a DWARF value form code into its string name. */
4071 dwarf_form_name (unsigned int form
)
4073 const char *name
= get_DW_FORM_name (form
);
4078 return "DW_FORM_<unknown>";
4081 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4082 instance of an inlined instance of a decl which is local to an inline
4083 function, so we have to trace all of the way back through the origin chain
4084 to find out what sort of node actually served as the original seed for the
4088 decl_ultimate_origin (const_tree decl
)
4090 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
4093 /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
4094 we're trying to output the abstract instance of this function. */
4095 if (DECL_ABSTRACT_P (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4098 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4099 most distant ancestor, this should never happen. */
4100 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
4102 return DECL_ABSTRACT_ORIGIN (decl
);
4105 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4106 of a virtual function may refer to a base class, so we check the 'this'
4110 decl_class_context (tree decl
)
4112 tree context
= NULL_TREE
;
4114 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4115 context
= DECL_CONTEXT (decl
);
4117 context
= TYPE_MAIN_VARIANT
4118 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4120 if (context
&& !TYPE_P (context
))
4121 context
= NULL_TREE
;
4126 /* Add an attribute/value pair to a DIE. */
4129 add_dwarf_attr (dw_die_ref die
, dw_attr_node
*attr
)
4131 /* Maybe this should be an assert? */
4137 /* Check we do not add duplicate attrs. Can't use get_AT here
4138 because that recurses to the specification/abstract origin DIE. */
4141 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4142 gcc_assert (a
->dw_attr
!= attr
->dw_attr
);
4145 vec_safe_reserve (die
->die_attr
, 1);
4146 vec_safe_push (die
->die_attr
, *attr
);
4149 static inline enum dw_val_class
4150 AT_class (dw_attr_node
*a
)
4152 return a
->dw_attr_val
.val_class
;
4155 /* Return the index for any attribute that will be referenced with a
4156 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
4157 are stored in dw_attr_val.v.val_str for reference counting
4160 static inline unsigned int
4161 AT_index (dw_attr_node
*a
)
4163 if (AT_class (a
) == dw_val_class_str
)
4164 return a
->dw_attr_val
.v
.val_str
->index
;
4165 else if (a
->dw_attr_val
.val_entry
!= NULL
)
4166 return a
->dw_attr_val
.val_entry
->index
;
4170 /* Add a flag value attribute to a DIE. */
4173 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
4177 attr
.dw_attr
= attr_kind
;
4178 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
4179 attr
.dw_attr_val
.val_entry
= NULL
;
4180 attr
.dw_attr_val
.v
.val_flag
= flag
;
4181 add_dwarf_attr (die
, &attr
);
4184 static inline unsigned
4185 AT_flag (dw_attr_node
*a
)
4187 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
4188 return a
->dw_attr_val
.v
.val_flag
;
4191 /* Add a signed integer attribute value to a DIE. */
4194 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
4198 attr
.dw_attr
= attr_kind
;
4199 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
4200 attr
.dw_attr_val
.val_entry
= NULL
;
4201 attr
.dw_attr_val
.v
.val_int
= int_val
;
4202 add_dwarf_attr (die
, &attr
);
4205 static inline HOST_WIDE_INT
4206 AT_int (dw_attr_node
*a
)
4208 gcc_assert (a
&& (AT_class (a
) == dw_val_class_const
4209 || AT_class (a
) == dw_val_class_const_implicit
));
4210 return a
->dw_attr_val
.v
.val_int
;
4213 /* Add an unsigned integer attribute value to a DIE. */
4216 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4217 unsigned HOST_WIDE_INT unsigned_val
)
4221 attr
.dw_attr
= attr_kind
;
4222 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4223 attr
.dw_attr_val
.val_entry
= NULL
;
4224 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4225 add_dwarf_attr (die
, &attr
);
4228 static inline unsigned HOST_WIDE_INT
4229 AT_unsigned (dw_attr_node
*a
)
4231 gcc_assert (a
&& (AT_class (a
) == dw_val_class_unsigned_const
4232 || AT_class (a
) == dw_val_class_unsigned_const_implicit
));
4233 return a
->dw_attr_val
.v
.val_unsigned
;
4236 /* Add an unsigned wide integer attribute value to a DIE. */
4239 add_AT_wide (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4244 attr
.dw_attr
= attr_kind
;
4245 attr
.dw_attr_val
.val_class
= dw_val_class_wide_int
;
4246 attr
.dw_attr_val
.val_entry
= NULL
;
4247 attr
.dw_attr_val
.v
.val_wide
= ggc_alloc
<wide_int
> ();
4248 *attr
.dw_attr_val
.v
.val_wide
= w
;
4249 add_dwarf_attr (die
, &attr
);
4252 /* Add an unsigned double integer attribute value to a DIE. */
4255 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4256 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
4260 attr
.dw_attr
= attr_kind
;
4261 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
4262 attr
.dw_attr_val
.val_entry
= NULL
;
4263 attr
.dw_attr_val
.v
.val_double
.high
= high
;
4264 attr
.dw_attr_val
.v
.val_double
.low
= low
;
4265 add_dwarf_attr (die
, &attr
);
4268 /* Add a floating point attribute value to a DIE and return it. */
4271 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4272 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
4276 attr
.dw_attr
= attr_kind
;
4277 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
4278 attr
.dw_attr_val
.val_entry
= NULL
;
4279 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
4280 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
4281 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
4282 add_dwarf_attr (die
, &attr
);
4285 /* Add an 8-byte data attribute value to a DIE. */
4288 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4289 unsigned char data8
[8])
4293 attr
.dw_attr
= attr_kind
;
4294 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
4295 attr
.dw_attr_val
.val_entry
= NULL
;
4296 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
4297 add_dwarf_attr (die
, &attr
);
4300 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
4301 dwarf_split_debug_info, address attributes in dies destined for the
4302 final executable have force_direct set to avoid using indexed
4306 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
4312 lbl_id
= xstrdup (lbl_low
);
4313 attr
.dw_attr
= DW_AT_low_pc
;
4314 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4315 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4316 if (dwarf_split_debug_info
&& !force_direct
)
4317 attr
.dw_attr_val
.val_entry
4318 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4320 attr
.dw_attr_val
.val_entry
= NULL
;
4321 add_dwarf_attr (die
, &attr
);
4323 attr
.dw_attr
= DW_AT_high_pc
;
4324 if (dwarf_version
< 4)
4325 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4327 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
4328 lbl_id
= xstrdup (lbl_high
);
4329 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4330 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
4331 && dwarf_split_debug_info
&& !force_direct
)
4332 attr
.dw_attr_val
.val_entry
4333 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4335 attr
.dw_attr_val
.val_entry
= NULL
;
4336 add_dwarf_attr (die
, &attr
);
4339 /* Hash and equality functions for debug_str_hash. */
4342 indirect_string_hasher::hash (indirect_string_node
*x
)
4344 return htab_hash_string (x
->str
);
4348 indirect_string_hasher::equal (indirect_string_node
*x1
, const char *x2
)
4350 return strcmp (x1
->str
, x2
) == 0;
4353 /* Add STR to the given string hash table. */
4355 static struct indirect_string_node
*
4356 find_AT_string_in_table (const char *str
,
4357 hash_table
<indirect_string_hasher
> *table
)
4359 struct indirect_string_node
*node
;
4361 indirect_string_node
**slot
4362 = table
->find_slot_with_hash (str
, htab_hash_string (str
), INSERT
);
4365 node
= ggc_cleared_alloc
<indirect_string_node
> ();
4366 node
->str
= ggc_strdup (str
);
4376 /* Add STR to the indirect string hash table. */
4378 static struct indirect_string_node
*
4379 find_AT_string (const char *str
)
4381 if (! debug_str_hash
)
4382 debug_str_hash
= hash_table
<indirect_string_hasher
>::create_ggc (10);
4384 return find_AT_string_in_table (str
, debug_str_hash
);
4387 /* Add a string attribute value to a DIE. */
4390 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4393 struct indirect_string_node
*node
;
4395 node
= find_AT_string (str
);
4397 attr
.dw_attr
= attr_kind
;
4398 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4399 attr
.dw_attr_val
.val_entry
= NULL
;
4400 attr
.dw_attr_val
.v
.val_str
= node
;
4401 add_dwarf_attr (die
, &attr
);
4404 static inline const char *
4405 AT_string (dw_attr_node
*a
)
4407 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4408 return a
->dw_attr_val
.v
.val_str
->str
;
4411 /* Call this function directly to bypass AT_string_form's logic to put
4412 the string inline in the die. */
4415 set_indirect_string (struct indirect_string_node
*node
)
4417 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4418 /* Already indirect is a no op. */
4419 if (node
->form
== DW_FORM_strp
4420 || node
->form
== DW_FORM_line_strp
4421 || node
->form
== DW_FORM_GNU_str_index
)
4423 gcc_assert (node
->label
);
4426 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4427 ++dw2_string_counter
;
4428 node
->label
= xstrdup (label
);
4430 if (!dwarf_split_debug_info
)
4432 node
->form
= DW_FORM_strp
;
4433 node
->index
= NOT_INDEXED
;
4437 node
->form
= DW_FORM_GNU_str_index
;
4438 node
->index
= NO_INDEX_ASSIGNED
;
4442 /* A helper function for dwarf2out_finish, called to reset indirect
4443 string decisions done for early LTO dwarf output before fat object
4447 reset_indirect_string (indirect_string_node
**h
, void *)
4449 struct indirect_string_node
*node
= *h
;
4450 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
4454 node
->form
= (dwarf_form
) 0;
4460 /* Find out whether a string should be output inline in DIE
4461 or out-of-line in .debug_str section. */
4463 static enum dwarf_form
4464 find_string_form (struct indirect_string_node
*node
)
4471 len
= strlen (node
->str
) + 1;
4473 /* If the string is shorter or equal to the size of the reference, it is
4474 always better to put it inline. */
4475 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4476 return node
->form
= DW_FORM_string
;
4478 /* If we cannot expect the linker to merge strings in .debug_str
4479 section, only put it into .debug_str if it is worth even in this
4481 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4482 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4483 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
4484 return node
->form
= DW_FORM_string
;
4486 set_indirect_string (node
);
4491 /* Find out whether the string referenced from the attribute should be
4492 output inline in DIE or out-of-line in .debug_str section. */
4494 static enum dwarf_form
4495 AT_string_form (dw_attr_node
*a
)
4497 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4498 return find_string_form (a
->dw_attr_val
.v
.val_str
);
4501 /* Add a DIE reference attribute value to a DIE. */
4504 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4507 gcc_checking_assert (targ_die
!= NULL
);
4509 /* With LTO we can end up trying to reference something we didn't create
4510 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4511 if (targ_die
== NULL
)
4514 attr
.dw_attr
= attr_kind
;
4515 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4516 attr
.dw_attr_val
.val_entry
= NULL
;
4517 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4518 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4519 add_dwarf_attr (die
, &attr
);
4522 /* Change DIE reference REF to point to NEW_DIE instead. */
4525 change_AT_die_ref (dw_attr_node
*ref
, dw_die_ref new_die
)
4527 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4528 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4529 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4532 /* Add an AT_specification attribute to a DIE, and also make the back
4533 pointer from the specification to the definition. */
4536 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4538 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4539 gcc_assert (!targ_die
->die_definition
);
4540 targ_die
->die_definition
= die
;
4543 static inline dw_die_ref
4544 AT_ref (dw_attr_node
*a
)
4546 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4547 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4551 AT_ref_external (dw_attr_node
*a
)
4553 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4554 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4560 set_AT_ref_external (dw_attr_node
*a
, int i
)
4562 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4563 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4566 /* Add an FDE reference attribute value to a DIE. */
4569 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4573 attr
.dw_attr
= attr_kind
;
4574 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4575 attr
.dw_attr_val
.val_entry
= NULL
;
4576 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4577 add_dwarf_attr (die
, &attr
);
4580 /* Add a location description attribute value to a DIE. */
4583 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4587 attr
.dw_attr
= attr_kind
;
4588 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4589 attr
.dw_attr_val
.val_entry
= NULL
;
4590 attr
.dw_attr_val
.v
.val_loc
= loc
;
4591 add_dwarf_attr (die
, &attr
);
4594 static inline dw_loc_descr_ref
4595 AT_loc (dw_attr_node
*a
)
4597 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4598 return a
->dw_attr_val
.v
.val_loc
;
4602 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4606 if (XCOFF_DEBUGGING_INFO
&& !HAVE_XCOFF_DWARF_EXTRAS
)
4609 attr
.dw_attr
= attr_kind
;
4610 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4611 attr
.dw_attr_val
.val_entry
= NULL
;
4612 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4613 add_dwarf_attr (die
, &attr
);
4614 have_location_lists
= true;
4617 static inline dw_loc_list_ref
4618 AT_loc_list (dw_attr_node
*a
)
4620 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4621 return a
->dw_attr_val
.v
.val_loc_list
;
4624 static inline dw_loc_list_ref
*
4625 AT_loc_list_ptr (dw_attr_node
*a
)
4627 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4628 return &a
->dw_attr_val
.v
.val_loc_list
;
4631 struct addr_hasher
: ggc_ptr_hash
<addr_table_entry
>
4633 static hashval_t
hash (addr_table_entry
*);
4634 static bool equal (addr_table_entry
*, addr_table_entry
*);
4637 /* Table of entries into the .debug_addr section. */
4639 static GTY (()) hash_table
<addr_hasher
> *addr_index_table
;
4641 /* Hash an address_table_entry. */
4644 addr_hasher::hash (addr_table_entry
*a
)
4646 inchash::hash hstate
;
4652 case ate_kind_rtx_dtprel
:
4655 case ate_kind_label
:
4656 return htab_hash_string (a
->addr
.label
);
4660 inchash::add_rtx (a
->addr
.rtl
, hstate
);
4661 return hstate
.end ();
4664 /* Determine equality for two address_table_entries. */
4667 addr_hasher::equal (addr_table_entry
*a1
, addr_table_entry
*a2
)
4669 if (a1
->kind
!= a2
->kind
)
4674 case ate_kind_rtx_dtprel
:
4675 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4676 case ate_kind_label
:
4677 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4683 /* Initialize an addr_table_entry. */
4686 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4692 case ate_kind_rtx_dtprel
:
4693 e
->addr
.rtl
= (rtx
) addr
;
4695 case ate_kind_label
:
4696 e
->addr
.label
= (char *) addr
;
4700 e
->index
= NO_INDEX_ASSIGNED
;
4703 /* Add attr to the address table entry to the table. Defer setting an
4704 index until output time. */
4706 static addr_table_entry
*
4707 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4709 addr_table_entry
*node
;
4710 addr_table_entry finder
;
4712 gcc_assert (dwarf_split_debug_info
);
4713 if (! addr_index_table
)
4714 addr_index_table
= hash_table
<addr_hasher
>::create_ggc (10);
4715 init_addr_table_entry (&finder
, kind
, addr
);
4716 addr_table_entry
**slot
= addr_index_table
->find_slot (&finder
, INSERT
);
4718 if (*slot
== HTAB_EMPTY_ENTRY
)
4720 node
= ggc_cleared_alloc
<addr_table_entry
> ();
4721 init_addr_table_entry (node
, kind
, addr
);
4731 /* Remove an entry from the addr table by decrementing its refcount.
4732 Strictly, decrementing the refcount would be enough, but the
4733 assertion that the entry is actually in the table has found
4737 remove_addr_table_entry (addr_table_entry
*entry
)
4739 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4740 /* After an index is assigned, the table is frozen. */
4741 gcc_assert (entry
->refcount
> 0 && entry
->index
== NO_INDEX_ASSIGNED
);
4745 /* Given a location list, remove all addresses it refers to from the
4749 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4751 for (; descr
; descr
= descr
->dw_loc_next
)
4752 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4754 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4755 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4759 /* A helper function for dwarf2out_finish called through
4760 htab_traverse. Assign an addr_table_entry its index. All entries
4761 must be collected into the table when this function is called,
4762 because the indexing code relies on htab_traverse to traverse nodes
4763 in the same order for each run. */
4766 index_addr_table_entry (addr_table_entry
**h
, unsigned int *index
)
4768 addr_table_entry
*node
= *h
;
4770 /* Don't index unreferenced nodes. */
4771 if (node
->refcount
== 0)
4774 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
4775 node
->index
= *index
;
4781 /* Add an address constant attribute value to a DIE. When using
4782 dwarf_split_debug_info, address attributes in dies destined for the
4783 final executable should be direct references--setting the parameter
4784 force_direct ensures this behavior. */
4787 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4792 attr
.dw_attr
= attr_kind
;
4793 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4794 attr
.dw_attr_val
.v
.val_addr
= addr
;
4795 if (dwarf_split_debug_info
&& !force_direct
)
4796 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4798 attr
.dw_attr_val
.val_entry
= NULL
;
4799 add_dwarf_attr (die
, &attr
);
4802 /* Get the RTX from to an address DIE attribute. */
4805 AT_addr (dw_attr_node
*a
)
4807 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4808 return a
->dw_attr_val
.v
.val_addr
;
4811 /* Add a file attribute value to a DIE. */
4814 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4815 struct dwarf_file_data
*fd
)
4819 attr
.dw_attr
= attr_kind
;
4820 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4821 attr
.dw_attr_val
.val_entry
= NULL
;
4822 attr
.dw_attr_val
.v
.val_file
= fd
;
4823 add_dwarf_attr (die
, &attr
);
4826 /* Get the dwarf_file_data from a file DIE attribute. */
4828 static inline struct dwarf_file_data
*
4829 AT_file (dw_attr_node
*a
)
4831 gcc_assert (a
&& (AT_class (a
) == dw_val_class_file
4832 || AT_class (a
) == dw_val_class_file_implicit
));
4833 return a
->dw_attr_val
.v
.val_file
;
4836 /* Add a vms delta attribute value to a DIE. */
4839 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4840 const char *lbl1
, const char *lbl2
)
4844 attr
.dw_attr
= attr_kind
;
4845 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4846 attr
.dw_attr_val
.val_entry
= NULL
;
4847 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4848 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4849 add_dwarf_attr (die
, &attr
);
4852 /* Add a label identifier attribute value to a DIE. */
4855 add_AT_lbl_id (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_lbl_id
;
4862 attr
.dw_attr_val
.val_entry
= NULL
;
4863 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4864 if (dwarf_split_debug_info
)
4865 attr
.dw_attr_val
.val_entry
4866 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4868 add_dwarf_attr (die
, &attr
);
4871 /* Add a section offset attribute value to a DIE, an offset into the
4872 debug_line section. */
4875 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4880 attr
.dw_attr
= attr_kind
;
4881 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4882 attr
.dw_attr_val
.val_entry
= NULL
;
4883 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4884 add_dwarf_attr (die
, &attr
);
4887 /* Add a section offset attribute value to a DIE, an offset into the
4888 debug_loclists section. */
4891 add_AT_loclistsptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4896 attr
.dw_attr
= attr_kind
;
4897 attr
.dw_attr_val
.val_class
= dw_val_class_loclistsptr
;
4898 attr
.dw_attr_val
.val_entry
= NULL
;
4899 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4900 add_dwarf_attr (die
, &attr
);
4903 /* Add a section offset attribute value to a DIE, an offset into the
4904 debug_macinfo section. */
4907 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4912 attr
.dw_attr
= attr_kind
;
4913 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4914 attr
.dw_attr_val
.val_entry
= NULL
;
4915 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4916 add_dwarf_attr (die
, &attr
);
4919 /* Add an offset attribute value to a DIE. */
4922 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4923 unsigned HOST_WIDE_INT offset
)
4927 attr
.dw_attr
= attr_kind
;
4928 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4929 attr
.dw_attr_val
.val_entry
= NULL
;
4930 attr
.dw_attr_val
.v
.val_offset
= offset
;
4931 add_dwarf_attr (die
, &attr
);
4934 /* Add a range_list attribute value to a DIE. When using
4935 dwarf_split_debug_info, address attributes in dies destined for the
4936 final executable should be direct references--setting the parameter
4937 force_direct ensures this behavior. */
4939 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4940 #define RELOCATED_OFFSET (NULL)
4943 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4944 long unsigned int offset
, bool force_direct
)
4948 attr
.dw_attr
= attr_kind
;
4949 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4950 /* For the range_list attribute, use val_entry to store whether the
4951 offset should follow split-debug-info or normal semantics. This
4952 value is read in output_range_list_offset. */
4953 if (dwarf_split_debug_info
&& !force_direct
)
4954 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4956 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4957 attr
.dw_attr_val
.v
.val_offset
= offset
;
4958 add_dwarf_attr (die
, &attr
);
4961 /* Return the start label of a delta attribute. */
4963 static inline const char *
4964 AT_vms_delta1 (dw_attr_node
*a
)
4966 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4967 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4970 /* Return the end label of a delta attribute. */
4972 static inline const char *
4973 AT_vms_delta2 (dw_attr_node
*a
)
4975 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4976 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4979 static inline const char *
4980 AT_lbl (dw_attr_node
*a
)
4982 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4983 || AT_class (a
) == dw_val_class_lineptr
4984 || AT_class (a
) == dw_val_class_macptr
4985 || AT_class (a
) == dw_val_class_loclistsptr
4986 || AT_class (a
) == dw_val_class_high_pc
));
4987 return a
->dw_attr_val
.v
.val_lbl_id
;
4990 /* Get the attribute of type attr_kind. */
4992 static dw_attr_node
*
4993 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4997 dw_die_ref spec
= NULL
;
5002 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5003 if (a
->dw_attr
== attr_kind
)
5005 else if (a
->dw_attr
== DW_AT_specification
5006 || a
->dw_attr
== DW_AT_abstract_origin
)
5010 return get_AT (spec
, attr_kind
);
5015 /* Returns the parent of the declaration of DIE. */
5018 get_die_parent (dw_die_ref die
)
5025 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
5026 || (t
= get_AT_ref (die
, DW_AT_specification
)))
5029 return die
->die_parent
;
5032 /* Return the "low pc" attribute value, typically associated with a subprogram
5033 DIE. Return null if the "low pc" attribute is either not present, or if it
5034 cannot be represented as an assembler label identifier. */
5036 static inline const char *
5037 get_AT_low_pc (dw_die_ref die
)
5039 dw_attr_node
*a
= get_AT (die
, DW_AT_low_pc
);
5041 return a
? AT_lbl (a
) : NULL
;
5044 /* Return the "high pc" attribute value, typically associated with a subprogram
5045 DIE. Return null if the "high pc" attribute is either not present, or if it
5046 cannot be represented as an assembler label identifier. */
5048 static inline const char *
5049 get_AT_hi_pc (dw_die_ref die
)
5051 dw_attr_node
*a
= get_AT (die
, DW_AT_high_pc
);
5053 return a
? AT_lbl (a
) : NULL
;
5056 /* Return the value of the string attribute designated by ATTR_KIND, or
5057 NULL if it is not present. */
5059 static inline const char *
5060 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5062 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5064 return a
? AT_string (a
) : NULL
;
5067 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5068 if it is not present. */
5071 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5073 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5075 return a
? AT_flag (a
) : 0;
5078 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5079 if it is not present. */
5081 static inline unsigned
5082 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5084 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5086 return a
? AT_unsigned (a
) : 0;
5089 static inline dw_die_ref
5090 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5092 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5094 return a
? AT_ref (a
) : NULL
;
5097 static inline struct dwarf_file_data
*
5098 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5100 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5102 return a
? AT_file (a
) : NULL
;
5105 /* Return TRUE if the language is C++. */
5110 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5112 return (lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
5113 || lang
== DW_LANG_C_plus_plus_11
|| lang
== DW_LANG_C_plus_plus_14
);
5116 /* Return TRUE if DECL was created by the C++ frontend. */
5119 is_cxx (const_tree decl
)
5123 const_tree context
= get_ultimate_context (decl
);
5124 if (context
&& TRANSLATION_UNIT_LANGUAGE (context
))
5125 return strncmp (TRANSLATION_UNIT_LANGUAGE (context
), "GNU C++", 7) == 0;
5130 /* Return TRUE if the language is Fortran. */
5135 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5137 return (lang
== DW_LANG_Fortran77
5138 || lang
== DW_LANG_Fortran90
5139 || lang
== DW_LANG_Fortran95
5140 || lang
== DW_LANG_Fortran03
5141 || lang
== DW_LANG_Fortran08
);
5145 is_fortran (const_tree decl
)
5149 const_tree context
= get_ultimate_context (decl
);
5150 if (context
&& TRANSLATION_UNIT_LANGUAGE (context
))
5151 return (strncmp (TRANSLATION_UNIT_LANGUAGE (context
),
5152 "GNU Fortran", 11) == 0
5153 || strcmp (TRANSLATION_UNIT_LANGUAGE (context
),
5156 return is_fortran ();
5159 /* Return TRUE if the language is Ada. */
5164 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5166 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
5169 /* Remove the specified attribute if present. Return TRUE if removal
5173 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5181 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5182 if (a
->dw_attr
== attr_kind
)
5184 if (AT_class (a
) == dw_val_class_str
)
5185 if (a
->dw_attr_val
.v
.val_str
->refcount
)
5186 a
->dw_attr_val
.v
.val_str
->refcount
--;
5188 /* vec::ordered_remove should help reduce the number of abbrevs
5190 die
->die_attr
->ordered_remove (ix
);
5196 /* Remove CHILD from its parent. PREV must have the property that
5197 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
5200 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
5202 gcc_assert (child
->die_parent
== prev
->die_parent
);
5203 gcc_assert (prev
->die_sib
== child
);
5206 gcc_assert (child
->die_parent
->die_child
== child
);
5210 prev
->die_sib
= child
->die_sib
;
5211 if (child
->die_parent
->die_child
== child
)
5212 child
->die_parent
->die_child
= prev
;
5213 child
->die_sib
= NULL
;
5216 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
5217 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
5220 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
5222 dw_die_ref parent
= old_child
->die_parent
;
5224 gcc_assert (parent
== prev
->die_parent
);
5225 gcc_assert (prev
->die_sib
== old_child
);
5227 new_child
->die_parent
= parent
;
5228 if (prev
== old_child
)
5230 gcc_assert (parent
->die_child
== old_child
);
5231 new_child
->die_sib
= new_child
;
5235 prev
->die_sib
= new_child
;
5236 new_child
->die_sib
= old_child
->die_sib
;
5238 if (old_child
->die_parent
->die_child
== old_child
)
5239 old_child
->die_parent
->die_child
= new_child
;
5240 old_child
->die_sib
= NULL
;
5243 /* Move all children from OLD_PARENT to NEW_PARENT. */
5246 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
5249 new_parent
->die_child
= old_parent
->die_child
;
5250 old_parent
->die_child
= NULL
;
5251 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
5254 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
5258 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
5264 dw_die_ref prev
= c
;
5266 while (c
->die_tag
== tag
)
5268 remove_child_with_prev (c
, prev
);
5269 c
->die_parent
= NULL
;
5270 /* Might have removed every child. */
5271 if (die
->die_child
== NULL
)
5275 } while (c
!= die
->die_child
);
5278 /* Add a CHILD_DIE as the last child of DIE. */
5281 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
5283 /* FIXME this should probably be an assert. */
5284 if (! die
|| ! child_die
)
5286 gcc_assert (die
!= child_die
);
5288 child_die
->die_parent
= die
;
5291 child_die
->die_sib
= die
->die_child
->die_sib
;
5292 die
->die_child
->die_sib
= child_die
;
5295 child_die
->die_sib
= child_die
;
5296 die
->die_child
= child_die
;
5299 /* Like add_child_die, but put CHILD_DIE after AFTER_DIE. */
5302 add_child_die_after (dw_die_ref die
, dw_die_ref child_die
,
5303 dw_die_ref after_die
)
5309 && die
!= child_die
);
5311 child_die
->die_parent
= die
;
5312 child_die
->die_sib
= after_die
->die_sib
;
5313 after_die
->die_sib
= child_die
;
5314 if (die
->die_child
== after_die
)
5315 die
->die_child
= child_die
;
5318 /* Unassociate CHILD from its parent, and make its parent be
5322 reparent_child (dw_die_ref child
, dw_die_ref new_parent
)
5324 for (dw_die_ref p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
5325 if (p
->die_sib
== child
)
5327 remove_child_with_prev (child
, p
);
5330 add_child_die (new_parent
, child
);
5333 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5334 is the specification, to the end of PARENT's list of children.
5335 This is done by removing and re-adding it. */
5338 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
5340 /* We want the declaration DIE from inside the class, not the
5341 specification DIE at toplevel. */
5342 if (child
->die_parent
!= parent
)
5344 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5350 gcc_assert (child
->die_parent
== parent
5351 || (child
->die_parent
5352 == get_AT_ref (parent
, DW_AT_specification
)));
5354 reparent_child (child
, parent
);
5357 /* Create and return a new die with TAG_VALUE as tag. */
5359 static inline dw_die_ref
5360 new_die_raw (enum dwarf_tag tag_value
)
5362 dw_die_ref die
= ggc_cleared_alloc
<die_node
> ();
5363 die
->die_tag
= tag_value
;
5367 /* Create and return a new die with a parent of PARENT_DIE. If
5368 PARENT_DIE is NULL, the new DIE is placed in limbo and an
5369 associated tree T must be supplied to determine parenthood
5372 static inline dw_die_ref
5373 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
5375 dw_die_ref die
= new_die_raw (tag_value
);
5377 if (parent_die
!= NULL
)
5378 add_child_die (parent_die
, die
);
5381 limbo_die_node
*limbo_node
;
5383 /* No DIEs created after early dwarf should end up in limbo,
5384 because the limbo list should not persist past LTO
5386 if (tag_value
!= DW_TAG_compile_unit
5387 /* These are allowed because they're generated while
5388 breaking out COMDAT units late. */
5389 && tag_value
!= DW_TAG_type_unit
5390 && tag_value
!= DW_TAG_skeleton_unit
5392 /* Allow nested functions to live in limbo because they will
5393 only temporarily live there, as decls_for_scope will fix
5395 && (TREE_CODE (t
) != FUNCTION_DECL
5396 || !decl_function_context (t
))
5397 /* Same as nested functions above but for types. Types that
5398 are local to a function will be fixed in
5400 && (!RECORD_OR_UNION_TYPE_P (t
)
5401 || !TYPE_CONTEXT (t
)
5402 || TREE_CODE (TYPE_CONTEXT (t
)) != FUNCTION_DECL
)
5403 /* FIXME debug-early: Allow late limbo DIE creation for LTO,
5404 especially in the ltrans stage, but once we implement LTO
5405 dwarf streaming, we should remove this exception. */
5408 fprintf (stderr
, "symbol ended up in limbo too late:");
5409 debug_generic_stmt (t
);
5413 limbo_node
= ggc_cleared_alloc
<limbo_die_node
> ();
5414 limbo_node
->die
= die
;
5415 limbo_node
->created_for
= t
;
5416 limbo_node
->next
= limbo_die_list
;
5417 limbo_die_list
= limbo_node
;
5423 /* Return the DIE associated with the given type specifier. */
5425 static inline dw_die_ref
5426 lookup_type_die (tree type
)
5428 dw_die_ref die
= TYPE_SYMTAB_DIE (type
);
5429 if (die
&& die
->removed
)
5431 TYPE_SYMTAB_DIE (type
) = NULL
;
5437 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
5438 anonymous type named by the typedef TYPE_DIE, return the DIE of the
5439 anonymous type instead the one of the naming typedef. */
5441 static inline dw_die_ref
5442 strip_naming_typedef (tree type
, dw_die_ref type_die
)
5445 && TREE_CODE (type
) == RECORD_TYPE
5447 && type_die
->die_tag
== DW_TAG_typedef
5448 && is_naming_typedef_decl (TYPE_NAME (type
)))
5449 type_die
= get_AT_ref (type_die
, DW_AT_type
);
5453 /* Like lookup_type_die, but if type is an anonymous type named by a
5454 typedef[1], return the DIE of the anonymous type instead the one of
5455 the naming typedef. This is because in gen_typedef_die, we did
5456 equate the anonymous struct named by the typedef with the DIE of
5457 the naming typedef. So by default, lookup_type_die on an anonymous
5458 struct yields the DIE of the naming typedef.
5460 [1]: Read the comment of is_naming_typedef_decl to learn about what
5461 a naming typedef is. */
5463 static inline dw_die_ref
5464 lookup_type_die_strip_naming_typedef (tree type
)
5466 dw_die_ref die
= lookup_type_die (type
);
5467 return strip_naming_typedef (type
, die
);
5470 /* Equate a DIE to a given type specifier. */
5473 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5475 TYPE_SYMTAB_DIE (type
) = type_die
;
5478 /* Returns a hash value for X (which really is a die_struct). */
5481 decl_die_hasher::hash (die_node
*x
)
5483 return (hashval_t
) x
->decl_id
;
5486 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5489 decl_die_hasher::equal (die_node
*x
, tree y
)
5491 return (x
->decl_id
== DECL_UID (y
));
5494 /* Return the DIE associated with a given declaration. */
5496 static inline dw_die_ref
5497 lookup_decl_die (tree decl
)
5499 dw_die_ref
*die
= decl_die_table
->find_slot_with_hash (decl
, DECL_UID (decl
),
5503 if ((*die
)->removed
)
5505 decl_die_table
->clear_slot (die
);
5512 /* For DECL which might have early dwarf output query a SYMBOL + OFFSET
5513 style reference. Return true if we found one refering to a DIE for
5514 DECL, otherwise return false. */
5517 dwarf2out_die_ref_for_decl (tree decl
, const char **sym
,
5518 unsigned HOST_WIDE_INT
*off
)
5522 if (flag_wpa
&& !decl_die_table
)
5525 if (TREE_CODE (decl
) == BLOCK
)
5526 die
= BLOCK_DIE (decl
);
5528 die
= lookup_decl_die (decl
);
5532 /* During WPA stage we currently use DIEs to store the
5533 decl <-> label + offset map. That's quite inefficient but it
5537 dw_die_ref ref
= get_AT_ref (die
, DW_AT_abstract_origin
);
5540 gcc_assert (die
== comp_unit_die ());
5543 *off
= ref
->die_offset
;
5544 *sym
= ref
->die_id
.die_symbol
;
5548 /* Similar to get_ref_die_offset_label, but using the "correct"
5550 *off
= die
->die_offset
;
5551 while (die
->die_parent
)
5552 die
= die
->die_parent
;
5553 /* For the containing CU DIE we compute a die_symbol in
5554 compute_comp_unit_symbol. */
5555 gcc_assert (die
->die_tag
== DW_TAG_compile_unit
5556 && die
->die_id
.die_symbol
!= NULL
);
5557 *sym
= die
->die_id
.die_symbol
;
5561 /* Add a reference of kind ATTR_KIND to a DIE at SYMBOL + OFFSET to DIE. */
5564 add_AT_external_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5565 const char *symbol
, HOST_WIDE_INT offset
)
5567 /* Create a fake DIE that contains the reference. Don't use
5568 new_die because we don't want to end up in the limbo list. */
5569 dw_die_ref ref
= new_die_raw (die
->die_tag
);
5570 ref
->die_id
.die_symbol
= IDENTIFIER_POINTER (get_identifier (symbol
));
5571 ref
->die_offset
= offset
;
5572 ref
->with_offset
= 1;
5573 add_AT_die_ref (die
, attr_kind
, ref
);
5576 /* Create a DIE for DECL if required and add a reference to a DIE
5577 at SYMBOL + OFFSET which contains attributes dumped early. */
5580 dwarf2out_register_external_die (tree decl
, const char *sym
,
5581 unsigned HOST_WIDE_INT off
)
5583 if (debug_info_level
== DINFO_LEVEL_NONE
)
5586 if (flag_wpa
&& !decl_die_table
)
5587 decl_die_table
= hash_table
<decl_die_hasher
>::create_ggc (1000);
5590 = TREE_CODE (decl
) == BLOCK
? BLOCK_DIE (decl
) : lookup_decl_die (decl
);
5594 dw_die_ref parent
= NULL
;
5595 /* Need to lookup a DIE for the decls context - the containing
5596 function or translation unit. */
5597 if (TREE_CODE (decl
) == BLOCK
)
5599 ctx
= BLOCK_SUPERCONTEXT (decl
);
5600 /* ??? We do not output DIEs for all scopes thus skip as
5601 many DIEs as needed. */
5602 while (TREE_CODE (ctx
) == BLOCK
5603 && !BLOCK_DIE (ctx
))
5604 ctx
= BLOCK_SUPERCONTEXT (ctx
);
5607 ctx
= DECL_CONTEXT (decl
);
5608 while (ctx
&& TYPE_P (ctx
))
5609 ctx
= TYPE_CONTEXT (ctx
);
5612 if (TREE_CODE (ctx
) == BLOCK
)
5613 parent
= BLOCK_DIE (ctx
);
5614 else if (TREE_CODE (ctx
) == TRANSLATION_UNIT_DECL
5615 /* Keep the 1:1 association during WPA. */
5617 /* Otherwise all late annotations go to the main CU which
5618 imports the original CUs. */
5619 parent
= comp_unit_die ();
5620 else if (TREE_CODE (ctx
) == FUNCTION_DECL
5621 && TREE_CODE (decl
) != PARM_DECL
5622 && TREE_CODE (decl
) != BLOCK
)
5623 /* Leave function local entities parent determination to when
5624 we process scope vars. */
5627 parent
= lookup_decl_die (ctx
);
5630 /* In some cases the FEs fail to set DECL_CONTEXT properly.
5631 Handle this case gracefully by globalizing stuff. */
5632 parent
= comp_unit_die ();
5633 /* Create a DIE "stub". */
5634 switch (TREE_CODE (decl
))
5636 case TRANSLATION_UNIT_DECL
:
5639 die
= comp_unit_die ();
5640 dw_die_ref import
= new_die (DW_TAG_imported_unit
, die
, NULL_TREE
);
5641 add_AT_external_die_ref (import
, DW_AT_import
, sym
, off
);
5642 /* We re-target all CU decls to the LTRANS CU DIE, so no need
5643 to create a DIE for the original CUs. */
5646 /* Keep the 1:1 association during WPA. */
5647 die
= new_die (DW_TAG_compile_unit
, NULL
, decl
);
5649 case NAMESPACE_DECL
:
5650 if (is_fortran (decl
))
5651 die
= new_die (DW_TAG_module
, parent
, decl
);
5653 die
= new_die (DW_TAG_namespace
, parent
, decl
);
5656 die
= new_die (DW_TAG_subprogram
, parent
, decl
);
5659 die
= new_die (DW_TAG_variable
, parent
, decl
);
5662 die
= new_die (DW_TAG_variable
, parent
, decl
);
5665 die
= new_die (DW_TAG_formal_parameter
, parent
, decl
);
5668 die
= new_die (DW_TAG_constant
, parent
, decl
);
5671 die
= new_die (DW_TAG_label
, parent
, decl
);
5674 die
= new_die (DW_TAG_lexical_block
, parent
, decl
);
5679 if (TREE_CODE (decl
) == BLOCK
)
5680 BLOCK_DIE (decl
) = die
;
5682 equate_decl_number_to_die (decl
, die
);
5684 /* Add a reference to the DIE providing early debug at $sym + off. */
5685 add_AT_external_die_ref (die
, DW_AT_abstract_origin
, sym
, off
);
5688 /* Returns a hash value for X (which really is a var_loc_list). */
5691 decl_loc_hasher::hash (var_loc_list
*x
)
5693 return (hashval_t
) x
->decl_id
;
5696 /* Return nonzero if decl_id of var_loc_list X is the same as
5700 decl_loc_hasher::equal (var_loc_list
*x
, const_tree y
)
5702 return (x
->decl_id
== DECL_UID (y
));
5705 /* Return the var_loc list associated with a given declaration. */
5707 static inline var_loc_list
*
5708 lookup_decl_loc (const_tree decl
)
5710 if (!decl_loc_table
)
5712 return decl_loc_table
->find_with_hash (decl
, DECL_UID (decl
));
5715 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5718 dw_loc_list_hasher::hash (cached_dw_loc_list
*x
)
5720 return (hashval_t
) x
->decl_id
;
5723 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5727 dw_loc_list_hasher::equal (cached_dw_loc_list
*x
, const_tree y
)
5729 return (x
->decl_id
== DECL_UID (y
));
5732 /* Equate a DIE to a particular declaration. */
5735 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5737 unsigned int decl_id
= DECL_UID (decl
);
5739 *decl_die_table
->find_slot_with_hash (decl
, decl_id
, INSERT
) = decl_die
;
5740 decl_die
->decl_id
= decl_id
;
5743 /* Return how many bits covers PIECE EXPR_LIST. */
5745 static HOST_WIDE_INT
5746 decl_piece_bitsize (rtx piece
)
5748 int ret
= (int) GET_MODE (piece
);
5751 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
5752 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
5753 return INTVAL (XEXP (XEXP (piece
, 0), 0));
5756 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5759 decl_piece_varloc_ptr (rtx piece
)
5761 if ((int) GET_MODE (piece
))
5762 return &XEXP (piece
, 0);
5764 return &XEXP (XEXP (piece
, 0), 1);
5767 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5768 Next is the chain of following piece nodes. */
5770 static rtx_expr_list
*
5771 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
5773 if (bitsize
> 0 && bitsize
<= (int) MAX_MACHINE_MODE
)
5774 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
5776 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
5781 /* Return rtx that should be stored into loc field for
5782 LOC_NOTE and BITPOS/BITSIZE. */
5785 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
5786 HOST_WIDE_INT bitsize
)
5790 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
5792 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
5797 /* This function either modifies location piece list *DEST in
5798 place (if SRC and INNER is NULL), or copies location piece list
5799 *SRC to *DEST while modifying it. Location BITPOS is modified
5800 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5801 not copied and if needed some padding around it is added.
5802 When modifying in place, DEST should point to EXPR_LIST where
5803 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5804 to the start of the whole list and INNER points to the EXPR_LIST
5805 where earlier pieces cover PIECE_BITPOS bits. */
5808 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
5809 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
5810 HOST_WIDE_INT bitsize
, rtx loc_note
)
5813 bool copy
= inner
!= NULL
;
5817 /* First copy all nodes preceding the current bitpos. */
5818 while (src
!= inner
)
5820 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5821 decl_piece_bitsize (*src
), NULL_RTX
);
5822 dest
= &XEXP (*dest
, 1);
5823 src
= &XEXP (*src
, 1);
5826 /* Add padding if needed. */
5827 if (bitpos
!= piece_bitpos
)
5829 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5830 copy
? NULL_RTX
: *dest
);
5831 dest
= &XEXP (*dest
, 1);
5833 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5836 /* A piece with correct bitpos and bitsize already exist,
5837 just update the location for it and return. */
5838 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5841 /* Add the piece that changed. */
5842 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5843 dest
= &XEXP (*dest
, 1);
5844 /* Skip over pieces that overlap it. */
5845 diff
= bitpos
- piece_bitpos
+ bitsize
;
5848 while (diff
> 0 && *src
)
5851 diff
-= decl_piece_bitsize (piece
);
5853 src
= &XEXP (piece
, 1);
5856 *src
= XEXP (piece
, 1);
5857 free_EXPR_LIST_node (piece
);
5860 /* Add padding if needed. */
5861 if (diff
< 0 && *src
)
5865 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5866 dest
= &XEXP (*dest
, 1);
5870 /* Finally copy all nodes following it. */
5873 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5874 decl_piece_bitsize (*src
), NULL_RTX
);
5875 dest
= &XEXP (*dest
, 1);
5876 src
= &XEXP (*src
, 1);
5880 /* Add a variable location node to the linked list for DECL. */
5882 static struct var_loc_node
*
5883 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5885 unsigned int decl_id
;
5887 struct var_loc_node
*loc
= NULL
;
5888 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5890 if (VAR_P (decl
) && DECL_HAS_DEBUG_EXPR_P (decl
))
5892 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5893 if (handled_component_p (realdecl
)
5894 || (TREE_CODE (realdecl
) == MEM_REF
5895 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5897 HOST_WIDE_INT maxsize
;
5900 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
,
5902 if (!DECL_P (innerdecl
)
5903 || DECL_IGNORED_P (innerdecl
)
5904 || TREE_STATIC (innerdecl
)
5906 || bitpos
+ bitsize
> 256
5907 || bitsize
!= maxsize
)
5913 decl_id
= DECL_UID (decl
);
5915 = decl_loc_table
->find_slot_with_hash (decl
, decl_id
, INSERT
);
5918 temp
= ggc_cleared_alloc
<var_loc_list
> ();
5919 temp
->decl_id
= decl_id
;
5925 /* For PARM_DECLs try to keep around the original incoming value,
5926 even if that means we'll emit a zero-range .debug_loc entry. */
5928 && temp
->first
== temp
->last
5929 && TREE_CODE (decl
) == PARM_DECL
5930 && NOTE_P (temp
->first
->loc
)
5931 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5932 && DECL_INCOMING_RTL (decl
)
5933 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5934 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5935 == GET_CODE (DECL_INCOMING_RTL (decl
))
5936 && prev_real_insn (as_a
<rtx_insn
*> (temp
->first
->loc
)) == NULL_RTX
5938 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5939 NOTE_VAR_LOCATION_LOC (loc_note
))
5940 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5941 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5943 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5944 temp
->first
->next
= loc
;
5946 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5948 else if (temp
->last
)
5950 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5951 rtx
*piece_loc
= NULL
, last_loc_note
;
5952 HOST_WIDE_INT piece_bitpos
= 0;
5956 gcc_assert (last
->next
== NULL
);
5958 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5960 piece_loc
= &last
->loc
;
5963 HOST_WIDE_INT cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5964 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5966 piece_bitpos
+= cur_bitsize
;
5967 piece_loc
= &XEXP (*piece_loc
, 1);
5971 /* TEMP->LAST here is either pointer to the last but one or
5972 last element in the chained list, LAST is pointer to the
5974 if (label
&& strcmp (last
->label
, label
) == 0)
5976 /* For SRA optimized variables if there weren't any real
5977 insns since last note, just modify the last node. */
5978 if (piece_loc
!= NULL
)
5980 adjust_piece_list (piece_loc
, NULL
, NULL
,
5981 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5984 /* If the last note doesn't cover any instructions, remove it. */
5985 if (temp
->last
!= last
)
5987 temp
->last
->next
= NULL
;
5990 gcc_assert (strcmp (last
->label
, label
) != 0);
5994 gcc_assert (temp
->first
== temp
->last
5995 || (temp
->first
->next
== temp
->last
5996 && TREE_CODE (decl
) == PARM_DECL
));
5997 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5998 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
6002 if (bitsize
== -1 && NOTE_P (last
->loc
))
6003 last_loc_note
= last
->loc
;
6004 else if (piece_loc
!= NULL
6005 && *piece_loc
!= NULL_RTX
6006 && piece_bitpos
== bitpos
6007 && decl_piece_bitsize (*piece_loc
) == bitsize
)
6008 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
6010 last_loc_note
= NULL_RTX
;
6011 /* If the current location is the same as the end of the list,
6012 and either both or neither of the locations is uninitialized,
6013 we have nothing to do. */
6014 if (last_loc_note
== NULL_RTX
6015 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
6016 NOTE_VAR_LOCATION_LOC (loc_note
)))
6017 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
6018 != NOTE_VAR_LOCATION_STATUS (loc_note
))
6019 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
6020 == VAR_INIT_STATUS_UNINITIALIZED
)
6021 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
6022 == VAR_INIT_STATUS_UNINITIALIZED
))))
6024 /* Add LOC to the end of list and update LAST. If the last
6025 element of the list has been removed above, reuse its
6026 memory for the new node, otherwise allocate a new one. */
6030 memset (loc
, '\0', sizeof (*loc
));
6033 loc
= ggc_cleared_alloc
<var_loc_node
> ();
6034 if (bitsize
== -1 || piece_loc
== NULL
)
6035 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
6037 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
6038 bitpos
, piece_bitpos
, bitsize
, loc_note
);
6040 /* Ensure TEMP->LAST will point either to the new last but one
6041 element of the chain, or to the last element in it. */
6042 if (last
!= temp
->last
)
6050 loc
= ggc_cleared_alloc
<var_loc_node
> ();
6053 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
6058 /* Keep track of the number of spaces used to indent the
6059 output of the debugging routines that print the structure of
6060 the DIE internal representation. */
6061 static int print_indent
;
6063 /* Indent the line the number of spaces given by print_indent. */
6066 print_spaces (FILE *outfile
)
6068 fprintf (outfile
, "%*s", print_indent
, "");
6071 /* Print a type signature in hex. */
6074 print_signature (FILE *outfile
, char *sig
)
6078 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
6079 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
6083 print_discr_value (FILE *outfile
, dw_discr_value
*discr_value
)
6085 if (discr_value
->pos
)
6086 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, discr_value
->v
.sval
);
6088 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, discr_value
->v
.uval
);
6091 static void print_loc_descr (dw_loc_descr_ref
, FILE *);
6093 /* Print the value associated to the VAL DWARF value node to OUTFILE. If
6094 RECURSE, output location descriptor operations. */
6097 print_dw_val (dw_val_node
*val
, bool recurse
, FILE *outfile
)
6099 switch (val
->val_class
)
6101 case dw_val_class_addr
:
6102 fprintf (outfile
, "address");
6104 case dw_val_class_offset
:
6105 fprintf (outfile
, "offset");
6107 case dw_val_class_loc
:
6108 fprintf (outfile
, "location descriptor");
6109 if (val
->v
.val_loc
== NULL
)
6110 fprintf (outfile
, " -> <null>\n");
6113 fprintf (outfile
, ":\n");
6115 print_loc_descr (val
->v
.val_loc
, outfile
);
6119 fprintf (outfile
, " (%p)\n", (void *) val
->v
.val_loc
);
6121 case dw_val_class_loc_list
:
6122 fprintf (outfile
, "location list -> label:%s",
6123 val
->v
.val_loc_list
->ll_symbol
);
6125 case dw_val_class_range_list
:
6126 fprintf (outfile
, "range list");
6128 case dw_val_class_const
:
6129 case dw_val_class_const_implicit
:
6130 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, val
->v
.val_int
);
6132 case dw_val_class_unsigned_const
:
6133 case dw_val_class_unsigned_const_implicit
:
6134 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, val
->v
.val_unsigned
);
6136 case dw_val_class_const_double
:
6137 fprintf (outfile
, "constant (" HOST_WIDE_INT_PRINT_DEC
","\
6138 HOST_WIDE_INT_PRINT_UNSIGNED
")",
6139 val
->v
.val_double
.high
,
6140 val
->v
.val_double
.low
);
6142 case dw_val_class_wide_int
:
6144 int i
= val
->v
.val_wide
->get_len ();
6145 fprintf (outfile
, "constant (");
6147 if (val
->v
.val_wide
->elt (i
- 1) == 0)
6148 fprintf (outfile
, "0x");
6149 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
,
6150 val
->v
.val_wide
->elt (--i
));
6152 fprintf (outfile
, HOST_WIDE_INT_PRINT_PADDED_HEX
,
6153 val
->v
.val_wide
->elt (i
));
6154 fprintf (outfile
, ")");
6157 case dw_val_class_vec
:
6158 fprintf (outfile
, "floating-point or vector constant");
6160 case dw_val_class_flag
:
6161 fprintf (outfile
, "%u", val
->v
.val_flag
);
6163 case dw_val_class_die_ref
:
6164 if (val
->v
.val_die_ref
.die
!= NULL
)
6166 dw_die_ref die
= val
->v
.val_die_ref
.die
;
6168 if (die
->comdat_type_p
)
6170 fprintf (outfile
, "die -> signature: ");
6171 print_signature (outfile
,
6172 die
->die_id
.die_type_node
->signature
);
6174 else if (die
->die_id
.die_symbol
)
6176 fprintf (outfile
, "die -> label: %s", die
->die_id
.die_symbol
);
6177 if (die
->with_offset
)
6178 fprintf (outfile
, " + %ld", die
->die_offset
);
6181 fprintf (outfile
, "die -> %ld", die
->die_offset
);
6182 fprintf (outfile
, " (%p)", (void *) die
);
6185 fprintf (outfile
, "die -> <null>");
6187 case dw_val_class_vms_delta
:
6188 fprintf (outfile
, "delta: @slotcount(%s-%s)",
6189 val
->v
.val_vms_delta
.lbl2
, val
->v
.val_vms_delta
.lbl1
);
6191 case dw_val_class_lbl_id
:
6192 case dw_val_class_lineptr
:
6193 case dw_val_class_macptr
:
6194 case dw_val_class_loclistsptr
:
6195 case dw_val_class_high_pc
:
6196 fprintf (outfile
, "label: %s", val
->v
.val_lbl_id
);
6198 case dw_val_class_str
:
6199 if (val
->v
.val_str
->str
!= NULL
)
6200 fprintf (outfile
, "\"%s\"", val
->v
.val_str
->str
);
6202 fprintf (outfile
, "<null>");
6204 case dw_val_class_file
:
6205 case dw_val_class_file_implicit
:
6206 fprintf (outfile
, "\"%s\" (%d)", val
->v
.val_file
->filename
,
6207 val
->v
.val_file
->emitted_number
);
6209 case dw_val_class_data8
:
6213 for (i
= 0; i
< 8; i
++)
6214 fprintf (outfile
, "%02x", val
->v
.val_data8
[i
]);
6217 case dw_val_class_discr_value
:
6218 print_discr_value (outfile
, &val
->v
.val_discr_value
);
6220 case dw_val_class_discr_list
:
6221 for (dw_discr_list_ref node
= val
->v
.val_discr_list
;
6223 node
= node
->dw_discr_next
)
6225 if (node
->dw_discr_range
)
6227 fprintf (outfile
, " .. ");
6228 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
6229 print_discr_value (outfile
, &node
->dw_discr_upper_bound
);
6232 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
6234 if (node
->dw_discr_next
!= NULL
)
6235 fprintf (outfile
, " | ");
6242 /* Likewise, for a DIE attribute. */
6245 print_attribute (dw_attr_node
*a
, bool recurse
, FILE *outfile
)
6247 print_dw_val (&a
->dw_attr_val
, recurse
, outfile
);
6251 /* Print the list of operands in the LOC location description to OUTFILE. This
6252 routine is a debugging aid only. */
6255 print_loc_descr (dw_loc_descr_ref loc
, FILE *outfile
)
6257 dw_loc_descr_ref l
= loc
;
6261 print_spaces (outfile
);
6262 fprintf (outfile
, "<null>\n");
6266 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
6268 print_spaces (outfile
);
6269 fprintf (outfile
, "(%p) %s",
6271 dwarf_stack_op_name (l
->dw_loc_opc
));
6272 if (l
->dw_loc_oprnd1
.val_class
!= dw_val_class_none
)
6274 fprintf (outfile
, " ");
6275 print_dw_val (&l
->dw_loc_oprnd1
, false, outfile
);
6277 if (l
->dw_loc_oprnd2
.val_class
!= dw_val_class_none
)
6279 fprintf (outfile
, ", ");
6280 print_dw_val (&l
->dw_loc_oprnd2
, false, outfile
);
6282 fprintf (outfile
, "\n");
6286 /* Print the information associated with a given DIE, and its children.
6287 This routine is a debugging aid only. */
6290 print_die (dw_die_ref die
, FILE *outfile
)
6296 print_spaces (outfile
);
6297 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
6298 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
6300 print_spaces (outfile
);
6301 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
6302 fprintf (outfile
, " offset: %ld", die
->die_offset
);
6303 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
6305 if (die
->comdat_type_p
)
6307 print_spaces (outfile
);
6308 fprintf (outfile
, " signature: ");
6309 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
6310 fprintf (outfile
, "\n");
6313 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6315 print_spaces (outfile
);
6316 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
6318 print_attribute (a
, true, outfile
);
6319 fprintf (outfile
, "\n");
6322 if (die
->die_child
!= NULL
)
6325 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
6328 if (print_indent
== 0)
6329 fprintf (outfile
, "\n");
6332 /* Print the list of operations in the LOC location description. */
6335 debug_dwarf_loc_descr (dw_loc_descr_ref loc
)
6337 print_loc_descr (loc
, stderr
);
6340 /* Print the information collected for a given DIE. */
6343 debug_dwarf_die (dw_die_ref die
)
6345 print_die (die
, stderr
);
6349 debug (die_struct
&ref
)
6351 print_die (&ref
, stderr
);
6355 debug (die_struct
*ptr
)
6360 fprintf (stderr
, "<nil>\n");
6364 /* Print all DWARF information collected for the compilation unit.
6365 This routine is a debugging aid only. */
6371 print_die (comp_unit_die (), stderr
);
6374 /* Verify the DIE tree structure. */
6377 verify_die (dw_die_ref die
)
6379 gcc_assert (!die
->die_mark
);
6380 if (die
->die_parent
== NULL
6381 && die
->die_sib
== NULL
)
6383 /* Verify the die_sib list is cyclic. */
6390 while (x
&& !x
->die_mark
);
6391 gcc_assert (x
== die
);
6395 /* Verify all dies have the same parent. */
6396 gcc_assert (x
->die_parent
== die
->die_parent
);
6399 /* Verify the child has the proper parent and recurse. */
6400 gcc_assert (x
->die_child
->die_parent
== x
);
6401 verify_die (x
->die_child
);
6406 while (x
&& x
->die_mark
);
6409 /* Sanity checks on DIEs. */
6412 check_die (dw_die_ref die
)
6416 bool inline_found
= false;
6417 int n_location
= 0, n_low_pc
= 0, n_high_pc
= 0, n_artificial
= 0;
6418 int n_decl_line
= 0, n_decl_column
= 0, n_decl_file
= 0;
6419 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6424 if (a
->dw_attr_val
.v
.val_unsigned
)
6425 inline_found
= true;
6427 case DW_AT_location
:
6436 case DW_AT_artificial
:
6439 case DW_AT_decl_column
:
6442 case DW_AT_decl_line
:
6445 case DW_AT_decl_file
:
6452 if (n_location
> 1 || n_low_pc
> 1 || n_high_pc
> 1 || n_artificial
> 1
6453 || n_decl_column
> 1 || n_decl_line
> 1 || n_decl_file
> 1)
6455 fprintf (stderr
, "Duplicate attributes in DIE:\n");
6456 debug_dwarf_die (die
);
6461 /* A debugging information entry that is a member of an abstract
6462 instance tree [that has DW_AT_inline] should not contain any
6463 attributes which describe aspects of the subroutine which vary
6464 between distinct inlined expansions or distinct out-of-line
6466 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6467 gcc_assert (a
->dw_attr
!= DW_AT_low_pc
6468 && a
->dw_attr
!= DW_AT_high_pc
6469 && a
->dw_attr
!= DW_AT_location
6470 && a
->dw_attr
!= DW_AT_frame_base
6471 && a
->dw_attr
!= DW_AT_call_all_calls
6472 && a
->dw_attr
!= DW_AT_GNU_all_call_sites
);
6476 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6477 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
6478 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
6480 /* Calculate the checksum of a location expression. */
6483 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
6486 inchash::hash hstate
;
6489 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
6491 hash_loc_operands (loc
, hstate
);
6492 hash
= hstate
.end();
6496 /* Calculate the checksum of an attribute. */
6499 attr_checksum (dw_attr_node
*at
, struct md5_ctx
*ctx
, int *mark
)
6501 dw_loc_descr_ref loc
;
6504 CHECKSUM (at
->dw_attr
);
6506 /* We don't care that this was compiled with a different compiler
6507 snapshot; if the output is the same, that's what matters. */
6508 if (at
->dw_attr
== DW_AT_producer
)
6511 switch (AT_class (at
))
6513 case dw_val_class_const
:
6514 case dw_val_class_const_implicit
:
6515 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
6517 case dw_val_class_unsigned_const
:
6518 case dw_val_class_unsigned_const_implicit
:
6519 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
6521 case dw_val_class_const_double
:
6522 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
6524 case dw_val_class_wide_int
:
6525 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
6526 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6527 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
6529 case dw_val_class_vec
:
6530 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
6531 (at
->dw_attr_val
.v
.val_vec
.length
6532 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
6534 case dw_val_class_flag
:
6535 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
6537 case dw_val_class_str
:
6538 CHECKSUM_STRING (AT_string (at
));
6541 case dw_val_class_addr
:
6543 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6544 CHECKSUM_STRING (XSTR (r
, 0));
6547 case dw_val_class_offset
:
6548 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
6551 case dw_val_class_loc
:
6552 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6553 loc_checksum (loc
, ctx
);
6556 case dw_val_class_die_ref
:
6557 die_checksum (AT_ref (at
), ctx
, mark
);
6560 case dw_val_class_fde_ref
:
6561 case dw_val_class_vms_delta
:
6562 case dw_val_class_lbl_id
:
6563 case dw_val_class_lineptr
:
6564 case dw_val_class_macptr
:
6565 case dw_val_class_loclistsptr
:
6566 case dw_val_class_high_pc
:
6569 case dw_val_class_file
:
6570 case dw_val_class_file_implicit
:
6571 CHECKSUM_STRING (AT_file (at
)->filename
);
6574 case dw_val_class_data8
:
6575 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6583 /* Calculate the checksum of a DIE. */
6586 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6592 /* To avoid infinite recursion. */
6595 CHECKSUM (die
->die_mark
);
6598 die
->die_mark
= ++(*mark
);
6600 CHECKSUM (die
->die_tag
);
6602 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6603 attr_checksum (a
, ctx
, mark
);
6605 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
6609 #undef CHECKSUM_BLOCK
6610 #undef CHECKSUM_STRING
6612 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
6613 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6614 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
6615 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
6616 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
6617 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
6618 #define CHECKSUM_ATTR(FOO) \
6619 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
6621 /* Calculate the checksum of a number in signed LEB128 format. */
6624 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
6631 byte
= (value
& 0x7f);
6633 more
= !((value
== 0 && (byte
& 0x40) == 0)
6634 || (value
== -1 && (byte
& 0x40) != 0));
6643 /* Calculate the checksum of a number in unsigned LEB128 format. */
6646 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
6650 unsigned char byte
= (value
& 0x7f);
6653 /* More bytes to follow. */
6661 /* Checksum the context of the DIE. This adds the names of any
6662 surrounding namespaces or structures to the checksum. */
6665 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
6669 int tag
= die
->die_tag
;
6671 if (tag
!= DW_TAG_namespace
6672 && tag
!= DW_TAG_structure_type
6673 && tag
!= DW_TAG_class_type
)
6676 name
= get_AT_string (die
, DW_AT_name
);
6678 spec
= get_AT_ref (die
, DW_AT_specification
);
6682 if (die
->die_parent
!= NULL
)
6683 checksum_die_context (die
->die_parent
, ctx
);
6685 CHECKSUM_ULEB128 ('C');
6686 CHECKSUM_ULEB128 (tag
);
6688 CHECKSUM_STRING (name
);
6691 /* Calculate the checksum of a location expression. */
6694 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
6696 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
6697 were emitted as a DW_FORM_sdata instead of a location expression. */
6698 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
6700 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6701 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
6705 /* Otherwise, just checksum the raw location expression. */
6708 inchash::hash hstate
;
6711 CHECKSUM_ULEB128 (loc
->dtprel
);
6712 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
6713 hash_loc_operands (loc
, hstate
);
6714 hash
= hstate
.end ();
6716 loc
= loc
->dw_loc_next
;
6720 /* Calculate the checksum of an attribute. */
6723 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_node
*at
,
6724 struct md5_ctx
*ctx
, int *mark
)
6726 dw_loc_descr_ref loc
;
6729 if (AT_class (at
) == dw_val_class_die_ref
)
6731 dw_die_ref target_die
= AT_ref (at
);
6733 /* For pointer and reference types, we checksum only the (qualified)
6734 name of the target type (if there is a name). For friend entries,
6735 we checksum only the (qualified) name of the target type or function.
6736 This allows the checksum to remain the same whether the target type
6737 is complete or not. */
6738 if ((at
->dw_attr
== DW_AT_type
6739 && (tag
== DW_TAG_pointer_type
6740 || tag
== DW_TAG_reference_type
6741 || tag
== DW_TAG_rvalue_reference_type
6742 || tag
== DW_TAG_ptr_to_member_type
))
6743 || (at
->dw_attr
== DW_AT_friend
6744 && tag
== DW_TAG_friend
))
6746 dw_attr_node
*name_attr
= get_AT (target_die
, DW_AT_name
);
6748 if (name_attr
!= NULL
)
6750 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6754 CHECKSUM_ULEB128 ('N');
6755 CHECKSUM_ULEB128 (at
->dw_attr
);
6756 if (decl
->die_parent
!= NULL
)
6757 checksum_die_context (decl
->die_parent
, ctx
);
6758 CHECKSUM_ULEB128 ('E');
6759 CHECKSUM_STRING (AT_string (name_attr
));
6764 /* For all other references to another DIE, we check to see if the
6765 target DIE has already been visited. If it has, we emit a
6766 backward reference; if not, we descend recursively. */
6767 if (target_die
->die_mark
> 0)
6769 CHECKSUM_ULEB128 ('R');
6770 CHECKSUM_ULEB128 (at
->dw_attr
);
6771 CHECKSUM_ULEB128 (target_die
->die_mark
);
6775 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6779 target_die
->die_mark
= ++(*mark
);
6780 CHECKSUM_ULEB128 ('T');
6781 CHECKSUM_ULEB128 (at
->dw_attr
);
6782 if (decl
->die_parent
!= NULL
)
6783 checksum_die_context (decl
->die_parent
, ctx
);
6784 die_checksum_ordered (target_die
, ctx
, mark
);
6789 CHECKSUM_ULEB128 ('A');
6790 CHECKSUM_ULEB128 (at
->dw_attr
);
6792 switch (AT_class (at
))
6794 case dw_val_class_const
:
6795 case dw_val_class_const_implicit
:
6796 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6797 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
6800 case dw_val_class_unsigned_const
:
6801 case dw_val_class_unsigned_const_implicit
:
6802 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6803 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
6806 case dw_val_class_const_double
:
6807 CHECKSUM_ULEB128 (DW_FORM_block
);
6808 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
6809 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
6812 case dw_val_class_wide_int
:
6813 CHECKSUM_ULEB128 (DW_FORM_block
);
6814 CHECKSUM_ULEB128 (get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6815 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
6816 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
6817 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6818 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
6821 case dw_val_class_vec
:
6822 CHECKSUM_ULEB128 (DW_FORM_block
);
6823 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
6824 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
6825 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
6826 (at
->dw_attr_val
.v
.val_vec
.length
6827 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
6830 case dw_val_class_flag
:
6831 CHECKSUM_ULEB128 (DW_FORM_flag
);
6832 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
6835 case dw_val_class_str
:
6836 CHECKSUM_ULEB128 (DW_FORM_string
);
6837 CHECKSUM_STRING (AT_string (at
));
6840 case dw_val_class_addr
:
6842 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6843 CHECKSUM_ULEB128 (DW_FORM_string
);
6844 CHECKSUM_STRING (XSTR (r
, 0));
6847 case dw_val_class_offset
:
6848 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6849 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
6852 case dw_val_class_loc
:
6853 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6854 loc_checksum_ordered (loc
, ctx
);
6857 case dw_val_class_fde_ref
:
6858 case dw_val_class_lbl_id
:
6859 case dw_val_class_lineptr
:
6860 case dw_val_class_macptr
:
6861 case dw_val_class_loclistsptr
:
6862 case dw_val_class_high_pc
:
6865 case dw_val_class_file
:
6866 case dw_val_class_file_implicit
:
6867 CHECKSUM_ULEB128 (DW_FORM_string
);
6868 CHECKSUM_STRING (AT_file (at
)->filename
);
6871 case dw_val_class_data8
:
6872 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6880 struct checksum_attributes
6882 dw_attr_node
*at_name
;
6883 dw_attr_node
*at_type
;
6884 dw_attr_node
*at_friend
;
6885 dw_attr_node
*at_accessibility
;
6886 dw_attr_node
*at_address_class
;
6887 dw_attr_node
*at_alignment
;
6888 dw_attr_node
*at_allocated
;
6889 dw_attr_node
*at_artificial
;
6890 dw_attr_node
*at_associated
;
6891 dw_attr_node
*at_binary_scale
;
6892 dw_attr_node
*at_bit_offset
;
6893 dw_attr_node
*at_bit_size
;
6894 dw_attr_node
*at_bit_stride
;
6895 dw_attr_node
*at_byte_size
;
6896 dw_attr_node
*at_byte_stride
;
6897 dw_attr_node
*at_const_value
;
6898 dw_attr_node
*at_containing_type
;
6899 dw_attr_node
*at_count
;
6900 dw_attr_node
*at_data_location
;
6901 dw_attr_node
*at_data_member_location
;
6902 dw_attr_node
*at_decimal_scale
;
6903 dw_attr_node
*at_decimal_sign
;
6904 dw_attr_node
*at_default_value
;
6905 dw_attr_node
*at_digit_count
;
6906 dw_attr_node
*at_discr
;
6907 dw_attr_node
*at_discr_list
;
6908 dw_attr_node
*at_discr_value
;
6909 dw_attr_node
*at_encoding
;
6910 dw_attr_node
*at_endianity
;
6911 dw_attr_node
*at_explicit
;
6912 dw_attr_node
*at_is_optional
;
6913 dw_attr_node
*at_location
;
6914 dw_attr_node
*at_lower_bound
;
6915 dw_attr_node
*at_mutable
;
6916 dw_attr_node
*at_ordering
;
6917 dw_attr_node
*at_picture_string
;
6918 dw_attr_node
*at_prototyped
;
6919 dw_attr_node
*at_small
;
6920 dw_attr_node
*at_segment
;
6921 dw_attr_node
*at_string_length
;
6922 dw_attr_node
*at_string_length_bit_size
;
6923 dw_attr_node
*at_string_length_byte_size
;
6924 dw_attr_node
*at_threads_scaled
;
6925 dw_attr_node
*at_upper_bound
;
6926 dw_attr_node
*at_use_location
;
6927 dw_attr_node
*at_use_UTF8
;
6928 dw_attr_node
*at_variable_parameter
;
6929 dw_attr_node
*at_virtuality
;
6930 dw_attr_node
*at_visibility
;
6931 dw_attr_node
*at_vtable_elem_location
;
6934 /* Collect the attributes that we will want to use for the checksum. */
6937 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
6942 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6953 attrs
->at_friend
= a
;
6955 case DW_AT_accessibility
:
6956 attrs
->at_accessibility
= a
;
6958 case DW_AT_address_class
:
6959 attrs
->at_address_class
= a
;
6961 case DW_AT_alignment
:
6962 attrs
->at_alignment
= a
;
6964 case DW_AT_allocated
:
6965 attrs
->at_allocated
= a
;
6967 case DW_AT_artificial
:
6968 attrs
->at_artificial
= a
;
6970 case DW_AT_associated
:
6971 attrs
->at_associated
= a
;
6973 case DW_AT_binary_scale
:
6974 attrs
->at_binary_scale
= a
;
6976 case DW_AT_bit_offset
:
6977 attrs
->at_bit_offset
= a
;
6979 case DW_AT_bit_size
:
6980 attrs
->at_bit_size
= a
;
6982 case DW_AT_bit_stride
:
6983 attrs
->at_bit_stride
= a
;
6985 case DW_AT_byte_size
:
6986 attrs
->at_byte_size
= a
;
6988 case DW_AT_byte_stride
:
6989 attrs
->at_byte_stride
= a
;
6991 case DW_AT_const_value
:
6992 attrs
->at_const_value
= a
;
6994 case DW_AT_containing_type
:
6995 attrs
->at_containing_type
= a
;
6998 attrs
->at_count
= a
;
7000 case DW_AT_data_location
:
7001 attrs
->at_data_location
= a
;
7003 case DW_AT_data_member_location
:
7004 attrs
->at_data_member_location
= a
;
7006 case DW_AT_decimal_scale
:
7007 attrs
->at_decimal_scale
= a
;
7009 case DW_AT_decimal_sign
:
7010 attrs
->at_decimal_sign
= a
;
7012 case DW_AT_default_value
:
7013 attrs
->at_default_value
= a
;
7015 case DW_AT_digit_count
:
7016 attrs
->at_digit_count
= a
;
7019 attrs
->at_discr
= a
;
7021 case DW_AT_discr_list
:
7022 attrs
->at_discr_list
= a
;
7024 case DW_AT_discr_value
:
7025 attrs
->at_discr_value
= a
;
7027 case DW_AT_encoding
:
7028 attrs
->at_encoding
= a
;
7030 case DW_AT_endianity
:
7031 attrs
->at_endianity
= a
;
7033 case DW_AT_explicit
:
7034 attrs
->at_explicit
= a
;
7036 case DW_AT_is_optional
:
7037 attrs
->at_is_optional
= a
;
7039 case DW_AT_location
:
7040 attrs
->at_location
= a
;
7042 case DW_AT_lower_bound
:
7043 attrs
->at_lower_bound
= a
;
7046 attrs
->at_mutable
= a
;
7048 case DW_AT_ordering
:
7049 attrs
->at_ordering
= a
;
7051 case DW_AT_picture_string
:
7052 attrs
->at_picture_string
= a
;
7054 case DW_AT_prototyped
:
7055 attrs
->at_prototyped
= a
;
7058 attrs
->at_small
= a
;
7061 attrs
->at_segment
= a
;
7063 case DW_AT_string_length
:
7064 attrs
->at_string_length
= a
;
7066 case DW_AT_string_length_bit_size
:
7067 attrs
->at_string_length_bit_size
= a
;
7069 case DW_AT_string_length_byte_size
:
7070 attrs
->at_string_length_byte_size
= a
;
7072 case DW_AT_threads_scaled
:
7073 attrs
->at_threads_scaled
= a
;
7075 case DW_AT_upper_bound
:
7076 attrs
->at_upper_bound
= a
;
7078 case DW_AT_use_location
:
7079 attrs
->at_use_location
= a
;
7081 case DW_AT_use_UTF8
:
7082 attrs
->at_use_UTF8
= a
;
7084 case DW_AT_variable_parameter
:
7085 attrs
->at_variable_parameter
= a
;
7087 case DW_AT_virtuality
:
7088 attrs
->at_virtuality
= a
;
7090 case DW_AT_visibility
:
7091 attrs
->at_visibility
= a
;
7093 case DW_AT_vtable_elem_location
:
7094 attrs
->at_vtable_elem_location
= a
;
7102 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
7105 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
7109 struct checksum_attributes attrs
;
7111 CHECKSUM_ULEB128 ('D');
7112 CHECKSUM_ULEB128 (die
->die_tag
);
7114 memset (&attrs
, 0, sizeof (attrs
));
7116 decl
= get_AT_ref (die
, DW_AT_specification
);
7118 collect_checksum_attributes (&attrs
, decl
);
7119 collect_checksum_attributes (&attrs
, die
);
7121 CHECKSUM_ATTR (attrs
.at_name
);
7122 CHECKSUM_ATTR (attrs
.at_accessibility
);
7123 CHECKSUM_ATTR (attrs
.at_address_class
);
7124 CHECKSUM_ATTR (attrs
.at_allocated
);
7125 CHECKSUM_ATTR (attrs
.at_artificial
);
7126 CHECKSUM_ATTR (attrs
.at_associated
);
7127 CHECKSUM_ATTR (attrs
.at_binary_scale
);
7128 CHECKSUM_ATTR (attrs
.at_bit_offset
);
7129 CHECKSUM_ATTR (attrs
.at_bit_size
);
7130 CHECKSUM_ATTR (attrs
.at_bit_stride
);
7131 CHECKSUM_ATTR (attrs
.at_byte_size
);
7132 CHECKSUM_ATTR (attrs
.at_byte_stride
);
7133 CHECKSUM_ATTR (attrs
.at_const_value
);
7134 CHECKSUM_ATTR (attrs
.at_containing_type
);
7135 CHECKSUM_ATTR (attrs
.at_count
);
7136 CHECKSUM_ATTR (attrs
.at_data_location
);
7137 CHECKSUM_ATTR (attrs
.at_data_member_location
);
7138 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
7139 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
7140 CHECKSUM_ATTR (attrs
.at_default_value
);
7141 CHECKSUM_ATTR (attrs
.at_digit_count
);
7142 CHECKSUM_ATTR (attrs
.at_discr
);
7143 CHECKSUM_ATTR (attrs
.at_discr_list
);
7144 CHECKSUM_ATTR (attrs
.at_discr_value
);
7145 CHECKSUM_ATTR (attrs
.at_encoding
);
7146 CHECKSUM_ATTR (attrs
.at_endianity
);
7147 CHECKSUM_ATTR (attrs
.at_explicit
);
7148 CHECKSUM_ATTR (attrs
.at_is_optional
);
7149 CHECKSUM_ATTR (attrs
.at_location
);
7150 CHECKSUM_ATTR (attrs
.at_lower_bound
);
7151 CHECKSUM_ATTR (attrs
.at_mutable
);
7152 CHECKSUM_ATTR (attrs
.at_ordering
);
7153 CHECKSUM_ATTR (attrs
.at_picture_string
);
7154 CHECKSUM_ATTR (attrs
.at_prototyped
);
7155 CHECKSUM_ATTR (attrs
.at_small
);
7156 CHECKSUM_ATTR (attrs
.at_segment
);
7157 CHECKSUM_ATTR (attrs
.at_string_length
);
7158 CHECKSUM_ATTR (attrs
.at_string_length_bit_size
);
7159 CHECKSUM_ATTR (attrs
.at_string_length_byte_size
);
7160 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
7161 CHECKSUM_ATTR (attrs
.at_upper_bound
);
7162 CHECKSUM_ATTR (attrs
.at_use_location
);
7163 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
7164 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
7165 CHECKSUM_ATTR (attrs
.at_virtuality
);
7166 CHECKSUM_ATTR (attrs
.at_visibility
);
7167 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
7168 CHECKSUM_ATTR (attrs
.at_type
);
7169 CHECKSUM_ATTR (attrs
.at_friend
);
7170 CHECKSUM_ATTR (attrs
.at_alignment
);
7172 /* Checksum the child DIEs. */
7175 dw_attr_node
*name_attr
;
7178 name_attr
= get_AT (c
, DW_AT_name
);
7179 if (is_template_instantiation (c
))
7181 /* Ignore instantiations of member type and function templates. */
7183 else if (name_attr
!= NULL
7184 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
7186 /* Use a shallow checksum for named nested types and member
7188 CHECKSUM_ULEB128 ('S');
7189 CHECKSUM_ULEB128 (c
->die_tag
);
7190 CHECKSUM_STRING (AT_string (name_attr
));
7194 /* Use a deep checksum for other children. */
7195 /* Mark this DIE so it gets processed when unmarking. */
7196 if (c
->die_mark
== 0)
7198 die_checksum_ordered (c
, ctx
, mark
);
7200 } while (c
!= die
->die_child
);
7202 CHECKSUM_ULEB128 (0);
7205 /* Add a type name and tag to a hash. */
7207 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
7209 CHECKSUM_ULEB128 (tag
);
7210 CHECKSUM_STRING (name
);
7214 #undef CHECKSUM_STRING
7215 #undef CHECKSUM_ATTR
7216 #undef CHECKSUM_LEB128
7217 #undef CHECKSUM_ULEB128
7219 /* Generate the type signature for DIE. This is computed by generating an
7220 MD5 checksum over the DIE's tag, its relevant attributes, and its
7221 children. Attributes that are references to other DIEs are processed
7222 by recursion, using the MARK field to prevent infinite recursion.
7223 If the DIE is nested inside a namespace or another type, we also
7224 need to include that context in the signature. The lower 64 bits
7225 of the resulting MD5 checksum comprise the signature. */
7228 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
7232 unsigned char checksum
[16];
7237 name
= get_AT_string (die
, DW_AT_name
);
7238 decl
= get_AT_ref (die
, DW_AT_specification
);
7239 parent
= get_die_parent (die
);
7241 /* First, compute a signature for just the type name (and its surrounding
7242 context, if any. This is stored in the type unit DIE for link-time
7243 ODR (one-definition rule) checking. */
7245 if (is_cxx () && name
!= NULL
)
7247 md5_init_ctx (&ctx
);
7249 /* Checksum the names of surrounding namespaces and structures. */
7251 checksum_die_context (parent
, &ctx
);
7253 /* Checksum the current DIE. */
7254 die_odr_checksum (die
->die_tag
, name
, &ctx
);
7255 md5_finish_ctx (&ctx
, checksum
);
7257 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
7260 /* Next, compute the complete type signature. */
7262 md5_init_ctx (&ctx
);
7264 die
->die_mark
= mark
;
7266 /* Checksum the names of surrounding namespaces and structures. */
7268 checksum_die_context (parent
, &ctx
);
7270 /* Checksum the DIE and its children. */
7271 die_checksum_ordered (die
, &ctx
, &mark
);
7272 unmark_all_dies (die
);
7273 md5_finish_ctx (&ctx
, checksum
);
7275 /* Store the signature in the type node and link the type DIE and the
7276 type node together. */
7277 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
7278 DWARF_TYPE_SIGNATURE_SIZE
);
7279 die
->comdat_type_p
= true;
7280 die
->die_id
.die_type_node
= type_node
;
7281 type_node
->type_die
= die
;
7283 /* If the DIE is a specification, link its declaration to the type node
7287 decl
->comdat_type_p
= true;
7288 decl
->die_id
.die_type_node
= type_node
;
7292 /* Do the location expressions look same? */
7294 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
7296 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
7297 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
7298 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
7301 /* Do the values look the same? */
7303 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
7305 dw_loc_descr_ref loc1
, loc2
;
7308 if (v1
->val_class
!= v2
->val_class
)
7311 switch (v1
->val_class
)
7313 case dw_val_class_const
:
7314 case dw_val_class_const_implicit
:
7315 return v1
->v
.val_int
== v2
->v
.val_int
;
7316 case dw_val_class_unsigned_const
:
7317 case dw_val_class_unsigned_const_implicit
:
7318 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
7319 case dw_val_class_const_double
:
7320 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
7321 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
7322 case dw_val_class_wide_int
:
7323 return *v1
->v
.val_wide
== *v2
->v
.val_wide
;
7324 case dw_val_class_vec
:
7325 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
7326 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
7328 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
7329 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
7332 case dw_val_class_flag
:
7333 return v1
->v
.val_flag
== v2
->v
.val_flag
;
7334 case dw_val_class_str
:
7335 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
7337 case dw_val_class_addr
:
7338 r1
= v1
->v
.val_addr
;
7339 r2
= v2
->v
.val_addr
;
7340 if (GET_CODE (r1
) != GET_CODE (r2
))
7342 return !rtx_equal_p (r1
, r2
);
7344 case dw_val_class_offset
:
7345 return v1
->v
.val_offset
== v2
->v
.val_offset
;
7347 case dw_val_class_loc
:
7348 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
7350 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
7351 if (!same_loc_p (loc1
, loc2
, mark
))
7353 return !loc1
&& !loc2
;
7355 case dw_val_class_die_ref
:
7356 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
7358 case dw_val_class_fde_ref
:
7359 case dw_val_class_vms_delta
:
7360 case dw_val_class_lbl_id
:
7361 case dw_val_class_lineptr
:
7362 case dw_val_class_macptr
:
7363 case dw_val_class_loclistsptr
:
7364 case dw_val_class_high_pc
:
7367 case dw_val_class_file
:
7368 case dw_val_class_file_implicit
:
7369 return v1
->v
.val_file
== v2
->v
.val_file
;
7371 case dw_val_class_data8
:
7372 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
7379 /* Do the attributes look the same? */
7382 same_attr_p (dw_attr_node
*at1
, dw_attr_node
*at2
, int *mark
)
7384 if (at1
->dw_attr
!= at2
->dw_attr
)
7387 /* We don't care that this was compiled with a different compiler
7388 snapshot; if the output is the same, that's what matters. */
7389 if (at1
->dw_attr
== DW_AT_producer
)
7392 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
7395 /* Do the dies look the same? */
7398 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
7404 /* To avoid infinite recursion. */
7406 return die1
->die_mark
== die2
->die_mark
;
7407 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
7409 if (die1
->die_tag
!= die2
->die_tag
)
7412 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
7415 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
7416 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
7419 c1
= die1
->die_child
;
7420 c2
= die2
->die_child
;
7429 if (!same_die_p (c1
, c2
, mark
))
7433 if (c1
== die1
->die_child
)
7435 if (c2
== die2
->die_child
)
7445 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
7446 children, and set die_symbol. */
7449 compute_comp_unit_symbol (dw_die_ref unit_die
)
7451 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
7452 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
7453 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
7456 unsigned char checksum
[16];
7459 /* Compute the checksum of the DIE, then append part of it as hex digits to
7460 the name filename of the unit. */
7462 md5_init_ctx (&ctx
);
7464 die_checksum (unit_die
, &ctx
, &mark
);
7465 unmark_all_dies (unit_die
);
7466 md5_finish_ctx (&ctx
, checksum
);
7468 /* When we this for comp_unit_die () we have a DW_AT_name that might
7469 not start with a letter but with anything valid for filenames and
7470 clean_symbol_name doesn't fix that up. Prepend 'g' if the first
7471 character is not a letter. */
7472 sprintf (name
, "%s%s.", ISALPHA (*base
) ? "" : "g", base
);
7473 clean_symbol_name (name
);
7475 p
= name
+ strlen (name
);
7476 for (i
= 0; i
< 4; i
++)
7478 sprintf (p
, "%.2x", checksum
[i
]);
7482 unit_die
->die_id
.die_symbol
= xstrdup (name
);
7485 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
7488 is_type_die (dw_die_ref die
)
7490 switch (die
->die_tag
)
7492 case DW_TAG_array_type
:
7493 case DW_TAG_class_type
:
7494 case DW_TAG_interface_type
:
7495 case DW_TAG_enumeration_type
:
7496 case DW_TAG_pointer_type
:
7497 case DW_TAG_reference_type
:
7498 case DW_TAG_rvalue_reference_type
:
7499 case DW_TAG_string_type
:
7500 case DW_TAG_structure_type
:
7501 case DW_TAG_subroutine_type
:
7502 case DW_TAG_union_type
:
7503 case DW_TAG_ptr_to_member_type
:
7504 case DW_TAG_set_type
:
7505 case DW_TAG_subrange_type
:
7506 case DW_TAG_base_type
:
7507 case DW_TAG_const_type
:
7508 case DW_TAG_file_type
:
7509 case DW_TAG_packed_type
:
7510 case DW_TAG_volatile_type
:
7511 case DW_TAG_typedef
:
7518 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
7519 Basically, we want to choose the bits that are likely to be shared between
7520 compilations (types) and leave out the bits that are specific to individual
7521 compilations (functions). */
7524 is_comdat_die (dw_die_ref c
)
7526 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
7527 we do for stabs. The advantage is a greater likelihood of sharing between
7528 objects that don't include headers in the same order (and therefore would
7529 put the base types in a different comdat). jason 8/28/00 */
7531 if (c
->die_tag
== DW_TAG_base_type
)
7534 if (c
->die_tag
== DW_TAG_pointer_type
7535 || c
->die_tag
== DW_TAG_reference_type
7536 || c
->die_tag
== DW_TAG_rvalue_reference_type
7537 || c
->die_tag
== DW_TAG_const_type
7538 || c
->die_tag
== DW_TAG_volatile_type
)
7540 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
7542 return t
? is_comdat_die (t
) : 0;
7545 return is_type_die (c
);
7548 /* Returns true iff C is a compile-unit DIE. */
7551 is_cu_die (dw_die_ref c
)
7553 return c
&& (c
->die_tag
== DW_TAG_compile_unit
7554 || c
->die_tag
== DW_TAG_skeleton_unit
);
7557 /* Returns true iff C is a unit DIE of some sort. */
7560 is_unit_die (dw_die_ref c
)
7562 return c
&& (c
->die_tag
== DW_TAG_compile_unit
7563 || c
->die_tag
== DW_TAG_partial_unit
7564 || c
->die_tag
== DW_TAG_type_unit
7565 || c
->die_tag
== DW_TAG_skeleton_unit
);
7568 /* Returns true iff C is a namespace DIE. */
7571 is_namespace_die (dw_die_ref c
)
7573 return c
&& c
->die_tag
== DW_TAG_namespace
;
7576 /* Returns true iff C is a class or structure DIE. */
7579 is_class_die (dw_die_ref c
)
7581 return c
&& (c
->die_tag
== DW_TAG_class_type
7582 || c
->die_tag
== DW_TAG_structure_type
);
7585 /* Return non-zero if this DIE is a template parameter. */
7588 is_template_parameter (dw_die_ref die
)
7590 switch (die
->die_tag
)
7592 case DW_TAG_template_type_param
:
7593 case DW_TAG_template_value_param
:
7594 case DW_TAG_GNU_template_template_param
:
7595 case DW_TAG_GNU_template_parameter_pack
:
7602 /* Return non-zero if this DIE represents a template instantiation. */
7605 is_template_instantiation (dw_die_ref die
)
7609 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
7611 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
7616 gen_internal_sym (const char *prefix
)
7618 char buf
[MAX_ARTIFICIAL_LABEL_BYTES
];
7620 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
7621 return xstrdup (buf
);
7624 /* Return non-zero if this DIE is a declaration. */
7627 is_declaration_die (dw_die_ref die
)
7632 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7633 if (a
->dw_attr
== DW_AT_declaration
)
7639 /* Return non-zero if this DIE is nested inside a subprogram. */
7642 is_nested_in_subprogram (dw_die_ref die
)
7644 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
7648 return local_scope_p (decl
);
7651 /* Return non-zero if this DIE contains a defining declaration of a
7655 contains_subprogram_definition (dw_die_ref die
)
7659 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
7661 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
7665 /* Return non-zero if this is a type DIE that should be moved to a
7666 COMDAT .debug_types section or .debug_info section with DW_UT_*type
7670 should_move_die_to_comdat (dw_die_ref die
)
7672 switch (die
->die_tag
)
7674 case DW_TAG_class_type
:
7675 case DW_TAG_structure_type
:
7676 case DW_TAG_enumeration_type
:
7677 case DW_TAG_union_type
:
7678 /* Don't move declarations, inlined instances, types nested in a
7679 subprogram, or types that contain subprogram definitions. */
7680 if (is_declaration_die (die
)
7681 || get_AT (die
, DW_AT_abstract_origin
)
7682 || is_nested_in_subprogram (die
)
7683 || contains_subprogram_definition (die
))
7686 case DW_TAG_array_type
:
7687 case DW_TAG_interface_type
:
7688 case DW_TAG_pointer_type
:
7689 case DW_TAG_reference_type
:
7690 case DW_TAG_rvalue_reference_type
:
7691 case DW_TAG_string_type
:
7692 case DW_TAG_subroutine_type
:
7693 case DW_TAG_ptr_to_member_type
:
7694 case DW_TAG_set_type
:
7695 case DW_TAG_subrange_type
:
7696 case DW_TAG_base_type
:
7697 case DW_TAG_const_type
:
7698 case DW_TAG_file_type
:
7699 case DW_TAG_packed_type
:
7700 case DW_TAG_volatile_type
:
7701 case DW_TAG_typedef
:
7707 /* Make a clone of DIE. */
7710 clone_die (dw_die_ref die
)
7712 dw_die_ref clone
= new_die_raw (die
->die_tag
);
7716 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7717 add_dwarf_attr (clone
, a
);
7722 /* Make a clone of the tree rooted at DIE. */
7725 clone_tree (dw_die_ref die
)
7728 dw_die_ref clone
= clone_die (die
);
7730 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
7735 /* Make a clone of DIE as a declaration. */
7738 clone_as_declaration (dw_die_ref die
)
7745 /* If the DIE is already a declaration, just clone it. */
7746 if (is_declaration_die (die
))
7747 return clone_die (die
);
7749 /* If the DIE is a specification, just clone its declaration DIE. */
7750 decl
= get_AT_ref (die
, DW_AT_specification
);
7753 clone
= clone_die (decl
);
7754 if (die
->comdat_type_p
)
7755 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7759 clone
= new_die_raw (die
->die_tag
);
7761 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7763 /* We don't want to copy over all attributes.
7764 For example we don't want DW_AT_byte_size because otherwise we will no
7765 longer have a declaration and GDB will treat it as a definition. */
7769 case DW_AT_abstract_origin
:
7770 case DW_AT_artificial
:
7771 case DW_AT_containing_type
:
7772 case DW_AT_external
:
7775 case DW_AT_virtuality
:
7776 case DW_AT_linkage_name
:
7777 case DW_AT_MIPS_linkage_name
:
7778 add_dwarf_attr (clone
, a
);
7780 case DW_AT_byte_size
:
7781 case DW_AT_alignment
:
7787 if (die
->comdat_type_p
)
7788 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7790 add_AT_flag (clone
, DW_AT_declaration
, 1);
7795 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7797 struct decl_table_entry
7803 /* Helpers to manipulate hash table of copied declarations. */
7805 /* Hashtable helpers. */
7807 struct decl_table_entry_hasher
: free_ptr_hash
<decl_table_entry
>
7809 typedef die_struct
*compare_type
;
7810 static inline hashval_t
hash (const decl_table_entry
*);
7811 static inline bool equal (const decl_table_entry
*, const die_struct
*);
7815 decl_table_entry_hasher::hash (const decl_table_entry
*entry
)
7817 return htab_hash_pointer (entry
->orig
);
7821 decl_table_entry_hasher::equal (const decl_table_entry
*entry1
,
7822 const die_struct
*entry2
)
7824 return entry1
->orig
== entry2
;
7827 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
7829 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7830 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7831 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7832 to check if the ancestor has already been copied into UNIT. */
7835 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
,
7836 decl_hash_type
*decl_table
)
7838 dw_die_ref parent
= die
->die_parent
;
7839 dw_die_ref new_parent
= unit
;
7841 decl_table_entry
**slot
= NULL
;
7842 struct decl_table_entry
*entry
= NULL
;
7846 /* Check if the entry has already been copied to UNIT. */
7847 slot
= decl_table
->find_slot_with_hash (die
, htab_hash_pointer (die
),
7849 if (*slot
!= HTAB_EMPTY_ENTRY
)
7855 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7856 entry
= XCNEW (struct decl_table_entry
);
7864 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7867 if (!is_unit_die (parent
))
7868 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7871 copy
= clone_as_declaration (die
);
7872 add_child_die (new_parent
, copy
);
7876 /* Record the pointer to the copy. */
7882 /* Copy the declaration context to the new type unit DIE. This includes
7883 any surrounding namespace or type declarations. If the DIE has an
7884 AT_specification attribute, it also includes attributes and children
7885 attached to the specification, and returns a pointer to the original
7886 parent of the declaration DIE. Returns NULL otherwise. */
7889 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7892 dw_die_ref new_decl
;
7893 dw_die_ref orig_parent
= NULL
;
7895 decl
= get_AT_ref (die
, DW_AT_specification
);
7904 /* The original DIE will be changed to a declaration, and must
7905 be moved to be a child of the original declaration DIE. */
7906 orig_parent
= decl
->die_parent
;
7908 /* Copy the type node pointer from the new DIE to the original
7909 declaration DIE so we can forward references later. */
7910 decl
->comdat_type_p
= true;
7911 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7913 remove_AT (die
, DW_AT_specification
);
7915 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
7917 if (a
->dw_attr
!= DW_AT_name
7918 && a
->dw_attr
!= DW_AT_declaration
7919 && a
->dw_attr
!= DW_AT_external
)
7920 add_dwarf_attr (die
, a
);
7923 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
7926 if (decl
->die_parent
!= NULL
7927 && !is_unit_die (decl
->die_parent
))
7929 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
7930 if (new_decl
!= NULL
)
7932 remove_AT (new_decl
, DW_AT_signature
);
7933 add_AT_specification (die
, new_decl
);
7940 /* Generate the skeleton ancestor tree for the given NODE, then clone
7941 the DIE and add the clone into the tree. */
7944 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7946 if (node
->new_die
!= NULL
)
7949 node
->new_die
= clone_as_declaration (node
->old_die
);
7951 if (node
->parent
!= NULL
)
7953 generate_skeleton_ancestor_tree (node
->parent
);
7954 add_child_die (node
->parent
->new_die
, node
->new_die
);
7958 /* Generate a skeleton tree of DIEs containing any declarations that are
7959 found in the original tree. We traverse the tree looking for declaration
7960 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7963 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7965 skeleton_chain_node node
;
7968 dw_die_ref prev
= NULL
;
7969 dw_die_ref next
= NULL
;
7971 node
.parent
= parent
;
7973 first
= c
= parent
->old_die
->die_child
;
7977 if (prev
== NULL
|| prev
->die_sib
== c
)
7980 next
= (c
== first
? NULL
: c
->die_sib
);
7982 node
.new_die
= NULL
;
7983 if (is_declaration_die (c
))
7985 if (is_template_instantiation (c
))
7987 /* Instantiated templates do not need to be cloned into the
7988 type unit. Just move the DIE and its children back to
7989 the skeleton tree (in the main CU). */
7990 remove_child_with_prev (c
, prev
);
7991 add_child_die (parent
->new_die
, c
);
7994 else if (c
->comdat_type_p
)
7996 /* This is the skeleton of earlier break_out_comdat_types
7997 type. Clone the existing DIE, but keep the children
7998 under the original (which is in the main CU). */
7999 dw_die_ref clone
= clone_die (c
);
8001 replace_child (c
, clone
, prev
);
8002 generate_skeleton_ancestor_tree (parent
);
8003 add_child_die (parent
->new_die
, c
);
8009 /* Clone the existing DIE, move the original to the skeleton
8010 tree (which is in the main CU), and put the clone, with
8011 all the original's children, where the original came from
8012 (which is about to be moved to the type unit). */
8013 dw_die_ref clone
= clone_die (c
);
8014 move_all_children (c
, clone
);
8016 /* If the original has a DW_AT_object_pointer attribute,
8017 it would now point to a child DIE just moved to the
8018 cloned tree, so we need to remove that attribute from
8020 remove_AT (c
, DW_AT_object_pointer
);
8022 replace_child (c
, clone
, prev
);
8023 generate_skeleton_ancestor_tree (parent
);
8024 add_child_die (parent
->new_die
, c
);
8025 node
.old_die
= clone
;
8030 generate_skeleton_bottom_up (&node
);
8031 } while (next
!= NULL
);
8034 /* Wrapper function for generate_skeleton_bottom_up. */
8037 generate_skeleton (dw_die_ref die
)
8039 skeleton_chain_node node
;
8042 node
.new_die
= NULL
;
8045 /* If this type definition is nested inside another type,
8046 and is not an instantiation of a template, always leave
8047 at least a declaration in its place. */
8048 if (die
->die_parent
!= NULL
8049 && is_type_die (die
->die_parent
)
8050 && !is_template_instantiation (die
))
8051 node
.new_die
= clone_as_declaration (die
);
8053 generate_skeleton_bottom_up (&node
);
8054 return node
.new_die
;
8057 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
8058 declaration. The original DIE is moved to a new compile unit so that
8059 existing references to it follow it to the new location. If any of the
8060 original DIE's descendants is a declaration, we need to replace the
8061 original DIE with a skeleton tree and move the declarations back into the
8065 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
8068 dw_die_ref skeleton
, orig_parent
;
8070 /* Copy the declaration context to the type unit DIE. If the returned
8071 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
8073 orig_parent
= copy_declaration_context (unit
, child
);
8075 skeleton
= generate_skeleton (child
);
8076 if (skeleton
== NULL
)
8077 remove_child_with_prev (child
, prev
);
8080 skeleton
->comdat_type_p
= true;
8081 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
8083 /* If the original DIE was a specification, we need to put
8084 the skeleton under the parent DIE of the declaration.
8085 This leaves the original declaration in the tree, but
8086 it will be pruned later since there are no longer any
8087 references to it. */
8088 if (orig_parent
!= NULL
)
8090 remove_child_with_prev (child
, prev
);
8091 add_child_die (orig_parent
, skeleton
);
8094 replace_child (child
, skeleton
, prev
);
8101 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
8102 comdat_type_node
*type_node
,
8103 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
);
8105 /* Helper for copy_dwarf_procs_ref_in_dies. Make a copy of the DIE DWARF
8106 procedure, put it under TYPE_NODE and return the copy. Continue looking for
8107 DWARF procedure references in the DW_AT_location attribute. */
8110 copy_dwarf_procedure (dw_die_ref die
,
8111 comdat_type_node
*type_node
,
8112 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8114 gcc_assert (die
->die_tag
== DW_TAG_dwarf_procedure
);
8116 /* DWARF procedures are not supposed to have children... */
8117 gcc_assert (die
->die_child
== NULL
);
8119 /* ... and they are supposed to have only one attribute: DW_AT_location. */
8120 gcc_assert (vec_safe_length (die
->die_attr
) == 1
8121 && ((*die
->die_attr
)[0].dw_attr
== DW_AT_location
));
8123 /* Do not copy more than once DWARF procedures. */
8125 dw_die_ref
&die_copy
= copied_dwarf_procs
.get_or_insert (die
, &existed
);
8129 die_copy
= clone_die (die
);
8130 add_child_die (type_node
->root_die
, die_copy
);
8131 copy_dwarf_procs_ref_in_attrs (die_copy
, type_node
, copied_dwarf_procs
);
8135 /* Helper for copy_dwarf_procs_ref_in_dies. Look for references to DWARF
8136 procedures in DIE's attributes. */
8139 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
8140 comdat_type_node
*type_node
,
8141 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8146 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, i
, a
)
8148 dw_loc_descr_ref loc
;
8150 if (a
->dw_attr_val
.val_class
!= dw_val_class_loc
)
8153 for (loc
= a
->dw_attr_val
.v
.val_loc
; loc
!= NULL
; loc
= loc
->dw_loc_next
)
8155 switch (loc
->dw_loc_opc
)
8159 case DW_OP_call_ref
:
8160 gcc_assert (loc
->dw_loc_oprnd1
.val_class
8161 == dw_val_class_die_ref
);
8162 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
8163 = copy_dwarf_procedure (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
,
8165 copied_dwarf_procs
);
8174 /* Copy DWARF procedures that are referenced by the DIE tree to TREE_NODE and
8175 rewrite references to point to the copies.
8177 References are looked for in DIE's attributes and recursively in all its
8178 children attributes that are location descriptions. COPIED_DWARF_PROCS is a
8179 mapping from old DWARF procedures to their copy. It is used not to copy
8180 twice the same DWARF procedure under TYPE_NODE. */
8183 copy_dwarf_procs_ref_in_dies (dw_die_ref die
,
8184 comdat_type_node
*type_node
,
8185 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8189 copy_dwarf_procs_ref_in_attrs (die
, type_node
, copied_dwarf_procs
);
8190 FOR_EACH_CHILD (die
, c
, copy_dwarf_procs_ref_in_dies (c
,
8192 copied_dwarf_procs
));
8195 /* Traverse the DIE and set up additional .debug_types or .debug_info
8196 DW_UT_*type sections for each type worthy of being placed in a COMDAT
8200 break_out_comdat_types (dw_die_ref die
)
8204 dw_die_ref prev
= NULL
;
8205 dw_die_ref next
= NULL
;
8206 dw_die_ref unit
= NULL
;
8208 first
= c
= die
->die_child
;
8212 if (prev
== NULL
|| prev
->die_sib
== c
)
8215 next
= (c
== first
? NULL
: c
->die_sib
);
8216 if (should_move_die_to_comdat (c
))
8218 dw_die_ref replacement
;
8219 comdat_type_node
*type_node
;
8221 /* Break out nested types into their own type units. */
8222 break_out_comdat_types (c
);
8224 /* Create a new type unit DIE as the root for the new tree, and
8225 add it to the list of comdat types. */
8226 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8227 add_AT_unsigned (unit
, DW_AT_language
,
8228 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
8229 type_node
= ggc_cleared_alloc
<comdat_type_node
> ();
8230 type_node
->root_die
= unit
;
8231 type_node
->next
= comdat_type_list
;
8232 comdat_type_list
= type_node
;
8234 /* Generate the type signature. */
8235 generate_type_signature (c
, type_node
);
8237 /* Copy the declaration context, attributes, and children of the
8238 declaration into the new type unit DIE, then remove this DIE
8239 from the main CU (or replace it with a skeleton if necessary). */
8240 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
8241 type_node
->skeleton_die
= replacement
;
8243 /* Add the DIE to the new compunit. */
8244 add_child_die (unit
, c
);
8246 /* Types can reference DWARF procedures for type size or data location
8247 expressions. Calls in DWARF expressions cannot target procedures
8248 that are not in the same section. So we must copy DWARF procedures
8249 along with this type and then rewrite references to them. */
8250 hash_map
<dw_die_ref
, dw_die_ref
> copied_dwarf_procs
;
8251 copy_dwarf_procs_ref_in_dies (c
, type_node
, copied_dwarf_procs
);
8253 if (replacement
!= NULL
)
8256 else if (c
->die_tag
== DW_TAG_namespace
8257 || c
->die_tag
== DW_TAG_class_type
8258 || c
->die_tag
== DW_TAG_structure_type
8259 || c
->die_tag
== DW_TAG_union_type
)
8261 /* Look for nested types that can be broken out. */
8262 break_out_comdat_types (c
);
8264 } while (next
!= NULL
);
8267 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
8268 Enter all the cloned children into the hash table decl_table. */
8271 clone_tree_partial (dw_die_ref die
, decl_hash_type
*decl_table
)
8275 struct decl_table_entry
*entry
;
8276 decl_table_entry
**slot
;
8278 if (die
->die_tag
== DW_TAG_subprogram
)
8279 clone
= clone_as_declaration (die
);
8281 clone
= clone_die (die
);
8283 slot
= decl_table
->find_slot_with_hash (die
,
8284 htab_hash_pointer (die
), INSERT
);
8286 /* Assert that DIE isn't in the hash table yet. If it would be there
8287 before, the ancestors would be necessarily there as well, therefore
8288 clone_tree_partial wouldn't be called. */
8289 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
8291 entry
= XCNEW (struct decl_table_entry
);
8293 entry
->copy
= clone
;
8296 if (die
->die_tag
!= DW_TAG_subprogram
)
8297 FOR_EACH_CHILD (die
, c
,
8298 add_child_die (clone
, clone_tree_partial (c
, decl_table
)));
8303 /* Walk the DIE and its children, looking for references to incomplete
8304 or trivial types that are unmarked (i.e., that are not in the current
8308 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type
*decl_table
)
8314 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8316 if (AT_class (a
) == dw_val_class_die_ref
)
8318 dw_die_ref targ
= AT_ref (a
);
8319 decl_table_entry
**slot
;
8320 struct decl_table_entry
*entry
;
8322 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
8325 slot
= decl_table
->find_slot_with_hash (targ
,
8326 htab_hash_pointer (targ
),
8329 if (*slot
!= HTAB_EMPTY_ENTRY
)
8331 /* TARG has already been copied, so we just need to
8332 modify the reference to point to the copy. */
8334 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
8338 dw_die_ref parent
= unit
;
8339 dw_die_ref copy
= clone_die (targ
);
8341 /* Record in DECL_TABLE that TARG has been copied.
8342 Need to do this now, before the recursive call,
8343 because DECL_TABLE may be expanded and SLOT
8344 would no longer be a valid pointer. */
8345 entry
= XCNEW (struct decl_table_entry
);
8350 /* If TARG is not a declaration DIE, we need to copy its
8352 if (!is_declaration_die (targ
))
8356 add_child_die (copy
,
8357 clone_tree_partial (c
, decl_table
)));
8360 /* Make sure the cloned tree is marked as part of the
8364 /* If TARG has surrounding context, copy its ancestor tree
8365 into the new type unit. */
8366 if (targ
->die_parent
!= NULL
8367 && !is_unit_die (targ
->die_parent
))
8368 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
8371 add_child_die (parent
, copy
);
8372 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
8374 /* Make sure the newly-copied DIE is walked. If it was
8375 installed in a previously-added context, it won't
8376 get visited otherwise. */
8379 /* Find the highest point of the newly-added tree,
8380 mark each node along the way, and walk from there. */
8381 parent
->die_mark
= 1;
8382 while (parent
->die_parent
8383 && parent
->die_parent
->die_mark
== 0)
8385 parent
= parent
->die_parent
;
8386 parent
->die_mark
= 1;
8388 copy_decls_walk (unit
, parent
, decl_table
);
8394 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
8397 /* Copy declarations for "unworthy" types into the new comdat section.
8398 Incomplete types, modified types, and certain other types aren't broken
8399 out into comdat sections of their own, so they don't have a signature,
8400 and we need to copy the declaration into the same section so that we
8401 don't have an external reference. */
8404 copy_decls_for_unworthy_types (dw_die_ref unit
)
8407 decl_hash_type
decl_table (10);
8408 copy_decls_walk (unit
, unit
, &decl_table
);
8412 /* Traverse the DIE and add a sibling attribute if it may have the
8413 effect of speeding up access to siblings. To save some space,
8414 avoid generating sibling attributes for DIE's without children. */
8417 add_sibling_attributes (dw_die_ref die
)
8421 if (! die
->die_child
)
8424 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
8425 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
8427 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
8430 /* Output all location lists for the DIE and its children. */
8433 output_location_lists (dw_die_ref die
)
8439 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8440 if (AT_class (a
) == dw_val_class_loc_list
)
8441 output_loc_list (AT_loc_list (a
));
8443 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
8446 /* During assign_location_list_indexes and output_loclists_offset the
8447 current index, after it the number of assigned indexes (i.e. how
8448 large the .debug_loclists* offset table should be). */
8449 static unsigned int loc_list_idx
;
8451 /* Output all location list offsets for the DIE and its children. */
8454 output_loclists_offsets (dw_die_ref die
)
8460 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8461 if (AT_class (a
) == dw_val_class_loc_list
)
8463 dw_loc_list_ref l
= AT_loc_list (a
);
8464 if (l
->offset_emitted
)
8466 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l
->ll_symbol
,
8467 loc_section_label
, NULL
);
8468 gcc_assert (l
->hash
== loc_list_idx
);
8470 l
->offset_emitted
= true;
8473 FOR_EACH_CHILD (die
, c
, output_loclists_offsets (c
));
8476 /* Recursively set indexes of location lists. */
8479 assign_location_list_indexes (dw_die_ref die
)
8485 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8486 if (AT_class (a
) == dw_val_class_loc_list
)
8488 dw_loc_list_ref list
= AT_loc_list (a
);
8489 if (!list
->num_assigned
)
8491 list
->num_assigned
= true;
8492 list
->hash
= loc_list_idx
++;
8496 FOR_EACH_CHILD (die
, c
, assign_location_list_indexes (c
));
8499 /* We want to limit the number of external references, because they are
8500 larger than local references: a relocation takes multiple words, and
8501 even a sig8 reference is always eight bytes, whereas a local reference
8502 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
8503 So if we encounter multiple external references to the same type DIE, we
8504 make a local typedef stub for it and redirect all references there.
8506 This is the element of the hash table for keeping track of these
8516 /* Hashtable helpers. */
8518 struct external_ref_hasher
: free_ptr_hash
<external_ref
>
8520 static inline hashval_t
hash (const external_ref
*);
8521 static inline bool equal (const external_ref
*, const external_ref
*);
8525 external_ref_hasher::hash (const external_ref
*r
)
8527 dw_die_ref die
= r
->type
;
8530 /* We can't use the address of the DIE for hashing, because
8531 that will make the order of the stub DIEs non-deterministic. */
8532 if (! die
->comdat_type_p
)
8533 /* We have a symbol; use it to compute a hash. */
8534 h
= htab_hash_string (die
->die_id
.die_symbol
);
8537 /* We have a type signature; use a subset of the bits as the hash.
8538 The 8-byte signature is at least as large as hashval_t. */
8539 comdat_type_node
*type_node
= die
->die_id
.die_type_node
;
8540 memcpy (&h
, type_node
->signature
, sizeof (h
));
8546 external_ref_hasher::equal (const external_ref
*r1
, const external_ref
*r2
)
8548 return r1
->type
== r2
->type
;
8551 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
8553 /* Return a pointer to the external_ref for references to DIE. */
8555 static struct external_ref
*
8556 lookup_external_ref (external_ref_hash_type
*map
, dw_die_ref die
)
8558 struct external_ref ref
, *ref_p
;
8559 external_ref
**slot
;
8562 slot
= map
->find_slot (&ref
, INSERT
);
8563 if (*slot
!= HTAB_EMPTY_ENTRY
)
8566 ref_p
= XCNEW (struct external_ref
);
8572 /* Subroutine of optimize_external_refs, below.
8574 If we see a type skeleton, record it as our stub. If we see external
8575 references, remember how many we've seen. */
8578 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type
*map
)
8583 struct external_ref
*ref_p
;
8585 if (is_type_die (die
)
8586 && (c
= get_AT_ref (die
, DW_AT_signature
)))
8588 /* This is a local skeleton; use it for local references. */
8589 ref_p
= lookup_external_ref (map
, c
);
8593 /* Scan the DIE references, and remember any that refer to DIEs from
8594 other CUs (i.e. those which are not marked). */
8595 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8596 if (AT_class (a
) == dw_val_class_die_ref
8597 && (c
= AT_ref (a
))->die_mark
== 0
8600 ref_p
= lookup_external_ref (map
, c
);
8604 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
8607 /* htab_traverse callback function for optimize_external_refs, below. SLOT
8608 points to an external_ref, DATA is the CU we're processing. If we don't
8609 already have a local stub, and we have multiple refs, build a stub. */
8612 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
8614 struct external_ref
*ref_p
= *slot
;
8616 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
8618 /* We have multiple references to this type, so build a small stub.
8619 Both of these forms are a bit dodgy from the perspective of the
8620 DWARF standard, since technically they should have names. */
8621 dw_die_ref cu
= data
;
8622 dw_die_ref type
= ref_p
->type
;
8623 dw_die_ref stub
= NULL
;
8625 if (type
->comdat_type_p
)
8627 /* If we refer to this type via sig8, use AT_signature. */
8628 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
8629 add_AT_die_ref (stub
, DW_AT_signature
, type
);
8633 /* Otherwise, use a typedef with no name. */
8634 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
8635 add_AT_die_ref (stub
, DW_AT_type
, type
);
8644 /* DIE is a unit; look through all the DIE references to see if there are
8645 any external references to types, and if so, create local stubs for
8646 them which will be applied in build_abbrev_table. This is useful because
8647 references to local DIEs are smaller. */
8649 static external_ref_hash_type
*
8650 optimize_external_refs (dw_die_ref die
)
8652 external_ref_hash_type
*map
= new external_ref_hash_type (10);
8653 optimize_external_refs_1 (die
, map
);
8654 map
->traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
8658 /* The following 3 variables are temporaries that are computed only during the
8659 build_abbrev_table call and used and released during the following
8660 optimize_abbrev_table call. */
8662 /* First abbrev_id that can be optimized based on usage. */
8663 static unsigned int abbrev_opt_start
;
8665 /* Maximum abbrev_id of a base type plus one (we can't optimize DIEs with
8666 abbrev_id smaller than this, because they must be already sized
8667 during build_abbrev_table). */
8668 static unsigned int abbrev_opt_base_type_end
;
8670 /* Vector of usage counts during build_abbrev_table. Indexed by
8671 abbrev_id - abbrev_opt_start. */
8672 static vec
<unsigned int> abbrev_usage_count
;
8674 /* Vector of all DIEs added with die_abbrev >= abbrev_opt_start. */
8675 static vec
<dw_die_ref
> sorted_abbrev_dies
;
8677 /* The format of each DIE (and its attribute value pairs) is encoded in an
8678 abbreviation table. This routine builds the abbreviation table and assigns
8679 a unique abbreviation id for each abbreviation entry. The children of each
8680 die are visited recursively. */
8683 build_abbrev_table (dw_die_ref die
, external_ref_hash_type
*extern_map
)
8685 unsigned int abbrev_id
= 0;
8691 /* Scan the DIE references, and replace any that refer to
8692 DIEs from other CUs (i.e. those which are not marked) with
8693 the local stubs we built in optimize_external_refs. */
8694 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8695 if (AT_class (a
) == dw_val_class_die_ref
8696 && (c
= AT_ref (a
))->die_mark
== 0)
8698 struct external_ref
*ref_p
;
8699 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
8701 ref_p
= lookup_external_ref (extern_map
, c
);
8702 if (ref_p
->stub
&& ref_p
->stub
!= die
)
8703 change_AT_die_ref (a
, ref_p
->stub
);
8705 /* We aren't changing this reference, so mark it external. */
8706 set_AT_ref_external (a
, 1);
8709 FOR_EACH_VEC_SAFE_ELT (abbrev_die_table
, abbrev_id
, abbrev
)
8711 dw_attr_node
*die_a
, *abbrev_a
;
8717 if (abbrev
->die_tag
!= die
->die_tag
)
8719 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
8722 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
8725 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
8727 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
8728 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
8729 || (value_format (abbrev_a
) != value_format (die_a
)))
8739 if (abbrev_id
>= vec_safe_length (abbrev_die_table
))
8741 vec_safe_push (abbrev_die_table
, die
);
8742 if (abbrev_opt_start
)
8743 abbrev_usage_count
.safe_push (0);
8745 if (abbrev_opt_start
&& abbrev_id
>= abbrev_opt_start
)
8747 abbrev_usage_count
[abbrev_id
- abbrev_opt_start
]++;
8748 sorted_abbrev_dies
.safe_push (die
);
8751 die
->die_abbrev
= abbrev_id
;
8752 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
8755 /* Callback function for sorted_abbrev_dies vector sorting. We sort
8756 by die_abbrev's usage count, from the most commonly used
8757 abbreviation to the least. */
8760 die_abbrev_cmp (const void *p1
, const void *p2
)
8762 dw_die_ref die1
= *(const dw_die_ref
*) p1
;
8763 dw_die_ref die2
= *(const dw_die_ref
*) p2
;
8765 gcc_checking_assert (die1
->die_abbrev
>= abbrev_opt_start
);
8766 gcc_checking_assert (die2
->die_abbrev
>= abbrev_opt_start
);
8768 if (die1
->die_abbrev
>= abbrev_opt_base_type_end
8769 && die2
->die_abbrev
>= abbrev_opt_base_type_end
)
8771 if (abbrev_usage_count
[die1
->die_abbrev
- abbrev_opt_start
]
8772 > abbrev_usage_count
[die2
->die_abbrev
- abbrev_opt_start
])
8774 if (abbrev_usage_count
[die1
->die_abbrev
- abbrev_opt_start
]
8775 < abbrev_usage_count
[die2
->die_abbrev
- abbrev_opt_start
])
8779 /* Stabilize the sort. */
8780 if (die1
->die_abbrev
< die2
->die_abbrev
)
8782 if (die1
->die_abbrev
> die2
->die_abbrev
)
8788 /* Convert dw_val_class_const and dw_val_class_unsigned_const class attributes
8789 of DIEs in between sorted_abbrev_dies[first_id] and abbrev_dies[end_id - 1]
8790 into dw_val_class_const_implicit or
8791 dw_val_class_unsigned_const_implicit. */
8794 optimize_implicit_const (unsigned int first_id
, unsigned int end
,
8795 vec
<bool> &implicit_consts
)
8797 /* It never makes sense if there is just one DIE using the abbreviation. */
8798 if (end
< first_id
+ 2)
8803 dw_die_ref die
= sorted_abbrev_dies
[first_id
];
8804 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8805 if (implicit_consts
[ix
])
8807 enum dw_val_class new_class
= dw_val_class_none
;
8808 switch (AT_class (a
))
8810 case dw_val_class_unsigned_const
:
8811 if ((HOST_WIDE_INT
) AT_unsigned (a
) < 0)
8814 /* The .debug_abbrev section will grow by
8815 size_of_sleb128 (AT_unsigned (a)) and we avoid the constants
8816 in all the DIEs using that abbreviation. */
8817 if (constant_size (AT_unsigned (a
)) * (end
- first_id
)
8818 <= (unsigned) size_of_sleb128 (AT_unsigned (a
)))
8821 new_class
= dw_val_class_unsigned_const_implicit
;
8824 case dw_val_class_const
:
8825 new_class
= dw_val_class_const_implicit
;
8828 case dw_val_class_file
:
8829 new_class
= dw_val_class_file_implicit
;
8835 for (i
= first_id
; i
< end
; i
++)
8836 (*sorted_abbrev_dies
[i
]->die_attr
)[ix
].dw_attr_val
.val_class
8841 /* Attempt to optimize abbreviation table from abbrev_opt_start
8842 abbreviation above. */
8845 optimize_abbrev_table (void)
8847 if (abbrev_opt_start
8848 && vec_safe_length (abbrev_die_table
) > abbrev_opt_start
8849 && (dwarf_version
>= 5 || vec_safe_length (abbrev_die_table
) > 127))
8851 auto_vec
<bool, 32> implicit_consts
;
8852 sorted_abbrev_dies
.qsort (die_abbrev_cmp
);
8854 unsigned int abbrev_id
= abbrev_opt_start
- 1;
8855 unsigned int first_id
= ~0U;
8856 unsigned int last_abbrev_id
= 0;
8859 if (abbrev_opt_base_type_end
> abbrev_opt_start
)
8860 abbrev_id
= abbrev_opt_base_type_end
- 1;
8861 /* Reassign abbreviation ids from abbrev_opt_start above, so that
8862 most commonly used abbreviations come first. */
8863 FOR_EACH_VEC_ELT (sorted_abbrev_dies
, i
, die
)
8868 /* If calc_base_type_die_sizes has been called, the CU and
8869 base types after it can't be optimized, because we've already
8870 calculated their DIE offsets. We've sorted them first. */
8871 if (die
->die_abbrev
< abbrev_opt_base_type_end
)
8873 if (die
->die_abbrev
!= last_abbrev_id
)
8875 last_abbrev_id
= die
->die_abbrev
;
8876 if (dwarf_version
>= 5 && first_id
!= ~0U)
8877 optimize_implicit_const (first_id
, i
, implicit_consts
);
8879 (*abbrev_die_table
)[abbrev_id
] = die
;
8880 if (dwarf_version
>= 5)
8883 implicit_consts
.truncate (0);
8885 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8886 switch (AT_class (a
))
8888 case dw_val_class_const
:
8889 case dw_val_class_unsigned_const
:
8890 case dw_val_class_file
:
8891 implicit_consts
.safe_push (true);
8894 implicit_consts
.safe_push (false);
8899 else if (dwarf_version
>= 5)
8901 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8902 if (!implicit_consts
[ix
])
8906 dw_attr_node
*other_a
8907 = &(*(*abbrev_die_table
)[abbrev_id
]->die_attr
)[ix
];
8908 if (!dw_val_equal_p (&a
->dw_attr_val
,
8909 &other_a
->dw_attr_val
))
8910 implicit_consts
[ix
] = false;
8913 die
->die_abbrev
= abbrev_id
;
8915 gcc_assert (abbrev_id
== vec_safe_length (abbrev_die_table
) - 1);
8916 if (dwarf_version
>= 5 && first_id
!= ~0U)
8917 optimize_implicit_const (first_id
, i
, implicit_consts
);
8920 abbrev_opt_start
= 0;
8921 abbrev_opt_base_type_end
= 0;
8922 abbrev_usage_count
.release ();
8923 sorted_abbrev_dies
.release ();
8926 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8929 constant_size (unsigned HOST_WIDE_INT value
)
8936 log
= floor_log2 (value
);
8939 log
= 1 << (floor_log2 (log
) + 1);
8944 /* Return the size of a DIE as it is represented in the
8945 .debug_info section. */
8947 static unsigned long
8948 size_of_die (dw_die_ref die
)
8950 unsigned long size
= 0;
8953 enum dwarf_form form
;
8955 size
+= size_of_uleb128 (die
->die_abbrev
);
8956 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8958 switch (AT_class (a
))
8960 case dw_val_class_addr
:
8961 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8963 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8964 size
+= size_of_uleb128 (AT_index (a
));
8967 size
+= DWARF2_ADDR_SIZE
;
8969 case dw_val_class_offset
:
8970 size
+= DWARF_OFFSET_SIZE
;
8972 case dw_val_class_loc
:
8974 unsigned long lsize
= size_of_locs (AT_loc (a
));
8977 if (dwarf_version
>= 4)
8978 size
+= size_of_uleb128 (lsize
);
8980 size
+= constant_size (lsize
);
8984 case dw_val_class_loc_list
:
8985 if (dwarf_split_debug_info
&& dwarf_version
>= 5)
8987 gcc_assert (AT_loc_list (a
)->num_assigned
);
8988 size
+= size_of_uleb128 (AT_loc_list (a
)->hash
);
8991 size
+= DWARF_OFFSET_SIZE
;
8993 case dw_val_class_range_list
:
8994 if (value_format (a
) == DW_FORM_rnglistx
)
8996 gcc_assert (rnglist_idx
);
8997 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
8998 size
+= size_of_uleb128 (r
->idx
);
9001 size
+= DWARF_OFFSET_SIZE
;
9003 case dw_val_class_const
:
9004 size
+= size_of_sleb128 (AT_int (a
));
9006 case dw_val_class_unsigned_const
:
9008 int csize
= constant_size (AT_unsigned (a
));
9009 if (dwarf_version
== 3
9010 && a
->dw_attr
== DW_AT_data_member_location
9012 size
+= size_of_uleb128 (AT_unsigned (a
));
9017 case dw_val_class_const_implicit
:
9018 case dw_val_class_unsigned_const_implicit
:
9019 case dw_val_class_file_implicit
:
9020 /* These occupy no size in the DIE, just an extra sleb128 in
9023 case dw_val_class_const_double
:
9024 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
9025 if (HOST_BITS_PER_WIDE_INT
>= DWARF_LARGEST_DATA_FORM_BITS
)
9028 case dw_val_class_wide_int
:
9029 size
+= (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
9030 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
9031 if (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
9032 * HOST_BITS_PER_WIDE_INT
> DWARF_LARGEST_DATA_FORM_BITS
)
9035 case dw_val_class_vec
:
9036 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
9037 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
9038 + a
->dw_attr_val
.v
.val_vec
.length
9039 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
9041 case dw_val_class_flag
:
9042 if (dwarf_version
>= 4)
9043 /* Currently all add_AT_flag calls pass in 1 as last argument,
9044 so DW_FORM_flag_present can be used. If that ever changes,
9045 we'll need to use DW_FORM_flag and have some optimization
9046 in build_abbrev_table that will change those to
9047 DW_FORM_flag_present if it is set to 1 in all DIEs using
9048 the same abbrev entry. */
9049 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
9053 case dw_val_class_die_ref
:
9054 if (AT_ref_external (a
))
9056 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
9057 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
9058 is sized by target address length, whereas in DWARF3
9059 it's always sized as an offset. */
9060 if (use_debug_types
)
9061 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
9062 else if (dwarf_version
== 2)
9063 size
+= DWARF2_ADDR_SIZE
;
9065 size
+= DWARF_OFFSET_SIZE
;
9068 size
+= DWARF_OFFSET_SIZE
;
9070 case dw_val_class_fde_ref
:
9071 size
+= DWARF_OFFSET_SIZE
;
9073 case dw_val_class_lbl_id
:
9074 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
9076 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
9077 size
+= size_of_uleb128 (AT_index (a
));
9080 size
+= DWARF2_ADDR_SIZE
;
9082 case dw_val_class_lineptr
:
9083 case dw_val_class_macptr
:
9084 case dw_val_class_loclistsptr
:
9085 size
+= DWARF_OFFSET_SIZE
;
9087 case dw_val_class_str
:
9088 form
= AT_string_form (a
);
9089 if (form
== DW_FORM_strp
|| form
== DW_FORM_line_strp
)
9090 size
+= DWARF_OFFSET_SIZE
;
9091 else if (form
== DW_FORM_GNU_str_index
)
9092 size
+= size_of_uleb128 (AT_index (a
));
9094 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
9096 case dw_val_class_file
:
9097 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
9099 case dw_val_class_data8
:
9102 case dw_val_class_vms_delta
:
9103 size
+= DWARF_OFFSET_SIZE
;
9105 case dw_val_class_high_pc
:
9106 size
+= DWARF2_ADDR_SIZE
;
9108 case dw_val_class_discr_value
:
9109 size
+= size_of_discr_value (&a
->dw_attr_val
.v
.val_discr_value
);
9111 case dw_val_class_discr_list
:
9113 unsigned block_size
= size_of_discr_list (AT_discr_list (a
));
9115 /* This is a block, so we have the block length and then its
9117 size
+= constant_size (block_size
) + block_size
;
9128 /* Size the debugging information associated with a given DIE. Visits the
9129 DIE's children recursively. Updates the global variable next_die_offset, on
9130 each time through. Uses the current value of next_die_offset to update the
9131 die_offset field in each DIE. */
9134 calc_die_sizes (dw_die_ref die
)
9138 gcc_assert (die
->die_offset
== 0
9139 || (unsigned long int) die
->die_offset
== next_die_offset
);
9140 die
->die_offset
= next_die_offset
;
9141 next_die_offset
+= size_of_die (die
);
9143 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
9145 if (die
->die_child
!= NULL
)
9146 /* Count the null byte used to terminate sibling lists. */
9147 next_die_offset
+= 1;
9150 /* Size just the base type children at the start of the CU.
9151 This is needed because build_abbrev needs to size locs
9152 and sizing of type based stack ops needs to know die_offset
9153 values for the base types. */
9156 calc_base_type_die_sizes (void)
9158 unsigned long die_offset
= (dwarf_split_debug_info
9159 ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
9160 : DWARF_COMPILE_UNIT_HEADER_SIZE
);
9162 dw_die_ref base_type
;
9163 #if ENABLE_ASSERT_CHECKING
9164 dw_die_ref prev
= comp_unit_die ()->die_child
;
9167 die_offset
+= size_of_die (comp_unit_die ());
9168 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
9170 #if ENABLE_ASSERT_CHECKING
9171 gcc_assert (base_type
->die_offset
== 0
9172 && prev
->die_sib
== base_type
9173 && base_type
->die_child
== NULL
9174 && base_type
->die_abbrev
);
9177 if (abbrev_opt_start
9178 && base_type
->die_abbrev
>= abbrev_opt_base_type_end
)
9179 abbrev_opt_base_type_end
= base_type
->die_abbrev
+ 1;
9180 base_type
->die_offset
= die_offset
;
9181 die_offset
+= size_of_die (base_type
);
9185 /* Set the marks for a die and its children. We do this so
9186 that we know whether or not a reference needs to use FORM_ref_addr; only
9187 DIEs in the same CU will be marked. We used to clear out the offset
9188 and use that as the flag, but ran into ordering problems. */
9191 mark_dies (dw_die_ref die
)
9195 gcc_assert (!die
->die_mark
);
9198 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
9201 /* Clear the marks for a die and its children. */
9204 unmark_dies (dw_die_ref die
)
9208 if (! use_debug_types
)
9209 gcc_assert (die
->die_mark
);
9212 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
9215 /* Clear the marks for a die, its children and referred dies. */
9218 unmark_all_dies (dw_die_ref die
)
9228 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
9230 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9231 if (AT_class (a
) == dw_val_class_die_ref
)
9232 unmark_all_dies (AT_ref (a
));
9235 /* Calculate if the entry should appear in the final output file. It may be
9236 from a pruned a type. */
9239 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
9241 /* By limiting gnu pubnames to definitions only, gold can generate a
9242 gdb index without entries for declarations, which don't include
9243 enough information to be useful. */
9244 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
9247 if (table
== pubname_table
)
9249 /* Enumerator names are part of the pubname table, but the
9250 parent DW_TAG_enumeration_type die may have been pruned.
9251 Don't output them if that is the case. */
9252 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
9253 (p
->die
->die_parent
== NULL
9254 || !p
->die
->die_parent
->die_perennial_p
))
9257 /* Everything else in the pubname table is included. */
9261 /* The pubtypes table shouldn't include types that have been
9263 return (p
->die
->die_offset
!= 0
9264 || !flag_eliminate_unused_debug_types
);
9267 /* Return the size of the .debug_pubnames or .debug_pubtypes table
9268 generated for the compilation unit. */
9270 static unsigned long
9271 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9276 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
9278 size
= DWARF_PUBNAMES_HEADER_SIZE
;
9279 FOR_EACH_VEC_ELT (*names
, i
, p
)
9280 if (include_pubname_in_output (names
, p
))
9281 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
9283 size
+= DWARF_OFFSET_SIZE
;
9287 /* Return the size of the information in the .debug_aranges section. */
9289 static unsigned long
9290 size_of_aranges (void)
9294 size
= DWARF_ARANGES_HEADER_SIZE
;
9296 /* Count the address/length pair for this compilation unit. */
9297 if (text_section_used
)
9298 size
+= 2 * DWARF2_ADDR_SIZE
;
9299 if (cold_text_section_used
)
9300 size
+= 2 * DWARF2_ADDR_SIZE
;
9301 if (have_multiple_function_sections
)
9306 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9308 if (DECL_IGNORED_P (fde
->decl
))
9310 if (!fde
->in_std_section
)
9311 size
+= 2 * DWARF2_ADDR_SIZE
;
9312 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9313 size
+= 2 * DWARF2_ADDR_SIZE
;
9317 /* Count the two zero words used to terminated the address range table. */
9318 size
+= 2 * DWARF2_ADDR_SIZE
;
9322 /* Select the encoding of an attribute value. */
9324 static enum dwarf_form
9325 value_format (dw_attr_node
*a
)
9327 switch (AT_class (a
))
9329 case dw_val_class_addr
:
9330 /* Only very few attributes allow DW_FORM_addr. */
9335 case DW_AT_entry_pc
:
9336 case DW_AT_trampoline
:
9337 return (AT_index (a
) == NOT_INDEXED
9338 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
9342 switch (DWARF2_ADDR_SIZE
)
9345 return DW_FORM_data1
;
9347 return DW_FORM_data2
;
9349 return DW_FORM_data4
;
9351 return DW_FORM_data8
;
9355 case dw_val_class_loc_list
:
9356 if (dwarf_split_debug_info
9357 && dwarf_version
>= 5
9358 && AT_loc_list (a
)->num_assigned
)
9359 return DW_FORM_loclistx
;
9361 case dw_val_class_range_list
:
9362 /* For range lists in DWARF 5, use DW_FORM_rnglistx from .debug_info.dwo
9363 but in .debug_info use DW_FORM_sec_offset, which is shorter if we
9364 care about sizes of .debug* sections in shared libraries and
9365 executables and don't take into account relocations that affect just
9366 relocatable objects - for DW_FORM_rnglistx we'd have to emit offset
9367 table in the .debug_rnglists section. */
9368 if (dwarf_split_debug_info
9369 && dwarf_version
>= 5
9370 && AT_class (a
) == dw_val_class_range_list
9372 && a
->dw_attr_val
.val_entry
!= RELOCATED_OFFSET
)
9373 return DW_FORM_rnglistx
;
9374 if (dwarf_version
>= 4)
9375 return DW_FORM_sec_offset
;
9377 case dw_val_class_vms_delta
:
9378 case dw_val_class_offset
:
9379 switch (DWARF_OFFSET_SIZE
)
9382 return DW_FORM_data4
;
9384 return DW_FORM_data8
;
9388 case dw_val_class_loc
:
9389 if (dwarf_version
>= 4)
9390 return DW_FORM_exprloc
;
9391 switch (constant_size (size_of_locs (AT_loc (a
))))
9394 return DW_FORM_block1
;
9396 return DW_FORM_block2
;
9398 return DW_FORM_block4
;
9402 case dw_val_class_const
:
9403 return DW_FORM_sdata
;
9404 case dw_val_class_unsigned_const
:
9405 switch (constant_size (AT_unsigned (a
)))
9408 return DW_FORM_data1
;
9410 return DW_FORM_data2
;
9412 /* In DWARF3 DW_AT_data_member_location with
9413 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
9414 constant, so we need to use DW_FORM_udata if we need
9415 a large constant. */
9416 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
9417 return DW_FORM_udata
;
9418 return DW_FORM_data4
;
9420 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
9421 return DW_FORM_udata
;
9422 return DW_FORM_data8
;
9426 case dw_val_class_const_implicit
:
9427 case dw_val_class_unsigned_const_implicit
:
9428 case dw_val_class_file_implicit
:
9429 return DW_FORM_implicit_const
;
9430 case dw_val_class_const_double
:
9431 switch (HOST_BITS_PER_WIDE_INT
)
9434 return DW_FORM_data2
;
9436 return DW_FORM_data4
;
9438 return DW_FORM_data8
;
9440 if (dwarf_version
>= 5)
9441 return DW_FORM_data16
;
9444 return DW_FORM_block1
;
9446 case dw_val_class_wide_int
:
9447 switch (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
)
9450 return DW_FORM_data1
;
9452 return DW_FORM_data2
;
9454 return DW_FORM_data4
;
9456 return DW_FORM_data8
;
9458 if (dwarf_version
>= 5)
9459 return DW_FORM_data16
;
9462 return DW_FORM_block1
;
9464 case dw_val_class_vec
:
9465 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
9466 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
9469 return DW_FORM_block1
;
9471 return DW_FORM_block2
;
9473 return DW_FORM_block4
;
9477 case dw_val_class_flag
:
9478 if (dwarf_version
>= 4)
9480 /* Currently all add_AT_flag calls pass in 1 as last argument,
9481 so DW_FORM_flag_present can be used. If that ever changes,
9482 we'll need to use DW_FORM_flag and have some optimization
9483 in build_abbrev_table that will change those to
9484 DW_FORM_flag_present if it is set to 1 in all DIEs using
9485 the same abbrev entry. */
9486 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
9487 return DW_FORM_flag_present
;
9489 return DW_FORM_flag
;
9490 case dw_val_class_die_ref
:
9491 if (AT_ref_external (a
))
9492 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
9495 case dw_val_class_fde_ref
:
9496 return DW_FORM_data
;
9497 case dw_val_class_lbl_id
:
9498 return (AT_index (a
) == NOT_INDEXED
9499 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
9500 case dw_val_class_lineptr
:
9501 case dw_val_class_macptr
:
9502 case dw_val_class_loclistsptr
:
9503 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
9504 case dw_val_class_str
:
9505 return AT_string_form (a
);
9506 case dw_val_class_file
:
9507 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
9510 return DW_FORM_data1
;
9512 return DW_FORM_data2
;
9514 return DW_FORM_data4
;
9519 case dw_val_class_data8
:
9520 return DW_FORM_data8
;
9522 case dw_val_class_high_pc
:
9523 switch (DWARF2_ADDR_SIZE
)
9526 return DW_FORM_data1
;
9528 return DW_FORM_data2
;
9530 return DW_FORM_data4
;
9532 return DW_FORM_data8
;
9537 case dw_val_class_discr_value
:
9538 return (a
->dw_attr_val
.v
.val_discr_value
.pos
9541 case dw_val_class_discr_list
:
9542 switch (constant_size (size_of_discr_list (AT_discr_list (a
))))
9545 return DW_FORM_block1
;
9547 return DW_FORM_block2
;
9549 return DW_FORM_block4
;
9559 /* Output the encoding of an attribute value. */
9562 output_value_format (dw_attr_node
*a
)
9564 enum dwarf_form form
= value_format (a
);
9566 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
9569 /* Given a die and id, produce the appropriate abbreviations. */
9572 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
9575 dw_attr_node
*a_attr
;
9577 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
9578 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
9579 dwarf_tag_name (abbrev
->die_tag
));
9581 if (abbrev
->die_child
!= NULL
)
9582 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
9584 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
9586 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
9588 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
9589 dwarf_attr_name (a_attr
->dw_attr
));
9590 output_value_format (a_attr
);
9591 if (value_format (a_attr
) == DW_FORM_implicit_const
)
9593 if (AT_class (a_attr
) == dw_val_class_file_implicit
)
9595 int f
= maybe_emit_file (a_attr
->dw_attr_val
.v
.val_file
);
9596 const char *filename
= a_attr
->dw_attr_val
.v
.val_file
->filename
;
9597 dw2_asm_output_data_sleb128 (f
, "(%s)", filename
);
9600 dw2_asm_output_data_sleb128 (a_attr
->dw_attr_val
.v
.val_int
, NULL
);
9604 dw2_asm_output_data (1, 0, NULL
);
9605 dw2_asm_output_data (1, 0, NULL
);
9609 /* Output the .debug_abbrev section which defines the DIE abbreviation
9613 output_abbrev_section (void)
9615 unsigned int abbrev_id
;
9618 FOR_EACH_VEC_SAFE_ELT (abbrev_die_table
, abbrev_id
, abbrev
)
9620 output_die_abbrevs (abbrev_id
, abbrev
);
9622 /* Terminate the table. */
9623 dw2_asm_output_data (1, 0, NULL
);
9626 /* Return a new location list, given the begin and end range, and the
9629 static inline dw_loc_list_ref
9630 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
9631 const char *section
)
9633 dw_loc_list_ref retlist
= ggc_cleared_alloc
<dw_loc_list_node
> ();
9635 retlist
->begin
= begin
;
9636 retlist
->begin_entry
= NULL
;
9638 retlist
->expr
= expr
;
9639 retlist
->section
= section
;
9644 /* Generate a new internal symbol for this location list node, if it
9645 hasn't got one yet. */
9648 gen_llsym (dw_loc_list_ref list
)
9650 gcc_assert (!list
->ll_symbol
);
9651 list
->ll_symbol
= gen_internal_sym ("LLST");
9654 /* Output the location list given to us. */
9657 output_loc_list (dw_loc_list_ref list_head
)
9659 if (list_head
->emitted
)
9661 list_head
->emitted
= true;
9663 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
9665 dw_loc_list_ref curr
= list_head
;
9666 const char *last_section
= NULL
;
9667 const char *base_label
= NULL
;
9669 /* Walk the location list, and output each range + expression. */
9670 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
9673 /* Don't output an entry that starts and ends at the same address. */
9674 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
9676 size
= size_of_locs (curr
->expr
);
9677 /* If the expression is too large, drop it on the floor. We could
9678 perhaps put it into DW_TAG_dwarf_procedure and refer to that
9679 in the expression, but >= 64KB expressions for a single value
9680 in a single range are unlikely very useful. */
9681 if (dwarf_version
< 5 && size
> 0xffff)
9683 if (dwarf_version
>= 5)
9685 if (dwarf_split_debug_info
)
9687 /* For -gsplit-dwarf, emit DW_LLE_starx_length, which has
9688 uleb128 index into .debug_addr and uleb128 length. */
9689 dw2_asm_output_data (1, DW_LLE_startx_length
,
9690 "DW_LLE_startx_length (%s)",
9691 list_head
->ll_symbol
);
9692 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
9693 "Location list range start index "
9694 "(%s)", curr
->begin
);
9695 /* FIXME: This will ICE ifndef HAVE_AS_LEB128.
9696 For that case we probably need to emit DW_LLE_startx_endx,
9697 but we'd need 2 .debug_addr entries rather than just one. */
9698 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->begin
,
9699 "Location list length (%s)",
9700 list_head
->ll_symbol
);
9702 else if (!have_multiple_function_sections
&& HAVE_AS_LEB128
)
9704 /* If all code is in .text section, the base address is
9705 already provided by the CU attributes. Use
9706 DW_LLE_offset_pair where both addresses are uleb128 encoded
9707 offsets against that base. */
9708 dw2_asm_output_data (1, DW_LLE_offset_pair
,
9709 "DW_LLE_offset_pair (%s)",
9710 list_head
->ll_symbol
);
9711 dw2_asm_output_delta_uleb128 (curr
->begin
, curr
->section
,
9712 "Location list begin address (%s)",
9713 list_head
->ll_symbol
);
9714 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->section
,
9715 "Location list end address (%s)",
9716 list_head
->ll_symbol
);
9718 else if (HAVE_AS_LEB128
)
9720 /* Otherwise, find out how many consecutive entries could share
9721 the same base entry. If just one, emit DW_LLE_start_length,
9722 otherwise emit DW_LLE_base_address for the base address
9723 followed by a series of DW_LLE_offset_pair. */
9724 if (last_section
== NULL
|| curr
->section
!= last_section
)
9726 dw_loc_list_ref curr2
;
9727 for (curr2
= curr
->dw_loc_next
; curr2
!= NULL
;
9728 curr2
= curr2
->dw_loc_next
)
9730 if (strcmp (curr2
->begin
, curr2
->end
) == 0
9735 if (curr2
== NULL
|| curr
->section
!= curr2
->section
)
9736 last_section
= NULL
;
9739 last_section
= curr
->section
;
9740 base_label
= curr
->begin
;
9741 dw2_asm_output_data (1, DW_LLE_base_address
,
9742 "DW_LLE_base_address (%s)",
9743 list_head
->ll_symbol
);
9744 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, base_label
,
9745 "Base address (%s)",
9746 list_head
->ll_symbol
);
9749 /* Only one entry with the same base address. Use
9750 DW_LLE_start_length with absolute address and uleb128
9752 if (last_section
== NULL
)
9754 dw2_asm_output_data (1, DW_LLE_start_length
,
9755 "DW_LLE_start_length (%s)",
9756 list_head
->ll_symbol
);
9757 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
9758 "Location list begin address (%s)",
9759 list_head
->ll_symbol
);
9760 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->begin
,
9761 "Location list length "
9762 "(%s)", list_head
->ll_symbol
);
9764 /* Otherwise emit DW_LLE_offset_pair, relative to above emitted
9765 DW_LLE_base_address. */
9768 dw2_asm_output_data (1, DW_LLE_offset_pair
,
9769 "DW_LLE_offset_pair (%s)",
9770 list_head
->ll_symbol
);
9771 dw2_asm_output_delta_uleb128 (curr
->begin
, base_label
,
9772 "Location list begin address "
9773 "(%s)", list_head
->ll_symbol
);
9774 dw2_asm_output_delta_uleb128 (curr
->end
, base_label
,
9775 "Location list end address "
9776 "(%s)", list_head
->ll_symbol
);
9779 /* The assembler does not support .uleb128 directive. Emit
9780 DW_LLE_start_end with a pair of absolute addresses. */
9783 dw2_asm_output_data (1, DW_LLE_start_end
,
9784 "DW_LLE_start_end (%s)",
9785 list_head
->ll_symbol
);
9786 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
9787 "Location list begin address (%s)",
9788 list_head
->ll_symbol
);
9789 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
9790 "Location list end address (%s)",
9791 list_head
->ll_symbol
);
9794 else if (dwarf_split_debug_info
)
9796 /* For -gsplit-dwarf -gdwarf-{2,3,4} emit index into .debug_addr
9797 and 4 byte length. */
9798 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
9799 "Location list start/length entry (%s)",
9800 list_head
->ll_symbol
);
9801 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
9802 "Location list range start index (%s)",
9804 /* The length field is 4 bytes. If we ever need to support
9805 an 8-byte length, we can add a new DW_LLE code or fall back
9806 to DW_LLE_GNU_start_end_entry. */
9807 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
9808 "Location list range length (%s)",
9809 list_head
->ll_symbol
);
9811 else if (!have_multiple_function_sections
)
9813 /* Pair of relative addresses against start of text section. */
9814 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
9815 "Location list begin address (%s)",
9816 list_head
->ll_symbol
);
9817 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
9818 "Location list end address (%s)",
9819 list_head
->ll_symbol
);
9823 /* Pair of absolute addresses. */
9824 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
9825 "Location list begin address (%s)",
9826 list_head
->ll_symbol
);
9827 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
9828 "Location list end address (%s)",
9829 list_head
->ll_symbol
);
9832 /* Output the block length for this list of location operations. */
9833 if (dwarf_version
>= 5)
9834 dw2_asm_output_data_uleb128 (size
, "Location expression size");
9837 gcc_assert (size
<= 0xffff);
9838 dw2_asm_output_data (2, size
, "Location expression size");
9841 output_loc_sequence (curr
->expr
, -1);
9844 /* And finally list termination. */
9845 if (dwarf_version
>= 5)
9846 dw2_asm_output_data (1, DW_LLE_end_of_list
,
9847 "DW_LLE_end_of_list (%s)", list_head
->ll_symbol
);
9848 else if (dwarf_split_debug_info
)
9849 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
9850 "Location list terminator (%s)",
9851 list_head
->ll_symbol
);
9854 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
9855 "Location list terminator begin (%s)",
9856 list_head
->ll_symbol
);
9857 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
9858 "Location list terminator end (%s)",
9859 list_head
->ll_symbol
);
9863 /* Output a range_list offset into the .debug_ranges or .debug_rnglists
9864 section. Emit a relocated reference if val_entry is NULL, otherwise,
9865 emit an indirect reference. */
9868 output_range_list_offset (dw_attr_node
*a
)
9870 const char *name
= dwarf_attr_name (a
->dw_attr
);
9872 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
9874 if (dwarf_version
>= 5)
9876 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
9877 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, r
->label
,
9878 debug_ranges_section
, "%s", name
);
9882 char *p
= strchr (ranges_section_label
, '\0');
9883 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
9884 a
->dw_attr_val
.v
.val_offset
* 2 * DWARF2_ADDR_SIZE
);
9885 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
9886 debug_ranges_section
, "%s", name
);
9890 else if (dwarf_version
>= 5)
9892 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
9893 gcc_assert (rnglist_idx
);
9894 dw2_asm_output_data_uleb128 (r
->idx
, "%s", name
);
9897 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9898 a
->dw_attr_val
.v
.val_offset
* 2 * DWARF2_ADDR_SIZE
,
9899 "%s (offset from %s)", name
, ranges_section_label
);
9902 /* Output the offset into the debug_loc section. */
9905 output_loc_list_offset (dw_attr_node
*a
)
9907 char *sym
= AT_loc_list (a
)->ll_symbol
;
9910 if (!dwarf_split_debug_info
)
9911 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
9912 "%s", dwarf_attr_name (a
->dw_attr
));
9913 else if (dwarf_version
>= 5)
9915 gcc_assert (AT_loc_list (a
)->num_assigned
);
9916 dw2_asm_output_data_uleb128 (AT_loc_list (a
)->hash
, "%s (%s)",
9917 dwarf_attr_name (a
->dw_attr
),
9921 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
9922 "%s", dwarf_attr_name (a
->dw_attr
));
9925 /* Output an attribute's index or value appropriately. */
9928 output_attr_index_or_value (dw_attr_node
*a
)
9930 const char *name
= dwarf_attr_name (a
->dw_attr
);
9932 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
9934 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
9937 switch (AT_class (a
))
9939 case dw_val_class_addr
:
9940 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
9942 case dw_val_class_high_pc
:
9943 case dw_val_class_lbl_id
:
9944 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
9951 /* Output a type signature. */
9954 output_signature (const char *sig
, const char *name
)
9958 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9959 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
9962 /* Output a discriminant value. */
9965 output_discr_value (dw_discr_value
*discr_value
, const char *name
)
9967 if (discr_value
->pos
)
9968 dw2_asm_output_data_uleb128 (discr_value
->v
.uval
, "%s", name
);
9970 dw2_asm_output_data_sleb128 (discr_value
->v
.sval
, "%s", name
);
9973 /* Output the DIE and its attributes. Called recursively to generate
9974 the definitions of each child DIE. */
9977 output_die (dw_die_ref die
)
9984 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
9985 (unsigned long)die
->die_offset
,
9986 dwarf_tag_name (die
->die_tag
));
9988 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9990 const char *name
= dwarf_attr_name (a
->dw_attr
);
9992 switch (AT_class (a
))
9994 case dw_val_class_addr
:
9995 output_attr_index_or_value (a
);
9998 case dw_val_class_offset
:
9999 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
10003 case dw_val_class_range_list
:
10004 output_range_list_offset (a
);
10007 case dw_val_class_loc
:
10008 size
= size_of_locs (AT_loc (a
));
10010 /* Output the block length for this list of location operations. */
10011 if (dwarf_version
>= 4)
10012 dw2_asm_output_data_uleb128 (size
, "%s", name
);
10014 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
10016 output_loc_sequence (AT_loc (a
), -1);
10019 case dw_val_class_const
:
10020 /* ??? It would be slightly more efficient to use a scheme like is
10021 used for unsigned constants below, but gdb 4.x does not sign
10022 extend. Gdb 5.x does sign extend. */
10023 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
10026 case dw_val_class_unsigned_const
:
10028 int csize
= constant_size (AT_unsigned (a
));
10029 if (dwarf_version
== 3
10030 && a
->dw_attr
== DW_AT_data_member_location
10032 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
10034 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
10038 case dw_val_class_const_implicit
:
10039 if (flag_debug_asm
)
10040 fprintf (asm_out_file
, "\t\t\t%s %s ("
10041 HOST_WIDE_INT_PRINT_DEC
")\n",
10042 ASM_COMMENT_START
, name
, AT_int (a
));
10045 case dw_val_class_unsigned_const_implicit
:
10046 if (flag_debug_asm
)
10047 fprintf (asm_out_file
, "\t\t\t%s %s ("
10048 HOST_WIDE_INT_PRINT_HEX
")\n",
10049 ASM_COMMENT_START
, name
, AT_unsigned (a
));
10052 case dw_val_class_const_double
:
10054 unsigned HOST_WIDE_INT first
, second
;
10056 if (HOST_BITS_PER_WIDE_INT
>= DWARF_LARGEST_DATA_FORM_BITS
)
10057 dw2_asm_output_data (1,
10058 HOST_BITS_PER_DOUBLE_INT
10059 / HOST_BITS_PER_CHAR
,
10062 if (WORDS_BIG_ENDIAN
)
10064 first
= a
->dw_attr_val
.v
.val_double
.high
;
10065 second
= a
->dw_attr_val
.v
.val_double
.low
;
10069 first
= a
->dw_attr_val
.v
.val_double
.low
;
10070 second
= a
->dw_attr_val
.v
.val_double
.high
;
10073 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
10074 first
, "%s", name
);
10075 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
10080 case dw_val_class_wide_int
:
10083 int len
= get_full_len (*a
->dw_attr_val
.v
.val_wide
);
10084 int l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
10085 if (len
* HOST_BITS_PER_WIDE_INT
> DWARF_LARGEST_DATA_FORM_BITS
)
10086 dw2_asm_output_data (1, get_full_len (*a
->dw_attr_val
.v
.val_wide
)
10089 if (WORDS_BIG_ENDIAN
)
10090 for (i
= len
- 1; i
>= 0; --i
)
10092 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
10097 for (i
= 0; i
< len
; ++i
)
10099 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
10106 case dw_val_class_vec
:
10108 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
10109 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
10113 dw2_asm_output_data (constant_size (len
* elt_size
),
10114 len
* elt_size
, "%s", name
);
10115 if (elt_size
> sizeof (HOST_WIDE_INT
))
10120 for (i
= 0, p
= (unsigned char *) a
->dw_attr_val
.v
.val_vec
.array
;
10122 i
++, p
+= elt_size
)
10123 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
10124 "fp or vector constant word %u", i
);
10128 case dw_val_class_flag
:
10129 if (dwarf_version
>= 4)
10131 /* Currently all add_AT_flag calls pass in 1 as last argument,
10132 so DW_FORM_flag_present can be used. If that ever changes,
10133 we'll need to use DW_FORM_flag and have some optimization
10134 in build_abbrev_table that will change those to
10135 DW_FORM_flag_present if it is set to 1 in all DIEs using
10136 the same abbrev entry. */
10137 gcc_assert (AT_flag (a
) == 1);
10138 if (flag_debug_asm
)
10139 fprintf (asm_out_file
, "\t\t\t%s %s\n",
10140 ASM_COMMENT_START
, name
);
10143 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
10146 case dw_val_class_loc_list
:
10147 output_loc_list_offset (a
);
10150 case dw_val_class_die_ref
:
10151 if (AT_ref_external (a
))
10153 if (AT_ref (a
)->comdat_type_p
)
10155 comdat_type_node
*type_node
10156 = AT_ref (a
)->die_id
.die_type_node
;
10158 gcc_assert (type_node
);
10159 output_signature (type_node
->signature
, name
);
10163 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
10167 /* In DWARF2, DW_FORM_ref_addr is sized by target address
10168 length, whereas in DWARF3 it's always sized as an
10170 if (dwarf_version
== 2)
10171 size
= DWARF2_ADDR_SIZE
;
10173 size
= DWARF_OFFSET_SIZE
;
10174 /* ??? We cannot unconditionally output die_offset if
10175 non-zero - others might create references to those
10177 And we do not clear its DIE offset after outputting it
10178 (and the label refers to the actual DIEs, not the
10179 DWARF CU unit header which is when using label + offset
10180 would be the correct thing to do).
10181 ??? This is the reason for the with_offset flag. */
10182 if (AT_ref (a
)->with_offset
)
10183 dw2_asm_output_offset (size
, sym
, AT_ref (a
)->die_offset
,
10184 debug_info_section
, "%s", name
);
10186 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
10192 gcc_assert (AT_ref (a
)->die_offset
);
10193 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
10198 case dw_val_class_fde_ref
:
10200 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
10202 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
10203 a
->dw_attr_val
.v
.val_fde_index
* 2);
10204 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
10209 case dw_val_class_vms_delta
:
10210 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
10211 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
10212 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
10215 dw2_asm_output_delta (DWARF_OFFSET_SIZE
,
10216 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
10221 case dw_val_class_lbl_id
:
10222 output_attr_index_or_value (a
);
10225 case dw_val_class_lineptr
:
10226 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
10227 debug_line_section
, "%s", name
);
10230 case dw_val_class_macptr
:
10231 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
10232 debug_macinfo_section
, "%s", name
);
10235 case dw_val_class_loclistsptr
:
10236 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
10237 debug_loc_section
, "%s", name
);
10240 case dw_val_class_str
:
10241 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
10242 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
10243 a
->dw_attr_val
.v
.val_str
->label
,
10245 "%s: \"%s\"", name
, AT_string (a
));
10246 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_line_strp
)
10247 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
10248 a
->dw_attr_val
.v
.val_str
->label
,
10249 debug_line_str_section
,
10250 "%s: \"%s\"", name
, AT_string (a
));
10251 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
10252 dw2_asm_output_data_uleb128 (AT_index (a
),
10253 "%s: \"%s\"", name
, AT_string (a
));
10255 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
10258 case dw_val_class_file
:
10260 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
10262 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
10263 a
->dw_attr_val
.v
.val_file
->filename
);
10267 case dw_val_class_file_implicit
:
10268 if (flag_debug_asm
)
10269 fprintf (asm_out_file
, "\t\t\t%s %s (%d, %s)\n",
10270 ASM_COMMENT_START
, name
,
10271 maybe_emit_file (a
->dw_attr_val
.v
.val_file
),
10272 a
->dw_attr_val
.v
.val_file
->filename
);
10275 case dw_val_class_data8
:
10279 for (i
= 0; i
< 8; i
++)
10280 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
10281 i
== 0 ? "%s" : NULL
, name
);
10285 case dw_val_class_high_pc
:
10286 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
10287 get_AT_low_pc (die
), "DW_AT_high_pc");
10290 case dw_val_class_discr_value
:
10291 output_discr_value (&a
->dw_attr_val
.v
.val_discr_value
, name
);
10294 case dw_val_class_discr_list
:
10296 dw_discr_list_ref list
= AT_discr_list (a
);
10297 const int size
= size_of_discr_list (list
);
10299 /* This is a block, so output its length first. */
10300 dw2_asm_output_data (constant_size (size
), size
,
10301 "%s: block size", name
);
10303 for (; list
!= NULL
; list
= list
->dw_discr_next
)
10305 /* One byte for the discriminant value descriptor, and then as
10306 many LEB128 numbers as required. */
10307 if (list
->dw_discr_range
)
10308 dw2_asm_output_data (1, DW_DSC_range
,
10309 "%s: DW_DSC_range", name
);
10311 dw2_asm_output_data (1, DW_DSC_label
,
10312 "%s: DW_DSC_label", name
);
10314 output_discr_value (&list
->dw_discr_lower_bound
, name
);
10315 if (list
->dw_discr_range
)
10316 output_discr_value (&list
->dw_discr_upper_bound
, name
);
10322 gcc_unreachable ();
10326 FOR_EACH_CHILD (die
, c
, output_die (c
));
10328 /* Add null byte to terminate sibling list. */
10329 if (die
->die_child
!= NULL
)
10330 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
10331 (unsigned long) die
->die_offset
);
10334 /* Output the compilation unit that appears at the beginning of the
10335 .debug_info section, and precedes the DIE descriptions. */
10338 output_compilation_unit_header (enum dwarf_unit_type ut
)
10340 if (!XCOFF_DEBUGGING_INFO
)
10342 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10343 dw2_asm_output_data (4, 0xffffffff,
10344 "Initial length escape value indicating 64-bit DWARF extension");
10345 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
10346 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
10347 "Length of Compilation Unit Info");
10350 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
10351 if (dwarf_version
>= 5)
10356 case DW_UT_compile
: name
= "DW_UT_compile"; break;
10357 case DW_UT_type
: name
= "DW_UT_type"; break;
10358 case DW_UT_split_compile
: name
= "DW_UT_split_compile"; break;
10359 case DW_UT_split_type
: name
= "DW_UT_split_type"; break;
10360 default: gcc_unreachable ();
10362 dw2_asm_output_data (1, ut
, "%s", name
);
10363 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10365 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
10366 debug_abbrev_section
,
10367 "Offset Into Abbrev. Section");
10368 if (dwarf_version
< 5)
10369 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10372 /* Output the compilation unit DIE and its children. */
10375 output_comp_unit (dw_die_ref die
, int output_if_empty
,
10376 const unsigned char *dwo_id
)
10378 const char *secname
, *oldsym
;
10381 /* Unless we are outputting main CU, we may throw away empty ones. */
10382 if (!output_if_empty
&& die
->die_child
== NULL
)
10385 /* Even if there are no children of this DIE, we must output the information
10386 about the compilation unit. Otherwise, on an empty translation unit, we
10387 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
10388 will then complain when examining the file. First mark all the DIEs in
10389 this CU so we know which get local refs. */
10392 external_ref_hash_type
*extern_map
= optimize_external_refs (die
);
10394 /* For now, optimize only the main CU, in order to optimize the rest
10395 we'd need to see all of them earlier. Leave the rest for post-linking
10397 if (die
== comp_unit_die ())
10398 abbrev_opt_start
= vec_safe_length (abbrev_die_table
);
10400 build_abbrev_table (die
, extern_map
);
10402 optimize_abbrev_table ();
10406 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
10407 next_die_offset
= (dwo_id
10408 ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
10409 : DWARF_COMPILE_UNIT_HEADER_SIZE
);
10410 calc_die_sizes (die
);
10412 oldsym
= die
->die_id
.die_symbol
;
10413 if (oldsym
&& die
->comdat_type_p
)
10415 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
10417 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
10419 die
->die_id
.die_symbol
= NULL
;
10420 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
10424 switch_to_section (debug_info_section
);
10425 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
10426 info_section_emitted
= true;
10429 /* For LTO cross unit DIE refs we want a symbol on the start of the
10430 debuginfo section, not on the CU DIE. */
10431 if ((flag_generate_lto
|| flag_generate_offload
) && oldsym
)
10433 /* ??? No way to get visibility assembled without a decl. */
10434 tree decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
,
10435 get_identifier (oldsym
), char_type_node
);
10436 TREE_PUBLIC (decl
) = true;
10437 TREE_STATIC (decl
) = true;
10438 DECL_ARTIFICIAL (decl
) = true;
10439 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
10440 DECL_VISIBILITY_SPECIFIED (decl
) = true;
10441 targetm
.asm_out
.assemble_visibility (decl
, VISIBILITY_HIDDEN
);
10442 #ifdef ASM_WEAKEN_LABEL
10443 /* We prefer a .weak because that handles duplicates from duplicate
10444 archive members in a graceful way. */
10445 ASM_WEAKEN_LABEL (asm_out_file
, oldsym
);
10447 targetm
.asm_out
.globalize_label (asm_out_file
, oldsym
);
10449 ASM_OUTPUT_LABEL (asm_out_file
, oldsym
);
10452 /* Output debugging information. */
10453 output_compilation_unit_header (dwo_id
10454 ? DW_UT_split_compile
: DW_UT_compile
);
10455 if (dwarf_version
>= 5)
10457 if (dwo_id
!= NULL
)
10458 for (int i
= 0; i
< 8; i
++)
10459 dw2_asm_output_data (1, dwo_id
[i
], i
== 0 ? "DWO id" : NULL
);
10463 /* Leave the marks on the main CU, so we can check them in
10464 output_pubnames. */
10468 die
->die_id
.die_symbol
= oldsym
;
10472 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
10473 and .debug_pubtypes. This is configured per-target, but can be
10474 overridden by the -gpubnames or -gno-pubnames options. */
10477 want_pubnames (void)
10479 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
10481 if (debug_generate_pub_sections
!= -1)
10482 return debug_generate_pub_sections
;
10483 return targetm
.want_debug_pub_sections
;
10486 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
10489 add_AT_pubnames (dw_die_ref die
)
10491 if (want_pubnames ())
10492 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
10495 /* Add a string attribute value to a skeleton DIE. */
10498 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
10502 struct indirect_string_node
*node
;
10504 if (! skeleton_debug_str_hash
)
10505 skeleton_debug_str_hash
10506 = hash_table
<indirect_string_hasher
>::create_ggc (10);
10508 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
10509 find_string_form (node
);
10510 if (node
->form
== DW_FORM_GNU_str_index
)
10511 node
->form
= DW_FORM_strp
;
10513 attr
.dw_attr
= attr_kind
;
10514 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
10515 attr
.dw_attr_val
.val_entry
= NULL
;
10516 attr
.dw_attr_val
.v
.val_str
= node
;
10517 add_dwarf_attr (die
, &attr
);
10520 /* Helper function to generate top-level dies for skeleton debug_info and
10524 add_top_level_skeleton_die_attrs (dw_die_ref die
)
10526 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
10527 const char *comp_dir
= comp_dir_string ();
10529 add_skeleton_AT_string (die
, dwarf_AT (DW_AT_dwo_name
), dwo_file_name
);
10530 if (comp_dir
!= NULL
)
10531 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
10532 add_AT_pubnames (die
);
10533 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
10536 /* Output skeleton debug sections that point to the dwo file. */
10539 output_skeleton_debug_sections (dw_die_ref comp_unit
,
10540 const unsigned char *dwo_id
)
10542 /* These attributes will be found in the full debug_info section. */
10543 remove_AT (comp_unit
, DW_AT_producer
);
10544 remove_AT (comp_unit
, DW_AT_language
);
10546 switch_to_section (debug_skeleton_info_section
);
10547 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
10549 /* Produce the skeleton compilation-unit header. This one differs enough from
10550 a normal CU header that it's better not to call output_compilation_unit
10552 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10553 dw2_asm_output_data (4, 0xffffffff,
10554 "Initial length escape value indicating 64-bit "
10555 "DWARF extension");
10557 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
10558 DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
10559 - DWARF_INITIAL_LENGTH_SIZE
10560 + size_of_die (comp_unit
),
10561 "Length of Compilation Unit Info");
10562 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
10563 if (dwarf_version
>= 5)
10565 dw2_asm_output_data (1, DW_UT_skeleton
, "DW_UT_skeleton");
10566 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10568 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
10569 debug_skeleton_abbrev_section
,
10570 "Offset Into Abbrev. Section");
10571 if (dwarf_version
< 5)
10572 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10574 for (int i
= 0; i
< 8; i
++)
10575 dw2_asm_output_data (1, dwo_id
[i
], i
== 0 ? "DWO id" : NULL
);
10577 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
10578 output_die (comp_unit
);
10580 /* Build the skeleton debug_abbrev section. */
10581 switch_to_section (debug_skeleton_abbrev_section
);
10582 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
10584 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
10586 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
10589 /* Output a comdat type unit DIE and its children. */
10592 output_comdat_type_unit (comdat_type_node
*node
)
10594 const char *secname
;
10597 #if defined (OBJECT_FORMAT_ELF)
10601 /* First mark all the DIEs in this CU so we know which get local refs. */
10602 mark_dies (node
->root_die
);
10604 external_ref_hash_type
*extern_map
= optimize_external_refs (node
->root_die
);
10606 build_abbrev_table (node
->root_die
, extern_map
);
10611 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
10612 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
10613 calc_die_sizes (node
->root_die
);
10615 #if defined (OBJECT_FORMAT_ELF)
10616 if (dwarf_version
>= 5)
10618 if (!dwarf_split_debug_info
)
10619 secname
= ".debug_info";
10621 secname
= ".debug_info.dwo";
10623 else if (!dwarf_split_debug_info
)
10624 secname
= ".debug_types";
10626 secname
= ".debug_types.dwo";
10628 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
10629 sprintf (tmp
, dwarf_version
>= 5 ? "wi." : "wt.");
10630 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
10631 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
10632 comdat_key
= get_identifier (tmp
);
10633 targetm
.asm_out
.named_section (secname
,
10634 SECTION_DEBUG
| SECTION_LINKONCE
,
10637 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
10638 sprintf (tmp
, (dwarf_version
>= 5
10639 ? ".gnu.linkonce.wi." : ".gnu.linkonce.wt."));
10640 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
10641 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
10643 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
10646 /* Output debugging information. */
10647 output_compilation_unit_header (dwarf_split_debug_info
10648 ? DW_UT_split_type
: DW_UT_type
);
10649 output_signature (node
->signature
, "Type Signature");
10650 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
10651 "Offset to Type DIE");
10652 output_die (node
->root_die
);
10654 unmark_dies (node
->root_die
);
10657 /* Return the DWARF2/3 pubname associated with a decl. */
10659 static const char *
10660 dwarf2_name (tree decl
, int scope
)
10662 if (DECL_NAMELESS (decl
))
10664 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
10667 /* Add a new entry to .debug_pubnames if appropriate. */
10670 add_pubname_string (const char *str
, dw_die_ref die
)
10675 e
.name
= xstrdup (str
);
10676 vec_safe_push (pubname_table
, e
);
10680 add_pubname (tree decl
, dw_die_ref die
)
10682 if (!want_pubnames ())
10685 /* Don't add items to the table when we expect that the consumer will have
10686 just read the enclosing die. For example, if the consumer is looking at a
10687 class_member, it will either be inside the class already, or will have just
10688 looked up the class to find the member. Either way, searching the class is
10689 faster than searching the index. */
10690 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
10691 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
10693 const char *name
= dwarf2_name (decl
, 1);
10696 add_pubname_string (name
, die
);
10700 /* Add an enumerator to the pubnames section. */
10703 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
10707 gcc_assert (scope_name
);
10708 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
10710 vec_safe_push (pubname_table
, e
);
10713 /* Add a new entry to .debug_pubtypes if appropriate. */
10716 add_pubtype (tree decl
, dw_die_ref die
)
10720 if (!want_pubnames ())
10723 if ((TREE_PUBLIC (decl
)
10724 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
10725 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
10728 const char *scope_name
= "";
10729 const char *sep
= is_cxx () ? "::" : ".";
10732 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
10733 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
10735 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
10736 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
10737 scope_name
= concat (scope_name
, sep
, NULL
);
10743 name
= type_tag (decl
);
10745 name
= lang_hooks
.dwarf_name (decl
, 1);
10747 /* If we don't have a name for the type, there's no point in adding
10748 it to the table. */
10749 if (name
!= NULL
&& name
[0] != '\0')
10752 e
.name
= concat (scope_name
, name
, NULL
);
10753 vec_safe_push (pubtype_table
, e
);
10756 /* Although it might be more consistent to add the pubinfo for the
10757 enumerators as their dies are created, they should only be added if the
10758 enum type meets the criteria above. So rather than re-check the parent
10759 enum type whenever an enumerator die is created, just output them all
10760 here. This isn't protected by the name conditional because anonymous
10761 enums don't have names. */
10762 if (die
->die_tag
== DW_TAG_enumeration_type
)
10766 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
10771 /* Output a single entry in the pubnames table. */
10774 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
10776 dw_die_ref die
= entry
->die
;
10777 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
10779 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
10781 if (debug_generate_pub_sections
== 2)
10783 /* This logic follows gdb's method for determining the value of the flag
10785 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
10786 switch (die
->die_tag
)
10788 case DW_TAG_typedef
:
10789 case DW_TAG_base_type
:
10790 case DW_TAG_subrange_type
:
10791 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
10792 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
10794 case DW_TAG_enumerator
:
10795 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10796 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
10798 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
10800 case DW_TAG_subprogram
:
10801 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10802 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
10804 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
10806 case DW_TAG_constant
:
10807 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10808 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
10809 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
10811 case DW_TAG_variable
:
10812 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10813 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
10814 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
10816 case DW_TAG_namespace
:
10817 case DW_TAG_imported_declaration
:
10818 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
10820 case DW_TAG_class_type
:
10821 case DW_TAG_interface_type
:
10822 case DW_TAG_structure_type
:
10823 case DW_TAG_union_type
:
10824 case DW_TAG_enumeration_type
:
10825 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
10827 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
10830 /* An unusual tag. Leave the flag-byte empty. */
10833 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
10834 "GDB-index flags");
10837 dw2_asm_output_nstring (entry
->name
, -1, "external name");
10841 /* Output the public names table used to speed up access to externally
10842 visible names; or the public types table used to find type definitions. */
10845 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
10848 unsigned long pubnames_length
= size_of_pubnames (names
);
10849 pubname_entry
*pub
;
10851 if (!XCOFF_DEBUGGING_INFO
)
10853 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10854 dw2_asm_output_data (4, 0xffffffff,
10855 "Initial length escape value indicating 64-bit DWARF extension");
10856 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
10857 "Pub Info Length");
10860 /* Version number for pubnames/pubtypes is independent of dwarf version. */
10861 dw2_asm_output_data (2, 2, "DWARF Version");
10863 if (dwarf_split_debug_info
)
10864 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
10865 debug_skeleton_info_section
,
10866 "Offset of Compilation Unit Info");
10868 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
10869 debug_info_section
,
10870 "Offset of Compilation Unit Info");
10871 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
10872 "Compilation Unit Length");
10874 FOR_EACH_VEC_ELT (*names
, i
, pub
)
10876 if (include_pubname_in_output (names
, pub
))
10878 dw_offset die_offset
= pub
->die
->die_offset
;
10880 /* We shouldn't see pubnames for DIEs outside of the main CU. */
10881 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
10882 gcc_assert (pub
->die
->die_mark
);
10884 /* If we're putting types in their own .debug_types sections,
10885 the .debug_pubtypes table will still point to the compile
10886 unit (not the type unit), so we want to use the offset of
10887 the skeleton DIE (if there is one). */
10888 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
10890 comdat_type_node
*type_node
= pub
->die
->die_id
.die_type_node
;
10892 if (type_node
!= NULL
)
10893 die_offset
= (type_node
->skeleton_die
!= NULL
10894 ? type_node
->skeleton_die
->die_offset
10895 : comp_unit_die ()->die_offset
);
10898 output_pubname (die_offset
, pub
);
10902 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
10905 /* Output public names and types tables if necessary. */
10908 output_pubtables (void)
10910 if (!want_pubnames () || !info_section_emitted
)
10913 switch_to_section (debug_pubnames_section
);
10914 output_pubnames (pubname_table
);
10915 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
10916 It shouldn't hurt to emit it always, since pure DWARF2 consumers
10917 simply won't look for the section. */
10918 switch_to_section (debug_pubtypes_section
);
10919 output_pubnames (pubtype_table
);
10923 /* Output the information that goes into the .debug_aranges table.
10924 Namely, define the beginning and ending address range of the
10925 text section generated for this compilation unit. */
10928 output_aranges (void)
10931 unsigned long aranges_length
= size_of_aranges ();
10933 if (!XCOFF_DEBUGGING_INFO
)
10935 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10936 dw2_asm_output_data (4, 0xffffffff,
10937 "Initial length escape value indicating 64-bit DWARF extension");
10938 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
10939 "Length of Address Ranges Info");
10942 /* Version number for aranges is still 2, even up to DWARF5. */
10943 dw2_asm_output_data (2, 2, "DWARF Version");
10944 if (dwarf_split_debug_info
)
10945 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
10946 debug_skeleton_info_section
,
10947 "Offset of Compilation Unit Info");
10949 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
10950 debug_info_section
,
10951 "Offset of Compilation Unit Info");
10952 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
10953 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
10955 /* We need to align to twice the pointer size here. */
10956 if (DWARF_ARANGES_PAD_SIZE
)
10958 /* Pad using a 2 byte words so that padding is correct for any
10960 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
10961 2 * DWARF2_ADDR_SIZE
);
10962 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
10963 dw2_asm_output_data (2, 0, NULL
);
10966 /* It is necessary not to output these entries if the sections were
10967 not used; if the sections were not used, the length will be 0 and
10968 the address may end up as 0 if the section is discarded by ld
10969 --gc-sections, leaving an invalid (0, 0) entry that can be
10970 confused with the terminator. */
10971 if (text_section_used
)
10973 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
10974 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
10975 text_section_label
, "Length");
10977 if (cold_text_section_used
)
10979 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
10981 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
10982 cold_text_section_label
, "Length");
10985 if (have_multiple_function_sections
)
10990 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
10992 if (DECL_IGNORED_P (fde
->decl
))
10994 if (!fde
->in_std_section
)
10996 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
10998 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
10999 fde
->dw_fde_begin
, "Length");
11001 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
11003 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
11005 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
11006 fde
->dw_fde_second_begin
, "Length");
11011 /* Output the terminator words. */
11012 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11013 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11016 /* Add a new entry to .debug_ranges. Return its index into
11017 ranges_table vector. */
11019 static unsigned int
11020 add_ranges_num (int num
, bool maybe_new_sec
)
11022 dw_ranges r
= { NULL
, num
, 0, maybe_new_sec
};
11023 vec_safe_push (ranges_table
, r
);
11024 return vec_safe_length (ranges_table
) - 1;
11027 /* Add a new entry to .debug_ranges corresponding to a block, or a
11028 range terminator if BLOCK is NULL. MAYBE_NEW_SEC is true if
11029 this entry might be in a different section from previous range. */
11031 static unsigned int
11032 add_ranges (const_tree block
, bool maybe_new_sec
)
11034 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0, maybe_new_sec
);
11037 /* Note that (*rnglist_table)[offset] is either a head of a rnglist
11038 chain, or middle entry of a chain that will be directly referred to. */
11041 note_rnglist_head (unsigned int offset
)
11043 if (dwarf_version
< 5 || (*ranges_table
)[offset
].label
)
11045 (*ranges_table
)[offset
].label
= gen_internal_sym ("LLRL");
11048 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
11049 When using dwarf_split_debug_info, address attributes in dies destined
11050 for the final executable should be direct references--setting the
11051 parameter force_direct ensures this behavior. */
11054 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
11055 bool *added
, bool force_direct
)
11057 unsigned int in_use
= vec_safe_length (ranges_by_label
);
11058 unsigned int offset
;
11059 dw_ranges_by_label rbl
= { begin
, end
};
11060 vec_safe_push (ranges_by_label
, rbl
);
11061 offset
= add_ranges_num (-(int)in_use
- 1, true);
11064 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
11066 note_rnglist_head (offset
);
11070 /* Emit .debug_ranges section. */
11073 output_ranges (void)
11076 static const char *const start_fmt
= "Offset %#x";
11077 const char *fmt
= start_fmt
;
11080 switch_to_section (debug_ranges_section
);
11081 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
11082 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11084 int block_num
= r
->num
;
11088 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11089 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11091 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
11092 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
11094 /* If all code is in the text section, then the compilation
11095 unit base address defaults to DW_AT_low_pc, which is the
11096 base of the text section. */
11097 if (!have_multiple_function_sections
)
11099 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
11100 text_section_label
,
11101 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11102 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
11103 text_section_label
, NULL
);
11106 /* Otherwise, the compilation unit base address is zero,
11107 which allows us to use absolute addresses, and not worry
11108 about whether the target supports cross-section
11112 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11113 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11114 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
11120 /* Negative block_num stands for an index into ranges_by_label. */
11121 else if (block_num
< 0)
11123 int lab_idx
= - block_num
- 1;
11125 if (!have_multiple_function_sections
)
11127 gcc_unreachable ();
11129 /* If we ever use add_ranges_by_labels () for a single
11130 function section, all we have to do is to take out
11131 the #if 0 above. */
11132 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11133 (*ranges_by_label
)[lab_idx
].begin
,
11134 text_section_label
,
11135 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11136 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11137 (*ranges_by_label
)[lab_idx
].end
,
11138 text_section_label
, NULL
);
11143 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11144 (*ranges_by_label
)[lab_idx
].begin
,
11145 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11146 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11147 (*ranges_by_label
)[lab_idx
].end
,
11153 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11154 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11160 /* Non-zero if .debug_line_str should be used for .debug_line section
11161 strings or strings that are likely shareable with those. */
11162 #define DWARF5_USE_DEBUG_LINE_STR \
11163 (!DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET \
11164 && (DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) != 0 \
11165 /* FIXME: there is no .debug_line_str.dwo section, \
11166 for -gsplit-dwarf we should use DW_FORM_strx instead. */ \
11167 && !dwarf_split_debug_info)
11169 /* Assign .debug_rnglists indexes. */
11172 index_rnglists (void)
11177 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11179 r
->idx
= rnglist_idx
++;
11182 /* Emit .debug_rnglists section. */
11185 output_rnglists (void)
11189 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
11190 char l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
11191 char basebuf
[MAX_ARTIFICIAL_LABEL_BYTES
];
11193 switch_to_section (debug_ranges_section
);
11194 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
11195 ASM_GENERATE_INTERNAL_LABEL (l1
, DEBUG_RANGES_SECTION_LABEL
, 2);
11196 ASM_GENERATE_INTERNAL_LABEL (l2
, DEBUG_RANGES_SECTION_LABEL
, 3);
11197 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11198 dw2_asm_output_data (4, 0xffffffff,
11199 "Initial length escape value indicating "
11200 "64-bit DWARF extension");
11201 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
11202 "Length of Range Lists");
11203 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
11204 dw2_asm_output_data (2, dwarf_version
, "DWARF Version");
11205 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
11206 dw2_asm_output_data (1, 0, "Segment Size");
11207 /* Emit the offset table only for -gsplit-dwarf. If we don't care
11208 about relocation sizes and primarily care about the size of .debug*
11209 sections in linked shared libraries and executables, then
11210 the offset table plus corresponding DW_FORM_rnglistx uleb128 indexes
11211 into it are usually larger than just DW_FORM_sec_offset offsets
11212 into the .debug_rnglists section. */
11213 dw2_asm_output_data (4, dwarf_split_debug_info
? rnglist_idx
: 0,
11214 "Offset Entry Count");
11215 if (dwarf_split_debug_info
)
11217 ASM_OUTPUT_LABEL (asm_out_file
, ranges_base_label
);
11218 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11220 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, r
->label
,
11221 ranges_base_label
, NULL
);
11224 const char *lab
= "";
11225 unsigned int len
= vec_safe_length (ranges_table
);
11226 const char *base
= NULL
;
11227 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11229 int block_num
= r
->num
;
11233 ASM_OUTPUT_LABEL (asm_out_file
, r
->label
);
11236 if (HAVE_AS_LEB128
&& (r
->label
|| r
->maybe_new_sec
))
11240 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11241 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11243 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
11244 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
11246 if (HAVE_AS_LEB128
)
11248 /* If all code is in the text section, then the compilation
11249 unit base address defaults to DW_AT_low_pc, which is the
11250 base of the text section. */
11251 if (!have_multiple_function_sections
)
11253 dw2_asm_output_data (1, DW_RLE_offset_pair
,
11254 "DW_RLE_offset_pair (%s)", lab
);
11255 dw2_asm_output_delta_uleb128 (blabel
, text_section_label
,
11256 "Range begin address (%s)", lab
);
11257 dw2_asm_output_delta_uleb128 (elabel
, text_section_label
,
11258 "Range end address (%s)", lab
);
11263 dw_ranges
*r2
= NULL
;
11265 r2
= &(*ranges_table
)[i
+ 1];
11268 && r2
->label
== NULL
11269 && !r2
->maybe_new_sec
)
11271 dw2_asm_output_data (1, DW_RLE_base_address
,
11272 "DW_RLE_base_address (%s)", lab
);
11273 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11274 "Base address (%s)", lab
);
11275 strcpy (basebuf
, blabel
);
11281 dw2_asm_output_data (1, DW_RLE_offset_pair
,
11282 "DW_RLE_offset_pair (%s)", lab
);
11283 dw2_asm_output_delta_uleb128 (blabel
, base
,
11284 "Range begin address (%s)", lab
);
11285 dw2_asm_output_delta_uleb128 (elabel
, base
,
11286 "Range end address (%s)", lab
);
11289 dw2_asm_output_data (1, DW_RLE_start_length
,
11290 "DW_RLE_start_length (%s)", lab
);
11291 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11292 "Range begin address (%s)", lab
);
11293 dw2_asm_output_delta_uleb128 (elabel
, blabel
,
11294 "Range length (%s)", lab
);
11298 dw2_asm_output_data (1, DW_RLE_start_end
,
11299 "DW_RLE_start_end (%s)", lab
);
11300 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11301 "Range begin address (%s)", lab
);
11302 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
,
11303 "Range end address (%s)", lab
);
11307 /* Negative block_num stands for an index into ranges_by_label. */
11308 else if (block_num
< 0)
11310 int lab_idx
= - block_num
- 1;
11311 const char *blabel
= (*ranges_by_label
)[lab_idx
].begin
;
11312 const char *elabel
= (*ranges_by_label
)[lab_idx
].end
;
11314 if (!have_multiple_function_sections
)
11315 gcc_unreachable ();
11316 if (HAVE_AS_LEB128
)
11318 dw2_asm_output_data (1, DW_RLE_start_length
,
11319 "DW_RLE_start_length (%s)", lab
);
11320 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11321 "Range begin address (%s)", lab
);
11322 dw2_asm_output_delta_uleb128 (elabel
, blabel
,
11323 "Range length (%s)", lab
);
11327 dw2_asm_output_data (1, DW_RLE_start_end
,
11328 "DW_RLE_start_end (%s)", lab
);
11329 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11330 "Range begin address (%s)", lab
);
11331 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
,
11332 "Range end address (%s)", lab
);
11336 dw2_asm_output_data (1, DW_RLE_end_of_list
,
11337 "DW_RLE_end_of_list (%s)", lab
);
11339 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
11342 /* Data structure containing information about input files. */
11345 const char *path
; /* Complete file name. */
11346 const char *fname
; /* File name part. */
11347 int length
; /* Length of entire string. */
11348 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
11349 int dir_idx
; /* Index in directory table. */
11352 /* Data structure containing information about directories with source
11356 const char *path
; /* Path including directory name. */
11357 int length
; /* Path length. */
11358 int prefix
; /* Index of directory entry which is a prefix. */
11359 int count
; /* Number of files in this directory. */
11360 int dir_idx
; /* Index of directory used as base. */
11363 /* Callback function for file_info comparison. We sort by looking at
11364 the directories in the path. */
11367 file_info_cmp (const void *p1
, const void *p2
)
11369 const struct file_info
*const s1
= (const struct file_info
*) p1
;
11370 const struct file_info
*const s2
= (const struct file_info
*) p2
;
11371 const unsigned char *cp1
;
11372 const unsigned char *cp2
;
11374 /* Take care of file names without directories. We need to make sure that
11375 we return consistent values to qsort since some will get confused if
11376 we return the same value when identical operands are passed in opposite
11377 orders. So if neither has a directory, return 0 and otherwise return
11378 1 or -1 depending on which one has the directory. */
11379 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
11380 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
11382 cp1
= (const unsigned char *) s1
->path
;
11383 cp2
= (const unsigned char *) s2
->path
;
11389 /* Reached the end of the first path? If so, handle like above. */
11390 if ((cp1
== (const unsigned char *) s1
->fname
)
11391 || (cp2
== (const unsigned char *) s2
->fname
))
11392 return ((cp2
== (const unsigned char *) s2
->fname
)
11393 - (cp1
== (const unsigned char *) s1
->fname
));
11395 /* Character of current path component the same? */
11396 else if (*cp1
!= *cp2
)
11397 return *cp1
- *cp2
;
11401 struct file_name_acquire_data
11403 struct file_info
*files
;
11408 /* Traversal function for the hash table. */
11411 file_name_acquire (dwarf_file_data
**slot
, file_name_acquire_data
*fnad
)
11413 struct dwarf_file_data
*d
= *slot
;
11414 struct file_info
*fi
;
11417 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
11419 if (! d
->emitted_number
)
11422 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
11424 fi
= fnad
->files
+ fnad
->used_files
++;
11426 /* Skip all leading "./". */
11428 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
11431 /* Create a new array entry. */
11433 fi
->length
= strlen (f
);
11436 /* Search for the file name part. */
11437 f
= strrchr (f
, DIR_SEPARATOR
);
11438 #if defined (DIR_SEPARATOR_2)
11440 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
11444 if (f
== NULL
|| f
< g
)
11450 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
11454 /* Helper function for output_file_names. Emit a FORM encoded
11455 string STR, with assembly comment start ENTRY_KIND and
11459 output_line_string (enum dwarf_form form
, const char *str
,
11460 const char *entry_kind
, unsigned int idx
)
11464 case DW_FORM_string
:
11465 dw2_asm_output_nstring (str
, -1, "%s: %#x", entry_kind
, idx
);
11467 case DW_FORM_line_strp
:
11468 if (!debug_line_str_hash
)
11469 debug_line_str_hash
11470 = hash_table
<indirect_string_hasher
>::create_ggc (10);
11472 struct indirect_string_node
*node
;
11473 node
= find_AT_string_in_table (str
, debug_line_str_hash
);
11474 set_indirect_string (node
);
11476 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
11477 debug_line_str_section
, "%s: %#x: \"%s\"",
11478 entry_kind
, 0, node
->str
);
11481 gcc_unreachable ();
11485 /* Output the directory table and the file name table. We try to minimize
11486 the total amount of memory needed. A heuristic is used to avoid large
11487 slowdowns with many input files. */
11490 output_file_names (void)
11492 struct file_name_acquire_data fnad
;
11494 struct file_info
*files
;
11495 struct dir_info
*dirs
;
11503 if (!last_emitted_file
)
11505 if (dwarf_version
>= 5)
11507 dw2_asm_output_data (1, 0, "Directory entry format count");
11508 dw2_asm_output_data_uleb128 (0, "Directories count");
11509 dw2_asm_output_data (1, 0, "File name entry format count");
11510 dw2_asm_output_data_uleb128 (0, "File names count");
11514 dw2_asm_output_data (1, 0, "End directory table");
11515 dw2_asm_output_data (1, 0, "End file name table");
11520 numfiles
= last_emitted_file
->emitted_number
;
11522 /* Allocate the various arrays we need. */
11523 files
= XALLOCAVEC (struct file_info
, numfiles
);
11524 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
11526 fnad
.files
= files
;
11527 fnad
.used_files
= 0;
11528 fnad
.max_files
= numfiles
;
11529 file_table
->traverse
<file_name_acquire_data
*, file_name_acquire
> (&fnad
);
11530 gcc_assert (fnad
.used_files
== fnad
.max_files
);
11532 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
11534 /* Find all the different directories used. */
11535 dirs
[0].path
= files
[0].path
;
11536 dirs
[0].length
= files
[0].fname
- files
[0].path
;
11537 dirs
[0].prefix
= -1;
11539 dirs
[0].dir_idx
= 0;
11540 files
[0].dir_idx
= 0;
11543 for (i
= 1; i
< numfiles
; i
++)
11544 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
11545 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
11546 dirs
[ndirs
- 1].length
) == 0)
11548 /* Same directory as last entry. */
11549 files
[i
].dir_idx
= ndirs
- 1;
11550 ++dirs
[ndirs
- 1].count
;
11556 /* This is a new directory. */
11557 dirs
[ndirs
].path
= files
[i
].path
;
11558 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
11559 dirs
[ndirs
].count
= 1;
11560 dirs
[ndirs
].dir_idx
= ndirs
;
11561 files
[i
].dir_idx
= ndirs
;
11563 /* Search for a prefix. */
11564 dirs
[ndirs
].prefix
= -1;
11565 for (j
= 0; j
< ndirs
; j
++)
11566 if (dirs
[j
].length
< dirs
[ndirs
].length
11567 && dirs
[j
].length
> 1
11568 && (dirs
[ndirs
].prefix
== -1
11569 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
11570 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
11571 dirs
[ndirs
].prefix
= j
;
11576 /* Now to the actual work. We have to find a subset of the directories which
11577 allow expressing the file name using references to the directory table
11578 with the least amount of characters. We do not do an exhaustive search
11579 where we would have to check out every combination of every single
11580 possible prefix. Instead we use a heuristic which provides nearly optimal
11581 results in most cases and never is much off. */
11582 saved
= XALLOCAVEC (int, ndirs
);
11583 savehere
= XALLOCAVEC (int, ndirs
);
11585 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
11586 for (i
= 0; i
< ndirs
; i
++)
11591 /* We can always save some space for the current directory. But this
11592 does not mean it will be enough to justify adding the directory. */
11593 savehere
[i
] = dirs
[i
].length
;
11594 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
11596 for (j
= i
+ 1; j
< ndirs
; j
++)
11599 if (saved
[j
] < dirs
[i
].length
)
11601 /* Determine whether the dirs[i] path is a prefix of the
11605 k
= dirs
[j
].prefix
;
11606 while (k
!= -1 && k
!= (int) i
)
11607 k
= dirs
[k
].prefix
;
11611 /* Yes it is. We can possibly save some memory by
11612 writing the filenames in dirs[j] relative to
11614 savehere
[j
] = dirs
[i
].length
;
11615 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
11620 /* Check whether we can save enough to justify adding the dirs[i]
11622 if (total
> dirs
[i
].length
+ 1)
11624 /* It's worthwhile adding. */
11625 for (j
= i
; j
< ndirs
; j
++)
11626 if (savehere
[j
] > 0)
11628 /* Remember how much we saved for this directory so far. */
11629 saved
[j
] = savehere
[j
];
11631 /* Remember the prefix directory. */
11632 dirs
[j
].dir_idx
= i
;
11637 /* Emit the directory name table. */
11638 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
11639 enum dwarf_form str_form
= DW_FORM_string
;
11640 enum dwarf_form idx_form
= DW_FORM_udata
;
11641 if (dwarf_version
>= 5)
11643 const char *comp_dir
= comp_dir_string ();
11644 if (comp_dir
== NULL
)
11646 dw2_asm_output_data (1, 1, "Directory entry format count");
11647 if (DWARF5_USE_DEBUG_LINE_STR
)
11648 str_form
= DW_FORM_line_strp
;
11649 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
11650 dw2_asm_output_data_uleb128 (str_form
, "%s",
11651 get_DW_FORM_name (str_form
));
11652 dw2_asm_output_data_uleb128 (ndirs
+ idx_offset
, "Directories count");
11653 if (str_form
== DW_FORM_string
)
11655 dw2_asm_output_nstring (comp_dir
, -1, "Directory Entry: %#x", 0);
11656 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
11657 dw2_asm_output_nstring (dirs
[i
].path
,
11659 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
11660 "Directory Entry: %#x", i
+ idx_offset
);
11664 output_line_string (str_form
, comp_dir
, "Directory Entry", 0);
11665 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
11668 = ggc_alloc_string (dirs
[i
].path
,
11670 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
);
11671 output_line_string (str_form
, str
, "Directory Entry",
11672 (unsigned) i
+ idx_offset
);
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
);
11684 dw2_asm_output_data (1, 0, "End directory table");
11687 /* We have to emit them in the order of emitted_number since that's
11688 used in the debug info generation. To do this efficiently we
11689 generate a back-mapping of the indices first. */
11690 backmap
= XALLOCAVEC (int, numfiles
);
11691 for (i
= 0; i
< numfiles
; i
++)
11692 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
11694 if (dwarf_version
>= 5)
11696 const char *filename0
= get_AT_string (comp_unit_die (), DW_AT_name
);
11697 if (filename0
== NULL
)
11699 /* DW_LNCT_directory_index can use DW_FORM_udata, DW_FORM_data1 and
11700 DW_FORM_data2. Choose one based on the number of directories
11701 and how much space would they occupy in each encoding.
11702 If we have at most 256 directories, all indexes fit into
11703 a single byte, so DW_FORM_data1 is most compact (if there
11704 are at most 128 directories, DW_FORM_udata would be as
11705 compact as that, but not shorter and slower to decode). */
11706 if (ndirs
+ idx_offset
<= 256)
11707 idx_form
= DW_FORM_data1
;
11708 /* If there are more than 65536 directories, we have to use
11709 DW_FORM_udata, DW_FORM_data2 can't refer to them.
11710 Otherwise, compute what space would occupy if all the indexes
11711 used DW_FORM_udata - sum - and compare that to how large would
11712 be DW_FORM_data2 encoding, and pick the more efficient one. */
11713 else if (ndirs
+ idx_offset
<= 65536)
11715 unsigned HOST_WIDE_INT sum
= 1;
11716 for (i
= 0; i
< numfiles
; i
++)
11718 int file_idx
= backmap
[i
];
11719 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
11720 sum
+= size_of_uleb128 (dir_idx
);
11722 if (sum
>= HOST_WIDE_INT_UC (2) * (numfiles
+ 1))
11723 idx_form
= DW_FORM_data2
;
11725 #ifdef VMS_DEBUGGING_INFO
11726 dw2_asm_output_data (1, 4, "File name entry format count");
11728 dw2_asm_output_data (1, 2, "File name entry format count");
11730 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
11731 dw2_asm_output_data_uleb128 (str_form
, "%s",
11732 get_DW_FORM_name (str_form
));
11733 dw2_asm_output_data_uleb128 (DW_LNCT_directory_index
,
11734 "DW_LNCT_directory_index");
11735 dw2_asm_output_data_uleb128 (idx_form
, "%s",
11736 get_DW_FORM_name (idx_form
));
11737 #ifdef VMS_DEBUGGING_INFO
11738 dw2_asm_output_data_uleb128 (DW_LNCT_timestamp
, "DW_LNCT_timestamp");
11739 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
11740 dw2_asm_output_data_uleb128 (DW_LNCT_size
, "DW_LNCT_size");
11741 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
11743 dw2_asm_output_data_uleb128 (numfiles
+ 1, "File names count");
11745 output_line_string (str_form
, filename0
, "File Entry", 0);
11747 /* Include directory index. */
11748 if (idx_form
!= DW_FORM_udata
)
11749 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
11752 dw2_asm_output_data_uleb128 (0, NULL
);
11754 #ifdef VMS_DEBUGGING_INFO
11755 dw2_asm_output_data_uleb128 (0, NULL
);
11756 dw2_asm_output_data_uleb128 (0, NULL
);
11760 /* Now write all the file names. */
11761 for (i
= 0; i
< numfiles
; i
++)
11763 int file_idx
= backmap
[i
];
11764 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
11766 #ifdef VMS_DEBUGGING_INFO
11767 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
11769 /* Setting these fields can lead to debugger miscomparisons,
11770 but VMS Debug requires them to be set correctly. */
11775 int maxfilelen
= (strlen (files
[file_idx
].path
)
11776 + dirs
[dir_idx
].length
11777 + MAX_VMS_VERSION_LEN
+ 1);
11778 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
11780 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
11781 snprintf (filebuf
, maxfilelen
, "%s;%d",
11782 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
11784 output_line_string (str_form
, filebuf
, "File Entry", (unsigned) i
+ 1);
11786 /* Include directory index. */
11787 if (dwarf_version
>= 5 && idx_form
!= DW_FORM_udata
)
11788 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
11789 dir_idx
+ idx_offset
, NULL
);
11791 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
11793 /* Modification time. */
11794 dw2_asm_output_data_uleb128 ((vms_file_stats_name (files
[file_idx
].path
,
11795 &cdt
, 0, 0, 0) == 0)
11798 /* File length in bytes. */
11799 dw2_asm_output_data_uleb128 ((vms_file_stats_name (files
[file_idx
].path
,
11800 0, &siz
, 0, 0) == 0)
11803 output_line_string (str_form
,
11804 files
[file_idx
].path
+ dirs
[dir_idx
].length
,
11805 "File Entry", (unsigned) i
+ 1);
11807 /* Include directory index. */
11808 if (dwarf_version
>= 5 && idx_form
!= DW_FORM_udata
)
11809 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
11810 dir_idx
+ idx_offset
, NULL
);
11812 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
11814 if (dwarf_version
>= 5)
11817 /* Modification time. */
11818 dw2_asm_output_data_uleb128 (0, NULL
);
11820 /* File length in bytes. */
11821 dw2_asm_output_data_uleb128 (0, NULL
);
11822 #endif /* VMS_DEBUGGING_INFO */
11825 if (dwarf_version
< 5)
11826 dw2_asm_output_data (1, 0, "End file name table");
11830 /* Output one line number table into the .debug_line section. */
11833 output_one_line_info_table (dw_line_info_table
*table
)
11835 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
11836 unsigned int current_line
= 1;
11837 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
11838 dw_line_info_entry
*ent
;
11841 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
11843 switch (ent
->opcode
)
11845 case LI_set_address
:
11846 /* ??? Unfortunately, we have little choice here currently, and
11847 must always use the most general form. GCC does not know the
11848 address delta itself, so we can't use DW_LNS_advance_pc. Many
11849 ports do have length attributes which will give an upper bound
11850 on the address range. We could perhaps use length attributes
11851 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
11852 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
11854 /* This can handle any delta. This takes
11855 4+DWARF2_ADDR_SIZE bytes. */
11856 dw2_asm_output_data (1, 0, "set address %s", line_label
);
11857 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
11858 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
11859 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
11863 if (ent
->val
== current_line
)
11865 /* We still need to start a new row, so output a copy insn. */
11866 dw2_asm_output_data (1, DW_LNS_copy
,
11867 "copy line %u", current_line
);
11871 int line_offset
= ent
->val
- current_line
;
11872 int line_delta
= line_offset
- DWARF_LINE_BASE
;
11874 current_line
= ent
->val
;
11875 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
11877 /* This can handle deltas from -10 to 234, using the current
11878 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
11879 This takes 1 byte. */
11880 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
11881 "line %u", current_line
);
11885 /* This can handle any delta. This takes at least 4 bytes,
11886 depending on the value being encoded. */
11887 dw2_asm_output_data (1, DW_LNS_advance_line
,
11888 "advance to line %u", current_line
);
11889 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
11890 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
11896 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
11897 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
11900 case LI_set_column
:
11901 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
11902 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
11905 case LI_negate_stmt
:
11906 current_is_stmt
= !current_is_stmt
;
11907 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
11908 "is_stmt %d", current_is_stmt
);
11911 case LI_set_prologue_end
:
11912 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
11913 "set prologue end");
11916 case LI_set_epilogue_begin
:
11917 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
11918 "set epilogue begin");
11921 case LI_set_discriminator
:
11922 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
11923 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
11924 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
11925 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
11930 /* Emit debug info for the address of the end of the table. */
11931 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
11932 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
11933 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
11934 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
11936 dw2_asm_output_data (1, 0, "end sequence");
11937 dw2_asm_output_data_uleb128 (1, NULL
);
11938 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
11941 /* Output the source line number correspondence information. This
11942 information goes into the .debug_line section. */
11945 output_line_info (bool prologue_only
)
11947 static unsigned int generation
;
11948 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
11949 char p1
[MAX_ARTIFICIAL_LABEL_BYTES
], p2
[MAX_ARTIFICIAL_LABEL_BYTES
];
11950 bool saw_one
= false;
11953 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, generation
);
11954 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, generation
);
11955 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, generation
);
11956 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, generation
++);
11958 if (!XCOFF_DEBUGGING_INFO
)
11960 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11961 dw2_asm_output_data (4, 0xffffffff,
11962 "Initial length escape value indicating 64-bit DWARF extension");
11963 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
11964 "Length of Source Line Info");
11967 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
11969 dw2_asm_output_data (2, dwarf_version
, "DWARF Version");
11970 if (dwarf_version
>= 5)
11972 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
11973 dw2_asm_output_data (1, 0, "Segment Size");
11975 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
11976 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
11978 /* Define the architecture-dependent minimum instruction length (in bytes).
11979 In this implementation of DWARF, this field is used for information
11980 purposes only. Since GCC generates assembly language, we have no
11981 a priori knowledge of how many instruction bytes are generated for each
11982 source line, and therefore can use only the DW_LNE_set_address and
11983 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
11984 this as '1', which is "correct enough" for all architectures,
11985 and don't let the target override. */
11986 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
11988 if (dwarf_version
>= 4)
11989 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
11990 "Maximum Operations Per Instruction");
11991 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
11992 "Default is_stmt_start flag");
11993 dw2_asm_output_data (1, DWARF_LINE_BASE
,
11994 "Line Base Value (Special Opcodes)");
11995 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
11996 "Line Range Value (Special Opcodes)");
11997 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
11998 "Special Opcode Base");
12000 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
12005 case DW_LNS_advance_pc
:
12006 case DW_LNS_advance_line
:
12007 case DW_LNS_set_file
:
12008 case DW_LNS_set_column
:
12009 case DW_LNS_fixed_advance_pc
:
12010 case DW_LNS_set_isa
:
12018 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
12022 /* Write out the information about the files we use. */
12023 output_file_names ();
12024 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
12027 /* Output the marker for the end of the line number info. */
12028 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
12032 if (separate_line_info
)
12034 dw_line_info_table
*table
;
12037 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
12040 output_one_line_info_table (table
);
12044 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
12046 output_one_line_info_table (cold_text_section_line_info
);
12050 /* ??? Some Darwin linkers crash on a .debug_line section with no
12051 sequences. Further, merely a DW_LNE_end_sequence entry is not
12052 sufficient -- the address column must also be initialized.
12053 Make sure to output at least one set_address/end_sequence pair,
12054 choosing .text since that section is always present. */
12055 if (text_section_line_info
->in_use
|| !saw_one
)
12056 output_one_line_info_table (text_section_line_info
);
12058 /* Output the marker for the end of the line number info. */
12059 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
12062 /* Return true if DW_AT_endianity should be emitted according to REVERSE. */
12065 need_endianity_attribute_p (bool reverse
)
12067 return reverse
&& (dwarf_version
>= 3 || !dwarf_strict
);
12070 /* Given a pointer to a tree node for some base type, return a pointer to
12071 a DIE that describes the given type. REVERSE is true if the type is
12072 to be interpreted in the reverse storage order wrt the target order.
12074 This routine must only be called for GCC type nodes that correspond to
12075 Dwarf base (fundamental) types. */
12078 base_type_die (tree type
, bool reverse
)
12080 dw_die_ref base_type_result
;
12081 enum dwarf_type encoding
;
12082 bool fpt_used
= false;
12083 struct fixed_point_type_info fpt_info
;
12084 tree type_bias
= NULL_TREE
;
12086 /* If this is a subtype that should not be emitted as a subrange type,
12087 use the base type. See subrange_type_for_debug_p. */
12088 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
12089 type
= TREE_TYPE (type
);
12091 switch (TREE_CODE (type
))
12094 if ((dwarf_version
>= 4 || !dwarf_strict
)
12095 && TYPE_NAME (type
)
12096 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
12097 && DECL_IS_BUILTIN (TYPE_NAME (type
))
12098 && DECL_NAME (TYPE_NAME (type
)))
12100 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
12101 if (strcmp (name
, "char16_t") == 0
12102 || strcmp (name
, "char32_t") == 0)
12104 encoding
= DW_ATE_UTF
;
12108 if ((dwarf_version
>= 3 || !dwarf_strict
)
12109 && lang_hooks
.types
.get_fixed_point_type_info
)
12111 memset (&fpt_info
, 0, sizeof (fpt_info
));
12112 if (lang_hooks
.types
.get_fixed_point_type_info (type
, &fpt_info
))
12115 encoding
= ((TYPE_UNSIGNED (type
))
12116 ? DW_ATE_unsigned_fixed
12117 : DW_ATE_signed_fixed
);
12121 if (TYPE_STRING_FLAG (type
))
12123 if (TYPE_UNSIGNED (type
))
12124 encoding
= DW_ATE_unsigned_char
;
12126 encoding
= DW_ATE_signed_char
;
12128 else if (TYPE_UNSIGNED (type
))
12129 encoding
= DW_ATE_unsigned
;
12131 encoding
= DW_ATE_signed
;
12134 && lang_hooks
.types
.get_type_bias
)
12135 type_bias
= lang_hooks
.types
.get_type_bias (type
);
12139 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
12141 if (dwarf_version
>= 3 || !dwarf_strict
)
12142 encoding
= DW_ATE_decimal_float
;
12144 encoding
= DW_ATE_lo_user
;
12147 encoding
= DW_ATE_float
;
12150 case FIXED_POINT_TYPE
:
12151 if (!(dwarf_version
>= 3 || !dwarf_strict
))
12152 encoding
= DW_ATE_lo_user
;
12153 else if (TYPE_UNSIGNED (type
))
12154 encoding
= DW_ATE_unsigned_fixed
;
12156 encoding
= DW_ATE_signed_fixed
;
12159 /* Dwarf2 doesn't know anything about complex ints, so use
12160 a user defined type for it. */
12162 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
12163 encoding
= DW_ATE_complex_float
;
12165 encoding
= DW_ATE_lo_user
;
12169 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12170 encoding
= DW_ATE_boolean
;
12174 /* No other TREE_CODEs are Dwarf fundamental types. */
12175 gcc_unreachable ();
12178 base_type_result
= new_die_raw (DW_TAG_base_type
);
12180 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
12181 int_size_in_bytes (type
));
12182 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
12184 if (need_endianity_attribute_p (reverse
))
12185 add_AT_unsigned (base_type_result
, DW_AT_endianity
,
12186 BYTES_BIG_ENDIAN
? DW_END_little
: DW_END_big
);
12188 add_alignment_attribute (base_type_result
, type
);
12192 switch (fpt_info
.scale_factor_kind
)
12194 case fixed_point_scale_factor_binary
:
12195 add_AT_int (base_type_result
, DW_AT_binary_scale
,
12196 fpt_info
.scale_factor
.binary
);
12199 case fixed_point_scale_factor_decimal
:
12200 add_AT_int (base_type_result
, DW_AT_decimal_scale
,
12201 fpt_info
.scale_factor
.decimal
);
12204 case fixed_point_scale_factor_arbitrary
:
12205 /* Arbitrary scale factors cannot be described in standard DWARF,
12209 /* Describe the scale factor as a rational constant. */
12210 const dw_die_ref scale_factor
12211 = new_die (DW_TAG_constant
, comp_unit_die (), type
);
12213 add_AT_unsigned (scale_factor
, DW_AT_GNU_numerator
,
12214 fpt_info
.scale_factor
.arbitrary
.numerator
);
12215 add_AT_int (scale_factor
, DW_AT_GNU_denominator
,
12216 fpt_info
.scale_factor
.arbitrary
.denominator
);
12218 add_AT_die_ref (base_type_result
, DW_AT_small
, scale_factor
);
12223 gcc_unreachable ();
12228 add_scalar_info (base_type_result
, DW_AT_GNU_bias
, type_bias
,
12229 dw_scalar_form_constant
12230 | dw_scalar_form_exprloc
12231 | dw_scalar_form_reference
,
12234 return base_type_result
;
12237 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
12238 named 'auto' in its type: return true for it, false otherwise. */
12241 is_cxx_auto (tree type
)
12245 tree name
= TYPE_IDENTIFIER (type
);
12246 if (name
== get_identifier ("auto")
12247 || name
== get_identifier ("decltype(auto)"))
12253 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12254 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12257 is_base_type (tree type
)
12259 switch (TREE_CODE (type
))
12263 case FIXED_POINT_TYPE
:
12266 case POINTER_BOUNDS_TYPE
:
12273 case QUAL_UNION_TYPE
:
12274 case ENUMERAL_TYPE
:
12275 case FUNCTION_TYPE
:
12278 case REFERENCE_TYPE
:
12286 if (is_cxx_auto (type
))
12288 gcc_unreachable ();
12294 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12295 node, return the size in bits for the type if it is a constant, or else
12296 return the alignment for the type if the type's size is not constant, or
12297 else return BITS_PER_WORD if the type actually turns out to be an
12298 ERROR_MARK node. */
12300 static inline unsigned HOST_WIDE_INT
12301 simple_type_size_in_bits (const_tree type
)
12303 if (TREE_CODE (type
) == ERROR_MARK
)
12304 return BITS_PER_WORD
;
12305 else if (TYPE_SIZE (type
) == NULL_TREE
)
12307 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
12308 return tree_to_uhwi (TYPE_SIZE (type
));
12310 return TYPE_ALIGN (type
);
12313 /* Similarly, but return an offset_int instead of UHWI. */
12315 static inline offset_int
12316 offset_int_type_size_in_bits (const_tree type
)
12318 if (TREE_CODE (type
) == ERROR_MARK
)
12319 return BITS_PER_WORD
;
12320 else if (TYPE_SIZE (type
) == NULL_TREE
)
12322 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
12323 return wi::to_offset (TYPE_SIZE (type
));
12325 return TYPE_ALIGN (type
);
12328 /* Given a pointer to a tree node for a subrange type, return a pointer
12329 to a DIE that describes the given type. */
12332 subrange_type_die (tree type
, tree low
, tree high
, tree bias
,
12333 dw_die_ref context_die
)
12335 dw_die_ref subrange_die
;
12336 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
12338 if (context_die
== NULL
)
12339 context_die
= comp_unit_die ();
12341 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
12343 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
12345 /* The size of the subrange type and its base type do not match,
12346 so we need to generate a size attribute for the subrange type. */
12347 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
12350 add_alignment_attribute (subrange_die
, type
);
12353 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
, NULL
);
12355 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
, NULL
);
12356 if (bias
&& !dwarf_strict
)
12357 add_scalar_info (subrange_die
, DW_AT_GNU_bias
, bias
,
12358 dw_scalar_form_constant
12359 | dw_scalar_form_exprloc
12360 | dw_scalar_form_reference
,
12363 return subrange_die
;
12366 /* Returns the (const and/or volatile) cv_qualifiers associated with
12367 the decl node. This will normally be augmented with the
12368 cv_qualifiers of the underlying type in add_type_attribute. */
12371 decl_quals (const_tree decl
)
12373 return ((TREE_READONLY (decl
)
12374 /* The C++ front-end correctly marks reference-typed
12375 variables as readonly, but from a language (and debug
12376 info) standpoint they are not const-qualified. */
12377 && TREE_CODE (TREE_TYPE (decl
)) != REFERENCE_TYPE
12378 ? TYPE_QUAL_CONST
: TYPE_UNQUALIFIED
)
12379 | (TREE_THIS_VOLATILE (decl
)
12380 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
));
12383 /* Determine the TYPE whose qualifiers match the largest strict subset
12384 of the given TYPE_QUALS, and return its qualifiers. Ignore all
12385 qualifiers outside QUAL_MASK. */
12388 get_nearest_type_subqualifiers (tree type
, int type_quals
, int qual_mask
)
12391 int best_rank
= 0, best_qual
= 0, max_rank
;
12393 type_quals
&= qual_mask
;
12394 max_rank
= popcount_hwi (type_quals
) - 1;
12396 for (t
= TYPE_MAIN_VARIANT (type
); t
&& best_rank
< max_rank
;
12397 t
= TYPE_NEXT_VARIANT (t
))
12399 int q
= TYPE_QUALS (t
) & qual_mask
;
12401 if ((q
& type_quals
) == q
&& q
!= type_quals
12402 && check_base_type (t
, type
))
12404 int rank
= popcount_hwi (q
);
12406 if (rank
> best_rank
)
12417 struct dwarf_qual_info_t
{ int q
; enum dwarf_tag t
; };
12418 static const dwarf_qual_info_t dwarf_qual_info
[] =
12420 { TYPE_QUAL_CONST
, DW_TAG_const_type
},
12421 { TYPE_QUAL_VOLATILE
, DW_TAG_volatile_type
},
12422 { TYPE_QUAL_RESTRICT
, DW_TAG_restrict_type
},
12423 { TYPE_QUAL_ATOMIC
, DW_TAG_atomic_type
}
12425 static const unsigned int dwarf_qual_info_size
12426 = sizeof (dwarf_qual_info
) / sizeof (dwarf_qual_info
[0]);
12428 /* If DIE is a qualified DIE of some base DIE with the same parent,
12429 return the base DIE, otherwise return NULL. Set MASK to the
12430 qualifiers added compared to the returned DIE. */
12433 qualified_die_p (dw_die_ref die
, int *mask
, unsigned int depth
)
12436 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
12437 if (die
->die_tag
== dwarf_qual_info
[i
].t
)
12439 if (i
== dwarf_qual_info_size
)
12441 if (vec_safe_length (die
->die_attr
) != 1)
12443 dw_die_ref type
= get_AT_ref (die
, DW_AT_type
);
12444 if (type
== NULL
|| type
->die_parent
!= die
->die_parent
)
12446 *mask
|= dwarf_qual_info
[i
].q
;
12449 dw_die_ref ret
= qualified_die_p (type
, mask
, depth
- 1);
12456 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12457 entry that chains the modifiers specified by CV_QUALS in front of the
12458 given type. REVERSE is true if the type is to be interpreted in the
12459 reverse storage order wrt the target order. */
12462 modified_type_die (tree type
, int cv_quals
, bool reverse
,
12463 dw_die_ref context_die
)
12465 enum tree_code code
= TREE_CODE (type
);
12466 dw_die_ref mod_type_die
;
12467 dw_die_ref sub_die
= NULL
;
12468 tree item_type
= NULL
;
12469 tree qualified_type
;
12470 tree name
, low
, high
;
12471 dw_die_ref mod_scope
;
12472 /* Only these cv-qualifiers are currently handled. */
12473 const int cv_qual_mask
= (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
12474 | TYPE_QUAL_RESTRICT
| TYPE_QUAL_ATOMIC
|
12475 ENCODE_QUAL_ADDR_SPACE(~0U));
12476 const bool reverse_base_type
12477 = need_endianity_attribute_p (reverse
) && is_base_type (type
);
12479 if (code
== ERROR_MARK
)
12482 if (lang_hooks
.types
.get_debug_type
)
12484 tree debug_type
= lang_hooks
.types
.get_debug_type (type
);
12486 if (debug_type
!= NULL_TREE
&& debug_type
!= type
)
12487 return modified_type_die (debug_type
, cv_quals
, reverse
, context_die
);
12490 cv_quals
&= cv_qual_mask
;
12492 /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
12493 tag modifier (and not an attribute) old consumers won't be able
12495 if (dwarf_version
< 3)
12496 cv_quals
&= ~TYPE_QUAL_RESTRICT
;
12498 /* Likewise for DW_TAG_atomic_type for DWARFv5. */
12499 if (dwarf_version
< 5)
12500 cv_quals
&= ~TYPE_QUAL_ATOMIC
;
12502 /* See if we already have the appropriately qualified variant of
12504 qualified_type
= get_qualified_type (type
, cv_quals
);
12506 if (qualified_type
== sizetype
)
12508 /* Try not to expose the internal sizetype type's name. */
12509 if (TYPE_NAME (qualified_type
)
12510 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
12512 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
12514 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
12515 && (TYPE_PRECISION (t
)
12516 == TYPE_PRECISION (qualified_type
))
12517 && (TYPE_UNSIGNED (t
)
12518 == TYPE_UNSIGNED (qualified_type
)));
12519 qualified_type
= t
;
12521 else if (qualified_type
== sizetype
12522 && TREE_CODE (sizetype
) == TREE_CODE (size_type_node
)
12523 && TYPE_PRECISION (sizetype
) == TYPE_PRECISION (size_type_node
)
12524 && TYPE_UNSIGNED (sizetype
) == TYPE_UNSIGNED (size_type_node
))
12525 qualified_type
= size_type_node
;
12528 /* If we do, then we can just use its DIE, if it exists. */
12529 if (qualified_type
)
12531 mod_type_die
= lookup_type_die (qualified_type
);
12533 /* DW_AT_endianity doesn't come from a qualifier on the type, so it is
12534 dealt with specially: the DIE with the attribute, if it exists, is
12535 placed immediately after the regular DIE for the same base type. */
12537 && (!reverse_base_type
12538 || ((mod_type_die
= mod_type_die
->die_sib
) != NULL
12539 && get_AT_unsigned (mod_type_die
, DW_AT_endianity
))))
12540 return mod_type_die
;
12543 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
12545 /* Handle C typedef types. */
12547 && TREE_CODE (name
) == TYPE_DECL
12548 && DECL_ORIGINAL_TYPE (name
)
12549 && !DECL_ARTIFICIAL (name
))
12551 tree dtype
= TREE_TYPE (name
);
12553 /* Skip the typedef for base types with DW_AT_endianity, no big deal. */
12554 if (qualified_type
== dtype
&& !reverse_base_type
)
12556 tree origin
= decl_ultimate_origin (name
);
12558 /* Typedef variants that have an abstract origin don't get their own
12559 type DIE (see gen_typedef_die), so fall back on the ultimate
12560 abstract origin instead. */
12561 if (origin
!= NULL
&& origin
!= name
)
12562 return modified_type_die (TREE_TYPE (origin
), cv_quals
, reverse
,
12565 /* For a named type, use the typedef. */
12566 gen_type_die (qualified_type
, context_die
);
12567 return lookup_type_die (qualified_type
);
12571 int dquals
= TYPE_QUALS_NO_ADDR_SPACE (dtype
);
12572 dquals
&= cv_qual_mask
;
12573 if ((dquals
& ~cv_quals
) != TYPE_UNQUALIFIED
12574 || (cv_quals
== dquals
&& DECL_ORIGINAL_TYPE (name
) != type
))
12575 /* cv-unqualified version of named type. Just use
12576 the unnamed type to which it refers. */
12577 return modified_type_die (DECL_ORIGINAL_TYPE (name
), cv_quals
,
12578 reverse
, context_die
);
12579 /* Else cv-qualified version of named type; fall through. */
12583 mod_scope
= scope_die_for (type
, context_die
);
12587 int sub_quals
= 0, first_quals
= 0;
12589 dw_die_ref first
= NULL
, last
= NULL
;
12591 /* Determine a lesser qualified type that most closely matches
12592 this one. Then generate DW_TAG_* entries for the remaining
12594 sub_quals
= get_nearest_type_subqualifiers (type
, cv_quals
,
12596 if (sub_quals
&& use_debug_types
)
12598 bool needed
= false;
12599 /* If emitting type units, make sure the order of qualifiers
12600 is canonical. Thus, start from unqualified type if
12601 an earlier qualifier is missing in sub_quals, but some later
12602 one is present there. */
12603 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
12604 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
12606 else if (needed
&& (dwarf_qual_info
[i
].q
& cv_quals
))
12612 mod_type_die
= modified_type_die (type
, sub_quals
, reverse
, context_die
);
12613 if (mod_scope
&& mod_type_die
&& mod_type_die
->die_parent
== mod_scope
)
12615 /* As not all intermediate qualified DIEs have corresponding
12616 tree types, ensure that qualified DIEs in the same scope
12617 as their DW_AT_type are emitted after their DW_AT_type,
12618 only with other qualified DIEs for the same type possibly
12619 in between them. Determine the range of such qualified
12620 DIEs now (first being the base type, last being corresponding
12621 last qualified DIE for it). */
12622 unsigned int count
= 0;
12623 first
= qualified_die_p (mod_type_die
, &first_quals
,
12624 dwarf_qual_info_size
);
12626 first
= mod_type_die
;
12627 gcc_assert ((first_quals
& ~sub_quals
) == 0);
12628 for (count
= 0, last
= first
;
12629 count
< (1U << dwarf_qual_info_size
);
12630 count
++, last
= last
->die_sib
)
12633 if (last
== mod_scope
->die_child
)
12635 if (qualified_die_p (last
->die_sib
, &quals
, dwarf_qual_info_size
)
12641 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
12642 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
12645 if (first
&& first
!= last
)
12647 for (d
= first
->die_sib
; ; d
= d
->die_sib
)
12650 qualified_die_p (d
, &quals
, dwarf_qual_info_size
);
12651 if (quals
== (first_quals
| dwarf_qual_info
[i
].q
))
12667 d
= new_die_raw (dwarf_qual_info
[i
].t
);
12668 add_child_die_after (mod_scope
, d
, last
);
12672 d
= new_die (dwarf_qual_info
[i
].t
, mod_scope
, type
);
12674 add_AT_die_ref (d
, DW_AT_type
, mod_type_die
);
12676 first_quals
|= dwarf_qual_info
[i
].q
;
12679 else if (code
== POINTER_TYPE
|| code
== REFERENCE_TYPE
)
12681 dwarf_tag tag
= DW_TAG_pointer_type
;
12682 if (code
== REFERENCE_TYPE
)
12684 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
12685 tag
= DW_TAG_rvalue_reference_type
;
12687 tag
= DW_TAG_reference_type
;
12689 mod_type_die
= new_die (tag
, mod_scope
, type
);
12691 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
12692 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
12693 add_alignment_attribute (mod_type_die
, type
);
12694 item_type
= TREE_TYPE (type
);
12696 addr_space_t as
= TYPE_ADDR_SPACE (item_type
);
12697 if (!ADDR_SPACE_GENERIC_P (as
))
12699 int action
= targetm
.addr_space
.debug (as
);
12702 /* Positive values indicate an address_class. */
12703 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, action
);
12707 /* Negative values indicate an (inverted) segment base reg. */
12709 = one_reg_loc_descriptor (~action
, VAR_INIT_STATUS_INITIALIZED
);
12710 add_AT_loc (mod_type_die
, DW_AT_segment
, d
);
12714 else if (code
== INTEGER_TYPE
12715 && TREE_TYPE (type
) != NULL_TREE
12716 && subrange_type_for_debug_p (type
, &low
, &high
))
12718 tree bias
= NULL_TREE
;
12719 if (lang_hooks
.types
.get_type_bias
)
12720 bias
= lang_hooks
.types
.get_type_bias (type
);
12721 mod_type_die
= subrange_type_die (type
, low
, high
, bias
, context_die
);
12722 item_type
= TREE_TYPE (type
);
12724 else if (is_base_type (type
))
12726 mod_type_die
= base_type_die (type
, reverse
);
12728 /* The DIE with DW_AT_endianity is placed right after the naked DIE. */
12729 if (reverse_base_type
)
12731 dw_die_ref after_die
12732 = modified_type_die (type
, cv_quals
, false, context_die
);
12733 add_child_die_after (comp_unit_die (), mod_type_die
, after_die
);
12736 add_child_die (comp_unit_die (), mod_type_die
);
12738 add_pubtype (type
, mod_type_die
);
12742 gen_type_die (type
, context_die
);
12744 /* We have to get the type_main_variant here (and pass that to the
12745 `lookup_type_die' routine) because the ..._TYPE node we have
12746 might simply be a *copy* of some original type node (where the
12747 copy was created to help us keep track of typedef names) and
12748 that copy might have a different TYPE_UID from the original
12750 if (TREE_CODE (type
) == FUNCTION_TYPE
12751 || TREE_CODE (type
) == METHOD_TYPE
)
12753 /* For function/method types, can't just use type_main_variant here,
12754 because that can have different ref-qualifiers for C++,
12755 but try to canonicalize. */
12756 tree main
= TYPE_MAIN_VARIANT (type
);
12757 for (tree t
= main
; t
; t
= TYPE_NEXT_VARIANT (t
))
12758 if (TYPE_QUALS_NO_ADDR_SPACE (t
) == 0
12759 && check_base_type (t
, main
)
12760 && check_lang_type (t
, type
))
12761 return lookup_type_die (t
);
12762 return lookup_type_die (type
);
12764 else if (TREE_CODE (type
) != VECTOR_TYPE
12765 && TREE_CODE (type
) != ARRAY_TYPE
)
12766 return lookup_type_die (type_main_variant (type
));
12768 /* Vectors have the debugging information in the type,
12769 not the main variant. */
12770 return lookup_type_die (type
);
12773 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
12774 don't output a DW_TAG_typedef, since there isn't one in the
12775 user's program; just attach a DW_AT_name to the type.
12776 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
12777 if the base type already has the same name. */
12779 && ((TREE_CODE (name
) != TYPE_DECL
12780 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
12781 || (cv_quals
== TYPE_UNQUALIFIED
)))
12782 || (TREE_CODE (name
) == TYPE_DECL
12783 && TREE_TYPE (name
) == qualified_type
12784 && DECL_NAME (name
))))
12786 if (TREE_CODE (name
) == TYPE_DECL
)
12787 /* Could just call add_name_and_src_coords_attributes here,
12788 but since this is a builtin type it doesn't have any
12789 useful source coordinates anyway. */
12790 name
= DECL_NAME (name
);
12791 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
12793 /* This probably indicates a bug. */
12794 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
12796 name
= TYPE_IDENTIFIER (type
);
12797 add_name_attribute (mod_type_die
,
12798 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
12801 if (qualified_type
&& !reverse_base_type
)
12802 equate_type_number_to_die (qualified_type
, mod_type_die
);
12805 /* We must do this after the equate_type_number_to_die call, in case
12806 this is a recursive type. This ensures that the modified_type_die
12807 recursion will terminate even if the type is recursive. Recursive
12808 types are possible in Ada. */
12809 sub_die
= modified_type_die (item_type
,
12810 TYPE_QUALS_NO_ADDR_SPACE (item_type
),
12814 if (sub_die
!= NULL
)
12815 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
12817 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
12818 if (TYPE_ARTIFICIAL (type
))
12819 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
12821 return mod_type_die
;
12824 /* Generate DIEs for the generic parameters of T.
12825 T must be either a generic type or a generic function.
12826 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
12829 gen_generic_params_dies (tree t
)
12833 dw_die_ref die
= NULL
;
12836 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
12840 die
= lookup_type_die (t
);
12841 else if (DECL_P (t
))
12842 die
= lookup_decl_die (t
);
12846 parms
= lang_hooks
.get_innermost_generic_parms (t
);
12848 /* T has no generic parameter. It means T is neither a generic type
12849 or function. End of story. */
12852 parms_num
= TREE_VEC_LENGTH (parms
);
12853 args
= lang_hooks
.get_innermost_generic_args (t
);
12854 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
12855 non_default
= int_cst_value (TREE_CHAIN (args
));
12857 non_default
= TREE_VEC_LENGTH (args
);
12858 for (i
= 0; i
< parms_num
; i
++)
12860 tree parm
, arg
, arg_pack_elems
;
12861 dw_die_ref parm_die
;
12863 parm
= TREE_VEC_ELT (parms
, i
);
12864 arg
= TREE_VEC_ELT (args
, i
);
12865 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
12866 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
12868 if (parm
&& TREE_VALUE (parm
) && arg
)
12870 /* If PARM represents a template parameter pack,
12871 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
12872 by DW_TAG_template_*_parameter DIEs for the argument
12873 pack elements of ARG. Note that ARG would then be
12874 an argument pack. */
12875 if (arg_pack_elems
)
12876 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
12880 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
12881 true /* emit name */, die
);
12882 if (i
>= non_default
)
12883 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
12888 /* Create and return a DIE for PARM which should be
12889 the representation of a generic type parameter.
12890 For instance, in the C++ front end, PARM would be a template parameter.
12891 ARG is the argument to PARM.
12892 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
12894 PARENT_DIE is the parent DIE which the new created DIE should be added to,
12895 as a child node. */
12898 generic_parameter_die (tree parm
, tree arg
,
12900 dw_die_ref parent_die
)
12902 dw_die_ref tmpl_die
= NULL
;
12903 const char *name
= NULL
;
12905 if (!parm
|| !DECL_NAME (parm
) || !arg
)
12908 /* We support non-type generic parameters and arguments,
12909 type generic parameters and arguments, as well as
12910 generic generic parameters (a.k.a. template template parameters in C++)
12912 if (TREE_CODE (parm
) == PARM_DECL
)
12913 /* PARM is a nontype generic parameter */
12914 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
12915 else if (TREE_CODE (parm
) == TYPE_DECL
)
12916 /* PARM is a type generic parameter. */
12917 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
12918 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
12919 /* PARM is a generic generic parameter.
12920 Its DIE is a GNU extension. It shall have a
12921 DW_AT_name attribute to represent the name of the template template
12922 parameter, and a DW_AT_GNU_template_name attribute to represent the
12923 name of the template template argument. */
12924 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
12927 gcc_unreachable ();
12933 /* If PARM is a generic parameter pack, it means we are
12934 emitting debug info for a template argument pack element.
12935 In other terms, ARG is a template argument pack element.
12936 In that case, we don't emit any DW_AT_name attribute for
12940 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
12942 add_AT_string (tmpl_die
, DW_AT_name
, name
);
12945 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
12947 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
12948 TMPL_DIE should have a child DW_AT_type attribute that is set
12949 to the type of the argument to PARM, which is ARG.
12950 If PARM is a type generic parameter, TMPL_DIE should have a
12951 child DW_AT_type that is set to ARG. */
12952 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
12953 add_type_attribute (tmpl_die
, tmpl_type
,
12954 (TREE_THIS_VOLATILE (tmpl_type
)
12955 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
),
12956 false, parent_die
);
12960 /* So TMPL_DIE is a DIE representing a
12961 a generic generic template parameter, a.k.a template template
12962 parameter in C++ and arg is a template. */
12964 /* The DW_AT_GNU_template_name attribute of the DIE must be set
12965 to the name of the argument. */
12966 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
12968 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
12971 if (TREE_CODE (parm
) == PARM_DECL
)
12972 /* So PARM is a non-type generic parameter.
12973 DWARF3 5.6.8 says we must set a DW_AT_const_value child
12974 attribute of TMPL_DIE which value represents the value
12976 We must be careful here:
12977 The value of ARG might reference some function decls.
12978 We might currently be emitting debug info for a generic
12979 type and types are emitted before function decls, we don't
12980 know if the function decls referenced by ARG will actually be
12981 emitted after cgraph computations.
12982 So must defer the generation of the DW_AT_const_value to
12983 after cgraph is ready. */
12984 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
12990 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
12991 PARM_PACK must be a template parameter pack. The returned DIE
12992 will be child DIE of PARENT_DIE. */
12995 template_parameter_pack_die (tree parm_pack
,
12996 tree parm_pack_args
,
12997 dw_die_ref parent_die
)
13002 gcc_assert (parent_die
&& parm_pack
);
13004 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
13005 add_name_and_src_coords_attributes (die
, parm_pack
);
13006 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
13007 generic_parameter_die (parm_pack
,
13008 TREE_VEC_ELT (parm_pack_args
, j
),
13009 false /* Don't emit DW_AT_name */,
13014 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
13015 an enumerated type. */
13018 type_is_enum (const_tree type
)
13020 return TREE_CODE (type
) == ENUMERAL_TYPE
;
13023 /* Return the DBX register number described by a given RTL node. */
13025 static unsigned int
13026 dbx_reg_number (const_rtx rtl
)
13028 unsigned regno
= REGNO (rtl
);
13030 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
13032 #ifdef LEAF_REG_REMAP
13033 if (crtl
->uses_only_leaf_regs
)
13035 int leaf_reg
= LEAF_REG_REMAP (regno
);
13036 if (leaf_reg
!= -1)
13037 regno
= (unsigned) leaf_reg
;
13041 regno
= DBX_REGISTER_NUMBER (regno
);
13042 gcc_assert (regno
!= INVALID_REGNUM
);
13046 /* Optionally add a DW_OP_piece term to a location description expression.
13047 DW_OP_piece is only added if the location description expression already
13048 doesn't end with DW_OP_piece. */
13051 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
13053 dw_loc_descr_ref loc
;
13055 if (*list_head
!= NULL
)
13057 /* Find the end of the chain. */
13058 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
13061 if (loc
->dw_loc_opc
!= DW_OP_piece
)
13062 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
13066 /* Return a location descriptor that designates a machine register or
13067 zero if there is none. */
13069 static dw_loc_descr_ref
13070 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
13074 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
13077 /* We only use "frame base" when we're sure we're talking about the
13078 post-prologue local stack frame. We do this by *not* running
13079 register elimination until this point, and recognizing the special
13080 argument pointer and soft frame pointer rtx's.
13081 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
13082 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
13083 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
13085 dw_loc_descr_ref result
= NULL
;
13087 if (dwarf_version
>= 4 || !dwarf_strict
)
13089 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
13092 add_loc_descr (&result
,
13093 new_loc_descr (DW_OP_stack_value
, 0, 0));
13098 regs
= targetm
.dwarf_register_span (rtl
);
13100 if (REG_NREGS (rtl
) > 1 || regs
)
13101 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
13104 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
13105 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
13107 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
13111 /* Return a location descriptor that designates a machine register for
13112 a given hard register number. */
13114 static dw_loc_descr_ref
13115 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
13117 dw_loc_descr_ref reg_loc_descr
;
13121 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
13123 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
13125 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13126 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13128 return reg_loc_descr
;
13131 /* Given an RTL of a register, return a location descriptor that
13132 designates a value that spans more than one register. */
13134 static dw_loc_descr_ref
13135 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
13136 enum var_init_status initialized
)
13139 dw_loc_descr_ref loc_result
= NULL
;
13141 /* Simple, contiguous registers. */
13142 if (regs
== NULL_RTX
)
13144 unsigned reg
= REGNO (rtl
);
13147 #ifdef LEAF_REG_REMAP
13148 if (crtl
->uses_only_leaf_regs
)
13150 int leaf_reg
= LEAF_REG_REMAP (reg
);
13151 if (leaf_reg
!= -1)
13152 reg
= (unsigned) leaf_reg
;
13156 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
13157 nregs
= REG_NREGS (rtl
);
13159 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
13164 dw_loc_descr_ref t
;
13166 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
13167 VAR_INIT_STATUS_INITIALIZED
);
13168 add_loc_descr (&loc_result
, t
);
13169 add_loc_descr_op_piece (&loc_result
, size
);
13175 /* Now onto stupid register sets in non contiguous locations. */
13177 gcc_assert (GET_CODE (regs
) == PARALLEL
);
13179 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
13182 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
13184 dw_loc_descr_ref t
;
13186 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
13187 VAR_INIT_STATUS_INITIALIZED
);
13188 add_loc_descr (&loc_result
, t
);
13189 add_loc_descr_op_piece (&loc_result
, size
);
13192 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13193 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13197 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
13199 /* Return a location descriptor that designates a constant i,
13200 as a compound operation from constant (i >> shift), constant shift
13203 static dw_loc_descr_ref
13204 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
13206 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
13207 add_loc_descr (&ret
, int_loc_descriptor (shift
));
13208 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
13212 /* Return a location descriptor that designates a constant. */
13214 static dw_loc_descr_ref
13215 int_loc_descriptor (HOST_WIDE_INT i
)
13217 enum dwarf_location_atom op
;
13219 /* Pick the smallest representation of a constant, rather than just
13220 defaulting to the LEB encoding. */
13223 int clz
= clz_hwi (i
);
13224 int ctz
= ctz_hwi (i
);
13226 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
13227 else if (i
<= 0xff)
13228 op
= DW_OP_const1u
;
13229 else if (i
<= 0xffff)
13230 op
= DW_OP_const2u
;
13231 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
13232 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
13233 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
13234 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
13235 while DW_OP_const4u is 5 bytes. */
13236 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
13237 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13238 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
13239 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
13240 while DW_OP_const4u is 5 bytes. */
13241 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
13243 else if (DWARF2_ADDR_SIZE
== 4 && i
> 0x7fffffff
13244 && size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
)
13247 /* As i >= 2**31, the double cast above will yield a negative number.
13248 Since wrapping is defined in DWARF expressions we can output big
13249 positive integers as small negative ones, regardless of the size
13252 Here, since the evaluator will handle 32-bit values and since i >=
13253 2**31, we know it's going to be interpreted as a negative literal:
13254 store it this way if we can do better than 5 bytes this way. */
13255 return int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
);
13257 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
13258 op
= DW_OP_const4u
;
13260 /* Past this point, i >= 0x100000000 and thus DW_OP_constu will take at
13261 least 6 bytes: see if we can do better before falling back to it. */
13262 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13263 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
13264 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes. */
13265 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
13266 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
13267 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
13268 >= HOST_BITS_PER_WIDE_INT
)
13269 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
13270 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes. */
13271 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
13272 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
13273 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
13274 && size_of_uleb128 (i
) > 6)
13275 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
13276 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
13283 op
= DW_OP_const1s
;
13284 else if (i
>= -0x8000)
13285 op
= DW_OP_const2s
;
13286 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
13288 if (size_of_int_loc_descriptor (i
) < 5)
13290 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
13291 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
13294 op
= DW_OP_const4s
;
13298 if (size_of_int_loc_descriptor (i
)
13299 < (unsigned long) 1 + size_of_sleb128 (i
))
13301 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
13302 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
13309 return new_loc_descr (op
, i
, 0);
13312 /* Likewise, for unsigned constants. */
13314 static dw_loc_descr_ref
13315 uint_loc_descriptor (unsigned HOST_WIDE_INT i
)
13317 const unsigned HOST_WIDE_INT max_int
= INTTYPE_MAXIMUM (HOST_WIDE_INT
);
13318 const unsigned HOST_WIDE_INT max_uint
13319 = INTTYPE_MAXIMUM (unsigned HOST_WIDE_INT
);
13321 /* If possible, use the clever signed constants handling. */
13323 return int_loc_descriptor ((HOST_WIDE_INT
) i
);
13325 /* Here, we are left with positive numbers that cannot be represented as
13326 HOST_WIDE_INT, i.e.:
13327 max (HOST_WIDE_INT) < i <= max (unsigned HOST_WIDE_INT)
13329 Using DW_OP_const4/8/./u operation to encode them consumes a lot of bytes
13330 whereas may be better to output a negative integer: thanks to integer
13331 wrapping, we know that:
13332 x = x - 2 ** DWARF2_ADDR_SIZE
13333 = x - 2 * (max (HOST_WIDE_INT) + 1)
13334 So numbers close to max (unsigned HOST_WIDE_INT) could be represented as
13335 small negative integers. Let's try that in cases it will clearly improve
13336 the encoding: there is no gain turning DW_OP_const4u into
13338 if (DWARF2_ADDR_SIZE
* 8 == HOST_BITS_PER_WIDE_INT
13339 && ((DWARF2_ADDR_SIZE
== 4 && i
> max_uint
- 0x8000)
13340 || (DWARF2_ADDR_SIZE
== 8 && i
> max_uint
- 0x80000000)))
13342 const unsigned HOST_WIDE_INT first_shift
= i
- max_int
- 1;
13344 /* Now, -1 < first_shift <= max (HOST_WIDE_INT)
13345 i.e. 0 <= first_shift <= max (HOST_WIDE_INT). */
13346 const HOST_WIDE_INT second_shift
13347 = (HOST_WIDE_INT
) first_shift
- (HOST_WIDE_INT
) max_int
- 1;
13349 /* So we finally have:
13350 -max (HOST_WIDE_INT) - 1 <= second_shift <= -1.
13351 i.e. min (HOST_WIDE_INT) <= second_shift < 0. */
13352 return int_loc_descriptor (second_shift
);
13355 /* Last chance: fallback to a simple constant operation. */
13356 return new_loc_descr
13357 ((HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
13363 /* Generate and return a location description that computes the unsigned
13364 comparison of the two stack top entries (a OP b where b is the top-most
13365 entry and a is the second one). The KIND of comparison can be LT_EXPR,
13366 LE_EXPR, GT_EXPR or GE_EXPR. */
13368 static dw_loc_descr_ref
13369 uint_comparison_loc_list (enum tree_code kind
)
13371 enum dwarf_location_atom op
, flip_op
;
13372 dw_loc_descr_ref ret
, bra_node
, jmp_node
, tmp
;
13389 gcc_unreachable ();
13392 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
13393 jmp_node
= new_loc_descr (DW_OP_skip
, 0, 0);
13395 /* Until DWARFv4, operations all work on signed integers. It is nevertheless
13396 possible to perform unsigned comparisons: we just have to distinguish
13399 1. when a and b have the same sign (as signed integers); then we should
13400 return: a OP(signed) b;
13402 2. when a is a negative signed integer while b is a positive one, then a
13403 is a greater unsigned integer than b; likewise when a and b's roles
13406 So first, compare the sign of the two operands. */
13407 ret
= new_loc_descr (DW_OP_over
, 0, 0);
13408 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
13409 add_loc_descr (&ret
, new_loc_descr (DW_OP_xor
, 0, 0));
13410 /* If they have different signs (i.e. they have different sign bits), then
13411 the stack top value has now the sign bit set and thus it's smaller than
13413 add_loc_descr (&ret
, new_loc_descr (DW_OP_lit0
, 0, 0));
13414 add_loc_descr (&ret
, new_loc_descr (DW_OP_lt
, 0, 0));
13415 add_loc_descr (&ret
, bra_node
);
13417 /* We are in case 1. At this point, we know both operands have the same
13418 sign, to it's safe to use the built-in signed comparison. */
13419 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
13420 add_loc_descr (&ret
, jmp_node
);
13422 /* We are in case 2. Here, we know both operands do not have the same sign,
13423 so we have to flip the signed comparison. */
13424 flip_op
= (kind
== LT_EXPR
|| kind
== LE_EXPR
) ? DW_OP_gt
: DW_OP_lt
;
13425 tmp
= new_loc_descr (flip_op
, 0, 0);
13426 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13427 bra_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
13428 add_loc_descr (&ret
, tmp
);
13430 /* This dummy operation is necessary to make the two branches join. */
13431 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
13432 jmp_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13433 jmp_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
13434 add_loc_descr (&ret
, tmp
);
13439 /* Likewise, but takes the location description lists (might be destructive on
13440 them). Return NULL if either is NULL or if concatenation fails. */
13442 static dw_loc_list_ref
13443 loc_list_from_uint_comparison (dw_loc_list_ref left
, dw_loc_list_ref right
,
13444 enum tree_code kind
)
13446 if (left
== NULL
|| right
== NULL
)
13449 add_loc_list (&left
, right
);
13453 add_loc_descr_to_each (left
, uint_comparison_loc_list (kind
));
13457 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
13458 without actually allocating it. */
13460 static unsigned long
13461 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
13463 return size_of_int_loc_descriptor (i
>> shift
)
13464 + size_of_int_loc_descriptor (shift
)
13468 /* Return size_of_locs (int_loc_descriptor (i)) without
13469 actually allocating it. */
13471 static unsigned long
13472 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
13481 else if (i
<= 0xff)
13483 else if (i
<= 0xffff)
13487 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
13488 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
13489 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13491 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13492 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
13493 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13495 else if (DWARF2_ADDR_SIZE
== 4 && i
> 0x7fffffff
13496 && size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
)
13498 return size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
);
13499 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
13501 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
13502 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13503 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
13504 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13506 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
13507 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
13508 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13510 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
13511 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
13513 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13522 else if (i
>= -0x8000)
13524 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
13526 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
13528 s
= size_of_int_loc_descriptor (-i
) + 1;
13536 unsigned long r
= 1 + size_of_sleb128 (i
);
13537 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
13539 s
= size_of_int_loc_descriptor (-i
) + 1;
13548 /* Return loc description representing "address" of integer value.
13549 This can appear only as toplevel expression. */
13551 static dw_loc_descr_ref
13552 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
13555 dw_loc_descr_ref loc_result
= NULL
;
13557 if (!(dwarf_version
>= 4 || !dwarf_strict
))
13560 litsize
= size_of_int_loc_descriptor (i
);
13561 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13562 is more compact. For DW_OP_stack_value we need:
13563 litsize + 1 (DW_OP_stack_value)
13564 and for DW_OP_implicit_value:
13565 1 (DW_OP_implicit_value) + 1 (length) + size. */
13566 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
13568 loc_result
= int_loc_descriptor (i
);
13569 add_loc_descr (&loc_result
,
13570 new_loc_descr (DW_OP_stack_value
, 0, 0));
13574 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13576 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13577 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
13581 /* Return a location descriptor that designates a base+offset location. */
13583 static dw_loc_descr_ref
13584 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
13585 enum var_init_status initialized
)
13587 unsigned int regno
;
13588 dw_loc_descr_ref result
;
13589 dw_fde_ref fde
= cfun
->fde
;
13591 /* We only use "frame base" when we're sure we're talking about the
13592 post-prologue local stack frame. We do this by *not* running
13593 register elimination until this point, and recognizing the special
13594 argument pointer and soft frame pointer rtx's. */
13595 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
13597 rtx elim
= (ira_use_lra_p
13598 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
13599 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
13603 if (GET_CODE (elim
) == PLUS
)
13605 offset
+= INTVAL (XEXP (elim
, 1));
13606 elim
= XEXP (elim
, 0);
13608 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13609 && (elim
== hard_frame_pointer_rtx
13610 || elim
== stack_pointer_rtx
))
13611 || elim
== (frame_pointer_needed
13612 ? hard_frame_pointer_rtx
13613 : stack_pointer_rtx
));
13615 /* If drap register is used to align stack, use frame
13616 pointer + offset to access stack variables. If stack
13617 is aligned without drap, use stack pointer + offset to
13618 access stack variables. */
13619 if (crtl
->stack_realign_tried
13620 && reg
== frame_pointer_rtx
)
13623 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
13624 ? HARD_FRAME_POINTER_REGNUM
13626 return new_reg_loc_descr (base_reg
, offset
);
13629 gcc_assert (frame_pointer_fb_offset_valid
);
13630 offset
+= frame_pointer_fb_offset
;
13631 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
13635 regno
= REGNO (reg
);
13636 #ifdef LEAF_REG_REMAP
13637 if (crtl
->uses_only_leaf_regs
)
13639 int leaf_reg
= LEAF_REG_REMAP (regno
);
13640 if (leaf_reg
!= -1)
13641 regno
= (unsigned) leaf_reg
;
13644 regno
= DWARF_FRAME_REGNUM (regno
);
13646 if (!optimize
&& fde
13647 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
13649 /* Use cfa+offset to represent the location of arguments passed
13650 on the stack when drap is used to align stack.
13651 Only do this when not optimizing, for optimized code var-tracking
13652 is supposed to track where the arguments live and the register
13653 used as vdrap or drap in some spot might be used for something
13654 else in other part of the routine. */
13655 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
13659 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
13662 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
13664 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13665 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13670 /* Return true if this RTL expression describes a base+offset calculation. */
13673 is_based_loc (const_rtx rtl
)
13675 return (GET_CODE (rtl
) == PLUS
13676 && ((REG_P (XEXP (rtl
, 0))
13677 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
13678 && CONST_INT_P (XEXP (rtl
, 1)))));
13681 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13684 static dw_loc_descr_ref
13685 tls_mem_loc_descriptor (rtx mem
)
13688 dw_loc_descr_ref loc_result
;
13690 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
13693 base
= get_base_address (MEM_EXPR (mem
));
13696 || !DECL_THREAD_LOCAL_P (base
))
13699 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1, NULL
);
13700 if (loc_result
== NULL
)
13703 if (MEM_OFFSET (mem
))
13704 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
13709 /* Output debug info about reason why we failed to expand expression as dwarf
13713 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
13715 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
13717 fprintf (dump_file
, "Failed to expand as dwarf: ");
13719 print_generic_expr (dump_file
, expr
, dump_flags
);
13722 fprintf (dump_file
, "\n");
13723 print_rtl (dump_file
, rtl
);
13725 fprintf (dump_file
, "\nReason: %s\n", reason
);
13729 /* Helper function for const_ok_for_output. */
13732 const_ok_for_output_1 (rtx rtl
)
13734 if (targetm
.const_not_ok_for_debug_p (rtl
))
13736 if (GET_CODE (rtl
) != UNSPEC
)
13738 expansion_failed (NULL_TREE
, rtl
,
13739 "Expression rejected for debug by the backend.\n");
13743 /* If delegitimize_address couldn't do anything with the UNSPEC, and
13744 the target hook doesn't explicitly allow it in debug info, 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 /* FIXME: Refer to PR60655. It is possible for simplification
13772 of rtl expressions in var tracking to produce such expressions.
13773 We should really identify / validate expressions
13774 enclosed in CONST that can be handled by assemblers on various
13775 targets and only handle legitimate cases here. */
13776 switch (GET_CODE (rtl
))
13787 if (CONSTANT_POOL_ADDRESS_P (rtl
))
13790 get_pool_constant_mark (rtl
, &marked
);
13791 /* If all references to this pool constant were optimized away,
13792 it was not output and thus we can't represent it. */
13795 expansion_failed (NULL_TREE
, rtl
,
13796 "Constant was removed from constant pool.\n");
13801 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
13804 /* Avoid references to external symbols in debug info, on several targets
13805 the linker might even refuse to link when linking a shared library,
13806 and in many other cases the relocations for .debug_info/.debug_loc are
13807 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13808 to be defined within the same shared library or executable are fine. */
13809 if (SYMBOL_REF_EXTERNAL_P (rtl
))
13811 tree decl
= SYMBOL_REF_DECL (rtl
);
13813 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
13815 expansion_failed (NULL_TREE
, rtl
,
13816 "Symbol not defined in current TU.\n");
13824 /* Return true if constant RTL can be emitted in DW_OP_addr or
13825 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13826 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13829 const_ok_for_output (rtx rtl
)
13831 if (GET_CODE (rtl
) == SYMBOL_REF
)
13832 return const_ok_for_output_1 (rtl
);
13834 if (GET_CODE (rtl
) == CONST
)
13836 subrtx_var_iterator::array_type array
;
13837 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 0), ALL
)
13838 if (!const_ok_for_output_1 (*iter
))
13846 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
13847 if possible, NULL otherwise. */
13850 base_type_for_mode (machine_mode mode
, bool unsignedp
)
13852 dw_die_ref type_die
;
13853 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
13857 switch (TREE_CODE (type
))
13865 type_die
= lookup_type_die (type
);
13867 type_die
= modified_type_die (type
, TYPE_UNQUALIFIED
, false,
13869 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
13874 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
13875 type matching MODE, or, if MODE is narrower than or as wide as
13876 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
13879 static dw_loc_descr_ref
13880 convert_descriptor_to_mode (scalar_int_mode mode
, dw_loc_descr_ref op
)
13882 machine_mode outer_mode
= mode
;
13883 dw_die_ref type_die
;
13884 dw_loc_descr_ref cvt
;
13886 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
13888 add_loc_descr (&op
, new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0));
13891 type_die
= base_type_for_mode (outer_mode
, 1);
13892 if (type_die
== NULL
)
13894 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
13895 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13896 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13897 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13898 add_loc_descr (&op
, cvt
);
13902 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
13904 static dw_loc_descr_ref
13905 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
13906 dw_loc_descr_ref op1
)
13908 dw_loc_descr_ref ret
= op0
;
13909 add_loc_descr (&ret
, op1
);
13910 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
13911 if (STORE_FLAG_VALUE
!= 1)
13913 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
13914 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
13919 /* Subroutine of scompare_loc_descriptor for the case in which we're
13920 comparing two scalar integer operands OP0 and OP1 that have mode OP_MODE,
13921 and in which OP_MODE is bigger than DWARF2_ADDR_SIZE. */
13923 static dw_loc_descr_ref
13924 scompare_loc_descriptor_wide (enum dwarf_location_atom op
,
13925 scalar_int_mode op_mode
,
13926 dw_loc_descr_ref op0
, dw_loc_descr_ref op1
)
13928 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
13929 dw_loc_descr_ref cvt
;
13931 if (type_die
== NULL
)
13933 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
13934 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13935 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13936 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13937 add_loc_descr (&op0
, cvt
);
13938 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
13939 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13940 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13941 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13942 add_loc_descr (&op1
, cvt
);
13943 return compare_loc_descriptor (op
, op0
, op1
);
13946 /* Subroutine of scompare_loc_descriptor for the case in which we're
13947 comparing two scalar integer operands OP0 and OP1 that have mode OP_MODE,
13948 and in which OP_MODE is smaller than DWARF2_ADDR_SIZE. */
13950 static dw_loc_descr_ref
13951 scompare_loc_descriptor_narrow (enum dwarf_location_atom op
, rtx rtl
,
13952 scalar_int_mode op_mode
,
13953 dw_loc_descr_ref op0
, dw_loc_descr_ref op1
)
13955 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
13956 /* For eq/ne, if the operands are known to be zero-extended,
13957 there is no need to do the fancy shifting up. */
13958 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
13960 dw_loc_descr_ref last0
, last1
;
13961 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
13963 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
13965 /* deref_size zero extends, and for constants we can check
13966 whether they are zero extended or not. */
13967 if (((last0
->dw_loc_opc
== DW_OP_deref_size
13968 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
13969 || (CONST_INT_P (XEXP (rtl
, 0))
13970 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
13971 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
13972 && ((last1
->dw_loc_opc
== DW_OP_deref_size
13973 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
13974 || (CONST_INT_P (XEXP (rtl
, 1))
13975 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
13976 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
13977 return compare_loc_descriptor (op
, op0
, op1
);
13979 /* EQ/NE comparison against constant in narrower type than
13980 DWARF2_ADDR_SIZE can be performed either as
13981 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
13984 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
13985 DW_OP_{eq,ne}. Pick whatever is shorter. */
13986 if (CONST_INT_P (XEXP (rtl
, 1))
13987 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
13988 && (size_of_int_loc_descriptor (shift
) + 1
13989 + size_of_int_loc_descriptor (UINTVAL (XEXP (rtl
, 1)) << shift
)
13990 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
13991 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
13992 & GET_MODE_MASK (op_mode
))))
13994 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
13995 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
13996 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
13997 & GET_MODE_MASK (op_mode
));
13998 return compare_loc_descriptor (op
, op0
, op1
);
14001 add_loc_descr (&op0
, int_loc_descriptor (shift
));
14002 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
14003 if (CONST_INT_P (XEXP (rtl
, 1)))
14004 op1
= int_loc_descriptor (UINTVAL (XEXP (rtl
, 1)) << shift
);
14007 add_loc_descr (&op1
, int_loc_descriptor (shift
));
14008 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
14010 return compare_loc_descriptor (op
, op0
, op1
);
14013 /* Return location descriptor for unsigned comparison OP RTL. */
14015 static dw_loc_descr_ref
14016 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
14017 machine_mode mem_mode
)
14019 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
14020 dw_loc_descr_ref op0
, op1
;
14022 if (op_mode
== VOIDmode
)
14023 op_mode
= GET_MODE (XEXP (rtl
, 1));
14024 if (op_mode
== VOIDmode
)
14027 scalar_int_mode int_op_mode
;
14029 && dwarf_version
< 5
14030 && (!is_a
<scalar_int_mode
> (op_mode
, &int_op_mode
)
14031 || GET_MODE_SIZE (int_op_mode
) > DWARF2_ADDR_SIZE
))
14034 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
14035 VAR_INIT_STATUS_INITIALIZED
);
14036 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
14037 VAR_INIT_STATUS_INITIALIZED
);
14039 if (op0
== NULL
|| op1
== NULL
)
14042 if (is_a
<scalar_int_mode
> (op_mode
, &int_op_mode
))
14044 if (GET_MODE_SIZE (int_op_mode
) < DWARF2_ADDR_SIZE
)
14045 return scompare_loc_descriptor_narrow (op
, rtl
, int_op_mode
, op0
, op1
);
14047 if (GET_MODE_SIZE (int_op_mode
) > DWARF2_ADDR_SIZE
)
14048 return scompare_loc_descriptor_wide (op
, int_op_mode
, op0
, op1
);
14050 return compare_loc_descriptor (op
, op0
, op1
);
14053 /* Return location descriptor for unsigned comparison OP RTL. */
14055 static dw_loc_descr_ref
14056 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
14057 machine_mode mem_mode
)
14059 dw_loc_descr_ref op0
, op1
;
14061 machine_mode test_op_mode
= GET_MODE (XEXP (rtl
, 0));
14062 if (test_op_mode
== VOIDmode
)
14063 test_op_mode
= GET_MODE (XEXP (rtl
, 1));
14065 scalar_int_mode op_mode
;
14066 if (!is_a
<scalar_int_mode
> (test_op_mode
, &op_mode
))
14070 && dwarf_version
< 5
14071 && GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
14074 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
14075 VAR_INIT_STATUS_INITIALIZED
);
14076 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
14077 VAR_INIT_STATUS_INITIALIZED
);
14079 if (op0
== NULL
|| op1
== NULL
)
14082 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
14084 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
14085 dw_loc_descr_ref last0
, last1
;
14086 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
14088 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
14090 if (CONST_INT_P (XEXP (rtl
, 0)))
14091 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
14092 /* deref_size zero extends, so no need to mask it again. */
14093 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
14094 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
14096 add_loc_descr (&op0
, int_loc_descriptor (mask
));
14097 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
14099 if (CONST_INT_P (XEXP (rtl
, 1)))
14100 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
14101 /* deref_size zero extends, so no need to mask it again. */
14102 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
14103 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
14105 add_loc_descr (&op1
, int_loc_descriptor (mask
));
14106 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
14109 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
14111 HOST_WIDE_INT bias
= 1;
14112 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
14113 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14114 if (CONST_INT_P (XEXP (rtl
, 1)))
14115 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
14116 + INTVAL (XEXP (rtl
, 1)));
14118 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
14121 return compare_loc_descriptor (op
, op0
, op1
);
14124 /* Return location descriptor for {U,S}{MIN,MAX}. */
14126 static dw_loc_descr_ref
14127 minmax_loc_descriptor (rtx rtl
, machine_mode mode
,
14128 machine_mode mem_mode
)
14130 enum dwarf_location_atom op
;
14131 dw_loc_descr_ref op0
, op1
, ret
;
14132 dw_loc_descr_ref bra_node
, drop_node
;
14134 scalar_int_mode int_mode
;
14136 && dwarf_version
< 5
14137 && (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
14138 || GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
))
14141 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14142 VAR_INIT_STATUS_INITIALIZED
);
14143 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
14144 VAR_INIT_STATUS_INITIALIZED
);
14146 if (op0
== NULL
|| op1
== NULL
)
14149 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
14150 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
14151 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
14152 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
14154 /* Checked by the caller. */
14155 int_mode
= as_a
<scalar_int_mode
> (mode
);
14156 if (GET_MODE_SIZE (int_mode
) < DWARF2_ADDR_SIZE
)
14158 HOST_WIDE_INT mask
= GET_MODE_MASK (int_mode
);
14159 add_loc_descr (&op0
, int_loc_descriptor (mask
));
14160 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
14161 add_loc_descr (&op1
, int_loc_descriptor (mask
));
14162 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
14164 else if (GET_MODE_SIZE (int_mode
) == DWARF2_ADDR_SIZE
)
14166 HOST_WIDE_INT bias
= 1;
14167 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
14168 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14169 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14172 else if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
14173 && GET_MODE_SIZE (int_mode
) < DWARF2_ADDR_SIZE
)
14175 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (int_mode
)) * BITS_PER_UNIT
;
14176 add_loc_descr (&op0
, int_loc_descriptor (shift
));
14177 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
14178 add_loc_descr (&op1
, int_loc_descriptor (shift
));
14179 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
14181 else if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
14182 && GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
14184 dw_die_ref type_die
= base_type_for_mode (int_mode
, 0);
14185 dw_loc_descr_ref cvt
;
14186 if (type_die
== NULL
)
14188 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14189 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14190 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14191 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14192 add_loc_descr (&op0
, cvt
);
14193 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14194 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14195 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14196 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14197 add_loc_descr (&op1
, cvt
);
14200 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
14205 add_loc_descr (&ret
, op1
);
14206 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
14207 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14208 add_loc_descr (&ret
, bra_node
);
14209 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14210 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
14211 add_loc_descr (&ret
, drop_node
);
14212 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14213 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
14214 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
14215 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
14216 && GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
14217 ret
= convert_descriptor_to_mode (int_mode
, ret
);
14221 /* Helper function for mem_loc_descriptor. Perform OP binary op,
14222 but after converting arguments to type_die, afterwards
14223 convert back to unsigned. */
14225 static dw_loc_descr_ref
14226 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
14227 scalar_int_mode mode
, machine_mode mem_mode
)
14229 dw_loc_descr_ref cvt
, op0
, op1
;
14231 if (type_die
== NULL
)
14233 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14234 VAR_INIT_STATUS_INITIALIZED
);
14235 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
14236 VAR_INIT_STATUS_INITIALIZED
);
14237 if (op0
== NULL
|| op1
== NULL
)
14239 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14240 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14241 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14242 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14243 add_loc_descr (&op0
, cvt
);
14244 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14245 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14246 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14247 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14248 add_loc_descr (&op1
, cvt
);
14249 add_loc_descr (&op0
, op1
);
14250 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
14251 return convert_descriptor_to_mode (mode
, op0
);
14254 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
14255 const0 is DW_OP_lit0 or corresponding typed constant,
14256 const1 is DW_OP_lit1 or corresponding typed constant
14257 and constMSB is constant with just the MSB bit set
14259 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
14260 L1: const0 DW_OP_swap
14261 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
14262 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14267 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
14268 L1: const0 DW_OP_swap
14269 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
14270 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14275 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
14276 L1: const1 DW_OP_swap
14277 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
14278 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14282 static dw_loc_descr_ref
14283 clz_loc_descriptor (rtx rtl
, scalar_int_mode mode
,
14284 machine_mode mem_mode
)
14286 dw_loc_descr_ref op0
, ret
, tmp
;
14287 HOST_WIDE_INT valv
;
14288 dw_loc_descr_ref l1jump
, l1label
;
14289 dw_loc_descr_ref l2jump
, l2label
;
14290 dw_loc_descr_ref l3jump
, l3label
;
14291 dw_loc_descr_ref l4jump
, l4label
;
14294 if (GET_MODE (XEXP (rtl
, 0)) != mode
)
14297 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14298 VAR_INIT_STATUS_INITIALIZED
);
14302 if (GET_CODE (rtl
) == CLZ
)
14304 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
14305 valv
= GET_MODE_BITSIZE (mode
);
14307 else if (GET_CODE (rtl
) == FFS
)
14309 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
14310 valv
= GET_MODE_BITSIZE (mode
);
14311 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
14312 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14313 add_loc_descr (&ret
, l1jump
);
14314 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
14315 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
14316 VAR_INIT_STATUS_INITIALIZED
);
14319 add_loc_descr (&ret
, tmp
);
14320 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14321 add_loc_descr (&ret
, l4jump
);
14322 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
14323 ? const1_rtx
: const0_rtx
,
14325 VAR_INIT_STATUS_INITIALIZED
);
14326 if (l1label
== NULL
)
14328 add_loc_descr (&ret
, l1label
);
14329 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14330 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
14331 add_loc_descr (&ret
, l2label
);
14332 if (GET_CODE (rtl
) != CLZ
)
14334 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
14335 msb
= GEN_INT (HOST_WIDE_INT_1U
14336 << (GET_MODE_BITSIZE (mode
) - 1));
14338 msb
= immed_wide_int_const
14339 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode
) - 1,
14340 GET_MODE_PRECISION (mode
)), mode
);
14341 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
14342 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
14343 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
14344 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
14346 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
14347 VAR_INIT_STATUS_INITIALIZED
);
14350 add_loc_descr (&ret
, tmp
);
14351 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
14352 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14353 add_loc_descr (&ret
, l3jump
);
14354 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
14355 VAR_INIT_STATUS_INITIALIZED
);
14358 add_loc_descr (&ret
, tmp
);
14359 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
14360 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
14361 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14362 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
14363 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14364 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14365 add_loc_descr (&ret
, l2jump
);
14366 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
14367 add_loc_descr (&ret
, l3label
);
14368 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
14369 add_loc_descr (&ret
, l4label
);
14370 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14371 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
14372 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14373 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
14374 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14375 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
14376 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14377 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
14381 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
14382 const1 is DW_OP_lit1 or corresponding typed constant):
14384 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
14385 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
14389 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
14390 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
14393 static dw_loc_descr_ref
14394 popcount_loc_descriptor (rtx rtl
, scalar_int_mode mode
,
14395 machine_mode mem_mode
)
14397 dw_loc_descr_ref op0
, ret
, tmp
;
14398 dw_loc_descr_ref l1jump
, l1label
;
14399 dw_loc_descr_ref l2jump
, l2label
;
14401 if (GET_MODE (XEXP (rtl
, 0)) != mode
)
14404 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14405 VAR_INIT_STATUS_INITIALIZED
);
14409 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
14410 VAR_INIT_STATUS_INITIALIZED
);
14413 add_loc_descr (&ret
, tmp
);
14414 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14415 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
14416 add_loc_descr (&ret
, l1label
);
14417 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14418 add_loc_descr (&ret
, l2jump
);
14419 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
14420 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
14421 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
14422 VAR_INIT_STATUS_INITIALIZED
);
14425 add_loc_descr (&ret
, tmp
);
14426 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
14427 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
14428 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
14429 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14430 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
14431 VAR_INIT_STATUS_INITIALIZED
);
14432 add_loc_descr (&ret
, tmp
);
14433 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
14434 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14435 add_loc_descr (&ret
, l1jump
);
14436 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
14437 add_loc_descr (&ret
, l2label
);
14438 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14439 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
14440 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14441 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
14445 /* BSWAP (constS is initial shift count, either 56 or 24):
14447 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
14448 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
14449 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
14450 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
14451 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
14453 static dw_loc_descr_ref
14454 bswap_loc_descriptor (rtx rtl
, scalar_int_mode mode
,
14455 machine_mode mem_mode
)
14457 dw_loc_descr_ref op0
, ret
, tmp
;
14458 dw_loc_descr_ref l1jump
, l1label
;
14459 dw_loc_descr_ref l2jump
, l2label
;
14461 if (BITS_PER_UNIT
!= 8
14462 || (GET_MODE_BITSIZE (mode
) != 32
14463 && GET_MODE_BITSIZE (mode
) != 64))
14466 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14467 VAR_INIT_STATUS_INITIALIZED
);
14472 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
14474 VAR_INIT_STATUS_INITIALIZED
);
14477 add_loc_descr (&ret
, tmp
);
14478 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
14479 VAR_INIT_STATUS_INITIALIZED
);
14482 add_loc_descr (&ret
, tmp
);
14483 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
14484 add_loc_descr (&ret
, l1label
);
14485 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
14487 VAR_INIT_STATUS_INITIALIZED
);
14488 add_loc_descr (&ret
, tmp
);
14489 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
14490 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14491 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
14492 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
14493 VAR_INIT_STATUS_INITIALIZED
);
14496 add_loc_descr (&ret
, tmp
);
14497 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
14498 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
14499 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
14500 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
14501 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14502 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
14503 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
14504 VAR_INIT_STATUS_INITIALIZED
);
14505 add_loc_descr (&ret
, tmp
);
14506 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
14507 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14508 add_loc_descr (&ret
, l2jump
);
14509 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
14510 VAR_INIT_STATUS_INITIALIZED
);
14511 add_loc_descr (&ret
, tmp
);
14512 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14513 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14514 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14515 add_loc_descr (&ret
, l1jump
);
14516 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
14517 add_loc_descr (&ret
, l2label
);
14518 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14519 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
14520 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14521 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
14522 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14523 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
14527 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
14528 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
14529 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
14530 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
14532 ROTATERT is similar:
14533 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
14534 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
14535 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
14537 static dw_loc_descr_ref
14538 rotate_loc_descriptor (rtx rtl
, scalar_int_mode mode
,
14539 machine_mode mem_mode
)
14541 rtx rtlop1
= XEXP (rtl
, 1);
14542 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
14545 if (is_narrower_int_mode (GET_MODE (rtlop1
), mode
))
14546 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
14547 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14548 VAR_INIT_STATUS_INITIALIZED
);
14549 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
14550 VAR_INIT_STATUS_INITIALIZED
);
14551 if (op0
== NULL
|| op1
== NULL
)
14553 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
14554 for (i
= 0; i
< 2; i
++)
14556 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
14557 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
14559 VAR_INIT_STATUS_INITIALIZED
);
14560 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
14561 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
14563 : HOST_BITS_PER_WIDE_INT
== 64
14564 ? DW_OP_const8u
: DW_OP_constu
,
14565 GET_MODE_MASK (mode
), 0);
14568 if (mask
[i
] == NULL
)
14570 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
14573 add_loc_descr (&ret
, op1
);
14574 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
14575 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
14576 if (GET_CODE (rtl
) == ROTATERT
)
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_shl
, 0, 0));
14583 if (mask
[0] != NULL
)
14584 add_loc_descr (&ret
, mask
[0]);
14585 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
14586 if (mask
[1] != NULL
)
14588 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14589 add_loc_descr (&ret
, mask
[1]);
14590 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14592 if (GET_CODE (rtl
) == ROTATE
)
14594 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
14595 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
14596 GET_MODE_BITSIZE (mode
), 0));
14598 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
14599 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
14603 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
14604 for DEBUG_PARAMETER_REF RTL. */
14606 static dw_loc_descr_ref
14607 parameter_ref_descriptor (rtx rtl
)
14609 dw_loc_descr_ref ret
;
14614 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
14615 /* With LTO during LTRANS we get the late DIE that refers to the early
14616 DIE, thus we add another indirection here. This seems to confuse
14617 gdb enough to make gcc.dg/guality/pr68860-1.c FAIL with LTO. */
14618 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
14619 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
14622 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14623 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
14624 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14628 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
14629 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
14634 /* The following routine converts the RTL for a variable or parameter
14635 (resident in memory) into an equivalent Dwarf representation of a
14636 mechanism for getting the address of that same variable onto the top of a
14637 hypothetical "address evaluation" stack.
14639 When creating memory location descriptors, we are effectively transforming
14640 the RTL for a memory-resident object into its Dwarf postfix expression
14641 equivalent. This routine recursively descends an RTL tree, turning
14642 it into Dwarf postfix code as it goes.
14644 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
14646 MEM_MODE is the mode of the memory reference, needed to handle some
14647 autoincrement addressing modes.
14649 Return 0 if we can't represent the location. */
14652 mem_loc_descriptor (rtx rtl
, machine_mode mode
,
14653 machine_mode mem_mode
,
14654 enum var_init_status initialized
)
14656 dw_loc_descr_ref mem_loc_result
= NULL
;
14657 enum dwarf_location_atom op
;
14658 dw_loc_descr_ref op0
, op1
;
14659 rtx inner
= NULL_RTX
;
14661 if (mode
== VOIDmode
)
14662 mode
= GET_MODE (rtl
);
14664 /* Note that for a dynamically sized array, the location we will generate a
14665 description of here will be the lowest numbered location which is
14666 actually within the array. That's *not* necessarily the same as the
14667 zeroth element of the array. */
14669 rtl
= targetm
.delegitimize_address (rtl
);
14671 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
14674 scalar_int_mode int_mode
, inner_mode
, op1_mode
;
14675 switch (GET_CODE (rtl
))
14680 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
14683 /* The case of a subreg may arise when we have a local (register)
14684 variable or a formal (register) parameter which doesn't quite fill
14685 up an entire register. For now, just assume that it is
14686 legitimate to make the Dwarf info refer to the whole register which
14687 contains the given subreg. */
14688 if (!subreg_lowpart_p (rtl
))
14690 inner
= SUBREG_REG (rtl
);
14693 if (inner
== NULL_RTX
)
14694 inner
= XEXP (rtl
, 0);
14695 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
14696 && is_a
<scalar_int_mode
> (GET_MODE (inner
), &inner_mode
)
14697 && (GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
14698 #ifdef POINTERS_EXTEND_UNSIGNED
14699 || (int_mode
== Pmode
&& mem_mode
!= VOIDmode
)
14702 && GET_MODE_SIZE (inner_mode
) <= DWARF2_ADDR_SIZE
)
14704 mem_loc_result
= mem_loc_descriptor (inner
,
14706 mem_mode
, initialized
);
14709 if (dwarf_strict
&& dwarf_version
< 5)
14711 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
14712 && is_a
<scalar_int_mode
> (GET_MODE (inner
), &inner_mode
)
14713 ? GET_MODE_SIZE (int_mode
) <= GET_MODE_SIZE (inner_mode
)
14714 : GET_MODE_SIZE (mode
) == GET_MODE_SIZE (GET_MODE (inner
)))
14716 dw_die_ref type_die
;
14717 dw_loc_descr_ref cvt
;
14719 mem_loc_result
= mem_loc_descriptor (inner
,
14721 mem_mode
, initialized
);
14722 if (mem_loc_result
== NULL
)
14724 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
14725 if (type_die
== NULL
)
14727 mem_loc_result
= NULL
;
14730 if (GET_MODE_SIZE (mode
)
14731 != GET_MODE_SIZE (GET_MODE (inner
)))
14732 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14734 cvt
= new_loc_descr (dwarf_OP (DW_OP_reinterpret
), 0, 0);
14735 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14736 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14737 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14738 add_loc_descr (&mem_loc_result
, cvt
);
14739 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
14740 && GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
)
14742 /* Convert it to untyped afterwards. */
14743 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14744 add_loc_descr (&mem_loc_result
, cvt
);
14750 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
14751 || (GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
14752 && rtl
!= arg_pointer_rtx
14753 && rtl
!= frame_pointer_rtx
14754 #ifdef POINTERS_EXTEND_UNSIGNED
14755 && (int_mode
!= Pmode
|| mem_mode
== VOIDmode
)
14759 dw_die_ref type_die
;
14760 unsigned int dbx_regnum
;
14762 if (dwarf_strict
&& dwarf_version
< 5)
14764 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
14766 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
14767 if (type_die
== NULL
)
14770 dbx_regnum
= dbx_reg_number (rtl
);
14771 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
14773 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_regval_type
),
14775 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
14776 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
14777 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
14780 /* Whenever a register number forms a part of the description of the
14781 method for calculating the (dynamic) address of a memory resident
14782 object, DWARF rules require the register number be referred to as
14783 a "base register". This distinction is not based in any way upon
14784 what category of register the hardware believes the given register
14785 belongs to. This is strictly DWARF terminology we're dealing with
14786 here. Note that in cases where the location of a memory-resident
14787 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
14788 OP_CONST (0)) the actual DWARF location descriptor that we generate
14789 may just be OP_BASEREG (basereg). This may look deceptively like
14790 the object in question was allocated to a register (rather than in
14791 memory) so DWARF consumers need to be aware of the subtle
14792 distinction between OP_REG and OP_BASEREG. */
14793 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
14794 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
14795 else if (stack_realign_drap
14797 && crtl
->args
.internal_arg_pointer
== rtl
14798 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
14800 /* If RTL is internal_arg_pointer, which has been optimized
14801 out, use DRAP instead. */
14802 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
14803 VAR_INIT_STATUS_INITIALIZED
);
14809 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
14810 || !is_a
<scalar_int_mode
> (GET_MODE (XEXP (rtl
, 0)), &inner_mode
))
14812 op0
= mem_loc_descriptor (XEXP (rtl
, 0), inner_mode
,
14813 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
14816 else if (GET_CODE (rtl
) == ZERO_EXTEND
14817 && GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
14818 && GET_MODE_BITSIZE (inner_mode
) < HOST_BITS_PER_WIDE_INT
14819 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
14820 to expand zero extend as two shifts instead of
14822 && GET_MODE_SIZE (inner_mode
) <= 4)
14824 mem_loc_result
= op0
;
14825 add_loc_descr (&mem_loc_result
,
14826 int_loc_descriptor (GET_MODE_MASK (inner_mode
)));
14827 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
14829 else if (GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
)
14831 int shift
= DWARF2_ADDR_SIZE
- GET_MODE_SIZE (inner_mode
);
14832 shift
*= BITS_PER_UNIT
;
14833 if (GET_CODE (rtl
) == SIGN_EXTEND
)
14837 mem_loc_result
= op0
;
14838 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
14839 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
14840 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
14841 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
14843 else if (!dwarf_strict
|| dwarf_version
>= 5)
14845 dw_die_ref type_die1
, type_die2
;
14846 dw_loc_descr_ref cvt
;
14848 type_die1
= base_type_for_mode (inner_mode
,
14849 GET_CODE (rtl
) == ZERO_EXTEND
);
14850 if (type_die1
== NULL
)
14852 type_die2
= base_type_for_mode (int_mode
, 1);
14853 if (type_die2
== NULL
)
14855 mem_loc_result
= op0
;
14856 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14857 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14858 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
14859 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14860 add_loc_descr (&mem_loc_result
, cvt
);
14861 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14862 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14863 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
14864 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14865 add_loc_descr (&mem_loc_result
, cvt
);
14871 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
14872 if (new_rtl
!= rtl
)
14874 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
14876 if (mem_loc_result
!= NULL
)
14877 return mem_loc_result
;
14880 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
14881 get_address_mode (rtl
), mode
,
14882 VAR_INIT_STATUS_INITIALIZED
);
14883 if (mem_loc_result
== NULL
)
14884 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
14885 if (mem_loc_result
!= NULL
)
14887 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
14888 || GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
14890 dw_die_ref type_die
;
14891 dw_loc_descr_ref deref
;
14893 if (dwarf_strict
&& dwarf_version
< 5)
14896 = base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
14897 if (type_die
== NULL
)
14899 deref
= new_loc_descr (dwarf_OP (DW_OP_deref_type
),
14900 GET_MODE_SIZE (mode
), 0);
14901 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
14902 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
14903 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
14904 add_loc_descr (&mem_loc_result
, deref
);
14906 else if (GET_MODE_SIZE (int_mode
) == DWARF2_ADDR_SIZE
)
14907 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
14909 add_loc_descr (&mem_loc_result
,
14910 new_loc_descr (DW_OP_deref_size
,
14911 GET_MODE_SIZE (int_mode
), 0));
14916 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
14919 /* Some ports can transform a symbol ref into a label ref, because
14920 the symbol ref is too far away and has to be dumped into a constant
14924 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
14925 || (GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
14926 #ifdef POINTERS_EXTEND_UNSIGNED
14927 && (int_mode
!= Pmode
|| mem_mode
== VOIDmode
)
14931 if (GET_CODE (rtl
) == SYMBOL_REF
14932 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
14934 dw_loc_descr_ref temp
;
14936 /* If this is not defined, we have no way to emit the data. */
14937 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
14940 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
14942 /* We check for DWARF 5 here because gdb did not implement
14943 DW_OP_form_tls_address until after 7.12. */
14944 mem_loc_result
= new_loc_descr ((dwarf_version
>= 5
14945 ? DW_OP_form_tls_address
14946 : DW_OP_GNU_push_tls_address
),
14948 add_loc_descr (&mem_loc_result
, temp
);
14953 if (!const_ok_for_output (rtl
))
14955 if (GET_CODE (rtl
) == CONST
)
14956 switch (GET_CODE (XEXP (rtl
, 0)))
14960 goto try_const_unop
;
14963 goto try_const_unop
;
14966 arg
= XEXP (XEXP (rtl
, 0), 0);
14967 if (!CONSTANT_P (arg
))
14968 arg
= gen_rtx_CONST (int_mode
, arg
);
14969 op0
= mem_loc_descriptor (arg
, int_mode
, mem_mode
,
14973 mem_loc_result
= op0
;
14974 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
14978 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), int_mode
,
14979 mem_mode
, initialized
);
14986 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
14987 vec_safe_push (used_rtx_array
, rtl
);
14993 case DEBUG_IMPLICIT_PTR
:
14994 expansion_failed (NULL_TREE
, rtl
,
14995 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
14999 if (dwarf_strict
&& dwarf_version
< 5)
15001 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
15003 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
15004 || GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
15005 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
15006 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15009 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
15010 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
15012 op0
= one_reg_loc_descriptor (dbx_regnum
,
15013 VAR_INIT_STATUS_INITIALIZED
);
15016 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
15017 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
15019 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
15020 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15021 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
15025 gcc_unreachable ();
15028 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_entry_value
), 0, 0);
15029 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15030 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
15033 case DEBUG_PARAMETER_REF
:
15034 mem_loc_result
= parameter_ref_descriptor (rtl
);
15038 /* Extract the PLUS expression nested inside and fall into
15039 PLUS code below. */
15040 rtl
= XEXP (rtl
, 1);
15045 /* Turn these into a PLUS expression and fall into the PLUS code
15047 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
15048 gen_int_mode (GET_CODE (rtl
) == PRE_INC
15049 ? GET_MODE_UNIT_SIZE (mem_mode
)
15050 : -GET_MODE_UNIT_SIZE (mem_mode
),
15057 if (is_based_loc (rtl
)
15058 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
15059 && (GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
15060 || XEXP (rtl
, 0) == arg_pointer_rtx
15061 || XEXP (rtl
, 0) == frame_pointer_rtx
))
15062 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
15063 INTVAL (XEXP (rtl
, 1)),
15064 VAR_INIT_STATUS_INITIALIZED
);
15067 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15068 VAR_INIT_STATUS_INITIALIZED
);
15069 if (mem_loc_result
== 0)
15072 if (CONST_INT_P (XEXP (rtl
, 1))
15073 && (GET_MODE_SIZE (as_a
<scalar_int_mode
> (mode
))
15074 <= DWARF2_ADDR_SIZE
))
15075 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
15078 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15079 VAR_INIT_STATUS_INITIALIZED
);
15082 add_loc_descr (&mem_loc_result
, op1
);
15083 add_loc_descr (&mem_loc_result
,
15084 new_loc_descr (DW_OP_plus
, 0, 0));
15089 /* If a pseudo-reg is optimized away, it is possible for it to
15090 be replaced with a MEM containing a multiply or shift. */
15100 if ((!dwarf_strict
|| dwarf_version
>= 5)
15101 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
15102 && GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
15104 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
15105 base_type_for_mode (mode
, 0),
15106 int_mode
, mem_mode
);
15129 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
))
15131 op0
= mem_loc_descriptor (XEXP (rtl
, 0), int_mode
, mem_mode
,
15132 VAR_INIT_STATUS_INITIALIZED
);
15134 rtx rtlop1
= XEXP (rtl
, 1);
15135 if (is_a
<scalar_int_mode
> (GET_MODE (rtlop1
), &op1_mode
)
15136 && GET_MODE_BITSIZE (op1_mode
) < GET_MODE_BITSIZE (int_mode
))
15137 rtlop1
= gen_rtx_ZERO_EXTEND (int_mode
, rtlop1
);
15138 op1
= mem_loc_descriptor (rtlop1
, int_mode
, mem_mode
,
15139 VAR_INIT_STATUS_INITIALIZED
);
15142 if (op0
== 0 || op1
== 0)
15145 mem_loc_result
= op0
;
15146 add_loc_descr (&mem_loc_result
, op1
);
15147 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15163 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15164 VAR_INIT_STATUS_INITIALIZED
);
15165 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15166 VAR_INIT_STATUS_INITIALIZED
);
15168 if (op0
== 0 || op1
== 0)
15171 mem_loc_result
= op0
;
15172 add_loc_descr (&mem_loc_result
, op1
);
15173 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15177 if ((!dwarf_strict
|| dwarf_version
>= 5)
15178 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
15179 && GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
15181 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
15182 base_type_for_mode (mode
, 0),
15183 int_mode
, mem_mode
);
15187 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15188 VAR_INIT_STATUS_INITIALIZED
);
15189 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15190 VAR_INIT_STATUS_INITIALIZED
);
15192 if (op0
== 0 || op1
== 0)
15195 mem_loc_result
= op0
;
15196 add_loc_descr (&mem_loc_result
, op1
);
15197 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
15198 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
15199 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
15200 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
15201 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
15205 if ((!dwarf_strict
|| dwarf_version
>= 5)
15206 && is_a
<scalar_int_mode
> (mode
, &int_mode
))
15208 if (GET_MODE_SIZE (int_mode
) > DWARF2_ADDR_SIZE
)
15213 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
15214 base_type_for_mode (int_mode
, 1),
15215 int_mode
, mem_mode
);
15232 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15233 VAR_INIT_STATUS_INITIALIZED
);
15238 mem_loc_result
= op0
;
15239 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15243 if (!is_a
<scalar_int_mode
> (mode
, &int_mode
)
15244 || GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
15245 #ifdef POINTERS_EXTEND_UNSIGNED
15246 || (int_mode
== Pmode
15247 && mem_mode
!= VOIDmode
15248 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
15252 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
15255 if ((!dwarf_strict
|| dwarf_version
>= 5)
15256 && (GET_MODE_BITSIZE (int_mode
) == HOST_BITS_PER_WIDE_INT
15257 || GET_MODE_BITSIZE (int_mode
) == HOST_BITS_PER_DOUBLE_INT
))
15259 dw_die_ref type_die
= base_type_for_mode (int_mode
, 1);
15260 scalar_int_mode amode
;
15261 if (type_die
== NULL
)
15263 if (INTVAL (rtl
) >= 0
15264 && (int_mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
, 0)
15266 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
15267 /* const DW_OP_convert <XXX> vs.
15268 DW_OP_const_type <XXX, 1, const>. */
15269 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
15270 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (int_mode
))
15272 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
15273 op0
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15274 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15275 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15276 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15277 add_loc_descr (&mem_loc_result
, op0
);
15278 return mem_loc_result
;
15280 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0,
15282 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15283 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15284 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15285 if (GET_MODE_BITSIZE (int_mode
) == HOST_BITS_PER_WIDE_INT
)
15286 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
15289 mem_loc_result
->dw_loc_oprnd2
.val_class
15290 = dw_val_class_const_double
;
15291 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
15292 = double_int::from_shwi (INTVAL (rtl
));
15298 if (!dwarf_strict
|| dwarf_version
>= 5)
15300 dw_die_ref type_die
;
15302 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
15303 CONST_DOUBLE rtx could represent either a large integer
15304 or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
15305 the value is always a floating point constant.
15307 When it is an integer, a CONST_DOUBLE is used whenever
15308 the constant requires 2 HWIs to be adequately represented.
15309 We output CONST_DOUBLEs as blocks. */
15310 if (mode
== VOIDmode
15311 || (GET_MODE (rtl
) == VOIDmode
15312 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
15314 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
15315 if (type_die
== NULL
)
15317 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0, 0);
15318 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15319 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15320 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15321 #if TARGET_SUPPORTS_WIDE_INT == 0
15322 if (!SCALAR_FLOAT_MODE_P (mode
))
15324 mem_loc_result
->dw_loc_oprnd2
.val_class
15325 = dw_val_class_const_double
;
15326 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
15327 = rtx_to_double_int (rtl
);
15332 scalar_float_mode float_mode
= as_a
<scalar_float_mode
> (mode
);
15333 unsigned int length
= GET_MODE_SIZE (float_mode
);
15334 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
15336 insert_float (rtl
, array
);
15337 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
15338 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
15339 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
15340 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
15345 case CONST_WIDE_INT
:
15346 if (!dwarf_strict
|| dwarf_version
>= 5)
15348 dw_die_ref type_die
;
15350 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
15351 if (type_die
== NULL
)
15353 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0, 0);
15354 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15355 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15356 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15357 mem_loc_result
->dw_loc_oprnd2
.val_class
15358 = dw_val_class_wide_int
;
15359 mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
15360 *mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= rtx_mode_t (rtl
, mode
);
15365 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
15369 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
15373 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
15377 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
15381 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
15385 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
15389 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
15393 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
15397 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
15401 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
15406 if (!SCALAR_INT_MODE_P (mode
))
15411 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
15416 if (CONST_INT_P (XEXP (rtl
, 1))
15417 && CONST_INT_P (XEXP (rtl
, 2))
15418 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
15419 && is_a
<scalar_int_mode
> (GET_MODE (XEXP (rtl
, 0)), &inner_mode
)
15420 && GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
15421 && GET_MODE_SIZE (inner_mode
) <= DWARF2_ADDR_SIZE
15422 && ((unsigned) INTVAL (XEXP (rtl
, 1))
15423 + (unsigned) INTVAL (XEXP (rtl
, 2))
15424 <= GET_MODE_BITSIZE (int_mode
)))
15427 op0
= mem_loc_descriptor (XEXP (rtl
, 0), inner_mode
,
15428 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
15431 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
15435 mem_loc_result
= op0
;
15436 size
= INTVAL (XEXP (rtl
, 1));
15437 shift
= INTVAL (XEXP (rtl
, 2));
15438 if (BITS_BIG_ENDIAN
)
15439 shift
= GET_MODE_BITSIZE (inner_mode
) - shift
- size
;
15440 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
15442 add_loc_descr (&mem_loc_result
,
15443 int_loc_descriptor (DWARF2_ADDR_SIZE
15445 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
15447 if (size
!= (int) DWARF2_ADDR_SIZE
)
15449 add_loc_descr (&mem_loc_result
,
15450 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
15451 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15458 dw_loc_descr_ref op2
, bra_node
, drop_node
;
15459 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
15460 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
15461 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
15462 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
15463 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15464 VAR_INIT_STATUS_INITIALIZED
);
15465 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
15466 VAR_INIT_STATUS_INITIALIZED
);
15467 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
15470 mem_loc_result
= op1
;
15471 add_loc_descr (&mem_loc_result
, op2
);
15472 add_loc_descr (&mem_loc_result
, op0
);
15473 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
15474 add_loc_descr (&mem_loc_result
, bra_node
);
15475 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
15476 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
15477 add_loc_descr (&mem_loc_result
, drop_node
);
15478 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15479 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
15484 case FLOAT_TRUNCATE
:
15486 case UNSIGNED_FLOAT
:
15489 if (!dwarf_strict
|| dwarf_version
>= 5)
15491 dw_die_ref type_die
;
15492 dw_loc_descr_ref cvt
;
15494 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
15495 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
15498 if (is_a
<scalar_int_mode
> (GET_MODE (XEXP (rtl
, 0)), &int_mode
)
15499 && (GET_CODE (rtl
) == FLOAT
15500 || GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
))
15502 type_die
= base_type_for_mode (int_mode
,
15503 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
15504 if (type_die
== NULL
)
15506 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15507 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15508 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15509 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15510 add_loc_descr (&op0
, cvt
);
15512 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
15513 if (type_die
== NULL
)
15515 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15516 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15517 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15518 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15519 add_loc_descr (&op0
, cvt
);
15520 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
15521 && (GET_CODE (rtl
) == FIX
15522 || GET_MODE_SIZE (int_mode
) < DWARF2_ADDR_SIZE
))
15524 op0
= convert_descriptor_to_mode (int_mode
, op0
);
15528 mem_loc_result
= op0
;
15535 if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
15536 mem_loc_result
= clz_loc_descriptor (rtl
, int_mode
, mem_mode
);
15541 if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
15542 mem_loc_result
= popcount_loc_descriptor (rtl
, int_mode
, mem_mode
);
15546 if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
15547 mem_loc_result
= bswap_loc_descriptor (rtl
, int_mode
, mem_mode
);
15552 if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
15553 mem_loc_result
= rotate_loc_descriptor (rtl
, int_mode
, mem_mode
);
15557 /* In theory, we could implement the above. */
15558 /* DWARF cannot represent the unsigned compare operations
15583 case FRACT_CONVERT
:
15584 case UNSIGNED_FRACT_CONVERT
:
15586 case UNSIGNED_SAT_FRACT
:
15592 case VEC_DUPLICATE
:
15597 case STRICT_LOW_PART
:
15602 /* If delegitimize_address couldn't do anything with the UNSPEC, we
15603 can't express it in the debug info. This can happen e.g. with some
15608 resolve_one_addr (&rtl
);
15611 /* RTL sequences inside PARALLEL record a series of DWARF operations for
15612 the expression. An UNSPEC rtx represents a raw DWARF operation,
15613 new_loc_descr is called for it to build the operation directly.
15614 Otherwise mem_loc_descriptor is called recursively. */
15618 dw_loc_descr_ref exp_result
= NULL
;
15620 for (; index
< XVECLEN (rtl
, 0); index
++)
15622 rtx elem
= XVECEXP (rtl
, 0, index
);
15623 if (GET_CODE (elem
) == UNSPEC
)
15625 /* Each DWARF operation UNSPEC contain two operands, if
15626 one operand is not used for the operation, const0_rtx is
15628 gcc_assert (XVECLEN (elem
, 0) == 2);
15630 HOST_WIDE_INT dw_op
= XINT (elem
, 1);
15631 HOST_WIDE_INT oprnd1
= INTVAL (XVECEXP (elem
, 0, 0));
15632 HOST_WIDE_INT oprnd2
= INTVAL (XVECEXP (elem
, 0, 1));
15634 = new_loc_descr ((enum dwarf_location_atom
) dw_op
, oprnd1
,
15639 = mem_loc_descriptor (elem
, mode
, mem_mode
,
15640 VAR_INIT_STATUS_INITIALIZED
);
15642 if (!mem_loc_result
)
15643 mem_loc_result
= exp_result
;
15645 add_loc_descr (&mem_loc_result
, exp_result
);
15654 print_rtl (stderr
, rtl
);
15655 gcc_unreachable ();
15660 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
15661 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
15663 return mem_loc_result
;
15666 /* Return a descriptor that describes the concatenation of two locations.
15667 This is typically a complex variable. */
15669 static dw_loc_descr_ref
15670 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
15672 dw_loc_descr_ref cc_loc_result
= NULL
;
15673 dw_loc_descr_ref x0_ref
15674 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15675 dw_loc_descr_ref x1_ref
15676 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15678 if (x0_ref
== 0 || x1_ref
== 0)
15681 cc_loc_result
= x0_ref
;
15682 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
15684 add_loc_descr (&cc_loc_result
, x1_ref
);
15685 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
15687 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
15688 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
15690 return cc_loc_result
;
15693 /* Return a descriptor that describes the concatenation of N
15696 static dw_loc_descr_ref
15697 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
15700 dw_loc_descr_ref cc_loc_result
= NULL
;
15701 unsigned int n
= XVECLEN (concatn
, 0);
15703 for (i
= 0; i
< n
; ++i
)
15705 dw_loc_descr_ref ref
;
15706 rtx x
= XVECEXP (concatn
, 0, i
);
15708 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15712 add_loc_descr (&cc_loc_result
, ref
);
15713 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
15716 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
15717 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
15719 return cc_loc_result
;
15722 /* Helper function for loc_descriptor. Return DW_OP_implicit_pointer
15723 for DEBUG_IMPLICIT_PTR RTL. */
15725 static dw_loc_descr_ref
15726 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
15728 dw_loc_descr_ref ret
;
15731 if (dwarf_strict
&& dwarf_version
< 5)
15733 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
15734 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
15735 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
15736 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
15737 ret
= new_loc_descr (dwarf_OP (DW_OP_implicit_pointer
), 0, offset
);
15738 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
15741 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15742 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
15743 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15747 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
15748 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
15753 /* Output a proper Dwarf location descriptor for a variable or parameter
15754 which is either allocated in a register or in a memory location. For a
15755 register, we just generate an OP_REG and the register number. For a
15756 memory location we provide a Dwarf postfix expression describing how to
15757 generate the (dynamic) address of the object onto the address stack.
15759 MODE is mode of the decl if this loc_descriptor is going to be used in
15760 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
15761 allowed, VOIDmode otherwise.
15763 If we don't know how to describe it, return 0. */
15765 static dw_loc_descr_ref
15766 loc_descriptor (rtx rtl
, machine_mode mode
,
15767 enum var_init_status initialized
)
15769 dw_loc_descr_ref loc_result
= NULL
;
15770 scalar_int_mode int_mode
;
15772 switch (GET_CODE (rtl
))
15775 /* The case of a subreg may arise when we have a local (register)
15776 variable or a formal (register) parameter which doesn't quite fill
15777 up an entire register. For now, just assume that it is
15778 legitimate to make the Dwarf info refer to the whole register which
15779 contains the given subreg. */
15780 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
15781 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
15782 GET_MODE (SUBREG_REG (rtl
)), initialized
);
15788 loc_result
= reg_loc_descriptor (rtl
, initialized
);
15792 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
15793 GET_MODE (rtl
), initialized
);
15794 if (loc_result
== NULL
)
15795 loc_result
= tls_mem_loc_descriptor (rtl
);
15796 if (loc_result
== NULL
)
15798 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
15799 if (new_rtl
!= rtl
)
15800 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
15805 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
15810 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
15815 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
15817 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
15818 if (GET_CODE (loc
) == EXPR_LIST
)
15819 loc
= XEXP (loc
, 0);
15820 loc_result
= loc_descriptor (loc
, mode
, initialized
);
15824 rtl
= XEXP (rtl
, 1);
15829 rtvec par_elems
= XVEC (rtl
, 0);
15830 int num_elem
= GET_NUM_ELEM (par_elems
);
15834 /* Create the first one, so we have something to add to. */
15835 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
15836 VOIDmode
, initialized
);
15837 if (loc_result
== NULL
)
15839 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
15840 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
15841 for (i
= 1; i
< num_elem
; i
++)
15843 dw_loc_descr_ref temp
;
15845 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
15846 VOIDmode
, initialized
);
15849 add_loc_descr (&loc_result
, temp
);
15850 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
15851 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
15857 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
15859 int_mode
= as_a
<scalar_int_mode
> (mode
);
15860 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (int_mode
),
15866 if (mode
== VOIDmode
)
15867 mode
= GET_MODE (rtl
);
15869 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
15871 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
15873 /* Note that a CONST_DOUBLE rtx could represent either an integer
15874 or a floating-point constant. A CONST_DOUBLE is used whenever
15875 the constant requires more than one word in order to be
15876 adequately represented. We output CONST_DOUBLEs as blocks. */
15877 scalar_mode smode
= as_a
<scalar_mode
> (mode
);
15878 loc_result
= new_loc_descr (DW_OP_implicit_value
,
15879 GET_MODE_SIZE (smode
), 0);
15880 #if TARGET_SUPPORTS_WIDE_INT == 0
15881 if (!SCALAR_FLOAT_MODE_P (smode
))
15883 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
15884 loc_result
->dw_loc_oprnd2
.v
.val_double
15885 = rtx_to_double_int (rtl
);
15890 unsigned int length
= GET_MODE_SIZE (smode
);
15891 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
15893 insert_float (rtl
, array
);
15894 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
15895 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
15896 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
15897 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
15902 case CONST_WIDE_INT
:
15903 if (mode
== VOIDmode
)
15904 mode
= GET_MODE (rtl
);
15906 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
15908 int_mode
= as_a
<scalar_int_mode
> (mode
);
15909 loc_result
= new_loc_descr (DW_OP_implicit_value
,
15910 GET_MODE_SIZE (int_mode
), 0);
15911 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_wide_int
;
15912 loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
15913 *loc_result
->dw_loc_oprnd2
.v
.val_wide
= rtx_mode_t (rtl
, int_mode
);
15918 if (mode
== VOIDmode
)
15919 mode
= GET_MODE (rtl
);
15921 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
15923 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
15924 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
15925 unsigned char *array
15926 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
15929 machine_mode imode
= GET_MODE_INNER (mode
);
15931 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
15932 switch (GET_MODE_CLASS (mode
))
15934 case MODE_VECTOR_INT
:
15935 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15937 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15938 insert_wide_int (rtx_mode_t (elt
, imode
), p
, elt_size
);
15942 case MODE_VECTOR_FLOAT
:
15943 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15945 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15946 insert_float (elt
, p
);
15951 gcc_unreachable ();
15954 loc_result
= new_loc_descr (DW_OP_implicit_value
,
15955 length
* elt_size
, 0);
15956 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
15957 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
15958 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
15959 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
15964 if (mode
== VOIDmode
15965 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
15966 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
15967 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
15969 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
15974 if (!const_ok_for_output (rtl
))
15978 if (is_a
<scalar_int_mode
> (mode
, &int_mode
)
15979 && GET_MODE_SIZE (int_mode
) == DWARF2_ADDR_SIZE
15980 && (dwarf_version
>= 4 || !dwarf_strict
))
15982 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
15983 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15984 vec_safe_push (used_rtx_array
, rtl
);
15988 case DEBUG_IMPLICIT_PTR
:
15989 loc_result
= implicit_ptr_descriptor (rtl
, 0);
15993 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
15994 && CONST_INT_P (XEXP (rtl
, 1)))
15997 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
16003 if ((is_a
<scalar_int_mode
> (mode
, &int_mode
)
16004 && GET_MODE (rtl
) == int_mode
16005 && GET_MODE_SIZE (int_mode
) <= DWARF2_ADDR_SIZE
16006 && dwarf_version
>= 4)
16007 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
16009 /* Value expression. */
16010 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
16012 add_loc_descr (&loc_result
,
16013 new_loc_descr (DW_OP_stack_value
, 0, 0));
16021 /* We need to figure out what section we should use as the base for the
16022 address ranges where a given location is valid.
16023 1. If this particular DECL has a section associated with it, use that.
16024 2. If this function has a section associated with it, use that.
16025 3. Otherwise, use the text section.
16026 XXX: If you split a variable across multiple sections, we won't notice. */
16028 static const char *
16029 secname_for_decl (const_tree decl
)
16031 const char *secname
;
16033 if (VAR_OR_FUNCTION_DECL_P (decl
)
16034 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
) || TREE_STATIC (decl
))
16035 && DECL_SECTION_NAME (decl
))
16036 secname
= DECL_SECTION_NAME (decl
);
16037 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
16038 secname
= DECL_SECTION_NAME (current_function_decl
);
16039 else if (cfun
&& in_cold_section_p
)
16040 secname
= crtl
->subsections
.cold_section_label
;
16042 secname
= text_section_label
;
16047 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
16050 decl_by_reference_p (tree decl
)
16052 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
16054 && DECL_BY_REFERENCE (decl
));
16057 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
16060 static dw_loc_descr_ref
16061 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
16062 enum var_init_status initialized
)
16064 int have_address
= 0;
16065 dw_loc_descr_ref descr
;
16068 if (want_address
!= 2)
16070 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
16072 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
16074 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
16075 if (GET_CODE (varloc
) == EXPR_LIST
)
16076 varloc
= XEXP (varloc
, 0);
16077 mode
= GET_MODE (varloc
);
16078 if (MEM_P (varloc
))
16080 rtx addr
= XEXP (varloc
, 0);
16081 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
16082 mode
, initialized
);
16087 rtx x
= avoid_constant_pool_reference (varloc
);
16089 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
16094 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
16101 if (GET_CODE (varloc
) == VAR_LOCATION
)
16102 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
16104 mode
= DECL_MODE (loc
);
16105 descr
= loc_descriptor (varloc
, mode
, initialized
);
16112 if (want_address
== 2 && !have_address
16113 && (dwarf_version
>= 4 || !dwarf_strict
))
16115 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
16117 expansion_failed (loc
, NULL_RTX
,
16118 "DWARF address size mismatch");
16121 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
16124 /* Show if we can't fill the request for an address. */
16125 if (want_address
&& !have_address
)
16127 expansion_failed (loc
, NULL_RTX
,
16128 "Want address and only have value");
16132 /* If we've got an address and don't want one, dereference. */
16133 if (!want_address
&& have_address
)
16135 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
16136 enum dwarf_location_atom op
;
16138 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
16140 expansion_failed (loc
, NULL_RTX
,
16141 "DWARF address size mismatch");
16144 else if (size
== DWARF2_ADDR_SIZE
)
16147 op
= DW_OP_deref_size
;
16149 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
16155 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
16156 if it is not possible. */
16158 static dw_loc_descr_ref
16159 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
16161 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
16162 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
16163 else if (dwarf_version
>= 3 || !dwarf_strict
)
16164 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
16169 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
16170 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
16172 static dw_loc_descr_ref
16173 dw_sra_loc_expr (tree decl
, rtx loc
)
16176 unsigned HOST_WIDE_INT padsize
= 0;
16177 dw_loc_descr_ref descr
, *descr_tail
;
16178 unsigned HOST_WIDE_INT decl_size
;
16180 enum var_init_status initialized
;
16182 if (DECL_SIZE (decl
) == NULL
16183 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
16186 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
16188 descr_tail
= &descr
;
16190 for (p
= loc
; p
; p
= XEXP (p
, 1))
16192 unsigned HOST_WIDE_INT bitsize
= decl_piece_bitsize (p
);
16193 rtx loc_note
= *decl_piece_varloc_ptr (p
);
16194 dw_loc_descr_ref cur_descr
;
16195 dw_loc_descr_ref
*tail
, last
= NULL
;
16196 unsigned HOST_WIDE_INT opsize
= 0;
16198 if (loc_note
== NULL_RTX
16199 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
16201 padsize
+= bitsize
;
16204 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
16205 varloc
= NOTE_VAR_LOCATION (loc_note
);
16206 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
16207 if (cur_descr
== NULL
)
16209 padsize
+= bitsize
;
16213 /* Check that cur_descr either doesn't use
16214 DW_OP_*piece operations, or their sum is equal
16215 to bitsize. Otherwise we can't embed it. */
16216 for (tail
= &cur_descr
; *tail
!= NULL
;
16217 tail
= &(*tail
)->dw_loc_next
)
16218 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
16220 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
16224 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
16226 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
16230 if (last
!= NULL
&& opsize
!= bitsize
)
16232 padsize
+= bitsize
;
16233 /* Discard the current piece of the descriptor and release any
16234 addr_table entries it uses. */
16235 remove_loc_list_addr_table_entries (cur_descr
);
16239 /* If there is a hole, add DW_OP_*piece after empty DWARF
16240 expression, which means that those bits are optimized out. */
16243 if (padsize
> decl_size
)
16245 remove_loc_list_addr_table_entries (cur_descr
);
16246 goto discard_descr
;
16248 decl_size
-= padsize
;
16249 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
16250 if (*descr_tail
== NULL
)
16252 remove_loc_list_addr_table_entries (cur_descr
);
16253 goto discard_descr
;
16255 descr_tail
= &(*descr_tail
)->dw_loc_next
;
16258 *descr_tail
= cur_descr
;
16260 if (bitsize
> decl_size
)
16261 goto discard_descr
;
16262 decl_size
-= bitsize
;
16265 HOST_WIDE_INT offset
= 0;
16266 if (GET_CODE (varloc
) == VAR_LOCATION
16267 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
16269 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
16270 if (GET_CODE (varloc
) == EXPR_LIST
)
16271 varloc
= XEXP (varloc
, 0);
16275 if (GET_CODE (varloc
) == CONST
16276 || GET_CODE (varloc
) == SIGN_EXTEND
16277 || GET_CODE (varloc
) == ZERO_EXTEND
)
16278 varloc
= XEXP (varloc
, 0);
16279 else if (GET_CODE (varloc
) == SUBREG
)
16280 varloc
= SUBREG_REG (varloc
);
16285 /* DW_OP_bit_size offset should be zero for register
16286 or implicit location descriptions and empty location
16287 descriptions, but for memory addresses needs big endian
16289 if (MEM_P (varloc
))
16291 unsigned HOST_WIDE_INT memsize
16292 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
16293 if (memsize
!= bitsize
)
16295 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
16296 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
16297 goto discard_descr
;
16298 if (memsize
< bitsize
)
16299 goto discard_descr
;
16300 if (BITS_BIG_ENDIAN
)
16301 offset
= memsize
- bitsize
;
16305 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
16306 if (*descr_tail
== NULL
)
16307 goto discard_descr
;
16308 descr_tail
= &(*descr_tail
)->dw_loc_next
;
16312 /* If there were any non-empty expressions, add padding till the end of
16314 if (descr
!= NULL
&& decl_size
!= 0)
16316 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
16317 if (*descr_tail
== NULL
)
16318 goto discard_descr
;
16323 /* Discard the descriptor and release any addr_table entries it uses. */
16324 remove_loc_list_addr_table_entries (descr
);
16328 /* Return the dwarf representation of the location list LOC_LIST of
16329 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
16332 static dw_loc_list_ref
16333 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
16335 const char *endname
, *secname
;
16337 enum var_init_status initialized
;
16338 struct var_loc_node
*node
;
16339 dw_loc_descr_ref descr
;
16340 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
16341 dw_loc_list_ref list
= NULL
;
16342 dw_loc_list_ref
*listp
= &list
;
16344 /* Now that we know what section we are using for a base,
16345 actually construct the list of locations.
16346 The first location information is what is passed to the
16347 function that creates the location list, and the remaining
16348 locations just get added on to that list.
16349 Note that we only know the start address for a location
16350 (IE location changes), so to build the range, we use
16351 the range [current location start, next location start].
16352 This means we have to special case the last node, and generate
16353 a range of [last location start, end of function label]. */
16355 if (cfun
&& crtl
->has_bb_partition
)
16357 bool save_in_cold_section_p
= in_cold_section_p
;
16358 in_cold_section_p
= first_function_block_is_cold
;
16359 if (loc_list
->last_before_switch
== NULL
)
16360 in_cold_section_p
= !in_cold_section_p
;
16361 secname
= secname_for_decl (decl
);
16362 in_cold_section_p
= save_in_cold_section_p
;
16365 secname
= secname_for_decl (decl
);
16367 for (node
= loc_list
->first
; node
; node
= node
->next
)
16369 bool range_across_switch
= false;
16370 if (GET_CODE (node
->loc
) == EXPR_LIST
16371 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
16373 if (GET_CODE (node
->loc
) == EXPR_LIST
)
16376 /* This requires DW_OP_{,bit_}piece, which is not usable
16377 inside DWARF expressions. */
16378 if (want_address
== 2)
16379 descr
= dw_sra_loc_expr (decl
, node
->loc
);
16383 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
16384 varloc
= NOTE_VAR_LOCATION (node
->loc
);
16385 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
16389 /* If section switch happens in between node->label
16390 and node->next->label (or end of function) and
16391 we can't emit it as a single entry list,
16392 emit two ranges, first one ending at the end
16393 of first partition and second one starting at the
16394 beginning of second partition. */
16395 if (node
== loc_list
->last_before_switch
16396 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
16397 && current_function_decl
)
16399 endname
= cfun
->fde
->dw_fde_end
;
16400 range_across_switch
= true;
16402 /* The variable has a location between NODE->LABEL and
16403 NODE->NEXT->LABEL. */
16404 else if (node
->next
)
16405 endname
= node
->next
->label
;
16406 /* If the variable has a location at the last label
16407 it keeps its location until the end of function. */
16408 else if (!current_function_decl
)
16409 endname
= text_end_label
;
16412 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
16413 current_function_funcdef_no
);
16414 endname
= ggc_strdup (label_id
);
16417 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
16418 if (TREE_CODE (decl
) == PARM_DECL
16419 && node
== loc_list
->first
16420 && NOTE_P (node
->loc
)
16421 && strcmp (node
->label
, endname
) == 0)
16422 (*listp
)->force
= true;
16423 listp
= &(*listp
)->dw_loc_next
;
16428 && crtl
->has_bb_partition
16429 && node
== loc_list
->last_before_switch
)
16431 bool save_in_cold_section_p
= in_cold_section_p
;
16432 in_cold_section_p
= !first_function_block_is_cold
;
16433 secname
= secname_for_decl (decl
);
16434 in_cold_section_p
= save_in_cold_section_p
;
16437 if (range_across_switch
)
16439 if (GET_CODE (node
->loc
) == EXPR_LIST
)
16440 descr
= dw_sra_loc_expr (decl
, node
->loc
);
16443 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
16444 varloc
= NOTE_VAR_LOCATION (node
->loc
);
16445 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
16448 gcc_assert (descr
);
16449 /* The variable has a location between NODE->LABEL and
16450 NODE->NEXT->LABEL. */
16452 endname
= node
->next
->label
;
16454 endname
= cfun
->fde
->dw_fde_second_end
;
16455 *listp
= new_loc_list (descr
, cfun
->fde
->dw_fde_second_begin
,
16457 listp
= &(*listp
)->dw_loc_next
;
16461 /* Try to avoid the overhead of a location list emitting a location
16462 expression instead, but only if we didn't have more than one
16463 location entry in the first place. If some entries were not
16464 representable, we don't want to pretend a single entry that was
16465 applies to the entire scope in which the variable is
16467 if (list
&& loc_list
->first
->next
)
16473 /* Return if the loc_list has only single element and thus can be represented
16474 as location description. */
16477 single_element_loc_list_p (dw_loc_list_ref list
)
16479 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
16480 return !list
->ll_symbol
;
16483 /* Duplicate a single element of location list. */
16485 static inline dw_loc_descr_ref
16486 copy_loc_descr (dw_loc_descr_ref ref
)
16488 dw_loc_descr_ref copy
= ggc_alloc
<dw_loc_descr_node
> ();
16489 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
16493 /* To each location in list LIST append loc descr REF. */
16496 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
16498 dw_loc_descr_ref copy
;
16499 add_loc_descr (&list
->expr
, ref
);
16500 list
= list
->dw_loc_next
;
16503 copy
= copy_loc_descr (ref
);
16504 add_loc_descr (&list
->expr
, copy
);
16505 while (copy
->dw_loc_next
)
16506 copy
= copy
->dw_loc_next
= copy_loc_descr (copy
->dw_loc_next
);
16507 list
= list
->dw_loc_next
;
16511 /* To each location in list LIST prepend loc descr REF. */
16514 prepend_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
16516 dw_loc_descr_ref copy
;
16517 dw_loc_descr_ref ref_end
= list
->expr
;
16518 add_loc_descr (&ref
, list
->expr
);
16520 list
= list
->dw_loc_next
;
16523 dw_loc_descr_ref end
= list
->expr
;
16524 list
->expr
= copy
= copy_loc_descr (ref
);
16525 while (copy
->dw_loc_next
!= ref_end
)
16526 copy
= copy
->dw_loc_next
= copy_loc_descr (copy
->dw_loc_next
);
16527 copy
->dw_loc_next
= end
;
16528 list
= list
->dw_loc_next
;
16532 /* Given two lists RET and LIST
16533 produce location list that is result of adding expression in LIST
16534 to expression in RET on each position in program.
16535 Might be destructive on both RET and LIST.
16537 TODO: We handle only simple cases of RET or LIST having at most one
16538 element. General case would involve sorting the lists in program order
16539 and merging them that will need some additional work.
16540 Adding that will improve quality of debug info especially for SRA-ed
16544 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
16553 if (!list
->dw_loc_next
)
16555 add_loc_descr_to_each (*ret
, list
->expr
);
16558 if (!(*ret
)->dw_loc_next
)
16560 prepend_loc_descr_to_each (list
, (*ret
)->expr
);
16564 expansion_failed (NULL_TREE
, NULL_RTX
,
16565 "Don't know how to merge two non-trivial"
16566 " location lists.\n");
16571 /* LOC is constant expression. Try a luck, look it up in constant
16572 pool and return its loc_descr of its address. */
16574 static dw_loc_descr_ref
16575 cst_pool_loc_descr (tree loc
)
16577 /* Get an RTL for this, if something has been emitted. */
16578 rtx rtl
= lookup_constant_def (loc
);
16580 if (!rtl
|| !MEM_P (rtl
))
16585 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
16587 /* TODO: We might get more coverage if we was actually delaying expansion
16588 of all expressions till end of compilation when constant pools are fully
16590 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
16592 expansion_failed (loc
, NULL_RTX
,
16593 "CST value in contant pool but not marked.");
16596 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
16597 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
16600 /* Return dw_loc_list representing address of addr_expr LOC
16601 by looking for inner INDIRECT_REF expression and turning
16602 it into simple arithmetics.
16604 See loc_list_from_tree for the meaning of CONTEXT. */
16606 static dw_loc_list_ref
16607 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
,
16608 loc_descr_context
*context
)
16611 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
16613 int unsignedp
, reversep
, volatilep
= 0;
16614 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
16616 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
16617 &bitsize
, &bitpos
, &offset
, &mode
,
16618 &unsignedp
, &reversep
, &volatilep
);
16620 if (bitpos
% BITS_PER_UNIT
)
16622 expansion_failed (loc
, NULL_RTX
, "bitfield access");
16625 if (!INDIRECT_REF_P (obj
))
16627 expansion_failed (obj
,
16628 NULL_RTX
, "no indirect ref in inner refrence");
16631 if (!offset
&& !bitpos
)
16632 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1,
16635 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
16636 && (dwarf_version
>= 4 || !dwarf_strict
))
16638 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0, context
);
16643 /* Variable offset. */
16644 list_ret1
= loc_list_from_tree (offset
, 0, context
);
16645 if (list_ret1
== 0)
16647 add_loc_list (&list_ret
, list_ret1
);
16650 add_loc_descr_to_each (list_ret
,
16651 new_loc_descr (DW_OP_plus
, 0, 0));
16653 bytepos
= bitpos
/ BITS_PER_UNIT
;
16655 add_loc_descr_to_each (list_ret
,
16656 new_loc_descr (DW_OP_plus_uconst
,
16658 else if (bytepos
< 0)
16659 loc_list_plus_const (list_ret
, bytepos
);
16660 add_loc_descr_to_each (list_ret
,
16661 new_loc_descr (DW_OP_stack_value
, 0, 0));
16666 /* Set LOC to the next operation that is not a DW_OP_nop operation. In the case
16667 all operations from LOC are nops, move to the last one. Insert in NOPS all
16668 operations that are skipped. */
16671 loc_descr_to_next_no_nop (dw_loc_descr_ref
&loc
,
16672 hash_set
<dw_loc_descr_ref
> &nops
)
16674 while (loc
->dw_loc_next
!= NULL
&& loc
->dw_loc_opc
== DW_OP_nop
)
16677 loc
= loc
->dw_loc_next
;
16681 /* Helper for loc_descr_without_nops: free the location description operation
16685 free_loc_descr (const dw_loc_descr_ref
&loc
, void *data ATTRIBUTE_UNUSED
)
16691 /* Remove all DW_OP_nop operations from LOC except, if it exists, the one that
16695 loc_descr_without_nops (dw_loc_descr_ref
&loc
)
16697 if (loc
->dw_loc_opc
== DW_OP_nop
&& loc
->dw_loc_next
== NULL
)
16700 /* Set of all DW_OP_nop operations we remove. */
16701 hash_set
<dw_loc_descr_ref
> nops
;
16703 /* First, strip all prefix NOP operations in order to keep the head of the
16704 operations list. */
16705 loc_descr_to_next_no_nop (loc
, nops
);
16707 for (dw_loc_descr_ref cur
= loc
; cur
!= NULL
;)
16709 /* For control flow operations: strip "prefix" nops in destination
16711 if (cur
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
)
16712 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd1
.v
.val_loc
, nops
);
16713 if (cur
->dw_loc_oprnd2
.val_class
== dw_val_class_loc
)
16714 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd2
.v
.val_loc
, nops
);
16716 /* Do the same for the operations that follow, then move to the next
16718 if (cur
->dw_loc_next
!= NULL
)
16719 loc_descr_to_next_no_nop (cur
->dw_loc_next
, nops
);
16720 cur
= cur
->dw_loc_next
;
16723 nops
.traverse
<void *, free_loc_descr
> (NULL
);
16727 struct dwarf_procedure_info
;
16729 /* Helper structure for location descriptions generation. */
16730 struct loc_descr_context
16732 /* The type that is implicitly referenced by DW_OP_push_object_address, or
16733 NULL_TREE if DW_OP_push_object_address in invalid for this location
16734 description. This is used when processing PLACEHOLDER_EXPR nodes. */
16736 /* The ..._DECL node that should be translated as a
16737 DW_OP_push_object_address operation. */
16739 /* Information about the DWARF procedure we are currently generating. NULL if
16740 we are not generating a DWARF procedure. */
16741 struct dwarf_procedure_info
*dpi
;
16742 /* True if integral PLACEHOLDER_EXPR stands for the first argument passed
16743 by consumer. Used for DW_TAG_generic_subrange attributes. */
16744 bool placeholder_arg
;
16745 /* True if PLACEHOLDER_EXPR has been seen. */
16746 bool placeholder_seen
;
16749 /* DWARF procedures generation
16751 DWARF expressions (aka. location descriptions) are used to encode variable
16752 things such as sizes or offsets. Such computations can have redundant parts
16753 that can be factorized in order to reduce the size of the output debug
16754 information. This is the whole point of DWARF procedures.
16756 Thanks to stor-layout.c, size and offset expressions in GENERIC trees are
16757 already factorized into functions ("size functions") in order to handle very
16758 big and complex types. Such functions are quite simple: they have integral
16759 arguments, they return an integral result and their body contains only a
16760 return statement with arithmetic expressions. This is the only kind of
16761 function we are interested in translating into DWARF procedures, here.
16763 DWARF expressions and DWARF procedure are executed using a stack, so we have
16764 to define some calling convention for them to interact. Let's say that:
16766 - Before calling a DWARF procedure, DWARF expressions must push on the stack
16767 all arguments in reverse order (right-to-left) so that when the DWARF
16768 procedure execution starts, the first argument is the top of the stack.
16770 - Then, when returning, the DWARF procedure must have consumed all arguments
16771 on the stack, must have pushed the result and touched nothing else.
16773 - Each integral argument and the result are integral types can be hold in a
16776 - We call "frame offset" the number of stack slots that are "under DWARF
16777 procedure control": it includes the arguments slots, the temporaries and
16778 the result slot. Thus, it is equal to the number of arguments when the
16779 procedure execution starts and must be equal to one (the result) when it
16782 /* Helper structure used when generating operations for a DWARF procedure. */
16783 struct dwarf_procedure_info
16785 /* The FUNCTION_DECL node corresponding to the DWARF procedure that is
16786 currently translated. */
16788 /* The number of arguments FNDECL takes. */
16789 unsigned args_count
;
16792 /* Return a pointer to a newly created DIE node for a DWARF procedure. Add
16793 LOCATION as its DW_AT_location attribute. If FNDECL is not NULL_TREE,
16794 equate it to this DIE. */
16797 new_dwarf_proc_die (dw_loc_descr_ref location
, tree fndecl
,
16798 dw_die_ref parent_die
)
16800 dw_die_ref dwarf_proc_die
;
16802 if ((dwarf_version
< 3 && dwarf_strict
)
16803 || location
== NULL
)
16806 dwarf_proc_die
= new_die (DW_TAG_dwarf_procedure
, parent_die
, fndecl
);
16808 equate_decl_number_to_die (fndecl
, dwarf_proc_die
);
16809 add_AT_loc (dwarf_proc_die
, DW_AT_location
, location
);
16810 return dwarf_proc_die
;
16813 /* Return whether TYPE is a supported type as a DWARF procedure argument
16814 type or return type (we handle only scalar types and pointer types that
16815 aren't wider than the DWARF expression evaluation stack. */
16818 is_handled_procedure_type (tree type
)
16820 return ((INTEGRAL_TYPE_P (type
)
16821 || TREE_CODE (type
) == OFFSET_TYPE
16822 || TREE_CODE (type
) == POINTER_TYPE
)
16823 && int_size_in_bytes (type
) <= DWARF2_ADDR_SIZE
);
16826 /* Helper for resolve_args_picking: do the same but stop when coming across
16827 visited nodes. For each node we visit, register in FRAME_OFFSETS the frame
16828 offset *before* evaluating the corresponding operation. */
16831 resolve_args_picking_1 (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
16832 struct dwarf_procedure_info
*dpi
,
16833 hash_map
<dw_loc_descr_ref
, unsigned> &frame_offsets
)
16835 /* The "frame_offset" identifier is already used to name a macro... */
16836 unsigned frame_offset_
= initial_frame_offset
;
16837 dw_loc_descr_ref l
;
16839 for (l
= loc
; l
!= NULL
;)
16842 unsigned &l_frame_offset
= frame_offsets
.get_or_insert (l
, &existed
);
16844 /* If we already met this node, there is nothing to compute anymore. */
16847 /* Make sure that the stack size is consistent wherever the execution
16848 flow comes from. */
16849 gcc_assert ((unsigned) l_frame_offset
== frame_offset_
);
16852 l_frame_offset
= frame_offset_
;
16854 /* If needed, relocate the picking offset with respect to the frame
16856 if (l
->frame_offset_rel
)
16858 unsigned HOST_WIDE_INT off
;
16859 switch (l
->dw_loc_opc
)
16862 off
= l
->dw_loc_oprnd1
.v
.val_unsigned
;
16871 gcc_unreachable ();
16873 /* frame_offset_ is the size of the current stack frame, including
16874 incoming arguments. Besides, the arguments are pushed
16875 right-to-left. Thus, in order to access the Nth argument from
16876 this operation node, the picking has to skip temporaries *plus*
16877 one stack slot per argument (0 for the first one, 1 for the second
16880 The targetted argument number (N) is already set as the operand,
16881 and the number of temporaries can be computed with:
16882 frame_offsets_ - dpi->args_count */
16883 off
+= frame_offset_
- dpi
->args_count
;
16885 /* DW_OP_pick handles only offsets from 0 to 255 (inclusive)... */
16891 l
->dw_loc_opc
= DW_OP_dup
;
16892 l
->dw_loc_oprnd1
.v
.val_unsigned
= 0;
16896 l
->dw_loc_opc
= DW_OP_over
;
16897 l
->dw_loc_oprnd1
.v
.val_unsigned
= 0;
16901 l
->dw_loc_opc
= DW_OP_pick
;
16902 l
->dw_loc_oprnd1
.v
.val_unsigned
= off
;
16906 /* Update frame_offset according to the effect the current operation has
16908 switch (l
->dw_loc_opc
)
16916 case DW_OP_plus_uconst
:
16952 case DW_OP_deref_size
:
16954 case DW_OP_bit_piece
:
16955 case DW_OP_implicit_value
:
16956 case DW_OP_stack_value
:
16960 case DW_OP_const1u
:
16961 case DW_OP_const1s
:
16962 case DW_OP_const2u
:
16963 case DW_OP_const2s
:
16964 case DW_OP_const4u
:
16965 case DW_OP_const4s
:
16966 case DW_OP_const8u
:
16967 case DW_OP_const8s
:
17038 case DW_OP_push_object_address
:
17039 case DW_OP_call_frame_cfa
:
17040 case DW_OP_GNU_variable_value
:
17065 case DW_OP_xderef_size
:
17071 case DW_OP_call_ref
:
17073 dw_die_ref dwarf_proc
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
17074 int *stack_usage
= dwarf_proc_stack_usage_map
->get (dwarf_proc
);
17076 if (stack_usage
== NULL
)
17078 frame_offset_
+= *stack_usage
;
17082 case DW_OP_implicit_pointer
:
17083 case DW_OP_entry_value
:
17084 case DW_OP_const_type
:
17085 case DW_OP_regval_type
:
17086 case DW_OP_deref_type
:
17087 case DW_OP_convert
:
17088 case DW_OP_reinterpret
:
17089 case DW_OP_form_tls_address
:
17090 case DW_OP_GNU_push_tls_address
:
17091 case DW_OP_GNU_uninit
:
17092 case DW_OP_GNU_encoded_addr
:
17093 case DW_OP_GNU_implicit_pointer
:
17094 case DW_OP_GNU_entry_value
:
17095 case DW_OP_GNU_const_type
:
17096 case DW_OP_GNU_regval_type
:
17097 case DW_OP_GNU_deref_type
:
17098 case DW_OP_GNU_convert
:
17099 case DW_OP_GNU_reinterpret
:
17100 case DW_OP_GNU_parameter_ref
:
17101 /* loc_list_from_tree will probably not output these operations for
17102 size functions, so assume they will not appear here. */
17103 /* Fall through... */
17106 gcc_unreachable ();
17109 /* Now, follow the control flow (except subroutine calls). */
17110 switch (l
->dw_loc_opc
)
17113 if (!resolve_args_picking_1 (l
->dw_loc_next
, frame_offset_
, dpi
,
17116 /* Fall through. */
17119 l
= l
->dw_loc_oprnd1
.v
.val_loc
;
17122 case DW_OP_stack_value
:
17126 l
= l
->dw_loc_next
;
17134 /* Make a DFS over operations reachable through LOC (i.e. follow branch
17135 operations) in order to resolve the operand of DW_OP_pick operations that
17136 target DWARF procedure arguments (DPI). INITIAL_FRAME_OFFSET is the frame
17137 offset *before* LOC is executed. Return if all relocations were
17141 resolve_args_picking (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
17142 struct dwarf_procedure_info
*dpi
)
17144 /* Associate to all visited operations the frame offset *before* evaluating
17146 hash_map
<dw_loc_descr_ref
, unsigned> frame_offsets
;
17148 return resolve_args_picking_1 (loc
, initial_frame_offset
, dpi
,
17152 /* Try to generate a DWARF procedure that computes the same result as FNDECL.
17153 Return NULL if it is not possible. */
17156 function_to_dwarf_procedure (tree fndecl
)
17158 struct loc_descr_context ctx
;
17159 struct dwarf_procedure_info dpi
;
17160 dw_die_ref dwarf_proc_die
;
17161 tree tree_body
= DECL_SAVED_TREE (fndecl
);
17162 dw_loc_descr_ref loc_body
, epilogue
;
17167 /* Do not generate multiple DWARF procedures for the same function
17169 dwarf_proc_die
= lookup_decl_die (fndecl
);
17170 if (dwarf_proc_die
!= NULL
)
17171 return dwarf_proc_die
;
17173 /* DWARF procedures are available starting with the DWARFv3 standard. */
17174 if (dwarf_version
< 3 && dwarf_strict
)
17177 /* We handle only functions for which we still have a body, that return a
17178 supported type and that takes arguments with supported types. Note that
17179 there is no point translating functions that return nothing. */
17180 if (tree_body
== NULL_TREE
17181 || DECL_RESULT (fndecl
) == NULL_TREE
17182 || !is_handled_procedure_type (TREE_TYPE (DECL_RESULT (fndecl
))))
17185 for (cursor
= DECL_ARGUMENTS (fndecl
);
17186 cursor
!= NULL_TREE
;
17187 cursor
= TREE_CHAIN (cursor
))
17188 if (!is_handled_procedure_type (TREE_TYPE (cursor
)))
17191 /* Match only "expr" in: RETURN_EXPR (MODIFY_EXPR (RESULT_DECL, expr)). */
17192 if (TREE_CODE (tree_body
) != RETURN_EXPR
)
17194 tree_body
= TREE_OPERAND (tree_body
, 0);
17195 if (TREE_CODE (tree_body
) != MODIFY_EXPR
17196 || TREE_OPERAND (tree_body
, 0) != DECL_RESULT (fndecl
))
17198 tree_body
= TREE_OPERAND (tree_body
, 1);
17200 /* Try to translate the body expression itself. Note that this will probably
17201 cause an infinite recursion if its call graph has a cycle. This is very
17202 unlikely for size functions, however, so don't bother with such things at
17204 ctx
.context_type
= NULL_TREE
;
17205 ctx
.base_decl
= NULL_TREE
;
17207 ctx
.placeholder_arg
= false;
17208 ctx
.placeholder_seen
= false;
17209 dpi
.fndecl
= fndecl
;
17210 dpi
.args_count
= list_length (DECL_ARGUMENTS (fndecl
));
17211 loc_body
= loc_descriptor_from_tree (tree_body
, 0, &ctx
);
17215 /* After evaluating all operands in "loc_body", we should still have on the
17216 stack all arguments plus the desired function result (top of the stack).
17217 Generate code in order to keep only the result in our stack frame. */
17219 for (i
= 0; i
< dpi
.args_count
; ++i
)
17221 dw_loc_descr_ref op_couple
= new_loc_descr (DW_OP_swap
, 0, 0);
17222 op_couple
->dw_loc_next
= new_loc_descr (DW_OP_drop
, 0, 0);
17223 op_couple
->dw_loc_next
->dw_loc_next
= epilogue
;
17224 epilogue
= op_couple
;
17226 add_loc_descr (&loc_body
, epilogue
);
17227 if (!resolve_args_picking (loc_body
, dpi
.args_count
, &dpi
))
17230 /* Trailing nops from loc_descriptor_from_tree (if any) cannot be removed
17231 because they are considered useful. Now there is an epilogue, they are
17232 not anymore, so give it another try. */
17233 loc_descr_without_nops (loc_body
);
17235 /* fndecl may be used both as a regular DW_TAG_subprogram DIE and as
17236 a DW_TAG_dwarf_procedure, so we may have a conflict, here. It's unlikely,
17237 though, given that size functions do not come from source, so they should
17238 not have a dedicated DW_TAG_subprogram DIE. */
17240 = new_dwarf_proc_die (loc_body
, fndecl
,
17241 get_context_die (DECL_CONTEXT (fndecl
)));
17243 /* The called DWARF procedure consumes one stack slot per argument and
17244 returns one stack slot. */
17245 dwarf_proc_stack_usage_map
->put (dwarf_proc_die
, 1 - dpi
.args_count
);
17247 return dwarf_proc_die
;
17251 /* Generate Dwarf location list representing LOC.
17252 If WANT_ADDRESS is false, expression computing LOC will be computed
17253 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
17254 if WANT_ADDRESS is 2, expression computing address useable in location
17255 will be returned (i.e. DW_OP_reg can be used
17256 to refer to register values).
17258 CONTEXT provides information to customize the location descriptions
17259 generation. Its context_type field specifies what type is implicitly
17260 referenced by DW_OP_push_object_address. If it is NULL_TREE, this operation
17261 will not be generated.
17263 Its DPI field determines whether we are generating a DWARF expression for a
17264 DWARF procedure, so PARM_DECL references are processed specifically.
17266 If CONTEXT is NULL, the behavior is the same as if context_type, base_decl
17267 and dpi fields were null. */
17269 static dw_loc_list_ref
17270 loc_list_from_tree_1 (tree loc
, int want_address
,
17271 struct loc_descr_context
*context
)
17273 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
17274 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
17275 int have_address
= 0;
17276 enum dwarf_location_atom op
;
17278 /* ??? Most of the time we do not take proper care for sign/zero
17279 extending the values properly. Hopefully this won't be a real
17282 if (context
!= NULL
17283 && context
->base_decl
== loc
17284 && want_address
== 0)
17286 if (dwarf_version
>= 3 || !dwarf_strict
)
17287 return new_loc_list (new_loc_descr (DW_OP_push_object_address
, 0, 0),
17293 switch (TREE_CODE (loc
))
17296 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
17299 case PLACEHOLDER_EXPR
:
17300 /* This case involves extracting fields from an object to determine the
17301 position of other fields. It is supposed to appear only as the first
17302 operand of COMPONENT_REF nodes and to reference precisely the type
17303 that the context allows. */
17304 if (context
!= NULL
17305 && TREE_TYPE (loc
) == context
->context_type
17306 && want_address
>= 1)
17308 if (dwarf_version
>= 3 || !dwarf_strict
)
17310 ret
= new_loc_descr (DW_OP_push_object_address
, 0, 0);
17317 /* For DW_TAG_generic_subrange attributes, PLACEHOLDER_EXPR stands for
17318 the single argument passed by consumer. */
17319 else if (context
!= NULL
17320 && context
->placeholder_arg
17321 && INTEGRAL_TYPE_P (TREE_TYPE (loc
))
17322 && want_address
== 0)
17324 ret
= new_loc_descr (DW_OP_pick
, 0, 0);
17325 ret
->frame_offset_rel
= 1;
17326 context
->placeholder_seen
= true;
17330 expansion_failed (loc
, NULL_RTX
,
17331 "PLACEHOLDER_EXPR for an unexpected type");
17336 const int nargs
= call_expr_nargs (loc
);
17337 tree callee
= get_callee_fndecl (loc
);
17339 dw_die_ref dwarf_proc
;
17341 if (callee
== NULL_TREE
)
17342 goto call_expansion_failed
;
17344 /* We handle only functions that return an integer. */
17345 if (!is_handled_procedure_type (TREE_TYPE (TREE_TYPE (callee
))))
17346 goto call_expansion_failed
;
17348 dwarf_proc
= function_to_dwarf_procedure (callee
);
17349 if (dwarf_proc
== NULL
)
17350 goto call_expansion_failed
;
17352 /* Evaluate arguments right-to-left so that the first argument will
17353 be the top-most one on the stack. */
17354 for (i
= nargs
- 1; i
>= 0; --i
)
17356 dw_loc_descr_ref loc_descr
17357 = loc_descriptor_from_tree (CALL_EXPR_ARG (loc
, i
), 0,
17360 if (loc_descr
== NULL
)
17361 goto call_expansion_failed
;
17363 add_loc_descr (&ret
, loc_descr
);
17366 ret1
= new_loc_descr (DW_OP_call4
, 0, 0);
17367 ret1
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
17368 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.die
= dwarf_proc
;
17369 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
17370 add_loc_descr (&ret
, ret1
);
17373 call_expansion_failed
:
17374 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
17375 /* There are no opcodes for these operations. */
17379 case PREINCREMENT_EXPR
:
17380 case PREDECREMENT_EXPR
:
17381 case POSTINCREMENT_EXPR
:
17382 case POSTDECREMENT_EXPR
:
17383 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
17384 /* There are no opcodes for these operations. */
17388 /* If we already want an address, see if there is INDIRECT_REF inside
17389 e.g. for &this->field. */
17392 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
17393 (loc
, want_address
== 2, context
);
17396 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
17397 && (ret
= cst_pool_loc_descr (loc
)))
17400 /* Otherwise, process the argument and look for the address. */
17401 if (!list_ret
&& !ret
)
17402 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 1, context
);
17406 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
17412 if (DECL_THREAD_LOCAL_P (loc
))
17415 enum dwarf_location_atom tls_op
;
17416 enum dtprel_bool dtprel
= dtprel_false
;
17418 if (targetm
.have_tls
)
17420 /* If this is not defined, we have no way to emit the
17422 if (!targetm
.asm_out
.output_dwarf_dtprel
)
17425 /* The way DW_OP_GNU_push_tls_address is specified, we
17426 can only look up addresses of objects in the current
17427 module. We used DW_OP_addr as first op, but that's
17428 wrong, because DW_OP_addr is relocated by the debug
17429 info consumer, while DW_OP_GNU_push_tls_address
17430 operand shouldn't be. */
17431 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
17433 dtprel
= dtprel_true
;
17434 /* We check for DWARF 5 here because gdb did not implement
17435 DW_OP_form_tls_address until after 7.12. */
17436 tls_op
= (dwarf_version
>= 5 ? DW_OP_form_tls_address
17437 : DW_OP_GNU_push_tls_address
);
17441 if (!targetm
.emutls
.debug_form_tls_address
17442 || !(dwarf_version
>= 3 || !dwarf_strict
))
17444 /* We stuffed the control variable into the DECL_VALUE_EXPR
17445 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
17446 no longer appear in gimple code. We used the control
17447 variable in specific so that we could pick it up here. */
17448 loc
= DECL_VALUE_EXPR (loc
);
17449 tls_op
= DW_OP_form_tls_address
;
17452 rtl
= rtl_for_decl_location (loc
);
17453 if (rtl
== NULL_RTX
)
17458 rtl
= XEXP (rtl
, 0);
17459 if (! CONSTANT_P (rtl
))
17462 ret
= new_addr_loc_descr (rtl
, dtprel
);
17463 ret1
= new_loc_descr (tls_op
, 0, 0);
17464 add_loc_descr (&ret
, ret1
);
17472 if (context
!= NULL
&& context
->dpi
!= NULL
17473 && DECL_CONTEXT (loc
) == context
->dpi
->fndecl
)
17475 /* We are generating code for a DWARF procedure and we want to access
17476 one of its arguments: find the appropriate argument offset and let
17477 the resolve_args_picking pass compute the offset that complies
17478 with the stack frame size. */
17482 for (cursor
= DECL_ARGUMENTS (context
->dpi
->fndecl
);
17483 cursor
!= NULL_TREE
&& cursor
!= loc
;
17484 cursor
= TREE_CHAIN (cursor
), ++i
)
17486 /* If we are translating a DWARF procedure, all referenced parameters
17487 must belong to the current function. */
17488 gcc_assert (cursor
!= NULL_TREE
);
17490 ret
= new_loc_descr (DW_OP_pick
, i
, 0);
17491 ret
->frame_offset_rel
= 1;
17497 if (DECL_HAS_VALUE_EXPR_P (loc
))
17498 return loc_list_from_tree_1 (DECL_VALUE_EXPR (loc
),
17499 want_address
, context
);
17502 case FUNCTION_DECL
:
17505 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
17507 if (loc_list
&& loc_list
->first
)
17509 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
17510 have_address
= want_address
!= 0;
17513 rtl
= rtl_for_decl_location (loc
);
17514 if (rtl
== NULL_RTX
)
17516 if (TREE_CODE (loc
) != FUNCTION_DECL
17518 && current_function_decl
17519 && want_address
!= 1
17520 && ! DECL_IGNORED_P (loc
)
17521 && (INTEGRAL_TYPE_P (TREE_TYPE (loc
))
17522 || POINTER_TYPE_P (TREE_TYPE (loc
)))
17523 && DECL_CONTEXT (loc
) == current_function_decl
17524 && (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (loc
)))
17525 <= DWARF2_ADDR_SIZE
))
17527 dw_die_ref ref
= lookup_decl_die (loc
);
17528 ret
= new_loc_descr (DW_OP_GNU_variable_value
, 0, 0);
17531 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
17532 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
17533 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
17537 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
17538 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= loc
;
17542 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
17545 else if (CONST_INT_P (rtl
))
17547 HOST_WIDE_INT val
= INTVAL (rtl
);
17548 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
17549 val
&= GET_MODE_MASK (DECL_MODE (loc
));
17550 ret
= int_loc_descriptor (val
);
17552 else if (GET_CODE (rtl
) == CONST_STRING
)
17554 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
17557 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
17558 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
17561 machine_mode mode
, mem_mode
;
17563 /* Certain constructs can only be represented at top-level. */
17564 if (want_address
== 2)
17566 ret
= loc_descriptor (rtl
, VOIDmode
,
17567 VAR_INIT_STATUS_INITIALIZED
);
17572 mode
= GET_MODE (rtl
);
17573 mem_mode
= VOIDmode
;
17577 mode
= get_address_mode (rtl
);
17578 rtl
= XEXP (rtl
, 0);
17581 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
17582 VAR_INIT_STATUS_INITIALIZED
);
17585 expansion_failed (loc
, rtl
,
17586 "failed to produce loc descriptor for rtl");
17592 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
17599 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17603 case TARGET_MEM_REF
:
17605 case DEBUG_EXPR_DECL
:
17608 case COMPOUND_EXPR
:
17609 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), want_address
,
17613 case VIEW_CONVERT_EXPR
:
17616 case NON_LVALUE_EXPR
:
17617 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), want_address
,
17620 case COMPONENT_REF
:
17621 case BIT_FIELD_REF
:
17623 case ARRAY_RANGE_REF
:
17624 case REALPART_EXPR
:
17625 case IMAGPART_EXPR
:
17628 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
17630 int unsignedp
, reversep
, volatilep
= 0;
17632 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
17633 &unsignedp
, &reversep
, &volatilep
);
17635 gcc_assert (obj
!= loc
);
17637 list_ret
= loc_list_from_tree_1 (obj
,
17639 && !bitpos
&& !offset
? 2 : 1,
17641 /* TODO: We can extract value of the small expression via shifting even
17642 for nonzero bitpos. */
17645 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
17647 expansion_failed (loc
, NULL_RTX
,
17648 "bitfield access");
17652 if (offset
!= NULL_TREE
)
17654 /* Variable offset. */
17655 list_ret1
= loc_list_from_tree_1 (offset
, 0, context
);
17656 if (list_ret1
== 0)
17658 add_loc_list (&list_ret
, list_ret1
);
17661 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
17664 bytepos
= bitpos
/ BITS_PER_UNIT
;
17666 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
17667 else if (bytepos
< 0)
17668 loc_list_plus_const (list_ret
, bytepos
);
17675 if ((want_address
|| !tree_fits_shwi_p (loc
))
17676 && (ret
= cst_pool_loc_descr (loc
)))
17678 else if (want_address
== 2
17679 && tree_fits_shwi_p (loc
)
17680 && (ret
= address_of_int_loc_descriptor
17681 (int_size_in_bytes (TREE_TYPE (loc
)),
17682 tree_to_shwi (loc
))))
17684 else if (tree_fits_shwi_p (loc
))
17685 ret
= int_loc_descriptor (tree_to_shwi (loc
));
17686 else if (tree_fits_uhwi_p (loc
))
17687 ret
= uint_loc_descriptor (tree_to_uhwi (loc
));
17690 expansion_failed (loc
, NULL_RTX
,
17691 "Integer operand is not host integer");
17700 if ((ret
= cst_pool_loc_descr (loc
)))
17702 else if (TREE_CODE (loc
) == CONSTRUCTOR
)
17704 tree type
= TREE_TYPE (loc
);
17705 unsigned HOST_WIDE_INT size
= int_size_in_bytes (type
);
17706 unsigned HOST_WIDE_INT offset
= 0;
17707 unsigned HOST_WIDE_INT cnt
;
17708 constructor_elt
*ce
;
17710 if (TREE_CODE (type
) == RECORD_TYPE
)
17712 /* This is very limited, but it's enough to output
17713 pointers to member functions, as long as the
17714 referenced function is defined in the current
17715 translation unit. */
17716 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (loc
), cnt
, ce
)
17718 tree val
= ce
->value
;
17720 tree field
= ce
->index
;
17725 if (!field
|| DECL_BIT_FIELD (field
))
17727 expansion_failed (loc
, NULL_RTX
,
17728 "bitfield in record type constructor");
17729 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
17734 HOST_WIDE_INT fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
17735 unsigned HOST_WIDE_INT pos
= int_byte_position (field
);
17736 gcc_assert (pos
+ fieldsize
<= size
);
17739 expansion_failed (loc
, NULL_RTX
,
17740 "out-of-order fields in record constructor");
17741 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
17747 ret1
= new_loc_descr (DW_OP_piece
, pos
- offset
, 0);
17748 add_loc_descr (&ret
, ret1
);
17751 if (val
&& fieldsize
!= 0)
17753 ret1
= loc_descriptor_from_tree (val
, want_address
, context
);
17756 expansion_failed (loc
, NULL_RTX
,
17757 "unsupported expression in field");
17758 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
17762 add_loc_descr (&ret
, ret1
);
17766 ret1
= new_loc_descr (DW_OP_piece
, fieldsize
, 0);
17767 add_loc_descr (&ret
, ret1
);
17768 offset
= pos
+ fieldsize
;
17772 if (offset
!= size
)
17774 ret1
= new_loc_descr (DW_OP_piece
, size
- offset
, 0);
17775 add_loc_descr (&ret
, ret1
);
17779 have_address
= !!want_address
;
17782 expansion_failed (loc
, NULL_RTX
,
17783 "constructor of non-record type");
17786 /* We can construct small constants here using int_loc_descriptor. */
17787 expansion_failed (loc
, NULL_RTX
,
17788 "constructor or constant not in constant pool");
17791 case TRUTH_AND_EXPR
:
17792 case TRUTH_ANDIF_EXPR
:
17797 case TRUTH_XOR_EXPR
:
17802 case TRUTH_OR_EXPR
:
17803 case TRUTH_ORIF_EXPR
:
17808 case FLOOR_DIV_EXPR
:
17809 case CEIL_DIV_EXPR
:
17810 case ROUND_DIV_EXPR
:
17811 case TRUNC_DIV_EXPR
:
17812 case EXACT_DIV_EXPR
:
17813 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
17822 case FLOOR_MOD_EXPR
:
17823 case CEIL_MOD_EXPR
:
17824 case ROUND_MOD_EXPR
:
17825 case TRUNC_MOD_EXPR
:
17826 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
17831 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17832 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
17833 if (list_ret
== 0 || list_ret1
== 0)
17836 add_loc_list (&list_ret
, list_ret1
);
17839 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
17840 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
17841 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
17842 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
17843 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
17855 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
17858 case POINTER_PLUS_EXPR
:
17861 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
17863 /* Big unsigned numbers can fit in HOST_WIDE_INT but it may be
17864 smarter to encode their opposite. The DW_OP_plus_uconst operation
17865 takes 1 + X bytes, X being the size of the ULEB128 addend. On the
17866 other hand, a "<push literal>; DW_OP_minus" pattern takes 1 + Y
17867 bytes, Y being the size of the operation that pushes the opposite
17868 of the addend. So let's choose the smallest representation. */
17869 const tree tree_addend
= TREE_OPERAND (loc
, 1);
17870 offset_int wi_addend
;
17871 HOST_WIDE_INT shwi_addend
;
17872 dw_loc_descr_ref loc_naddend
;
17874 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17878 /* Try to get the literal to push. It is the opposite of the addend,
17879 so as we rely on wrapping during DWARF evaluation, first decode
17880 the literal as a "DWARF-sized" signed number. */
17881 wi_addend
= wi::to_offset (tree_addend
);
17882 wi_addend
= wi::sext (wi_addend
, DWARF2_ADDR_SIZE
* 8);
17883 shwi_addend
= wi_addend
.to_shwi ();
17884 loc_naddend
= (shwi_addend
!= INTTYPE_MINIMUM (HOST_WIDE_INT
))
17885 ? int_loc_descriptor (-shwi_addend
)
17888 if (loc_naddend
!= NULL
17889 && ((unsigned) size_of_uleb128 (shwi_addend
)
17890 > size_of_loc_descr (loc_naddend
)))
17892 add_loc_descr_to_each (list_ret
, loc_naddend
);
17893 add_loc_descr_to_each (list_ret
,
17894 new_loc_descr (DW_OP_minus
, 0, 0));
17898 for (dw_loc_descr_ref loc_cur
= loc_naddend
; loc_cur
!= NULL
; )
17900 loc_naddend
= loc_cur
;
17901 loc_cur
= loc_cur
->dw_loc_next
;
17902 ggc_free (loc_naddend
);
17904 loc_list_plus_const (list_ret
, wi_addend
.to_shwi ());
17914 goto do_comp_binop
;
17918 goto do_comp_binop
;
17922 goto do_comp_binop
;
17926 goto do_comp_binop
;
17929 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
17931 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
17932 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
17933 list_ret
= loc_list_from_uint_comparison (list_ret
, list_ret1
,
17949 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17950 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
17951 if (list_ret
== 0 || list_ret1
== 0)
17954 add_loc_list (&list_ret
, list_ret1
);
17957 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
17960 case TRUTH_NOT_EXPR
:
17974 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17978 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
17984 const enum tree_code code
=
17985 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
17987 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
17988 build2 (code
, integer_type_node
,
17989 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
17990 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
17997 dw_loc_descr_ref lhs
17998 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
17999 dw_loc_list_ref rhs
18000 = loc_list_from_tree_1 (TREE_OPERAND (loc
, 2), 0, context
);
18001 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
18003 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
18004 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
18007 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
18008 add_loc_descr_to_each (list_ret
, bra_node
);
18010 add_loc_list (&list_ret
, rhs
);
18011 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
18012 add_loc_descr_to_each (list_ret
, jump_node
);
18014 add_loc_descr_to_each (list_ret
, lhs
);
18015 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
18016 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
18018 /* ??? Need a node to point the skip at. Use a nop. */
18019 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
18020 add_loc_descr_to_each (list_ret
, tmp
);
18021 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
18022 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
18026 case FIX_TRUNC_EXPR
:
18030 /* Leave front-end specific codes as simply unknown. This comes
18031 up, for instance, with the C STMT_EXPR. */
18032 if ((unsigned int) TREE_CODE (loc
)
18033 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
18035 expansion_failed (loc
, NULL_RTX
,
18036 "language specific tree node");
18040 /* Otherwise this is a generic code; we should just lists all of
18041 these explicitly. We forgot one. */
18043 gcc_unreachable ();
18045 /* In a release build, we want to degrade gracefully: better to
18046 generate incomplete debugging information than to crash. */
18050 if (!ret
&& !list_ret
)
18053 if (want_address
== 2 && !have_address
18054 && (dwarf_version
>= 4 || !dwarf_strict
))
18056 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
18058 expansion_failed (loc
, NULL_RTX
,
18059 "DWARF address size mismatch");
18063 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
18065 add_loc_descr_to_each (list_ret
,
18066 new_loc_descr (DW_OP_stack_value
, 0, 0));
18069 /* Show if we can't fill the request for an address. */
18070 if (want_address
&& !have_address
)
18072 expansion_failed (loc
, NULL_RTX
,
18073 "Want address and only have value");
18077 gcc_assert (!ret
|| !list_ret
);
18079 /* If we've got an address and don't want one, dereference. */
18080 if (!want_address
&& have_address
)
18082 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
18084 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
18086 expansion_failed (loc
, NULL_RTX
,
18087 "DWARF address size mismatch");
18090 else if (size
== DWARF2_ADDR_SIZE
)
18093 op
= DW_OP_deref_size
;
18096 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
18098 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
18101 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
18106 /* Likewise, but strip useless DW_OP_nop operations in the resulting
18109 static dw_loc_list_ref
18110 loc_list_from_tree (tree loc
, int want_address
,
18111 struct loc_descr_context
*context
)
18113 dw_loc_list_ref result
= loc_list_from_tree_1 (loc
, want_address
, context
);
18115 for (dw_loc_list_ref loc_cur
= result
;
18116 loc_cur
!= NULL
; loc_cur
= loc_cur
->dw_loc_next
)
18117 loc_descr_without_nops (loc_cur
->expr
);
18121 /* Same as above but return only single location expression. */
18122 static dw_loc_descr_ref
18123 loc_descriptor_from_tree (tree loc
, int want_address
,
18124 struct loc_descr_context
*context
)
18126 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
, context
);
18129 if (ret
->dw_loc_next
)
18131 expansion_failed (loc
, NULL_RTX
,
18132 "Location list where only loc descriptor needed");
18138 /* Given a value, round it up to the lowest multiple of `boundary'
18139 which is not less than the value itself. */
18141 static inline HOST_WIDE_INT
18142 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
18144 return (((value
+ boundary
- 1) / boundary
) * boundary
);
18147 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
18148 pointer to the declared type for the relevant field variable, or return
18149 `integer_type_node' if the given node turns out to be an
18150 ERROR_MARK node. */
18153 field_type (const_tree decl
)
18157 if (TREE_CODE (decl
) == ERROR_MARK
)
18158 return integer_type_node
;
18160 type
= DECL_BIT_FIELD_TYPE (decl
);
18161 if (type
== NULL_TREE
)
18162 type
= TREE_TYPE (decl
);
18167 /* Given a pointer to a tree node, return the alignment in bits for
18168 it, or else return BITS_PER_WORD if the node actually turns out to
18169 be an ERROR_MARK node. */
18171 static inline unsigned
18172 simple_type_align_in_bits (const_tree type
)
18174 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
18177 static inline unsigned
18178 simple_decl_align_in_bits (const_tree decl
)
18180 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
18183 /* Return the result of rounding T up to ALIGN. */
18185 static inline offset_int
18186 round_up_to_align (const offset_int
&t
, unsigned int align
)
18188 return wi::udiv_trunc (t
+ align
- 1, align
) * align
;
18191 /* Compute the size of TYPE in bytes. If possible, return NULL and store the
18192 size as an integer constant in CST_SIZE. Otherwise, if possible, return a
18193 DWARF expression that computes the size. Return NULL and set CST_SIZE to -1
18194 if we fail to return the size in one of these two forms. */
18196 static dw_loc_descr_ref
18197 type_byte_size (const_tree type
, HOST_WIDE_INT
*cst_size
)
18200 struct loc_descr_context ctx
;
18202 /* Return a constant integer in priority, if possible. */
18203 *cst_size
= int_size_in_bytes (type
);
18204 if (*cst_size
!= -1)
18207 ctx
.context_type
= const_cast<tree
> (type
);
18208 ctx
.base_decl
= NULL_TREE
;
18210 ctx
.placeholder_arg
= false;
18211 ctx
.placeholder_seen
= false;
18213 type
= TYPE_MAIN_VARIANT (type
);
18214 tree_size
= TYPE_SIZE_UNIT (type
);
18215 return ((tree_size
!= NULL_TREE
)
18216 ? loc_descriptor_from_tree (tree_size
, 0, &ctx
)
18220 /* Helper structure for RECORD_TYPE processing. */
18223 /* Root RECORD_TYPE. It is needed to generate data member location
18224 descriptions in variable-length records (VLR), but also to cope with
18225 variants, which are composed of nested structures multiplexed with
18226 QUAL_UNION_TYPE nodes. Each time such a structure is passed to a
18227 function processing a FIELD_DECL, it is required to be non null. */
18229 /* When generating a variant part in a RECORD_TYPE (i.e. a nested
18230 QUAL_UNION_TYPE), this holds an expression that computes the offset for
18231 this variant part as part of the root record (in storage units). For
18232 regular records, it must be NULL_TREE. */
18233 tree variant_part_offset
;
18236 /* Given a pointer to a FIELD_DECL, compute the byte offset of the lowest
18237 addressed byte of the "containing object" for the given FIELD_DECL. If
18238 possible, return a native constant through CST_OFFSET (in which case NULL is
18239 returned); otherwise return a DWARF expression that computes the offset.
18241 Set *CST_OFFSET to 0 and return NULL if we are unable to determine what
18242 that offset is, either because the argument turns out to be a pointer to an
18243 ERROR_MARK node, or because the offset expression is too complex for us.
18245 CTX is required: see the comment for VLR_CONTEXT. */
18247 static dw_loc_descr_ref
18248 field_byte_offset (const_tree decl
, struct vlr_context
*ctx
,
18249 HOST_WIDE_INT
*cst_offset
)
18252 dw_loc_list_ref loc_result
;
18256 if (TREE_CODE (decl
) == ERROR_MARK
)
18259 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
18261 /* We cannot handle variable bit offsets at the moment, so abort if it's the
18263 if (TREE_CODE (DECL_FIELD_BIT_OFFSET (decl
)) != INTEGER_CST
)
18266 #ifdef PCC_BITFIELD_TYPE_MATTERS
18267 /* We used to handle only constant offsets in all cases. Now, we handle
18268 properly dynamic byte offsets only when PCC bitfield type doesn't
18270 if (PCC_BITFIELD_TYPE_MATTERS
18271 && TREE_CODE (DECL_FIELD_OFFSET (decl
)) == INTEGER_CST
)
18273 offset_int object_offset_in_bits
;
18274 offset_int object_offset_in_bytes
;
18275 offset_int bitpos_int
;
18277 tree field_size_tree
;
18278 offset_int deepest_bitpos
;
18279 offset_int field_size_in_bits
;
18280 unsigned int type_align_in_bits
;
18281 unsigned int decl_align_in_bits
;
18282 offset_int type_size_in_bits
;
18284 bitpos_int
= wi::to_offset (bit_position (decl
));
18285 type
= field_type (decl
);
18286 type_size_in_bits
= offset_int_type_size_in_bits (type
);
18287 type_align_in_bits
= simple_type_align_in_bits (type
);
18289 field_size_tree
= DECL_SIZE (decl
);
18291 /* The size could be unspecified if there was an error, or for
18292 a flexible array member. */
18293 if (!field_size_tree
)
18294 field_size_tree
= bitsize_zero_node
;
18296 /* If the size of the field is not constant, use the type size. */
18297 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
18298 field_size_in_bits
= wi::to_offset (field_size_tree
);
18300 field_size_in_bits
= type_size_in_bits
;
18302 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
18304 /* The GCC front-end doesn't make any attempt to keep track of the
18305 starting bit offset (relative to the start of the containing
18306 structure type) of the hypothetical "containing object" for a
18307 bit-field. Thus, when computing the byte offset value for the
18308 start of the "containing object" of a bit-field, we must deduce
18309 this information on our own. This can be rather tricky to do in
18310 some cases. For example, handling the following structure type
18311 definition when compiling for an i386/i486 target (which only
18312 aligns long long's to 32-bit boundaries) can be very tricky:
18314 struct S { int field1; long long field2:31; };
18316 Fortunately, there is a simple rule-of-thumb which can be used
18317 in such cases. When compiling for an i386/i486, GCC will
18318 allocate 8 bytes for the structure shown above. It decides to
18319 do this based upon one simple rule for bit-field allocation.
18320 GCC allocates each "containing object" for each bit-field at
18321 the first (i.e. lowest addressed) legitimate alignment boundary
18322 (based upon the required minimum alignment for the declared
18323 type of the field) which it can possibly use, subject to the
18324 condition that there is still enough available space remaining
18325 in the containing object (when allocated at the selected point)
18326 to fully accommodate all of the bits of the bit-field itself.
18328 This simple rule makes it obvious why GCC allocates 8 bytes for
18329 each object of the structure type shown above. When looking
18330 for a place to allocate the "containing object" for `field2',
18331 the compiler simply tries to allocate a 64-bit "containing
18332 object" at each successive 32-bit boundary (starting at zero)
18333 until it finds a place to allocate that 64- bit field such that
18334 at least 31 contiguous (and previously unallocated) bits remain
18335 within that selected 64 bit field. (As it turns out, for the
18336 example above, the compiler finds it is OK to allocate the
18337 "containing object" 64-bit field at bit-offset zero within the
18340 Here we attempt to work backwards from the limited set of facts
18341 we're given, and we try to deduce from those facts, where GCC
18342 must have believed that the containing object started (within
18343 the structure type). The value we deduce is then used (by the
18344 callers of this routine) to generate DW_AT_location and
18345 DW_AT_bit_offset attributes for fields (both bit-fields and, in
18346 the case of DW_AT_location, regular fields as well). */
18348 /* Figure out the bit-distance from the start of the structure to
18349 the "deepest" bit of the bit-field. */
18350 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
18352 /* This is the tricky part. Use some fancy footwork to deduce
18353 where the lowest addressed bit of the containing object must
18355 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
18357 /* Round up to type_align by default. This works best for
18359 object_offset_in_bits
18360 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
18362 if (wi::gtu_p (object_offset_in_bits
, bitpos_int
))
18364 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
18366 /* Round up to decl_align instead. */
18367 object_offset_in_bits
18368 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
18371 object_offset_in_bytes
18372 = wi::lrshift (object_offset_in_bits
, LOG2_BITS_PER_UNIT
);
18373 if (ctx
->variant_part_offset
== NULL_TREE
)
18375 *cst_offset
= object_offset_in_bytes
.to_shwi ();
18378 tree_result
= wide_int_to_tree (sizetype
, object_offset_in_bytes
);
18381 #endif /* PCC_BITFIELD_TYPE_MATTERS */
18382 tree_result
= byte_position (decl
);
18384 if (ctx
->variant_part_offset
!= NULL_TREE
)
18385 tree_result
= fold_build2 (PLUS_EXPR
, TREE_TYPE (tree_result
),
18386 ctx
->variant_part_offset
, tree_result
);
18388 /* If the byte offset is a constant, it's simplier to handle a native
18389 constant rather than a DWARF expression. */
18390 if (TREE_CODE (tree_result
) == INTEGER_CST
)
18392 *cst_offset
= wi::to_offset (tree_result
).to_shwi ();
18395 struct loc_descr_context loc_ctx
= {
18396 ctx
->struct_type
, /* context_type */
18397 NULL_TREE
, /* base_decl */
18399 false, /* placeholder_arg */
18400 false /* placeholder_seen */
18402 loc_result
= loc_list_from_tree (tree_result
, 0, &loc_ctx
);
18404 /* We want a DWARF expression: abort if we only have a location list with
18405 multiple elements. */
18406 if (!loc_result
|| !single_element_loc_list_p (loc_result
))
18409 return loc_result
->expr
;
18412 /* The following routines define various Dwarf attributes and any data
18413 associated with them. */
18415 /* Add a location description attribute value to a DIE.
18417 This emits location attributes suitable for whole variables and
18418 whole parameters. Note that the location attributes for struct fields are
18419 generated by the routine `data_member_location_attribute' below. */
18422 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
18423 dw_loc_list_ref descr
)
18427 if (single_element_loc_list_p (descr
))
18428 add_AT_loc (die
, attr_kind
, descr
->expr
);
18430 add_AT_loc_list (die
, attr_kind
, descr
);
18433 /* Add DW_AT_accessibility attribute to DIE if needed. */
18436 add_accessibility_attribute (dw_die_ref die
, tree decl
)
18438 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
18439 children, otherwise the default is DW_ACCESS_public. In DWARF2
18440 the default has always been DW_ACCESS_public. */
18441 if (TREE_PROTECTED (decl
))
18442 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
18443 else if (TREE_PRIVATE (decl
))
18445 if (dwarf_version
== 2
18446 || die
->die_parent
== NULL
18447 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
18448 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
18450 else if (dwarf_version
> 2
18452 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
18453 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
18456 /* Attach the specialized form of location attribute used for data members of
18457 struct and union types. In the special case of a FIELD_DECL node which
18458 represents a bit-field, the "offset" part of this special location
18459 descriptor must indicate the distance in bytes from the lowest-addressed
18460 byte of the containing struct or union type to the lowest-addressed byte of
18461 the "containing object" for the bit-field. (See the `field_byte_offset'
18464 For any given bit-field, the "containing object" is a hypothetical object
18465 (of some integral or enum type) within which the given bit-field lives. The
18466 type of this hypothetical "containing object" is always the same as the
18467 declared type of the individual bit-field itself (for GCC anyway... the
18468 DWARF spec doesn't actually mandate this). Note that it is the size (in
18469 bytes) of the hypothetical "containing object" which will be given in the
18470 DW_AT_byte_size attribute for this bit-field. (See the
18471 `byte_size_attribute' function below.) It is also used when calculating the
18472 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
18475 CTX is required: see the comment for VLR_CONTEXT. */
18478 add_data_member_location_attribute (dw_die_ref die
,
18480 struct vlr_context
*ctx
)
18482 HOST_WIDE_INT offset
;
18483 dw_loc_descr_ref loc_descr
= 0;
18485 if (TREE_CODE (decl
) == TREE_BINFO
)
18487 /* We're working on the TAG_inheritance for a base class. */
18488 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
18490 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
18491 aren't at a fixed offset from all (sub)objects of the same
18492 type. We need to extract the appropriate offset from our
18493 vtable. The following dwarf expression means
18495 BaseAddr = ObAddr + *((*ObAddr) - Offset)
18497 This is specific to the V3 ABI, of course. */
18499 dw_loc_descr_ref tmp
;
18501 /* Make a copy of the object address. */
18502 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
18503 add_loc_descr (&loc_descr
, tmp
);
18505 /* Extract the vtable address. */
18506 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
18507 add_loc_descr (&loc_descr
, tmp
);
18509 /* Calculate the address of the offset. */
18510 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
18511 gcc_assert (offset
< 0);
18513 tmp
= int_loc_descriptor (-offset
);
18514 add_loc_descr (&loc_descr
, tmp
);
18515 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
18516 add_loc_descr (&loc_descr
, tmp
);
18518 /* Extract the offset. */
18519 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
18520 add_loc_descr (&loc_descr
, tmp
);
18522 /* Add it to the object address. */
18523 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
18524 add_loc_descr (&loc_descr
, tmp
);
18527 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
18531 loc_descr
= field_byte_offset (decl
, ctx
, &offset
);
18533 /* If loc_descr is available then we know the field offset is dynamic.
18534 However, GDB does not handle dynamic field offsets very well at the
18536 if (loc_descr
!= NULL
&& gnat_encodings
!= DWARF_GNAT_ENCODINGS_MINIMAL
)
18542 /* Data member location evalutation starts with the base address on the
18543 stack. Compute the field offset and add it to this base address. */
18544 else if (loc_descr
!= NULL
)
18545 add_loc_descr (&loc_descr
, new_loc_descr (DW_OP_plus
, 0, 0));
18550 /* While DW_AT_data_bit_offset has been added already in DWARF4,
18551 e.g. GDB only added support to it in November 2016. For DWARF5
18552 we need newer debug info consumers anyway. We might change this
18553 to dwarf_version >= 4 once most consumers catched up. */
18554 if (dwarf_version
>= 5
18555 && TREE_CODE (decl
) == FIELD_DECL
18556 && DECL_BIT_FIELD_TYPE (decl
))
18558 tree off
= bit_position (decl
);
18559 if (tree_fits_uhwi_p (off
) && get_AT (die
, DW_AT_bit_size
))
18561 remove_AT (die
, DW_AT_byte_size
);
18562 remove_AT (die
, DW_AT_bit_offset
);
18563 add_AT_unsigned (die
, DW_AT_data_bit_offset
, tree_to_uhwi (off
));
18567 if (dwarf_version
> 2)
18569 /* Don't need to output a location expression, just the constant. */
18571 add_AT_int (die
, DW_AT_data_member_location
, offset
);
18573 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
18578 enum dwarf_location_atom op
;
18580 /* The DWARF2 standard says that we should assume that the structure
18581 address is already on the stack, so we can specify a structure
18582 field address by using DW_OP_plus_uconst. */
18583 op
= DW_OP_plus_uconst
;
18584 loc_descr
= new_loc_descr (op
, offset
, 0);
18588 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
18591 /* Writes integer values to dw_vec_const array. */
18594 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
18598 *dest
++ = val
& 0xff;
18604 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
18606 static HOST_WIDE_INT
18607 extract_int (const unsigned char *src
, unsigned int size
)
18609 HOST_WIDE_INT val
= 0;
18615 val
|= *--src
& 0xff;
18621 /* Writes wide_int values to dw_vec_const array. */
18624 insert_wide_int (const wide_int
&val
, unsigned char *dest
, int elt_size
)
18628 if (elt_size
<= HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
)
18630 insert_int ((HOST_WIDE_INT
) val
.elt (0), elt_size
, dest
);
18634 /* We'd have to extend this code to support odd sizes. */
18635 gcc_assert (elt_size
% (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
) == 0);
18637 int n
= elt_size
/ (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
18639 if (WORDS_BIG_ENDIAN
)
18640 for (i
= n
- 1; i
>= 0; i
--)
18642 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
18643 dest
+= sizeof (HOST_WIDE_INT
);
18646 for (i
= 0; i
< n
; i
++)
18648 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
18649 dest
+= sizeof (HOST_WIDE_INT
);
18653 /* Writes floating point values to dw_vec_const array. */
18656 insert_float (const_rtx rtl
, unsigned char *array
)
18660 scalar_float_mode mode
= as_a
<scalar_float_mode
> (GET_MODE (rtl
));
18662 real_to_target (val
, CONST_DOUBLE_REAL_VALUE (rtl
), mode
);
18664 /* real_to_target puts 32-bit pieces in each long. Pack them. */
18665 for (i
= 0; i
< GET_MODE_SIZE (mode
) / 4; i
++)
18667 insert_int (val
[i
], 4, array
);
18672 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
18673 does not have a "location" either in memory or in a register. These
18674 things can arise in GNU C when a constant is passed as an actual parameter
18675 to an inlined function. They can also arise in C++ where declared
18676 constants do not necessarily get memory "homes". */
18679 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
18681 switch (GET_CODE (rtl
))
18685 HOST_WIDE_INT val
= INTVAL (rtl
);
18688 add_AT_int (die
, DW_AT_const_value
, val
);
18690 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
18694 case CONST_WIDE_INT
:
18696 wide_int w1
= rtx_mode_t (rtl
, MAX_MODE_INT
);
18697 unsigned int prec
= MIN (wi::min_precision (w1
, UNSIGNED
),
18698 (unsigned int)CONST_WIDE_INT_NUNITS (rtl
) * HOST_BITS_PER_WIDE_INT
);
18699 wide_int w
= wi::zext (w1
, prec
);
18700 add_AT_wide (die
, DW_AT_const_value
, w
);
18705 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
18706 floating-point constant. A CONST_DOUBLE is used whenever the
18707 constant requires more than one word in order to be adequately
18709 if (TARGET_SUPPORTS_WIDE_INT
== 0
18710 && !SCALAR_FLOAT_MODE_P (GET_MODE (rtl
)))
18711 add_AT_double (die
, DW_AT_const_value
,
18712 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
18715 scalar_float_mode mode
= as_a
<scalar_float_mode
> (GET_MODE (rtl
));
18716 unsigned int length
= GET_MODE_SIZE (mode
);
18717 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
18719 insert_float (rtl
, array
);
18720 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
18726 machine_mode mode
= GET_MODE (rtl
);
18727 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
18728 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
18729 unsigned char *array
18730 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
18733 machine_mode imode
= GET_MODE_INNER (mode
);
18735 switch (GET_MODE_CLASS (mode
))
18737 case MODE_VECTOR_INT
:
18738 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
18740 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
18741 insert_wide_int (rtx_mode_t (elt
, imode
), p
, elt_size
);
18745 case MODE_VECTOR_FLOAT
:
18746 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
18748 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
18749 insert_float (elt
, p
);
18754 gcc_unreachable ();
18757 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
18762 if (dwarf_version
>= 4 || !dwarf_strict
)
18764 dw_loc_descr_ref loc_result
;
18765 resolve_one_addr (&rtl
);
18767 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
18768 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
18769 add_AT_loc (die
, DW_AT_location
, loc_result
);
18770 vec_safe_push (used_rtx_array
, rtl
);
18776 if (CONSTANT_P (XEXP (rtl
, 0)))
18777 return add_const_value_attribute (die
, XEXP (rtl
, 0));
18780 if (!const_ok_for_output (rtl
))
18784 if (dwarf_version
>= 4 || !dwarf_strict
)
18789 /* In cases where an inlined instance of an inline function is passed
18790 the address of an `auto' variable (which is local to the caller) we
18791 can get a situation where the DECL_RTL of the artificial local
18792 variable (for the inlining) which acts as a stand-in for the
18793 corresponding formal parameter (of the inline function) will look
18794 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
18795 exactly a compile-time constant expression, but it isn't the address
18796 of the (artificial) local variable either. Rather, it represents the
18797 *value* which the artificial local variable always has during its
18798 lifetime. We currently have no way to represent such quasi-constant
18799 values in Dwarf, so for now we just punt and generate nothing. */
18807 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
18808 && MEM_READONLY_P (rtl
)
18809 && GET_MODE (rtl
) == BLKmode
)
18811 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
18817 /* No other kinds of rtx should be possible here. */
18818 gcc_unreachable ();
18823 /* Determine whether the evaluation of EXPR references any variables
18824 or functions which aren't otherwise used (and therefore may not be
18827 reference_to_unused (tree
* tp
, int * walk_subtrees
,
18828 void * data ATTRIBUTE_UNUSED
)
18830 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
18831 *walk_subtrees
= 0;
18833 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
18834 && ! TREE_ASM_WRITTEN (*tp
))
18836 /* ??? The C++ FE emits debug information for using decls, so
18837 putting gcc_unreachable here falls over. See PR31899. For now
18838 be conservative. */
18839 else if (!symtab
->global_info_ready
&& VAR_OR_FUNCTION_DECL_P (*tp
))
18841 else if (VAR_P (*tp
))
18843 varpool_node
*node
= varpool_node::get (*tp
);
18844 if (!node
|| !node
->definition
)
18847 else if (TREE_CODE (*tp
) == FUNCTION_DECL
18848 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
18850 /* The call graph machinery must have finished analyzing,
18851 optimizing and gimplifying the CU by now.
18852 So if *TP has no call graph node associated
18853 to it, it means *TP will not be emitted. */
18854 if (!cgraph_node::get (*tp
))
18857 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
18863 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
18864 for use in a later add_const_value_attribute call. */
18867 rtl_for_decl_init (tree init
, tree type
)
18869 rtx rtl
= NULL_RTX
;
18873 /* If a variable is initialized with a string constant without embedded
18874 zeros, build CONST_STRING. */
18875 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
18877 tree enttype
= TREE_TYPE (type
);
18878 tree domain
= TYPE_DOMAIN (type
);
18879 scalar_int_mode mode
;
18881 if (is_int_mode (TYPE_MODE (enttype
), &mode
)
18882 && GET_MODE_SIZE (mode
) == 1
18884 && integer_zerop (TYPE_MIN_VALUE (domain
))
18885 && compare_tree_int (TYPE_MAX_VALUE (domain
),
18886 TREE_STRING_LENGTH (init
) - 1) == 0
18887 && ((size_t) TREE_STRING_LENGTH (init
)
18888 == strlen (TREE_STRING_POINTER (init
)) + 1))
18890 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
18891 ggc_strdup (TREE_STRING_POINTER (init
)));
18892 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
18893 MEM_READONLY_P (rtl
) = 1;
18896 /* Other aggregates, and complex values, could be represented using
18898 else if (AGGREGATE_TYPE_P (type
)
18899 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
18900 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
18901 || TREE_CODE (type
) == COMPLEX_TYPE
)
18903 /* Vectors only work if their mode is supported by the target.
18904 FIXME: generic vectors ought to work too. */
18905 else if (TREE_CODE (type
) == VECTOR_TYPE
18906 && !VECTOR_MODE_P (TYPE_MODE (type
)))
18908 /* If the initializer is something that we know will expand into an
18909 immediate RTL constant, expand it now. We must be careful not to
18910 reference variables which won't be output. */
18911 else if (initializer_constant_valid_p (init
, type
)
18912 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
18914 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
18916 if (TREE_CODE (type
) == VECTOR_TYPE
)
18917 switch (TREE_CODE (init
))
18922 if (TREE_CONSTANT (init
))
18924 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
18925 bool constant_p
= true;
18927 unsigned HOST_WIDE_INT ix
;
18929 /* Even when ctor is constant, it might contain non-*_CST
18930 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
18931 belong into VECTOR_CST nodes. */
18932 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
18933 if (!CONSTANT_CLASS_P (value
))
18935 constant_p
= false;
18941 init
= build_vector_from_ctor (type
, elts
);
18951 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
18953 /* If expand_expr returns a MEM, it wasn't immediate. */
18954 gcc_assert (!rtl
|| !MEM_P (rtl
));
18960 /* Generate RTL for the variable DECL to represent its location. */
18963 rtl_for_decl_location (tree decl
)
18967 /* Here we have to decide where we are going to say the parameter "lives"
18968 (as far as the debugger is concerned). We only have a couple of
18969 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
18971 DECL_RTL normally indicates where the parameter lives during most of the
18972 activation of the function. If optimization is enabled however, this
18973 could be either NULL or else a pseudo-reg. Both of those cases indicate
18974 that the parameter doesn't really live anywhere (as far as the code
18975 generation parts of GCC are concerned) during most of the function's
18976 activation. That will happen (for example) if the parameter is never
18977 referenced within the function.
18979 We could just generate a location descriptor here for all non-NULL
18980 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
18981 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
18982 where DECL_RTL is NULL or is a pseudo-reg.
18984 Note however that we can only get away with using DECL_INCOMING_RTL as
18985 a backup substitute for DECL_RTL in certain limited cases. In cases
18986 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
18987 we can be sure that the parameter was passed using the same type as it is
18988 declared to have within the function, and that its DECL_INCOMING_RTL
18989 points us to a place where a value of that type is passed.
18991 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
18992 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
18993 because in these cases DECL_INCOMING_RTL points us to a value of some
18994 type which is *different* from the type of the parameter itself. Thus,
18995 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
18996 such cases, the debugger would end up (for example) trying to fetch a
18997 `float' from a place which actually contains the first part of a
18998 `double'. That would lead to really incorrect and confusing
18999 output at debug-time.
19001 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
19002 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
19003 are a couple of exceptions however. On little-endian machines we can
19004 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
19005 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
19006 an integral type that is smaller than TREE_TYPE (decl). These cases arise
19007 when (on a little-endian machine) a non-prototyped function has a
19008 parameter declared to be of type `short' or `char'. In such cases,
19009 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
19010 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
19011 passed `int' value. If the debugger then uses that address to fetch
19012 a `short' or a `char' (on a little-endian machine) the result will be
19013 the correct data, so we allow for such exceptional cases below.
19015 Note that our goal here is to describe the place where the given formal
19016 parameter lives during most of the function's activation (i.e. between the
19017 end of the prologue and the start of the epilogue). We'll do that as best
19018 as we can. Note however that if the given formal parameter is modified
19019 sometime during the execution of the function, then a stack backtrace (at
19020 debug-time) will show the function as having been called with the *new*
19021 value rather than the value which was originally passed in. This happens
19022 rarely enough that it is not a major problem, but it *is* a problem, and
19023 I'd like to fix it.
19025 A future version of dwarf2out.c may generate two additional attributes for
19026 any given DW_TAG_formal_parameter DIE which will describe the "passed
19027 type" and the "passed location" for the given formal parameter in addition
19028 to the attributes we now generate to indicate the "declared type" and the
19029 "active location" for each parameter. This additional set of attributes
19030 could be used by debuggers for stack backtraces. Separately, note that
19031 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
19032 This happens (for example) for inlined-instances of inline function formal
19033 parameters which are never referenced. This really shouldn't be
19034 happening. All PARM_DECL nodes should get valid non-NULL
19035 DECL_INCOMING_RTL values. FIXME. */
19037 /* Use DECL_RTL as the "location" unless we find something better. */
19038 rtl
= DECL_RTL_IF_SET (decl
);
19040 /* When generating abstract instances, ignore everything except
19041 constants, symbols living in memory, and symbols living in
19042 fixed registers. */
19043 if (! reload_completed
)
19046 && (CONSTANT_P (rtl
)
19048 && CONSTANT_P (XEXP (rtl
, 0)))
19051 && TREE_STATIC (decl
))))
19053 rtl
= targetm
.delegitimize_address (rtl
);
19058 else if (TREE_CODE (decl
) == PARM_DECL
)
19060 if (rtl
== NULL_RTX
19061 || is_pseudo_reg (rtl
)
19063 && is_pseudo_reg (XEXP (rtl
, 0))
19064 && DECL_INCOMING_RTL (decl
)
19065 && MEM_P (DECL_INCOMING_RTL (decl
))
19066 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
19068 tree declared_type
= TREE_TYPE (decl
);
19069 tree passed_type
= DECL_ARG_TYPE (decl
);
19070 machine_mode dmode
= TYPE_MODE (declared_type
);
19071 machine_mode pmode
= TYPE_MODE (passed_type
);
19073 /* This decl represents a formal parameter which was optimized out.
19074 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
19075 all cases where (rtl == NULL_RTX) just below. */
19076 if (dmode
== pmode
)
19077 rtl
= DECL_INCOMING_RTL (decl
);
19078 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
19079 && SCALAR_INT_MODE_P (dmode
)
19080 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
19081 && DECL_INCOMING_RTL (decl
))
19083 rtx inc
= DECL_INCOMING_RTL (decl
);
19086 else if (MEM_P (inc
))
19088 if (BYTES_BIG_ENDIAN
)
19089 rtl
= adjust_address_nv (inc
, dmode
,
19090 GET_MODE_SIZE (pmode
)
19091 - GET_MODE_SIZE (dmode
));
19098 /* If the parm was passed in registers, but lives on the stack, then
19099 make a big endian correction if the mode of the type of the
19100 parameter is not the same as the mode of the rtl. */
19101 /* ??? This is the same series of checks that are made in dbxout.c before
19102 we reach the big endian correction code there. It isn't clear if all
19103 of these checks are necessary here, but keeping them all is the safe
19105 else if (MEM_P (rtl
)
19106 && XEXP (rtl
, 0) != const0_rtx
19107 && ! CONSTANT_P (XEXP (rtl
, 0))
19108 /* Not passed in memory. */
19109 && !MEM_P (DECL_INCOMING_RTL (decl
))
19110 /* Not passed by invisible reference. */
19111 && (!REG_P (XEXP (rtl
, 0))
19112 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
19113 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
19114 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
19115 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
19118 /* Big endian correction check. */
19119 && BYTES_BIG_ENDIAN
19120 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
19121 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
19124 machine_mode addr_mode
= get_address_mode (rtl
);
19125 int offset
= (UNITS_PER_WORD
19126 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
19128 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
19129 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
19132 else if (VAR_P (decl
)
19135 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
)))
19137 machine_mode addr_mode
= get_address_mode (rtl
);
19138 HOST_WIDE_INT offset
= byte_lowpart_offset (TYPE_MODE (TREE_TYPE (decl
)),
19141 /* If a variable is declared "register" yet is smaller than
19142 a register, then if we store the variable to memory, it
19143 looks like we're storing a register-sized value, when in
19144 fact we are not. We need to adjust the offset of the
19145 storage location to reflect the actual value's bytes,
19146 else gdb will not be able to display it. */
19148 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
19149 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
19152 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
19153 and will have been substituted directly into all expressions that use it.
19154 C does not have such a concept, but C++ and other languages do. */
19155 if (!rtl
&& VAR_P (decl
) && DECL_INITIAL (decl
))
19156 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
19159 rtl
= targetm
.delegitimize_address (rtl
);
19161 /* If we don't look past the constant pool, we risk emitting a
19162 reference to a constant pool entry that isn't referenced from
19163 code, and thus is not emitted. */
19165 rtl
= avoid_constant_pool_reference (rtl
);
19167 /* Try harder to get a rtl. If this symbol ends up not being emitted
19168 in the current CU, resolve_addr will remove the expression referencing
19170 if (rtl
== NULL_RTX
19172 && !DECL_EXTERNAL (decl
)
19173 && TREE_STATIC (decl
)
19174 && DECL_NAME (decl
)
19175 && !DECL_HARD_REGISTER (decl
)
19176 && DECL_MODE (decl
) != VOIDmode
)
19178 rtl
= make_decl_rtl_for_debug (decl
);
19180 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
19181 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
19188 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
19189 returned. If so, the decl for the COMMON block is returned, and the
19190 value is the offset into the common block for the symbol. */
19193 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
19195 tree val_expr
, cvar
;
19197 HOST_WIDE_INT bitsize
, bitpos
;
19199 int unsignedp
, reversep
, volatilep
= 0;
19201 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
19202 it does not have a value (the offset into the common area), or if it
19203 is thread local (as opposed to global) then it isn't common, and shouldn't
19204 be handled as such. */
19206 || !TREE_STATIC (decl
)
19207 || !DECL_HAS_VALUE_EXPR_P (decl
)
19211 val_expr
= DECL_VALUE_EXPR (decl
);
19212 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
19215 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
, &mode
,
19216 &unsignedp
, &reversep
, &volatilep
);
19218 if (cvar
== NULL_TREE
19220 || DECL_ARTIFICIAL (cvar
)
19221 || !TREE_PUBLIC (cvar
))
19225 if (offset
!= NULL
)
19227 if (!tree_fits_shwi_p (offset
))
19229 *value
= tree_to_shwi (offset
);
19232 *value
+= bitpos
/ BITS_PER_UNIT
;
19237 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
19238 data attribute for a variable or a parameter. We generate the
19239 DW_AT_const_value attribute only in those cases where the given variable
19240 or parameter does not have a true "location" either in memory or in a
19241 register. This can happen (for example) when a constant is passed as an
19242 actual argument in a call to an inline function. (It's possible that
19243 these things can crop up in other ways also.) Note that one type of
19244 constant value which can be passed into an inlined function is a constant
19245 pointer. This can happen for example if an actual argument in an inlined
19246 function call evaluates to a compile-time constant address.
19248 CACHE_P is true if it is worth caching the location list for DECL,
19249 so that future calls can reuse it rather than regenerate it from scratch.
19250 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
19251 since we will need to refer to them each time the function is inlined. */
19254 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
)
19257 dw_loc_list_ref list
;
19258 var_loc_list
*loc_list
;
19259 cached_dw_loc_list
*cache
;
19264 if (TREE_CODE (decl
) == ERROR_MARK
)
19267 if (get_AT (die
, DW_AT_location
)
19268 || get_AT (die
, DW_AT_const_value
))
19271 gcc_assert (VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
19272 || TREE_CODE (decl
) == RESULT_DECL
);
19274 /* Try to get some constant RTL for this decl, and use that as the value of
19277 rtl
= rtl_for_decl_location (decl
);
19278 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
19279 && add_const_value_attribute (die
, rtl
))
19282 /* See if we have single element location list that is equivalent to
19283 a constant value. That way we are better to use add_const_value_attribute
19284 rather than expanding constant value equivalent. */
19285 loc_list
= lookup_decl_loc (decl
);
19288 && loc_list
->first
->next
== NULL
19289 && NOTE_P (loc_list
->first
->loc
)
19290 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
19291 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
19293 struct var_loc_node
*node
;
19295 node
= loc_list
->first
;
19296 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
19297 if (GET_CODE (rtl
) == EXPR_LIST
)
19298 rtl
= XEXP (rtl
, 0);
19299 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
19300 && add_const_value_attribute (die
, rtl
))
19303 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
19304 list several times. See if we've already cached the contents. */
19306 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
19310 cache
= cached_dw_loc_list_table
->find_with_hash (decl
, DECL_UID (decl
));
19312 list
= cache
->loc_list
;
19316 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2,
19318 /* It is usually worth caching this result if the decl is from
19319 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
19320 if (cache_p
&& list
&& list
->dw_loc_next
)
19322 cached_dw_loc_list
**slot
19323 = cached_dw_loc_list_table
->find_slot_with_hash (decl
,
19326 cache
= ggc_cleared_alloc
<cached_dw_loc_list
> ();
19327 cache
->decl_id
= DECL_UID (decl
);
19328 cache
->loc_list
= list
;
19334 add_AT_location_description (die
, DW_AT_location
, list
);
19337 /* None of that worked, so it must not really have a location;
19338 try adding a constant value attribute from the DECL_INITIAL. */
19339 return tree_add_const_value_attribute_for_decl (die
, decl
);
19342 /* Helper function for tree_add_const_value_attribute. Natively encode
19343 initializer INIT into an array. Return true if successful. */
19346 native_encode_initializer (tree init
, unsigned char *array
, int size
)
19350 if (init
== NULL_TREE
)
19354 switch (TREE_CODE (init
))
19357 type
= TREE_TYPE (init
);
19358 if (TREE_CODE (type
) == ARRAY_TYPE
)
19360 tree enttype
= TREE_TYPE (type
);
19361 scalar_int_mode mode
;
19363 if (!is_int_mode (TYPE_MODE (enttype
), &mode
)
19364 || GET_MODE_SIZE (mode
) != 1)
19366 if (int_size_in_bytes (type
) != size
)
19368 if (size
> TREE_STRING_LENGTH (init
))
19370 memcpy (array
, TREE_STRING_POINTER (init
),
19371 TREE_STRING_LENGTH (init
));
19372 memset (array
+ TREE_STRING_LENGTH (init
),
19373 '\0', size
- TREE_STRING_LENGTH (init
));
19376 memcpy (array
, TREE_STRING_POINTER (init
), size
);
19381 type
= TREE_TYPE (init
);
19382 if (int_size_in_bytes (type
) != size
)
19384 if (TREE_CODE (type
) == ARRAY_TYPE
)
19386 HOST_WIDE_INT min_index
;
19387 unsigned HOST_WIDE_INT cnt
;
19388 int curpos
= 0, fieldsize
;
19389 constructor_elt
*ce
;
19391 if (TYPE_DOMAIN (type
) == NULL_TREE
19392 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))))
19395 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
19396 if (fieldsize
<= 0)
19399 min_index
= tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)));
19400 memset (array
, '\0', size
);
19401 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
19403 tree val
= ce
->value
;
19404 tree index
= ce
->index
;
19406 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
19407 pos
= (tree_to_shwi (TREE_OPERAND (index
, 0)) - min_index
)
19410 pos
= (tree_to_shwi (index
) - min_index
) * fieldsize
;
19415 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
19418 curpos
= pos
+ fieldsize
;
19419 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
19421 int count
= tree_to_shwi (TREE_OPERAND (index
, 1))
19422 - tree_to_shwi (TREE_OPERAND (index
, 0));
19423 while (count
-- > 0)
19426 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
19427 curpos
+= fieldsize
;
19430 gcc_assert (curpos
<= size
);
19434 else if (TREE_CODE (type
) == RECORD_TYPE
19435 || TREE_CODE (type
) == UNION_TYPE
)
19437 tree field
= NULL_TREE
;
19438 unsigned HOST_WIDE_INT cnt
;
19439 constructor_elt
*ce
;
19441 if (int_size_in_bytes (type
) != size
)
19444 if (TREE_CODE (type
) == RECORD_TYPE
)
19445 field
= TYPE_FIELDS (type
);
19447 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
19449 tree val
= ce
->value
;
19450 int pos
, fieldsize
;
19452 if (ce
->index
!= 0)
19458 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
19461 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
19462 && TYPE_DOMAIN (TREE_TYPE (field
))
19463 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
19465 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
19466 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field
)))
19468 fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
19469 pos
= int_byte_position (field
);
19470 gcc_assert (pos
+ fieldsize
<= size
);
19471 if (val
&& fieldsize
!= 0
19472 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
19478 case VIEW_CONVERT_EXPR
:
19479 case NON_LVALUE_EXPR
:
19480 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
19482 return native_encode_expr (init
, array
, size
) == size
;
19486 /* Attach a DW_AT_const_value attribute to DIE. The value of the
19487 attribute is the const value T. */
19490 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
19493 tree type
= TREE_TYPE (t
);
19496 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
19500 gcc_assert (!DECL_P (init
));
19502 if (TREE_CODE (init
) == INTEGER_CST
)
19504 if (tree_fits_uhwi_p (init
))
19506 add_AT_unsigned (die
, DW_AT_const_value
, tree_to_uhwi (init
));
19509 if (tree_fits_shwi_p (init
))
19511 add_AT_int (die
, DW_AT_const_value
, tree_to_shwi (init
));
19517 rtl
= rtl_for_decl_init (init
, type
);
19519 return add_const_value_attribute (die
, rtl
);
19521 /* If the host and target are sane, try harder. */
19522 if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
19523 && initializer_constant_valid_p (init
, type
))
19525 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
19526 if (size
> 0 && (int) size
== size
)
19528 unsigned char *array
= ggc_cleared_vec_alloc
<unsigned char> (size
);
19530 if (native_encode_initializer (init
, array
, size
))
19532 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
19541 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
19542 attribute is the const value of T, where T is an integral constant
19543 variable with static storage duration
19544 (so it can't be a PARM_DECL or a RESULT_DECL). */
19547 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
19551 || (!VAR_P (decl
) && TREE_CODE (decl
) != CONST_DECL
)
19552 || (VAR_P (decl
) && !TREE_STATIC (decl
)))
19555 if (TREE_READONLY (decl
)
19556 && ! TREE_THIS_VOLATILE (decl
)
19557 && DECL_INITIAL (decl
))
19562 /* Don't add DW_AT_const_value if abstract origin already has one. */
19563 if (get_AT (var_die
, DW_AT_const_value
))
19566 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
19569 /* Convert the CFI instructions for the current function into a
19570 location list. This is used for DW_AT_frame_base when we targeting
19571 a dwarf2 consumer that does not support the dwarf3
19572 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
19575 static dw_loc_list_ref
19576 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
19580 dw_loc_list_ref list
, *list_tail
;
19582 dw_cfa_location last_cfa
, next_cfa
;
19583 const char *start_label
, *last_label
, *section
;
19584 dw_cfa_location remember
;
19587 gcc_assert (fde
!= NULL
);
19589 section
= secname_for_decl (current_function_decl
);
19593 memset (&next_cfa
, 0, sizeof (next_cfa
));
19594 next_cfa
.reg
= INVALID_REGNUM
;
19595 remember
= next_cfa
;
19597 start_label
= fde
->dw_fde_begin
;
19599 /* ??? Bald assumption that the CIE opcode list does not contain
19600 advance opcodes. */
19601 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
19602 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
19604 last_cfa
= next_cfa
;
19605 last_label
= start_label
;
19607 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
19609 /* If the first partition contained no CFI adjustments, the
19610 CIE opcodes apply to the whole first partition. */
19611 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19612 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
19613 list_tail
=&(*list_tail
)->dw_loc_next
;
19614 start_label
= last_label
= fde
->dw_fde_second_begin
;
19617 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
19619 switch (cfi
->dw_cfi_opc
)
19621 case DW_CFA_set_loc
:
19622 case DW_CFA_advance_loc1
:
19623 case DW_CFA_advance_loc2
:
19624 case DW_CFA_advance_loc4
:
19625 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
19627 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19628 start_label
, last_label
, section
);
19630 list_tail
= &(*list_tail
)->dw_loc_next
;
19631 last_cfa
= next_cfa
;
19632 start_label
= last_label
;
19634 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
19637 case DW_CFA_advance_loc
:
19638 /* The encoding is complex enough that we should never emit this. */
19639 gcc_unreachable ();
19642 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
19645 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
19647 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
19649 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19650 start_label
, last_label
, section
);
19652 list_tail
= &(*list_tail
)->dw_loc_next
;
19653 last_cfa
= next_cfa
;
19654 start_label
= last_label
;
19656 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19657 start_label
, fde
->dw_fde_end
, section
);
19658 list_tail
= &(*list_tail
)->dw_loc_next
;
19659 start_label
= last_label
= fde
->dw_fde_second_begin
;
19663 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
19665 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19666 start_label
, last_label
, section
);
19667 list_tail
= &(*list_tail
)->dw_loc_next
;
19668 start_label
= last_label
;
19671 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
19673 fde
->dw_fde_second_begin
19674 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
19677 if (list
&& list
->dw_loc_next
)
19683 /* Compute a displacement from the "steady-state frame pointer" to the
19684 frame base (often the same as the CFA), and store it in
19685 frame_pointer_fb_offset. OFFSET is added to the displacement
19686 before the latter is negated. */
19689 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
19693 #ifdef FRAME_POINTER_CFA_OFFSET
19694 reg
= frame_pointer_rtx
;
19695 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
19697 reg
= arg_pointer_rtx
;
19698 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
19701 elim
= (ira_use_lra_p
19702 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
19703 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
19704 if (GET_CODE (elim
) == PLUS
)
19706 offset
+= INTVAL (XEXP (elim
, 1));
19707 elim
= XEXP (elim
, 0);
19710 frame_pointer_fb_offset
= -offset
;
19712 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
19713 in which to eliminate. This is because it's stack pointer isn't
19714 directly accessible as a register within the ISA. To work around
19715 this, assume that while we cannot provide a proper value for
19716 frame_pointer_fb_offset, we won't need one either. */
19717 frame_pointer_fb_offset_valid
19718 = ((SUPPORTS_STACK_ALIGNMENT
19719 && (elim
== hard_frame_pointer_rtx
19720 || elim
== stack_pointer_rtx
))
19721 || elim
== (frame_pointer_needed
19722 ? hard_frame_pointer_rtx
19723 : stack_pointer_rtx
));
19726 /* Generate a DW_AT_name attribute given some string value to be included as
19727 the value of the attribute. */
19730 add_name_attribute (dw_die_ref die
, const char *name_string
)
19732 if (name_string
!= NULL
&& *name_string
!= 0)
19734 if (demangle_name_func
)
19735 name_string
= (*demangle_name_func
) (name_string
);
19737 add_AT_string (die
, DW_AT_name
, name_string
);
19741 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
19742 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
19743 of TYPE accordingly.
19745 ??? This is a temporary measure until after we're able to generate
19746 regular DWARF for the complex Ada type system. */
19749 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
19750 dw_die_ref context_die
)
19753 dw_die_ref dtype_die
;
19755 if (!lang_hooks
.types
.descriptive_type
)
19758 dtype
= lang_hooks
.types
.descriptive_type (type
);
19762 dtype_die
= lookup_type_die (dtype
);
19765 gen_type_die (dtype
, context_die
);
19766 dtype_die
= lookup_type_die (dtype
);
19767 gcc_assert (dtype_die
);
19770 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
19773 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
19775 static const char *
19776 comp_dir_string (void)
19780 static const char *cached_wd
= NULL
;
19782 if (cached_wd
!= NULL
)
19785 wd
= get_src_pwd ();
19789 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
19793 wdlen
= strlen (wd
);
19794 wd1
= ggc_vec_alloc
<char> (wdlen
+ 2);
19796 wd1
[wdlen
] = DIR_SEPARATOR
;
19797 wd1
[wdlen
+ 1] = 0;
19801 cached_wd
= remap_debug_filename (wd
);
19805 /* Generate a DW_AT_comp_dir attribute for DIE. */
19808 add_comp_dir_attribute (dw_die_ref die
)
19810 const char * wd
= comp_dir_string ();
19812 add_AT_string (die
, DW_AT_comp_dir
, wd
);
19815 /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
19816 pointer computation, ...), output a representation for that bound according
19817 to the accepted FORMS (see enum dw_scalar_form) and add it to DIE. See
19818 loc_list_from_tree for the meaning of CONTEXT. */
19821 add_scalar_info (dw_die_ref die
, enum dwarf_attribute attr
, tree value
,
19822 int forms
, struct loc_descr_context
*context
)
19824 dw_die_ref context_die
, decl_die
;
19825 dw_loc_list_ref list
;
19826 bool strip_conversions
= true;
19827 bool placeholder_seen
= false;
19829 while (strip_conversions
)
19830 switch (TREE_CODE (value
))
19837 case VIEW_CONVERT_EXPR
:
19838 value
= TREE_OPERAND (value
, 0);
19842 strip_conversions
= false;
19846 /* If possible and permitted, output the attribute as a constant. */
19847 if ((forms
& dw_scalar_form_constant
) != 0
19848 && TREE_CODE (value
) == INTEGER_CST
)
19850 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (value
));
19852 /* If HOST_WIDE_INT is big enough then represent the bound as
19853 a constant value. We need to choose a form based on
19854 whether the type is signed or unsigned. We cannot just
19855 call add_AT_unsigned if the value itself is positive
19856 (add_AT_unsigned might add the unsigned value encoded as
19857 DW_FORM_data[1248]). Some DWARF consumers will lookup the
19858 bounds type and then sign extend any unsigned values found
19859 for signed types. This is needed only for
19860 DW_AT_{lower,upper}_bound, since for most other attributes,
19861 consumers will treat DW_FORM_data[1248] as unsigned values,
19862 regardless of the underlying type. */
19863 if (prec
<= HOST_BITS_PER_WIDE_INT
19864 || tree_fits_uhwi_p (value
))
19866 if (TYPE_UNSIGNED (TREE_TYPE (value
)))
19867 add_AT_unsigned (die
, attr
, TREE_INT_CST_LOW (value
));
19869 add_AT_int (die
, attr
, TREE_INT_CST_LOW (value
));
19872 /* Otherwise represent the bound as an unsigned value with
19873 the precision of its type. The precision and signedness
19874 of the type will be necessary to re-interpret it
19876 add_AT_wide (die
, attr
, wi::to_wide (value
));
19880 /* Otherwise, if it's possible and permitted too, output a reference to
19882 if ((forms
& dw_scalar_form_reference
) != 0)
19884 tree decl
= NULL_TREE
;
19886 /* Some type attributes reference an outer type. For instance, the upper
19887 bound of an array may reference an embedding record (this happens in
19889 if (TREE_CODE (value
) == COMPONENT_REF
19890 && TREE_CODE (TREE_OPERAND (value
, 0)) == PLACEHOLDER_EXPR
19891 && TREE_CODE (TREE_OPERAND (value
, 1)) == FIELD_DECL
)
19892 decl
= TREE_OPERAND (value
, 1);
19894 else if (VAR_P (value
)
19895 || TREE_CODE (value
) == PARM_DECL
19896 || TREE_CODE (value
) == RESULT_DECL
)
19899 if (decl
!= NULL_TREE
)
19901 dw_die_ref decl_die
= lookup_decl_die (decl
);
19903 /* ??? Can this happen, or should the variable have been bound
19904 first? Probably it can, since I imagine that we try to create
19905 the types of parameters in the order in which they exist in
19906 the list, and won't have created a forward reference to a
19907 later parameter. */
19908 if (decl_die
!= NULL
)
19910 add_AT_die_ref (die
, attr
, decl_die
);
19916 /* Last chance: try to create a stack operation procedure to evaluate the
19917 value. Do nothing if even that is not possible or permitted. */
19918 if ((forms
& dw_scalar_form_exprloc
) == 0)
19921 list
= loc_list_from_tree (value
, 2, context
);
19922 if (context
&& context
->placeholder_arg
)
19924 placeholder_seen
= context
->placeholder_seen
;
19925 context
->placeholder_seen
= false;
19927 if (list
== NULL
|| single_element_loc_list_p (list
))
19929 /* If this attribute is not a reference nor constant, it is
19930 a DWARF expression rather than location description. For that
19931 loc_list_from_tree (value, 0, &context) is needed. */
19932 dw_loc_list_ref list2
= loc_list_from_tree (value
, 0, context
);
19933 if (list2
&& single_element_loc_list_p (list2
))
19935 if (placeholder_seen
)
19937 struct dwarf_procedure_info dpi
;
19938 dpi
.fndecl
= NULL_TREE
;
19939 dpi
.args_count
= 1;
19940 if (!resolve_args_picking (list2
->expr
, 1, &dpi
))
19943 add_AT_loc (die
, attr
, list2
->expr
);
19948 /* If that failed to give a single element location list, fall back to
19949 outputting this as a reference... still if permitted. */
19951 || (forms
& dw_scalar_form_reference
) == 0
19952 || placeholder_seen
)
19955 if (current_function_decl
== 0)
19956 context_die
= comp_unit_die ();
19958 context_die
= lookup_decl_die (current_function_decl
);
19960 decl_die
= new_die (DW_TAG_variable
, context_die
, value
);
19961 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
19962 add_type_attribute (decl_die
, TREE_TYPE (value
), TYPE_QUAL_CONST
, false,
19964 add_AT_location_description (decl_die
, DW_AT_location
, list
);
19965 add_AT_die_ref (die
, attr
, decl_die
);
19968 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
19972 lower_bound_default (void)
19974 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
19980 case DW_LANG_C_plus_plus
:
19981 case DW_LANG_C_plus_plus_11
:
19982 case DW_LANG_C_plus_plus_14
:
19984 case DW_LANG_ObjC_plus_plus
:
19986 case DW_LANG_Fortran77
:
19987 case DW_LANG_Fortran90
:
19988 case DW_LANG_Fortran95
:
19989 case DW_LANG_Fortran03
:
19990 case DW_LANG_Fortran08
:
19994 case DW_LANG_Python
:
19995 return dwarf_version
>= 4 ? 0 : -1;
19996 case DW_LANG_Ada95
:
19997 case DW_LANG_Ada83
:
19998 case DW_LANG_Cobol74
:
19999 case DW_LANG_Cobol85
:
20000 case DW_LANG_Modula2
:
20002 return dwarf_version
>= 4 ? 1 : -1;
20008 /* Given a tree node describing an array bound (either lower or upper) output
20009 a representation for that bound. */
20012 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
,
20013 tree bound
, struct loc_descr_context
*context
)
20018 switch (TREE_CODE (bound
))
20020 /* Strip all conversions. */
20022 case VIEW_CONVERT_EXPR
:
20023 bound
= TREE_OPERAND (bound
, 0);
20026 /* All fixed-bounds are represented by INTEGER_CST nodes. Lower bounds
20027 are even omitted when they are the default. */
20029 /* If the value for this bound is the default one, we can even omit the
20031 if (bound_attr
== DW_AT_lower_bound
20032 && tree_fits_shwi_p (bound
)
20033 && (dflt
= lower_bound_default ()) != -1
20034 && tree_to_shwi (bound
) == dflt
)
20040 /* Because of the complex interaction there can be with other GNAT
20041 encodings, GDB isn't ready yet to handle proper DWARF description
20042 for self-referencial subrange bounds: let GNAT encodings do the
20043 magic in such a case. */
20045 && gnat_encodings
!= DWARF_GNAT_ENCODINGS_MINIMAL
20046 && contains_placeholder_p (bound
))
20049 add_scalar_info (subrange_die
, bound_attr
, bound
,
20050 dw_scalar_form_constant
20051 | dw_scalar_form_exprloc
20052 | dw_scalar_form_reference
,
20058 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
20059 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
20060 Note that the block of subscript information for an array type also
20061 includes information about the element type of the given array type.
20063 This function reuses previously set type and bound information if
20067 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
20069 unsigned dimension_number
;
20071 dw_die_ref child
= type_die
->die_child
;
20073 for (dimension_number
= 0;
20074 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
20075 type
= TREE_TYPE (type
), dimension_number
++)
20077 tree domain
= TYPE_DOMAIN (type
);
20079 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
20082 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
20083 and (in GNU C only) variable bounds. Handle all three forms
20086 /* Find and reuse a previously generated DW_TAG_subrange_type if
20089 For multi-dimensional arrays, as we iterate through the
20090 various dimensions in the enclosing for loop above, we also
20091 iterate through the DIE children and pick at each
20092 DW_TAG_subrange_type previously generated (if available).
20093 Each child DW_TAG_subrange_type DIE describes the range of
20094 the current dimension. At this point we should have as many
20095 DW_TAG_subrange_type's as we have dimensions in the
20097 dw_die_ref subrange_die
= NULL
;
20101 child
= child
->die_sib
;
20102 if (child
->die_tag
== DW_TAG_subrange_type
)
20103 subrange_die
= child
;
20104 if (child
== type_die
->die_child
)
20106 /* If we wrapped around, stop looking next time. */
20110 if (child
->die_tag
== DW_TAG_subrange_type
)
20114 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
20118 /* We have an array type with specified bounds. */
20119 lower
= TYPE_MIN_VALUE (domain
);
20120 upper
= TYPE_MAX_VALUE (domain
);
20122 /* Define the index type. */
20123 if (TREE_TYPE (domain
)
20124 && !get_AT (subrange_die
, DW_AT_type
))
20126 /* ??? This is probably an Ada unnamed subrange type. Ignore the
20127 TREE_TYPE field. We can't emit debug info for this
20128 because it is an unnamed integral type. */
20129 if (TREE_CODE (domain
) == INTEGER_TYPE
20130 && TYPE_NAME (domain
) == NULL_TREE
20131 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
20132 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
20135 add_type_attribute (subrange_die
, TREE_TYPE (domain
),
20136 TYPE_UNQUALIFIED
, false, type_die
);
20139 /* ??? If upper is NULL, the array has unspecified length,
20140 but it does have a lower bound. This happens with Fortran
20142 Since the debugger is definitely going to need to know N
20143 to produce useful results, go ahead and output the lower
20144 bound solo, and hope the debugger can cope. */
20146 if (!get_AT (subrange_die
, DW_AT_lower_bound
))
20147 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
, NULL
);
20148 if (upper
&& !get_AT (subrange_die
, DW_AT_upper_bound
))
20149 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
, NULL
);
20152 /* Otherwise we have an array type with an unspecified length. The
20153 DWARF-2 spec does not say how to handle this; let's just leave out the
20158 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
20161 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
20163 dw_die_ref decl_die
;
20164 HOST_WIDE_INT size
;
20165 dw_loc_descr_ref size_expr
= NULL
;
20167 switch (TREE_CODE (tree_node
))
20172 case ENUMERAL_TYPE
:
20175 case QUAL_UNION_TYPE
:
20176 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
20177 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
20179 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
20182 size_expr
= type_byte_size (tree_node
, &size
);
20185 /* For a data member of a struct or union, the DW_AT_byte_size is
20186 generally given as the number of bytes normally allocated for an
20187 object of the *declared* type of the member itself. This is true
20188 even for bit-fields. */
20189 size
= int_size_in_bytes (field_type (tree_node
));
20192 gcc_unreachable ();
20195 /* Support for dynamically-sized objects was introduced by DWARFv3.
20196 At the moment, GDB does not handle variable byte sizes very well,
20198 if ((dwarf_version
>= 3 || !dwarf_strict
)
20199 && gnat_encodings
== DWARF_GNAT_ENCODINGS_MINIMAL
20200 && size_expr
!= NULL
)
20201 add_AT_loc (die
, DW_AT_byte_size
, size_expr
);
20203 /* Note that `size' might be -1 when we get to this point. If it is, that
20204 indicates that the byte size of the entity in question is variable and
20205 that we could not generate a DWARF expression that computes it. */
20207 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
20210 /* Add a DW_AT_alignment attribute to DIE with TREE_NODE's non-default
20214 add_alignment_attribute (dw_die_ref die
, tree tree_node
)
20216 if (dwarf_version
< 5 && dwarf_strict
)
20221 if (DECL_P (tree_node
))
20223 if (!DECL_USER_ALIGN (tree_node
))
20226 align
= DECL_ALIGN_UNIT (tree_node
);
20228 else if (TYPE_P (tree_node
))
20230 if (!TYPE_USER_ALIGN (tree_node
))
20233 align
= TYPE_ALIGN_UNIT (tree_node
);
20236 gcc_unreachable ();
20238 add_AT_unsigned (die
, DW_AT_alignment
, align
);
20241 /* For a FIELD_DECL node which represents a bit-field, output an attribute
20242 which specifies the distance in bits from the highest order bit of the
20243 "containing object" for the bit-field to the highest order bit of the
20246 For any given bit-field, the "containing object" is a hypothetical object
20247 (of some integral or enum type) within which the given bit-field lives. The
20248 type of this hypothetical "containing object" is always the same as the
20249 declared type of the individual bit-field itself. The determination of the
20250 exact location of the "containing object" for a bit-field is rather
20251 complicated. It's handled by the `field_byte_offset' function (above).
20253 CTX is required: see the comment for VLR_CONTEXT.
20255 Note that it is the size (in bytes) of the hypothetical "containing object"
20256 which will be given in the DW_AT_byte_size attribute for this bit-field.
20257 (See `byte_size_attribute' above). */
20260 add_bit_offset_attribute (dw_die_ref die
, tree decl
, struct vlr_context
*ctx
)
20262 HOST_WIDE_INT object_offset_in_bytes
;
20263 tree original_type
= DECL_BIT_FIELD_TYPE (decl
);
20264 HOST_WIDE_INT bitpos_int
;
20265 HOST_WIDE_INT highest_order_object_bit_offset
;
20266 HOST_WIDE_INT highest_order_field_bit_offset
;
20267 HOST_WIDE_INT bit_offset
;
20269 field_byte_offset (decl
, ctx
, &object_offset_in_bytes
);
20271 /* Must be a field and a bit field. */
20272 gcc_assert (original_type
&& TREE_CODE (decl
) == FIELD_DECL
);
20274 /* We can't yet handle bit-fields whose offsets are variable, so if we
20275 encounter such things, just return without generating any attribute
20276 whatsoever. Likewise for variable or too large size. */
20277 if (! tree_fits_shwi_p (bit_position (decl
))
20278 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
20281 bitpos_int
= int_bit_position (decl
);
20283 /* Note that the bit offset is always the distance (in bits) from the
20284 highest-order bit of the "containing object" to the highest-order bit of
20285 the bit-field itself. Since the "high-order end" of any object or field
20286 is different on big-endian and little-endian machines, the computation
20287 below must take account of these differences. */
20288 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
20289 highest_order_field_bit_offset
= bitpos_int
;
20291 if (! BYTES_BIG_ENDIAN
)
20293 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
20294 highest_order_object_bit_offset
+=
20295 simple_type_size_in_bits (original_type
);
20299 = (! BYTES_BIG_ENDIAN
20300 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
20301 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
20303 if (bit_offset
< 0)
20304 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
20306 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
20309 /* For a FIELD_DECL node which represents a bit field, output an attribute
20310 which specifies the length in bits of the given field. */
20313 add_bit_size_attribute (dw_die_ref die
, tree decl
)
20315 /* Must be a field and a bit field. */
20316 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
20317 && DECL_BIT_FIELD_TYPE (decl
));
20319 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
20320 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
20323 /* If the compiled language is ANSI C, then add a 'prototyped'
20324 attribute, if arg types are given for the parameters of a function. */
20327 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
20329 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
20336 if (prototype_p (func_type
))
20337 add_AT_flag (die
, DW_AT_prototyped
, 1);
20344 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
20345 by looking in the type declaration, the object declaration equate table or
20346 the block mapping. */
20348 static inline dw_die_ref
20349 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
20351 dw_die_ref origin_die
= NULL
;
20353 if (DECL_P (origin
))
20356 origin_die
= lookup_decl_die (origin
);
20357 /* "Unwrap" the decls DIE which we put in the imported unit context.
20358 We are looking for the abstract copy here. */
20361 && (c
= get_AT_ref (origin_die
, DW_AT_abstract_origin
))
20362 /* ??? Identify this better. */
20366 else if (TYPE_P (origin
))
20367 origin_die
= lookup_type_die (origin
);
20368 else if (TREE_CODE (origin
) == BLOCK
)
20369 origin_die
= BLOCK_DIE (origin
);
20371 /* XXX: Functions that are never lowered don't always have correct block
20372 trees (in the case of java, they simply have no block tree, in some other
20373 languages). For these functions, there is nothing we can really do to
20374 output correct debug info for inlined functions in all cases. Rather
20375 than die, we'll just produce deficient debug info now, in that we will
20376 have variables without a proper abstract origin. In the future, when all
20377 functions are lowered, we should re-add a gcc_assert (origin_die)
20381 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
20385 /* We do not currently support the pure_virtual attribute. */
20388 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
20390 if (DECL_VINDEX (func_decl
))
20392 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
20394 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
20395 add_AT_loc (die
, DW_AT_vtable_elem_location
,
20396 new_loc_descr (DW_OP_constu
,
20397 tree_to_shwi (DECL_VINDEX (func_decl
)),
20400 /* GNU extension: Record what type this method came from originally. */
20401 if (debug_info_level
> DINFO_LEVEL_TERSE
20402 && DECL_CONTEXT (func_decl
))
20403 add_AT_die_ref (die
, DW_AT_containing_type
,
20404 lookup_type_die (DECL_CONTEXT (func_decl
)));
20408 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
20409 given decl. This used to be a vendor extension until after DWARF 4
20410 standardized it. */
20413 add_linkage_attr (dw_die_ref die
, tree decl
)
20415 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
20417 /* Mimic what assemble_name_raw does with a leading '*'. */
20418 if (name
[0] == '*')
20421 if (dwarf_version
>= 4)
20422 add_AT_string (die
, DW_AT_linkage_name
, name
);
20424 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
20427 /* Add source coordinate attributes for the given decl. */
20430 add_src_coords_attributes (dw_die_ref die
, tree decl
)
20432 expanded_location s
;
20434 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
20436 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
20437 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
20438 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
20439 if (debug_column_info
&& s
.column
)
20440 add_AT_unsigned (die
, DW_AT_decl_column
, s
.column
);
20443 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
20446 add_linkage_name_raw (dw_die_ref die
, tree decl
)
20448 /* Defer until we have an assembler name set. */
20449 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
20451 limbo_die_node
*asm_name
;
20453 asm_name
= ggc_cleared_alloc
<limbo_die_node
> ();
20454 asm_name
->die
= die
;
20455 asm_name
->created_for
= decl
;
20456 asm_name
->next
= deferred_asm_name
;
20457 deferred_asm_name
= asm_name
;
20459 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
20460 add_linkage_attr (die
, decl
);
20463 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl if desired. */
20466 add_linkage_name (dw_die_ref die
, tree decl
)
20468 if (debug_info_level
> DINFO_LEVEL_NONE
20469 && VAR_OR_FUNCTION_DECL_P (decl
)
20470 && TREE_PUBLIC (decl
)
20471 && !(VAR_P (decl
) && DECL_REGISTER (decl
))
20472 && die
->die_tag
!= DW_TAG_member
)
20473 add_linkage_name_raw (die
, decl
);
20476 /* Add a DW_AT_name attribute and source coordinate attribute for the
20477 given decl, but only if it actually has a name. */
20480 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
,
20481 bool no_linkage_name
)
20485 decl_name
= DECL_NAME (decl
);
20486 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
20488 const char *name
= dwarf2_name (decl
, 0);
20490 add_name_attribute (die
, name
);
20491 if (! DECL_ARTIFICIAL (decl
))
20492 add_src_coords_attributes (die
, decl
);
20494 if (!no_linkage_name
)
20495 add_linkage_name (die
, decl
);
20498 #ifdef VMS_DEBUGGING_INFO
20499 /* Get the function's name, as described by its RTL. This may be different
20500 from the DECL_NAME name used in the source file. */
20501 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
20503 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
20504 XEXP (DECL_RTL (decl
), 0), false);
20505 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
20507 #endif /* VMS_DEBUGGING_INFO */
20510 /* Add VALUE as a DW_AT_discr_value attribute to DIE. */
20513 add_discr_value (dw_die_ref die
, dw_discr_value
*value
)
20517 attr
.dw_attr
= DW_AT_discr_value
;
20518 attr
.dw_attr_val
.val_class
= dw_val_class_discr_value
;
20519 attr
.dw_attr_val
.val_entry
= NULL
;
20520 attr
.dw_attr_val
.v
.val_discr_value
.pos
= value
->pos
;
20522 attr
.dw_attr_val
.v
.val_discr_value
.v
.uval
= value
->v
.uval
;
20524 attr
.dw_attr_val
.v
.val_discr_value
.v
.sval
= value
->v
.sval
;
20525 add_dwarf_attr (die
, &attr
);
20528 /* Add DISCR_LIST as a DW_AT_discr_list to DIE. */
20531 add_discr_list (dw_die_ref die
, dw_discr_list_ref discr_list
)
20535 attr
.dw_attr
= DW_AT_discr_list
;
20536 attr
.dw_attr_val
.val_class
= dw_val_class_discr_list
;
20537 attr
.dw_attr_val
.val_entry
= NULL
;
20538 attr
.dw_attr_val
.v
.val_discr_list
= discr_list
;
20539 add_dwarf_attr (die
, &attr
);
20542 static inline dw_discr_list_ref
20543 AT_discr_list (dw_attr_node
*attr
)
20545 return attr
->dw_attr_val
.v
.val_discr_list
;
20548 #ifdef VMS_DEBUGGING_INFO
20549 /* Output the debug main pointer die for VMS */
20552 dwarf2out_vms_debug_main_pointer (void)
20554 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20557 /* Allocate the VMS debug main subprogram die. */
20558 die
= new_die_raw (DW_TAG_subprogram
);
20559 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
20560 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
20561 current_function_funcdef_no
);
20562 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
20564 /* Make it the first child of comp_unit_die (). */
20565 die
->die_parent
= comp_unit_die ();
20566 if (comp_unit_die ()->die_child
)
20568 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
20569 comp_unit_die ()->die_child
->die_sib
= die
;
20573 die
->die_sib
= die
;
20574 comp_unit_die ()->die_child
= die
;
20577 #endif /* VMS_DEBUGGING_INFO */
20579 /* Push a new declaration scope. */
20582 push_decl_scope (tree scope
)
20584 vec_safe_push (decl_scope_table
, scope
);
20587 /* Pop a declaration scope. */
20590 pop_decl_scope (void)
20592 decl_scope_table
->pop ();
20595 /* walk_tree helper function for uses_local_type, below. */
20598 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
20601 *walk_subtrees
= 0;
20604 tree name
= TYPE_NAME (*tp
);
20605 if (name
&& DECL_P (name
) && decl_function_context (name
))
20611 /* If TYPE involves a function-local type (including a local typedef to a
20612 non-local type), returns that type; otherwise returns NULL_TREE. */
20615 uses_local_type (tree type
)
20617 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
20621 /* Return the DIE for the scope that immediately contains this type.
20622 Non-named types that do not involve a function-local type get global
20623 scope. Named types nested in namespaces or other types get their
20624 containing scope. All other types (i.e. function-local named types) get
20625 the current active scope. */
20628 scope_die_for (tree t
, dw_die_ref context_die
)
20630 dw_die_ref scope_die
= NULL
;
20631 tree containing_scope
;
20633 /* Non-types always go in the current scope. */
20634 gcc_assert (TYPE_P (t
));
20636 /* Use the scope of the typedef, rather than the scope of the type
20638 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
20639 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
20641 containing_scope
= TYPE_CONTEXT (t
);
20643 /* Use the containing namespace if there is one. */
20644 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
20646 if (context_die
== lookup_decl_die (containing_scope
))
20648 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
20649 context_die
= get_context_die (containing_scope
);
20651 containing_scope
= NULL_TREE
;
20654 /* Ignore function type "scopes" from the C frontend. They mean that
20655 a tagged type is local to a parmlist of a function declarator, but
20656 that isn't useful to DWARF. */
20657 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
20658 containing_scope
= NULL_TREE
;
20660 if (SCOPE_FILE_SCOPE_P (containing_scope
))
20662 /* If T uses a local type keep it local as well, to avoid references
20663 to function-local DIEs from outside the function. */
20664 if (current_function_decl
&& uses_local_type (t
))
20665 scope_die
= context_die
;
20667 scope_die
= comp_unit_die ();
20669 else if (TYPE_P (containing_scope
))
20671 /* For types, we can just look up the appropriate DIE. */
20672 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20673 scope_die
= get_context_die (containing_scope
);
20676 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
20677 if (scope_die
== NULL
)
20678 scope_die
= comp_unit_die ();
20682 scope_die
= context_die
;
20687 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
20690 local_scope_p (dw_die_ref context_die
)
20692 for (; context_die
; context_die
= context_die
->die_parent
)
20693 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
20694 || context_die
->die_tag
== DW_TAG_subprogram
)
20700 /* Returns nonzero if CONTEXT_DIE is a class. */
20703 class_scope_p (dw_die_ref context_die
)
20705 return (context_die
20706 && (context_die
->die_tag
== DW_TAG_structure_type
20707 || context_die
->die_tag
== DW_TAG_class_type
20708 || context_die
->die_tag
== DW_TAG_interface_type
20709 || context_die
->die_tag
== DW_TAG_union_type
));
20712 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
20713 whether or not to treat a DIE in this context as a declaration. */
20716 class_or_namespace_scope_p (dw_die_ref context_die
)
20718 return (class_scope_p (context_die
)
20719 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
20722 /* Many forms of DIEs require a "type description" attribute. This
20723 routine locates the proper "type descriptor" die for the type given
20724 by 'type' plus any additional qualifiers given by 'cv_quals', and
20725 adds a DW_AT_type attribute below the given die. */
20728 add_type_attribute (dw_die_ref object_die
, tree type
, int cv_quals
,
20729 bool reverse
, dw_die_ref context_die
)
20731 enum tree_code code
= TREE_CODE (type
);
20732 dw_die_ref type_die
= NULL
;
20734 /* ??? If this type is an unnamed subrange type of an integral, floating-point
20735 or fixed-point type, use the inner type. This is because we have no
20736 support for unnamed types in base_type_die. This can happen if this is
20737 an Ada subrange type. Correct solution is emit a subrange type die. */
20738 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
20739 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
20740 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
20742 if (code
== ERROR_MARK
20743 /* Handle a special case. For functions whose return type is void, we
20744 generate *no* type attribute. (Note that no object may have type
20745 `void', so this only applies to function return types). */
20746 || code
== VOID_TYPE
)
20749 type_die
= modified_type_die (type
,
20750 cv_quals
| TYPE_QUALS (type
),
20754 if (type_die
!= NULL
)
20755 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
20758 /* Given an object die, add the calling convention attribute for the
20759 function call type. */
20761 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
20763 enum dwarf_calling_convention value
= DW_CC_normal
;
20765 value
= ((enum dwarf_calling_convention
)
20766 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
20769 && id_equal (DECL_ASSEMBLER_NAME (decl
), "MAIN__"))
20771 /* DWARF 2 doesn't provide a way to identify a program's source-level
20772 entry point. DW_AT_calling_convention attributes are only meant
20773 to describe functions' calling conventions. However, lacking a
20774 better way to signal the Fortran main program, we used this for
20775 a long time, following existing custom. Now, DWARF 4 has
20776 DW_AT_main_subprogram, which we add below, but some tools still
20777 rely on the old way, which we thus keep. */
20778 value
= DW_CC_program
;
20780 if (dwarf_version
>= 4 || !dwarf_strict
)
20781 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
20784 /* Only add the attribute if the backend requests it, and
20785 is not DW_CC_normal. */
20786 if (value
&& (value
!= DW_CC_normal
))
20787 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
20790 /* Given a tree pointer to a struct, class, union, or enum type node, return
20791 a pointer to the (string) tag name for the given type, or zero if the type
20792 was declared without a tag. */
20794 static const char *
20795 type_tag (const_tree type
)
20797 const char *name
= 0;
20799 if (TYPE_NAME (type
) != 0)
20803 /* Find the IDENTIFIER_NODE for the type name. */
20804 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
20805 && !TYPE_NAMELESS (type
))
20806 t
= TYPE_NAME (type
);
20808 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
20809 a TYPE_DECL node, regardless of whether or not a `typedef' was
20811 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
20812 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
20814 /* We want to be extra verbose. Don't call dwarf_name if
20815 DECL_NAME isn't set. The default hook for decl_printable_name
20816 doesn't like that, and in this context it's correct to return
20817 0, instead of "<anonymous>" or the like. */
20818 if (DECL_NAME (TYPE_NAME (type
))
20819 && !DECL_NAMELESS (TYPE_NAME (type
)))
20820 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
20823 /* Now get the name as a string, or invent one. */
20824 if (!name
&& t
!= 0)
20825 name
= IDENTIFIER_POINTER (t
);
20828 return (name
== 0 || *name
== '\0') ? 0 : name
;
20831 /* Return the type associated with a data member, make a special check
20832 for bit field types. */
20835 member_declared_type (const_tree member
)
20837 return (DECL_BIT_FIELD_TYPE (member
)
20838 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
20841 /* Get the decl's label, as described by its RTL. This may be different
20842 from the DECL_NAME name used in the source file. */
20845 static const char *
20846 decl_start_label (tree decl
)
20849 const char *fnname
;
20851 x
= DECL_RTL (decl
);
20852 gcc_assert (MEM_P (x
));
20855 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
20857 fnname
= XSTR (x
, 0);
20862 /* For variable-length arrays that have been previously generated, but
20863 may be incomplete due to missing subscript info, fill the subscript
20864 info. Return TRUE if this is one of those cases. */
20866 fill_variable_array_bounds (tree type
)
20868 if (TREE_ASM_WRITTEN (type
)
20869 && TREE_CODE (type
) == ARRAY_TYPE
20870 && variably_modified_type_p (type
, NULL
))
20872 dw_die_ref array_die
= lookup_type_die (type
);
20875 add_subscript_info (array_die
, type
, !is_ada ());
20881 /* These routines generate the internal representation of the DIE's for
20882 the compilation unit. Debugging information is collected by walking
20883 the declaration trees passed in from dwarf2out_decl(). */
20886 gen_array_type_die (tree type
, dw_die_ref context_die
)
20888 dw_die_ref array_die
;
20890 /* GNU compilers represent multidimensional array types as sequences of one
20891 dimensional array types whose element types are themselves array types.
20892 We sometimes squish that down to a single array_type DIE with multiple
20893 subscripts in the Dwarf debugging info. The draft Dwarf specification
20894 say that we are allowed to do this kind of compression in C, because
20895 there is no difference between an array of arrays and a multidimensional
20896 array. We don't do this for Ada to remain as close as possible to the
20897 actual representation, which is especially important against the language
20898 flexibilty wrt arrays of variable size. */
20900 bool collapse_nested_arrays
= !is_ada ();
20902 if (fill_variable_array_bounds (type
))
20905 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
20908 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
20909 DW_TAG_string_type doesn't have DW_AT_type attribute). */
20910 if (TYPE_STRING_FLAG (type
)
20911 && TREE_CODE (type
) == ARRAY_TYPE
20913 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
20915 HOST_WIDE_INT size
;
20917 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
20918 add_name_attribute (array_die
, type_tag (type
));
20919 equate_type_number_to_die (type
, array_die
);
20920 size
= int_size_in_bytes (type
);
20922 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
20923 /* ??? We can't annotate types late, but for LTO we may not
20924 generate a location early either (gfortran.dg/save_6.f90). */
20925 else if (! (early_dwarf
&& (flag_generate_lto
|| flag_generate_offload
))
20926 && TYPE_DOMAIN (type
) != NULL_TREE
20927 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
)
20929 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
20930 tree rszdecl
= szdecl
;
20932 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
20933 if (!DECL_P (szdecl
))
20935 if (TREE_CODE (szdecl
) == INDIRECT_REF
20936 && DECL_P (TREE_OPERAND (szdecl
, 0)))
20938 rszdecl
= TREE_OPERAND (szdecl
, 0);
20939 if (int_size_in_bytes (TREE_TYPE (rszdecl
))
20940 != DWARF2_ADDR_SIZE
)
20948 dw_loc_list_ref loc
20949 = loc_list_from_tree (rszdecl
, szdecl
== rszdecl
? 2 : 0,
20953 add_AT_location_description (array_die
, DW_AT_string_length
,
20955 if (size
!= DWARF2_ADDR_SIZE
)
20956 add_AT_unsigned (array_die
, dwarf_version
>= 5
20957 ? DW_AT_string_length_byte_size
20958 : DW_AT_byte_size
, size
);
20965 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
20966 add_name_attribute (array_die
, type_tag (type
));
20967 equate_type_number_to_die (type
, array_die
);
20969 if (TREE_CODE (type
) == VECTOR_TYPE
)
20970 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
20972 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
20974 && TREE_CODE (type
) == ARRAY_TYPE
20975 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
20976 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
20977 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
20980 /* We default the array ordering. Debuggers will probably do the right
20981 things even if DW_AT_ordering is not present. It's not even an issue
20982 until we start to get into multidimensional arrays anyway. If a debugger
20983 is ever caught doing the Wrong Thing for multi-dimensional arrays,
20984 then we'll have to put the DW_AT_ordering attribute back in. (But if
20985 and when we find out that we need to put these in, we will only do so
20986 for multidimensional arrays. */
20987 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
20990 if (TREE_CODE (type
) == VECTOR_TYPE
)
20992 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
20993 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
20994 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
, NULL
);
20995 add_bound_info (subrange_die
, DW_AT_upper_bound
,
20996 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1), NULL
);
20999 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
21001 /* Add representation of the type of the elements of this array type and
21002 emit the corresponding DIE if we haven't done it already. */
21003 element_type
= TREE_TYPE (type
);
21004 if (collapse_nested_arrays
)
21005 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
21007 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
21009 element_type
= TREE_TYPE (element_type
);
21012 add_type_attribute (array_die
, element_type
, TYPE_UNQUALIFIED
,
21013 TREE_CODE (type
) == ARRAY_TYPE
21014 && TYPE_REVERSE_STORAGE_ORDER (type
),
21017 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
21018 if (TYPE_ARTIFICIAL (type
))
21019 add_AT_flag (array_die
, DW_AT_artificial
, 1);
21021 if (get_AT (array_die
, DW_AT_name
))
21022 add_pubtype (type
, array_die
);
21024 add_alignment_attribute (array_die
, type
);
21027 /* This routine generates DIE for array with hidden descriptor, details
21028 are filled into *info by a langhook. */
21031 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
21032 dw_die_ref context_die
)
21034 const dw_die_ref scope_die
= scope_die_for (type
, context_die
);
21035 const dw_die_ref array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
21036 struct loc_descr_context context
= { type
, info
->base_decl
, NULL
,
21038 enum dwarf_tag subrange_tag
= DW_TAG_subrange_type
;
21041 add_name_attribute (array_die
, type_tag (type
));
21042 equate_type_number_to_die (type
, array_die
);
21044 if (info
->ndimensions
> 1)
21045 switch (info
->ordering
)
21047 case array_descr_ordering_row_major
:
21048 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
21050 case array_descr_ordering_column_major
:
21051 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
21057 if (dwarf_version
>= 3 || !dwarf_strict
)
21059 if (info
->data_location
)
21060 add_scalar_info (array_die
, DW_AT_data_location
, info
->data_location
,
21061 dw_scalar_form_exprloc
, &context
);
21062 if (info
->associated
)
21063 add_scalar_info (array_die
, DW_AT_associated
, info
->associated
,
21064 dw_scalar_form_constant
21065 | dw_scalar_form_exprloc
21066 | dw_scalar_form_reference
, &context
);
21067 if (info
->allocated
)
21068 add_scalar_info (array_die
, DW_AT_allocated
, info
->allocated
,
21069 dw_scalar_form_constant
21070 | dw_scalar_form_exprloc
21071 | dw_scalar_form_reference
, &context
);
21074 const enum dwarf_attribute attr
21075 = (info
->stride_in_bits
) ? DW_AT_bit_stride
: DW_AT_byte_stride
;
21077 = (info
->stride_in_bits
)
21078 ? dw_scalar_form_constant
21079 : (dw_scalar_form_constant
21080 | dw_scalar_form_exprloc
21081 | dw_scalar_form_reference
);
21083 add_scalar_info (array_die
, attr
, info
->stride
, forms
, &context
);
21086 if (dwarf_version
>= 5)
21090 add_scalar_info (array_die
, DW_AT_rank
, info
->rank
,
21091 dw_scalar_form_constant
21092 | dw_scalar_form_exprloc
, &context
);
21093 subrange_tag
= DW_TAG_generic_subrange
;
21094 context
.placeholder_arg
= true;
21098 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
21100 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
21102 dw_die_ref subrange_die
= new_die (subrange_tag
, array_die
, NULL
);
21104 if (info
->dimen
[dim
].bounds_type
)
21105 add_type_attribute (subrange_die
,
21106 info
->dimen
[dim
].bounds_type
, TYPE_UNQUALIFIED
,
21107 false, context_die
);
21108 if (info
->dimen
[dim
].lower_bound
)
21109 add_bound_info (subrange_die
, DW_AT_lower_bound
,
21110 info
->dimen
[dim
].lower_bound
, &context
);
21111 if (info
->dimen
[dim
].upper_bound
)
21112 add_bound_info (subrange_die
, DW_AT_upper_bound
,
21113 info
->dimen
[dim
].upper_bound
, &context
);
21114 if ((dwarf_version
>= 3 || !dwarf_strict
) && info
->dimen
[dim
].stride
)
21115 add_scalar_info (subrange_die
, DW_AT_byte_stride
,
21116 info
->dimen
[dim
].stride
,
21117 dw_scalar_form_constant
21118 | dw_scalar_form_exprloc
21119 | dw_scalar_form_reference
,
21123 gen_type_die (info
->element_type
, context_die
);
21124 add_type_attribute (array_die
, info
->element_type
, TYPE_UNQUALIFIED
,
21125 TREE_CODE (type
) == ARRAY_TYPE
21126 && TYPE_REVERSE_STORAGE_ORDER (type
),
21129 if (get_AT (array_die
, DW_AT_name
))
21130 add_pubtype (type
, array_die
);
21132 add_alignment_attribute (array_die
, type
);
21137 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
21139 tree origin
= decl_ultimate_origin (decl
);
21140 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
21142 if (origin
!= NULL
)
21143 add_abstract_origin_attribute (decl_die
, origin
);
21146 add_name_and_src_coords_attributes (decl_die
, decl
);
21147 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
21148 TYPE_UNQUALIFIED
, false, context_die
);
21151 if (DECL_ABSTRACT_P (decl
))
21152 equate_decl_number_to_die (decl
, decl_die
);
21154 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
21158 /* Walk through the list of incomplete types again, trying once more to
21159 emit full debugging info for them. */
21162 retry_incomplete_types (void)
21167 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
21168 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
21169 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
21170 vec_safe_truncate (incomplete_types
, 0);
21173 /* Determine what tag to use for a record type. */
21175 static enum dwarf_tag
21176 record_type_tag (tree type
)
21178 if (! lang_hooks
.types
.classify_record
)
21179 return DW_TAG_structure_type
;
21181 switch (lang_hooks
.types
.classify_record (type
))
21183 case RECORD_IS_STRUCT
:
21184 return DW_TAG_structure_type
;
21186 case RECORD_IS_CLASS
:
21187 return DW_TAG_class_type
;
21189 case RECORD_IS_INTERFACE
:
21190 if (dwarf_version
>= 3 || !dwarf_strict
)
21191 return DW_TAG_interface_type
;
21192 return DW_TAG_structure_type
;
21195 gcc_unreachable ();
21199 /* Generate a DIE to represent an enumeration type. Note that these DIEs
21200 include all of the information about the enumeration values also. Each
21201 enumerated type name/value is listed as a child of the enumerated type
21205 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
21207 dw_die_ref type_die
= lookup_type_die (type
);
21209 if (type_die
== NULL
)
21211 type_die
= new_die (DW_TAG_enumeration_type
,
21212 scope_die_for (type
, context_die
), type
);
21213 equate_type_number_to_die (type
, type_die
);
21214 add_name_attribute (type_die
, type_tag (type
));
21215 if (dwarf_version
>= 4 || !dwarf_strict
)
21217 if (ENUM_IS_SCOPED (type
))
21218 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
21219 if (ENUM_IS_OPAQUE (type
))
21220 add_AT_flag (type_die
, DW_AT_declaration
, 1);
21223 add_AT_unsigned (type_die
, DW_AT_encoding
,
21224 TYPE_UNSIGNED (type
)
21228 else if (! TYPE_SIZE (type
))
21231 remove_AT (type_die
, DW_AT_declaration
);
21233 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
21234 given enum type is incomplete, do not generate the DW_AT_byte_size
21235 attribute or the DW_AT_element_list attribute. */
21236 if (TYPE_SIZE (type
))
21240 TREE_ASM_WRITTEN (type
) = 1;
21241 add_byte_size_attribute (type_die
, type
);
21242 add_alignment_attribute (type_die
, type
);
21243 if (dwarf_version
>= 3 || !dwarf_strict
)
21245 tree underlying
= lang_hooks
.types
.enum_underlying_base_type (type
);
21246 add_type_attribute (type_die
, underlying
, TYPE_UNQUALIFIED
, false,
21249 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
21251 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
21252 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
21255 /* If the first reference to this type was as the return type of an
21256 inline function, then it may not have a parent. Fix this now. */
21257 if (type_die
->die_parent
== NULL
)
21258 add_child_die (scope_die_for (type
, context_die
), type_die
);
21260 for (link
= TYPE_VALUES (type
);
21261 link
!= NULL
; link
= TREE_CHAIN (link
))
21263 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
21264 tree value
= TREE_VALUE (link
);
21266 add_name_attribute (enum_die
,
21267 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
21269 if (TREE_CODE (value
) == CONST_DECL
)
21270 value
= DECL_INITIAL (value
);
21272 if (simple_type_size_in_bits (TREE_TYPE (value
))
21273 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
21275 /* For constant forms created by add_AT_unsigned DWARF
21276 consumers (GDB, elfutils, etc.) always zero extend
21277 the value. Only when the actual value is negative
21278 do we need to use add_AT_int to generate a constant
21279 form that can represent negative values. */
21280 HOST_WIDE_INT val
= TREE_INT_CST_LOW (value
);
21281 if (TYPE_UNSIGNED (TREE_TYPE (value
)) || val
>= 0)
21282 add_AT_unsigned (enum_die
, DW_AT_const_value
,
21283 (unsigned HOST_WIDE_INT
) val
);
21285 add_AT_int (enum_die
, DW_AT_const_value
, val
);
21288 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
21289 that here. TODO: This should be re-worked to use correct
21290 signed/unsigned double tags for all cases. */
21291 add_AT_wide (enum_die
, DW_AT_const_value
, wi::to_wide (value
));
21294 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
21295 if (TYPE_ARTIFICIAL (type
))
21296 add_AT_flag (type_die
, DW_AT_artificial
, 1);
21299 add_AT_flag (type_die
, DW_AT_declaration
, 1);
21301 add_pubtype (type
, type_die
);
21306 /* Generate a DIE to represent either a real live formal parameter decl or to
21307 represent just the type of some formal parameter position in some function
21310 Note that this routine is a bit unusual because its argument may be a
21311 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
21312 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
21313 node. If it's the former then this function is being called to output a
21314 DIE to represent a formal parameter object (or some inlining thereof). If
21315 it's the latter, then this function is only being called to output a
21316 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
21317 argument type of some subprogram type.
21318 If EMIT_NAME_P is true, name and source coordinate attributes
21322 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
21323 dw_die_ref context_die
)
21325 tree node_or_origin
= node
? node
: origin
;
21326 tree ultimate_origin
;
21327 dw_die_ref parm_die
= NULL
;
21329 if (DECL_P (node_or_origin
))
21331 parm_die
= lookup_decl_die (node
);
21333 /* If the contexts differ, we may not be talking about the same
21335 ??? When in LTO the DIE parent is the "abstract" copy and the
21336 context_die is the specification "copy". But this whole block
21337 should eventually be no longer needed. */
21338 if (parm_die
&& parm_die
->die_parent
!= context_die
&& !in_lto_p
)
21340 if (!DECL_ABSTRACT_P (node
))
21342 /* This can happen when creating an inlined instance, in
21343 which case we need to create a new DIE that will get
21344 annotated with DW_AT_abstract_origin. */
21348 gcc_unreachable ();
21351 if (parm_die
&& parm_die
->die_parent
== NULL
)
21353 /* Check that parm_die already has the right attributes that
21354 we would have added below. If any attributes are
21355 missing, fall through to add them. */
21356 if (! DECL_ABSTRACT_P (node_or_origin
)
21357 && !get_AT (parm_die
, DW_AT_location
)
21358 && !get_AT (parm_die
, DW_AT_const_value
))
21359 /* We are missing location info, and are about to add it. */
21363 add_child_die (context_die
, parm_die
);
21369 /* If we have a previously generated DIE, use it, unless this is an
21370 concrete instance (origin != NULL), in which case we need a new
21371 DIE with a corresponding DW_AT_abstract_origin. */
21373 if (parm_die
&& origin
== NULL
)
21374 reusing_die
= true;
21377 parm_die
= new_die (DW_TAG_formal_parameter
, context_die
, node
);
21378 reusing_die
= false;
21381 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
21383 case tcc_declaration
:
21384 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
21385 if (node
|| ultimate_origin
)
21386 origin
= ultimate_origin
;
21391 if (origin
!= NULL
)
21392 add_abstract_origin_attribute (parm_die
, origin
);
21393 else if (emit_name_p
)
21394 add_name_and_src_coords_attributes (parm_die
, node
);
21396 || (! DECL_ABSTRACT_P (node_or_origin
)
21397 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
21398 decl_function_context
21399 (node_or_origin
))))
21401 tree type
= TREE_TYPE (node_or_origin
);
21402 if (decl_by_reference_p (node_or_origin
))
21403 add_type_attribute (parm_die
, TREE_TYPE (type
),
21405 false, context_die
);
21407 add_type_attribute (parm_die
, type
,
21408 decl_quals (node_or_origin
),
21409 false, context_die
);
21411 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
21412 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
21414 if (node
&& node
!= origin
)
21415 equate_decl_number_to_die (node
, parm_die
);
21416 if (! DECL_ABSTRACT_P (node_or_origin
))
21417 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
21423 /* We were called with some kind of a ..._TYPE node. */
21424 add_type_attribute (parm_die
, node_or_origin
, TYPE_UNQUALIFIED
, false,
21429 gcc_unreachable ();
21435 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
21436 children DW_TAG_formal_parameter DIEs representing the arguments of the
21439 PARM_PACK must be a function parameter pack.
21440 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
21441 must point to the subsequent arguments of the function PACK_ARG belongs to.
21442 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
21443 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
21444 following the last one for which a DIE was generated. */
21447 gen_formal_parameter_pack_die (tree parm_pack
,
21449 dw_die_ref subr_die
,
21453 dw_die_ref parm_pack_die
;
21455 gcc_assert (parm_pack
21456 && lang_hooks
.function_parameter_pack_p (parm_pack
)
21459 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
21460 add_src_coords_attributes (parm_pack_die
, parm_pack
);
21462 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
21464 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
21467 gen_formal_parameter_die (arg
, NULL
,
21468 false /* Don't emit name attribute. */,
21473 return parm_pack_die
;
21476 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
21477 at the end of an (ANSI prototyped) formal parameters list. */
21480 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
21482 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
21485 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
21486 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
21487 parameters as specified in some function type specification (except for
21488 those which appear as part of a function *definition*). */
21491 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
21494 tree formal_type
= NULL
;
21495 tree first_parm_type
;
21498 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
21500 arg
= DECL_ARGUMENTS (function_or_method_type
);
21501 function_or_method_type
= TREE_TYPE (function_or_method_type
);
21506 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
21508 /* Make our first pass over the list of formal parameter types and output a
21509 DW_TAG_formal_parameter DIE for each one. */
21510 for (link
= first_parm_type
; link
; )
21512 dw_die_ref parm_die
;
21514 formal_type
= TREE_VALUE (link
);
21515 if (formal_type
== void_type_node
)
21518 /* Output a (nameless) DIE to represent the formal parameter itself. */
21519 if (!POINTER_BOUNDS_TYPE_P (formal_type
))
21521 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
21522 true /* Emit name attribute. */,
21524 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
21525 && link
== first_parm_type
)
21527 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
21528 if (dwarf_version
>= 3 || !dwarf_strict
)
21529 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
21531 else if (arg
&& DECL_ARTIFICIAL (arg
))
21532 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
21535 link
= TREE_CHAIN (link
);
21537 arg
= DECL_CHAIN (arg
);
21540 /* If this function type has an ellipsis, add a
21541 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
21542 if (formal_type
!= void_type_node
)
21543 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
21545 /* Make our second (and final) pass over the list of formal parameter types
21546 and output DIEs to represent those types (as necessary). */
21547 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
21548 link
&& TREE_VALUE (link
);
21549 link
= TREE_CHAIN (link
))
21550 gen_type_die (TREE_VALUE (link
), context_die
);
21553 /* We want to generate the DIE for TYPE so that we can generate the
21554 die for MEMBER, which has been defined; we will need to refer back
21555 to the member declaration nested within TYPE. If we're trying to
21556 generate minimal debug info for TYPE, processing TYPE won't do the
21557 trick; we need to attach the member declaration by hand. */
21560 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
21562 gen_type_die (type
, context_die
);
21564 /* If we're trying to avoid duplicate debug info, we may not have
21565 emitted the member decl for this function. Emit it now. */
21566 if (TYPE_STUB_DECL (type
)
21567 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
21568 && ! lookup_decl_die (member
))
21570 dw_die_ref type_die
;
21571 gcc_assert (!decl_ultimate_origin (member
));
21573 push_decl_scope (type
);
21574 type_die
= lookup_type_die_strip_naming_typedef (type
);
21575 if (TREE_CODE (member
) == FUNCTION_DECL
)
21576 gen_subprogram_die (member
, type_die
);
21577 else if (TREE_CODE (member
) == FIELD_DECL
)
21579 /* Ignore the nameless fields that are used to skip bits but handle
21580 C++ anonymous unions and structs. */
21581 if (DECL_NAME (member
) != NULL_TREE
21582 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
21583 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
21585 struct vlr_context vlr_ctx
= {
21586 DECL_CONTEXT (member
), /* struct_type */
21587 NULL_TREE
/* variant_part_offset */
21589 gen_type_die (member_declared_type (member
), type_die
);
21590 gen_field_die (member
, &vlr_ctx
, type_die
);
21594 gen_variable_die (member
, NULL_TREE
, type_die
);
21600 /* Forward declare these functions, because they are mutually recursive
21601 with their set_block_* pairing functions. */
21602 static void set_decl_origin_self (tree
);
21604 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
21605 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
21606 that it points to the node itself, thus indicating that the node is its
21607 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
21608 the given node is NULL, recursively descend the decl/block tree which
21609 it is the root of, and for each other ..._DECL or BLOCK node contained
21610 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
21611 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
21612 values to point to themselves. */
21615 set_block_origin_self (tree stmt
)
21617 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
21619 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
21624 for (local_decl
= BLOCK_VARS (stmt
);
21625 local_decl
!= NULL_TREE
;
21626 local_decl
= DECL_CHAIN (local_decl
))
21627 /* Do not recurse on nested functions since the inlining status
21628 of parent and child can be different as per the DWARF spec. */
21629 if (TREE_CODE (local_decl
) != FUNCTION_DECL
21630 && !DECL_EXTERNAL (local_decl
))
21631 set_decl_origin_self (local_decl
);
21637 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
21638 subblock
!= NULL_TREE
;
21639 subblock
= BLOCK_CHAIN (subblock
))
21640 set_block_origin_self (subblock
); /* Recurse. */
21645 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
21646 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
21647 node to so that it points to the node itself, thus indicating that the
21648 node represents its own (abstract) origin. Additionally, if the
21649 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
21650 the decl/block tree of which the given node is the root of, and for
21651 each other ..._DECL or BLOCK node contained therein whose
21652 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
21653 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
21654 point to themselves. */
21657 set_decl_origin_self (tree decl
)
21659 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
21661 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
21662 if (TREE_CODE (decl
) == FUNCTION_DECL
)
21666 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
21667 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
21668 if (DECL_INITIAL (decl
) != NULL_TREE
21669 && DECL_INITIAL (decl
) != error_mark_node
)
21670 set_block_origin_self (DECL_INITIAL (decl
));
21675 /* Mark the early DIE for DECL as the abstract instance. */
21678 dwarf2out_abstract_function (tree decl
)
21680 dw_die_ref old_die
;
21682 /* Make sure we have the actual abstract inline, not a clone. */
21683 decl
= DECL_ORIGIN (decl
);
21685 if (DECL_IGNORED_P (decl
))
21688 old_die
= lookup_decl_die (decl
);
21689 /* With early debug we always have an old DIE unless we are in LTO
21690 and the user did not compile but only link with debug. */
21691 if (in_lto_p
&& ! old_die
)
21693 gcc_assert (old_die
!= NULL
);
21694 if (get_AT (old_die
, DW_AT_inline
)
21695 || get_AT (old_die
, DW_AT_abstract_origin
))
21696 /* We've already generated the abstract instance. */
21699 /* Go ahead and put DW_AT_inline on the DIE. */
21700 if (DECL_DECLARED_INLINE_P (decl
))
21702 if (cgraph_function_possibly_inlined_p (decl
))
21703 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_declared_inlined
);
21705 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
21709 if (cgraph_function_possibly_inlined_p (decl
))
21710 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_inlined
);
21712 add_AT_unsigned (old_die
, DW_AT_inline
, DW_INL_not_inlined
);
21715 if (DECL_DECLARED_INLINE_P (decl
)
21716 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
21717 add_AT_flag (old_die
, DW_AT_artificial
, 1);
21719 set_decl_origin_self (decl
);
21722 /* Helper function of premark_used_types() which gets called through
21725 Marks the DIE of a given type in *SLOT as perennial, so it never gets
21726 marked as unused by prune_unused_types. */
21729 premark_used_types_helper (tree
const &type
, void *)
21733 die
= lookup_type_die (type
);
21735 die
->die_perennial_p
= 1;
21739 /* Helper function of premark_types_used_by_global_vars which gets called
21740 through htab_traverse.
21742 Marks the DIE of a given type in *SLOT as perennial, so it never gets
21743 marked as unused by prune_unused_types. The DIE of the type is marked
21744 only if the global variable using the type will actually be emitted. */
21747 premark_types_used_by_global_vars_helper (types_used_by_vars_entry
**slot
,
21750 struct types_used_by_vars_entry
*entry
;
21753 entry
= (struct types_used_by_vars_entry
*) *slot
;
21754 gcc_assert (entry
->type
!= NULL
21755 && entry
->var_decl
!= NULL
);
21756 die
= lookup_type_die (entry
->type
);
21759 /* Ask cgraph if the global variable really is to be emitted.
21760 If yes, then we'll keep the DIE of ENTRY->TYPE. */
21761 varpool_node
*node
= varpool_node::get (entry
->var_decl
);
21762 if (node
&& node
->definition
)
21764 die
->die_perennial_p
= 1;
21765 /* Keep the parent DIEs as well. */
21766 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
21767 die
->die_perennial_p
= 1;
21773 /* Mark all members of used_types_hash as perennial. */
21776 premark_used_types (struct function
*fun
)
21778 if (fun
&& fun
->used_types_hash
)
21779 fun
->used_types_hash
->traverse
<void *, premark_used_types_helper
> (NULL
);
21782 /* Mark all members of types_used_by_vars_entry as perennial. */
21785 premark_types_used_by_global_vars (void)
21787 if (types_used_by_vars_hash
)
21788 types_used_by_vars_hash
21789 ->traverse
<void *, premark_types_used_by_global_vars_helper
> (NULL
);
21792 /* Generate a DW_TAG_call_site DIE in function DECL under SUBR_DIE
21793 for CA_LOC call arg loc node. */
21796 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
21797 struct call_arg_loc_node
*ca_loc
)
21799 dw_die_ref stmt_die
= NULL
, die
;
21800 tree block
= ca_loc
->block
;
21803 && block
!= DECL_INITIAL (decl
)
21804 && TREE_CODE (block
) == BLOCK
)
21806 stmt_die
= BLOCK_DIE (block
);
21809 block
= BLOCK_SUPERCONTEXT (block
);
21811 if (stmt_die
== NULL
)
21812 stmt_die
= subr_die
;
21813 die
= new_die (dwarf_TAG (DW_TAG_call_site
), stmt_die
, NULL_TREE
);
21814 add_AT_lbl_id (die
, dwarf_AT (DW_AT_call_return_pc
), ca_loc
->label
);
21815 if (ca_loc
->tail_call_p
)
21816 add_AT_flag (die
, dwarf_AT (DW_AT_call_tail_call
), 1);
21817 if (ca_loc
->symbol_ref
)
21819 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
21821 add_AT_die_ref (die
, dwarf_AT (DW_AT_call_origin
), tdie
);
21823 add_AT_addr (die
, dwarf_AT (DW_AT_call_origin
), ca_loc
->symbol_ref
,
21829 /* Generate a DIE to represent a declared function (either file-scope or
21833 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
21835 tree origin
= decl_ultimate_origin (decl
);
21836 dw_die_ref subr_die
;
21837 dw_die_ref old_die
= lookup_decl_die (decl
);
21839 /* This function gets called multiple times for different stages of
21840 the debug process. For example, for func() in this code:
21844 void func() { ... }
21847 ...we get called 4 times. Twice in early debug and twice in
21853 1. Once while generating func() within the namespace. This is
21854 the declaration. The declaration bit below is set, as the
21855 context is the namespace.
21857 A new DIE will be generated with DW_AT_declaration set.
21859 2. Once for func() itself. This is the specification. The
21860 declaration bit below is clear as the context is the CU.
21862 We will use the cached DIE from (1) to create a new DIE with
21863 DW_AT_specification pointing to the declaration in (1).
21865 Late debug via rest_of_handle_final()
21866 -------------------------------------
21868 3. Once generating func() within the namespace. This is also the
21869 declaration, as in (1), but this time we will early exit below
21870 as we have a cached DIE and a declaration needs no additional
21871 annotations (no locations), as the source declaration line
21874 4. Once for func() itself. As in (2), this is the specification,
21875 but this time we will re-use the cached DIE, and just annotate
21876 it with the location information that should now be available.
21878 For something without namespaces, but with abstract instances, we
21879 are also called a multiple times:
21884 Base (); // constructor declaration (1)
21887 Base::Base () { } // constructor specification (2)
21892 1. Once for the Base() constructor by virtue of it being a
21893 member of the Base class. This is done via
21894 rest_of_type_compilation.
21896 This is a declaration, so a new DIE will be created with
21899 2. Once for the Base() constructor definition, but this time
21900 while generating the abstract instance of the base
21901 constructor (__base_ctor) which is being generated via early
21902 debug of reachable functions.
21904 Even though we have a cached version of the declaration (1),
21905 we will create a DW_AT_specification of the declaration DIE
21908 3. Once for the __base_ctor itself, but this time, we generate
21909 an DW_AT_abstract_origin version of the DW_AT_specification in
21912 Late debug via rest_of_handle_final
21913 -----------------------------------
21915 4. One final time for the __base_ctor (which will have a cached
21916 DIE with DW_AT_abstract_origin created in (3). This time,
21917 we will just annotate the location information now
21920 int declaration
= (current_function_decl
!= decl
21921 || class_or_namespace_scope_p (context_die
));
21923 /* Now that the C++ front end lazily declares artificial member fns, we
21924 might need to retrofit the declaration into its class. */
21925 if (!declaration
&& !origin
&& !old_die
21926 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
21927 && !class_or_namespace_scope_p (context_die
)
21928 && debug_info_level
> DINFO_LEVEL_TERSE
)
21929 old_die
= force_decl_die (decl
);
21931 /* A concrete instance, tag a new DIE with DW_AT_abstract_origin. */
21932 if (origin
!= NULL
)
21934 gcc_assert (!declaration
|| local_scope_p (context_die
));
21936 /* Fixup die_parent for the abstract instance of a nested
21937 inline function. */
21938 if (old_die
&& old_die
->die_parent
== NULL
)
21939 add_child_die (context_die
, old_die
);
21941 if (old_die
&& get_AT_ref (old_die
, DW_AT_abstract_origin
))
21943 /* If we have a DW_AT_abstract_origin we have a working
21945 subr_die
= old_die
;
21949 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
21950 add_abstract_origin_attribute (subr_die
, origin
);
21951 /* This is where the actual code for a cloned function is.
21952 Let's emit linkage name attribute for it. This helps
21953 debuggers to e.g, set breakpoints into
21954 constructors/destructors when the user asks "break
21956 add_linkage_name (subr_die
, decl
);
21959 /* A cached copy, possibly from early dwarf generation. Reuse as
21960 much as possible. */
21963 /* A declaration that has been previously dumped needs no
21964 additional information. */
21968 if (!get_AT_flag (old_die
, DW_AT_declaration
)
21969 /* We can have a normal definition following an inline one in the
21970 case of redefinition of GNU C extern inlines.
21971 It seems reasonable to use AT_specification in this case. */
21972 && !get_AT (old_die
, DW_AT_inline
))
21974 /* Detect and ignore this case, where we are trying to output
21975 something we have already output. */
21976 if (get_AT (old_die
, DW_AT_low_pc
)
21977 || get_AT (old_die
, DW_AT_ranges
))
21980 /* If we have no location information, this must be a
21981 partially generated DIE from early dwarf generation.
21982 Fall through and generate it. */
21985 /* If the definition comes from the same place as the declaration,
21986 maybe use the old DIE. We always want the DIE for this function
21987 that has the *_pc attributes to be under comp_unit_die so the
21988 debugger can find it. We also need to do this for abstract
21989 instances of inlines, since the spec requires the out-of-line copy
21990 to have the same parent. For local class methods, this doesn't
21991 apply; we just use the old DIE. */
21992 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
21993 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
21994 if ((is_cu_die (old_die
->die_parent
)
21995 /* This condition fixes the inconsistency/ICE with the
21996 following Fortran test (or some derivative thereof) while
21997 building libgfortran:
22001 logical function funky (FLAG)
22006 || (old_die
->die_parent
22007 && old_die
->die_parent
->die_tag
== DW_TAG_module
)
22008 || context_die
== NULL
)
22009 && (DECL_ARTIFICIAL (decl
)
22010 /* The location attributes may be in the abstract origin
22011 which in the case of LTO might be not available to
22013 || get_AT (old_die
, DW_AT_abstract_origin
)
22014 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
22015 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
22016 == (unsigned) s
.line
)
22017 && (!debug_column_info
22019 || (get_AT_unsigned (old_die
, DW_AT_decl_column
)
22020 == (unsigned) s
.column
)))))
22022 subr_die
= old_die
;
22024 /* Clear out the declaration attribute, but leave the
22025 parameters so they can be augmented with location
22026 information later. Unless this was a declaration, in
22027 which case, wipe out the nameless parameters and recreate
22028 them further down. */
22029 if (remove_AT (subr_die
, DW_AT_declaration
))
22032 remove_AT (subr_die
, DW_AT_object_pointer
);
22033 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
22036 /* Make a specification pointing to the previously built
22040 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
22041 add_AT_specification (subr_die
, old_die
);
22042 add_pubname (decl
, subr_die
);
22043 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
22044 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
22045 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
22046 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
22047 if (debug_column_info
22049 && (get_AT_unsigned (old_die
, DW_AT_decl_column
)
22050 != (unsigned) s
.column
))
22051 add_AT_unsigned (subr_die
, DW_AT_decl_column
, s
.column
);
22053 /* If the prototype had an 'auto' or 'decltype(auto)' return type,
22054 emit the real type on the definition die. */
22055 if (is_cxx () && debug_info_level
> DINFO_LEVEL_TERSE
)
22057 dw_die_ref die
= get_AT_ref (old_die
, DW_AT_type
);
22058 if (die
== auto_die
|| die
== decltype_auto_die
)
22059 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
22060 TYPE_UNQUALIFIED
, false, context_die
);
22063 /* When we process the method declaration, we haven't seen
22064 the out-of-class defaulted definition yet, so we have to
22066 if ((dwarf_version
>= 5 || ! dwarf_strict
)
22067 && !get_AT (subr_die
, DW_AT_defaulted
))
22070 = lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22072 if (defaulted
!= -1)
22074 /* Other values must have been handled before. */
22075 gcc_assert (defaulted
== DW_DEFAULTED_out_of_class
);
22076 add_AT_unsigned (subr_die
, DW_AT_defaulted
, defaulted
);
22081 /* Create a fresh DIE for anything else. */
22084 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
22086 if (TREE_PUBLIC (decl
))
22087 add_AT_flag (subr_die
, DW_AT_external
, 1);
22089 add_name_and_src_coords_attributes (subr_die
, decl
);
22090 add_pubname (decl
, subr_die
);
22091 if (debug_info_level
> DINFO_LEVEL_TERSE
)
22093 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
22094 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
22095 TYPE_UNQUALIFIED
, false, context_die
);
22098 add_pure_or_virtual_attribute (subr_die
, decl
);
22099 if (DECL_ARTIFICIAL (decl
))
22100 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
22102 if (TREE_THIS_VOLATILE (decl
) && (dwarf_version
>= 5 || !dwarf_strict
))
22103 add_AT_flag (subr_die
, DW_AT_noreturn
, 1);
22105 add_alignment_attribute (subr_die
, decl
);
22107 add_accessibility_attribute (subr_die
, decl
);
22110 /* Unless we have an existing non-declaration DIE, equate the new
22112 if (!old_die
|| is_declaration_die (old_die
))
22113 equate_decl_number_to_die (decl
, subr_die
);
22117 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
22119 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
22121 /* If this is an explicit function declaration then generate
22122 a DW_AT_explicit attribute. */
22123 if ((dwarf_version
>= 3 || !dwarf_strict
)
22124 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22125 DW_AT_explicit
) == 1)
22126 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
22128 /* If this is a C++11 deleted special function member then generate
22129 a DW_AT_deleted attribute. */
22130 if ((dwarf_version
>= 5 || !dwarf_strict
)
22131 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22132 DW_AT_deleted
) == 1)
22133 add_AT_flag (subr_die
, DW_AT_deleted
, 1);
22135 /* If this is a C++11 defaulted special function member then
22136 generate a DW_AT_defaulted attribute. */
22137 if (dwarf_version
>= 5 || !dwarf_strict
)
22140 = lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22142 if (defaulted
!= -1)
22143 add_AT_unsigned (subr_die
, DW_AT_defaulted
, defaulted
);
22146 /* If this is a C++11 non-static member function with & ref-qualifier
22147 then generate a DW_AT_reference attribute. */
22148 if ((dwarf_version
>= 5 || !dwarf_strict
)
22149 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22150 DW_AT_reference
) == 1)
22151 add_AT_flag (subr_die
, DW_AT_reference
, 1);
22153 /* If this is a C++11 non-static member function with &&
22154 ref-qualifier then generate a DW_AT_reference attribute. */
22155 if ((dwarf_version
>= 5 || !dwarf_strict
)
22156 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22157 DW_AT_rvalue_reference
)
22159 add_AT_flag (subr_die
, DW_AT_rvalue_reference
, 1);
22162 /* For non DECL_EXTERNALs, if range information is available, fill
22163 the DIE with it. */
22164 else if (!DECL_EXTERNAL (decl
) && !early_dwarf
)
22166 HOST_WIDE_INT cfa_fb_offset
;
22168 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
22170 if (!crtl
->has_bb_partition
)
22172 dw_fde_ref fde
= fun
->fde
;
22173 if (fde
->dw_fde_begin
)
22175 /* We have already generated the labels. */
22176 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
22177 fde
->dw_fde_end
, false);
22181 /* Create start/end labels and add the range. */
22182 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
22183 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
22184 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
22185 current_function_funcdef_no
);
22186 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
22187 current_function_funcdef_no
);
22188 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
22192 #if VMS_DEBUGGING_INFO
22193 /* HP OpenVMS Industry Standard 64: DWARF Extensions
22194 Section 2.3 Prologue and Epilogue Attributes:
22195 When a breakpoint is set on entry to a function, it is generally
22196 desirable for execution to be suspended, not on the very first
22197 instruction of the function, but rather at a point after the
22198 function's frame has been set up, after any language defined local
22199 declaration processing has been completed, and before execution of
22200 the first statement of the function begins. Debuggers generally
22201 cannot properly determine where this point is. Similarly for a
22202 breakpoint set on exit from a function. The prologue and epilogue
22203 attributes allow a compiler to communicate the location(s) to use. */
22206 if (fde
->dw_fde_vms_end_prologue
)
22207 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
22208 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
22210 if (fde
->dw_fde_vms_begin_epilogue
)
22211 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
22212 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
22219 /* Generate pubnames entries for the split function code ranges. */
22220 dw_fde_ref fde
= fun
->fde
;
22222 if (fde
->dw_fde_second_begin
)
22224 if (dwarf_version
>= 3 || !dwarf_strict
)
22226 /* We should use ranges for non-contiguous code section
22227 addresses. Use the actual code range for the initial
22228 section, since the HOT/COLD labels might precede an
22229 alignment offset. */
22230 bool range_list_added
= false;
22231 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
22232 fde
->dw_fde_end
, &range_list_added
,
22234 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
22235 fde
->dw_fde_second_end
,
22236 &range_list_added
, false);
22237 if (range_list_added
)
22242 /* There is no real support in DW2 for this .. so we make
22243 a work-around. First, emit the pub name for the segment
22244 containing the function label. Then make and emit a
22245 simplified subprogram DIE for the second segment with the
22246 name pre-fixed by __hot/cold_sect_of_. We use the same
22247 linkage name for the second die so that gdb will find both
22248 sections when given "b foo". */
22249 const char *name
= NULL
;
22250 tree decl_name
= DECL_NAME (decl
);
22251 dw_die_ref seg_die
;
22253 /* Do the 'primary' section. */
22254 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
22255 fde
->dw_fde_end
, false);
22257 /* Build a minimal DIE for the secondary section. */
22258 seg_die
= new_die (DW_TAG_subprogram
,
22259 subr_die
->die_parent
, decl
);
22261 if (TREE_PUBLIC (decl
))
22262 add_AT_flag (seg_die
, DW_AT_external
, 1);
22264 if (decl_name
!= NULL
22265 && IDENTIFIER_POINTER (decl_name
) != NULL
)
22267 name
= dwarf2_name (decl
, 1);
22268 if (! DECL_ARTIFICIAL (decl
))
22269 add_src_coords_attributes (seg_die
, decl
);
22271 add_linkage_name (seg_die
, decl
);
22273 gcc_assert (name
!= NULL
);
22274 add_pure_or_virtual_attribute (seg_die
, decl
);
22275 if (DECL_ARTIFICIAL (decl
))
22276 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
22278 name
= concat ("__second_sect_of_", name
, NULL
);
22279 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
22280 fde
->dw_fde_second_end
, false);
22281 add_name_attribute (seg_die
, name
);
22282 if (want_pubnames ())
22283 add_pubname_string (name
, seg_die
);
22287 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
22291 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
22293 /* We define the "frame base" as the function's CFA. This is more
22294 convenient for several reasons: (1) It's stable across the prologue
22295 and epilogue, which makes it better than just a frame pointer,
22296 (2) With dwarf3, there exists a one-byte encoding that allows us
22297 to reference the .debug_frame data by proxy, but failing that,
22298 (3) We can at least reuse the code inspection and interpretation
22299 code that determines the CFA position at various points in the
22301 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
22303 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
22304 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
22308 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
22309 if (list
->dw_loc_next
)
22310 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
22312 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
22315 /* Compute a displacement from the "steady-state frame pointer" to
22316 the CFA. The former is what all stack slots and argument slots
22317 will reference in the rtl; the latter is what we've told the
22318 debugger about. We'll need to adjust all frame_base references
22319 by this displacement. */
22320 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
22322 if (fun
->static_chain_decl
)
22324 /* DWARF requires here a location expression that computes the
22325 address of the enclosing subprogram's frame base. The machinery
22326 in tree-nested.c is supposed to store this specific address in the
22327 last field of the FRAME record. */
22328 const tree frame_type
22329 = TREE_TYPE (TREE_TYPE (fun
->static_chain_decl
));
22330 const tree fb_decl
= tree_last (TYPE_FIELDS (frame_type
));
22333 = build1 (INDIRECT_REF
, frame_type
, fun
->static_chain_decl
);
22334 fb_expr
= build3 (COMPONENT_REF
, TREE_TYPE (fb_decl
),
22335 fb_expr
, fb_decl
, NULL_TREE
);
22337 add_AT_location_description (subr_die
, DW_AT_static_link
,
22338 loc_list_from_tree (fb_expr
, 0, NULL
));
22341 resolve_variable_values ();
22344 /* Generate child dies for template paramaters. */
22345 if (early_dwarf
&& debug_info_level
> DINFO_LEVEL_TERSE
)
22346 gen_generic_params_dies (decl
);
22348 /* Now output descriptions of the arguments for this function. This gets
22349 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
22350 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
22351 `...' at the end of the formal parameter list. In order to find out if
22352 there was a trailing ellipsis or not, we must instead look at the type
22353 associated with the FUNCTION_DECL. This will be a node of type
22354 FUNCTION_TYPE. If the chain of type nodes hanging off of this
22355 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
22356 an ellipsis at the end. */
22358 /* In the case where we are describing a mere function declaration, all we
22359 need to do here (and all we *can* do here) is to describe the *types* of
22360 its formal parameters. */
22361 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
22363 else if (declaration
)
22364 gen_formal_types_die (decl
, subr_die
);
22367 /* Generate DIEs to represent all known formal parameters. */
22368 tree parm
= DECL_ARGUMENTS (decl
);
22369 tree generic_decl
= early_dwarf
22370 ? lang_hooks
.decls
.get_generic_function_decl (decl
) : NULL
;
22371 tree generic_decl_parm
= generic_decl
22372 ? DECL_ARGUMENTS (generic_decl
)
22375 /* Now we want to walk the list of parameters of the function and
22376 emit their relevant DIEs.
22378 We consider the case of DECL being an instance of a generic function
22379 as well as it being a normal function.
22381 If DECL is an instance of a generic function we walk the
22382 parameters of the generic function declaration _and_ the parameters of
22383 DECL itself. This is useful because we want to emit specific DIEs for
22384 function parameter packs and those are declared as part of the
22385 generic function declaration. In that particular case,
22386 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
22387 That DIE has children DIEs representing the set of arguments
22388 of the pack. Note that the set of pack arguments can be empty.
22389 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
22392 Otherwise, we just consider the parameters of DECL. */
22393 while (generic_decl_parm
|| parm
)
22395 if (generic_decl_parm
22396 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
22397 gen_formal_parameter_pack_die (generic_decl_parm
,
22400 else if (parm
&& !POINTER_BOUNDS_P (parm
))
22402 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, NULL
, subr_die
);
22405 && parm
== DECL_ARGUMENTS (decl
)
22406 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
22408 && (dwarf_version
>= 3 || !dwarf_strict
))
22409 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
22411 parm
= DECL_CHAIN (parm
);
22414 parm
= DECL_CHAIN (parm
);
22416 if (generic_decl_parm
)
22417 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
22420 /* Decide whether we need an unspecified_parameters DIE at the end.
22421 There are 2 more cases to do this for: 1) the ansi ... declaration -
22422 this is detectable when the end of the arg list is not a
22423 void_type_node 2) an unprototyped function declaration (not a
22424 definition). This just means that we have no info about the
22425 parameters at all. */
22428 if (prototype_p (TREE_TYPE (decl
)))
22430 /* This is the prototyped case, check for.... */
22431 if (stdarg_p (TREE_TYPE (decl
)))
22432 gen_unspecified_parameters_die (decl
, subr_die
);
22434 else if (DECL_INITIAL (decl
) == NULL_TREE
)
22435 gen_unspecified_parameters_die (decl
, subr_die
);
22439 if (subr_die
!= old_die
)
22440 /* Add the calling convention attribute if requested. */
22441 add_calling_convention_attribute (subr_die
, decl
);
22443 /* Output Dwarf info for all of the stuff within the body of the function
22444 (if it has one - it may be just a declaration).
22446 OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
22447 a function. This BLOCK actually represents the outermost binding contour
22448 for the function, i.e. the contour in which the function's formal
22449 parameters and labels get declared. Curiously, it appears that the front
22450 end doesn't actually put the PARM_DECL nodes for the current function onto
22451 the BLOCK_VARS list for this outer scope, but are strung off of the
22452 DECL_ARGUMENTS list for the function instead.
22454 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
22455 the LABEL_DECL nodes for the function however, and we output DWARF info
22456 for those in decls_for_scope. Just within the `outer_scope' there will be
22457 a BLOCK node representing the function's outermost pair of curly braces,
22458 and any blocks used for the base and member initializers of a C++
22459 constructor function. */
22460 tree outer_scope
= DECL_INITIAL (decl
);
22461 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
22463 int call_site_note_count
= 0;
22464 int tail_call_site_note_count
= 0;
22466 /* Emit a DW_TAG_variable DIE for a named return value. */
22467 if (DECL_NAME (DECL_RESULT (decl
)))
22468 gen_decl_die (DECL_RESULT (decl
), NULL
, NULL
, subr_die
);
22470 /* The first time through decls_for_scope we will generate the
22471 DIEs for the locals. The second time, we fill in the
22473 decls_for_scope (outer_scope
, subr_die
);
22475 if (call_arg_locations
&& (!dwarf_strict
|| dwarf_version
>= 5))
22477 struct call_arg_loc_node
*ca_loc
;
22478 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
22480 dw_die_ref die
= NULL
;
22481 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
22484 for (arg
= (ca_loc
->call_arg_loc_note
!= NULL_RTX
22485 ? NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
)
22487 arg
; arg
= next_arg
)
22489 dw_loc_descr_ref reg
, val
;
22490 machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
22491 dw_die_ref cdie
, tdie
= NULL
;
22493 next_arg
= XEXP (arg
, 1);
22494 if (REG_P (XEXP (XEXP (arg
, 0), 0))
22496 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
22497 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
22498 && REGNO (XEXP (XEXP (arg
, 0), 0))
22499 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
22500 next_arg
= XEXP (next_arg
, 1);
22501 if (mode
== VOIDmode
)
22503 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
22504 if (mode
== VOIDmode
)
22505 mode
= GET_MODE (XEXP (arg
, 0));
22507 if (mode
== VOIDmode
|| mode
== BLKmode
)
22509 /* Get dynamic information about call target only if we
22510 have no static information: we cannot generate both
22511 DW_AT_call_origin and DW_AT_call_target
22513 if (ca_loc
->symbol_ref
== NULL_RTX
)
22515 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
22517 tloc
= XEXP (XEXP (arg
, 0), 1);
22520 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
22521 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
22523 tlocc
= XEXP (XEXP (arg
, 0), 1);
22528 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
22529 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
22530 VAR_INIT_STATUS_INITIALIZED
);
22531 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
22533 rtx mem
= XEXP (XEXP (arg
, 0), 0);
22534 reg
= mem_loc_descriptor (XEXP (mem
, 0),
22535 get_address_mode (mem
),
22537 VAR_INIT_STATUS_INITIALIZED
);
22539 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
22540 == DEBUG_PARAMETER_REF
)
22543 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
22544 tdie
= lookup_decl_die (tdecl
);
22551 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
22552 != DEBUG_PARAMETER_REF
)
22554 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
22556 VAR_INIT_STATUS_INITIALIZED
);
22560 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
22561 cdie
= new_die (dwarf_TAG (DW_TAG_call_site_parameter
), die
,
22564 add_AT_loc (cdie
, DW_AT_location
, reg
);
22565 else if (tdie
!= NULL
)
22566 add_AT_die_ref (cdie
, dwarf_AT (DW_AT_call_parameter
),
22568 add_AT_loc (cdie
, dwarf_AT (DW_AT_call_value
), val
);
22569 if (next_arg
!= XEXP (arg
, 1))
22571 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
22572 if (mode
== VOIDmode
)
22573 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
22574 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
22577 VAR_INIT_STATUS_INITIALIZED
);
22579 add_AT_loc (cdie
, dwarf_AT (DW_AT_call_data_value
),
22584 && (ca_loc
->symbol_ref
|| tloc
))
22585 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
22586 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
22588 dw_loc_descr_ref tval
= NULL
;
22590 if (tloc
!= NULL_RTX
)
22591 tval
= mem_loc_descriptor (tloc
,
22592 GET_MODE (tloc
) == VOIDmode
22593 ? Pmode
: GET_MODE (tloc
),
22595 VAR_INIT_STATUS_INITIALIZED
);
22597 add_AT_loc (die
, dwarf_AT (DW_AT_call_target
), tval
);
22598 else if (tlocc
!= NULL_RTX
)
22600 tval
= mem_loc_descriptor (tlocc
,
22601 GET_MODE (tlocc
) == VOIDmode
22602 ? Pmode
: GET_MODE (tlocc
),
22604 VAR_INIT_STATUS_INITIALIZED
);
22607 dwarf_AT (DW_AT_call_target_clobbered
),
22613 call_site_note_count
++;
22614 if (ca_loc
->tail_call_p
)
22615 tail_call_site_note_count
++;
22619 call_arg_locations
= NULL
;
22620 call_arg_loc_last
= NULL
;
22621 if (tail_call_site_count
>= 0
22622 && tail_call_site_count
== tail_call_site_note_count
22623 && (!dwarf_strict
|| dwarf_version
>= 5))
22625 if (call_site_count
>= 0
22626 && call_site_count
== call_site_note_count
)
22627 add_AT_flag (subr_die
, dwarf_AT (DW_AT_call_all_calls
), 1);
22629 add_AT_flag (subr_die
, dwarf_AT (DW_AT_call_all_tail_calls
), 1);
22631 call_site_count
= -1;
22632 tail_call_site_count
= -1;
22635 /* Mark used types after we have created DIEs for the functions scopes. */
22636 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
22639 /* Returns a hash value for X (which really is a die_struct). */
22642 block_die_hasher::hash (die_struct
*d
)
22644 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
22647 /* Return nonzero if decl_id and die_parent of die_struct X is the same
22648 as decl_id and die_parent of die_struct Y. */
22651 block_die_hasher::equal (die_struct
*x
, die_struct
*y
)
22653 return x
->decl_id
== y
->decl_id
&& x
->die_parent
== y
->die_parent
;
22656 /* Return TRUE if DECL, which may have been previously generated as
22657 OLD_DIE, is a candidate for a DW_AT_specification. DECLARATION is
22658 true if decl (or its origin) is either an extern declaration or a
22659 class/namespace scoped declaration.
22661 The declare_in_namespace support causes us to get two DIEs for one
22662 variable, both of which are declarations. We want to avoid
22663 considering one to be a specification, so we must test for
22664 DECLARATION and DW_AT_declaration. */
22666 decl_will_get_specification_p (dw_die_ref old_die
, tree decl
, bool declaration
)
22668 return (old_die
&& TREE_STATIC (decl
) && !declaration
22669 && get_AT_flag (old_die
, DW_AT_declaration
) == 1);
22672 /* Return true if DECL is a local static. */
22675 local_function_static (tree decl
)
22677 gcc_assert (VAR_P (decl
));
22678 return TREE_STATIC (decl
)
22679 && DECL_CONTEXT (decl
)
22680 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
;
22683 /* Generate a DIE to represent a declared data object.
22684 Either DECL or ORIGIN must be non-null. */
22687 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
22689 HOST_WIDE_INT off
= 0;
22691 tree decl_or_origin
= decl
? decl
: origin
;
22692 tree ultimate_origin
;
22693 dw_die_ref var_die
;
22694 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
22695 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
22696 || class_or_namespace_scope_p (context_die
));
22697 bool specialization_p
= false;
22698 bool no_linkage_name
= false;
22700 /* While C++ inline static data members have definitions inside of the
22701 class, force the first DIE to be a declaration, then let gen_member_die
22702 reparent it to the class context and call gen_variable_die again
22703 to create the outside of the class DIE for the definition. */
22707 && DECL_CONTEXT (decl
)
22708 && TYPE_P (DECL_CONTEXT (decl
))
22709 && lang_hooks
.decls
.decl_dwarf_attribute (decl
, DW_AT_inline
) != -1)
22711 declaration
= true;
22712 if (dwarf_version
< 5)
22713 no_linkage_name
= true;
22716 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
22717 if (decl
|| ultimate_origin
)
22718 origin
= ultimate_origin
;
22719 com_decl
= fortran_common (decl_or_origin
, &off
);
22721 /* Symbol in common gets emitted as a child of the common block, in the form
22722 of a data member. */
22725 dw_die_ref com_die
;
22726 dw_loc_list_ref loc
= NULL
;
22727 die_node com_die_arg
;
22729 var_die
= lookup_decl_die (decl_or_origin
);
22732 if (! early_dwarf
&& get_AT (var_die
, DW_AT_location
) == NULL
)
22734 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2, NULL
);
22739 /* Optimize the common case. */
22740 if (single_element_loc_list_p (loc
)
22741 && loc
->expr
->dw_loc_opc
== DW_OP_addr
22742 && loc
->expr
->dw_loc_next
== NULL
22743 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
22746 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
22747 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
22748 = plus_constant (GET_MODE (x
), x
, off
);
22751 loc_list_plus_const (loc
, off
);
22753 add_AT_location_description (var_die
, DW_AT_location
, loc
);
22754 remove_AT (var_die
, DW_AT_declaration
);
22760 if (common_block_die_table
== NULL
)
22761 common_block_die_table
= hash_table
<block_die_hasher
>::create_ggc (10);
22763 com_die_arg
.decl_id
= DECL_UID (com_decl
);
22764 com_die_arg
.die_parent
= context_die
;
22765 com_die
= common_block_die_table
->find (&com_die_arg
);
22767 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
22768 if (com_die
== NULL
)
22771 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
22774 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
22775 add_name_and_src_coords_attributes (com_die
, com_decl
);
22778 add_AT_location_description (com_die
, DW_AT_location
, loc
);
22779 /* Avoid sharing the same loc descriptor between
22780 DW_TAG_common_block and DW_TAG_variable. */
22781 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
22783 else if (DECL_EXTERNAL (decl_or_origin
))
22784 add_AT_flag (com_die
, DW_AT_declaration
, 1);
22785 if (want_pubnames ())
22786 add_pubname_string (cnam
, com_die
); /* ??? needed? */
22787 com_die
->decl_id
= DECL_UID (com_decl
);
22788 slot
= common_block_die_table
->find_slot (com_die
, INSERT
);
22791 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
22793 add_AT_location_description (com_die
, DW_AT_location
, loc
);
22794 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
22795 remove_AT (com_die
, DW_AT_declaration
);
22797 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
22798 add_name_and_src_coords_attributes (var_die
, decl_or_origin
);
22799 add_type_attribute (var_die
, TREE_TYPE (decl_or_origin
),
22800 decl_quals (decl_or_origin
), false,
22802 add_alignment_attribute (var_die
, decl
);
22803 add_AT_flag (var_die
, DW_AT_external
, 1);
22808 /* Optimize the common case. */
22809 if (single_element_loc_list_p (loc
)
22810 && loc
->expr
->dw_loc_opc
== DW_OP_addr
22811 && loc
->expr
->dw_loc_next
== NULL
22812 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
22814 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
22815 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
22816 = plus_constant (GET_MODE (x
), x
, off
);
22819 loc_list_plus_const (loc
, off
);
22821 add_AT_location_description (var_die
, DW_AT_location
, loc
);
22823 else if (DECL_EXTERNAL (decl_or_origin
))
22824 add_AT_flag (var_die
, DW_AT_declaration
, 1);
22826 equate_decl_number_to_die (decl
, var_die
);
22834 /* A declaration that has been previously dumped, needs no
22835 further annotations, since it doesn't need location on
22836 the second pass. */
22839 else if (decl_will_get_specification_p (old_die
, decl
, declaration
)
22840 && !get_AT (old_die
, DW_AT_specification
))
22842 /* Fall-thru so we can make a new variable die along with a
22843 DW_AT_specification. */
22845 else if (origin
&& old_die
->die_parent
!= context_die
)
22847 /* If we will be creating an inlined instance, we need a
22848 new DIE that will get annotated with
22849 DW_AT_abstract_origin. Clear things so we can get a
22851 gcc_assert (!DECL_ABSTRACT_P (decl
));
22856 /* If a DIE was dumped early, it still needs location info.
22857 Skip to where we fill the location bits. */
22860 /* ??? In LTRANS we cannot annotate early created variably
22861 modified type DIEs without copying them and adjusting all
22862 references to them. Thus we dumped them again, also add a
22863 reference to them. */
22864 tree type
= TREE_TYPE (decl_or_origin
);
22866 && variably_modified_type_p
22867 (type
, decl_function_context (decl_or_origin
)))
22869 if (decl_by_reference_p (decl_or_origin
))
22870 add_type_attribute (var_die
, TREE_TYPE (type
),
22871 TYPE_UNQUALIFIED
, false, context_die
);
22873 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
),
22874 false, context_die
);
22877 goto gen_variable_die_location
;
22881 /* For static data members, the declaration in the class is supposed
22882 to have DW_TAG_member tag in DWARF{3,4} and we emit it for compatibility
22883 also in DWARF2; the specification should still be DW_TAG_variable
22884 referencing the DW_TAG_member DIE. */
22885 if (declaration
&& class_scope_p (context_die
) && dwarf_version
< 5)
22886 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
22888 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
22890 if (origin
!= NULL
)
22891 add_abstract_origin_attribute (var_die
, origin
);
22893 /* Loop unrolling can create multiple blocks that refer to the same
22894 static variable, so we must test for the DW_AT_declaration flag.
22896 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
22897 copy decls and set the DECL_ABSTRACT_P flag on them instead of
22900 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
22901 else if (decl_will_get_specification_p (old_die
, decl
, declaration
))
22903 /* This is a definition of a C++ class level static. */
22904 add_AT_specification (var_die
, old_die
);
22905 specialization_p
= true;
22906 if (DECL_NAME (decl
))
22908 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
22909 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
22911 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
22912 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
22914 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
22915 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
22917 if (debug_column_info
22919 && (get_AT_unsigned (old_die
, DW_AT_decl_column
)
22920 != (unsigned) s
.column
))
22921 add_AT_unsigned (var_die
, DW_AT_decl_column
, s
.column
);
22923 if (old_die
->die_tag
== DW_TAG_member
)
22924 add_linkage_name (var_die
, decl
);
22928 add_name_and_src_coords_attributes (var_die
, decl
, no_linkage_name
);
22930 if ((origin
== NULL
&& !specialization_p
)
22932 && !DECL_ABSTRACT_P (decl_or_origin
)
22933 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
22934 decl_function_context
22935 (decl_or_origin
))))
22937 tree type
= TREE_TYPE (decl_or_origin
);
22939 if (decl_by_reference_p (decl_or_origin
))
22940 add_type_attribute (var_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
22943 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
), false,
22947 if (origin
== NULL
&& !specialization_p
)
22949 if (TREE_PUBLIC (decl
))
22950 add_AT_flag (var_die
, DW_AT_external
, 1);
22952 if (DECL_ARTIFICIAL (decl
))
22953 add_AT_flag (var_die
, DW_AT_artificial
, 1);
22955 add_alignment_attribute (var_die
, decl
);
22957 add_accessibility_attribute (var_die
, decl
);
22961 add_AT_flag (var_die
, DW_AT_declaration
, 1);
22963 if (decl
&& (DECL_ABSTRACT_P (decl
)
22964 || !old_die
|| is_declaration_die (old_die
)))
22965 equate_decl_number_to_die (decl
, var_die
);
22967 gen_variable_die_location
:
22969 && (! DECL_ABSTRACT_P (decl_or_origin
)
22970 /* Local static vars are shared between all clones/inlines,
22971 so emit DW_AT_location on the abstract DIE if DECL_RTL is
22973 || (VAR_P (decl_or_origin
)
22974 && TREE_STATIC (decl_or_origin
)
22975 && DECL_RTL_SET_P (decl_or_origin
))))
22978 add_pubname (decl_or_origin
, var_die
);
22980 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
22984 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
22986 if ((dwarf_version
>= 4 || !dwarf_strict
)
22987 && lang_hooks
.decls
.decl_dwarf_attribute (decl_or_origin
,
22988 DW_AT_const_expr
) == 1
22989 && !get_AT (var_die
, DW_AT_const_expr
)
22990 && !specialization_p
)
22991 add_AT_flag (var_die
, DW_AT_const_expr
, 1);
22995 int inl
= lang_hooks
.decls
.decl_dwarf_attribute (decl_or_origin
,
22998 && !get_AT (var_die
, DW_AT_inline
)
22999 && !specialization_p
)
23000 add_AT_unsigned (var_die
, DW_AT_inline
, inl
);
23004 /* Generate a DIE to represent a named constant. */
23007 gen_const_die (tree decl
, dw_die_ref context_die
)
23009 dw_die_ref const_die
;
23010 tree type
= TREE_TYPE (decl
);
23012 const_die
= lookup_decl_die (decl
);
23016 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
23017 equate_decl_number_to_die (decl
, const_die
);
23018 add_name_and_src_coords_attributes (const_die
, decl
);
23019 add_type_attribute (const_die
, type
, TYPE_QUAL_CONST
, false, context_die
);
23020 if (TREE_PUBLIC (decl
))
23021 add_AT_flag (const_die
, DW_AT_external
, 1);
23022 if (DECL_ARTIFICIAL (decl
))
23023 add_AT_flag (const_die
, DW_AT_artificial
, 1);
23024 tree_add_const_value_attribute_for_decl (const_die
, decl
);
23027 /* Generate a DIE to represent a label identifier. */
23030 gen_label_die (tree decl
, dw_die_ref context_die
)
23032 tree origin
= decl_ultimate_origin (decl
);
23033 dw_die_ref lbl_die
= lookup_decl_die (decl
);
23035 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
23039 lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
23040 equate_decl_number_to_die (decl
, lbl_die
);
23042 if (origin
!= NULL
)
23043 add_abstract_origin_attribute (lbl_die
, origin
);
23045 add_name_and_src_coords_attributes (lbl_die
, decl
);
23048 if (DECL_ABSTRACT_P (decl
))
23049 equate_decl_number_to_die (decl
, lbl_die
);
23050 else if (! early_dwarf
)
23052 insn
= DECL_RTL_IF_SET (decl
);
23054 /* Deleted labels are programmer specified labels which have been
23055 eliminated because of various optimizations. We still emit them
23056 here so that it is possible to put breakpoints on them. */
23060 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
23062 /* When optimization is enabled (via -O) some parts of the compiler
23063 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
23064 represent source-level labels which were explicitly declared by
23065 the user. This really shouldn't be happening though, so catch
23066 it if it ever does happen. */
23067 gcc_assert (!as_a
<rtx_insn
*> (insn
)->deleted ());
23069 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
23070 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
23074 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
23075 && CODE_LABEL_NUMBER (insn
) != -1)
23077 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
23078 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
23083 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
23084 attributes to the DIE for a block STMT, to describe where the inlined
23085 function was called from. This is similar to add_src_coords_attributes. */
23088 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
23090 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
23092 if (dwarf_version
>= 3 || !dwarf_strict
)
23094 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
23095 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
23096 if (debug_column_info
&& s
.column
)
23097 add_AT_unsigned (die
, DW_AT_call_column
, s
.column
);
23102 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
23103 Add low_pc and high_pc attributes to the DIE for a block STMT. */
23106 add_high_low_attributes (tree stmt
, dw_die_ref die
)
23108 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
23110 if (BLOCK_FRAGMENT_CHAIN (stmt
)
23111 && (dwarf_version
>= 3 || !dwarf_strict
))
23113 tree chain
, superblock
= NULL_TREE
;
23115 dw_attr_node
*attr
= NULL
;
23117 if (inlined_function_outer_scope_p (stmt
))
23119 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
23120 BLOCK_NUMBER (stmt
));
23121 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
23124 /* Optimize duplicate .debug_ranges lists or even tails of
23125 lists. If this BLOCK has same ranges as its supercontext,
23126 lookup DW_AT_ranges attribute in the supercontext (and
23127 recursively so), verify that the ranges_table contains the
23128 right values and use it instead of adding a new .debug_range. */
23129 for (chain
= stmt
, pdie
= die
;
23130 BLOCK_SAME_RANGE (chain
);
23131 chain
= BLOCK_SUPERCONTEXT (chain
))
23133 dw_attr_node
*new_attr
;
23135 pdie
= pdie
->die_parent
;
23138 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
23140 new_attr
= get_AT (pdie
, DW_AT_ranges
);
23141 if (new_attr
== NULL
23142 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
23145 superblock
= BLOCK_SUPERCONTEXT (chain
);
23148 && ((*ranges_table
)[attr
->dw_attr_val
.v
.val_offset
].num
23149 == BLOCK_NUMBER (superblock
))
23150 && BLOCK_FRAGMENT_CHAIN (superblock
))
23152 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
;
23153 unsigned long supercnt
= 0, thiscnt
= 0;
23154 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
23155 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
23158 gcc_checking_assert ((*ranges_table
)[off
+ supercnt
].num
23159 == BLOCK_NUMBER (chain
));
23161 gcc_checking_assert ((*ranges_table
)[off
+ supercnt
+ 1].num
== 0);
23162 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
23163 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
23165 gcc_assert (supercnt
>= thiscnt
);
23166 add_AT_range_list (die
, DW_AT_ranges
, off
+ supercnt
- thiscnt
,
23168 note_rnglist_head (off
+ supercnt
- thiscnt
);
23172 unsigned int offset
= add_ranges (stmt
, true);
23173 add_AT_range_list (die
, DW_AT_ranges
, offset
, false);
23174 note_rnglist_head (offset
);
23176 bool prev_in_cold
= BLOCK_IN_COLD_SECTION_P (stmt
);
23177 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
23180 add_ranges (chain
, prev_in_cold
!= BLOCK_IN_COLD_SECTION_P (chain
));
23181 prev_in_cold
= BLOCK_IN_COLD_SECTION_P (chain
);
23182 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
23189 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
23190 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
23191 BLOCK_NUMBER (stmt
));
23192 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
23193 BLOCK_NUMBER (stmt
));
23194 add_AT_low_high_pc (die
, label
, label_high
, false);
23198 /* Generate a DIE for a lexical block. */
23201 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
)
23203 dw_die_ref old_die
= BLOCK_DIE (stmt
);
23204 dw_die_ref stmt_die
= NULL
;
23207 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
23208 BLOCK_DIE (stmt
) = stmt_die
;
23211 if (BLOCK_ABSTRACT (stmt
))
23215 /* This must have been generated early and it won't even
23216 need location information since it's a DW_AT_inline
23219 for (dw_die_ref c
= context_die
; c
; c
= c
->die_parent
)
23220 if (c
->die_tag
== DW_TAG_inlined_subroutine
23221 || c
->die_tag
== DW_TAG_subprogram
)
23223 gcc_assert (get_AT (c
, DW_AT_inline
));
23229 else if (BLOCK_ABSTRACT_ORIGIN (stmt
))
23231 /* If this is an inlined instance, create a new lexical die for
23232 anything below to attach DW_AT_abstract_origin to. */
23235 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
23236 BLOCK_DIE (stmt
) = stmt_die
;
23240 tree origin
= block_ultimate_origin (stmt
);
23241 if (origin
!= NULL_TREE
&& origin
!= stmt
)
23242 add_abstract_origin_attribute (stmt_die
, origin
);
23246 stmt_die
= old_die
;
23248 /* A non abstract block whose blocks have already been reordered
23249 should have the instruction range for this block. If so, set the
23250 high/low attributes. */
23251 if (!early_dwarf
&& !BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
23253 gcc_assert (stmt_die
);
23254 add_high_low_attributes (stmt
, stmt_die
);
23257 decls_for_scope (stmt
, stmt_die
);
23260 /* Generate a DIE for an inlined subprogram. */
23263 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
)
23267 /* The instance of function that is effectively being inlined shall not
23269 gcc_assert (! BLOCK_ABSTRACT (stmt
));
23271 decl
= block_ultimate_origin (stmt
);
23273 /* Make sure any inlined functions are known to be inlineable. */
23274 gcc_checking_assert (DECL_ABSTRACT_P (decl
)
23275 || cgraph_function_possibly_inlined_p (decl
));
23277 if (! BLOCK_ABSTRACT (stmt
))
23279 dw_die_ref subr_die
23280 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
23282 if (call_arg_locations
)
23283 BLOCK_DIE (stmt
) = subr_die
;
23284 add_abstract_origin_attribute (subr_die
, decl
);
23285 if (TREE_ASM_WRITTEN (stmt
))
23286 add_high_low_attributes (stmt
, subr_die
);
23287 add_call_src_coords_attributes (stmt
, subr_die
);
23289 decls_for_scope (stmt
, subr_die
);
23293 /* Generate a DIE for a field in a record, or structure. CTX is required: see
23294 the comment for VLR_CONTEXT. */
23297 gen_field_die (tree decl
, struct vlr_context
*ctx
, dw_die_ref context_die
)
23299 dw_die_ref decl_die
;
23301 if (TREE_TYPE (decl
) == error_mark_node
)
23304 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
23305 add_name_and_src_coords_attributes (decl_die
, decl
);
23306 add_type_attribute (decl_die
, member_declared_type (decl
), decl_quals (decl
),
23307 TYPE_REVERSE_STORAGE_ORDER (DECL_FIELD_CONTEXT (decl
)),
23310 if (DECL_BIT_FIELD_TYPE (decl
))
23312 add_byte_size_attribute (decl_die
, decl
);
23313 add_bit_size_attribute (decl_die
, decl
);
23314 add_bit_offset_attribute (decl_die
, decl
, ctx
);
23317 add_alignment_attribute (decl_die
, decl
);
23319 /* If we have a variant part offset, then we are supposed to process a member
23320 of a QUAL_UNION_TYPE, which is how we represent variant parts in
23322 gcc_assert (ctx
->variant_part_offset
== NULL_TREE
23323 || TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != QUAL_UNION_TYPE
);
23324 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
23325 add_data_member_location_attribute (decl_die
, decl
, ctx
);
23327 if (DECL_ARTIFICIAL (decl
))
23328 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
23330 add_accessibility_attribute (decl_die
, decl
);
23332 /* Equate decl number to die, so that we can look up this decl later on. */
23333 equate_decl_number_to_die (decl
, decl_die
);
23336 /* Generate a DIE for a pointer to a member type. TYPE can be an
23337 OFFSET_TYPE, for a pointer to data member, or a RECORD_TYPE, for a
23338 pointer to member function. */
23341 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
23343 if (lookup_type_die (type
))
23346 dw_die_ref ptr_die
= new_die (DW_TAG_ptr_to_member_type
,
23347 scope_die_for (type
, context_die
), type
);
23349 equate_type_number_to_die (type
, ptr_die
);
23350 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
23351 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
23352 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
23354 add_alignment_attribute (ptr_die
, type
);
23356 if (TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
23357 && TREE_CODE (TREE_TYPE (type
)) != METHOD_TYPE
)
23359 dw_loc_descr_ref op
= new_loc_descr (DW_OP_plus
, 0, 0);
23360 add_AT_loc (ptr_die
, DW_AT_use_location
, op
);
23364 static char *producer_string
;
23366 /* Return a heap allocated producer string including command line options
23367 if -grecord-gcc-switches. */
23370 gen_producer_string (void)
23373 auto_vec
<const char *> switches
;
23374 const char *language_string
= lang_hooks
.name
;
23375 char *producer
, *tail
;
23377 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
23378 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
23380 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
23381 switch (save_decoded_options
[j
].opt_index
)
23388 case OPT_auxbase_strip
:
23397 case OPT_SPECIAL_unknown
:
23398 case OPT_SPECIAL_ignore
:
23399 case OPT_SPECIAL_program_name
:
23400 case OPT_SPECIAL_input_file
:
23401 case OPT_grecord_gcc_switches
:
23402 case OPT__output_pch_
:
23403 case OPT_fdiagnostics_show_location_
:
23404 case OPT_fdiagnostics_show_option
:
23405 case OPT_fdiagnostics_show_caret
:
23406 case OPT_fdiagnostics_color_
:
23407 case OPT_fverbose_asm
:
23409 case OPT__sysroot_
:
23411 case OPT_nostdinc__
:
23412 case OPT_fpreprocessed
:
23413 case OPT_fltrans_output_list_
:
23414 case OPT_fresolution_
:
23415 case OPT_fdebug_prefix_map_
:
23416 case OPT_fcompare_debug
:
23417 /* Ignore these. */
23420 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
23421 & CL_NO_DWARF_RECORD
)
23423 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
23425 switch (save_decoded_options
[j
].canonical_option
[0][1])
23432 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
23439 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
23440 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
23444 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
23446 sprintf (tail
, "%s %s", language_string
, version_string
);
23449 FOR_EACH_VEC_ELT (switches
, j
, p
)
23453 memcpy (tail
+ 1, p
, len
);
23461 /* Given a C and/or C++ language/version string return the "highest".
23462 C++ is assumed to be "higher" than C in this case. Used for merging
23463 LTO translation unit languages. */
23464 static const char *
23465 highest_c_language (const char *lang1
, const char *lang2
)
23467 if (strcmp ("GNU C++17", lang1
) == 0 || strcmp ("GNU C++17", lang2
) == 0)
23468 return "GNU C++17";
23469 if (strcmp ("GNU C++14", lang1
) == 0 || strcmp ("GNU C++14", lang2
) == 0)
23470 return "GNU C++14";
23471 if (strcmp ("GNU C++11", lang1
) == 0 || strcmp ("GNU C++11", lang2
) == 0)
23472 return "GNU C++11";
23473 if (strcmp ("GNU C++98", lang1
) == 0 || strcmp ("GNU C++98", lang2
) == 0)
23474 return "GNU C++98";
23476 if (strcmp ("GNU C17", lang1
) == 0 || strcmp ("GNU C17", lang2
) == 0)
23478 if (strcmp ("GNU C11", lang1
) == 0 || strcmp ("GNU C11", lang2
) == 0)
23480 if (strcmp ("GNU C99", lang1
) == 0 || strcmp ("GNU C99", lang2
) == 0)
23482 if (strcmp ("GNU C89", lang1
) == 0 || strcmp ("GNU C89", lang2
) == 0)
23485 gcc_unreachable ();
23489 /* Generate the DIE for the compilation unit. */
23492 gen_compile_unit_die (const char *filename
)
23495 const char *language_string
= lang_hooks
.name
;
23498 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
23502 add_name_attribute (die
, filename
);
23503 /* Don't add cwd for <built-in>. */
23504 if (filename
[0] != '<')
23505 add_comp_dir_attribute (die
);
23508 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
23510 /* If our producer is LTO try to figure out a common language to use
23511 from the global list of translation units. */
23512 if (strcmp (language_string
, "GNU GIMPLE") == 0)
23516 const char *common_lang
= NULL
;
23518 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
23520 if (!TRANSLATION_UNIT_LANGUAGE (t
))
23523 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
23524 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
23526 else if (strncmp (common_lang
, "GNU C", 5) == 0
23527 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
23528 /* Mixing C and C++ is ok, use C++ in that case. */
23529 common_lang
= highest_c_language (common_lang
,
23530 TRANSLATION_UNIT_LANGUAGE (t
));
23533 /* Fall back to C. */
23534 common_lang
= NULL
;
23540 language_string
= common_lang
;
23543 language
= DW_LANG_C
;
23544 if (strncmp (language_string
, "GNU C", 5) == 0
23545 && ISDIGIT (language_string
[5]))
23547 language
= DW_LANG_C89
;
23548 if (dwarf_version
>= 3 || !dwarf_strict
)
23550 if (strcmp (language_string
, "GNU C89") != 0)
23551 language
= DW_LANG_C99
;
23553 if (dwarf_version
>= 5 /* || !dwarf_strict */)
23554 if (strcmp (language_string
, "GNU C11") == 0
23555 || strcmp (language_string
, "GNU C17") == 0)
23556 language
= DW_LANG_C11
;
23559 else if (strncmp (language_string
, "GNU C++", 7) == 0)
23561 language
= DW_LANG_C_plus_plus
;
23562 if (dwarf_version
>= 5 /* || !dwarf_strict */)
23564 if (strcmp (language_string
, "GNU C++11") == 0)
23565 language
= DW_LANG_C_plus_plus_11
;
23566 else if (strcmp (language_string
, "GNU C++14") == 0)
23567 language
= DW_LANG_C_plus_plus_14
;
23568 else if (strcmp (language_string
, "GNU C++17") == 0)
23570 language
= DW_LANG_C_plus_plus_14
;
23573 else if (strcmp (language_string
, "GNU F77") == 0)
23574 language
= DW_LANG_Fortran77
;
23575 else if (dwarf_version
>= 3 || !dwarf_strict
)
23577 if (strcmp (language_string
, "GNU Ada") == 0)
23578 language
= DW_LANG_Ada95
;
23579 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
23581 language
= DW_LANG_Fortran95
;
23582 if (dwarf_version
>= 5 /* || !dwarf_strict */)
23584 if (strcmp (language_string
, "GNU Fortran2003") == 0)
23585 language
= DW_LANG_Fortran03
;
23586 else if (strcmp (language_string
, "GNU Fortran2008") == 0)
23587 language
= DW_LANG_Fortran08
;
23590 else if (strcmp (language_string
, "GNU Objective-C") == 0)
23591 language
= DW_LANG_ObjC
;
23592 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
23593 language
= DW_LANG_ObjC_plus_plus
;
23594 else if (dwarf_version
>= 5 || !dwarf_strict
)
23596 if (strcmp (language_string
, "GNU Go") == 0)
23597 language
= DW_LANG_Go
;
23600 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
23601 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
23602 language
= DW_LANG_Fortran90
;
23604 add_AT_unsigned (die
, DW_AT_language
, language
);
23608 case DW_LANG_Fortran77
:
23609 case DW_LANG_Fortran90
:
23610 case DW_LANG_Fortran95
:
23611 case DW_LANG_Fortran03
:
23612 case DW_LANG_Fortran08
:
23613 /* Fortran has case insensitive identifiers and the front-end
23614 lowercases everything. */
23615 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
23618 /* The default DW_ID_case_sensitive doesn't need to be specified. */
23624 /* Generate the DIE for a base class. */
23627 gen_inheritance_die (tree binfo
, tree access
, tree type
,
23628 dw_die_ref context_die
)
23630 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
23631 struct vlr_context ctx
= { type
, NULL
};
23633 add_type_attribute (die
, BINFO_TYPE (binfo
), TYPE_UNQUALIFIED
, false,
23635 add_data_member_location_attribute (die
, binfo
, &ctx
);
23637 if (BINFO_VIRTUAL_P (binfo
))
23638 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
23640 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
23641 children, otherwise the default is DW_ACCESS_public. In DWARF2
23642 the default has always been DW_ACCESS_private. */
23643 if (access
== access_public_node
)
23645 if (dwarf_version
== 2
23646 || context_die
->die_tag
== DW_TAG_class_type
)
23647 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
23649 else if (access
== access_protected_node
)
23650 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
23651 else if (dwarf_version
> 2
23652 && context_die
->die_tag
!= DW_TAG_class_type
)
23653 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
23656 /* Return whether DECL is a FIELD_DECL that represents the variant part of a
23659 is_variant_part (tree decl
)
23661 return (TREE_CODE (decl
) == FIELD_DECL
23662 && TREE_CODE (TREE_TYPE (decl
)) == QUAL_UNION_TYPE
);
23665 /* Check that OPERAND is a reference to a field in STRUCT_TYPE. If it is,
23666 return the FIELD_DECL. Return NULL_TREE otherwise. */
23669 analyze_discr_in_predicate (tree operand
, tree struct_type
)
23671 bool continue_stripping
= true;
23672 while (continue_stripping
)
23673 switch (TREE_CODE (operand
))
23676 operand
= TREE_OPERAND (operand
, 0);
23679 continue_stripping
= false;
23683 /* Match field access to members of struct_type only. */
23684 if (TREE_CODE (operand
) == COMPONENT_REF
23685 && TREE_CODE (TREE_OPERAND (operand
, 0)) == PLACEHOLDER_EXPR
23686 && TREE_TYPE (TREE_OPERAND (operand
, 0)) == struct_type
23687 && TREE_CODE (TREE_OPERAND (operand
, 1)) == FIELD_DECL
)
23688 return TREE_OPERAND (operand
, 1);
23693 /* Check that SRC is a constant integer that can be represented as a native
23694 integer constant (either signed or unsigned). If so, store it into DEST and
23695 return true. Return false otherwise. */
23698 get_discr_value (tree src
, dw_discr_value
*dest
)
23700 tree discr_type
= TREE_TYPE (src
);
23702 if (lang_hooks
.types
.get_debug_type
)
23704 tree debug_type
= lang_hooks
.types
.get_debug_type (discr_type
);
23705 if (debug_type
!= NULL
)
23706 discr_type
= debug_type
;
23709 if (TREE_CODE (src
) != INTEGER_CST
|| !INTEGRAL_TYPE_P (discr_type
))
23712 /* Signedness can vary between the original type and the debug type. This
23713 can happen for character types in Ada for instance: the character type
23714 used for code generation can be signed, to be compatible with the C one,
23715 but from a debugger point of view, it must be unsigned. */
23716 bool is_orig_unsigned
= TYPE_UNSIGNED (TREE_TYPE (src
));
23717 bool is_debug_unsigned
= TYPE_UNSIGNED (discr_type
);
23719 if (is_orig_unsigned
!= is_debug_unsigned
)
23720 src
= fold_convert (discr_type
, src
);
23722 if (!(is_debug_unsigned
? tree_fits_uhwi_p (src
) : tree_fits_shwi_p (src
)))
23725 dest
->pos
= is_debug_unsigned
;
23726 if (is_debug_unsigned
)
23727 dest
->v
.uval
= tree_to_uhwi (src
);
23729 dest
->v
.sval
= tree_to_shwi (src
);
23734 /* Try to extract synthetic properties out of VARIANT_PART_DECL, which is a
23735 FIELD_DECL in STRUCT_TYPE that represents a variant part. If unsuccessful,
23736 store NULL_TREE in DISCR_DECL. Otherwise:
23738 - store the discriminant field in STRUCT_TYPE that controls the variant
23739 part to *DISCR_DECL
23741 - put in *DISCR_LISTS_P an array where for each variant, the item
23742 represents the corresponding matching list of discriminant values.
23744 - put in *DISCR_LISTS_LENGTH the number of variants, which is the size of
23747 Note that when the array is allocated (i.e. when the analysis is
23748 successful), it is up to the caller to free the array. */
23751 analyze_variants_discr (tree variant_part_decl
,
23754 dw_discr_list_ref
**discr_lists_p
,
23755 unsigned *discr_lists_length
)
23757 tree variant_part_type
= TREE_TYPE (variant_part_decl
);
23759 dw_discr_list_ref
*discr_lists
;
23762 /* Compute how many variants there are in this variant part. */
23763 *discr_lists_length
= 0;
23764 for (variant
= TYPE_FIELDS (variant_part_type
);
23765 variant
!= NULL_TREE
;
23766 variant
= DECL_CHAIN (variant
))
23767 ++*discr_lists_length
;
23769 *discr_decl
= NULL_TREE
;
23771 = (dw_discr_list_ref
*) xcalloc (*discr_lists_length
,
23772 sizeof (**discr_lists_p
));
23773 discr_lists
= *discr_lists_p
;
23775 /* And then analyze all variants to extract discriminant information for all
23776 of them. This analysis is conservative: as soon as we detect something we
23777 do not support, abort everything and pretend we found nothing. */
23778 for (variant
= TYPE_FIELDS (variant_part_type
), i
= 0;
23779 variant
!= NULL_TREE
;
23780 variant
= DECL_CHAIN (variant
), ++i
)
23782 tree match_expr
= DECL_QUALIFIER (variant
);
23784 /* Now, try to analyze the predicate and deduce a discriminant for
23786 if (match_expr
== boolean_true_node
)
23787 /* Typically happens for the default variant: it matches all cases that
23788 previous variants rejected. Don't output any matching value for
23792 /* The following loop tries to iterate over each discriminant
23793 possibility: single values or ranges. */
23794 while (match_expr
!= NULL_TREE
)
23796 tree next_round_match_expr
;
23797 tree candidate_discr
= NULL_TREE
;
23798 dw_discr_list_ref new_node
= NULL
;
23800 /* Possibilities are matched one after the other by nested
23801 TRUTH_ORIF_EXPR expressions. Process the current possibility and
23802 continue with the rest at next iteration. */
23803 if (TREE_CODE (match_expr
) == TRUTH_ORIF_EXPR
)
23805 next_round_match_expr
= TREE_OPERAND (match_expr
, 0);
23806 match_expr
= TREE_OPERAND (match_expr
, 1);
23809 next_round_match_expr
= NULL_TREE
;
23811 if (match_expr
== boolean_false_node
)
23812 /* This sub-expression matches nothing: just wait for the next
23816 else if (TREE_CODE (match_expr
) == EQ_EXPR
)
23818 /* We are matching: <discr_field> == <integer_cst>
23819 This sub-expression matches a single value. */
23820 tree integer_cst
= TREE_OPERAND (match_expr
, 1);
23823 = analyze_discr_in_predicate (TREE_OPERAND (match_expr
, 0),
23826 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
23827 if (!get_discr_value (integer_cst
,
23828 &new_node
->dw_discr_lower_bound
))
23830 new_node
->dw_discr_range
= false;
23833 else if (TREE_CODE (match_expr
) == TRUTH_ANDIF_EXPR
)
23835 /* We are matching:
23836 <discr_field> > <integer_cst>
23837 && <discr_field> < <integer_cst>.
23838 This sub-expression matches the range of values between the
23839 two matched integer constants. Note that comparisons can be
23840 inclusive or exclusive. */
23841 tree candidate_discr_1
, candidate_discr_2
;
23842 tree lower_cst
, upper_cst
;
23843 bool lower_cst_included
, upper_cst_included
;
23844 tree lower_op
= TREE_OPERAND (match_expr
, 0);
23845 tree upper_op
= TREE_OPERAND (match_expr
, 1);
23847 /* When the comparison is exclusive, the integer constant is not
23848 the discriminant range bound we are looking for: we will have
23849 to increment or decrement it. */
23850 if (TREE_CODE (lower_op
) == GE_EXPR
)
23851 lower_cst_included
= true;
23852 else if (TREE_CODE (lower_op
) == GT_EXPR
)
23853 lower_cst_included
= false;
23857 if (TREE_CODE (upper_op
) == LE_EXPR
)
23858 upper_cst_included
= true;
23859 else if (TREE_CODE (upper_op
) == LT_EXPR
)
23860 upper_cst_included
= false;
23864 /* Extract the discriminant from the first operand and check it
23865 is consistant with the same analysis in the second
23868 = analyze_discr_in_predicate (TREE_OPERAND (lower_op
, 0),
23871 = analyze_discr_in_predicate (TREE_OPERAND (upper_op
, 0),
23873 if (candidate_discr_1
== candidate_discr_2
)
23874 candidate_discr
= candidate_discr_1
;
23878 /* Extract bounds from both. */
23879 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
23880 lower_cst
= TREE_OPERAND (lower_op
, 1);
23881 upper_cst
= TREE_OPERAND (upper_op
, 1);
23883 if (!lower_cst_included
)
23885 = fold_build2 (PLUS_EXPR
, TREE_TYPE (lower_cst
), lower_cst
,
23886 build_int_cst (TREE_TYPE (lower_cst
), 1));
23887 if (!upper_cst_included
)
23889 = fold_build2 (MINUS_EXPR
, TREE_TYPE (upper_cst
), upper_cst
,
23890 build_int_cst (TREE_TYPE (upper_cst
), 1));
23892 if (!get_discr_value (lower_cst
,
23893 &new_node
->dw_discr_lower_bound
)
23894 || !get_discr_value (upper_cst
,
23895 &new_node
->dw_discr_upper_bound
))
23898 new_node
->dw_discr_range
= true;
23902 /* Unsupported sub-expression: we cannot determine the set of
23903 matching discriminant values. Abort everything. */
23906 /* If the discriminant info is not consistant with what we saw so
23907 far, consider the analysis failed and abort everything. */
23908 if (candidate_discr
== NULL_TREE
23909 || (*discr_decl
!= NULL_TREE
&& candidate_discr
!= *discr_decl
))
23912 *discr_decl
= candidate_discr
;
23914 if (new_node
!= NULL
)
23916 new_node
->dw_discr_next
= discr_lists
[i
];
23917 discr_lists
[i
] = new_node
;
23919 match_expr
= next_round_match_expr
;
23923 /* If we reach this point, we could match everything we were interested
23928 /* Clean all data structure and return no result. */
23929 free (*discr_lists_p
);
23930 *discr_lists_p
= NULL
;
23931 *discr_decl
= NULL_TREE
;
23934 /* Generate a DIE to represent VARIANT_PART_DECL, a variant part that is part
23935 of STRUCT_TYPE, a record type. This new DIE is emitted as the next child
23938 Variant parts are supposed to be implemented as a FIELD_DECL whose type is a
23939 QUAL_UNION_TYPE: this is the VARIANT_PART_DECL parameter. The members for
23940 this type, which are record types, represent the available variants and each
23941 has a DECL_QUALIFIER attribute. The discriminant and the discriminant
23942 values are inferred from these attributes.
23944 In trees, the offsets for the fields inside these sub-records are relative
23945 to the variant part itself, whereas the corresponding DIEs should have
23946 offset attributes that are relative to the embedding record base address.
23947 This is why the caller must provide a VARIANT_PART_OFFSET expression: it
23948 must be an expression that computes the offset of the variant part to
23949 describe in DWARF. */
23952 gen_variant_part (tree variant_part_decl
, struct vlr_context
*vlr_ctx
,
23953 dw_die_ref context_die
)
23955 const tree variant_part_type
= TREE_TYPE (variant_part_decl
);
23956 tree variant_part_offset
= vlr_ctx
->variant_part_offset
;
23957 struct loc_descr_context ctx
= {
23958 vlr_ctx
->struct_type
, /* context_type */
23959 NULL_TREE
, /* base_decl */
23961 false, /* placeholder_arg */
23962 false /* placeholder_seen */
23965 /* The FIELD_DECL node in STRUCT_TYPE that acts as the discriminant, or
23966 NULL_TREE if there is no such field. */
23967 tree discr_decl
= NULL_TREE
;
23968 dw_discr_list_ref
*discr_lists
;
23969 unsigned discr_lists_length
= 0;
23972 dw_die_ref dwarf_proc_die
= NULL
;
23973 dw_die_ref variant_part_die
23974 = new_die (DW_TAG_variant_part
, context_die
, variant_part_type
);
23976 equate_decl_number_to_die (variant_part_decl
, variant_part_die
);
23978 analyze_variants_discr (variant_part_decl
, vlr_ctx
->struct_type
,
23979 &discr_decl
, &discr_lists
, &discr_lists_length
);
23981 if (discr_decl
!= NULL_TREE
)
23983 dw_die_ref discr_die
= lookup_decl_die (discr_decl
);
23986 add_AT_die_ref (variant_part_die
, DW_AT_discr
, discr_die
);
23988 /* We have no DIE for the discriminant, so just discard all
23989 discrimimant information in the output. */
23990 discr_decl
= NULL_TREE
;
23993 /* If the offset for this variant part is more complex than a constant,
23994 create a DWARF procedure for it so that we will not have to generate DWARF
23995 expressions for it for each member. */
23996 if (TREE_CODE (variant_part_offset
) != INTEGER_CST
23997 && (dwarf_version
>= 3 || !dwarf_strict
))
23999 const tree dwarf_proc_fndecl
24000 = build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, NULL_TREE
,
24001 build_function_type (TREE_TYPE (variant_part_offset
),
24003 const tree dwarf_proc_call
= build_call_expr (dwarf_proc_fndecl
, 0);
24004 const dw_loc_descr_ref dwarf_proc_body
24005 = loc_descriptor_from_tree (variant_part_offset
, 0, &ctx
);
24007 dwarf_proc_die
= new_dwarf_proc_die (dwarf_proc_body
,
24008 dwarf_proc_fndecl
, context_die
);
24009 if (dwarf_proc_die
!= NULL
)
24010 variant_part_offset
= dwarf_proc_call
;
24013 /* Output DIEs for all variants. */
24015 for (tree variant
= TYPE_FIELDS (variant_part_type
);
24016 variant
!= NULL_TREE
;
24017 variant
= DECL_CHAIN (variant
), ++i
)
24019 tree variant_type
= TREE_TYPE (variant
);
24020 dw_die_ref variant_die
;
24022 /* All variants (i.e. members of a variant part) are supposed to be
24023 encoded as structures. Sub-variant parts are QUAL_UNION_TYPE fields
24024 under these records. */
24025 gcc_assert (TREE_CODE (variant_type
) == RECORD_TYPE
);
24027 variant_die
= new_die (DW_TAG_variant
, variant_part_die
, variant_type
);
24028 equate_decl_number_to_die (variant
, variant_die
);
24030 /* Output discriminant values this variant matches, if any. */
24031 if (discr_decl
== NULL
|| discr_lists
[i
] == NULL
)
24032 /* In the case we have discriminant information at all, this is
24033 probably the default variant: as the standard says, don't
24034 output any discriminant value/list attribute. */
24036 else if (discr_lists
[i
]->dw_discr_next
== NULL
24037 && !discr_lists
[i
]->dw_discr_range
)
24038 /* If there is only one accepted value, don't bother outputting a
24040 add_discr_value (variant_die
, &discr_lists
[i
]->dw_discr_lower_bound
);
24042 add_discr_list (variant_die
, discr_lists
[i
]);
24044 for (tree member
= TYPE_FIELDS (variant_type
);
24045 member
!= NULL_TREE
;
24046 member
= DECL_CHAIN (member
))
24048 struct vlr_context vlr_sub_ctx
= {
24049 vlr_ctx
->struct_type
, /* struct_type */
24050 NULL
/* variant_part_offset */
24052 if (is_variant_part (member
))
24054 /* All offsets for fields inside variant parts are relative to
24055 the top-level embedding RECORD_TYPE's base address. On the
24056 other hand, offsets in GCC's types are relative to the
24057 nested-most variant part. So we have to sum offsets each time
24060 vlr_sub_ctx
.variant_part_offset
24061 = fold_build2 (PLUS_EXPR
, TREE_TYPE (variant_part_offset
),
24062 variant_part_offset
, byte_position (member
));
24063 gen_variant_part (member
, &vlr_sub_ctx
, variant_die
);
24067 vlr_sub_ctx
.variant_part_offset
= variant_part_offset
;
24068 gen_decl_die (member
, NULL
, &vlr_sub_ctx
, variant_die
);
24073 free (discr_lists
);
24076 /* Generate a DIE for a class member. */
24079 gen_member_die (tree type
, dw_die_ref context_die
)
24082 tree binfo
= TYPE_BINFO (type
);
24084 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
24086 /* If this is not an incomplete type, output descriptions of each of its
24087 members. Note that as we output the DIEs necessary to represent the
24088 members of this record or union type, we will also be trying to output
24089 DIEs to represent the *types* of those members. However the `type'
24090 function (above) will specifically avoid generating type DIEs for member
24091 types *within* the list of member DIEs for this (containing) type except
24092 for those types (of members) which are explicitly marked as also being
24093 members of this (containing) type themselves. The g++ front- end can
24094 force any given type to be treated as a member of some other (containing)
24095 type by setting the TYPE_CONTEXT of the given (member) type to point to
24096 the TREE node representing the appropriate (containing) type. */
24098 /* First output info about the base classes. */
24101 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
24105 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
24106 gen_inheritance_die (base
,
24107 (accesses
? (*accesses
)[i
] : access_public_node
),
24112 /* Now output info about the data members and type members. */
24113 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
24115 struct vlr_context vlr_ctx
= { type
, NULL_TREE
};
24116 bool static_inline_p
24117 = (TREE_STATIC (member
)
24118 && (lang_hooks
.decls
.decl_dwarf_attribute (member
, DW_AT_inline
)
24121 /* Ignore clones. */
24122 if (DECL_ABSTRACT_ORIGIN (member
))
24125 /* If we thought we were generating minimal debug info for TYPE
24126 and then changed our minds, some of the member declarations
24127 may have already been defined. Don't define them again, but
24128 do put them in the right order. */
24130 if (dw_die_ref child
= lookup_decl_die (member
))
24132 /* Handle inline static data members, which only have in-class
24134 dw_die_ref ref
= NULL
;
24135 if (child
->die_tag
== DW_TAG_variable
24136 && child
->die_parent
== comp_unit_die ())
24138 ref
= get_AT_ref (child
, DW_AT_specification
);
24139 /* For C++17 inline static data members followed by redundant
24140 out of class redeclaration, we might get here with
24141 child being the DIE created for the out of class
24142 redeclaration and with its DW_AT_specification being
24143 the DIE created for in-class definition. We want to
24144 reparent the latter, and don't want to create another
24145 DIE with DW_AT_specification in that case, because
24146 we already have one. */
24149 && ref
->die_tag
== DW_TAG_variable
24150 && ref
->die_parent
== comp_unit_die ()
24151 && get_AT (ref
, DW_AT_specification
) == NULL
)
24155 static_inline_p
= false;
24159 if (child
->die_tag
== DW_TAG_variable
24160 && child
->die_parent
== comp_unit_die ()
24163 reparent_child (child
, context_die
);
24164 if (dwarf_version
< 5)
24165 child
->die_tag
= DW_TAG_member
;
24168 splice_child_die (context_die
, child
);
24171 /* Do not generate standard DWARF for variant parts if we are generating
24172 the corresponding GNAT encodings: DIEs generated for both would
24173 conflict in our mappings. */
24174 else if (is_variant_part (member
)
24175 && gnat_encodings
== DWARF_GNAT_ENCODINGS_MINIMAL
)
24177 vlr_ctx
.variant_part_offset
= byte_position (member
);
24178 gen_variant_part (member
, &vlr_ctx
, context_die
);
24182 vlr_ctx
.variant_part_offset
= NULL_TREE
;
24183 gen_decl_die (member
, NULL
, &vlr_ctx
, context_die
);
24186 /* For C++ inline static data members emit immediately a DW_TAG_variable
24187 DIE that will refer to that DW_TAG_member/DW_TAG_variable through
24188 DW_AT_specification. */
24189 if (static_inline_p
)
24191 int old_extern
= DECL_EXTERNAL (member
);
24192 DECL_EXTERNAL (member
) = 0;
24193 gen_decl_die (member
, NULL
, NULL
, comp_unit_die ());
24194 DECL_EXTERNAL (member
) = old_extern
;
24199 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
24200 is set, we pretend that the type was never defined, so we only get the
24201 member DIEs needed by later specification DIEs. */
24204 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
24205 enum debug_info_usage usage
)
24207 if (TREE_ASM_WRITTEN (type
))
24209 /* Fill in the bound of variable-length fields in late dwarf if
24210 still incomplete. */
24211 if (!early_dwarf
&& variably_modified_type_p (type
, NULL
))
24212 for (tree member
= TYPE_FIELDS (type
);
24214 member
= DECL_CHAIN (member
))
24215 fill_variable_array_bounds (TREE_TYPE (member
));
24219 dw_die_ref type_die
= lookup_type_die (type
);
24220 dw_die_ref scope_die
= 0;
24222 int complete
= (TYPE_SIZE (type
)
24223 && (! TYPE_STUB_DECL (type
)
24224 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
24225 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
24226 complete
= complete
&& should_emit_struct_debug (type
, usage
);
24228 if (type_die
&& ! complete
)
24231 if (TYPE_CONTEXT (type
) != NULL_TREE
24232 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
24233 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
24236 scope_die
= scope_die_for (type
, context_die
);
24238 /* Generate child dies for template paramaters. */
24239 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
24240 schedule_generic_params_dies_gen (type
);
24242 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
24243 /* First occurrence of type or toplevel definition of nested class. */
24245 dw_die_ref old_die
= type_die
;
24247 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
24248 ? record_type_tag (type
) : DW_TAG_union_type
,
24250 equate_type_number_to_die (type
, type_die
);
24252 add_AT_specification (type_die
, old_die
);
24254 add_name_attribute (type_die
, type_tag (type
));
24257 remove_AT (type_die
, DW_AT_declaration
);
24259 /* If this type has been completed, then give it a byte_size attribute and
24260 then give a list of members. */
24261 if (complete
&& !ns_decl
)
24263 /* Prevent infinite recursion in cases where the type of some member of
24264 this type is expressed in terms of this type itself. */
24265 TREE_ASM_WRITTEN (type
) = 1;
24266 add_byte_size_attribute (type_die
, type
);
24267 add_alignment_attribute (type_die
, type
);
24268 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
24270 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
24271 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
24274 /* If the first reference to this type was as the return type of an
24275 inline function, then it may not have a parent. Fix this now. */
24276 if (type_die
->die_parent
== NULL
)
24277 add_child_die (scope_die
, type_die
);
24279 push_decl_scope (type
);
24280 gen_member_die (type
, type_die
);
24283 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
24284 if (TYPE_ARTIFICIAL (type
))
24285 add_AT_flag (type_die
, DW_AT_artificial
, 1);
24287 /* GNU extension: Record what type our vtable lives in. */
24288 if (TYPE_VFIELD (type
))
24290 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
24292 gen_type_die (vtype
, context_die
);
24293 add_AT_die_ref (type_die
, DW_AT_containing_type
,
24294 lookup_type_die (vtype
));
24299 add_AT_flag (type_die
, DW_AT_declaration
, 1);
24301 /* We don't need to do this for function-local types. */
24302 if (TYPE_STUB_DECL (type
)
24303 && ! decl_function_context (TYPE_STUB_DECL (type
)))
24304 vec_safe_push (incomplete_types
, type
);
24307 if (get_AT (type_die
, DW_AT_name
))
24308 add_pubtype (type
, type_die
);
24311 /* Generate a DIE for a subroutine _type_. */
24314 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
24316 tree return_type
= TREE_TYPE (type
);
24317 dw_die_ref subr_die
24318 = new_die (DW_TAG_subroutine_type
,
24319 scope_die_for (type
, context_die
), type
);
24321 equate_type_number_to_die (type
, subr_die
);
24322 add_prototyped_attribute (subr_die
, type
);
24323 add_type_attribute (subr_die
, return_type
, TYPE_UNQUALIFIED
, false,
24325 add_alignment_attribute (subr_die
, type
);
24326 gen_formal_types_die (type
, subr_die
);
24328 if (get_AT (subr_die
, DW_AT_name
))
24329 add_pubtype (type
, subr_die
);
24330 if ((dwarf_version
>= 5 || !dwarf_strict
)
24331 && lang_hooks
.types
.type_dwarf_attribute (type
, DW_AT_reference
) != -1)
24332 add_AT_flag (subr_die
, DW_AT_reference
, 1);
24333 if ((dwarf_version
>= 5 || !dwarf_strict
)
24334 && lang_hooks
.types
.type_dwarf_attribute (type
,
24335 DW_AT_rvalue_reference
) != -1)
24336 add_AT_flag (subr_die
, DW_AT_rvalue_reference
, 1);
24339 /* Generate a DIE for a type definition. */
24342 gen_typedef_die (tree decl
, dw_die_ref context_die
)
24344 dw_die_ref type_die
;
24347 if (TREE_ASM_WRITTEN (decl
))
24349 if (DECL_ORIGINAL_TYPE (decl
))
24350 fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl
));
24354 /* As we avoid creating DIEs for local typedefs (see decl_ultimate_origin
24355 checks in process_scope_var and modified_type_die), this should be called
24356 only for original types. */
24357 gcc_assert (decl_ultimate_origin (decl
) == NULL
24358 || decl_ultimate_origin (decl
) == decl
);
24360 TREE_ASM_WRITTEN (decl
) = 1;
24361 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
24363 add_name_and_src_coords_attributes (type_die
, decl
);
24364 if (DECL_ORIGINAL_TYPE (decl
))
24366 type
= DECL_ORIGINAL_TYPE (decl
);
24367 if (type
== error_mark_node
)
24370 gcc_assert (type
!= TREE_TYPE (decl
));
24371 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
24375 type
= TREE_TYPE (decl
);
24376 if (type
== error_mark_node
)
24379 if (is_naming_typedef_decl (TYPE_NAME (type
)))
24381 /* Here, we are in the case of decl being a typedef naming
24382 an anonymous type, e.g:
24383 typedef struct {...} foo;
24384 In that case TREE_TYPE (decl) is not a typedef variant
24385 type and TYPE_NAME of the anonymous type is set to the
24386 TYPE_DECL of the typedef. This construct is emitted by
24389 TYPE is the anonymous struct named by the typedef
24390 DECL. As we need the DW_AT_type attribute of the
24391 DW_TAG_typedef to point to the DIE of TYPE, let's
24392 generate that DIE right away. add_type_attribute
24393 called below will then pick (via lookup_type_die) that
24394 anonymous struct DIE. */
24395 if (!TREE_ASM_WRITTEN (type
))
24396 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
24398 /* This is a GNU Extension. We are adding a
24399 DW_AT_linkage_name attribute to the DIE of the
24400 anonymous struct TYPE. The value of that attribute
24401 is the name of the typedef decl naming the anonymous
24402 struct. This greatly eases the work of consumers of
24403 this debug info. */
24404 add_linkage_name_raw (lookup_type_die (type
), decl
);
24408 add_type_attribute (type_die
, type
, decl_quals (decl
), false,
24411 if (is_naming_typedef_decl (decl
))
24412 /* We want that all subsequent calls to lookup_type_die with
24413 TYPE in argument yield the DW_TAG_typedef we have just
24415 equate_type_number_to_die (type
, type_die
);
24417 add_alignment_attribute (type_die
, TREE_TYPE (decl
));
24419 add_accessibility_attribute (type_die
, decl
);
24421 if (DECL_ABSTRACT_P (decl
))
24422 equate_decl_number_to_die (decl
, type_die
);
24424 if (get_AT (type_die
, DW_AT_name
))
24425 add_pubtype (decl
, type_die
);
24428 /* Generate a DIE for a struct, class, enum or union type. */
24431 gen_tagged_type_die (tree type
,
24432 dw_die_ref context_die
,
24433 enum debug_info_usage usage
)
24437 if (type
== NULL_TREE
24438 || !is_tagged_type (type
))
24441 if (TREE_ASM_WRITTEN (type
))
24443 /* If this is a nested type whose containing class hasn't been written
24444 out yet, writing it out will cover this one, too. This does not apply
24445 to instantiations of member class templates; they need to be added to
24446 the containing class as they are generated. FIXME: This hurts the
24447 idea of combining type decls from multiple TUs, since we can't predict
24448 what set of template instantiations we'll get. */
24449 else if (TYPE_CONTEXT (type
)
24450 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
24451 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
24453 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
24455 if (TREE_ASM_WRITTEN (type
))
24458 /* If that failed, attach ourselves to the stub. */
24459 push_decl_scope (TYPE_CONTEXT (type
));
24460 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
24463 else if (TYPE_CONTEXT (type
) != NULL_TREE
24464 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
24466 /* If this type is local to a function that hasn't been written
24467 out yet, use a NULL context for now; it will be fixed up in
24468 decls_for_scope. */
24469 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
24470 /* A declaration DIE doesn't count; nested types need to go in the
24472 if (context_die
&& is_declaration_die (context_die
))
24473 context_die
= NULL
;
24478 context_die
= declare_in_namespace (type
, context_die
);
24482 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
24484 /* This might have been written out by the call to
24485 declare_in_namespace. */
24486 if (!TREE_ASM_WRITTEN (type
))
24487 gen_enumeration_type_die (type
, context_die
);
24490 gen_struct_or_union_type_die (type
, context_die
, usage
);
24495 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
24496 it up if it is ever completed. gen_*_type_die will set it for us
24497 when appropriate. */
24500 /* Generate a type description DIE. */
24503 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
24504 enum debug_info_usage usage
)
24506 struct array_descr_info info
;
24508 if (type
== NULL_TREE
|| type
== error_mark_node
)
24511 if (flag_checking
&& type
)
24512 verify_type (type
);
24514 if (TYPE_NAME (type
) != NULL_TREE
24515 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
24516 && is_redundant_typedef (TYPE_NAME (type
))
24517 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
24518 /* The DECL of this type is a typedef we don't want to emit debug
24519 info for but we want debug info for its underlying typedef.
24520 This can happen for e.g, the injected-class-name of a C++
24522 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
24524 /* If TYPE is a typedef type variant, let's generate debug info
24525 for the parent typedef which TYPE is a type of. */
24526 if (typedef_variant_p (type
))
24528 if (TREE_ASM_WRITTEN (type
))
24531 tree name
= TYPE_NAME (type
);
24532 tree origin
= decl_ultimate_origin (name
);
24533 if (origin
!= NULL
&& origin
!= name
)
24535 gen_decl_die (origin
, NULL
, NULL
, context_die
);
24539 /* Prevent broken recursion; we can't hand off to the same type. */
24540 gcc_assert (DECL_ORIGINAL_TYPE (name
) != type
);
24542 /* Give typedefs the right scope. */
24543 context_die
= scope_die_for (type
, context_die
);
24545 TREE_ASM_WRITTEN (type
) = 1;
24547 gen_decl_die (name
, NULL
, NULL
, context_die
);
24551 /* If type is an anonymous tagged type named by a typedef, let's
24552 generate debug info for the typedef. */
24553 if (is_naming_typedef_decl (TYPE_NAME (type
)))
24555 /* Use the DIE of the containing namespace as the parent DIE of
24556 the type description DIE we want to generate. */
24557 if (DECL_CONTEXT (TYPE_NAME (type
))
24558 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
24559 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
24561 gen_decl_die (TYPE_NAME (type
), NULL
, NULL
, context_die
);
24565 if (lang_hooks
.types
.get_debug_type
)
24567 tree debug_type
= lang_hooks
.types
.get_debug_type (type
);
24569 if (debug_type
!= NULL_TREE
&& debug_type
!= type
)
24571 gen_type_die_with_usage (debug_type
, context_die
, usage
);
24576 /* We are going to output a DIE to represent the unqualified version
24577 of this type (i.e. without any const or volatile qualifiers) so
24578 get the main variant (i.e. the unqualified version) of this type
24579 now. (Vectors and arrays are special because the debugging info is in the
24580 cloned type itself. Similarly function/method types can contain extra
24581 ref-qualification). */
24582 if (TREE_CODE (type
) == FUNCTION_TYPE
24583 || TREE_CODE (type
) == METHOD_TYPE
)
24585 /* For function/method types, can't use type_main_variant here,
24586 because that can have different ref-qualifiers for C++,
24587 but try to canonicalize. */
24588 tree main
= TYPE_MAIN_VARIANT (type
);
24589 for (tree t
= main
; t
; t
= TYPE_NEXT_VARIANT (t
))
24590 if (TYPE_QUALS_NO_ADDR_SPACE (t
) == 0
24591 && check_base_type (t
, main
)
24592 && check_lang_type (t
, type
))
24598 else if (TREE_CODE (type
) != VECTOR_TYPE
24599 && TREE_CODE (type
) != ARRAY_TYPE
)
24600 type
= type_main_variant (type
);
24602 /* If this is an array type with hidden descriptor, handle it first. */
24603 if (!TREE_ASM_WRITTEN (type
)
24604 && lang_hooks
.types
.get_array_descr_info
)
24606 memset (&info
, 0, sizeof (info
));
24607 if (lang_hooks
.types
.get_array_descr_info (type
, &info
))
24609 /* Fortran sometimes emits array types with no dimension. */
24610 gcc_assert (info
.ndimensions
>= 0
24611 && (info
.ndimensions
24612 <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN
));
24613 gen_descr_array_type_die (type
, &info
, context_die
);
24614 TREE_ASM_WRITTEN (type
) = 1;
24619 if (TREE_ASM_WRITTEN (type
))
24621 /* Variable-length types may be incomplete even if
24622 TREE_ASM_WRITTEN. For such types, fall through to
24623 gen_array_type_die() and possibly fill in
24624 DW_AT_{upper,lower}_bound attributes. */
24625 if ((TREE_CODE (type
) != ARRAY_TYPE
24626 && TREE_CODE (type
) != RECORD_TYPE
24627 && TREE_CODE (type
) != UNION_TYPE
24628 && TREE_CODE (type
) != QUAL_UNION_TYPE
)
24629 || !variably_modified_type_p (type
, NULL
))
24633 switch (TREE_CODE (type
))
24639 case REFERENCE_TYPE
:
24640 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
24641 ensures that the gen_type_die recursion will terminate even if the
24642 type is recursive. Recursive types are possible in Ada. */
24643 /* ??? We could perhaps do this for all types before the switch
24645 TREE_ASM_WRITTEN (type
) = 1;
24647 /* For these types, all that is required is that we output a DIE (or a
24648 set of DIEs) to represent the "basis" type. */
24649 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24650 DINFO_USAGE_IND_USE
);
24654 /* This code is used for C++ pointer-to-data-member types.
24655 Output a description of the relevant class type. */
24656 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
24657 DINFO_USAGE_IND_USE
);
24659 /* Output a description of the type of the object pointed to. */
24660 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24661 DINFO_USAGE_IND_USE
);
24663 /* Now output a DIE to represent this pointer-to-data-member type
24665 gen_ptr_to_mbr_type_die (type
, context_die
);
24668 case FUNCTION_TYPE
:
24669 /* Force out return type (in case it wasn't forced out already). */
24670 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24671 DINFO_USAGE_DIR_USE
);
24672 gen_subroutine_type_die (type
, context_die
);
24676 /* Force out return type (in case it wasn't forced out already). */
24677 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24678 DINFO_USAGE_DIR_USE
);
24679 gen_subroutine_type_die (type
, context_die
);
24684 gen_array_type_die (type
, context_die
);
24687 case ENUMERAL_TYPE
:
24690 case QUAL_UNION_TYPE
:
24691 gen_tagged_type_die (type
, context_die
, usage
);
24697 case FIXED_POINT_TYPE
:
24700 case POINTER_BOUNDS_TYPE
:
24701 /* No DIEs needed for fundamental types. */
24706 /* Just use DW_TAG_unspecified_type. */
24708 dw_die_ref type_die
= lookup_type_die (type
);
24709 if (type_die
== NULL
)
24711 tree name
= TYPE_IDENTIFIER (type
);
24712 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (),
24714 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
24715 equate_type_number_to_die (type
, type_die
);
24721 if (is_cxx_auto (type
))
24723 tree name
= TYPE_IDENTIFIER (type
);
24724 dw_die_ref
*die
= (name
== get_identifier ("auto")
24725 ? &auto_die
: &decltype_auto_die
);
24728 *die
= new_die (DW_TAG_unspecified_type
,
24729 comp_unit_die (), NULL_TREE
);
24730 add_name_attribute (*die
, IDENTIFIER_POINTER (name
));
24732 equate_type_number_to_die (type
, *die
);
24735 gcc_unreachable ();
24738 TREE_ASM_WRITTEN (type
) = 1;
24742 gen_type_die (tree type
, dw_die_ref context_die
)
24744 if (type
!= error_mark_node
)
24746 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
24749 dw_die_ref die
= lookup_type_die (type
);
24756 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
24757 things which are local to the given block. */
24760 gen_block_die (tree stmt
, dw_die_ref context_die
)
24762 int must_output_die
= 0;
24765 /* Ignore blocks that are NULL. */
24766 if (stmt
== NULL_TREE
)
24769 inlined_func
= inlined_function_outer_scope_p (stmt
);
24771 /* If the block is one fragment of a non-contiguous block, do not
24772 process the variables, since they will have been done by the
24773 origin block. Do process subblocks. */
24774 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
24778 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
24779 gen_block_die (sub
, context_die
);
24784 /* Determine if we need to output any Dwarf DIEs at all to represent this
24787 /* The outer scopes for inlinings *must* always be represented. We
24788 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
24789 must_output_die
= 1;
24792 /* Determine if this block directly contains any "significant"
24793 local declarations which we will need to output DIEs for. */
24794 if (debug_info_level
> DINFO_LEVEL_TERSE
)
24795 /* We are not in terse mode so *any* local declaration counts
24796 as being a "significant" one. */
24797 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
24798 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
24799 && (TREE_USED (stmt
)
24800 || TREE_ASM_WRITTEN (stmt
)
24801 || BLOCK_ABSTRACT (stmt
)));
24802 else if ((TREE_USED (stmt
)
24803 || TREE_ASM_WRITTEN (stmt
)
24804 || BLOCK_ABSTRACT (stmt
))
24805 && !dwarf2out_ignore_block (stmt
))
24806 must_output_die
= 1;
24809 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
24810 DIE for any block which contains no significant local declarations at
24811 all. Rather, in such cases we just call `decls_for_scope' so that any
24812 needed Dwarf info for any sub-blocks will get properly generated. Note
24813 that in terse mode, our definition of what constitutes a "significant"
24814 local declaration gets restricted to include only inlined function
24815 instances and local (nested) function definitions. */
24816 if (must_output_die
)
24820 /* If STMT block is abstract, that means we have been called
24821 indirectly from dwarf2out_abstract_function.
24822 That function rightfully marks the descendent blocks (of
24823 the abstract function it is dealing with) as being abstract,
24824 precisely to prevent us from emitting any
24825 DW_TAG_inlined_subroutine DIE as a descendent
24826 of an abstract function instance. So in that case, we should
24827 not call gen_inlined_subroutine_die.
24829 Later though, when cgraph asks dwarf2out to emit info
24830 for the concrete instance of the function decl into which
24831 the concrete instance of STMT got inlined, the later will lead
24832 to the generation of a DW_TAG_inlined_subroutine DIE. */
24833 if (! BLOCK_ABSTRACT (stmt
))
24834 gen_inlined_subroutine_die (stmt
, context_die
);
24837 gen_lexical_block_die (stmt
, context_die
);
24840 decls_for_scope (stmt
, context_die
);
24843 /* Process variable DECL (or variable with origin ORIGIN) within
24844 block STMT and add it to CONTEXT_DIE. */
24846 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
24849 tree decl_or_origin
= decl
? decl
: origin
;
24851 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
24852 die
= lookup_decl_die (decl_or_origin
);
24853 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
)
24855 if (TYPE_DECL_IS_STUB (decl_or_origin
))
24856 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
24858 die
= lookup_decl_die (decl_or_origin
);
24859 /* Avoid re-creating the DIE late if it was optimized as unused early. */
24860 if (! die
&& ! early_dwarf
)
24866 /* Avoid creating DIEs for local typedefs and concrete static variables that
24867 will only be pruned later. */
24868 if ((origin
|| decl_ultimate_origin (decl
))
24869 && (TREE_CODE (decl_or_origin
) == TYPE_DECL
24870 || (VAR_P (decl_or_origin
) && TREE_STATIC (decl_or_origin
))))
24872 origin
= decl_ultimate_origin (decl_or_origin
);
24873 if (decl
&& VAR_P (decl
) && die
!= NULL
)
24875 die
= lookup_decl_die (origin
);
24877 equate_decl_number_to_die (decl
, die
);
24882 if (die
!= NULL
&& die
->die_parent
== NULL
)
24883 add_child_die (context_die
, die
);
24884 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
24887 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
24888 stmt
, context_die
);
24892 if (decl
&& DECL_P (decl
))
24894 die
= lookup_decl_die (decl
);
24896 /* Early created DIEs do not have a parent as the decls refer
24897 to the function as DECL_CONTEXT rather than the BLOCK. */
24898 if (die
&& die
->die_parent
== NULL
)
24900 gcc_assert (in_lto_p
);
24901 add_child_die (context_die
, die
);
24905 gen_decl_die (decl
, origin
, NULL
, context_die
);
24909 /* Generate all of the decls declared within a given scope and (recursively)
24910 all of its sub-blocks. */
24913 decls_for_scope (tree stmt
, dw_die_ref context_die
)
24919 /* Ignore NULL blocks. */
24920 if (stmt
== NULL_TREE
)
24923 /* Output the DIEs to represent all of the data objects and typedefs
24924 declared directly within this block but not within any nested
24925 sub-blocks. Also, nested function and tag DIEs have been
24926 generated with a parent of NULL; fix that up now. We don't
24927 have to do this if we're at -g1. */
24928 if (debug_info_level
> DINFO_LEVEL_TERSE
)
24930 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
24931 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
24932 /* BLOCK_NONLOCALIZED_VARs simply generate DIE stubs with abstract
24933 origin - avoid doing this twice as we have no good way to see
24934 if we've done it once already. */
24936 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
24938 decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
24939 if (decl
== current_function_decl
)
24940 /* Ignore declarations of the current function, while they
24941 are declarations, gen_subprogram_die would treat them
24942 as definitions again, because they are equal to
24943 current_function_decl and endlessly recurse. */;
24944 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
24945 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
24947 process_scope_var (stmt
, NULL_TREE
, decl
, context_die
);
24951 /* Even if we're at -g1, we need to process the subblocks in order to get
24952 inlined call information. */
24954 /* Output the DIEs to represent all sub-blocks (and the items declared
24955 therein) of this block. */
24956 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
24958 subblocks
= BLOCK_CHAIN (subblocks
))
24959 gen_block_die (subblocks
, context_die
);
24962 /* Is this a typedef we can avoid emitting? */
24965 is_redundant_typedef (const_tree decl
)
24967 if (TYPE_DECL_IS_STUB (decl
))
24970 if (DECL_ARTIFICIAL (decl
)
24971 && DECL_CONTEXT (decl
)
24972 && is_tagged_type (DECL_CONTEXT (decl
))
24973 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
24974 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
24975 /* Also ignore the artificial member typedef for the class name. */
24981 /* Return TRUE if TYPE is a typedef that names a type for linkage
24982 purposes. This kind of typedefs is produced by the C++ FE for
24985 typedef struct {...} foo;
24987 In that case, there is no typedef variant type produced for foo.
24988 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
24992 is_naming_typedef_decl (const_tree decl
)
24994 if (decl
== NULL_TREE
24995 || TREE_CODE (decl
) != TYPE_DECL
24996 || DECL_NAMELESS (decl
)
24997 || !is_tagged_type (TREE_TYPE (decl
))
24998 || DECL_IS_BUILTIN (decl
)
24999 || is_redundant_typedef (decl
)
25000 /* It looks like Ada produces TYPE_DECLs that are very similar
25001 to C++ naming typedefs but that have different
25002 semantics. Let's be specific to c++ for now. */
25006 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
25007 && TYPE_NAME (TREE_TYPE (decl
)) == decl
25008 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
25009 != TYPE_NAME (TREE_TYPE (decl
))));
25012 /* Looks up the DIE for a context. */
25014 static inline dw_die_ref
25015 lookup_context_die (tree context
)
25019 /* Find die that represents this context. */
25020 if (TYPE_P (context
))
25022 context
= TYPE_MAIN_VARIANT (context
);
25023 dw_die_ref ctx
= lookup_type_die (context
);
25026 return strip_naming_typedef (context
, ctx
);
25029 return lookup_decl_die (context
);
25031 return comp_unit_die ();
25034 /* Returns the DIE for a context. */
25036 static inline dw_die_ref
25037 get_context_die (tree context
)
25041 /* Find die that represents this context. */
25042 if (TYPE_P (context
))
25044 context
= TYPE_MAIN_VARIANT (context
);
25045 return strip_naming_typedef (context
, force_type_die (context
));
25048 return force_decl_die (context
);
25050 return comp_unit_die ();
25053 /* Returns the DIE for decl. A DIE will always be returned. */
25056 force_decl_die (tree decl
)
25058 dw_die_ref decl_die
;
25059 unsigned saved_external_flag
;
25060 tree save_fn
= NULL_TREE
;
25061 decl_die
= lookup_decl_die (decl
);
25064 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
25066 decl_die
= lookup_decl_die (decl
);
25070 switch (TREE_CODE (decl
))
25072 case FUNCTION_DECL
:
25073 /* Clear current_function_decl, so that gen_subprogram_die thinks
25074 that this is a declaration. At this point, we just want to force
25075 declaration die. */
25076 save_fn
= current_function_decl
;
25077 current_function_decl
= NULL_TREE
;
25078 gen_subprogram_die (decl
, context_die
);
25079 current_function_decl
= save_fn
;
25083 /* Set external flag to force declaration die. Restore it after
25084 gen_decl_die() call. */
25085 saved_external_flag
= DECL_EXTERNAL (decl
);
25086 DECL_EXTERNAL (decl
) = 1;
25087 gen_decl_die (decl
, NULL
, NULL
, context_die
);
25088 DECL_EXTERNAL (decl
) = saved_external_flag
;
25091 case NAMESPACE_DECL
:
25092 if (dwarf_version
>= 3 || !dwarf_strict
)
25093 dwarf2out_decl (decl
);
25095 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
25096 decl_die
= comp_unit_die ();
25099 case TRANSLATION_UNIT_DECL
:
25100 decl_die
= comp_unit_die ();
25104 gcc_unreachable ();
25107 /* We should be able to find the DIE now. */
25109 decl_die
= lookup_decl_die (decl
);
25110 gcc_assert (decl_die
);
25116 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
25117 always returned. */
25120 force_type_die (tree type
)
25122 dw_die_ref type_die
;
25124 type_die
= lookup_type_die (type
);
25127 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
25129 type_die
= modified_type_die (type
, TYPE_QUALS_NO_ADDR_SPACE (type
),
25130 false, context_die
);
25131 gcc_assert (type_die
);
25136 /* Force out any required namespaces to be able to output DECL,
25137 and return the new context_die for it, if it's changed. */
25140 setup_namespace_context (tree thing
, dw_die_ref context_die
)
25142 tree context
= (DECL_P (thing
)
25143 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
25144 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
25145 /* Force out the namespace. */
25146 context_die
= force_decl_die (context
);
25148 return context_die
;
25151 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
25152 type) within its namespace, if appropriate.
25154 For compatibility with older debuggers, namespace DIEs only contain
25155 declarations; all definitions are emitted at CU scope, with
25156 DW_AT_specification pointing to the declaration (like with class
25160 declare_in_namespace (tree thing
, dw_die_ref context_die
)
25162 dw_die_ref ns_context
;
25164 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25165 return context_die
;
25167 /* External declarations in the local scope only need to be emitted
25168 once, not once in the namespace and once in the scope.
25170 This avoids declaring the `extern' below in the
25171 namespace DIE as well as in the innermost scope:
25184 if (DECL_P (thing
) && DECL_EXTERNAL (thing
) && local_scope_p (context_die
))
25185 return context_die
;
25187 /* If this decl is from an inlined function, then don't try to emit it in its
25188 namespace, as we will get confused. It would have already been emitted
25189 when the abstract instance of the inline function was emitted anyways. */
25190 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
25191 return context_die
;
25193 ns_context
= setup_namespace_context (thing
, context_die
);
25195 if (ns_context
!= context_die
)
25199 if (DECL_P (thing
))
25200 gen_decl_die (thing
, NULL
, NULL
, ns_context
);
25202 gen_type_die (thing
, ns_context
);
25204 return context_die
;
25207 /* Generate a DIE for a namespace or namespace alias. */
25210 gen_namespace_die (tree decl
, dw_die_ref context_die
)
25212 dw_die_ref namespace_die
;
25214 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
25215 they are an alias of. */
25216 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
25218 /* Output a real namespace or module. */
25219 context_die
= setup_namespace_context (decl
, comp_unit_die ());
25220 namespace_die
= new_die (is_fortran ()
25221 ? DW_TAG_module
: DW_TAG_namespace
,
25222 context_die
, decl
);
25223 /* For Fortran modules defined in different CU don't add src coords. */
25224 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
25226 const char *name
= dwarf2_name (decl
, 0);
25228 add_name_attribute (namespace_die
, name
);
25231 add_name_and_src_coords_attributes (namespace_die
, decl
);
25232 if (DECL_EXTERNAL (decl
))
25233 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
25234 equate_decl_number_to_die (decl
, namespace_die
);
25238 /* Output a namespace alias. */
25240 /* Force out the namespace we are an alias of, if necessary. */
25241 dw_die_ref origin_die
25242 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
25244 if (DECL_FILE_SCOPE_P (decl
)
25245 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
25246 context_die
= setup_namespace_context (decl
, comp_unit_die ());
25247 /* Now create the namespace alias DIE. */
25248 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
25249 add_name_and_src_coords_attributes (namespace_die
, decl
);
25250 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
25251 equate_decl_number_to_die (decl
, namespace_die
);
25253 if ((dwarf_version
>= 5 || !dwarf_strict
)
25254 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
25255 DW_AT_export_symbols
) == 1)
25256 add_AT_flag (namespace_die
, DW_AT_export_symbols
, 1);
25258 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
25259 if (want_pubnames ())
25260 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
25263 /* Generate Dwarf debug information for a decl described by DECL.
25264 The return value is currently only meaningful for PARM_DECLs,
25265 for all other decls it returns NULL.
25267 If DECL is a FIELD_DECL, CTX is required: see the comment for VLR_CONTEXT.
25268 It can be NULL otherwise. */
25271 gen_decl_die (tree decl
, tree origin
, struct vlr_context
*ctx
,
25272 dw_die_ref context_die
)
25274 tree decl_or_origin
= decl
? decl
: origin
;
25275 tree class_origin
= NULL
, ultimate_origin
;
25277 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
25280 /* Ignore pointer bounds decls. */
25281 if (DECL_P (decl_or_origin
)
25282 && TREE_TYPE (decl_or_origin
)
25283 && POINTER_BOUNDS_P (decl_or_origin
))
25286 switch (TREE_CODE (decl_or_origin
))
25292 if (!is_fortran () && !is_ada ())
25294 /* The individual enumerators of an enum type get output when we output
25295 the Dwarf representation of the relevant enum type itself. */
25299 /* Emit its type. */
25300 gen_type_die (TREE_TYPE (decl
), context_die
);
25302 /* And its containing namespace. */
25303 context_die
= declare_in_namespace (decl
, context_die
);
25305 gen_const_die (decl
, context_die
);
25308 case FUNCTION_DECL
:
25311 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
25312 on local redeclarations of global functions. That seems broken. */
25313 if (current_function_decl
!= decl
)
25314 /* This is only a declaration. */;
25317 /* We should have abstract copies already and should not generate
25318 stray type DIEs in late LTO dumping. */
25322 /* If we're emitting a clone, emit info for the abstract instance. */
25323 else if (origin
|| DECL_ORIGIN (decl
) != decl
)
25324 dwarf2out_abstract_function (origin
25325 ? DECL_ORIGIN (origin
)
25326 : DECL_ABSTRACT_ORIGIN (decl
));
25328 /* If we're emitting a possibly inlined function emit it as
25329 abstract instance. */
25330 else if (cgraph_function_possibly_inlined_p (decl
)
25331 && ! DECL_ABSTRACT_P (decl
)
25332 && ! class_or_namespace_scope_p (context_die
)
25333 /* dwarf2out_abstract_function won't emit a die if this is just
25334 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
25335 that case, because that works only if we have a die. */
25336 && DECL_INITIAL (decl
) != NULL_TREE
)
25337 dwarf2out_abstract_function (decl
);
25339 /* Otherwise we're emitting the primary DIE for this decl. */
25340 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
25342 /* Before we describe the FUNCTION_DECL itself, make sure that we
25343 have its containing type. */
25345 origin
= decl_class_context (decl
);
25346 if (origin
!= NULL_TREE
)
25347 gen_type_die (origin
, context_die
);
25349 /* And its return type. */
25350 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
25352 /* And its virtual context. */
25353 if (DECL_VINDEX (decl
) != NULL_TREE
)
25354 gen_type_die (DECL_CONTEXT (decl
), context_die
);
25356 /* Make sure we have a member DIE for decl. */
25357 if (origin
!= NULL_TREE
)
25358 gen_type_die_for_member (origin
, decl
, context_die
);
25360 /* And its containing namespace. */
25361 context_die
= declare_in_namespace (decl
, context_die
);
25364 /* Now output a DIE to represent the function itself. */
25366 gen_subprogram_die (decl
, context_die
);
25370 /* If we are in terse mode, don't generate any DIEs to represent any
25371 actual typedefs. */
25372 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25375 /* In the special case of a TYPE_DECL node representing the declaration
25376 of some type tag, if the given TYPE_DECL is marked as having been
25377 instantiated from some other (original) TYPE_DECL node (e.g. one which
25378 was generated within the original definition of an inline function) we
25379 used to generate a special (abbreviated) DW_TAG_structure_type,
25380 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
25381 should be actually referencing those DIEs, as variable DIEs with that
25382 type would be emitted already in the abstract origin, so it was always
25383 removed during unused type prunning. Don't add anything in this
25385 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
25388 if (is_redundant_typedef (decl
))
25389 gen_type_die (TREE_TYPE (decl
), context_die
);
25391 /* Output a DIE to represent the typedef itself. */
25392 gen_typedef_die (decl
, context_die
);
25396 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
25397 gen_label_die (decl
, context_die
);
25402 /* If we are in terse mode, don't generate any DIEs to represent any
25403 variable declarations or definitions. */
25404 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25407 /* Avoid generating stray type DIEs during late dwarf dumping.
25408 All types have been dumped early. */
25410 /* ??? But in LTRANS we cannot annotate early created variably
25411 modified type DIEs without copying them and adjusting all
25412 references to them. Dump them again as happens for inlining
25413 which copies both the decl and the types. */
25414 /* ??? And even non-LTO needs to re-visit type DIEs to fill
25415 in VLA bound information for example. */
25416 || (decl
&& variably_modified_type_p (TREE_TYPE (decl
),
25417 current_function_decl
)))
25419 /* Output any DIEs that are needed to specify the type of this data
25421 if (decl_by_reference_p (decl_or_origin
))
25422 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
25424 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
25429 /* And its containing type. */
25430 class_origin
= decl_class_context (decl_or_origin
);
25431 if (class_origin
!= NULL_TREE
)
25432 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
25434 /* And its containing namespace. */
25435 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
25438 /* Now output the DIE to represent the data object itself. This gets
25439 complicated because of the possibility that the VAR_DECL really
25440 represents an inlined instance of a formal parameter for an inline
25442 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
25443 if (ultimate_origin
!= NULL_TREE
25444 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
25445 gen_formal_parameter_die (decl
, origin
,
25446 true /* Emit name attribute. */,
25449 gen_variable_die (decl
, origin
, context_die
);
25453 gcc_assert (ctx
!= NULL
&& ctx
->struct_type
!= NULL
);
25454 /* Ignore the nameless fields that are used to skip bits but handle C++
25455 anonymous unions and structs. */
25456 if (DECL_NAME (decl
) != NULL_TREE
25457 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
25458 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
25460 gen_type_die (member_declared_type (decl
), context_die
);
25461 gen_field_die (decl
, ctx
, context_die
);
25466 /* Avoid generating stray type DIEs during late dwarf dumping.
25467 All types have been dumped early. */
25469 /* ??? But in LTRANS we cannot annotate early created variably
25470 modified type DIEs without copying them and adjusting all
25471 references to them. Dump them again as happens for inlining
25472 which copies both the decl and the types. */
25473 /* ??? And even non-LTO needs to re-visit type DIEs to fill
25474 in VLA bound information for example. */
25475 || (decl
&& variably_modified_type_p (TREE_TYPE (decl
),
25476 current_function_decl
)))
25478 if (DECL_BY_REFERENCE (decl_or_origin
))
25479 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
25481 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
25483 return gen_formal_parameter_die (decl
, origin
,
25484 true /* Emit name attribute. */,
25487 case NAMESPACE_DECL
:
25488 if (dwarf_version
>= 3 || !dwarf_strict
)
25489 gen_namespace_die (decl
, context_die
);
25492 case IMPORTED_DECL
:
25493 dwarf2out_imported_module_or_decl_1 (decl
, DECL_NAME (decl
),
25494 DECL_CONTEXT (decl
), context_die
);
25497 case NAMELIST_DECL
:
25498 gen_namelist_decl (DECL_NAME (decl
), context_die
,
25499 NAMELIST_DECL_ASSOCIATED_DECL (decl
));
25503 /* Probably some frontend-internal decl. Assume we don't care. */
25504 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
25511 /* Output initial debug information for global DECL. Called at the
25512 end of the parsing process.
25514 This is the initial debug generation process. As such, the DIEs
25515 generated may be incomplete. A later debug generation pass
25516 (dwarf2out_late_global_decl) will augment the information generated
25517 in this pass (e.g., with complete location info). */
25520 dwarf2out_early_global_decl (tree decl
)
25524 /* gen_decl_die() will set DECL_ABSTRACT because
25525 cgraph_function_possibly_inlined_p() returns true. This is in
25526 turn will cause DW_AT_inline attributes to be set.
25528 This happens because at early dwarf generation, there is no
25529 cgraph information, causing cgraph_function_possibly_inlined_p()
25530 to return true. Trick cgraph_function_possibly_inlined_p()
25531 while we generate dwarf early. */
25532 bool save
= symtab
->global_info_ready
;
25533 symtab
->global_info_ready
= true;
25535 /* We don't handle TYPE_DECLs. If required, they'll be reached via
25536 other DECLs and they can point to template types or other things
25537 that dwarf2out can't handle when done via dwarf2out_decl. */
25538 if (TREE_CODE (decl
) != TYPE_DECL
25539 && TREE_CODE (decl
) != PARM_DECL
)
25541 if (TREE_CODE (decl
) == FUNCTION_DECL
)
25543 tree save_fndecl
= current_function_decl
;
25545 /* For nested functions, make sure we have DIEs for the parents first
25546 so that all nested DIEs are generated at the proper scope in the
25548 tree context
= decl_function_context (decl
);
25549 if (context
!= NULL
)
25551 dw_die_ref context_die
= lookup_decl_die (context
);
25552 current_function_decl
= context
;
25554 /* Avoid emitting DIEs multiple times, but still process CONTEXT
25555 enough so that it lands in its own context. This avoids type
25556 pruning issues later on. */
25557 if (context_die
== NULL
|| is_declaration_die (context_die
))
25558 dwarf2out_decl (context
);
25561 /* Emit an abstract origin of a function first. This happens
25562 with C++ constructor clones for example and makes
25563 dwarf2out_abstract_function happy which requires the early
25564 DIE of the abstract instance to be present. */
25565 tree origin
= DECL_ABSTRACT_ORIGIN (decl
);
25566 dw_die_ref origin_die
;
25568 /* Do not emit the DIE multiple times but make sure to
25569 process it fully here in case we just saw a declaration. */
25570 && ((origin_die
= lookup_decl_die (origin
)) == NULL
25571 || is_declaration_die (origin_die
)))
25573 current_function_decl
= origin
;
25574 dwarf2out_decl (origin
);
25577 /* Emit the DIE for decl but avoid doing that multiple times. */
25578 dw_die_ref old_die
;
25579 if ((old_die
= lookup_decl_die (decl
)) == NULL
25580 || is_declaration_die (old_die
))
25582 current_function_decl
= decl
;
25583 dwarf2out_decl (decl
);
25586 current_function_decl
= save_fndecl
;
25589 dwarf2out_decl (decl
);
25591 symtab
->global_info_ready
= save
;
25594 /* Output debug information for global decl DECL. Called from
25595 toplev.c after compilation proper has finished. */
25598 dwarf2out_late_global_decl (tree decl
)
25600 /* Fill-in any location information we were unable to determine
25601 on the first pass. */
25602 if (VAR_P (decl
) && !POINTER_BOUNDS_P (decl
))
25604 dw_die_ref die
= lookup_decl_die (decl
);
25606 /* We may have to generate early debug late for LTO in case debug
25607 was not enabled at compile-time or the target doesn't support
25608 the LTO early debug scheme. */
25609 if (! die
&& in_lto_p
)
25611 dwarf2out_decl (decl
);
25612 die
= lookup_decl_die (decl
);
25617 /* We get called via the symtab code invoking late_global_decl
25618 for symbols that are optimized out. Do not add locations
25619 for those, except if they have a DECL_VALUE_EXPR, in which case
25620 they are relevant for debuggers. */
25621 varpool_node
*node
= varpool_node::get (decl
);
25622 if ((! node
|| ! node
->definition
) && ! DECL_HAS_VALUE_EXPR_P (decl
))
25623 tree_add_const_value_attribute_for_decl (die
, decl
);
25625 add_location_or_const_value_attribute (die
, decl
, false);
25630 /* Output debug information for type decl DECL. Called from toplev.c
25631 and from language front ends (to record built-in types). */
25633 dwarf2out_type_decl (tree decl
, int local
)
25638 dwarf2out_decl (decl
);
25642 /* Output debug information for imported module or decl DECL.
25643 NAME is non-NULL name in the lexical block if the decl has been renamed.
25644 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
25645 that DECL belongs to.
25646 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
25648 dwarf2out_imported_module_or_decl_1 (tree decl
,
25650 tree lexical_block
,
25651 dw_die_ref lexical_block_die
)
25653 expanded_location xloc
;
25654 dw_die_ref imported_die
= NULL
;
25655 dw_die_ref at_import_die
;
25657 if (TREE_CODE (decl
) == IMPORTED_DECL
)
25659 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
25660 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
25664 xloc
= expand_location (input_location
);
25666 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
25668 at_import_die
= force_type_die (TREE_TYPE (decl
));
25669 /* For namespace N { typedef void T; } using N::T; base_type_die
25670 returns NULL, but DW_TAG_imported_declaration requires
25671 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
25672 if (!at_import_die
)
25674 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
25675 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
25676 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
25677 gcc_assert (at_import_die
);
25682 at_import_die
= lookup_decl_die (decl
);
25683 if (!at_import_die
)
25685 /* If we're trying to avoid duplicate debug info, we may not have
25686 emitted the member decl for this field. Emit it now. */
25687 if (TREE_CODE (decl
) == FIELD_DECL
)
25689 tree type
= DECL_CONTEXT (decl
);
25691 if (TYPE_CONTEXT (type
)
25692 && TYPE_P (TYPE_CONTEXT (type
))
25693 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
25694 DINFO_USAGE_DIR_USE
))
25696 gen_type_die_for_member (type
, decl
,
25697 get_context_die (TYPE_CONTEXT (type
)));
25699 if (TREE_CODE (decl
) == NAMELIST_DECL
)
25700 at_import_die
= gen_namelist_decl (DECL_NAME (decl
),
25701 get_context_die (DECL_CONTEXT (decl
)),
25704 at_import_die
= force_decl_die (decl
);
25708 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
25710 if (dwarf_version
>= 3 || !dwarf_strict
)
25711 imported_die
= new_die (DW_TAG_imported_module
,
25718 imported_die
= new_die (DW_TAG_imported_declaration
,
25722 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
25723 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
25724 if (debug_column_info
&& xloc
.column
)
25725 add_AT_unsigned (imported_die
, DW_AT_decl_column
, xloc
.column
);
25727 add_AT_string (imported_die
, DW_AT_name
,
25728 IDENTIFIER_POINTER (name
));
25729 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
25732 /* Output debug information for imported module or decl DECL.
25733 NAME is non-NULL name in context if the decl has been renamed.
25734 CHILD is true if decl is one of the renamed decls as part of
25735 importing whole module.
25736 IMPLICIT is set if this hook is called for an implicit import
25737 such as inline namespace. */
25740 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
25741 bool child
, bool implicit
)
25743 /* dw_die_ref at_import_die; */
25744 dw_die_ref scope_die
;
25746 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25751 /* For DWARF5, just DW_AT_export_symbols on the DW_TAG_namespace
25752 should be enough, for DWARF4 and older even if we emit as extension
25753 DW_AT_export_symbols add the implicit DW_TAG_imported_module anyway
25754 for the benefit of consumers unaware of DW_AT_export_symbols. */
25756 && dwarf_version
>= 5
25757 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
25758 DW_AT_export_symbols
) == 1)
25763 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
25764 We need decl DIE for reference and scope die. First, get DIE for the decl
25767 /* Get the scope die for decl context. Use comp_unit_die for global module
25768 or decl. If die is not found for non globals, force new die. */
25770 && TYPE_P (context
)
25771 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
25774 scope_die
= get_context_die (context
);
25778 /* DW_TAG_imported_module was introduced in the DWARFv3 specification, so
25779 there is nothing we can do, here. */
25780 if (dwarf_version
< 3 && dwarf_strict
)
25783 gcc_assert (scope_die
->die_child
);
25784 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
25785 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
25786 scope_die
= scope_die
->die_child
;
25789 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
25790 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
25793 /* Output debug information for namelists. */
25796 gen_namelist_decl (tree name
, dw_die_ref scope_die
, tree item_decls
)
25798 dw_die_ref nml_die
, nml_item_die
, nml_item_ref_die
;
25802 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25805 gcc_assert (scope_die
!= NULL
);
25806 nml_die
= new_die (DW_TAG_namelist
, scope_die
, NULL
);
25807 add_AT_string (nml_die
, DW_AT_name
, IDENTIFIER_POINTER (name
));
25809 /* If there are no item_decls, we have a nondefining namelist, e.g.
25810 with USE association; hence, set DW_AT_declaration. */
25811 if (item_decls
== NULL_TREE
)
25813 add_AT_flag (nml_die
, DW_AT_declaration
, 1);
25817 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls
), i
, value
)
25819 nml_item_ref_die
= lookup_decl_die (value
);
25820 if (!nml_item_ref_die
)
25821 nml_item_ref_die
= force_decl_die (value
);
25823 nml_item_die
= new_die (DW_TAG_namelist_item
, nml_die
, NULL
);
25824 add_AT_die_ref (nml_item_die
, DW_AT_namelist_items
, nml_item_ref_die
);
25830 /* Write the debugging output for DECL and return the DIE. */
25833 dwarf2out_decl (tree decl
)
25835 dw_die_ref context_die
= comp_unit_die ();
25837 switch (TREE_CODE (decl
))
25842 case FUNCTION_DECL
:
25843 /* If we're a nested function, initially use a parent of NULL; if we're
25844 a plain function, this will be fixed up in decls_for_scope. If
25845 we're a method, it will be ignored, since we already have a DIE. */
25846 if (decl_function_context (decl
)
25847 /* But if we're in terse mode, we don't care about scope. */
25848 && debug_info_level
> DINFO_LEVEL_TERSE
)
25849 context_die
= NULL
;
25853 /* For local statics lookup proper context die. */
25854 if (local_function_static (decl
))
25855 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
25857 /* If we are in terse mode, don't generate any DIEs to represent any
25858 variable declarations or definitions. */
25859 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25864 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25866 if (!is_fortran () && !is_ada ())
25868 if (TREE_STATIC (decl
) && decl_function_context (decl
))
25869 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
25872 case NAMESPACE_DECL
:
25873 case IMPORTED_DECL
:
25874 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25876 if (lookup_decl_die (decl
) != NULL
)
25881 /* Don't emit stubs for types unless they are needed by other DIEs. */
25882 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
25885 /* Don't bother trying to generate any DIEs to represent any of the
25886 normal built-in types for the language we are compiling. */
25887 if (DECL_IS_BUILTIN (decl
))
25890 /* If we are in terse mode, don't generate any DIEs for types. */
25891 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25894 /* If we're a function-scope tag, initially use a parent of NULL;
25895 this will be fixed up in decls_for_scope. */
25896 if (decl_function_context (decl
))
25897 context_die
= NULL
;
25901 case NAMELIST_DECL
:
25908 gen_decl_die (decl
, NULL
, NULL
, context_die
);
25912 dw_die_ref die
= lookup_decl_die (decl
);
25918 /* Write the debugging output for DECL. */
25921 dwarf2out_function_decl (tree decl
)
25923 dwarf2out_decl (decl
);
25924 call_arg_locations
= NULL
;
25925 call_arg_loc_last
= NULL
;
25926 call_site_count
= -1;
25927 tail_call_site_count
= -1;
25928 decl_loc_table
->empty ();
25929 cached_dw_loc_list_table
->empty ();
25932 /* Output a marker (i.e. a label) for the beginning of the generated code for
25933 a lexical block. */
25936 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
25937 unsigned int blocknum
)
25939 switch_to_section (current_function_section ());
25940 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
25943 /* Output a marker (i.e. a label) for the end of the generated code for a
25947 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
25949 switch_to_section (current_function_section ());
25950 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
25953 /* Returns nonzero if it is appropriate not to emit any debugging
25954 information for BLOCK, because it doesn't contain any instructions.
25956 Don't allow this for blocks with nested functions or local classes
25957 as we would end up with orphans, and in the presence of scheduling
25958 we may end up calling them anyway. */
25961 dwarf2out_ignore_block (const_tree block
)
25966 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
25967 if (TREE_CODE (decl
) == FUNCTION_DECL
25968 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
25970 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
25972 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
25973 if (TREE_CODE (decl
) == FUNCTION_DECL
25974 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
25981 /* Hash table routines for file_hash. */
25984 dwarf_file_hasher::equal (dwarf_file_data
*p1
, const char *p2
)
25986 return filename_cmp (p1
->filename
, p2
) == 0;
25990 dwarf_file_hasher::hash (dwarf_file_data
*p
)
25992 return htab_hash_string (p
->filename
);
25995 /* Lookup FILE_NAME (in the list of filenames that we know about here in
25996 dwarf2out.c) and return its "index". The index of each (known) filename is
25997 just a unique number which is associated with only that one filename. We
25998 need such numbers for the sake of generating labels (in the .debug_sfnames
25999 section) and references to those files numbers (in the .debug_srcinfo
26000 and .debug_macinfo sections). If the filename given as an argument is not
26001 found in our current list, add it to the list and assign it the next
26002 available unique index number. */
26004 static struct dwarf_file_data
*
26005 lookup_filename (const char *file_name
)
26007 struct dwarf_file_data
* created
;
26012 dwarf_file_data
**slot
26013 = file_table
->find_slot_with_hash (file_name
, htab_hash_string (file_name
),
26018 created
= ggc_alloc
<dwarf_file_data
> ();
26019 created
->filename
= file_name
;
26020 created
->emitted_number
= 0;
26025 /* If the assembler will construct the file table, then translate the compiler
26026 internal file table number into the assembler file table number, and emit
26027 a .file directive if we haven't already emitted one yet. The file table
26028 numbers are different because we prune debug info for unused variables and
26029 types, which may include filenames. */
26032 maybe_emit_file (struct dwarf_file_data
* fd
)
26034 if (! fd
->emitted_number
)
26036 if (last_emitted_file
)
26037 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
26039 fd
->emitted_number
= 1;
26040 last_emitted_file
= fd
;
26042 if (DWARF2_ASM_LINE_DEBUG_INFO
)
26044 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
26045 output_quoted_string (asm_out_file
,
26046 remap_debug_filename (fd
->filename
));
26047 fputc ('\n', asm_out_file
);
26051 return fd
->emitted_number
;
26054 /* Schedule generation of a DW_AT_const_value attribute to DIE.
26055 That generation should happen after function debug info has been
26056 generated. The value of the attribute is the constant value of ARG. */
26059 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
26061 die_arg_entry entry
;
26066 gcc_assert (early_dwarf
);
26068 if (!tmpl_value_parm_die_table
)
26069 vec_alloc (tmpl_value_parm_die_table
, 32);
26073 vec_safe_push (tmpl_value_parm_die_table
, entry
);
26076 /* Return TRUE if T is an instance of generic type, FALSE
26080 generic_type_p (tree t
)
26082 if (t
== NULL_TREE
|| !TYPE_P (t
))
26084 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
26087 /* Schedule the generation of the generic parameter dies for the
26088 instance of generic type T. The proper generation itself is later
26089 done by gen_scheduled_generic_parms_dies. */
26092 schedule_generic_params_dies_gen (tree t
)
26094 if (!generic_type_p (t
))
26097 gcc_assert (early_dwarf
);
26099 if (!generic_type_instances
)
26100 vec_alloc (generic_type_instances
, 256);
26102 vec_safe_push (generic_type_instances
, t
);
26105 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
26106 by append_entry_to_tmpl_value_parm_die_table. This function must
26107 be called after function DIEs have been generated. */
26110 gen_remaining_tmpl_value_param_die_attribute (void)
26112 if (tmpl_value_parm_die_table
)
26117 /* We do this in two phases - first get the cases we can
26118 handle during early-finish, preserving those we cannot
26119 (containing symbolic constants where we don't yet know
26120 whether we are going to output the referenced symbols).
26121 For those we try again at late-finish. */
26123 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
26125 if (!e
->die
->removed
26126 && !tree_add_const_value_attribute (e
->die
, e
->arg
))
26128 dw_loc_descr_ref loc
= NULL
;
26130 && (dwarf_version
>= 5 || !dwarf_strict
))
26131 loc
= loc_descriptor_from_tree (e
->arg
, 2, NULL
);
26133 add_AT_loc (e
->die
, DW_AT_location
, loc
);
26135 (*tmpl_value_parm_die_table
)[j
++] = *e
;
26138 tmpl_value_parm_die_table
->truncate (j
);
26142 /* Generate generic parameters DIEs for instances of generic types
26143 that have been previously scheduled by
26144 schedule_generic_params_dies_gen. This function must be called
26145 after all the types of the CU have been laid out. */
26148 gen_scheduled_generic_parms_dies (void)
26153 if (!generic_type_instances
)
26156 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
26157 if (COMPLETE_TYPE_P (t
))
26158 gen_generic_params_dies (t
);
26160 generic_type_instances
= NULL
;
26164 /* Replace DW_AT_name for the decl with name. */
26167 dwarf2out_set_name (tree decl
, tree name
)
26170 dw_attr_node
*attr
;
26173 die
= TYPE_SYMTAB_DIE (decl
);
26177 dname
= dwarf2_name (name
, 0);
26181 attr
= get_AT (die
, DW_AT_name
);
26184 struct indirect_string_node
*node
;
26186 node
= find_AT_string (dname
);
26187 /* replace the string. */
26188 attr
->dw_attr_val
.v
.val_str
= node
;
26192 add_name_attribute (die
, dname
);
26195 /* True if before or during processing of the first function being emitted. */
26196 static bool in_first_function_p
= true;
26197 /* True if loc_note during dwarf2out_var_location call might still be
26198 before first real instruction at address equal to .Ltext0. */
26199 static bool maybe_at_text_label_p
= true;
26200 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
26201 static unsigned int first_loclabel_num_not_at_text_label
;
26203 /* Called by the final INSN scan whenever we see a var location. We
26204 use it to drop labels in the right places, and throw the location in
26205 our lookup table. */
26208 dwarf2out_var_location (rtx_insn
*loc_note
)
26210 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
26211 struct var_loc_node
*newloc
;
26212 rtx_insn
*next_real
, *next_note
;
26213 rtx_insn
*call_insn
= NULL
;
26214 static const char *last_label
;
26215 static const char *last_postcall_label
;
26216 static bool last_in_cold_section_p
;
26217 static rtx_insn
*expected_next_loc_note
;
26221 if (!NOTE_P (loc_note
))
26223 if (CALL_P (loc_note
))
26226 if (SIBLING_CALL_P (loc_note
))
26227 tail_call_site_count
++;
26228 if (optimize
== 0 && !flag_var_tracking
)
26230 /* When the var-tracking pass is not running, there is no note
26231 for indirect calls whose target is compile-time known. In this
26232 case, process such calls specifically so that we generate call
26233 sites for them anyway. */
26234 rtx x
= PATTERN (loc_note
);
26235 if (GET_CODE (x
) == PARALLEL
)
26236 x
= XVECEXP (x
, 0, 0);
26237 if (GET_CODE (x
) == SET
)
26239 if (GET_CODE (x
) == CALL
)
26242 || GET_CODE (XEXP (x
, 0)) != SYMBOL_REF
26243 || !SYMBOL_REF_DECL (XEXP (x
, 0))
26244 || (TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0)))
26247 call_insn
= loc_note
;
26251 next_real
= next_real_insn (call_insn
);
26253 cached_next_real_insn
= NULL
;
26261 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
26262 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
26265 /* Optimize processing a large consecutive sequence of location
26266 notes so we don't spend too much time in next_real_insn. If the
26267 next insn is another location note, remember the next_real_insn
26268 calculation for next time. */
26269 next_real
= cached_next_real_insn
;
26272 if (expected_next_loc_note
!= loc_note
)
26276 next_note
= NEXT_INSN (loc_note
);
26278 || next_note
->deleted ()
26279 || ! NOTE_P (next_note
)
26280 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
26281 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
26285 next_real
= next_real_insn (loc_note
);
26289 expected_next_loc_note
= next_note
;
26290 cached_next_real_insn
= next_real
;
26293 cached_next_real_insn
= NULL
;
26295 /* If there are no instructions which would be affected by this note,
26296 don't do anything. */
26298 && next_real
== NULL_RTX
26299 && !NOTE_DURING_CALL_P (loc_note
))
26304 if (next_real
== NULL_RTX
)
26305 next_real
= get_last_insn ();
26307 /* If there were any real insns between note we processed last time
26308 and this note (or if it is the first note), clear
26309 last_{,postcall_}label so that they are not reused this time. */
26310 if (last_var_location_insn
== NULL_RTX
26311 || last_var_location_insn
!= next_real
26312 || last_in_cold_section_p
!= in_cold_section_p
)
26315 last_postcall_label
= NULL
;
26320 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
26321 newloc
= add_var_loc_to_decl (decl
, loc_note
,
26322 NOTE_DURING_CALL_P (loc_note
)
26323 ? last_postcall_label
: last_label
);
26324 if (newloc
== NULL
)
26333 /* If there were no real insns between note we processed last time
26334 and this note, use the label we emitted last time. Otherwise
26335 create a new label and emit it. */
26336 if (last_label
== NULL
)
26338 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
26339 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
26341 last_label
= ggc_strdup (loclabel
);
26342 /* See if loclabel might be equal to .Ltext0. If yes,
26343 bump first_loclabel_num_not_at_text_label. */
26344 if (!have_multiple_function_sections
26345 && in_first_function_p
26346 && maybe_at_text_label_p
)
26348 static rtx_insn
*last_start
;
26350 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
26351 if (insn
== last_start
)
26353 else if (!NONDEBUG_INSN_P (insn
))
26357 rtx body
= PATTERN (insn
);
26358 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
26360 /* Inline asm could occupy zero bytes. */
26361 else if (GET_CODE (body
) == ASM_INPUT
26362 || asm_noperands (body
) >= 0)
26364 #ifdef HAVE_attr_length
26365 else if (get_attr_min_length (insn
) == 0)
26370 /* Assume insn has non-zero length. */
26371 maybe_at_text_label_p
= false;
26375 if (maybe_at_text_label_p
)
26377 last_start
= loc_note
;
26378 first_loclabel_num_not_at_text_label
= loclabel_num
;
26383 gcc_assert ((loc_note
== NULL_RTX
&& call_insn
!= NULL_RTX
)
26384 || (loc_note
!= NULL_RTX
&& call_insn
== NULL_RTX
));
26388 struct call_arg_loc_node
*ca_loc
26389 = ggc_cleared_alloc
<call_arg_loc_node
> ();
26391 = loc_note
!= NULL_RTX
? prev_real_insn (loc_note
) : call_insn
;
26393 ca_loc
->call_arg_loc_note
= loc_note
;
26394 ca_loc
->next
= NULL
;
26395 ca_loc
->label
= last_label
;
26398 || (NONJUMP_INSN_P (prev
)
26399 && GET_CODE (PATTERN (prev
)) == SEQUENCE
26400 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
26401 if (!CALL_P (prev
))
26402 prev
= as_a
<rtx_sequence
*> (PATTERN (prev
))->insn (0);
26403 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
26405 /* Look for a SYMBOL_REF in the "prev" instruction. */
26406 rtx x
= get_call_rtx_from (PATTERN (prev
));
26409 /* Try to get the call symbol, if any. */
26410 if (MEM_P (XEXP (x
, 0)))
26412 /* First, look for a memory access to a symbol_ref. */
26413 if (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
26414 && SYMBOL_REF_DECL (XEXP (x
, 0))
26415 && TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0))) == FUNCTION_DECL
)
26416 ca_loc
->symbol_ref
= XEXP (x
, 0);
26417 /* Otherwise, look at a compile-time known user-level function
26421 && TREE_CODE (MEM_EXPR (x
)) == FUNCTION_DECL
)
26422 ca_loc
->symbol_ref
= XEXP (DECL_RTL (MEM_EXPR (x
)), 0);
26425 ca_loc
->block
= insn_scope (prev
);
26426 if (call_arg_locations
)
26427 call_arg_loc_last
->next
= ca_loc
;
26429 call_arg_locations
= ca_loc
;
26430 call_arg_loc_last
= ca_loc
;
26432 else if (loc_note
!= NULL_RTX
&& !NOTE_DURING_CALL_P (loc_note
))
26433 newloc
->label
= last_label
;
26436 if (!last_postcall_label
)
26438 sprintf (loclabel
, "%s-1", last_label
);
26439 last_postcall_label
= ggc_strdup (loclabel
);
26441 newloc
->label
= last_postcall_label
;
26444 last_var_location_insn
= next_real
;
26445 last_in_cold_section_p
= in_cold_section_p
;
26448 /* Called from finalize_size_functions for size functions so that their body
26449 can be encoded in the debug info to describe the layout of variable-length
26453 dwarf2out_size_function (tree decl
)
26455 function_to_dwarf_procedure (decl
);
26458 /* Note in one location list that text section has changed. */
26461 var_location_switch_text_section_1 (var_loc_list
**slot
, void *)
26463 var_loc_list
*list
= *slot
;
26465 list
->last_before_switch
26466 = list
->last
->next
? list
->last
->next
: list
->last
;
26470 /* Note in all location lists that text section has changed. */
26473 var_location_switch_text_section (void)
26475 if (decl_loc_table
== NULL
)
26478 decl_loc_table
->traverse
<void *, var_location_switch_text_section_1
> (NULL
);
26481 /* Create a new line number table. */
26483 static dw_line_info_table
*
26484 new_line_info_table (void)
26486 dw_line_info_table
*table
;
26488 table
= ggc_cleared_alloc
<dw_line_info_table
> ();
26489 table
->file_num
= 1;
26490 table
->line_num
= 1;
26491 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
26496 /* Lookup the "current" table into which we emit line info, so
26497 that we don't have to do it for every source line. */
26500 set_cur_line_info_table (section
*sec
)
26502 dw_line_info_table
*table
;
26504 if (sec
== text_section
)
26505 table
= text_section_line_info
;
26506 else if (sec
== cold_text_section
)
26508 table
= cold_text_section_line_info
;
26511 cold_text_section_line_info
= table
= new_line_info_table ();
26512 table
->end_label
= cold_end_label
;
26517 const char *end_label
;
26519 if (crtl
->has_bb_partition
)
26521 if (in_cold_section_p
)
26522 end_label
= crtl
->subsections
.cold_section_end_label
;
26524 end_label
= crtl
->subsections
.hot_section_end_label
;
26528 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
26529 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
26530 current_function_funcdef_no
);
26531 end_label
= ggc_strdup (label
);
26534 table
= new_line_info_table ();
26535 table
->end_label
= end_label
;
26537 vec_safe_push (separate_line_info
, table
);
26540 if (DWARF2_ASM_LINE_DEBUG_INFO
)
26541 table
->is_stmt
= (cur_line_info_table
26542 ? cur_line_info_table
->is_stmt
26543 : DWARF_LINE_DEFAULT_IS_STMT_START
);
26544 cur_line_info_table
= table
;
26548 /* We need to reset the locations at the beginning of each
26549 function. We can't do this in the end_function hook, because the
26550 declarations that use the locations won't have been output when
26551 that hook is called. Also compute have_multiple_function_sections here. */
26554 dwarf2out_begin_function (tree fun
)
26556 section
*sec
= function_section (fun
);
26558 if (sec
!= text_section
)
26559 have_multiple_function_sections
= true;
26561 if (crtl
->has_bb_partition
&& !cold_text_section
)
26563 gcc_assert (current_function_decl
== fun
);
26564 cold_text_section
= unlikely_text_section ();
26565 switch_to_section (cold_text_section
);
26566 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
26567 switch_to_section (sec
);
26570 dwarf2out_note_section_used ();
26571 call_site_count
= 0;
26572 tail_call_site_count
= 0;
26574 set_cur_line_info_table (sec
);
26577 /* Helper function of dwarf2out_end_function, called only after emitting
26578 the very first function into assembly. Check if some .debug_loc range
26579 might end with a .LVL* label that could be equal to .Ltext0.
26580 In that case we must force using absolute addresses in .debug_loc ranges,
26581 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
26582 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
26584 Set have_multiple_function_sections to true in that case and
26585 terminate htab traversal. */
26588 find_empty_loc_ranges_at_text_label (var_loc_list
**slot
, int)
26590 var_loc_list
*entry
= *slot
;
26591 struct var_loc_node
*node
;
26593 node
= entry
->first
;
26594 if (node
&& node
->next
&& node
->next
->label
)
26597 const char *label
= node
->next
->label
;
26598 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
26600 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
26602 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
26603 if (strcmp (label
, loclabel
) == 0)
26605 have_multiple_function_sections
= true;
26613 /* Hook called after emitting a function into assembly.
26614 This does something only for the very first function emitted. */
26617 dwarf2out_end_function (unsigned int)
26619 if (in_first_function_p
26620 && !have_multiple_function_sections
26621 && first_loclabel_num_not_at_text_label
26623 decl_loc_table
->traverse
<int, find_empty_loc_ranges_at_text_label
> (0);
26624 in_first_function_p
= false;
26625 maybe_at_text_label_p
= false;
26628 /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
26629 front-ends register a translation unit even before dwarf2out_init is
26631 static tree main_translation_unit
= NULL_TREE
;
26633 /* Hook called by front-ends after they built their main translation unit.
26634 Associate comp_unit_die to UNIT. */
26637 dwarf2out_register_main_translation_unit (tree unit
)
26639 gcc_assert (TREE_CODE (unit
) == TRANSLATION_UNIT_DECL
26640 && main_translation_unit
== NULL_TREE
);
26641 main_translation_unit
= unit
;
26642 /* If dwarf2out_init has not been called yet, it will perform the association
26643 itself looking at main_translation_unit. */
26644 if (decl_die_table
!= NULL
)
26645 equate_decl_number_to_die (unit
, comp_unit_die ());
26648 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
26651 push_dw_line_info_entry (dw_line_info_table
*table
,
26652 enum dw_line_info_opcode opcode
, unsigned int val
)
26654 dw_line_info_entry e
;
26657 vec_safe_push (table
->entries
, e
);
26660 /* Output a label to mark the beginning of a source code line entry
26661 and record information relating to this source line, in
26662 'line_info_table' for later output of the .debug_line section. */
26663 /* ??? The discriminator parameter ought to be unsigned. */
26666 dwarf2out_source_line (unsigned int line
, unsigned int column
,
26667 const char *filename
,
26668 int discriminator
, bool is_stmt
)
26670 unsigned int file_num
;
26671 dw_line_info_table
*table
;
26673 if (debug_info_level
< DINFO_LEVEL_TERSE
|| line
== 0)
26676 /* The discriminator column was added in dwarf4. Simplify the below
26677 by simply removing it if we're not supposed to output it. */
26678 if (dwarf_version
< 4 && dwarf_strict
)
26681 if (!debug_column_info
)
26684 table
= cur_line_info_table
;
26685 file_num
= maybe_emit_file (lookup_filename (filename
));
26687 /* ??? TODO: Elide duplicate line number entries. Traditionally,
26688 the debugger has used the second (possibly duplicate) line number
26689 at the beginning of the function to mark the end of the prologue.
26690 We could eliminate any other duplicates within the function. For
26691 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
26692 that second line number entry. */
26693 /* Recall that this end-of-prologue indication is *not* the same thing
26694 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
26695 to which the hook corresponds, follows the last insn that was
26696 emitted by gen_prologue. What we need is to precede the first insn
26697 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
26698 insn that corresponds to something the user wrote. These may be
26699 very different locations once scheduling is enabled. */
26701 if (0 && file_num
== table
->file_num
26702 && line
== table
->line_num
26703 && column
== table
->column_num
26704 && discriminator
== table
->discrim_num
26705 && is_stmt
== table
->is_stmt
)
26708 switch_to_section (current_function_section ());
26710 /* If requested, emit something human-readable. */
26711 if (flag_debug_asm
)
26713 if (debug_column_info
)
26714 fprintf (asm_out_file
, "\t%s %s:%d:%d\n", ASM_COMMENT_START
,
26715 filename
, line
, column
);
26717 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
26721 if (DWARF2_ASM_LINE_DEBUG_INFO
)
26723 /* Emit the .loc directive understood by GNU as. */
26724 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
26725 file_num, line, is_stmt, discriminator */
26726 fputs ("\t.loc ", asm_out_file
);
26727 fprint_ul (asm_out_file
, file_num
);
26728 putc (' ', asm_out_file
);
26729 fprint_ul (asm_out_file
, line
);
26730 putc (' ', asm_out_file
);
26731 fprint_ul (asm_out_file
, column
);
26733 if (is_stmt
!= table
->is_stmt
)
26735 fputs (" is_stmt ", asm_out_file
);
26736 putc (is_stmt
? '1' : '0', asm_out_file
);
26738 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
26740 gcc_assert (discriminator
> 0);
26741 fputs (" discriminator ", asm_out_file
);
26742 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
26744 putc ('\n', asm_out_file
);
26748 unsigned int label_num
= ++line_info_label_num
;
26750 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
26752 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
26753 if (file_num
!= table
->file_num
)
26754 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
26755 if (discriminator
!= table
->discrim_num
)
26756 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
26757 if (is_stmt
!= table
->is_stmt
)
26758 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
26759 push_dw_line_info_entry (table
, LI_set_line
, line
);
26760 if (debug_column_info
)
26761 push_dw_line_info_entry (table
, LI_set_column
, column
);
26764 table
->file_num
= file_num
;
26765 table
->line_num
= line
;
26766 table
->column_num
= column
;
26767 table
->discrim_num
= discriminator
;
26768 table
->is_stmt
= is_stmt
;
26769 table
->in_use
= true;
26772 /* Record the beginning of a new source file. */
26775 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
26777 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26780 e
.code
= DW_MACINFO_start_file
;
26782 e
.info
= ggc_strdup (filename
);
26783 vec_safe_push (macinfo_table
, e
);
26787 /* Record the end of a source file. */
26790 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
26792 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26795 e
.code
= DW_MACINFO_end_file
;
26798 vec_safe_push (macinfo_table
, e
);
26802 /* Called from debug_define in toplev.c. The `buffer' parameter contains
26803 the tail part of the directive line, i.e. the part which is past the
26804 initial whitespace, #, whitespace, directive-name, whitespace part. */
26807 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
26808 const char *buffer ATTRIBUTE_UNUSED
)
26810 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26813 /* Insert a dummy first entry to be able to optimize the whole
26814 predefined macro block using DW_MACRO_import. */
26815 if (macinfo_table
->is_empty () && lineno
<= 1)
26820 vec_safe_push (macinfo_table
, e
);
26822 e
.code
= DW_MACINFO_define
;
26824 e
.info
= ggc_strdup (buffer
);
26825 vec_safe_push (macinfo_table
, e
);
26829 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
26830 the tail part of the directive line, i.e. the part which is past the
26831 initial whitespace, #, whitespace, directive-name, whitespace part. */
26834 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
26835 const char *buffer ATTRIBUTE_UNUSED
)
26837 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26840 /* Insert a dummy first entry to be able to optimize the whole
26841 predefined macro block using DW_MACRO_import. */
26842 if (macinfo_table
->is_empty () && lineno
<= 1)
26847 vec_safe_push (macinfo_table
, e
);
26849 e
.code
= DW_MACINFO_undef
;
26851 e
.info
= ggc_strdup (buffer
);
26852 vec_safe_push (macinfo_table
, e
);
26856 /* Helpers to manipulate hash table of CUs. */
26858 struct macinfo_entry_hasher
: nofree_ptr_hash
<macinfo_entry
>
26860 static inline hashval_t
hash (const macinfo_entry
*);
26861 static inline bool equal (const macinfo_entry
*, const macinfo_entry
*);
26865 macinfo_entry_hasher::hash (const macinfo_entry
*entry
)
26867 return htab_hash_string (entry
->info
);
26871 macinfo_entry_hasher::equal (const macinfo_entry
*entry1
,
26872 const macinfo_entry
*entry2
)
26874 return !strcmp (entry1
->info
, entry2
->info
);
26877 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
26879 /* Output a single .debug_macinfo entry. */
26882 output_macinfo_op (macinfo_entry
*ref
)
26886 struct indirect_string_node
*node
;
26887 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
26888 struct dwarf_file_data
*fd
;
26892 case DW_MACINFO_start_file
:
26893 fd
= lookup_filename (ref
->info
);
26894 file_num
= maybe_emit_file (fd
);
26895 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
26896 dw2_asm_output_data_uleb128 (ref
->lineno
,
26897 "Included from line number %lu",
26898 (unsigned long) ref
->lineno
);
26899 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
26901 case DW_MACINFO_end_file
:
26902 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
26904 case DW_MACINFO_define
:
26905 case DW_MACINFO_undef
:
26906 len
= strlen (ref
->info
) + 1;
26908 && len
> DWARF_OFFSET_SIZE
26909 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
26910 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
26912 ref
->code
= ref
->code
== DW_MACINFO_define
26913 ? DW_MACRO_define_strp
: DW_MACRO_undef_strp
;
26914 output_macinfo_op (ref
);
26917 dw2_asm_output_data (1, ref
->code
,
26918 ref
->code
== DW_MACINFO_define
26919 ? "Define macro" : "Undefine macro");
26920 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
26921 (unsigned long) ref
->lineno
);
26922 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
26924 case DW_MACRO_define_strp
:
26925 case DW_MACRO_undef_strp
:
26926 node
= find_AT_string (ref
->info
);
26928 && (node
->form
== DW_FORM_strp
26929 || node
->form
== DW_FORM_GNU_str_index
));
26930 dw2_asm_output_data (1, ref
->code
,
26931 ref
->code
== DW_MACRO_define_strp
26932 ? "Define macro strp"
26933 : "Undefine macro strp");
26934 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
26935 (unsigned long) ref
->lineno
);
26936 if (node
->form
== DW_FORM_strp
)
26937 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
26938 debug_str_section
, "The macro: \"%s\"",
26941 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
26944 case DW_MACRO_import
:
26945 dw2_asm_output_data (1, ref
->code
, "Import");
26946 ASM_GENERATE_INTERNAL_LABEL (label
,
26947 DEBUG_MACRO_SECTION_LABEL
,
26948 ref
->lineno
+ macinfo_label_base
);
26949 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
26952 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
26953 ASM_COMMENT_START
, (unsigned long) ref
->code
);
26958 /* Attempt to make a sequence of define/undef macinfo ops shareable with
26959 other compilation unit .debug_macinfo sections. IDX is the first
26960 index of a define/undef, return the number of ops that should be
26961 emitted in a comdat .debug_macinfo section and emit
26962 a DW_MACRO_import entry referencing it.
26963 If the define/undef entry should be emitted normally, return 0. */
26966 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
26967 macinfo_hash_type
**macinfo_htab
)
26969 macinfo_entry
*first
, *second
, *cur
, *inc
;
26970 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
26971 unsigned char checksum
[16];
26972 struct md5_ctx ctx
;
26973 char *grp_name
, *tail
;
26975 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
26976 macinfo_entry
**slot
;
26978 first
= &(*macinfo_table
)[idx
];
26979 second
= &(*macinfo_table
)[idx
+ 1];
26981 /* Optimize only if there are at least two consecutive define/undef ops,
26982 and either all of them are before first DW_MACINFO_start_file
26983 with lineno {0,1} (i.e. predefined macro block), or all of them are
26984 in some included header file. */
26985 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
26987 if (vec_safe_is_empty (files
))
26989 if (first
->lineno
> 1 || second
->lineno
> 1)
26992 else if (first
->lineno
== 0)
26995 /* Find the last define/undef entry that can be grouped together
26996 with first and at the same time compute md5 checksum of their
26997 codes, linenumbers and strings. */
26998 md5_init_ctx (&ctx
);
26999 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
27000 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
27002 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
27006 unsigned char code
= cur
->code
;
27007 md5_process_bytes (&code
, 1, &ctx
);
27008 checksum_uleb128 (cur
->lineno
, &ctx
);
27009 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
27011 md5_finish_ctx (&ctx
, checksum
);
27014 /* From the containing include filename (if any) pick up just
27015 usable characters from its basename. */
27016 if (vec_safe_is_empty (files
))
27019 base
= lbasename (files
->last ().info
);
27020 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
27021 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
27022 encoded_filename_len
++;
27023 /* Count . at the end. */
27024 if (encoded_filename_len
)
27025 encoded_filename_len
++;
27027 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
27028 linebuf_len
= strlen (linebuf
);
27030 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
27031 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
27033 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
27034 tail
= grp_name
+ 4;
27035 if (encoded_filename_len
)
27037 for (i
= 0; base
[i
]; i
++)
27038 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
27042 memcpy (tail
, linebuf
, linebuf_len
);
27043 tail
+= linebuf_len
;
27045 for (i
= 0; i
< 16; i
++)
27046 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
27048 /* Construct a macinfo_entry for DW_MACRO_import
27049 in the empty vector entry before the first define/undef. */
27050 inc
= &(*macinfo_table
)[idx
- 1];
27051 inc
->code
= DW_MACRO_import
;
27053 inc
->info
= ggc_strdup (grp_name
);
27054 if (!*macinfo_htab
)
27055 *macinfo_htab
= new macinfo_hash_type (10);
27056 /* Avoid emitting duplicates. */
27057 slot
= (*macinfo_htab
)->find_slot (inc
, INSERT
);
27062 /* If such an entry has been used before, just emit
27063 a DW_MACRO_import op. */
27065 output_macinfo_op (inc
);
27066 /* And clear all macinfo_entry in the range to avoid emitting them
27067 in the second pass. */
27068 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
27077 inc
->lineno
= (*macinfo_htab
)->elements ();
27078 output_macinfo_op (inc
);
27083 /* Save any strings needed by the macinfo table in the debug str
27084 table. All strings must be collected into the table by the time
27085 index_string is called. */
27088 save_macinfo_strings (void)
27092 macinfo_entry
*ref
;
27094 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
27098 /* Match the logic in output_macinfo_op to decide on
27099 indirect strings. */
27100 case DW_MACINFO_define
:
27101 case DW_MACINFO_undef
:
27102 len
= strlen (ref
->info
) + 1;
27104 && len
> DWARF_OFFSET_SIZE
27105 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
27106 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
27107 set_indirect_string (find_AT_string (ref
->info
));
27109 case DW_MACRO_define_strp
:
27110 case DW_MACRO_undef_strp
:
27111 set_indirect_string (find_AT_string (ref
->info
));
27119 /* Output macinfo section(s). */
27122 output_macinfo (const char *debug_line_label
, bool early_lto_debug
)
27125 unsigned long length
= vec_safe_length (macinfo_table
);
27126 macinfo_entry
*ref
;
27127 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
27128 macinfo_hash_type
*macinfo_htab
= NULL
;
27129 char dl_section_ref
[MAX_ARTIFICIAL_LABEL_BYTES
];
27134 /* output_macinfo* uses these interchangeably. */
27135 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_define
27136 && (int) DW_MACINFO_undef
== (int) DW_MACRO_undef
27137 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_start_file
27138 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_end_file
);
27140 /* AIX Assembler inserts the length, so adjust the reference to match the
27141 offset expected by debuggers. */
27142 strcpy (dl_section_ref
, debug_line_label
);
27143 if (XCOFF_DEBUGGING_INFO
)
27144 strcat (dl_section_ref
, DWARF_INITIAL_LENGTH_SIZE_STR
);
27146 /* For .debug_macro emit the section header. */
27147 if (!dwarf_strict
|| dwarf_version
>= 5)
27149 dw2_asm_output_data (2, dwarf_version
>= 5 ? 5 : 4,
27150 "DWARF macro version number");
27151 if (DWARF_OFFSET_SIZE
== 8)
27152 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
27154 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
27155 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_line_label
,
27156 debug_line_section
, NULL
);
27159 /* In the first loop, it emits the primary .debug_macinfo section
27160 and after each emitted op the macinfo_entry is cleared.
27161 If a longer range of define/undef ops can be optimized using
27162 DW_MACRO_import, the DW_MACRO_import op is emitted and kept in
27163 the vector before the first define/undef in the range and the
27164 whole range of define/undef ops is not emitted and kept. */
27165 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
27169 case DW_MACINFO_start_file
:
27170 vec_safe_push (files
, *ref
);
27172 case DW_MACINFO_end_file
:
27173 if (!vec_safe_is_empty (files
))
27176 case DW_MACINFO_define
:
27177 case DW_MACINFO_undef
:
27178 if ((!dwarf_strict
|| dwarf_version
>= 5)
27179 && HAVE_COMDAT_GROUP
27180 && vec_safe_length (files
) != 1
27183 && (*macinfo_table
)[i
- 1].code
== 0)
27185 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
27194 /* A dummy entry may be inserted at the beginning to be able
27195 to optimize the whole block of predefined macros. */
27201 output_macinfo_op (ref
);
27209 /* Save the number of transparent includes so we can adjust the
27210 label number for the fat LTO object DWARF. */
27211 unsigned macinfo_label_base_adj
= macinfo_htab
->elements ();
27213 delete macinfo_htab
;
27214 macinfo_htab
= NULL
;
27216 /* If any DW_MACRO_import were used, on those DW_MACRO_import entries
27217 terminate the current chain and switch to a new comdat .debug_macinfo
27218 section and emit the define/undef entries within it. */
27219 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
27224 case DW_MACRO_import
:
27226 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
27227 tree comdat_key
= get_identifier (ref
->info
);
27228 /* Terminate the previous .debug_macinfo section. */
27229 dw2_asm_output_data (1, 0, "End compilation unit");
27230 targetm
.asm_out
.named_section (debug_macinfo_section_name
,
27234 ? SECTION_EXCLUDE
: 0),
27236 ASM_GENERATE_INTERNAL_LABEL (label
,
27237 DEBUG_MACRO_SECTION_LABEL
,
27238 ref
->lineno
+ macinfo_label_base
);
27239 ASM_OUTPUT_LABEL (asm_out_file
, label
);
27242 dw2_asm_output_data (2, dwarf_version
>= 5 ? 5 : 4,
27243 "DWARF macro version number");
27244 if (DWARF_OFFSET_SIZE
== 8)
27245 dw2_asm_output_data (1, 1, "Flags: 64-bit");
27247 dw2_asm_output_data (1, 0, "Flags: 32-bit");
27250 case DW_MACINFO_define
:
27251 case DW_MACINFO_undef
:
27252 output_macinfo_op (ref
);
27257 gcc_unreachable ();
27260 macinfo_label_base
+= macinfo_label_base_adj
;
27263 /* Initialize the various sections and labels for dwarf output and prefix
27264 them with PREFIX if non-NULL. */
27267 init_sections_and_labels (bool early_lto_debug
)
27269 /* As we may get called multiple times have a generation count for
27271 static unsigned generation
= 0;
27273 if (early_lto_debug
)
27275 if (!dwarf_split_debug_info
)
27277 debug_info_section
= get_section (DEBUG_LTO_INFO_SECTION
,
27278 SECTION_DEBUG
| SECTION_EXCLUDE
,
27280 debug_abbrev_section
= get_section (DEBUG_LTO_ABBREV_SECTION
,
27281 SECTION_DEBUG
| SECTION_EXCLUDE
,
27283 debug_macinfo_section_name
27284 = ((dwarf_strict
&& dwarf_version
< 5)
27285 ? DEBUG_LTO_MACINFO_SECTION
: DEBUG_LTO_MACRO_SECTION
);
27286 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
27288 | SECTION_EXCLUDE
, NULL
);
27289 /* For macro info we have to refer to a debug_line section, so
27290 similar to split-dwarf emit a skeleton one for early debug. */
27291 debug_skeleton_line_section
27292 = get_section (DEBUG_LTO_LINE_SECTION
,
27293 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27294 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
27295 DEBUG_SKELETON_LINE_SECTION_LABEL
,
27300 /* ??? Which of the following do we need early? */
27301 debug_info_section
= get_section (DEBUG_LTO_DWO_INFO_SECTION
,
27302 SECTION_DEBUG
| SECTION_EXCLUDE
,
27304 debug_abbrev_section
= get_section (DEBUG_LTO_DWO_ABBREV_SECTION
,
27305 SECTION_DEBUG
| SECTION_EXCLUDE
,
27307 debug_skeleton_info_section
= get_section (DEBUG_LTO_INFO_SECTION
,
27309 | SECTION_EXCLUDE
, NULL
);
27310 debug_skeleton_abbrev_section
27311 = get_section (DEBUG_LTO_ABBREV_SECTION
,
27312 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27313 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
27314 DEBUG_SKELETON_ABBREV_SECTION_LABEL
,
27317 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections
27318 stay in the main .o, but the skeleton_line goes into the split
27320 debug_skeleton_line_section
27321 = get_section (DEBUG_LTO_LINE_SECTION
,
27322 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27323 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
27324 DEBUG_SKELETON_LINE_SECTION_LABEL
,
27326 debug_str_offsets_section
27327 = get_section (DEBUG_LTO_DWO_STR_OFFSETS_SECTION
,
27328 SECTION_DEBUG
| SECTION_EXCLUDE
,
27330 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
27331 DEBUG_SKELETON_INFO_SECTION_LABEL
,
27333 debug_str_dwo_section
= get_section (DEBUG_LTO_STR_DWO_SECTION
,
27334 DEBUG_STR_DWO_SECTION_FLAGS
,
27336 debug_macinfo_section_name
27337 = ((dwarf_strict
&& dwarf_version
< 5)
27338 ? DEBUG_LTO_DWO_MACINFO_SECTION
: DEBUG_LTO_DWO_MACRO_SECTION
);
27339 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
27340 SECTION_DEBUG
| SECTION_EXCLUDE
,
27343 debug_str_section
= get_section (DEBUG_LTO_STR_SECTION
,
27344 DEBUG_STR_SECTION_FLAGS
27345 | SECTION_EXCLUDE
, NULL
);
27346 if (!dwarf_split_debug_info
&& !DWARF2_ASM_LINE_DEBUG_INFO
)
27347 debug_line_str_section
27348 = get_section (DEBUG_LTO_LINE_STR_SECTION
,
27349 DEBUG_STR_SECTION_FLAGS
| SECTION_EXCLUDE
, NULL
);
27353 if (!dwarf_split_debug_info
)
27355 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
27356 SECTION_DEBUG
, NULL
);
27357 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
27358 SECTION_DEBUG
, NULL
);
27359 debug_loc_section
= get_section (dwarf_version
>= 5
27360 ? DEBUG_LOCLISTS_SECTION
27361 : DEBUG_LOC_SECTION
,
27362 SECTION_DEBUG
, NULL
);
27363 debug_macinfo_section_name
27364 = ((dwarf_strict
&& dwarf_version
< 5)
27365 ? DEBUG_MACINFO_SECTION
: DEBUG_MACRO_SECTION
);
27366 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
27367 SECTION_DEBUG
, NULL
);
27371 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
27372 SECTION_DEBUG
| SECTION_EXCLUDE
,
27374 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
27375 SECTION_DEBUG
| SECTION_EXCLUDE
,
27377 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
27378 SECTION_DEBUG
, NULL
);
27379 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
27380 SECTION_DEBUG
, NULL
);
27381 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
27382 SECTION_DEBUG
, NULL
);
27383 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
27384 DEBUG_SKELETON_ABBREV_SECTION_LABEL
,
27387 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections
27388 stay in the main .o, but the skeleton_line goes into the
27390 debug_skeleton_line_section
27391 = get_section (DEBUG_DWO_LINE_SECTION
,
27392 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27393 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
27394 DEBUG_SKELETON_LINE_SECTION_LABEL
,
27396 debug_str_offsets_section
27397 = get_section (DEBUG_DWO_STR_OFFSETS_SECTION
,
27398 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27399 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
27400 DEBUG_SKELETON_INFO_SECTION_LABEL
,
27402 debug_loc_section
= get_section (dwarf_version
>= 5
27403 ? DEBUG_DWO_LOCLISTS_SECTION
27404 : DEBUG_DWO_LOC_SECTION
,
27405 SECTION_DEBUG
| SECTION_EXCLUDE
,
27407 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
27408 DEBUG_STR_DWO_SECTION_FLAGS
,
27410 debug_macinfo_section_name
27411 = ((dwarf_strict
&& dwarf_version
< 5)
27412 ? DEBUG_DWO_MACINFO_SECTION
: DEBUG_DWO_MACRO_SECTION
);
27413 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
27414 SECTION_DEBUG
| SECTION_EXCLUDE
,
27417 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
27418 SECTION_DEBUG
, NULL
);
27419 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
27420 SECTION_DEBUG
, NULL
);
27421 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
27422 SECTION_DEBUG
, NULL
);
27423 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
27424 SECTION_DEBUG
, NULL
);
27425 debug_str_section
= get_section (DEBUG_STR_SECTION
,
27426 DEBUG_STR_SECTION_FLAGS
, NULL
);
27427 if (!dwarf_split_debug_info
&& !DWARF2_ASM_LINE_DEBUG_INFO
)
27428 debug_line_str_section
= get_section (DEBUG_LINE_STR_SECTION
,
27429 DEBUG_STR_SECTION_FLAGS
, NULL
);
27430 debug_ranges_section
= get_section (dwarf_version
>= 5
27431 ? DEBUG_RNGLISTS_SECTION
27432 : DEBUG_RANGES_SECTION
,
27433 SECTION_DEBUG
, NULL
);
27434 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
27435 SECTION_DEBUG
, NULL
);
27438 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
27439 DEBUG_ABBREV_SECTION_LABEL
, generation
);
27440 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
27441 DEBUG_INFO_SECTION_LABEL
, generation
);
27442 info_section_emitted
= false;
27443 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
27444 DEBUG_LINE_SECTION_LABEL
, generation
);
27445 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
27446 DEBUG_RANGES_SECTION_LABEL
, generation
);
27447 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
27448 ASM_GENERATE_INTERNAL_LABEL (ranges_base_label
,
27449 DEBUG_RANGES_SECTION_LABEL
, 2 + generation
);
27450 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
27451 DEBUG_ADDR_SECTION_LABEL
, generation
);
27452 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
27453 (dwarf_strict
&& dwarf_version
< 5)
27454 ? DEBUG_MACINFO_SECTION_LABEL
27455 : DEBUG_MACRO_SECTION_LABEL
, generation
);
27456 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
,
27462 /* Set up for Dwarf output at the start of compilation. */
27465 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
27467 /* Allocate the file_table. */
27468 file_table
= hash_table
<dwarf_file_hasher
>::create_ggc (50);
27470 #ifndef DWARF2_LINENO_DEBUGGING_INFO
27471 /* Allocate the decl_die_table. */
27472 decl_die_table
= hash_table
<decl_die_hasher
>::create_ggc (10);
27474 /* Allocate the decl_loc_table. */
27475 decl_loc_table
= hash_table
<decl_loc_hasher
>::create_ggc (10);
27477 /* Allocate the cached_dw_loc_list_table. */
27478 cached_dw_loc_list_table
= hash_table
<dw_loc_list_hasher
>::create_ggc (10);
27480 /* Allocate the initial hunk of the decl_scope_table. */
27481 vec_alloc (decl_scope_table
, 256);
27483 /* Allocate the initial hunk of the abbrev_die_table. */
27484 vec_alloc (abbrev_die_table
, 256);
27485 /* Zero-th entry is allocated, but unused. */
27486 abbrev_die_table
->quick_push (NULL
);
27488 /* Allocate the dwarf_proc_stack_usage_map. */
27489 dwarf_proc_stack_usage_map
= new hash_map
<dw_die_ref
, int>;
27491 /* Allocate the pubtypes and pubnames vectors. */
27492 vec_alloc (pubname_table
, 32);
27493 vec_alloc (pubtype_table
, 32);
27495 vec_alloc (incomplete_types
, 64);
27497 vec_alloc (used_rtx_array
, 32);
27499 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
27500 vec_alloc (macinfo_table
, 64);
27503 /* If front-ends already registered a main translation unit but we were not
27504 ready to perform the association, do this now. */
27505 if (main_translation_unit
!= NULL_TREE
)
27506 equate_decl_number_to_die (main_translation_unit
, comp_unit_die ());
27509 /* Called before compile () starts outputtting functions, variables
27510 and toplevel asms into assembly. */
27513 dwarf2out_assembly_start (void)
27515 if (text_section_line_info
)
27518 #ifndef DWARF2_LINENO_DEBUGGING_INFO
27519 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
27520 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
27521 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
27522 COLD_TEXT_SECTION_LABEL
, 0);
27523 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
27525 switch_to_section (text_section
);
27526 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
27529 /* Make sure the line number table for .text always exists. */
27530 text_section_line_info
= new_line_info_table ();
27531 text_section_line_info
->end_label
= text_end_label
;
27533 #ifdef DWARF2_LINENO_DEBUGGING_INFO
27534 cur_line_info_table
= text_section_line_info
;
27537 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
27538 && dwarf2out_do_cfi_asm ()
27539 && !dwarf2out_do_eh_frame ())
27540 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
27543 /* A helper function for dwarf2out_finish called through
27544 htab_traverse. Assign a string its index. All strings must be
27545 collected into the table by the time index_string is called,
27546 because the indexing code relies on htab_traverse to traverse nodes
27547 in the same order for each run. */
27550 index_string (indirect_string_node
**h
, unsigned int *index
)
27552 indirect_string_node
*node
= *h
;
27554 find_string_form (node
);
27555 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
27557 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
27558 node
->index
= *index
;
27564 /* A helper function for output_indirect_strings called through
27565 htab_traverse. Output the offset to a string and update the
27569 output_index_string_offset (indirect_string_node
**h
, unsigned int *offset
)
27571 indirect_string_node
*node
= *h
;
27573 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
27575 /* Assert that this node has been assigned an index. */
27576 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
27577 && node
->index
!= NOT_INDEXED
);
27578 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
27579 "indexed string 0x%x: %s", node
->index
, node
->str
);
27580 *offset
+= strlen (node
->str
) + 1;
27585 /* A helper function for dwarf2out_finish called through
27586 htab_traverse. Output the indexed string. */
27589 output_index_string (indirect_string_node
**h
, unsigned int *cur_idx
)
27591 struct indirect_string_node
*node
= *h
;
27593 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
27595 /* Assert that the strings are output in the same order as their
27596 indexes were assigned. */
27597 gcc_assert (*cur_idx
== node
->index
);
27598 assemble_string (node
->str
, strlen (node
->str
) + 1);
27604 /* A helper function for dwarf2out_finish called through
27605 htab_traverse. Emit one queued .debug_str string. */
27608 output_indirect_string (indirect_string_node
**h
, enum dwarf_form form
)
27610 struct indirect_string_node
*node
= *h
;
27612 node
->form
= find_string_form (node
);
27613 if (node
->form
== form
&& node
->refcount
> 0)
27615 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
27616 assemble_string (node
->str
, strlen (node
->str
) + 1);
27622 /* Output the indexed string table. */
27625 output_indirect_strings (void)
27627 switch_to_section (debug_str_section
);
27628 if (!dwarf_split_debug_info
)
27629 debug_str_hash
->traverse
<enum dwarf_form
,
27630 output_indirect_string
> (DW_FORM_strp
);
27633 unsigned int offset
= 0;
27634 unsigned int cur_idx
= 0;
27636 skeleton_debug_str_hash
->traverse
<enum dwarf_form
,
27637 output_indirect_string
> (DW_FORM_strp
);
27639 switch_to_section (debug_str_offsets_section
);
27640 debug_str_hash
->traverse_noresize
27641 <unsigned int *, output_index_string_offset
> (&offset
);
27642 switch_to_section (debug_str_dwo_section
);
27643 debug_str_hash
->traverse_noresize
<unsigned int *, output_index_string
>
27648 /* Callback for htab_traverse to assign an index to an entry in the
27649 table, and to write that entry to the .debug_addr section. */
27652 output_addr_table_entry (addr_table_entry
**slot
, unsigned int *cur_index
)
27654 addr_table_entry
*entry
= *slot
;
27656 if (entry
->refcount
== 0)
27658 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
27659 || entry
->index
== NOT_INDEXED
);
27663 gcc_assert (entry
->index
== *cur_index
);
27666 switch (entry
->kind
)
27669 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
27670 "0x%x", entry
->index
);
27672 case ate_kind_rtx_dtprel
:
27673 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
27674 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
27677 fputc ('\n', asm_out_file
);
27679 case ate_kind_label
:
27680 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
27681 "0x%x", entry
->index
);
27684 gcc_unreachable ();
27689 /* Produce the .debug_addr section. */
27692 output_addr_table (void)
27694 unsigned int index
= 0;
27695 if (addr_index_table
== NULL
|| addr_index_table
->size () == 0)
27698 switch_to_section (debug_addr_section
);
27700 ->traverse_noresize
<unsigned int *, output_addr_table_entry
> (&index
);
27703 #if ENABLE_ASSERT_CHECKING
27704 /* Verify that all marks are clear. */
27707 verify_marks_clear (dw_die_ref die
)
27711 gcc_assert (! die
->die_mark
);
27712 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
27714 #endif /* ENABLE_ASSERT_CHECKING */
27716 /* Clear the marks for a die and its children.
27717 Be cool if the mark isn't set. */
27720 prune_unmark_dies (dw_die_ref die
)
27726 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
27729 /* Given LOC that is referenced by a DIE we're marking as used, find all
27730 referenced DWARF procedures it references and mark them as used. */
27733 prune_unused_types_walk_loc_descr (dw_loc_descr_ref loc
)
27735 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
27736 switch (loc
->dw_loc_opc
)
27738 case DW_OP_implicit_pointer
:
27739 case DW_OP_convert
:
27740 case DW_OP_reinterpret
:
27741 case DW_OP_GNU_implicit_pointer
:
27742 case DW_OP_GNU_convert
:
27743 case DW_OP_GNU_reinterpret
:
27744 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
)
27745 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
27747 case DW_OP_GNU_variable_value
:
27748 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
27751 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
27754 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
27755 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
27756 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
27761 case DW_OP_call_ref
:
27762 case DW_OP_const_type
:
27763 case DW_OP_GNU_const_type
:
27764 case DW_OP_GNU_parameter_ref
:
27765 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
);
27766 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
27768 case DW_OP_regval_type
:
27769 case DW_OP_deref_type
:
27770 case DW_OP_GNU_regval_type
:
27771 case DW_OP_GNU_deref_type
:
27772 gcc_assert (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_die_ref
);
27773 prune_unused_types_mark (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
, 1);
27775 case DW_OP_entry_value
:
27776 case DW_OP_GNU_entry_value
:
27777 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
);
27778 prune_unused_types_walk_loc_descr (loc
->dw_loc_oprnd1
.v
.val_loc
);
27785 /* Given DIE that we're marking as used, find any other dies
27786 it references as attributes and mark them as used. */
27789 prune_unused_types_walk_attribs (dw_die_ref die
)
27794 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
27796 switch (AT_class (a
))
27798 /* Make sure DWARF procedures referenced by location descriptions will
27800 case dw_val_class_loc
:
27801 prune_unused_types_walk_loc_descr (AT_loc (a
));
27803 case dw_val_class_loc_list
:
27804 for (dw_loc_list_ref list
= AT_loc_list (a
);
27806 list
= list
->dw_loc_next
)
27807 prune_unused_types_walk_loc_descr (list
->expr
);
27810 case dw_val_class_die_ref
:
27811 /* A reference to another DIE.
27812 Make sure that it will get emitted.
27813 If it was broken out into a comdat group, don't follow it. */
27814 if (! AT_ref (a
)->comdat_type_p
27815 || a
->dw_attr
== DW_AT_specification
)
27816 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
27819 case dw_val_class_str
:
27820 /* Set the string's refcount to 0 so that prune_unused_types_mark
27821 accounts properly for it. */
27822 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
27831 /* Mark the generic parameters and arguments children DIEs of DIE. */
27834 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
27838 if (die
== NULL
|| die
->die_child
== NULL
)
27840 c
= die
->die_child
;
27843 if (is_template_parameter (c
))
27844 prune_unused_types_mark (c
, 1);
27846 } while (c
&& c
!= die
->die_child
);
27849 /* Mark DIE as being used. If DOKIDS is true, then walk down
27850 to DIE's children. */
27853 prune_unused_types_mark (dw_die_ref die
, int dokids
)
27857 if (die
->die_mark
== 0)
27859 /* We haven't done this node yet. Mark it as used. */
27861 /* If this is the DIE of a generic type instantiation,
27862 mark the children DIEs that describe its generic parms and
27864 prune_unused_types_mark_generic_parms_dies (die
);
27866 /* We also have to mark its parents as used.
27867 (But we don't want to mark our parent's kids due to this,
27868 unless it is a class.) */
27869 if (die
->die_parent
)
27870 prune_unused_types_mark (die
->die_parent
,
27871 class_scope_p (die
->die_parent
));
27873 /* Mark any referenced nodes. */
27874 prune_unused_types_walk_attribs (die
);
27876 /* If this node is a specification,
27877 also mark the definition, if it exists. */
27878 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
27879 prune_unused_types_mark (die
->die_definition
, 1);
27882 if (dokids
&& die
->die_mark
!= 2)
27884 /* We need to walk the children, but haven't done so yet.
27885 Remember that we've walked the kids. */
27888 /* If this is an array type, we need to make sure our
27889 kids get marked, even if they're types. If we're
27890 breaking out types into comdat sections, do this
27891 for all type definitions. */
27892 if (die
->die_tag
== DW_TAG_array_type
27893 || (use_debug_types
27894 && is_type_die (die
) && ! is_declaration_die (die
)))
27895 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
27897 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
27901 /* For local classes, look if any static member functions were emitted
27902 and if so, mark them. */
27905 prune_unused_types_walk_local_classes (dw_die_ref die
)
27909 if (die
->die_mark
== 2)
27912 switch (die
->die_tag
)
27914 case DW_TAG_structure_type
:
27915 case DW_TAG_union_type
:
27916 case DW_TAG_class_type
:
27919 case DW_TAG_subprogram
:
27920 if (!get_AT_flag (die
, DW_AT_declaration
)
27921 || die
->die_definition
!= NULL
)
27922 prune_unused_types_mark (die
, 1);
27929 /* Mark children. */
27930 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
27933 /* Walk the tree DIE and mark types that we actually use. */
27936 prune_unused_types_walk (dw_die_ref die
)
27940 /* Don't do anything if this node is already marked and
27941 children have been marked as well. */
27942 if (die
->die_mark
== 2)
27945 switch (die
->die_tag
)
27947 case DW_TAG_structure_type
:
27948 case DW_TAG_union_type
:
27949 case DW_TAG_class_type
:
27950 if (die
->die_perennial_p
)
27953 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
27954 if (c
->die_tag
== DW_TAG_subprogram
)
27957 /* Finding used static member functions inside of classes
27958 is needed just for local classes, because for other classes
27959 static member function DIEs with DW_AT_specification
27960 are emitted outside of the DW_TAG_*_type. If we ever change
27961 it, we'd need to call this even for non-local classes. */
27963 prune_unused_types_walk_local_classes (die
);
27965 /* It's a type node --- don't mark it. */
27968 case DW_TAG_const_type
:
27969 case DW_TAG_packed_type
:
27970 case DW_TAG_pointer_type
:
27971 case DW_TAG_reference_type
:
27972 case DW_TAG_rvalue_reference_type
:
27973 case DW_TAG_volatile_type
:
27974 case DW_TAG_typedef
:
27975 case DW_TAG_array_type
:
27976 case DW_TAG_interface_type
:
27977 case DW_TAG_friend
:
27978 case DW_TAG_enumeration_type
:
27979 case DW_TAG_subroutine_type
:
27980 case DW_TAG_string_type
:
27981 case DW_TAG_set_type
:
27982 case DW_TAG_subrange_type
:
27983 case DW_TAG_ptr_to_member_type
:
27984 case DW_TAG_file_type
:
27985 /* Type nodes are useful only when other DIEs reference them --- don't
27989 case DW_TAG_dwarf_procedure
:
27990 /* Likewise for DWARF procedures. */
27992 if (die
->die_perennial_p
)
27998 /* Mark everything else. */
28002 if (die
->die_mark
== 0)
28006 /* Now, mark any dies referenced from here. */
28007 prune_unused_types_walk_attribs (die
);
28012 /* Mark children. */
28013 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
28016 /* Increment the string counts on strings referred to from DIE's
28020 prune_unused_types_update_strings (dw_die_ref die
)
28025 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
28026 if (AT_class (a
) == dw_val_class_str
)
28028 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
28030 /* Avoid unnecessarily putting strings that are used less than
28031 twice in the hash table. */
28033 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
28035 indirect_string_node
**slot
28036 = debug_str_hash
->find_slot_with_hash (s
->str
,
28037 htab_hash_string (s
->str
),
28039 gcc_assert (*slot
== NULL
);
28045 /* Mark DIE and its children as removed. */
28048 mark_removed (dw_die_ref die
)
28051 die
->removed
= true;
28052 FOR_EACH_CHILD (die
, c
, mark_removed (c
));
28055 /* Remove from the tree DIE any dies that aren't marked. */
28058 prune_unused_types_prune (dw_die_ref die
)
28062 gcc_assert (die
->die_mark
);
28063 prune_unused_types_update_strings (die
);
28065 if (! die
->die_child
)
28068 c
= die
->die_child
;
28070 dw_die_ref prev
= c
, next
;
28071 for (c
= c
->die_sib
; ! c
->die_mark
; c
= next
)
28072 if (c
== die
->die_child
)
28074 /* No marked children between 'prev' and the end of the list. */
28076 /* No marked children at all. */
28077 die
->die_child
= NULL
;
28080 prev
->die_sib
= c
->die_sib
;
28081 die
->die_child
= prev
;
28094 if (c
!= prev
->die_sib
)
28096 prune_unused_types_prune (c
);
28097 } while (c
!= die
->die_child
);
28100 /* Remove dies representing declarations that we never use. */
28103 prune_unused_types (void)
28106 limbo_die_node
*node
;
28107 comdat_type_node
*ctnode
;
28108 pubname_entry
*pub
;
28109 dw_die_ref base_type
;
28111 #if ENABLE_ASSERT_CHECKING
28112 /* All the marks should already be clear. */
28113 verify_marks_clear (comp_unit_die ());
28114 for (node
= limbo_die_list
; node
; node
= node
->next
)
28115 verify_marks_clear (node
->die
);
28116 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
28117 verify_marks_clear (ctnode
->root_die
);
28118 #endif /* ENABLE_ASSERT_CHECKING */
28120 /* Mark types that are used in global variables. */
28121 premark_types_used_by_global_vars ();
28123 /* Set the mark on nodes that are actually used. */
28124 prune_unused_types_walk (comp_unit_die ());
28125 for (node
= limbo_die_list
; node
; node
= node
->next
)
28126 prune_unused_types_walk (node
->die
);
28127 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
28129 prune_unused_types_walk (ctnode
->root_die
);
28130 prune_unused_types_mark (ctnode
->type_die
, 1);
28133 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
28134 are unusual in that they are pubnames that are the children of pubtypes.
28135 They should only be marked via their parent DW_TAG_enumeration_type die,
28136 not as roots in themselves. */
28137 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
28138 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
28139 prune_unused_types_mark (pub
->die
, 1);
28140 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
28141 prune_unused_types_mark (base_type
, 1);
28143 /* For -fvar-tracking-assignments, also set the mark on nodes that could be
28144 referenced by DW_TAG_call_site DW_AT_call_origin (i.e. direct call
28146 cgraph_node
*cnode
;
28147 FOR_EACH_FUNCTION (cnode
)
28148 if (cnode
->referred_to_p (false))
28150 dw_die_ref die
= lookup_decl_die (cnode
->decl
);
28151 if (die
== NULL
|| die
->die_mark
)
28153 for (cgraph_edge
*e
= cnode
->callers
; e
; e
= e
->next_caller
)
28154 if (e
->caller
!= cnode
28155 && opt_for_fn (e
->caller
->decl
, flag_var_tracking_assignments
))
28157 prune_unused_types_mark (die
, 1);
28162 if (debug_str_hash
)
28163 debug_str_hash
->empty ();
28164 if (skeleton_debug_str_hash
)
28165 skeleton_debug_str_hash
->empty ();
28166 prune_unused_types_prune (comp_unit_die ());
28167 for (limbo_die_node
**pnode
= &limbo_die_list
; *pnode
; )
28170 if (!node
->die
->die_mark
)
28171 *pnode
= node
->next
;
28174 prune_unused_types_prune (node
->die
);
28175 pnode
= &node
->next
;
28178 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
28179 prune_unused_types_prune (ctnode
->root_die
);
28181 /* Leave the marks clear. */
28182 prune_unmark_dies (comp_unit_die ());
28183 for (node
= limbo_die_list
; node
; node
= node
->next
)
28184 prune_unmark_dies (node
->die
);
28185 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
28186 prune_unmark_dies (ctnode
->root_die
);
28189 /* Helpers to manipulate hash table of comdat type units. */
28191 struct comdat_type_hasher
: nofree_ptr_hash
<comdat_type_node
>
28193 static inline hashval_t
hash (const comdat_type_node
*);
28194 static inline bool equal (const comdat_type_node
*, const comdat_type_node
*);
28198 comdat_type_hasher::hash (const comdat_type_node
*type_node
)
28201 memcpy (&h
, type_node
->signature
, sizeof (h
));
28206 comdat_type_hasher::equal (const comdat_type_node
*type_node_1
,
28207 const comdat_type_node
*type_node_2
)
28209 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
28210 DWARF_TYPE_SIGNATURE_SIZE
));
28213 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
28214 to the location it would have been added, should we know its
28215 DECL_ASSEMBLER_NAME when we added other attributes. This will
28216 probably improve compactness of debug info, removing equivalent
28217 abbrevs, and hide any differences caused by deferring the
28218 computation of the assembler name, triggered by e.g. PCH. */
28221 move_linkage_attr (dw_die_ref die
)
28223 unsigned ix
= vec_safe_length (die
->die_attr
);
28224 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
28226 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
28227 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
28231 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
28233 if (prev
->dw_attr
== DW_AT_decl_line
28234 || prev
->dw_attr
== DW_AT_decl_column
28235 || prev
->dw_attr
== DW_AT_name
)
28239 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
28241 die
->die_attr
->pop ();
28242 die
->die_attr
->quick_insert (ix
, linkage
);
28246 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
28247 referenced from typed stack ops and count how often they are used. */
28250 mark_base_types (dw_loc_descr_ref loc
)
28252 dw_die_ref base_type
= NULL
;
28254 for (; loc
; loc
= loc
->dw_loc_next
)
28256 switch (loc
->dw_loc_opc
)
28258 case DW_OP_regval_type
:
28259 case DW_OP_deref_type
:
28260 case DW_OP_GNU_regval_type
:
28261 case DW_OP_GNU_deref_type
:
28262 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
28264 case DW_OP_convert
:
28265 case DW_OP_reinterpret
:
28266 case DW_OP_GNU_convert
:
28267 case DW_OP_GNU_reinterpret
:
28268 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
28271 case DW_OP_const_type
:
28272 case DW_OP_GNU_const_type
:
28273 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28275 case DW_OP_entry_value
:
28276 case DW_OP_GNU_entry_value
:
28277 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
28282 gcc_assert (base_type
->die_parent
== comp_unit_die ());
28283 if (base_type
->die_mark
)
28284 base_type
->die_mark
++;
28287 base_types
.safe_push (base_type
);
28288 base_type
->die_mark
= 1;
28293 /* Comparison function for sorting marked base types. */
28296 base_type_cmp (const void *x
, const void *y
)
28298 dw_die_ref dx
= *(const dw_die_ref
*) x
;
28299 dw_die_ref dy
= *(const dw_die_ref
*) y
;
28300 unsigned int byte_size1
, byte_size2
;
28301 unsigned int encoding1
, encoding2
;
28302 unsigned int align1
, align2
;
28303 if (dx
->die_mark
> dy
->die_mark
)
28305 if (dx
->die_mark
< dy
->die_mark
)
28307 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
28308 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
28309 if (byte_size1
< byte_size2
)
28311 if (byte_size1
> byte_size2
)
28313 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
28314 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
28315 if (encoding1
< encoding2
)
28317 if (encoding1
> encoding2
)
28319 align1
= get_AT_unsigned (dx
, DW_AT_alignment
);
28320 align2
= get_AT_unsigned (dy
, DW_AT_alignment
);
28321 if (align1
< align2
)
28323 if (align1
> align2
)
28328 /* Move base types marked by mark_base_types as early as possible
28329 in the CU, sorted by decreasing usage count both to make the
28330 uleb128 references as small as possible and to make sure they
28331 will have die_offset already computed by calc_die_sizes when
28332 sizes of typed stack loc ops is computed. */
28335 move_marked_base_types (void)
28338 dw_die_ref base_type
, die
, c
;
28340 if (base_types
.is_empty ())
28343 /* Sort by decreasing usage count, they will be added again in that
28345 base_types
.qsort (base_type_cmp
);
28346 die
= comp_unit_die ();
28347 c
= die
->die_child
;
28350 dw_die_ref prev
= c
;
28352 while (c
->die_mark
)
28354 remove_child_with_prev (c
, prev
);
28355 /* As base types got marked, there must be at least
28356 one node other than DW_TAG_base_type. */
28357 gcc_assert (die
->die_child
!= NULL
);
28361 while (c
!= die
->die_child
);
28362 gcc_assert (die
->die_child
);
28363 c
= die
->die_child
;
28364 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
28366 base_type
->die_mark
= 0;
28367 base_type
->die_sib
= c
->die_sib
;
28368 c
->die_sib
= base_type
;
28373 /* Helper function for resolve_addr, attempt to resolve
28374 one CONST_STRING, return true if successful. Similarly verify that
28375 SYMBOL_REFs refer to variables emitted in the current CU. */
28378 resolve_one_addr (rtx
*addr
)
28382 if (GET_CODE (rtl
) == CONST_STRING
)
28384 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
28385 tree t
= build_string (len
, XSTR (rtl
, 0));
28386 tree tlen
= size_int (len
- 1);
28388 = build_array_type (char_type_node
, build_index_type (tlen
));
28389 rtl
= lookup_constant_def (t
);
28390 if (!rtl
|| !MEM_P (rtl
))
28392 rtl
= XEXP (rtl
, 0);
28393 if (GET_CODE (rtl
) == SYMBOL_REF
28394 && SYMBOL_REF_DECL (rtl
)
28395 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
28397 vec_safe_push (used_rtx_array
, rtl
);
28402 if (GET_CODE (rtl
) == SYMBOL_REF
28403 && SYMBOL_REF_DECL (rtl
))
28405 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
28407 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
28410 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
28414 if (GET_CODE (rtl
) == CONST
)
28416 subrtx_ptr_iterator::array_type array
;
28417 FOR_EACH_SUBRTX_PTR (iter
, array
, &XEXP (rtl
, 0), ALL
)
28418 if (!resolve_one_addr (*iter
))
28425 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
28426 if possible, and create DW_TAG_dwarf_procedure that can be referenced
28427 from DW_OP_implicit_pointer if the string hasn't been seen yet. */
28430 string_cst_pool_decl (tree t
)
28432 rtx rtl
= output_constant_def (t
, 1);
28433 unsigned char *array
;
28434 dw_loc_descr_ref l
;
28439 if (!rtl
|| !MEM_P (rtl
))
28441 rtl
= XEXP (rtl
, 0);
28442 if (GET_CODE (rtl
) != SYMBOL_REF
28443 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
28446 decl
= SYMBOL_REF_DECL (rtl
);
28447 if (!lookup_decl_die (decl
))
28449 len
= TREE_STRING_LENGTH (t
);
28450 vec_safe_push (used_rtx_array
, rtl
);
28451 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
28452 array
= ggc_vec_alloc
<unsigned char> (len
);
28453 memcpy (array
, TREE_STRING_POINTER (t
), len
);
28454 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
28455 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
28456 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
28457 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
28458 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
28459 add_AT_loc (ref
, DW_AT_location
, l
);
28460 equate_decl_number_to_die (decl
, ref
);
28465 /* Helper function of resolve_addr_in_expr. LOC is
28466 a DW_OP_addr followed by DW_OP_stack_value, either at the start
28467 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
28468 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
28469 with DW_OP_implicit_pointer if possible
28470 and return true, if unsuccessful, return false. */
28473 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
28475 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
28476 HOST_WIDE_INT offset
= 0;
28477 dw_die_ref ref
= NULL
;
28480 if (GET_CODE (rtl
) == CONST
28481 && GET_CODE (XEXP (rtl
, 0)) == PLUS
28482 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
28484 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
28485 rtl
= XEXP (XEXP (rtl
, 0), 0);
28487 if (GET_CODE (rtl
) == CONST_STRING
)
28489 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
28490 tree t
= build_string (len
, XSTR (rtl
, 0));
28491 tree tlen
= size_int (len
- 1);
28494 = build_array_type (char_type_node
, build_index_type (tlen
));
28495 rtl
= string_cst_pool_decl (t
);
28499 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
28501 decl
= SYMBOL_REF_DECL (rtl
);
28502 if (VAR_P (decl
) && !DECL_EXTERNAL (decl
))
28504 ref
= lookup_decl_die (decl
);
28505 if (ref
&& (get_AT (ref
, DW_AT_location
)
28506 || get_AT (ref
, DW_AT_const_value
)))
28508 loc
->dw_loc_opc
= dwarf_OP (DW_OP_implicit_pointer
);
28509 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28510 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
28511 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
28512 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28513 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
28514 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
28522 /* Helper function for resolve_addr, handle one location
28523 expression, return false if at least one CONST_STRING or SYMBOL_REF in
28524 the location list couldn't be resolved. */
28527 resolve_addr_in_expr (dw_attr_node
*a
, dw_loc_descr_ref loc
)
28529 dw_loc_descr_ref keep
= NULL
;
28530 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
28531 switch (loc
->dw_loc_opc
)
28534 if (!resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
28537 || prev
->dw_loc_opc
== DW_OP_piece
28538 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
28539 && loc
->dw_loc_next
28540 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
28541 && (!dwarf_strict
|| dwarf_version
>= 5)
28542 && optimize_one_addr_into_implicit_ptr (loc
))
28547 case DW_OP_GNU_addr_index
:
28548 case DW_OP_GNU_const_index
:
28549 if (loc
->dw_loc_opc
== DW_OP_GNU_addr_index
28550 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
28552 rtx rtl
= loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
;
28553 if (!resolve_one_addr (&rtl
))
28555 remove_addr_table_entry (loc
->dw_loc_oprnd1
.val_entry
);
28556 loc
->dw_loc_oprnd1
.val_entry
28557 = add_addr_table_entry (rtl
, ate_kind_rtx
);
28560 case DW_OP_const4u
:
28561 case DW_OP_const8u
:
28563 && !resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
28566 case DW_OP_plus_uconst
:
28567 if (size_of_loc_descr (loc
)
28568 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
28570 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
28572 dw_loc_descr_ref repl
28573 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
28574 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
28575 add_loc_descr (&repl
, loc
->dw_loc_next
);
28579 case DW_OP_implicit_value
:
28580 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
28581 && !resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
))
28584 case DW_OP_implicit_pointer
:
28585 case DW_OP_GNU_implicit_pointer
:
28586 case DW_OP_GNU_parameter_ref
:
28587 case DW_OP_GNU_variable_value
:
28588 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
28591 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
28594 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28595 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
28596 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28598 if (loc
->dw_loc_opc
== DW_OP_GNU_variable_value
)
28601 && loc
->dw_loc_next
== NULL
28602 && AT_class (a
) == dw_val_class_loc
)
28603 switch (a
->dw_attr
)
28605 /* Following attributes allow both exprloc and reference,
28606 so if the whole expression is DW_OP_GNU_variable_value
28607 alone we could transform it into reference. */
28608 case DW_AT_byte_size
:
28609 case DW_AT_bit_size
:
28610 case DW_AT_lower_bound
:
28611 case DW_AT_upper_bound
:
28612 case DW_AT_bit_stride
:
28614 case DW_AT_allocated
:
28615 case DW_AT_associated
:
28616 case DW_AT_byte_stride
:
28617 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
28618 a
->dw_attr_val
.val_entry
= NULL
;
28619 a
->dw_attr_val
.v
.val_die_ref
.die
28620 = loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28621 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
28630 case DW_OP_const_type
:
28631 case DW_OP_regval_type
:
28632 case DW_OP_deref_type
:
28633 case DW_OP_convert
:
28634 case DW_OP_reinterpret
:
28635 case DW_OP_GNU_const_type
:
28636 case DW_OP_GNU_regval_type
:
28637 case DW_OP_GNU_deref_type
:
28638 case DW_OP_GNU_convert
:
28639 case DW_OP_GNU_reinterpret
:
28640 while (loc
->dw_loc_next
28641 && (loc
->dw_loc_next
->dw_loc_opc
== DW_OP_convert
28642 || loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
))
28644 dw_die_ref base1
, base2
;
28645 unsigned enc1
, enc2
, size1
, size2
;
28646 if (loc
->dw_loc_opc
== DW_OP_regval_type
28647 || loc
->dw_loc_opc
== DW_OP_deref_type
28648 || loc
->dw_loc_opc
== DW_OP_GNU_regval_type
28649 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
28650 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
28651 else if (loc
->dw_loc_oprnd1
.val_class
28652 == dw_val_class_unsigned_const
)
28655 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28656 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
28657 == dw_val_class_unsigned_const
)
28659 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28660 gcc_assert (base1
->die_tag
== DW_TAG_base_type
28661 && base2
->die_tag
== DW_TAG_base_type
);
28662 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
28663 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
28664 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
28665 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
28667 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
28668 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
28672 /* Optimize away next DW_OP_convert after
28673 adjusting LOC's base type die reference. */
28674 if (loc
->dw_loc_opc
== DW_OP_regval_type
28675 || loc
->dw_loc_opc
== DW_OP_deref_type
28676 || loc
->dw_loc_opc
== DW_OP_GNU_regval_type
28677 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
28678 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
28680 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
28681 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
28684 /* Don't change integer DW_OP_convert after e.g. floating
28685 point typed stack entry. */
28686 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
28687 keep
= loc
->dw_loc_next
;
28697 /* Helper function of resolve_addr. DIE had DW_AT_location of
28698 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
28699 and DW_OP_addr couldn't be resolved. resolve_addr has already
28700 removed the DW_AT_location attribute. This function attempts to
28701 add a new DW_AT_location attribute with DW_OP_implicit_pointer
28702 to it or DW_AT_const_value attribute, if possible. */
28705 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
28708 || lookup_decl_die (decl
) != die
28709 || DECL_EXTERNAL (decl
)
28710 || !TREE_STATIC (decl
)
28711 || DECL_INITIAL (decl
) == NULL_TREE
28712 || DECL_P (DECL_INITIAL (decl
))
28713 || get_AT (die
, DW_AT_const_value
))
28716 tree init
= DECL_INITIAL (decl
);
28717 HOST_WIDE_INT offset
= 0;
28718 /* For variables that have been optimized away and thus
28719 don't have a memory location, see if we can emit
28720 DW_AT_const_value instead. */
28721 if (tree_add_const_value_attribute (die
, init
))
28723 if (dwarf_strict
&& dwarf_version
< 5)
28725 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
28726 and ADDR_EXPR refers to a decl that has DW_AT_location or
28727 DW_AT_const_value (but isn't addressable, otherwise
28728 resolving the original DW_OP_addr wouldn't fail), see if
28729 we can add DW_OP_implicit_pointer. */
28731 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
28732 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
28734 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
28735 init
= TREE_OPERAND (init
, 0);
28738 if (TREE_CODE (init
) != ADDR_EXPR
)
28740 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
28741 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
28742 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
28743 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
28744 && TREE_OPERAND (init
, 0) != decl
))
28747 dw_loc_descr_ref l
;
28749 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
28751 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
28754 decl
= SYMBOL_REF_DECL (rtl
);
28757 decl
= TREE_OPERAND (init
, 0);
28758 ref
= lookup_decl_die (decl
);
28760 || (!get_AT (ref
, DW_AT_location
)
28761 && !get_AT (ref
, DW_AT_const_value
)))
28763 l
= new_loc_descr (dwarf_OP (DW_OP_implicit_pointer
), 0, offset
);
28764 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28765 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
28766 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28767 add_AT_loc (die
, DW_AT_location
, l
);
28771 /* Return NULL if l is a DWARF expression, or first op that is not
28772 valid DWARF expression. */
28774 static dw_loc_descr_ref
28775 non_dwarf_expression (dw_loc_descr_ref l
)
28779 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
28781 switch (l
->dw_loc_opc
)
28784 case DW_OP_implicit_value
:
28785 case DW_OP_stack_value
:
28786 case DW_OP_implicit_pointer
:
28787 case DW_OP_GNU_implicit_pointer
:
28788 case DW_OP_GNU_parameter_ref
:
28790 case DW_OP_bit_piece
:
28795 l
= l
->dw_loc_next
;
28800 /* Return adjusted copy of EXPR:
28801 If it is empty DWARF expression, return it.
28802 If it is valid non-empty DWARF expression,
28803 return copy of EXPR with DW_OP_deref appended to it.
28804 If it is DWARF expression followed by DW_OP_reg{N,x}, return
28805 copy of the DWARF expression with DW_OP_breg{N,x} <0> appended.
28806 If it is DWARF expression followed by DW_OP_stack_value, return
28807 copy of the DWARF expression without anything appended.
28808 Otherwise, return NULL. */
28810 static dw_loc_descr_ref
28811 copy_deref_exprloc (dw_loc_descr_ref expr
)
28813 dw_loc_descr_ref tail
= NULL
;
28818 dw_loc_descr_ref l
= non_dwarf_expression (expr
);
28819 if (l
&& l
->dw_loc_next
)
28824 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
28825 tail
= new_loc_descr ((enum dwarf_location_atom
)
28826 (DW_OP_breg0
+ (l
->dw_loc_opc
- DW_OP_reg0
)),
28829 switch (l
->dw_loc_opc
)
28832 tail
= new_loc_descr (DW_OP_bregx
,
28833 l
->dw_loc_oprnd1
.v
.val_unsigned
, 0);
28835 case DW_OP_stack_value
:
28842 tail
= new_loc_descr (DW_OP_deref
, 0, 0);
28844 dw_loc_descr_ref ret
= NULL
, *p
= &ret
;
28847 *p
= new_loc_descr (expr
->dw_loc_opc
, 0, 0);
28848 (*p
)->dw_loc_oprnd1
= expr
->dw_loc_oprnd1
;
28849 (*p
)->dw_loc_oprnd2
= expr
->dw_loc_oprnd2
;
28850 p
= &(*p
)->dw_loc_next
;
28851 expr
= expr
->dw_loc_next
;
28857 /* For DW_AT_string_length attribute with DW_OP_GNU_variable_value
28858 reference to a variable or argument, adjust it if needed and return:
28859 -1 if the DW_AT_string_length attribute and DW_AT_{string_length_,}byte_size
28860 attribute if present should be removed
28861 0 keep the attribute perhaps with minor modifications, no need to rescan
28862 1 if the attribute has been successfully adjusted. */
28865 optimize_string_length (dw_attr_node
*a
)
28867 dw_loc_descr_ref l
= AT_loc (a
), lv
;
28869 if (l
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
28871 tree decl
= l
->dw_loc_oprnd1
.v
.val_decl_ref
;
28872 die
= lookup_decl_die (decl
);
28875 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28876 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= die
;
28877 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28883 die
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28885 /* DWARF5 allows reference class, so we can then reference the DIE.
28886 Only do this for DW_OP_GNU_variable_value DW_OP_stack_value. */
28887 if (l
->dw_loc_next
!= NULL
&& dwarf_version
>= 5)
28889 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
28890 a
->dw_attr_val
.val_entry
= NULL
;
28891 a
->dw_attr_val
.v
.val_die_ref
.die
= die
;
28892 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
28896 dw_attr_node
*av
= get_AT (die
, DW_AT_location
);
28898 bool non_dwarf_expr
= false;
28901 return dwarf_strict
? -1 : 0;
28902 switch (AT_class (av
))
28904 case dw_val_class_loc_list
:
28905 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
28906 if (d
->expr
&& non_dwarf_expression (d
->expr
))
28907 non_dwarf_expr
= true;
28909 case dw_val_class_loc
:
28912 return dwarf_strict
? -1 : 0;
28913 if (non_dwarf_expression (lv
))
28914 non_dwarf_expr
= true;
28917 return dwarf_strict
? -1 : 0;
28920 /* If it is safe to transform DW_OP_GNU_variable_value DW_OP_stack_value
28921 into DW_OP_call4 or DW_OP_GNU_variable_value into
28922 DW_OP_call4 DW_OP_deref, do so. */
28923 if (!non_dwarf_expr
28924 && (l
->dw_loc_next
!= NULL
|| AT_class (av
) == dw_val_class_loc
))
28926 l
->dw_loc_opc
= DW_OP_call4
;
28927 if (l
->dw_loc_next
)
28928 l
->dw_loc_next
= NULL
;
28930 l
->dw_loc_next
= new_loc_descr (DW_OP_deref
, 0, 0);
28934 /* For DW_OP_GNU_variable_value DW_OP_stack_value, we can just
28935 copy over the DW_AT_location attribute from die to a. */
28936 if (l
->dw_loc_next
!= NULL
)
28938 a
->dw_attr_val
= av
->dw_attr_val
;
28942 dw_loc_list_ref list
, *p
;
28943 switch (AT_class (av
))
28945 case dw_val_class_loc_list
:
28948 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
28950 lv
= copy_deref_exprloc (d
->expr
);
28953 *p
= new_loc_list (lv
, d
->begin
, d
->end
, d
->section
);
28954 p
= &(*p
)->dw_loc_next
;
28956 else if (!dwarf_strict
&& d
->expr
)
28960 return dwarf_strict
? -1 : 0;
28961 a
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
28963 *AT_loc_list_ptr (a
) = list
;
28965 case dw_val_class_loc
:
28966 lv
= copy_deref_exprloc (AT_loc (av
));
28968 return dwarf_strict
? -1 : 0;
28969 a
->dw_attr_val
.v
.val_loc
= lv
;
28972 gcc_unreachable ();
28976 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
28977 an address in .rodata section if the string literal is emitted there,
28978 or remove the containing location list or replace DW_AT_const_value
28979 with DW_AT_location and empty location expression, if it isn't found
28980 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
28981 to something that has been emitted in the current CU. */
28984 resolve_addr (dw_die_ref die
)
28988 dw_loc_list_ref
*curr
, *start
, loc
;
28990 bool remove_AT_byte_size
= false;
28992 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
28993 switch (AT_class (a
))
28995 case dw_val_class_loc_list
:
28996 start
= curr
= AT_loc_list_ptr (a
);
28999 /* The same list can be referenced more than once. See if we have
29000 already recorded the result from a previous pass. */
29002 *curr
= loc
->dw_loc_next
;
29003 else if (!loc
->resolved_addr
)
29005 /* As things stand, we do not expect or allow one die to
29006 reference a suffix of another die's location list chain.
29007 References must be identical or completely separate.
29008 There is therefore no need to cache the result of this
29009 pass on any list other than the first; doing so
29010 would lead to unnecessary writes. */
29013 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
29014 if (!resolve_addr_in_expr (a
, (*curr
)->expr
))
29016 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
29017 dw_loc_descr_ref l
= (*curr
)->expr
;
29019 if (next
&& (*curr
)->ll_symbol
)
29021 gcc_assert (!next
->ll_symbol
);
29022 next
->ll_symbol
= (*curr
)->ll_symbol
;
29024 if (dwarf_split_debug_info
)
29025 remove_loc_list_addr_table_entries (l
);
29030 mark_base_types ((*curr
)->expr
);
29031 curr
= &(*curr
)->dw_loc_next
;
29035 loc
->resolved_addr
= 1;
29039 loc
->dw_loc_next
= *start
;
29044 remove_AT (die
, a
->dw_attr
);
29048 case dw_val_class_loc
:
29050 dw_loc_descr_ref l
= AT_loc (a
);
29051 /* DW_OP_GNU_variable_value DW_OP_stack_value or
29052 DW_OP_GNU_variable_value in DW_AT_string_length can be converted
29053 into DW_OP_call4 or DW_OP_call4 DW_OP_deref, which is standard
29054 DWARF4 unlike DW_OP_GNU_variable_value. Or for DWARF5
29055 DW_OP_GNU_variable_value DW_OP_stack_value can be replaced
29056 with DW_FORM_ref referencing the same DIE as
29057 DW_OP_GNU_variable_value used to reference. */
29058 if (a
->dw_attr
== DW_AT_string_length
29060 && l
->dw_loc_opc
== DW_OP_GNU_variable_value
29061 && (l
->dw_loc_next
== NULL
29062 || (l
->dw_loc_next
->dw_loc_next
== NULL
29063 && l
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
)))
29065 switch (optimize_string_length (a
))
29068 remove_AT (die
, a
->dw_attr
);
29070 /* If we drop DW_AT_string_length, we need to drop also
29071 DW_AT_{string_length_,}byte_size. */
29072 remove_AT_byte_size
= true;
29077 /* Even if we keep the optimized DW_AT_string_length,
29078 it might have changed AT_class, so process it again. */
29083 /* For -gdwarf-2 don't attempt to optimize
29084 DW_AT_data_member_location containing
29085 DW_OP_plus_uconst - older consumers might
29086 rely on it being that op instead of a more complex,
29087 but shorter, location description. */
29088 if ((dwarf_version
> 2
29089 || a
->dw_attr
!= DW_AT_data_member_location
29091 || l
->dw_loc_opc
!= DW_OP_plus_uconst
29092 || l
->dw_loc_next
!= NULL
)
29093 && !resolve_addr_in_expr (a
, l
))
29095 if (dwarf_split_debug_info
)
29096 remove_loc_list_addr_table_entries (l
);
29098 && l
->dw_loc_next
== NULL
29099 && l
->dw_loc_opc
== DW_OP_addr
29100 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
29101 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
29102 && a
->dw_attr
== DW_AT_location
)
29104 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
29105 remove_AT (die
, a
->dw_attr
);
29107 optimize_location_into_implicit_ptr (die
, decl
);
29110 if (a
->dw_attr
== DW_AT_string_length
)
29111 /* If we drop DW_AT_string_length, we need to drop also
29112 DW_AT_{string_length_,}byte_size. */
29113 remove_AT_byte_size
= true;
29114 remove_AT (die
, a
->dw_attr
);
29118 mark_base_types (l
);
29121 case dw_val_class_addr
:
29122 if (a
->dw_attr
== DW_AT_const_value
29123 && !resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
))
29125 if (AT_index (a
) != NOT_INDEXED
)
29126 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
29127 remove_AT (die
, a
->dw_attr
);
29130 if ((die
->die_tag
== DW_TAG_call_site
29131 && a
->dw_attr
== DW_AT_call_origin
)
29132 || (die
->die_tag
== DW_TAG_GNU_call_site
29133 && a
->dw_attr
== DW_AT_abstract_origin
))
29135 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
29136 dw_die_ref tdie
= lookup_decl_die (tdecl
);
29139 && DECL_EXTERNAL (tdecl
)
29140 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
29141 && (cdie
= lookup_context_die (DECL_CONTEXT (tdecl
))))
29143 dw_die_ref pdie
= cdie
;
29144 /* Make sure we don't add these DIEs into type units.
29145 We could emit skeleton DIEs for context (namespaces,
29146 outer structs/classes) and a skeleton DIE for the
29147 innermost context with DW_AT_signature pointing to the
29148 type unit. See PR78835. */
29149 while (pdie
&& pdie
->die_tag
!= DW_TAG_type_unit
)
29150 pdie
= pdie
->die_parent
;
29153 /* Creating a full DIE for tdecl is overly expensive and
29154 at this point even wrong when in the LTO phase
29155 as it can end up generating new type DIEs we didn't
29156 output and thus optimize_external_refs will crash. */
29157 tdie
= new_die (DW_TAG_subprogram
, cdie
, NULL_TREE
);
29158 add_AT_flag (tdie
, DW_AT_external
, 1);
29159 add_AT_flag (tdie
, DW_AT_declaration
, 1);
29160 add_linkage_attr (tdie
, tdecl
);
29161 add_name_and_src_coords_attributes (tdie
, tdecl
, true);
29162 equate_decl_number_to_die (tdecl
, tdie
);
29167 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
29168 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
29169 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
29173 if (AT_index (a
) != NOT_INDEXED
)
29174 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
29175 remove_AT (die
, a
->dw_attr
);
29184 if (remove_AT_byte_size
)
29185 remove_AT (die
, dwarf_version
>= 5
29186 ? DW_AT_string_length_byte_size
29187 : DW_AT_byte_size
);
29189 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
29192 /* Helper routines for optimize_location_lists.
29193 This pass tries to share identical local lists in .debug_loc
29196 /* Iteratively hash operands of LOC opcode into HSTATE. */
29199 hash_loc_operands (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
29201 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
29202 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
29204 switch (loc
->dw_loc_opc
)
29206 case DW_OP_const4u
:
29207 case DW_OP_const8u
:
29211 case DW_OP_const1u
:
29212 case DW_OP_const1s
:
29213 case DW_OP_const2u
:
29214 case DW_OP_const2s
:
29215 case DW_OP_const4s
:
29216 case DW_OP_const8s
:
29220 case DW_OP_plus_uconst
:
29256 case DW_OP_deref_size
:
29257 case DW_OP_xderef_size
:
29258 hstate
.add_object (val1
->v
.val_int
);
29265 gcc_assert (val1
->val_class
== dw_val_class_loc
);
29266 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
29267 hstate
.add_object (offset
);
29270 case DW_OP_implicit_value
:
29271 hstate
.add_object (val1
->v
.val_unsigned
);
29272 switch (val2
->val_class
)
29274 case dw_val_class_const
:
29275 hstate
.add_object (val2
->v
.val_int
);
29277 case dw_val_class_vec
:
29279 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
29280 unsigned int len
= val2
->v
.val_vec
.length
;
29282 hstate
.add_int (elt_size
);
29283 hstate
.add_int (len
);
29284 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
29287 case dw_val_class_const_double
:
29288 hstate
.add_object (val2
->v
.val_double
.low
);
29289 hstate
.add_object (val2
->v
.val_double
.high
);
29291 case dw_val_class_wide_int
:
29292 hstate
.add (val2
->v
.val_wide
->get_val (),
29293 get_full_len (*val2
->v
.val_wide
)
29294 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
29296 case dw_val_class_addr
:
29297 inchash::add_rtx (val2
->v
.val_addr
, hstate
);
29300 gcc_unreachable ();
29304 case DW_OP_bit_piece
:
29305 hstate
.add_object (val1
->v
.val_int
);
29306 hstate
.add_object (val2
->v
.val_int
);
29312 unsigned char dtprel
= 0xd1;
29313 hstate
.add_object (dtprel
);
29315 inchash::add_rtx (val1
->v
.val_addr
, hstate
);
29317 case DW_OP_GNU_addr_index
:
29318 case DW_OP_GNU_const_index
:
29322 unsigned char dtprel
= 0xd1;
29323 hstate
.add_object (dtprel
);
29325 inchash::add_rtx (val1
->val_entry
->addr
.rtl
, hstate
);
29328 case DW_OP_implicit_pointer
:
29329 case DW_OP_GNU_implicit_pointer
:
29330 hstate
.add_int (val2
->v
.val_int
);
29332 case DW_OP_entry_value
:
29333 case DW_OP_GNU_entry_value
:
29334 hstate
.add_object (val1
->v
.val_loc
);
29336 case DW_OP_regval_type
:
29337 case DW_OP_deref_type
:
29338 case DW_OP_GNU_regval_type
:
29339 case DW_OP_GNU_deref_type
:
29341 unsigned int byte_size
29342 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
29343 unsigned int encoding
29344 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
29345 hstate
.add_object (val1
->v
.val_int
);
29346 hstate
.add_object (byte_size
);
29347 hstate
.add_object (encoding
);
29350 case DW_OP_convert
:
29351 case DW_OP_reinterpret
:
29352 case DW_OP_GNU_convert
:
29353 case DW_OP_GNU_reinterpret
:
29354 if (val1
->val_class
== dw_val_class_unsigned_const
)
29356 hstate
.add_object (val1
->v
.val_unsigned
);
29360 case DW_OP_const_type
:
29361 case DW_OP_GNU_const_type
:
29363 unsigned int byte_size
29364 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
29365 unsigned int encoding
29366 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
29367 hstate
.add_object (byte_size
);
29368 hstate
.add_object (encoding
);
29369 if (loc
->dw_loc_opc
!= DW_OP_const_type
29370 && loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
29372 hstate
.add_object (val2
->val_class
);
29373 switch (val2
->val_class
)
29375 case dw_val_class_const
:
29376 hstate
.add_object (val2
->v
.val_int
);
29378 case dw_val_class_vec
:
29380 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
29381 unsigned int len
= val2
->v
.val_vec
.length
;
29383 hstate
.add_object (elt_size
);
29384 hstate
.add_object (len
);
29385 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
29388 case dw_val_class_const_double
:
29389 hstate
.add_object (val2
->v
.val_double
.low
);
29390 hstate
.add_object (val2
->v
.val_double
.high
);
29392 case dw_val_class_wide_int
:
29393 hstate
.add (val2
->v
.val_wide
->get_val (),
29394 get_full_len (*val2
->v
.val_wide
)
29395 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
29398 gcc_unreachable ();
29404 /* Other codes have no operands. */
29409 /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
29412 hash_locs (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
29414 dw_loc_descr_ref l
;
29415 bool sizes_computed
= false;
29416 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
29417 size_of_locs (loc
);
29419 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
29421 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
29422 hstate
.add_object (opc
);
29423 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
29425 size_of_locs (loc
);
29426 sizes_computed
= true;
29428 hash_loc_operands (l
, hstate
);
29432 /* Compute hash of the whole location list LIST_HEAD. */
29435 hash_loc_list (dw_loc_list_ref list_head
)
29437 dw_loc_list_ref curr
= list_head
;
29438 inchash::hash hstate
;
29440 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
29442 hstate
.add (curr
->begin
, strlen (curr
->begin
) + 1);
29443 hstate
.add (curr
->end
, strlen (curr
->end
) + 1);
29445 hstate
.add (curr
->section
, strlen (curr
->section
) + 1);
29446 hash_locs (curr
->expr
, hstate
);
29448 list_head
->hash
= hstate
.end ();
29451 /* Return true if X and Y opcodes have the same operands. */
29454 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
29456 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
29457 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
29458 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
29459 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
29461 switch (x
->dw_loc_opc
)
29463 case DW_OP_const4u
:
29464 case DW_OP_const8u
:
29468 case DW_OP_const1u
:
29469 case DW_OP_const1s
:
29470 case DW_OP_const2u
:
29471 case DW_OP_const2s
:
29472 case DW_OP_const4s
:
29473 case DW_OP_const8s
:
29477 case DW_OP_plus_uconst
:
29513 case DW_OP_deref_size
:
29514 case DW_OP_xderef_size
:
29515 return valx1
->v
.val_int
== valy1
->v
.val_int
;
29518 /* If splitting debug info, the use of DW_OP_GNU_addr_index
29519 can cause irrelevant differences in dw_loc_addr. */
29520 gcc_assert (valx1
->val_class
== dw_val_class_loc
29521 && valy1
->val_class
== dw_val_class_loc
29522 && (dwarf_split_debug_info
29523 || x
->dw_loc_addr
== y
->dw_loc_addr
));
29524 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
29525 case DW_OP_implicit_value
:
29526 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
29527 || valx2
->val_class
!= valy2
->val_class
)
29529 switch (valx2
->val_class
)
29531 case dw_val_class_const
:
29532 return valx2
->v
.val_int
== valy2
->v
.val_int
;
29533 case dw_val_class_vec
:
29534 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
29535 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
29536 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
29537 valx2
->v
.val_vec
.elt_size
29538 * valx2
->v
.val_vec
.length
) == 0;
29539 case dw_val_class_const_double
:
29540 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
29541 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
29542 case dw_val_class_wide_int
:
29543 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
29544 case dw_val_class_addr
:
29545 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
29547 gcc_unreachable ();
29550 case DW_OP_bit_piece
:
29551 return valx1
->v
.val_int
== valy1
->v
.val_int
29552 && valx2
->v
.val_int
== valy2
->v
.val_int
;
29555 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
29556 case DW_OP_GNU_addr_index
:
29557 case DW_OP_GNU_const_index
:
29559 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
29560 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
29561 return rtx_equal_p (ax1
, ay1
);
29563 case DW_OP_implicit_pointer
:
29564 case DW_OP_GNU_implicit_pointer
:
29565 return valx1
->val_class
== dw_val_class_die_ref
29566 && valx1
->val_class
== valy1
->val_class
29567 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
29568 && valx2
->v
.val_int
== valy2
->v
.val_int
;
29569 case DW_OP_entry_value
:
29570 case DW_OP_GNU_entry_value
:
29571 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
29572 case DW_OP_const_type
:
29573 case DW_OP_GNU_const_type
:
29574 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
29575 || valx2
->val_class
!= valy2
->val_class
)
29577 switch (valx2
->val_class
)
29579 case dw_val_class_const
:
29580 return valx2
->v
.val_int
== valy2
->v
.val_int
;
29581 case dw_val_class_vec
:
29582 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
29583 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
29584 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
29585 valx2
->v
.val_vec
.elt_size
29586 * valx2
->v
.val_vec
.length
) == 0;
29587 case dw_val_class_const_double
:
29588 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
29589 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
29590 case dw_val_class_wide_int
:
29591 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
29593 gcc_unreachable ();
29595 case DW_OP_regval_type
:
29596 case DW_OP_deref_type
:
29597 case DW_OP_GNU_regval_type
:
29598 case DW_OP_GNU_deref_type
:
29599 return valx1
->v
.val_int
== valy1
->v
.val_int
29600 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
29601 case DW_OP_convert
:
29602 case DW_OP_reinterpret
:
29603 case DW_OP_GNU_convert
:
29604 case DW_OP_GNU_reinterpret
:
29605 if (valx1
->val_class
!= valy1
->val_class
)
29607 if (valx1
->val_class
== dw_val_class_unsigned_const
)
29608 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
29609 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
29610 case DW_OP_GNU_parameter_ref
:
29611 return valx1
->val_class
== dw_val_class_die_ref
29612 && valx1
->val_class
== valy1
->val_class
29613 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
29615 /* Other codes have no operands. */
29620 /* Return true if DWARF location expressions X and Y are the same. */
29623 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
29625 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
29626 if (x
->dw_loc_opc
!= y
->dw_loc_opc
29627 || x
->dtprel
!= y
->dtprel
29628 || !compare_loc_operands (x
, y
))
29630 return x
== NULL
&& y
== NULL
;
29633 /* Hashtable helpers. */
29635 struct loc_list_hasher
: nofree_ptr_hash
<dw_loc_list_struct
>
29637 static inline hashval_t
hash (const dw_loc_list_struct
*);
29638 static inline bool equal (const dw_loc_list_struct
*,
29639 const dw_loc_list_struct
*);
29642 /* Return precomputed hash of location list X. */
29645 loc_list_hasher::hash (const dw_loc_list_struct
*x
)
29650 /* Return true if location lists A and B are the same. */
29653 loc_list_hasher::equal (const dw_loc_list_struct
*a
,
29654 const dw_loc_list_struct
*b
)
29658 if (a
->hash
!= b
->hash
)
29660 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
29661 if (strcmp (a
->begin
, b
->begin
) != 0
29662 || strcmp (a
->end
, b
->end
) != 0
29663 || (a
->section
== NULL
) != (b
->section
== NULL
)
29664 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
29665 || !compare_locs (a
->expr
, b
->expr
))
29667 return a
== NULL
&& b
== NULL
;
29670 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
29673 /* Recursively optimize location lists referenced from DIE
29674 children and share them whenever possible. */
29677 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type
*htab
)
29682 dw_loc_list_struct
**slot
;
29684 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
29685 if (AT_class (a
) == dw_val_class_loc_list
)
29687 dw_loc_list_ref list
= AT_loc_list (a
);
29688 /* TODO: perform some optimizations here, before hashing
29689 it and storing into the hash table. */
29690 hash_loc_list (list
);
29691 slot
= htab
->find_slot_with_hash (list
, list
->hash
, INSERT
);
29695 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
29698 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
29702 /* Recursively assign each location list a unique index into the debug_addr
29706 index_location_lists (dw_die_ref die
)
29712 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
29713 if (AT_class (a
) == dw_val_class_loc_list
)
29715 dw_loc_list_ref list
= AT_loc_list (a
);
29716 dw_loc_list_ref curr
;
29717 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
29719 /* Don't index an entry that has already been indexed
29720 or won't be output. */
29721 if (curr
->begin_entry
!= NULL
29722 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
29726 = add_addr_table_entry (xstrdup (curr
->begin
), ate_kind_label
);
29730 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
29733 /* Optimize location lists referenced from DIE
29734 children and share them whenever possible. */
29737 optimize_location_lists (dw_die_ref die
)
29739 loc_list_hash_type
htab (500);
29740 optimize_location_lists_1 (die
, &htab
);
29743 /* Traverse the limbo die list, and add parent/child links. The only
29744 dies without parents that should be here are concrete instances of
29745 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
29746 For concrete instances, we can get the parent die from the abstract
29750 flush_limbo_die_list (void)
29752 limbo_die_node
*node
;
29754 /* get_context_die calls force_decl_die, which can put new DIEs on the
29755 limbo list in LTO mode when nested functions are put in a different
29756 partition than that of their parent function. */
29757 while ((node
= limbo_die_list
))
29759 dw_die_ref die
= node
->die
;
29760 limbo_die_list
= node
->next
;
29762 if (die
->die_parent
== NULL
)
29764 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
29766 if (origin
&& origin
->die_parent
)
29767 add_child_die (origin
->die_parent
, die
);
29768 else if (is_cu_die (die
))
29770 else if (seen_error ())
29771 /* It's OK to be confused by errors in the input. */
29772 add_child_die (comp_unit_die (), die
);
29775 /* In certain situations, the lexical block containing a
29776 nested function can be optimized away, which results
29777 in the nested function die being orphaned. Likewise
29778 with the return type of that nested function. Force
29779 this to be a child of the containing function.
29781 It may happen that even the containing function got fully
29782 inlined and optimized out. In that case we are lost and
29783 assign the empty child. This should not be big issue as
29784 the function is likely unreachable too. */
29785 gcc_assert (node
->created_for
);
29787 if (DECL_P (node
->created_for
))
29788 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
29789 else if (TYPE_P (node
->created_for
))
29790 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
29792 origin
= comp_unit_die ();
29794 add_child_die (origin
, die
);
29800 /* Reset DIEs so we can output them again. */
29803 reset_dies (dw_die_ref die
)
29807 /* Remove stuff we re-generate. */
29809 die
->die_offset
= 0;
29810 die
->die_abbrev
= 0;
29811 remove_AT (die
, DW_AT_sibling
);
29813 FOR_EACH_CHILD (die
, c
, reset_dies (c
));
29816 /* Output stuff that dwarf requires at the end of every file,
29817 and generate the DWARF-2 debugging info. */
29820 dwarf2out_finish (const char *)
29822 comdat_type_node
*ctnode
;
29823 dw_die_ref main_comp_unit_die
;
29824 unsigned char checksum
[16];
29825 char dl_section_ref
[MAX_ARTIFICIAL_LABEL_BYTES
];
29827 /* Flush out any latecomers to the limbo party. */
29828 flush_limbo_die_list ();
29832 verify_die (comp_unit_die ());
29833 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
29834 verify_die (node
->die
);
29837 /* We shouldn't have any symbols with delayed asm names for
29838 DIEs generated after early finish. */
29839 gcc_assert (deferred_asm_name
== NULL
);
29841 gen_remaining_tmpl_value_param_die_attribute ();
29843 if (flag_generate_lto
|| flag_generate_offload
)
29845 gcc_assert (flag_fat_lto_objects
|| flag_generate_offload
);
29847 /* Prune stuff so that dwarf2out_finish runs successfully
29848 for the fat part of the object. */
29849 reset_dies (comp_unit_die ());
29850 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
29851 reset_dies (node
->die
);
29853 hash_table
<comdat_type_hasher
> comdat_type_table (100);
29854 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
29856 comdat_type_node
**slot
29857 = comdat_type_table
.find_slot (ctnode
, INSERT
);
29859 /* Don't reset types twice. */
29860 if (*slot
!= HTAB_EMPTY_ENTRY
)
29863 /* Add a pointer to the line table for the main compilation unit
29864 so that the debugger can make sense of DW_AT_decl_file
29866 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
29867 reset_dies (ctnode
->root_die
);
29872 /* Reset die CU symbol so we don't output it twice. */
29873 comp_unit_die ()->die_id
.die_symbol
= NULL
;
29875 /* Remove DW_AT_macro from the early output. */
29877 remove_AT (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE
);
29879 /* Remove indirect string decisions. */
29880 debug_str_hash
->traverse
<void *, reset_indirect_string
> (NULL
);
29883 #if ENABLE_ASSERT_CHECKING
29885 dw_die_ref die
= comp_unit_die (), c
;
29886 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
29889 resolve_addr (comp_unit_die ());
29890 move_marked_base_types ();
29892 /* Initialize sections and labels used for actual assembler output. */
29893 init_sections_and_labels (false);
29895 /* Traverse the DIE's and add sibling attributes to those DIE's that
29897 add_sibling_attributes (comp_unit_die ());
29898 limbo_die_node
*node
;
29899 for (node
= cu_die_list
; node
; node
= node
->next
)
29900 add_sibling_attributes (node
->die
);
29901 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
29902 add_sibling_attributes (ctnode
->root_die
);
29904 /* When splitting DWARF info, we put some attributes in the
29905 skeleton compile_unit DIE that remains in the .o, while
29906 most attributes go in the DWO compile_unit_die. */
29907 if (dwarf_split_debug_info
)
29909 limbo_die_node
*cu
;
29910 main_comp_unit_die
= gen_compile_unit_die (NULL
);
29911 if (dwarf_version
>= 5)
29912 main_comp_unit_die
->die_tag
= DW_TAG_skeleton_unit
;
29913 cu
= limbo_die_list
;
29914 gcc_assert (cu
->die
== main_comp_unit_die
);
29915 limbo_die_list
= limbo_die_list
->next
;
29916 cu
->next
= cu_die_list
;
29920 main_comp_unit_die
= comp_unit_die ();
29922 /* Output a terminator label for the .text section. */
29923 switch_to_section (text_section
);
29924 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
29925 if (cold_text_section
)
29927 switch_to_section (cold_text_section
);
29928 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
29931 /* We can only use the low/high_pc attributes if all of the code was
29933 if (!have_multiple_function_sections
29934 || (dwarf_version
< 3 && dwarf_strict
))
29936 /* Don't add if the CU has no associated code. */
29937 if (text_section_used
)
29938 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
29939 text_end_label
, true);
29945 bool range_list_added
= false;
29947 if (text_section_used
)
29948 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
29949 text_end_label
, &range_list_added
, true);
29950 if (cold_text_section_used
)
29951 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
29952 cold_end_label
, &range_list_added
, true);
29954 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
29956 if (DECL_IGNORED_P (fde
->decl
))
29958 if (!fde
->in_std_section
)
29959 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
29960 fde
->dw_fde_end
, &range_list_added
,
29962 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
29963 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
29964 fde
->dw_fde_second_end
, &range_list_added
,
29968 if (range_list_added
)
29970 /* We need to give .debug_loc and .debug_ranges an appropriate
29971 "base address". Use zero so that these addresses become
29972 absolute. Historically, we've emitted the unexpected
29973 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
29974 Emit both to give time for other tools to adapt. */
29975 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
29976 if (! dwarf_strict
&& dwarf_version
< 4)
29977 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
29983 /* AIX Assembler inserts the length, so adjust the reference to match the
29984 offset expected by debuggers. */
29985 strcpy (dl_section_ref
, debug_line_section_label
);
29986 if (XCOFF_DEBUGGING_INFO
)
29987 strcat (dl_section_ref
, DWARF_INITIAL_LENGTH_SIZE_STR
);
29989 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
29990 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
29994 add_AT_macptr (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE
,
29995 macinfo_section_label
);
29997 if (dwarf_split_debug_info
)
29999 if (have_location_lists
)
30001 if (dwarf_version
>= 5)
30002 add_AT_loclistsptr (comp_unit_die (), DW_AT_loclists_base
,
30003 loc_section_label
);
30004 /* optimize_location_lists calculates the size of the lists,
30005 so index them first, and assign indices to the entries.
30006 Although optimize_location_lists will remove entries from
30007 the table, it only does so for duplicates, and therefore
30008 only reduces ref_counts to 1. */
30009 index_location_lists (comp_unit_die ());
30012 if (addr_index_table
!= NULL
)
30014 unsigned int index
= 0;
30016 ->traverse_noresize
<unsigned int *, index_addr_table_entry
>
30022 if (have_location_lists
)
30024 optimize_location_lists (comp_unit_die ());
30025 /* And finally assign indexes to the entries for -gsplit-dwarf. */
30026 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
30027 assign_location_list_indexes (comp_unit_die ());
30030 save_macinfo_strings ();
30032 if (dwarf_split_debug_info
)
30034 unsigned int index
= 0;
30036 /* Add attributes common to skeleton compile_units and
30037 type_units. Because these attributes include strings, it
30038 must be done before freezing the string table. Top-level
30039 skeleton die attrs are added when the skeleton type unit is
30040 created, so ensure it is created by this point. */
30041 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
30042 debug_str_hash
->traverse_noresize
<unsigned int *, index_string
> (&index
);
30045 /* Output all of the compilation units. We put the main one last so that
30046 the offsets are available to output_pubnames. */
30047 for (node
= cu_die_list
; node
; node
= node
->next
)
30048 output_comp_unit (node
->die
, 0, NULL
);
30050 hash_table
<comdat_type_hasher
> comdat_type_table (100);
30051 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
30053 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
30055 /* Don't output duplicate types. */
30056 if (*slot
!= HTAB_EMPTY_ENTRY
)
30059 /* Add a pointer to the line table for the main compilation unit
30060 so that the debugger can make sense of DW_AT_decl_file
30062 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
30063 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
30064 (!dwarf_split_debug_info
30066 : debug_skeleton_line_section_label
));
30068 output_comdat_type_unit (ctnode
);
30072 if (dwarf_split_debug_info
)
30075 struct md5_ctx ctx
;
30077 if (dwarf_version
>= 5 && !vec_safe_is_empty (ranges_table
))
30080 /* Compute a checksum of the comp_unit to use as the dwo_id. */
30081 md5_init_ctx (&ctx
);
30083 die_checksum (comp_unit_die (), &ctx
, &mark
);
30084 unmark_all_dies (comp_unit_die ());
30085 md5_finish_ctx (&ctx
, checksum
);
30087 if (dwarf_version
< 5)
30089 /* Use the first 8 bytes of the checksum as the dwo_id,
30090 and add it to both comp-unit DIEs. */
30091 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
30092 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
30095 /* Add the base offset of the ranges table to the skeleton
30097 if (!vec_safe_is_empty (ranges_table
))
30099 if (dwarf_version
>= 5)
30100 add_AT_lineptr (main_comp_unit_die
, DW_AT_rnglists_base
,
30101 ranges_base_label
);
30103 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
30104 ranges_section_label
);
30107 switch_to_section (debug_addr_section
);
30108 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
30109 output_addr_table ();
30112 /* Output the main compilation unit if non-empty or if .debug_macinfo
30113 or .debug_macro will be emitted. */
30114 output_comp_unit (comp_unit_die (), have_macinfo
,
30115 dwarf_split_debug_info
? checksum
: NULL
);
30117 if (dwarf_split_debug_info
&& info_section_emitted
)
30118 output_skeleton_debug_sections (main_comp_unit_die
, checksum
);
30120 /* Output the abbreviation table. */
30121 if (vec_safe_length (abbrev_die_table
) != 1)
30123 switch_to_section (debug_abbrev_section
);
30124 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
30125 output_abbrev_section ();
30128 /* Output location list section if necessary. */
30129 if (have_location_lists
)
30131 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
30132 char l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
30133 /* Output the location lists info. */
30134 switch_to_section (debug_loc_section
);
30135 if (dwarf_version
>= 5)
30137 ASM_GENERATE_INTERNAL_LABEL (l1
, DEBUG_LOC_SECTION_LABEL
, 1);
30138 ASM_GENERATE_INTERNAL_LABEL (l2
, DEBUG_LOC_SECTION_LABEL
, 2);
30139 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
30140 dw2_asm_output_data (4, 0xffffffff,
30141 "Initial length escape value indicating "
30142 "64-bit DWARF extension");
30143 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
30144 "Length of Location Lists");
30145 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
30146 dw2_asm_output_data (2, dwarf_version
, "DWARF Version");
30147 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
30148 dw2_asm_output_data (1, 0, "Segment Size");
30149 dw2_asm_output_data (4, dwarf_split_debug_info
? loc_list_idx
: 0,
30150 "Offset Entry Count");
30152 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
30153 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
30155 unsigned int save_loc_list_idx
= loc_list_idx
;
30157 output_loclists_offsets (comp_unit_die ());
30158 gcc_assert (save_loc_list_idx
== loc_list_idx
);
30160 output_location_lists (comp_unit_die ());
30161 if (dwarf_version
>= 5)
30162 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
30165 output_pubtables ();
30167 /* Output the address range information if a CU (.debug_info section)
30168 was emitted. We output an empty table even if we had no functions
30169 to put in it. This because the consumer has no way to tell the
30170 difference between an empty table that we omitted and failure to
30171 generate a table that would have contained data. */
30172 if (info_section_emitted
)
30174 switch_to_section (debug_aranges_section
);
30178 /* Output ranges section if necessary. */
30179 if (!vec_safe_is_empty (ranges_table
))
30181 if (dwarf_version
>= 5)
30182 output_rnglists ();
30187 /* Have to end the macro section. */
30190 switch_to_section (debug_macinfo_section
);
30191 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
30192 output_macinfo (!dwarf_split_debug_info
? debug_line_section_label
30193 : debug_skeleton_line_section_label
, false);
30194 dw2_asm_output_data (1, 0, "End compilation unit");
30197 /* Output the source line correspondence table. We must do this
30198 even if there is no line information. Otherwise, on an empty
30199 translation unit, we will generate a present, but empty,
30200 .debug_info section. IRIX 6.5 `nm' will then complain when
30201 examining the file. This is done late so that any filenames
30202 used by the debug_info section are marked as 'used'. */
30203 switch_to_section (debug_line_section
);
30204 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
30205 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
30206 output_line_info (false);
30208 if (dwarf_split_debug_info
&& info_section_emitted
)
30210 switch_to_section (debug_skeleton_line_section
);
30211 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
30212 output_line_info (true);
30215 /* If we emitted any indirect strings, output the string table too. */
30216 if (debug_str_hash
|| skeleton_debug_str_hash
)
30217 output_indirect_strings ();
30218 if (debug_line_str_hash
)
30220 switch_to_section (debug_line_str_section
);
30221 const enum dwarf_form form
= DW_FORM_line_strp
;
30222 debug_line_str_hash
->traverse
<enum dwarf_form
,
30223 output_indirect_string
> (form
);
30227 /* Returns a hash value for X (which really is a variable_value_struct). */
30230 variable_value_hasher::hash (variable_value_struct
*x
)
30232 return (hashval_t
) x
->decl_id
;
30235 /* Return nonzero if decl_id of variable_value_struct X is the same as
30239 variable_value_hasher::equal (variable_value_struct
*x
, tree y
)
30241 return x
->decl_id
== DECL_UID (y
);
30244 /* Helper function for resolve_variable_value, handle
30245 DW_OP_GNU_variable_value in one location expression.
30246 Return true if exprloc has been changed into loclist. */
30249 resolve_variable_value_in_expr (dw_attr_node
*a
, dw_loc_descr_ref loc
)
30251 dw_loc_descr_ref next
;
30252 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= next
)
30254 next
= loc
->dw_loc_next
;
30255 if (loc
->dw_loc_opc
!= DW_OP_GNU_variable_value
30256 || loc
->dw_loc_oprnd1
.val_class
!= dw_val_class_decl_ref
)
30259 tree decl
= loc
->dw_loc_oprnd1
.v
.val_decl_ref
;
30260 if (DECL_CONTEXT (decl
) != current_function_decl
)
30263 dw_die_ref ref
= lookup_decl_die (decl
);
30266 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
30267 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
30268 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
30271 dw_loc_list_ref l
= loc_list_from_tree (decl
, 0, NULL
);
30274 if (l
->dw_loc_next
)
30276 if (AT_class (a
) != dw_val_class_loc
)
30278 switch (a
->dw_attr
)
30280 /* Following attributes allow both exprloc and loclist
30281 classes, so we can change them into a loclist. */
30282 case DW_AT_location
:
30283 case DW_AT_string_length
:
30284 case DW_AT_return_addr
:
30285 case DW_AT_data_member_location
:
30286 case DW_AT_frame_base
:
30287 case DW_AT_segment
:
30288 case DW_AT_static_link
:
30289 case DW_AT_use_location
:
30290 case DW_AT_vtable_elem_location
:
30293 prev
->dw_loc_next
= NULL
;
30294 prepend_loc_descr_to_each (l
, AT_loc (a
));
30297 add_loc_descr_to_each (l
, next
);
30298 a
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
30299 a
->dw_attr_val
.val_entry
= NULL
;
30300 a
->dw_attr_val
.v
.val_loc_list
= l
;
30301 have_location_lists
= true;
30303 /* Following attributes allow both exprloc and reference,
30304 so if the whole expression is DW_OP_GNU_variable_value alone
30305 we could transform it into reference. */
30306 case DW_AT_byte_size
:
30307 case DW_AT_bit_size
:
30308 case DW_AT_lower_bound
:
30309 case DW_AT_upper_bound
:
30310 case DW_AT_bit_stride
:
30312 case DW_AT_allocated
:
30313 case DW_AT_associated
:
30314 case DW_AT_byte_stride
:
30315 if (prev
== NULL
&& next
== NULL
)
30323 /* Create DW_TAG_variable that we can refer to. */
30324 gen_decl_die (decl
, NULL_TREE
, NULL
,
30325 lookup_decl_die (current_function_decl
));
30326 ref
= lookup_decl_die (decl
);
30329 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
30330 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
30331 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
30337 prev
->dw_loc_next
= l
->expr
;
30338 add_loc_descr (&prev
->dw_loc_next
, next
);
30339 free_loc_descr (loc
, NULL
);
30340 next
= prev
->dw_loc_next
;
30344 memcpy (loc
, l
->expr
, sizeof (dw_loc_descr_node
));
30345 add_loc_descr (&loc
, next
);
30353 /* Attempt to resolve DW_OP_GNU_variable_value using loc_list_from_tree. */
30356 resolve_variable_value (dw_die_ref die
)
30359 dw_loc_list_ref loc
;
30362 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
30363 switch (AT_class (a
))
30365 case dw_val_class_loc
:
30366 if (!resolve_variable_value_in_expr (a
, AT_loc (a
)))
30369 case dw_val_class_loc_list
:
30370 loc
= AT_loc_list (a
);
30372 for (; loc
; loc
= loc
->dw_loc_next
)
30373 resolve_variable_value_in_expr (a
, loc
->expr
);
30380 /* Attempt to optimize DW_OP_GNU_variable_value refering to
30381 temporaries in the current function. */
30384 resolve_variable_values (void)
30386 if (!variable_value_hash
|| !current_function_decl
)
30389 struct variable_value_struct
*node
30390 = variable_value_hash
->find_with_hash (current_function_decl
,
30391 DECL_UID (current_function_decl
));
30398 FOR_EACH_VEC_SAFE_ELT (node
->dies
, i
, die
)
30399 resolve_variable_value (die
);
30402 /* Helper function for note_variable_value, handle one location
30406 note_variable_value_in_expr (dw_die_ref die
, dw_loc_descr_ref loc
)
30408 for (; loc
; loc
= loc
->dw_loc_next
)
30409 if (loc
->dw_loc_opc
== DW_OP_GNU_variable_value
30410 && loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
30412 tree decl
= loc
->dw_loc_oprnd1
.v
.val_decl_ref
;
30413 dw_die_ref ref
= lookup_decl_die (decl
);
30414 if (! ref
&& (flag_generate_lto
|| flag_generate_offload
))
30416 /* ??? This is somewhat a hack because we do not create DIEs
30417 for variables not in BLOCK trees early but when generating
30418 early LTO output we need the dw_val_class_decl_ref to be
30419 fully resolved. For fat LTO objects we'd also like to
30420 undo this after LTO dwarf output. */
30421 gcc_assert (DECL_CONTEXT (decl
));
30422 dw_die_ref ctx
= lookup_decl_die (DECL_CONTEXT (decl
));
30423 gcc_assert (ctx
!= NULL
);
30424 gen_decl_die (decl
, NULL_TREE
, NULL
, ctx
);
30425 ref
= lookup_decl_die (decl
);
30426 gcc_assert (ref
!= NULL
);
30430 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
30431 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
30432 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
30436 && DECL_CONTEXT (decl
)
30437 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
30438 && lookup_decl_die (DECL_CONTEXT (decl
)))
30440 if (!variable_value_hash
)
30441 variable_value_hash
30442 = hash_table
<variable_value_hasher
>::create_ggc (10);
30444 tree fndecl
= DECL_CONTEXT (decl
);
30445 struct variable_value_struct
*node
;
30446 struct variable_value_struct
**slot
30447 = variable_value_hash
->find_slot_with_hash (fndecl
,
30452 node
= ggc_cleared_alloc
<variable_value_struct
> ();
30453 node
->decl_id
= DECL_UID (fndecl
);
30459 vec_safe_push (node
->dies
, die
);
30464 /* Walk the tree DIE and note DIEs with DW_OP_GNU_variable_value still
30465 with dw_val_class_decl_ref operand. */
30468 note_variable_value (dw_die_ref die
)
30472 dw_loc_list_ref loc
;
30475 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
30476 switch (AT_class (a
))
30478 case dw_val_class_loc_list
:
30479 loc
= AT_loc_list (a
);
30481 if (!loc
->noted_variable_value
)
30483 loc
->noted_variable_value
= 1;
30484 for (; loc
; loc
= loc
->dw_loc_next
)
30485 note_variable_value_in_expr (die
, loc
->expr
);
30488 case dw_val_class_loc
:
30489 note_variable_value_in_expr (die
, AT_loc (a
));
30495 /* Mark children. */
30496 FOR_EACH_CHILD (die
, c
, note_variable_value (c
));
30499 /* Perform any cleanups needed after the early debug generation pass
30503 dwarf2out_early_finish (const char *filename
)
30507 /* PCH might result in DW_AT_producer string being restored from the
30508 header compilation, so always fill it with empty string initially
30509 and overwrite only here. */
30510 dw_attr_node
*producer
= get_AT (comp_unit_die (), DW_AT_producer
);
30511 producer_string
= gen_producer_string ();
30512 producer
->dw_attr_val
.v
.val_str
->refcount
--;
30513 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
30515 /* Add the name for the main input file now. We delayed this from
30516 dwarf2out_init to avoid complications with PCH. */
30517 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
30518 add_comp_dir_attribute (comp_unit_die ());
30520 /* When emitting DWARF5 .debug_line_str, move DW_AT_name and
30521 DW_AT_comp_dir into .debug_line_str section. */
30522 if (!DWARF2_ASM_LINE_DEBUG_INFO
30523 && dwarf_version
>= 5
30524 && DWARF5_USE_DEBUG_LINE_STR
)
30526 for (int i
= 0; i
< 2; i
++)
30528 dw_attr_node
*a
= get_AT (comp_unit_die (),
30529 i
? DW_AT_comp_dir
: DW_AT_name
);
30531 || AT_class (a
) != dw_val_class_str
30532 || strlen (AT_string (a
)) + 1 <= DWARF_OFFSET_SIZE
)
30535 if (! debug_line_str_hash
)
30536 debug_line_str_hash
30537 = hash_table
<indirect_string_hasher
>::create_ggc (10);
30539 struct indirect_string_node
*node
30540 = find_AT_string_in_table (AT_string (a
), debug_line_str_hash
);
30541 set_indirect_string (node
);
30542 node
->form
= DW_FORM_line_strp
;
30543 a
->dw_attr_val
.v
.val_str
->refcount
--;
30544 a
->dw_attr_val
.v
.val_str
= node
;
30548 /* With LTO early dwarf was really finished at compile-time, so make
30549 sure to adjust the phase after annotating the LTRANS CU DIE. */
30552 early_dwarf_finished
= true;
30556 /* Walk through the list of incomplete types again, trying once more to
30557 emit full debugging info for them. */
30558 retry_incomplete_types ();
30560 /* The point here is to flush out the limbo list so that it is empty
30561 and we don't need to stream it for LTO. */
30562 flush_limbo_die_list ();
30564 gen_scheduled_generic_parms_dies ();
30565 gen_remaining_tmpl_value_param_die_attribute ();
30567 /* Add DW_AT_linkage_name for all deferred DIEs. */
30568 for (limbo_die_node
*node
= deferred_asm_name
; node
; node
= node
->next
)
30570 tree decl
= node
->created_for
;
30571 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
30572 /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
30573 ended up in deferred_asm_name before we knew it was
30574 constant and never written to disk. */
30575 && DECL_ASSEMBLER_NAME (decl
))
30577 add_linkage_attr (node
->die
, decl
);
30578 move_linkage_attr (node
->die
);
30581 deferred_asm_name
= NULL
;
30583 if (flag_eliminate_unused_debug_types
)
30584 prune_unused_types ();
30586 /* Generate separate COMDAT sections for type DIEs. */
30587 if (use_debug_types
)
30589 break_out_comdat_types (comp_unit_die ());
30591 /* Each new type_unit DIE was added to the limbo die list when created.
30592 Since these have all been added to comdat_type_list, clear the
30594 limbo_die_list
= NULL
;
30596 /* For each new comdat type unit, copy declarations for incomplete
30597 types to make the new unit self-contained (i.e., no direct
30598 references to the main compile unit). */
30599 for (comdat_type_node
*ctnode
= comdat_type_list
;
30600 ctnode
!= NULL
; ctnode
= ctnode
->next
)
30601 copy_decls_for_unworthy_types (ctnode
->root_die
);
30602 copy_decls_for_unworthy_types (comp_unit_die ());
30604 /* In the process of copying declarations from one unit to another,
30605 we may have left some declarations behind that are no longer
30606 referenced. Prune them. */
30607 prune_unused_types ();
30610 /* Traverse the DIE's and note DIEs with DW_OP_GNU_variable_value still
30611 with dw_val_class_decl_ref operand. */
30612 note_variable_value (comp_unit_die ());
30613 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
30614 note_variable_value (node
->die
);
30615 for (comdat_type_node
*ctnode
= comdat_type_list
; ctnode
!= NULL
;
30616 ctnode
= ctnode
->next
)
30617 note_variable_value (ctnode
->root_die
);
30618 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
30619 note_variable_value (node
->die
);
30621 /* The AT_pubnames attribute needs to go in all skeleton dies, including
30622 both the main_cu and all skeleton TUs. Making this call unconditional
30623 would end up either adding a second copy of the AT_pubnames attribute, or
30624 requiring a special case in add_top_level_skeleton_die_attrs. */
30625 if (!dwarf_split_debug_info
)
30626 add_AT_pubnames (comp_unit_die ());
30628 /* The early debug phase is now finished. */
30629 early_dwarf_finished
= true;
30631 /* Do not generate DWARF assembler now when not producing LTO bytecode. */
30632 if (!flag_generate_lto
&& !flag_generate_offload
)
30635 /* Now as we are going to output for LTO initialize sections and labels
30636 to the LTO variants. We don't need a random-seed postfix as other
30637 LTO sections as linking the LTO debug sections into one in a partial
30639 init_sections_and_labels (true);
30641 /* The output below is modeled after dwarf2out_finish with all
30642 location related output removed and some LTO specific changes.
30643 Some refactoring might make both smaller and easier to match up. */
30645 /* Traverse the DIE's and add add sibling attributes to those DIE's
30646 that have children. */
30647 add_sibling_attributes (comp_unit_die ());
30648 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
30649 add_sibling_attributes (node
->die
);
30650 for (comdat_type_node
*ctnode
= comdat_type_list
;
30651 ctnode
!= NULL
; ctnode
= ctnode
->next
)
30652 add_sibling_attributes (ctnode
->root_die
);
30655 add_AT_macptr (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE
,
30656 macinfo_section_label
);
30658 save_macinfo_strings ();
30660 /* Output all of the compilation units. We put the main one last so that
30661 the offsets are available to output_pubnames. */
30662 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
30663 output_comp_unit (node
->die
, 0, NULL
);
30665 hash_table
<comdat_type_hasher
> comdat_type_table (100);
30666 for (comdat_type_node
*ctnode
= comdat_type_list
;
30667 ctnode
!= NULL
; ctnode
= ctnode
->next
)
30669 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
30671 /* Don't output duplicate types. */
30672 if (*slot
!= HTAB_EMPTY_ENTRY
)
30675 /* Add a pointer to the line table for the main compilation unit
30676 so that the debugger can make sense of DW_AT_decl_file
30678 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
30679 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
30680 (!dwarf_split_debug_info
30681 ? debug_line_section_label
30682 : debug_skeleton_line_section_label
));
30684 output_comdat_type_unit (ctnode
);
30688 /* Stick a unique symbol to the main debuginfo section. */
30689 compute_comp_unit_symbol (comp_unit_die ());
30691 /* Output the main compilation unit. We always need it if only for
30693 output_comp_unit (comp_unit_die (), true, NULL
);
30695 /* Output the abbreviation table. */
30696 if (vec_safe_length (abbrev_die_table
) != 1)
30698 switch_to_section (debug_abbrev_section
);
30699 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
30700 output_abbrev_section ();
30703 /* Have to end the macro section. */
30706 /* We have to save macinfo state if we need to output it again
30707 for the FAT part of the object. */
30708 vec
<macinfo_entry
, va_gc
> *saved_macinfo_table
= macinfo_table
;
30709 if (flag_fat_lto_objects
)
30710 macinfo_table
= macinfo_table
->copy ();
30712 switch_to_section (debug_macinfo_section
);
30713 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
30714 output_macinfo (debug_skeleton_line_section_label
, true);
30715 dw2_asm_output_data (1, 0, "End compilation unit");
30717 /* Emit a skeleton debug_line section. */
30718 switch_to_section (debug_skeleton_line_section
);
30719 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
30720 output_line_info (true);
30722 if (flag_fat_lto_objects
)
30724 vec_free (macinfo_table
);
30725 macinfo_table
= saved_macinfo_table
;
30730 /* If we emitted any indirect strings, output the string table too. */
30731 if (debug_str_hash
|| skeleton_debug_str_hash
)
30732 output_indirect_strings ();
30734 /* Switch back to the text section. */
30735 switch_to_section (text_section
);
30738 /* Reset all state within dwarf2out.c so that we can rerun the compiler
30739 within the same process. For use by toplev::finalize. */
30742 dwarf2out_c_finalize (void)
30744 last_var_location_insn
= NULL
;
30745 cached_next_real_insn
= NULL
;
30746 used_rtx_array
= NULL
;
30747 incomplete_types
= NULL
;
30748 decl_scope_table
= NULL
;
30749 debug_info_section
= NULL
;
30750 debug_skeleton_info_section
= NULL
;
30751 debug_abbrev_section
= NULL
;
30752 debug_skeleton_abbrev_section
= NULL
;
30753 debug_aranges_section
= NULL
;
30754 debug_addr_section
= NULL
;
30755 debug_macinfo_section
= NULL
;
30756 debug_line_section
= NULL
;
30757 debug_skeleton_line_section
= NULL
;
30758 debug_loc_section
= NULL
;
30759 debug_pubnames_section
= NULL
;
30760 debug_pubtypes_section
= NULL
;
30761 debug_str_section
= NULL
;
30762 debug_line_str_section
= NULL
;
30763 debug_str_dwo_section
= NULL
;
30764 debug_str_offsets_section
= NULL
;
30765 debug_ranges_section
= NULL
;
30766 debug_frame_section
= NULL
;
30768 debug_str_hash
= NULL
;
30769 debug_line_str_hash
= NULL
;
30770 skeleton_debug_str_hash
= NULL
;
30771 dw2_string_counter
= 0;
30772 have_multiple_function_sections
= false;
30773 text_section_used
= false;
30774 cold_text_section_used
= false;
30775 cold_text_section
= NULL
;
30776 current_unit_personality
= NULL
;
30778 early_dwarf
= false;
30779 early_dwarf_finished
= false;
30781 next_die_offset
= 0;
30782 single_comp_unit_die
= NULL
;
30783 comdat_type_list
= NULL
;
30784 limbo_die_list
= NULL
;
30786 decl_die_table
= NULL
;
30787 common_block_die_table
= NULL
;
30788 decl_loc_table
= NULL
;
30789 call_arg_locations
= NULL
;
30790 call_arg_loc_last
= NULL
;
30791 call_site_count
= -1;
30792 tail_call_site_count
= -1;
30793 cached_dw_loc_list_table
= NULL
;
30794 abbrev_die_table
= NULL
;
30795 delete dwarf_proc_stack_usage_map
;
30796 dwarf_proc_stack_usage_map
= NULL
;
30797 line_info_label_num
= 0;
30798 cur_line_info_table
= NULL
;
30799 text_section_line_info
= NULL
;
30800 cold_text_section_line_info
= NULL
;
30801 separate_line_info
= NULL
;
30802 info_section_emitted
= false;
30803 pubname_table
= NULL
;
30804 pubtype_table
= NULL
;
30805 macinfo_table
= NULL
;
30806 ranges_table
= NULL
;
30807 ranges_by_label
= NULL
;
30809 have_location_lists
= false;
30812 last_emitted_file
= NULL
;
30814 tmpl_value_parm_die_table
= NULL
;
30815 generic_type_instances
= NULL
;
30816 frame_pointer_fb_offset
= 0;
30817 frame_pointer_fb_offset_valid
= false;
30818 base_types
.release ();
30819 XDELETEVEC (producer_string
);
30820 producer_string
= NULL
;
30823 #include "gt-dwarf2out.h"