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 GTY(()) section
*debug_line_section
;
168 static GTY(()) section
*debug_skeleton_line_section
;
169 static GTY(()) section
*debug_loc_section
;
170 static GTY(()) section
*debug_pubnames_section
;
171 static GTY(()) section
*debug_pubtypes_section
;
172 static GTY(()) section
*debug_str_section
;
173 static GTY(()) section
*debug_line_str_section
;
174 static GTY(()) section
*debug_str_dwo_section
;
175 static GTY(()) section
*debug_str_offsets_section
;
176 static GTY(()) section
*debug_ranges_section
;
177 static GTY(()) section
*debug_frame_section
;
179 /* Maximum size (in bytes) of an artificially generated label. */
180 #define MAX_ARTIFICIAL_LABEL_BYTES 30
182 /* According to the (draft) DWARF 3 specification, the initial length
183 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
184 bytes are 0xffffffff, followed by the length stored in the next 8
187 However, the SGI/MIPS ABI uses an initial length which is equal to
188 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
190 #ifndef DWARF_INITIAL_LENGTH_SIZE
191 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
194 #ifndef DWARF_INITIAL_LENGTH_SIZE_STR
195 #define DWARF_INITIAL_LENGTH_SIZE_STR (DWARF_OFFSET_SIZE == 4 ? "-4" : "-12")
198 /* Round SIZE up to the nearest BOUNDARY. */
199 #define DWARF_ROUND(SIZE,BOUNDARY) \
200 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
202 /* CIE identifier. */
203 #if HOST_BITS_PER_WIDE_INT >= 64
204 #define DWARF_CIE_ID \
205 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
207 #define DWARF_CIE_ID DW_CIE_ID
211 /* A vector for a table that contains frame description
212 information for each routine. */
213 #define NOT_INDEXED (-1U)
214 #define NO_INDEX_ASSIGNED (-2U)
216 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
218 struct GTY((for_user
)) indirect_string_node
{
220 unsigned int refcount
;
221 enum dwarf_form form
;
226 struct indirect_string_hasher
: ggc_ptr_hash
<indirect_string_node
>
228 typedef const char *compare_type
;
230 static hashval_t
hash (indirect_string_node
*);
231 static bool equal (indirect_string_node
*, const char *);
234 static GTY (()) hash_table
<indirect_string_hasher
> *debug_str_hash
;
236 static GTY (()) hash_table
<indirect_string_hasher
> *debug_line_str_hash
;
238 /* With split_debug_info, both the comp_dir and dwo_name go in the
239 main object file, rather than the dwo, similar to the force_direct
240 parameter elsewhere but with additional complications:
242 1) The string is needed in both the main object file and the dwo.
243 That is, the comp_dir and dwo_name will appear in both places.
245 2) Strings can use four forms: DW_FORM_string, DW_FORM_strp,
246 DW_FORM_line_strp or DW_FORM_GNU_str_index.
248 3) GCC chooses the form to use late, depending on the size and
251 Rather than forcing the all debug string handling functions and
252 callers to deal with these complications, simply use a separate,
253 special-cased string table for any attribute that should go in the
254 main object file. This limits the complexity to just the places
257 static GTY (()) hash_table
<indirect_string_hasher
> *skeleton_debug_str_hash
;
259 static GTY(()) int dw2_string_counter
;
261 /* True if the compilation unit places functions in more than one section. */
262 static GTY(()) bool have_multiple_function_sections
= false;
264 /* 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 /* .debug_rnglists next index. */
288 static unsigned int rnglist_idx
;
290 /* Data and reference forms for relocatable data. */
291 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
292 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
294 #ifndef DEBUG_FRAME_SECTION
295 #define DEBUG_FRAME_SECTION ".debug_frame"
298 #ifndef FUNC_BEGIN_LABEL
299 #define FUNC_BEGIN_LABEL "LFB"
302 #ifndef FUNC_END_LABEL
303 #define FUNC_END_LABEL "LFE"
306 #ifndef PROLOGUE_END_LABEL
307 #define PROLOGUE_END_LABEL "LPE"
310 #ifndef EPILOGUE_BEGIN_LABEL
311 #define EPILOGUE_BEGIN_LABEL "LEB"
314 #ifndef FRAME_BEGIN_LABEL
315 #define FRAME_BEGIN_LABEL "Lframe"
317 #define CIE_AFTER_SIZE_LABEL "LSCIE"
318 #define CIE_END_LABEL "LECIE"
319 #define FDE_LABEL "LSFDE"
320 #define FDE_AFTER_SIZE_LABEL "LASFDE"
321 #define FDE_END_LABEL "LEFDE"
322 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
323 #define LINE_NUMBER_END_LABEL "LELT"
324 #define LN_PROLOG_AS_LABEL "LASLTP"
325 #define LN_PROLOG_END_LABEL "LELTP"
326 #define DIE_LABEL_PREFIX "DW"
328 /* Match the base name of a file to the base name of a compilation unit. */
331 matches_main_base (const char *path
)
333 /* Cache the last query. */
334 static const char *last_path
= NULL
;
335 static int last_match
= 0;
336 if (path
!= last_path
)
339 int length
= base_of_path (path
, &base
);
341 last_match
= (length
== main_input_baselength
342 && memcmp (base
, main_input_basename
, length
) == 0);
347 #ifdef DEBUG_DEBUG_STRUCT
350 dump_struct_debug (tree type
, enum debug_info_usage usage
,
351 enum debug_struct_file criterion
, int generic
,
352 int matches
, int result
)
354 /* Find the type name. */
355 tree type_decl
= TYPE_STUB_DECL (type
);
357 const char *name
= 0;
358 if (TREE_CODE (t
) == TYPE_DECL
)
361 name
= IDENTIFIER_POINTER (t
);
363 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
365 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
366 matches
? "bas" : "hdr",
367 generic
? "gen" : "ord",
368 usage
== DINFO_USAGE_DFN
? ";" :
369 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
371 (void*) type_decl
, name
);
374 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
375 dump_struct_debug (type, usage, criterion, generic, matches, result)
379 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
384 /* Get the number of HOST_WIDE_INTs needed to represent the precision
385 of the number. Some constants have a large uniform precision, so
386 we get the precision needed for the actual value of the number. */
389 get_full_len (const wide_int
&op
)
391 int prec
= wi::min_precision (op
, UNSIGNED
);
392 return ((prec
+ HOST_BITS_PER_WIDE_INT
- 1)
393 / HOST_BITS_PER_WIDE_INT
);
397 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
399 enum debug_struct_file criterion
;
401 bool generic
= lang_hooks
.types
.generic_p (type
);
404 criterion
= debug_struct_generic
[usage
];
406 criterion
= debug_struct_ordinary
[usage
];
408 if (criterion
== DINFO_STRUCT_FILE_NONE
)
409 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
410 if (criterion
== DINFO_STRUCT_FILE_ANY
)
411 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
413 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
415 if (type_decl
!= NULL
)
417 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
418 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
420 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
421 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
424 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
427 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
428 switch to the data section instead, and write out a synthetic start label
429 for collect2 the first time around. */
432 switch_to_eh_frame_section (bool back ATTRIBUTE_UNUSED
)
434 if (eh_frame_section
== 0)
438 if (EH_TABLES_CAN_BE_READ_ONLY
)
444 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
446 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
448 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
451 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
452 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
453 && (per_encoding
& 0x70) != DW_EH_PE_absptr
454 && (per_encoding
& 0x70) != DW_EH_PE_aligned
455 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
456 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
457 ? 0 : SECTION_WRITE
);
460 flags
= SECTION_WRITE
;
462 #ifdef EH_FRAME_SECTION_NAME
463 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
465 eh_frame_section
= ((flags
== SECTION_WRITE
)
466 ? data_section
: readonly_data_section
);
467 #endif /* EH_FRAME_SECTION_NAME */
470 switch_to_section (eh_frame_section
);
472 #ifdef EH_FRAME_THROUGH_COLLECT2
473 /* We have no special eh_frame section. Emit special labels to guide
477 tree label
= get_file_function_name ("F");
478 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
479 targetm
.asm_out
.globalize_label (asm_out_file
,
480 IDENTIFIER_POINTER (label
));
481 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
486 /* Switch [BACK] to the eh or debug frame table section, depending on
490 switch_to_frame_table_section (int for_eh
, bool back
)
493 switch_to_eh_frame_section (back
);
496 if (!debug_frame_section
)
497 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
498 SECTION_DEBUG
, NULL
);
499 switch_to_section (debug_frame_section
);
503 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
505 enum dw_cfi_oprnd_type
506 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
511 case DW_CFA_GNU_window_save
:
512 case DW_CFA_remember_state
:
513 case DW_CFA_restore_state
:
514 return dw_cfi_oprnd_unused
;
517 case DW_CFA_advance_loc1
:
518 case DW_CFA_advance_loc2
:
519 case DW_CFA_advance_loc4
:
520 case DW_CFA_MIPS_advance_loc8
:
521 return dw_cfi_oprnd_addr
;
524 case DW_CFA_offset_extended
:
526 case DW_CFA_offset_extended_sf
:
527 case DW_CFA_def_cfa_sf
:
529 case DW_CFA_restore_extended
:
530 case DW_CFA_undefined
:
531 case DW_CFA_same_value
:
532 case DW_CFA_def_cfa_register
:
533 case DW_CFA_register
:
534 case DW_CFA_expression
:
535 case DW_CFA_val_expression
:
536 return dw_cfi_oprnd_reg_num
;
538 case DW_CFA_def_cfa_offset
:
539 case DW_CFA_GNU_args_size
:
540 case DW_CFA_def_cfa_offset_sf
:
541 return dw_cfi_oprnd_offset
;
543 case DW_CFA_def_cfa_expression
:
544 return dw_cfi_oprnd_loc
;
551 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
553 enum dw_cfi_oprnd_type
554 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
559 case DW_CFA_def_cfa_sf
:
561 case DW_CFA_offset_extended_sf
:
562 case DW_CFA_offset_extended
:
563 return dw_cfi_oprnd_offset
;
565 case DW_CFA_register
:
566 return dw_cfi_oprnd_reg_num
;
568 case DW_CFA_expression
:
569 case DW_CFA_val_expression
:
570 return dw_cfi_oprnd_loc
;
573 return dw_cfi_oprnd_unused
;
577 /* Output one FDE. */
580 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
581 char *section_start_label
, int fde_encoding
, char *augmentation
,
582 bool any_lsda_needed
, int lsda_encoding
)
584 const char *begin
, *end
;
585 static unsigned int j
;
586 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
588 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
590 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
592 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
593 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
594 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
596 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
597 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
598 " indicating 64-bit DWARF extension");
599 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
602 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
605 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
607 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
608 debug_frame_section
, "FDE CIE offset");
610 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
611 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
615 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
616 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
617 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
618 "FDE initial location");
619 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
620 end
, begin
, "FDE address range");
624 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
625 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
632 int size
= size_of_encoded_value (lsda_encoding
);
634 if (lsda_encoding
== DW_EH_PE_aligned
)
636 int offset
= ( 4 /* Length */
638 + 2 * size_of_encoded_value (fde_encoding
)
639 + 1 /* Augmentation size */ );
640 int pad
= -offset
& (PTR_SIZE
- 1);
643 gcc_assert (size_of_uleb128 (size
) == 1);
646 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
648 if (fde
->uses_eh_lsda
)
650 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
651 fde
->funcdef_number
);
652 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
653 gen_rtx_SYMBOL_REF (Pmode
, l1
),
655 "Language Specific Data Area");
659 if (lsda_encoding
== DW_EH_PE_aligned
)
660 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
661 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
662 "Language Specific Data Area (none)");
666 dw2_asm_output_data_uleb128 (0, "Augmentation size");
669 /* Loop through the Call Frame Instructions associated with this FDE. */
670 fde
->dw_fde_current_label
= begin
;
672 size_t from
, until
, i
;
675 until
= vec_safe_length (fde
->dw_fde_cfi
);
677 if (fde
->dw_fde_second_begin
== NULL
)
680 until
= fde
->dw_fde_switch_cfi_index
;
682 from
= fde
->dw_fde_switch_cfi_index
;
684 for (i
= from
; i
< until
; i
++)
685 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
688 /* If we are to emit a ref/link from function bodies to their frame tables,
689 do it now. This is typically performed to make sure that tables
690 associated with functions are dragged with them and not discarded in
691 garbage collecting links. We need to do this on a per function basis to
692 cope with -ffunction-sections. */
694 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
695 /* Switch to the function section, emit the ref to the tables, and
696 switch *back* into the table section. */
697 switch_to_section (function_section (fde
->decl
));
698 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
699 switch_to_frame_table_section (for_eh
, true);
702 /* Pad the FDE out to an address sized boundary. */
703 ASM_OUTPUT_ALIGN (asm_out_file
,
704 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
705 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
710 /* Return true if frame description entry FDE is needed for EH. */
713 fde_needed_for_eh_p (dw_fde_ref fde
)
715 if (flag_asynchronous_unwind_tables
)
718 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
721 if (fde
->uses_eh_lsda
)
724 /* If exceptions are enabled, we have collected nothrow info. */
725 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
731 /* Output the call frame information used to record information
732 that relates to calculating the frame pointer, and records the
733 location of saved registers. */
736 output_call_frame_info (int for_eh
)
741 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
742 char section_start_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
743 bool any_lsda_needed
= false;
744 char augmentation
[6];
745 int augmentation_size
;
746 int fde_encoding
= DW_EH_PE_absptr
;
747 int per_encoding
= DW_EH_PE_absptr
;
748 int lsda_encoding
= DW_EH_PE_absptr
;
750 rtx personality
= NULL
;
753 /* Don't emit a CIE if there won't be any FDEs. */
757 /* Nothing to do if the assembler's doing it all. */
758 if (dwarf2out_do_cfi_asm ())
761 /* If we don't have any functions we'll want to unwind out of, don't emit
762 any EH unwind information. If we make FDEs linkonce, we may have to
763 emit an empty label for an FDE that wouldn't otherwise be emitted. We
764 want to avoid having an FDE kept around when the function it refers to
765 is discarded. Example where this matters: a primary function template
766 in C++ requires EH information, an explicit specialization doesn't. */
769 bool any_eh_needed
= false;
771 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
773 if (fde
->uses_eh_lsda
)
774 any_eh_needed
= any_lsda_needed
= true;
775 else if (fde_needed_for_eh_p (fde
))
776 any_eh_needed
= true;
777 else if (TARGET_USES_WEAK_UNWIND_INFO
)
778 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
785 /* We're going to be generating comments, so turn on app. */
789 /* Switch to the proper frame section, first time. */
790 switch_to_frame_table_section (for_eh
, false);
792 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
793 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
795 /* Output the CIE. */
796 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
797 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
798 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
800 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
801 dw2_asm_output_data (4, 0xffffffff,
802 "Initial length escape value indicating 64-bit DWARF extension");
803 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
804 "Length of Common Information Entry");
806 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
808 /* Now that the CIE pointer is PC-relative for EH,
809 use 0 to identify the CIE. */
810 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
811 (for_eh
? 0 : DWARF_CIE_ID
),
812 "CIE Identifier Tag");
814 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
815 use CIE version 1, unless that would produce incorrect results
816 due to overflowing the return register column. */
817 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
819 if (return_reg
>= 256 || dwarf_version
> 2)
821 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
824 augmentation_size
= 0;
826 personality
= current_unit_personality
;
832 z Indicates that a uleb128 is present to size the
833 augmentation section.
834 L Indicates the encoding (and thus presence) of
835 an LSDA pointer in the FDE augmentation.
836 R Indicates a non-default pointer encoding for
838 P Indicates the presence of an encoding + language
839 personality routine in the CIE augmentation. */
841 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
842 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
843 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
845 p
= augmentation
+ 1;
849 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
850 assemble_external_libcall (personality
);
855 augmentation_size
+= 1;
857 if (fde_encoding
!= DW_EH_PE_absptr
)
860 augmentation_size
+= 1;
862 if (p
> augmentation
+ 1)
864 augmentation
[0] = 'z';
868 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
869 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
871 int offset
= ( 4 /* Length */
873 + 1 /* CIE version */
874 + strlen (augmentation
) + 1 /* Augmentation */
875 + size_of_uleb128 (1) /* Code alignment */
876 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
878 + 1 /* Augmentation size */
879 + 1 /* Personality encoding */ );
880 int pad
= -offset
& (PTR_SIZE
- 1);
882 augmentation_size
+= pad
;
884 /* Augmentations should be small, so there's scarce need to
885 iterate for a solution. Die if we exceed one uleb128 byte. */
886 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
890 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
891 if (dw_cie_version
>= 4)
893 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
894 dw2_asm_output_data (1, 0, "CIE Segment Size");
896 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
897 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
898 "CIE Data Alignment Factor");
900 if (dw_cie_version
== 1)
901 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
903 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
907 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
910 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
911 eh_data_format_name (per_encoding
));
912 dw2_asm_output_encoded_addr_rtx (per_encoding
,
918 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
919 eh_data_format_name (lsda_encoding
));
921 if (fde_encoding
!= DW_EH_PE_absptr
)
922 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
923 eh_data_format_name (fde_encoding
));
926 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
927 output_cfi (cfi
, NULL
, for_eh
);
929 /* Pad the CIE out to an address sized boundary. */
930 ASM_OUTPUT_ALIGN (asm_out_file
,
931 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
932 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
934 /* Loop through all of the FDE's. */
935 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
939 /* Don't emit EH unwind info for leaf functions that don't need it. */
940 if (for_eh
&& !fde_needed_for_eh_p (fde
))
943 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
944 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
945 augmentation
, any_lsda_needed
, lsda_encoding
);
948 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
949 dw2_asm_output_data (4, 0, "End of Table");
951 /* Turn off app to make assembly quicker. */
956 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
959 dwarf2out_do_cfi_startproc (bool second
)
963 rtx personality
= get_personality_function (current_function_decl
);
965 fprintf (asm_out_file
, "\t.cfi_startproc\n");
969 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
972 /* ??? The GAS support isn't entirely consistent. We have to
973 handle indirect support ourselves, but PC-relative is done
974 in the assembler. Further, the assembler can't handle any
975 of the weirder relocation types. */
976 if (enc
& DW_EH_PE_indirect
)
977 ref
= dw2_force_const_mem (ref
, true);
979 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
980 output_addr_const (asm_out_file
, ref
);
981 fputc ('\n', asm_out_file
);
984 if (crtl
->uses_eh_lsda
)
986 char lab
[MAX_ARTIFICIAL_LABEL_BYTES
];
988 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
989 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
990 current_function_funcdef_no
);
991 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
992 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
994 if (enc
& DW_EH_PE_indirect
)
995 ref
= dw2_force_const_mem (ref
, true);
997 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
998 output_addr_const (asm_out_file
, ref
);
999 fputc ('\n', asm_out_file
);
1003 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
1004 this allocation may be done before pass_final. */
1007 dwarf2out_alloc_current_fde (void)
1011 fde
= ggc_cleared_alloc
<dw_fde_node
> ();
1012 fde
->decl
= current_function_decl
;
1013 fde
->funcdef_number
= current_function_funcdef_no
;
1014 fde
->fde_index
= vec_safe_length (fde_vec
);
1015 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
1016 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
1017 fde
->nothrow
= crtl
->nothrow
;
1018 fde
->drap_reg
= INVALID_REGNUM
;
1019 fde
->vdrap_reg
= INVALID_REGNUM
;
1021 /* Record the FDE associated with this function. */
1023 vec_safe_push (fde_vec
, fde
);
1028 /* Output a marker (i.e. a label) for the beginning of a function, before
1032 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1033 unsigned int column ATTRIBUTE_UNUSED
,
1034 const char *file ATTRIBUTE_UNUSED
)
1036 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1042 current_function_func_begin_label
= NULL
;
1044 do_frame
= dwarf2out_do_frame ();
1046 /* ??? current_function_func_begin_label is also used by except.c for
1047 call-site information. We must emit this label if it might be used. */
1049 && (!flag_exceptions
1050 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1053 fnsec
= function_section (current_function_decl
);
1054 switch_to_section (fnsec
);
1055 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1056 current_function_funcdef_no
);
1057 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1058 current_function_funcdef_no
);
1059 dup_label
= xstrdup (label
);
1060 current_function_func_begin_label
= dup_label
;
1062 /* We can elide the fde allocation if we're not emitting debug info. */
1066 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1067 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1068 would include pass_dwarf2_frame. If we've not created the FDE yet,
1072 fde
= dwarf2out_alloc_current_fde ();
1074 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1075 fde
->dw_fde_begin
= dup_label
;
1076 fde
->dw_fde_current_label
= dup_label
;
1077 fde
->in_std_section
= (fnsec
== text_section
1078 || (cold_text_section
&& fnsec
== cold_text_section
));
1080 /* We only want to output line number information for the genuine dwarf2
1081 prologue case, not the eh frame case. */
1082 #ifdef DWARF2_DEBUGGING_INFO
1084 dwarf2out_source_line (line
, column
, file
, 0, true);
1087 if (dwarf2out_do_cfi_asm ())
1088 dwarf2out_do_cfi_startproc (false);
1091 rtx personality
= get_personality_function (current_function_decl
);
1092 if (!current_unit_personality
)
1093 current_unit_personality
= personality
;
1095 /* We cannot keep a current personality per function as without CFI
1096 asm, at the point where we emit the CFI data, there is no current
1097 function anymore. */
1098 if (personality
&& current_unit_personality
!= personality
)
1099 sorry ("multiple EH personalities are supported only with assemblers "
1100 "supporting .cfi_personality directive");
1104 /* Output a marker (i.e. a label) for the end of the generated code
1105 for a function prologue. This gets called *after* the prologue code has
1109 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1110 const char *file ATTRIBUTE_UNUSED
)
1112 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1114 /* Output a label to mark the endpoint of the code generated for this
1116 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1117 current_function_funcdef_no
);
1118 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1119 current_function_funcdef_no
);
1120 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1123 /* Output a marker (i.e. a label) for the beginning of the generated code
1124 for a function epilogue. This gets called *before* the prologue code has
1128 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1129 const char *file ATTRIBUTE_UNUSED
)
1131 dw_fde_ref fde
= cfun
->fde
;
1132 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1134 if (fde
->dw_fde_vms_begin_epilogue
)
1137 /* Output a label to mark the endpoint of the code generated for this
1139 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1140 current_function_funcdef_no
);
1141 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1142 current_function_funcdef_no
);
1143 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1146 /* Output a marker (i.e. a label) for the absolute end of the generated code
1147 for a function definition. This gets called *after* the epilogue code has
1151 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1152 const char *file ATTRIBUTE_UNUSED
)
1155 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1157 last_var_location_insn
= NULL
;
1158 cached_next_real_insn
= NULL
;
1160 if (dwarf2out_do_cfi_asm ())
1161 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1163 /* Output a label to mark the endpoint of the code generated for this
1165 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1166 current_function_funcdef_no
);
1167 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1169 gcc_assert (fde
!= NULL
);
1170 if (fde
->dw_fde_second_begin
== NULL
)
1171 fde
->dw_fde_end
= xstrdup (label
);
1175 dwarf2out_frame_finish (void)
1177 /* Output call frame information. */
1178 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1179 output_call_frame_info (0);
1181 /* Output another copy for the unwinder. */
1182 if ((flag_unwind_tables
|| flag_exceptions
)
1183 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1184 output_call_frame_info (1);
1187 /* Note that the current function section is being used for code. */
1190 dwarf2out_note_section_used (void)
1192 section
*sec
= current_function_section ();
1193 if (sec
== text_section
)
1194 text_section_used
= true;
1195 else if (sec
== cold_text_section
)
1196 cold_text_section_used
= true;
1199 static void var_location_switch_text_section (void);
1200 static void set_cur_line_info_table (section
*);
1203 dwarf2out_switch_text_section (void)
1206 dw_fde_ref fde
= cfun
->fde
;
1208 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1210 if (!in_cold_section_p
)
1212 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1213 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1214 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1218 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1219 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1220 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1222 have_multiple_function_sections
= true;
1224 /* There is no need to mark used sections when not debugging. */
1225 if (cold_text_section
!= NULL
)
1226 dwarf2out_note_section_used ();
1228 if (dwarf2out_do_cfi_asm ())
1229 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1231 /* Now do the real section switch. */
1232 sect
= current_function_section ();
1233 switch_to_section (sect
);
1235 fde
->second_in_std_section
1236 = (sect
== text_section
1237 || (cold_text_section
&& sect
== cold_text_section
));
1239 if (dwarf2out_do_cfi_asm ())
1240 dwarf2out_do_cfi_startproc (true);
1242 var_location_switch_text_section ();
1244 if (cold_text_section
!= NULL
)
1245 set_cur_line_info_table (sect
);
1248 /* And now, the subset of the debugging information support code necessary
1249 for emitting location expressions. */
1251 /* Data about a single source file. */
1252 struct GTY((for_user
)) dwarf_file_data
{
1253 const char * filename
;
1257 /* Describe an entry into the .debug_addr section. */
1261 ate_kind_rtx_dtprel
,
1265 struct GTY((for_user
)) addr_table_entry
{
1267 unsigned int refcount
;
1269 union addr_table_entry_struct_union
1271 rtx
GTY ((tag ("0"))) rtl
;
1272 char * GTY ((tag ("1"))) label
;
1274 GTY ((desc ("%1.kind"))) addr
;
1277 /* Location lists are ranges + location descriptions for that range,
1278 so you can track variables that are in different places over
1279 their entire life. */
1280 typedef struct GTY(()) dw_loc_list_struct
{
1281 dw_loc_list_ref dw_loc_next
;
1282 const char *begin
; /* Label and addr_entry for start of range */
1283 addr_table_entry
*begin_entry
;
1284 const char *end
; /* Label for end of range */
1285 char *ll_symbol
; /* Label for beginning of location list.
1286 Only on head of list */
1287 const char *section
; /* Section this loclist is relative to */
1288 dw_loc_descr_ref expr
;
1290 /* True if all addresses in this and subsequent lists are known to be
1293 /* True if this list has been replaced by dw_loc_next. */
1295 /* True if it has been emitted into .debug_loc* / .debug_loclists*
1297 unsigned char emitted
: 1;
1298 /* True if hash field is index rather than hash value. */
1299 unsigned char num_assigned
: 1;
1300 /* True if .debug_loclists.dwo offset has been emitted for it already. */
1301 unsigned char offset_emitted
: 1;
1302 /* True if note_variable_value_in_expr has been called on it. */
1303 unsigned char noted_variable_value
: 1;
1304 /* True if the range should be emitted even if begin and end
1309 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1310 static dw_loc_descr_ref
uint_loc_descriptor (unsigned HOST_WIDE_INT
);
1312 /* Convert a DWARF stack opcode into its string name. */
1315 dwarf_stack_op_name (unsigned int op
)
1317 const char *name
= get_DW_OP_name (op
);
1322 return "OP_<unknown>";
1325 /* Return a pointer to a newly allocated location description. Location
1326 descriptions are simple expression terms that can be strung
1327 together to form more complicated location (address) descriptions. */
1329 static inline dw_loc_descr_ref
1330 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1331 unsigned HOST_WIDE_INT oprnd2
)
1333 dw_loc_descr_ref descr
= ggc_cleared_alloc
<dw_loc_descr_node
> ();
1335 descr
->dw_loc_opc
= op
;
1336 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1337 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1338 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1339 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1340 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1341 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1346 /* Return a pointer to a newly allocated location description for
1349 static inline dw_loc_descr_ref
1350 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1353 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1356 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1359 /* Add a location description term to a location description expression. */
1362 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1364 dw_loc_descr_ref
*d
;
1366 /* Find the end of the chain. */
1367 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1373 /* Compare two location operands for exact equality. */
1376 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1378 if (a
->val_class
!= b
->val_class
)
1380 switch (a
->val_class
)
1382 case dw_val_class_none
:
1384 case dw_val_class_addr
:
1385 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1387 case dw_val_class_offset
:
1388 case dw_val_class_unsigned_const
:
1389 case dw_val_class_const
:
1390 case dw_val_class_unsigned_const_implicit
:
1391 case dw_val_class_const_implicit
:
1392 case dw_val_class_range_list
:
1393 /* These are all HOST_WIDE_INT, signed or unsigned. */
1394 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1396 case dw_val_class_loc
:
1397 return a
->v
.val_loc
== b
->v
.val_loc
;
1398 case dw_val_class_loc_list
:
1399 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1400 case dw_val_class_die_ref
:
1401 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1402 case dw_val_class_fde_ref
:
1403 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1404 case dw_val_class_lbl_id
:
1405 case dw_val_class_lineptr
:
1406 case dw_val_class_macptr
:
1407 case dw_val_class_loclistsptr
:
1408 case dw_val_class_high_pc
:
1409 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1410 case dw_val_class_str
:
1411 return a
->v
.val_str
== b
->v
.val_str
;
1412 case dw_val_class_flag
:
1413 return a
->v
.val_flag
== b
->v
.val_flag
;
1414 case dw_val_class_file
:
1415 case dw_val_class_file_implicit
:
1416 return a
->v
.val_file
== b
->v
.val_file
;
1417 case dw_val_class_decl_ref
:
1418 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1420 case dw_val_class_const_double
:
1421 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1422 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1424 case dw_val_class_wide_int
:
1425 return *a
->v
.val_wide
== *b
->v
.val_wide
;
1427 case dw_val_class_vec
:
1429 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1430 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1432 return (a_len
== b_len
1433 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1436 case dw_val_class_data8
:
1437 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1439 case dw_val_class_vms_delta
:
1440 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1441 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1443 case dw_val_class_discr_value
:
1444 return (a
->v
.val_discr_value
.pos
== b
->v
.val_discr_value
.pos
1445 && a
->v
.val_discr_value
.v
.uval
== b
->v
.val_discr_value
.v
.uval
);
1446 case dw_val_class_discr_list
:
1447 /* It makes no sense comparing two discriminant value lists. */
1453 /* Compare two location atoms for exact equality. */
1456 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1458 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1461 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1462 address size, but since we always allocate cleared storage it
1463 should be zero for other types of locations. */
1464 if (a
->dtprel
!= b
->dtprel
)
1467 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1468 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1471 /* Compare two complete location expressions for exact equality. */
1474 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1480 if (a
== NULL
|| b
== NULL
)
1482 if (!loc_descr_equal_p_1 (a
, b
))
1491 /* Add a constant OFFSET to a location expression. */
1494 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1496 dw_loc_descr_ref loc
;
1499 gcc_assert (*list_head
!= NULL
);
1504 /* Find the end of the chain. */
1505 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1509 if (loc
->dw_loc_opc
== DW_OP_fbreg
1510 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1511 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1512 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1513 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1515 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1516 offset. Don't optimize if an signed integer overflow would happen. */
1518 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1519 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1522 else if (offset
> 0)
1523 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1528 = uint_loc_descriptor (-(unsigned HOST_WIDE_INT
) offset
);
1529 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1533 /* Add a constant OFFSET to a location list. */
1536 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1539 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1540 loc_descr_plus_const (&d
->expr
, offset
);
1543 #define DWARF_REF_SIZE \
1544 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1546 /* The number of bits that can be encoded by largest DW_FORM_dataN.
1547 In DWARF4 and earlier it is DW_FORM_data8 with 64 bits, in DWARF5
1548 DW_FORM_data16 with 128 bits. */
1549 #define DWARF_LARGEST_DATA_FORM_BITS \
1550 (dwarf_version >= 5 ? 128 : 64)
1552 /* Utility inline function for construction of ops that were GNU extension
1554 static inline enum dwarf_location_atom
1555 dwarf_OP (enum dwarf_location_atom op
)
1559 case DW_OP_implicit_pointer
:
1560 if (dwarf_version
< 5)
1561 return DW_OP_GNU_implicit_pointer
;
1564 case DW_OP_entry_value
:
1565 if (dwarf_version
< 5)
1566 return DW_OP_GNU_entry_value
;
1569 case DW_OP_const_type
:
1570 if (dwarf_version
< 5)
1571 return DW_OP_GNU_const_type
;
1574 case DW_OP_regval_type
:
1575 if (dwarf_version
< 5)
1576 return DW_OP_GNU_regval_type
;
1579 case DW_OP_deref_type
:
1580 if (dwarf_version
< 5)
1581 return DW_OP_GNU_deref_type
;
1585 if (dwarf_version
< 5)
1586 return DW_OP_GNU_convert
;
1589 case DW_OP_reinterpret
:
1590 if (dwarf_version
< 5)
1591 return DW_OP_GNU_reinterpret
;
1600 /* Similarly for attributes. */
1601 static inline enum dwarf_attribute
1602 dwarf_AT (enum dwarf_attribute at
)
1606 case DW_AT_call_return_pc
:
1607 if (dwarf_version
< 5)
1608 return DW_AT_low_pc
;
1611 case DW_AT_call_tail_call
:
1612 if (dwarf_version
< 5)
1613 return DW_AT_GNU_tail_call
;
1616 case DW_AT_call_origin
:
1617 if (dwarf_version
< 5)
1618 return DW_AT_abstract_origin
;
1621 case DW_AT_call_target
:
1622 if (dwarf_version
< 5)
1623 return DW_AT_GNU_call_site_target
;
1626 case DW_AT_call_target_clobbered
:
1627 if (dwarf_version
< 5)
1628 return DW_AT_GNU_call_site_target_clobbered
;
1631 case DW_AT_call_parameter
:
1632 if (dwarf_version
< 5)
1633 return DW_AT_abstract_origin
;
1636 case DW_AT_call_value
:
1637 if (dwarf_version
< 5)
1638 return DW_AT_GNU_call_site_value
;
1641 case DW_AT_call_data_value
:
1642 if (dwarf_version
< 5)
1643 return DW_AT_GNU_call_site_data_value
;
1646 case DW_AT_call_all_calls
:
1647 if (dwarf_version
< 5)
1648 return DW_AT_GNU_all_call_sites
;
1651 case DW_AT_call_all_tail_calls
:
1652 if (dwarf_version
< 5)
1653 return DW_AT_GNU_all_tail_call_sites
;
1656 case DW_AT_dwo_name
:
1657 if (dwarf_version
< 5)
1658 return DW_AT_GNU_dwo_name
;
1667 /* And similarly for tags. */
1668 static inline enum dwarf_tag
1669 dwarf_TAG (enum dwarf_tag tag
)
1673 case DW_TAG_call_site
:
1674 if (dwarf_version
< 5)
1675 return DW_TAG_GNU_call_site
;
1678 case DW_TAG_call_site_parameter
:
1679 if (dwarf_version
< 5)
1680 return DW_TAG_GNU_call_site_parameter
;
1689 static unsigned long int get_base_type_offset (dw_die_ref
);
1691 /* Return the size of a location descriptor. */
1693 static unsigned long
1694 size_of_loc_descr (dw_loc_descr_ref loc
)
1696 unsigned long size
= 1;
1698 switch (loc
->dw_loc_opc
)
1701 size
+= DWARF2_ADDR_SIZE
;
1703 case DW_OP_GNU_addr_index
:
1704 case DW_OP_GNU_const_index
:
1705 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1706 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1725 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1728 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1733 case DW_OP_plus_uconst
:
1734 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1772 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1775 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
);
1782 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1785 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1787 case DW_OP_bit_piece
:
1788 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1789 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1791 case DW_OP_deref_size
:
1792 case DW_OP_xderef_size
:
1801 case DW_OP_call_ref
:
1802 case DW_OP_GNU_variable_value
:
1803 size
+= DWARF_REF_SIZE
;
1805 case DW_OP_implicit_value
:
1806 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1807 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1809 case DW_OP_implicit_pointer
:
1810 case DW_OP_GNU_implicit_pointer
:
1811 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1813 case DW_OP_entry_value
:
1814 case DW_OP_GNU_entry_value
:
1816 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1817 size
+= size_of_uleb128 (op_size
) + op_size
;
1820 case DW_OP_const_type
:
1821 case DW_OP_GNU_const_type
:
1824 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1825 size
+= size_of_uleb128 (o
) + 1;
1826 switch (loc
->dw_loc_oprnd2
.val_class
)
1828 case dw_val_class_vec
:
1829 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1830 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1832 case dw_val_class_const
:
1833 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1835 case dw_val_class_const_double
:
1836 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1838 case dw_val_class_wide_int
:
1839 size
+= (get_full_len (*loc
->dw_loc_oprnd2
.v
.val_wide
)
1840 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
1847 case DW_OP_regval_type
:
1848 case DW_OP_GNU_regval_type
:
1851 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1852 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1853 + size_of_uleb128 (o
);
1856 case DW_OP_deref_type
:
1857 case DW_OP_GNU_deref_type
:
1860 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1861 size
+= 1 + size_of_uleb128 (o
);
1865 case DW_OP_reinterpret
:
1866 case DW_OP_GNU_convert
:
1867 case DW_OP_GNU_reinterpret
:
1868 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1869 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1873 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1874 size
+= size_of_uleb128 (o
);
1877 case DW_OP_GNU_parameter_ref
:
1887 /* Return the size of a series of location descriptors. */
1890 size_of_locs (dw_loc_descr_ref loc
)
1895 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1896 field, to avoid writing to a PCH file. */
1897 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1899 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1901 size
+= size_of_loc_descr (l
);
1906 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1908 l
->dw_loc_addr
= size
;
1909 size
+= size_of_loc_descr (l
);
1915 /* Return the size of the value in a DW_AT_discr_value attribute. */
1918 size_of_discr_value (dw_discr_value
*discr_value
)
1920 if (discr_value
->pos
)
1921 return size_of_uleb128 (discr_value
->v
.uval
);
1923 return size_of_sleb128 (discr_value
->v
.sval
);
1926 /* Return the size of the value in a DW_AT_discr_list attribute. */
1929 size_of_discr_list (dw_discr_list_ref discr_list
)
1933 for (dw_discr_list_ref list
= discr_list
;
1935 list
= list
->dw_discr_next
)
1937 /* One byte for the discriminant value descriptor, and then one or two
1938 LEB128 numbers, depending on whether it's a single case label or a
1941 size
+= size_of_discr_value (&list
->dw_discr_lower_bound
);
1942 if (list
->dw_discr_range
!= 0)
1943 size
+= size_of_discr_value (&list
->dw_discr_upper_bound
);
1948 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1949 static void get_ref_die_offset_label (char *, dw_die_ref
);
1950 static unsigned long int get_ref_die_offset (dw_die_ref
);
1952 /* Output location description stack opcode's operands (if any).
1953 The for_eh_or_skip parameter controls whether register numbers are
1954 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1955 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1956 info). This should be suppressed for the cases that have not been converted
1957 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1960 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1962 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1963 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1965 switch (loc
->dw_loc_opc
)
1967 #ifdef DWARF2_DEBUGGING_INFO
1970 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1975 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1976 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1978 fputc ('\n', asm_out_file
);
1983 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1988 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1989 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1991 fputc ('\n', asm_out_file
);
1996 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1997 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
2004 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2005 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2007 dw2_asm_output_data (2, offset
, NULL
);
2010 case DW_OP_implicit_value
:
2011 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2012 switch (val2
->val_class
)
2014 case dw_val_class_const
:
2015 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
2017 case dw_val_class_vec
:
2019 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2020 unsigned int len
= val2
->v
.val_vec
.length
;
2024 if (elt_size
> sizeof (HOST_WIDE_INT
))
2029 for (i
= 0, p
= (unsigned char *) val2
->v
.val_vec
.array
;
2032 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2033 "fp or vector constant word %u", i
);
2036 case dw_val_class_const_double
:
2038 unsigned HOST_WIDE_INT first
, second
;
2040 if (WORDS_BIG_ENDIAN
)
2042 first
= val2
->v
.val_double
.high
;
2043 second
= val2
->v
.val_double
.low
;
2047 first
= val2
->v
.val_double
.low
;
2048 second
= val2
->v
.val_double
.high
;
2050 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2052 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2056 case dw_val_class_wide_int
:
2059 int len
= get_full_len (*val2
->v
.val_wide
);
2060 if (WORDS_BIG_ENDIAN
)
2061 for (i
= len
- 1; i
>= 0; --i
)
2062 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2063 val2
->v
.val_wide
->elt (i
), NULL
);
2065 for (i
= 0; i
< len
; ++i
)
2066 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2067 val2
->v
.val_wide
->elt (i
), NULL
);
2070 case dw_val_class_addr
:
2071 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
2072 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
2087 case DW_OP_implicit_value
:
2088 /* We currently don't make any attempt to make sure these are
2089 aligned properly like we do for the main unwind info, so
2090 don't support emitting things larger than a byte if we're
2091 only doing unwinding. */
2096 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2099 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2102 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2105 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2107 case DW_OP_plus_uconst
:
2108 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2142 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2146 unsigned r
= val1
->v
.val_unsigned
;
2147 if (for_eh_or_skip
>= 0)
2148 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2149 gcc_assert (size_of_uleb128 (r
)
2150 == size_of_uleb128 (val1
->v
.val_unsigned
));
2151 dw2_asm_output_data_uleb128 (r
, NULL
);
2155 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2159 unsigned r
= val1
->v
.val_unsigned
;
2160 if (for_eh_or_skip
>= 0)
2161 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2162 gcc_assert (size_of_uleb128 (r
)
2163 == size_of_uleb128 (val1
->v
.val_unsigned
));
2164 dw2_asm_output_data_uleb128 (r
, NULL
);
2165 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2169 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2171 case DW_OP_bit_piece
:
2172 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2173 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
2175 case DW_OP_deref_size
:
2176 case DW_OP_xderef_size
:
2177 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2183 if (targetm
.asm_out
.output_dwarf_dtprel
)
2185 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
2188 fputc ('\n', asm_out_file
);
2195 #ifdef DWARF2_DEBUGGING_INFO
2196 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2203 case DW_OP_GNU_addr_index
:
2204 case DW_OP_GNU_const_index
:
2205 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
2206 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
2207 "(index into .debug_addr)");
2213 unsigned long die_offset
2214 = get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2215 /* Make sure the offset has been computed and that we can encode it as
2217 gcc_assert (die_offset
> 0
2218 && die_offset
<= (loc
->dw_loc_opc
== DW_OP_call2
2221 dw2_asm_output_data ((loc
->dw_loc_opc
== DW_OP_call2
) ? 2 : 4,
2226 case DW_OP_call_ref
:
2227 case DW_OP_GNU_variable_value
:
2229 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2230 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2231 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2232 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2233 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2237 case DW_OP_implicit_pointer
:
2238 case DW_OP_GNU_implicit_pointer
:
2240 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2241 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2242 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2243 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2244 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2245 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2249 case DW_OP_entry_value
:
2250 case DW_OP_GNU_entry_value
:
2251 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
2252 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
2255 case DW_OP_const_type
:
2256 case DW_OP_GNU_const_type
:
2258 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
2260 dw2_asm_output_data_uleb128 (o
, NULL
);
2261 switch (val2
->val_class
)
2263 case dw_val_class_const
:
2264 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2265 dw2_asm_output_data (1, l
, NULL
);
2266 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
2268 case dw_val_class_vec
:
2270 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2271 unsigned int len
= val2
->v
.val_vec
.length
;
2276 dw2_asm_output_data (1, l
, NULL
);
2277 if (elt_size
> sizeof (HOST_WIDE_INT
))
2282 for (i
= 0, p
= (unsigned char *) val2
->v
.val_vec
.array
;
2285 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2286 "fp or vector constant word %u", i
);
2289 case dw_val_class_const_double
:
2291 unsigned HOST_WIDE_INT first
, second
;
2292 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2294 dw2_asm_output_data (1, 2 * l
, NULL
);
2295 if (WORDS_BIG_ENDIAN
)
2297 first
= val2
->v
.val_double
.high
;
2298 second
= val2
->v
.val_double
.low
;
2302 first
= val2
->v
.val_double
.low
;
2303 second
= val2
->v
.val_double
.high
;
2305 dw2_asm_output_data (l
, first
, NULL
);
2306 dw2_asm_output_data (l
, second
, NULL
);
2309 case dw_val_class_wide_int
:
2312 int len
= get_full_len (*val2
->v
.val_wide
);
2313 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2315 dw2_asm_output_data (1, len
* l
, NULL
);
2316 if (WORDS_BIG_ENDIAN
)
2317 for (i
= len
- 1; i
>= 0; --i
)
2318 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2320 for (i
= 0; i
< len
; ++i
)
2321 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2329 case DW_OP_regval_type
:
2330 case DW_OP_GNU_regval_type
:
2332 unsigned r
= val1
->v
.val_unsigned
;
2333 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2335 if (for_eh_or_skip
>= 0)
2337 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2338 gcc_assert (size_of_uleb128 (r
)
2339 == size_of_uleb128 (val1
->v
.val_unsigned
));
2341 dw2_asm_output_data_uleb128 (r
, NULL
);
2342 dw2_asm_output_data_uleb128 (o
, NULL
);
2345 case DW_OP_deref_type
:
2346 case DW_OP_GNU_deref_type
:
2348 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2350 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2351 dw2_asm_output_data_uleb128 (o
, NULL
);
2355 case DW_OP_reinterpret
:
2356 case DW_OP_GNU_convert
:
2357 case DW_OP_GNU_reinterpret
:
2358 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2359 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2362 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2364 dw2_asm_output_data_uleb128 (o
, NULL
);
2368 case DW_OP_GNU_parameter_ref
:
2371 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2372 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2373 dw2_asm_output_data (4, o
, NULL
);
2378 /* Other codes have no operands. */
2383 /* Output a sequence of location operations.
2384 The for_eh_or_skip parameter controls whether register numbers are
2385 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2386 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2387 info). This should be suppressed for the cases that have not been converted
2388 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2391 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2393 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2395 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2396 /* Output the opcode. */
2397 if (for_eh_or_skip
>= 0
2398 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2400 unsigned r
= (opc
- DW_OP_breg0
);
2401 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2402 gcc_assert (r
<= 31);
2403 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2405 else if (for_eh_or_skip
>= 0
2406 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2408 unsigned r
= (opc
- DW_OP_reg0
);
2409 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2410 gcc_assert (r
<= 31);
2411 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2414 dw2_asm_output_data (1, opc
,
2415 "%s", dwarf_stack_op_name (opc
));
2417 /* Output the operand(s) (if any). */
2418 output_loc_operands (loc
, for_eh_or_skip
);
2422 /* Output location description stack opcode's operands (if any).
2423 The output is single bytes on a line, suitable for .cfi_escape. */
2426 output_loc_operands_raw (dw_loc_descr_ref loc
)
2428 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2429 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2431 switch (loc
->dw_loc_opc
)
2434 case DW_OP_GNU_addr_index
:
2435 case DW_OP_GNU_const_index
:
2436 case DW_OP_implicit_value
:
2437 /* We cannot output addresses in .cfi_escape, only bytes. */
2443 case DW_OP_deref_size
:
2444 case DW_OP_xderef_size
:
2445 fputc (',', asm_out_file
);
2446 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2451 fputc (',', asm_out_file
);
2452 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2457 fputc (',', asm_out_file
);
2458 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2463 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2464 fputc (',', asm_out_file
);
2465 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2473 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2474 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2476 fputc (',', asm_out_file
);
2477 dw2_asm_output_data_raw (2, offset
);
2483 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2484 gcc_assert (size_of_uleb128 (r
)
2485 == size_of_uleb128 (val1
->v
.val_unsigned
));
2486 fputc (',', asm_out_file
);
2487 dw2_asm_output_data_uleb128_raw (r
);
2492 case DW_OP_plus_uconst
:
2494 fputc (',', asm_out_file
);
2495 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2498 case DW_OP_bit_piece
:
2499 fputc (',', asm_out_file
);
2500 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2501 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2538 fputc (',', asm_out_file
);
2539 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2544 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2545 gcc_assert (size_of_uleb128 (r
)
2546 == size_of_uleb128 (val1
->v
.val_unsigned
));
2547 fputc (',', asm_out_file
);
2548 dw2_asm_output_data_uleb128_raw (r
);
2549 fputc (',', asm_out_file
);
2550 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2554 case DW_OP_implicit_pointer
:
2555 case DW_OP_entry_value
:
2556 case DW_OP_const_type
:
2557 case DW_OP_regval_type
:
2558 case DW_OP_deref_type
:
2560 case DW_OP_reinterpret
:
2561 case DW_OP_GNU_implicit_pointer
:
2562 case DW_OP_GNU_entry_value
:
2563 case DW_OP_GNU_const_type
:
2564 case DW_OP_GNU_regval_type
:
2565 case DW_OP_GNU_deref_type
:
2566 case DW_OP_GNU_convert
:
2567 case DW_OP_GNU_reinterpret
:
2568 case DW_OP_GNU_parameter_ref
:
2573 /* Other codes have no operands. */
2579 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2583 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2584 /* Output the opcode. */
2585 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2587 unsigned r
= (opc
- DW_OP_breg0
);
2588 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2589 gcc_assert (r
<= 31);
2590 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2592 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2594 unsigned r
= (opc
- DW_OP_reg0
);
2595 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2596 gcc_assert (r
<= 31);
2597 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2599 /* Output the opcode. */
2600 fprintf (asm_out_file
, "%#x", opc
);
2601 output_loc_operands_raw (loc
);
2603 if (!loc
->dw_loc_next
)
2605 loc
= loc
->dw_loc_next
;
2607 fputc (',', asm_out_file
);
2611 /* This function builds a dwarf location descriptor sequence from a
2612 dw_cfa_location, adding the given OFFSET to the result of the
2615 struct dw_loc_descr_node
*
2616 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2618 struct dw_loc_descr_node
*head
, *tmp
;
2620 offset
+= cfa
->offset
;
2624 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2625 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2626 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2627 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2628 add_loc_descr (&head
, tmp
);
2631 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2632 add_loc_descr (&head
, tmp
);
2636 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2641 /* This function builds a dwarf location descriptor sequence for
2642 the address at OFFSET from the CFA when stack is aligned to
2645 struct dw_loc_descr_node
*
2646 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2647 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2649 struct dw_loc_descr_node
*head
;
2650 unsigned int dwarf_fp
2651 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2653 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2654 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2656 head
= new_reg_loc_descr (dwarf_fp
, 0);
2657 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2658 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2659 loc_descr_plus_const (&head
, offset
);
2662 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2666 /* And now, the support for symbolic debugging information. */
2668 /* .debug_str support. */
2670 static void dwarf2out_init (const char *);
2671 static void dwarf2out_finish (const char *);
2672 static void dwarf2out_early_finish (const char *);
2673 static void dwarf2out_assembly_start (void);
2674 static void dwarf2out_define (unsigned int, const char *);
2675 static void dwarf2out_undef (unsigned int, const char *);
2676 static void dwarf2out_start_source_file (unsigned, const char *);
2677 static void dwarf2out_end_source_file (unsigned);
2678 static void dwarf2out_function_decl (tree
);
2679 static void dwarf2out_begin_block (unsigned, unsigned);
2680 static void dwarf2out_end_block (unsigned, unsigned);
2681 static bool dwarf2out_ignore_block (const_tree
);
2682 static void dwarf2out_early_global_decl (tree
);
2683 static void dwarf2out_late_global_decl (tree
);
2684 static void dwarf2out_type_decl (tree
, int);
2685 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool, bool);
2686 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2688 static void dwarf2out_abstract_function (tree
);
2689 static void dwarf2out_var_location (rtx_insn
*);
2690 static void dwarf2out_size_function (tree
);
2691 static void dwarf2out_begin_function (tree
);
2692 static void dwarf2out_end_function (unsigned int);
2693 static void dwarf2out_register_main_translation_unit (tree unit
);
2694 static void dwarf2out_set_name (tree
, tree
);
2696 /* The debug hooks structure. */
2698 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2702 dwarf2out_early_finish
,
2703 dwarf2out_assembly_start
,
2706 dwarf2out_start_source_file
,
2707 dwarf2out_end_source_file
,
2708 dwarf2out_begin_block
,
2709 dwarf2out_end_block
,
2710 dwarf2out_ignore_block
,
2711 dwarf2out_source_line
,
2712 dwarf2out_begin_prologue
,
2713 #if VMS_DEBUGGING_INFO
2714 dwarf2out_vms_end_prologue
,
2715 dwarf2out_vms_begin_epilogue
,
2717 debug_nothing_int_charstar
,
2718 debug_nothing_int_charstar
,
2720 dwarf2out_end_epilogue
,
2721 dwarf2out_begin_function
,
2722 dwarf2out_end_function
, /* end_function */
2723 dwarf2out_register_main_translation_unit
,
2724 dwarf2out_function_decl
, /* function_decl */
2725 dwarf2out_early_global_decl
,
2726 dwarf2out_late_global_decl
,
2727 dwarf2out_type_decl
, /* type_decl */
2728 dwarf2out_imported_module_or_decl
,
2729 debug_nothing_tree
, /* deferred_inline_function */
2730 /* The DWARF 2 backend tries to reduce debugging bloat by not
2731 emitting the abstract description of inline functions until
2732 something tries to reference them. */
2733 dwarf2out_abstract_function
, /* outlining_inline_function */
2734 debug_nothing_rtx_code_label
, /* label */
2735 debug_nothing_int
, /* handle_pch */
2736 dwarf2out_var_location
,
2737 dwarf2out_size_function
, /* size_function */
2738 dwarf2out_switch_text_section
,
2740 1, /* start_end_main_source_file */
2741 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2744 const struct gcc_debug_hooks dwarf2_lineno_debug_hooks
=
2747 debug_nothing_charstar
,
2748 debug_nothing_charstar
,
2749 dwarf2out_assembly_start
,
2750 debug_nothing_int_charstar
,
2751 debug_nothing_int_charstar
,
2752 debug_nothing_int_charstar
,
2754 debug_nothing_int_int
, /* begin_block */
2755 debug_nothing_int_int
, /* end_block */
2756 debug_true_const_tree
, /* ignore_block */
2757 dwarf2out_source_line
, /* source_line */
2758 debug_nothing_int_int_charstar
, /* begin_prologue */
2759 debug_nothing_int_charstar
, /* end_prologue */
2760 debug_nothing_int_charstar
, /* begin_epilogue */
2761 debug_nothing_int_charstar
, /* end_epilogue */
2762 debug_nothing_tree
, /* begin_function */
2763 debug_nothing_int
, /* end_function */
2764 debug_nothing_tree
, /* register_main_translation_unit */
2765 debug_nothing_tree
, /* function_decl */
2766 debug_nothing_tree
, /* early_global_decl */
2767 debug_nothing_tree
, /* late_global_decl */
2768 debug_nothing_tree_int
, /* type_decl */
2769 debug_nothing_tree_tree_tree_bool_bool
,/* imported_module_or_decl */
2770 debug_nothing_tree
, /* deferred_inline_function */
2771 debug_nothing_tree
, /* outlining_inline_function */
2772 debug_nothing_rtx_code_label
, /* label */
2773 debug_nothing_int
, /* handle_pch */
2774 debug_nothing_rtx_insn
, /* var_location */
2775 debug_nothing_tree
, /* size_function */
2776 debug_nothing_void
, /* switch_text_section */
2777 debug_nothing_tree_tree
, /* set_name */
2778 0, /* start_end_main_source_file */
2779 TYPE_SYMTAB_IS_ADDRESS
/* tree_type_symtab_field */
2782 /* NOTE: In the comments in this file, many references are made to
2783 "Debugging Information Entries". This term is abbreviated as `DIE'
2784 throughout the remainder of this file. */
2786 /* An internal representation of the DWARF output is built, and then
2787 walked to generate the DWARF debugging info. The walk of the internal
2788 representation is done after the entire program has been compiled.
2789 The types below are used to describe the internal representation. */
2791 /* Whether to put type DIEs into their own section .debug_types instead
2792 of making them part of the .debug_info section. Only supported for
2793 Dwarf V4 or higher and the user didn't disable them through
2794 -fno-debug-types-section. It is more efficient to put them in a
2795 separate comdat sections since the linker will then be able to
2796 remove duplicates. But not all tools support .debug_types sections
2797 yet. For Dwarf V5 or higher .debug_types doesn't exist any more,
2798 it is DW_UT_type unit type in .debug_info section. */
2800 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2802 /* Various DIE's use offsets relative to the beginning of the
2803 .debug_info section to refer to each other. */
2805 typedef long int dw_offset
;
2807 struct comdat_type_node
;
2809 /* The entries in the line_info table more-or-less mirror the opcodes
2810 that are used in the real dwarf line table. Arrays of these entries
2811 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2814 enum dw_line_info_opcode
{
2815 /* Emit DW_LNE_set_address; the operand is the label index. */
2818 /* Emit a row to the matrix with the given line. This may be done
2819 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2823 /* Emit a DW_LNS_set_file. */
2826 /* Emit a DW_LNS_set_column. */
2829 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2832 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2833 LI_set_prologue_end
,
2834 LI_set_epilogue_begin
,
2836 /* Emit a DW_LNE_set_discriminator. */
2837 LI_set_discriminator
2840 typedef struct GTY(()) dw_line_info_struct
{
2841 enum dw_line_info_opcode opcode
;
2843 } dw_line_info_entry
;
2846 struct GTY(()) dw_line_info_table
{
2847 /* The label that marks the end of this section. */
2848 const char *end_label
;
2850 /* The values for the last row of the matrix, as collected in the table.
2851 These are used to minimize the changes to the next row. */
2852 unsigned int file_num
;
2853 unsigned int line_num
;
2854 unsigned int column_num
;
2859 vec
<dw_line_info_entry
, va_gc
> *entries
;
2863 /* Each DIE attribute has a field specifying the attribute kind,
2864 a link to the next attribute in the chain, and an attribute value.
2865 Attributes are typically linked below the DIE they modify. */
2867 typedef struct GTY(()) dw_attr_struct
{
2868 enum dwarf_attribute dw_attr
;
2869 dw_val_node dw_attr_val
;
2874 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2875 The children of each node form a circular list linked by
2876 die_sib. die_child points to the node *before* the "first" child node. */
2878 typedef struct GTY((chain_circular ("%h.die_sib"), for_user
)) die_struct
{
2879 union die_symbol_or_type_node
2881 const char * GTY ((tag ("0"))) die_symbol
;
2882 comdat_type_node
*GTY ((tag ("1"))) die_type_node
;
2884 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2885 vec
<dw_attr_node
, va_gc
> *die_attr
;
2886 dw_die_ref die_parent
;
2887 dw_die_ref die_child
;
2889 dw_die_ref die_definition
; /* ref from a specification to its definition */
2890 dw_offset die_offset
;
2891 unsigned long die_abbrev
;
2893 unsigned int decl_id
;
2894 enum dwarf_tag die_tag
;
2895 /* Die is used and must not be pruned as unused. */
2896 BOOL_BITFIELD die_perennial_p
: 1;
2897 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2898 /* Whether this DIE was removed from the DIE tree, for example via
2899 prune_unused_types. We don't consider those present from the
2900 DIE lookup routines. */
2901 BOOL_BITFIELD removed
: 1;
2902 /* Lots of spare bits. */
2906 /* Set to TRUE while dwarf2out_early_global_decl is running. */
2907 static bool early_dwarf
;
2908 static bool early_dwarf_finished
;
2909 struct set_early_dwarf
{
2911 set_early_dwarf () : saved(early_dwarf
)
2913 gcc_assert (! early_dwarf_finished
);
2916 ~set_early_dwarf () { early_dwarf
= saved
; }
2919 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2920 #define FOR_EACH_CHILD(die, c, expr) do { \
2921 c = die->die_child; \
2925 } while (c != die->die_child); \
2928 /* The pubname structure */
2930 typedef struct GTY(()) pubname_struct
{
2937 struct GTY(()) dw_ranges
{
2939 /* If this is positive, it's a block number, otherwise it's a
2940 bitwise-negated index into dw_ranges_by_label. */
2942 /* Index for the range list for DW_FORM_rnglistx. */
2943 unsigned int idx
: 31;
2944 /* True if this range might be possibly in a different section
2945 from previous entry. */
2946 unsigned int maybe_new_sec
: 1;
2949 /* A structure to hold a macinfo entry. */
2951 typedef struct GTY(()) macinfo_struct
{
2953 unsigned HOST_WIDE_INT lineno
;
2959 struct GTY(()) dw_ranges_by_label
{
2964 /* The comdat type node structure. */
2965 struct GTY(()) comdat_type_node
2967 dw_die_ref root_die
;
2968 dw_die_ref type_die
;
2969 dw_die_ref skeleton_die
;
2970 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2971 comdat_type_node
*next
;
2974 /* A list of DIEs for which we can't determine ancestry (parent_die
2975 field) just yet. Later in dwarf2out_finish we will fill in the
2977 typedef struct GTY(()) limbo_die_struct
{
2979 /* The tree for which this DIE was created. We use this to
2980 determine ancestry later. */
2982 struct limbo_die_struct
*next
;
2986 typedef struct skeleton_chain_struct
2990 struct skeleton_chain_struct
*parent
;
2992 skeleton_chain_node
;
2994 /* Define a macro which returns nonzero for a TYPE_DECL which was
2995 implicitly generated for a type.
2997 Note that, unlike the C front-end (which generates a NULL named
2998 TYPE_DECL node for each complete tagged type, each array type,
2999 and each function type node created) the C++ front-end generates
3000 a _named_ TYPE_DECL node for each tagged type node created.
3001 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3002 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
3003 front-end, but for each type, tagged or not. */
3005 #define TYPE_DECL_IS_STUB(decl) \
3006 (DECL_NAME (decl) == NULL_TREE \
3007 || (DECL_ARTIFICIAL (decl) \
3008 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3009 /* This is necessary for stub decls that \
3010 appear in nested inline functions. */ \
3011 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3012 && (decl_ultimate_origin (decl) \
3013 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3015 /* Information concerning the compilation unit's programming
3016 language, and compiler version. */
3018 /* Fixed size portion of the DWARF compilation unit header. */
3019 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3020 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE \
3021 + (dwarf_version >= 5 ? 4 : 3))
3023 /* Fixed size portion of the DWARF comdat type unit header. */
3024 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
3025 (DWARF_COMPILE_UNIT_HEADER_SIZE \
3026 + DWARF_TYPE_SIGNATURE_SIZE + DWARF_OFFSET_SIZE)
3028 /* Fixed size portion of the DWARF skeleton compilation unit header. */
3029 #define DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE \
3030 (DWARF_COMPILE_UNIT_HEADER_SIZE + (dwarf_version >= 5 ? 8 : 0))
3032 /* Fixed size portion of public names info. */
3033 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3035 /* Fixed size portion of the address range info. */
3036 #define DWARF_ARANGES_HEADER_SIZE \
3037 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3038 DWARF2_ADDR_SIZE * 2) \
3039 - DWARF_INITIAL_LENGTH_SIZE)
3041 /* Size of padding portion in the address range info. It must be
3042 aligned to twice the pointer size. */
3043 #define DWARF_ARANGES_PAD_SIZE \
3044 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3045 DWARF2_ADDR_SIZE * 2) \
3046 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3048 /* Use assembler line directives if available. */
3049 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3050 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3051 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3053 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3057 /* Minimum line offset in a special line info. opcode.
3058 This value was chosen to give a reasonable range of values. */
3059 #define DWARF_LINE_BASE -10
3061 /* First special line opcode - leave room for the standard opcodes. */
3062 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
3064 /* Range of line offsets in a special line info. opcode. */
3065 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3067 /* Flag that indicates the initial value of the is_stmt_start flag.
3068 In the present implementation, we do not mark any lines as
3069 the beginning of a source statement, because that information
3070 is not made available by the GCC front-end. */
3071 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3073 /* Maximum number of operations per instruction bundle. */
3074 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
3075 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
3078 /* This location is used by calc_die_sizes() to keep track
3079 the offset of each DIE within the .debug_info section. */
3080 static unsigned long next_die_offset
;
3082 /* Record the root of the DIE's built for the current compilation unit. */
3083 static GTY(()) dw_die_ref single_comp_unit_die
;
3085 /* A list of type DIEs that have been separated into comdat sections. */
3086 static GTY(()) comdat_type_node
*comdat_type_list
;
3088 /* A list of CU DIEs that have been separated. */
3089 static GTY(()) limbo_die_node
*cu_die_list
;
3091 /* A list of DIEs with a NULL parent waiting to be relocated. */
3092 static GTY(()) limbo_die_node
*limbo_die_list
;
3094 /* A list of DIEs for which we may have to generate
3095 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
3096 static GTY(()) limbo_die_node
*deferred_asm_name
;
3098 struct dwarf_file_hasher
: ggc_ptr_hash
<dwarf_file_data
>
3100 typedef const char *compare_type
;
3102 static hashval_t
hash (dwarf_file_data
*);
3103 static bool equal (dwarf_file_data
*, const char *);
3106 /* Filenames referenced by this compilation unit. */
3107 static GTY(()) hash_table
<dwarf_file_hasher
> *file_table
;
3109 struct decl_die_hasher
: ggc_ptr_hash
<die_node
>
3111 typedef tree compare_type
;
3113 static hashval_t
hash (die_node
*);
3114 static bool equal (die_node
*, tree
);
3116 /* A hash table of references to DIE's that describe declarations.
3117 The key is a DECL_UID() which is a unique number identifying each decl. */
3118 static GTY (()) hash_table
<decl_die_hasher
> *decl_die_table
;
3120 struct GTY ((for_user
)) variable_value_struct
{
3121 unsigned int decl_id
;
3122 vec
<dw_die_ref
, va_gc
> *dies
;
3125 struct variable_value_hasher
: ggc_ptr_hash
<variable_value_struct
>
3127 typedef tree compare_type
;
3129 static hashval_t
hash (variable_value_struct
*);
3130 static bool equal (variable_value_struct
*, tree
);
3132 /* A hash table of DIEs that contain DW_OP_GNU_variable_value with
3133 dw_val_class_decl_ref class, indexed by FUNCTION_DECLs which is
3134 DECL_CONTEXT of the referenced VAR_DECLs. */
3135 static GTY (()) hash_table
<variable_value_hasher
> *variable_value_hash
;
3137 struct block_die_hasher
: ggc_ptr_hash
<die_struct
>
3139 static hashval_t
hash (die_struct
*);
3140 static bool equal (die_struct
*, die_struct
*);
3143 /* A hash table of references to DIE's that describe COMMON blocks.
3144 The key is DECL_UID() ^ die_parent. */
3145 static GTY (()) hash_table
<block_die_hasher
> *common_block_die_table
;
3147 typedef struct GTY(()) die_arg_entry_struct
{
3153 /* Node of the variable location list. */
3154 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
3155 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
3156 EXPR_LIST chain. For small bitsizes, bitsize is encoded
3157 in mode of the EXPR_LIST node and first EXPR_LIST operand
3158 is either NOTE_INSN_VAR_LOCATION for a piece with a known
3159 location or NULL for padding. For larger bitsizes,
3160 mode is 0 and first operand is a CONCAT with bitsize
3161 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
3162 NULL as second operand. */
3164 const char * GTY (()) label
;
3165 struct var_loc_node
* GTY (()) next
;
3168 /* Variable location list. */
3169 struct GTY ((for_user
)) var_loc_list_def
{
3170 struct var_loc_node
* GTY (()) first
;
3172 /* Pointer to the last but one or last element of the
3173 chained list. If the list is empty, both first and
3174 last are NULL, if the list contains just one node
3175 or the last node certainly is not redundant, it points
3176 to the last node, otherwise points to the last but one.
3177 Do not mark it for GC because it is marked through the chain. */
3178 struct var_loc_node
* GTY ((skip ("%h"))) last
;
3180 /* Pointer to the last element before section switch,
3181 if NULL, either sections weren't switched or first
3182 is after section switch. */
3183 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
3185 /* DECL_UID of the variable decl. */
3186 unsigned int decl_id
;
3188 typedef struct var_loc_list_def var_loc_list
;
3190 /* Call argument location list. */
3191 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
3192 rtx
GTY (()) call_arg_loc_note
;
3193 const char * GTY (()) label
;
3194 tree
GTY (()) block
;
3196 rtx
GTY (()) symbol_ref
;
3197 struct call_arg_loc_node
* GTY (()) next
;
3201 struct decl_loc_hasher
: ggc_ptr_hash
<var_loc_list
>
3203 typedef const_tree compare_type
;
3205 static hashval_t
hash (var_loc_list
*);
3206 static bool equal (var_loc_list
*, const_tree
);
3209 /* Table of decl location linked lists. */
3210 static GTY (()) hash_table
<decl_loc_hasher
> *decl_loc_table
;
3212 /* Head and tail of call_arg_loc chain. */
3213 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
3214 static struct call_arg_loc_node
*call_arg_loc_last
;
3216 /* Number of call sites in the current function. */
3217 static int call_site_count
= -1;
3218 /* Number of tail call sites in the current function. */
3219 static int tail_call_site_count
= -1;
3221 /* A cached location list. */
3222 struct GTY ((for_user
)) cached_dw_loc_list_def
{
3223 /* The DECL_UID of the decl that this entry describes. */
3224 unsigned int decl_id
;
3226 /* The cached location list. */
3227 dw_loc_list_ref loc_list
;
3229 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
3231 struct dw_loc_list_hasher
: ggc_ptr_hash
<cached_dw_loc_list
>
3234 typedef const_tree compare_type
;
3236 static hashval_t
hash (cached_dw_loc_list
*);
3237 static bool equal (cached_dw_loc_list
*, const_tree
);
3240 /* Table of cached location lists. */
3241 static GTY (()) hash_table
<dw_loc_list_hasher
> *cached_dw_loc_list_table
;
3243 /* A vector of references to DIE's that are uniquely identified by their tag,
3244 presence/absence of children DIE's, and list of attribute/value pairs. */
3245 static GTY(()) vec
<dw_die_ref
, va_gc
> *abbrev_die_table
;
3247 /* A hash map to remember the stack usage for DWARF procedures. The value
3248 stored is the stack size difference between before the DWARF procedure
3249 invokation and after it returned. In other words, for a DWARF procedure
3250 that consumes N stack slots and that pushes M ones, this stores M - N. */
3251 static hash_map
<dw_die_ref
, int> *dwarf_proc_stack_usage_map
;
3253 /* A global counter for generating labels for line number data. */
3254 static unsigned int line_info_label_num
;
3256 /* The current table to which we should emit line number information
3257 for the current function. This will be set up at the beginning of
3258 assembly for the function. */
3259 static GTY(()) dw_line_info_table
*cur_line_info_table
;
3261 /* The two default tables of line number info. */
3262 static GTY(()) dw_line_info_table
*text_section_line_info
;
3263 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
3265 /* The set of all non-default tables of line number info. */
3266 static GTY(()) vec
<dw_line_info_table
*, va_gc
> *separate_line_info
;
3268 /* A flag to tell pubnames/types export if there is an info section to
3270 static bool info_section_emitted
;
3272 /* A pointer to the base of a table that contains a list of publicly
3273 accessible names. */
3274 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
3276 /* A pointer to the base of a table that contains a list of publicly
3277 accessible types. */
3278 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
3280 /* A pointer to the base of a table that contains a list of macro
3281 defines/undefines (and file start/end markers). */
3282 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
3284 /* True if .debug_macinfo or .debug_macros section is going to be
3286 #define have_macinfo \
3287 ((!XCOFF_DEBUGGING_INFO || HAVE_XCOFF_DWARF_EXTRAS) \
3288 && debug_info_level >= DINFO_LEVEL_VERBOSE \
3289 && !macinfo_table->is_empty ())
3291 /* Vector of dies for which we should generate .debug_ranges info. */
3292 static GTY (()) vec
<dw_ranges
, va_gc
> *ranges_table
;
3294 /* Vector of pairs of labels referenced in ranges_table. */
3295 static GTY (()) vec
<dw_ranges_by_label
, va_gc
> *ranges_by_label
;
3297 /* Whether we have location lists that need outputting */
3298 static GTY(()) bool have_location_lists
;
3300 /* Unique label counter. */
3301 static GTY(()) unsigned int loclabel_num
;
3303 /* Unique label counter for point-of-call tables. */
3304 static GTY(()) unsigned int poc_label_num
;
3306 /* The last file entry emitted by maybe_emit_file(). */
3307 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
3309 /* Number of internal labels generated by gen_internal_sym(). */
3310 static GTY(()) int label_num
;
3312 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
3314 /* Instances of generic types for which we need to generate debug
3315 info that describe their generic parameters and arguments. That
3316 generation needs to happen once all types are properly laid out so
3317 we do it at the end of compilation. */
3318 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
3320 /* Offset from the "steady-state frame pointer" to the frame base,
3321 within the current function. */
3322 static HOST_WIDE_INT frame_pointer_fb_offset
;
3323 static bool frame_pointer_fb_offset_valid
;
3325 static vec
<dw_die_ref
> base_types
;
3327 /* Flags to represent a set of attribute classes for attributes that represent
3328 a scalar value (bounds, pointers, ...). */
3331 dw_scalar_form_constant
= 0x01,
3332 dw_scalar_form_exprloc
= 0x02,
3333 dw_scalar_form_reference
= 0x04
3336 /* Forward declarations for functions defined in this file. */
3338 static int is_pseudo_reg (const_rtx
);
3339 static tree
type_main_variant (tree
);
3340 static int is_tagged_type (const_tree
);
3341 static const char *dwarf_tag_name (unsigned);
3342 static const char *dwarf_attr_name (unsigned);
3343 static const char *dwarf_form_name (unsigned);
3344 static tree
decl_ultimate_origin (const_tree
);
3345 static tree
decl_class_context (tree
);
3346 static void add_dwarf_attr (dw_die_ref
, dw_attr_node
*);
3347 static inline enum dw_val_class
AT_class (dw_attr_node
*);
3348 static inline unsigned int AT_index (dw_attr_node
*);
3349 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3350 static inline unsigned AT_flag (dw_attr_node
*);
3351 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3352 static inline HOST_WIDE_INT
AT_int (dw_attr_node
*);
3353 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3354 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_node
*);
3355 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
3356 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
3357 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3358 unsigned int, unsigned char *);
3359 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
3360 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3361 static inline const char *AT_string (dw_attr_node
*);
3362 static enum dwarf_form
AT_string_form (dw_attr_node
*);
3363 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3364 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3365 static inline dw_die_ref
AT_ref (dw_attr_node
*);
3366 static inline int AT_ref_external (dw_attr_node
*);
3367 static inline void set_AT_ref_external (dw_attr_node
*, int);
3368 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3369 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3370 static inline dw_loc_descr_ref
AT_loc (dw_attr_node
*);
3371 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3373 static inline dw_loc_list_ref
AT_loc_list (dw_attr_node
*);
3374 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
3375 static void remove_addr_table_entry (addr_table_entry
*);
3376 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
3377 static inline rtx
AT_addr (dw_attr_node
*);
3378 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3379 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3380 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3381 static void add_AT_loclistsptr (dw_die_ref
, enum dwarf_attribute
,
3383 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3384 unsigned HOST_WIDE_INT
);
3385 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3386 unsigned long, bool);
3387 static inline const char *AT_lbl (dw_attr_node
*);
3388 static dw_attr_node
*get_AT (dw_die_ref
, enum dwarf_attribute
);
3389 static const char *get_AT_low_pc (dw_die_ref
);
3390 static const char *get_AT_hi_pc (dw_die_ref
);
3391 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3392 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3393 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3394 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3395 static bool is_cxx (void);
3396 static bool is_cxx (const_tree
);
3397 static bool is_fortran (void);
3398 static bool is_ada (void);
3399 static bool remove_AT (dw_die_ref
, enum dwarf_attribute
);
3400 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3401 static void add_child_die (dw_die_ref
, dw_die_ref
);
3402 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3403 static dw_die_ref
lookup_type_die (tree
);
3404 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3405 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3406 static void equate_type_number_to_die (tree
, dw_die_ref
);
3407 static dw_die_ref
lookup_decl_die (tree
);
3408 static var_loc_list
*lookup_decl_loc (const_tree
);
3409 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3410 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3411 static void print_spaces (FILE *);
3412 static void print_die (dw_die_ref
, FILE *);
3413 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3414 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3415 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3416 static void attr_checksum (dw_attr_node
*, struct md5_ctx
*, int *);
3417 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3418 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3419 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3420 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3421 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_node
*,
3422 struct md5_ctx
*, int *);
3423 struct checksum_attributes
;
3424 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3425 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3426 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3427 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3428 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3429 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3430 static int same_attr_p (dw_attr_node
*, dw_attr_node
*, int *);
3431 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3432 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3433 static void compute_section_prefix (dw_die_ref
);
3434 static int is_type_die (dw_die_ref
);
3435 static int is_comdat_die (dw_die_ref
);
3436 static int is_symbol_die (dw_die_ref
);
3437 static inline bool is_template_instantiation (dw_die_ref
);
3438 static void assign_symbol_names (dw_die_ref
);
3439 static void break_out_includes (dw_die_ref
);
3440 static int is_declaration_die (dw_die_ref
);
3441 static int should_move_die_to_comdat (dw_die_ref
);
3442 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3443 static dw_die_ref
clone_die (dw_die_ref
);
3444 static dw_die_ref
clone_tree (dw_die_ref
);
3445 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3446 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3447 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3448 static dw_die_ref
generate_skeleton (dw_die_ref
);
3449 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3452 static void break_out_comdat_types (dw_die_ref
);
3453 static void copy_decls_for_unworthy_types (dw_die_ref
);
3455 static void add_sibling_attributes (dw_die_ref
);
3456 static void output_location_lists (dw_die_ref
);
3457 static int constant_size (unsigned HOST_WIDE_INT
);
3458 static unsigned long size_of_die (dw_die_ref
);
3459 static void calc_die_sizes (dw_die_ref
);
3460 static void calc_base_type_die_sizes (void);
3461 static void mark_dies (dw_die_ref
);
3462 static void unmark_dies (dw_die_ref
);
3463 static void unmark_all_dies (dw_die_ref
);
3464 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3465 static unsigned long size_of_aranges (void);
3466 static enum dwarf_form
value_format (dw_attr_node
*);
3467 static void output_value_format (dw_attr_node
*);
3468 static void output_abbrev_section (void);
3469 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3470 static void output_die_symbol (dw_die_ref
);
3471 static void output_die (dw_die_ref
);
3472 static void output_compilation_unit_header (enum dwarf_unit_type
);
3473 static void output_comp_unit (dw_die_ref
, int, const unsigned char *);
3474 static void output_comdat_type_unit (comdat_type_node
*);
3475 static const char *dwarf2_name (tree
, int);
3476 static void add_pubname (tree
, dw_die_ref
);
3477 static void add_enumerator_pubname (const char *, dw_die_ref
);
3478 static void add_pubname_string (const char *, dw_die_ref
);
3479 static void add_pubtype (tree
, dw_die_ref
);
3480 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3481 static void output_aranges (void);
3482 static unsigned int add_ranges (const_tree
, bool = false);
3483 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3485 static void output_ranges (void);
3486 static dw_line_info_table
*new_line_info_table (void);
3487 static void output_line_info (bool);
3488 static void output_file_names (void);
3489 static dw_die_ref
base_type_die (tree
, bool);
3490 static int is_base_type (tree
);
3491 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, tree
, dw_die_ref
);
3492 static int decl_quals (const_tree
);
3493 static dw_die_ref
modified_type_die (tree
, int, bool, dw_die_ref
);
3494 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3495 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3496 static int type_is_enum (const_tree
);
3497 static unsigned int dbx_reg_number (const_rtx
);
3498 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3499 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3500 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3501 enum var_init_status
);
3502 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3503 enum var_init_status
);
3504 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3505 enum var_init_status
);
3506 static int is_based_loc (const_rtx
);
3507 static bool resolve_one_addr (rtx
*);
3508 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3509 enum var_init_status
);
3510 static dw_loc_descr_ref
loc_descriptor (rtx
, machine_mode mode
,
3511 enum var_init_status
);
3512 struct loc_descr_context
;
3513 static void add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
);
3514 static void add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
);
3515 static dw_loc_list_ref
loc_list_from_tree (tree
, int,
3516 struct loc_descr_context
*);
3517 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int,
3518 struct loc_descr_context
*);
3519 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3520 static tree
field_type (const_tree
);
3521 static unsigned int simple_type_align_in_bits (const_tree
);
3522 static unsigned int simple_decl_align_in_bits (const_tree
);
3523 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3525 static dw_loc_descr_ref
field_byte_offset (const_tree
, struct vlr_context
*,
3527 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3529 static void add_data_member_location_attribute (dw_die_ref
, tree
,
3530 struct vlr_context
*);
3531 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3532 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3533 static void insert_wide_int (const wide_int
&, unsigned char *, int);
3534 static void insert_float (const_rtx
, unsigned char *);
3535 static rtx
rtl_for_decl_location (tree
);
3536 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool);
3537 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3538 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3539 static void add_name_attribute (dw_die_ref
, const char *);
3540 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3541 static void add_comp_dir_attribute (dw_die_ref
);
3542 static void add_scalar_info (dw_die_ref
, enum dwarf_attribute
, tree
, int,
3543 struct loc_descr_context
*);
3544 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
,
3545 struct loc_descr_context
*);
3546 static void add_subscript_info (dw_die_ref
, tree
, bool);
3547 static void add_byte_size_attribute (dw_die_ref
, tree
);
3548 static void add_alignment_attribute (dw_die_ref
, tree
);
3549 static inline void add_bit_offset_attribute (dw_die_ref
, tree
,
3550 struct vlr_context
*);
3551 static void add_bit_size_attribute (dw_die_ref
, tree
);
3552 static void add_prototyped_attribute (dw_die_ref
, tree
);
3553 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3554 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3555 static void add_src_coords_attributes (dw_die_ref
, tree
);
3556 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
, bool = false);
3557 static void add_discr_value (dw_die_ref
, dw_discr_value
*);
3558 static void add_discr_list (dw_die_ref
, dw_discr_list_ref
);
3559 static inline dw_discr_list_ref
AT_discr_list (dw_attr_node
*);
3560 static void push_decl_scope (tree
);
3561 static void pop_decl_scope (void);
3562 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3563 static inline int local_scope_p (dw_die_ref
);
3564 static inline int class_scope_p (dw_die_ref
);
3565 static inline int class_or_namespace_scope_p (dw_die_ref
);
3566 static void add_type_attribute (dw_die_ref
, tree
, int, bool, dw_die_ref
);
3567 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3568 static const char *type_tag (const_tree
);
3569 static tree
member_declared_type (const_tree
);
3571 static const char *decl_start_label (tree
);
3573 static void gen_array_type_die (tree
, dw_die_ref
);
3574 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3576 static void gen_entry_point_die (tree
, dw_die_ref
);
3578 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3579 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3580 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3581 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3582 static void gen_formal_types_die (tree
, dw_die_ref
);
3583 static void gen_subprogram_die (tree
, dw_die_ref
);
3584 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3585 static void gen_const_die (tree
, dw_die_ref
);
3586 static void gen_label_die (tree
, dw_die_ref
);
3587 static void gen_lexical_block_die (tree
, dw_die_ref
);
3588 static void gen_inlined_subroutine_die (tree
, dw_die_ref
);
3589 static void gen_field_die (tree
, struct vlr_context
*, dw_die_ref
);
3590 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3591 static dw_die_ref
gen_compile_unit_die (const char *);
3592 static void gen_inheritance_die (tree
, tree
, tree
, dw_die_ref
);
3593 static void gen_member_die (tree
, dw_die_ref
);
3594 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3595 enum debug_info_usage
);
3596 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3597 static void gen_typedef_die (tree
, dw_die_ref
);
3598 static void gen_type_die (tree
, dw_die_ref
);
3599 static void gen_block_die (tree
, dw_die_ref
);
3600 static void decls_for_scope (tree
, dw_die_ref
);
3601 static bool is_naming_typedef_decl (const_tree
);
3602 static inline dw_die_ref
get_context_die (tree
);
3603 static void gen_namespace_die (tree
, dw_die_ref
);
3604 static dw_die_ref
gen_namelist_decl (tree
, dw_die_ref
, tree
);
3605 static dw_die_ref
gen_decl_die (tree
, tree
, struct vlr_context
*, dw_die_ref
);
3606 static dw_die_ref
force_decl_die (tree
);
3607 static dw_die_ref
force_type_die (tree
);
3608 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3609 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3610 static struct dwarf_file_data
* lookup_filename (const char *);
3611 static void retry_incomplete_types (void);
3612 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3613 static void gen_generic_params_dies (tree
);
3614 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3615 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3616 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3617 static int file_info_cmp (const void *, const void *);
3618 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3619 const char *, const char *);
3620 static void output_loc_list (dw_loc_list_ref
);
3621 static char *gen_internal_sym (const char *);
3622 static bool want_pubnames (void);
3624 static void prune_unmark_dies (dw_die_ref
);
3625 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3626 static void prune_unused_types_mark (dw_die_ref
, int);
3627 static void prune_unused_types_walk (dw_die_ref
);
3628 static void prune_unused_types_walk_attribs (dw_die_ref
);
3629 static void prune_unused_types_prune (dw_die_ref
);
3630 static void prune_unused_types (void);
3631 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3632 static inline const char *AT_vms_delta1 (dw_attr_node
*);
3633 static inline const char *AT_vms_delta2 (dw_attr_node
*);
3634 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3635 const char *, const char *);
3636 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3637 static void gen_remaining_tmpl_value_param_die_attribute (void);
3638 static bool generic_type_p (tree
);
3639 static void schedule_generic_params_dies_gen (tree t
);
3640 static void gen_scheduled_generic_parms_dies (void);
3641 static void resolve_variable_values (void);
3643 static const char *comp_dir_string (void);
3645 static void hash_loc_operands (dw_loc_descr_ref
, inchash::hash
&);
3647 /* enum for tracking thread-local variables whose address is really an offset
3648 relative to the TLS pointer, which will need link-time relocation, but will
3649 not need relocation by the DWARF consumer. */
3657 /* Return the operator to use for an address of a variable. For dtprel_true, we
3658 use DW_OP_const*. For regular variables, which need both link-time
3659 relocation and consumer-level relocation (e.g., to account for shared objects
3660 loaded at a random address), we use DW_OP_addr*. */
3662 static inline enum dwarf_location_atom
3663 dw_addr_op (enum dtprel_bool dtprel
)
3665 if (dtprel
== dtprel_true
)
3666 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3667 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3669 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3672 /* Return a pointer to a newly allocated address location description. If
3673 dwarf_split_debug_info is true, then record the address with the appropriate
3675 static inline dw_loc_descr_ref
3676 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3678 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3680 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3681 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3682 ref
->dtprel
= dtprel
;
3683 if (dwarf_split_debug_info
)
3684 ref
->dw_loc_oprnd1
.val_entry
3685 = add_addr_table_entry (addr
,
3686 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3688 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3693 /* Section names used to hold DWARF debugging information. */
3695 #ifndef DEBUG_INFO_SECTION
3696 #define DEBUG_INFO_SECTION ".debug_info"
3698 #ifndef DEBUG_DWO_INFO_SECTION
3699 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3701 #ifndef DEBUG_ABBREV_SECTION
3702 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3704 #ifndef DEBUG_DWO_ABBREV_SECTION
3705 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3707 #ifndef DEBUG_ARANGES_SECTION
3708 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3710 #ifndef DEBUG_ADDR_SECTION
3711 #define DEBUG_ADDR_SECTION ".debug_addr"
3713 #ifndef DEBUG_MACINFO_SECTION
3714 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3716 #ifndef DEBUG_DWO_MACINFO_SECTION
3717 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3719 #ifndef DEBUG_DWO_MACRO_SECTION
3720 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3722 #ifndef DEBUG_MACRO_SECTION
3723 #define DEBUG_MACRO_SECTION ".debug_macro"
3725 #ifndef DEBUG_LINE_SECTION
3726 #define DEBUG_LINE_SECTION ".debug_line"
3728 #ifndef DEBUG_DWO_LINE_SECTION
3729 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3731 #ifndef DEBUG_LOC_SECTION
3732 #define DEBUG_LOC_SECTION ".debug_loc"
3734 #ifndef DEBUG_DWO_LOC_SECTION
3735 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3737 #ifndef DEBUG_LOCLISTS_SECTION
3738 #define DEBUG_LOCLISTS_SECTION ".debug_loclists"
3740 #ifndef DEBUG_DWO_LOCLISTS_SECTION
3741 #define DEBUG_DWO_LOCLISTS_SECTION ".debug_loclists.dwo"
3743 #ifndef DEBUG_PUBNAMES_SECTION
3744 #define DEBUG_PUBNAMES_SECTION \
3745 ((debug_generate_pub_sections == 2) \
3746 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3748 #ifndef DEBUG_PUBTYPES_SECTION
3749 #define DEBUG_PUBTYPES_SECTION \
3750 ((debug_generate_pub_sections == 2) \
3751 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3753 #ifndef DEBUG_STR_OFFSETS_SECTION
3754 #define DEBUG_STR_OFFSETS_SECTION ".debug_str_offsets"
3756 #ifndef DEBUG_DWO_STR_OFFSETS_SECTION
3757 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3759 #ifndef DEBUG_STR_DWO_SECTION
3760 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3762 #ifndef DEBUG_STR_SECTION
3763 #define DEBUG_STR_SECTION ".debug_str"
3765 #ifndef DEBUG_RANGES_SECTION
3766 #define DEBUG_RANGES_SECTION ".debug_ranges"
3768 #ifndef DEBUG_RNGLISTS_SECTION
3769 #define DEBUG_RNGLISTS_SECTION ".debug_rnglists"
3771 #ifndef DEBUG_LINE_STR_SECTION
3772 #define DEBUG_LINE_STR_SECTION ".debug_line_str"
3775 /* Standard ELF section names for compiled code and data. */
3776 #ifndef TEXT_SECTION_NAME
3777 #define TEXT_SECTION_NAME ".text"
3780 /* Section flags for .debug_str section. */
3781 #define DEBUG_STR_SECTION_FLAGS \
3782 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3783 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3786 /* Section flags for .debug_str.dwo section. */
3787 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3789 /* Labels we insert at beginning sections we can reference instead of
3790 the section names themselves. */
3792 #ifndef TEXT_SECTION_LABEL
3793 #define TEXT_SECTION_LABEL "Ltext"
3795 #ifndef COLD_TEXT_SECTION_LABEL
3796 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3798 #ifndef DEBUG_LINE_SECTION_LABEL
3799 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3801 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3802 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3804 #ifndef DEBUG_INFO_SECTION_LABEL
3805 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3807 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3808 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3810 #ifndef DEBUG_ABBREV_SECTION_LABEL
3811 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3813 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3814 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3816 #ifndef DEBUG_ADDR_SECTION_LABEL
3817 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3819 #ifndef DEBUG_LOC_SECTION_LABEL
3820 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3822 #ifndef DEBUG_RANGES_SECTION_LABEL
3823 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3825 #ifndef DEBUG_MACINFO_SECTION_LABEL
3826 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3828 #ifndef DEBUG_MACRO_SECTION_LABEL
3829 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3831 #define SKELETON_COMP_DIE_ABBREV 1
3832 #define SKELETON_TYPE_DIE_ABBREV 2
3834 /* Definitions of defaults for formats and names of various special
3835 (artificial) labels which may be generated within this file (when the -g
3836 options is used and DWARF2_DEBUGGING_INFO is in effect.
3837 If necessary, these may be overridden from within the tm.h file, but
3838 typically, overriding these defaults is unnecessary. */
3840 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3841 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3842 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3843 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3844 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3845 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3846 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3847 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3848 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3849 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3850 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3851 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3852 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3853 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3854 static char ranges_base_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3856 #ifndef TEXT_END_LABEL
3857 #define TEXT_END_LABEL "Letext"
3859 #ifndef COLD_END_LABEL
3860 #define COLD_END_LABEL "Letext_cold"
3862 #ifndef BLOCK_BEGIN_LABEL
3863 #define BLOCK_BEGIN_LABEL "LBB"
3865 #ifndef BLOCK_END_LABEL
3866 #define BLOCK_END_LABEL "LBE"
3868 #ifndef LINE_CODE_LABEL
3869 #define LINE_CODE_LABEL "LM"
3873 /* Return the root of the DIE's built for the current compilation unit. */
3875 comp_unit_die (void)
3877 if (!single_comp_unit_die
)
3878 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3879 return single_comp_unit_die
;
3882 /* We allow a language front-end to designate a function that is to be
3883 called to "demangle" any name before it is put into a DIE. */
3885 static const char *(*demangle_name_func
) (const char *);
3888 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3890 demangle_name_func
= func
;
3893 /* Test if rtl node points to a pseudo register. */
3896 is_pseudo_reg (const_rtx rtl
)
3898 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3899 || (GET_CODE (rtl
) == SUBREG
3900 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3903 /* Return a reference to a type, with its const and volatile qualifiers
3907 type_main_variant (tree type
)
3909 type
= TYPE_MAIN_VARIANT (type
);
3911 /* ??? There really should be only one main variant among any group of
3912 variants of a given type (and all of the MAIN_VARIANT values for all
3913 members of the group should point to that one type) but sometimes the C
3914 front-end messes this up for array types, so we work around that bug
3916 if (TREE_CODE (type
) == ARRAY_TYPE
)
3917 while (type
!= TYPE_MAIN_VARIANT (type
))
3918 type
= TYPE_MAIN_VARIANT (type
);
3923 /* Return nonzero if the given type node represents a tagged type. */
3926 is_tagged_type (const_tree type
)
3928 enum tree_code code
= TREE_CODE (type
);
3930 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3931 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3934 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3937 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3939 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3942 /* Return die_offset of a DIE reference to a base type. */
3944 static unsigned long int
3945 get_base_type_offset (dw_die_ref ref
)
3947 if (ref
->die_offset
)
3948 return ref
->die_offset
;
3949 if (comp_unit_die ()->die_abbrev
)
3951 calc_base_type_die_sizes ();
3952 gcc_assert (ref
->die_offset
);
3954 return ref
->die_offset
;
3957 /* Return die_offset of a DIE reference other than base type. */
3959 static unsigned long int
3960 get_ref_die_offset (dw_die_ref ref
)
3962 gcc_assert (ref
->die_offset
);
3963 return ref
->die_offset
;
3966 /* Convert a DIE tag into its string name. */
3969 dwarf_tag_name (unsigned int tag
)
3971 const char *name
= get_DW_TAG_name (tag
);
3976 return "DW_TAG_<unknown>";
3979 /* Convert a DWARF attribute code into its string name. */
3982 dwarf_attr_name (unsigned int attr
)
3988 #if VMS_DEBUGGING_INFO
3989 case DW_AT_HP_prologue
:
3990 return "DW_AT_HP_prologue";
3992 case DW_AT_MIPS_loop_unroll_factor
:
3993 return "DW_AT_MIPS_loop_unroll_factor";
3996 #if VMS_DEBUGGING_INFO
3997 case DW_AT_HP_epilogue
:
3998 return "DW_AT_HP_epilogue";
4000 case DW_AT_MIPS_stride
:
4001 return "DW_AT_MIPS_stride";
4005 name
= get_DW_AT_name (attr
);
4010 return "DW_AT_<unknown>";
4013 /* Convert a DWARF value form code into its string name. */
4016 dwarf_form_name (unsigned int form
)
4018 const char *name
= get_DW_FORM_name (form
);
4023 return "DW_FORM_<unknown>";
4026 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4027 instance of an inlined instance of a decl which is local to an inline
4028 function, so we have to trace all of the way back through the origin chain
4029 to find out what sort of node actually served as the original seed for the
4033 decl_ultimate_origin (const_tree decl
)
4035 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
4038 /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
4039 we're trying to output the abstract instance of this function. */
4040 if (DECL_ABSTRACT_P (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4043 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4044 most distant ancestor, this should never happen. */
4045 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
4047 return DECL_ABSTRACT_ORIGIN (decl
);
4050 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4051 of a virtual function may refer to a base class, so we check the 'this'
4055 decl_class_context (tree decl
)
4057 tree context
= NULL_TREE
;
4059 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4060 context
= DECL_CONTEXT (decl
);
4062 context
= TYPE_MAIN_VARIANT
4063 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4065 if (context
&& !TYPE_P (context
))
4066 context
= NULL_TREE
;
4071 /* Add an attribute/value pair to a DIE. */
4074 add_dwarf_attr (dw_die_ref die
, dw_attr_node
*attr
)
4076 /* Maybe this should be an assert? */
4080 vec_safe_reserve (die
->die_attr
, 1);
4081 vec_safe_push (die
->die_attr
, *attr
);
4084 static inline enum dw_val_class
4085 AT_class (dw_attr_node
*a
)
4087 return a
->dw_attr_val
.val_class
;
4090 /* Return the index for any attribute that will be referenced with a
4091 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
4092 are stored in dw_attr_val.v.val_str for reference counting
4095 static inline unsigned int
4096 AT_index (dw_attr_node
*a
)
4098 if (AT_class (a
) == dw_val_class_str
)
4099 return a
->dw_attr_val
.v
.val_str
->index
;
4100 else if (a
->dw_attr_val
.val_entry
!= NULL
)
4101 return a
->dw_attr_val
.val_entry
->index
;
4105 /* Add a flag value attribute to a DIE. */
4108 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
4112 attr
.dw_attr
= attr_kind
;
4113 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
4114 attr
.dw_attr_val
.val_entry
= NULL
;
4115 attr
.dw_attr_val
.v
.val_flag
= flag
;
4116 add_dwarf_attr (die
, &attr
);
4119 static inline unsigned
4120 AT_flag (dw_attr_node
*a
)
4122 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
4123 return a
->dw_attr_val
.v
.val_flag
;
4126 /* Add a signed integer attribute value to a DIE. */
4129 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
4133 attr
.dw_attr
= attr_kind
;
4134 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
4135 attr
.dw_attr_val
.val_entry
= NULL
;
4136 attr
.dw_attr_val
.v
.val_int
= int_val
;
4137 add_dwarf_attr (die
, &attr
);
4140 static inline HOST_WIDE_INT
4141 AT_int (dw_attr_node
*a
)
4143 gcc_assert (a
&& (AT_class (a
) == dw_val_class_const
4144 || AT_class (a
) == dw_val_class_const_implicit
));
4145 return a
->dw_attr_val
.v
.val_int
;
4148 /* Add an unsigned integer attribute value to a DIE. */
4151 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4152 unsigned HOST_WIDE_INT unsigned_val
)
4156 attr
.dw_attr
= attr_kind
;
4157 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4158 attr
.dw_attr_val
.val_entry
= NULL
;
4159 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4160 add_dwarf_attr (die
, &attr
);
4163 static inline unsigned HOST_WIDE_INT
4164 AT_unsigned (dw_attr_node
*a
)
4166 gcc_assert (a
&& (AT_class (a
) == dw_val_class_unsigned_const
4167 || AT_class (a
) == dw_val_class_unsigned_const_implicit
));
4168 return a
->dw_attr_val
.v
.val_unsigned
;
4171 /* Add an unsigned wide integer attribute value to a DIE. */
4174 add_AT_wide (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4179 attr
.dw_attr
= attr_kind
;
4180 attr
.dw_attr_val
.val_class
= dw_val_class_wide_int
;
4181 attr
.dw_attr_val
.val_entry
= NULL
;
4182 attr
.dw_attr_val
.v
.val_wide
= ggc_alloc
<wide_int
> ();
4183 *attr
.dw_attr_val
.v
.val_wide
= w
;
4184 add_dwarf_attr (die
, &attr
);
4187 /* Add an unsigned double integer attribute value to a DIE. */
4190 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4191 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
4195 attr
.dw_attr
= attr_kind
;
4196 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
4197 attr
.dw_attr_val
.val_entry
= NULL
;
4198 attr
.dw_attr_val
.v
.val_double
.high
= high
;
4199 attr
.dw_attr_val
.v
.val_double
.low
= low
;
4200 add_dwarf_attr (die
, &attr
);
4203 /* Add a floating point attribute value to a DIE and return it. */
4206 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4207 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
4211 attr
.dw_attr
= attr_kind
;
4212 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
4213 attr
.dw_attr_val
.val_entry
= NULL
;
4214 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
4215 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
4216 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
4217 add_dwarf_attr (die
, &attr
);
4220 /* Add an 8-byte data attribute value to a DIE. */
4223 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4224 unsigned char data8
[8])
4228 attr
.dw_attr
= attr_kind
;
4229 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
4230 attr
.dw_attr_val
.val_entry
= NULL
;
4231 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
4232 add_dwarf_attr (die
, &attr
);
4235 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
4236 dwarf_split_debug_info, address attributes in dies destined for the
4237 final executable have force_direct set to avoid using indexed
4241 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
4247 lbl_id
= xstrdup (lbl_low
);
4248 attr
.dw_attr
= DW_AT_low_pc
;
4249 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4250 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4251 if (dwarf_split_debug_info
&& !force_direct
)
4252 attr
.dw_attr_val
.val_entry
4253 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4255 attr
.dw_attr_val
.val_entry
= NULL
;
4256 add_dwarf_attr (die
, &attr
);
4258 attr
.dw_attr
= DW_AT_high_pc
;
4259 if (dwarf_version
< 4)
4260 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4262 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
4263 lbl_id
= xstrdup (lbl_high
);
4264 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4265 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
4266 && dwarf_split_debug_info
&& !force_direct
)
4267 attr
.dw_attr_val
.val_entry
4268 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4270 attr
.dw_attr_val
.val_entry
= NULL
;
4271 add_dwarf_attr (die
, &attr
);
4274 /* Hash and equality functions for debug_str_hash. */
4277 indirect_string_hasher::hash (indirect_string_node
*x
)
4279 return htab_hash_string (x
->str
);
4283 indirect_string_hasher::equal (indirect_string_node
*x1
, const char *x2
)
4285 return strcmp (x1
->str
, x2
) == 0;
4288 /* Add STR to the given string hash table. */
4290 static struct indirect_string_node
*
4291 find_AT_string_in_table (const char *str
,
4292 hash_table
<indirect_string_hasher
> *table
)
4294 struct indirect_string_node
*node
;
4296 indirect_string_node
**slot
4297 = table
->find_slot_with_hash (str
, htab_hash_string (str
), INSERT
);
4300 node
= ggc_cleared_alloc
<indirect_string_node
> ();
4301 node
->str
= ggc_strdup (str
);
4311 /* Add STR to the indirect string hash table. */
4313 static struct indirect_string_node
*
4314 find_AT_string (const char *str
)
4316 if (! debug_str_hash
)
4317 debug_str_hash
= hash_table
<indirect_string_hasher
>::create_ggc (10);
4319 return find_AT_string_in_table (str
, debug_str_hash
);
4322 /* Add a string attribute value to a DIE. */
4325 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4328 struct indirect_string_node
*node
;
4330 node
= find_AT_string (str
);
4332 attr
.dw_attr
= attr_kind
;
4333 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4334 attr
.dw_attr_val
.val_entry
= NULL
;
4335 attr
.dw_attr_val
.v
.val_str
= node
;
4336 add_dwarf_attr (die
, &attr
);
4339 static inline const char *
4340 AT_string (dw_attr_node
*a
)
4342 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4343 return a
->dw_attr_val
.v
.val_str
->str
;
4346 /* Call this function directly to bypass AT_string_form's logic to put
4347 the string inline in the die. */
4350 set_indirect_string (struct indirect_string_node
*node
)
4352 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4353 /* Already indirect is a no op. */
4354 if (node
->form
== DW_FORM_strp
4355 || node
->form
== DW_FORM_line_strp
4356 || node
->form
== DW_FORM_GNU_str_index
)
4358 gcc_assert (node
->label
);
4361 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4362 ++dw2_string_counter
;
4363 node
->label
= xstrdup (label
);
4365 if (!dwarf_split_debug_info
)
4367 node
->form
= DW_FORM_strp
;
4368 node
->index
= NOT_INDEXED
;
4372 node
->form
= DW_FORM_GNU_str_index
;
4373 node
->index
= NO_INDEX_ASSIGNED
;
4377 /* Find out whether a string should be output inline in DIE
4378 or out-of-line in .debug_str section. */
4380 static enum dwarf_form
4381 find_string_form (struct indirect_string_node
*node
)
4388 len
= strlen (node
->str
) + 1;
4390 /* If the string is shorter or equal to the size of the reference, it is
4391 always better to put it inline. */
4392 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4393 return node
->form
= DW_FORM_string
;
4395 /* If we cannot expect the linker to merge strings in .debug_str
4396 section, only put it into .debug_str if it is worth even in this
4398 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4399 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4400 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
4401 return node
->form
= DW_FORM_string
;
4403 set_indirect_string (node
);
4408 /* Find out whether the string referenced from the attribute should be
4409 output inline in DIE or out-of-line in .debug_str section. */
4411 static enum dwarf_form
4412 AT_string_form (dw_attr_node
*a
)
4414 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4415 return find_string_form (a
->dw_attr_val
.v
.val_str
);
4418 /* Add a DIE reference attribute value to a DIE. */
4421 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4424 gcc_checking_assert (targ_die
!= NULL
);
4426 /* With LTO we can end up trying to reference something we didn't create
4427 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4428 if (targ_die
== NULL
)
4431 attr
.dw_attr
= attr_kind
;
4432 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4433 attr
.dw_attr_val
.val_entry
= NULL
;
4434 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4435 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4436 add_dwarf_attr (die
, &attr
);
4439 /* Change DIE reference REF to point to NEW_DIE instead. */
4442 change_AT_die_ref (dw_attr_node
*ref
, dw_die_ref new_die
)
4444 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4445 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4446 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4449 /* Add an AT_specification attribute to a DIE, and also make the back
4450 pointer from the specification to the definition. */
4453 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4455 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4456 gcc_assert (!targ_die
->die_definition
);
4457 targ_die
->die_definition
= die
;
4460 static inline dw_die_ref
4461 AT_ref (dw_attr_node
*a
)
4463 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4464 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4468 AT_ref_external (dw_attr_node
*a
)
4470 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4471 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4477 set_AT_ref_external (dw_attr_node
*a
, int i
)
4479 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4480 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4483 /* Add an FDE reference attribute value to a DIE. */
4486 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4490 attr
.dw_attr
= attr_kind
;
4491 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4492 attr
.dw_attr_val
.val_entry
= NULL
;
4493 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4494 add_dwarf_attr (die
, &attr
);
4497 /* Add a location description attribute value to a DIE. */
4500 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4504 attr
.dw_attr
= attr_kind
;
4505 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4506 attr
.dw_attr_val
.val_entry
= NULL
;
4507 attr
.dw_attr_val
.v
.val_loc
= loc
;
4508 add_dwarf_attr (die
, &attr
);
4511 static inline dw_loc_descr_ref
4512 AT_loc (dw_attr_node
*a
)
4514 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4515 return a
->dw_attr_val
.v
.val_loc
;
4519 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4523 if (XCOFF_DEBUGGING_INFO
&& !HAVE_XCOFF_DWARF_EXTRAS
)
4526 attr
.dw_attr
= attr_kind
;
4527 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4528 attr
.dw_attr_val
.val_entry
= NULL
;
4529 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4530 add_dwarf_attr (die
, &attr
);
4531 have_location_lists
= true;
4534 static inline dw_loc_list_ref
4535 AT_loc_list (dw_attr_node
*a
)
4537 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4538 return a
->dw_attr_val
.v
.val_loc_list
;
4541 static inline dw_loc_list_ref
*
4542 AT_loc_list_ptr (dw_attr_node
*a
)
4544 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4545 return &a
->dw_attr_val
.v
.val_loc_list
;
4548 struct addr_hasher
: ggc_ptr_hash
<addr_table_entry
>
4550 static hashval_t
hash (addr_table_entry
*);
4551 static bool equal (addr_table_entry
*, addr_table_entry
*);
4554 /* Table of entries into the .debug_addr section. */
4556 static GTY (()) hash_table
<addr_hasher
> *addr_index_table
;
4558 /* Hash an address_table_entry. */
4561 addr_hasher::hash (addr_table_entry
*a
)
4563 inchash::hash hstate
;
4569 case ate_kind_rtx_dtprel
:
4572 case ate_kind_label
:
4573 return htab_hash_string (a
->addr
.label
);
4577 inchash::add_rtx (a
->addr
.rtl
, hstate
);
4578 return hstate
.end ();
4581 /* Determine equality for two address_table_entries. */
4584 addr_hasher::equal (addr_table_entry
*a1
, addr_table_entry
*a2
)
4586 if (a1
->kind
!= a2
->kind
)
4591 case ate_kind_rtx_dtprel
:
4592 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4593 case ate_kind_label
:
4594 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4600 /* Initialize an addr_table_entry. */
4603 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4609 case ate_kind_rtx_dtprel
:
4610 e
->addr
.rtl
= (rtx
) addr
;
4612 case ate_kind_label
:
4613 e
->addr
.label
= (char *) addr
;
4617 e
->index
= NO_INDEX_ASSIGNED
;
4620 /* Add attr to the address table entry to the table. Defer setting an
4621 index until output time. */
4623 static addr_table_entry
*
4624 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4626 addr_table_entry
*node
;
4627 addr_table_entry finder
;
4629 gcc_assert (dwarf_split_debug_info
);
4630 if (! addr_index_table
)
4631 addr_index_table
= hash_table
<addr_hasher
>::create_ggc (10);
4632 init_addr_table_entry (&finder
, kind
, addr
);
4633 addr_table_entry
**slot
= addr_index_table
->find_slot (&finder
, INSERT
);
4635 if (*slot
== HTAB_EMPTY_ENTRY
)
4637 node
= ggc_cleared_alloc
<addr_table_entry
> ();
4638 init_addr_table_entry (node
, kind
, addr
);
4648 /* Remove an entry from the addr table by decrementing its refcount.
4649 Strictly, decrementing the refcount would be enough, but the
4650 assertion that the entry is actually in the table has found
4654 remove_addr_table_entry (addr_table_entry
*entry
)
4656 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4657 /* After an index is assigned, the table is frozen. */
4658 gcc_assert (entry
->refcount
> 0 && entry
->index
== NO_INDEX_ASSIGNED
);
4662 /* Given a location list, remove all addresses it refers to from the
4666 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4668 for (; descr
; descr
= descr
->dw_loc_next
)
4669 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4671 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4672 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4676 /* A helper function for dwarf2out_finish called through
4677 htab_traverse. Assign an addr_table_entry its index. All entries
4678 must be collected into the table when this function is called,
4679 because the indexing code relies on htab_traverse to traverse nodes
4680 in the same order for each run. */
4683 index_addr_table_entry (addr_table_entry
**h
, unsigned int *index
)
4685 addr_table_entry
*node
= *h
;
4687 /* Don't index unreferenced nodes. */
4688 if (node
->refcount
== 0)
4691 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
4692 node
->index
= *index
;
4698 /* Add an address constant attribute value to a DIE. When using
4699 dwarf_split_debug_info, address attributes in dies destined for the
4700 final executable should be direct references--setting the parameter
4701 force_direct ensures this behavior. */
4704 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4709 attr
.dw_attr
= attr_kind
;
4710 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4711 attr
.dw_attr_val
.v
.val_addr
= addr
;
4712 if (dwarf_split_debug_info
&& !force_direct
)
4713 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4715 attr
.dw_attr_val
.val_entry
= NULL
;
4716 add_dwarf_attr (die
, &attr
);
4719 /* Get the RTX from to an address DIE attribute. */
4722 AT_addr (dw_attr_node
*a
)
4724 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4725 return a
->dw_attr_val
.v
.val_addr
;
4728 /* Add a file attribute value to a DIE. */
4731 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4732 struct dwarf_file_data
*fd
)
4736 attr
.dw_attr
= attr_kind
;
4737 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4738 attr
.dw_attr_val
.val_entry
= NULL
;
4739 attr
.dw_attr_val
.v
.val_file
= fd
;
4740 add_dwarf_attr (die
, &attr
);
4743 /* Get the dwarf_file_data from a file DIE attribute. */
4745 static inline struct dwarf_file_data
*
4746 AT_file (dw_attr_node
*a
)
4748 gcc_assert (a
&& (AT_class (a
) == dw_val_class_file
4749 || AT_class (a
) == dw_val_class_file_implicit
));
4750 return a
->dw_attr_val
.v
.val_file
;
4753 /* Add a vms delta attribute value to a DIE. */
4756 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4757 const char *lbl1
, const char *lbl2
)
4761 attr
.dw_attr
= attr_kind
;
4762 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4763 attr
.dw_attr_val
.val_entry
= NULL
;
4764 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4765 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4766 add_dwarf_attr (die
, &attr
);
4769 /* Add a label identifier attribute value to a DIE. */
4772 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4777 attr
.dw_attr
= attr_kind
;
4778 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4779 attr
.dw_attr_val
.val_entry
= NULL
;
4780 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4781 if (dwarf_split_debug_info
)
4782 attr
.dw_attr_val
.val_entry
4783 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4785 add_dwarf_attr (die
, &attr
);
4788 /* Add a section offset attribute value to a DIE, an offset into the
4789 debug_line section. */
4792 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4797 attr
.dw_attr
= attr_kind
;
4798 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4799 attr
.dw_attr_val
.val_entry
= NULL
;
4800 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4801 add_dwarf_attr (die
, &attr
);
4804 /* Add a section offset attribute value to a DIE, an offset into the
4805 debug_loclists section. */
4808 add_AT_loclistsptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4813 attr
.dw_attr
= attr_kind
;
4814 attr
.dw_attr_val
.val_class
= dw_val_class_loclistsptr
;
4815 attr
.dw_attr_val
.val_entry
= NULL
;
4816 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4817 add_dwarf_attr (die
, &attr
);
4820 /* Add a section offset attribute value to a DIE, an offset into the
4821 debug_macinfo section. */
4824 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4829 attr
.dw_attr
= attr_kind
;
4830 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4831 attr
.dw_attr_val
.val_entry
= NULL
;
4832 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4833 add_dwarf_attr (die
, &attr
);
4836 /* Add an offset attribute value to a DIE. */
4839 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4840 unsigned HOST_WIDE_INT offset
)
4844 attr
.dw_attr
= attr_kind
;
4845 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4846 attr
.dw_attr_val
.val_entry
= NULL
;
4847 attr
.dw_attr_val
.v
.val_offset
= offset
;
4848 add_dwarf_attr (die
, &attr
);
4851 /* Add a range_list attribute value to a DIE. When using
4852 dwarf_split_debug_info, address attributes in dies destined for the
4853 final executable should be direct references--setting the parameter
4854 force_direct ensures this behavior. */
4856 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4857 #define RELOCATED_OFFSET (NULL)
4860 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4861 long unsigned int offset
, bool force_direct
)
4865 attr
.dw_attr
= attr_kind
;
4866 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4867 /* For the range_list attribute, use val_entry to store whether the
4868 offset should follow split-debug-info or normal semantics. This
4869 value is read in output_range_list_offset. */
4870 if (dwarf_split_debug_info
&& !force_direct
)
4871 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4873 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4874 attr
.dw_attr_val
.v
.val_offset
= offset
;
4875 add_dwarf_attr (die
, &attr
);
4878 /* Return the start label of a delta attribute. */
4880 static inline const char *
4881 AT_vms_delta1 (dw_attr_node
*a
)
4883 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4884 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4887 /* Return the end label of a delta attribute. */
4889 static inline const char *
4890 AT_vms_delta2 (dw_attr_node
*a
)
4892 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4893 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4896 static inline const char *
4897 AT_lbl (dw_attr_node
*a
)
4899 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4900 || AT_class (a
) == dw_val_class_lineptr
4901 || AT_class (a
) == dw_val_class_macptr
4902 || AT_class (a
) == dw_val_class_loclistsptr
4903 || AT_class (a
) == dw_val_class_high_pc
));
4904 return a
->dw_attr_val
.v
.val_lbl_id
;
4907 /* Get the attribute of type attr_kind. */
4909 static dw_attr_node
*
4910 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4914 dw_die_ref spec
= NULL
;
4919 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4920 if (a
->dw_attr
== attr_kind
)
4922 else if (a
->dw_attr
== DW_AT_specification
4923 || a
->dw_attr
== DW_AT_abstract_origin
)
4927 return get_AT (spec
, attr_kind
);
4932 /* Returns the parent of the declaration of DIE. */
4935 get_die_parent (dw_die_ref die
)
4942 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4943 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4946 return die
->die_parent
;
4949 /* Return the "low pc" attribute value, typically associated with a subprogram
4950 DIE. Return null if the "low pc" attribute is either not present, or if it
4951 cannot be represented as an assembler label identifier. */
4953 static inline const char *
4954 get_AT_low_pc (dw_die_ref die
)
4956 dw_attr_node
*a
= get_AT (die
, DW_AT_low_pc
);
4958 return a
? AT_lbl (a
) : NULL
;
4961 /* Return the "high pc" attribute value, typically associated with a subprogram
4962 DIE. Return null if the "high pc" attribute is either not present, or if it
4963 cannot be represented as an assembler label identifier. */
4965 static inline const char *
4966 get_AT_hi_pc (dw_die_ref die
)
4968 dw_attr_node
*a
= get_AT (die
, DW_AT_high_pc
);
4970 return a
? AT_lbl (a
) : NULL
;
4973 /* Return the value of the string attribute designated by ATTR_KIND, or
4974 NULL if it is not present. */
4976 static inline const char *
4977 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4979 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4981 return a
? AT_string (a
) : NULL
;
4984 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4985 if it is not present. */
4988 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4990 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4992 return a
? AT_flag (a
) : 0;
4995 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4996 if it is not present. */
4998 static inline unsigned
4999 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5001 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5003 return a
? AT_unsigned (a
) : 0;
5006 static inline dw_die_ref
5007 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5009 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5011 return a
? AT_ref (a
) : NULL
;
5014 static inline struct dwarf_file_data
*
5015 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5017 dw_attr_node
*a
= get_AT (die
, attr_kind
);
5019 return a
? AT_file (a
) : NULL
;
5022 /* Return TRUE if the language is C++. */
5027 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5029 return (lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
5030 || lang
== DW_LANG_C_plus_plus_11
|| lang
== DW_LANG_C_plus_plus_14
);
5033 /* Return TRUE if DECL was created by the C++ frontend. */
5036 is_cxx (const_tree decl
)
5040 const_tree context
= decl
;
5041 while (context
&& TREE_CODE (context
) != TRANSLATION_UNIT_DECL
)
5043 if (TREE_CODE (context
) == BLOCK
)
5044 context
= BLOCK_SUPERCONTEXT (context
);
5046 context
= get_containing_scope (context
);
5048 if (context
&& TRANSLATION_UNIT_LANGUAGE (context
))
5049 return strncmp (TRANSLATION_UNIT_LANGUAGE (context
), "GNU C++", 7) == 0;
5054 /* Return TRUE if the language is Fortran. */
5059 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5061 return (lang
== DW_LANG_Fortran77
5062 || lang
== DW_LANG_Fortran90
5063 || lang
== DW_LANG_Fortran95
5064 || lang
== DW_LANG_Fortran03
5065 || lang
== DW_LANG_Fortran08
);
5068 /* Return TRUE if the language is Ada. */
5073 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5075 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
5078 /* Remove the specified attribute if present. Return TRUE if removal
5082 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5090 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5091 if (a
->dw_attr
== attr_kind
)
5093 if (AT_class (a
) == dw_val_class_str
)
5094 if (a
->dw_attr_val
.v
.val_str
->refcount
)
5095 a
->dw_attr_val
.v
.val_str
->refcount
--;
5097 /* vec::ordered_remove should help reduce the number of abbrevs
5099 die
->die_attr
->ordered_remove (ix
);
5105 /* Remove CHILD from its parent. PREV must have the property that
5106 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
5109 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
5111 gcc_assert (child
->die_parent
== prev
->die_parent
);
5112 gcc_assert (prev
->die_sib
== child
);
5115 gcc_assert (child
->die_parent
->die_child
== child
);
5119 prev
->die_sib
= child
->die_sib
;
5120 if (child
->die_parent
->die_child
== child
)
5121 child
->die_parent
->die_child
= prev
;
5122 child
->die_sib
= NULL
;
5125 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
5126 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
5129 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
5131 dw_die_ref parent
= old_child
->die_parent
;
5133 gcc_assert (parent
== prev
->die_parent
);
5134 gcc_assert (prev
->die_sib
== old_child
);
5136 new_child
->die_parent
= parent
;
5137 if (prev
== old_child
)
5139 gcc_assert (parent
->die_child
== old_child
);
5140 new_child
->die_sib
= new_child
;
5144 prev
->die_sib
= new_child
;
5145 new_child
->die_sib
= old_child
->die_sib
;
5147 if (old_child
->die_parent
->die_child
== old_child
)
5148 old_child
->die_parent
->die_child
= new_child
;
5149 old_child
->die_sib
= NULL
;
5152 /* Move all children from OLD_PARENT to NEW_PARENT. */
5155 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
5158 new_parent
->die_child
= old_parent
->die_child
;
5159 old_parent
->die_child
= NULL
;
5160 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
5163 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
5167 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
5173 dw_die_ref prev
= c
;
5175 while (c
->die_tag
== tag
)
5177 remove_child_with_prev (c
, prev
);
5178 c
->die_parent
= NULL
;
5179 /* Might have removed every child. */
5180 if (die
->die_child
== NULL
)
5184 } while (c
!= die
->die_child
);
5187 /* Add a CHILD_DIE as the last child of DIE. */
5190 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
5192 /* FIXME this should probably be an assert. */
5193 if (! die
|| ! child_die
)
5195 gcc_assert (die
!= child_die
);
5197 child_die
->die_parent
= die
;
5200 child_die
->die_sib
= die
->die_child
->die_sib
;
5201 die
->die_child
->die_sib
= child_die
;
5204 child_die
->die_sib
= child_die
;
5205 die
->die_child
= child_die
;
5208 /* Like add_child_die, but put CHILD_DIE after AFTER_DIE. */
5211 add_child_die_after (dw_die_ref die
, dw_die_ref child_die
,
5212 dw_die_ref after_die
)
5218 && die
!= child_die
);
5220 child_die
->die_parent
= die
;
5221 child_die
->die_sib
= after_die
->die_sib
;
5222 after_die
->die_sib
= child_die
;
5223 if (die
->die_child
== after_die
)
5224 die
->die_child
= child_die
;
5227 /* Unassociate CHILD from its parent, and make its parent be
5231 reparent_child (dw_die_ref child
, dw_die_ref new_parent
)
5233 for (dw_die_ref p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
5234 if (p
->die_sib
== child
)
5236 remove_child_with_prev (child
, p
);
5239 add_child_die (new_parent
, child
);
5242 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5243 is the specification, to the end of PARENT's list of children.
5244 This is done by removing and re-adding it. */
5247 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
5249 /* We want the declaration DIE from inside the class, not the
5250 specification DIE at toplevel. */
5251 if (child
->die_parent
!= parent
)
5253 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5259 gcc_assert (child
->die_parent
== parent
5260 || (child
->die_parent
5261 == get_AT_ref (parent
, DW_AT_specification
)));
5263 reparent_child (child
, parent
);
5266 /* Create and return a new die with a parent of PARENT_DIE. If
5267 PARENT_DIE is NULL, the new DIE is placed in limbo and an
5268 associated tree T must be supplied to determine parenthood
5271 static inline dw_die_ref
5272 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
5274 dw_die_ref die
= ggc_cleared_alloc
<die_node
> ();
5276 die
->die_tag
= tag_value
;
5278 if (parent_die
!= NULL
)
5279 add_child_die (parent_die
, die
);
5282 limbo_die_node
*limbo_node
;
5284 /* No DIEs created after early dwarf should end up in limbo,
5285 because the limbo list should not persist past LTO
5287 if (tag_value
!= DW_TAG_compile_unit
5288 /* These are allowed because they're generated while
5289 breaking out COMDAT units late. */
5290 && tag_value
!= DW_TAG_type_unit
5291 && tag_value
!= DW_TAG_skeleton_unit
5293 /* Allow nested functions to live in limbo because they will
5294 only temporarily live there, as decls_for_scope will fix
5296 && (TREE_CODE (t
) != FUNCTION_DECL
5297 || !decl_function_context (t
))
5298 /* Same as nested functions above but for types. Types that
5299 are local to a function will be fixed in
5301 && (!RECORD_OR_UNION_TYPE_P (t
)
5302 || !TYPE_CONTEXT (t
)
5303 || TREE_CODE (TYPE_CONTEXT (t
)) != FUNCTION_DECL
)
5304 /* FIXME debug-early: Allow late limbo DIE creation for LTO,
5305 especially in the ltrans stage, but once we implement LTO
5306 dwarf streaming, we should remove this exception. */
5309 fprintf (stderr
, "symbol ended up in limbo too late:");
5310 debug_generic_stmt (t
);
5314 limbo_node
= ggc_cleared_alloc
<limbo_die_node
> ();
5315 limbo_node
->die
= die
;
5316 limbo_node
->created_for
= t
;
5317 limbo_node
->next
= limbo_die_list
;
5318 limbo_die_list
= limbo_node
;
5324 /* Return the DIE associated with the given type specifier. */
5326 static inline dw_die_ref
5327 lookup_type_die (tree type
)
5329 dw_die_ref die
= TYPE_SYMTAB_DIE (type
);
5330 if (die
&& die
->removed
)
5332 TYPE_SYMTAB_DIE (type
) = NULL
;
5338 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
5339 anonymous type named by the typedef TYPE_DIE, return the DIE of the
5340 anonymous type instead the one of the naming typedef. */
5342 static inline dw_die_ref
5343 strip_naming_typedef (tree type
, dw_die_ref type_die
)
5346 && TREE_CODE (type
) == RECORD_TYPE
5348 && type_die
->die_tag
== DW_TAG_typedef
5349 && is_naming_typedef_decl (TYPE_NAME (type
)))
5350 type_die
= get_AT_ref (type_die
, DW_AT_type
);
5354 /* Like lookup_type_die, but if type is an anonymous type named by a
5355 typedef[1], return the DIE of the anonymous type instead the one of
5356 the naming typedef. This is because in gen_typedef_die, we did
5357 equate the anonymous struct named by the typedef with the DIE of
5358 the naming typedef. So by default, lookup_type_die on an anonymous
5359 struct yields the DIE of the naming typedef.
5361 [1]: Read the comment of is_naming_typedef_decl to learn about what
5362 a naming typedef is. */
5364 static inline dw_die_ref
5365 lookup_type_die_strip_naming_typedef (tree type
)
5367 dw_die_ref die
= lookup_type_die (type
);
5368 return strip_naming_typedef (type
, die
);
5371 /* Equate a DIE to a given type specifier. */
5374 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5376 TYPE_SYMTAB_DIE (type
) = type_die
;
5379 /* Returns a hash value for X (which really is a die_struct). */
5382 decl_die_hasher::hash (die_node
*x
)
5384 return (hashval_t
) x
->decl_id
;
5387 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5390 decl_die_hasher::equal (die_node
*x
, tree y
)
5392 return (x
->decl_id
== DECL_UID (y
));
5395 /* Return the DIE associated with a given declaration. */
5397 static inline dw_die_ref
5398 lookup_decl_die (tree decl
)
5400 dw_die_ref
*die
= decl_die_table
->find_slot_with_hash (decl
, DECL_UID (decl
),
5404 if ((*die
)->removed
)
5406 decl_die_table
->clear_slot (die
);
5412 /* Returns a hash value for X (which really is a var_loc_list). */
5415 decl_loc_hasher::hash (var_loc_list
*x
)
5417 return (hashval_t
) x
->decl_id
;
5420 /* Return nonzero if decl_id of var_loc_list X is the same as
5424 decl_loc_hasher::equal (var_loc_list
*x
, const_tree y
)
5426 return (x
->decl_id
== DECL_UID (y
));
5429 /* Return the var_loc list associated with a given declaration. */
5431 static inline var_loc_list
*
5432 lookup_decl_loc (const_tree decl
)
5434 if (!decl_loc_table
)
5436 return decl_loc_table
->find_with_hash (decl
, DECL_UID (decl
));
5439 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5442 dw_loc_list_hasher::hash (cached_dw_loc_list
*x
)
5444 return (hashval_t
) x
->decl_id
;
5447 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5451 dw_loc_list_hasher::equal (cached_dw_loc_list
*x
, const_tree y
)
5453 return (x
->decl_id
== DECL_UID (y
));
5456 /* Equate a DIE to a particular declaration. */
5459 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5461 unsigned int decl_id
= DECL_UID (decl
);
5463 *decl_die_table
->find_slot_with_hash (decl
, decl_id
, INSERT
) = decl_die
;
5464 decl_die
->decl_id
= decl_id
;
5467 /* Return how many bits covers PIECE EXPR_LIST. */
5469 static HOST_WIDE_INT
5470 decl_piece_bitsize (rtx piece
)
5472 int ret
= (int) GET_MODE (piece
);
5475 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
5476 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
5477 return INTVAL (XEXP (XEXP (piece
, 0), 0));
5480 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5483 decl_piece_varloc_ptr (rtx piece
)
5485 if ((int) GET_MODE (piece
))
5486 return &XEXP (piece
, 0);
5488 return &XEXP (XEXP (piece
, 0), 1);
5491 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5492 Next is the chain of following piece nodes. */
5494 static rtx_expr_list
*
5495 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
5497 if (bitsize
> 0 && bitsize
<= (int) MAX_MACHINE_MODE
)
5498 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
5500 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
5505 /* Return rtx that should be stored into loc field for
5506 LOC_NOTE and BITPOS/BITSIZE. */
5509 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
5510 HOST_WIDE_INT bitsize
)
5514 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
5516 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
5521 /* This function either modifies location piece list *DEST in
5522 place (if SRC and INNER is NULL), or copies location piece list
5523 *SRC to *DEST while modifying it. Location BITPOS is modified
5524 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5525 not copied and if needed some padding around it is added.
5526 When modifying in place, DEST should point to EXPR_LIST where
5527 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5528 to the start of the whole list and INNER points to the EXPR_LIST
5529 where earlier pieces cover PIECE_BITPOS bits. */
5532 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
5533 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
5534 HOST_WIDE_INT bitsize
, rtx loc_note
)
5537 bool copy
= inner
!= NULL
;
5541 /* First copy all nodes preceding the current bitpos. */
5542 while (src
!= inner
)
5544 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5545 decl_piece_bitsize (*src
), NULL_RTX
);
5546 dest
= &XEXP (*dest
, 1);
5547 src
= &XEXP (*src
, 1);
5550 /* Add padding if needed. */
5551 if (bitpos
!= piece_bitpos
)
5553 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5554 copy
? NULL_RTX
: *dest
);
5555 dest
= &XEXP (*dest
, 1);
5557 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5560 /* A piece with correct bitpos and bitsize already exist,
5561 just update the location for it and return. */
5562 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5565 /* Add the piece that changed. */
5566 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5567 dest
= &XEXP (*dest
, 1);
5568 /* Skip over pieces that overlap it. */
5569 diff
= bitpos
- piece_bitpos
+ bitsize
;
5572 while (diff
> 0 && *src
)
5575 diff
-= decl_piece_bitsize (piece
);
5577 src
= &XEXP (piece
, 1);
5580 *src
= XEXP (piece
, 1);
5581 free_EXPR_LIST_node (piece
);
5584 /* Add padding if needed. */
5585 if (diff
< 0 && *src
)
5589 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5590 dest
= &XEXP (*dest
, 1);
5594 /* Finally copy all nodes following it. */
5597 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5598 decl_piece_bitsize (*src
), NULL_RTX
);
5599 dest
= &XEXP (*dest
, 1);
5600 src
= &XEXP (*src
, 1);
5604 /* Add a variable location node to the linked list for DECL. */
5606 static struct var_loc_node
*
5607 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5609 unsigned int decl_id
;
5611 struct var_loc_node
*loc
= NULL
;
5612 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5614 if (VAR_P (decl
) && DECL_HAS_DEBUG_EXPR_P (decl
))
5616 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5617 if (handled_component_p (realdecl
)
5618 || (TREE_CODE (realdecl
) == MEM_REF
5619 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5621 HOST_WIDE_INT maxsize
;
5624 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
,
5626 if (!DECL_P (innerdecl
)
5627 || DECL_IGNORED_P (innerdecl
)
5628 || TREE_STATIC (innerdecl
)
5630 || bitpos
+ bitsize
> 256
5631 || bitsize
!= maxsize
)
5637 decl_id
= DECL_UID (decl
);
5639 = decl_loc_table
->find_slot_with_hash (decl
, decl_id
, INSERT
);
5642 temp
= ggc_cleared_alloc
<var_loc_list
> ();
5643 temp
->decl_id
= decl_id
;
5649 /* For PARM_DECLs try to keep around the original incoming value,
5650 even if that means we'll emit a zero-range .debug_loc entry. */
5652 && temp
->first
== temp
->last
5653 && TREE_CODE (decl
) == PARM_DECL
5654 && NOTE_P (temp
->first
->loc
)
5655 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5656 && DECL_INCOMING_RTL (decl
)
5657 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5658 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5659 == GET_CODE (DECL_INCOMING_RTL (decl
))
5660 && prev_real_insn (as_a
<rtx_insn
*> (temp
->first
->loc
)) == NULL_RTX
5662 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5663 NOTE_VAR_LOCATION_LOC (loc_note
))
5664 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5665 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5667 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5668 temp
->first
->next
= loc
;
5670 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5672 else if (temp
->last
)
5674 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5675 rtx
*piece_loc
= NULL
, last_loc_note
;
5676 HOST_WIDE_INT piece_bitpos
= 0;
5680 gcc_assert (last
->next
== NULL
);
5682 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5684 piece_loc
= &last
->loc
;
5687 HOST_WIDE_INT cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5688 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5690 piece_bitpos
+= cur_bitsize
;
5691 piece_loc
= &XEXP (*piece_loc
, 1);
5695 /* TEMP->LAST here is either pointer to the last but one or
5696 last element in the chained list, LAST is pointer to the
5698 if (label
&& strcmp (last
->label
, label
) == 0)
5700 /* For SRA optimized variables if there weren't any real
5701 insns since last note, just modify the last node. */
5702 if (piece_loc
!= NULL
)
5704 adjust_piece_list (piece_loc
, NULL
, NULL
,
5705 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5708 /* If the last note doesn't cover any instructions, remove it. */
5709 if (temp
->last
!= last
)
5711 temp
->last
->next
= NULL
;
5714 gcc_assert (strcmp (last
->label
, label
) != 0);
5718 gcc_assert (temp
->first
== temp
->last
5719 || (temp
->first
->next
== temp
->last
5720 && TREE_CODE (decl
) == PARM_DECL
));
5721 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5722 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5726 if (bitsize
== -1 && NOTE_P (last
->loc
))
5727 last_loc_note
= last
->loc
;
5728 else if (piece_loc
!= NULL
5729 && *piece_loc
!= NULL_RTX
5730 && piece_bitpos
== bitpos
5731 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5732 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5734 last_loc_note
= NULL_RTX
;
5735 /* If the current location is the same as the end of the list,
5736 and either both or neither of the locations is uninitialized,
5737 we have nothing to do. */
5738 if (last_loc_note
== NULL_RTX
5739 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5740 NOTE_VAR_LOCATION_LOC (loc_note
)))
5741 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5742 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5743 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5744 == VAR_INIT_STATUS_UNINITIALIZED
)
5745 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5746 == VAR_INIT_STATUS_UNINITIALIZED
))))
5748 /* Add LOC to the end of list and update LAST. If the last
5749 element of the list has been removed above, reuse its
5750 memory for the new node, otherwise allocate a new one. */
5754 memset (loc
, '\0', sizeof (*loc
));
5757 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5758 if (bitsize
== -1 || piece_loc
== NULL
)
5759 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5761 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5762 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5764 /* Ensure TEMP->LAST will point either to the new last but one
5765 element of the chain, or to the last element in it. */
5766 if (last
!= temp
->last
)
5774 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5777 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5782 /* Keep track of the number of spaces used to indent the
5783 output of the debugging routines that print the structure of
5784 the DIE internal representation. */
5785 static int print_indent
;
5787 /* Indent the line the number of spaces given by print_indent. */
5790 print_spaces (FILE *outfile
)
5792 fprintf (outfile
, "%*s", print_indent
, "");
5795 /* Print a type signature in hex. */
5798 print_signature (FILE *outfile
, char *sig
)
5802 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5803 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5807 print_discr_value (FILE *outfile
, dw_discr_value
*discr_value
)
5809 if (discr_value
->pos
)
5810 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, discr_value
->v
.sval
);
5812 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, discr_value
->v
.uval
);
5815 static void print_loc_descr (dw_loc_descr_ref
, FILE *);
5817 /* Print the value associated to the VAL DWARF value node to OUTFILE. If
5818 RECURSE, output location descriptor operations. */
5821 print_dw_val (dw_val_node
*val
, bool recurse
, FILE *outfile
)
5823 switch (val
->val_class
)
5825 case dw_val_class_addr
:
5826 fprintf (outfile
, "address");
5828 case dw_val_class_offset
:
5829 fprintf (outfile
, "offset");
5831 case dw_val_class_loc
:
5832 fprintf (outfile
, "location descriptor");
5833 if (val
->v
.val_loc
== NULL
)
5834 fprintf (outfile
, " -> <null>\n");
5837 fprintf (outfile
, ":\n");
5839 print_loc_descr (val
->v
.val_loc
, outfile
);
5843 fprintf (outfile
, " (%p)\n", (void *) val
->v
.val_loc
);
5845 case dw_val_class_loc_list
:
5846 fprintf (outfile
, "location list -> label:%s",
5847 val
->v
.val_loc_list
->ll_symbol
);
5849 case dw_val_class_range_list
:
5850 fprintf (outfile
, "range list");
5852 case dw_val_class_const
:
5853 case dw_val_class_const_implicit
:
5854 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, val
->v
.val_int
);
5856 case dw_val_class_unsigned_const
:
5857 case dw_val_class_unsigned_const_implicit
:
5858 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, val
->v
.val_unsigned
);
5860 case dw_val_class_const_double
:
5861 fprintf (outfile
, "constant (" HOST_WIDE_INT_PRINT_DEC
","\
5862 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5863 val
->v
.val_double
.high
,
5864 val
->v
.val_double
.low
);
5866 case dw_val_class_wide_int
:
5868 int i
= val
->v
.val_wide
->get_len ();
5869 fprintf (outfile
, "constant (");
5871 if (val
->v
.val_wide
->elt (i
- 1) == 0)
5872 fprintf (outfile
, "0x");
5873 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
,
5874 val
->v
.val_wide
->elt (--i
));
5876 fprintf (outfile
, HOST_WIDE_INT_PRINT_PADDED_HEX
,
5877 val
->v
.val_wide
->elt (i
));
5878 fprintf (outfile
, ")");
5881 case dw_val_class_vec
:
5882 fprintf (outfile
, "floating-point or vector constant");
5884 case dw_val_class_flag
:
5885 fprintf (outfile
, "%u", val
->v
.val_flag
);
5887 case dw_val_class_die_ref
:
5888 if (val
->v
.val_die_ref
.die
!= NULL
)
5890 dw_die_ref die
= val
->v
.val_die_ref
.die
;
5892 if (die
->comdat_type_p
)
5894 fprintf (outfile
, "die -> signature: ");
5895 print_signature (outfile
,
5896 die
->die_id
.die_type_node
->signature
);
5898 else if (die
->die_id
.die_symbol
)
5899 fprintf (outfile
, "die -> label: %s", die
->die_id
.die_symbol
);
5901 fprintf (outfile
, "die -> %ld", die
->die_offset
);
5902 fprintf (outfile
, " (%p)", (void *) die
);
5905 fprintf (outfile
, "die -> <null>");
5907 case dw_val_class_vms_delta
:
5908 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5909 val
->v
.val_vms_delta
.lbl2
, val
->v
.val_vms_delta
.lbl1
);
5911 case dw_val_class_lbl_id
:
5912 case dw_val_class_lineptr
:
5913 case dw_val_class_macptr
:
5914 case dw_val_class_loclistsptr
:
5915 case dw_val_class_high_pc
:
5916 fprintf (outfile
, "label: %s", val
->v
.val_lbl_id
);
5918 case dw_val_class_str
:
5919 if (val
->v
.val_str
->str
!= NULL
)
5920 fprintf (outfile
, "\"%s\"", val
->v
.val_str
->str
);
5922 fprintf (outfile
, "<null>");
5924 case dw_val_class_file
:
5925 case dw_val_class_file_implicit
:
5926 fprintf (outfile
, "\"%s\" (%d)", val
->v
.val_file
->filename
,
5927 val
->v
.val_file
->emitted_number
);
5929 case dw_val_class_data8
:
5933 for (i
= 0; i
< 8; i
++)
5934 fprintf (outfile
, "%02x", val
->v
.val_data8
[i
]);
5937 case dw_val_class_discr_value
:
5938 print_discr_value (outfile
, &val
->v
.val_discr_value
);
5940 case dw_val_class_discr_list
:
5941 for (dw_discr_list_ref node
= val
->v
.val_discr_list
;
5943 node
= node
->dw_discr_next
)
5945 if (node
->dw_discr_range
)
5947 fprintf (outfile
, " .. ");
5948 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
5949 print_discr_value (outfile
, &node
->dw_discr_upper_bound
);
5952 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
5954 if (node
->dw_discr_next
!= NULL
)
5955 fprintf (outfile
, " | ");
5962 /* Likewise, for a DIE attribute. */
5965 print_attribute (dw_attr_node
*a
, bool recurse
, FILE *outfile
)
5967 print_dw_val (&a
->dw_attr_val
, recurse
, outfile
);
5971 /* Print the list of operands in the LOC location description to OUTFILE. This
5972 routine is a debugging aid only. */
5975 print_loc_descr (dw_loc_descr_ref loc
, FILE *outfile
)
5977 dw_loc_descr_ref l
= loc
;
5981 print_spaces (outfile
);
5982 fprintf (outfile
, "<null>\n");
5986 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
5988 print_spaces (outfile
);
5989 fprintf (outfile
, "(%p) %s",
5991 dwarf_stack_op_name (l
->dw_loc_opc
));
5992 if (l
->dw_loc_oprnd1
.val_class
!= dw_val_class_none
)
5994 fprintf (outfile
, " ");
5995 print_dw_val (&l
->dw_loc_oprnd1
, false, outfile
);
5997 if (l
->dw_loc_oprnd2
.val_class
!= dw_val_class_none
)
5999 fprintf (outfile
, ", ");
6000 print_dw_val (&l
->dw_loc_oprnd2
, false, outfile
);
6002 fprintf (outfile
, "\n");
6006 /* Print the information associated with a given DIE, and its children.
6007 This routine is a debugging aid only. */
6010 print_die (dw_die_ref die
, FILE *outfile
)
6016 print_spaces (outfile
);
6017 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
6018 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
6020 print_spaces (outfile
);
6021 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
6022 fprintf (outfile
, " offset: %ld", die
->die_offset
);
6023 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
6025 if (die
->comdat_type_p
)
6027 print_spaces (outfile
);
6028 fprintf (outfile
, " signature: ");
6029 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
6030 fprintf (outfile
, "\n");
6033 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6035 print_spaces (outfile
);
6036 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
6038 print_attribute (a
, true, outfile
);
6039 fprintf (outfile
, "\n");
6042 if (die
->die_child
!= NULL
)
6045 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
6048 if (print_indent
== 0)
6049 fprintf (outfile
, "\n");
6052 /* Print the list of operations in the LOC location description. */
6055 debug_dwarf_loc_descr (dw_loc_descr_ref loc
)
6057 print_loc_descr (loc
, stderr
);
6060 /* Print the information collected for a given DIE. */
6063 debug_dwarf_die (dw_die_ref die
)
6065 print_die (die
, stderr
);
6069 debug (die_struct
&ref
)
6071 print_die (&ref
, stderr
);
6075 debug (die_struct
*ptr
)
6080 fprintf (stderr
, "<nil>\n");
6084 /* Print all DWARF information collected for the compilation unit.
6085 This routine is a debugging aid only. */
6091 print_die (comp_unit_die (), stderr
);
6094 /* Verify the DIE tree structure. */
6097 verify_die (dw_die_ref die
)
6099 gcc_assert (!die
->die_mark
);
6100 if (die
->die_parent
== NULL
6101 && die
->die_sib
== NULL
)
6103 /* Verify the die_sib list is cyclic. */
6110 while (x
&& !x
->die_mark
);
6111 gcc_assert (x
== die
);
6115 /* Verify all dies have the same parent. */
6116 gcc_assert (x
->die_parent
== die
->die_parent
);
6119 /* Verify the child has the proper parent and recurse. */
6120 gcc_assert (x
->die_child
->die_parent
== x
);
6121 verify_die (x
->die_child
);
6126 while (x
&& x
->die_mark
);
6129 /* Sanity checks on DIEs. */
6132 check_die (dw_die_ref die
)
6136 bool inline_found
= false;
6137 int n_location
= 0, n_low_pc
= 0, n_high_pc
= 0, n_artificial
= 0;
6138 int n_decl_line
= 0, n_decl_column
= 0, n_decl_file
= 0;
6139 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6144 if (a
->dw_attr_val
.v
.val_unsigned
)
6145 inline_found
= true;
6147 case DW_AT_location
:
6156 case DW_AT_artificial
:
6159 case DW_AT_decl_column
:
6162 case DW_AT_decl_line
:
6165 case DW_AT_decl_file
:
6172 if (n_location
> 1 || n_low_pc
> 1 || n_high_pc
> 1 || n_artificial
> 1
6173 || n_decl_column
> 1 || n_decl_line
> 1 || n_decl_file
> 1)
6175 fprintf (stderr
, "Duplicate attributes in DIE:\n");
6176 debug_dwarf_die (die
);
6181 /* A debugging information entry that is a member of an abstract
6182 instance tree [that has DW_AT_inline] should not contain any
6183 attributes which describe aspects of the subroutine which vary
6184 between distinct inlined expansions or distinct out-of-line
6186 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6187 gcc_assert (a
->dw_attr
!= DW_AT_low_pc
6188 && a
->dw_attr
!= DW_AT_high_pc
6189 && a
->dw_attr
!= DW_AT_location
6190 && a
->dw_attr
!= DW_AT_frame_base
6191 && a
->dw_attr
!= DW_AT_call_all_calls
6192 && a
->dw_attr
!= DW_AT_GNU_all_call_sites
);
6196 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
6197 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
6198 DIE that marks the start of the DIEs for this include file. */
6201 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
6203 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
6204 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
6206 new_unit
->die_sib
= old_unit
;
6210 /* Close an include-file CU and reopen the enclosing one. */
6213 pop_compile_unit (dw_die_ref old_unit
)
6215 dw_die_ref new_unit
= old_unit
->die_sib
;
6217 old_unit
->die_sib
= NULL
;
6221 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6222 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
6223 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
6225 /* Calculate the checksum of a location expression. */
6228 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
6231 inchash::hash hstate
;
6234 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
6236 hash_loc_operands (loc
, hstate
);
6237 hash
= hstate
.end();
6241 /* Calculate the checksum of an attribute. */
6244 attr_checksum (dw_attr_node
*at
, struct md5_ctx
*ctx
, int *mark
)
6246 dw_loc_descr_ref loc
;
6249 CHECKSUM (at
->dw_attr
);
6251 /* We don't care that this was compiled with a different compiler
6252 snapshot; if the output is the same, that's what matters. */
6253 if (at
->dw_attr
== DW_AT_producer
)
6256 switch (AT_class (at
))
6258 case dw_val_class_const
:
6259 case dw_val_class_const_implicit
:
6260 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
6262 case dw_val_class_unsigned_const
:
6263 case dw_val_class_unsigned_const_implicit
:
6264 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
6266 case dw_val_class_const_double
:
6267 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
6269 case dw_val_class_wide_int
:
6270 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
6271 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6272 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
6274 case dw_val_class_vec
:
6275 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
6276 (at
->dw_attr_val
.v
.val_vec
.length
6277 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
6279 case dw_val_class_flag
:
6280 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
6282 case dw_val_class_str
:
6283 CHECKSUM_STRING (AT_string (at
));
6286 case dw_val_class_addr
:
6288 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6289 CHECKSUM_STRING (XSTR (r
, 0));
6292 case dw_val_class_offset
:
6293 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
6296 case dw_val_class_loc
:
6297 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6298 loc_checksum (loc
, ctx
);
6301 case dw_val_class_die_ref
:
6302 die_checksum (AT_ref (at
), ctx
, mark
);
6305 case dw_val_class_fde_ref
:
6306 case dw_val_class_vms_delta
:
6307 case dw_val_class_lbl_id
:
6308 case dw_val_class_lineptr
:
6309 case dw_val_class_macptr
:
6310 case dw_val_class_loclistsptr
:
6311 case dw_val_class_high_pc
:
6314 case dw_val_class_file
:
6315 case dw_val_class_file_implicit
:
6316 CHECKSUM_STRING (AT_file (at
)->filename
);
6319 case dw_val_class_data8
:
6320 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6328 /* Calculate the checksum of a DIE. */
6331 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6337 /* To avoid infinite recursion. */
6340 CHECKSUM (die
->die_mark
);
6343 die
->die_mark
= ++(*mark
);
6345 CHECKSUM (die
->die_tag
);
6347 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6348 attr_checksum (a
, ctx
, mark
);
6350 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
6354 #undef CHECKSUM_BLOCK
6355 #undef CHECKSUM_STRING
6357 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
6358 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6359 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
6360 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
6361 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
6362 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
6363 #define CHECKSUM_ATTR(FOO) \
6364 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
6366 /* Calculate the checksum of a number in signed LEB128 format. */
6369 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
6376 byte
= (value
& 0x7f);
6378 more
= !((value
== 0 && (byte
& 0x40) == 0)
6379 || (value
== -1 && (byte
& 0x40) != 0));
6388 /* Calculate the checksum of a number in unsigned LEB128 format. */
6391 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
6395 unsigned char byte
= (value
& 0x7f);
6398 /* More bytes to follow. */
6406 /* Checksum the context of the DIE. This adds the names of any
6407 surrounding namespaces or structures to the checksum. */
6410 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
6414 int tag
= die
->die_tag
;
6416 if (tag
!= DW_TAG_namespace
6417 && tag
!= DW_TAG_structure_type
6418 && tag
!= DW_TAG_class_type
)
6421 name
= get_AT_string (die
, DW_AT_name
);
6423 spec
= get_AT_ref (die
, DW_AT_specification
);
6427 if (die
->die_parent
!= NULL
)
6428 checksum_die_context (die
->die_parent
, ctx
);
6430 CHECKSUM_ULEB128 ('C');
6431 CHECKSUM_ULEB128 (tag
);
6433 CHECKSUM_STRING (name
);
6436 /* Calculate the checksum of a location expression. */
6439 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
6441 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
6442 were emitted as a DW_FORM_sdata instead of a location expression. */
6443 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
6445 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6446 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
6450 /* Otherwise, just checksum the raw location expression. */
6453 inchash::hash hstate
;
6456 CHECKSUM_ULEB128 (loc
->dtprel
);
6457 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
6458 hash_loc_operands (loc
, hstate
);
6459 hash
= hstate
.end ();
6461 loc
= loc
->dw_loc_next
;
6465 /* Calculate the checksum of an attribute. */
6468 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_node
*at
,
6469 struct md5_ctx
*ctx
, int *mark
)
6471 dw_loc_descr_ref loc
;
6474 if (AT_class (at
) == dw_val_class_die_ref
)
6476 dw_die_ref target_die
= AT_ref (at
);
6478 /* For pointer and reference types, we checksum only the (qualified)
6479 name of the target type (if there is a name). For friend entries,
6480 we checksum only the (qualified) name of the target type or function.
6481 This allows the checksum to remain the same whether the target type
6482 is complete or not. */
6483 if ((at
->dw_attr
== DW_AT_type
6484 && (tag
== DW_TAG_pointer_type
6485 || tag
== DW_TAG_reference_type
6486 || tag
== DW_TAG_rvalue_reference_type
6487 || tag
== DW_TAG_ptr_to_member_type
))
6488 || (at
->dw_attr
== DW_AT_friend
6489 && tag
== DW_TAG_friend
))
6491 dw_attr_node
*name_attr
= get_AT (target_die
, DW_AT_name
);
6493 if (name_attr
!= NULL
)
6495 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6499 CHECKSUM_ULEB128 ('N');
6500 CHECKSUM_ULEB128 (at
->dw_attr
);
6501 if (decl
->die_parent
!= NULL
)
6502 checksum_die_context (decl
->die_parent
, ctx
);
6503 CHECKSUM_ULEB128 ('E');
6504 CHECKSUM_STRING (AT_string (name_attr
));
6509 /* For all other references to another DIE, we check to see if the
6510 target DIE has already been visited. If it has, we emit a
6511 backward reference; if not, we descend recursively. */
6512 if (target_die
->die_mark
> 0)
6514 CHECKSUM_ULEB128 ('R');
6515 CHECKSUM_ULEB128 (at
->dw_attr
);
6516 CHECKSUM_ULEB128 (target_die
->die_mark
);
6520 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6524 target_die
->die_mark
= ++(*mark
);
6525 CHECKSUM_ULEB128 ('T');
6526 CHECKSUM_ULEB128 (at
->dw_attr
);
6527 if (decl
->die_parent
!= NULL
)
6528 checksum_die_context (decl
->die_parent
, ctx
);
6529 die_checksum_ordered (target_die
, ctx
, mark
);
6534 CHECKSUM_ULEB128 ('A');
6535 CHECKSUM_ULEB128 (at
->dw_attr
);
6537 switch (AT_class (at
))
6539 case dw_val_class_const
:
6540 case dw_val_class_const_implicit
:
6541 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6542 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
6545 case dw_val_class_unsigned_const
:
6546 case dw_val_class_unsigned_const_implicit
:
6547 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6548 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
6551 case dw_val_class_const_double
:
6552 CHECKSUM_ULEB128 (DW_FORM_block
);
6553 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
6554 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
6557 case dw_val_class_wide_int
:
6558 CHECKSUM_ULEB128 (DW_FORM_block
);
6559 CHECKSUM_ULEB128 (get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6560 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
6561 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
6562 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6563 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
6566 case dw_val_class_vec
:
6567 CHECKSUM_ULEB128 (DW_FORM_block
);
6568 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
6569 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
6570 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
6571 (at
->dw_attr_val
.v
.val_vec
.length
6572 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
6575 case dw_val_class_flag
:
6576 CHECKSUM_ULEB128 (DW_FORM_flag
);
6577 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
6580 case dw_val_class_str
:
6581 CHECKSUM_ULEB128 (DW_FORM_string
);
6582 CHECKSUM_STRING (AT_string (at
));
6585 case dw_val_class_addr
:
6587 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6588 CHECKSUM_ULEB128 (DW_FORM_string
);
6589 CHECKSUM_STRING (XSTR (r
, 0));
6592 case dw_val_class_offset
:
6593 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6594 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
6597 case dw_val_class_loc
:
6598 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6599 loc_checksum_ordered (loc
, ctx
);
6602 case dw_val_class_fde_ref
:
6603 case dw_val_class_lbl_id
:
6604 case dw_val_class_lineptr
:
6605 case dw_val_class_macptr
:
6606 case dw_val_class_loclistsptr
:
6607 case dw_val_class_high_pc
:
6610 case dw_val_class_file
:
6611 case dw_val_class_file_implicit
:
6612 CHECKSUM_ULEB128 (DW_FORM_string
);
6613 CHECKSUM_STRING (AT_file (at
)->filename
);
6616 case dw_val_class_data8
:
6617 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6625 struct checksum_attributes
6627 dw_attr_node
*at_name
;
6628 dw_attr_node
*at_type
;
6629 dw_attr_node
*at_friend
;
6630 dw_attr_node
*at_accessibility
;
6631 dw_attr_node
*at_address_class
;
6632 dw_attr_node
*at_alignment
;
6633 dw_attr_node
*at_allocated
;
6634 dw_attr_node
*at_artificial
;
6635 dw_attr_node
*at_associated
;
6636 dw_attr_node
*at_binary_scale
;
6637 dw_attr_node
*at_bit_offset
;
6638 dw_attr_node
*at_bit_size
;
6639 dw_attr_node
*at_bit_stride
;
6640 dw_attr_node
*at_byte_size
;
6641 dw_attr_node
*at_byte_stride
;
6642 dw_attr_node
*at_const_value
;
6643 dw_attr_node
*at_containing_type
;
6644 dw_attr_node
*at_count
;
6645 dw_attr_node
*at_data_location
;
6646 dw_attr_node
*at_data_member_location
;
6647 dw_attr_node
*at_decimal_scale
;
6648 dw_attr_node
*at_decimal_sign
;
6649 dw_attr_node
*at_default_value
;
6650 dw_attr_node
*at_digit_count
;
6651 dw_attr_node
*at_discr
;
6652 dw_attr_node
*at_discr_list
;
6653 dw_attr_node
*at_discr_value
;
6654 dw_attr_node
*at_encoding
;
6655 dw_attr_node
*at_endianity
;
6656 dw_attr_node
*at_explicit
;
6657 dw_attr_node
*at_is_optional
;
6658 dw_attr_node
*at_location
;
6659 dw_attr_node
*at_lower_bound
;
6660 dw_attr_node
*at_mutable
;
6661 dw_attr_node
*at_ordering
;
6662 dw_attr_node
*at_picture_string
;
6663 dw_attr_node
*at_prototyped
;
6664 dw_attr_node
*at_small
;
6665 dw_attr_node
*at_segment
;
6666 dw_attr_node
*at_string_length
;
6667 dw_attr_node
*at_string_length_bit_size
;
6668 dw_attr_node
*at_string_length_byte_size
;
6669 dw_attr_node
*at_threads_scaled
;
6670 dw_attr_node
*at_upper_bound
;
6671 dw_attr_node
*at_use_location
;
6672 dw_attr_node
*at_use_UTF8
;
6673 dw_attr_node
*at_variable_parameter
;
6674 dw_attr_node
*at_virtuality
;
6675 dw_attr_node
*at_visibility
;
6676 dw_attr_node
*at_vtable_elem_location
;
6679 /* Collect the attributes that we will want to use for the checksum. */
6682 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
6687 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6698 attrs
->at_friend
= a
;
6700 case DW_AT_accessibility
:
6701 attrs
->at_accessibility
= a
;
6703 case DW_AT_address_class
:
6704 attrs
->at_address_class
= a
;
6706 case DW_AT_alignment
:
6707 attrs
->at_alignment
= a
;
6709 case DW_AT_allocated
:
6710 attrs
->at_allocated
= a
;
6712 case DW_AT_artificial
:
6713 attrs
->at_artificial
= a
;
6715 case DW_AT_associated
:
6716 attrs
->at_associated
= a
;
6718 case DW_AT_binary_scale
:
6719 attrs
->at_binary_scale
= a
;
6721 case DW_AT_bit_offset
:
6722 attrs
->at_bit_offset
= a
;
6724 case DW_AT_bit_size
:
6725 attrs
->at_bit_size
= a
;
6727 case DW_AT_bit_stride
:
6728 attrs
->at_bit_stride
= a
;
6730 case DW_AT_byte_size
:
6731 attrs
->at_byte_size
= a
;
6733 case DW_AT_byte_stride
:
6734 attrs
->at_byte_stride
= a
;
6736 case DW_AT_const_value
:
6737 attrs
->at_const_value
= a
;
6739 case DW_AT_containing_type
:
6740 attrs
->at_containing_type
= a
;
6743 attrs
->at_count
= a
;
6745 case DW_AT_data_location
:
6746 attrs
->at_data_location
= a
;
6748 case DW_AT_data_member_location
:
6749 attrs
->at_data_member_location
= a
;
6751 case DW_AT_decimal_scale
:
6752 attrs
->at_decimal_scale
= a
;
6754 case DW_AT_decimal_sign
:
6755 attrs
->at_decimal_sign
= a
;
6757 case DW_AT_default_value
:
6758 attrs
->at_default_value
= a
;
6760 case DW_AT_digit_count
:
6761 attrs
->at_digit_count
= a
;
6764 attrs
->at_discr
= a
;
6766 case DW_AT_discr_list
:
6767 attrs
->at_discr_list
= a
;
6769 case DW_AT_discr_value
:
6770 attrs
->at_discr_value
= a
;
6772 case DW_AT_encoding
:
6773 attrs
->at_encoding
= a
;
6775 case DW_AT_endianity
:
6776 attrs
->at_endianity
= a
;
6778 case DW_AT_explicit
:
6779 attrs
->at_explicit
= a
;
6781 case DW_AT_is_optional
:
6782 attrs
->at_is_optional
= a
;
6784 case DW_AT_location
:
6785 attrs
->at_location
= a
;
6787 case DW_AT_lower_bound
:
6788 attrs
->at_lower_bound
= a
;
6791 attrs
->at_mutable
= a
;
6793 case DW_AT_ordering
:
6794 attrs
->at_ordering
= a
;
6796 case DW_AT_picture_string
:
6797 attrs
->at_picture_string
= a
;
6799 case DW_AT_prototyped
:
6800 attrs
->at_prototyped
= a
;
6803 attrs
->at_small
= a
;
6806 attrs
->at_segment
= a
;
6808 case DW_AT_string_length
:
6809 attrs
->at_string_length
= a
;
6811 case DW_AT_string_length_bit_size
:
6812 attrs
->at_string_length_bit_size
= a
;
6814 case DW_AT_string_length_byte_size
:
6815 attrs
->at_string_length_byte_size
= a
;
6817 case DW_AT_threads_scaled
:
6818 attrs
->at_threads_scaled
= a
;
6820 case DW_AT_upper_bound
:
6821 attrs
->at_upper_bound
= a
;
6823 case DW_AT_use_location
:
6824 attrs
->at_use_location
= a
;
6826 case DW_AT_use_UTF8
:
6827 attrs
->at_use_UTF8
= a
;
6829 case DW_AT_variable_parameter
:
6830 attrs
->at_variable_parameter
= a
;
6832 case DW_AT_virtuality
:
6833 attrs
->at_virtuality
= a
;
6835 case DW_AT_visibility
:
6836 attrs
->at_visibility
= a
;
6838 case DW_AT_vtable_elem_location
:
6839 attrs
->at_vtable_elem_location
= a
;
6847 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6850 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6854 struct checksum_attributes attrs
;
6856 CHECKSUM_ULEB128 ('D');
6857 CHECKSUM_ULEB128 (die
->die_tag
);
6859 memset (&attrs
, 0, sizeof (attrs
));
6861 decl
= get_AT_ref (die
, DW_AT_specification
);
6863 collect_checksum_attributes (&attrs
, decl
);
6864 collect_checksum_attributes (&attrs
, die
);
6866 CHECKSUM_ATTR (attrs
.at_name
);
6867 CHECKSUM_ATTR (attrs
.at_accessibility
);
6868 CHECKSUM_ATTR (attrs
.at_address_class
);
6869 CHECKSUM_ATTR (attrs
.at_allocated
);
6870 CHECKSUM_ATTR (attrs
.at_artificial
);
6871 CHECKSUM_ATTR (attrs
.at_associated
);
6872 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6873 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6874 CHECKSUM_ATTR (attrs
.at_bit_size
);
6875 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6876 CHECKSUM_ATTR (attrs
.at_byte_size
);
6877 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6878 CHECKSUM_ATTR (attrs
.at_const_value
);
6879 CHECKSUM_ATTR (attrs
.at_containing_type
);
6880 CHECKSUM_ATTR (attrs
.at_count
);
6881 CHECKSUM_ATTR (attrs
.at_data_location
);
6882 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6883 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6884 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6885 CHECKSUM_ATTR (attrs
.at_default_value
);
6886 CHECKSUM_ATTR (attrs
.at_digit_count
);
6887 CHECKSUM_ATTR (attrs
.at_discr
);
6888 CHECKSUM_ATTR (attrs
.at_discr_list
);
6889 CHECKSUM_ATTR (attrs
.at_discr_value
);
6890 CHECKSUM_ATTR (attrs
.at_encoding
);
6891 CHECKSUM_ATTR (attrs
.at_endianity
);
6892 CHECKSUM_ATTR (attrs
.at_explicit
);
6893 CHECKSUM_ATTR (attrs
.at_is_optional
);
6894 CHECKSUM_ATTR (attrs
.at_location
);
6895 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6896 CHECKSUM_ATTR (attrs
.at_mutable
);
6897 CHECKSUM_ATTR (attrs
.at_ordering
);
6898 CHECKSUM_ATTR (attrs
.at_picture_string
);
6899 CHECKSUM_ATTR (attrs
.at_prototyped
);
6900 CHECKSUM_ATTR (attrs
.at_small
);
6901 CHECKSUM_ATTR (attrs
.at_segment
);
6902 CHECKSUM_ATTR (attrs
.at_string_length
);
6903 CHECKSUM_ATTR (attrs
.at_string_length_bit_size
);
6904 CHECKSUM_ATTR (attrs
.at_string_length_byte_size
);
6905 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6906 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6907 CHECKSUM_ATTR (attrs
.at_use_location
);
6908 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6909 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6910 CHECKSUM_ATTR (attrs
.at_virtuality
);
6911 CHECKSUM_ATTR (attrs
.at_visibility
);
6912 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6913 CHECKSUM_ATTR (attrs
.at_type
);
6914 CHECKSUM_ATTR (attrs
.at_friend
);
6915 CHECKSUM_ATTR (attrs
.at_alignment
);
6917 /* Checksum the child DIEs. */
6920 dw_attr_node
*name_attr
;
6923 name_attr
= get_AT (c
, DW_AT_name
);
6924 if (is_template_instantiation (c
))
6926 /* Ignore instantiations of member type and function templates. */
6928 else if (name_attr
!= NULL
6929 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
6931 /* Use a shallow checksum for named nested types and member
6933 CHECKSUM_ULEB128 ('S');
6934 CHECKSUM_ULEB128 (c
->die_tag
);
6935 CHECKSUM_STRING (AT_string (name_attr
));
6939 /* Use a deep checksum for other children. */
6940 /* Mark this DIE so it gets processed when unmarking. */
6941 if (c
->die_mark
== 0)
6943 die_checksum_ordered (c
, ctx
, mark
);
6945 } while (c
!= die
->die_child
);
6947 CHECKSUM_ULEB128 (0);
6950 /* Add a type name and tag to a hash. */
6952 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
6954 CHECKSUM_ULEB128 (tag
);
6955 CHECKSUM_STRING (name
);
6959 #undef CHECKSUM_STRING
6960 #undef CHECKSUM_ATTR
6961 #undef CHECKSUM_LEB128
6962 #undef CHECKSUM_ULEB128
6964 /* Generate the type signature for DIE. This is computed by generating an
6965 MD5 checksum over the DIE's tag, its relevant attributes, and its
6966 children. Attributes that are references to other DIEs are processed
6967 by recursion, using the MARK field to prevent infinite recursion.
6968 If the DIE is nested inside a namespace or another type, we also
6969 need to include that context in the signature. The lower 64 bits
6970 of the resulting MD5 checksum comprise the signature. */
6973 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6977 unsigned char checksum
[16];
6982 name
= get_AT_string (die
, DW_AT_name
);
6983 decl
= get_AT_ref (die
, DW_AT_specification
);
6984 parent
= get_die_parent (die
);
6986 /* First, compute a signature for just the type name (and its surrounding
6987 context, if any. This is stored in the type unit DIE for link-time
6988 ODR (one-definition rule) checking. */
6990 if (is_cxx () && name
!= NULL
)
6992 md5_init_ctx (&ctx
);
6994 /* Checksum the names of surrounding namespaces and structures. */
6996 checksum_die_context (parent
, &ctx
);
6998 /* Checksum the current DIE. */
6999 die_odr_checksum (die
->die_tag
, name
, &ctx
);
7000 md5_finish_ctx (&ctx
, checksum
);
7002 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
7005 /* Next, compute the complete type signature. */
7007 md5_init_ctx (&ctx
);
7009 die
->die_mark
= mark
;
7011 /* Checksum the names of surrounding namespaces and structures. */
7013 checksum_die_context (parent
, &ctx
);
7015 /* Checksum the DIE and its children. */
7016 die_checksum_ordered (die
, &ctx
, &mark
);
7017 unmark_all_dies (die
);
7018 md5_finish_ctx (&ctx
, checksum
);
7020 /* Store the signature in the type node and link the type DIE and the
7021 type node together. */
7022 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
7023 DWARF_TYPE_SIGNATURE_SIZE
);
7024 die
->comdat_type_p
= true;
7025 die
->die_id
.die_type_node
= type_node
;
7026 type_node
->type_die
= die
;
7028 /* If the DIE is a specification, link its declaration to the type node
7032 decl
->comdat_type_p
= true;
7033 decl
->die_id
.die_type_node
= type_node
;
7037 /* Do the location expressions look same? */
7039 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
7041 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
7042 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
7043 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
7046 /* Do the values look the same? */
7048 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
7050 dw_loc_descr_ref loc1
, loc2
;
7053 if (v1
->val_class
!= v2
->val_class
)
7056 switch (v1
->val_class
)
7058 case dw_val_class_const
:
7059 case dw_val_class_const_implicit
:
7060 return v1
->v
.val_int
== v2
->v
.val_int
;
7061 case dw_val_class_unsigned_const
:
7062 case dw_val_class_unsigned_const_implicit
:
7063 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
7064 case dw_val_class_const_double
:
7065 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
7066 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
7067 case dw_val_class_wide_int
:
7068 return *v1
->v
.val_wide
== *v2
->v
.val_wide
;
7069 case dw_val_class_vec
:
7070 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
7071 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
7073 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
7074 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
7077 case dw_val_class_flag
:
7078 return v1
->v
.val_flag
== v2
->v
.val_flag
;
7079 case dw_val_class_str
:
7080 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
7082 case dw_val_class_addr
:
7083 r1
= v1
->v
.val_addr
;
7084 r2
= v2
->v
.val_addr
;
7085 if (GET_CODE (r1
) != GET_CODE (r2
))
7087 return !rtx_equal_p (r1
, r2
);
7089 case dw_val_class_offset
:
7090 return v1
->v
.val_offset
== v2
->v
.val_offset
;
7092 case dw_val_class_loc
:
7093 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
7095 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
7096 if (!same_loc_p (loc1
, loc2
, mark
))
7098 return !loc1
&& !loc2
;
7100 case dw_val_class_die_ref
:
7101 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
7103 case dw_val_class_fde_ref
:
7104 case dw_val_class_vms_delta
:
7105 case dw_val_class_lbl_id
:
7106 case dw_val_class_lineptr
:
7107 case dw_val_class_macptr
:
7108 case dw_val_class_loclistsptr
:
7109 case dw_val_class_high_pc
:
7112 case dw_val_class_file
:
7113 case dw_val_class_file_implicit
:
7114 return v1
->v
.val_file
== v2
->v
.val_file
;
7116 case dw_val_class_data8
:
7117 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
7124 /* Do the attributes look the same? */
7127 same_attr_p (dw_attr_node
*at1
, dw_attr_node
*at2
, int *mark
)
7129 if (at1
->dw_attr
!= at2
->dw_attr
)
7132 /* We don't care that this was compiled with a different compiler
7133 snapshot; if the output is the same, that's what matters. */
7134 if (at1
->dw_attr
== DW_AT_producer
)
7137 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
7140 /* Do the dies look the same? */
7143 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
7149 /* To avoid infinite recursion. */
7151 return die1
->die_mark
== die2
->die_mark
;
7152 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
7154 if (die1
->die_tag
!= die2
->die_tag
)
7157 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
7160 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
7161 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
7164 c1
= die1
->die_child
;
7165 c2
= die2
->die_child
;
7174 if (!same_die_p (c1
, c2
, mark
))
7178 if (c1
== die1
->die_child
)
7180 if (c2
== die2
->die_child
)
7190 /* Do the dies look the same? Wrapper around same_die_p. */
7193 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
7196 int ret
= same_die_p (die1
, die2
, &mark
);
7198 unmark_all_dies (die1
);
7199 unmark_all_dies (die2
);
7204 /* The prefix to attach to symbols on DIEs in the current comdat debug
7206 static const char *comdat_symbol_id
;
7208 /* The index of the current symbol within the current comdat CU. */
7209 static unsigned int comdat_symbol_number
;
7211 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
7212 children, and set comdat_symbol_id accordingly. */
7215 compute_section_prefix (dw_die_ref unit_die
)
7217 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
7218 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
7219 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
7222 unsigned char checksum
[16];
7225 /* Compute the checksum of the DIE, then append part of it as hex digits to
7226 the name filename of the unit. */
7228 md5_init_ctx (&ctx
);
7230 die_checksum (unit_die
, &ctx
, &mark
);
7231 unmark_all_dies (unit_die
);
7232 md5_finish_ctx (&ctx
, checksum
);
7234 sprintf (name
, "%s.", base
);
7235 clean_symbol_name (name
);
7237 p
= name
+ strlen (name
);
7238 for (i
= 0; i
< 4; i
++)
7240 sprintf (p
, "%.2x", checksum
[i
]);
7244 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
7245 comdat_symbol_number
= 0;
7248 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
7251 is_type_die (dw_die_ref die
)
7253 switch (die
->die_tag
)
7255 case DW_TAG_array_type
:
7256 case DW_TAG_class_type
:
7257 case DW_TAG_interface_type
:
7258 case DW_TAG_enumeration_type
:
7259 case DW_TAG_pointer_type
:
7260 case DW_TAG_reference_type
:
7261 case DW_TAG_rvalue_reference_type
:
7262 case DW_TAG_string_type
:
7263 case DW_TAG_structure_type
:
7264 case DW_TAG_subroutine_type
:
7265 case DW_TAG_union_type
:
7266 case DW_TAG_ptr_to_member_type
:
7267 case DW_TAG_set_type
:
7268 case DW_TAG_subrange_type
:
7269 case DW_TAG_base_type
:
7270 case DW_TAG_const_type
:
7271 case DW_TAG_file_type
:
7272 case DW_TAG_packed_type
:
7273 case DW_TAG_volatile_type
:
7274 case DW_TAG_typedef
:
7281 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
7282 Basically, we want to choose the bits that are likely to be shared between
7283 compilations (types) and leave out the bits that are specific to individual
7284 compilations (functions). */
7287 is_comdat_die (dw_die_ref c
)
7289 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
7290 we do for stabs. The advantage is a greater likelihood of sharing between
7291 objects that don't include headers in the same order (and therefore would
7292 put the base types in a different comdat). jason 8/28/00 */
7294 if (c
->die_tag
== DW_TAG_base_type
)
7297 if (c
->die_tag
== DW_TAG_pointer_type
7298 || c
->die_tag
== DW_TAG_reference_type
7299 || c
->die_tag
== DW_TAG_rvalue_reference_type
7300 || c
->die_tag
== DW_TAG_const_type
7301 || c
->die_tag
== DW_TAG_volatile_type
)
7303 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
7305 return t
? is_comdat_die (t
) : 0;
7308 return is_type_die (c
);
7311 /* Returns 1 iff C is the sort of DIE that might be referred to from another
7312 compilation unit. */
7315 is_symbol_die (dw_die_ref c
)
7317 return (is_type_die (c
)
7318 || is_declaration_die (c
)
7319 || c
->die_tag
== DW_TAG_namespace
7320 || c
->die_tag
== DW_TAG_module
);
7323 /* Returns true iff C is a compile-unit DIE. */
7326 is_cu_die (dw_die_ref c
)
7328 return c
&& (c
->die_tag
== DW_TAG_compile_unit
7329 || c
->die_tag
== DW_TAG_skeleton_unit
);
7332 /* Returns true iff C is a unit DIE of some sort. */
7335 is_unit_die (dw_die_ref c
)
7337 return c
&& (c
->die_tag
== DW_TAG_compile_unit
7338 || c
->die_tag
== DW_TAG_partial_unit
7339 || c
->die_tag
== DW_TAG_type_unit
7340 || c
->die_tag
== DW_TAG_skeleton_unit
);
7343 /* Returns true iff C is a namespace DIE. */
7346 is_namespace_die (dw_die_ref c
)
7348 return c
&& c
->die_tag
== DW_TAG_namespace
;
7351 /* Returns true iff C is a class or structure DIE. */
7354 is_class_die (dw_die_ref c
)
7356 return c
&& (c
->die_tag
== DW_TAG_class_type
7357 || c
->die_tag
== DW_TAG_structure_type
);
7360 /* Return non-zero if this DIE is a template parameter. */
7363 is_template_parameter (dw_die_ref die
)
7365 switch (die
->die_tag
)
7367 case DW_TAG_template_type_param
:
7368 case DW_TAG_template_value_param
:
7369 case DW_TAG_GNU_template_template_param
:
7370 case DW_TAG_GNU_template_parameter_pack
:
7377 /* Return non-zero if this DIE represents a template instantiation. */
7380 is_template_instantiation (dw_die_ref die
)
7384 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
7386 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
7391 gen_internal_sym (const char *prefix
)
7393 char buf
[MAX_ARTIFICIAL_LABEL_BYTES
];
7395 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
7396 return xstrdup (buf
);
7399 /* Assign symbols to all worthy DIEs under DIE. */
7402 assign_symbol_names (dw_die_ref die
)
7406 if (is_symbol_die (die
) && !die
->comdat_type_p
)
7408 if (comdat_symbol_id
)
7410 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
7412 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
7413 comdat_symbol_id
, comdat_symbol_number
++);
7414 die
->die_id
.die_symbol
= xstrdup (p
);
7417 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
7420 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
7423 struct cu_hash_table_entry
7426 unsigned min_comdat_num
, max_comdat_num
;
7427 struct cu_hash_table_entry
*next
;
7430 /* Helpers to manipulate hash table of CUs. */
7432 struct cu_hash_table_entry_hasher
: pointer_hash
<cu_hash_table_entry
>
7434 typedef die_struct
*compare_type
;
7435 static inline hashval_t
hash (const cu_hash_table_entry
*);
7436 static inline bool equal (const cu_hash_table_entry
*, const die_struct
*);
7437 static inline void remove (cu_hash_table_entry
*);
7441 cu_hash_table_entry_hasher::hash (const cu_hash_table_entry
*entry
)
7443 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
7447 cu_hash_table_entry_hasher::equal (const cu_hash_table_entry
*entry1
,
7448 const die_struct
*entry2
)
7450 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
7454 cu_hash_table_entry_hasher::remove (cu_hash_table_entry
*entry
)
7456 struct cu_hash_table_entry
*next
;
7466 typedef hash_table
<cu_hash_table_entry_hasher
> cu_hash_type
;
7468 /* Check whether we have already seen this CU and set up SYM_NUM
7471 check_duplicate_cu (dw_die_ref cu
, cu_hash_type
*htable
, unsigned int *sym_num
)
7473 struct cu_hash_table_entry dummy
;
7474 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
7476 dummy
.max_comdat_num
= 0;
7478 slot
= htable
->find_slot_with_hash (cu
,
7479 htab_hash_string (cu
->die_id
.die_symbol
),
7483 for (; entry
; last
= entry
, entry
= entry
->next
)
7485 if (same_die_p_wrap (cu
, entry
->cu
))
7491 *sym_num
= entry
->min_comdat_num
;
7495 entry
= XCNEW (struct cu_hash_table_entry
);
7497 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
7498 entry
->next
= *slot
;
7504 /* Record SYM_NUM to record of CU in HTABLE. */
7506 record_comdat_symbol_number (dw_die_ref cu
, cu_hash_type
*htable
,
7507 unsigned int sym_num
)
7509 struct cu_hash_table_entry
**slot
, *entry
;
7511 slot
= htable
->find_slot_with_hash (cu
,
7512 htab_hash_string (cu
->die_id
.die_symbol
),
7516 entry
->max_comdat_num
= sym_num
;
7519 /* Traverse the DIE (which is always comp_unit_die), and set up
7520 additional compilation units for each of the include files we see
7521 bracketed by BINCL/EINCL. */
7524 break_out_includes (dw_die_ref die
)
7527 dw_die_ref unit
= NULL
;
7528 limbo_die_node
*node
, **pnode
;
7532 dw_die_ref prev
= c
;
7534 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
7535 || (unit
&& is_comdat_die (c
)))
7537 dw_die_ref next
= c
->die_sib
;
7539 /* This DIE is for a secondary CU; remove it from the main one. */
7540 remove_child_with_prev (c
, prev
);
7542 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
7543 unit
= push_new_compile_unit (unit
, c
);
7544 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
7545 unit
= pop_compile_unit (unit
);
7547 add_child_die (unit
, c
);
7549 if (c
== die
->die_child
)
7552 } while (c
!= die
->die_child
);
7555 /* We can only use this in debugging, since the frontend doesn't check
7556 to make sure that we leave every include file we enter. */
7560 assign_symbol_names (die
);
7561 cu_hash_type
cu_hash_table (10);
7562 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
7568 compute_section_prefix (node
->die
);
7569 is_dupl
= check_duplicate_cu (node
->die
, &cu_hash_table
,
7570 &comdat_symbol_number
);
7571 assign_symbol_names (node
->die
);
7573 *pnode
= node
->next
;
7576 pnode
= &node
->next
;
7577 record_comdat_symbol_number (node
->die
, &cu_hash_table
,
7578 comdat_symbol_number
);
7583 /* Return non-zero if this DIE is a declaration. */
7586 is_declaration_die (dw_die_ref die
)
7591 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7592 if (a
->dw_attr
== DW_AT_declaration
)
7598 /* Return non-zero if this DIE is nested inside a subprogram. */
7601 is_nested_in_subprogram (dw_die_ref die
)
7603 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
7607 return local_scope_p (decl
);
7610 /* Return non-zero if this DIE contains a defining declaration of a
7614 contains_subprogram_definition (dw_die_ref die
)
7618 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
7620 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
7624 /* Return non-zero if this is a type DIE that should be moved to a
7625 COMDAT .debug_types section or .debug_info section with DW_UT_*type
7629 should_move_die_to_comdat (dw_die_ref die
)
7631 switch (die
->die_tag
)
7633 case DW_TAG_class_type
:
7634 case DW_TAG_structure_type
:
7635 case DW_TAG_enumeration_type
:
7636 case DW_TAG_union_type
:
7637 /* Don't move declarations, inlined instances, types nested in a
7638 subprogram, or types that contain subprogram definitions. */
7639 if (is_declaration_die (die
)
7640 || get_AT (die
, DW_AT_abstract_origin
)
7641 || is_nested_in_subprogram (die
)
7642 || contains_subprogram_definition (die
))
7645 case DW_TAG_array_type
:
7646 case DW_TAG_interface_type
:
7647 case DW_TAG_pointer_type
:
7648 case DW_TAG_reference_type
:
7649 case DW_TAG_rvalue_reference_type
:
7650 case DW_TAG_string_type
:
7651 case DW_TAG_subroutine_type
:
7652 case DW_TAG_ptr_to_member_type
:
7653 case DW_TAG_set_type
:
7654 case DW_TAG_subrange_type
:
7655 case DW_TAG_base_type
:
7656 case DW_TAG_const_type
:
7657 case DW_TAG_file_type
:
7658 case DW_TAG_packed_type
:
7659 case DW_TAG_volatile_type
:
7660 case DW_TAG_typedef
:
7666 /* Make a clone of DIE. */
7669 clone_die (dw_die_ref die
)
7675 clone
= ggc_cleared_alloc
<die_node
> ();
7676 clone
->die_tag
= die
->die_tag
;
7678 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7679 add_dwarf_attr (clone
, a
);
7684 /* Make a clone of the tree rooted at DIE. */
7687 clone_tree (dw_die_ref die
)
7690 dw_die_ref clone
= clone_die (die
);
7692 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
7697 /* Make a clone of DIE as a declaration. */
7700 clone_as_declaration (dw_die_ref die
)
7707 /* If the DIE is already a declaration, just clone it. */
7708 if (is_declaration_die (die
))
7709 return clone_die (die
);
7711 /* If the DIE is a specification, just clone its declaration DIE. */
7712 decl
= get_AT_ref (die
, DW_AT_specification
);
7715 clone
= clone_die (decl
);
7716 if (die
->comdat_type_p
)
7717 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7721 clone
= ggc_cleared_alloc
<die_node
> ();
7722 clone
->die_tag
= die
->die_tag
;
7724 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7726 /* We don't want to copy over all attributes.
7727 For example we don't want DW_AT_byte_size because otherwise we will no
7728 longer have a declaration and GDB will treat it as a definition. */
7732 case DW_AT_abstract_origin
:
7733 case DW_AT_artificial
:
7734 case DW_AT_containing_type
:
7735 case DW_AT_external
:
7738 case DW_AT_virtuality
:
7739 case DW_AT_linkage_name
:
7740 case DW_AT_MIPS_linkage_name
:
7741 add_dwarf_attr (clone
, a
);
7743 case DW_AT_byte_size
:
7744 case DW_AT_alignment
:
7750 if (die
->comdat_type_p
)
7751 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7753 add_AT_flag (clone
, DW_AT_declaration
, 1);
7758 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7760 struct decl_table_entry
7766 /* Helpers to manipulate hash table of copied declarations. */
7768 /* Hashtable helpers. */
7770 struct decl_table_entry_hasher
: free_ptr_hash
<decl_table_entry
>
7772 typedef die_struct
*compare_type
;
7773 static inline hashval_t
hash (const decl_table_entry
*);
7774 static inline bool equal (const decl_table_entry
*, const die_struct
*);
7778 decl_table_entry_hasher::hash (const decl_table_entry
*entry
)
7780 return htab_hash_pointer (entry
->orig
);
7784 decl_table_entry_hasher::equal (const decl_table_entry
*entry1
,
7785 const die_struct
*entry2
)
7787 return entry1
->orig
== entry2
;
7790 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
7792 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7793 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7794 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7795 to check if the ancestor has already been copied into UNIT. */
7798 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
,
7799 decl_hash_type
*decl_table
)
7801 dw_die_ref parent
= die
->die_parent
;
7802 dw_die_ref new_parent
= unit
;
7804 decl_table_entry
**slot
= NULL
;
7805 struct decl_table_entry
*entry
= NULL
;
7809 /* Check if the entry has already been copied to UNIT. */
7810 slot
= decl_table
->find_slot_with_hash (die
, htab_hash_pointer (die
),
7812 if (*slot
!= HTAB_EMPTY_ENTRY
)
7818 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7819 entry
= XCNEW (struct decl_table_entry
);
7827 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7830 if (!is_unit_die (parent
))
7831 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7834 copy
= clone_as_declaration (die
);
7835 add_child_die (new_parent
, copy
);
7839 /* Record the pointer to the copy. */
7845 /* Copy the declaration context to the new type unit DIE. This includes
7846 any surrounding namespace or type declarations. If the DIE has an
7847 AT_specification attribute, it also includes attributes and children
7848 attached to the specification, and returns a pointer to the original
7849 parent of the declaration DIE. Returns NULL otherwise. */
7852 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7855 dw_die_ref new_decl
;
7856 dw_die_ref orig_parent
= NULL
;
7858 decl
= get_AT_ref (die
, DW_AT_specification
);
7867 /* The original DIE will be changed to a declaration, and must
7868 be moved to be a child of the original declaration DIE. */
7869 orig_parent
= decl
->die_parent
;
7871 /* Copy the type node pointer from the new DIE to the original
7872 declaration DIE so we can forward references later. */
7873 decl
->comdat_type_p
= true;
7874 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7876 remove_AT (die
, DW_AT_specification
);
7878 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
7880 if (a
->dw_attr
!= DW_AT_name
7881 && a
->dw_attr
!= DW_AT_declaration
7882 && a
->dw_attr
!= DW_AT_external
)
7883 add_dwarf_attr (die
, a
);
7886 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
7889 if (decl
->die_parent
!= NULL
7890 && !is_unit_die (decl
->die_parent
))
7892 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
7893 if (new_decl
!= NULL
)
7895 remove_AT (new_decl
, DW_AT_signature
);
7896 add_AT_specification (die
, new_decl
);
7903 /* Generate the skeleton ancestor tree for the given NODE, then clone
7904 the DIE and add the clone into the tree. */
7907 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7909 if (node
->new_die
!= NULL
)
7912 node
->new_die
= clone_as_declaration (node
->old_die
);
7914 if (node
->parent
!= NULL
)
7916 generate_skeleton_ancestor_tree (node
->parent
);
7917 add_child_die (node
->parent
->new_die
, node
->new_die
);
7921 /* Generate a skeleton tree of DIEs containing any declarations that are
7922 found in the original tree. We traverse the tree looking for declaration
7923 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7926 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7928 skeleton_chain_node node
;
7931 dw_die_ref prev
= NULL
;
7932 dw_die_ref next
= NULL
;
7934 node
.parent
= parent
;
7936 first
= c
= parent
->old_die
->die_child
;
7940 if (prev
== NULL
|| prev
->die_sib
== c
)
7943 next
= (c
== first
? NULL
: c
->die_sib
);
7945 node
.new_die
= NULL
;
7946 if (is_declaration_die (c
))
7948 if (is_template_instantiation (c
))
7950 /* Instantiated templates do not need to be cloned into the
7951 type unit. Just move the DIE and its children back to
7952 the skeleton tree (in the main CU). */
7953 remove_child_with_prev (c
, prev
);
7954 add_child_die (parent
->new_die
, c
);
7957 else if (c
->comdat_type_p
)
7959 /* This is the skeleton of earlier break_out_comdat_types
7960 type. Clone the existing DIE, but keep the children
7961 under the original (which is in the main CU). */
7962 dw_die_ref clone
= clone_die (c
);
7964 replace_child (c
, clone
, prev
);
7965 generate_skeleton_ancestor_tree (parent
);
7966 add_child_die (parent
->new_die
, c
);
7972 /* Clone the existing DIE, move the original to the skeleton
7973 tree (which is in the main CU), and put the clone, with
7974 all the original's children, where the original came from
7975 (which is about to be moved to the type unit). */
7976 dw_die_ref clone
= clone_die (c
);
7977 move_all_children (c
, clone
);
7979 /* If the original has a DW_AT_object_pointer attribute,
7980 it would now point to a child DIE just moved to the
7981 cloned tree, so we need to remove that attribute from
7983 remove_AT (c
, DW_AT_object_pointer
);
7985 replace_child (c
, clone
, prev
);
7986 generate_skeleton_ancestor_tree (parent
);
7987 add_child_die (parent
->new_die
, c
);
7988 node
.old_die
= clone
;
7993 generate_skeleton_bottom_up (&node
);
7994 } while (next
!= NULL
);
7997 /* Wrapper function for generate_skeleton_bottom_up. */
8000 generate_skeleton (dw_die_ref die
)
8002 skeleton_chain_node node
;
8005 node
.new_die
= NULL
;
8008 /* If this type definition is nested inside another type,
8009 and is not an instantiation of a template, always leave
8010 at least a declaration in its place. */
8011 if (die
->die_parent
!= NULL
8012 && is_type_die (die
->die_parent
)
8013 && !is_template_instantiation (die
))
8014 node
.new_die
= clone_as_declaration (die
);
8016 generate_skeleton_bottom_up (&node
);
8017 return node
.new_die
;
8020 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
8021 declaration. The original DIE is moved to a new compile unit so that
8022 existing references to it follow it to the new location. If any of the
8023 original DIE's descendants is a declaration, we need to replace the
8024 original DIE with a skeleton tree and move the declarations back into the
8028 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
8031 dw_die_ref skeleton
, orig_parent
;
8033 /* Copy the declaration context to the type unit DIE. If the returned
8034 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
8036 orig_parent
= copy_declaration_context (unit
, child
);
8038 skeleton
= generate_skeleton (child
);
8039 if (skeleton
== NULL
)
8040 remove_child_with_prev (child
, prev
);
8043 skeleton
->comdat_type_p
= true;
8044 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
8046 /* If the original DIE was a specification, we need to put
8047 the skeleton under the parent DIE of the declaration.
8048 This leaves the original declaration in the tree, but
8049 it will be pruned later since there are no longer any
8050 references to it. */
8051 if (orig_parent
!= NULL
)
8053 remove_child_with_prev (child
, prev
);
8054 add_child_die (orig_parent
, skeleton
);
8057 replace_child (child
, skeleton
, prev
);
8064 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
8065 comdat_type_node
*type_node
,
8066 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
);
8068 /* Helper for copy_dwarf_procs_ref_in_dies. Make a copy of the DIE DWARF
8069 procedure, put it under TYPE_NODE and return the copy. Continue looking for
8070 DWARF procedure references in the DW_AT_location attribute. */
8073 copy_dwarf_procedure (dw_die_ref die
,
8074 comdat_type_node
*type_node
,
8075 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8077 gcc_assert (die
->die_tag
== DW_TAG_dwarf_procedure
);
8079 /* DWARF procedures are not supposed to have children... */
8080 gcc_assert (die
->die_child
== NULL
);
8082 /* ... and they are supposed to have only one attribute: DW_AT_location. */
8083 gcc_assert (vec_safe_length (die
->die_attr
) == 1
8084 && ((*die
->die_attr
)[0].dw_attr
== DW_AT_location
));
8086 /* Do not copy more than once DWARF procedures. */
8088 dw_die_ref
&die_copy
= copied_dwarf_procs
.get_or_insert (die
, &existed
);
8092 die_copy
= clone_die (die
);
8093 add_child_die (type_node
->root_die
, die_copy
);
8094 copy_dwarf_procs_ref_in_attrs (die_copy
, type_node
, copied_dwarf_procs
);
8098 /* Helper for copy_dwarf_procs_ref_in_dies. Look for references to DWARF
8099 procedures in DIE's attributes. */
8102 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
8103 comdat_type_node
*type_node
,
8104 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8109 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, i
, a
)
8111 dw_loc_descr_ref loc
;
8113 if (a
->dw_attr_val
.val_class
!= dw_val_class_loc
)
8116 for (loc
= a
->dw_attr_val
.v
.val_loc
; loc
!= NULL
; loc
= loc
->dw_loc_next
)
8118 switch (loc
->dw_loc_opc
)
8122 case DW_OP_call_ref
:
8123 gcc_assert (loc
->dw_loc_oprnd1
.val_class
8124 == dw_val_class_die_ref
);
8125 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
8126 = copy_dwarf_procedure (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
,
8128 copied_dwarf_procs
);
8137 /* Copy DWARF procedures that are referenced by the DIE tree to TREE_NODE and
8138 rewrite references to point to the copies.
8140 References are looked for in DIE's attributes and recursively in all its
8141 children attributes that are location descriptions. COPIED_DWARF_PROCS is a
8142 mapping from old DWARF procedures to their copy. It is used not to copy
8143 twice the same DWARF procedure under TYPE_NODE. */
8146 copy_dwarf_procs_ref_in_dies (dw_die_ref die
,
8147 comdat_type_node
*type_node
,
8148 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8152 copy_dwarf_procs_ref_in_attrs (die
, type_node
, copied_dwarf_procs
);
8153 FOR_EACH_CHILD (die
, c
, copy_dwarf_procs_ref_in_dies (c
,
8155 copied_dwarf_procs
));
8158 /* Traverse the DIE and set up additional .debug_types or .debug_info
8159 DW_UT_*type sections for each type worthy of being placed in a COMDAT
8163 break_out_comdat_types (dw_die_ref die
)
8167 dw_die_ref prev
= NULL
;
8168 dw_die_ref next
= NULL
;
8169 dw_die_ref unit
= NULL
;
8171 first
= c
= die
->die_child
;
8175 if (prev
== NULL
|| prev
->die_sib
== c
)
8178 next
= (c
== first
? NULL
: c
->die_sib
);
8179 if (should_move_die_to_comdat (c
))
8181 dw_die_ref replacement
;
8182 comdat_type_node
*type_node
;
8184 /* Break out nested types into their own type units. */
8185 break_out_comdat_types (c
);
8187 /* Create a new type unit DIE as the root for the new tree, and
8188 add it to the list of comdat types. */
8189 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8190 add_AT_unsigned (unit
, DW_AT_language
,
8191 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
8192 type_node
= ggc_cleared_alloc
<comdat_type_node
> ();
8193 type_node
->root_die
= unit
;
8194 type_node
->next
= comdat_type_list
;
8195 comdat_type_list
= type_node
;
8197 /* Generate the type signature. */
8198 generate_type_signature (c
, type_node
);
8200 /* Copy the declaration context, attributes, and children of the
8201 declaration into the new type unit DIE, then remove this DIE
8202 from the main CU (or replace it with a skeleton if necessary). */
8203 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
8204 type_node
->skeleton_die
= replacement
;
8206 /* Add the DIE to the new compunit. */
8207 add_child_die (unit
, c
);
8209 /* Types can reference DWARF procedures for type size or data location
8210 expressions. Calls in DWARF expressions cannot target procedures
8211 that are not in the same section. So we must copy DWARF procedures
8212 along with this type and then rewrite references to them. */
8213 hash_map
<dw_die_ref
, dw_die_ref
> copied_dwarf_procs
;
8214 copy_dwarf_procs_ref_in_dies (c
, type_node
, copied_dwarf_procs
);
8216 if (replacement
!= NULL
)
8219 else if (c
->die_tag
== DW_TAG_namespace
8220 || c
->die_tag
== DW_TAG_class_type
8221 || c
->die_tag
== DW_TAG_structure_type
8222 || c
->die_tag
== DW_TAG_union_type
)
8224 /* Look for nested types that can be broken out. */
8225 break_out_comdat_types (c
);
8227 } while (next
!= NULL
);
8230 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
8231 Enter all the cloned children into the hash table decl_table. */
8234 clone_tree_partial (dw_die_ref die
, decl_hash_type
*decl_table
)
8238 struct decl_table_entry
*entry
;
8239 decl_table_entry
**slot
;
8241 if (die
->die_tag
== DW_TAG_subprogram
)
8242 clone
= clone_as_declaration (die
);
8244 clone
= clone_die (die
);
8246 slot
= decl_table
->find_slot_with_hash (die
,
8247 htab_hash_pointer (die
), INSERT
);
8249 /* Assert that DIE isn't in the hash table yet. If it would be there
8250 before, the ancestors would be necessarily there as well, therefore
8251 clone_tree_partial wouldn't be called. */
8252 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
8254 entry
= XCNEW (struct decl_table_entry
);
8256 entry
->copy
= clone
;
8259 if (die
->die_tag
!= DW_TAG_subprogram
)
8260 FOR_EACH_CHILD (die
, c
,
8261 add_child_die (clone
, clone_tree_partial (c
, decl_table
)));
8266 /* Walk the DIE and its children, looking for references to incomplete
8267 or trivial types that are unmarked (i.e., that are not in the current
8271 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type
*decl_table
)
8277 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8279 if (AT_class (a
) == dw_val_class_die_ref
)
8281 dw_die_ref targ
= AT_ref (a
);
8282 decl_table_entry
**slot
;
8283 struct decl_table_entry
*entry
;
8285 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
8288 slot
= decl_table
->find_slot_with_hash (targ
,
8289 htab_hash_pointer (targ
),
8292 if (*slot
!= HTAB_EMPTY_ENTRY
)
8294 /* TARG has already been copied, so we just need to
8295 modify the reference to point to the copy. */
8297 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
8301 dw_die_ref parent
= unit
;
8302 dw_die_ref copy
= clone_die (targ
);
8304 /* Record in DECL_TABLE that TARG has been copied.
8305 Need to do this now, before the recursive call,
8306 because DECL_TABLE may be expanded and SLOT
8307 would no longer be a valid pointer. */
8308 entry
= XCNEW (struct decl_table_entry
);
8313 /* If TARG is not a declaration DIE, we need to copy its
8315 if (!is_declaration_die (targ
))
8319 add_child_die (copy
,
8320 clone_tree_partial (c
, decl_table
)));
8323 /* Make sure the cloned tree is marked as part of the
8327 /* If TARG has surrounding context, copy its ancestor tree
8328 into the new type unit. */
8329 if (targ
->die_parent
!= NULL
8330 && !is_unit_die (targ
->die_parent
))
8331 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
8334 add_child_die (parent
, copy
);
8335 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
8337 /* Make sure the newly-copied DIE is walked. If it was
8338 installed in a previously-added context, it won't
8339 get visited otherwise. */
8342 /* Find the highest point of the newly-added tree,
8343 mark each node along the way, and walk from there. */
8344 parent
->die_mark
= 1;
8345 while (parent
->die_parent
8346 && parent
->die_parent
->die_mark
== 0)
8348 parent
= parent
->die_parent
;
8349 parent
->die_mark
= 1;
8351 copy_decls_walk (unit
, parent
, decl_table
);
8357 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
8360 /* Copy declarations for "unworthy" types into the new comdat section.
8361 Incomplete types, modified types, and certain other types aren't broken
8362 out into comdat sections of their own, so they don't have a signature,
8363 and we need to copy the declaration into the same section so that we
8364 don't have an external reference. */
8367 copy_decls_for_unworthy_types (dw_die_ref unit
)
8370 decl_hash_type
decl_table (10);
8371 copy_decls_walk (unit
, unit
, &decl_table
);
8375 /* Traverse the DIE and add a sibling attribute if it may have the
8376 effect of speeding up access to siblings. To save some space,
8377 avoid generating sibling attributes for DIE's without children. */
8380 add_sibling_attributes (dw_die_ref die
)
8384 if (! die
->die_child
)
8387 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
8388 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
8390 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
8393 /* Output all location lists for the DIE and its children. */
8396 output_location_lists (dw_die_ref die
)
8402 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8403 if (AT_class (a
) == dw_val_class_loc_list
)
8404 output_loc_list (AT_loc_list (a
));
8406 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
8409 /* During assign_location_list_indexes and output_loclists_offset the
8410 current index, after it the number of assigned indexes (i.e. how
8411 large the .debug_loclists* offset table should be). */
8412 static unsigned int loc_list_idx
;
8414 /* Output all location list offsets for the DIE and its children. */
8417 output_loclists_offsets (dw_die_ref die
)
8423 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8424 if (AT_class (a
) == dw_val_class_loc_list
)
8426 dw_loc_list_ref l
= AT_loc_list (a
);
8427 if (l
->offset_emitted
)
8429 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l
->ll_symbol
,
8430 loc_section_label
, NULL
);
8431 gcc_assert (l
->hash
== loc_list_idx
);
8433 l
->offset_emitted
= true;
8436 FOR_EACH_CHILD (die
, c
, output_loclists_offsets (c
));
8439 /* Recursively set indexes of location lists. */
8442 assign_location_list_indexes (dw_die_ref die
)
8448 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8449 if (AT_class (a
) == dw_val_class_loc_list
)
8451 dw_loc_list_ref list
= AT_loc_list (a
);
8452 if (!list
->num_assigned
)
8454 list
->num_assigned
= true;
8455 list
->hash
= loc_list_idx
++;
8459 FOR_EACH_CHILD (die
, c
, assign_location_list_indexes (c
));
8462 /* We want to limit the number of external references, because they are
8463 larger than local references: a relocation takes multiple words, and
8464 even a sig8 reference is always eight bytes, whereas a local reference
8465 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
8466 So if we encounter multiple external references to the same type DIE, we
8467 make a local typedef stub for it and redirect all references there.
8469 This is the element of the hash table for keeping track of these
8479 /* Hashtable helpers. */
8481 struct external_ref_hasher
: free_ptr_hash
<external_ref
>
8483 static inline hashval_t
hash (const external_ref
*);
8484 static inline bool equal (const external_ref
*, const external_ref
*);
8488 external_ref_hasher::hash (const external_ref
*r
)
8490 dw_die_ref die
= r
->type
;
8493 /* We can't use the address of the DIE for hashing, because
8494 that will make the order of the stub DIEs non-deterministic. */
8495 if (! die
->comdat_type_p
)
8496 /* We have a symbol; use it to compute a hash. */
8497 h
= htab_hash_string (die
->die_id
.die_symbol
);
8500 /* We have a type signature; use a subset of the bits as the hash.
8501 The 8-byte signature is at least as large as hashval_t. */
8502 comdat_type_node
*type_node
= die
->die_id
.die_type_node
;
8503 memcpy (&h
, type_node
->signature
, sizeof (h
));
8509 external_ref_hasher::equal (const external_ref
*r1
, const external_ref
*r2
)
8511 return r1
->type
== r2
->type
;
8514 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
8516 /* Return a pointer to the external_ref for references to DIE. */
8518 static struct external_ref
*
8519 lookup_external_ref (external_ref_hash_type
*map
, dw_die_ref die
)
8521 struct external_ref ref
, *ref_p
;
8522 external_ref
**slot
;
8525 slot
= map
->find_slot (&ref
, INSERT
);
8526 if (*slot
!= HTAB_EMPTY_ENTRY
)
8529 ref_p
= XCNEW (struct external_ref
);
8535 /* Subroutine of optimize_external_refs, below.
8537 If we see a type skeleton, record it as our stub. If we see external
8538 references, remember how many we've seen. */
8541 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type
*map
)
8546 struct external_ref
*ref_p
;
8548 if (is_type_die (die
)
8549 && (c
= get_AT_ref (die
, DW_AT_signature
)))
8551 /* This is a local skeleton; use it for local references. */
8552 ref_p
= lookup_external_ref (map
, c
);
8556 /* Scan the DIE references, and remember any that refer to DIEs from
8557 other CUs (i.e. those which are not marked). */
8558 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8559 if (AT_class (a
) == dw_val_class_die_ref
8560 && (c
= AT_ref (a
))->die_mark
== 0
8563 ref_p
= lookup_external_ref (map
, c
);
8567 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
8570 /* htab_traverse callback function for optimize_external_refs, below. SLOT
8571 points to an external_ref, DATA is the CU we're processing. If we don't
8572 already have a local stub, and we have multiple refs, build a stub. */
8575 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
8577 struct external_ref
*ref_p
= *slot
;
8579 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
8581 /* We have multiple references to this type, so build a small stub.
8582 Both of these forms are a bit dodgy from the perspective of the
8583 DWARF standard, since technically they should have names. */
8584 dw_die_ref cu
= data
;
8585 dw_die_ref type
= ref_p
->type
;
8586 dw_die_ref stub
= NULL
;
8588 if (type
->comdat_type_p
)
8590 /* If we refer to this type via sig8, use AT_signature. */
8591 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
8592 add_AT_die_ref (stub
, DW_AT_signature
, type
);
8596 /* Otherwise, use a typedef with no name. */
8597 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
8598 add_AT_die_ref (stub
, DW_AT_type
, type
);
8607 /* DIE is a unit; look through all the DIE references to see if there are
8608 any external references to types, and if so, create local stubs for
8609 them which will be applied in build_abbrev_table. This is useful because
8610 references to local DIEs are smaller. */
8612 static external_ref_hash_type
*
8613 optimize_external_refs (dw_die_ref die
)
8615 external_ref_hash_type
*map
= new external_ref_hash_type (10);
8616 optimize_external_refs_1 (die
, map
);
8617 map
->traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
8621 /* The following 3 variables are temporaries that are computed only during the
8622 build_abbrev_table call and used and released during the following
8623 optimize_abbrev_table call. */
8625 /* First abbrev_id that can be optimized based on usage. */
8626 static unsigned int abbrev_opt_start
;
8628 /* Maximum abbrev_id of a base type plus one (we can't optimize DIEs with
8629 abbrev_id smaller than this, because they must be already sized
8630 during build_abbrev_table). */
8631 static unsigned int abbrev_opt_base_type_end
;
8633 /* Vector of usage counts during build_abbrev_table. Indexed by
8634 abbrev_id - abbrev_opt_start. */
8635 static vec
<unsigned int> abbrev_usage_count
;
8637 /* Vector of all DIEs added with die_abbrev >= abbrev_opt_start. */
8638 static vec
<dw_die_ref
> sorted_abbrev_dies
;
8640 /* The format of each DIE (and its attribute value pairs) is encoded in an
8641 abbreviation table. This routine builds the abbreviation table and assigns
8642 a unique abbreviation id for each abbreviation entry. The children of each
8643 die are visited recursively. */
8646 build_abbrev_table (dw_die_ref die
, external_ref_hash_type
*extern_map
)
8648 unsigned int abbrev_id
= 0;
8654 /* Scan the DIE references, and replace any that refer to
8655 DIEs from other CUs (i.e. those which are not marked) with
8656 the local stubs we built in optimize_external_refs. */
8657 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8658 if (AT_class (a
) == dw_val_class_die_ref
8659 && (c
= AT_ref (a
))->die_mark
== 0)
8661 struct external_ref
*ref_p
;
8662 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
8664 ref_p
= lookup_external_ref (extern_map
, c
);
8665 if (ref_p
->stub
&& ref_p
->stub
!= die
)
8666 change_AT_die_ref (a
, ref_p
->stub
);
8668 /* We aren't changing this reference, so mark it external. */
8669 set_AT_ref_external (a
, 1);
8672 FOR_EACH_VEC_SAFE_ELT (abbrev_die_table
, abbrev_id
, abbrev
)
8674 dw_attr_node
*die_a
, *abbrev_a
;
8680 if (abbrev
->die_tag
!= die
->die_tag
)
8682 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
8685 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
8688 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
8690 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
8691 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
8692 || (value_format (abbrev_a
) != value_format (die_a
)))
8702 if (abbrev_id
>= vec_safe_length (abbrev_die_table
))
8704 vec_safe_push (abbrev_die_table
, die
);
8705 if (abbrev_opt_start
)
8706 abbrev_usage_count
.safe_push (0);
8708 if (abbrev_opt_start
&& abbrev_id
>= abbrev_opt_start
)
8710 abbrev_usage_count
[abbrev_id
- abbrev_opt_start
]++;
8711 sorted_abbrev_dies
.safe_push (die
);
8714 die
->die_abbrev
= abbrev_id
;
8715 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
8718 /* Callback function for sorted_abbrev_dies vector sorting. We sort
8719 by die_abbrev's usage count, from the most commonly used
8720 abbreviation to the least. */
8723 die_abbrev_cmp (const void *p1
, const void *p2
)
8725 dw_die_ref die1
= *(const dw_die_ref
*) p1
;
8726 dw_die_ref die2
= *(const dw_die_ref
*) p2
;
8728 gcc_checking_assert (die1
->die_abbrev
>= abbrev_opt_start
);
8729 gcc_checking_assert (die2
->die_abbrev
>= abbrev_opt_start
);
8731 if (die1
->die_abbrev
>= abbrev_opt_base_type_end
8732 && die2
->die_abbrev
>= abbrev_opt_base_type_end
)
8734 if (abbrev_usage_count
[die1
->die_abbrev
- abbrev_opt_start
]
8735 > abbrev_usage_count
[die2
->die_abbrev
- abbrev_opt_start
])
8737 if (abbrev_usage_count
[die1
->die_abbrev
- abbrev_opt_start
]
8738 < abbrev_usage_count
[die2
->die_abbrev
- abbrev_opt_start
])
8742 /* Stabilize the sort. */
8743 if (die1
->die_abbrev
< die2
->die_abbrev
)
8745 if (die1
->die_abbrev
> die2
->die_abbrev
)
8751 /* Convert dw_val_class_const and dw_val_class_unsigned_const class attributes
8752 of DIEs in between sorted_abbrev_dies[first_id] and abbrev_dies[end_id - 1]
8753 into dw_val_class_const_implicit or
8754 dw_val_class_unsigned_const_implicit. */
8757 optimize_implicit_const (unsigned int first_id
, unsigned int end
,
8758 vec
<bool> &implicit_consts
)
8760 /* It never makes sense if there is just one DIE using the abbreviation. */
8761 if (end
< first_id
+ 2)
8766 dw_die_ref die
= sorted_abbrev_dies
[first_id
];
8767 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8768 if (implicit_consts
[ix
])
8770 enum dw_val_class new_class
= dw_val_class_none
;
8771 switch (AT_class (a
))
8773 case dw_val_class_unsigned_const
:
8774 if ((HOST_WIDE_INT
) AT_unsigned (a
) < 0)
8777 /* The .debug_abbrev section will grow by
8778 size_of_sleb128 (AT_unsigned (a)) and we avoid the constants
8779 in all the DIEs using that abbreviation. */
8780 if (constant_size (AT_unsigned (a
)) * (end
- first_id
)
8781 <= (unsigned) size_of_sleb128 (AT_unsigned (a
)))
8784 new_class
= dw_val_class_unsigned_const_implicit
;
8787 case dw_val_class_const
:
8788 new_class
= dw_val_class_const_implicit
;
8791 case dw_val_class_file
:
8792 new_class
= dw_val_class_file_implicit
;
8798 for (i
= first_id
; i
< end
; i
++)
8799 (*sorted_abbrev_dies
[i
]->die_attr
)[ix
].dw_attr_val
.val_class
8804 /* Attempt to optimize abbreviation table from abbrev_opt_start
8805 abbreviation above. */
8808 optimize_abbrev_table (void)
8810 if (abbrev_opt_start
8811 && vec_safe_length (abbrev_die_table
) > abbrev_opt_start
8812 && (dwarf_version
>= 5 || vec_safe_length (abbrev_die_table
) > 127))
8814 auto_vec
<bool, 32> implicit_consts
;
8815 sorted_abbrev_dies
.qsort (die_abbrev_cmp
);
8817 unsigned int abbrev_id
= abbrev_opt_start
- 1;
8818 unsigned int first_id
= ~0U;
8819 unsigned int last_abbrev_id
= 0;
8822 if (abbrev_opt_base_type_end
> abbrev_opt_start
)
8823 abbrev_id
= abbrev_opt_base_type_end
- 1;
8824 /* Reassign abbreviation ids from abbrev_opt_start above, so that
8825 most commonly used abbreviations come first. */
8826 FOR_EACH_VEC_ELT (sorted_abbrev_dies
, i
, die
)
8831 /* If calc_base_type_die_sizes has been called, the CU and
8832 base types after it can't be optimized, because we've already
8833 calculated their DIE offsets. We've sorted them first. */
8834 if (die
->die_abbrev
< abbrev_opt_base_type_end
)
8836 if (die
->die_abbrev
!= last_abbrev_id
)
8838 last_abbrev_id
= die
->die_abbrev
;
8839 if (dwarf_version
>= 5 && first_id
!= ~0U)
8840 optimize_implicit_const (first_id
, i
, implicit_consts
);
8842 (*abbrev_die_table
)[abbrev_id
] = die
;
8843 if (dwarf_version
>= 5)
8846 implicit_consts
.truncate (0);
8848 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8849 switch (AT_class (a
))
8851 case dw_val_class_const
:
8852 case dw_val_class_unsigned_const
:
8853 case dw_val_class_file
:
8854 implicit_consts
.safe_push (true);
8857 implicit_consts
.safe_push (false);
8862 else if (dwarf_version
>= 5)
8864 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8865 if (!implicit_consts
[ix
])
8869 dw_attr_node
*other_a
8870 = &(*(*abbrev_die_table
)[abbrev_id
]->die_attr
)[ix
];
8871 if (!dw_val_equal_p (&a
->dw_attr_val
,
8872 &other_a
->dw_attr_val
))
8873 implicit_consts
[ix
] = false;
8876 die
->die_abbrev
= abbrev_id
;
8878 gcc_assert (abbrev_id
== vec_safe_length (abbrev_die_table
) - 1);
8879 if (dwarf_version
>= 5 && first_id
!= ~0U)
8880 optimize_implicit_const (first_id
, i
, implicit_consts
);
8883 abbrev_opt_start
= 0;
8884 abbrev_opt_base_type_end
= 0;
8885 abbrev_usage_count
.release ();
8886 sorted_abbrev_dies
.release ();
8889 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8892 constant_size (unsigned HOST_WIDE_INT value
)
8899 log
= floor_log2 (value
);
8902 log
= 1 << (floor_log2 (log
) + 1);
8907 /* Return the size of a DIE as it is represented in the
8908 .debug_info section. */
8910 static unsigned long
8911 size_of_die (dw_die_ref die
)
8913 unsigned long size
= 0;
8916 enum dwarf_form form
;
8918 size
+= size_of_uleb128 (die
->die_abbrev
);
8919 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8921 switch (AT_class (a
))
8923 case dw_val_class_addr
:
8924 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8926 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8927 size
+= size_of_uleb128 (AT_index (a
));
8930 size
+= DWARF2_ADDR_SIZE
;
8932 case dw_val_class_offset
:
8933 size
+= DWARF_OFFSET_SIZE
;
8935 case dw_val_class_loc
:
8937 unsigned long lsize
= size_of_locs (AT_loc (a
));
8940 if (dwarf_version
>= 4)
8941 size
+= size_of_uleb128 (lsize
);
8943 size
+= constant_size (lsize
);
8947 case dw_val_class_loc_list
:
8948 if (dwarf_split_debug_info
&& dwarf_version
>= 5)
8950 gcc_assert (AT_loc_list (a
)->num_assigned
);
8951 size
+= size_of_uleb128 (AT_loc_list (a
)->hash
);
8954 size
+= DWARF_OFFSET_SIZE
;
8956 case dw_val_class_range_list
:
8957 if (value_format (a
) == DW_FORM_rnglistx
)
8959 gcc_assert (rnglist_idx
);
8960 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
8961 size
+= size_of_uleb128 (r
->idx
);
8964 size
+= DWARF_OFFSET_SIZE
;
8966 case dw_val_class_const
:
8967 size
+= size_of_sleb128 (AT_int (a
));
8969 case dw_val_class_unsigned_const
:
8971 int csize
= constant_size (AT_unsigned (a
));
8972 if (dwarf_version
== 3
8973 && a
->dw_attr
== DW_AT_data_member_location
8975 size
+= size_of_uleb128 (AT_unsigned (a
));
8980 case dw_val_class_const_implicit
:
8981 case dw_val_class_unsigned_const_implicit
:
8982 case dw_val_class_file_implicit
:
8983 /* These occupy no size in the DIE, just an extra sleb128 in
8986 case dw_val_class_const_double
:
8987 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
8988 if (HOST_BITS_PER_WIDE_INT
>= DWARF_LARGEST_DATA_FORM_BITS
)
8991 case dw_val_class_wide_int
:
8992 size
+= (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
8993 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
8994 if (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
8995 * HOST_BITS_PER_WIDE_INT
> DWARF_LARGEST_DATA_FORM_BITS
)
8998 case dw_val_class_vec
:
8999 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
9000 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
9001 + a
->dw_attr_val
.v
.val_vec
.length
9002 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
9004 case dw_val_class_flag
:
9005 if (dwarf_version
>= 4)
9006 /* Currently all add_AT_flag calls pass in 1 as last argument,
9007 so DW_FORM_flag_present can be used. If that ever changes,
9008 we'll need to use DW_FORM_flag and have some optimization
9009 in build_abbrev_table that will change those to
9010 DW_FORM_flag_present if it is set to 1 in all DIEs using
9011 the same abbrev entry. */
9012 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
9016 case dw_val_class_die_ref
:
9017 if (AT_ref_external (a
))
9019 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
9020 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
9021 is sized by target address length, whereas in DWARF3
9022 it's always sized as an offset. */
9023 if (use_debug_types
)
9024 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
9025 else if (dwarf_version
== 2)
9026 size
+= DWARF2_ADDR_SIZE
;
9028 size
+= DWARF_OFFSET_SIZE
;
9031 size
+= DWARF_OFFSET_SIZE
;
9033 case dw_val_class_fde_ref
:
9034 size
+= DWARF_OFFSET_SIZE
;
9036 case dw_val_class_lbl_id
:
9037 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
9039 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
9040 size
+= size_of_uleb128 (AT_index (a
));
9043 size
+= DWARF2_ADDR_SIZE
;
9045 case dw_val_class_lineptr
:
9046 case dw_val_class_macptr
:
9047 case dw_val_class_loclistsptr
:
9048 size
+= DWARF_OFFSET_SIZE
;
9050 case dw_val_class_str
:
9051 form
= AT_string_form (a
);
9052 if (form
== DW_FORM_strp
|| form
== DW_FORM_line_strp
)
9053 size
+= DWARF_OFFSET_SIZE
;
9054 else if (form
== DW_FORM_GNU_str_index
)
9055 size
+= size_of_uleb128 (AT_index (a
));
9057 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
9059 case dw_val_class_file
:
9060 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
9062 case dw_val_class_data8
:
9065 case dw_val_class_vms_delta
:
9066 size
+= DWARF_OFFSET_SIZE
;
9068 case dw_val_class_high_pc
:
9069 size
+= DWARF2_ADDR_SIZE
;
9071 case dw_val_class_discr_value
:
9072 size
+= size_of_discr_value (&a
->dw_attr_val
.v
.val_discr_value
);
9074 case dw_val_class_discr_list
:
9076 unsigned block_size
= size_of_discr_list (AT_discr_list (a
));
9078 /* This is a block, so we have the block length and then its
9080 size
+= constant_size (block_size
) + block_size
;
9091 /* Size the debugging information associated with a given DIE. Visits the
9092 DIE's children recursively. Updates the global variable next_die_offset, on
9093 each time through. Uses the current value of next_die_offset to update the
9094 die_offset field in each DIE. */
9097 calc_die_sizes (dw_die_ref die
)
9101 gcc_assert (die
->die_offset
== 0
9102 || (unsigned long int) die
->die_offset
== next_die_offset
);
9103 die
->die_offset
= next_die_offset
;
9104 next_die_offset
+= size_of_die (die
);
9106 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
9108 if (die
->die_child
!= NULL
)
9109 /* Count the null byte used to terminate sibling lists. */
9110 next_die_offset
+= 1;
9113 /* Size just the base type children at the start of the CU.
9114 This is needed because build_abbrev needs to size locs
9115 and sizing of type based stack ops needs to know die_offset
9116 values for the base types. */
9119 calc_base_type_die_sizes (void)
9121 unsigned long die_offset
= (dwarf_split_debug_info
9122 ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
9123 : DWARF_COMPILE_UNIT_HEADER_SIZE
);
9125 dw_die_ref base_type
;
9126 #if ENABLE_ASSERT_CHECKING
9127 dw_die_ref prev
= comp_unit_die ()->die_child
;
9130 die_offset
+= size_of_die (comp_unit_die ());
9131 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
9133 #if ENABLE_ASSERT_CHECKING
9134 gcc_assert (base_type
->die_offset
== 0
9135 && prev
->die_sib
== base_type
9136 && base_type
->die_child
== NULL
9137 && base_type
->die_abbrev
);
9140 if (abbrev_opt_start
9141 && base_type
->die_abbrev
>= abbrev_opt_base_type_end
)
9142 abbrev_opt_base_type_end
= base_type
->die_abbrev
+ 1;
9143 base_type
->die_offset
= die_offset
;
9144 die_offset
+= size_of_die (base_type
);
9148 /* Set the marks for a die and its children. We do this so
9149 that we know whether or not a reference needs to use FORM_ref_addr; only
9150 DIEs in the same CU will be marked. We used to clear out the offset
9151 and use that as the flag, but ran into ordering problems. */
9154 mark_dies (dw_die_ref die
)
9158 gcc_assert (!die
->die_mark
);
9161 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
9164 /* Clear the marks for a die and its children. */
9167 unmark_dies (dw_die_ref die
)
9171 if (! use_debug_types
)
9172 gcc_assert (die
->die_mark
);
9175 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
9178 /* Clear the marks for a die, its children and referred dies. */
9181 unmark_all_dies (dw_die_ref die
)
9191 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
9193 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9194 if (AT_class (a
) == dw_val_class_die_ref
)
9195 unmark_all_dies (AT_ref (a
));
9198 /* Calculate if the entry should appear in the final output file. It may be
9199 from a pruned a type. */
9202 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
9204 /* By limiting gnu pubnames to definitions only, gold can generate a
9205 gdb index without entries for declarations, which don't include
9206 enough information to be useful. */
9207 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
9210 if (table
== pubname_table
)
9212 /* Enumerator names are part of the pubname table, but the
9213 parent DW_TAG_enumeration_type die may have been pruned.
9214 Don't output them if that is the case. */
9215 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
9216 (p
->die
->die_parent
== NULL
9217 || !p
->die
->die_parent
->die_perennial_p
))
9220 /* Everything else in the pubname table is included. */
9224 /* The pubtypes table shouldn't include types that have been
9226 return (p
->die
->die_offset
!= 0
9227 || !flag_eliminate_unused_debug_types
);
9230 /* Return the size of the .debug_pubnames or .debug_pubtypes table
9231 generated for the compilation unit. */
9233 static unsigned long
9234 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9239 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
9241 size
= DWARF_PUBNAMES_HEADER_SIZE
;
9242 FOR_EACH_VEC_ELT (*names
, i
, p
)
9243 if (include_pubname_in_output (names
, p
))
9244 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
9246 size
+= DWARF_OFFSET_SIZE
;
9250 /* Return the size of the information in the .debug_aranges section. */
9252 static unsigned long
9253 size_of_aranges (void)
9257 size
= DWARF_ARANGES_HEADER_SIZE
;
9259 /* Count the address/length pair for this compilation unit. */
9260 if (text_section_used
)
9261 size
+= 2 * DWARF2_ADDR_SIZE
;
9262 if (cold_text_section_used
)
9263 size
+= 2 * DWARF2_ADDR_SIZE
;
9264 if (have_multiple_function_sections
)
9269 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9271 if (DECL_IGNORED_P (fde
->decl
))
9273 if (!fde
->in_std_section
)
9274 size
+= 2 * DWARF2_ADDR_SIZE
;
9275 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9276 size
+= 2 * DWARF2_ADDR_SIZE
;
9280 /* Count the two zero words used to terminated the address range table. */
9281 size
+= 2 * DWARF2_ADDR_SIZE
;
9285 /* Select the encoding of an attribute value. */
9287 static enum dwarf_form
9288 value_format (dw_attr_node
*a
)
9290 switch (AT_class (a
))
9292 case dw_val_class_addr
:
9293 /* Only very few attributes allow DW_FORM_addr. */
9298 case DW_AT_entry_pc
:
9299 case DW_AT_trampoline
:
9300 return (AT_index (a
) == NOT_INDEXED
9301 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
9305 switch (DWARF2_ADDR_SIZE
)
9308 return DW_FORM_data1
;
9310 return DW_FORM_data2
;
9312 return DW_FORM_data4
;
9314 return DW_FORM_data8
;
9318 case dw_val_class_loc_list
:
9319 if (dwarf_split_debug_info
9320 && dwarf_version
>= 5
9321 && AT_loc_list (a
)->num_assigned
)
9322 return DW_FORM_loclistx
;
9324 case dw_val_class_range_list
:
9325 /* For range lists in DWARF 5, use DW_FORM_rnglistx from .debug_info.dwo
9326 but in .debug_info use DW_FORM_sec_offset, which is shorter if we
9327 care about sizes of .debug* sections in shared libraries and
9328 executables and don't take into account relocations that affect just
9329 relocatable objects - for DW_FORM_rnglistx we'd have to emit offset
9330 table in the .debug_rnglists section. */
9331 if (dwarf_split_debug_info
9332 && dwarf_version
>= 5
9333 && AT_class (a
) == dw_val_class_range_list
9335 && a
->dw_attr_val
.val_entry
!= RELOCATED_OFFSET
)
9336 return DW_FORM_rnglistx
;
9337 if (dwarf_version
>= 4)
9338 return DW_FORM_sec_offset
;
9340 case dw_val_class_vms_delta
:
9341 case dw_val_class_offset
:
9342 switch (DWARF_OFFSET_SIZE
)
9345 return DW_FORM_data4
;
9347 return DW_FORM_data8
;
9351 case dw_val_class_loc
:
9352 if (dwarf_version
>= 4)
9353 return DW_FORM_exprloc
;
9354 switch (constant_size (size_of_locs (AT_loc (a
))))
9357 return DW_FORM_block1
;
9359 return DW_FORM_block2
;
9361 return DW_FORM_block4
;
9365 case dw_val_class_const
:
9366 return DW_FORM_sdata
;
9367 case dw_val_class_unsigned_const
:
9368 switch (constant_size (AT_unsigned (a
)))
9371 return DW_FORM_data1
;
9373 return DW_FORM_data2
;
9375 /* In DWARF3 DW_AT_data_member_location with
9376 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
9377 constant, so we need to use DW_FORM_udata if we need
9378 a large constant. */
9379 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
9380 return DW_FORM_udata
;
9381 return DW_FORM_data4
;
9383 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
9384 return DW_FORM_udata
;
9385 return DW_FORM_data8
;
9389 case dw_val_class_const_implicit
:
9390 case dw_val_class_unsigned_const_implicit
:
9391 case dw_val_class_file_implicit
:
9392 return DW_FORM_implicit_const
;
9393 case dw_val_class_const_double
:
9394 switch (HOST_BITS_PER_WIDE_INT
)
9397 return DW_FORM_data2
;
9399 return DW_FORM_data4
;
9401 return DW_FORM_data8
;
9403 if (dwarf_version
>= 5)
9404 return DW_FORM_data16
;
9407 return DW_FORM_block1
;
9409 case dw_val_class_wide_int
:
9410 switch (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
)
9413 return DW_FORM_data1
;
9415 return DW_FORM_data2
;
9417 return DW_FORM_data4
;
9419 return DW_FORM_data8
;
9421 if (dwarf_version
>= 5)
9422 return DW_FORM_data16
;
9425 return DW_FORM_block1
;
9427 case dw_val_class_vec
:
9428 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
9429 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
9432 return DW_FORM_block1
;
9434 return DW_FORM_block2
;
9436 return DW_FORM_block4
;
9440 case dw_val_class_flag
:
9441 if (dwarf_version
>= 4)
9443 /* Currently all add_AT_flag calls pass in 1 as last argument,
9444 so DW_FORM_flag_present can be used. If that ever changes,
9445 we'll need to use DW_FORM_flag and have some optimization
9446 in build_abbrev_table that will change those to
9447 DW_FORM_flag_present if it is set to 1 in all DIEs using
9448 the same abbrev entry. */
9449 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
9450 return DW_FORM_flag_present
;
9452 return DW_FORM_flag
;
9453 case dw_val_class_die_ref
:
9454 if (AT_ref_external (a
))
9455 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
9458 case dw_val_class_fde_ref
:
9459 return DW_FORM_data
;
9460 case dw_val_class_lbl_id
:
9461 return (AT_index (a
) == NOT_INDEXED
9462 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
9463 case dw_val_class_lineptr
:
9464 case dw_val_class_macptr
:
9465 case dw_val_class_loclistsptr
:
9466 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
9467 case dw_val_class_str
:
9468 return AT_string_form (a
);
9469 case dw_val_class_file
:
9470 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
9473 return DW_FORM_data1
;
9475 return DW_FORM_data2
;
9477 return DW_FORM_data4
;
9482 case dw_val_class_data8
:
9483 return DW_FORM_data8
;
9485 case dw_val_class_high_pc
:
9486 switch (DWARF2_ADDR_SIZE
)
9489 return DW_FORM_data1
;
9491 return DW_FORM_data2
;
9493 return DW_FORM_data4
;
9495 return DW_FORM_data8
;
9500 case dw_val_class_discr_value
:
9501 return (a
->dw_attr_val
.v
.val_discr_value
.pos
9504 case dw_val_class_discr_list
:
9505 switch (constant_size (size_of_discr_list (AT_discr_list (a
))))
9508 return DW_FORM_block1
;
9510 return DW_FORM_block2
;
9512 return DW_FORM_block4
;
9522 /* Output the encoding of an attribute value. */
9525 output_value_format (dw_attr_node
*a
)
9527 enum dwarf_form form
= value_format (a
);
9529 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
9532 /* Given a die and id, produce the appropriate abbreviations. */
9535 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
9538 dw_attr_node
*a_attr
;
9540 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
9541 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
9542 dwarf_tag_name (abbrev
->die_tag
));
9544 if (abbrev
->die_child
!= NULL
)
9545 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
9547 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
9549 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
9551 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
9552 dwarf_attr_name (a_attr
->dw_attr
));
9553 output_value_format (a_attr
);
9554 if (value_format (a_attr
) == DW_FORM_implicit_const
)
9556 if (AT_class (a_attr
) == dw_val_class_file_implicit
)
9558 int f
= maybe_emit_file (a_attr
->dw_attr_val
.v
.val_file
);
9559 const char *filename
= a_attr
->dw_attr_val
.v
.val_file
->filename
;
9560 dw2_asm_output_data_sleb128 (f
, "(%s)", filename
);
9563 dw2_asm_output_data_sleb128 (a_attr
->dw_attr_val
.v
.val_int
, NULL
);
9567 dw2_asm_output_data (1, 0, NULL
);
9568 dw2_asm_output_data (1, 0, NULL
);
9572 /* Output the .debug_abbrev section which defines the DIE abbreviation
9576 output_abbrev_section (void)
9578 unsigned int abbrev_id
;
9581 FOR_EACH_VEC_SAFE_ELT (abbrev_die_table
, abbrev_id
, abbrev
)
9583 output_die_abbrevs (abbrev_id
, abbrev
);
9585 /* Terminate the table. */
9586 dw2_asm_output_data (1, 0, NULL
);
9589 /* Output a symbol we can use to refer to this DIE from another CU. */
9592 output_die_symbol (dw_die_ref die
)
9594 const char *sym
= die
->die_id
.die_symbol
;
9596 gcc_assert (!die
->comdat_type_p
);
9601 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
9602 /* We make these global, not weak; if the target doesn't support
9603 .linkonce, it doesn't support combining the sections, so debugging
9605 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
9607 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
9610 /* Return a new location list, given the begin and end range, and the
9613 static inline dw_loc_list_ref
9614 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
9615 const char *section
)
9617 dw_loc_list_ref retlist
= ggc_cleared_alloc
<dw_loc_list_node
> ();
9619 retlist
->begin
= begin
;
9620 retlist
->begin_entry
= NULL
;
9622 retlist
->expr
= expr
;
9623 retlist
->section
= section
;
9628 /* Generate a new internal symbol for this location list node, if it
9629 hasn't got one yet. */
9632 gen_llsym (dw_loc_list_ref list
)
9634 gcc_assert (!list
->ll_symbol
);
9635 list
->ll_symbol
= gen_internal_sym ("LLST");
9638 /* Output the location list given to us. */
9641 output_loc_list (dw_loc_list_ref list_head
)
9643 if (list_head
->emitted
)
9645 list_head
->emitted
= true;
9647 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
9649 dw_loc_list_ref curr
= list_head
;
9650 const char *last_section
= NULL
;
9651 const char *base_label
= NULL
;
9653 /* Walk the location list, and output each range + expression. */
9654 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
9657 /* Don't output an entry that starts and ends at the same address. */
9658 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
9660 size
= size_of_locs (curr
->expr
);
9661 /* If the expression is too large, drop it on the floor. We could
9662 perhaps put it into DW_TAG_dwarf_procedure and refer to that
9663 in the expression, but >= 64KB expressions for a single value
9664 in a single range are unlikely very useful. */
9665 if (dwarf_version
< 5 && size
> 0xffff)
9667 if (dwarf_version
>= 5)
9669 if (dwarf_split_debug_info
)
9671 /* For -gsplit-dwarf, emit DW_LLE_starx_length, which has
9672 uleb128 index into .debug_addr and uleb128 length. */
9673 dw2_asm_output_data (1, DW_LLE_startx_length
,
9674 "DW_LLE_startx_length (%s)",
9675 list_head
->ll_symbol
);
9676 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
9677 "Location list range start index "
9678 "(%s)", curr
->begin
);
9679 /* FIXME: This will ICE ifndef HAVE_AS_LEB128.
9680 For that case we probably need to emit DW_LLE_startx_endx,
9681 but we'd need 2 .debug_addr entries rather than just one. */
9682 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->begin
,
9683 "Location list length (%s)",
9684 list_head
->ll_symbol
);
9686 else if (!have_multiple_function_sections
&& HAVE_AS_LEB128
)
9688 /* If all code is in .text section, the base address is
9689 already provided by the CU attributes. Use
9690 DW_LLE_offset_pair where both addresses are uleb128 encoded
9691 offsets against that base. */
9692 dw2_asm_output_data (1, DW_LLE_offset_pair
,
9693 "DW_LLE_offset_pair (%s)",
9694 list_head
->ll_symbol
);
9695 dw2_asm_output_delta_uleb128 (curr
->begin
, curr
->section
,
9696 "Location list begin address (%s)",
9697 list_head
->ll_symbol
);
9698 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->section
,
9699 "Location list end address (%s)",
9700 list_head
->ll_symbol
);
9702 else if (HAVE_AS_LEB128
)
9704 /* Otherwise, find out how many consecutive entries could share
9705 the same base entry. If just one, emit DW_LLE_start_length,
9706 otherwise emit DW_LLE_base_address for the base address
9707 followed by a series of DW_LLE_offset_pair. */
9708 if (last_section
== NULL
|| curr
->section
!= last_section
)
9710 dw_loc_list_ref curr2
;
9711 for (curr2
= curr
->dw_loc_next
; curr2
!= NULL
;
9712 curr2
= curr2
->dw_loc_next
)
9714 if (strcmp (curr2
->begin
, curr2
->end
) == 0
9719 if (curr2
== NULL
|| curr
->section
!= curr2
->section
)
9720 last_section
= NULL
;
9723 last_section
= curr
->section
;
9724 base_label
= curr
->begin
;
9725 dw2_asm_output_data (1, DW_LLE_base_address
,
9726 "DW_LLE_base_address (%s)",
9727 list_head
->ll_symbol
);
9728 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, base_label
,
9729 "Base address (%s)",
9730 list_head
->ll_symbol
);
9733 /* Only one entry with the same base address. Use
9734 DW_LLE_start_length with absolute address and uleb128
9736 if (last_section
== NULL
)
9738 dw2_asm_output_data (1, DW_LLE_start_length
,
9739 "DW_LLE_start_length (%s)",
9740 list_head
->ll_symbol
);
9741 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
9742 "Location list begin address (%s)",
9743 list_head
->ll_symbol
);
9744 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->begin
,
9745 "Location list length "
9746 "(%s)", list_head
->ll_symbol
);
9748 /* Otherwise emit DW_LLE_offset_pair, relative to above emitted
9749 DW_LLE_base_address. */
9752 dw2_asm_output_data (1, DW_LLE_offset_pair
,
9753 "DW_LLE_offset_pair (%s)",
9754 list_head
->ll_symbol
);
9755 dw2_asm_output_delta_uleb128 (curr
->begin
, base_label
,
9756 "Location list begin address "
9757 "(%s)", list_head
->ll_symbol
);
9758 dw2_asm_output_delta_uleb128 (curr
->end
, base_label
,
9759 "Location list end address "
9760 "(%s)", list_head
->ll_symbol
);
9763 /* The assembler does not support .uleb128 directive. Emit
9764 DW_LLE_start_end with a pair of absolute addresses. */
9767 dw2_asm_output_data (1, DW_LLE_start_end
,
9768 "DW_LLE_start_end (%s)",
9769 list_head
->ll_symbol
);
9770 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
9771 "Location list begin address (%s)",
9772 list_head
->ll_symbol
);
9773 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
9774 "Location list end address (%s)",
9775 list_head
->ll_symbol
);
9778 else if (dwarf_split_debug_info
)
9780 /* For -gsplit-dwarf -gdwarf-{2,3,4} emit index into .debug_addr
9781 and 4 byte length. */
9782 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
9783 "Location list start/length entry (%s)",
9784 list_head
->ll_symbol
);
9785 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
9786 "Location list range start index (%s)",
9788 /* The length field is 4 bytes. If we ever need to support
9789 an 8-byte length, we can add a new DW_LLE code or fall back
9790 to DW_LLE_GNU_start_end_entry. */
9791 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
9792 "Location list range length (%s)",
9793 list_head
->ll_symbol
);
9795 else if (!have_multiple_function_sections
)
9797 /* Pair of relative addresses against start of text section. */
9798 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
9799 "Location list begin address (%s)",
9800 list_head
->ll_symbol
);
9801 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
9802 "Location list end address (%s)",
9803 list_head
->ll_symbol
);
9807 /* Pair of absolute addresses. */
9808 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
9809 "Location list begin address (%s)",
9810 list_head
->ll_symbol
);
9811 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
9812 "Location list end address (%s)",
9813 list_head
->ll_symbol
);
9816 /* Output the block length for this list of location operations. */
9817 if (dwarf_version
>= 5)
9818 dw2_asm_output_data_uleb128 (size
, "Location expression size");
9821 gcc_assert (size
<= 0xffff);
9822 dw2_asm_output_data (2, size
, "Location expression size");
9825 output_loc_sequence (curr
->expr
, -1);
9828 /* And finally list termination. */
9829 if (dwarf_version
>= 5)
9830 dw2_asm_output_data (1, DW_LLE_end_of_list
,
9831 "DW_LLE_end_of_list (%s)", list_head
->ll_symbol
);
9832 else if (dwarf_split_debug_info
)
9833 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
9834 "Location list terminator (%s)",
9835 list_head
->ll_symbol
);
9838 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
9839 "Location list terminator begin (%s)",
9840 list_head
->ll_symbol
);
9841 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
9842 "Location list terminator end (%s)",
9843 list_head
->ll_symbol
);
9847 /* Output a range_list offset into the .debug_ranges or .debug_rnglists
9848 section. Emit a relocated reference if val_entry is NULL, otherwise,
9849 emit an indirect reference. */
9852 output_range_list_offset (dw_attr_node
*a
)
9854 const char *name
= dwarf_attr_name (a
->dw_attr
);
9856 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
9858 if (dwarf_version
>= 5)
9860 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
9861 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, r
->label
,
9862 debug_ranges_section
, "%s", name
);
9866 char *p
= strchr (ranges_section_label
, '\0');
9867 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
9868 a
->dw_attr_val
.v
.val_offset
* 2 * DWARF2_ADDR_SIZE
);
9869 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
9870 debug_ranges_section
, "%s", name
);
9874 else if (dwarf_version
>= 5)
9876 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
9877 gcc_assert (rnglist_idx
);
9878 dw2_asm_output_data_uleb128 (r
->idx
, "%s", name
);
9881 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9882 a
->dw_attr_val
.v
.val_offset
* 2 * DWARF2_ADDR_SIZE
,
9883 "%s (offset from %s)", name
, ranges_section_label
);
9886 /* Output the offset into the debug_loc section. */
9889 output_loc_list_offset (dw_attr_node
*a
)
9891 char *sym
= AT_loc_list (a
)->ll_symbol
;
9894 if (!dwarf_split_debug_info
)
9895 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
9896 "%s", dwarf_attr_name (a
->dw_attr
));
9897 else if (dwarf_version
>= 5)
9899 gcc_assert (AT_loc_list (a
)->num_assigned
);
9900 dw2_asm_output_data_uleb128 (AT_loc_list (a
)->hash
, "%s (%s)",
9901 dwarf_attr_name (a
->dw_attr
),
9905 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
9906 "%s", dwarf_attr_name (a
->dw_attr
));
9909 /* Output an attribute's index or value appropriately. */
9912 output_attr_index_or_value (dw_attr_node
*a
)
9914 const char *name
= dwarf_attr_name (a
->dw_attr
);
9916 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
9918 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
9921 switch (AT_class (a
))
9923 case dw_val_class_addr
:
9924 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
9926 case dw_val_class_high_pc
:
9927 case dw_val_class_lbl_id
:
9928 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
9935 /* Output a type signature. */
9938 output_signature (const char *sig
, const char *name
)
9942 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9943 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
9946 /* Output a discriminant value. */
9949 output_discr_value (dw_discr_value
*discr_value
, const char *name
)
9951 if (discr_value
->pos
)
9952 dw2_asm_output_data_uleb128 (discr_value
->v
.uval
, "%s", name
);
9954 dw2_asm_output_data_sleb128 (discr_value
->v
.sval
, "%s", name
);
9957 /* Output the DIE and its attributes. Called recursively to generate
9958 the definitions of each child DIE. */
9961 output_die (dw_die_ref die
)
9968 /* If someone in another CU might refer to us, set up a symbol for
9969 them to point to. */
9970 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
9971 output_die_symbol (die
);
9973 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
9974 (unsigned long)die
->die_offset
,
9975 dwarf_tag_name (die
->die_tag
));
9977 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9979 const char *name
= dwarf_attr_name (a
->dw_attr
);
9981 switch (AT_class (a
))
9983 case dw_val_class_addr
:
9984 output_attr_index_or_value (a
);
9987 case dw_val_class_offset
:
9988 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
9992 case dw_val_class_range_list
:
9993 output_range_list_offset (a
);
9996 case dw_val_class_loc
:
9997 size
= size_of_locs (AT_loc (a
));
9999 /* Output the block length for this list of location operations. */
10000 if (dwarf_version
>= 4)
10001 dw2_asm_output_data_uleb128 (size
, "%s", name
);
10003 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
10005 output_loc_sequence (AT_loc (a
), -1);
10008 case dw_val_class_const
:
10009 /* ??? It would be slightly more efficient to use a scheme like is
10010 used for unsigned constants below, but gdb 4.x does not sign
10011 extend. Gdb 5.x does sign extend. */
10012 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
10015 case dw_val_class_unsigned_const
:
10017 int csize
= constant_size (AT_unsigned (a
));
10018 if (dwarf_version
== 3
10019 && a
->dw_attr
== DW_AT_data_member_location
10021 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
10023 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
10027 case dw_val_class_const_implicit
:
10028 if (flag_debug_asm
)
10029 fprintf (asm_out_file
, "\t\t\t%s %s ("
10030 HOST_WIDE_INT_PRINT_DEC
")\n",
10031 ASM_COMMENT_START
, name
, AT_int (a
));
10034 case dw_val_class_unsigned_const_implicit
:
10035 if (flag_debug_asm
)
10036 fprintf (asm_out_file
, "\t\t\t%s %s ("
10037 HOST_WIDE_INT_PRINT_HEX
")\n",
10038 ASM_COMMENT_START
, name
, AT_unsigned (a
));
10041 case dw_val_class_const_double
:
10043 unsigned HOST_WIDE_INT first
, second
;
10045 if (HOST_BITS_PER_WIDE_INT
>= DWARF_LARGEST_DATA_FORM_BITS
)
10046 dw2_asm_output_data (1,
10047 HOST_BITS_PER_DOUBLE_INT
10048 / HOST_BITS_PER_CHAR
,
10051 if (WORDS_BIG_ENDIAN
)
10053 first
= a
->dw_attr_val
.v
.val_double
.high
;
10054 second
= a
->dw_attr_val
.v
.val_double
.low
;
10058 first
= a
->dw_attr_val
.v
.val_double
.low
;
10059 second
= a
->dw_attr_val
.v
.val_double
.high
;
10062 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
10063 first
, "%s", name
);
10064 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
10069 case dw_val_class_wide_int
:
10072 int len
= get_full_len (*a
->dw_attr_val
.v
.val_wide
);
10073 int l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
10074 if (len
* HOST_BITS_PER_WIDE_INT
> DWARF_LARGEST_DATA_FORM_BITS
)
10075 dw2_asm_output_data (1, get_full_len (*a
->dw_attr_val
.v
.val_wide
)
10078 if (WORDS_BIG_ENDIAN
)
10079 for (i
= len
- 1; i
>= 0; --i
)
10081 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
10086 for (i
= 0; i
< len
; ++i
)
10088 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
10095 case dw_val_class_vec
:
10097 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
10098 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
10102 dw2_asm_output_data (constant_size (len
* elt_size
),
10103 len
* elt_size
, "%s", name
);
10104 if (elt_size
> sizeof (HOST_WIDE_INT
))
10109 for (i
= 0, p
= (unsigned char *) a
->dw_attr_val
.v
.val_vec
.array
;
10111 i
++, p
+= elt_size
)
10112 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
10113 "fp or vector constant word %u", i
);
10117 case dw_val_class_flag
:
10118 if (dwarf_version
>= 4)
10120 /* Currently all add_AT_flag calls pass in 1 as last argument,
10121 so DW_FORM_flag_present can be used. If that ever changes,
10122 we'll need to use DW_FORM_flag and have some optimization
10123 in build_abbrev_table that will change those to
10124 DW_FORM_flag_present if it is set to 1 in all DIEs using
10125 the same abbrev entry. */
10126 gcc_assert (AT_flag (a
) == 1);
10127 if (flag_debug_asm
)
10128 fprintf (asm_out_file
, "\t\t\t%s %s\n",
10129 ASM_COMMENT_START
, name
);
10132 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
10135 case dw_val_class_loc_list
:
10136 output_loc_list_offset (a
);
10139 case dw_val_class_die_ref
:
10140 if (AT_ref_external (a
))
10142 if (AT_ref (a
)->comdat_type_p
)
10144 comdat_type_node
*type_node
10145 = AT_ref (a
)->die_id
.die_type_node
;
10147 gcc_assert (type_node
);
10148 output_signature (type_node
->signature
, name
);
10152 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
10156 /* In DWARF2, DW_FORM_ref_addr is sized by target address
10157 length, whereas in DWARF3 it's always sized as an
10159 if (dwarf_version
== 2)
10160 size
= DWARF2_ADDR_SIZE
;
10162 size
= DWARF_OFFSET_SIZE
;
10163 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
10169 gcc_assert (AT_ref (a
)->die_offset
);
10170 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
10175 case dw_val_class_fde_ref
:
10177 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
10179 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
10180 a
->dw_attr_val
.v
.val_fde_index
* 2);
10181 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
10186 case dw_val_class_vms_delta
:
10187 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
10188 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
10189 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
10192 dw2_asm_output_delta (DWARF_OFFSET_SIZE
,
10193 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
10198 case dw_val_class_lbl_id
:
10199 output_attr_index_or_value (a
);
10202 case dw_val_class_lineptr
:
10203 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
10204 debug_line_section
, "%s", name
);
10207 case dw_val_class_macptr
:
10208 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
10209 debug_macinfo_section
, "%s", name
);
10212 case dw_val_class_loclistsptr
:
10213 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
10214 debug_loc_section
, "%s", name
);
10217 case dw_val_class_str
:
10218 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
10219 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
10220 a
->dw_attr_val
.v
.val_str
->label
,
10222 "%s: \"%s\"", name
, AT_string (a
));
10223 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_line_strp
)
10224 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
10225 a
->dw_attr_val
.v
.val_str
->label
,
10226 debug_line_str_section
,
10227 "%s: \"%s\"", name
, AT_string (a
));
10228 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
10229 dw2_asm_output_data_uleb128 (AT_index (a
),
10230 "%s: \"%s\"", name
, AT_string (a
));
10232 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
10235 case dw_val_class_file
:
10237 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
10239 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
10240 a
->dw_attr_val
.v
.val_file
->filename
);
10244 case dw_val_class_file_implicit
:
10245 if (flag_debug_asm
)
10246 fprintf (asm_out_file
, "\t\t\t%s %s (%d, %s)\n",
10247 ASM_COMMENT_START
, name
,
10248 maybe_emit_file (a
->dw_attr_val
.v
.val_file
),
10249 a
->dw_attr_val
.v
.val_file
->filename
);
10252 case dw_val_class_data8
:
10256 for (i
= 0; i
< 8; i
++)
10257 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
10258 i
== 0 ? "%s" : NULL
, name
);
10262 case dw_val_class_high_pc
:
10263 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
10264 get_AT_low_pc (die
), "DW_AT_high_pc");
10267 case dw_val_class_discr_value
:
10268 output_discr_value (&a
->dw_attr_val
.v
.val_discr_value
, name
);
10271 case dw_val_class_discr_list
:
10273 dw_discr_list_ref list
= AT_discr_list (a
);
10274 const int size
= size_of_discr_list (list
);
10276 /* This is a block, so output its length first. */
10277 dw2_asm_output_data (constant_size (size
), size
,
10278 "%s: block size", name
);
10280 for (; list
!= NULL
; list
= list
->dw_discr_next
)
10282 /* One byte for the discriminant value descriptor, and then as
10283 many LEB128 numbers as required. */
10284 if (list
->dw_discr_range
)
10285 dw2_asm_output_data (1, DW_DSC_range
,
10286 "%s: DW_DSC_range", name
);
10288 dw2_asm_output_data (1, DW_DSC_label
,
10289 "%s: DW_DSC_label", name
);
10291 output_discr_value (&list
->dw_discr_lower_bound
, name
);
10292 if (list
->dw_discr_range
)
10293 output_discr_value (&list
->dw_discr_upper_bound
, name
);
10299 gcc_unreachable ();
10303 FOR_EACH_CHILD (die
, c
, output_die (c
));
10305 /* Add null byte to terminate sibling list. */
10306 if (die
->die_child
!= NULL
)
10307 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
10308 (unsigned long) die
->die_offset
);
10311 /* Output the compilation unit that appears at the beginning of the
10312 .debug_info section, and precedes the DIE descriptions. */
10315 output_compilation_unit_header (enum dwarf_unit_type ut
)
10317 if (!XCOFF_DEBUGGING_INFO
)
10319 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10320 dw2_asm_output_data (4, 0xffffffff,
10321 "Initial length escape value indicating 64-bit DWARF extension");
10322 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
10323 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
10324 "Length of Compilation Unit Info");
10327 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
10328 if (dwarf_version
>= 5)
10333 case DW_UT_compile
: name
= "DW_UT_compile"; break;
10334 case DW_UT_type
: name
= "DW_UT_type"; break;
10335 case DW_UT_split_compile
: name
= "DW_UT_split_compile"; break;
10336 case DW_UT_split_type
: name
= "DW_UT_split_type"; break;
10337 default: gcc_unreachable ();
10339 dw2_asm_output_data (1, ut
, "%s", name
);
10340 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10342 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
10343 debug_abbrev_section
,
10344 "Offset Into Abbrev. Section");
10345 if (dwarf_version
< 5)
10346 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10349 /* Output the compilation unit DIE and its children. */
10352 output_comp_unit (dw_die_ref die
, int output_if_empty
,
10353 const unsigned char *dwo_id
)
10355 const char *secname
, *oldsym
;
10358 /* Unless we are outputting main CU, we may throw away empty ones. */
10359 if (!output_if_empty
&& die
->die_child
== NULL
)
10362 /* Even if there are no children of this DIE, we must output the information
10363 about the compilation unit. Otherwise, on an empty translation unit, we
10364 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
10365 will then complain when examining the file. First mark all the DIEs in
10366 this CU so we know which get local refs. */
10369 external_ref_hash_type
*extern_map
= optimize_external_refs (die
);
10371 /* For now, optimize only the main CU, in order to optimize the rest
10372 we'd need to see all of them earlier. Leave the rest for post-linking
10374 if (die
== comp_unit_die ())
10375 abbrev_opt_start
= vec_safe_length (abbrev_die_table
);
10377 build_abbrev_table (die
, extern_map
);
10379 optimize_abbrev_table ();
10383 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
10384 next_die_offset
= (dwo_id
10385 ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
10386 : DWARF_COMPILE_UNIT_HEADER_SIZE
);
10387 calc_die_sizes (die
);
10389 oldsym
= die
->die_id
.die_symbol
;
10392 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
10394 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
10396 die
->die_id
.die_symbol
= NULL
;
10397 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
10401 switch_to_section (debug_info_section
);
10402 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
10403 info_section_emitted
= true;
10406 /* Output debugging information. */
10407 output_compilation_unit_header (dwo_id
10408 ? DW_UT_split_compile
: DW_UT_compile
);
10409 if (dwarf_version
>= 5)
10411 if (dwo_id
!= NULL
)
10412 for (int i
= 0; i
< 8; i
++)
10413 dw2_asm_output_data (1, dwo_id
[i
], i
== 0 ? "DWO id" : NULL
);
10417 /* Leave the marks on the main CU, so we can check them in
10418 output_pubnames. */
10422 die
->die_id
.die_symbol
= oldsym
;
10426 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
10427 and .debug_pubtypes. This is configured per-target, but can be
10428 overridden by the -gpubnames or -gno-pubnames options. */
10431 want_pubnames (void)
10433 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
10435 if (debug_generate_pub_sections
!= -1)
10436 return debug_generate_pub_sections
;
10437 return targetm
.want_debug_pub_sections
;
10440 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
10443 add_AT_pubnames (dw_die_ref die
)
10445 if (want_pubnames ())
10446 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
10449 /* Add a string attribute value to a skeleton DIE. */
10452 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
10456 struct indirect_string_node
*node
;
10458 if (! skeleton_debug_str_hash
)
10459 skeleton_debug_str_hash
10460 = hash_table
<indirect_string_hasher
>::create_ggc (10);
10462 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
10463 find_string_form (node
);
10464 if (node
->form
== DW_FORM_GNU_str_index
)
10465 node
->form
= DW_FORM_strp
;
10467 attr
.dw_attr
= attr_kind
;
10468 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
10469 attr
.dw_attr_val
.val_entry
= NULL
;
10470 attr
.dw_attr_val
.v
.val_str
= node
;
10471 add_dwarf_attr (die
, &attr
);
10474 /* Helper function to generate top-level dies for skeleton debug_info and
10478 add_top_level_skeleton_die_attrs (dw_die_ref die
)
10480 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
10481 const char *comp_dir
= comp_dir_string ();
10483 add_skeleton_AT_string (die
, dwarf_AT (DW_AT_dwo_name
), dwo_file_name
);
10484 if (comp_dir
!= NULL
)
10485 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
10486 add_AT_pubnames (die
);
10487 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
10490 /* Output skeleton debug sections that point to the dwo file. */
10493 output_skeleton_debug_sections (dw_die_ref comp_unit
,
10494 const unsigned char *dwo_id
)
10496 /* These attributes will be found in the full debug_info section. */
10497 remove_AT (comp_unit
, DW_AT_producer
);
10498 remove_AT (comp_unit
, DW_AT_language
);
10500 switch_to_section (debug_skeleton_info_section
);
10501 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
10503 /* Produce the skeleton compilation-unit header. This one differs enough from
10504 a normal CU header that it's better not to call output_compilation_unit
10506 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10507 dw2_asm_output_data (4, 0xffffffff,
10508 "Initial length escape value indicating 64-bit "
10509 "DWARF extension");
10511 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
10512 DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
10513 - DWARF_INITIAL_LENGTH_SIZE
10514 + size_of_die (comp_unit
),
10515 "Length of Compilation Unit Info");
10516 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
10517 if (dwarf_version
>= 5)
10519 dw2_asm_output_data (1, DW_UT_skeleton
, "DW_UT_skeleton");
10520 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10522 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
10523 debug_skeleton_abbrev_section
,
10524 "Offset Into Abbrev. Section");
10525 if (dwarf_version
< 5)
10526 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10528 for (int i
= 0; i
< 8; i
++)
10529 dw2_asm_output_data (1, dwo_id
[i
], i
== 0 ? "DWO id" : NULL
);
10531 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
10532 output_die (comp_unit
);
10534 /* Build the skeleton debug_abbrev section. */
10535 switch_to_section (debug_skeleton_abbrev_section
);
10536 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
10538 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
10540 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
10543 /* Output a comdat type unit DIE and its children. */
10546 output_comdat_type_unit (comdat_type_node
*node
)
10548 const char *secname
;
10551 #if defined (OBJECT_FORMAT_ELF)
10555 /* First mark all the DIEs in this CU so we know which get local refs. */
10556 mark_dies (node
->root_die
);
10558 external_ref_hash_type
*extern_map
= optimize_external_refs (node
->root_die
);
10560 build_abbrev_table (node
->root_die
, extern_map
);
10565 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
10566 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
10567 calc_die_sizes (node
->root_die
);
10569 #if defined (OBJECT_FORMAT_ELF)
10570 if (dwarf_version
>= 5)
10572 if (!dwarf_split_debug_info
)
10573 secname
= ".debug_info";
10575 secname
= ".debug_info.dwo";
10577 else if (!dwarf_split_debug_info
)
10578 secname
= ".debug_types";
10580 secname
= ".debug_types.dwo";
10582 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
10583 sprintf (tmp
, dwarf_version
>= 5 ? "wi." : "wt.");
10584 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
10585 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
10586 comdat_key
= get_identifier (tmp
);
10587 targetm
.asm_out
.named_section (secname
,
10588 SECTION_DEBUG
| SECTION_LINKONCE
,
10591 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
10592 sprintf (tmp
, (dwarf_version
>= 5
10593 ? ".gnu.linkonce.wi." : ".gnu.linkonce.wt."));
10594 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
10595 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
10597 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
10600 /* Output debugging information. */
10601 output_compilation_unit_header (dwarf_split_debug_info
10602 ? DW_UT_split_type
: DW_UT_type
);
10603 output_signature (node
->signature
, "Type Signature");
10604 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
10605 "Offset to Type DIE");
10606 output_die (node
->root_die
);
10608 unmark_dies (node
->root_die
);
10611 /* Return the DWARF2/3 pubname associated with a decl. */
10613 static const char *
10614 dwarf2_name (tree decl
, int scope
)
10616 if (DECL_NAMELESS (decl
))
10618 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
10621 /* Add a new entry to .debug_pubnames if appropriate. */
10624 add_pubname_string (const char *str
, dw_die_ref die
)
10629 e
.name
= xstrdup (str
);
10630 vec_safe_push (pubname_table
, e
);
10634 add_pubname (tree decl
, dw_die_ref die
)
10636 if (!want_pubnames ())
10639 /* Don't add items to the table when we expect that the consumer will have
10640 just read the enclosing die. For example, if the consumer is looking at a
10641 class_member, it will either be inside the class already, or will have just
10642 looked up the class to find the member. Either way, searching the class is
10643 faster than searching the index. */
10644 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
10645 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
10647 const char *name
= dwarf2_name (decl
, 1);
10650 add_pubname_string (name
, die
);
10654 /* Add an enumerator to the pubnames section. */
10657 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
10661 gcc_assert (scope_name
);
10662 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
10664 vec_safe_push (pubname_table
, e
);
10667 /* Add a new entry to .debug_pubtypes if appropriate. */
10670 add_pubtype (tree decl
, dw_die_ref die
)
10674 if (!want_pubnames ())
10677 if ((TREE_PUBLIC (decl
)
10678 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
10679 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
10682 const char *scope_name
= "";
10683 const char *sep
= is_cxx () ? "::" : ".";
10686 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
10687 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
10689 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
10690 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
10691 scope_name
= concat (scope_name
, sep
, NULL
);
10697 name
= type_tag (decl
);
10699 name
= lang_hooks
.dwarf_name (decl
, 1);
10701 /* If we don't have a name for the type, there's no point in adding
10702 it to the table. */
10703 if (name
!= NULL
&& name
[0] != '\0')
10706 e
.name
= concat (scope_name
, name
, NULL
);
10707 vec_safe_push (pubtype_table
, e
);
10710 /* Although it might be more consistent to add the pubinfo for the
10711 enumerators as their dies are created, they should only be added if the
10712 enum type meets the criteria above. So rather than re-check the parent
10713 enum type whenever an enumerator die is created, just output them all
10714 here. This isn't protected by the name conditional because anonymous
10715 enums don't have names. */
10716 if (die
->die_tag
== DW_TAG_enumeration_type
)
10720 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
10725 /* Output a single entry in the pubnames table. */
10728 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
10730 dw_die_ref die
= entry
->die
;
10731 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
10733 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
10735 if (debug_generate_pub_sections
== 2)
10737 /* This logic follows gdb's method for determining the value of the flag
10739 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
10740 switch (die
->die_tag
)
10742 case DW_TAG_typedef
:
10743 case DW_TAG_base_type
:
10744 case DW_TAG_subrange_type
:
10745 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
10746 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
10748 case DW_TAG_enumerator
:
10749 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10750 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
10752 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
10754 case DW_TAG_subprogram
:
10755 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10756 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
10758 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
10760 case DW_TAG_constant
:
10761 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10762 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
10763 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
10765 case DW_TAG_variable
:
10766 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10767 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
10768 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
10770 case DW_TAG_namespace
:
10771 case DW_TAG_imported_declaration
:
10772 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
10774 case DW_TAG_class_type
:
10775 case DW_TAG_interface_type
:
10776 case DW_TAG_structure_type
:
10777 case DW_TAG_union_type
:
10778 case DW_TAG_enumeration_type
:
10779 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
10781 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
10784 /* An unusual tag. Leave the flag-byte empty. */
10787 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
10788 "GDB-index flags");
10791 dw2_asm_output_nstring (entry
->name
, -1, "external name");
10795 /* Output the public names table used to speed up access to externally
10796 visible names; or the public types table used to find type definitions. */
10799 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
10802 unsigned long pubnames_length
= size_of_pubnames (names
);
10803 pubname_entry
*pub
;
10805 if (!XCOFF_DEBUGGING_INFO
)
10807 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10808 dw2_asm_output_data (4, 0xffffffff,
10809 "Initial length escape value indicating 64-bit DWARF extension");
10810 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
10811 "Pub Info Length");
10814 /* Version number for pubnames/pubtypes is independent of dwarf version. */
10815 dw2_asm_output_data (2, 2, "DWARF Version");
10817 if (dwarf_split_debug_info
)
10818 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
10819 debug_skeleton_info_section
,
10820 "Offset of Compilation Unit Info");
10822 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
10823 debug_info_section
,
10824 "Offset of Compilation Unit Info");
10825 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
10826 "Compilation Unit Length");
10828 FOR_EACH_VEC_ELT (*names
, i
, pub
)
10830 if (include_pubname_in_output (names
, pub
))
10832 dw_offset die_offset
= pub
->die
->die_offset
;
10834 /* We shouldn't see pubnames for DIEs outside of the main CU. */
10835 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
10836 gcc_assert (pub
->die
->die_mark
);
10838 /* If we're putting types in their own .debug_types sections,
10839 the .debug_pubtypes table will still point to the compile
10840 unit (not the type unit), so we want to use the offset of
10841 the skeleton DIE (if there is one). */
10842 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
10844 comdat_type_node
*type_node
= pub
->die
->die_id
.die_type_node
;
10846 if (type_node
!= NULL
)
10847 die_offset
= (type_node
->skeleton_die
!= NULL
10848 ? type_node
->skeleton_die
->die_offset
10849 : comp_unit_die ()->die_offset
);
10852 output_pubname (die_offset
, pub
);
10856 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
10859 /* Output public names and types tables if necessary. */
10862 output_pubtables (void)
10864 if (!want_pubnames () || !info_section_emitted
)
10867 switch_to_section (debug_pubnames_section
);
10868 output_pubnames (pubname_table
);
10869 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
10870 It shouldn't hurt to emit it always, since pure DWARF2 consumers
10871 simply won't look for the section. */
10872 switch_to_section (debug_pubtypes_section
);
10873 output_pubnames (pubtype_table
);
10877 /* Output the information that goes into the .debug_aranges table.
10878 Namely, define the beginning and ending address range of the
10879 text section generated for this compilation unit. */
10882 output_aranges (void)
10885 unsigned long aranges_length
= size_of_aranges ();
10887 if (!XCOFF_DEBUGGING_INFO
)
10889 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10890 dw2_asm_output_data (4, 0xffffffff,
10891 "Initial length escape value indicating 64-bit DWARF extension");
10892 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
10893 "Length of Address Ranges Info");
10896 /* Version number for aranges is still 2, even up to DWARF5. */
10897 dw2_asm_output_data (2, 2, "DWARF Version");
10898 if (dwarf_split_debug_info
)
10899 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
10900 debug_skeleton_info_section
,
10901 "Offset of Compilation Unit Info");
10903 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
10904 debug_info_section
,
10905 "Offset of Compilation Unit Info");
10906 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
10907 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
10909 /* We need to align to twice the pointer size here. */
10910 if (DWARF_ARANGES_PAD_SIZE
)
10912 /* Pad using a 2 byte words so that padding is correct for any
10914 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
10915 2 * DWARF2_ADDR_SIZE
);
10916 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
10917 dw2_asm_output_data (2, 0, NULL
);
10920 /* It is necessary not to output these entries if the sections were
10921 not used; if the sections were not used, the length will be 0 and
10922 the address may end up as 0 if the section is discarded by ld
10923 --gc-sections, leaving an invalid (0, 0) entry that can be
10924 confused with the terminator. */
10925 if (text_section_used
)
10927 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
10928 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
10929 text_section_label
, "Length");
10931 if (cold_text_section_used
)
10933 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
10935 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
10936 cold_text_section_label
, "Length");
10939 if (have_multiple_function_sections
)
10944 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
10946 if (DECL_IGNORED_P (fde
->decl
))
10948 if (!fde
->in_std_section
)
10950 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
10952 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
10953 fde
->dw_fde_begin
, "Length");
10955 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
10957 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
10959 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
10960 fde
->dw_fde_second_begin
, "Length");
10965 /* Output the terminator words. */
10966 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
10967 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
10970 /* Add a new entry to .debug_ranges. Return its index into
10971 ranges_table vector. */
10973 static unsigned int
10974 add_ranges_num (int num
, bool maybe_new_sec
)
10976 dw_ranges r
= { NULL
, num
, 0, maybe_new_sec
};
10977 vec_safe_push (ranges_table
, r
);
10978 return vec_safe_length (ranges_table
) - 1;
10981 /* Add a new entry to .debug_ranges corresponding to a block, or a
10982 range terminator if BLOCK is NULL. MAYBE_NEW_SEC is true if
10983 this entry might be in a different section from previous range. */
10985 static unsigned int
10986 add_ranges (const_tree block
, bool maybe_new_sec
)
10988 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0, maybe_new_sec
);
10991 /* Note that (*rnglist_table)[offset] is either a head of a rnglist
10992 chain, or middle entry of a chain that will be directly referred to. */
10995 note_rnglist_head (unsigned int offset
)
10997 if (dwarf_version
< 5 || (*ranges_table
)[offset
].label
)
10999 (*ranges_table
)[offset
].label
= gen_internal_sym ("LLRL");
11002 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
11003 When using dwarf_split_debug_info, address attributes in dies destined
11004 for the final executable should be direct references--setting the
11005 parameter force_direct ensures this behavior. */
11008 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
11009 bool *added
, bool force_direct
)
11011 unsigned int in_use
= vec_safe_length (ranges_by_label
);
11012 unsigned int offset
;
11013 dw_ranges_by_label rbl
= { begin
, end
};
11014 vec_safe_push (ranges_by_label
, rbl
);
11015 offset
= add_ranges_num (-(int)in_use
- 1, true);
11018 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
11020 note_rnglist_head (offset
);
11024 /* Emit .debug_ranges section. */
11027 output_ranges (void)
11030 static const char *const start_fmt
= "Offset %#x";
11031 const char *fmt
= start_fmt
;
11034 switch_to_section (debug_ranges_section
);
11035 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
11036 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11038 int block_num
= r
->num
;
11042 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11043 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11045 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
11046 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
11048 /* If all code is in the text section, then the compilation
11049 unit base address defaults to DW_AT_low_pc, which is the
11050 base of the text section. */
11051 if (!have_multiple_function_sections
)
11053 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
11054 text_section_label
,
11055 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11056 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
11057 text_section_label
, NULL
);
11060 /* Otherwise, the compilation unit base address is zero,
11061 which allows us to use absolute addresses, and not worry
11062 about whether the target supports cross-section
11066 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11067 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11068 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
11074 /* Negative block_num stands for an index into ranges_by_label. */
11075 else if (block_num
< 0)
11077 int lab_idx
= - block_num
- 1;
11079 if (!have_multiple_function_sections
)
11081 gcc_unreachable ();
11083 /* If we ever use add_ranges_by_labels () for a single
11084 function section, all we have to do is to take out
11085 the #if 0 above. */
11086 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11087 (*ranges_by_label
)[lab_idx
].begin
,
11088 text_section_label
,
11089 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11090 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11091 (*ranges_by_label
)[lab_idx
].end
,
11092 text_section_label
, NULL
);
11097 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11098 (*ranges_by_label
)[lab_idx
].begin
,
11099 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11100 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11101 (*ranges_by_label
)[lab_idx
].end
,
11107 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11108 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11114 /* Non-zero if .debug_line_str should be used for .debug_line section
11115 strings or strings that are likely shareable with those. */
11116 #define DWARF5_USE_DEBUG_LINE_STR \
11117 (!DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET \
11118 && (DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) != 0 \
11119 /* FIXME: there is no .debug_line_str.dwo section, \
11120 for -gsplit-dwarf we should use DW_FORM_strx instead. */ \
11121 && !dwarf_split_debug_info)
11123 /* Assign .debug_rnglists indexes. */
11126 index_rnglists (void)
11131 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11133 r
->idx
= rnglist_idx
++;
11136 /* Emit .debug_rnglists section. */
11139 output_rnglists (void)
11143 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
11144 char l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
11145 char basebuf
[MAX_ARTIFICIAL_LABEL_BYTES
];
11147 switch_to_section (debug_ranges_section
);
11148 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
11149 ASM_GENERATE_INTERNAL_LABEL (l1
, DEBUG_RANGES_SECTION_LABEL
, 2);
11150 ASM_GENERATE_INTERNAL_LABEL (l2
, DEBUG_RANGES_SECTION_LABEL
, 3);
11151 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11152 dw2_asm_output_data (4, 0xffffffff,
11153 "Initial length escape value indicating "
11154 "64-bit DWARF extension");
11155 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
11156 "Length of Range Lists");
11157 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
11158 dw2_asm_output_data (2, dwarf_version
, "DWARF Version");
11159 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
11160 dw2_asm_output_data (1, 0, "Segment Size");
11161 /* Emit the offset table only for -gsplit-dwarf. If we don't care
11162 about relocation sizes and primarily care about the size of .debug*
11163 sections in linked shared libraries and executables, then
11164 the offset table plus corresponding DW_FORM_rnglistx uleb128 indexes
11165 into it are usually larger than just DW_FORM_sec_offset offsets
11166 into the .debug_rnglists section. */
11167 dw2_asm_output_data (4, dwarf_split_debug_info
? rnglist_idx
: 0,
11168 "Offset Entry Count");
11169 if (dwarf_split_debug_info
)
11171 ASM_OUTPUT_LABEL (asm_out_file
, ranges_base_label
);
11172 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11174 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, r
->label
,
11175 ranges_base_label
, NULL
);
11178 const char *lab
= "";
11179 unsigned int len
= vec_safe_length (ranges_table
);
11180 const char *base
= NULL
;
11181 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11183 int block_num
= r
->num
;
11187 ASM_OUTPUT_LABEL (asm_out_file
, r
->label
);
11190 if (HAVE_AS_LEB128
&& (r
->label
|| r
->maybe_new_sec
))
11194 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11195 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11197 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
11198 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
11200 if (HAVE_AS_LEB128
)
11202 /* If all code is in the text section, then the compilation
11203 unit base address defaults to DW_AT_low_pc, which is the
11204 base of the text section. */
11205 if (!have_multiple_function_sections
)
11207 dw2_asm_output_data (1, DW_RLE_offset_pair
,
11208 "DW_RLE_offset_pair (%s)", lab
);
11209 dw2_asm_output_delta_uleb128 (blabel
, text_section_label
,
11210 "Range begin address (%s)", lab
);
11211 dw2_asm_output_delta_uleb128 (elabel
, text_section_label
,
11212 "Range end address (%s)", lab
);
11217 dw_ranges
*r2
= NULL
;
11219 r2
= &(*ranges_table
)[i
+ 1];
11222 && r2
->label
== NULL
11223 && !r2
->maybe_new_sec
)
11225 dw2_asm_output_data (1, DW_RLE_base_address
,
11226 "DW_RLE_base_address (%s)", lab
);
11227 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11228 "Base address (%s)", lab
);
11229 strcpy (basebuf
, blabel
);
11235 dw2_asm_output_data (1, DW_RLE_offset_pair
,
11236 "DW_RLE_offset_pair (%s)", lab
);
11237 dw2_asm_output_delta_uleb128 (blabel
, base
,
11238 "Range begin address (%s)", lab
);
11239 dw2_asm_output_delta_uleb128 (elabel
, base
,
11240 "Range end address (%s)", lab
);
11243 dw2_asm_output_data (1, DW_RLE_start_length
,
11244 "DW_RLE_start_length (%s)", lab
);
11245 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11246 "Range begin address (%s)", lab
);
11247 dw2_asm_output_delta_uleb128 (elabel
, blabel
,
11248 "Range length (%s)", lab
);
11252 dw2_asm_output_data (1, DW_RLE_start_end
,
11253 "DW_RLE_start_end (%s)", lab
);
11254 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11255 "Range begin address (%s)", lab
);
11256 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
,
11257 "Range end address (%s)", lab
);
11261 /* Negative block_num stands for an index into ranges_by_label. */
11262 else if (block_num
< 0)
11264 int lab_idx
= - block_num
- 1;
11265 const char *blabel
= (*ranges_by_label
)[lab_idx
].begin
;
11266 const char *elabel
= (*ranges_by_label
)[lab_idx
].end
;
11268 if (!have_multiple_function_sections
)
11269 gcc_unreachable ();
11270 if (HAVE_AS_LEB128
)
11272 dw2_asm_output_data (1, DW_RLE_start_length
,
11273 "DW_RLE_start_length (%s)", lab
);
11274 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11275 "Range begin address (%s)", lab
);
11276 dw2_asm_output_delta_uleb128 (elabel
, blabel
,
11277 "Range length (%s)", lab
);
11281 dw2_asm_output_data (1, DW_RLE_start_end
,
11282 "DW_RLE_start_end (%s)", lab
);
11283 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11284 "Range begin address (%s)", lab
);
11285 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
,
11286 "Range end address (%s)", lab
);
11290 dw2_asm_output_data (1, DW_RLE_end_of_list
,
11291 "DW_RLE_end_of_list (%s)", lab
);
11293 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
11296 /* Data structure containing information about input files. */
11299 const char *path
; /* Complete file name. */
11300 const char *fname
; /* File name part. */
11301 int length
; /* Length of entire string. */
11302 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
11303 int dir_idx
; /* Index in directory table. */
11306 /* Data structure containing information about directories with source
11310 const char *path
; /* Path including directory name. */
11311 int length
; /* Path length. */
11312 int prefix
; /* Index of directory entry which is a prefix. */
11313 int count
; /* Number of files in this directory. */
11314 int dir_idx
; /* Index of directory used as base. */
11317 /* Callback function for file_info comparison. We sort by looking at
11318 the directories in the path. */
11321 file_info_cmp (const void *p1
, const void *p2
)
11323 const struct file_info
*const s1
= (const struct file_info
*) p1
;
11324 const struct file_info
*const s2
= (const struct file_info
*) p2
;
11325 const unsigned char *cp1
;
11326 const unsigned char *cp2
;
11328 /* Take care of file names without directories. We need to make sure that
11329 we return consistent values to qsort since some will get confused if
11330 we return the same value when identical operands are passed in opposite
11331 orders. So if neither has a directory, return 0 and otherwise return
11332 1 or -1 depending on which one has the directory. */
11333 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
11334 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
11336 cp1
= (const unsigned char *) s1
->path
;
11337 cp2
= (const unsigned char *) s2
->path
;
11343 /* Reached the end of the first path? If so, handle like above. */
11344 if ((cp1
== (const unsigned char *) s1
->fname
)
11345 || (cp2
== (const unsigned char *) s2
->fname
))
11346 return ((cp2
== (const unsigned char *) s2
->fname
)
11347 - (cp1
== (const unsigned char *) s1
->fname
));
11349 /* Character of current path component the same? */
11350 else if (*cp1
!= *cp2
)
11351 return *cp1
- *cp2
;
11355 struct file_name_acquire_data
11357 struct file_info
*files
;
11362 /* Traversal function for the hash table. */
11365 file_name_acquire (dwarf_file_data
**slot
, file_name_acquire_data
*fnad
)
11367 struct dwarf_file_data
*d
= *slot
;
11368 struct file_info
*fi
;
11371 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
11373 if (! d
->emitted_number
)
11376 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
11378 fi
= fnad
->files
+ fnad
->used_files
++;
11380 /* Skip all leading "./". */
11382 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
11385 /* Create a new array entry. */
11387 fi
->length
= strlen (f
);
11390 /* Search for the file name part. */
11391 f
= strrchr (f
, DIR_SEPARATOR
);
11392 #if defined (DIR_SEPARATOR_2)
11394 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
11398 if (f
== NULL
|| f
< g
)
11404 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
11408 /* Helper function for output_file_names. Emit a FORM encoded
11409 string STR, with assembly comment start ENTRY_KIND and
11413 output_line_string (enum dwarf_form form
, const char *str
,
11414 const char *entry_kind
, unsigned int idx
)
11418 case DW_FORM_string
:
11419 dw2_asm_output_nstring (str
, -1, "%s: %#x", entry_kind
, idx
);
11421 case DW_FORM_line_strp
:
11422 if (!debug_line_str_hash
)
11423 debug_line_str_hash
11424 = hash_table
<indirect_string_hasher
>::create_ggc (10);
11426 struct indirect_string_node
*node
;
11427 node
= find_AT_string_in_table (str
, debug_line_str_hash
);
11428 set_indirect_string (node
);
11430 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
11431 debug_line_str_section
, "%s: %#x: \"%s\"",
11432 entry_kind
, 0, node
->str
);
11435 gcc_unreachable ();
11439 /* Output the directory table and the file name table. We try to minimize
11440 the total amount of memory needed. A heuristic is used to avoid large
11441 slowdowns with many input files. */
11444 output_file_names (void)
11446 struct file_name_acquire_data fnad
;
11448 struct file_info
*files
;
11449 struct dir_info
*dirs
;
11457 if (!last_emitted_file
)
11459 if (dwarf_version
>= 5)
11461 dw2_asm_output_data (1, 0, "Directory entry format count");
11462 dw2_asm_output_data_uleb128 (0, "Directories count");
11463 dw2_asm_output_data (1, 0, "File name entry format count");
11464 dw2_asm_output_data_uleb128 (0, "File names count");
11468 dw2_asm_output_data (1, 0, "End directory table");
11469 dw2_asm_output_data (1, 0, "End file name table");
11474 numfiles
= last_emitted_file
->emitted_number
;
11476 /* Allocate the various arrays we need. */
11477 files
= XALLOCAVEC (struct file_info
, numfiles
);
11478 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
11480 fnad
.files
= files
;
11481 fnad
.used_files
= 0;
11482 fnad
.max_files
= numfiles
;
11483 file_table
->traverse
<file_name_acquire_data
*, file_name_acquire
> (&fnad
);
11484 gcc_assert (fnad
.used_files
== fnad
.max_files
);
11486 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
11488 /* Find all the different directories used. */
11489 dirs
[0].path
= files
[0].path
;
11490 dirs
[0].length
= files
[0].fname
- files
[0].path
;
11491 dirs
[0].prefix
= -1;
11493 dirs
[0].dir_idx
= 0;
11494 files
[0].dir_idx
= 0;
11497 for (i
= 1; i
< numfiles
; i
++)
11498 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
11499 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
11500 dirs
[ndirs
- 1].length
) == 0)
11502 /* Same directory as last entry. */
11503 files
[i
].dir_idx
= ndirs
- 1;
11504 ++dirs
[ndirs
- 1].count
;
11510 /* This is a new directory. */
11511 dirs
[ndirs
].path
= files
[i
].path
;
11512 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
11513 dirs
[ndirs
].count
= 1;
11514 dirs
[ndirs
].dir_idx
= ndirs
;
11515 files
[i
].dir_idx
= ndirs
;
11517 /* Search for a prefix. */
11518 dirs
[ndirs
].prefix
= -1;
11519 for (j
= 0; j
< ndirs
; j
++)
11520 if (dirs
[j
].length
< dirs
[ndirs
].length
11521 && dirs
[j
].length
> 1
11522 && (dirs
[ndirs
].prefix
== -1
11523 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
11524 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
11525 dirs
[ndirs
].prefix
= j
;
11530 /* Now to the actual work. We have to find a subset of the directories which
11531 allow expressing the file name using references to the directory table
11532 with the least amount of characters. We do not do an exhaustive search
11533 where we would have to check out every combination of every single
11534 possible prefix. Instead we use a heuristic which provides nearly optimal
11535 results in most cases and never is much off. */
11536 saved
= XALLOCAVEC (int, ndirs
);
11537 savehere
= XALLOCAVEC (int, ndirs
);
11539 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
11540 for (i
= 0; i
< ndirs
; i
++)
11545 /* We can always save some space for the current directory. But this
11546 does not mean it will be enough to justify adding the directory. */
11547 savehere
[i
] = dirs
[i
].length
;
11548 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
11550 for (j
= i
+ 1; j
< ndirs
; j
++)
11553 if (saved
[j
] < dirs
[i
].length
)
11555 /* Determine whether the dirs[i] path is a prefix of the
11559 k
= dirs
[j
].prefix
;
11560 while (k
!= -1 && k
!= (int) i
)
11561 k
= dirs
[k
].prefix
;
11565 /* Yes it is. We can possibly save some memory by
11566 writing the filenames in dirs[j] relative to
11568 savehere
[j
] = dirs
[i
].length
;
11569 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
11574 /* Check whether we can save enough to justify adding the dirs[i]
11576 if (total
> dirs
[i
].length
+ 1)
11578 /* It's worthwhile adding. */
11579 for (j
= i
; j
< ndirs
; j
++)
11580 if (savehere
[j
] > 0)
11582 /* Remember how much we saved for this directory so far. */
11583 saved
[j
] = savehere
[j
];
11585 /* Remember the prefix directory. */
11586 dirs
[j
].dir_idx
= i
;
11591 /* Emit the directory name table. */
11592 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
11593 enum dwarf_form str_form
= DW_FORM_string
;
11594 enum dwarf_form idx_form
= DW_FORM_udata
;
11595 if (dwarf_version
>= 5)
11597 const char *comp_dir
= comp_dir_string ();
11598 if (comp_dir
== NULL
)
11600 dw2_asm_output_data (1, 1, "Directory entry format count");
11601 if (DWARF5_USE_DEBUG_LINE_STR
)
11602 str_form
= DW_FORM_line_strp
;
11603 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
11604 dw2_asm_output_data_uleb128 (str_form
, "%s",
11605 get_DW_FORM_name (str_form
));
11606 dw2_asm_output_data_uleb128 (ndirs
+ idx_offset
, "Directories count");
11607 if (str_form
== DW_FORM_string
)
11609 dw2_asm_output_nstring (comp_dir
, -1, "Directory Entry: %#x", 0);
11610 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
11611 dw2_asm_output_nstring (dirs
[i
].path
,
11613 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
11614 "Directory Entry: %#x", i
+ idx_offset
);
11618 output_line_string (str_form
, comp_dir
, "Directory Entry", 0);
11619 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
11622 = ggc_alloc_string (dirs
[i
].path
,
11624 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
);
11625 output_line_string (str_form
, str
, "Directory Entry",
11626 (unsigned) i
+ idx_offset
);
11632 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
11633 dw2_asm_output_nstring (dirs
[i
].path
,
11635 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
11636 "Directory Entry: %#x", i
+ idx_offset
);
11638 dw2_asm_output_data (1, 0, "End directory table");
11641 /* We have to emit them in the order of emitted_number since that's
11642 used in the debug info generation. To do this efficiently we
11643 generate a back-mapping of the indices first. */
11644 backmap
= XALLOCAVEC (int, numfiles
);
11645 for (i
= 0; i
< numfiles
; i
++)
11646 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
11648 if (dwarf_version
>= 5)
11650 const char *filename0
= get_AT_string (comp_unit_die (), DW_AT_name
);
11651 if (filename0
== NULL
)
11653 /* DW_LNCT_directory_index can use DW_FORM_udata, DW_FORM_data1 and
11654 DW_FORM_data2. Choose one based on the number of directories
11655 and how much space would they occupy in each encoding.
11656 If we have at most 256 directories, all indexes fit into
11657 a single byte, so DW_FORM_data1 is most compact (if there
11658 are at most 128 directories, DW_FORM_udata would be as
11659 compact as that, but not shorter and slower to decode). */
11660 if (ndirs
+ idx_offset
<= 256)
11661 idx_form
= DW_FORM_data1
;
11662 /* If there are more than 65536 directories, we have to use
11663 DW_FORM_udata, DW_FORM_data2 can't refer to them.
11664 Otherwise, compute what space would occupy if all the indexes
11665 used DW_FORM_udata - sum - and compare that to how large would
11666 be DW_FORM_data2 encoding, and pick the more efficient one. */
11667 else if (ndirs
+ idx_offset
<= 65536)
11669 unsigned HOST_WIDE_INT sum
= 1;
11670 for (i
= 0; i
< numfiles
; i
++)
11672 int file_idx
= backmap
[i
];
11673 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
11674 sum
+= size_of_uleb128 (dir_idx
);
11676 if (sum
>= HOST_WIDE_INT_UC (2) * (numfiles
+ 1))
11677 idx_form
= DW_FORM_data2
;
11679 #ifdef VMS_DEBUGGING_INFO
11680 dw2_asm_output_data (1, 4, "File name entry format count");
11682 dw2_asm_output_data (1, 2, "File name entry format count");
11684 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
11685 dw2_asm_output_data_uleb128 (str_form
, "%s",
11686 get_DW_FORM_name (str_form
));
11687 dw2_asm_output_data_uleb128 (DW_LNCT_directory_index
,
11688 "DW_LNCT_directory_index");
11689 dw2_asm_output_data_uleb128 (idx_form
, "%s",
11690 get_DW_FORM_name (idx_form
));
11691 #ifdef VMS_DEBUGGING_INFO
11692 dw2_asm_output_data_uleb128 (DW_LNCT_timestamp
, "DW_LNCT_timestamp");
11693 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
11694 dw2_asm_output_data_uleb128 (DW_LNCT_size
, "DW_LNCT_size");
11695 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
11697 dw2_asm_output_data_uleb128 (numfiles
+ 1, "File names count");
11699 output_line_string (str_form
, filename0
, "File Entry", 0);
11701 /* Include directory index. */
11702 if (idx_form
!= DW_FORM_udata
)
11703 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
11706 dw2_asm_output_data_uleb128 (0, NULL
);
11708 #ifdef VMS_DEBUGGING_INFO
11709 dw2_asm_output_data_uleb128 (0, NULL
);
11710 dw2_asm_output_data_uleb128 (0, NULL
);
11714 /* Now write all the file names. */
11715 for (i
= 0; i
< numfiles
; i
++)
11717 int file_idx
= backmap
[i
];
11718 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
11720 #ifdef VMS_DEBUGGING_INFO
11721 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
11723 /* Setting these fields can lead to debugger miscomparisons,
11724 but VMS Debug requires them to be set correctly. */
11729 int maxfilelen
= (strlen (files
[file_idx
].path
)
11730 + dirs
[dir_idx
].length
11731 + MAX_VMS_VERSION_LEN
+ 1);
11732 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
11734 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
11735 snprintf (filebuf
, maxfilelen
, "%s;%d",
11736 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
11738 output_line_string (str_form
, filebuf
, "File Entry", (unsigned) i
+ 1);
11740 /* Include directory index. */
11741 if (dwarf_version
>= 5 && idx_form
!= DW_FORM_udata
)
11742 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
11743 dir_idx
+ idx_offset
, NULL
);
11745 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
11747 /* Modification time. */
11748 dw2_asm_output_data_uleb128 ((vms_file_stats_name (files
[file_idx
].path
,
11749 &cdt
, 0, 0, 0) == 0)
11752 /* File length in bytes. */
11753 dw2_asm_output_data_uleb128 ((vms_file_stats_name (files
[file_idx
].path
,
11754 0, &siz
, 0, 0) == 0)
11757 output_line_string (str_form
,
11758 files
[file_idx
].path
+ dirs
[dir_idx
].length
,
11759 "File Entry", (unsigned) i
+ 1);
11761 /* Include directory index. */
11762 if (dwarf_version
>= 5 && idx_form
!= DW_FORM_udata
)
11763 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
11764 dir_idx
+ idx_offset
, NULL
);
11766 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
11768 if (dwarf_version
>= 5)
11771 /* Modification time. */
11772 dw2_asm_output_data_uleb128 (0, NULL
);
11774 /* File length in bytes. */
11775 dw2_asm_output_data_uleb128 (0, NULL
);
11776 #endif /* VMS_DEBUGGING_INFO */
11779 if (dwarf_version
< 5)
11780 dw2_asm_output_data (1, 0, "End file name table");
11784 /* Output one line number table into the .debug_line section. */
11787 output_one_line_info_table (dw_line_info_table
*table
)
11789 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
11790 unsigned int current_line
= 1;
11791 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
11792 dw_line_info_entry
*ent
;
11795 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
11797 switch (ent
->opcode
)
11799 case LI_set_address
:
11800 /* ??? Unfortunately, we have little choice here currently, and
11801 must always use the most general form. GCC does not know the
11802 address delta itself, so we can't use DW_LNS_advance_pc. Many
11803 ports do have length attributes which will give an upper bound
11804 on the address range. We could perhaps use length attributes
11805 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
11806 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
11808 /* This can handle any delta. This takes
11809 4+DWARF2_ADDR_SIZE bytes. */
11810 dw2_asm_output_data (1, 0, "set address %s", line_label
);
11811 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
11812 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
11813 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
11817 if (ent
->val
== current_line
)
11819 /* We still need to start a new row, so output a copy insn. */
11820 dw2_asm_output_data (1, DW_LNS_copy
,
11821 "copy line %u", current_line
);
11825 int line_offset
= ent
->val
- current_line
;
11826 int line_delta
= line_offset
- DWARF_LINE_BASE
;
11828 current_line
= ent
->val
;
11829 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
11831 /* This can handle deltas from -10 to 234, using the current
11832 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
11833 This takes 1 byte. */
11834 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
11835 "line %u", current_line
);
11839 /* This can handle any delta. This takes at least 4 bytes,
11840 depending on the value being encoded. */
11841 dw2_asm_output_data (1, DW_LNS_advance_line
,
11842 "advance to line %u", current_line
);
11843 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
11844 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
11850 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
11851 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
11854 case LI_set_column
:
11855 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
11856 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
11859 case LI_negate_stmt
:
11860 current_is_stmt
= !current_is_stmt
;
11861 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
11862 "is_stmt %d", current_is_stmt
);
11865 case LI_set_prologue_end
:
11866 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
11867 "set prologue end");
11870 case LI_set_epilogue_begin
:
11871 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
11872 "set epilogue begin");
11875 case LI_set_discriminator
:
11876 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
11877 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
11878 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
11879 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
11884 /* Emit debug info for the address of the end of the table. */
11885 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
11886 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
11887 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
11888 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
11890 dw2_asm_output_data (1, 0, "end sequence");
11891 dw2_asm_output_data_uleb128 (1, NULL
);
11892 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
11895 /* Output the source line number correspondence information. This
11896 information goes into the .debug_line section. */
11899 output_line_info (bool prologue_only
)
11901 static unsigned int generation
;
11902 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
11903 char p1
[MAX_ARTIFICIAL_LABEL_BYTES
], p2
[MAX_ARTIFICIAL_LABEL_BYTES
];
11904 bool saw_one
= false;
11907 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, generation
);
11908 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, generation
);
11909 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, generation
);
11910 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, generation
++);
11912 if (!XCOFF_DEBUGGING_INFO
)
11914 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11915 dw2_asm_output_data (4, 0xffffffff,
11916 "Initial length escape value indicating 64-bit DWARF extension");
11917 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
11918 "Length of Source Line Info");
11921 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
11923 dw2_asm_output_data (2, dwarf_version
, "DWARF Version");
11924 if (dwarf_version
>= 5)
11926 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
11927 dw2_asm_output_data (1, 0, "Segment Size");
11929 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
11930 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
11932 /* Define the architecture-dependent minimum instruction length (in bytes).
11933 In this implementation of DWARF, this field is used for information
11934 purposes only. Since GCC generates assembly language, we have no
11935 a priori knowledge of how many instruction bytes are generated for each
11936 source line, and therefore can use only the DW_LNE_set_address and
11937 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
11938 this as '1', which is "correct enough" for all architectures,
11939 and don't let the target override. */
11940 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
11942 if (dwarf_version
>= 4)
11943 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
11944 "Maximum Operations Per Instruction");
11945 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
11946 "Default is_stmt_start flag");
11947 dw2_asm_output_data (1, DWARF_LINE_BASE
,
11948 "Line Base Value (Special Opcodes)");
11949 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
11950 "Line Range Value (Special Opcodes)");
11951 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
11952 "Special Opcode Base");
11954 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
11959 case DW_LNS_advance_pc
:
11960 case DW_LNS_advance_line
:
11961 case DW_LNS_set_file
:
11962 case DW_LNS_set_column
:
11963 case DW_LNS_fixed_advance_pc
:
11964 case DW_LNS_set_isa
:
11972 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
11976 /* Write out the information about the files we use. */
11977 output_file_names ();
11978 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
11981 /* Output the marker for the end of the line number info. */
11982 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
11986 if (separate_line_info
)
11988 dw_line_info_table
*table
;
11991 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
11994 output_one_line_info_table (table
);
11998 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
12000 output_one_line_info_table (cold_text_section_line_info
);
12004 /* ??? Some Darwin linkers crash on a .debug_line section with no
12005 sequences. Further, merely a DW_LNE_end_sequence entry is not
12006 sufficient -- the address column must also be initialized.
12007 Make sure to output at least one set_address/end_sequence pair,
12008 choosing .text since that section is always present. */
12009 if (text_section_line_info
->in_use
|| !saw_one
)
12010 output_one_line_info_table (text_section_line_info
);
12012 /* Output the marker for the end of the line number info. */
12013 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
12016 /* Return true if DW_AT_endianity should be emitted according to REVERSE. */
12019 need_endianity_attribute_p (bool reverse
)
12021 return reverse
&& (dwarf_version
>= 3 || !dwarf_strict
);
12024 /* Given a pointer to a tree node for some base type, return a pointer to
12025 a DIE that describes the given type. REVERSE is true if the type is
12026 to be interpreted in the reverse storage order wrt the target order.
12028 This routine must only be called for GCC type nodes that correspond to
12029 Dwarf base (fundamental) types. */
12032 base_type_die (tree type
, bool reverse
)
12034 dw_die_ref base_type_result
;
12035 enum dwarf_type encoding
;
12036 bool fpt_used
= false;
12037 struct fixed_point_type_info fpt_info
;
12038 tree type_bias
= NULL_TREE
;
12040 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
12043 /* If this is a subtype that should not be emitted as a subrange type,
12044 use the base type. See subrange_type_for_debug_p. */
12045 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
12046 type
= TREE_TYPE (type
);
12048 switch (TREE_CODE (type
))
12051 if ((dwarf_version
>= 4 || !dwarf_strict
)
12052 && TYPE_NAME (type
)
12053 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
12054 && DECL_IS_BUILTIN (TYPE_NAME (type
))
12055 && DECL_NAME (TYPE_NAME (type
)))
12057 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
12058 if (strcmp (name
, "char16_t") == 0
12059 || strcmp (name
, "char32_t") == 0)
12061 encoding
= DW_ATE_UTF
;
12065 if ((dwarf_version
>= 3 || !dwarf_strict
)
12066 && lang_hooks
.types
.get_fixed_point_type_info
)
12068 memset (&fpt_info
, 0, sizeof (fpt_info
));
12069 if (lang_hooks
.types
.get_fixed_point_type_info (type
, &fpt_info
))
12072 encoding
= ((TYPE_UNSIGNED (type
))
12073 ? DW_ATE_unsigned_fixed
12074 : DW_ATE_signed_fixed
);
12078 if (TYPE_STRING_FLAG (type
))
12080 if (TYPE_UNSIGNED (type
))
12081 encoding
= DW_ATE_unsigned_char
;
12083 encoding
= DW_ATE_signed_char
;
12085 else if (TYPE_UNSIGNED (type
))
12086 encoding
= DW_ATE_unsigned
;
12088 encoding
= DW_ATE_signed
;
12091 && lang_hooks
.types
.get_type_bias
)
12092 type_bias
= lang_hooks
.types
.get_type_bias (type
);
12096 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
12098 if (dwarf_version
>= 3 || !dwarf_strict
)
12099 encoding
= DW_ATE_decimal_float
;
12101 encoding
= DW_ATE_lo_user
;
12104 encoding
= DW_ATE_float
;
12107 case FIXED_POINT_TYPE
:
12108 if (!(dwarf_version
>= 3 || !dwarf_strict
))
12109 encoding
= DW_ATE_lo_user
;
12110 else if (TYPE_UNSIGNED (type
))
12111 encoding
= DW_ATE_unsigned_fixed
;
12113 encoding
= DW_ATE_signed_fixed
;
12116 /* Dwarf2 doesn't know anything about complex ints, so use
12117 a user defined type for it. */
12119 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
12120 encoding
= DW_ATE_complex_float
;
12122 encoding
= DW_ATE_lo_user
;
12126 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12127 encoding
= DW_ATE_boolean
;
12131 /* No other TREE_CODEs are Dwarf fundamental types. */
12132 gcc_unreachable ();
12135 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
12137 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
12138 int_size_in_bytes (type
));
12139 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
12141 if (need_endianity_attribute_p (reverse
))
12142 add_AT_unsigned (base_type_result
, DW_AT_endianity
,
12143 BYTES_BIG_ENDIAN
? DW_END_little
: DW_END_big
);
12145 add_alignment_attribute (base_type_result
, type
);
12149 switch (fpt_info
.scale_factor_kind
)
12151 case fixed_point_scale_factor_binary
:
12152 add_AT_int (base_type_result
, DW_AT_binary_scale
,
12153 fpt_info
.scale_factor
.binary
);
12156 case fixed_point_scale_factor_decimal
:
12157 add_AT_int (base_type_result
, DW_AT_decimal_scale
,
12158 fpt_info
.scale_factor
.decimal
);
12161 case fixed_point_scale_factor_arbitrary
:
12162 /* Arbitrary scale factors cannot be described in standard DWARF,
12166 /* Describe the scale factor as a rational constant. */
12167 const dw_die_ref scale_factor
12168 = new_die (DW_TAG_constant
, comp_unit_die (), type
);
12170 add_AT_unsigned (scale_factor
, DW_AT_GNU_numerator
,
12171 fpt_info
.scale_factor
.arbitrary
.numerator
);
12172 add_AT_int (scale_factor
, DW_AT_GNU_denominator
,
12173 fpt_info
.scale_factor
.arbitrary
.denominator
);
12175 add_AT_die_ref (base_type_result
, DW_AT_small
, scale_factor
);
12180 gcc_unreachable ();
12185 add_scalar_info (base_type_result
, DW_AT_GNU_bias
, type_bias
,
12186 dw_scalar_form_constant
12187 | dw_scalar_form_exprloc
12188 | dw_scalar_form_reference
,
12191 add_pubtype (type
, base_type_result
);
12193 return base_type_result
;
12196 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
12197 named 'auto' in its type: return true for it, false otherwise. */
12200 is_cxx_auto (tree type
)
12204 tree name
= TYPE_IDENTIFIER (type
);
12205 if (name
== get_identifier ("auto")
12206 || name
== get_identifier ("decltype(auto)"))
12212 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12213 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12216 is_base_type (tree type
)
12218 switch (TREE_CODE (type
))
12224 case FIXED_POINT_TYPE
:
12227 case POINTER_BOUNDS_TYPE
:
12233 case QUAL_UNION_TYPE
:
12234 case ENUMERAL_TYPE
:
12235 case FUNCTION_TYPE
:
12238 case REFERENCE_TYPE
:
12246 if (is_cxx_auto (type
))
12248 gcc_unreachable ();
12254 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12255 node, return the size in bits for the type if it is a constant, or else
12256 return the alignment for the type if the type's size is not constant, or
12257 else return BITS_PER_WORD if the type actually turns out to be an
12258 ERROR_MARK node. */
12260 static inline unsigned HOST_WIDE_INT
12261 simple_type_size_in_bits (const_tree type
)
12263 if (TREE_CODE (type
) == ERROR_MARK
)
12264 return BITS_PER_WORD
;
12265 else if (TYPE_SIZE (type
) == NULL_TREE
)
12267 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
12268 return tree_to_uhwi (TYPE_SIZE (type
));
12270 return TYPE_ALIGN (type
);
12273 /* Similarly, but return an offset_int instead of UHWI. */
12275 static inline offset_int
12276 offset_int_type_size_in_bits (const_tree type
)
12278 if (TREE_CODE (type
) == ERROR_MARK
)
12279 return BITS_PER_WORD
;
12280 else if (TYPE_SIZE (type
) == NULL_TREE
)
12282 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
12283 return wi::to_offset (TYPE_SIZE (type
));
12285 return TYPE_ALIGN (type
);
12288 /* Given a pointer to a tree node for a subrange type, return a pointer
12289 to a DIE that describes the given type. */
12292 subrange_type_die (tree type
, tree low
, tree high
, tree bias
,
12293 dw_die_ref context_die
)
12295 dw_die_ref subrange_die
;
12296 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
12298 if (context_die
== NULL
)
12299 context_die
= comp_unit_die ();
12301 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
12303 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
12305 /* The size of the subrange type and its base type do not match,
12306 so we need to generate a size attribute for the subrange type. */
12307 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
12310 add_alignment_attribute (subrange_die
, type
);
12313 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
, NULL
);
12315 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
, NULL
);
12316 if (bias
&& !dwarf_strict
)
12317 add_scalar_info (subrange_die
, DW_AT_GNU_bias
, bias
,
12318 dw_scalar_form_constant
12319 | dw_scalar_form_exprloc
12320 | dw_scalar_form_reference
,
12323 return subrange_die
;
12326 /* Returns the (const and/or volatile) cv_qualifiers associated with
12327 the decl node. This will normally be augmented with the
12328 cv_qualifiers of the underlying type in add_type_attribute. */
12331 decl_quals (const_tree decl
)
12333 return ((TREE_READONLY (decl
)
12334 /* The C++ front-end correctly marks reference-typed
12335 variables as readonly, but from a language (and debug
12336 info) standpoint they are not const-qualified. */
12337 && TREE_CODE (TREE_TYPE (decl
)) != REFERENCE_TYPE
12338 ? TYPE_QUAL_CONST
: TYPE_UNQUALIFIED
)
12339 | (TREE_THIS_VOLATILE (decl
)
12340 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
));
12343 /* Determine the TYPE whose qualifiers match the largest strict subset
12344 of the given TYPE_QUALS, and return its qualifiers. Ignore all
12345 qualifiers outside QUAL_MASK. */
12348 get_nearest_type_subqualifiers (tree type
, int type_quals
, int qual_mask
)
12351 int best_rank
= 0, best_qual
= 0, max_rank
;
12353 type_quals
&= qual_mask
;
12354 max_rank
= popcount_hwi (type_quals
) - 1;
12356 for (t
= TYPE_MAIN_VARIANT (type
); t
&& best_rank
< max_rank
;
12357 t
= TYPE_NEXT_VARIANT (t
))
12359 int q
= TYPE_QUALS (t
) & qual_mask
;
12361 if ((q
& type_quals
) == q
&& q
!= type_quals
12362 && check_base_type (t
, type
))
12364 int rank
= popcount_hwi (q
);
12366 if (rank
> best_rank
)
12377 struct dwarf_qual_info_t
{ int q
; enum dwarf_tag t
; };
12378 static const dwarf_qual_info_t dwarf_qual_info
[] =
12380 { TYPE_QUAL_CONST
, DW_TAG_const_type
},
12381 { TYPE_QUAL_VOLATILE
, DW_TAG_volatile_type
},
12382 { TYPE_QUAL_RESTRICT
, DW_TAG_restrict_type
},
12383 { TYPE_QUAL_ATOMIC
, DW_TAG_atomic_type
}
12385 static const unsigned int dwarf_qual_info_size
12386 = sizeof (dwarf_qual_info
) / sizeof (dwarf_qual_info
[0]);
12388 /* If DIE is a qualified DIE of some base DIE with the same parent,
12389 return the base DIE, otherwise return NULL. Set MASK to the
12390 qualifiers added compared to the returned DIE. */
12393 qualified_die_p (dw_die_ref die
, int *mask
, unsigned int depth
)
12396 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
12397 if (die
->die_tag
== dwarf_qual_info
[i
].t
)
12399 if (i
== dwarf_qual_info_size
)
12401 if (vec_safe_length (die
->die_attr
) != 1)
12403 dw_die_ref type
= get_AT_ref (die
, DW_AT_type
);
12404 if (type
== NULL
|| type
->die_parent
!= die
->die_parent
)
12406 *mask
|= dwarf_qual_info
[i
].q
;
12409 dw_die_ref ret
= qualified_die_p (type
, mask
, depth
- 1);
12416 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12417 entry that chains the modifiers specified by CV_QUALS in front of the
12418 given type. REVERSE is true if the type is to be interpreted in the
12419 reverse storage order wrt the target order. */
12422 modified_type_die (tree type
, int cv_quals
, bool reverse
,
12423 dw_die_ref context_die
)
12425 enum tree_code code
= TREE_CODE (type
);
12426 dw_die_ref mod_type_die
;
12427 dw_die_ref sub_die
= NULL
;
12428 tree item_type
= NULL
;
12429 tree qualified_type
;
12430 tree name
, low
, high
;
12431 dw_die_ref mod_scope
;
12432 /* Only these cv-qualifiers are currently handled. */
12433 const int cv_qual_mask
= (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
12434 | TYPE_QUAL_RESTRICT
| TYPE_QUAL_ATOMIC
);
12436 if (code
== ERROR_MARK
)
12439 if (lang_hooks
.types
.get_debug_type
)
12441 tree debug_type
= lang_hooks
.types
.get_debug_type (type
);
12443 if (debug_type
!= NULL_TREE
&& debug_type
!= type
)
12444 return modified_type_die (debug_type
, cv_quals
, reverse
, context_die
);
12447 cv_quals
&= cv_qual_mask
;
12449 /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
12450 tag modifier (and not an attribute) old consumers won't be able
12452 if (dwarf_version
< 3)
12453 cv_quals
&= ~TYPE_QUAL_RESTRICT
;
12455 /* Likewise for DW_TAG_atomic_type for DWARFv5. */
12456 if (dwarf_version
< 5)
12457 cv_quals
&= ~TYPE_QUAL_ATOMIC
;
12459 /* See if we already have the appropriately qualified variant of
12461 qualified_type
= get_qualified_type (type
, cv_quals
);
12463 if (qualified_type
== sizetype
)
12465 /* Try not to expose the internal sizetype type's name. */
12466 if (TYPE_NAME (qualified_type
)
12467 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
12469 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
12471 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
12472 && (TYPE_PRECISION (t
)
12473 == TYPE_PRECISION (qualified_type
))
12474 && (TYPE_UNSIGNED (t
)
12475 == TYPE_UNSIGNED (qualified_type
)));
12476 qualified_type
= t
;
12478 else if (qualified_type
== sizetype
12479 && TREE_CODE (sizetype
) == TREE_CODE (size_type_node
)
12480 && TYPE_PRECISION (sizetype
) == TYPE_PRECISION (size_type_node
)
12481 && TYPE_UNSIGNED (sizetype
) == TYPE_UNSIGNED (size_type_node
))
12482 qualified_type
= size_type_node
;
12486 /* If we do, then we can just use its DIE, if it exists. */
12487 if (qualified_type
)
12489 mod_type_die
= lookup_type_die (qualified_type
);
12491 /* DW_AT_endianity doesn't come from a qualifier on the type. */
12493 && (!need_endianity_attribute_p (reverse
)
12494 || !is_base_type (type
)
12495 || get_AT_unsigned (mod_type_die
, DW_AT_endianity
)))
12496 return mod_type_die
;
12499 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
12501 /* Handle C typedef types. */
12502 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
12503 && !DECL_ARTIFICIAL (name
))
12505 tree dtype
= TREE_TYPE (name
);
12507 if (qualified_type
== dtype
)
12509 /* For a named type, use the typedef. */
12510 gen_type_die (qualified_type
, context_die
);
12511 return lookup_type_die (qualified_type
);
12515 int dquals
= TYPE_QUALS_NO_ADDR_SPACE (dtype
);
12516 dquals
&= cv_qual_mask
;
12517 if ((dquals
& ~cv_quals
) != TYPE_UNQUALIFIED
12518 || (cv_quals
== dquals
&& DECL_ORIGINAL_TYPE (name
) != type
))
12519 /* cv-unqualified version of named type. Just use
12520 the unnamed type to which it refers. */
12521 return modified_type_die (DECL_ORIGINAL_TYPE (name
), cv_quals
,
12522 reverse
, context_die
);
12523 /* Else cv-qualified version of named type; fall through. */
12527 mod_scope
= scope_die_for (type
, context_die
);
12531 int sub_quals
= 0, first_quals
= 0;
12533 dw_die_ref first
= NULL
, last
= NULL
;
12535 /* Determine a lesser qualified type that most closely matches
12536 this one. Then generate DW_TAG_* entries for the remaining
12538 sub_quals
= get_nearest_type_subqualifiers (type
, cv_quals
,
12540 if (sub_quals
&& use_debug_types
)
12542 bool needed
= false;
12543 /* If emitting type units, make sure the order of qualifiers
12544 is canonical. Thus, start from unqualified type if
12545 an earlier qualifier is missing in sub_quals, but some later
12546 one is present there. */
12547 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
12548 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
12550 else if (needed
&& (dwarf_qual_info
[i
].q
& cv_quals
))
12556 mod_type_die
= modified_type_die (type
, sub_quals
, reverse
, context_die
);
12557 if (mod_scope
&& mod_type_die
&& mod_type_die
->die_parent
== mod_scope
)
12559 /* As not all intermediate qualified DIEs have corresponding
12560 tree types, ensure that qualified DIEs in the same scope
12561 as their DW_AT_type are emitted after their DW_AT_type,
12562 only with other qualified DIEs for the same type possibly
12563 in between them. Determine the range of such qualified
12564 DIEs now (first being the base type, last being corresponding
12565 last qualified DIE for it). */
12566 unsigned int count
= 0;
12567 first
= qualified_die_p (mod_type_die
, &first_quals
,
12568 dwarf_qual_info_size
);
12570 first
= mod_type_die
;
12571 gcc_assert ((first_quals
& ~sub_quals
) == 0);
12572 for (count
= 0, last
= first
;
12573 count
< (1U << dwarf_qual_info_size
);
12574 count
++, last
= last
->die_sib
)
12577 if (last
== mod_scope
->die_child
)
12579 if (qualified_die_p (last
->die_sib
, &quals
, dwarf_qual_info_size
)
12585 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
12586 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
12589 if (first
&& first
!= last
)
12591 for (d
= first
->die_sib
; ; d
= d
->die_sib
)
12594 qualified_die_p (d
, &quals
, dwarf_qual_info_size
);
12595 if (quals
== (first_quals
| dwarf_qual_info
[i
].q
))
12611 d
= ggc_cleared_alloc
<die_node
> ();
12612 d
->die_tag
= dwarf_qual_info
[i
].t
;
12613 add_child_die_after (mod_scope
, d
, last
);
12617 d
= new_die (dwarf_qual_info
[i
].t
, mod_scope
, type
);
12619 add_AT_die_ref (d
, DW_AT_type
, mod_type_die
);
12621 first_quals
|= dwarf_qual_info
[i
].q
;
12624 else if (code
== POINTER_TYPE
|| code
== REFERENCE_TYPE
)
12626 dwarf_tag tag
= DW_TAG_pointer_type
;
12627 if (code
== REFERENCE_TYPE
)
12629 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
12630 tag
= DW_TAG_rvalue_reference_type
;
12632 tag
= DW_TAG_reference_type
;
12634 mod_type_die
= new_die (tag
, mod_scope
, type
);
12636 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
12637 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
12638 add_alignment_attribute (mod_type_die
, type
);
12639 item_type
= TREE_TYPE (type
);
12641 addr_space_t as
= TYPE_ADDR_SPACE (item_type
);
12642 if (!ADDR_SPACE_GENERIC_P (as
))
12644 int action
= targetm
.addr_space
.debug (as
);
12647 /* Positive values indicate an address_class. */
12648 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, action
);
12652 /* Negative values indicate an (inverted) segment base reg. */
12654 = one_reg_loc_descriptor (~action
, VAR_INIT_STATUS_INITIALIZED
);
12655 add_AT_loc (mod_type_die
, DW_AT_segment
, d
);
12659 else if (code
== INTEGER_TYPE
12660 && TREE_TYPE (type
) != NULL_TREE
12661 && subrange_type_for_debug_p (type
, &low
, &high
))
12663 tree bias
= NULL_TREE
;
12664 if (lang_hooks
.types
.get_type_bias
)
12665 bias
= lang_hooks
.types
.get_type_bias (type
);
12666 mod_type_die
= subrange_type_die (type
, low
, high
, bias
, context_die
);
12667 item_type
= TREE_TYPE (type
);
12669 else if (is_base_type (type
))
12670 mod_type_die
= base_type_die (type
, reverse
);
12673 gen_type_die (type
, context_die
);
12675 /* We have to get the type_main_variant here (and pass that to the
12676 `lookup_type_die' routine) because the ..._TYPE node we have
12677 might simply be a *copy* of some original type node (where the
12678 copy was created to help us keep track of typedef names) and
12679 that copy might have a different TYPE_UID from the original
12681 if (TREE_CODE (type
) == FUNCTION_TYPE
12682 || TREE_CODE (type
) == METHOD_TYPE
)
12684 /* For function/method types, can't just use type_main_variant here,
12685 because that can have different ref-qualifiers for C++,
12686 but try to canonicalize. */
12687 tree main
= TYPE_MAIN_VARIANT (type
);
12688 for (tree t
= main
; t
; t
= TYPE_NEXT_VARIANT (t
))
12689 if (TYPE_QUALS_NO_ADDR_SPACE (t
) == 0
12690 && check_base_type (t
, main
)
12691 && check_lang_type (t
, type
))
12692 return lookup_type_die (t
);
12693 return lookup_type_die (type
);
12695 else if (TREE_CODE (type
) != VECTOR_TYPE
12696 && TREE_CODE (type
) != ARRAY_TYPE
)
12697 return lookup_type_die (type_main_variant (type
));
12699 /* Vectors have the debugging information in the type,
12700 not the main variant. */
12701 return lookup_type_die (type
);
12704 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
12705 don't output a DW_TAG_typedef, since there isn't one in the
12706 user's program; just attach a DW_AT_name to the type.
12707 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
12708 if the base type already has the same name. */
12710 && ((TREE_CODE (name
) != TYPE_DECL
12711 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
12712 || (cv_quals
== TYPE_UNQUALIFIED
)))
12713 || (TREE_CODE (name
) == TYPE_DECL
12714 && TREE_TYPE (name
) == qualified_type
12715 && DECL_NAME (name
))))
12717 if (TREE_CODE (name
) == TYPE_DECL
)
12718 /* Could just call add_name_and_src_coords_attributes here,
12719 but since this is a builtin type it doesn't have any
12720 useful source coordinates anyway. */
12721 name
= DECL_NAME (name
);
12722 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
12724 /* This probably indicates a bug. */
12725 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
12727 name
= TYPE_IDENTIFIER (type
);
12728 add_name_attribute (mod_type_die
,
12729 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
12732 if (qualified_type
)
12733 equate_type_number_to_die (qualified_type
, mod_type_die
);
12736 /* We must do this after the equate_type_number_to_die call, in case
12737 this is a recursive type. This ensures that the modified_type_die
12738 recursion will terminate even if the type is recursive. Recursive
12739 types are possible in Ada. */
12740 sub_die
= modified_type_die (item_type
,
12741 TYPE_QUALS_NO_ADDR_SPACE (item_type
),
12745 if (sub_die
!= NULL
)
12746 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
12748 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
12749 if (TYPE_ARTIFICIAL (type
))
12750 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
12752 return mod_type_die
;
12755 /* Generate DIEs for the generic parameters of T.
12756 T must be either a generic type or a generic function.
12757 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
12760 gen_generic_params_dies (tree t
)
12764 dw_die_ref die
= NULL
;
12767 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
12771 die
= lookup_type_die (t
);
12772 else if (DECL_P (t
))
12773 die
= lookup_decl_die (t
);
12777 parms
= lang_hooks
.get_innermost_generic_parms (t
);
12779 /* T has no generic parameter. It means T is neither a generic type
12780 or function. End of story. */
12783 parms_num
= TREE_VEC_LENGTH (parms
);
12784 args
= lang_hooks
.get_innermost_generic_args (t
);
12785 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
12786 non_default
= int_cst_value (TREE_CHAIN (args
));
12788 non_default
= TREE_VEC_LENGTH (args
);
12789 for (i
= 0; i
< parms_num
; i
++)
12791 tree parm
, arg
, arg_pack_elems
;
12792 dw_die_ref parm_die
;
12794 parm
= TREE_VEC_ELT (parms
, i
);
12795 arg
= TREE_VEC_ELT (args
, i
);
12796 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
12797 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
12799 if (parm
&& TREE_VALUE (parm
) && arg
)
12801 /* If PARM represents a template parameter pack,
12802 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
12803 by DW_TAG_template_*_parameter DIEs for the argument
12804 pack elements of ARG. Note that ARG would then be
12805 an argument pack. */
12806 if (arg_pack_elems
)
12807 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
12811 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
12812 true /* emit name */, die
);
12813 if (i
>= non_default
)
12814 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
12819 /* Create and return a DIE for PARM which should be
12820 the representation of a generic type parameter.
12821 For instance, in the C++ front end, PARM would be a template parameter.
12822 ARG is the argument to PARM.
12823 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
12825 PARENT_DIE is the parent DIE which the new created DIE should be added to,
12826 as a child node. */
12829 generic_parameter_die (tree parm
, tree arg
,
12831 dw_die_ref parent_die
)
12833 dw_die_ref tmpl_die
= NULL
;
12834 const char *name
= NULL
;
12836 if (!parm
|| !DECL_NAME (parm
) || !arg
)
12839 /* We support non-type generic parameters and arguments,
12840 type generic parameters and arguments, as well as
12841 generic generic parameters (a.k.a. template template parameters in C++)
12843 if (TREE_CODE (parm
) == PARM_DECL
)
12844 /* PARM is a nontype generic parameter */
12845 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
12846 else if (TREE_CODE (parm
) == TYPE_DECL
)
12847 /* PARM is a type generic parameter. */
12848 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
12849 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
12850 /* PARM is a generic generic parameter.
12851 Its DIE is a GNU extension. It shall have a
12852 DW_AT_name attribute to represent the name of the template template
12853 parameter, and a DW_AT_GNU_template_name attribute to represent the
12854 name of the template template argument. */
12855 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
12858 gcc_unreachable ();
12864 /* If PARM is a generic parameter pack, it means we are
12865 emitting debug info for a template argument pack element.
12866 In other terms, ARG is a template argument pack element.
12867 In that case, we don't emit any DW_AT_name attribute for
12871 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
12873 add_AT_string (tmpl_die
, DW_AT_name
, name
);
12876 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
12878 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
12879 TMPL_DIE should have a child DW_AT_type attribute that is set
12880 to the type of the argument to PARM, which is ARG.
12881 If PARM is a type generic parameter, TMPL_DIE should have a
12882 child DW_AT_type that is set to ARG. */
12883 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
12884 add_type_attribute (tmpl_die
, tmpl_type
,
12885 (TREE_THIS_VOLATILE (tmpl_type
)
12886 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
),
12887 false, parent_die
);
12891 /* So TMPL_DIE is a DIE representing a
12892 a generic generic template parameter, a.k.a template template
12893 parameter in C++ and arg is a template. */
12895 /* The DW_AT_GNU_template_name attribute of the DIE must be set
12896 to the name of the argument. */
12897 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
12899 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
12902 if (TREE_CODE (parm
) == PARM_DECL
)
12903 /* So PARM is a non-type generic parameter.
12904 DWARF3 5.6.8 says we must set a DW_AT_const_value child
12905 attribute of TMPL_DIE which value represents the value
12907 We must be careful here:
12908 The value of ARG might reference some function decls.
12909 We might currently be emitting debug info for a generic
12910 type and types are emitted before function decls, we don't
12911 know if the function decls referenced by ARG will actually be
12912 emitted after cgraph computations.
12913 So must defer the generation of the DW_AT_const_value to
12914 after cgraph is ready. */
12915 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
12921 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
12922 PARM_PACK must be a template parameter pack. The returned DIE
12923 will be child DIE of PARENT_DIE. */
12926 template_parameter_pack_die (tree parm_pack
,
12927 tree parm_pack_args
,
12928 dw_die_ref parent_die
)
12933 gcc_assert (parent_die
&& parm_pack
);
12935 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
12936 add_name_and_src_coords_attributes (die
, parm_pack
);
12937 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
12938 generic_parameter_die (parm_pack
,
12939 TREE_VEC_ELT (parm_pack_args
, j
),
12940 false /* Don't emit DW_AT_name */,
12945 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
12946 an enumerated type. */
12949 type_is_enum (const_tree type
)
12951 return TREE_CODE (type
) == ENUMERAL_TYPE
;
12954 /* Return the DBX register number described by a given RTL node. */
12956 static unsigned int
12957 dbx_reg_number (const_rtx rtl
)
12959 unsigned regno
= REGNO (rtl
);
12961 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
12963 #ifdef LEAF_REG_REMAP
12964 if (crtl
->uses_only_leaf_regs
)
12966 int leaf_reg
= LEAF_REG_REMAP (regno
);
12967 if (leaf_reg
!= -1)
12968 regno
= (unsigned) leaf_reg
;
12972 regno
= DBX_REGISTER_NUMBER (regno
);
12973 gcc_assert (regno
!= INVALID_REGNUM
);
12977 /* Optionally add a DW_OP_piece term to a location description expression.
12978 DW_OP_piece is only added if the location description expression already
12979 doesn't end with DW_OP_piece. */
12982 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
12984 dw_loc_descr_ref loc
;
12986 if (*list_head
!= NULL
)
12988 /* Find the end of the chain. */
12989 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
12992 if (loc
->dw_loc_opc
!= DW_OP_piece
)
12993 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
12997 /* Return a location descriptor that designates a machine register or
12998 zero if there is none. */
13000 static dw_loc_descr_ref
13001 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
13005 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
13008 /* We only use "frame base" when we're sure we're talking about the
13009 post-prologue local stack frame. We do this by *not* running
13010 register elimination until this point, and recognizing the special
13011 argument pointer and soft frame pointer rtx's.
13012 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
13013 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
13014 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
13016 dw_loc_descr_ref result
= NULL
;
13018 if (dwarf_version
>= 4 || !dwarf_strict
)
13020 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
13023 add_loc_descr (&result
,
13024 new_loc_descr (DW_OP_stack_value
, 0, 0));
13029 regs
= targetm
.dwarf_register_span (rtl
);
13031 if (REG_NREGS (rtl
) > 1 || regs
)
13032 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
13035 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
13036 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
13038 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
13042 /* Return a location descriptor that designates a machine register for
13043 a given hard register number. */
13045 static dw_loc_descr_ref
13046 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
13048 dw_loc_descr_ref reg_loc_descr
;
13052 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
13054 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
13056 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13057 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13059 return reg_loc_descr
;
13062 /* Given an RTL of a register, return a location descriptor that
13063 designates a value that spans more than one register. */
13065 static dw_loc_descr_ref
13066 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
13067 enum var_init_status initialized
)
13070 dw_loc_descr_ref loc_result
= NULL
;
13072 /* Simple, contiguous registers. */
13073 if (regs
== NULL_RTX
)
13075 unsigned reg
= REGNO (rtl
);
13078 #ifdef LEAF_REG_REMAP
13079 if (crtl
->uses_only_leaf_regs
)
13081 int leaf_reg
= LEAF_REG_REMAP (reg
);
13082 if (leaf_reg
!= -1)
13083 reg
= (unsigned) leaf_reg
;
13087 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
13088 nregs
= REG_NREGS (rtl
);
13090 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
13095 dw_loc_descr_ref t
;
13097 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
13098 VAR_INIT_STATUS_INITIALIZED
);
13099 add_loc_descr (&loc_result
, t
);
13100 add_loc_descr_op_piece (&loc_result
, size
);
13106 /* Now onto stupid register sets in non contiguous locations. */
13108 gcc_assert (GET_CODE (regs
) == PARALLEL
);
13110 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
13113 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
13115 dw_loc_descr_ref t
;
13117 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
13118 VAR_INIT_STATUS_INITIALIZED
);
13119 add_loc_descr (&loc_result
, t
);
13120 add_loc_descr_op_piece (&loc_result
, size
);
13123 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13124 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13128 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
13130 /* Return a location descriptor that designates a constant i,
13131 as a compound operation from constant (i >> shift), constant shift
13134 static dw_loc_descr_ref
13135 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
13137 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
13138 add_loc_descr (&ret
, int_loc_descriptor (shift
));
13139 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
13143 /* Return a location descriptor that designates a constant. */
13145 static dw_loc_descr_ref
13146 int_loc_descriptor (HOST_WIDE_INT i
)
13148 enum dwarf_location_atom op
;
13150 /* Pick the smallest representation of a constant, rather than just
13151 defaulting to the LEB encoding. */
13154 int clz
= clz_hwi (i
);
13155 int ctz
= ctz_hwi (i
);
13157 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
13158 else if (i
<= 0xff)
13159 op
= DW_OP_const1u
;
13160 else if (i
<= 0xffff)
13161 op
= DW_OP_const2u
;
13162 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
13163 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
13164 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
13165 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
13166 while DW_OP_const4u is 5 bytes. */
13167 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
13168 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13169 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
13170 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
13171 while DW_OP_const4u is 5 bytes. */
13172 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
13174 else if (DWARF2_ADDR_SIZE
== 4 && i
> 0x7fffffff
13175 && size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
)
13178 /* As i >= 2**31, the double cast above will yield a negative number.
13179 Since wrapping is defined in DWARF expressions we can output big
13180 positive integers as small negative ones, regardless of the size
13183 Here, since the evaluator will handle 32-bit values and since i >=
13184 2**31, we know it's going to be interpreted as a negative literal:
13185 store it this way if we can do better than 5 bytes this way. */
13186 return int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
);
13188 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
13189 op
= DW_OP_const4u
;
13191 /* Past this point, i >= 0x100000000 and thus DW_OP_constu will take at
13192 least 6 bytes: see if we can do better before falling back to it. */
13193 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13194 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
13195 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes. */
13196 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
13197 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
13198 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
13199 >= HOST_BITS_PER_WIDE_INT
)
13200 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
13201 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes. */
13202 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
13203 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
13204 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
13205 && size_of_uleb128 (i
) > 6)
13206 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
13207 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
13214 op
= DW_OP_const1s
;
13215 else if (i
>= -0x8000)
13216 op
= DW_OP_const2s
;
13217 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
13219 if (size_of_int_loc_descriptor (i
) < 5)
13221 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
13222 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
13225 op
= DW_OP_const4s
;
13229 if (size_of_int_loc_descriptor (i
)
13230 < (unsigned long) 1 + size_of_sleb128 (i
))
13232 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
13233 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
13240 return new_loc_descr (op
, i
, 0);
13243 /* Likewise, for unsigned constants. */
13245 static dw_loc_descr_ref
13246 uint_loc_descriptor (unsigned HOST_WIDE_INT i
)
13248 const unsigned HOST_WIDE_INT max_int
= INTTYPE_MAXIMUM (HOST_WIDE_INT
);
13249 const unsigned HOST_WIDE_INT max_uint
13250 = INTTYPE_MAXIMUM (unsigned HOST_WIDE_INT
);
13252 /* If possible, use the clever signed constants handling. */
13254 return int_loc_descriptor ((HOST_WIDE_INT
) i
);
13256 /* Here, we are left with positive numbers that cannot be represented as
13257 HOST_WIDE_INT, i.e.:
13258 max (HOST_WIDE_INT) < i <= max (unsigned HOST_WIDE_INT)
13260 Using DW_OP_const4/8/./u operation to encode them consumes a lot of bytes
13261 whereas may be better to output a negative integer: thanks to integer
13262 wrapping, we know that:
13263 x = x - 2 ** DWARF2_ADDR_SIZE
13264 = x - 2 * (max (HOST_WIDE_INT) + 1)
13265 So numbers close to max (unsigned HOST_WIDE_INT) could be represented as
13266 small negative integers. Let's try that in cases it will clearly improve
13267 the encoding: there is no gain turning DW_OP_const4u into
13269 if (DWARF2_ADDR_SIZE
* 8 == HOST_BITS_PER_WIDE_INT
13270 && ((DWARF2_ADDR_SIZE
== 4 && i
> max_uint
- 0x8000)
13271 || (DWARF2_ADDR_SIZE
== 8 && i
> max_uint
- 0x80000000)))
13273 const unsigned HOST_WIDE_INT first_shift
= i
- max_int
- 1;
13275 /* Now, -1 < first_shift <= max (HOST_WIDE_INT)
13276 i.e. 0 <= first_shift <= max (HOST_WIDE_INT). */
13277 const HOST_WIDE_INT second_shift
13278 = (HOST_WIDE_INT
) first_shift
- (HOST_WIDE_INT
) max_int
- 1;
13280 /* So we finally have:
13281 -max (HOST_WIDE_INT) - 1 <= second_shift <= -1.
13282 i.e. min (HOST_WIDE_INT) <= second_shift < 0. */
13283 return int_loc_descriptor (second_shift
);
13286 /* Last chance: fallback to a simple constant operation. */
13287 return new_loc_descr
13288 ((HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
13294 /* Generate and return a location description that computes the unsigned
13295 comparison of the two stack top entries (a OP b where b is the top-most
13296 entry and a is the second one). The KIND of comparison can be LT_EXPR,
13297 LE_EXPR, GT_EXPR or GE_EXPR. */
13299 static dw_loc_descr_ref
13300 uint_comparison_loc_list (enum tree_code kind
)
13302 enum dwarf_location_atom op
, flip_op
;
13303 dw_loc_descr_ref ret
, bra_node
, jmp_node
, tmp
;
13320 gcc_unreachable ();
13323 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
13324 jmp_node
= new_loc_descr (DW_OP_skip
, 0, 0);
13326 /* Until DWARFv4, operations all work on signed integers. It is nevertheless
13327 possible to perform unsigned comparisons: we just have to distinguish
13330 1. when a and b have the same sign (as signed integers); then we should
13331 return: a OP(signed) b;
13333 2. when a is a negative signed integer while b is a positive one, then a
13334 is a greater unsigned integer than b; likewise when a and b's roles
13337 So first, compare the sign of the two operands. */
13338 ret
= new_loc_descr (DW_OP_over
, 0, 0);
13339 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
13340 add_loc_descr (&ret
, new_loc_descr (DW_OP_xor
, 0, 0));
13341 /* If they have different signs (i.e. they have different sign bits), then
13342 the stack top value has now the sign bit set and thus it's smaller than
13344 add_loc_descr (&ret
, new_loc_descr (DW_OP_lit0
, 0, 0));
13345 add_loc_descr (&ret
, new_loc_descr (DW_OP_lt
, 0, 0));
13346 add_loc_descr (&ret
, bra_node
);
13348 /* We are in case 1. At this point, we know both operands have the same
13349 sign, to it's safe to use the built-in signed comparison. */
13350 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
13351 add_loc_descr (&ret
, jmp_node
);
13353 /* We are in case 2. Here, we know both operands do not have the same sign,
13354 so we have to flip the signed comparison. */
13355 flip_op
= (kind
== LT_EXPR
|| kind
== LE_EXPR
) ? DW_OP_gt
: DW_OP_lt
;
13356 tmp
= new_loc_descr (flip_op
, 0, 0);
13357 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13358 bra_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
13359 add_loc_descr (&ret
, tmp
);
13361 /* This dummy operation is necessary to make the two branches join. */
13362 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
13363 jmp_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13364 jmp_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
13365 add_loc_descr (&ret
, tmp
);
13370 /* Likewise, but takes the location description lists (might be destructive on
13371 them). Return NULL if either is NULL or if concatenation fails. */
13373 static dw_loc_list_ref
13374 loc_list_from_uint_comparison (dw_loc_list_ref left
, dw_loc_list_ref right
,
13375 enum tree_code kind
)
13377 if (left
== NULL
|| right
== NULL
)
13380 add_loc_list (&left
, right
);
13384 add_loc_descr_to_each (left
, uint_comparison_loc_list (kind
));
13388 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
13389 without actually allocating it. */
13391 static unsigned long
13392 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
13394 return size_of_int_loc_descriptor (i
>> shift
)
13395 + size_of_int_loc_descriptor (shift
)
13399 /* Return size_of_locs (int_loc_descriptor (i)) without
13400 actually allocating it. */
13402 static unsigned long
13403 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
13412 else if (i
<= 0xff)
13414 else if (i
<= 0xffff)
13418 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
13419 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
13420 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13422 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13423 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
13424 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13426 else if (DWARF2_ADDR_SIZE
== 4 && i
> 0x7fffffff
13427 && size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
)
13429 return size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
);
13430 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
13432 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
13433 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13434 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
13435 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13437 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
13438 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
13439 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13441 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
13442 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
13444 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13453 else if (i
>= -0x8000)
13455 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
13457 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
13459 s
= size_of_int_loc_descriptor (-i
) + 1;
13467 unsigned long r
= 1 + size_of_sleb128 (i
);
13468 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
13470 s
= size_of_int_loc_descriptor (-i
) + 1;
13479 /* Return loc description representing "address" of integer value.
13480 This can appear only as toplevel expression. */
13482 static dw_loc_descr_ref
13483 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
13486 dw_loc_descr_ref loc_result
= NULL
;
13488 if (!(dwarf_version
>= 4 || !dwarf_strict
))
13491 litsize
= size_of_int_loc_descriptor (i
);
13492 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13493 is more compact. For DW_OP_stack_value we need:
13494 litsize + 1 (DW_OP_stack_value)
13495 and for DW_OP_implicit_value:
13496 1 (DW_OP_implicit_value) + 1 (length) + size. */
13497 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
13499 loc_result
= int_loc_descriptor (i
);
13500 add_loc_descr (&loc_result
,
13501 new_loc_descr (DW_OP_stack_value
, 0, 0));
13505 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13507 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13508 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
13512 /* Return a location descriptor that designates a base+offset location. */
13514 static dw_loc_descr_ref
13515 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
13516 enum var_init_status initialized
)
13518 unsigned int regno
;
13519 dw_loc_descr_ref result
;
13520 dw_fde_ref fde
= cfun
->fde
;
13522 /* We only use "frame base" when we're sure we're talking about the
13523 post-prologue local stack frame. We do this by *not* running
13524 register elimination until this point, and recognizing the special
13525 argument pointer and soft frame pointer rtx's. */
13526 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
13528 rtx elim
= (ira_use_lra_p
13529 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
13530 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
13534 if (GET_CODE (elim
) == PLUS
)
13536 offset
+= INTVAL (XEXP (elim
, 1));
13537 elim
= XEXP (elim
, 0);
13539 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13540 && (elim
== hard_frame_pointer_rtx
13541 || elim
== stack_pointer_rtx
))
13542 || elim
== (frame_pointer_needed
13543 ? hard_frame_pointer_rtx
13544 : stack_pointer_rtx
));
13546 /* If drap register is used to align stack, use frame
13547 pointer + offset to access stack variables. If stack
13548 is aligned without drap, use stack pointer + offset to
13549 access stack variables. */
13550 if (crtl
->stack_realign_tried
13551 && reg
== frame_pointer_rtx
)
13554 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
13555 ? HARD_FRAME_POINTER_REGNUM
13557 return new_reg_loc_descr (base_reg
, offset
);
13560 gcc_assert (frame_pointer_fb_offset_valid
);
13561 offset
+= frame_pointer_fb_offset
;
13562 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
13566 regno
= REGNO (reg
);
13567 #ifdef LEAF_REG_REMAP
13568 if (crtl
->uses_only_leaf_regs
)
13570 int leaf_reg
= LEAF_REG_REMAP (regno
);
13571 if (leaf_reg
!= -1)
13572 regno
= (unsigned) leaf_reg
;
13575 regno
= DWARF_FRAME_REGNUM (regno
);
13577 if (!optimize
&& fde
13578 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
13580 /* Use cfa+offset to represent the location of arguments passed
13581 on the stack when drap is used to align stack.
13582 Only do this when not optimizing, for optimized code var-tracking
13583 is supposed to track where the arguments live and the register
13584 used as vdrap or drap in some spot might be used for something
13585 else in other part of the routine. */
13586 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
13590 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
13593 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
13595 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13596 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13601 /* Return true if this RTL expression describes a base+offset calculation. */
13604 is_based_loc (const_rtx rtl
)
13606 return (GET_CODE (rtl
) == PLUS
13607 && ((REG_P (XEXP (rtl
, 0))
13608 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
13609 && CONST_INT_P (XEXP (rtl
, 1)))));
13612 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13615 static dw_loc_descr_ref
13616 tls_mem_loc_descriptor (rtx mem
)
13619 dw_loc_descr_ref loc_result
;
13621 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
13624 base
= get_base_address (MEM_EXPR (mem
));
13627 || !DECL_THREAD_LOCAL_P (base
))
13630 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1, NULL
);
13631 if (loc_result
== NULL
)
13634 if (MEM_OFFSET (mem
))
13635 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
13640 /* Output debug info about reason why we failed to expand expression as dwarf
13644 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
13646 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
13648 fprintf (dump_file
, "Failed to expand as dwarf: ");
13650 print_generic_expr (dump_file
, expr
, dump_flags
);
13653 fprintf (dump_file
, "\n");
13654 print_rtl (dump_file
, rtl
);
13656 fprintf (dump_file
, "\nReason: %s\n", reason
);
13660 /* Helper function for const_ok_for_output. */
13663 const_ok_for_output_1 (rtx rtl
)
13665 if (GET_CODE (rtl
) == UNSPEC
)
13667 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
13668 we can't express it in the debug info. */
13669 /* Don't complain about TLS UNSPECs, those are just too hard to
13670 delegitimize. Note this could be a non-decl SYMBOL_REF such as
13671 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
13672 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
13674 && (XVECLEN (rtl
, 0) == 0
13675 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
13676 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
))
13677 inform (current_function_decl
13678 ? DECL_SOURCE_LOCATION (current_function_decl
)
13679 : UNKNOWN_LOCATION
,
13680 #if NUM_UNSPEC_VALUES > 0
13681 "non-delegitimized UNSPEC %s (%d) found in variable location",
13682 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
13683 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
13686 "non-delegitimized UNSPEC %d found in variable location",
13689 expansion_failed (NULL_TREE
, rtl
,
13690 "UNSPEC hasn't been delegitimized.\n");
13694 if (targetm
.const_not_ok_for_debug_p (rtl
))
13696 expansion_failed (NULL_TREE
, rtl
,
13697 "Expression rejected for debug by the backend.\n");
13701 /* FIXME: Refer to PR60655. It is possible for simplification
13702 of rtl expressions in var tracking to produce such expressions.
13703 We should really identify / validate expressions
13704 enclosed in CONST that can be handled by assemblers on various
13705 targets and only handle legitimate cases here. */
13706 if (GET_CODE (rtl
) != SYMBOL_REF
)
13708 if (GET_CODE (rtl
) == NOT
)
13713 if (CONSTANT_POOL_ADDRESS_P (rtl
))
13716 get_pool_constant_mark (rtl
, &marked
);
13717 /* If all references to this pool constant were optimized away,
13718 it was not output and thus we can't represent it. */
13721 expansion_failed (NULL_TREE
, rtl
,
13722 "Constant was removed from constant pool.\n");
13727 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
13730 /* Avoid references to external symbols in debug info, on several targets
13731 the linker might even refuse to link when linking a shared library,
13732 and in many other cases the relocations for .debug_info/.debug_loc are
13733 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13734 to be defined within the same shared library or executable are fine. */
13735 if (SYMBOL_REF_EXTERNAL_P (rtl
))
13737 tree decl
= SYMBOL_REF_DECL (rtl
);
13739 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
13741 expansion_failed (NULL_TREE
, rtl
,
13742 "Symbol not defined in current TU.\n");
13750 /* Return true if constant RTL can be emitted in DW_OP_addr or
13751 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13752 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13755 const_ok_for_output (rtx rtl
)
13757 if (GET_CODE (rtl
) == SYMBOL_REF
)
13758 return const_ok_for_output_1 (rtl
);
13760 if (GET_CODE (rtl
) == CONST
)
13762 subrtx_var_iterator::array_type array
;
13763 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 0), ALL
)
13764 if (!const_ok_for_output_1 (*iter
))
13772 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
13773 if possible, NULL otherwise. */
13776 base_type_for_mode (machine_mode mode
, bool unsignedp
)
13778 dw_die_ref type_die
;
13779 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
13783 switch (TREE_CODE (type
))
13791 type_die
= lookup_type_die (type
);
13793 type_die
= modified_type_die (type
, TYPE_UNQUALIFIED
, false,
13795 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
13800 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
13801 type matching MODE, or, if MODE is narrower than or as wide as
13802 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
13805 static dw_loc_descr_ref
13806 convert_descriptor_to_mode (machine_mode mode
, dw_loc_descr_ref op
)
13808 machine_mode outer_mode
= mode
;
13809 dw_die_ref type_die
;
13810 dw_loc_descr_ref cvt
;
13812 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
13814 add_loc_descr (&op
, new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0));
13817 type_die
= base_type_for_mode (outer_mode
, 1);
13818 if (type_die
== NULL
)
13820 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
13821 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13822 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13823 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13824 add_loc_descr (&op
, cvt
);
13828 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
13830 static dw_loc_descr_ref
13831 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
13832 dw_loc_descr_ref op1
)
13834 dw_loc_descr_ref ret
= op0
;
13835 add_loc_descr (&ret
, op1
);
13836 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
13837 if (STORE_FLAG_VALUE
!= 1)
13839 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
13840 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
13845 /* Return location descriptor for signed comparison OP RTL. */
13847 static dw_loc_descr_ref
13848 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
13849 machine_mode mem_mode
)
13851 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
13852 dw_loc_descr_ref op0
, op1
;
13855 if (op_mode
== VOIDmode
)
13856 op_mode
= GET_MODE (XEXP (rtl
, 1));
13857 if (op_mode
== VOIDmode
)
13861 && dwarf_version
< 5
13862 && (!SCALAR_INT_MODE_P (op_mode
)
13863 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
13866 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
13867 VAR_INIT_STATUS_INITIALIZED
);
13868 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
13869 VAR_INIT_STATUS_INITIALIZED
);
13871 if (op0
== NULL
|| op1
== NULL
)
13874 if (!SCALAR_INT_MODE_P (op_mode
)
13875 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
13876 return compare_loc_descriptor (op
, op0
, op1
);
13878 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
13880 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
13881 dw_loc_descr_ref cvt
;
13883 if (type_die
== NULL
)
13885 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
13886 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13887 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13888 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13889 add_loc_descr (&op0
, cvt
);
13890 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
13891 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13892 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13893 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13894 add_loc_descr (&op1
, cvt
);
13895 return compare_loc_descriptor (op
, op0
, op1
);
13898 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
13899 /* For eq/ne, if the operands are known to be zero-extended,
13900 there is no need to do the fancy shifting up. */
13901 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
13903 dw_loc_descr_ref last0
, last1
;
13904 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
13906 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
13908 /* deref_size zero extends, and for constants we can check
13909 whether they are zero extended or not. */
13910 if (((last0
->dw_loc_opc
== DW_OP_deref_size
13911 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
13912 || (CONST_INT_P (XEXP (rtl
, 0))
13913 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
13914 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
13915 && ((last1
->dw_loc_opc
== DW_OP_deref_size
13916 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
13917 || (CONST_INT_P (XEXP (rtl
, 1))
13918 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
13919 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
13920 return compare_loc_descriptor (op
, op0
, op1
);
13922 /* EQ/NE comparison against constant in narrower type than
13923 DWARF2_ADDR_SIZE can be performed either as
13924 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
13927 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
13928 DW_OP_{eq,ne}. Pick whatever is shorter. */
13929 if (CONST_INT_P (XEXP (rtl
, 1))
13930 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
13931 && (size_of_int_loc_descriptor (shift
) + 1
13932 + size_of_int_loc_descriptor (UINTVAL (XEXP (rtl
, 1)) << shift
)
13933 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
13934 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
13935 & GET_MODE_MASK (op_mode
))))
13937 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
13938 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
13939 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
13940 & GET_MODE_MASK (op_mode
));
13941 return compare_loc_descriptor (op
, op0
, op1
);
13944 add_loc_descr (&op0
, int_loc_descriptor (shift
));
13945 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
13946 if (CONST_INT_P (XEXP (rtl
, 1)))
13947 op1
= int_loc_descriptor (UINTVAL (XEXP (rtl
, 1)) << shift
);
13950 add_loc_descr (&op1
, int_loc_descriptor (shift
));
13951 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
13953 return compare_loc_descriptor (op
, op0
, op1
);
13956 /* Return location descriptor for unsigned comparison OP RTL. */
13958 static dw_loc_descr_ref
13959 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
13960 machine_mode mem_mode
)
13962 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
13963 dw_loc_descr_ref op0
, op1
;
13965 if (op_mode
== VOIDmode
)
13966 op_mode
= GET_MODE (XEXP (rtl
, 1));
13967 if (op_mode
== VOIDmode
)
13969 if (!SCALAR_INT_MODE_P (op_mode
))
13973 && dwarf_version
< 5
13974 && GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
13977 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
13978 VAR_INIT_STATUS_INITIALIZED
);
13979 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
13980 VAR_INIT_STATUS_INITIALIZED
);
13982 if (op0
== NULL
|| op1
== NULL
)
13985 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
13987 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
13988 dw_loc_descr_ref last0
, last1
;
13989 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
13991 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
13993 if (CONST_INT_P (XEXP (rtl
, 0)))
13994 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
13995 /* deref_size zero extends, so no need to mask it again. */
13996 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
13997 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
13999 add_loc_descr (&op0
, int_loc_descriptor (mask
));
14000 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
14002 if (CONST_INT_P (XEXP (rtl
, 1)))
14003 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
14004 /* deref_size zero extends, so no need to mask it again. */
14005 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
14006 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
14008 add_loc_descr (&op1
, int_loc_descriptor (mask
));
14009 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
14012 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
14014 HOST_WIDE_INT bias
= 1;
14015 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
14016 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14017 if (CONST_INT_P (XEXP (rtl
, 1)))
14018 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
14019 + INTVAL (XEXP (rtl
, 1)));
14021 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
14024 return compare_loc_descriptor (op
, op0
, op1
);
14027 /* Return location descriptor for {U,S}{MIN,MAX}. */
14029 static dw_loc_descr_ref
14030 minmax_loc_descriptor (rtx rtl
, machine_mode mode
,
14031 machine_mode mem_mode
)
14033 enum dwarf_location_atom op
;
14034 dw_loc_descr_ref op0
, op1
, ret
;
14035 dw_loc_descr_ref bra_node
, drop_node
;
14038 && dwarf_version
< 5
14039 && (!SCALAR_INT_MODE_P (mode
)
14040 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
14043 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14044 VAR_INIT_STATUS_INITIALIZED
);
14045 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
14046 VAR_INIT_STATUS_INITIALIZED
);
14048 if (op0
== NULL
|| op1
== NULL
)
14051 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
14052 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
14053 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
14054 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
14056 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
14058 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
14059 add_loc_descr (&op0
, int_loc_descriptor (mask
));
14060 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
14061 add_loc_descr (&op1
, int_loc_descriptor (mask
));
14062 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
14064 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
14066 HOST_WIDE_INT bias
= 1;
14067 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
14068 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14069 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14072 else if (!SCALAR_INT_MODE_P (mode
)
14073 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
14075 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
14076 add_loc_descr (&op0
, int_loc_descriptor (shift
));
14077 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
14078 add_loc_descr (&op1
, int_loc_descriptor (shift
));
14079 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
14081 else if (SCALAR_INT_MODE_P (mode
)
14082 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
14084 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
14085 dw_loc_descr_ref cvt
;
14086 if (type_die
== NULL
)
14088 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14089 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14090 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14091 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14092 add_loc_descr (&op0
, cvt
);
14093 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14094 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14095 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14096 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14097 add_loc_descr (&op1
, cvt
);
14100 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
14105 add_loc_descr (&ret
, op1
);
14106 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
14107 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14108 add_loc_descr (&ret
, bra_node
);
14109 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14110 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
14111 add_loc_descr (&ret
, drop_node
);
14112 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14113 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
14114 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
14115 && SCALAR_INT_MODE_P (mode
)
14116 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
14117 ret
= convert_descriptor_to_mode (mode
, ret
);
14121 /* Helper function for mem_loc_descriptor. Perform OP binary op,
14122 but after converting arguments to type_die, afterwards
14123 convert back to unsigned. */
14125 static dw_loc_descr_ref
14126 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
14127 machine_mode mode
, machine_mode mem_mode
)
14129 dw_loc_descr_ref cvt
, op0
, op1
;
14131 if (type_die
== NULL
)
14133 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14134 VAR_INIT_STATUS_INITIALIZED
);
14135 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
14136 VAR_INIT_STATUS_INITIALIZED
);
14137 if (op0
== NULL
|| op1
== NULL
)
14139 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14140 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14141 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14142 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14143 add_loc_descr (&op0
, cvt
);
14144 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14145 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14146 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14147 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14148 add_loc_descr (&op1
, cvt
);
14149 add_loc_descr (&op0
, op1
);
14150 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
14151 return convert_descriptor_to_mode (mode
, op0
);
14154 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
14155 const0 is DW_OP_lit0 or corresponding typed constant,
14156 const1 is DW_OP_lit1 or corresponding typed constant
14157 and constMSB is constant with just the MSB bit set
14159 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
14160 L1: const0 DW_OP_swap
14161 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
14162 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14167 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
14168 L1: const0 DW_OP_swap
14169 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
14170 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14175 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
14176 L1: const1 DW_OP_swap
14177 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
14178 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14182 static dw_loc_descr_ref
14183 clz_loc_descriptor (rtx rtl
, machine_mode mode
,
14184 machine_mode mem_mode
)
14186 dw_loc_descr_ref op0
, ret
, tmp
;
14187 HOST_WIDE_INT valv
;
14188 dw_loc_descr_ref l1jump
, l1label
;
14189 dw_loc_descr_ref l2jump
, l2label
;
14190 dw_loc_descr_ref l3jump
, l3label
;
14191 dw_loc_descr_ref l4jump
, l4label
;
14194 if (!SCALAR_INT_MODE_P (mode
)
14195 || GET_MODE (XEXP (rtl
, 0)) != mode
)
14198 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14199 VAR_INIT_STATUS_INITIALIZED
);
14203 if (GET_CODE (rtl
) == CLZ
)
14205 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
14206 valv
= GET_MODE_BITSIZE (mode
);
14208 else if (GET_CODE (rtl
) == FFS
)
14210 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
14211 valv
= GET_MODE_BITSIZE (mode
);
14212 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
14213 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14214 add_loc_descr (&ret
, l1jump
);
14215 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
14216 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
14217 VAR_INIT_STATUS_INITIALIZED
);
14220 add_loc_descr (&ret
, tmp
);
14221 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14222 add_loc_descr (&ret
, l4jump
);
14223 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
14224 ? const1_rtx
: const0_rtx
,
14226 VAR_INIT_STATUS_INITIALIZED
);
14227 if (l1label
== NULL
)
14229 add_loc_descr (&ret
, l1label
);
14230 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14231 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
14232 add_loc_descr (&ret
, l2label
);
14233 if (GET_CODE (rtl
) != CLZ
)
14235 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
14236 msb
= GEN_INT (HOST_WIDE_INT_1U
14237 << (GET_MODE_BITSIZE (mode
) - 1));
14239 msb
= immed_wide_int_const
14240 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode
) - 1,
14241 GET_MODE_PRECISION (mode
)), mode
);
14242 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
14243 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
14244 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
14245 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
14247 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
14248 VAR_INIT_STATUS_INITIALIZED
);
14251 add_loc_descr (&ret
, tmp
);
14252 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
14253 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14254 add_loc_descr (&ret
, l3jump
);
14255 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
14256 VAR_INIT_STATUS_INITIALIZED
);
14259 add_loc_descr (&ret
, tmp
);
14260 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
14261 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
14262 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14263 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
14264 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14265 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14266 add_loc_descr (&ret
, l2jump
);
14267 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
14268 add_loc_descr (&ret
, l3label
);
14269 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
14270 add_loc_descr (&ret
, l4label
);
14271 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14272 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
14273 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14274 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
14275 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14276 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
14277 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14278 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
14282 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
14283 const1 is DW_OP_lit1 or corresponding typed constant):
14285 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
14286 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
14290 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
14291 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
14294 static dw_loc_descr_ref
14295 popcount_loc_descriptor (rtx rtl
, machine_mode mode
,
14296 machine_mode mem_mode
)
14298 dw_loc_descr_ref op0
, ret
, tmp
;
14299 dw_loc_descr_ref l1jump
, l1label
;
14300 dw_loc_descr_ref l2jump
, l2label
;
14302 if (!SCALAR_INT_MODE_P (mode
)
14303 || GET_MODE (XEXP (rtl
, 0)) != mode
)
14306 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14307 VAR_INIT_STATUS_INITIALIZED
);
14311 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
14312 VAR_INIT_STATUS_INITIALIZED
);
14315 add_loc_descr (&ret
, tmp
);
14316 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14317 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
14318 add_loc_descr (&ret
, l1label
);
14319 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14320 add_loc_descr (&ret
, l2jump
);
14321 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
14322 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
14323 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
14324 VAR_INIT_STATUS_INITIALIZED
);
14327 add_loc_descr (&ret
, tmp
);
14328 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
14329 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
14330 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
14331 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14332 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
14333 VAR_INIT_STATUS_INITIALIZED
);
14334 add_loc_descr (&ret
, tmp
);
14335 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
14336 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14337 add_loc_descr (&ret
, l1jump
);
14338 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
14339 add_loc_descr (&ret
, l2label
);
14340 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14341 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
14342 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14343 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
14347 /* BSWAP (constS is initial shift count, either 56 or 24):
14349 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
14350 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
14351 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
14352 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
14353 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
14355 static dw_loc_descr_ref
14356 bswap_loc_descriptor (rtx rtl
, machine_mode mode
,
14357 machine_mode mem_mode
)
14359 dw_loc_descr_ref op0
, ret
, tmp
;
14360 dw_loc_descr_ref l1jump
, l1label
;
14361 dw_loc_descr_ref l2jump
, l2label
;
14363 if (!SCALAR_INT_MODE_P (mode
)
14364 || BITS_PER_UNIT
!= 8
14365 || (GET_MODE_BITSIZE (mode
) != 32
14366 && GET_MODE_BITSIZE (mode
) != 64))
14369 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14370 VAR_INIT_STATUS_INITIALIZED
);
14375 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
14377 VAR_INIT_STATUS_INITIALIZED
);
14380 add_loc_descr (&ret
, tmp
);
14381 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
14382 VAR_INIT_STATUS_INITIALIZED
);
14385 add_loc_descr (&ret
, tmp
);
14386 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
14387 add_loc_descr (&ret
, l1label
);
14388 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
14390 VAR_INIT_STATUS_INITIALIZED
);
14391 add_loc_descr (&ret
, tmp
);
14392 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
14393 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14394 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
14395 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
14396 VAR_INIT_STATUS_INITIALIZED
);
14399 add_loc_descr (&ret
, tmp
);
14400 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
14401 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
14402 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
14403 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
14404 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14405 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
14406 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
14407 VAR_INIT_STATUS_INITIALIZED
);
14408 add_loc_descr (&ret
, tmp
);
14409 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
14410 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14411 add_loc_descr (&ret
, l2jump
);
14412 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
14413 VAR_INIT_STATUS_INITIALIZED
);
14414 add_loc_descr (&ret
, tmp
);
14415 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14416 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14417 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14418 add_loc_descr (&ret
, l1jump
);
14419 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
14420 add_loc_descr (&ret
, l2label
);
14421 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14422 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
14423 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14424 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
14425 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14426 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
14430 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
14431 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
14432 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
14433 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
14435 ROTATERT is similar:
14436 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
14437 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
14438 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
14440 static dw_loc_descr_ref
14441 rotate_loc_descriptor (rtx rtl
, machine_mode mode
,
14442 machine_mode mem_mode
)
14444 rtx rtlop1
= XEXP (rtl
, 1);
14445 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
14448 if (!SCALAR_INT_MODE_P (mode
))
14451 if (GET_MODE (rtlop1
) != VOIDmode
14452 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
14453 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
14454 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14455 VAR_INIT_STATUS_INITIALIZED
);
14456 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
14457 VAR_INIT_STATUS_INITIALIZED
);
14458 if (op0
== NULL
|| op1
== NULL
)
14460 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
14461 for (i
= 0; i
< 2; i
++)
14463 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
14464 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
14466 VAR_INIT_STATUS_INITIALIZED
);
14467 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
14468 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
14470 : HOST_BITS_PER_WIDE_INT
== 64
14471 ? DW_OP_const8u
: DW_OP_constu
,
14472 GET_MODE_MASK (mode
), 0);
14475 if (mask
[i
] == NULL
)
14477 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
14480 add_loc_descr (&ret
, op1
);
14481 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
14482 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
14483 if (GET_CODE (rtl
) == ROTATERT
)
14485 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
14486 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
14487 GET_MODE_BITSIZE (mode
), 0));
14489 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
14490 if (mask
[0] != NULL
)
14491 add_loc_descr (&ret
, mask
[0]);
14492 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
14493 if (mask
[1] != NULL
)
14495 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14496 add_loc_descr (&ret
, mask
[1]);
14497 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14499 if (GET_CODE (rtl
) == ROTATE
)
14501 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
14502 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
14503 GET_MODE_BITSIZE (mode
), 0));
14505 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
14506 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
14510 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
14511 for DEBUG_PARAMETER_REF RTL. */
14513 static dw_loc_descr_ref
14514 parameter_ref_descriptor (rtx rtl
)
14516 dw_loc_descr_ref ret
;
14521 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
14522 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
14523 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
14526 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14527 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
14528 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14532 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
14533 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
14538 /* The following routine converts the RTL for a variable or parameter
14539 (resident in memory) into an equivalent Dwarf representation of a
14540 mechanism for getting the address of that same variable onto the top of a
14541 hypothetical "address evaluation" stack.
14543 When creating memory location descriptors, we are effectively transforming
14544 the RTL for a memory-resident object into its Dwarf postfix expression
14545 equivalent. This routine recursively descends an RTL tree, turning
14546 it into Dwarf postfix code as it goes.
14548 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
14550 MEM_MODE is the mode of the memory reference, needed to handle some
14551 autoincrement addressing modes.
14553 Return 0 if we can't represent the location. */
14556 mem_loc_descriptor (rtx rtl
, machine_mode mode
,
14557 machine_mode mem_mode
,
14558 enum var_init_status initialized
)
14560 dw_loc_descr_ref mem_loc_result
= NULL
;
14561 enum dwarf_location_atom op
;
14562 dw_loc_descr_ref op0
, op1
;
14563 rtx inner
= NULL_RTX
;
14565 if (mode
== VOIDmode
)
14566 mode
= GET_MODE (rtl
);
14568 /* Note that for a dynamically sized array, the location we will generate a
14569 description of here will be the lowest numbered location which is
14570 actually within the array. That's *not* necessarily the same as the
14571 zeroth element of the array. */
14573 rtl
= targetm
.delegitimize_address (rtl
);
14575 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
14578 switch (GET_CODE (rtl
))
14583 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
14586 /* The case of a subreg may arise when we have a local (register)
14587 variable or a formal (register) parameter which doesn't quite fill
14588 up an entire register. For now, just assume that it is
14589 legitimate to make the Dwarf info refer to the whole register which
14590 contains the given subreg. */
14591 if (!subreg_lowpart_p (rtl
))
14593 inner
= SUBREG_REG (rtl
);
14596 if (inner
== NULL_RTX
)
14597 inner
= XEXP (rtl
, 0);
14598 if (SCALAR_INT_MODE_P (mode
)
14599 && SCALAR_INT_MODE_P (GET_MODE (inner
))
14600 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
14601 #ifdef POINTERS_EXTEND_UNSIGNED
14602 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
14605 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
14607 mem_loc_result
= mem_loc_descriptor (inner
,
14609 mem_mode
, initialized
);
14612 if (dwarf_strict
&& dwarf_version
< 5)
14614 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
14616 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
14617 && (!SCALAR_INT_MODE_P (mode
)
14618 || !SCALAR_INT_MODE_P (GET_MODE (inner
))))
14622 dw_die_ref type_die
;
14623 dw_loc_descr_ref cvt
;
14625 mem_loc_result
= mem_loc_descriptor (inner
,
14627 mem_mode
, initialized
);
14628 if (mem_loc_result
== NULL
)
14630 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
14631 if (type_die
== NULL
)
14633 mem_loc_result
= NULL
;
14636 if (GET_MODE_SIZE (mode
)
14637 != GET_MODE_SIZE (GET_MODE (inner
)))
14638 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14640 cvt
= new_loc_descr (dwarf_OP (DW_OP_reinterpret
), 0, 0);
14641 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14642 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14643 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14644 add_loc_descr (&mem_loc_result
, cvt
);
14645 if (SCALAR_INT_MODE_P (mode
)
14646 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
14648 /* Convert it to untyped afterwards. */
14649 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14650 add_loc_descr (&mem_loc_result
, cvt
);
14656 if (! SCALAR_INT_MODE_P (mode
)
14657 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
14658 && rtl
!= arg_pointer_rtx
14659 && rtl
!= frame_pointer_rtx
14660 #ifdef POINTERS_EXTEND_UNSIGNED
14661 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
14665 dw_die_ref type_die
;
14666 unsigned int dbx_regnum
;
14668 if (dwarf_strict
&& dwarf_version
< 5)
14670 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
14672 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
14673 if (type_die
== NULL
)
14676 dbx_regnum
= dbx_reg_number (rtl
);
14677 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
14679 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_regval_type
),
14681 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
14682 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
14683 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
14686 /* Whenever a register number forms a part of the description of the
14687 method for calculating the (dynamic) address of a memory resident
14688 object, DWARF rules require the register number be referred to as
14689 a "base register". This distinction is not based in any way upon
14690 what category of register the hardware believes the given register
14691 belongs to. This is strictly DWARF terminology we're dealing with
14692 here. Note that in cases where the location of a memory-resident
14693 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
14694 OP_CONST (0)) the actual DWARF location descriptor that we generate
14695 may just be OP_BASEREG (basereg). This may look deceptively like
14696 the object in question was allocated to a register (rather than in
14697 memory) so DWARF consumers need to be aware of the subtle
14698 distinction between OP_REG and OP_BASEREG. */
14699 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
14700 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
14701 else if (stack_realign_drap
14703 && crtl
->args
.internal_arg_pointer
== rtl
14704 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
14706 /* If RTL is internal_arg_pointer, which has been optimized
14707 out, use DRAP instead. */
14708 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
14709 VAR_INIT_STATUS_INITIALIZED
);
14715 if (!SCALAR_INT_MODE_P (mode
))
14717 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
14718 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
14721 else if (GET_CODE (rtl
) == ZERO_EXTEND
14722 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
14723 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
14724 < HOST_BITS_PER_WIDE_INT
14725 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
14726 to expand zero extend as two shifts instead of
14728 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
14730 machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
14731 mem_loc_result
= op0
;
14732 add_loc_descr (&mem_loc_result
,
14733 int_loc_descriptor (GET_MODE_MASK (imode
)));
14734 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
14736 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
14738 int shift
= DWARF2_ADDR_SIZE
14739 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
14740 shift
*= BITS_PER_UNIT
;
14741 if (GET_CODE (rtl
) == SIGN_EXTEND
)
14745 mem_loc_result
= op0
;
14746 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
14747 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
14748 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
14749 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
14751 else if (!dwarf_strict
|| dwarf_version
>= 5)
14753 dw_die_ref type_die1
, type_die2
;
14754 dw_loc_descr_ref cvt
;
14756 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
14757 GET_CODE (rtl
) == ZERO_EXTEND
);
14758 if (type_die1
== NULL
)
14760 type_die2
= base_type_for_mode (mode
, 1);
14761 if (type_die2
== NULL
)
14763 mem_loc_result
= op0
;
14764 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14765 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14766 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
14767 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14768 add_loc_descr (&mem_loc_result
, cvt
);
14769 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14770 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14771 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
14772 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14773 add_loc_descr (&mem_loc_result
, cvt
);
14779 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
14780 if (new_rtl
!= rtl
)
14782 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
14784 if (mem_loc_result
!= NULL
)
14785 return mem_loc_result
;
14788 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
14789 get_address_mode (rtl
), mode
,
14790 VAR_INIT_STATUS_INITIALIZED
);
14791 if (mem_loc_result
== NULL
)
14792 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
14793 if (mem_loc_result
!= NULL
)
14795 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
14796 || !SCALAR_INT_MODE_P(mode
))
14798 dw_die_ref type_die
;
14799 dw_loc_descr_ref deref
;
14801 if (dwarf_strict
&& dwarf_version
< 5)
14804 = base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
14805 if (type_die
== NULL
)
14807 deref
= new_loc_descr (dwarf_OP (DW_OP_deref_type
),
14808 GET_MODE_SIZE (mode
), 0);
14809 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
14810 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
14811 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
14812 add_loc_descr (&mem_loc_result
, deref
);
14814 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
14815 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
14817 add_loc_descr (&mem_loc_result
,
14818 new_loc_descr (DW_OP_deref_size
,
14819 GET_MODE_SIZE (mode
), 0));
14824 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
14827 /* Some ports can transform a symbol ref into a label ref, because
14828 the symbol ref is too far away and has to be dumped into a constant
14832 if (!SCALAR_INT_MODE_P (mode
)
14833 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
14834 #ifdef POINTERS_EXTEND_UNSIGNED
14835 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
14839 if (GET_CODE (rtl
) == SYMBOL_REF
14840 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
14842 dw_loc_descr_ref temp
;
14844 /* If this is not defined, we have no way to emit the data. */
14845 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
14848 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
14850 /* We check for DWARF 5 here because gdb did not implement
14851 DW_OP_form_tls_address until after 7.12. */
14852 mem_loc_result
= new_loc_descr ((dwarf_version
>= 5
14853 ? DW_OP_form_tls_address
14854 : DW_OP_GNU_push_tls_address
),
14856 add_loc_descr (&mem_loc_result
, temp
);
14861 if (!const_ok_for_output (rtl
))
14863 if (GET_CODE (rtl
) == CONST
)
14864 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14870 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
14871 vec_safe_push (used_rtx_array
, rtl
);
14877 case DEBUG_IMPLICIT_PTR
:
14878 expansion_failed (NULL_TREE
, rtl
,
14879 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
14883 if (dwarf_strict
&& dwarf_version
< 5)
14885 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
14887 if (!SCALAR_INT_MODE_P (mode
)
14888 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
14889 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
14890 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14893 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
14894 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
14896 op0
= one_reg_loc_descriptor (dbx_regnum
,
14897 VAR_INIT_STATUS_INITIALIZED
);
14900 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
14901 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
14903 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
14904 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14905 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
14909 gcc_unreachable ();
14912 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_entry_value
), 0, 0);
14913 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14914 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
14917 case DEBUG_PARAMETER_REF
:
14918 mem_loc_result
= parameter_ref_descriptor (rtl
);
14922 /* Extract the PLUS expression nested inside and fall into
14923 PLUS code below. */
14924 rtl
= XEXP (rtl
, 1);
14929 /* Turn these into a PLUS expression and fall into the PLUS code
14931 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
14932 gen_int_mode (GET_CODE (rtl
) == PRE_INC
14933 ? GET_MODE_UNIT_SIZE (mem_mode
)
14934 : -GET_MODE_UNIT_SIZE (mem_mode
),
14941 if (is_based_loc (rtl
)
14942 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
14943 || XEXP (rtl
, 0) == arg_pointer_rtx
14944 || XEXP (rtl
, 0) == frame_pointer_rtx
)
14945 && SCALAR_INT_MODE_P (mode
))
14946 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
14947 INTVAL (XEXP (rtl
, 1)),
14948 VAR_INIT_STATUS_INITIALIZED
);
14951 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14952 VAR_INIT_STATUS_INITIALIZED
);
14953 if (mem_loc_result
== 0)
14956 if (CONST_INT_P (XEXP (rtl
, 1))
14957 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
14958 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
14961 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
14962 VAR_INIT_STATUS_INITIALIZED
);
14965 add_loc_descr (&mem_loc_result
, op1
);
14966 add_loc_descr (&mem_loc_result
,
14967 new_loc_descr (DW_OP_plus
, 0, 0));
14972 /* If a pseudo-reg is optimized away, it is possible for it to
14973 be replaced with a MEM containing a multiply or shift. */
14983 if ((!dwarf_strict
|| dwarf_version
>= 5)
14984 && SCALAR_INT_MODE_P (mode
)
14985 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
14987 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
14988 base_type_for_mode (mode
, 0),
15012 if (!SCALAR_INT_MODE_P (mode
))
15014 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15015 VAR_INIT_STATUS_INITIALIZED
);
15017 rtx rtlop1
= XEXP (rtl
, 1);
15018 if (GET_MODE (rtlop1
) != VOIDmode
15019 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
15020 < GET_MODE_BITSIZE (mode
))
15021 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
15022 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
15023 VAR_INIT_STATUS_INITIALIZED
);
15026 if (op0
== 0 || op1
== 0)
15029 mem_loc_result
= op0
;
15030 add_loc_descr (&mem_loc_result
, op1
);
15031 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15047 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15048 VAR_INIT_STATUS_INITIALIZED
);
15049 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15050 VAR_INIT_STATUS_INITIALIZED
);
15052 if (op0
== 0 || op1
== 0)
15055 mem_loc_result
= op0
;
15056 add_loc_descr (&mem_loc_result
, op1
);
15057 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15061 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
15062 && (!dwarf_strict
|| dwarf_version
>= 5))
15064 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
15065 base_type_for_mode (mode
, 0),
15070 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15071 VAR_INIT_STATUS_INITIALIZED
);
15072 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15073 VAR_INIT_STATUS_INITIALIZED
);
15075 if (op0
== 0 || op1
== 0)
15078 mem_loc_result
= op0
;
15079 add_loc_descr (&mem_loc_result
, op1
);
15080 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
15081 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
15082 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
15083 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
15084 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
15088 if ((!dwarf_strict
|| dwarf_version
>= 5)
15089 && SCALAR_INT_MODE_P (mode
))
15091 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
15096 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
15097 base_type_for_mode (mode
, 1),
15115 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15116 VAR_INIT_STATUS_INITIALIZED
);
15121 mem_loc_result
= op0
;
15122 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15126 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
15127 #ifdef POINTERS_EXTEND_UNSIGNED
15129 && mem_mode
!= VOIDmode
15130 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
15134 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
15137 if ((!dwarf_strict
|| dwarf_version
>= 5)
15138 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
15139 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
15141 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
15142 machine_mode amode
;
15143 if (type_die
== NULL
)
15145 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
15147 if (INTVAL (rtl
) >= 0
15148 && amode
!= BLKmode
15149 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
15150 /* const DW_OP_convert <XXX> vs.
15151 DW_OP_const_type <XXX, 1, const>. */
15152 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
15153 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
15155 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
15156 op0
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15157 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15158 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15159 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15160 add_loc_descr (&mem_loc_result
, op0
);
15161 return mem_loc_result
;
15163 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0,
15165 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15166 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15167 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15168 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
15169 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
15172 mem_loc_result
->dw_loc_oprnd2
.val_class
15173 = dw_val_class_const_double
;
15174 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
15175 = double_int::from_shwi (INTVAL (rtl
));
15181 if (!dwarf_strict
|| dwarf_version
>= 5)
15183 dw_die_ref type_die
;
15185 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
15186 CONST_DOUBLE rtx could represent either a large integer
15187 or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
15188 the value is always a floating point constant.
15190 When it is an integer, a CONST_DOUBLE is used whenever
15191 the constant requires 2 HWIs to be adequately represented.
15192 We output CONST_DOUBLEs as blocks. */
15193 if (mode
== VOIDmode
15194 || (GET_MODE (rtl
) == VOIDmode
15195 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
15197 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
15198 if (type_die
== NULL
)
15200 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0, 0);
15201 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15202 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15203 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15204 #if TARGET_SUPPORTS_WIDE_INT == 0
15205 if (!SCALAR_FLOAT_MODE_P (mode
))
15207 mem_loc_result
->dw_loc_oprnd2
.val_class
15208 = dw_val_class_const_double
;
15209 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
15210 = rtx_to_double_int (rtl
);
15215 unsigned int length
= GET_MODE_SIZE (mode
);
15216 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
15218 insert_float (rtl
, array
);
15219 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
15220 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
15221 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
15222 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
15227 case CONST_WIDE_INT
:
15228 if (!dwarf_strict
|| dwarf_version
>= 5)
15230 dw_die_ref type_die
;
15232 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
15233 if (type_die
== NULL
)
15235 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0, 0);
15236 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15237 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15238 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15239 mem_loc_result
->dw_loc_oprnd2
.val_class
15240 = dw_val_class_wide_int
;
15241 mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
15242 *mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= rtx_mode_t (rtl
, mode
);
15247 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
15251 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
15255 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
15259 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
15263 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
15267 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
15271 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
15275 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
15279 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
15283 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
15288 if (!SCALAR_INT_MODE_P (mode
))
15293 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
15298 if (CONST_INT_P (XEXP (rtl
, 1))
15299 && CONST_INT_P (XEXP (rtl
, 2))
15300 && ((unsigned) INTVAL (XEXP (rtl
, 1))
15301 + (unsigned) INTVAL (XEXP (rtl
, 2))
15302 <= GET_MODE_BITSIZE (mode
))
15303 && SCALAR_INT_MODE_P (mode
)
15304 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
15305 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
15308 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
15309 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
15312 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
15316 mem_loc_result
= op0
;
15317 size
= INTVAL (XEXP (rtl
, 1));
15318 shift
= INTVAL (XEXP (rtl
, 2));
15319 if (BITS_BIG_ENDIAN
)
15320 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
15322 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
15324 add_loc_descr (&mem_loc_result
,
15325 int_loc_descriptor (DWARF2_ADDR_SIZE
15327 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
15329 if (size
!= (int) DWARF2_ADDR_SIZE
)
15331 add_loc_descr (&mem_loc_result
,
15332 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
15333 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15340 dw_loc_descr_ref op2
, bra_node
, drop_node
;
15341 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
15342 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
15343 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
15344 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
15345 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15346 VAR_INIT_STATUS_INITIALIZED
);
15347 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
15348 VAR_INIT_STATUS_INITIALIZED
);
15349 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
15352 mem_loc_result
= op1
;
15353 add_loc_descr (&mem_loc_result
, op2
);
15354 add_loc_descr (&mem_loc_result
, op0
);
15355 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
15356 add_loc_descr (&mem_loc_result
, bra_node
);
15357 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
15358 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
15359 add_loc_descr (&mem_loc_result
, drop_node
);
15360 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15361 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
15366 case FLOAT_TRUNCATE
:
15368 case UNSIGNED_FLOAT
:
15371 if (!dwarf_strict
|| dwarf_version
>= 5)
15373 dw_die_ref type_die
;
15374 dw_loc_descr_ref cvt
;
15376 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
15377 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
15380 if (SCALAR_INT_MODE_P (GET_MODE (XEXP (rtl
, 0)))
15381 && (GET_CODE (rtl
) == FLOAT
15382 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
15383 <= DWARF2_ADDR_SIZE
))
15385 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
15386 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
15387 if (type_die
== NULL
)
15389 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15390 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15391 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15392 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15393 add_loc_descr (&op0
, cvt
);
15395 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
15396 if (type_die
== NULL
)
15398 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15399 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15400 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15401 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15402 add_loc_descr (&op0
, cvt
);
15403 if (SCALAR_INT_MODE_P (mode
)
15404 && (GET_CODE (rtl
) == FIX
15405 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
15407 op0
= convert_descriptor_to_mode (mode
, op0
);
15411 mem_loc_result
= op0
;
15418 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
15423 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
15427 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
15432 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
15436 /* In theory, we could implement the above. */
15437 /* DWARF cannot represent the unsigned compare operations
15462 case FRACT_CONVERT
:
15463 case UNSIGNED_FRACT_CONVERT
:
15465 case UNSIGNED_SAT_FRACT
:
15471 case VEC_DUPLICATE
:
15475 case STRICT_LOW_PART
:
15480 /* If delegitimize_address couldn't do anything with the UNSPEC, we
15481 can't express it in the debug info. This can happen e.g. with some
15486 resolve_one_addr (&rtl
);
15489 /* RTL sequences inside PARALLEL record a series of DWARF operations for
15490 the expression. An UNSPEC rtx represents a raw DWARF operation,
15491 new_loc_descr is called for it to build the operation directly.
15492 Otherwise mem_loc_descriptor is called recursively. */
15496 dw_loc_descr_ref exp_result
= NULL
;
15498 for (; index
< XVECLEN (rtl
, 0); index
++)
15500 rtx elem
= XVECEXP (rtl
, 0, index
);
15501 if (GET_CODE (elem
) == UNSPEC
)
15503 /* Each DWARF operation UNSPEC contain two operands, if
15504 one operand is not used for the operation, const0_rtx is
15506 gcc_assert (XVECLEN (elem
, 0) == 2);
15508 HOST_WIDE_INT dw_op
= XINT (elem
, 1);
15509 HOST_WIDE_INT oprnd1
= INTVAL (XVECEXP (elem
, 0, 0));
15510 HOST_WIDE_INT oprnd2
= INTVAL (XVECEXP (elem
, 0, 1));
15512 = new_loc_descr ((enum dwarf_location_atom
) dw_op
, oprnd1
,
15517 = mem_loc_descriptor (elem
, mode
, mem_mode
,
15518 VAR_INIT_STATUS_INITIALIZED
);
15520 if (!mem_loc_result
)
15521 mem_loc_result
= exp_result
;
15523 add_loc_descr (&mem_loc_result
, exp_result
);
15532 print_rtl (stderr
, rtl
);
15533 gcc_unreachable ();
15538 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
15539 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
15541 return mem_loc_result
;
15544 /* Return a descriptor that describes the concatenation of two locations.
15545 This is typically a complex variable. */
15547 static dw_loc_descr_ref
15548 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
15550 dw_loc_descr_ref cc_loc_result
= NULL
;
15551 dw_loc_descr_ref x0_ref
15552 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15553 dw_loc_descr_ref x1_ref
15554 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15556 if (x0_ref
== 0 || x1_ref
== 0)
15559 cc_loc_result
= x0_ref
;
15560 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
15562 add_loc_descr (&cc_loc_result
, x1_ref
);
15563 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
15565 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
15566 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
15568 return cc_loc_result
;
15571 /* Return a descriptor that describes the concatenation of N
15574 static dw_loc_descr_ref
15575 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
15578 dw_loc_descr_ref cc_loc_result
= NULL
;
15579 unsigned int n
= XVECLEN (concatn
, 0);
15581 for (i
= 0; i
< n
; ++i
)
15583 dw_loc_descr_ref ref
;
15584 rtx x
= XVECEXP (concatn
, 0, i
);
15586 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15590 add_loc_descr (&cc_loc_result
, ref
);
15591 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
15594 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
15595 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
15597 return cc_loc_result
;
15600 /* Helper function for loc_descriptor. Return DW_OP_implicit_pointer
15601 for DEBUG_IMPLICIT_PTR RTL. */
15603 static dw_loc_descr_ref
15604 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
15606 dw_loc_descr_ref ret
;
15609 if (dwarf_strict
&& dwarf_version
< 5)
15611 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
15612 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
15613 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
15614 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
15615 ret
= new_loc_descr (dwarf_OP (DW_OP_implicit_pointer
), 0, offset
);
15616 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
15619 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15620 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
15621 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15625 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
15626 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
15631 /* Output a proper Dwarf location descriptor for a variable or parameter
15632 which is either allocated in a register or in a memory location. For a
15633 register, we just generate an OP_REG and the register number. For a
15634 memory location we provide a Dwarf postfix expression describing how to
15635 generate the (dynamic) address of the object onto the address stack.
15637 MODE is mode of the decl if this loc_descriptor is going to be used in
15638 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
15639 allowed, VOIDmode otherwise.
15641 If we don't know how to describe it, return 0. */
15643 static dw_loc_descr_ref
15644 loc_descriptor (rtx rtl
, machine_mode mode
,
15645 enum var_init_status initialized
)
15647 dw_loc_descr_ref loc_result
= NULL
;
15649 switch (GET_CODE (rtl
))
15652 /* The case of a subreg may arise when we have a local (register)
15653 variable or a formal (register) parameter which doesn't quite fill
15654 up an entire register. For now, just assume that it is
15655 legitimate to make the Dwarf info refer to the whole register which
15656 contains the given subreg. */
15657 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
15658 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
15659 GET_MODE (SUBREG_REG (rtl
)), initialized
);
15665 loc_result
= reg_loc_descriptor (rtl
, initialized
);
15669 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
15670 GET_MODE (rtl
), initialized
);
15671 if (loc_result
== NULL
)
15672 loc_result
= tls_mem_loc_descriptor (rtl
);
15673 if (loc_result
== NULL
)
15675 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
15676 if (new_rtl
!= rtl
)
15677 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
15682 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
15687 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
15692 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
15694 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
15695 if (GET_CODE (loc
) == EXPR_LIST
)
15696 loc
= XEXP (loc
, 0);
15697 loc_result
= loc_descriptor (loc
, mode
, initialized
);
15701 rtl
= XEXP (rtl
, 1);
15706 rtvec par_elems
= XVEC (rtl
, 0);
15707 int num_elem
= GET_NUM_ELEM (par_elems
);
15711 /* Create the first one, so we have something to add to. */
15712 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
15713 VOIDmode
, initialized
);
15714 if (loc_result
== NULL
)
15716 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
15717 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
15718 for (i
= 1; i
< num_elem
; i
++)
15720 dw_loc_descr_ref temp
;
15722 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
15723 VOIDmode
, initialized
);
15726 add_loc_descr (&loc_result
, temp
);
15727 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
15728 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
15734 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
15735 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
15740 if (mode
== VOIDmode
)
15741 mode
= GET_MODE (rtl
);
15743 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
15745 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
15747 /* Note that a CONST_DOUBLE rtx could represent either an integer
15748 or a floating-point constant. A CONST_DOUBLE is used whenever
15749 the constant requires more than one word in order to be
15750 adequately represented. We output CONST_DOUBLEs as blocks. */
15751 loc_result
= new_loc_descr (DW_OP_implicit_value
,
15752 GET_MODE_SIZE (mode
), 0);
15753 #if TARGET_SUPPORTS_WIDE_INT == 0
15754 if (!SCALAR_FLOAT_MODE_P (mode
))
15756 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
15757 loc_result
->dw_loc_oprnd2
.v
.val_double
15758 = rtx_to_double_int (rtl
);
15763 unsigned int length
= GET_MODE_SIZE (mode
);
15764 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
15766 insert_float (rtl
, array
);
15767 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
15768 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
15769 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
15770 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
15775 case CONST_WIDE_INT
:
15776 if (mode
== VOIDmode
)
15777 mode
= GET_MODE (rtl
);
15779 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
15781 loc_result
= new_loc_descr (DW_OP_implicit_value
,
15782 GET_MODE_SIZE (mode
), 0);
15783 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_wide_int
;
15784 loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
15785 *loc_result
->dw_loc_oprnd2
.v
.val_wide
= rtx_mode_t (rtl
, mode
);
15790 if (mode
== VOIDmode
)
15791 mode
= GET_MODE (rtl
);
15793 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
15795 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
15796 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
15797 unsigned char *array
15798 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
15801 machine_mode imode
= GET_MODE_INNER (mode
);
15803 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
15804 switch (GET_MODE_CLASS (mode
))
15806 case MODE_VECTOR_INT
:
15807 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15809 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15810 insert_wide_int (rtx_mode_t (elt
, imode
), p
, elt_size
);
15814 case MODE_VECTOR_FLOAT
:
15815 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15817 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15818 insert_float (elt
, p
);
15823 gcc_unreachable ();
15826 loc_result
= new_loc_descr (DW_OP_implicit_value
,
15827 length
* elt_size
, 0);
15828 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
15829 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
15830 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
15831 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
15836 if (mode
== VOIDmode
15837 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
15838 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
15839 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
15841 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
15846 if (!const_ok_for_output (rtl
))
15850 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
15851 && (dwarf_version
>= 4 || !dwarf_strict
))
15853 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
15854 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15855 vec_safe_push (used_rtx_array
, rtl
);
15859 case DEBUG_IMPLICIT_PTR
:
15860 loc_result
= implicit_ptr_descriptor (rtl
, 0);
15864 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
15865 && CONST_INT_P (XEXP (rtl
, 1)))
15868 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
15874 if ((SCALAR_INT_MODE_P (mode
)
15875 && GET_MODE (rtl
) == mode
15876 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
15877 && dwarf_version
>= 4)
15878 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
15880 /* Value expression. */
15881 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
15883 add_loc_descr (&loc_result
,
15884 new_loc_descr (DW_OP_stack_value
, 0, 0));
15892 /* We need to figure out what section we should use as the base for the
15893 address ranges where a given location is valid.
15894 1. If this particular DECL has a section associated with it, use that.
15895 2. If this function has a section associated with it, use that.
15896 3. Otherwise, use the text section.
15897 XXX: If you split a variable across multiple sections, we won't notice. */
15899 static const char *
15900 secname_for_decl (const_tree decl
)
15902 const char *secname
;
15904 if (VAR_OR_FUNCTION_DECL_P (decl
)
15905 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
) || TREE_STATIC (decl
))
15906 && DECL_SECTION_NAME (decl
))
15907 secname
= DECL_SECTION_NAME (decl
);
15908 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
15909 secname
= DECL_SECTION_NAME (current_function_decl
);
15910 else if (cfun
&& in_cold_section_p
)
15911 secname
= crtl
->subsections
.cold_section_label
;
15913 secname
= text_section_label
;
15918 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
15921 decl_by_reference_p (tree decl
)
15923 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
15925 && DECL_BY_REFERENCE (decl
));
15928 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
15931 static dw_loc_descr_ref
15932 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
15933 enum var_init_status initialized
)
15935 int have_address
= 0;
15936 dw_loc_descr_ref descr
;
15939 if (want_address
!= 2)
15941 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
15943 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
15945 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
15946 if (GET_CODE (varloc
) == EXPR_LIST
)
15947 varloc
= XEXP (varloc
, 0);
15948 mode
= GET_MODE (varloc
);
15949 if (MEM_P (varloc
))
15951 rtx addr
= XEXP (varloc
, 0);
15952 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
15953 mode
, initialized
);
15958 rtx x
= avoid_constant_pool_reference (varloc
);
15960 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
15965 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
15972 if (GET_CODE (varloc
) == VAR_LOCATION
)
15973 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
15975 mode
= DECL_MODE (loc
);
15976 descr
= loc_descriptor (varloc
, mode
, initialized
);
15983 if (want_address
== 2 && !have_address
15984 && (dwarf_version
>= 4 || !dwarf_strict
))
15986 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
15988 expansion_failed (loc
, NULL_RTX
,
15989 "DWARF address size mismatch");
15992 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15995 /* Show if we can't fill the request for an address. */
15996 if (want_address
&& !have_address
)
15998 expansion_failed (loc
, NULL_RTX
,
15999 "Want address and only have value");
16003 /* If we've got an address and don't want one, dereference. */
16004 if (!want_address
&& have_address
)
16006 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
16007 enum dwarf_location_atom op
;
16009 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
16011 expansion_failed (loc
, NULL_RTX
,
16012 "DWARF address size mismatch");
16015 else if (size
== DWARF2_ADDR_SIZE
)
16018 op
= DW_OP_deref_size
;
16020 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
16026 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
16027 if it is not possible. */
16029 static dw_loc_descr_ref
16030 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
16032 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
16033 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
16034 else if (dwarf_version
>= 3 || !dwarf_strict
)
16035 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
16040 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
16041 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
16043 static dw_loc_descr_ref
16044 dw_sra_loc_expr (tree decl
, rtx loc
)
16047 unsigned HOST_WIDE_INT padsize
= 0;
16048 dw_loc_descr_ref descr
, *descr_tail
;
16049 unsigned HOST_WIDE_INT decl_size
;
16051 enum var_init_status initialized
;
16053 if (DECL_SIZE (decl
) == NULL
16054 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
16057 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
16059 descr_tail
= &descr
;
16061 for (p
= loc
; p
; p
= XEXP (p
, 1))
16063 unsigned HOST_WIDE_INT bitsize
= decl_piece_bitsize (p
);
16064 rtx loc_note
= *decl_piece_varloc_ptr (p
);
16065 dw_loc_descr_ref cur_descr
;
16066 dw_loc_descr_ref
*tail
, last
= NULL
;
16067 unsigned HOST_WIDE_INT opsize
= 0;
16069 if (loc_note
== NULL_RTX
16070 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
16072 padsize
+= bitsize
;
16075 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
16076 varloc
= NOTE_VAR_LOCATION (loc_note
);
16077 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
16078 if (cur_descr
== NULL
)
16080 padsize
+= bitsize
;
16084 /* Check that cur_descr either doesn't use
16085 DW_OP_*piece operations, or their sum is equal
16086 to bitsize. Otherwise we can't embed it. */
16087 for (tail
= &cur_descr
; *tail
!= NULL
;
16088 tail
= &(*tail
)->dw_loc_next
)
16089 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
16091 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
16095 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
16097 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
16101 if (last
!= NULL
&& opsize
!= bitsize
)
16103 padsize
+= bitsize
;
16104 /* Discard the current piece of the descriptor and release any
16105 addr_table entries it uses. */
16106 remove_loc_list_addr_table_entries (cur_descr
);
16110 /* If there is a hole, add DW_OP_*piece after empty DWARF
16111 expression, which means that those bits are optimized out. */
16114 if (padsize
> decl_size
)
16116 remove_loc_list_addr_table_entries (cur_descr
);
16117 goto discard_descr
;
16119 decl_size
-= padsize
;
16120 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
16121 if (*descr_tail
== NULL
)
16123 remove_loc_list_addr_table_entries (cur_descr
);
16124 goto discard_descr
;
16126 descr_tail
= &(*descr_tail
)->dw_loc_next
;
16129 *descr_tail
= cur_descr
;
16131 if (bitsize
> decl_size
)
16132 goto discard_descr
;
16133 decl_size
-= bitsize
;
16136 HOST_WIDE_INT offset
= 0;
16137 if (GET_CODE (varloc
) == VAR_LOCATION
16138 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
16140 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
16141 if (GET_CODE (varloc
) == EXPR_LIST
)
16142 varloc
= XEXP (varloc
, 0);
16146 if (GET_CODE (varloc
) == CONST
16147 || GET_CODE (varloc
) == SIGN_EXTEND
16148 || GET_CODE (varloc
) == ZERO_EXTEND
)
16149 varloc
= XEXP (varloc
, 0);
16150 else if (GET_CODE (varloc
) == SUBREG
)
16151 varloc
= SUBREG_REG (varloc
);
16156 /* DW_OP_bit_size offset should be zero for register
16157 or implicit location descriptions and empty location
16158 descriptions, but for memory addresses needs big endian
16160 if (MEM_P (varloc
))
16162 unsigned HOST_WIDE_INT memsize
16163 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
16164 if (memsize
!= bitsize
)
16166 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
16167 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
16168 goto discard_descr
;
16169 if (memsize
< bitsize
)
16170 goto discard_descr
;
16171 if (BITS_BIG_ENDIAN
)
16172 offset
= memsize
- bitsize
;
16176 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
16177 if (*descr_tail
== NULL
)
16178 goto discard_descr
;
16179 descr_tail
= &(*descr_tail
)->dw_loc_next
;
16183 /* If there were any non-empty expressions, add padding till the end of
16185 if (descr
!= NULL
&& decl_size
!= 0)
16187 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
16188 if (*descr_tail
== NULL
)
16189 goto discard_descr
;
16194 /* Discard the descriptor and release any addr_table entries it uses. */
16195 remove_loc_list_addr_table_entries (descr
);
16199 /* Return the dwarf representation of the location list LOC_LIST of
16200 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
16203 static dw_loc_list_ref
16204 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
16206 const char *endname
, *secname
;
16208 enum var_init_status initialized
;
16209 struct var_loc_node
*node
;
16210 dw_loc_descr_ref descr
;
16211 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
16212 dw_loc_list_ref list
= NULL
;
16213 dw_loc_list_ref
*listp
= &list
;
16215 /* Now that we know what section we are using for a base,
16216 actually construct the list of locations.
16217 The first location information is what is passed to the
16218 function that creates the location list, and the remaining
16219 locations just get added on to that list.
16220 Note that we only know the start address for a location
16221 (IE location changes), so to build the range, we use
16222 the range [current location start, next location start].
16223 This means we have to special case the last node, and generate
16224 a range of [last location start, end of function label]. */
16226 secname
= secname_for_decl (decl
);
16228 for (node
= loc_list
->first
; node
; node
= node
->next
)
16229 if (GET_CODE (node
->loc
) == EXPR_LIST
16230 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
16232 if (GET_CODE (node
->loc
) == EXPR_LIST
)
16234 /* This requires DW_OP_{,bit_}piece, which is not usable
16235 inside DWARF expressions. */
16236 if (want_address
!= 2)
16238 descr
= dw_sra_loc_expr (decl
, node
->loc
);
16244 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
16245 varloc
= NOTE_VAR_LOCATION (node
->loc
);
16246 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
16250 bool range_across_switch
= false;
16251 /* If section switch happens in between node->label
16252 and node->next->label (or end of function) and
16253 we can't emit it as a single entry list,
16254 emit two ranges, first one ending at the end
16255 of first partition and second one starting at the
16256 beginning of second partition. */
16257 if (node
== loc_list
->last_before_switch
16258 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
16259 && current_function_decl
)
16261 endname
= cfun
->fde
->dw_fde_end
;
16262 range_across_switch
= true;
16264 /* The variable has a location between NODE->LABEL and
16265 NODE->NEXT->LABEL. */
16266 else if (node
->next
)
16267 endname
= node
->next
->label
;
16268 /* If the variable has a location at the last label
16269 it keeps its location until the end of function. */
16270 else if (!current_function_decl
)
16271 endname
= text_end_label
;
16274 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
16275 current_function_funcdef_no
);
16276 endname
= ggc_strdup (label_id
);
16279 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
16280 if (TREE_CODE (decl
) == PARM_DECL
16281 && node
== loc_list
->first
16282 && NOTE_P (node
->loc
)
16283 && strcmp (node
->label
, endname
) == 0)
16284 (*listp
)->force
= true;
16285 listp
= &(*listp
)->dw_loc_next
;
16287 if (range_across_switch
)
16289 if (GET_CODE (node
->loc
) == EXPR_LIST
)
16290 descr
= dw_sra_loc_expr (decl
, node
->loc
);
16293 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
16294 varloc
= NOTE_VAR_LOCATION (node
->loc
);
16295 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
16298 gcc_assert (descr
);
16299 /* The variable has a location between NODE->LABEL and
16300 NODE->NEXT->LABEL. */
16302 endname
= node
->next
->label
;
16304 endname
= cfun
->fde
->dw_fde_second_end
;
16305 *listp
= new_loc_list (descr
,
16306 cfun
->fde
->dw_fde_second_begin
,
16308 listp
= &(*listp
)->dw_loc_next
;
16313 /* Try to avoid the overhead of a location list emitting a location
16314 expression instead, but only if we didn't have more than one
16315 location entry in the first place. If some entries were not
16316 representable, we don't want to pretend a single entry that was
16317 applies to the entire scope in which the variable is
16319 if (list
&& loc_list
->first
->next
)
16325 /* Return if the loc_list has only single element and thus can be represented
16326 as location description. */
16329 single_element_loc_list_p (dw_loc_list_ref list
)
16331 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
16332 return !list
->ll_symbol
;
16335 /* Duplicate a single element of location list. */
16337 static inline dw_loc_descr_ref
16338 copy_loc_descr (dw_loc_descr_ref ref
)
16340 dw_loc_descr_ref copy
= ggc_alloc
<dw_loc_descr_node
> ();
16341 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
16345 /* To each location in list LIST append loc descr REF. */
16348 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
16350 dw_loc_descr_ref copy
;
16351 add_loc_descr (&list
->expr
, ref
);
16352 list
= list
->dw_loc_next
;
16355 copy
= copy_loc_descr (ref
);
16356 add_loc_descr (&list
->expr
, copy
);
16357 while (copy
->dw_loc_next
)
16358 copy
= copy
->dw_loc_next
= copy_loc_descr (copy
->dw_loc_next
);
16359 list
= list
->dw_loc_next
;
16363 /* To each location in list LIST prepend loc descr REF. */
16366 prepend_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
16368 dw_loc_descr_ref copy
;
16369 dw_loc_descr_ref ref_end
= list
->expr
;
16370 add_loc_descr (&ref
, list
->expr
);
16372 list
= list
->dw_loc_next
;
16375 dw_loc_descr_ref end
= list
->expr
;
16376 list
->expr
= copy
= copy_loc_descr (ref
);
16377 while (copy
->dw_loc_next
!= ref_end
)
16378 copy
= copy
->dw_loc_next
= copy_loc_descr (copy
->dw_loc_next
);
16379 copy
->dw_loc_next
= end
;
16380 list
= list
->dw_loc_next
;
16384 /* Given two lists RET and LIST
16385 produce location list that is result of adding expression in LIST
16386 to expression in RET on each position in program.
16387 Might be destructive on both RET and LIST.
16389 TODO: We handle only simple cases of RET or LIST having at most one
16390 element. General case would involve sorting the lists in program order
16391 and merging them that will need some additional work.
16392 Adding that will improve quality of debug info especially for SRA-ed
16396 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
16405 if (!list
->dw_loc_next
)
16407 add_loc_descr_to_each (*ret
, list
->expr
);
16410 if (!(*ret
)->dw_loc_next
)
16412 prepend_loc_descr_to_each (list
, (*ret
)->expr
);
16416 expansion_failed (NULL_TREE
, NULL_RTX
,
16417 "Don't know how to merge two non-trivial"
16418 " location lists.\n");
16423 /* LOC is constant expression. Try a luck, look it up in constant
16424 pool and return its loc_descr of its address. */
16426 static dw_loc_descr_ref
16427 cst_pool_loc_descr (tree loc
)
16429 /* Get an RTL for this, if something has been emitted. */
16430 rtx rtl
= lookup_constant_def (loc
);
16432 if (!rtl
|| !MEM_P (rtl
))
16437 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
16439 /* TODO: We might get more coverage if we was actually delaying expansion
16440 of all expressions till end of compilation when constant pools are fully
16442 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
16444 expansion_failed (loc
, NULL_RTX
,
16445 "CST value in contant pool but not marked.");
16448 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
16449 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
16452 /* Return dw_loc_list representing address of addr_expr LOC
16453 by looking for inner INDIRECT_REF expression and turning
16454 it into simple arithmetics.
16456 See loc_list_from_tree for the meaning of CONTEXT. */
16458 static dw_loc_list_ref
16459 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
,
16460 loc_descr_context
*context
)
16463 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
16465 int unsignedp
, reversep
, volatilep
= 0;
16466 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
16468 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
16469 &bitsize
, &bitpos
, &offset
, &mode
,
16470 &unsignedp
, &reversep
, &volatilep
);
16472 if (bitpos
% BITS_PER_UNIT
)
16474 expansion_failed (loc
, NULL_RTX
, "bitfield access");
16477 if (!INDIRECT_REF_P (obj
))
16479 expansion_failed (obj
,
16480 NULL_RTX
, "no indirect ref in inner refrence");
16483 if (!offset
&& !bitpos
)
16484 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1,
16487 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
16488 && (dwarf_version
>= 4 || !dwarf_strict
))
16490 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0, context
);
16495 /* Variable offset. */
16496 list_ret1
= loc_list_from_tree (offset
, 0, context
);
16497 if (list_ret1
== 0)
16499 add_loc_list (&list_ret
, list_ret1
);
16502 add_loc_descr_to_each (list_ret
,
16503 new_loc_descr (DW_OP_plus
, 0, 0));
16505 bytepos
= bitpos
/ BITS_PER_UNIT
;
16507 add_loc_descr_to_each (list_ret
,
16508 new_loc_descr (DW_OP_plus_uconst
,
16510 else if (bytepos
< 0)
16511 loc_list_plus_const (list_ret
, bytepos
);
16512 add_loc_descr_to_each (list_ret
,
16513 new_loc_descr (DW_OP_stack_value
, 0, 0));
16518 /* Set LOC to the next operation that is not a DW_OP_nop operation. In the case
16519 all operations from LOC are nops, move to the last one. Insert in NOPS all
16520 operations that are skipped. */
16523 loc_descr_to_next_no_nop (dw_loc_descr_ref
&loc
,
16524 hash_set
<dw_loc_descr_ref
> &nops
)
16526 while (loc
->dw_loc_next
!= NULL
&& loc
->dw_loc_opc
== DW_OP_nop
)
16529 loc
= loc
->dw_loc_next
;
16533 /* Helper for loc_descr_without_nops: free the location description operation
16537 free_loc_descr (const dw_loc_descr_ref
&loc
, void *data ATTRIBUTE_UNUSED
)
16543 /* Remove all DW_OP_nop operations from LOC except, if it exists, the one that
16547 loc_descr_without_nops (dw_loc_descr_ref
&loc
)
16549 if (loc
->dw_loc_opc
== DW_OP_nop
&& loc
->dw_loc_next
== NULL
)
16552 /* Set of all DW_OP_nop operations we remove. */
16553 hash_set
<dw_loc_descr_ref
> nops
;
16555 /* First, strip all prefix NOP operations in order to keep the head of the
16556 operations list. */
16557 loc_descr_to_next_no_nop (loc
, nops
);
16559 for (dw_loc_descr_ref cur
= loc
; cur
!= NULL
;)
16561 /* For control flow operations: strip "prefix" nops in destination
16563 if (cur
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
)
16564 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd1
.v
.val_loc
, nops
);
16565 if (cur
->dw_loc_oprnd2
.val_class
== dw_val_class_loc
)
16566 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd2
.v
.val_loc
, nops
);
16568 /* Do the same for the operations that follow, then move to the next
16570 if (cur
->dw_loc_next
!= NULL
)
16571 loc_descr_to_next_no_nop (cur
->dw_loc_next
, nops
);
16572 cur
= cur
->dw_loc_next
;
16575 nops
.traverse
<void *, free_loc_descr
> (NULL
);
16579 struct dwarf_procedure_info
;
16581 /* Helper structure for location descriptions generation. */
16582 struct loc_descr_context
16584 /* The type that is implicitly referenced by DW_OP_push_object_address, or
16585 NULL_TREE if DW_OP_push_object_address in invalid for this location
16586 description. This is used when processing PLACEHOLDER_EXPR nodes. */
16588 /* The ..._DECL node that should be translated as a
16589 DW_OP_push_object_address operation. */
16591 /* Information about the DWARF procedure we are currently generating. NULL if
16592 we are not generating a DWARF procedure. */
16593 struct dwarf_procedure_info
*dpi
;
16594 /* True if integral PLACEHOLDER_EXPR stands for the first argument passed
16595 by consumer. Used for DW_TAG_generic_subrange attributes. */
16596 bool placeholder_arg
;
16597 /* True if PLACEHOLDER_EXPR has been seen. */
16598 bool placeholder_seen
;
16601 /* DWARF procedures generation
16603 DWARF expressions (aka. location descriptions) are used to encode variable
16604 things such as sizes or offsets. Such computations can have redundant parts
16605 that can be factorized in order to reduce the size of the output debug
16606 information. This is the whole point of DWARF procedures.
16608 Thanks to stor-layout.c, size and offset expressions in GENERIC trees are
16609 already factorized into functions ("size functions") in order to handle very
16610 big and complex types. Such functions are quite simple: they have integral
16611 arguments, they return an integral result and their body contains only a
16612 return statement with arithmetic expressions. This is the only kind of
16613 function we are interested in translating into DWARF procedures, here.
16615 DWARF expressions and DWARF procedure are executed using a stack, so we have
16616 to define some calling convention for them to interact. Let's say that:
16618 - Before calling a DWARF procedure, DWARF expressions must push on the stack
16619 all arguments in reverse order (right-to-left) so that when the DWARF
16620 procedure execution starts, the first argument is the top of the stack.
16622 - Then, when returning, the DWARF procedure must have consumed all arguments
16623 on the stack, must have pushed the result and touched nothing else.
16625 - Each integral argument and the result are integral types can be hold in a
16628 - We call "frame offset" the number of stack slots that are "under DWARF
16629 procedure control": it includes the arguments slots, the temporaries and
16630 the result slot. Thus, it is equal to the number of arguments when the
16631 procedure execution starts and must be equal to one (the result) when it
16634 /* Helper structure used when generating operations for a DWARF procedure. */
16635 struct dwarf_procedure_info
16637 /* The FUNCTION_DECL node corresponding to the DWARF procedure that is
16638 currently translated. */
16640 /* The number of arguments FNDECL takes. */
16641 unsigned args_count
;
16644 /* Return a pointer to a newly created DIE node for a DWARF procedure. Add
16645 LOCATION as its DW_AT_location attribute. If FNDECL is not NULL_TREE,
16646 equate it to this DIE. */
16649 new_dwarf_proc_die (dw_loc_descr_ref location
, tree fndecl
,
16650 dw_die_ref parent_die
)
16652 dw_die_ref dwarf_proc_die
;
16654 if ((dwarf_version
< 3 && dwarf_strict
)
16655 || location
== NULL
)
16658 dwarf_proc_die
= new_die (DW_TAG_dwarf_procedure
, parent_die
, fndecl
);
16660 equate_decl_number_to_die (fndecl
, dwarf_proc_die
);
16661 add_AT_loc (dwarf_proc_die
, DW_AT_location
, location
);
16662 return dwarf_proc_die
;
16665 /* Return whether TYPE is a supported type as a DWARF procedure argument
16666 type or return type (we handle only scalar types and pointer types that
16667 aren't wider than the DWARF expression evaluation stack. */
16670 is_handled_procedure_type (tree type
)
16672 return ((INTEGRAL_TYPE_P (type
)
16673 || TREE_CODE (type
) == OFFSET_TYPE
16674 || TREE_CODE (type
) == POINTER_TYPE
)
16675 && int_size_in_bytes (type
) <= DWARF2_ADDR_SIZE
);
16678 /* Helper for resolve_args_picking: do the same but stop when coming across
16679 visited nodes. For each node we visit, register in FRAME_OFFSETS the frame
16680 offset *before* evaluating the corresponding operation. */
16683 resolve_args_picking_1 (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
16684 struct dwarf_procedure_info
*dpi
,
16685 hash_map
<dw_loc_descr_ref
, unsigned> &frame_offsets
)
16687 /* The "frame_offset" identifier is already used to name a macro... */
16688 unsigned frame_offset_
= initial_frame_offset
;
16689 dw_loc_descr_ref l
;
16691 for (l
= loc
; l
!= NULL
;)
16694 unsigned &l_frame_offset
= frame_offsets
.get_or_insert (l
, &existed
);
16696 /* If we already met this node, there is nothing to compute anymore. */
16699 /* Make sure that the stack size is consistent wherever the execution
16700 flow comes from. */
16701 gcc_assert ((unsigned) l_frame_offset
== frame_offset_
);
16704 l_frame_offset
= frame_offset_
;
16706 /* If needed, relocate the picking offset with respect to the frame
16708 if (l
->frame_offset_rel
)
16710 unsigned HOST_WIDE_INT off
;
16711 switch (l
->dw_loc_opc
)
16714 off
= l
->dw_loc_oprnd1
.v
.val_unsigned
;
16723 gcc_unreachable ();
16725 /* frame_offset_ is the size of the current stack frame, including
16726 incoming arguments. Besides, the arguments are pushed
16727 right-to-left. Thus, in order to access the Nth argument from
16728 this operation node, the picking has to skip temporaries *plus*
16729 one stack slot per argument (0 for the first one, 1 for the second
16732 The targetted argument number (N) is already set as the operand,
16733 and the number of temporaries can be computed with:
16734 frame_offsets_ - dpi->args_count */
16735 off
+= frame_offset_
- dpi
->args_count
;
16737 /* DW_OP_pick handles only offsets from 0 to 255 (inclusive)... */
16743 l
->dw_loc_opc
= DW_OP_dup
;
16744 l
->dw_loc_oprnd1
.v
.val_unsigned
= 0;
16748 l
->dw_loc_opc
= DW_OP_over
;
16749 l
->dw_loc_oprnd1
.v
.val_unsigned
= 0;
16753 l
->dw_loc_opc
= DW_OP_pick
;
16754 l
->dw_loc_oprnd1
.v
.val_unsigned
= off
;
16758 /* Update frame_offset according to the effect the current operation has
16760 switch (l
->dw_loc_opc
)
16768 case DW_OP_plus_uconst
:
16804 case DW_OP_deref_size
:
16806 case DW_OP_bit_piece
:
16807 case DW_OP_implicit_value
:
16808 case DW_OP_stack_value
:
16812 case DW_OP_const1u
:
16813 case DW_OP_const1s
:
16814 case DW_OP_const2u
:
16815 case DW_OP_const2s
:
16816 case DW_OP_const4u
:
16817 case DW_OP_const4s
:
16818 case DW_OP_const8u
:
16819 case DW_OP_const8s
:
16890 case DW_OP_push_object_address
:
16891 case DW_OP_call_frame_cfa
:
16892 case DW_OP_GNU_variable_value
:
16917 case DW_OP_xderef_size
:
16923 case DW_OP_call_ref
:
16925 dw_die_ref dwarf_proc
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
16926 int *stack_usage
= dwarf_proc_stack_usage_map
->get (dwarf_proc
);
16928 if (stack_usage
== NULL
)
16930 frame_offset_
+= *stack_usage
;
16934 case DW_OP_implicit_pointer
:
16935 case DW_OP_entry_value
:
16936 case DW_OP_const_type
:
16937 case DW_OP_regval_type
:
16938 case DW_OP_deref_type
:
16939 case DW_OP_convert
:
16940 case DW_OP_reinterpret
:
16941 case DW_OP_form_tls_address
:
16942 case DW_OP_GNU_push_tls_address
:
16943 case DW_OP_GNU_uninit
:
16944 case DW_OP_GNU_encoded_addr
:
16945 case DW_OP_GNU_implicit_pointer
:
16946 case DW_OP_GNU_entry_value
:
16947 case DW_OP_GNU_const_type
:
16948 case DW_OP_GNU_regval_type
:
16949 case DW_OP_GNU_deref_type
:
16950 case DW_OP_GNU_convert
:
16951 case DW_OP_GNU_reinterpret
:
16952 case DW_OP_GNU_parameter_ref
:
16953 /* loc_list_from_tree will probably not output these operations for
16954 size functions, so assume they will not appear here. */
16955 /* Fall through... */
16958 gcc_unreachable ();
16961 /* Now, follow the control flow (except subroutine calls). */
16962 switch (l
->dw_loc_opc
)
16965 if (!resolve_args_picking_1 (l
->dw_loc_next
, frame_offset_
, dpi
,
16968 /* Fall through. */
16971 l
= l
->dw_loc_oprnd1
.v
.val_loc
;
16974 case DW_OP_stack_value
:
16978 l
= l
->dw_loc_next
;
16986 /* Make a DFS over operations reachable through LOC (i.e. follow branch
16987 operations) in order to resolve the operand of DW_OP_pick operations that
16988 target DWARF procedure arguments (DPI). INITIAL_FRAME_OFFSET is the frame
16989 offset *before* LOC is executed. Return if all relocations were
16993 resolve_args_picking (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
16994 struct dwarf_procedure_info
*dpi
)
16996 /* Associate to all visited operations the frame offset *before* evaluating
16998 hash_map
<dw_loc_descr_ref
, unsigned> frame_offsets
;
17000 return resolve_args_picking_1 (loc
, initial_frame_offset
, dpi
,
17004 /* Try to generate a DWARF procedure that computes the same result as FNDECL.
17005 Return NULL if it is not possible. */
17008 function_to_dwarf_procedure (tree fndecl
)
17010 struct loc_descr_context ctx
;
17011 struct dwarf_procedure_info dpi
;
17012 dw_die_ref dwarf_proc_die
;
17013 tree tree_body
= DECL_SAVED_TREE (fndecl
);
17014 dw_loc_descr_ref loc_body
, epilogue
;
17019 /* Do not generate multiple DWARF procedures for the same function
17021 dwarf_proc_die
= lookup_decl_die (fndecl
);
17022 if (dwarf_proc_die
!= NULL
)
17023 return dwarf_proc_die
;
17025 /* DWARF procedures are available starting with the DWARFv3 standard. */
17026 if (dwarf_version
< 3 && dwarf_strict
)
17029 /* We handle only functions for which we still have a body, that return a
17030 supported type and that takes arguments with supported types. Note that
17031 there is no point translating functions that return nothing. */
17032 if (tree_body
== NULL_TREE
17033 || DECL_RESULT (fndecl
) == NULL_TREE
17034 || !is_handled_procedure_type (TREE_TYPE (DECL_RESULT (fndecl
))))
17037 for (cursor
= DECL_ARGUMENTS (fndecl
);
17038 cursor
!= NULL_TREE
;
17039 cursor
= TREE_CHAIN (cursor
))
17040 if (!is_handled_procedure_type (TREE_TYPE (cursor
)))
17043 /* Match only "expr" in: RETURN_EXPR (MODIFY_EXPR (RESULT_DECL, expr)). */
17044 if (TREE_CODE (tree_body
) != RETURN_EXPR
)
17046 tree_body
= TREE_OPERAND (tree_body
, 0);
17047 if (TREE_CODE (tree_body
) != MODIFY_EXPR
17048 || TREE_OPERAND (tree_body
, 0) != DECL_RESULT (fndecl
))
17050 tree_body
= TREE_OPERAND (tree_body
, 1);
17052 /* Try to translate the body expression itself. Note that this will probably
17053 cause an infinite recursion if its call graph has a cycle. This is very
17054 unlikely for size functions, however, so don't bother with such things at
17056 ctx
.context_type
= NULL_TREE
;
17057 ctx
.base_decl
= NULL_TREE
;
17059 ctx
.placeholder_arg
= false;
17060 ctx
.placeholder_seen
= false;
17061 dpi
.fndecl
= fndecl
;
17062 dpi
.args_count
= list_length (DECL_ARGUMENTS (fndecl
));
17063 loc_body
= loc_descriptor_from_tree (tree_body
, 0, &ctx
);
17067 /* After evaluating all operands in "loc_body", we should still have on the
17068 stack all arguments plus the desired function result (top of the stack).
17069 Generate code in order to keep only the result in our stack frame. */
17071 for (i
= 0; i
< dpi
.args_count
; ++i
)
17073 dw_loc_descr_ref op_couple
= new_loc_descr (DW_OP_swap
, 0, 0);
17074 op_couple
->dw_loc_next
= new_loc_descr (DW_OP_drop
, 0, 0);
17075 op_couple
->dw_loc_next
->dw_loc_next
= epilogue
;
17076 epilogue
= op_couple
;
17078 add_loc_descr (&loc_body
, epilogue
);
17079 if (!resolve_args_picking (loc_body
, dpi
.args_count
, &dpi
))
17082 /* Trailing nops from loc_descriptor_from_tree (if any) cannot be removed
17083 because they are considered useful. Now there is an epilogue, they are
17084 not anymore, so give it another try. */
17085 loc_descr_without_nops (loc_body
);
17087 /* fndecl may be used both as a regular DW_TAG_subprogram DIE and as
17088 a DW_TAG_dwarf_procedure, so we may have a conflict, here. It's unlikely,
17089 though, given that size functions do not come from source, so they should
17090 not have a dedicated DW_TAG_subprogram DIE. */
17092 = new_dwarf_proc_die (loc_body
, fndecl
,
17093 get_context_die (DECL_CONTEXT (fndecl
)));
17095 /* The called DWARF procedure consumes one stack slot per argument and
17096 returns one stack slot. */
17097 dwarf_proc_stack_usage_map
->put (dwarf_proc_die
, 1 - dpi
.args_count
);
17099 return dwarf_proc_die
;
17103 /* Generate Dwarf location list representing LOC.
17104 If WANT_ADDRESS is false, expression computing LOC will be computed
17105 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
17106 if WANT_ADDRESS is 2, expression computing address useable in location
17107 will be returned (i.e. DW_OP_reg can be used
17108 to refer to register values).
17110 CONTEXT provides information to customize the location descriptions
17111 generation. Its context_type field specifies what type is implicitly
17112 referenced by DW_OP_push_object_address. If it is NULL_TREE, this operation
17113 will not be generated.
17115 Its DPI field determines whether we are generating a DWARF expression for a
17116 DWARF procedure, so PARM_DECL references are processed specifically.
17118 If CONTEXT is NULL, the behavior is the same as if context_type, base_decl
17119 and dpi fields were null. */
17121 static dw_loc_list_ref
17122 loc_list_from_tree_1 (tree loc
, int want_address
,
17123 struct loc_descr_context
*context
)
17125 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
17126 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
17127 int have_address
= 0;
17128 enum dwarf_location_atom op
;
17130 /* ??? Most of the time we do not take proper care for sign/zero
17131 extending the values properly. Hopefully this won't be a real
17134 if (context
!= NULL
17135 && context
->base_decl
== loc
17136 && want_address
== 0)
17138 if (dwarf_version
>= 3 || !dwarf_strict
)
17139 return new_loc_list (new_loc_descr (DW_OP_push_object_address
, 0, 0),
17145 switch (TREE_CODE (loc
))
17148 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
17151 case PLACEHOLDER_EXPR
:
17152 /* This case involves extracting fields from an object to determine the
17153 position of other fields. It is supposed to appear only as the first
17154 operand of COMPONENT_REF nodes and to reference precisely the type
17155 that the context allows. */
17156 if (context
!= NULL
17157 && TREE_TYPE (loc
) == context
->context_type
17158 && want_address
>= 1)
17160 if (dwarf_version
>= 3 || !dwarf_strict
)
17162 ret
= new_loc_descr (DW_OP_push_object_address
, 0, 0);
17169 /* For DW_TAG_generic_subrange attributes, PLACEHOLDER_EXPR stands for
17170 the single argument passed by consumer. */
17171 else if (context
!= NULL
17172 && context
->placeholder_arg
17173 && INTEGRAL_TYPE_P (TREE_TYPE (loc
))
17174 && want_address
== 0)
17176 ret
= new_loc_descr (DW_OP_pick
, 0, 0);
17177 ret
->frame_offset_rel
= 1;
17178 context
->placeholder_seen
= true;
17182 expansion_failed (loc
, NULL_RTX
,
17183 "PLACEHOLDER_EXPR for an unexpected type");
17188 const int nargs
= call_expr_nargs (loc
);
17189 tree callee
= get_callee_fndecl (loc
);
17191 dw_die_ref dwarf_proc
;
17193 if (callee
== NULL_TREE
)
17194 goto call_expansion_failed
;
17196 /* We handle only functions that return an integer. */
17197 if (!is_handled_procedure_type (TREE_TYPE (TREE_TYPE (callee
))))
17198 goto call_expansion_failed
;
17200 dwarf_proc
= function_to_dwarf_procedure (callee
);
17201 if (dwarf_proc
== NULL
)
17202 goto call_expansion_failed
;
17204 /* Evaluate arguments right-to-left so that the first argument will
17205 be the top-most one on the stack. */
17206 for (i
= nargs
- 1; i
>= 0; --i
)
17208 dw_loc_descr_ref loc_descr
17209 = loc_descriptor_from_tree (CALL_EXPR_ARG (loc
, i
), 0,
17212 if (loc_descr
== NULL
)
17213 goto call_expansion_failed
;
17215 add_loc_descr (&ret
, loc_descr
);
17218 ret1
= new_loc_descr (DW_OP_call4
, 0, 0);
17219 ret1
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
17220 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.die
= dwarf_proc
;
17221 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
17222 add_loc_descr (&ret
, ret1
);
17225 call_expansion_failed
:
17226 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
17227 /* There are no opcodes for these operations. */
17231 case PREINCREMENT_EXPR
:
17232 case PREDECREMENT_EXPR
:
17233 case POSTINCREMENT_EXPR
:
17234 case POSTDECREMENT_EXPR
:
17235 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
17236 /* There are no opcodes for these operations. */
17240 /* If we already want an address, see if there is INDIRECT_REF inside
17241 e.g. for &this->field. */
17244 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
17245 (loc
, want_address
== 2, context
);
17248 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
17249 && (ret
= cst_pool_loc_descr (loc
)))
17252 /* Otherwise, process the argument and look for the address. */
17253 if (!list_ret
&& !ret
)
17254 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 1, context
);
17258 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
17264 if (DECL_THREAD_LOCAL_P (loc
))
17267 enum dwarf_location_atom tls_op
;
17268 enum dtprel_bool dtprel
= dtprel_false
;
17270 if (targetm
.have_tls
)
17272 /* If this is not defined, we have no way to emit the
17274 if (!targetm
.asm_out
.output_dwarf_dtprel
)
17277 /* The way DW_OP_GNU_push_tls_address is specified, we
17278 can only look up addresses of objects in the current
17279 module. We used DW_OP_addr as first op, but that's
17280 wrong, because DW_OP_addr is relocated by the debug
17281 info consumer, while DW_OP_GNU_push_tls_address
17282 operand shouldn't be. */
17283 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
17285 dtprel
= dtprel_true
;
17286 /* We check for DWARF 5 here because gdb did not implement
17287 DW_OP_form_tls_address until after 7.12. */
17288 tls_op
= (dwarf_version
>= 5 ? DW_OP_form_tls_address
17289 : DW_OP_GNU_push_tls_address
);
17293 if (!targetm
.emutls
.debug_form_tls_address
17294 || !(dwarf_version
>= 3 || !dwarf_strict
))
17296 /* We stuffed the control variable into the DECL_VALUE_EXPR
17297 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
17298 no longer appear in gimple code. We used the control
17299 variable in specific so that we could pick it up here. */
17300 loc
= DECL_VALUE_EXPR (loc
);
17301 tls_op
= DW_OP_form_tls_address
;
17304 rtl
= rtl_for_decl_location (loc
);
17305 if (rtl
== NULL_RTX
)
17310 rtl
= XEXP (rtl
, 0);
17311 if (! CONSTANT_P (rtl
))
17314 ret
= new_addr_loc_descr (rtl
, dtprel
);
17315 ret1
= new_loc_descr (tls_op
, 0, 0);
17316 add_loc_descr (&ret
, ret1
);
17324 if (context
!= NULL
&& context
->dpi
!= NULL
17325 && DECL_CONTEXT (loc
) == context
->dpi
->fndecl
)
17327 /* We are generating code for a DWARF procedure and we want to access
17328 one of its arguments: find the appropriate argument offset and let
17329 the resolve_args_picking pass compute the offset that complies
17330 with the stack frame size. */
17334 for (cursor
= DECL_ARGUMENTS (context
->dpi
->fndecl
);
17335 cursor
!= NULL_TREE
&& cursor
!= loc
;
17336 cursor
= TREE_CHAIN (cursor
), ++i
)
17338 /* If we are translating a DWARF procedure, all referenced parameters
17339 must belong to the current function. */
17340 gcc_assert (cursor
!= NULL_TREE
);
17342 ret
= new_loc_descr (DW_OP_pick
, i
, 0);
17343 ret
->frame_offset_rel
= 1;
17349 if (DECL_HAS_VALUE_EXPR_P (loc
))
17350 return loc_list_from_tree_1 (DECL_VALUE_EXPR (loc
),
17351 want_address
, context
);
17354 case FUNCTION_DECL
:
17357 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
17359 if (loc_list
&& loc_list
->first
)
17361 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
17362 have_address
= want_address
!= 0;
17365 rtl
= rtl_for_decl_location (loc
);
17366 if (rtl
== NULL_RTX
)
17368 if (TREE_CODE (loc
) != FUNCTION_DECL
17370 && current_function_decl
17371 && want_address
!= 1
17372 && ! DECL_IGNORED_P (loc
)
17373 && (INTEGRAL_TYPE_P (TREE_TYPE (loc
))
17374 || POINTER_TYPE_P (TREE_TYPE (loc
)))
17375 && DECL_CONTEXT (loc
) == current_function_decl
17376 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc
)))
17377 <= DWARF2_ADDR_SIZE
))
17379 dw_die_ref ref
= lookup_decl_die (loc
);
17380 ret
= new_loc_descr (DW_OP_GNU_variable_value
, 0, 0);
17383 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
17384 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
17385 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
17389 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
17390 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= loc
;
17394 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
17397 else if (CONST_INT_P (rtl
))
17399 HOST_WIDE_INT val
= INTVAL (rtl
);
17400 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
17401 val
&= GET_MODE_MASK (DECL_MODE (loc
));
17402 ret
= int_loc_descriptor (val
);
17404 else if (GET_CODE (rtl
) == CONST_STRING
)
17406 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
17409 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
17410 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
17413 machine_mode mode
, mem_mode
;
17415 /* Certain constructs can only be represented at top-level. */
17416 if (want_address
== 2)
17418 ret
= loc_descriptor (rtl
, VOIDmode
,
17419 VAR_INIT_STATUS_INITIALIZED
);
17424 mode
= GET_MODE (rtl
);
17425 mem_mode
= VOIDmode
;
17429 mode
= get_address_mode (rtl
);
17430 rtl
= XEXP (rtl
, 0);
17433 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
17434 VAR_INIT_STATUS_INITIALIZED
);
17437 expansion_failed (loc
, rtl
,
17438 "failed to produce loc descriptor for rtl");
17444 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
17451 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17455 case TARGET_MEM_REF
:
17457 case DEBUG_EXPR_DECL
:
17460 case COMPOUND_EXPR
:
17461 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), want_address
,
17465 case VIEW_CONVERT_EXPR
:
17468 case NON_LVALUE_EXPR
:
17469 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), want_address
,
17472 case COMPONENT_REF
:
17473 case BIT_FIELD_REF
:
17475 case ARRAY_RANGE_REF
:
17476 case REALPART_EXPR
:
17477 case IMAGPART_EXPR
:
17480 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
17482 int unsignedp
, reversep
, volatilep
= 0;
17484 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
17485 &unsignedp
, &reversep
, &volatilep
);
17487 gcc_assert (obj
!= loc
);
17489 list_ret
= loc_list_from_tree_1 (obj
,
17491 && !bitpos
&& !offset
? 2 : 1,
17493 /* TODO: We can extract value of the small expression via shifting even
17494 for nonzero bitpos. */
17497 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
17499 expansion_failed (loc
, NULL_RTX
,
17500 "bitfield access");
17504 if (offset
!= NULL_TREE
)
17506 /* Variable offset. */
17507 list_ret1
= loc_list_from_tree_1 (offset
, 0, context
);
17508 if (list_ret1
== 0)
17510 add_loc_list (&list_ret
, list_ret1
);
17513 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
17516 bytepos
= bitpos
/ BITS_PER_UNIT
;
17518 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
17519 else if (bytepos
< 0)
17520 loc_list_plus_const (list_ret
, bytepos
);
17527 if ((want_address
|| !tree_fits_shwi_p (loc
))
17528 && (ret
= cst_pool_loc_descr (loc
)))
17530 else if (want_address
== 2
17531 && tree_fits_shwi_p (loc
)
17532 && (ret
= address_of_int_loc_descriptor
17533 (int_size_in_bytes (TREE_TYPE (loc
)),
17534 tree_to_shwi (loc
))))
17536 else if (tree_fits_shwi_p (loc
))
17537 ret
= int_loc_descriptor (tree_to_shwi (loc
));
17538 else if (tree_fits_uhwi_p (loc
))
17539 ret
= uint_loc_descriptor (tree_to_uhwi (loc
));
17542 expansion_failed (loc
, NULL_RTX
,
17543 "Integer operand is not host integer");
17552 if ((ret
= cst_pool_loc_descr (loc
)))
17554 else if (TREE_CODE (loc
) == CONSTRUCTOR
)
17556 tree type
= TREE_TYPE (loc
);
17557 unsigned HOST_WIDE_INT size
= int_size_in_bytes (type
);
17558 unsigned HOST_WIDE_INT offset
= 0;
17559 unsigned HOST_WIDE_INT cnt
;
17560 constructor_elt
*ce
;
17562 if (TREE_CODE (type
) == RECORD_TYPE
)
17564 /* This is very limited, but it's enough to output
17565 pointers to member functions, as long as the
17566 referenced function is defined in the current
17567 translation unit. */
17568 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (loc
), cnt
, ce
)
17570 tree val
= ce
->value
;
17572 tree field
= ce
->index
;
17577 if (!field
|| DECL_BIT_FIELD (field
))
17579 expansion_failed (loc
, NULL_RTX
,
17580 "bitfield in record type constructor");
17581 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
17586 HOST_WIDE_INT fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
17587 unsigned HOST_WIDE_INT pos
= int_byte_position (field
);
17588 gcc_assert (pos
+ fieldsize
<= size
);
17591 expansion_failed (loc
, NULL_RTX
,
17592 "out-of-order fields in record constructor");
17593 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
17599 ret1
= new_loc_descr (DW_OP_piece
, pos
- offset
, 0);
17600 add_loc_descr (&ret
, ret1
);
17603 if (val
&& fieldsize
!= 0)
17605 ret1
= loc_descriptor_from_tree (val
, want_address
, context
);
17608 expansion_failed (loc
, NULL_RTX
,
17609 "unsupported expression in field");
17610 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
17614 add_loc_descr (&ret
, ret1
);
17618 ret1
= new_loc_descr (DW_OP_piece
, fieldsize
, 0);
17619 add_loc_descr (&ret
, ret1
);
17620 offset
= pos
+ fieldsize
;
17624 if (offset
!= size
)
17626 ret1
= new_loc_descr (DW_OP_piece
, size
- offset
, 0);
17627 add_loc_descr (&ret
, ret1
);
17631 have_address
= !!want_address
;
17634 expansion_failed (loc
, NULL_RTX
,
17635 "constructor of non-record type");
17638 /* We can construct small constants here using int_loc_descriptor. */
17639 expansion_failed (loc
, NULL_RTX
,
17640 "constructor or constant not in constant pool");
17643 case TRUTH_AND_EXPR
:
17644 case TRUTH_ANDIF_EXPR
:
17649 case TRUTH_XOR_EXPR
:
17654 case TRUTH_OR_EXPR
:
17655 case TRUTH_ORIF_EXPR
:
17660 case FLOOR_DIV_EXPR
:
17661 case CEIL_DIV_EXPR
:
17662 case ROUND_DIV_EXPR
:
17663 case TRUNC_DIV_EXPR
:
17664 case EXACT_DIV_EXPR
:
17665 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
17674 case FLOOR_MOD_EXPR
:
17675 case CEIL_MOD_EXPR
:
17676 case ROUND_MOD_EXPR
:
17677 case TRUNC_MOD_EXPR
:
17678 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
17683 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17684 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
17685 if (list_ret
== 0 || list_ret1
== 0)
17688 add_loc_list (&list_ret
, list_ret1
);
17691 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
17692 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
17693 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
17694 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
17695 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
17707 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
17710 case POINTER_PLUS_EXPR
:
17713 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
17715 /* Big unsigned numbers can fit in HOST_WIDE_INT but it may be
17716 smarter to encode their opposite. The DW_OP_plus_uconst operation
17717 takes 1 + X bytes, X being the size of the ULEB128 addend. On the
17718 other hand, a "<push literal>; DW_OP_minus" pattern takes 1 + Y
17719 bytes, Y being the size of the operation that pushes the opposite
17720 of the addend. So let's choose the smallest representation. */
17721 const tree tree_addend
= TREE_OPERAND (loc
, 1);
17722 offset_int wi_addend
;
17723 HOST_WIDE_INT shwi_addend
;
17724 dw_loc_descr_ref loc_naddend
;
17726 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17730 /* Try to get the literal to push. It is the opposite of the addend,
17731 so as we rely on wrapping during DWARF evaluation, first decode
17732 the literal as a "DWARF-sized" signed number. */
17733 wi_addend
= wi::to_offset (tree_addend
);
17734 wi_addend
= wi::sext (wi_addend
, DWARF2_ADDR_SIZE
* 8);
17735 shwi_addend
= wi_addend
.to_shwi ();
17736 loc_naddend
= (shwi_addend
!= INTTYPE_MINIMUM (HOST_WIDE_INT
))
17737 ? int_loc_descriptor (-shwi_addend
)
17740 if (loc_naddend
!= NULL
17741 && ((unsigned) size_of_uleb128 (shwi_addend
)
17742 > size_of_loc_descr (loc_naddend
)))
17744 add_loc_descr_to_each (list_ret
, loc_naddend
);
17745 add_loc_descr_to_each (list_ret
,
17746 new_loc_descr (DW_OP_minus
, 0, 0));
17750 for (dw_loc_descr_ref loc_cur
= loc_naddend
; loc_cur
!= NULL
; )
17752 loc_naddend
= loc_cur
;
17753 loc_cur
= loc_cur
->dw_loc_next
;
17754 ggc_free (loc_naddend
);
17756 loc_list_plus_const (list_ret
, wi_addend
.to_shwi ());
17766 goto do_comp_binop
;
17770 goto do_comp_binop
;
17774 goto do_comp_binop
;
17778 goto do_comp_binop
;
17781 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
17783 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
17784 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
17785 list_ret
= loc_list_from_uint_comparison (list_ret
, list_ret1
,
17801 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17802 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
17803 if (list_ret
== 0 || list_ret1
== 0)
17806 add_loc_list (&list_ret
, list_ret1
);
17809 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
17812 case TRUTH_NOT_EXPR
:
17826 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17830 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
17836 const enum tree_code code
=
17837 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
17839 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
17840 build2 (code
, integer_type_node
,
17841 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
17842 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
17849 dw_loc_descr_ref lhs
17850 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
17851 dw_loc_list_ref rhs
17852 = loc_list_from_tree_1 (TREE_OPERAND (loc
, 2), 0, context
);
17853 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
17855 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17856 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
17859 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
17860 add_loc_descr_to_each (list_ret
, bra_node
);
17862 add_loc_list (&list_ret
, rhs
);
17863 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
17864 add_loc_descr_to_each (list_ret
, jump_node
);
17866 add_loc_descr_to_each (list_ret
, lhs
);
17867 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
17868 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
17870 /* ??? Need a node to point the skip at. Use a nop. */
17871 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
17872 add_loc_descr_to_each (list_ret
, tmp
);
17873 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
17874 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
17878 case FIX_TRUNC_EXPR
:
17882 /* Leave front-end specific codes as simply unknown. This comes
17883 up, for instance, with the C STMT_EXPR. */
17884 if ((unsigned int) TREE_CODE (loc
)
17885 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
17887 expansion_failed (loc
, NULL_RTX
,
17888 "language specific tree node");
17892 /* Otherwise this is a generic code; we should just lists all of
17893 these explicitly. We forgot one. */
17895 gcc_unreachable ();
17897 /* In a release build, we want to degrade gracefully: better to
17898 generate incomplete debugging information than to crash. */
17902 if (!ret
&& !list_ret
)
17905 if (want_address
== 2 && !have_address
17906 && (dwarf_version
>= 4 || !dwarf_strict
))
17908 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
17910 expansion_failed (loc
, NULL_RTX
,
17911 "DWARF address size mismatch");
17915 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
17917 add_loc_descr_to_each (list_ret
,
17918 new_loc_descr (DW_OP_stack_value
, 0, 0));
17921 /* Show if we can't fill the request for an address. */
17922 if (want_address
&& !have_address
)
17924 expansion_failed (loc
, NULL_RTX
,
17925 "Want address and only have value");
17929 gcc_assert (!ret
|| !list_ret
);
17931 /* If we've got an address and don't want one, dereference. */
17932 if (!want_address
&& have_address
)
17934 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
17936 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
17938 expansion_failed (loc
, NULL_RTX
,
17939 "DWARF address size mismatch");
17942 else if (size
== DWARF2_ADDR_SIZE
)
17945 op
= DW_OP_deref_size
;
17948 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
17950 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
17953 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
17958 /* Likewise, but strip useless DW_OP_nop operations in the resulting
17961 static dw_loc_list_ref
17962 loc_list_from_tree (tree loc
, int want_address
,
17963 struct loc_descr_context
*context
)
17965 dw_loc_list_ref result
= loc_list_from_tree_1 (loc
, want_address
, context
);
17967 for (dw_loc_list_ref loc_cur
= result
;
17968 loc_cur
!= NULL
; loc_cur
= loc_cur
->dw_loc_next
)
17969 loc_descr_without_nops (loc_cur
->expr
);
17973 /* Same as above but return only single location expression. */
17974 static dw_loc_descr_ref
17975 loc_descriptor_from_tree (tree loc
, int want_address
,
17976 struct loc_descr_context
*context
)
17978 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
, context
);
17981 if (ret
->dw_loc_next
)
17983 expansion_failed (loc
, NULL_RTX
,
17984 "Location list where only loc descriptor needed");
17990 /* Given a value, round it up to the lowest multiple of `boundary'
17991 which is not less than the value itself. */
17993 static inline HOST_WIDE_INT
17994 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
17996 return (((value
+ boundary
- 1) / boundary
) * boundary
);
17999 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
18000 pointer to the declared type for the relevant field variable, or return
18001 `integer_type_node' if the given node turns out to be an
18002 ERROR_MARK node. */
18005 field_type (const_tree decl
)
18009 if (TREE_CODE (decl
) == ERROR_MARK
)
18010 return integer_type_node
;
18012 type
= DECL_BIT_FIELD_TYPE (decl
);
18013 if (type
== NULL_TREE
)
18014 type
= TREE_TYPE (decl
);
18019 /* Given a pointer to a tree node, return the alignment in bits for
18020 it, or else return BITS_PER_WORD if the node actually turns out to
18021 be an ERROR_MARK node. */
18023 static inline unsigned
18024 simple_type_align_in_bits (const_tree type
)
18026 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
18029 static inline unsigned
18030 simple_decl_align_in_bits (const_tree decl
)
18032 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
18035 /* Return the result of rounding T up to ALIGN. */
18037 static inline offset_int
18038 round_up_to_align (const offset_int
&t
, unsigned int align
)
18040 return wi::udiv_trunc (t
+ align
- 1, align
) * align
;
18043 /* Compute the size of TYPE in bytes. If possible, return NULL and store the
18044 size as an integer constant in CST_SIZE. Otherwise, if possible, return a
18045 DWARF expression that computes the size. Return NULL and set CST_SIZE to -1
18046 if we fail to return the size in one of these two forms. */
18048 static dw_loc_descr_ref
18049 type_byte_size (const_tree type
, HOST_WIDE_INT
*cst_size
)
18052 struct loc_descr_context ctx
;
18054 /* Return a constant integer in priority, if possible. */
18055 *cst_size
= int_size_in_bytes (type
);
18056 if (*cst_size
!= -1)
18059 ctx
.context_type
= const_cast<tree
> (type
);
18060 ctx
.base_decl
= NULL_TREE
;
18062 ctx
.placeholder_arg
= false;
18063 ctx
.placeholder_seen
= false;
18065 type
= TYPE_MAIN_VARIANT (type
);
18066 tree_size
= TYPE_SIZE_UNIT (type
);
18067 return ((tree_size
!= NULL_TREE
)
18068 ? loc_descriptor_from_tree (tree_size
, 0, &ctx
)
18072 /* Helper structure for RECORD_TYPE processing. */
18075 /* Root RECORD_TYPE. It is needed to generate data member location
18076 descriptions in variable-length records (VLR), but also to cope with
18077 variants, which are composed of nested structures multiplexed with
18078 QUAL_UNION_TYPE nodes. Each time such a structure is passed to a
18079 function processing a FIELD_DECL, it is required to be non null. */
18081 /* When generating a variant part in a RECORD_TYPE (i.e. a nested
18082 QUAL_UNION_TYPE), this holds an expression that computes the offset for
18083 this variant part as part of the root record (in storage units). For
18084 regular records, it must be NULL_TREE. */
18085 tree variant_part_offset
;
18088 /* Given a pointer to a FIELD_DECL, compute the byte offset of the lowest
18089 addressed byte of the "containing object" for the given FIELD_DECL. If
18090 possible, return a native constant through CST_OFFSET (in which case NULL is
18091 returned); otherwise return a DWARF expression that computes the offset.
18093 Set *CST_OFFSET to 0 and return NULL if we are unable to determine what
18094 that offset is, either because the argument turns out to be a pointer to an
18095 ERROR_MARK node, or because the offset expression is too complex for us.
18097 CTX is required: see the comment for VLR_CONTEXT. */
18099 static dw_loc_descr_ref
18100 field_byte_offset (const_tree decl
, struct vlr_context
*ctx
,
18101 HOST_WIDE_INT
*cst_offset
)
18104 dw_loc_list_ref loc_result
;
18108 if (TREE_CODE (decl
) == ERROR_MARK
)
18111 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
18113 /* We cannot handle variable bit offsets at the moment, so abort if it's the
18115 if (TREE_CODE (DECL_FIELD_BIT_OFFSET (decl
)) != INTEGER_CST
)
18118 #ifdef PCC_BITFIELD_TYPE_MATTERS
18119 /* We used to handle only constant offsets in all cases. Now, we handle
18120 properly dynamic byte offsets only when PCC bitfield type doesn't
18122 if (PCC_BITFIELD_TYPE_MATTERS
18123 && TREE_CODE (DECL_FIELD_OFFSET (decl
)) == INTEGER_CST
)
18125 offset_int object_offset_in_bits
;
18126 offset_int object_offset_in_bytes
;
18127 offset_int bitpos_int
;
18129 tree field_size_tree
;
18130 offset_int deepest_bitpos
;
18131 offset_int field_size_in_bits
;
18132 unsigned int type_align_in_bits
;
18133 unsigned int decl_align_in_bits
;
18134 offset_int type_size_in_bits
;
18136 bitpos_int
= wi::to_offset (bit_position (decl
));
18137 type
= field_type (decl
);
18138 type_size_in_bits
= offset_int_type_size_in_bits (type
);
18139 type_align_in_bits
= simple_type_align_in_bits (type
);
18141 field_size_tree
= DECL_SIZE (decl
);
18143 /* The size could be unspecified if there was an error, or for
18144 a flexible array member. */
18145 if (!field_size_tree
)
18146 field_size_tree
= bitsize_zero_node
;
18148 /* If the size of the field is not constant, use the type size. */
18149 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
18150 field_size_in_bits
= wi::to_offset (field_size_tree
);
18152 field_size_in_bits
= type_size_in_bits
;
18154 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
18156 /* The GCC front-end doesn't make any attempt to keep track of the
18157 starting bit offset (relative to the start of the containing
18158 structure type) of the hypothetical "containing object" for a
18159 bit-field. Thus, when computing the byte offset value for the
18160 start of the "containing object" of a bit-field, we must deduce
18161 this information on our own. This can be rather tricky to do in
18162 some cases. For example, handling the following structure type
18163 definition when compiling for an i386/i486 target (which only
18164 aligns long long's to 32-bit boundaries) can be very tricky:
18166 struct S { int field1; long long field2:31; };
18168 Fortunately, there is a simple rule-of-thumb which can be used
18169 in such cases. When compiling for an i386/i486, GCC will
18170 allocate 8 bytes for the structure shown above. It decides to
18171 do this based upon one simple rule for bit-field allocation.
18172 GCC allocates each "containing object" for each bit-field at
18173 the first (i.e. lowest addressed) legitimate alignment boundary
18174 (based upon the required minimum alignment for the declared
18175 type of the field) which it can possibly use, subject to the
18176 condition that there is still enough available space remaining
18177 in the containing object (when allocated at the selected point)
18178 to fully accommodate all of the bits of the bit-field itself.
18180 This simple rule makes it obvious why GCC allocates 8 bytes for
18181 each object of the structure type shown above. When looking
18182 for a place to allocate the "containing object" for `field2',
18183 the compiler simply tries to allocate a 64-bit "containing
18184 object" at each successive 32-bit boundary (starting at zero)
18185 until it finds a place to allocate that 64- bit field such that
18186 at least 31 contiguous (and previously unallocated) bits remain
18187 within that selected 64 bit field. (As it turns out, for the
18188 example above, the compiler finds it is OK to allocate the
18189 "containing object" 64-bit field at bit-offset zero within the
18192 Here we attempt to work backwards from the limited set of facts
18193 we're given, and we try to deduce from those facts, where GCC
18194 must have believed that the containing object started (within
18195 the structure type). The value we deduce is then used (by the
18196 callers of this routine) to generate DW_AT_location and
18197 DW_AT_bit_offset attributes for fields (both bit-fields and, in
18198 the case of DW_AT_location, regular fields as well). */
18200 /* Figure out the bit-distance from the start of the structure to
18201 the "deepest" bit of the bit-field. */
18202 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
18204 /* This is the tricky part. Use some fancy footwork to deduce
18205 where the lowest addressed bit of the containing object must
18207 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
18209 /* Round up to type_align by default. This works best for
18211 object_offset_in_bits
18212 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
18214 if (wi::gtu_p (object_offset_in_bits
, bitpos_int
))
18216 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
18218 /* Round up to decl_align instead. */
18219 object_offset_in_bits
18220 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
18223 object_offset_in_bytes
18224 = wi::lrshift (object_offset_in_bits
, LOG2_BITS_PER_UNIT
);
18225 if (ctx
->variant_part_offset
== NULL_TREE
)
18227 *cst_offset
= object_offset_in_bytes
.to_shwi ();
18230 tree_result
= wide_int_to_tree (sizetype
, object_offset_in_bytes
);
18233 #endif /* PCC_BITFIELD_TYPE_MATTERS */
18234 tree_result
= byte_position (decl
);
18236 if (ctx
->variant_part_offset
!= NULL_TREE
)
18237 tree_result
= fold_build2 (PLUS_EXPR
, TREE_TYPE (tree_result
),
18238 ctx
->variant_part_offset
, tree_result
);
18240 /* If the byte offset is a constant, it's simplier to handle a native
18241 constant rather than a DWARF expression. */
18242 if (TREE_CODE (tree_result
) == INTEGER_CST
)
18244 *cst_offset
= wi::to_offset (tree_result
).to_shwi ();
18247 struct loc_descr_context loc_ctx
= {
18248 ctx
->struct_type
, /* context_type */
18249 NULL_TREE
, /* base_decl */
18251 false, /* placeholder_arg */
18252 false /* placeholder_seen */
18254 loc_result
= loc_list_from_tree (tree_result
, 0, &loc_ctx
);
18256 /* We want a DWARF expression: abort if we only have a location list with
18257 multiple elements. */
18258 if (!loc_result
|| !single_element_loc_list_p (loc_result
))
18261 return loc_result
->expr
;
18264 /* The following routines define various Dwarf attributes and any data
18265 associated with them. */
18267 /* Add a location description attribute value to a DIE.
18269 This emits location attributes suitable for whole variables and
18270 whole parameters. Note that the location attributes for struct fields are
18271 generated by the routine `data_member_location_attribute' below. */
18274 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
18275 dw_loc_list_ref descr
)
18279 if (single_element_loc_list_p (descr
))
18280 add_AT_loc (die
, attr_kind
, descr
->expr
);
18282 add_AT_loc_list (die
, attr_kind
, descr
);
18285 /* Add DW_AT_accessibility attribute to DIE if needed. */
18288 add_accessibility_attribute (dw_die_ref die
, tree decl
)
18290 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
18291 children, otherwise the default is DW_ACCESS_public. In DWARF2
18292 the default has always been DW_ACCESS_public. */
18293 if (TREE_PROTECTED (decl
))
18294 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
18295 else if (TREE_PRIVATE (decl
))
18297 if (dwarf_version
== 2
18298 || die
->die_parent
== NULL
18299 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
18300 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
18302 else if (dwarf_version
> 2
18304 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
18305 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
18308 /* Attach the specialized form of location attribute used for data members of
18309 struct and union types. In the special case of a FIELD_DECL node which
18310 represents a bit-field, the "offset" part of this special location
18311 descriptor must indicate the distance in bytes from the lowest-addressed
18312 byte of the containing struct or union type to the lowest-addressed byte of
18313 the "containing object" for the bit-field. (See the `field_byte_offset'
18316 For any given bit-field, the "containing object" is a hypothetical object
18317 (of some integral or enum type) within which the given bit-field lives. The
18318 type of this hypothetical "containing object" is always the same as the
18319 declared type of the individual bit-field itself (for GCC anyway... the
18320 DWARF spec doesn't actually mandate this). Note that it is the size (in
18321 bytes) of the hypothetical "containing object" which will be given in the
18322 DW_AT_byte_size attribute for this bit-field. (See the
18323 `byte_size_attribute' function below.) It is also used when calculating the
18324 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
18327 CTX is required: see the comment for VLR_CONTEXT. */
18330 add_data_member_location_attribute (dw_die_ref die
,
18332 struct vlr_context
*ctx
)
18334 HOST_WIDE_INT offset
;
18335 dw_loc_descr_ref loc_descr
= 0;
18337 if (TREE_CODE (decl
) == TREE_BINFO
)
18339 /* We're working on the TAG_inheritance for a base class. */
18340 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
18342 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
18343 aren't at a fixed offset from all (sub)objects of the same
18344 type. We need to extract the appropriate offset from our
18345 vtable. The following dwarf expression means
18347 BaseAddr = ObAddr + *((*ObAddr) - Offset)
18349 This is specific to the V3 ABI, of course. */
18351 dw_loc_descr_ref tmp
;
18353 /* Make a copy of the object address. */
18354 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
18355 add_loc_descr (&loc_descr
, tmp
);
18357 /* Extract the vtable address. */
18358 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
18359 add_loc_descr (&loc_descr
, tmp
);
18361 /* Calculate the address of the offset. */
18362 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
18363 gcc_assert (offset
< 0);
18365 tmp
= int_loc_descriptor (-offset
);
18366 add_loc_descr (&loc_descr
, tmp
);
18367 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
18368 add_loc_descr (&loc_descr
, tmp
);
18370 /* Extract the offset. */
18371 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
18372 add_loc_descr (&loc_descr
, tmp
);
18374 /* Add it to the object address. */
18375 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
18376 add_loc_descr (&loc_descr
, tmp
);
18379 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
18383 loc_descr
= field_byte_offset (decl
, ctx
, &offset
);
18385 /* If loc_descr is available then we know the field offset is dynamic.
18386 However, GDB does not handle dynamic field offsets very well at the
18388 if (loc_descr
!= NULL
&& gnat_encodings
!= DWARF_GNAT_ENCODINGS_MINIMAL
)
18394 /* Data member location evalutation starts with the base address on the
18395 stack. Compute the field offset and add it to this base address. */
18396 else if (loc_descr
!= NULL
)
18397 add_loc_descr (&loc_descr
, new_loc_descr (DW_OP_plus
, 0, 0));
18402 /* While DW_AT_data_bit_offset has been added already in DWARF4,
18403 e.g. GDB only added support to it in November 2016. For DWARF5
18404 we need newer debug info consumers anyway. We might change this
18405 to dwarf_version >= 4 once most consumers catched up. */
18406 if (dwarf_version
>= 5
18407 && TREE_CODE (decl
) == FIELD_DECL
18408 && DECL_BIT_FIELD_TYPE (decl
))
18410 tree off
= bit_position (decl
);
18411 if (tree_fits_uhwi_p (off
) && get_AT (die
, DW_AT_bit_size
))
18413 remove_AT (die
, DW_AT_byte_size
);
18414 remove_AT (die
, DW_AT_bit_offset
);
18415 add_AT_unsigned (die
, DW_AT_data_bit_offset
, tree_to_uhwi (off
));
18419 if (dwarf_version
> 2)
18421 /* Don't need to output a location expression, just the constant. */
18423 add_AT_int (die
, DW_AT_data_member_location
, offset
);
18425 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
18430 enum dwarf_location_atom op
;
18432 /* The DWARF2 standard says that we should assume that the structure
18433 address is already on the stack, so we can specify a structure
18434 field address by using DW_OP_plus_uconst. */
18435 op
= DW_OP_plus_uconst
;
18436 loc_descr
= new_loc_descr (op
, offset
, 0);
18440 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
18443 /* Writes integer values to dw_vec_const array. */
18446 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
18450 *dest
++ = val
& 0xff;
18456 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
18458 static HOST_WIDE_INT
18459 extract_int (const unsigned char *src
, unsigned int size
)
18461 HOST_WIDE_INT val
= 0;
18467 val
|= *--src
& 0xff;
18473 /* Writes wide_int values to dw_vec_const array. */
18476 insert_wide_int (const wide_int
&val
, unsigned char *dest
, int elt_size
)
18480 if (elt_size
<= HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
)
18482 insert_int ((HOST_WIDE_INT
) val
.elt (0), elt_size
, dest
);
18486 /* We'd have to extend this code to support odd sizes. */
18487 gcc_assert (elt_size
% (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
) == 0);
18489 int n
= elt_size
/ (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
18491 if (WORDS_BIG_ENDIAN
)
18492 for (i
= n
- 1; i
>= 0; i
--)
18494 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
18495 dest
+= sizeof (HOST_WIDE_INT
);
18498 for (i
= 0; i
< n
; i
++)
18500 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
18501 dest
+= sizeof (HOST_WIDE_INT
);
18505 /* Writes floating point values to dw_vec_const array. */
18508 insert_float (const_rtx rtl
, unsigned char *array
)
18513 real_to_target (val
, CONST_DOUBLE_REAL_VALUE (rtl
), GET_MODE (rtl
));
18515 /* real_to_target puts 32-bit pieces in each long. Pack them. */
18516 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
18518 insert_int (val
[i
], 4, array
);
18523 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
18524 does not have a "location" either in memory or in a register. These
18525 things can arise in GNU C when a constant is passed as an actual parameter
18526 to an inlined function. They can also arise in C++ where declared
18527 constants do not necessarily get memory "homes". */
18530 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
18532 switch (GET_CODE (rtl
))
18536 HOST_WIDE_INT val
= INTVAL (rtl
);
18539 add_AT_int (die
, DW_AT_const_value
, val
);
18541 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
18545 case CONST_WIDE_INT
:
18547 wide_int w1
= rtx_mode_t (rtl
, MAX_MODE_INT
);
18548 unsigned int prec
= MIN (wi::min_precision (w1
, UNSIGNED
),
18549 (unsigned int)CONST_WIDE_INT_NUNITS (rtl
) * HOST_BITS_PER_WIDE_INT
);
18550 wide_int w
= wi::zext (w1
, prec
);
18551 add_AT_wide (die
, DW_AT_const_value
, w
);
18556 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
18557 floating-point constant. A CONST_DOUBLE is used whenever the
18558 constant requires more than one word in order to be adequately
18561 machine_mode mode
= GET_MODE (rtl
);
18563 if (TARGET_SUPPORTS_WIDE_INT
== 0 && !SCALAR_FLOAT_MODE_P (mode
))
18564 add_AT_double (die
, DW_AT_const_value
,
18565 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
18568 unsigned int length
= GET_MODE_SIZE (mode
);
18569 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
18571 insert_float (rtl
, array
);
18572 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
18579 machine_mode mode
= GET_MODE (rtl
);
18580 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
18581 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
18582 unsigned char *array
18583 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
18586 machine_mode imode
= GET_MODE_INNER (mode
);
18588 switch (GET_MODE_CLASS (mode
))
18590 case MODE_VECTOR_INT
:
18591 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
18593 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
18594 insert_wide_int (rtx_mode_t (elt
, imode
), p
, elt_size
);
18598 case MODE_VECTOR_FLOAT
:
18599 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
18601 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
18602 insert_float (elt
, p
);
18607 gcc_unreachable ();
18610 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
18615 if (dwarf_version
>= 4 || !dwarf_strict
)
18617 dw_loc_descr_ref loc_result
;
18618 resolve_one_addr (&rtl
);
18620 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
18621 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
18622 add_AT_loc (die
, DW_AT_location
, loc_result
);
18623 vec_safe_push (used_rtx_array
, rtl
);
18629 if (CONSTANT_P (XEXP (rtl
, 0)))
18630 return add_const_value_attribute (die
, XEXP (rtl
, 0));
18633 if (!const_ok_for_output (rtl
))
18637 if (dwarf_version
>= 4 || !dwarf_strict
)
18642 /* In cases where an inlined instance of an inline function is passed
18643 the address of an `auto' variable (which is local to the caller) we
18644 can get a situation where the DECL_RTL of the artificial local
18645 variable (for the inlining) which acts as a stand-in for the
18646 corresponding formal parameter (of the inline function) will look
18647 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
18648 exactly a compile-time constant expression, but it isn't the address
18649 of the (artificial) local variable either. Rather, it represents the
18650 *value* which the artificial local variable always has during its
18651 lifetime. We currently have no way to represent such quasi-constant
18652 values in Dwarf, so for now we just punt and generate nothing. */
18660 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
18661 && MEM_READONLY_P (rtl
)
18662 && GET_MODE (rtl
) == BLKmode
)
18664 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
18670 /* No other kinds of rtx should be possible here. */
18671 gcc_unreachable ();
18676 /* Determine whether the evaluation of EXPR references any variables
18677 or functions which aren't otherwise used (and therefore may not be
18680 reference_to_unused (tree
* tp
, int * walk_subtrees
,
18681 void * data ATTRIBUTE_UNUSED
)
18683 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
18684 *walk_subtrees
= 0;
18686 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
18687 && ! TREE_ASM_WRITTEN (*tp
))
18689 /* ??? The C++ FE emits debug information for using decls, so
18690 putting gcc_unreachable here falls over. See PR31899. For now
18691 be conservative. */
18692 else if (!symtab
->global_info_ready
&& VAR_OR_FUNCTION_DECL_P (*tp
))
18694 else if (VAR_P (*tp
))
18696 varpool_node
*node
= varpool_node::get (*tp
);
18697 if (!node
|| !node
->definition
)
18700 else if (TREE_CODE (*tp
) == FUNCTION_DECL
18701 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
18703 /* The call graph machinery must have finished analyzing,
18704 optimizing and gimplifying the CU by now.
18705 So if *TP has no call graph node associated
18706 to it, it means *TP will not be emitted. */
18707 if (!cgraph_node::get (*tp
))
18710 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
18716 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
18717 for use in a later add_const_value_attribute call. */
18720 rtl_for_decl_init (tree init
, tree type
)
18722 rtx rtl
= NULL_RTX
;
18726 /* If a variable is initialized with a string constant without embedded
18727 zeros, build CONST_STRING. */
18728 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
18730 tree enttype
= TREE_TYPE (type
);
18731 tree domain
= TYPE_DOMAIN (type
);
18732 machine_mode mode
= TYPE_MODE (enttype
);
18734 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
18736 && integer_zerop (TYPE_MIN_VALUE (domain
))
18737 && compare_tree_int (TYPE_MAX_VALUE (domain
),
18738 TREE_STRING_LENGTH (init
) - 1) == 0
18739 && ((size_t) TREE_STRING_LENGTH (init
)
18740 == strlen (TREE_STRING_POINTER (init
)) + 1))
18742 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
18743 ggc_strdup (TREE_STRING_POINTER (init
)));
18744 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
18745 MEM_READONLY_P (rtl
) = 1;
18748 /* Other aggregates, and complex values, could be represented using
18750 else if (AGGREGATE_TYPE_P (type
)
18751 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
18752 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
18753 || TREE_CODE (type
) == COMPLEX_TYPE
)
18755 /* Vectors only work if their mode is supported by the target.
18756 FIXME: generic vectors ought to work too. */
18757 else if (TREE_CODE (type
) == VECTOR_TYPE
18758 && !VECTOR_MODE_P (TYPE_MODE (type
)))
18760 /* If the initializer is something that we know will expand into an
18761 immediate RTL constant, expand it now. We must be careful not to
18762 reference variables which won't be output. */
18763 else if (initializer_constant_valid_p (init
, type
)
18764 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
18766 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
18768 if (TREE_CODE (type
) == VECTOR_TYPE
)
18769 switch (TREE_CODE (init
))
18774 if (TREE_CONSTANT (init
))
18776 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
18777 bool constant_p
= true;
18779 unsigned HOST_WIDE_INT ix
;
18781 /* Even when ctor is constant, it might contain non-*_CST
18782 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
18783 belong into VECTOR_CST nodes. */
18784 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
18785 if (!CONSTANT_CLASS_P (value
))
18787 constant_p
= false;
18793 init
= build_vector_from_ctor (type
, elts
);
18803 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
18805 /* If expand_expr returns a MEM, it wasn't immediate. */
18806 gcc_assert (!rtl
|| !MEM_P (rtl
));
18812 /* Generate RTL for the variable DECL to represent its location. */
18815 rtl_for_decl_location (tree decl
)
18819 /* Here we have to decide where we are going to say the parameter "lives"
18820 (as far as the debugger is concerned). We only have a couple of
18821 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
18823 DECL_RTL normally indicates where the parameter lives during most of the
18824 activation of the function. If optimization is enabled however, this
18825 could be either NULL or else a pseudo-reg. Both of those cases indicate
18826 that the parameter doesn't really live anywhere (as far as the code
18827 generation parts of GCC are concerned) during most of the function's
18828 activation. That will happen (for example) if the parameter is never
18829 referenced within the function.
18831 We could just generate a location descriptor here for all non-NULL
18832 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
18833 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
18834 where DECL_RTL is NULL or is a pseudo-reg.
18836 Note however that we can only get away with using DECL_INCOMING_RTL as
18837 a backup substitute for DECL_RTL in certain limited cases. In cases
18838 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
18839 we can be sure that the parameter was passed using the same type as it is
18840 declared to have within the function, and that its DECL_INCOMING_RTL
18841 points us to a place where a value of that type is passed.
18843 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
18844 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
18845 because in these cases DECL_INCOMING_RTL points us to a value of some
18846 type which is *different* from the type of the parameter itself. Thus,
18847 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
18848 such cases, the debugger would end up (for example) trying to fetch a
18849 `float' from a place which actually contains the first part of a
18850 `double'. That would lead to really incorrect and confusing
18851 output at debug-time.
18853 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
18854 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
18855 are a couple of exceptions however. On little-endian machines we can
18856 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
18857 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
18858 an integral type that is smaller than TREE_TYPE (decl). These cases arise
18859 when (on a little-endian machine) a non-prototyped function has a
18860 parameter declared to be of type `short' or `char'. In such cases,
18861 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
18862 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
18863 passed `int' value. If the debugger then uses that address to fetch
18864 a `short' or a `char' (on a little-endian machine) the result will be
18865 the correct data, so we allow for such exceptional cases below.
18867 Note that our goal here is to describe the place where the given formal
18868 parameter lives during most of the function's activation (i.e. between the
18869 end of the prologue and the start of the epilogue). We'll do that as best
18870 as we can. Note however that if the given formal parameter is modified
18871 sometime during the execution of the function, then a stack backtrace (at
18872 debug-time) will show the function as having been called with the *new*
18873 value rather than the value which was originally passed in. This happens
18874 rarely enough that it is not a major problem, but it *is* a problem, and
18875 I'd like to fix it.
18877 A future version of dwarf2out.c may generate two additional attributes for
18878 any given DW_TAG_formal_parameter DIE which will describe the "passed
18879 type" and the "passed location" for the given formal parameter in addition
18880 to the attributes we now generate to indicate the "declared type" and the
18881 "active location" for each parameter. This additional set of attributes
18882 could be used by debuggers for stack backtraces. Separately, note that
18883 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
18884 This happens (for example) for inlined-instances of inline function formal
18885 parameters which are never referenced. This really shouldn't be
18886 happening. All PARM_DECL nodes should get valid non-NULL
18887 DECL_INCOMING_RTL values. FIXME. */
18889 /* Use DECL_RTL as the "location" unless we find something better. */
18890 rtl
= DECL_RTL_IF_SET (decl
);
18892 /* When generating abstract instances, ignore everything except
18893 constants, symbols living in memory, and symbols living in
18894 fixed registers. */
18895 if (! reload_completed
)
18898 && (CONSTANT_P (rtl
)
18900 && CONSTANT_P (XEXP (rtl
, 0)))
18903 && TREE_STATIC (decl
))))
18905 rtl
= targetm
.delegitimize_address (rtl
);
18910 else if (TREE_CODE (decl
) == PARM_DECL
)
18912 if (rtl
== NULL_RTX
18913 || is_pseudo_reg (rtl
)
18915 && is_pseudo_reg (XEXP (rtl
, 0))
18916 && DECL_INCOMING_RTL (decl
)
18917 && MEM_P (DECL_INCOMING_RTL (decl
))
18918 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
18920 tree declared_type
= TREE_TYPE (decl
);
18921 tree passed_type
= DECL_ARG_TYPE (decl
);
18922 machine_mode dmode
= TYPE_MODE (declared_type
);
18923 machine_mode pmode
= TYPE_MODE (passed_type
);
18925 /* This decl represents a formal parameter which was optimized out.
18926 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
18927 all cases where (rtl == NULL_RTX) just below. */
18928 if (dmode
== pmode
)
18929 rtl
= DECL_INCOMING_RTL (decl
);
18930 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
18931 && SCALAR_INT_MODE_P (dmode
)
18932 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
18933 && DECL_INCOMING_RTL (decl
))
18935 rtx inc
= DECL_INCOMING_RTL (decl
);
18938 else if (MEM_P (inc
))
18940 if (BYTES_BIG_ENDIAN
)
18941 rtl
= adjust_address_nv (inc
, dmode
,
18942 GET_MODE_SIZE (pmode
)
18943 - GET_MODE_SIZE (dmode
));
18950 /* If the parm was passed in registers, but lives on the stack, then
18951 make a big endian correction if the mode of the type of the
18952 parameter is not the same as the mode of the rtl. */
18953 /* ??? This is the same series of checks that are made in dbxout.c before
18954 we reach the big endian correction code there. It isn't clear if all
18955 of these checks are necessary here, but keeping them all is the safe
18957 else if (MEM_P (rtl
)
18958 && XEXP (rtl
, 0) != const0_rtx
18959 && ! CONSTANT_P (XEXP (rtl
, 0))
18960 /* Not passed in memory. */
18961 && !MEM_P (DECL_INCOMING_RTL (decl
))
18962 /* Not passed by invisible reference. */
18963 && (!REG_P (XEXP (rtl
, 0))
18964 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
18965 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
18966 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
18967 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
18970 /* Big endian correction check. */
18971 && BYTES_BIG_ENDIAN
18972 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
18973 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
18976 machine_mode addr_mode
= get_address_mode (rtl
);
18977 int offset
= (UNITS_PER_WORD
18978 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
18980 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
18981 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
18984 else if (VAR_P (decl
)
18987 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
18988 && BYTES_BIG_ENDIAN
)
18990 machine_mode addr_mode
= get_address_mode (rtl
);
18991 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
18992 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
18994 /* If a variable is declared "register" yet is smaller than
18995 a register, then if we store the variable to memory, it
18996 looks like we're storing a register-sized value, when in
18997 fact we are not. We need to adjust the offset of the
18998 storage location to reflect the actual value's bytes,
18999 else gdb will not be able to display it. */
19001 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
19002 plus_constant (addr_mode
, XEXP (rtl
, 0),
19006 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
19007 and will have been substituted directly into all expressions that use it.
19008 C does not have such a concept, but C++ and other languages do. */
19009 if (!rtl
&& VAR_P (decl
) && DECL_INITIAL (decl
))
19010 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
19013 rtl
= targetm
.delegitimize_address (rtl
);
19015 /* If we don't look past the constant pool, we risk emitting a
19016 reference to a constant pool entry that isn't referenced from
19017 code, and thus is not emitted. */
19019 rtl
= avoid_constant_pool_reference (rtl
);
19021 /* Try harder to get a rtl. If this symbol ends up not being emitted
19022 in the current CU, resolve_addr will remove the expression referencing
19024 if (rtl
== NULL_RTX
19026 && !DECL_EXTERNAL (decl
)
19027 && TREE_STATIC (decl
)
19028 && DECL_NAME (decl
)
19029 && !DECL_HARD_REGISTER (decl
)
19030 && DECL_MODE (decl
) != VOIDmode
)
19032 rtl
= make_decl_rtl_for_debug (decl
);
19034 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
19035 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
19042 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
19043 returned. If so, the decl for the COMMON block is returned, and the
19044 value is the offset into the common block for the symbol. */
19047 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
19049 tree val_expr
, cvar
;
19051 HOST_WIDE_INT bitsize
, bitpos
;
19053 int unsignedp
, reversep
, volatilep
= 0;
19055 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
19056 it does not have a value (the offset into the common area), or if it
19057 is thread local (as opposed to global) then it isn't common, and shouldn't
19058 be handled as such. */
19060 || !TREE_STATIC (decl
)
19061 || !DECL_HAS_VALUE_EXPR_P (decl
)
19065 val_expr
= DECL_VALUE_EXPR (decl
);
19066 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
19069 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
, &mode
,
19070 &unsignedp
, &reversep
, &volatilep
);
19072 if (cvar
== NULL_TREE
19074 || DECL_ARTIFICIAL (cvar
)
19075 || !TREE_PUBLIC (cvar
))
19079 if (offset
!= NULL
)
19081 if (!tree_fits_shwi_p (offset
))
19083 *value
= tree_to_shwi (offset
);
19086 *value
+= bitpos
/ BITS_PER_UNIT
;
19091 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
19092 data attribute for a variable or a parameter. We generate the
19093 DW_AT_const_value attribute only in those cases where the given variable
19094 or parameter does not have a true "location" either in memory or in a
19095 register. This can happen (for example) when a constant is passed as an
19096 actual argument in a call to an inline function. (It's possible that
19097 these things can crop up in other ways also.) Note that one type of
19098 constant value which can be passed into an inlined function is a constant
19099 pointer. This can happen for example if an actual argument in an inlined
19100 function call evaluates to a compile-time constant address.
19102 CACHE_P is true if it is worth caching the location list for DECL,
19103 so that future calls can reuse it rather than regenerate it from scratch.
19104 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
19105 since we will need to refer to them each time the function is inlined. */
19108 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
)
19111 dw_loc_list_ref list
;
19112 var_loc_list
*loc_list
;
19113 cached_dw_loc_list
*cache
;
19118 if (TREE_CODE (decl
) == ERROR_MARK
)
19121 if (get_AT (die
, DW_AT_location
)
19122 || get_AT (die
, DW_AT_const_value
))
19125 gcc_assert (VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
19126 || TREE_CODE (decl
) == RESULT_DECL
);
19128 /* Try to get some constant RTL for this decl, and use that as the value of
19131 rtl
= rtl_for_decl_location (decl
);
19132 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
19133 && add_const_value_attribute (die
, rtl
))
19136 /* See if we have single element location list that is equivalent to
19137 a constant value. That way we are better to use add_const_value_attribute
19138 rather than expanding constant value equivalent. */
19139 loc_list
= lookup_decl_loc (decl
);
19142 && loc_list
->first
->next
== NULL
19143 && NOTE_P (loc_list
->first
->loc
)
19144 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
19145 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
19147 struct var_loc_node
*node
;
19149 node
= loc_list
->first
;
19150 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
19151 if (GET_CODE (rtl
) == EXPR_LIST
)
19152 rtl
= XEXP (rtl
, 0);
19153 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
19154 && add_const_value_attribute (die
, rtl
))
19157 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
19158 list several times. See if we've already cached the contents. */
19160 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
19164 cache
= cached_dw_loc_list_table
->find_with_hash (decl
, DECL_UID (decl
));
19166 list
= cache
->loc_list
;
19170 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2,
19172 /* It is usually worth caching this result if the decl is from
19173 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
19174 if (cache_p
&& list
&& list
->dw_loc_next
)
19176 cached_dw_loc_list
**slot
19177 = cached_dw_loc_list_table
->find_slot_with_hash (decl
,
19180 cache
= ggc_cleared_alloc
<cached_dw_loc_list
> ();
19181 cache
->decl_id
= DECL_UID (decl
);
19182 cache
->loc_list
= list
;
19188 add_AT_location_description (die
, DW_AT_location
, list
);
19191 /* None of that worked, so it must not really have a location;
19192 try adding a constant value attribute from the DECL_INITIAL. */
19193 return tree_add_const_value_attribute_for_decl (die
, decl
);
19196 /* Helper function for tree_add_const_value_attribute. Natively encode
19197 initializer INIT into an array. Return true if successful. */
19200 native_encode_initializer (tree init
, unsigned char *array
, int size
)
19204 if (init
== NULL_TREE
)
19208 switch (TREE_CODE (init
))
19211 type
= TREE_TYPE (init
);
19212 if (TREE_CODE (type
) == ARRAY_TYPE
)
19214 tree enttype
= TREE_TYPE (type
);
19215 machine_mode mode
= TYPE_MODE (enttype
);
19217 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
19219 if (int_size_in_bytes (type
) != size
)
19221 if (size
> TREE_STRING_LENGTH (init
))
19223 memcpy (array
, TREE_STRING_POINTER (init
),
19224 TREE_STRING_LENGTH (init
));
19225 memset (array
+ TREE_STRING_LENGTH (init
),
19226 '\0', size
- TREE_STRING_LENGTH (init
));
19229 memcpy (array
, TREE_STRING_POINTER (init
), size
);
19234 type
= TREE_TYPE (init
);
19235 if (int_size_in_bytes (type
) != size
)
19237 if (TREE_CODE (type
) == ARRAY_TYPE
)
19239 HOST_WIDE_INT min_index
;
19240 unsigned HOST_WIDE_INT cnt
;
19241 int curpos
= 0, fieldsize
;
19242 constructor_elt
*ce
;
19244 if (TYPE_DOMAIN (type
) == NULL_TREE
19245 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))))
19248 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
19249 if (fieldsize
<= 0)
19252 min_index
= tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)));
19253 memset (array
, '\0', size
);
19254 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
19256 tree val
= ce
->value
;
19257 tree index
= ce
->index
;
19259 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
19260 pos
= (tree_to_shwi (TREE_OPERAND (index
, 0)) - min_index
)
19263 pos
= (tree_to_shwi (index
) - min_index
) * fieldsize
;
19268 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
19271 curpos
= pos
+ fieldsize
;
19272 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
19274 int count
= tree_to_shwi (TREE_OPERAND (index
, 1))
19275 - tree_to_shwi (TREE_OPERAND (index
, 0));
19276 while (count
-- > 0)
19279 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
19280 curpos
+= fieldsize
;
19283 gcc_assert (curpos
<= size
);
19287 else if (TREE_CODE (type
) == RECORD_TYPE
19288 || TREE_CODE (type
) == UNION_TYPE
)
19290 tree field
= NULL_TREE
;
19291 unsigned HOST_WIDE_INT cnt
;
19292 constructor_elt
*ce
;
19294 if (int_size_in_bytes (type
) != size
)
19297 if (TREE_CODE (type
) == RECORD_TYPE
)
19298 field
= TYPE_FIELDS (type
);
19300 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
19302 tree val
= ce
->value
;
19303 int pos
, fieldsize
;
19305 if (ce
->index
!= 0)
19311 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
19314 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
19315 && TYPE_DOMAIN (TREE_TYPE (field
))
19316 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
19318 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
19319 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field
)))
19321 fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
19322 pos
= int_byte_position (field
);
19323 gcc_assert (pos
+ fieldsize
<= size
);
19324 if (val
&& fieldsize
!= 0
19325 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
19331 case VIEW_CONVERT_EXPR
:
19332 case NON_LVALUE_EXPR
:
19333 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
19335 return native_encode_expr (init
, array
, size
) == size
;
19339 /* Attach a DW_AT_const_value attribute to DIE. The value of the
19340 attribute is the const value T. */
19343 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
19346 tree type
= TREE_TYPE (t
);
19349 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
19353 gcc_assert (!DECL_P (init
));
19357 rtl
= rtl_for_decl_init (init
, type
);
19359 return add_const_value_attribute (die
, rtl
);
19361 /* If the host and target are sane, try harder. */
19362 if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
19363 && initializer_constant_valid_p (init
, type
))
19365 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
19366 if (size
> 0 && (int) size
== size
)
19368 unsigned char *array
= ggc_cleared_vec_alloc
<unsigned char> (size
);
19370 if (native_encode_initializer (init
, array
, size
))
19372 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
19381 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
19382 attribute is the const value of T, where T is an integral constant
19383 variable with static storage duration
19384 (so it can't be a PARM_DECL or a RESULT_DECL). */
19387 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
19391 || (!VAR_P (decl
) && TREE_CODE (decl
) != CONST_DECL
)
19392 || (VAR_P (decl
) && !TREE_STATIC (decl
)))
19395 if (TREE_READONLY (decl
)
19396 && ! TREE_THIS_VOLATILE (decl
)
19397 && DECL_INITIAL (decl
))
19402 /* Don't add DW_AT_const_value if abstract origin already has one. */
19403 if (get_AT (var_die
, DW_AT_const_value
))
19406 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
19409 /* Convert the CFI instructions for the current function into a
19410 location list. This is used for DW_AT_frame_base when we targeting
19411 a dwarf2 consumer that does not support the dwarf3
19412 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
19415 static dw_loc_list_ref
19416 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
19420 dw_loc_list_ref list
, *list_tail
;
19422 dw_cfa_location last_cfa
, next_cfa
;
19423 const char *start_label
, *last_label
, *section
;
19424 dw_cfa_location remember
;
19427 gcc_assert (fde
!= NULL
);
19429 section
= secname_for_decl (current_function_decl
);
19433 memset (&next_cfa
, 0, sizeof (next_cfa
));
19434 next_cfa
.reg
= INVALID_REGNUM
;
19435 remember
= next_cfa
;
19437 start_label
= fde
->dw_fde_begin
;
19439 /* ??? Bald assumption that the CIE opcode list does not contain
19440 advance opcodes. */
19441 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
19442 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
19444 last_cfa
= next_cfa
;
19445 last_label
= start_label
;
19447 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
19449 /* If the first partition contained no CFI adjustments, the
19450 CIE opcodes apply to the whole first partition. */
19451 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19452 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
19453 list_tail
=&(*list_tail
)->dw_loc_next
;
19454 start_label
= last_label
= fde
->dw_fde_second_begin
;
19457 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
19459 switch (cfi
->dw_cfi_opc
)
19461 case DW_CFA_set_loc
:
19462 case DW_CFA_advance_loc1
:
19463 case DW_CFA_advance_loc2
:
19464 case DW_CFA_advance_loc4
:
19465 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
19467 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19468 start_label
, last_label
, section
);
19470 list_tail
= &(*list_tail
)->dw_loc_next
;
19471 last_cfa
= next_cfa
;
19472 start_label
= last_label
;
19474 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
19477 case DW_CFA_advance_loc
:
19478 /* The encoding is complex enough that we should never emit this. */
19479 gcc_unreachable ();
19482 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
19485 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
19487 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
19489 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19490 start_label
, last_label
, section
);
19492 list_tail
= &(*list_tail
)->dw_loc_next
;
19493 last_cfa
= next_cfa
;
19494 start_label
= last_label
;
19496 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19497 start_label
, fde
->dw_fde_end
, section
);
19498 list_tail
= &(*list_tail
)->dw_loc_next
;
19499 start_label
= last_label
= fde
->dw_fde_second_begin
;
19503 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
19505 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19506 start_label
, last_label
, section
);
19507 list_tail
= &(*list_tail
)->dw_loc_next
;
19508 start_label
= last_label
;
19511 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
19513 fde
->dw_fde_second_begin
19514 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
19517 if (list
&& list
->dw_loc_next
)
19523 /* Compute a displacement from the "steady-state frame pointer" to the
19524 frame base (often the same as the CFA), and store it in
19525 frame_pointer_fb_offset. OFFSET is added to the displacement
19526 before the latter is negated. */
19529 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
19533 #ifdef FRAME_POINTER_CFA_OFFSET
19534 reg
= frame_pointer_rtx
;
19535 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
19537 reg
= arg_pointer_rtx
;
19538 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
19541 elim
= (ira_use_lra_p
19542 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
19543 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
19544 if (GET_CODE (elim
) == PLUS
)
19546 offset
+= INTVAL (XEXP (elim
, 1));
19547 elim
= XEXP (elim
, 0);
19550 frame_pointer_fb_offset
= -offset
;
19552 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
19553 in which to eliminate. This is because it's stack pointer isn't
19554 directly accessible as a register within the ISA. To work around
19555 this, assume that while we cannot provide a proper value for
19556 frame_pointer_fb_offset, we won't need one either. */
19557 frame_pointer_fb_offset_valid
19558 = ((SUPPORTS_STACK_ALIGNMENT
19559 && (elim
== hard_frame_pointer_rtx
19560 || elim
== stack_pointer_rtx
))
19561 || elim
== (frame_pointer_needed
19562 ? hard_frame_pointer_rtx
19563 : stack_pointer_rtx
));
19566 /* Generate a DW_AT_name attribute given some string value to be included as
19567 the value of the attribute. */
19570 add_name_attribute (dw_die_ref die
, const char *name_string
)
19572 if (name_string
!= NULL
&& *name_string
!= 0)
19574 if (demangle_name_func
)
19575 name_string
= (*demangle_name_func
) (name_string
);
19577 add_AT_string (die
, DW_AT_name
, name_string
);
19581 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
19582 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
19583 of TYPE accordingly.
19585 ??? This is a temporary measure until after we're able to generate
19586 regular DWARF for the complex Ada type system. */
19589 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
19590 dw_die_ref context_die
)
19593 dw_die_ref dtype_die
;
19595 if (!lang_hooks
.types
.descriptive_type
)
19598 dtype
= lang_hooks
.types
.descriptive_type (type
);
19602 dtype_die
= lookup_type_die (dtype
);
19605 gen_type_die (dtype
, context_die
);
19606 dtype_die
= lookup_type_die (dtype
);
19607 gcc_assert (dtype_die
);
19610 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
19613 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
19615 static const char *
19616 comp_dir_string (void)
19620 static const char *cached_wd
= NULL
;
19622 if (cached_wd
!= NULL
)
19625 wd
= get_src_pwd ();
19629 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
19633 wdlen
= strlen (wd
);
19634 wd1
= ggc_vec_alloc
<char> (wdlen
+ 2);
19636 wd1
[wdlen
] = DIR_SEPARATOR
;
19637 wd1
[wdlen
+ 1] = 0;
19641 cached_wd
= remap_debug_filename (wd
);
19645 /* Generate a DW_AT_comp_dir attribute for DIE. */
19648 add_comp_dir_attribute (dw_die_ref die
)
19650 const char * wd
= comp_dir_string ();
19652 add_AT_string (die
, DW_AT_comp_dir
, wd
);
19655 /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
19656 pointer computation, ...), output a representation for that bound according
19657 to the accepted FORMS (see enum dw_scalar_form) and add it to DIE. See
19658 loc_list_from_tree for the meaning of CONTEXT. */
19661 add_scalar_info (dw_die_ref die
, enum dwarf_attribute attr
, tree value
,
19662 int forms
, struct loc_descr_context
*context
)
19664 dw_die_ref context_die
, decl_die
;
19665 dw_loc_list_ref list
;
19666 bool strip_conversions
= true;
19667 bool placeholder_seen
= false;
19669 while (strip_conversions
)
19670 switch (TREE_CODE (value
))
19677 case VIEW_CONVERT_EXPR
:
19678 value
= TREE_OPERAND (value
, 0);
19682 strip_conversions
= false;
19686 /* If possible and permitted, output the attribute as a constant. */
19687 if ((forms
& dw_scalar_form_constant
) != 0
19688 && TREE_CODE (value
) == INTEGER_CST
)
19690 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (value
));
19692 /* If HOST_WIDE_INT is big enough then represent the bound as
19693 a constant value. We need to choose a form based on
19694 whether the type is signed or unsigned. We cannot just
19695 call add_AT_unsigned if the value itself is positive
19696 (add_AT_unsigned might add the unsigned value encoded as
19697 DW_FORM_data[1248]). Some DWARF consumers will lookup the
19698 bounds type and then sign extend any unsigned values found
19699 for signed types. This is needed only for
19700 DW_AT_{lower,upper}_bound, since for most other attributes,
19701 consumers will treat DW_FORM_data[1248] as unsigned values,
19702 regardless of the underlying type. */
19703 if (prec
<= HOST_BITS_PER_WIDE_INT
19704 || tree_fits_uhwi_p (value
))
19706 if (TYPE_UNSIGNED (TREE_TYPE (value
)))
19707 add_AT_unsigned (die
, attr
, TREE_INT_CST_LOW (value
));
19709 add_AT_int (die
, attr
, TREE_INT_CST_LOW (value
));
19712 /* Otherwise represent the bound as an unsigned value with
19713 the precision of its type. The precision and signedness
19714 of the type will be necessary to re-interpret it
19716 add_AT_wide (die
, attr
, value
);
19720 /* Otherwise, if it's possible and permitted too, output a reference to
19722 if ((forms
& dw_scalar_form_reference
) != 0)
19724 tree decl
= NULL_TREE
;
19726 /* Some type attributes reference an outer type. For instance, the upper
19727 bound of an array may reference an embedding record (this happens in
19729 if (TREE_CODE (value
) == COMPONENT_REF
19730 && TREE_CODE (TREE_OPERAND (value
, 0)) == PLACEHOLDER_EXPR
19731 && TREE_CODE (TREE_OPERAND (value
, 1)) == FIELD_DECL
)
19732 decl
= TREE_OPERAND (value
, 1);
19734 else if (VAR_P (value
)
19735 || TREE_CODE (value
) == PARM_DECL
19736 || TREE_CODE (value
) == RESULT_DECL
)
19739 if (decl
!= NULL_TREE
)
19741 dw_die_ref decl_die
= lookup_decl_die (decl
);
19743 /* ??? Can this happen, or should the variable have been bound
19744 first? Probably it can, since I imagine that we try to create
19745 the types of parameters in the order in which they exist in
19746 the list, and won't have created a forward reference to a
19747 later parameter. */
19748 if (decl_die
!= NULL
)
19750 add_AT_die_ref (die
, attr
, decl_die
);
19756 /* Last chance: try to create a stack operation procedure to evaluate the
19757 value. Do nothing if even that is not possible or permitted. */
19758 if ((forms
& dw_scalar_form_exprloc
) == 0)
19761 list
= loc_list_from_tree (value
, 2, context
);
19762 if (context
&& context
->placeholder_arg
)
19764 placeholder_seen
= context
->placeholder_seen
;
19765 context
->placeholder_seen
= false;
19767 if (list
== NULL
|| single_element_loc_list_p (list
))
19769 /* If this attribute is not a reference nor constant, it is
19770 a DWARF expression rather than location description. For that
19771 loc_list_from_tree (value, 0, &context) is needed. */
19772 dw_loc_list_ref list2
= loc_list_from_tree (value
, 0, context
);
19773 if (list2
&& single_element_loc_list_p (list2
))
19775 if (placeholder_seen
)
19777 struct dwarf_procedure_info dpi
;
19778 dpi
.fndecl
= NULL_TREE
;
19779 dpi
.args_count
= 1;
19780 if (!resolve_args_picking (list2
->expr
, 1, &dpi
))
19783 add_AT_loc (die
, attr
, list2
->expr
);
19788 /* If that failed to give a single element location list, fall back to
19789 outputting this as a reference... still if permitted. */
19791 || (forms
& dw_scalar_form_reference
) == 0
19792 || placeholder_seen
)
19795 if (current_function_decl
== 0)
19796 context_die
= comp_unit_die ();
19798 context_die
= lookup_decl_die (current_function_decl
);
19800 decl_die
= new_die (DW_TAG_variable
, context_die
, value
);
19801 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
19802 add_type_attribute (decl_die
, TREE_TYPE (value
), TYPE_QUAL_CONST
, false,
19804 add_AT_location_description (decl_die
, DW_AT_location
, list
);
19805 add_AT_die_ref (die
, attr
, decl_die
);
19808 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
19812 lower_bound_default (void)
19814 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
19820 case DW_LANG_C_plus_plus
:
19821 case DW_LANG_C_plus_plus_11
:
19822 case DW_LANG_C_plus_plus_14
:
19824 case DW_LANG_ObjC_plus_plus
:
19826 case DW_LANG_Fortran77
:
19827 case DW_LANG_Fortran90
:
19828 case DW_LANG_Fortran95
:
19829 case DW_LANG_Fortran03
:
19830 case DW_LANG_Fortran08
:
19834 case DW_LANG_Python
:
19835 return dwarf_version
>= 4 ? 0 : -1;
19836 case DW_LANG_Ada95
:
19837 case DW_LANG_Ada83
:
19838 case DW_LANG_Cobol74
:
19839 case DW_LANG_Cobol85
:
19840 case DW_LANG_Modula2
:
19842 return dwarf_version
>= 4 ? 1 : -1;
19848 /* Given a tree node describing an array bound (either lower or upper) output
19849 a representation for that bound. */
19852 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
,
19853 tree bound
, struct loc_descr_context
*context
)
19858 switch (TREE_CODE (bound
))
19860 /* Strip all conversions. */
19862 case VIEW_CONVERT_EXPR
:
19863 bound
= TREE_OPERAND (bound
, 0);
19866 /* All fixed-bounds are represented by INTEGER_CST nodes. Lower bounds
19867 are even omitted when they are the default. */
19869 /* If the value for this bound is the default one, we can even omit the
19871 if (bound_attr
== DW_AT_lower_bound
19872 && tree_fits_shwi_p (bound
)
19873 && (dflt
= lower_bound_default ()) != -1
19874 && tree_to_shwi (bound
) == dflt
)
19880 /* Because of the complex interaction there can be with other GNAT
19881 encodings, GDB isn't ready yet to handle proper DWARF description
19882 for self-referencial subrange bounds: let GNAT encodings do the
19883 magic in such a case. */
19885 && gnat_encodings
!= DWARF_GNAT_ENCODINGS_MINIMAL
19886 && contains_placeholder_p (bound
))
19889 add_scalar_info (subrange_die
, bound_attr
, bound
,
19890 dw_scalar_form_constant
19891 | dw_scalar_form_exprloc
19892 | dw_scalar_form_reference
,
19898 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
19899 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
19900 Note that the block of subscript information for an array type also
19901 includes information about the element type of the given array type.
19903 This function reuses previously set type and bound information if
19907 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
19909 unsigned dimension_number
;
19911 dw_die_ref child
= type_die
->die_child
;
19913 for (dimension_number
= 0;
19914 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
19915 type
= TREE_TYPE (type
), dimension_number
++)
19917 tree domain
= TYPE_DOMAIN (type
);
19919 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
19922 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
19923 and (in GNU C only) variable bounds. Handle all three forms
19926 /* Find and reuse a previously generated DW_TAG_subrange_type if
19929 For multi-dimensional arrays, as we iterate through the
19930 various dimensions in the enclosing for loop above, we also
19931 iterate through the DIE children and pick at each
19932 DW_TAG_subrange_type previously generated (if available).
19933 Each child DW_TAG_subrange_type DIE describes the range of
19934 the current dimension. At this point we should have as many
19935 DW_TAG_subrange_type's as we have dimensions in the
19937 dw_die_ref subrange_die
= NULL
;
19941 child
= child
->die_sib
;
19942 if (child
->die_tag
== DW_TAG_subrange_type
)
19943 subrange_die
= child
;
19944 if (child
== type_die
->die_child
)
19946 /* If we wrapped around, stop looking next time. */
19950 if (child
->die_tag
== DW_TAG_subrange_type
)
19954 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
19958 /* We have an array type with specified bounds. */
19959 lower
= TYPE_MIN_VALUE (domain
);
19960 upper
= TYPE_MAX_VALUE (domain
);
19962 /* Define the index type. */
19963 if (TREE_TYPE (domain
)
19964 && !get_AT (subrange_die
, DW_AT_type
))
19966 /* ??? This is probably an Ada unnamed subrange type. Ignore the
19967 TREE_TYPE field. We can't emit debug info for this
19968 because it is an unnamed integral type. */
19969 if (TREE_CODE (domain
) == INTEGER_TYPE
19970 && TYPE_NAME (domain
) == NULL_TREE
19971 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
19972 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
19975 add_type_attribute (subrange_die
, TREE_TYPE (domain
),
19976 TYPE_UNQUALIFIED
, false, type_die
);
19979 /* ??? If upper is NULL, the array has unspecified length,
19980 but it does have a lower bound. This happens with Fortran
19982 Since the debugger is definitely going to need to know N
19983 to produce useful results, go ahead and output the lower
19984 bound solo, and hope the debugger can cope. */
19986 if (!get_AT (subrange_die
, DW_AT_lower_bound
))
19987 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
, NULL
);
19988 if (upper
&& !get_AT (subrange_die
, DW_AT_upper_bound
))
19989 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
, NULL
);
19992 /* Otherwise we have an array type with an unspecified length. The
19993 DWARF-2 spec does not say how to handle this; let's just leave out the
19998 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
20001 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
20003 dw_die_ref decl_die
;
20004 HOST_WIDE_INT size
;
20005 dw_loc_descr_ref size_expr
= NULL
;
20007 switch (TREE_CODE (tree_node
))
20012 case ENUMERAL_TYPE
:
20015 case QUAL_UNION_TYPE
:
20016 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
20017 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
20019 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
20022 size_expr
= type_byte_size (tree_node
, &size
);
20025 /* For a data member of a struct or union, the DW_AT_byte_size is
20026 generally given as the number of bytes normally allocated for an
20027 object of the *declared* type of the member itself. This is true
20028 even for bit-fields. */
20029 size
= int_size_in_bytes (field_type (tree_node
));
20032 gcc_unreachable ();
20035 /* Support for dynamically-sized objects was introduced by DWARFv3.
20036 At the moment, GDB does not handle variable byte sizes very well,
20038 if ((dwarf_version
>= 3 || !dwarf_strict
)
20039 && gnat_encodings
== DWARF_GNAT_ENCODINGS_MINIMAL
20040 && size_expr
!= NULL
)
20041 add_AT_loc (die
, DW_AT_byte_size
, size_expr
);
20043 /* Note that `size' might be -1 when we get to this point. If it is, that
20044 indicates that the byte size of the entity in question is variable and
20045 that we could not generate a DWARF expression that computes it. */
20047 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
20050 /* Add a DW_AT_alignment attribute to DIE with TREE_NODE's non-default
20054 add_alignment_attribute (dw_die_ref die
, tree tree_node
)
20056 if (dwarf_version
< 5 && dwarf_strict
)
20061 if (DECL_P (tree_node
))
20063 if (!DECL_USER_ALIGN (tree_node
))
20066 align
= DECL_ALIGN_UNIT (tree_node
);
20068 else if (TYPE_P (tree_node
))
20070 if (!TYPE_USER_ALIGN (tree_node
))
20073 align
= TYPE_ALIGN_UNIT (tree_node
);
20076 gcc_unreachable ();
20078 add_AT_unsigned (die
, DW_AT_alignment
, align
);
20081 /* For a FIELD_DECL node which represents a bit-field, output an attribute
20082 which specifies the distance in bits from the highest order bit of the
20083 "containing object" for the bit-field to the highest order bit of the
20086 For any given bit-field, the "containing object" is a hypothetical object
20087 (of some integral or enum type) within which the given bit-field lives. The
20088 type of this hypothetical "containing object" is always the same as the
20089 declared type of the individual bit-field itself. The determination of the
20090 exact location of the "containing object" for a bit-field is rather
20091 complicated. It's handled by the `field_byte_offset' function (above).
20093 CTX is required: see the comment for VLR_CONTEXT.
20095 Note that it is the size (in bytes) of the hypothetical "containing object"
20096 which will be given in the DW_AT_byte_size attribute for this bit-field.
20097 (See `byte_size_attribute' above). */
20100 add_bit_offset_attribute (dw_die_ref die
, tree decl
, struct vlr_context
*ctx
)
20102 HOST_WIDE_INT object_offset_in_bytes
;
20103 tree original_type
= DECL_BIT_FIELD_TYPE (decl
);
20104 HOST_WIDE_INT bitpos_int
;
20105 HOST_WIDE_INT highest_order_object_bit_offset
;
20106 HOST_WIDE_INT highest_order_field_bit_offset
;
20107 HOST_WIDE_INT bit_offset
;
20109 field_byte_offset (decl
, ctx
, &object_offset_in_bytes
);
20111 /* Must be a field and a bit field. */
20112 gcc_assert (original_type
&& TREE_CODE (decl
) == FIELD_DECL
);
20114 /* We can't yet handle bit-fields whose offsets are variable, so if we
20115 encounter such things, just return without generating any attribute
20116 whatsoever. Likewise for variable or too large size. */
20117 if (! tree_fits_shwi_p (bit_position (decl
))
20118 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
20121 bitpos_int
= int_bit_position (decl
);
20123 /* Note that the bit offset is always the distance (in bits) from the
20124 highest-order bit of the "containing object" to the highest-order bit of
20125 the bit-field itself. Since the "high-order end" of any object or field
20126 is different on big-endian and little-endian machines, the computation
20127 below must take account of these differences. */
20128 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
20129 highest_order_field_bit_offset
= bitpos_int
;
20131 if (! BYTES_BIG_ENDIAN
)
20133 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
20134 highest_order_object_bit_offset
+=
20135 simple_type_size_in_bits (original_type
);
20139 = (! BYTES_BIG_ENDIAN
20140 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
20141 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
20143 if (bit_offset
< 0)
20144 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
20146 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
20149 /* For a FIELD_DECL node which represents a bit field, output an attribute
20150 which specifies the length in bits of the given field. */
20153 add_bit_size_attribute (dw_die_ref die
, tree decl
)
20155 /* Must be a field and a bit field. */
20156 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
20157 && DECL_BIT_FIELD_TYPE (decl
));
20159 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
20160 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
20163 /* If the compiled language is ANSI C, then add a 'prototyped'
20164 attribute, if arg types are given for the parameters of a function. */
20167 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
20169 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
20176 if (prototype_p (func_type
))
20177 add_AT_flag (die
, DW_AT_prototyped
, 1);
20184 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
20185 by looking in the type declaration, the object declaration equate table or
20186 the block mapping. */
20188 static inline dw_die_ref
20189 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
20191 dw_die_ref origin_die
= NULL
;
20193 if (TREE_CODE (origin
) != FUNCTION_DECL
20194 && TREE_CODE (origin
) != BLOCK
)
20196 /* We may have gotten separated from the block for the inlined
20197 function, if we're in an exception handler or some such; make
20198 sure that the abstract function has been written out.
20200 Doing this for nested functions is wrong, however; functions are
20201 distinct units, and our context might not even be inline. */
20205 fn
= TYPE_STUB_DECL (fn
);
20207 fn
= decl_function_context (fn
);
20209 dwarf2out_abstract_function (fn
);
20212 if (DECL_P (origin
))
20213 origin_die
= lookup_decl_die (origin
);
20214 else if (TYPE_P (origin
))
20215 origin_die
= lookup_type_die (origin
);
20216 else if (TREE_CODE (origin
) == BLOCK
)
20217 origin_die
= BLOCK_DIE (origin
);
20219 /* XXX: Functions that are never lowered don't always have correct block
20220 trees (in the case of java, they simply have no block tree, in some other
20221 languages). For these functions, there is nothing we can really do to
20222 output correct debug info for inlined functions in all cases. Rather
20223 than die, we'll just produce deficient debug info now, in that we will
20224 have variables without a proper abstract origin. In the future, when all
20225 functions are lowered, we should re-add a gcc_assert (origin_die)
20229 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
20233 /* We do not currently support the pure_virtual attribute. */
20236 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
20238 if (DECL_VINDEX (func_decl
))
20240 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
20242 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
20243 add_AT_loc (die
, DW_AT_vtable_elem_location
,
20244 new_loc_descr (DW_OP_constu
,
20245 tree_to_shwi (DECL_VINDEX (func_decl
)),
20248 /* GNU extension: Record what type this method came from originally. */
20249 if (debug_info_level
> DINFO_LEVEL_TERSE
20250 && DECL_CONTEXT (func_decl
))
20251 add_AT_die_ref (die
, DW_AT_containing_type
,
20252 lookup_type_die (DECL_CONTEXT (func_decl
)));
20256 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
20257 given decl. This used to be a vendor extension until after DWARF 4
20258 standardized it. */
20261 add_linkage_attr (dw_die_ref die
, tree decl
)
20263 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
20265 /* Mimic what assemble_name_raw does with a leading '*'. */
20266 if (name
[0] == '*')
20269 if (dwarf_version
>= 4)
20270 add_AT_string (die
, DW_AT_linkage_name
, name
);
20272 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
20275 /* Add source coordinate attributes for the given decl. */
20278 add_src_coords_attributes (dw_die_ref die
, tree decl
)
20280 expanded_location s
;
20282 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
20284 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
20285 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
20286 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
20287 if (debug_column_info
&& s
.column
)
20288 add_AT_unsigned (die
, DW_AT_decl_column
, s
.column
);
20291 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
20294 add_linkage_name_raw (dw_die_ref die
, tree decl
)
20296 /* Defer until we have an assembler name set. */
20297 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
20299 limbo_die_node
*asm_name
;
20301 asm_name
= ggc_cleared_alloc
<limbo_die_node
> ();
20302 asm_name
->die
= die
;
20303 asm_name
->created_for
= decl
;
20304 asm_name
->next
= deferred_asm_name
;
20305 deferred_asm_name
= asm_name
;
20307 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
20308 add_linkage_attr (die
, decl
);
20311 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl if desired. */
20314 add_linkage_name (dw_die_ref die
, tree decl
)
20316 if (debug_info_level
> DINFO_LEVEL_NONE
20317 && VAR_OR_FUNCTION_DECL_P (decl
)
20318 && TREE_PUBLIC (decl
)
20319 && !(VAR_P (decl
) && DECL_REGISTER (decl
))
20320 && die
->die_tag
!= DW_TAG_member
)
20321 add_linkage_name_raw (die
, decl
);
20324 /* Add a DW_AT_name attribute and source coordinate attribute for the
20325 given decl, but only if it actually has a name. */
20328 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
,
20329 bool no_linkage_name
)
20333 decl_name
= DECL_NAME (decl
);
20334 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
20336 const char *name
= dwarf2_name (decl
, 0);
20338 add_name_attribute (die
, name
);
20339 if (! DECL_ARTIFICIAL (decl
))
20340 add_src_coords_attributes (die
, decl
);
20342 if (!no_linkage_name
)
20343 add_linkage_name (die
, decl
);
20346 #ifdef VMS_DEBUGGING_INFO
20347 /* Get the function's name, as described by its RTL. This may be different
20348 from the DECL_NAME name used in the source file. */
20349 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
20351 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
20352 XEXP (DECL_RTL (decl
), 0), false);
20353 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
20355 #endif /* VMS_DEBUGGING_INFO */
20358 /* Add VALUE as a DW_AT_discr_value attribute to DIE. */
20361 add_discr_value (dw_die_ref die
, dw_discr_value
*value
)
20365 attr
.dw_attr
= DW_AT_discr_value
;
20366 attr
.dw_attr_val
.val_class
= dw_val_class_discr_value
;
20367 attr
.dw_attr_val
.val_entry
= NULL
;
20368 attr
.dw_attr_val
.v
.val_discr_value
.pos
= value
->pos
;
20370 attr
.dw_attr_val
.v
.val_discr_value
.v
.uval
= value
->v
.uval
;
20372 attr
.dw_attr_val
.v
.val_discr_value
.v
.sval
= value
->v
.sval
;
20373 add_dwarf_attr (die
, &attr
);
20376 /* Add DISCR_LIST as a DW_AT_discr_list to DIE. */
20379 add_discr_list (dw_die_ref die
, dw_discr_list_ref discr_list
)
20383 attr
.dw_attr
= DW_AT_discr_list
;
20384 attr
.dw_attr_val
.val_class
= dw_val_class_discr_list
;
20385 attr
.dw_attr_val
.val_entry
= NULL
;
20386 attr
.dw_attr_val
.v
.val_discr_list
= discr_list
;
20387 add_dwarf_attr (die
, &attr
);
20390 static inline dw_discr_list_ref
20391 AT_discr_list (dw_attr_node
*attr
)
20393 return attr
->dw_attr_val
.v
.val_discr_list
;
20396 #ifdef VMS_DEBUGGING_INFO
20397 /* Output the debug main pointer die for VMS */
20400 dwarf2out_vms_debug_main_pointer (void)
20402 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20405 /* Allocate the VMS debug main subprogram die. */
20406 die
= ggc_cleared_alloc
<die_node
> ();
20407 die
->die_tag
= DW_TAG_subprogram
;
20408 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
20409 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
20410 current_function_funcdef_no
);
20411 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
20413 /* Make it the first child of comp_unit_die (). */
20414 die
->die_parent
= comp_unit_die ();
20415 if (comp_unit_die ()->die_child
)
20417 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
20418 comp_unit_die ()->die_child
->die_sib
= die
;
20422 die
->die_sib
= die
;
20423 comp_unit_die ()->die_child
= die
;
20426 #endif /* VMS_DEBUGGING_INFO */
20428 /* Push a new declaration scope. */
20431 push_decl_scope (tree scope
)
20433 vec_safe_push (decl_scope_table
, scope
);
20436 /* Pop a declaration scope. */
20439 pop_decl_scope (void)
20441 decl_scope_table
->pop ();
20444 /* walk_tree helper function for uses_local_type, below. */
20447 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
20450 *walk_subtrees
= 0;
20453 tree name
= TYPE_NAME (*tp
);
20454 if (name
&& DECL_P (name
) && decl_function_context (name
))
20460 /* If TYPE involves a function-local type (including a local typedef to a
20461 non-local type), returns that type; otherwise returns NULL_TREE. */
20464 uses_local_type (tree type
)
20466 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
20470 /* Return the DIE for the scope that immediately contains this type.
20471 Non-named types that do not involve a function-local type get global
20472 scope. Named types nested in namespaces or other types get their
20473 containing scope. All other types (i.e. function-local named types) get
20474 the current active scope. */
20477 scope_die_for (tree t
, dw_die_ref context_die
)
20479 dw_die_ref scope_die
= NULL
;
20480 tree containing_scope
;
20482 /* Non-types always go in the current scope. */
20483 gcc_assert (TYPE_P (t
));
20485 /* Use the scope of the typedef, rather than the scope of the type
20487 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
20488 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
20490 containing_scope
= TYPE_CONTEXT (t
);
20492 /* Use the containing namespace if there is one. */
20493 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
20495 if (context_die
== lookup_decl_die (containing_scope
))
20497 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
20498 context_die
= get_context_die (containing_scope
);
20500 containing_scope
= NULL_TREE
;
20503 /* Ignore function type "scopes" from the C frontend. They mean that
20504 a tagged type is local to a parmlist of a function declarator, but
20505 that isn't useful to DWARF. */
20506 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
20507 containing_scope
= NULL_TREE
;
20509 if (SCOPE_FILE_SCOPE_P (containing_scope
))
20511 /* If T uses a local type keep it local as well, to avoid references
20512 to function-local DIEs from outside the function. */
20513 if (current_function_decl
&& uses_local_type (t
))
20514 scope_die
= context_die
;
20516 scope_die
= comp_unit_die ();
20518 else if (TYPE_P (containing_scope
))
20520 /* For types, we can just look up the appropriate DIE. */
20521 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20522 scope_die
= get_context_die (containing_scope
);
20525 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
20526 if (scope_die
== NULL
)
20527 scope_die
= comp_unit_die ();
20531 scope_die
= context_die
;
20536 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
20539 local_scope_p (dw_die_ref context_die
)
20541 for (; context_die
; context_die
= context_die
->die_parent
)
20542 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
20543 || context_die
->die_tag
== DW_TAG_subprogram
)
20549 /* Returns nonzero if CONTEXT_DIE is a class. */
20552 class_scope_p (dw_die_ref context_die
)
20554 return (context_die
20555 && (context_die
->die_tag
== DW_TAG_structure_type
20556 || context_die
->die_tag
== DW_TAG_class_type
20557 || context_die
->die_tag
== DW_TAG_interface_type
20558 || context_die
->die_tag
== DW_TAG_union_type
));
20561 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
20562 whether or not to treat a DIE in this context as a declaration. */
20565 class_or_namespace_scope_p (dw_die_ref context_die
)
20567 return (class_scope_p (context_die
)
20568 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
20571 /* Many forms of DIEs require a "type description" attribute. This
20572 routine locates the proper "type descriptor" die for the type given
20573 by 'type' plus any additional qualifiers given by 'cv_quals', and
20574 adds a DW_AT_type attribute below the given die. */
20577 add_type_attribute (dw_die_ref object_die
, tree type
, int cv_quals
,
20578 bool reverse
, dw_die_ref context_die
)
20580 enum tree_code code
= TREE_CODE (type
);
20581 dw_die_ref type_die
= NULL
;
20583 /* ??? If this type is an unnamed subrange type of an integral, floating-point
20584 or fixed-point type, use the inner type. This is because we have no
20585 support for unnamed types in base_type_die. This can happen if this is
20586 an Ada subrange type. Correct solution is emit a subrange type die. */
20587 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
20588 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
20589 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
20591 if (code
== ERROR_MARK
20592 /* Handle a special case. For functions whose return type is void, we
20593 generate *no* type attribute. (Note that no object may have type
20594 `void', so this only applies to function return types). */
20595 || code
== VOID_TYPE
)
20598 type_die
= modified_type_die (type
,
20599 cv_quals
| TYPE_QUALS_NO_ADDR_SPACE (type
),
20603 if (type_die
!= NULL
)
20604 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
20607 /* Given an object die, add the calling convention attribute for the
20608 function call type. */
20610 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
20612 enum dwarf_calling_convention value
= DW_CC_normal
;
20614 value
= ((enum dwarf_calling_convention
)
20615 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
20618 && id_equal (DECL_ASSEMBLER_NAME (decl
), "MAIN__"))
20620 /* DWARF 2 doesn't provide a way to identify a program's source-level
20621 entry point. DW_AT_calling_convention attributes are only meant
20622 to describe functions' calling conventions. However, lacking a
20623 better way to signal the Fortran main program, we used this for
20624 a long time, following existing custom. Now, DWARF 4 has
20625 DW_AT_main_subprogram, which we add below, but some tools still
20626 rely on the old way, which we thus keep. */
20627 value
= DW_CC_program
;
20629 if (dwarf_version
>= 4 || !dwarf_strict
)
20630 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
20633 /* Only add the attribute if the backend requests it, and
20634 is not DW_CC_normal. */
20635 if (value
&& (value
!= DW_CC_normal
))
20636 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
20639 /* Given a tree pointer to a struct, class, union, or enum type node, return
20640 a pointer to the (string) tag name for the given type, or zero if the type
20641 was declared without a tag. */
20643 static const char *
20644 type_tag (const_tree type
)
20646 const char *name
= 0;
20648 if (TYPE_NAME (type
) != 0)
20652 /* Find the IDENTIFIER_NODE for the type name. */
20653 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
20654 && !TYPE_NAMELESS (type
))
20655 t
= TYPE_NAME (type
);
20657 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
20658 a TYPE_DECL node, regardless of whether or not a `typedef' was
20660 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
20661 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
20663 /* We want to be extra verbose. Don't call dwarf_name if
20664 DECL_NAME isn't set. The default hook for decl_printable_name
20665 doesn't like that, and in this context it's correct to return
20666 0, instead of "<anonymous>" or the like. */
20667 if (DECL_NAME (TYPE_NAME (type
))
20668 && !DECL_NAMELESS (TYPE_NAME (type
)))
20669 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
20672 /* Now get the name as a string, or invent one. */
20673 if (!name
&& t
!= 0)
20674 name
= IDENTIFIER_POINTER (t
);
20677 return (name
== 0 || *name
== '\0') ? 0 : name
;
20680 /* Return the type associated with a data member, make a special check
20681 for bit field types. */
20684 member_declared_type (const_tree member
)
20686 return (DECL_BIT_FIELD_TYPE (member
)
20687 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
20690 /* Get the decl's label, as described by its RTL. This may be different
20691 from the DECL_NAME name used in the source file. */
20694 static const char *
20695 decl_start_label (tree decl
)
20698 const char *fnname
;
20700 x
= DECL_RTL (decl
);
20701 gcc_assert (MEM_P (x
));
20704 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
20706 fnname
= XSTR (x
, 0);
20711 /* For variable-length arrays that have been previously generated, but
20712 may be incomplete due to missing subscript info, fill the subscript
20713 info. Return TRUE if this is one of those cases. */
20715 fill_variable_array_bounds (tree type
)
20717 if (TREE_ASM_WRITTEN (type
)
20718 && TREE_CODE (type
) == ARRAY_TYPE
20719 && variably_modified_type_p (type
, NULL
))
20721 dw_die_ref array_die
= lookup_type_die (type
);
20724 add_subscript_info (array_die
, type
, !is_ada ());
20730 /* These routines generate the internal representation of the DIE's for
20731 the compilation unit. Debugging information is collected by walking
20732 the declaration trees passed in from dwarf2out_decl(). */
20735 gen_array_type_die (tree type
, dw_die_ref context_die
)
20737 dw_die_ref array_die
;
20739 /* GNU compilers represent multidimensional array types as sequences of one
20740 dimensional array types whose element types are themselves array types.
20741 We sometimes squish that down to a single array_type DIE with multiple
20742 subscripts in the Dwarf debugging info. The draft Dwarf specification
20743 say that we are allowed to do this kind of compression in C, because
20744 there is no difference between an array of arrays and a multidimensional
20745 array. We don't do this for Ada to remain as close as possible to the
20746 actual representation, which is especially important against the language
20747 flexibilty wrt arrays of variable size. */
20749 bool collapse_nested_arrays
= !is_ada ();
20751 if (fill_variable_array_bounds (type
))
20754 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
20757 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
20758 DW_TAG_string_type doesn't have DW_AT_type attribute). */
20759 if (TYPE_STRING_FLAG (type
)
20760 && TREE_CODE (type
) == ARRAY_TYPE
20762 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
20764 HOST_WIDE_INT size
;
20766 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
20767 add_name_attribute (array_die
, type_tag (type
));
20768 equate_type_number_to_die (type
, array_die
);
20769 size
= int_size_in_bytes (type
);
20771 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
20772 else if (TYPE_DOMAIN (type
) != NULL_TREE
20773 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
)
20775 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
20776 tree rszdecl
= szdecl
;
20778 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
20779 if (!DECL_P (szdecl
))
20781 if (TREE_CODE (szdecl
) == INDIRECT_REF
20782 && DECL_P (TREE_OPERAND (szdecl
, 0)))
20784 rszdecl
= TREE_OPERAND (szdecl
, 0);
20785 if (int_size_in_bytes (TREE_TYPE (rszdecl
))
20786 != DWARF2_ADDR_SIZE
)
20794 dw_loc_list_ref loc
20795 = loc_list_from_tree (rszdecl
, szdecl
== rszdecl
? 2 : 0,
20799 add_AT_location_description (array_die
, DW_AT_string_length
,
20801 if (size
!= DWARF2_ADDR_SIZE
)
20802 add_AT_unsigned (array_die
, dwarf_version
>= 5
20803 ? DW_AT_string_length_byte_size
20804 : DW_AT_byte_size
, size
);
20811 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
20812 add_name_attribute (array_die
, type_tag (type
));
20813 equate_type_number_to_die (type
, array_die
);
20815 if (TREE_CODE (type
) == VECTOR_TYPE
)
20816 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
20818 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
20820 && TREE_CODE (type
) == ARRAY_TYPE
20821 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
20822 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
20823 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
20826 /* We default the array ordering. SDB will probably do
20827 the right things even if DW_AT_ordering is not present. It's not even
20828 an issue until we start to get into multidimensional arrays anyway. If
20829 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
20830 then we'll have to put the DW_AT_ordering attribute back in. (But if
20831 and when we find out that we need to put these in, we will only do so
20832 for multidimensional arrays. */
20833 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
20836 if (TREE_CODE (type
) == VECTOR_TYPE
)
20838 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
20839 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
20840 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
, NULL
);
20841 add_bound_info (subrange_die
, DW_AT_upper_bound
,
20842 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1), NULL
);
20845 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
20847 /* Add representation of the type of the elements of this array type and
20848 emit the corresponding DIE if we haven't done it already. */
20849 element_type
= TREE_TYPE (type
);
20850 if (collapse_nested_arrays
)
20851 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
20853 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
20855 element_type
= TREE_TYPE (element_type
);
20858 add_type_attribute (array_die
, element_type
, TYPE_UNQUALIFIED
,
20859 TREE_CODE (type
) == ARRAY_TYPE
20860 && TYPE_REVERSE_STORAGE_ORDER (type
),
20863 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
20864 if (TYPE_ARTIFICIAL (type
))
20865 add_AT_flag (array_die
, DW_AT_artificial
, 1);
20867 if (get_AT (array_die
, DW_AT_name
))
20868 add_pubtype (type
, array_die
);
20870 add_alignment_attribute (array_die
, type
);
20873 /* This routine generates DIE for array with hidden descriptor, details
20874 are filled into *info by a langhook. */
20877 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
20878 dw_die_ref context_die
)
20880 const dw_die_ref scope_die
= scope_die_for (type
, context_die
);
20881 const dw_die_ref array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
20882 struct loc_descr_context context
= { type
, info
->base_decl
, NULL
,
20884 enum dwarf_tag subrange_tag
= DW_TAG_subrange_type
;
20887 add_name_attribute (array_die
, type_tag (type
));
20888 equate_type_number_to_die (type
, array_die
);
20890 if (info
->ndimensions
> 1)
20891 switch (info
->ordering
)
20893 case array_descr_ordering_row_major
:
20894 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
20896 case array_descr_ordering_column_major
:
20897 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
20903 if (dwarf_version
>= 3 || !dwarf_strict
)
20905 if (info
->data_location
)
20906 add_scalar_info (array_die
, DW_AT_data_location
, info
->data_location
,
20907 dw_scalar_form_exprloc
, &context
);
20908 if (info
->associated
)
20909 add_scalar_info (array_die
, DW_AT_associated
, info
->associated
,
20910 dw_scalar_form_constant
20911 | dw_scalar_form_exprloc
20912 | dw_scalar_form_reference
, &context
);
20913 if (info
->allocated
)
20914 add_scalar_info (array_die
, DW_AT_allocated
, info
->allocated
,
20915 dw_scalar_form_constant
20916 | dw_scalar_form_exprloc
20917 | dw_scalar_form_reference
, &context
);
20920 const enum dwarf_attribute attr
20921 = (info
->stride_in_bits
) ? DW_AT_bit_stride
: DW_AT_byte_stride
;
20923 = (info
->stride_in_bits
)
20924 ? dw_scalar_form_constant
20925 : (dw_scalar_form_constant
20926 | dw_scalar_form_exprloc
20927 | dw_scalar_form_reference
);
20929 add_scalar_info (array_die
, attr
, info
->stride
, forms
, &context
);
20932 if (dwarf_version
>= 5)
20936 add_scalar_info (array_die
, DW_AT_rank
, info
->rank
,
20937 dw_scalar_form_constant
20938 | dw_scalar_form_exprloc
, &context
);
20939 subrange_tag
= DW_TAG_generic_subrange
;
20940 context
.placeholder_arg
= true;
20944 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
20946 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
20948 dw_die_ref subrange_die
= new_die (subrange_tag
, array_die
, NULL
);
20950 if (info
->dimen
[dim
].bounds_type
)
20951 add_type_attribute (subrange_die
,
20952 info
->dimen
[dim
].bounds_type
, TYPE_UNQUALIFIED
,
20953 false, context_die
);
20954 if (info
->dimen
[dim
].lower_bound
)
20955 add_bound_info (subrange_die
, DW_AT_lower_bound
,
20956 info
->dimen
[dim
].lower_bound
, &context
);
20957 if (info
->dimen
[dim
].upper_bound
)
20958 add_bound_info (subrange_die
, DW_AT_upper_bound
,
20959 info
->dimen
[dim
].upper_bound
, &context
);
20960 if ((dwarf_version
>= 3 || !dwarf_strict
) && info
->dimen
[dim
].stride
)
20961 add_scalar_info (subrange_die
, DW_AT_byte_stride
,
20962 info
->dimen
[dim
].stride
,
20963 dw_scalar_form_constant
20964 | dw_scalar_form_exprloc
20965 | dw_scalar_form_reference
,
20969 gen_type_die (info
->element_type
, context_die
);
20970 add_type_attribute (array_die
, info
->element_type
, TYPE_UNQUALIFIED
,
20971 TREE_CODE (type
) == ARRAY_TYPE
20972 && TYPE_REVERSE_STORAGE_ORDER (type
),
20975 if (get_AT (array_die
, DW_AT_name
))
20976 add_pubtype (type
, array_die
);
20978 add_alignment_attribute (array_die
, type
);
20983 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
20985 tree origin
= decl_ultimate_origin (decl
);
20986 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
20988 if (origin
!= NULL
)
20989 add_abstract_origin_attribute (decl_die
, origin
);
20992 add_name_and_src_coords_attributes (decl_die
, decl
);
20993 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
20994 TYPE_UNQUALIFIED
, false, context_die
);
20997 if (DECL_ABSTRACT_P (decl
))
20998 equate_decl_number_to_die (decl
, decl_die
);
21000 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
21004 /* Walk through the list of incomplete types again, trying once more to
21005 emit full debugging info for them. */
21008 retry_incomplete_types (void)
21013 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
21014 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
21015 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
21016 vec_safe_truncate (incomplete_types
, 0);
21019 /* Determine what tag to use for a record type. */
21021 static enum dwarf_tag
21022 record_type_tag (tree type
)
21024 if (! lang_hooks
.types
.classify_record
)
21025 return DW_TAG_structure_type
;
21027 switch (lang_hooks
.types
.classify_record (type
))
21029 case RECORD_IS_STRUCT
:
21030 return DW_TAG_structure_type
;
21032 case RECORD_IS_CLASS
:
21033 return DW_TAG_class_type
;
21035 case RECORD_IS_INTERFACE
:
21036 if (dwarf_version
>= 3 || !dwarf_strict
)
21037 return DW_TAG_interface_type
;
21038 return DW_TAG_structure_type
;
21041 gcc_unreachable ();
21045 /* Generate a DIE to represent an enumeration type. Note that these DIEs
21046 include all of the information about the enumeration values also. Each
21047 enumerated type name/value is listed as a child of the enumerated type
21051 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
21053 dw_die_ref type_die
= lookup_type_die (type
);
21055 if (type_die
== NULL
)
21057 type_die
= new_die (DW_TAG_enumeration_type
,
21058 scope_die_for (type
, context_die
), type
);
21059 equate_type_number_to_die (type
, type_die
);
21060 add_name_attribute (type_die
, type_tag (type
));
21061 if (dwarf_version
>= 4 || !dwarf_strict
)
21063 if (ENUM_IS_SCOPED (type
))
21064 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
21065 if (ENUM_IS_OPAQUE (type
))
21066 add_AT_flag (type_die
, DW_AT_declaration
, 1);
21069 add_AT_unsigned (type_die
, DW_AT_encoding
,
21070 TYPE_UNSIGNED (type
)
21074 else if (! TYPE_SIZE (type
))
21077 remove_AT (type_die
, DW_AT_declaration
);
21079 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
21080 given enum type is incomplete, do not generate the DW_AT_byte_size
21081 attribute or the DW_AT_element_list attribute. */
21082 if (TYPE_SIZE (type
))
21086 TREE_ASM_WRITTEN (type
) = 1;
21087 add_byte_size_attribute (type_die
, type
);
21088 add_alignment_attribute (type_die
, type
);
21089 if (dwarf_version
>= 3 || !dwarf_strict
)
21091 tree underlying
= lang_hooks
.types
.enum_underlying_base_type (type
);
21092 add_type_attribute (type_die
, underlying
, TYPE_UNQUALIFIED
, false,
21095 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
21097 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
21098 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
21101 /* If the first reference to this type was as the return type of an
21102 inline function, then it may not have a parent. Fix this now. */
21103 if (type_die
->die_parent
== NULL
)
21104 add_child_die (scope_die_for (type
, context_die
), type_die
);
21106 for (link
= TYPE_VALUES (type
);
21107 link
!= NULL
; link
= TREE_CHAIN (link
))
21109 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
21110 tree value
= TREE_VALUE (link
);
21112 add_name_attribute (enum_die
,
21113 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
21115 if (TREE_CODE (value
) == CONST_DECL
)
21116 value
= DECL_INITIAL (value
);
21118 if (simple_type_size_in_bits (TREE_TYPE (value
))
21119 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
21121 /* For constant forms created by add_AT_unsigned DWARF
21122 consumers (GDB, elfutils, etc.) always zero extend
21123 the value. Only when the actual value is negative
21124 do we need to use add_AT_int to generate a constant
21125 form that can represent negative values. */
21126 HOST_WIDE_INT val
= TREE_INT_CST_LOW (value
);
21127 if (TYPE_UNSIGNED (TREE_TYPE (value
)) || val
>= 0)
21128 add_AT_unsigned (enum_die
, DW_AT_const_value
,
21129 (unsigned HOST_WIDE_INT
) val
);
21131 add_AT_int (enum_die
, DW_AT_const_value
, val
);
21134 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
21135 that here. TODO: This should be re-worked to use correct
21136 signed/unsigned double tags for all cases. */
21137 add_AT_wide (enum_die
, DW_AT_const_value
, value
);
21140 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
21141 if (TYPE_ARTIFICIAL (type
))
21142 add_AT_flag (type_die
, DW_AT_artificial
, 1);
21145 add_AT_flag (type_die
, DW_AT_declaration
, 1);
21147 add_alignment_attribute (type_die
, type
);
21149 add_pubtype (type
, type_die
);
21154 /* Generate a DIE to represent either a real live formal parameter decl or to
21155 represent just the type of some formal parameter position in some function
21158 Note that this routine is a bit unusual because its argument may be a
21159 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
21160 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
21161 node. If it's the former then this function is being called to output a
21162 DIE to represent a formal parameter object (or some inlining thereof). If
21163 it's the latter, then this function is only being called to output a
21164 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
21165 argument type of some subprogram type.
21166 If EMIT_NAME_P is true, name and source coordinate attributes
21170 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
21171 dw_die_ref context_die
)
21173 tree node_or_origin
= node
? node
: origin
;
21174 tree ultimate_origin
;
21175 dw_die_ref parm_die
= NULL
;
21177 if (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)) == tcc_declaration
)
21179 parm_die
= lookup_decl_die (node
);
21181 /* If the contexts differ, we may not be talking about the same
21183 if (parm_die
&& parm_die
->die_parent
!= context_die
)
21185 if (!DECL_ABSTRACT_P (node
))
21187 /* This can happen when creating an inlined instance, in
21188 which case we need to create a new DIE that will get
21189 annotated with DW_AT_abstract_origin. */
21194 /* FIXME: Reuse DIE even with a differing context.
21196 This can happen when calling
21197 dwarf2out_abstract_function to build debug info for
21198 the abstract instance of a function for which we have
21199 already generated a DIE in
21200 dwarf2out_early_global_decl.
21202 Once we remove dwarf2out_abstract_function, we should
21203 have a call to gcc_unreachable here. */
21207 if (parm_die
&& parm_die
->die_parent
== NULL
)
21209 /* Check that parm_die already has the right attributes that
21210 we would have added below. If any attributes are
21211 missing, fall through to add them. */
21212 if (! DECL_ABSTRACT_P (node_or_origin
)
21213 && !get_AT (parm_die
, DW_AT_location
)
21214 && !get_AT (parm_die
, DW_AT_const_value
))
21215 /* We are missing location info, and are about to add it. */
21219 add_child_die (context_die
, parm_die
);
21225 /* If we have a previously generated DIE, use it, unless this is an
21226 concrete instance (origin != NULL), in which case we need a new
21227 DIE with a corresponding DW_AT_abstract_origin. */
21229 if (parm_die
&& origin
== NULL
)
21230 reusing_die
= true;
21233 parm_die
= new_die (DW_TAG_formal_parameter
, context_die
, node
);
21234 reusing_die
= false;
21237 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
21239 case tcc_declaration
:
21240 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
21241 if (node
|| ultimate_origin
)
21242 origin
= ultimate_origin
;
21247 if (origin
!= NULL
)
21248 add_abstract_origin_attribute (parm_die
, origin
);
21249 else if (emit_name_p
)
21250 add_name_and_src_coords_attributes (parm_die
, node
);
21252 || (! DECL_ABSTRACT_P (node_or_origin
)
21253 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
21254 decl_function_context
21255 (node_or_origin
))))
21257 tree type
= TREE_TYPE (node_or_origin
);
21258 if (decl_by_reference_p (node_or_origin
))
21259 add_type_attribute (parm_die
, TREE_TYPE (type
),
21261 false, context_die
);
21263 add_type_attribute (parm_die
, type
,
21264 decl_quals (node_or_origin
),
21265 false, context_die
);
21267 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
21268 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
21270 if (node
&& node
!= origin
)
21271 equate_decl_number_to_die (node
, parm_die
);
21272 if (! DECL_ABSTRACT_P (node_or_origin
))
21273 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
21279 /* We were called with some kind of a ..._TYPE node. */
21280 add_type_attribute (parm_die
, node_or_origin
, TYPE_UNQUALIFIED
, false,
21285 gcc_unreachable ();
21291 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
21292 children DW_TAG_formal_parameter DIEs representing the arguments of the
21295 PARM_PACK must be a function parameter pack.
21296 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
21297 must point to the subsequent arguments of the function PACK_ARG belongs to.
21298 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
21299 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
21300 following the last one for which a DIE was generated. */
21303 gen_formal_parameter_pack_die (tree parm_pack
,
21305 dw_die_ref subr_die
,
21309 dw_die_ref parm_pack_die
;
21311 gcc_assert (parm_pack
21312 && lang_hooks
.function_parameter_pack_p (parm_pack
)
21315 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
21316 add_src_coords_attributes (parm_pack_die
, parm_pack
);
21318 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
21320 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
21323 gen_formal_parameter_die (arg
, NULL
,
21324 false /* Don't emit name attribute. */,
21329 return parm_pack_die
;
21332 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
21333 at the end of an (ANSI prototyped) formal parameters list. */
21336 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
21338 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
21341 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
21342 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
21343 parameters as specified in some function type specification (except for
21344 those which appear as part of a function *definition*). */
21347 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
21350 tree formal_type
= NULL
;
21351 tree first_parm_type
;
21354 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
21356 arg
= DECL_ARGUMENTS (function_or_method_type
);
21357 function_or_method_type
= TREE_TYPE (function_or_method_type
);
21362 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
21364 /* Make our first pass over the list of formal parameter types and output a
21365 DW_TAG_formal_parameter DIE for each one. */
21366 for (link
= first_parm_type
; link
; )
21368 dw_die_ref parm_die
;
21370 formal_type
= TREE_VALUE (link
);
21371 if (formal_type
== void_type_node
)
21374 /* Output a (nameless) DIE to represent the formal parameter itself. */
21375 if (!POINTER_BOUNDS_TYPE_P (formal_type
))
21377 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
21378 true /* Emit name attribute. */,
21380 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
21381 && link
== first_parm_type
)
21383 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
21384 if (dwarf_version
>= 3 || !dwarf_strict
)
21385 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
21387 else if (arg
&& DECL_ARTIFICIAL (arg
))
21388 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
21391 link
= TREE_CHAIN (link
);
21393 arg
= DECL_CHAIN (arg
);
21396 /* If this function type has an ellipsis, add a
21397 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
21398 if (formal_type
!= void_type_node
)
21399 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
21401 /* Make our second (and final) pass over the list of formal parameter types
21402 and output DIEs to represent those types (as necessary). */
21403 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
21404 link
&& TREE_VALUE (link
);
21405 link
= TREE_CHAIN (link
))
21406 gen_type_die (TREE_VALUE (link
), context_die
);
21409 /* We want to generate the DIE for TYPE so that we can generate the
21410 die for MEMBER, which has been defined; we will need to refer back
21411 to the member declaration nested within TYPE. If we're trying to
21412 generate minimal debug info for TYPE, processing TYPE won't do the
21413 trick; we need to attach the member declaration by hand. */
21416 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
21418 gen_type_die (type
, context_die
);
21420 /* If we're trying to avoid duplicate debug info, we may not have
21421 emitted the member decl for this function. Emit it now. */
21422 if (TYPE_STUB_DECL (type
)
21423 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
21424 && ! lookup_decl_die (member
))
21426 dw_die_ref type_die
;
21427 gcc_assert (!decl_ultimate_origin (member
));
21429 push_decl_scope (type
);
21430 type_die
= lookup_type_die_strip_naming_typedef (type
);
21431 if (TREE_CODE (member
) == FUNCTION_DECL
)
21432 gen_subprogram_die (member
, type_die
);
21433 else if (TREE_CODE (member
) == FIELD_DECL
)
21435 /* Ignore the nameless fields that are used to skip bits but handle
21436 C++ anonymous unions and structs. */
21437 if (DECL_NAME (member
) != NULL_TREE
21438 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
21439 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
21441 struct vlr_context vlr_ctx
= {
21442 DECL_CONTEXT (member
), /* struct_type */
21443 NULL_TREE
/* variant_part_offset */
21445 gen_type_die (member_declared_type (member
), type_die
);
21446 gen_field_die (member
, &vlr_ctx
, type_die
);
21450 gen_variable_die (member
, NULL_TREE
, type_die
);
21456 /* Forward declare these functions, because they are mutually recursive
21457 with their set_block_* pairing functions. */
21458 static void set_decl_origin_self (tree
);
21459 static void set_decl_abstract_flags (tree
, vec
<tree
> &);
21461 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
21462 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
21463 that it points to the node itself, thus indicating that the node is its
21464 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
21465 the given node is NULL, recursively descend the decl/block tree which
21466 it is the root of, and for each other ..._DECL or BLOCK node contained
21467 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
21468 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
21469 values to point to themselves. */
21472 set_block_origin_self (tree stmt
)
21474 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
21476 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
21481 for (local_decl
= BLOCK_VARS (stmt
);
21482 local_decl
!= NULL_TREE
;
21483 local_decl
= DECL_CHAIN (local_decl
))
21484 /* Do not recurse on nested functions since the inlining status
21485 of parent and child can be different as per the DWARF spec. */
21486 if (TREE_CODE (local_decl
) != FUNCTION_DECL
21487 && !DECL_EXTERNAL (local_decl
))
21488 set_decl_origin_self (local_decl
);
21494 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
21495 subblock
!= NULL_TREE
;
21496 subblock
= BLOCK_CHAIN (subblock
))
21497 set_block_origin_self (subblock
); /* Recurse. */
21502 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
21503 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
21504 node to so that it points to the node itself, thus indicating that the
21505 node represents its own (abstract) origin. Additionally, if the
21506 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
21507 the decl/block tree of which the given node is the root of, and for
21508 each other ..._DECL or BLOCK node contained therein whose
21509 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
21510 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
21511 point to themselves. */
21514 set_decl_origin_self (tree decl
)
21516 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
21518 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
21519 if (TREE_CODE (decl
) == FUNCTION_DECL
)
21523 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
21524 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
21525 if (DECL_INITIAL (decl
) != NULL_TREE
21526 && DECL_INITIAL (decl
) != error_mark_node
)
21527 set_block_origin_self (DECL_INITIAL (decl
));
21532 /* Given a pointer to some BLOCK node, set the BLOCK_ABSTRACT flag to 1
21533 and if it wasn't 1 before, push it to abstract_vec vector.
21534 For all local decls and all local sub-blocks (recursively) do it
21538 set_block_abstract_flags (tree stmt
, vec
<tree
> &abstract_vec
)
21544 if (!BLOCK_ABSTRACT (stmt
))
21546 abstract_vec
.safe_push (stmt
);
21547 BLOCK_ABSTRACT (stmt
) = 1;
21550 for (local_decl
= BLOCK_VARS (stmt
);
21551 local_decl
!= NULL_TREE
;
21552 local_decl
= DECL_CHAIN (local_decl
))
21553 if (! DECL_EXTERNAL (local_decl
))
21554 set_decl_abstract_flags (local_decl
, abstract_vec
);
21556 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
21558 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
21559 if ((VAR_P (local_decl
) && !TREE_STATIC (local_decl
))
21560 || TREE_CODE (local_decl
) == PARM_DECL
)
21561 set_decl_abstract_flags (local_decl
, abstract_vec
);
21564 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
21565 subblock
!= NULL_TREE
;
21566 subblock
= BLOCK_CHAIN (subblock
))
21567 set_block_abstract_flags (subblock
, abstract_vec
);
21570 /* Given a pointer to some ..._DECL node, set DECL_ABSTRACT_P flag on it
21571 to 1 and if it wasn't 1 before, push to abstract_vec vector.
21572 In the case where the decl is a FUNCTION_DECL also set the abstract
21573 flags for all of the parameters, local vars, local
21574 blocks and sub-blocks (recursively). */
21577 set_decl_abstract_flags (tree decl
, vec
<tree
> &abstract_vec
)
21579 if (!DECL_ABSTRACT_P (decl
))
21581 abstract_vec
.safe_push (decl
);
21582 DECL_ABSTRACT_P (decl
) = 1;
21585 if (TREE_CODE (decl
) == FUNCTION_DECL
)
21589 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
21590 if (!DECL_ABSTRACT_P (arg
))
21592 abstract_vec
.safe_push (arg
);
21593 DECL_ABSTRACT_P (arg
) = 1;
21595 if (DECL_INITIAL (decl
) != NULL_TREE
21596 && DECL_INITIAL (decl
) != error_mark_node
)
21597 set_block_abstract_flags (DECL_INITIAL (decl
), abstract_vec
);
21601 /* Generate the DWARF2 info for the "abstract" instance of a function which we
21602 may later generate inlined and/or out-of-line instances of.
21604 FIXME: In the early-dwarf world, this function, and most of the
21605 DECL_ABSTRACT code should be obsoleted. The early DIE _is_
21606 the abstract instance. All we would need to do is annotate
21607 the early DIE with the appropriate DW_AT_inline in late
21608 dwarf (perhaps in gen_inlined_subroutine_die).
21610 However, we can't do this yet, because LTO streaming of DIEs
21611 has not been implemented yet. */
21614 dwarf2out_abstract_function (tree decl
)
21616 dw_die_ref old_die
;
21619 hash_table
<decl_loc_hasher
> *old_decl_loc_table
;
21620 hash_table
<dw_loc_list_hasher
> *old_cached_dw_loc_list_table
;
21621 int old_call_site_count
, old_tail_call_site_count
;
21622 struct call_arg_loc_node
*old_call_arg_locations
;
21624 /* Make sure we have the actual abstract inline, not a clone. */
21625 decl
= DECL_ORIGIN (decl
);
21627 old_die
= lookup_decl_die (decl
);
21628 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
21629 /* We've already generated the abstract instance. */
21632 /* We can be called while recursively when seeing block defining inlined subroutine
21633 DIE. Be sure to not clobber the outer location table nor use it or we would
21634 get locations in abstract instantces. */
21635 old_decl_loc_table
= decl_loc_table
;
21636 decl_loc_table
= NULL
;
21637 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
21638 cached_dw_loc_list_table
= NULL
;
21639 old_call_arg_locations
= call_arg_locations
;
21640 call_arg_locations
= NULL
;
21641 old_call_site_count
= call_site_count
;
21642 call_site_count
= -1;
21643 old_tail_call_site_count
= tail_call_site_count
;
21644 tail_call_site_count
= -1;
21646 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
21647 we don't get confused by DECL_ABSTRACT_P. */
21648 if (debug_info_level
> DINFO_LEVEL_TERSE
)
21650 context
= decl_class_context (decl
);
21652 gen_type_die_for_member
21653 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
21656 /* Pretend we've just finished compiling this function. */
21657 save_fn
= current_function_decl
;
21658 current_function_decl
= decl
;
21660 auto_vec
<tree
, 64> abstract_vec
;
21661 set_decl_abstract_flags (decl
, abstract_vec
);
21662 dwarf2out_decl (decl
);
21665 FOR_EACH_VEC_ELT (abstract_vec
, i
, t
)
21666 if (TREE_CODE (t
) == BLOCK
)
21667 BLOCK_ABSTRACT (t
) = 0;
21669 DECL_ABSTRACT_P (t
) = 0;
21671 current_function_decl
= save_fn
;
21672 decl_loc_table
= old_decl_loc_table
;
21673 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
21674 call_arg_locations
= old_call_arg_locations
;
21675 call_site_count
= old_call_site_count
;
21676 tail_call_site_count
= old_tail_call_site_count
;
21679 /* Helper function of premark_used_types() which gets called through
21682 Marks the DIE of a given type in *SLOT as perennial, so it never gets
21683 marked as unused by prune_unused_types. */
21686 premark_used_types_helper (tree
const &type
, void *)
21690 die
= lookup_type_die (type
);
21692 die
->die_perennial_p
= 1;
21696 /* Helper function of premark_types_used_by_global_vars which gets called
21697 through htab_traverse.
21699 Marks the DIE of a given type in *SLOT as perennial, so it never gets
21700 marked as unused by prune_unused_types. The DIE of the type is marked
21701 only if the global variable using the type will actually be emitted. */
21704 premark_types_used_by_global_vars_helper (types_used_by_vars_entry
**slot
,
21707 struct types_used_by_vars_entry
*entry
;
21710 entry
= (struct types_used_by_vars_entry
*) *slot
;
21711 gcc_assert (entry
->type
!= NULL
21712 && entry
->var_decl
!= NULL
);
21713 die
= lookup_type_die (entry
->type
);
21716 /* Ask cgraph if the global variable really is to be emitted.
21717 If yes, then we'll keep the DIE of ENTRY->TYPE. */
21718 varpool_node
*node
= varpool_node::get (entry
->var_decl
);
21719 if (node
&& node
->definition
)
21721 die
->die_perennial_p
= 1;
21722 /* Keep the parent DIEs as well. */
21723 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
21724 die
->die_perennial_p
= 1;
21730 /* Mark all members of used_types_hash as perennial. */
21733 premark_used_types (struct function
*fun
)
21735 if (fun
&& fun
->used_types_hash
)
21736 fun
->used_types_hash
->traverse
<void *, premark_used_types_helper
> (NULL
);
21739 /* Mark all members of types_used_by_vars_entry as perennial. */
21742 premark_types_used_by_global_vars (void)
21744 if (types_used_by_vars_hash
)
21745 types_used_by_vars_hash
21746 ->traverse
<void *, premark_types_used_by_global_vars_helper
> (NULL
);
21749 /* Generate a DW_TAG_call_site DIE in function DECL under SUBR_DIE
21750 for CA_LOC call arg loc node. */
21753 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
21754 struct call_arg_loc_node
*ca_loc
)
21756 dw_die_ref stmt_die
= NULL
, die
;
21757 tree block
= ca_loc
->block
;
21760 && block
!= DECL_INITIAL (decl
)
21761 && TREE_CODE (block
) == BLOCK
)
21763 stmt_die
= BLOCK_DIE (block
);
21766 block
= BLOCK_SUPERCONTEXT (block
);
21768 if (stmt_die
== NULL
)
21769 stmt_die
= subr_die
;
21770 die
= new_die (dwarf_TAG (DW_TAG_call_site
), stmt_die
, NULL_TREE
);
21771 add_AT_lbl_id (die
, dwarf_AT (DW_AT_call_return_pc
), ca_loc
->label
);
21772 if (ca_loc
->tail_call_p
)
21773 add_AT_flag (die
, dwarf_AT (DW_AT_call_tail_call
), 1);
21774 if (ca_loc
->symbol_ref
)
21776 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
21778 add_AT_die_ref (die
, dwarf_AT (DW_AT_call_origin
), tdie
);
21780 add_AT_addr (die
, dwarf_AT (DW_AT_call_origin
), ca_loc
->symbol_ref
,
21786 /* Generate a DIE to represent a declared function (either file-scope or
21790 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
21792 tree origin
= decl_ultimate_origin (decl
);
21793 dw_die_ref subr_die
;
21794 dw_die_ref old_die
= lookup_decl_die (decl
);
21796 /* This function gets called multiple times for different stages of
21797 the debug process. For example, for func() in this code:
21801 void func() { ... }
21804 ...we get called 4 times. Twice in early debug and twice in
21810 1. Once while generating func() within the namespace. This is
21811 the declaration. The declaration bit below is set, as the
21812 context is the namespace.
21814 A new DIE will be generated with DW_AT_declaration set.
21816 2. Once for func() itself. This is the specification. The
21817 declaration bit below is clear as the context is the CU.
21819 We will use the cached DIE from (1) to create a new DIE with
21820 DW_AT_specification pointing to the declaration in (1).
21822 Late debug via rest_of_handle_final()
21823 -------------------------------------
21825 3. Once generating func() within the namespace. This is also the
21826 declaration, as in (1), but this time we will early exit below
21827 as we have a cached DIE and a declaration needs no additional
21828 annotations (no locations), as the source declaration line
21831 4. Once for func() itself. As in (2), this is the specification,
21832 but this time we will re-use the cached DIE, and just annotate
21833 it with the location information that should now be available.
21835 For something without namespaces, but with abstract instances, we
21836 are also called a multiple times:
21841 Base (); // constructor declaration (1)
21844 Base::Base () { } // constructor specification (2)
21849 1. Once for the Base() constructor by virtue of it being a
21850 member of the Base class. This is done via
21851 rest_of_type_compilation.
21853 This is a declaration, so a new DIE will be created with
21856 2. Once for the Base() constructor definition, but this time
21857 while generating the abstract instance of the base
21858 constructor (__base_ctor) which is being generated via early
21859 debug of reachable functions.
21861 Even though we have a cached version of the declaration (1),
21862 we will create a DW_AT_specification of the declaration DIE
21865 3. Once for the __base_ctor itself, but this time, we generate
21866 an DW_AT_abstract_origin version of the DW_AT_specification in
21869 Late debug via rest_of_handle_final
21870 -----------------------------------
21872 4. One final time for the __base_ctor (which will have a cached
21873 DIE with DW_AT_abstract_origin created in (3). This time,
21874 we will just annotate the location information now
21877 int declaration
= (current_function_decl
!= decl
21878 || class_or_namespace_scope_p (context_die
));
21880 /* Now that the C++ front end lazily declares artificial member fns, we
21881 might need to retrofit the declaration into its class. */
21882 if (!declaration
&& !origin
&& !old_die
21883 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
21884 && !class_or_namespace_scope_p (context_die
)
21885 && debug_info_level
> DINFO_LEVEL_TERSE
)
21886 old_die
= force_decl_die (decl
);
21888 /* An inlined instance, tag a new DIE with DW_AT_abstract_origin. */
21889 if (origin
!= NULL
)
21891 gcc_assert (!declaration
|| local_scope_p (context_die
));
21893 /* Fixup die_parent for the abstract instance of a nested
21894 inline function. */
21895 if (old_die
&& old_die
->die_parent
== NULL
)
21896 add_child_die (context_die
, old_die
);
21898 if (old_die
&& get_AT_ref (old_die
, DW_AT_abstract_origin
))
21900 /* If we have a DW_AT_abstract_origin we have a working
21902 subr_die
= old_die
;
21906 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
21907 add_abstract_origin_attribute (subr_die
, origin
);
21908 /* This is where the actual code for a cloned function is.
21909 Let's emit linkage name attribute for it. This helps
21910 debuggers to e.g, set breakpoints into
21911 constructors/destructors when the user asks "break
21913 add_linkage_name (subr_die
, decl
);
21916 /* A cached copy, possibly from early dwarf generation. Reuse as
21917 much as possible. */
21920 /* A declaration that has been previously dumped needs no
21921 additional information. */
21925 if (!get_AT_flag (old_die
, DW_AT_declaration
)
21926 /* We can have a normal definition following an inline one in the
21927 case of redefinition of GNU C extern inlines.
21928 It seems reasonable to use AT_specification in this case. */
21929 && !get_AT (old_die
, DW_AT_inline
))
21931 /* Detect and ignore this case, where we are trying to output
21932 something we have already output. */
21933 if (get_AT (old_die
, DW_AT_low_pc
)
21934 || get_AT (old_die
, DW_AT_ranges
))
21937 /* If we have no location information, this must be a
21938 partially generated DIE from early dwarf generation.
21939 Fall through and generate it. */
21942 /* If the definition comes from the same place as the declaration,
21943 maybe use the old DIE. We always want the DIE for this function
21944 that has the *_pc attributes to be under comp_unit_die so the
21945 debugger can find it. We also need to do this for abstract
21946 instances of inlines, since the spec requires the out-of-line copy
21947 to have the same parent. For local class methods, this doesn't
21948 apply; we just use the old DIE. */
21949 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
21950 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
21951 if ((is_cu_die (old_die
->die_parent
)
21952 /* This condition fixes the inconsistency/ICE with the
21953 following Fortran test (or some derivative thereof) while
21954 building libgfortran:
21958 logical function funky (FLAG)
21963 || (old_die
->die_parent
21964 && old_die
->die_parent
->die_tag
== DW_TAG_module
)
21965 || context_die
== NULL
)
21966 && (DECL_ARTIFICIAL (decl
)
21967 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
21968 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
21969 == (unsigned) s
.line
)
21970 && (!debug_column_info
21972 || (get_AT_unsigned (old_die
, DW_AT_decl_column
)
21973 == (unsigned) s
.column
)))))
21975 subr_die
= old_die
;
21977 /* Clear out the declaration attribute, but leave the
21978 parameters so they can be augmented with location
21979 information later. Unless this was a declaration, in
21980 which case, wipe out the nameless parameters and recreate
21981 them further down. */
21982 if (remove_AT (subr_die
, DW_AT_declaration
))
21985 remove_AT (subr_die
, DW_AT_object_pointer
);
21986 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
21989 /* Make a specification pointing to the previously built
21993 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
21994 add_AT_specification (subr_die
, old_die
);
21995 add_pubname (decl
, subr_die
);
21996 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
21997 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
21998 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
21999 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
22000 if (debug_column_info
22002 && (get_AT_unsigned (old_die
, DW_AT_decl_column
)
22003 != (unsigned) s
.column
))
22004 add_AT_unsigned (subr_die
, DW_AT_decl_column
, s
.column
);
22006 /* If the prototype had an 'auto' or 'decltype(auto)' return type,
22007 emit the real type on the definition die. */
22008 if (is_cxx () && debug_info_level
> DINFO_LEVEL_TERSE
)
22010 dw_die_ref die
= get_AT_ref (old_die
, DW_AT_type
);
22011 if (die
== auto_die
|| die
== decltype_auto_die
)
22012 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
22013 TYPE_UNQUALIFIED
, false, context_die
);
22016 /* When we process the method declaration, we haven't seen
22017 the out-of-class defaulted definition yet, so we have to
22019 if ((dwarf_version
>= 5 || ! dwarf_strict
)
22020 && !get_AT (subr_die
, DW_AT_defaulted
))
22023 = lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22025 if (defaulted
!= -1)
22027 /* Other values must have been handled before. */
22028 gcc_assert (defaulted
== DW_DEFAULTED_out_of_class
);
22029 add_AT_unsigned (subr_die
, DW_AT_defaulted
, defaulted
);
22034 /* Create a fresh DIE for anything else. */
22037 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
22039 if (TREE_PUBLIC (decl
))
22040 add_AT_flag (subr_die
, DW_AT_external
, 1);
22042 add_name_and_src_coords_attributes (subr_die
, decl
);
22043 add_pubname (decl
, subr_die
);
22044 if (debug_info_level
> DINFO_LEVEL_TERSE
)
22046 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
22047 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
22048 TYPE_UNQUALIFIED
, false, context_die
);
22051 add_pure_or_virtual_attribute (subr_die
, decl
);
22052 if (DECL_ARTIFICIAL (decl
))
22053 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
22055 if (TREE_THIS_VOLATILE (decl
) && (dwarf_version
>= 5 || !dwarf_strict
))
22056 add_AT_flag (subr_die
, DW_AT_noreturn
, 1);
22058 add_alignment_attribute (subr_die
, decl
);
22060 add_accessibility_attribute (subr_die
, decl
);
22063 /* Unless we have an existing non-declaration DIE, equate the new
22065 if (!old_die
|| is_declaration_die (old_die
))
22066 equate_decl_number_to_die (decl
, subr_die
);
22070 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
22072 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
22074 /* If this is an explicit function declaration then generate
22075 a DW_AT_explicit attribute. */
22076 if ((dwarf_version
>= 3 || !dwarf_strict
)
22077 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22078 DW_AT_explicit
) == 1)
22079 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
22081 /* If this is a C++11 deleted special function member then generate
22082 a DW_AT_deleted attribute. */
22083 if ((dwarf_version
>= 5 || !dwarf_strict
)
22084 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22085 DW_AT_deleted
) == 1)
22086 add_AT_flag (subr_die
, DW_AT_deleted
, 1);
22088 /* If this is a C++11 defaulted special function member then
22089 generate a DW_AT_defaulted attribute. */
22090 if (dwarf_version
>= 5 || !dwarf_strict
)
22093 = lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22095 if (defaulted
!= -1)
22096 add_AT_unsigned (subr_die
, DW_AT_defaulted
, defaulted
);
22099 /* If this is a C++11 non-static member function with & ref-qualifier
22100 then generate a DW_AT_reference attribute. */
22101 if ((dwarf_version
>= 5 || !dwarf_strict
)
22102 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22103 DW_AT_reference
) == 1)
22104 add_AT_flag (subr_die
, DW_AT_reference
, 1);
22106 /* If this is a C++11 non-static member function with &&
22107 ref-qualifier then generate a DW_AT_reference attribute. */
22108 if ((dwarf_version
>= 5 || !dwarf_strict
)
22109 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
22110 DW_AT_rvalue_reference
)
22112 add_AT_flag (subr_die
, DW_AT_rvalue_reference
, 1);
22115 /* Tag abstract instances with DW_AT_inline. */
22116 else if (DECL_ABSTRACT_P (decl
))
22118 if (DECL_DECLARED_INLINE_P (decl
))
22120 if (cgraph_function_possibly_inlined_p (decl
))
22121 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
22123 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
22127 if (cgraph_function_possibly_inlined_p (decl
))
22128 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
22130 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
22133 if (DECL_DECLARED_INLINE_P (decl
)
22134 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
22135 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
22137 /* For non DECL_EXTERNALs, if range information is available, fill
22138 the DIE with it. */
22139 else if (!DECL_EXTERNAL (decl
) && !early_dwarf
)
22141 HOST_WIDE_INT cfa_fb_offset
;
22143 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
22145 if (!crtl
->has_bb_partition
)
22147 dw_fde_ref fde
= fun
->fde
;
22148 if (fde
->dw_fde_begin
)
22150 /* We have already generated the labels. */
22151 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
22152 fde
->dw_fde_end
, false);
22156 /* Create start/end labels and add the range. */
22157 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
22158 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
22159 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
22160 current_function_funcdef_no
);
22161 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
22162 current_function_funcdef_no
);
22163 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
22167 #if VMS_DEBUGGING_INFO
22168 /* HP OpenVMS Industry Standard 64: DWARF Extensions
22169 Section 2.3 Prologue and Epilogue Attributes:
22170 When a breakpoint is set on entry to a function, it is generally
22171 desirable for execution to be suspended, not on the very first
22172 instruction of the function, but rather at a point after the
22173 function's frame has been set up, after any language defined local
22174 declaration processing has been completed, and before execution of
22175 the first statement of the function begins. Debuggers generally
22176 cannot properly determine where this point is. Similarly for a
22177 breakpoint set on exit from a function. The prologue and epilogue
22178 attributes allow a compiler to communicate the location(s) to use. */
22181 if (fde
->dw_fde_vms_end_prologue
)
22182 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
22183 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
22185 if (fde
->dw_fde_vms_begin_epilogue
)
22186 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
22187 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
22194 /* Generate pubnames entries for the split function code ranges. */
22195 dw_fde_ref fde
= fun
->fde
;
22197 if (fde
->dw_fde_second_begin
)
22199 if (dwarf_version
>= 3 || !dwarf_strict
)
22201 /* We should use ranges for non-contiguous code section
22202 addresses. Use the actual code range for the initial
22203 section, since the HOT/COLD labels might precede an
22204 alignment offset. */
22205 bool range_list_added
= false;
22206 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
22207 fde
->dw_fde_end
, &range_list_added
,
22209 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
22210 fde
->dw_fde_second_end
,
22211 &range_list_added
, false);
22212 if (range_list_added
)
22217 /* There is no real support in DW2 for this .. so we make
22218 a work-around. First, emit the pub name for the segment
22219 containing the function label. Then make and emit a
22220 simplified subprogram DIE for the second segment with the
22221 name pre-fixed by __hot/cold_sect_of_. We use the same
22222 linkage name for the second die so that gdb will find both
22223 sections when given "b foo". */
22224 const char *name
= NULL
;
22225 tree decl_name
= DECL_NAME (decl
);
22226 dw_die_ref seg_die
;
22228 /* Do the 'primary' section. */
22229 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
22230 fde
->dw_fde_end
, false);
22232 /* Build a minimal DIE for the secondary section. */
22233 seg_die
= new_die (DW_TAG_subprogram
,
22234 subr_die
->die_parent
, decl
);
22236 if (TREE_PUBLIC (decl
))
22237 add_AT_flag (seg_die
, DW_AT_external
, 1);
22239 if (decl_name
!= NULL
22240 && IDENTIFIER_POINTER (decl_name
) != NULL
)
22242 name
= dwarf2_name (decl
, 1);
22243 if (! DECL_ARTIFICIAL (decl
))
22244 add_src_coords_attributes (seg_die
, decl
);
22246 add_linkage_name (seg_die
, decl
);
22248 gcc_assert (name
!= NULL
);
22249 add_pure_or_virtual_attribute (seg_die
, decl
);
22250 if (DECL_ARTIFICIAL (decl
))
22251 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
22253 name
= concat ("__second_sect_of_", name
, NULL
);
22254 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
22255 fde
->dw_fde_second_end
, false);
22256 add_name_attribute (seg_die
, name
);
22257 if (want_pubnames ())
22258 add_pubname_string (name
, seg_die
);
22262 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
22266 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
22268 /* We define the "frame base" as the function's CFA. This is more
22269 convenient for several reasons: (1) It's stable across the prologue
22270 and epilogue, which makes it better than just a frame pointer,
22271 (2) With dwarf3, there exists a one-byte encoding that allows us
22272 to reference the .debug_frame data by proxy, but failing that,
22273 (3) We can at least reuse the code inspection and interpretation
22274 code that determines the CFA position at various points in the
22276 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
22278 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
22279 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
22283 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
22284 if (list
->dw_loc_next
)
22285 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
22287 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
22290 /* Compute a displacement from the "steady-state frame pointer" to
22291 the CFA. The former is what all stack slots and argument slots
22292 will reference in the rtl; the latter is what we've told the
22293 debugger about. We'll need to adjust all frame_base references
22294 by this displacement. */
22295 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
22297 if (fun
->static_chain_decl
)
22299 /* DWARF requires here a location expression that computes the
22300 address of the enclosing subprogram's frame base. The machinery
22301 in tree-nested.c is supposed to store this specific address in the
22302 last field of the FRAME record. */
22303 const tree frame_type
22304 = TREE_TYPE (TREE_TYPE (fun
->static_chain_decl
));
22305 const tree fb_decl
= tree_last (TYPE_FIELDS (frame_type
));
22308 = build1 (INDIRECT_REF
, frame_type
, fun
->static_chain_decl
);
22309 fb_expr
= build3 (COMPONENT_REF
, TREE_TYPE (fb_decl
),
22310 fb_expr
, fb_decl
, NULL_TREE
);
22312 add_AT_location_description (subr_die
, DW_AT_static_link
,
22313 loc_list_from_tree (fb_expr
, 0, NULL
));
22316 resolve_variable_values ();
22319 /* Generate child dies for template paramaters. */
22320 if (early_dwarf
&& debug_info_level
> DINFO_LEVEL_TERSE
)
22321 gen_generic_params_dies (decl
);
22323 /* Now output descriptions of the arguments for this function. This gets
22324 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
22325 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
22326 `...' at the end of the formal parameter list. In order to find out if
22327 there was a trailing ellipsis or not, we must instead look at the type
22328 associated with the FUNCTION_DECL. This will be a node of type
22329 FUNCTION_TYPE. If the chain of type nodes hanging off of this
22330 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
22331 an ellipsis at the end. */
22333 /* In the case where we are describing a mere function declaration, all we
22334 need to do here (and all we *can* do here) is to describe the *types* of
22335 its formal parameters. */
22336 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
22338 else if (declaration
)
22339 gen_formal_types_die (decl
, subr_die
);
22342 /* Generate DIEs to represent all known formal parameters. */
22343 tree parm
= DECL_ARGUMENTS (decl
);
22344 tree generic_decl
= early_dwarf
22345 ? lang_hooks
.decls
.get_generic_function_decl (decl
) : NULL
;
22346 tree generic_decl_parm
= generic_decl
22347 ? DECL_ARGUMENTS (generic_decl
)
22350 /* Now we want to walk the list of parameters of the function and
22351 emit their relevant DIEs.
22353 We consider the case of DECL being an instance of a generic function
22354 as well as it being a normal function.
22356 If DECL is an instance of a generic function we walk the
22357 parameters of the generic function declaration _and_ the parameters of
22358 DECL itself. This is useful because we want to emit specific DIEs for
22359 function parameter packs and those are declared as part of the
22360 generic function declaration. In that particular case,
22361 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
22362 That DIE has children DIEs representing the set of arguments
22363 of the pack. Note that the set of pack arguments can be empty.
22364 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
22367 Otherwise, we just consider the parameters of DECL. */
22368 while (generic_decl_parm
|| parm
)
22370 if (generic_decl_parm
22371 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
22372 gen_formal_parameter_pack_die (generic_decl_parm
,
22375 else if (parm
&& !POINTER_BOUNDS_P (parm
))
22377 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, NULL
, subr_die
);
22379 if (parm
== DECL_ARGUMENTS (decl
)
22380 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
22382 && (dwarf_version
>= 3 || !dwarf_strict
))
22383 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
22385 parm
= DECL_CHAIN (parm
);
22388 parm
= DECL_CHAIN (parm
);
22390 if (generic_decl_parm
)
22391 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
22394 /* Decide whether we need an unspecified_parameters DIE at the end.
22395 There are 2 more cases to do this for: 1) the ansi ... declaration -
22396 this is detectable when the end of the arg list is not a
22397 void_type_node 2) an unprototyped function declaration (not a
22398 definition). This just means that we have no info about the
22399 parameters at all. */
22402 if (prototype_p (TREE_TYPE (decl
)))
22404 /* This is the prototyped case, check for.... */
22405 if (stdarg_p (TREE_TYPE (decl
)))
22406 gen_unspecified_parameters_die (decl
, subr_die
);
22408 else if (DECL_INITIAL (decl
) == NULL_TREE
)
22409 gen_unspecified_parameters_die (decl
, subr_die
);
22413 if (subr_die
!= old_die
)
22414 /* Add the calling convention attribute if requested. */
22415 add_calling_convention_attribute (subr_die
, decl
);
22417 /* Output Dwarf info for all of the stuff within the body of the function
22418 (if it has one - it may be just a declaration).
22420 OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
22421 a function. This BLOCK actually represents the outermost binding contour
22422 for the function, i.e. the contour in which the function's formal
22423 parameters and labels get declared. Curiously, it appears that the front
22424 end doesn't actually put the PARM_DECL nodes for the current function onto
22425 the BLOCK_VARS list for this outer scope, but are strung off of the
22426 DECL_ARGUMENTS list for the function instead.
22428 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
22429 the LABEL_DECL nodes for the function however, and we output DWARF info
22430 for those in decls_for_scope. Just within the `outer_scope' there will be
22431 a BLOCK node representing the function's outermost pair of curly braces,
22432 and any blocks used for the base and member initializers of a C++
22433 constructor function. */
22434 tree outer_scope
= DECL_INITIAL (decl
);
22435 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
22437 int call_site_note_count
= 0;
22438 int tail_call_site_note_count
= 0;
22440 /* Emit a DW_TAG_variable DIE for a named return value. */
22441 if (DECL_NAME (DECL_RESULT (decl
)))
22442 gen_decl_die (DECL_RESULT (decl
), NULL
, NULL
, subr_die
);
22444 /* The first time through decls_for_scope we will generate the
22445 DIEs for the locals. The second time, we fill in the
22447 decls_for_scope (outer_scope
, subr_die
);
22449 if (call_arg_locations
&& (!dwarf_strict
|| dwarf_version
>= 5))
22451 struct call_arg_loc_node
*ca_loc
;
22452 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
22454 dw_die_ref die
= NULL
;
22455 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
22458 for (arg
= (ca_loc
->call_arg_loc_note
!= NULL_RTX
22459 ? NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
)
22461 arg
; arg
= next_arg
)
22463 dw_loc_descr_ref reg
, val
;
22464 machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
22465 dw_die_ref cdie
, tdie
= NULL
;
22467 next_arg
= XEXP (arg
, 1);
22468 if (REG_P (XEXP (XEXP (arg
, 0), 0))
22470 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
22471 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
22472 && REGNO (XEXP (XEXP (arg
, 0), 0))
22473 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
22474 next_arg
= XEXP (next_arg
, 1);
22475 if (mode
== VOIDmode
)
22477 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
22478 if (mode
== VOIDmode
)
22479 mode
= GET_MODE (XEXP (arg
, 0));
22481 if (mode
== VOIDmode
|| mode
== BLKmode
)
22483 /* Get dynamic information about call target only if we
22484 have no static information: we cannot generate both
22485 DW_AT_call_origin and DW_AT_call_target
22487 if (ca_loc
->symbol_ref
== NULL_RTX
)
22489 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
22491 tloc
= XEXP (XEXP (arg
, 0), 1);
22494 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
22495 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
22497 tlocc
= XEXP (XEXP (arg
, 0), 1);
22502 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
22503 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
22504 VAR_INIT_STATUS_INITIALIZED
);
22505 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
22507 rtx mem
= XEXP (XEXP (arg
, 0), 0);
22508 reg
= mem_loc_descriptor (XEXP (mem
, 0),
22509 get_address_mode (mem
),
22511 VAR_INIT_STATUS_INITIALIZED
);
22513 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
22514 == DEBUG_PARAMETER_REF
)
22517 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
22518 tdie
= lookup_decl_die (tdecl
);
22525 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
22526 != DEBUG_PARAMETER_REF
)
22528 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
22530 VAR_INIT_STATUS_INITIALIZED
);
22534 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
22535 cdie
= new_die (dwarf_TAG (DW_TAG_call_site_parameter
), die
,
22538 add_AT_loc (cdie
, DW_AT_location
, reg
);
22539 else if (tdie
!= NULL
)
22540 add_AT_die_ref (cdie
, dwarf_AT (DW_AT_call_parameter
),
22542 add_AT_loc (cdie
, dwarf_AT (DW_AT_call_value
), val
);
22543 if (next_arg
!= XEXP (arg
, 1))
22545 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
22546 if (mode
== VOIDmode
)
22547 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
22548 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
22551 VAR_INIT_STATUS_INITIALIZED
);
22553 add_AT_loc (cdie
, dwarf_AT (DW_AT_call_data_value
),
22558 && (ca_loc
->symbol_ref
|| tloc
))
22559 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
22560 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
22562 dw_loc_descr_ref tval
= NULL
;
22564 if (tloc
!= NULL_RTX
)
22565 tval
= mem_loc_descriptor (tloc
,
22566 GET_MODE (tloc
) == VOIDmode
22567 ? Pmode
: GET_MODE (tloc
),
22569 VAR_INIT_STATUS_INITIALIZED
);
22571 add_AT_loc (die
, dwarf_AT (DW_AT_call_target
), tval
);
22572 else if (tlocc
!= NULL_RTX
)
22574 tval
= mem_loc_descriptor (tlocc
,
22575 GET_MODE (tlocc
) == VOIDmode
22576 ? Pmode
: GET_MODE (tlocc
),
22578 VAR_INIT_STATUS_INITIALIZED
);
22581 dwarf_AT (DW_AT_call_target_clobbered
),
22587 call_site_note_count
++;
22588 if (ca_loc
->tail_call_p
)
22589 tail_call_site_note_count
++;
22593 call_arg_locations
= NULL
;
22594 call_arg_loc_last
= NULL
;
22595 if (tail_call_site_count
>= 0
22596 && tail_call_site_count
== tail_call_site_note_count
22597 && (!dwarf_strict
|| dwarf_version
>= 5))
22599 if (call_site_count
>= 0
22600 && call_site_count
== call_site_note_count
)
22601 add_AT_flag (subr_die
, dwarf_AT (DW_AT_call_all_calls
), 1);
22603 add_AT_flag (subr_die
, dwarf_AT (DW_AT_call_all_tail_calls
), 1);
22605 call_site_count
= -1;
22606 tail_call_site_count
= -1;
22609 /* Mark used types after we have created DIEs for the functions scopes. */
22610 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
22613 /* Returns a hash value for X (which really is a die_struct). */
22616 block_die_hasher::hash (die_struct
*d
)
22618 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
22621 /* Return nonzero if decl_id and die_parent of die_struct X is the same
22622 as decl_id and die_parent of die_struct Y. */
22625 block_die_hasher::equal (die_struct
*x
, die_struct
*y
)
22627 return x
->decl_id
== y
->decl_id
&& x
->die_parent
== y
->die_parent
;
22630 /* Return TRUE if DECL, which may have been previously generated as
22631 OLD_DIE, is a candidate for a DW_AT_specification. DECLARATION is
22632 true if decl (or its origin) is either an extern declaration or a
22633 class/namespace scoped declaration.
22635 The declare_in_namespace support causes us to get two DIEs for one
22636 variable, both of which are declarations. We want to avoid
22637 considering one to be a specification, so we must test for
22638 DECLARATION and DW_AT_declaration. */
22640 decl_will_get_specification_p (dw_die_ref old_die
, tree decl
, bool declaration
)
22642 return (old_die
&& TREE_STATIC (decl
) && !declaration
22643 && get_AT_flag (old_die
, DW_AT_declaration
) == 1);
22646 /* Return true if DECL is a local static. */
22649 local_function_static (tree decl
)
22651 gcc_assert (VAR_P (decl
));
22652 return TREE_STATIC (decl
)
22653 && DECL_CONTEXT (decl
)
22654 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
;
22657 /* Generate a DIE to represent a declared data object.
22658 Either DECL or ORIGIN must be non-null. */
22661 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
22663 HOST_WIDE_INT off
= 0;
22665 tree decl_or_origin
= decl
? decl
: origin
;
22666 tree ultimate_origin
;
22667 dw_die_ref var_die
;
22668 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
22669 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
22670 || class_or_namespace_scope_p (context_die
));
22671 bool specialization_p
= false;
22672 bool no_linkage_name
= false;
22674 /* While C++ inline static data members have definitions inside of the
22675 class, force the first DIE to be a declaration, then let gen_member_die
22676 reparent it to the class context and call gen_variable_die again
22677 to create the outside of the class DIE for the definition. */
22681 && DECL_CONTEXT (decl
)
22682 && TYPE_P (DECL_CONTEXT (decl
))
22683 && lang_hooks
.decls
.decl_dwarf_attribute (decl
, DW_AT_inline
) != -1)
22685 declaration
= true;
22686 if (dwarf_version
< 5)
22687 no_linkage_name
= true;
22690 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
22691 if (decl
|| ultimate_origin
)
22692 origin
= ultimate_origin
;
22693 com_decl
= fortran_common (decl_or_origin
, &off
);
22695 /* Symbol in common gets emitted as a child of the common block, in the form
22696 of a data member. */
22699 dw_die_ref com_die
;
22700 dw_loc_list_ref loc
= NULL
;
22701 die_node com_die_arg
;
22703 var_die
= lookup_decl_die (decl_or_origin
);
22706 if (! early_dwarf
&& get_AT (var_die
, DW_AT_location
) == NULL
)
22708 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2, NULL
);
22713 /* Optimize the common case. */
22714 if (single_element_loc_list_p (loc
)
22715 && loc
->expr
->dw_loc_opc
== DW_OP_addr
22716 && loc
->expr
->dw_loc_next
== NULL
22717 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
22720 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
22721 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
22722 = plus_constant (GET_MODE (x
), x
, off
);
22725 loc_list_plus_const (loc
, off
);
22727 add_AT_location_description (var_die
, DW_AT_location
, loc
);
22728 remove_AT (var_die
, DW_AT_declaration
);
22734 if (common_block_die_table
== NULL
)
22735 common_block_die_table
= hash_table
<block_die_hasher
>::create_ggc (10);
22737 com_die_arg
.decl_id
= DECL_UID (com_decl
);
22738 com_die_arg
.die_parent
= context_die
;
22739 com_die
= common_block_die_table
->find (&com_die_arg
);
22741 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
22742 if (com_die
== NULL
)
22745 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
22748 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
22749 add_name_and_src_coords_attributes (com_die
, com_decl
);
22752 add_AT_location_description (com_die
, DW_AT_location
, loc
);
22753 /* Avoid sharing the same loc descriptor between
22754 DW_TAG_common_block and DW_TAG_variable. */
22755 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
22757 else if (DECL_EXTERNAL (decl_or_origin
))
22758 add_AT_flag (com_die
, DW_AT_declaration
, 1);
22759 if (want_pubnames ())
22760 add_pubname_string (cnam
, com_die
); /* ??? needed? */
22761 com_die
->decl_id
= DECL_UID (com_decl
);
22762 slot
= common_block_die_table
->find_slot (com_die
, INSERT
);
22765 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
22767 add_AT_location_description (com_die
, DW_AT_location
, loc
);
22768 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
22769 remove_AT (com_die
, DW_AT_declaration
);
22771 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
22772 add_name_and_src_coords_attributes (var_die
, decl_or_origin
);
22773 add_type_attribute (var_die
, TREE_TYPE (decl_or_origin
),
22774 decl_quals (decl_or_origin
), false,
22776 add_alignment_attribute (var_die
, decl
);
22777 add_AT_flag (var_die
, DW_AT_external
, 1);
22782 /* Optimize the common case. */
22783 if (single_element_loc_list_p (loc
)
22784 && loc
->expr
->dw_loc_opc
== DW_OP_addr
22785 && loc
->expr
->dw_loc_next
== NULL
22786 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
22788 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
22789 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
22790 = plus_constant (GET_MODE (x
), x
, off
);
22793 loc_list_plus_const (loc
, off
);
22795 add_AT_location_description (var_die
, DW_AT_location
, loc
);
22797 else if (DECL_EXTERNAL (decl_or_origin
))
22798 add_AT_flag (var_die
, DW_AT_declaration
, 1);
22800 equate_decl_number_to_die (decl
, var_die
);
22808 /* A declaration that has been previously dumped, needs no
22809 further annotations, since it doesn't need location on
22810 the second pass. */
22813 else if (decl_will_get_specification_p (old_die
, decl
, declaration
)
22814 && !get_AT (old_die
, DW_AT_specification
))
22816 /* Fall-thru so we can make a new variable die along with a
22817 DW_AT_specification. */
22819 else if (origin
&& old_die
->die_parent
!= context_die
)
22821 /* If we will be creating an inlined instance, we need a
22822 new DIE that will get annotated with
22823 DW_AT_abstract_origin. Clear things so we can get a
22825 gcc_assert (!DECL_ABSTRACT_P (decl
));
22830 /* If a DIE was dumped early, it still needs location info.
22831 Skip to where we fill the location bits. */
22833 goto gen_variable_die_location
;
22837 /* For static data members, the declaration in the class is supposed
22838 to have DW_TAG_member tag in DWARF{3,4} and we emit it for compatibility
22839 also in DWARF2; the specification should still be DW_TAG_variable
22840 referencing the DW_TAG_member DIE. */
22841 if (declaration
&& class_scope_p (context_die
) && dwarf_version
< 5)
22842 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
22844 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
22846 if (origin
!= NULL
)
22847 add_abstract_origin_attribute (var_die
, origin
);
22849 /* Loop unrolling can create multiple blocks that refer to the same
22850 static variable, so we must test for the DW_AT_declaration flag.
22852 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
22853 copy decls and set the DECL_ABSTRACT_P flag on them instead of
22856 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
22857 else if (decl_will_get_specification_p (old_die
, decl
, declaration
))
22859 /* This is a definition of a C++ class level static. */
22860 add_AT_specification (var_die
, old_die
);
22861 specialization_p
= true;
22862 if (DECL_NAME (decl
))
22864 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
22865 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
22867 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
22868 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
22870 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
22871 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
22873 if (debug_column_info
22875 && (get_AT_unsigned (old_die
, DW_AT_decl_column
)
22876 != (unsigned) s
.column
))
22877 add_AT_unsigned (var_die
, DW_AT_decl_column
, s
.column
);
22879 if (old_die
->die_tag
== DW_TAG_member
)
22880 add_linkage_name (var_die
, decl
);
22884 add_name_and_src_coords_attributes (var_die
, decl
, no_linkage_name
);
22886 if ((origin
== NULL
&& !specialization_p
)
22888 && !DECL_ABSTRACT_P (decl_or_origin
)
22889 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
22890 decl_function_context
22891 (decl_or_origin
))))
22893 tree type
= TREE_TYPE (decl_or_origin
);
22895 if (decl_by_reference_p (decl_or_origin
))
22896 add_type_attribute (var_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
22899 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
), false,
22903 if (origin
== NULL
&& !specialization_p
)
22905 if (TREE_PUBLIC (decl
))
22906 add_AT_flag (var_die
, DW_AT_external
, 1);
22908 if (DECL_ARTIFICIAL (decl
))
22909 add_AT_flag (var_die
, DW_AT_artificial
, 1);
22911 add_alignment_attribute (var_die
, decl
);
22913 add_accessibility_attribute (var_die
, decl
);
22917 add_AT_flag (var_die
, DW_AT_declaration
, 1);
22919 if (decl
&& (DECL_ABSTRACT_P (decl
)
22920 || !old_die
|| is_declaration_die (old_die
)))
22921 equate_decl_number_to_die (decl
, var_die
);
22923 gen_variable_die_location
:
22925 && (! DECL_ABSTRACT_P (decl_or_origin
)
22926 /* Local static vars are shared between all clones/inlines,
22927 so emit DW_AT_location on the abstract DIE if DECL_RTL is
22929 || (VAR_P (decl_or_origin
)
22930 && TREE_STATIC (decl_or_origin
)
22931 && DECL_RTL_SET_P (decl_or_origin
))))
22934 add_pubname (decl_or_origin
, var_die
);
22936 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
22940 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
22942 if ((dwarf_version
>= 4 || !dwarf_strict
)
22943 && lang_hooks
.decls
.decl_dwarf_attribute (decl_or_origin
,
22944 DW_AT_const_expr
) == 1
22945 && !get_AT (var_die
, DW_AT_const_expr
)
22946 && !specialization_p
)
22947 add_AT_flag (var_die
, DW_AT_const_expr
, 1);
22951 int inl
= lang_hooks
.decls
.decl_dwarf_attribute (decl_or_origin
,
22954 && !get_AT (var_die
, DW_AT_inline
)
22955 && !specialization_p
)
22956 add_AT_unsigned (var_die
, DW_AT_inline
, inl
);
22960 /* Generate a DIE to represent a named constant. */
22963 gen_const_die (tree decl
, dw_die_ref context_die
)
22965 dw_die_ref const_die
;
22966 tree type
= TREE_TYPE (decl
);
22968 const_die
= lookup_decl_die (decl
);
22972 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
22973 equate_decl_number_to_die (decl
, const_die
);
22974 add_name_and_src_coords_attributes (const_die
, decl
);
22975 add_type_attribute (const_die
, type
, TYPE_QUAL_CONST
, false, context_die
);
22976 if (TREE_PUBLIC (decl
))
22977 add_AT_flag (const_die
, DW_AT_external
, 1);
22978 if (DECL_ARTIFICIAL (decl
))
22979 add_AT_flag (const_die
, DW_AT_artificial
, 1);
22980 tree_add_const_value_attribute_for_decl (const_die
, decl
);
22983 /* Generate a DIE to represent a label identifier. */
22986 gen_label_die (tree decl
, dw_die_ref context_die
)
22988 tree origin
= decl_ultimate_origin (decl
);
22989 dw_die_ref lbl_die
= lookup_decl_die (decl
);
22991 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
22995 lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
22996 equate_decl_number_to_die (decl
, lbl_die
);
22998 if (origin
!= NULL
)
22999 add_abstract_origin_attribute (lbl_die
, origin
);
23001 add_name_and_src_coords_attributes (lbl_die
, decl
);
23004 if (DECL_ABSTRACT_P (decl
))
23005 equate_decl_number_to_die (decl
, lbl_die
);
23006 else if (! early_dwarf
)
23008 insn
= DECL_RTL_IF_SET (decl
);
23010 /* Deleted labels are programmer specified labels which have been
23011 eliminated because of various optimizations. We still emit them
23012 here so that it is possible to put breakpoints on them. */
23016 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
23018 /* When optimization is enabled (via -O) some parts of the compiler
23019 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
23020 represent source-level labels which were explicitly declared by
23021 the user. This really shouldn't be happening though, so catch
23022 it if it ever does happen. */
23023 gcc_assert (!as_a
<rtx_insn
*> (insn
)->deleted ());
23025 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
23026 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
23030 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
23031 && CODE_LABEL_NUMBER (insn
) != -1)
23033 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
23034 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
23039 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
23040 attributes to the DIE for a block STMT, to describe where the inlined
23041 function was called from. This is similar to add_src_coords_attributes. */
23044 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
23046 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
23048 if (dwarf_version
>= 3 || !dwarf_strict
)
23050 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
23051 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
23052 if (debug_column_info
&& s
.column
)
23053 add_AT_unsigned (die
, DW_AT_call_column
, s
.column
);
23058 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
23059 Add low_pc and high_pc attributes to the DIE for a block STMT. */
23062 add_high_low_attributes (tree stmt
, dw_die_ref die
)
23064 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
23066 if (BLOCK_FRAGMENT_CHAIN (stmt
)
23067 && (dwarf_version
>= 3 || !dwarf_strict
))
23069 tree chain
, superblock
= NULL_TREE
;
23071 dw_attr_node
*attr
= NULL
;
23073 if (inlined_function_outer_scope_p (stmt
))
23075 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
23076 BLOCK_NUMBER (stmt
));
23077 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
23080 /* Optimize duplicate .debug_ranges lists or even tails of
23081 lists. If this BLOCK has same ranges as its supercontext,
23082 lookup DW_AT_ranges attribute in the supercontext (and
23083 recursively so), verify that the ranges_table contains the
23084 right values and use it instead of adding a new .debug_range. */
23085 for (chain
= stmt
, pdie
= die
;
23086 BLOCK_SAME_RANGE (chain
);
23087 chain
= BLOCK_SUPERCONTEXT (chain
))
23089 dw_attr_node
*new_attr
;
23091 pdie
= pdie
->die_parent
;
23094 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
23096 new_attr
= get_AT (pdie
, DW_AT_ranges
);
23097 if (new_attr
== NULL
23098 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
23101 superblock
= BLOCK_SUPERCONTEXT (chain
);
23104 && ((*ranges_table
)[attr
->dw_attr_val
.v
.val_offset
].num
23105 == BLOCK_NUMBER (superblock
))
23106 && BLOCK_FRAGMENT_CHAIN (superblock
))
23108 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
;
23109 unsigned long supercnt
= 0, thiscnt
= 0;
23110 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
23111 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
23114 gcc_checking_assert ((*ranges_table
)[off
+ supercnt
].num
23115 == BLOCK_NUMBER (chain
));
23117 gcc_checking_assert ((*ranges_table
)[off
+ supercnt
+ 1].num
== 0);
23118 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
23119 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
23121 gcc_assert (supercnt
>= thiscnt
);
23122 add_AT_range_list (die
, DW_AT_ranges
, off
+ supercnt
- thiscnt
,
23124 note_rnglist_head (off
+ supercnt
- thiscnt
);
23128 unsigned int offset
= add_ranges (stmt
, true);
23129 add_AT_range_list (die
, DW_AT_ranges
, offset
, false);
23130 note_rnglist_head (offset
);
23132 bool prev_in_cold
= BLOCK_IN_COLD_SECTION_P (stmt
);
23133 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
23136 add_ranges (chain
, prev_in_cold
!= BLOCK_IN_COLD_SECTION_P (chain
));
23137 prev_in_cold
= BLOCK_IN_COLD_SECTION_P (chain
);
23138 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
23145 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
23146 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
23147 BLOCK_NUMBER (stmt
));
23148 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
23149 BLOCK_NUMBER (stmt
));
23150 add_AT_low_high_pc (die
, label
, label_high
, false);
23154 /* Generate a DIE for a lexical block. */
23157 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
)
23159 dw_die_ref old_die
= BLOCK_DIE (stmt
);
23160 dw_die_ref stmt_die
= NULL
;
23163 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
23164 BLOCK_DIE (stmt
) = stmt_die
;
23167 if (BLOCK_ABSTRACT (stmt
))
23171 /* This must have been generated early and it won't even
23172 need location information since it's a DW_AT_inline
23175 for (dw_die_ref c
= context_die
; c
; c
= c
->die_parent
)
23176 if (c
->die_tag
== DW_TAG_inlined_subroutine
23177 || c
->die_tag
== DW_TAG_subprogram
)
23179 gcc_assert (get_AT (c
, DW_AT_inline
));
23185 else if (BLOCK_ABSTRACT_ORIGIN (stmt
))
23187 /* If this is an inlined instance, create a new lexical die for
23188 anything below to attach DW_AT_abstract_origin to. */
23191 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
23192 BLOCK_DIE (stmt
) = stmt_die
;
23196 tree origin
= block_ultimate_origin (stmt
);
23197 if (origin
!= NULL_TREE
&& origin
!= stmt
)
23198 add_abstract_origin_attribute (stmt_die
, origin
);
23202 stmt_die
= old_die
;
23204 /* A non abstract block whose blocks have already been reordered
23205 should have the instruction range for this block. If so, set the
23206 high/low attributes. */
23207 if (!early_dwarf
&& !BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
23209 gcc_assert (stmt_die
);
23210 add_high_low_attributes (stmt
, stmt_die
);
23213 decls_for_scope (stmt
, stmt_die
);
23216 /* Generate a DIE for an inlined subprogram. */
23219 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
)
23223 /* The instance of function that is effectively being inlined shall not
23225 gcc_assert (! BLOCK_ABSTRACT (stmt
));
23227 decl
= block_ultimate_origin (stmt
);
23229 /* Make sure any inlined functions are known to be inlineable. */
23230 gcc_checking_assert (DECL_ABSTRACT_P (decl
)
23231 || cgraph_function_possibly_inlined_p (decl
));
23233 /* Emit info for the abstract instance first, if we haven't yet. We
23234 must emit this even if the block is abstract, otherwise when we
23235 emit the block below (or elsewhere), we may end up trying to emit
23236 a die whose origin die hasn't been emitted, and crashing. */
23237 dwarf2out_abstract_function (decl
);
23239 if (! BLOCK_ABSTRACT (stmt
))
23241 dw_die_ref subr_die
23242 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
23244 if (call_arg_locations
)
23245 BLOCK_DIE (stmt
) = subr_die
;
23246 add_abstract_origin_attribute (subr_die
, decl
);
23247 if (TREE_ASM_WRITTEN (stmt
))
23248 add_high_low_attributes (stmt
, subr_die
);
23249 add_call_src_coords_attributes (stmt
, subr_die
);
23251 decls_for_scope (stmt
, subr_die
);
23255 /* Generate a DIE for a field in a record, or structure. CTX is required: see
23256 the comment for VLR_CONTEXT. */
23259 gen_field_die (tree decl
, struct vlr_context
*ctx
, dw_die_ref context_die
)
23261 dw_die_ref decl_die
;
23263 if (TREE_TYPE (decl
) == error_mark_node
)
23266 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
23267 add_name_and_src_coords_attributes (decl_die
, decl
);
23268 add_type_attribute (decl_die
, member_declared_type (decl
), decl_quals (decl
),
23269 TYPE_REVERSE_STORAGE_ORDER (DECL_FIELD_CONTEXT (decl
)),
23272 if (DECL_BIT_FIELD_TYPE (decl
))
23274 add_byte_size_attribute (decl_die
, decl
);
23275 add_bit_size_attribute (decl_die
, decl
);
23276 add_bit_offset_attribute (decl_die
, decl
, ctx
);
23279 add_alignment_attribute (decl_die
, decl
);
23281 /* If we have a variant part offset, then we are supposed to process a member
23282 of a QUAL_UNION_TYPE, which is how we represent variant parts in
23284 gcc_assert (ctx
->variant_part_offset
== NULL_TREE
23285 || TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != QUAL_UNION_TYPE
);
23286 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
23287 add_data_member_location_attribute (decl_die
, decl
, ctx
);
23289 if (DECL_ARTIFICIAL (decl
))
23290 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
23292 add_accessibility_attribute (decl_die
, decl
);
23294 /* Equate decl number to die, so that we can look up this decl later on. */
23295 equate_decl_number_to_die (decl
, decl_die
);
23298 /* Generate a DIE for a pointer to a member type. TYPE can be an
23299 OFFSET_TYPE, for a pointer to data member, or a RECORD_TYPE, for a
23300 pointer to member function. */
23303 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
23305 if (lookup_type_die (type
))
23308 dw_die_ref ptr_die
= new_die (DW_TAG_ptr_to_member_type
,
23309 scope_die_for (type
, context_die
), type
);
23311 equate_type_number_to_die (type
, ptr_die
);
23312 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
23313 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
23314 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
23316 add_alignment_attribute (ptr_die
, type
);
23318 if (TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
23319 && TREE_CODE (TREE_TYPE (type
)) != METHOD_TYPE
)
23321 dw_loc_descr_ref op
= new_loc_descr (DW_OP_plus
, 0, 0);
23322 add_AT_loc (ptr_die
, DW_AT_use_location
, op
);
23326 static char *producer_string
;
23328 /* Return a heap allocated producer string including command line options
23329 if -grecord-gcc-switches. */
23332 gen_producer_string (void)
23335 auto_vec
<const char *> switches
;
23336 const char *language_string
= lang_hooks
.name
;
23337 char *producer
, *tail
;
23339 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
23340 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
23342 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
23343 switch (save_decoded_options
[j
].opt_index
)
23350 case OPT_auxbase_strip
:
23359 case OPT_SPECIAL_unknown
:
23360 case OPT_SPECIAL_ignore
:
23361 case OPT_SPECIAL_program_name
:
23362 case OPT_SPECIAL_input_file
:
23363 case OPT_grecord_gcc_switches
:
23364 case OPT_gno_record_gcc_switches
:
23365 case OPT__output_pch_
:
23366 case OPT_fdiagnostics_show_location_
:
23367 case OPT_fdiagnostics_show_option
:
23368 case OPT_fdiagnostics_show_caret
:
23369 case OPT_fdiagnostics_color_
:
23370 case OPT_fverbose_asm
:
23372 case OPT__sysroot_
:
23374 case OPT_nostdinc__
:
23375 case OPT_fpreprocessed
:
23376 case OPT_fltrans_output_list_
:
23377 case OPT_fresolution_
:
23378 case OPT_fdebug_prefix_map_
:
23379 /* Ignore these. */
23382 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
23383 & CL_NO_DWARF_RECORD
)
23385 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
23387 switch (save_decoded_options
[j
].canonical_option
[0][1])
23394 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
23401 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
23402 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
23406 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
23408 sprintf (tail
, "%s %s", language_string
, version_string
);
23411 FOR_EACH_VEC_ELT (switches
, j
, p
)
23415 memcpy (tail
+ 1, p
, len
);
23423 /* Given a C and/or C++ language/version string return the "highest".
23424 C++ is assumed to be "higher" than C in this case. Used for merging
23425 LTO translation unit languages. */
23426 static const char *
23427 highest_c_language (const char *lang1
, const char *lang2
)
23429 if (strcmp ("GNU C++14", lang1
) == 0 || strcmp ("GNU C++14", lang2
) == 0)
23430 return "GNU C++14";
23431 if (strcmp ("GNU C++11", lang1
) == 0 || strcmp ("GNU C++11", lang2
) == 0)
23432 return "GNU C++11";
23433 if (strcmp ("GNU C++98", lang1
) == 0 || strcmp ("GNU C++98", lang2
) == 0)
23434 return "GNU C++98";
23436 if (strcmp ("GNU C11", lang1
) == 0 || strcmp ("GNU C11", lang2
) == 0)
23438 if (strcmp ("GNU C99", lang1
) == 0 || strcmp ("GNU C99", lang2
) == 0)
23440 if (strcmp ("GNU C89", lang1
) == 0 || strcmp ("GNU C89", lang2
) == 0)
23443 gcc_unreachable ();
23447 /* Generate the DIE for the compilation unit. */
23450 gen_compile_unit_die (const char *filename
)
23453 const char *language_string
= lang_hooks
.name
;
23456 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
23460 add_name_attribute (die
, filename
);
23461 /* Don't add cwd for <built-in>. */
23462 if (filename
[0] != '<')
23463 add_comp_dir_attribute (die
);
23466 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
23468 /* If our producer is LTO try to figure out a common language to use
23469 from the global list of translation units. */
23470 if (strcmp (language_string
, "GNU GIMPLE") == 0)
23474 const char *common_lang
= NULL
;
23476 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
23478 if (!TRANSLATION_UNIT_LANGUAGE (t
))
23481 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
23482 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
23484 else if (strncmp (common_lang
, "GNU C", 5) == 0
23485 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
23486 /* Mixing C and C++ is ok, use C++ in that case. */
23487 common_lang
= highest_c_language (common_lang
,
23488 TRANSLATION_UNIT_LANGUAGE (t
));
23491 /* Fall back to C. */
23492 common_lang
= NULL
;
23498 language_string
= common_lang
;
23501 language
= DW_LANG_C
;
23502 if (strncmp (language_string
, "GNU C", 5) == 0
23503 && ISDIGIT (language_string
[5]))
23505 language
= DW_LANG_C89
;
23506 if (dwarf_version
>= 3 || !dwarf_strict
)
23508 if (strcmp (language_string
, "GNU C89") != 0)
23509 language
= DW_LANG_C99
;
23511 if (dwarf_version
>= 5 /* || !dwarf_strict */)
23512 if (strcmp (language_string
, "GNU C11") == 0)
23513 language
= DW_LANG_C11
;
23516 else if (strncmp (language_string
, "GNU C++", 7) == 0)
23518 language
= DW_LANG_C_plus_plus
;
23519 if (dwarf_version
>= 5 /* || !dwarf_strict */)
23521 if (strcmp (language_string
, "GNU C++11") == 0)
23522 language
= DW_LANG_C_plus_plus_11
;
23523 else if (strcmp (language_string
, "GNU C++14") == 0)
23524 language
= DW_LANG_C_plus_plus_14
;
23527 else if (strcmp (language_string
, "GNU F77") == 0)
23528 language
= DW_LANG_Fortran77
;
23529 else if (dwarf_version
>= 3 || !dwarf_strict
)
23531 if (strcmp (language_string
, "GNU Ada") == 0)
23532 language
= DW_LANG_Ada95
;
23533 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
23535 language
= DW_LANG_Fortran95
;
23536 if (dwarf_version
>= 5 /* || !dwarf_strict */)
23538 if (strcmp (language_string
, "GNU Fortran2003") == 0)
23539 language
= DW_LANG_Fortran03
;
23540 else if (strcmp (language_string
, "GNU Fortran2008") == 0)
23541 language
= DW_LANG_Fortran08
;
23544 else if (strcmp (language_string
, "GNU Objective-C") == 0)
23545 language
= DW_LANG_ObjC
;
23546 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
23547 language
= DW_LANG_ObjC_plus_plus
;
23548 else if (dwarf_version
>= 5 || !dwarf_strict
)
23550 if (strcmp (language_string
, "GNU Go") == 0)
23551 language
= DW_LANG_Go
;
23554 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
23555 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
23556 language
= DW_LANG_Fortran90
;
23558 add_AT_unsigned (die
, DW_AT_language
, language
);
23562 case DW_LANG_Fortran77
:
23563 case DW_LANG_Fortran90
:
23564 case DW_LANG_Fortran95
:
23565 case DW_LANG_Fortran03
:
23566 case DW_LANG_Fortran08
:
23567 /* Fortran has case insensitive identifiers and the front-end
23568 lowercases everything. */
23569 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
23572 /* The default DW_ID_case_sensitive doesn't need to be specified. */
23578 /* Generate the DIE for a base class. */
23581 gen_inheritance_die (tree binfo
, tree access
, tree type
,
23582 dw_die_ref context_die
)
23584 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
23585 struct vlr_context ctx
= { type
, NULL
};
23587 add_type_attribute (die
, BINFO_TYPE (binfo
), TYPE_UNQUALIFIED
, false,
23589 add_data_member_location_attribute (die
, binfo
, &ctx
);
23591 if (BINFO_VIRTUAL_P (binfo
))
23592 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
23594 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
23595 children, otherwise the default is DW_ACCESS_public. In DWARF2
23596 the default has always been DW_ACCESS_private. */
23597 if (access
== access_public_node
)
23599 if (dwarf_version
== 2
23600 || context_die
->die_tag
== DW_TAG_class_type
)
23601 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
23603 else if (access
== access_protected_node
)
23604 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
23605 else if (dwarf_version
> 2
23606 && context_die
->die_tag
!= DW_TAG_class_type
)
23607 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
23610 /* Return whether DECL is a FIELD_DECL that represents the variant part of a
23613 is_variant_part (tree decl
)
23615 return (TREE_CODE (decl
) == FIELD_DECL
23616 && TREE_CODE (TREE_TYPE (decl
)) == QUAL_UNION_TYPE
);
23619 /* Check that OPERAND is a reference to a field in STRUCT_TYPE. If it is,
23620 return the FIELD_DECL. Return NULL_TREE otherwise. */
23623 analyze_discr_in_predicate (tree operand
, tree struct_type
)
23625 bool continue_stripping
= true;
23626 while (continue_stripping
)
23627 switch (TREE_CODE (operand
))
23630 operand
= TREE_OPERAND (operand
, 0);
23633 continue_stripping
= false;
23637 /* Match field access to members of struct_type only. */
23638 if (TREE_CODE (operand
) == COMPONENT_REF
23639 && TREE_CODE (TREE_OPERAND (operand
, 0)) == PLACEHOLDER_EXPR
23640 && TREE_TYPE (TREE_OPERAND (operand
, 0)) == struct_type
23641 && TREE_CODE (TREE_OPERAND (operand
, 1)) == FIELD_DECL
)
23642 return TREE_OPERAND (operand
, 1);
23647 /* Check that SRC is a constant integer that can be represented as a native
23648 integer constant (either signed or unsigned). If so, store it into DEST and
23649 return true. Return false otherwise. */
23652 get_discr_value (tree src
, dw_discr_value
*dest
)
23654 tree discr_type
= TREE_TYPE (src
);
23656 if (lang_hooks
.types
.get_debug_type
)
23658 tree debug_type
= lang_hooks
.types
.get_debug_type (discr_type
);
23659 if (debug_type
!= NULL
)
23660 discr_type
= debug_type
;
23663 if (TREE_CODE (src
) != INTEGER_CST
|| !INTEGRAL_TYPE_P (discr_type
))
23666 /* Signedness can vary between the original type and the debug type. This
23667 can happen for character types in Ada for instance: the character type
23668 used for code generation can be signed, to be compatible with the C one,
23669 but from a debugger point of view, it must be unsigned. */
23670 bool is_orig_unsigned
= TYPE_UNSIGNED (TREE_TYPE (src
));
23671 bool is_debug_unsigned
= TYPE_UNSIGNED (discr_type
);
23673 if (is_orig_unsigned
!= is_debug_unsigned
)
23674 src
= fold_convert (discr_type
, src
);
23676 if (!(is_debug_unsigned
? tree_fits_uhwi_p (src
) : tree_fits_shwi_p (src
)))
23679 dest
->pos
= is_debug_unsigned
;
23680 if (is_debug_unsigned
)
23681 dest
->v
.uval
= tree_to_uhwi (src
);
23683 dest
->v
.sval
= tree_to_shwi (src
);
23688 /* Try to extract synthetic properties out of VARIANT_PART_DECL, which is a
23689 FIELD_DECL in STRUCT_TYPE that represents a variant part. If unsuccessful,
23690 store NULL_TREE in DISCR_DECL. Otherwise:
23692 - store the discriminant field in STRUCT_TYPE that controls the variant
23693 part to *DISCR_DECL
23695 - put in *DISCR_LISTS_P an array where for each variant, the item
23696 represents the corresponding matching list of discriminant values.
23698 - put in *DISCR_LISTS_LENGTH the number of variants, which is the size of
23701 Note that when the array is allocated (i.e. when the analysis is
23702 successful), it is up to the caller to free the array. */
23705 analyze_variants_discr (tree variant_part_decl
,
23708 dw_discr_list_ref
**discr_lists_p
,
23709 unsigned *discr_lists_length
)
23711 tree variant_part_type
= TREE_TYPE (variant_part_decl
);
23713 dw_discr_list_ref
*discr_lists
;
23716 /* Compute how many variants there are in this variant part. */
23717 *discr_lists_length
= 0;
23718 for (variant
= TYPE_FIELDS (variant_part_type
);
23719 variant
!= NULL_TREE
;
23720 variant
= DECL_CHAIN (variant
))
23721 ++*discr_lists_length
;
23723 *discr_decl
= NULL_TREE
;
23725 = (dw_discr_list_ref
*) xcalloc (*discr_lists_length
,
23726 sizeof (**discr_lists_p
));
23727 discr_lists
= *discr_lists_p
;
23729 /* And then analyze all variants to extract discriminant information for all
23730 of them. This analysis is conservative: as soon as we detect something we
23731 do not support, abort everything and pretend we found nothing. */
23732 for (variant
= TYPE_FIELDS (variant_part_type
), i
= 0;
23733 variant
!= NULL_TREE
;
23734 variant
= DECL_CHAIN (variant
), ++i
)
23736 tree match_expr
= DECL_QUALIFIER (variant
);
23738 /* Now, try to analyze the predicate and deduce a discriminant for
23740 if (match_expr
== boolean_true_node
)
23741 /* Typically happens for the default variant: it matches all cases that
23742 previous variants rejected. Don't output any matching value for
23746 /* The following loop tries to iterate over each discriminant
23747 possibility: single values or ranges. */
23748 while (match_expr
!= NULL_TREE
)
23750 tree next_round_match_expr
;
23751 tree candidate_discr
= NULL_TREE
;
23752 dw_discr_list_ref new_node
= NULL
;
23754 /* Possibilities are matched one after the other by nested
23755 TRUTH_ORIF_EXPR expressions. Process the current possibility and
23756 continue with the rest at next iteration. */
23757 if (TREE_CODE (match_expr
) == TRUTH_ORIF_EXPR
)
23759 next_round_match_expr
= TREE_OPERAND (match_expr
, 0);
23760 match_expr
= TREE_OPERAND (match_expr
, 1);
23763 next_round_match_expr
= NULL_TREE
;
23765 if (match_expr
== boolean_false_node
)
23766 /* This sub-expression matches nothing: just wait for the next
23770 else if (TREE_CODE (match_expr
) == EQ_EXPR
)
23772 /* We are matching: <discr_field> == <integer_cst>
23773 This sub-expression matches a single value. */
23774 tree integer_cst
= TREE_OPERAND (match_expr
, 1);
23777 = analyze_discr_in_predicate (TREE_OPERAND (match_expr
, 0),
23780 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
23781 if (!get_discr_value (integer_cst
,
23782 &new_node
->dw_discr_lower_bound
))
23784 new_node
->dw_discr_range
= false;
23787 else if (TREE_CODE (match_expr
) == TRUTH_ANDIF_EXPR
)
23789 /* We are matching:
23790 <discr_field> > <integer_cst>
23791 && <discr_field> < <integer_cst>.
23792 This sub-expression matches the range of values between the
23793 two matched integer constants. Note that comparisons can be
23794 inclusive or exclusive. */
23795 tree candidate_discr_1
, candidate_discr_2
;
23796 tree lower_cst
, upper_cst
;
23797 bool lower_cst_included
, upper_cst_included
;
23798 tree lower_op
= TREE_OPERAND (match_expr
, 0);
23799 tree upper_op
= TREE_OPERAND (match_expr
, 1);
23801 /* When the comparison is exclusive, the integer constant is not
23802 the discriminant range bound we are looking for: we will have
23803 to increment or decrement it. */
23804 if (TREE_CODE (lower_op
) == GE_EXPR
)
23805 lower_cst_included
= true;
23806 else if (TREE_CODE (lower_op
) == GT_EXPR
)
23807 lower_cst_included
= false;
23811 if (TREE_CODE (upper_op
) == LE_EXPR
)
23812 upper_cst_included
= true;
23813 else if (TREE_CODE (upper_op
) == LT_EXPR
)
23814 upper_cst_included
= false;
23818 /* Extract the discriminant from the first operand and check it
23819 is consistant with the same analysis in the second
23822 = analyze_discr_in_predicate (TREE_OPERAND (lower_op
, 0),
23825 = analyze_discr_in_predicate (TREE_OPERAND (upper_op
, 0),
23827 if (candidate_discr_1
== candidate_discr_2
)
23828 candidate_discr
= candidate_discr_1
;
23832 /* Extract bounds from both. */
23833 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
23834 lower_cst
= TREE_OPERAND (lower_op
, 1);
23835 upper_cst
= TREE_OPERAND (upper_op
, 1);
23837 if (!lower_cst_included
)
23839 = fold_build2 (PLUS_EXPR
, TREE_TYPE (lower_cst
), lower_cst
,
23840 build_int_cst (TREE_TYPE (lower_cst
), 1));
23841 if (!upper_cst_included
)
23843 = fold_build2 (MINUS_EXPR
, TREE_TYPE (upper_cst
), upper_cst
,
23844 build_int_cst (TREE_TYPE (upper_cst
), 1));
23846 if (!get_discr_value (lower_cst
,
23847 &new_node
->dw_discr_lower_bound
)
23848 || !get_discr_value (upper_cst
,
23849 &new_node
->dw_discr_upper_bound
))
23852 new_node
->dw_discr_range
= true;
23856 /* Unsupported sub-expression: we cannot determine the set of
23857 matching discriminant values. Abort everything. */
23860 /* If the discriminant info is not consistant with what we saw so
23861 far, consider the analysis failed and abort everything. */
23862 if (candidate_discr
== NULL_TREE
23863 || (*discr_decl
!= NULL_TREE
&& candidate_discr
!= *discr_decl
))
23866 *discr_decl
= candidate_discr
;
23868 if (new_node
!= NULL
)
23870 new_node
->dw_discr_next
= discr_lists
[i
];
23871 discr_lists
[i
] = new_node
;
23873 match_expr
= next_round_match_expr
;
23877 /* If we reach this point, we could match everything we were interested
23882 /* Clean all data structure and return no result. */
23883 free (*discr_lists_p
);
23884 *discr_lists_p
= NULL
;
23885 *discr_decl
= NULL_TREE
;
23888 /* Generate a DIE to represent VARIANT_PART_DECL, a variant part that is part
23889 of STRUCT_TYPE, a record type. This new DIE is emitted as the next child
23892 Variant parts are supposed to be implemented as a FIELD_DECL whose type is a
23893 QUAL_UNION_TYPE: this is the VARIANT_PART_DECL parameter. The members for
23894 this type, which are record types, represent the available variants and each
23895 has a DECL_QUALIFIER attribute. The discriminant and the discriminant
23896 values are inferred from these attributes.
23898 In trees, the offsets for the fields inside these sub-records are relative
23899 to the variant part itself, whereas the corresponding DIEs should have
23900 offset attributes that are relative to the embedding record base address.
23901 This is why the caller must provide a VARIANT_PART_OFFSET expression: it
23902 must be an expression that computes the offset of the variant part to
23903 describe in DWARF. */
23906 gen_variant_part (tree variant_part_decl
, struct vlr_context
*vlr_ctx
,
23907 dw_die_ref context_die
)
23909 const tree variant_part_type
= TREE_TYPE (variant_part_decl
);
23910 tree variant_part_offset
= vlr_ctx
->variant_part_offset
;
23911 struct loc_descr_context ctx
= {
23912 vlr_ctx
->struct_type
, /* context_type */
23913 NULL_TREE
, /* base_decl */
23915 false, /* placeholder_arg */
23916 false /* placeholder_seen */
23919 /* The FIELD_DECL node in STRUCT_TYPE that acts as the discriminant, or
23920 NULL_TREE if there is no such field. */
23921 tree discr_decl
= NULL_TREE
;
23922 dw_discr_list_ref
*discr_lists
;
23923 unsigned discr_lists_length
= 0;
23926 dw_die_ref dwarf_proc_die
= NULL
;
23927 dw_die_ref variant_part_die
23928 = new_die (DW_TAG_variant_part
, context_die
, variant_part_type
);
23930 equate_decl_number_to_die (variant_part_decl
, variant_part_die
);
23932 analyze_variants_discr (variant_part_decl
, vlr_ctx
->struct_type
,
23933 &discr_decl
, &discr_lists
, &discr_lists_length
);
23935 if (discr_decl
!= NULL_TREE
)
23937 dw_die_ref discr_die
= lookup_decl_die (discr_decl
);
23940 add_AT_die_ref (variant_part_die
, DW_AT_discr
, discr_die
);
23942 /* We have no DIE for the discriminant, so just discard all
23943 discrimimant information in the output. */
23944 discr_decl
= NULL_TREE
;
23947 /* If the offset for this variant part is more complex than a constant,
23948 create a DWARF procedure for it so that we will not have to generate DWARF
23949 expressions for it for each member. */
23950 if (TREE_CODE (variant_part_offset
) != INTEGER_CST
23951 && (dwarf_version
>= 3 || !dwarf_strict
))
23953 const tree dwarf_proc_fndecl
23954 = build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, NULL_TREE
,
23955 build_function_type (TREE_TYPE (variant_part_offset
),
23957 const tree dwarf_proc_call
= build_call_expr (dwarf_proc_fndecl
, 0);
23958 const dw_loc_descr_ref dwarf_proc_body
23959 = loc_descriptor_from_tree (variant_part_offset
, 0, &ctx
);
23961 dwarf_proc_die
= new_dwarf_proc_die (dwarf_proc_body
,
23962 dwarf_proc_fndecl
, context_die
);
23963 if (dwarf_proc_die
!= NULL
)
23964 variant_part_offset
= dwarf_proc_call
;
23967 /* Output DIEs for all variants. */
23969 for (tree variant
= TYPE_FIELDS (variant_part_type
);
23970 variant
!= NULL_TREE
;
23971 variant
= DECL_CHAIN (variant
), ++i
)
23973 tree variant_type
= TREE_TYPE (variant
);
23974 dw_die_ref variant_die
;
23976 /* All variants (i.e. members of a variant part) are supposed to be
23977 encoded as structures. Sub-variant parts are QUAL_UNION_TYPE fields
23978 under these records. */
23979 gcc_assert (TREE_CODE (variant_type
) == RECORD_TYPE
);
23981 variant_die
= new_die (DW_TAG_variant
, variant_part_die
, variant_type
);
23982 equate_decl_number_to_die (variant
, variant_die
);
23984 /* Output discriminant values this variant matches, if any. */
23985 if (discr_decl
== NULL
|| discr_lists
[i
] == NULL
)
23986 /* In the case we have discriminant information at all, this is
23987 probably the default variant: as the standard says, don't
23988 output any discriminant value/list attribute. */
23990 else if (discr_lists
[i
]->dw_discr_next
== NULL
23991 && !discr_lists
[i
]->dw_discr_range
)
23992 /* If there is only one accepted value, don't bother outputting a
23994 add_discr_value (variant_die
, &discr_lists
[i
]->dw_discr_lower_bound
);
23996 add_discr_list (variant_die
, discr_lists
[i
]);
23998 for (tree member
= TYPE_FIELDS (variant_type
);
23999 member
!= NULL_TREE
;
24000 member
= DECL_CHAIN (member
))
24002 struct vlr_context vlr_sub_ctx
= {
24003 vlr_ctx
->struct_type
, /* struct_type */
24004 NULL
/* variant_part_offset */
24006 if (is_variant_part (member
))
24008 /* All offsets for fields inside variant parts are relative to
24009 the top-level embedding RECORD_TYPE's base address. On the
24010 other hand, offsets in GCC's types are relative to the
24011 nested-most variant part. So we have to sum offsets each time
24014 vlr_sub_ctx
.variant_part_offset
24015 = fold_build2 (PLUS_EXPR
, TREE_TYPE (variant_part_offset
),
24016 variant_part_offset
, byte_position (member
));
24017 gen_variant_part (member
, &vlr_sub_ctx
, variant_die
);
24021 vlr_sub_ctx
.variant_part_offset
= variant_part_offset
;
24022 gen_decl_die (member
, NULL
, &vlr_sub_ctx
, variant_die
);
24027 free (discr_lists
);
24030 /* Generate a DIE for a class member. */
24033 gen_member_die (tree type
, dw_die_ref context_die
)
24036 tree binfo
= TYPE_BINFO (type
);
24038 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
24040 /* If this is not an incomplete type, output descriptions of each of its
24041 members. Note that as we output the DIEs necessary to represent the
24042 members of this record or union type, we will also be trying to output
24043 DIEs to represent the *types* of those members. However the `type'
24044 function (above) will specifically avoid generating type DIEs for member
24045 types *within* the list of member DIEs for this (containing) type except
24046 for those types (of members) which are explicitly marked as also being
24047 members of this (containing) type themselves. The g++ front- end can
24048 force any given type to be treated as a member of some other (containing)
24049 type by setting the TYPE_CONTEXT of the given (member) type to point to
24050 the TREE node representing the appropriate (containing) type. */
24052 /* First output info about the base classes. */
24055 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
24059 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
24060 gen_inheritance_die (base
,
24061 (accesses
? (*accesses
)[i
] : access_public_node
),
24066 /* Now output info about the data members and type members. */
24067 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
24069 struct vlr_context vlr_ctx
= { type
, NULL_TREE
};
24070 bool static_inline_p
24071 = (TREE_STATIC (member
)
24072 && (lang_hooks
.decls
.decl_dwarf_attribute (member
, DW_AT_inline
)
24075 /* Ignore clones. */
24076 if (DECL_ABSTRACT_ORIGIN (member
))
24079 /* If we thought we were generating minimal debug info for TYPE
24080 and then changed our minds, some of the member declarations
24081 may have already been defined. Don't define them again, but
24082 do put them in the right order. */
24084 if (dw_die_ref child
= lookup_decl_die (member
))
24086 /* Handle inline static data members, which only have in-class
24088 dw_die_ref ref
= NULL
;
24089 if (child
->die_tag
== DW_TAG_variable
24090 && child
->die_parent
== comp_unit_die ())
24092 ref
= get_AT_ref (child
, DW_AT_specification
);
24093 /* For C++17 inline static data members followed by redundant
24094 out of class redeclaration, we might get here with
24095 child being the DIE created for the out of class
24096 redeclaration and with its DW_AT_specification being
24097 the DIE created for in-class definition. We want to
24098 reparent the latter, and don't want to create another
24099 DIE with DW_AT_specification in that case, because
24100 we already have one. */
24103 && ref
->die_tag
== DW_TAG_variable
24104 && ref
->die_parent
== comp_unit_die ()
24105 && get_AT (ref
, DW_AT_specification
) == NULL
)
24109 static_inline_p
= false;
24113 if (child
->die_tag
== DW_TAG_variable
24114 && child
->die_parent
== comp_unit_die ()
24117 reparent_child (child
, context_die
);
24118 if (dwarf_version
< 5)
24119 child
->die_tag
= DW_TAG_member
;
24122 splice_child_die (context_die
, child
);
24125 /* Do not generate standard DWARF for variant parts if we are generating
24126 the corresponding GNAT encodings: DIEs generated for both would
24127 conflict in our mappings. */
24128 else if (is_variant_part (member
)
24129 && gnat_encodings
== DWARF_GNAT_ENCODINGS_MINIMAL
)
24131 vlr_ctx
.variant_part_offset
= byte_position (member
);
24132 gen_variant_part (member
, &vlr_ctx
, context_die
);
24136 vlr_ctx
.variant_part_offset
= NULL_TREE
;
24137 gen_decl_die (member
, NULL
, &vlr_ctx
, context_die
);
24140 /* For C++ inline static data members emit immediately a DW_TAG_variable
24141 DIE that will refer to that DW_TAG_member/DW_TAG_variable through
24142 DW_AT_specification. */
24143 if (static_inline_p
)
24145 int old_extern
= DECL_EXTERNAL (member
);
24146 DECL_EXTERNAL (member
) = 0;
24147 gen_decl_die (member
, NULL
, NULL
, comp_unit_die ());
24148 DECL_EXTERNAL (member
) = old_extern
;
24153 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
24154 is set, we pretend that the type was never defined, so we only get the
24155 member DIEs needed by later specification DIEs. */
24158 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
24159 enum debug_info_usage usage
)
24161 if (TREE_ASM_WRITTEN (type
))
24163 /* Fill in the bound of variable-length fields in late dwarf if
24164 still incomplete. */
24165 if (!early_dwarf
&& variably_modified_type_p (type
, NULL
))
24166 for (tree member
= TYPE_FIELDS (type
);
24168 member
= DECL_CHAIN (member
))
24169 fill_variable_array_bounds (TREE_TYPE (member
));
24173 dw_die_ref type_die
= lookup_type_die (type
);
24174 dw_die_ref scope_die
= 0;
24176 int complete
= (TYPE_SIZE (type
)
24177 && (! TYPE_STUB_DECL (type
)
24178 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
24179 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
24180 complete
= complete
&& should_emit_struct_debug (type
, usage
);
24182 if (type_die
&& ! complete
)
24185 if (TYPE_CONTEXT (type
) != NULL_TREE
24186 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
24187 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
24190 scope_die
= scope_die_for (type
, context_die
);
24192 /* Generate child dies for template paramaters. */
24193 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
24194 schedule_generic_params_dies_gen (type
);
24196 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
24197 /* First occurrence of type or toplevel definition of nested class. */
24199 dw_die_ref old_die
= type_die
;
24201 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
24202 ? record_type_tag (type
) : DW_TAG_union_type
,
24204 equate_type_number_to_die (type
, type_die
);
24206 add_AT_specification (type_die
, old_die
);
24208 add_name_attribute (type_die
, type_tag (type
));
24211 remove_AT (type_die
, DW_AT_declaration
);
24213 /* If this type has been completed, then give it a byte_size attribute and
24214 then give a list of members. */
24215 if (complete
&& !ns_decl
)
24217 /* Prevent infinite recursion in cases where the type of some member of
24218 this type is expressed in terms of this type itself. */
24219 TREE_ASM_WRITTEN (type
) = 1;
24220 add_byte_size_attribute (type_die
, type
);
24221 add_alignment_attribute (type_die
, type
);
24222 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
24224 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
24225 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
24228 /* If the first reference to this type was as the return type of an
24229 inline function, then it may not have a parent. Fix this now. */
24230 if (type_die
->die_parent
== NULL
)
24231 add_child_die (scope_die
, type_die
);
24233 push_decl_scope (type
);
24234 gen_member_die (type
, type_die
);
24237 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
24238 if (TYPE_ARTIFICIAL (type
))
24239 add_AT_flag (type_die
, DW_AT_artificial
, 1);
24241 /* GNU extension: Record what type our vtable lives in. */
24242 if (TYPE_VFIELD (type
))
24244 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
24246 gen_type_die (vtype
, context_die
);
24247 add_AT_die_ref (type_die
, DW_AT_containing_type
,
24248 lookup_type_die (vtype
));
24253 add_AT_flag (type_die
, DW_AT_declaration
, 1);
24255 /* We don't need to do this for function-local types. */
24256 if (TYPE_STUB_DECL (type
)
24257 && ! decl_function_context (TYPE_STUB_DECL (type
)))
24258 vec_safe_push (incomplete_types
, type
);
24261 if (get_AT (type_die
, DW_AT_name
))
24262 add_pubtype (type
, type_die
);
24265 /* Generate a DIE for a subroutine _type_. */
24268 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
24270 tree return_type
= TREE_TYPE (type
);
24271 dw_die_ref subr_die
24272 = new_die (DW_TAG_subroutine_type
,
24273 scope_die_for (type
, context_die
), type
);
24275 equate_type_number_to_die (type
, subr_die
);
24276 add_prototyped_attribute (subr_die
, type
);
24277 add_type_attribute (subr_die
, return_type
, TYPE_UNQUALIFIED
, false,
24279 add_alignment_attribute (subr_die
, type
);
24280 gen_formal_types_die (type
, subr_die
);
24282 if (get_AT (subr_die
, DW_AT_name
))
24283 add_pubtype (type
, subr_die
);
24284 if ((dwarf_version
>= 5 || !dwarf_strict
)
24285 && lang_hooks
.types
.type_dwarf_attribute (type
, DW_AT_reference
) != -1)
24286 add_AT_flag (subr_die
, DW_AT_reference
, 1);
24287 if ((dwarf_version
>= 5 || !dwarf_strict
)
24288 && lang_hooks
.types
.type_dwarf_attribute (type
,
24289 DW_AT_rvalue_reference
) != -1)
24290 add_AT_flag (subr_die
, DW_AT_rvalue_reference
, 1);
24293 /* Generate a DIE for a type definition. */
24296 gen_typedef_die (tree decl
, dw_die_ref context_die
)
24298 dw_die_ref type_die
;
24301 if (TREE_ASM_WRITTEN (decl
))
24303 if (DECL_ORIGINAL_TYPE (decl
))
24304 fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl
));
24308 TREE_ASM_WRITTEN (decl
) = 1;
24309 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
24310 origin
= decl_ultimate_origin (decl
);
24311 if (origin
!= NULL
)
24312 add_abstract_origin_attribute (type_die
, origin
);
24315 tree type
= TREE_TYPE (decl
);
24317 if (type
== error_mark_node
)
24320 add_name_and_src_coords_attributes (type_die
, decl
);
24321 if (DECL_ORIGINAL_TYPE (decl
))
24323 type
= DECL_ORIGINAL_TYPE (decl
);
24325 if (type
== error_mark_node
)
24328 gcc_assert (type
!= TREE_TYPE (decl
));
24329 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
24333 if (is_naming_typedef_decl (TYPE_NAME (type
)))
24335 /* Here, we are in the case of decl being a typedef naming
24336 an anonymous type, e.g:
24337 typedef struct {...} foo;
24338 In that case TREE_TYPE (decl) is not a typedef variant
24339 type and TYPE_NAME of the anonymous type is set to the
24340 TYPE_DECL of the typedef. This construct is emitted by
24343 TYPE is the anonymous struct named by the typedef
24344 DECL. As we need the DW_AT_type attribute of the
24345 DW_TAG_typedef to point to the DIE of TYPE, let's
24346 generate that DIE right away. add_type_attribute
24347 called below will then pick (via lookup_type_die) that
24348 anonymous struct DIE. */
24349 if (!TREE_ASM_WRITTEN (type
))
24350 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
24352 /* This is a GNU Extension. We are adding a
24353 DW_AT_linkage_name attribute to the DIE of the
24354 anonymous struct TYPE. The value of that attribute
24355 is the name of the typedef decl naming the anonymous
24356 struct. This greatly eases the work of consumers of
24357 this debug info. */
24358 add_linkage_name_raw (lookup_type_die (type
), decl
);
24362 add_type_attribute (type_die
, type
, decl_quals (decl
), false,
24365 if (is_naming_typedef_decl (decl
))
24366 /* We want that all subsequent calls to lookup_type_die with
24367 TYPE in argument yield the DW_TAG_typedef we have just
24369 equate_type_number_to_die (type
, type_die
);
24371 type
= TREE_TYPE (decl
);
24373 add_alignment_attribute (type_die
, type
);
24375 add_accessibility_attribute (type_die
, decl
);
24378 if (DECL_ABSTRACT_P (decl
))
24379 equate_decl_number_to_die (decl
, type_die
);
24381 if (get_AT (type_die
, DW_AT_name
))
24382 add_pubtype (decl
, type_die
);
24385 /* Generate a DIE for a struct, class, enum or union type. */
24388 gen_tagged_type_die (tree type
,
24389 dw_die_ref context_die
,
24390 enum debug_info_usage usage
)
24394 if (type
== NULL_TREE
24395 || !is_tagged_type (type
))
24398 if (TREE_ASM_WRITTEN (type
))
24400 /* If this is a nested type whose containing class hasn't been written
24401 out yet, writing it out will cover this one, too. This does not apply
24402 to instantiations of member class templates; they need to be added to
24403 the containing class as they are generated. FIXME: This hurts the
24404 idea of combining type decls from multiple TUs, since we can't predict
24405 what set of template instantiations we'll get. */
24406 else if (TYPE_CONTEXT (type
)
24407 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
24408 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
24410 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
24412 if (TREE_ASM_WRITTEN (type
))
24415 /* If that failed, attach ourselves to the stub. */
24416 push_decl_scope (TYPE_CONTEXT (type
));
24417 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
24420 else if (TYPE_CONTEXT (type
) != NULL_TREE
24421 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
24423 /* If this type is local to a function that hasn't been written
24424 out yet, use a NULL context for now; it will be fixed up in
24425 decls_for_scope. */
24426 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
24427 /* A declaration DIE doesn't count; nested types need to go in the
24429 if (context_die
&& is_declaration_die (context_die
))
24430 context_die
= NULL
;
24435 context_die
= declare_in_namespace (type
, context_die
);
24439 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
24441 /* This might have been written out by the call to
24442 declare_in_namespace. */
24443 if (!TREE_ASM_WRITTEN (type
))
24444 gen_enumeration_type_die (type
, context_die
);
24447 gen_struct_or_union_type_die (type
, context_die
, usage
);
24452 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
24453 it up if it is ever completed. gen_*_type_die will set it for us
24454 when appropriate. */
24457 /* Generate a type description DIE. */
24460 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
24461 enum debug_info_usage usage
)
24463 struct array_descr_info info
;
24465 if (type
== NULL_TREE
|| type
== error_mark_node
)
24468 if (flag_checking
&& type
)
24469 verify_type (type
);
24471 if (TYPE_NAME (type
) != NULL_TREE
24472 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
24473 && is_redundant_typedef (TYPE_NAME (type
))
24474 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
24475 /* The DECL of this type is a typedef we don't want to emit debug
24476 info for but we want debug info for its underlying typedef.
24477 This can happen for e.g, the injected-class-name of a C++
24479 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
24481 /* If TYPE is a typedef type variant, let's generate debug info
24482 for the parent typedef which TYPE is a type of. */
24483 if (typedef_variant_p (type
))
24485 if (TREE_ASM_WRITTEN (type
))
24488 /* Prevent broken recursion; we can't hand off to the same type. */
24489 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
24491 /* Give typedefs the right scope. */
24492 context_die
= scope_die_for (type
, context_die
);
24494 TREE_ASM_WRITTEN (type
) = 1;
24496 gen_decl_die (TYPE_NAME (type
), NULL
, NULL
, context_die
);
24500 /* If type is an anonymous tagged type named by a typedef, let's
24501 generate debug info for the typedef. */
24502 if (is_naming_typedef_decl (TYPE_NAME (type
)))
24504 /* Use the DIE of the containing namespace as the parent DIE of
24505 the type description DIE we want to generate. */
24506 if (DECL_CONTEXT (TYPE_NAME (type
))
24507 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
24508 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
24510 gen_decl_die (TYPE_NAME (type
), NULL
, NULL
, context_die
);
24514 if (lang_hooks
.types
.get_debug_type
)
24516 tree debug_type
= lang_hooks
.types
.get_debug_type (type
);
24518 if (debug_type
!= NULL_TREE
&& debug_type
!= type
)
24520 gen_type_die_with_usage (debug_type
, context_die
, usage
);
24525 /* We are going to output a DIE to represent the unqualified version
24526 of this type (i.e. without any const or volatile qualifiers) so
24527 get the main variant (i.e. the unqualified version) of this type
24528 now. (Vectors and arrays are special because the debugging info is in the
24529 cloned type itself. Similarly function/method types can contain extra
24530 ref-qualification). */
24531 if (TREE_CODE (type
) == FUNCTION_TYPE
24532 || TREE_CODE (type
) == METHOD_TYPE
)
24534 /* For function/method types, can't use type_main_variant here,
24535 because that can have different ref-qualifiers for C++,
24536 but try to canonicalize. */
24537 tree main
= TYPE_MAIN_VARIANT (type
);
24538 for (tree t
= main
; t
; t
= TYPE_NEXT_VARIANT (t
))
24539 if (TYPE_QUALS_NO_ADDR_SPACE (t
) == 0
24540 && check_base_type (t
, main
)
24541 && check_lang_type (t
, type
))
24547 else if (TREE_CODE (type
) != VECTOR_TYPE
24548 && TREE_CODE (type
) != ARRAY_TYPE
)
24549 type
= type_main_variant (type
);
24551 /* If this is an array type with hidden descriptor, handle it first. */
24552 if (!TREE_ASM_WRITTEN (type
)
24553 && lang_hooks
.types
.get_array_descr_info
)
24555 memset (&info
, 0, sizeof (info
));
24556 if (lang_hooks
.types
.get_array_descr_info (type
, &info
))
24558 /* Fortran sometimes emits array types with no dimension. */
24559 gcc_assert (info
.ndimensions
>= 0
24560 && (info
.ndimensions
24561 <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN
));
24562 gen_descr_array_type_die (type
, &info
, context_die
);
24563 TREE_ASM_WRITTEN (type
) = 1;
24568 if (TREE_ASM_WRITTEN (type
))
24570 /* Variable-length types may be incomplete even if
24571 TREE_ASM_WRITTEN. For such types, fall through to
24572 gen_array_type_die() and possibly fill in
24573 DW_AT_{upper,lower}_bound attributes. */
24574 if ((TREE_CODE (type
) != ARRAY_TYPE
24575 && TREE_CODE (type
) != RECORD_TYPE
24576 && TREE_CODE (type
) != UNION_TYPE
24577 && TREE_CODE (type
) != QUAL_UNION_TYPE
)
24578 || !variably_modified_type_p (type
, NULL
))
24582 switch (TREE_CODE (type
))
24588 case REFERENCE_TYPE
:
24589 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
24590 ensures that the gen_type_die recursion will terminate even if the
24591 type is recursive. Recursive types are possible in Ada. */
24592 /* ??? We could perhaps do this for all types before the switch
24594 TREE_ASM_WRITTEN (type
) = 1;
24596 /* For these types, all that is required is that we output a DIE (or a
24597 set of DIEs) to represent the "basis" type. */
24598 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24599 DINFO_USAGE_IND_USE
);
24603 /* This code is used for C++ pointer-to-data-member types.
24604 Output a description of the relevant class type. */
24605 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
24606 DINFO_USAGE_IND_USE
);
24608 /* Output a description of the type of the object pointed to. */
24609 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24610 DINFO_USAGE_IND_USE
);
24612 /* Now output a DIE to represent this pointer-to-data-member type
24614 gen_ptr_to_mbr_type_die (type
, context_die
);
24617 case FUNCTION_TYPE
:
24618 /* Force out return type (in case it wasn't forced out already). */
24619 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24620 DINFO_USAGE_DIR_USE
);
24621 gen_subroutine_type_die (type
, context_die
);
24625 /* Force out return type (in case it wasn't forced out already). */
24626 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24627 DINFO_USAGE_DIR_USE
);
24628 gen_subroutine_type_die (type
, context_die
);
24633 gen_array_type_die (type
, context_die
);
24636 case ENUMERAL_TYPE
:
24639 case QUAL_UNION_TYPE
:
24640 gen_tagged_type_die (type
, context_die
, usage
);
24646 case FIXED_POINT_TYPE
:
24649 case POINTER_BOUNDS_TYPE
:
24650 /* No DIEs needed for fundamental types. */
24655 /* Just use DW_TAG_unspecified_type. */
24657 dw_die_ref type_die
= lookup_type_die (type
);
24658 if (type_die
== NULL
)
24660 tree name
= TYPE_IDENTIFIER (type
);
24661 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (),
24663 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
24664 equate_type_number_to_die (type
, type_die
);
24670 if (is_cxx_auto (type
))
24672 tree name
= TYPE_IDENTIFIER (type
);
24673 dw_die_ref
*die
= (name
== get_identifier ("auto")
24674 ? &auto_die
: &decltype_auto_die
);
24677 *die
= new_die (DW_TAG_unspecified_type
,
24678 comp_unit_die (), NULL_TREE
);
24679 add_name_attribute (*die
, IDENTIFIER_POINTER (name
));
24681 equate_type_number_to_die (type
, *die
);
24684 gcc_unreachable ();
24687 TREE_ASM_WRITTEN (type
) = 1;
24691 gen_type_die (tree type
, dw_die_ref context_die
)
24693 if (type
!= error_mark_node
)
24695 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
24698 dw_die_ref die
= lookup_type_die (type
);
24705 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
24706 things which are local to the given block. */
24709 gen_block_die (tree stmt
, dw_die_ref context_die
)
24711 int must_output_die
= 0;
24714 /* Ignore blocks that are NULL. */
24715 if (stmt
== NULL_TREE
)
24718 inlined_func
= inlined_function_outer_scope_p (stmt
);
24720 /* If the block is one fragment of a non-contiguous block, do not
24721 process the variables, since they will have been done by the
24722 origin block. Do process subblocks. */
24723 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
24727 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
24728 gen_block_die (sub
, context_die
);
24733 /* Determine if we need to output any Dwarf DIEs at all to represent this
24736 /* The outer scopes for inlinings *must* always be represented. We
24737 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
24738 must_output_die
= 1;
24741 /* Determine if this block directly contains any "significant"
24742 local declarations which we will need to output DIEs for. */
24743 if (debug_info_level
> DINFO_LEVEL_TERSE
)
24744 /* We are not in terse mode so *any* local declaration counts
24745 as being a "significant" one. */
24746 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
24747 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
24748 && (TREE_USED (stmt
)
24749 || TREE_ASM_WRITTEN (stmt
)
24750 || BLOCK_ABSTRACT (stmt
)));
24751 else if ((TREE_USED (stmt
)
24752 || TREE_ASM_WRITTEN (stmt
)
24753 || BLOCK_ABSTRACT (stmt
))
24754 && !dwarf2out_ignore_block (stmt
))
24755 must_output_die
= 1;
24758 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
24759 DIE for any block which contains no significant local declarations at
24760 all. Rather, in such cases we just call `decls_for_scope' so that any
24761 needed Dwarf info for any sub-blocks will get properly generated. Note
24762 that in terse mode, our definition of what constitutes a "significant"
24763 local declaration gets restricted to include only inlined function
24764 instances and local (nested) function definitions. */
24765 if (must_output_die
)
24769 /* If STMT block is abstract, that means we have been called
24770 indirectly from dwarf2out_abstract_function.
24771 That function rightfully marks the descendent blocks (of
24772 the abstract function it is dealing with) as being abstract,
24773 precisely to prevent us from emitting any
24774 DW_TAG_inlined_subroutine DIE as a descendent
24775 of an abstract function instance. So in that case, we should
24776 not call gen_inlined_subroutine_die.
24778 Later though, when cgraph asks dwarf2out to emit info
24779 for the concrete instance of the function decl into which
24780 the concrete instance of STMT got inlined, the later will lead
24781 to the generation of a DW_TAG_inlined_subroutine DIE. */
24782 if (! BLOCK_ABSTRACT (stmt
))
24783 gen_inlined_subroutine_die (stmt
, context_die
);
24786 gen_lexical_block_die (stmt
, context_die
);
24789 decls_for_scope (stmt
, context_die
);
24792 /* Process variable DECL (or variable with origin ORIGIN) within
24793 block STMT and add it to CONTEXT_DIE. */
24795 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
24798 tree decl_or_origin
= decl
? decl
: origin
;
24800 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
24801 die
= lookup_decl_die (decl_or_origin
);
24802 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
)
24804 if (TYPE_DECL_IS_STUB (decl_or_origin
))
24805 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
24807 die
= lookup_decl_die (decl_or_origin
);
24808 /* Avoid re-creating the DIE late if it was optimized as unused early. */
24809 if (! die
&& ! early_dwarf
)
24815 if (die
!= NULL
&& die
->die_parent
== NULL
)
24816 add_child_die (context_die
, die
);
24817 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
24820 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
24821 stmt
, context_die
);
24824 gen_decl_die (decl
, origin
, NULL
, context_die
);
24827 /* Generate all of the decls declared within a given scope and (recursively)
24828 all of its sub-blocks. */
24831 decls_for_scope (tree stmt
, dw_die_ref context_die
)
24837 /* Ignore NULL blocks. */
24838 if (stmt
== NULL_TREE
)
24841 /* Output the DIEs to represent all of the data objects and typedefs
24842 declared directly within this block but not within any nested
24843 sub-blocks. Also, nested function and tag DIEs have been
24844 generated with a parent of NULL; fix that up now. We don't
24845 have to do this if we're at -g1. */
24846 if (debug_info_level
> DINFO_LEVEL_TERSE
)
24848 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
24849 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
24850 /* BLOCK_NONLOCALIZED_VARs simply generate DIE stubs with abstract
24851 origin - avoid doing this twice as we have no good way to see
24852 if we've done it once already. */
24854 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
24856 decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
24857 if (decl
== current_function_decl
)
24858 /* Ignore declarations of the current function, while they
24859 are declarations, gen_subprogram_die would treat them
24860 as definitions again, because they are equal to
24861 current_function_decl and endlessly recurse. */;
24862 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
24863 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
24865 process_scope_var (stmt
, NULL_TREE
, decl
, context_die
);
24869 /* Even if we're at -g1, we need to process the subblocks in order to get
24870 inlined call information. */
24872 /* Output the DIEs to represent all sub-blocks (and the items declared
24873 therein) of this block. */
24874 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
24876 subblocks
= BLOCK_CHAIN (subblocks
))
24877 gen_block_die (subblocks
, context_die
);
24880 /* Is this a typedef we can avoid emitting? */
24883 is_redundant_typedef (const_tree decl
)
24885 if (TYPE_DECL_IS_STUB (decl
))
24888 if (DECL_ARTIFICIAL (decl
)
24889 && DECL_CONTEXT (decl
)
24890 && is_tagged_type (DECL_CONTEXT (decl
))
24891 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
24892 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
24893 /* Also ignore the artificial member typedef for the class name. */
24899 /* Return TRUE if TYPE is a typedef that names a type for linkage
24900 purposes. This kind of typedefs is produced by the C++ FE for
24903 typedef struct {...} foo;
24905 In that case, there is no typedef variant type produced for foo.
24906 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
24910 is_naming_typedef_decl (const_tree decl
)
24912 if (decl
== NULL_TREE
24913 || TREE_CODE (decl
) != TYPE_DECL
24914 || DECL_NAMELESS (decl
)
24915 || !is_tagged_type (TREE_TYPE (decl
))
24916 || DECL_IS_BUILTIN (decl
)
24917 || is_redundant_typedef (decl
)
24918 /* It looks like Ada produces TYPE_DECLs that are very similar
24919 to C++ naming typedefs but that have different
24920 semantics. Let's be specific to c++ for now. */
24924 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
24925 && TYPE_NAME (TREE_TYPE (decl
)) == decl
24926 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
24927 != TYPE_NAME (TREE_TYPE (decl
))));
24930 /* Looks up the DIE for a context. */
24932 static inline dw_die_ref
24933 lookup_context_die (tree context
)
24937 /* Find die that represents this context. */
24938 if (TYPE_P (context
))
24940 context
= TYPE_MAIN_VARIANT (context
);
24941 dw_die_ref ctx
= lookup_type_die (context
);
24944 return strip_naming_typedef (context
, ctx
);
24947 return lookup_decl_die (context
);
24949 return comp_unit_die ();
24952 /* Returns the DIE for a context. */
24954 static inline dw_die_ref
24955 get_context_die (tree context
)
24959 /* Find die that represents this context. */
24960 if (TYPE_P (context
))
24962 context
= TYPE_MAIN_VARIANT (context
);
24963 return strip_naming_typedef (context
, force_type_die (context
));
24966 return force_decl_die (context
);
24968 return comp_unit_die ();
24971 /* Returns the DIE for decl. A DIE will always be returned. */
24974 force_decl_die (tree decl
)
24976 dw_die_ref decl_die
;
24977 unsigned saved_external_flag
;
24978 tree save_fn
= NULL_TREE
;
24979 decl_die
= lookup_decl_die (decl
);
24982 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
24984 decl_die
= lookup_decl_die (decl
);
24988 switch (TREE_CODE (decl
))
24990 case FUNCTION_DECL
:
24991 /* Clear current_function_decl, so that gen_subprogram_die thinks
24992 that this is a declaration. At this point, we just want to force
24993 declaration die. */
24994 save_fn
= current_function_decl
;
24995 current_function_decl
= NULL_TREE
;
24996 gen_subprogram_die (decl
, context_die
);
24997 current_function_decl
= save_fn
;
25001 /* Set external flag to force declaration die. Restore it after
25002 gen_decl_die() call. */
25003 saved_external_flag
= DECL_EXTERNAL (decl
);
25004 DECL_EXTERNAL (decl
) = 1;
25005 gen_decl_die (decl
, NULL
, NULL
, context_die
);
25006 DECL_EXTERNAL (decl
) = saved_external_flag
;
25009 case NAMESPACE_DECL
:
25010 if (dwarf_version
>= 3 || !dwarf_strict
)
25011 dwarf2out_decl (decl
);
25013 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
25014 decl_die
= comp_unit_die ();
25017 case TRANSLATION_UNIT_DECL
:
25018 decl_die
= comp_unit_die ();
25022 gcc_unreachable ();
25025 /* We should be able to find the DIE now. */
25027 decl_die
= lookup_decl_die (decl
);
25028 gcc_assert (decl_die
);
25034 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
25035 always returned. */
25038 force_type_die (tree type
)
25040 dw_die_ref type_die
;
25042 type_die
= lookup_type_die (type
);
25045 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
25047 type_die
= modified_type_die (type
, TYPE_QUALS_NO_ADDR_SPACE (type
),
25048 false, context_die
);
25049 gcc_assert (type_die
);
25054 /* Force out any required namespaces to be able to output DECL,
25055 and return the new context_die for it, if it's changed. */
25058 setup_namespace_context (tree thing
, dw_die_ref context_die
)
25060 tree context
= (DECL_P (thing
)
25061 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
25062 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
25063 /* Force out the namespace. */
25064 context_die
= force_decl_die (context
);
25066 return context_die
;
25069 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
25070 type) within its namespace, if appropriate.
25072 For compatibility with older debuggers, namespace DIEs only contain
25073 declarations; all definitions are emitted at CU scope, with
25074 DW_AT_specification pointing to the declaration (like with class
25078 declare_in_namespace (tree thing
, dw_die_ref context_die
)
25080 dw_die_ref ns_context
;
25082 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25083 return context_die
;
25085 /* External declarations in the local scope only need to be emitted
25086 once, not once in the namespace and once in the scope.
25088 This avoids declaring the `extern' below in the
25089 namespace DIE as well as in the innermost scope:
25102 if (DECL_P (thing
) && DECL_EXTERNAL (thing
) && local_scope_p (context_die
))
25103 return context_die
;
25105 /* If this decl is from an inlined function, then don't try to emit it in its
25106 namespace, as we will get confused. It would have already been emitted
25107 when the abstract instance of the inline function was emitted anyways. */
25108 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
25109 return context_die
;
25111 ns_context
= setup_namespace_context (thing
, context_die
);
25113 if (ns_context
!= context_die
)
25117 if (DECL_P (thing
))
25118 gen_decl_die (thing
, NULL
, NULL
, ns_context
);
25120 gen_type_die (thing
, ns_context
);
25122 return context_die
;
25125 /* Generate a DIE for a namespace or namespace alias. */
25128 gen_namespace_die (tree decl
, dw_die_ref context_die
)
25130 dw_die_ref namespace_die
;
25132 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
25133 they are an alias of. */
25134 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
25136 /* Output a real namespace or module. */
25137 context_die
= setup_namespace_context (decl
, comp_unit_die ());
25138 namespace_die
= new_die (is_fortran ()
25139 ? DW_TAG_module
: DW_TAG_namespace
,
25140 context_die
, decl
);
25141 /* For Fortran modules defined in different CU don't add src coords. */
25142 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
25144 const char *name
= dwarf2_name (decl
, 0);
25146 add_name_attribute (namespace_die
, name
);
25149 add_name_and_src_coords_attributes (namespace_die
, decl
);
25150 if (DECL_EXTERNAL (decl
))
25151 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
25152 equate_decl_number_to_die (decl
, namespace_die
);
25156 /* Output a namespace alias. */
25158 /* Force out the namespace we are an alias of, if necessary. */
25159 dw_die_ref origin_die
25160 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
25162 if (DECL_FILE_SCOPE_P (decl
)
25163 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
25164 context_die
= setup_namespace_context (decl
, comp_unit_die ());
25165 /* Now create the namespace alias DIE. */
25166 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
25167 add_name_and_src_coords_attributes (namespace_die
, decl
);
25168 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
25169 equate_decl_number_to_die (decl
, namespace_die
);
25171 if ((dwarf_version
>= 5 || !dwarf_strict
)
25172 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
25173 DW_AT_export_symbols
) == 1)
25174 add_AT_flag (namespace_die
, DW_AT_export_symbols
, 1);
25176 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
25177 if (want_pubnames ())
25178 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
25181 /* Generate Dwarf debug information for a decl described by DECL.
25182 The return value is currently only meaningful for PARM_DECLs,
25183 for all other decls it returns NULL.
25185 If DECL is a FIELD_DECL, CTX is required: see the comment for VLR_CONTEXT.
25186 It can be NULL otherwise. */
25189 gen_decl_die (tree decl
, tree origin
, struct vlr_context
*ctx
,
25190 dw_die_ref context_die
)
25192 tree decl_or_origin
= decl
? decl
: origin
;
25193 tree class_origin
= NULL
, ultimate_origin
;
25195 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
25198 /* Ignore pointer bounds decls. */
25199 if (DECL_P (decl_or_origin
)
25200 && TREE_TYPE (decl_or_origin
)
25201 && POINTER_BOUNDS_P (decl_or_origin
))
25204 switch (TREE_CODE (decl_or_origin
))
25210 if (!is_fortran () && !is_ada ())
25212 /* The individual enumerators of an enum type get output when we output
25213 the Dwarf representation of the relevant enum type itself. */
25217 /* Emit its type. */
25218 gen_type_die (TREE_TYPE (decl
), context_die
);
25220 /* And its containing namespace. */
25221 context_die
= declare_in_namespace (decl
, context_die
);
25223 gen_const_die (decl
, context_die
);
25226 case FUNCTION_DECL
:
25229 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
25230 on local redeclarations of global functions. That seems broken. */
25231 if (current_function_decl
!= decl
)
25232 /* This is only a declaration. */;
25235 /* If we're emitting a clone, emit info for the abstract instance. */
25236 if (origin
|| DECL_ORIGIN (decl
) != decl
)
25237 dwarf2out_abstract_function (origin
25238 ? DECL_ORIGIN (origin
)
25239 : DECL_ABSTRACT_ORIGIN (decl
));
25241 /* If we're emitting an out-of-line copy of an inline function,
25242 emit info for the abstract instance and set up to refer to it. */
25243 else if (cgraph_function_possibly_inlined_p (decl
)
25244 && ! DECL_ABSTRACT_P (decl
)
25245 && ! class_or_namespace_scope_p (context_die
)
25246 /* dwarf2out_abstract_function won't emit a die if this is just
25247 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
25248 that case, because that works only if we have a die. */
25249 && DECL_INITIAL (decl
) != NULL_TREE
)
25251 dwarf2out_abstract_function (decl
);
25252 set_decl_origin_self (decl
);
25255 /* Otherwise we're emitting the primary DIE for this decl. */
25256 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
25258 /* Before we describe the FUNCTION_DECL itself, make sure that we
25259 have its containing type. */
25261 origin
= decl_class_context (decl
);
25262 if (origin
!= NULL_TREE
)
25263 gen_type_die (origin
, context_die
);
25265 /* And its return type. */
25266 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
25268 /* And its virtual context. */
25269 if (DECL_VINDEX (decl
) != NULL_TREE
)
25270 gen_type_die (DECL_CONTEXT (decl
), context_die
);
25272 /* Make sure we have a member DIE for decl. */
25273 if (origin
!= NULL_TREE
)
25274 gen_type_die_for_member (origin
, decl
, context_die
);
25276 /* And its containing namespace. */
25277 context_die
= declare_in_namespace (decl
, context_die
);
25280 /* Now output a DIE to represent the function itself. */
25282 gen_subprogram_die (decl
, context_die
);
25286 /* If we are in terse mode, don't generate any DIEs to represent any
25287 actual typedefs. */
25288 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25291 /* In the special case of a TYPE_DECL node representing the declaration
25292 of some type tag, if the given TYPE_DECL is marked as having been
25293 instantiated from some other (original) TYPE_DECL node (e.g. one which
25294 was generated within the original definition of an inline function) we
25295 used to generate a special (abbreviated) DW_TAG_structure_type,
25296 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
25297 should be actually referencing those DIEs, as variable DIEs with that
25298 type would be emitted already in the abstract origin, so it was always
25299 removed during unused type prunning. Don't add anything in this
25301 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
25304 if (is_redundant_typedef (decl
))
25305 gen_type_die (TREE_TYPE (decl
), context_die
);
25307 /* Output a DIE to represent the typedef itself. */
25308 gen_typedef_die (decl
, context_die
);
25312 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
25313 gen_label_die (decl
, context_die
);
25318 /* If we are in terse mode, don't generate any DIEs to represent any
25319 variable declarations or definitions. */
25320 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25323 /* Output any DIEs that are needed to specify the type of this data
25325 if (decl_by_reference_p (decl_or_origin
))
25326 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
25328 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
25330 /* And its containing type. */
25331 class_origin
= decl_class_context (decl_or_origin
);
25332 if (class_origin
!= NULL_TREE
)
25333 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
25335 /* And its containing namespace. */
25336 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
25338 /* Now output the DIE to represent the data object itself. This gets
25339 complicated because of the possibility that the VAR_DECL really
25340 represents an inlined instance of a formal parameter for an inline
25342 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
25343 if (ultimate_origin
!= NULL_TREE
25344 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
25345 gen_formal_parameter_die (decl
, origin
,
25346 true /* Emit name attribute. */,
25349 gen_variable_die (decl
, origin
, context_die
);
25353 gcc_assert (ctx
!= NULL
&& ctx
->struct_type
!= NULL
);
25354 /* Ignore the nameless fields that are used to skip bits but handle C++
25355 anonymous unions and structs. */
25356 if (DECL_NAME (decl
) != NULL_TREE
25357 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
25358 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
25360 gen_type_die (member_declared_type (decl
), context_die
);
25361 gen_field_die (decl
, ctx
, context_die
);
25366 if (DECL_BY_REFERENCE (decl_or_origin
))
25367 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
25369 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
25370 return gen_formal_parameter_die (decl
, origin
,
25371 true /* Emit name attribute. */,
25374 case NAMESPACE_DECL
:
25375 if (dwarf_version
>= 3 || !dwarf_strict
)
25376 gen_namespace_die (decl
, context_die
);
25379 case IMPORTED_DECL
:
25380 dwarf2out_imported_module_or_decl_1 (decl
, DECL_NAME (decl
),
25381 DECL_CONTEXT (decl
), context_die
);
25384 case NAMELIST_DECL
:
25385 gen_namelist_decl (DECL_NAME (decl
), context_die
,
25386 NAMELIST_DECL_ASSOCIATED_DECL (decl
));
25390 /* Probably some frontend-internal decl. Assume we don't care. */
25391 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
25398 /* Output initial debug information for global DECL. Called at the
25399 end of the parsing process.
25401 This is the initial debug generation process. As such, the DIEs
25402 generated may be incomplete. A later debug generation pass
25403 (dwarf2out_late_global_decl) will augment the information generated
25404 in this pass (e.g., with complete location info). */
25407 dwarf2out_early_global_decl (tree decl
)
25411 /* gen_decl_die() will set DECL_ABSTRACT because
25412 cgraph_function_possibly_inlined_p() returns true. This is in
25413 turn will cause DW_AT_inline attributes to be set.
25415 This happens because at early dwarf generation, there is no
25416 cgraph information, causing cgraph_function_possibly_inlined_p()
25417 to return true. Trick cgraph_function_possibly_inlined_p()
25418 while we generate dwarf early. */
25419 bool save
= symtab
->global_info_ready
;
25420 symtab
->global_info_ready
= true;
25422 /* We don't handle TYPE_DECLs. If required, they'll be reached via
25423 other DECLs and they can point to template types or other things
25424 that dwarf2out can't handle when done via dwarf2out_decl. */
25425 if (TREE_CODE (decl
) != TYPE_DECL
25426 && TREE_CODE (decl
) != PARM_DECL
)
25428 tree save_fndecl
= current_function_decl
;
25429 if (TREE_CODE (decl
) == FUNCTION_DECL
)
25431 /* For nested functions, make sure we have DIEs for the parents first
25432 so that all nested DIEs are generated at the proper scope in the
25434 tree context
= decl_function_context (decl
);
25435 if (context
!= NULL
&& lookup_decl_die (context
) == NULL
)
25437 current_function_decl
= context
;
25438 dwarf2out_decl (context
);
25441 current_function_decl
= decl
;
25443 dwarf2out_decl (decl
);
25444 if (TREE_CODE (decl
) == FUNCTION_DECL
)
25445 current_function_decl
= save_fndecl
;
25447 symtab
->global_info_ready
= save
;
25450 /* Output debug information for global decl DECL. Called from
25451 toplev.c after compilation proper has finished. */
25454 dwarf2out_late_global_decl (tree decl
)
25456 /* Fill-in any location information we were unable to determine
25457 on the first pass. */
25458 if (VAR_P (decl
) && !POINTER_BOUNDS_P (decl
))
25460 dw_die_ref die
= lookup_decl_die (decl
);
25462 /* We have to generate early debug late for LTO. */
25463 if (! die
&& in_lto_p
)
25465 dwarf2out_decl (decl
);
25466 die
= lookup_decl_die (decl
);
25471 /* We get called via the symtab code invoking late_global_decl
25472 for symbols that are optimized out. Do not add locations
25473 for those, except if they have a DECL_VALUE_EXPR, in which case
25474 they are relevant for debuggers. */
25475 varpool_node
*node
= varpool_node::get (decl
);
25476 if ((! node
|| ! node
->definition
) && ! DECL_HAS_VALUE_EXPR_P (decl
))
25477 tree_add_const_value_attribute_for_decl (die
, decl
);
25479 add_location_or_const_value_attribute (die
, decl
, false);
25484 /* Output debug information for type decl DECL. Called from toplev.c
25485 and from language front ends (to record built-in types). */
25487 dwarf2out_type_decl (tree decl
, int local
)
25492 dwarf2out_decl (decl
);
25496 /* Output debug information for imported module or decl DECL.
25497 NAME is non-NULL name in the lexical block if the decl has been renamed.
25498 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
25499 that DECL belongs to.
25500 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
25502 dwarf2out_imported_module_or_decl_1 (tree decl
,
25504 tree lexical_block
,
25505 dw_die_ref lexical_block_die
)
25507 expanded_location xloc
;
25508 dw_die_ref imported_die
= NULL
;
25509 dw_die_ref at_import_die
;
25511 if (TREE_CODE (decl
) == IMPORTED_DECL
)
25513 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
25514 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
25518 xloc
= expand_location (input_location
);
25520 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
25522 at_import_die
= force_type_die (TREE_TYPE (decl
));
25523 /* For namespace N { typedef void T; } using N::T; base_type_die
25524 returns NULL, but DW_TAG_imported_declaration requires
25525 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
25526 if (!at_import_die
)
25528 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
25529 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
25530 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
25531 gcc_assert (at_import_die
);
25536 at_import_die
= lookup_decl_die (decl
);
25537 if (!at_import_die
)
25539 /* If we're trying to avoid duplicate debug info, we may not have
25540 emitted the member decl for this field. Emit it now. */
25541 if (TREE_CODE (decl
) == FIELD_DECL
)
25543 tree type
= DECL_CONTEXT (decl
);
25545 if (TYPE_CONTEXT (type
)
25546 && TYPE_P (TYPE_CONTEXT (type
))
25547 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
25548 DINFO_USAGE_DIR_USE
))
25550 gen_type_die_for_member (type
, decl
,
25551 get_context_die (TYPE_CONTEXT (type
)));
25553 if (TREE_CODE (decl
) == NAMELIST_DECL
)
25554 at_import_die
= gen_namelist_decl (DECL_NAME (decl
),
25555 get_context_die (DECL_CONTEXT (decl
)),
25558 at_import_die
= force_decl_die (decl
);
25562 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
25564 if (dwarf_version
>= 3 || !dwarf_strict
)
25565 imported_die
= new_die (DW_TAG_imported_module
,
25572 imported_die
= new_die (DW_TAG_imported_declaration
,
25576 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
25577 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
25578 if (debug_column_info
&& xloc
.column
)
25579 add_AT_unsigned (imported_die
, DW_AT_decl_column
, xloc
.column
);
25581 add_AT_string (imported_die
, DW_AT_name
,
25582 IDENTIFIER_POINTER (name
));
25583 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
25586 /* Output debug information for imported module or decl DECL.
25587 NAME is non-NULL name in context if the decl has been renamed.
25588 CHILD is true if decl is one of the renamed decls as part of
25589 importing whole module.
25590 IMPLICIT is set if this hook is called for an implicit import
25591 such as inline namespace. */
25594 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
25595 bool child
, bool implicit
)
25597 /* dw_die_ref at_import_die; */
25598 dw_die_ref scope_die
;
25600 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25605 /* For DWARF5, just DW_AT_export_symbols on the DW_TAG_namespace
25606 should be enough, for DWARF4 and older even if we emit as extension
25607 DW_AT_export_symbols add the implicit DW_TAG_imported_module anyway
25608 for the benefit of consumers unaware of DW_AT_export_symbols. */
25610 && dwarf_version
>= 5
25611 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
25612 DW_AT_export_symbols
) == 1)
25617 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
25618 We need decl DIE for reference and scope die. First, get DIE for the decl
25621 /* Get the scope die for decl context. Use comp_unit_die for global module
25622 or decl. If die is not found for non globals, force new die. */
25624 && TYPE_P (context
)
25625 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
25628 scope_die
= get_context_die (context
);
25632 /* DW_TAG_imported_module was introduced in the DWARFv3 specification, so
25633 there is nothing we can do, here. */
25634 if (dwarf_version
< 3 && dwarf_strict
)
25637 gcc_assert (scope_die
->die_child
);
25638 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
25639 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
25640 scope_die
= scope_die
->die_child
;
25643 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
25644 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
25647 /* Output debug information for namelists. */
25650 gen_namelist_decl (tree name
, dw_die_ref scope_die
, tree item_decls
)
25652 dw_die_ref nml_die
, nml_item_die
, nml_item_ref_die
;
25656 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25659 gcc_assert (scope_die
!= NULL
);
25660 nml_die
= new_die (DW_TAG_namelist
, scope_die
, NULL
);
25661 add_AT_string (nml_die
, DW_AT_name
, IDENTIFIER_POINTER (name
));
25663 /* If there are no item_decls, we have a nondefining namelist, e.g.
25664 with USE association; hence, set DW_AT_declaration. */
25665 if (item_decls
== NULL_TREE
)
25667 add_AT_flag (nml_die
, DW_AT_declaration
, 1);
25671 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls
), i
, value
)
25673 nml_item_ref_die
= lookup_decl_die (value
);
25674 if (!nml_item_ref_die
)
25675 nml_item_ref_die
= force_decl_die (value
);
25677 nml_item_die
= new_die (DW_TAG_namelist_item
, nml_die
, NULL
);
25678 add_AT_die_ref (nml_item_die
, DW_AT_namelist_items
, nml_item_ref_die
);
25684 /* Write the debugging output for DECL and return the DIE. */
25687 dwarf2out_decl (tree decl
)
25689 dw_die_ref context_die
= comp_unit_die ();
25691 switch (TREE_CODE (decl
))
25696 case FUNCTION_DECL
:
25697 /* If we're a nested function, initially use a parent of NULL; if we're
25698 a plain function, this will be fixed up in decls_for_scope. If
25699 we're a method, it will be ignored, since we already have a DIE. */
25700 if (decl_function_context (decl
)
25701 /* But if we're in terse mode, we don't care about scope. */
25702 && debug_info_level
> DINFO_LEVEL_TERSE
)
25703 context_die
= NULL
;
25707 /* For local statics lookup proper context die. */
25708 if (local_function_static (decl
))
25709 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
25711 /* If we are in terse mode, don't generate any DIEs to represent any
25712 variable declarations or definitions. */
25713 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25718 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25720 if (!is_fortran () && !is_ada ())
25722 if (TREE_STATIC (decl
) && decl_function_context (decl
))
25723 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
25726 case NAMESPACE_DECL
:
25727 case IMPORTED_DECL
:
25728 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25730 if (lookup_decl_die (decl
) != NULL
)
25735 /* Don't emit stubs for types unless they are needed by other DIEs. */
25736 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
25739 /* Don't bother trying to generate any DIEs to represent any of the
25740 normal built-in types for the language we are compiling. */
25741 if (DECL_IS_BUILTIN (decl
))
25744 /* If we are in terse mode, don't generate any DIEs for types. */
25745 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25748 /* If we're a function-scope tag, initially use a parent of NULL;
25749 this will be fixed up in decls_for_scope. */
25750 if (decl_function_context (decl
))
25751 context_die
= NULL
;
25755 case NAMELIST_DECL
:
25762 gen_decl_die (decl
, NULL
, NULL
, context_die
);
25766 dw_die_ref die
= lookup_decl_die (decl
);
25772 /* Write the debugging output for DECL. */
25775 dwarf2out_function_decl (tree decl
)
25777 dwarf2out_decl (decl
);
25778 call_arg_locations
= NULL
;
25779 call_arg_loc_last
= NULL
;
25780 call_site_count
= -1;
25781 tail_call_site_count
= -1;
25782 decl_loc_table
->empty ();
25783 cached_dw_loc_list_table
->empty ();
25786 /* Output a marker (i.e. a label) for the beginning of the generated code for
25787 a lexical block. */
25790 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
25791 unsigned int blocknum
)
25793 switch_to_section (current_function_section ());
25794 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
25797 /* Output a marker (i.e. a label) for the end of the generated code for a
25801 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
25803 switch_to_section (current_function_section ());
25804 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
25807 /* Returns nonzero if it is appropriate not to emit any debugging
25808 information for BLOCK, because it doesn't contain any instructions.
25810 Don't allow this for blocks with nested functions or local classes
25811 as we would end up with orphans, and in the presence of scheduling
25812 we may end up calling them anyway. */
25815 dwarf2out_ignore_block (const_tree block
)
25820 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
25821 if (TREE_CODE (decl
) == FUNCTION_DECL
25822 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
25824 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
25826 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
25827 if (TREE_CODE (decl
) == FUNCTION_DECL
25828 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
25835 /* Hash table routines for file_hash. */
25838 dwarf_file_hasher::equal (dwarf_file_data
*p1
, const char *p2
)
25840 return filename_cmp (p1
->filename
, p2
) == 0;
25844 dwarf_file_hasher::hash (dwarf_file_data
*p
)
25846 return htab_hash_string (p
->filename
);
25849 /* Lookup FILE_NAME (in the list of filenames that we know about here in
25850 dwarf2out.c) and return its "index". The index of each (known) filename is
25851 just a unique number which is associated with only that one filename. We
25852 need such numbers for the sake of generating labels (in the .debug_sfnames
25853 section) and references to those files numbers (in the .debug_srcinfo
25854 and .debug_macinfo sections). If the filename given as an argument is not
25855 found in our current list, add it to the list and assign it the next
25856 available unique index number. */
25858 static struct dwarf_file_data
*
25859 lookup_filename (const char *file_name
)
25861 struct dwarf_file_data
* created
;
25866 dwarf_file_data
**slot
25867 = file_table
->find_slot_with_hash (file_name
, htab_hash_string (file_name
),
25872 created
= ggc_alloc
<dwarf_file_data
> ();
25873 created
->filename
= file_name
;
25874 created
->emitted_number
= 0;
25879 /* If the assembler will construct the file table, then translate the compiler
25880 internal file table number into the assembler file table number, and emit
25881 a .file directive if we haven't already emitted one yet. The file table
25882 numbers are different because we prune debug info for unused variables and
25883 types, which may include filenames. */
25886 maybe_emit_file (struct dwarf_file_data
* fd
)
25888 if (! fd
->emitted_number
)
25890 if (last_emitted_file
)
25891 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
25893 fd
->emitted_number
= 1;
25894 last_emitted_file
= fd
;
25896 if (DWARF2_ASM_LINE_DEBUG_INFO
)
25898 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
25899 output_quoted_string (asm_out_file
,
25900 remap_debug_filename (fd
->filename
));
25901 fputc ('\n', asm_out_file
);
25905 return fd
->emitted_number
;
25908 /* Schedule generation of a DW_AT_const_value attribute to DIE.
25909 That generation should happen after function debug info has been
25910 generated. The value of the attribute is the constant value of ARG. */
25913 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
25915 die_arg_entry entry
;
25920 gcc_assert (early_dwarf
);
25922 if (!tmpl_value_parm_die_table
)
25923 vec_alloc (tmpl_value_parm_die_table
, 32);
25927 vec_safe_push (tmpl_value_parm_die_table
, entry
);
25930 /* Return TRUE if T is an instance of generic type, FALSE
25934 generic_type_p (tree t
)
25936 if (t
== NULL_TREE
|| !TYPE_P (t
))
25938 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
25941 /* Schedule the generation of the generic parameter dies for the
25942 instance of generic type T. The proper generation itself is later
25943 done by gen_scheduled_generic_parms_dies. */
25946 schedule_generic_params_dies_gen (tree t
)
25948 if (!generic_type_p (t
))
25951 gcc_assert (early_dwarf
);
25953 if (!generic_type_instances
)
25954 vec_alloc (generic_type_instances
, 256);
25956 vec_safe_push (generic_type_instances
, t
);
25959 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
25960 by append_entry_to_tmpl_value_parm_die_table. This function must
25961 be called after function DIEs have been generated. */
25964 gen_remaining_tmpl_value_param_die_attribute (void)
25966 if (tmpl_value_parm_die_table
)
25971 /* We do this in two phases - first get the cases we can
25972 handle during early-finish, preserving those we cannot
25973 (containing symbolic constants where we don't yet know
25974 whether we are going to output the referenced symbols).
25975 For those we try again at late-finish. */
25977 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
25979 if (!tree_add_const_value_attribute (e
->die
, e
->arg
))
25981 dw_loc_descr_ref loc
= NULL
;
25983 && (dwarf_version
>= 5 || !dwarf_strict
))
25984 loc
= loc_descriptor_from_tree (e
->arg
, 2, NULL
);
25986 add_AT_loc (e
->die
, DW_AT_location
, loc
);
25988 (*tmpl_value_parm_die_table
)[j
++] = *e
;
25991 tmpl_value_parm_die_table
->truncate (j
);
25995 /* Generate generic parameters DIEs for instances of generic types
25996 that have been previously scheduled by
25997 schedule_generic_params_dies_gen. This function must be called
25998 after all the types of the CU have been laid out. */
26001 gen_scheduled_generic_parms_dies (void)
26006 if (!generic_type_instances
)
26009 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
26010 if (COMPLETE_TYPE_P (t
))
26011 gen_generic_params_dies (t
);
26013 generic_type_instances
= NULL
;
26017 /* Replace DW_AT_name for the decl with name. */
26020 dwarf2out_set_name (tree decl
, tree name
)
26023 dw_attr_node
*attr
;
26026 die
= TYPE_SYMTAB_DIE (decl
);
26030 dname
= dwarf2_name (name
, 0);
26034 attr
= get_AT (die
, DW_AT_name
);
26037 struct indirect_string_node
*node
;
26039 node
= find_AT_string (dname
);
26040 /* replace the string. */
26041 attr
->dw_attr_val
.v
.val_str
= node
;
26045 add_name_attribute (die
, dname
);
26048 /* True if before or during processing of the first function being emitted. */
26049 static bool in_first_function_p
= true;
26050 /* True if loc_note during dwarf2out_var_location call might still be
26051 before first real instruction at address equal to .Ltext0. */
26052 static bool maybe_at_text_label_p
= true;
26053 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
26054 static unsigned int first_loclabel_num_not_at_text_label
;
26056 /* Called by the final INSN scan whenever we see a var location. We
26057 use it to drop labels in the right places, and throw the location in
26058 our lookup table. */
26061 dwarf2out_var_location (rtx_insn
*loc_note
)
26063 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
26064 struct var_loc_node
*newloc
;
26065 rtx_insn
*next_real
, *next_note
;
26066 rtx_insn
*call_insn
= NULL
;
26067 static const char *last_label
;
26068 static const char *last_postcall_label
;
26069 static bool last_in_cold_section_p
;
26070 static rtx_insn
*expected_next_loc_note
;
26074 if (!NOTE_P (loc_note
))
26076 if (CALL_P (loc_note
))
26079 if (SIBLING_CALL_P (loc_note
))
26080 tail_call_site_count
++;
26081 if (optimize
== 0 && !flag_var_tracking
)
26083 /* When the var-tracking pass is not running, there is no note
26084 for indirect calls whose target is compile-time known. In this
26085 case, process such calls specifically so that we generate call
26086 sites for them anyway. */
26087 rtx x
= PATTERN (loc_note
);
26088 if (GET_CODE (x
) == PARALLEL
)
26089 x
= XVECEXP (x
, 0, 0);
26090 if (GET_CODE (x
) == SET
)
26092 if (GET_CODE (x
) == CALL
)
26095 || GET_CODE (XEXP (x
, 0)) != SYMBOL_REF
26096 || !SYMBOL_REF_DECL (XEXP (x
, 0))
26097 || (TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0)))
26100 call_insn
= loc_note
;
26104 next_real
= next_real_insn (call_insn
);
26106 cached_next_real_insn
= NULL
;
26114 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
26115 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
26118 /* Optimize processing a large consecutive sequence of location
26119 notes so we don't spend too much time in next_real_insn. If the
26120 next insn is another location note, remember the next_real_insn
26121 calculation for next time. */
26122 next_real
= cached_next_real_insn
;
26125 if (expected_next_loc_note
!= loc_note
)
26129 next_note
= NEXT_INSN (loc_note
);
26131 || next_note
->deleted ()
26132 || ! NOTE_P (next_note
)
26133 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
26134 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
26138 next_real
= next_real_insn (loc_note
);
26142 expected_next_loc_note
= next_note
;
26143 cached_next_real_insn
= next_real
;
26146 cached_next_real_insn
= NULL
;
26148 /* If there are no instructions which would be affected by this note,
26149 don't do anything. */
26151 && next_real
== NULL_RTX
26152 && !NOTE_DURING_CALL_P (loc_note
))
26157 if (next_real
== NULL_RTX
)
26158 next_real
= get_last_insn ();
26160 /* If there were any real insns between note we processed last time
26161 and this note (or if it is the first note), clear
26162 last_{,postcall_}label so that they are not reused this time. */
26163 if (last_var_location_insn
== NULL_RTX
26164 || last_var_location_insn
!= next_real
26165 || last_in_cold_section_p
!= in_cold_section_p
)
26168 last_postcall_label
= NULL
;
26173 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
26174 newloc
= add_var_loc_to_decl (decl
, loc_note
,
26175 NOTE_DURING_CALL_P (loc_note
)
26176 ? last_postcall_label
: last_label
);
26177 if (newloc
== NULL
)
26186 /* If there were no real insns between note we processed last time
26187 and this note, use the label we emitted last time. Otherwise
26188 create a new label and emit it. */
26189 if (last_label
== NULL
)
26191 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
26192 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
26194 last_label
= ggc_strdup (loclabel
);
26195 /* See if loclabel might be equal to .Ltext0. If yes,
26196 bump first_loclabel_num_not_at_text_label. */
26197 if (!have_multiple_function_sections
26198 && in_first_function_p
26199 && maybe_at_text_label_p
)
26201 static rtx_insn
*last_start
;
26203 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
26204 if (insn
== last_start
)
26206 else if (!NONDEBUG_INSN_P (insn
))
26210 rtx body
= PATTERN (insn
);
26211 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
26213 /* Inline asm could occupy zero bytes. */
26214 else if (GET_CODE (body
) == ASM_INPUT
26215 || asm_noperands (body
) >= 0)
26217 #ifdef HAVE_attr_length
26218 else if (get_attr_min_length (insn
) == 0)
26223 /* Assume insn has non-zero length. */
26224 maybe_at_text_label_p
= false;
26228 if (maybe_at_text_label_p
)
26230 last_start
= loc_note
;
26231 first_loclabel_num_not_at_text_label
= loclabel_num
;
26236 gcc_assert ((loc_note
== NULL_RTX
&& call_insn
!= NULL_RTX
)
26237 || (loc_note
!= NULL_RTX
&& call_insn
== NULL_RTX
));
26241 struct call_arg_loc_node
*ca_loc
26242 = ggc_cleared_alloc
<call_arg_loc_node
> ();
26244 = loc_note
!= NULL_RTX
? prev_real_insn (loc_note
) : call_insn
;
26246 ca_loc
->call_arg_loc_note
= loc_note
;
26247 ca_loc
->next
= NULL
;
26248 ca_loc
->label
= last_label
;
26251 || (NONJUMP_INSN_P (prev
)
26252 && GET_CODE (PATTERN (prev
)) == SEQUENCE
26253 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
26254 if (!CALL_P (prev
))
26255 prev
= as_a
<rtx_sequence
*> (PATTERN (prev
))->insn (0);
26256 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
26258 /* Look for a SYMBOL_REF in the "prev" instruction. */
26259 rtx x
= get_call_rtx_from (PATTERN (prev
));
26262 /* Try to get the call symbol, if any. */
26263 if (MEM_P (XEXP (x
, 0)))
26265 /* First, look for a memory access to a symbol_ref. */
26266 if (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
26267 && SYMBOL_REF_DECL (XEXP (x
, 0))
26268 && TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0))) == FUNCTION_DECL
)
26269 ca_loc
->symbol_ref
= XEXP (x
, 0);
26270 /* Otherwise, look at a compile-time known user-level function
26274 && TREE_CODE (MEM_EXPR (x
)) == FUNCTION_DECL
)
26275 ca_loc
->symbol_ref
= XEXP (DECL_RTL (MEM_EXPR (x
)), 0);
26278 ca_loc
->block
= insn_scope (prev
);
26279 if (call_arg_locations
)
26280 call_arg_loc_last
->next
= ca_loc
;
26282 call_arg_locations
= ca_loc
;
26283 call_arg_loc_last
= ca_loc
;
26285 else if (loc_note
!= NULL_RTX
&& !NOTE_DURING_CALL_P (loc_note
))
26286 newloc
->label
= last_label
;
26289 if (!last_postcall_label
)
26291 sprintf (loclabel
, "%s-1", last_label
);
26292 last_postcall_label
= ggc_strdup (loclabel
);
26294 newloc
->label
= last_postcall_label
;
26297 last_var_location_insn
= next_real
;
26298 last_in_cold_section_p
= in_cold_section_p
;
26301 /* Called from finalize_size_functions for size functions so that their body
26302 can be encoded in the debug info to describe the layout of variable-length
26306 dwarf2out_size_function (tree decl
)
26308 function_to_dwarf_procedure (decl
);
26311 /* Note in one location list that text section has changed. */
26314 var_location_switch_text_section_1 (var_loc_list
**slot
, void *)
26316 var_loc_list
*list
= *slot
;
26318 list
->last_before_switch
26319 = list
->last
->next
? list
->last
->next
: list
->last
;
26323 /* Note in all location lists that text section has changed. */
26326 var_location_switch_text_section (void)
26328 if (decl_loc_table
== NULL
)
26331 decl_loc_table
->traverse
<void *, var_location_switch_text_section_1
> (NULL
);
26334 /* Create a new line number table. */
26336 static dw_line_info_table
*
26337 new_line_info_table (void)
26339 dw_line_info_table
*table
;
26341 table
= ggc_cleared_alloc
<dw_line_info_table
> ();
26342 table
->file_num
= 1;
26343 table
->line_num
= 1;
26344 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
26349 /* Lookup the "current" table into which we emit line info, so
26350 that we don't have to do it for every source line. */
26353 set_cur_line_info_table (section
*sec
)
26355 dw_line_info_table
*table
;
26357 if (sec
== text_section
)
26358 table
= text_section_line_info
;
26359 else if (sec
== cold_text_section
)
26361 table
= cold_text_section_line_info
;
26364 cold_text_section_line_info
= table
= new_line_info_table ();
26365 table
->end_label
= cold_end_label
;
26370 const char *end_label
;
26372 if (crtl
->has_bb_partition
)
26374 if (in_cold_section_p
)
26375 end_label
= crtl
->subsections
.cold_section_end_label
;
26377 end_label
= crtl
->subsections
.hot_section_end_label
;
26381 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
26382 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
26383 current_function_funcdef_no
);
26384 end_label
= ggc_strdup (label
);
26387 table
= new_line_info_table ();
26388 table
->end_label
= end_label
;
26390 vec_safe_push (separate_line_info
, table
);
26393 if (DWARF2_ASM_LINE_DEBUG_INFO
)
26394 table
->is_stmt
= (cur_line_info_table
26395 ? cur_line_info_table
->is_stmt
26396 : DWARF_LINE_DEFAULT_IS_STMT_START
);
26397 cur_line_info_table
= table
;
26401 /* We need to reset the locations at the beginning of each
26402 function. We can't do this in the end_function hook, because the
26403 declarations that use the locations won't have been output when
26404 that hook is called. Also compute have_multiple_function_sections here. */
26407 dwarf2out_begin_function (tree fun
)
26409 section
*sec
= function_section (fun
);
26411 if (sec
!= text_section
)
26412 have_multiple_function_sections
= true;
26414 if (crtl
->has_bb_partition
&& !cold_text_section
)
26416 gcc_assert (current_function_decl
== fun
);
26417 cold_text_section
= unlikely_text_section ();
26418 switch_to_section (cold_text_section
);
26419 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
26420 switch_to_section (sec
);
26423 dwarf2out_note_section_used ();
26424 call_site_count
= 0;
26425 tail_call_site_count
= 0;
26427 set_cur_line_info_table (sec
);
26430 /* Helper function of dwarf2out_end_function, called only after emitting
26431 the very first function into assembly. Check if some .debug_loc range
26432 might end with a .LVL* label that could be equal to .Ltext0.
26433 In that case we must force using absolute addresses in .debug_loc ranges,
26434 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
26435 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
26437 Set have_multiple_function_sections to true in that case and
26438 terminate htab traversal. */
26441 find_empty_loc_ranges_at_text_label (var_loc_list
**slot
, int)
26443 var_loc_list
*entry
= *slot
;
26444 struct var_loc_node
*node
;
26446 node
= entry
->first
;
26447 if (node
&& node
->next
&& node
->next
->label
)
26450 const char *label
= node
->next
->label
;
26451 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
26453 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
26455 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
26456 if (strcmp (label
, loclabel
) == 0)
26458 have_multiple_function_sections
= true;
26466 /* Hook called after emitting a function into assembly.
26467 This does something only for the very first function emitted. */
26470 dwarf2out_end_function (unsigned int)
26472 if (in_first_function_p
26473 && !have_multiple_function_sections
26474 && first_loclabel_num_not_at_text_label
26476 decl_loc_table
->traverse
<int, find_empty_loc_ranges_at_text_label
> (0);
26477 in_first_function_p
= false;
26478 maybe_at_text_label_p
= false;
26481 /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
26482 front-ends register a translation unit even before dwarf2out_init is
26484 static tree main_translation_unit
= NULL_TREE
;
26486 /* Hook called by front-ends after they built their main translation unit.
26487 Associate comp_unit_die to UNIT. */
26490 dwarf2out_register_main_translation_unit (tree unit
)
26492 gcc_assert (TREE_CODE (unit
) == TRANSLATION_UNIT_DECL
26493 && main_translation_unit
== NULL_TREE
);
26494 main_translation_unit
= unit
;
26495 /* If dwarf2out_init has not been called yet, it will perform the association
26496 itself looking at main_translation_unit. */
26497 if (decl_die_table
!= NULL
)
26498 equate_decl_number_to_die (unit
, comp_unit_die ());
26501 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
26504 push_dw_line_info_entry (dw_line_info_table
*table
,
26505 enum dw_line_info_opcode opcode
, unsigned int val
)
26507 dw_line_info_entry e
;
26510 vec_safe_push (table
->entries
, e
);
26513 /* Output a label to mark the beginning of a source code line entry
26514 and record information relating to this source line, in
26515 'line_info_table' for later output of the .debug_line section. */
26516 /* ??? The discriminator parameter ought to be unsigned. */
26519 dwarf2out_source_line (unsigned int line
, unsigned int column
,
26520 const char *filename
,
26521 int discriminator
, bool is_stmt
)
26523 unsigned int file_num
;
26524 dw_line_info_table
*table
;
26526 if (debug_info_level
< DINFO_LEVEL_TERSE
|| line
== 0)
26529 /* The discriminator column was added in dwarf4. Simplify the below
26530 by simply removing it if we're not supposed to output it. */
26531 if (dwarf_version
< 4 && dwarf_strict
)
26534 if (!debug_column_info
)
26537 table
= cur_line_info_table
;
26538 file_num
= maybe_emit_file (lookup_filename (filename
));
26540 /* ??? TODO: Elide duplicate line number entries. Traditionally,
26541 the debugger has used the second (possibly duplicate) line number
26542 at the beginning of the function to mark the end of the prologue.
26543 We could eliminate any other duplicates within the function. For
26544 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
26545 that second line number entry. */
26546 /* Recall that this end-of-prologue indication is *not* the same thing
26547 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
26548 to which the hook corresponds, follows the last insn that was
26549 emitted by gen_prologue. What we need is to precede the first insn
26550 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
26551 insn that corresponds to something the user wrote. These may be
26552 very different locations once scheduling is enabled. */
26554 if (0 && file_num
== table
->file_num
26555 && line
== table
->line_num
26556 && column
== table
->column_num
26557 && discriminator
== table
->discrim_num
26558 && is_stmt
== table
->is_stmt
)
26561 switch_to_section (current_function_section ());
26563 /* If requested, emit something human-readable. */
26564 if (flag_debug_asm
)
26566 if (debug_column_info
)
26567 fprintf (asm_out_file
, "\t%s %s:%d:%d\n", ASM_COMMENT_START
,
26568 filename
, line
, column
);
26570 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
26574 if (DWARF2_ASM_LINE_DEBUG_INFO
)
26576 /* Emit the .loc directive understood by GNU as. */
26577 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
26578 file_num, line, is_stmt, discriminator */
26579 fputs ("\t.loc ", asm_out_file
);
26580 fprint_ul (asm_out_file
, file_num
);
26581 putc (' ', asm_out_file
);
26582 fprint_ul (asm_out_file
, line
);
26583 putc (' ', asm_out_file
);
26584 if (debug_column_info
)
26585 fprint_ul (asm_out_file
, column
);
26587 putc ('0', asm_out_file
);
26589 if (is_stmt
!= table
->is_stmt
)
26591 fputs (" is_stmt ", asm_out_file
);
26592 putc (is_stmt
? '1' : '0', asm_out_file
);
26594 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
26596 gcc_assert (discriminator
> 0);
26597 fputs (" discriminator ", asm_out_file
);
26598 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
26600 putc ('\n', asm_out_file
);
26604 unsigned int label_num
= ++line_info_label_num
;
26606 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
26608 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
26609 if (file_num
!= table
->file_num
)
26610 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
26611 if (discriminator
!= table
->discrim_num
)
26612 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
26613 if (is_stmt
!= table
->is_stmt
)
26614 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
26615 push_dw_line_info_entry (table
, LI_set_line
, line
);
26616 if (debug_column_info
)
26617 push_dw_line_info_entry (table
, LI_set_column
, column
);
26620 table
->file_num
= file_num
;
26621 table
->line_num
= line
;
26622 table
->column_num
= column
;
26623 table
->discrim_num
= discriminator
;
26624 table
->is_stmt
= is_stmt
;
26625 table
->in_use
= true;
26628 /* Record the beginning of a new source file. */
26631 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
26633 if (flag_eliminate_dwarf2_dups
)
26635 /* Record the beginning of the file for break_out_includes. */
26636 dw_die_ref bincl_die
;
26638 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
26639 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
26642 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26645 e
.code
= DW_MACINFO_start_file
;
26647 e
.info
= ggc_strdup (filename
);
26648 vec_safe_push (macinfo_table
, e
);
26652 /* Record the end of a source file. */
26655 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
26657 if (flag_eliminate_dwarf2_dups
)
26658 /* Record the end of the file for break_out_includes. */
26659 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
26661 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26664 e
.code
= DW_MACINFO_end_file
;
26667 vec_safe_push (macinfo_table
, e
);
26671 /* Called from debug_define in toplev.c. The `buffer' parameter contains
26672 the tail part of the directive line, i.e. the part which is past the
26673 initial whitespace, #, whitespace, directive-name, whitespace part. */
26676 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
26677 const char *buffer ATTRIBUTE_UNUSED
)
26679 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26682 /* Insert a dummy first entry to be able to optimize the whole
26683 predefined macro block using DW_MACRO_import. */
26684 if (macinfo_table
->is_empty () && lineno
<= 1)
26689 vec_safe_push (macinfo_table
, e
);
26691 e
.code
= DW_MACINFO_define
;
26693 e
.info
= ggc_strdup (buffer
);
26694 vec_safe_push (macinfo_table
, e
);
26698 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
26699 the tail part of the directive line, i.e. the part which is past the
26700 initial whitespace, #, whitespace, directive-name, whitespace part. */
26703 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
26704 const char *buffer ATTRIBUTE_UNUSED
)
26706 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26709 /* Insert a dummy first entry to be able to optimize the whole
26710 predefined macro block using DW_MACRO_import. */
26711 if (macinfo_table
->is_empty () && lineno
<= 1)
26716 vec_safe_push (macinfo_table
, e
);
26718 e
.code
= DW_MACINFO_undef
;
26720 e
.info
= ggc_strdup (buffer
);
26721 vec_safe_push (macinfo_table
, e
);
26725 /* Helpers to manipulate hash table of CUs. */
26727 struct macinfo_entry_hasher
: nofree_ptr_hash
<macinfo_entry
>
26729 static inline hashval_t
hash (const macinfo_entry
*);
26730 static inline bool equal (const macinfo_entry
*, const macinfo_entry
*);
26734 macinfo_entry_hasher::hash (const macinfo_entry
*entry
)
26736 return htab_hash_string (entry
->info
);
26740 macinfo_entry_hasher::equal (const macinfo_entry
*entry1
,
26741 const macinfo_entry
*entry2
)
26743 return !strcmp (entry1
->info
, entry2
->info
);
26746 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
26748 /* Output a single .debug_macinfo entry. */
26751 output_macinfo_op (macinfo_entry
*ref
)
26755 struct indirect_string_node
*node
;
26756 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
26757 struct dwarf_file_data
*fd
;
26761 case DW_MACINFO_start_file
:
26762 fd
= lookup_filename (ref
->info
);
26763 file_num
= maybe_emit_file (fd
);
26764 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
26765 dw2_asm_output_data_uleb128 (ref
->lineno
,
26766 "Included from line number %lu",
26767 (unsigned long) ref
->lineno
);
26768 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
26770 case DW_MACINFO_end_file
:
26771 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
26773 case DW_MACINFO_define
:
26774 case DW_MACINFO_undef
:
26775 len
= strlen (ref
->info
) + 1;
26777 && len
> DWARF_OFFSET_SIZE
26778 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
26779 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
26781 ref
->code
= ref
->code
== DW_MACINFO_define
26782 ? DW_MACRO_define_strp
: DW_MACRO_undef_strp
;
26783 output_macinfo_op (ref
);
26786 dw2_asm_output_data (1, ref
->code
,
26787 ref
->code
== DW_MACINFO_define
26788 ? "Define macro" : "Undefine macro");
26789 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
26790 (unsigned long) ref
->lineno
);
26791 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
26793 case DW_MACRO_define_strp
:
26794 case DW_MACRO_undef_strp
:
26795 node
= find_AT_string (ref
->info
);
26797 && (node
->form
== DW_FORM_strp
26798 || node
->form
== DW_FORM_GNU_str_index
));
26799 dw2_asm_output_data (1, ref
->code
,
26800 ref
->code
== DW_MACRO_define_strp
26801 ? "Define macro strp"
26802 : "Undefine macro strp");
26803 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
26804 (unsigned long) ref
->lineno
);
26805 if (node
->form
== DW_FORM_strp
)
26806 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
26807 debug_str_section
, "The macro: \"%s\"",
26810 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
26813 case DW_MACRO_import
:
26814 dw2_asm_output_data (1, ref
->code
, "Import");
26815 ASM_GENERATE_INTERNAL_LABEL (label
,
26816 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
26817 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
26820 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
26821 ASM_COMMENT_START
, (unsigned long) ref
->code
);
26826 /* Attempt to make a sequence of define/undef macinfo ops shareable with
26827 other compilation unit .debug_macinfo sections. IDX is the first
26828 index of a define/undef, return the number of ops that should be
26829 emitted in a comdat .debug_macinfo section and emit
26830 a DW_MACRO_import entry referencing it.
26831 If the define/undef entry should be emitted normally, return 0. */
26834 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
26835 macinfo_hash_type
**macinfo_htab
)
26837 macinfo_entry
*first
, *second
, *cur
, *inc
;
26838 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
26839 unsigned char checksum
[16];
26840 struct md5_ctx ctx
;
26841 char *grp_name
, *tail
;
26843 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
26844 macinfo_entry
**slot
;
26846 first
= &(*macinfo_table
)[idx
];
26847 second
= &(*macinfo_table
)[idx
+ 1];
26849 /* Optimize only if there are at least two consecutive define/undef ops,
26850 and either all of them are before first DW_MACINFO_start_file
26851 with lineno {0,1} (i.e. predefined macro block), or all of them are
26852 in some included header file. */
26853 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
26855 if (vec_safe_is_empty (files
))
26857 if (first
->lineno
> 1 || second
->lineno
> 1)
26860 else if (first
->lineno
== 0)
26863 /* Find the last define/undef entry that can be grouped together
26864 with first and at the same time compute md5 checksum of their
26865 codes, linenumbers and strings. */
26866 md5_init_ctx (&ctx
);
26867 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
26868 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
26870 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
26874 unsigned char code
= cur
->code
;
26875 md5_process_bytes (&code
, 1, &ctx
);
26876 checksum_uleb128 (cur
->lineno
, &ctx
);
26877 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
26879 md5_finish_ctx (&ctx
, checksum
);
26882 /* From the containing include filename (if any) pick up just
26883 usable characters from its basename. */
26884 if (vec_safe_is_empty (files
))
26887 base
= lbasename (files
->last ().info
);
26888 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
26889 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
26890 encoded_filename_len
++;
26891 /* Count . at the end. */
26892 if (encoded_filename_len
)
26893 encoded_filename_len
++;
26895 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
26896 linebuf_len
= strlen (linebuf
);
26898 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
26899 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
26901 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
26902 tail
= grp_name
+ 4;
26903 if (encoded_filename_len
)
26905 for (i
= 0; base
[i
]; i
++)
26906 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
26910 memcpy (tail
, linebuf
, linebuf_len
);
26911 tail
+= linebuf_len
;
26913 for (i
= 0; i
< 16; i
++)
26914 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
26916 /* Construct a macinfo_entry for DW_MACRO_import
26917 in the empty vector entry before the first define/undef. */
26918 inc
= &(*macinfo_table
)[idx
- 1];
26919 inc
->code
= DW_MACRO_import
;
26921 inc
->info
= ggc_strdup (grp_name
);
26922 if (!*macinfo_htab
)
26923 *macinfo_htab
= new macinfo_hash_type (10);
26924 /* Avoid emitting duplicates. */
26925 slot
= (*macinfo_htab
)->find_slot (inc
, INSERT
);
26930 /* If such an entry has been used before, just emit
26931 a DW_MACRO_import op. */
26933 output_macinfo_op (inc
);
26934 /* And clear all macinfo_entry in the range to avoid emitting them
26935 in the second pass. */
26936 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
26945 inc
->lineno
= (*macinfo_htab
)->elements ();
26946 output_macinfo_op (inc
);
26951 /* Save any strings needed by the macinfo table in the debug str
26952 table. All strings must be collected into the table by the time
26953 index_string is called. */
26956 save_macinfo_strings (void)
26960 macinfo_entry
*ref
;
26962 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
26966 /* Match the logic in output_macinfo_op to decide on
26967 indirect strings. */
26968 case DW_MACINFO_define
:
26969 case DW_MACINFO_undef
:
26970 len
= strlen (ref
->info
) + 1;
26972 && len
> DWARF_OFFSET_SIZE
26973 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
26974 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
26975 set_indirect_string (find_AT_string (ref
->info
));
26977 case DW_MACRO_define_strp
:
26978 case DW_MACRO_undef_strp
:
26979 set_indirect_string (find_AT_string (ref
->info
));
26987 /* Output macinfo section(s). */
26990 output_macinfo (void)
26993 unsigned long length
= vec_safe_length (macinfo_table
);
26994 macinfo_entry
*ref
;
26995 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
26996 macinfo_hash_type
*macinfo_htab
= NULL
;
26997 char dl_section_ref
[MAX_ARTIFICIAL_LABEL_BYTES
];
27002 /* output_macinfo* uses these interchangeably. */
27003 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_define
27004 && (int) DW_MACINFO_undef
== (int) DW_MACRO_undef
27005 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_start_file
27006 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_end_file
);
27008 /* AIX Assembler inserts the length, so adjust the reference to match the
27009 offset expected by debuggers. */
27010 strcpy (dl_section_ref
, debug_line_section_label
);
27011 if (XCOFF_DEBUGGING_INFO
)
27012 strcat (dl_section_ref
, DWARF_INITIAL_LENGTH_SIZE_STR
);
27014 /* For .debug_macro emit the section header. */
27015 if (!dwarf_strict
|| dwarf_version
>= 5)
27017 dw2_asm_output_data (2, dwarf_version
>= 5 ? 5 : 4,
27018 "DWARF macro version number");
27019 if (DWARF_OFFSET_SIZE
== 8)
27020 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
27022 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
27023 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
27024 (!dwarf_split_debug_info
? dl_section_ref
27025 : debug_skeleton_line_section_label
),
27026 debug_line_section
, NULL
);
27029 /* In the first loop, it emits the primary .debug_macinfo section
27030 and after each emitted op the macinfo_entry is cleared.
27031 If a longer range of define/undef ops can be optimized using
27032 DW_MACRO_import, the DW_MACRO_import op is emitted and kept in
27033 the vector before the first define/undef in the range and the
27034 whole range of define/undef ops is not emitted and kept. */
27035 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
27039 case DW_MACINFO_start_file
:
27040 vec_safe_push (files
, *ref
);
27042 case DW_MACINFO_end_file
:
27043 if (!vec_safe_is_empty (files
))
27046 case DW_MACINFO_define
:
27047 case DW_MACINFO_undef
:
27048 if ((!dwarf_strict
|| dwarf_version
>= 5)
27049 && HAVE_COMDAT_GROUP
27050 && vec_safe_length (files
) != 1
27053 && (*macinfo_table
)[i
- 1].code
== 0)
27055 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
27064 /* A dummy entry may be inserted at the beginning to be able
27065 to optimize the whole block of predefined macros. */
27071 output_macinfo_op (ref
);
27079 delete macinfo_htab
;
27080 macinfo_htab
= NULL
;
27082 /* If any DW_MACRO_import were used, on those DW_MACRO_import entries
27083 terminate the current chain and switch to a new comdat .debug_macinfo
27084 section and emit the define/undef entries within it. */
27085 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
27090 case DW_MACRO_import
:
27092 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
27093 tree comdat_key
= get_identifier (ref
->info
);
27094 /* Terminate the previous .debug_macinfo section. */
27095 dw2_asm_output_data (1, 0, "End compilation unit");
27096 targetm
.asm_out
.named_section (debug_macinfo_section_name
,
27098 | SECTION_LINKONCE
,
27100 ASM_GENERATE_INTERNAL_LABEL (label
,
27101 DEBUG_MACRO_SECTION_LABEL
,
27103 ASM_OUTPUT_LABEL (asm_out_file
, label
);
27106 dw2_asm_output_data (2, dwarf_version
>= 5 ? 5 : 4,
27107 "DWARF macro version number");
27108 if (DWARF_OFFSET_SIZE
== 8)
27109 dw2_asm_output_data (1, 1, "Flags: 64-bit");
27111 dw2_asm_output_data (1, 0, "Flags: 32-bit");
27114 case DW_MACINFO_define
:
27115 case DW_MACINFO_undef
:
27116 output_macinfo_op (ref
);
27121 gcc_unreachable ();
27125 /* Initialize the various sections and labels for dwarf output. */
27128 init_sections_and_labels (void)
27130 if (!dwarf_split_debug_info
)
27132 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
27133 SECTION_DEBUG
, NULL
);
27134 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
27135 SECTION_DEBUG
, NULL
);
27136 debug_loc_section
= get_section (dwarf_version
>= 5
27137 ? DEBUG_LOCLISTS_SECTION
27138 : DEBUG_LOC_SECTION
,
27139 SECTION_DEBUG
, NULL
);
27140 debug_macinfo_section_name
27141 = (dwarf_strict
&& dwarf_version
< 5)
27142 ? DEBUG_MACINFO_SECTION
: DEBUG_MACRO_SECTION
;
27143 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
27144 SECTION_DEBUG
, NULL
);
27148 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
27149 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27150 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
27151 SECTION_DEBUG
| SECTION_EXCLUDE
,
27153 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
27154 SECTION_DEBUG
, NULL
);
27155 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
27156 SECTION_DEBUG
, NULL
);
27157 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
27158 SECTION_DEBUG
, NULL
);
27159 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
27160 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
27162 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
27163 the main .o, but the skeleton_line goes into the split off dwo. */
27164 debug_skeleton_line_section
27165 = get_section (DEBUG_DWO_LINE_SECTION
,
27166 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27167 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
27168 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
27169 debug_str_offsets_section
= get_section (DEBUG_DWO_STR_OFFSETS_SECTION
,
27170 SECTION_DEBUG
| SECTION_EXCLUDE
,
27172 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
27173 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
27174 debug_loc_section
= get_section (dwarf_version
>= 5
27175 ? DEBUG_DWO_LOCLISTS_SECTION
27176 : DEBUG_DWO_LOC_SECTION
,
27177 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27178 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
27179 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
27180 debug_macinfo_section_name
27181 = (dwarf_strict
&& dwarf_version
< 5)
27182 ? DEBUG_DWO_MACINFO_SECTION
: DEBUG_DWO_MACRO_SECTION
;
27183 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
27184 SECTION_DEBUG
| SECTION_EXCLUDE
,
27187 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
27188 SECTION_DEBUG
, NULL
);
27189 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
27190 SECTION_DEBUG
, NULL
);
27191 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
27192 SECTION_DEBUG
, NULL
);
27193 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
27194 SECTION_DEBUG
, NULL
);
27195 debug_str_section
= get_section (DEBUG_STR_SECTION
,
27196 DEBUG_STR_SECTION_FLAGS
, NULL
);
27197 if (!dwarf_split_debug_info
&& !DWARF2_ASM_LINE_DEBUG_INFO
)
27198 debug_line_str_section
= get_section (DEBUG_LINE_STR_SECTION
,
27199 DEBUG_STR_SECTION_FLAGS
, NULL
);
27201 debug_ranges_section
= get_section (dwarf_version
>= 5
27202 ? DEBUG_RNGLISTS_SECTION
27203 : DEBUG_RANGES_SECTION
,
27204 SECTION_DEBUG
, NULL
);
27205 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
27206 SECTION_DEBUG
, NULL
);
27208 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
27209 DEBUG_ABBREV_SECTION_LABEL
, 0);
27210 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
27211 DEBUG_INFO_SECTION_LABEL
, 0);
27212 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
27213 DEBUG_LINE_SECTION_LABEL
, 0);
27214 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
27215 DEBUG_RANGES_SECTION_LABEL
, 0);
27216 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
27217 ASM_GENERATE_INTERNAL_LABEL (ranges_base_label
,
27218 DEBUG_RANGES_SECTION_LABEL
, 1);
27219 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
27220 DEBUG_ADDR_SECTION_LABEL
, 0);
27221 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
27222 (dwarf_strict
&& dwarf_version
< 5)
27223 ? DEBUG_MACINFO_SECTION_LABEL
27224 : DEBUG_MACRO_SECTION_LABEL
, 0);
27225 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
27228 /* Set up for Dwarf output at the start of compilation. */
27231 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
27233 /* This option is currently broken, see (PR53118 and PR46102). */
27234 if (flag_eliminate_dwarf2_dups
27235 && strstr (lang_hooks
.name
, "C++"))
27237 warning (0, "-feliminate-dwarf2-dups is broken for C++, ignoring");
27238 flag_eliminate_dwarf2_dups
= 0;
27241 /* Allocate the file_table. */
27242 file_table
= hash_table
<dwarf_file_hasher
>::create_ggc (50);
27244 #ifndef DWARF2_LINENO_DEBUGGING_INFO
27245 /* Allocate the decl_die_table. */
27246 decl_die_table
= hash_table
<decl_die_hasher
>::create_ggc (10);
27248 /* Allocate the decl_loc_table. */
27249 decl_loc_table
= hash_table
<decl_loc_hasher
>::create_ggc (10);
27251 /* Allocate the cached_dw_loc_list_table. */
27252 cached_dw_loc_list_table
= hash_table
<dw_loc_list_hasher
>::create_ggc (10);
27254 /* Allocate the initial hunk of the decl_scope_table. */
27255 vec_alloc (decl_scope_table
, 256);
27257 /* Allocate the initial hunk of the abbrev_die_table. */
27258 vec_alloc (abbrev_die_table
, 256);
27259 /* Zero-th entry is allocated, but unused. */
27260 abbrev_die_table
->quick_push (NULL
);
27262 /* Allocate the dwarf_proc_stack_usage_map. */
27263 dwarf_proc_stack_usage_map
= new hash_map
<dw_die_ref
, int>;
27265 /* Allocate the pubtypes and pubnames vectors. */
27266 vec_alloc (pubname_table
, 32);
27267 vec_alloc (pubtype_table
, 32);
27269 vec_alloc (incomplete_types
, 64);
27271 vec_alloc (used_rtx_array
, 32);
27273 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
27274 vec_alloc (macinfo_table
, 64);
27277 /* If front-ends already registered a main translation unit but we were not
27278 ready to perform the association, do this now. */
27279 if (main_translation_unit
!= NULL_TREE
)
27280 equate_decl_number_to_die (main_translation_unit
, comp_unit_die ());
27283 /* Called before compile () starts outputtting functions, variables
27284 and toplevel asms into assembly. */
27287 dwarf2out_assembly_start (void)
27289 #ifndef DWARF2_LINENO_DEBUGGING_INFO
27290 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
27291 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
27292 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
27293 COLD_TEXT_SECTION_LABEL
, 0);
27294 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
27296 switch_to_section (text_section
);
27297 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
27300 /* Make sure the line number table for .text always exists. */
27301 text_section_line_info
= new_line_info_table ();
27302 text_section_line_info
->end_label
= text_end_label
;
27304 #ifdef DWARF2_LINENO_DEBUGGING_INFO
27305 cur_line_info_table
= text_section_line_info
;
27308 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
27309 && dwarf2out_do_cfi_asm ()
27310 && (!(flag_unwind_tables
|| flag_exceptions
)
27311 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
27312 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
27315 /* A helper function for dwarf2out_finish called through
27316 htab_traverse. Assign a string its index. All strings must be
27317 collected into the table by the time index_string is called,
27318 because the indexing code relies on htab_traverse to traverse nodes
27319 in the same order for each run. */
27322 index_string (indirect_string_node
**h
, unsigned int *index
)
27324 indirect_string_node
*node
= *h
;
27326 find_string_form (node
);
27327 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
27329 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
27330 node
->index
= *index
;
27336 /* A helper function for output_indirect_strings called through
27337 htab_traverse. Output the offset to a string and update the
27341 output_index_string_offset (indirect_string_node
**h
, unsigned int *offset
)
27343 indirect_string_node
*node
= *h
;
27345 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
27347 /* Assert that this node has been assigned an index. */
27348 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
27349 && node
->index
!= NOT_INDEXED
);
27350 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
27351 "indexed string 0x%x: %s", node
->index
, node
->str
);
27352 *offset
+= strlen (node
->str
) + 1;
27357 /* A helper function for dwarf2out_finish called through
27358 htab_traverse. Output the indexed string. */
27361 output_index_string (indirect_string_node
**h
, unsigned int *cur_idx
)
27363 struct indirect_string_node
*node
= *h
;
27365 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
27367 /* Assert that the strings are output in the same order as their
27368 indexes were assigned. */
27369 gcc_assert (*cur_idx
== node
->index
);
27370 assemble_string (node
->str
, strlen (node
->str
) + 1);
27376 /* A helper function for dwarf2out_finish called through
27377 htab_traverse. Emit one queued .debug_str string. */
27380 output_indirect_string (indirect_string_node
**h
, enum dwarf_form form
)
27382 struct indirect_string_node
*node
= *h
;
27384 node
->form
= find_string_form (node
);
27385 if (node
->form
== form
&& node
->refcount
> 0)
27387 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
27388 assemble_string (node
->str
, strlen (node
->str
) + 1);
27394 /* Output the indexed string table. */
27397 output_indirect_strings (void)
27399 switch_to_section (debug_str_section
);
27400 if (!dwarf_split_debug_info
)
27401 debug_str_hash
->traverse
<enum dwarf_form
,
27402 output_indirect_string
> (DW_FORM_strp
);
27405 unsigned int offset
= 0;
27406 unsigned int cur_idx
= 0;
27408 skeleton_debug_str_hash
->traverse
<enum dwarf_form
,
27409 output_indirect_string
> (DW_FORM_strp
);
27411 switch_to_section (debug_str_offsets_section
);
27412 debug_str_hash
->traverse_noresize
27413 <unsigned int *, output_index_string_offset
> (&offset
);
27414 switch_to_section (debug_str_dwo_section
);
27415 debug_str_hash
->traverse_noresize
<unsigned int *, output_index_string
>
27420 /* Callback for htab_traverse to assign an index to an entry in the
27421 table, and to write that entry to the .debug_addr section. */
27424 output_addr_table_entry (addr_table_entry
**slot
, unsigned int *cur_index
)
27426 addr_table_entry
*entry
= *slot
;
27428 if (entry
->refcount
== 0)
27430 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
27431 || entry
->index
== NOT_INDEXED
);
27435 gcc_assert (entry
->index
== *cur_index
);
27438 switch (entry
->kind
)
27441 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
27442 "0x%x", entry
->index
);
27444 case ate_kind_rtx_dtprel
:
27445 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
27446 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
27449 fputc ('\n', asm_out_file
);
27451 case ate_kind_label
:
27452 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
27453 "0x%x", entry
->index
);
27456 gcc_unreachable ();
27461 /* Produce the .debug_addr section. */
27464 output_addr_table (void)
27466 unsigned int index
= 0;
27467 if (addr_index_table
== NULL
|| addr_index_table
->size () == 0)
27470 switch_to_section (debug_addr_section
);
27472 ->traverse_noresize
<unsigned int *, output_addr_table_entry
> (&index
);
27475 #if ENABLE_ASSERT_CHECKING
27476 /* Verify that all marks are clear. */
27479 verify_marks_clear (dw_die_ref die
)
27483 gcc_assert (! die
->die_mark
);
27484 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
27486 #endif /* ENABLE_ASSERT_CHECKING */
27488 /* Clear the marks for a die and its children.
27489 Be cool if the mark isn't set. */
27492 prune_unmark_dies (dw_die_ref die
)
27498 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
27501 /* Given LOC that is referenced by a DIE we're marking as used, find all
27502 referenced DWARF procedures it references and mark them as used. */
27505 prune_unused_types_walk_loc_descr (dw_loc_descr_ref loc
)
27507 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
27508 switch (loc
->dw_loc_opc
)
27510 case DW_OP_implicit_pointer
:
27511 case DW_OP_convert
:
27512 case DW_OP_reinterpret
:
27513 case DW_OP_GNU_implicit_pointer
:
27514 case DW_OP_GNU_convert
:
27515 case DW_OP_GNU_reinterpret
:
27516 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
)
27517 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
27519 case DW_OP_GNU_variable_value
:
27520 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
27523 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
27526 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
27527 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
27528 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
27533 case DW_OP_call_ref
:
27534 case DW_OP_const_type
:
27535 case DW_OP_GNU_const_type
:
27536 case DW_OP_GNU_parameter_ref
:
27537 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
);
27538 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
27540 case DW_OP_regval_type
:
27541 case DW_OP_deref_type
:
27542 case DW_OP_GNU_regval_type
:
27543 case DW_OP_GNU_deref_type
:
27544 gcc_assert (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_die_ref
);
27545 prune_unused_types_mark (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
, 1);
27547 case DW_OP_entry_value
:
27548 case DW_OP_GNU_entry_value
:
27549 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
);
27550 prune_unused_types_walk_loc_descr (loc
->dw_loc_oprnd1
.v
.val_loc
);
27557 /* Given DIE that we're marking as used, find any other dies
27558 it references as attributes and mark them as used. */
27561 prune_unused_types_walk_attribs (dw_die_ref die
)
27566 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
27568 switch (AT_class (a
))
27570 /* Make sure DWARF procedures referenced by location descriptions will
27572 case dw_val_class_loc
:
27573 prune_unused_types_walk_loc_descr (AT_loc (a
));
27575 case dw_val_class_loc_list
:
27576 for (dw_loc_list_ref list
= AT_loc_list (a
);
27578 list
= list
->dw_loc_next
)
27579 prune_unused_types_walk_loc_descr (list
->expr
);
27582 case dw_val_class_die_ref
:
27583 /* A reference to another DIE.
27584 Make sure that it will get emitted.
27585 If it was broken out into a comdat group, don't follow it. */
27586 if (! AT_ref (a
)->comdat_type_p
27587 || a
->dw_attr
== DW_AT_specification
)
27588 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
27591 case dw_val_class_str
:
27592 /* Set the string's refcount to 0 so that prune_unused_types_mark
27593 accounts properly for it. */
27594 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
27603 /* Mark the generic parameters and arguments children DIEs of DIE. */
27606 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
27610 if (die
== NULL
|| die
->die_child
== NULL
)
27612 c
= die
->die_child
;
27615 if (is_template_parameter (c
))
27616 prune_unused_types_mark (c
, 1);
27618 } while (c
&& c
!= die
->die_child
);
27621 /* Mark DIE as being used. If DOKIDS is true, then walk down
27622 to DIE's children. */
27625 prune_unused_types_mark (dw_die_ref die
, int dokids
)
27629 if (die
->die_mark
== 0)
27631 /* We haven't done this node yet. Mark it as used. */
27633 /* If this is the DIE of a generic type instantiation,
27634 mark the children DIEs that describe its generic parms and
27636 prune_unused_types_mark_generic_parms_dies (die
);
27638 /* We also have to mark its parents as used.
27639 (But we don't want to mark our parent's kids due to this,
27640 unless it is a class.) */
27641 if (die
->die_parent
)
27642 prune_unused_types_mark (die
->die_parent
,
27643 class_scope_p (die
->die_parent
));
27645 /* Mark any referenced nodes. */
27646 prune_unused_types_walk_attribs (die
);
27648 /* If this node is a specification,
27649 also mark the definition, if it exists. */
27650 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
27651 prune_unused_types_mark (die
->die_definition
, 1);
27654 if (dokids
&& die
->die_mark
!= 2)
27656 /* We need to walk the children, but haven't done so yet.
27657 Remember that we've walked the kids. */
27660 /* If this is an array type, we need to make sure our
27661 kids get marked, even if they're types. If we're
27662 breaking out types into comdat sections, do this
27663 for all type definitions. */
27664 if (die
->die_tag
== DW_TAG_array_type
27665 || (use_debug_types
27666 && is_type_die (die
) && ! is_declaration_die (die
)))
27667 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
27669 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
27673 /* For local classes, look if any static member functions were emitted
27674 and if so, mark them. */
27677 prune_unused_types_walk_local_classes (dw_die_ref die
)
27681 if (die
->die_mark
== 2)
27684 switch (die
->die_tag
)
27686 case DW_TAG_structure_type
:
27687 case DW_TAG_union_type
:
27688 case DW_TAG_class_type
:
27691 case DW_TAG_subprogram
:
27692 if (!get_AT_flag (die
, DW_AT_declaration
)
27693 || die
->die_definition
!= NULL
)
27694 prune_unused_types_mark (die
, 1);
27701 /* Mark children. */
27702 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
27705 /* Walk the tree DIE and mark types that we actually use. */
27708 prune_unused_types_walk (dw_die_ref die
)
27712 /* Don't do anything if this node is already marked and
27713 children have been marked as well. */
27714 if (die
->die_mark
== 2)
27717 switch (die
->die_tag
)
27719 case DW_TAG_structure_type
:
27720 case DW_TAG_union_type
:
27721 case DW_TAG_class_type
:
27722 if (die
->die_perennial_p
)
27725 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
27726 if (c
->die_tag
== DW_TAG_subprogram
)
27729 /* Finding used static member functions inside of classes
27730 is needed just for local classes, because for other classes
27731 static member function DIEs with DW_AT_specification
27732 are emitted outside of the DW_TAG_*_type. If we ever change
27733 it, we'd need to call this even for non-local classes. */
27735 prune_unused_types_walk_local_classes (die
);
27737 /* It's a type node --- don't mark it. */
27740 case DW_TAG_const_type
:
27741 case DW_TAG_packed_type
:
27742 case DW_TAG_pointer_type
:
27743 case DW_TAG_reference_type
:
27744 case DW_TAG_rvalue_reference_type
:
27745 case DW_TAG_volatile_type
:
27746 case DW_TAG_typedef
:
27747 case DW_TAG_array_type
:
27748 case DW_TAG_interface_type
:
27749 case DW_TAG_friend
:
27750 case DW_TAG_enumeration_type
:
27751 case DW_TAG_subroutine_type
:
27752 case DW_TAG_string_type
:
27753 case DW_TAG_set_type
:
27754 case DW_TAG_subrange_type
:
27755 case DW_TAG_ptr_to_member_type
:
27756 case DW_TAG_file_type
:
27757 /* Type nodes are useful only when other DIEs reference them --- don't
27761 case DW_TAG_dwarf_procedure
:
27762 /* Likewise for DWARF procedures. */
27764 if (die
->die_perennial_p
)
27770 /* Mark everything else. */
27774 if (die
->die_mark
== 0)
27778 /* Now, mark any dies referenced from here. */
27779 prune_unused_types_walk_attribs (die
);
27784 /* Mark children. */
27785 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
27788 /* Increment the string counts on strings referred to from DIE's
27792 prune_unused_types_update_strings (dw_die_ref die
)
27797 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
27798 if (AT_class (a
) == dw_val_class_str
)
27800 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
27802 /* Avoid unnecessarily putting strings that are used less than
27803 twice in the hash table. */
27805 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
27807 indirect_string_node
**slot
27808 = debug_str_hash
->find_slot_with_hash (s
->str
,
27809 htab_hash_string (s
->str
),
27811 gcc_assert (*slot
== NULL
);
27817 /* Mark DIE and its children as removed. */
27820 mark_removed (dw_die_ref die
)
27823 die
->removed
= true;
27824 FOR_EACH_CHILD (die
, c
, mark_removed (c
));
27827 /* Remove from the tree DIE any dies that aren't marked. */
27830 prune_unused_types_prune (dw_die_ref die
)
27834 gcc_assert (die
->die_mark
);
27835 prune_unused_types_update_strings (die
);
27837 if (! die
->die_child
)
27840 c
= die
->die_child
;
27842 dw_die_ref prev
= c
, next
;
27843 for (c
= c
->die_sib
; ! c
->die_mark
; c
= next
)
27844 if (c
== die
->die_child
)
27846 /* No marked children between 'prev' and the end of the list. */
27848 /* No marked children at all. */
27849 die
->die_child
= NULL
;
27852 prev
->die_sib
= c
->die_sib
;
27853 die
->die_child
= prev
;
27866 if (c
!= prev
->die_sib
)
27868 prune_unused_types_prune (c
);
27869 } while (c
!= die
->die_child
);
27872 /* Remove dies representing declarations that we never use. */
27875 prune_unused_types (void)
27878 limbo_die_node
*node
;
27879 comdat_type_node
*ctnode
;
27880 pubname_entry
*pub
;
27881 dw_die_ref base_type
;
27883 #if ENABLE_ASSERT_CHECKING
27884 /* All the marks should already be clear. */
27885 verify_marks_clear (comp_unit_die ());
27886 for (node
= limbo_die_list
; node
; node
= node
->next
)
27887 verify_marks_clear (node
->die
);
27888 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
27889 verify_marks_clear (ctnode
->root_die
);
27890 #endif /* ENABLE_ASSERT_CHECKING */
27892 /* Mark types that are used in global variables. */
27893 premark_types_used_by_global_vars ();
27895 /* Set the mark on nodes that are actually used. */
27896 prune_unused_types_walk (comp_unit_die ());
27897 for (node
= limbo_die_list
; node
; node
= node
->next
)
27898 prune_unused_types_walk (node
->die
);
27899 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
27901 prune_unused_types_walk (ctnode
->root_die
);
27902 prune_unused_types_mark (ctnode
->type_die
, 1);
27905 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
27906 are unusual in that they are pubnames that are the children of pubtypes.
27907 They should only be marked via their parent DW_TAG_enumeration_type die,
27908 not as roots in themselves. */
27909 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
27910 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
27911 prune_unused_types_mark (pub
->die
, 1);
27912 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
27913 prune_unused_types_mark (base_type
, 1);
27915 /* For -fvar-tracking-assignments, also set the mark on nodes that could be
27916 referenced by DW_TAG_call_site DW_AT_call_origin (i.e. direct call
27918 cgraph_node
*cnode
;
27919 FOR_EACH_FUNCTION (cnode
)
27920 if (cnode
->referred_to_p (false))
27922 dw_die_ref die
= lookup_decl_die (cnode
->decl
);
27923 if (die
== NULL
|| die
->die_mark
)
27925 for (cgraph_edge
*e
= cnode
->callers
; e
; e
= e
->next_caller
)
27926 if (e
->caller
!= cnode
27927 && opt_for_fn (e
->caller
->decl
, flag_var_tracking_assignments
))
27929 prune_unused_types_mark (die
, 1);
27934 if (debug_str_hash
)
27935 debug_str_hash
->empty ();
27936 if (skeleton_debug_str_hash
)
27937 skeleton_debug_str_hash
->empty ();
27938 prune_unused_types_prune (comp_unit_die ());
27939 for (limbo_die_node
**pnode
= &limbo_die_list
; *pnode
; )
27942 if (!node
->die
->die_mark
)
27943 *pnode
= node
->next
;
27946 prune_unused_types_prune (node
->die
);
27947 pnode
= &node
->next
;
27950 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
27951 prune_unused_types_prune (ctnode
->root_die
);
27953 /* Leave the marks clear. */
27954 prune_unmark_dies (comp_unit_die ());
27955 for (node
= limbo_die_list
; node
; node
= node
->next
)
27956 prune_unmark_dies (node
->die
);
27957 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
27958 prune_unmark_dies (ctnode
->root_die
);
27961 /* Helpers to manipulate hash table of comdat type units. */
27963 struct comdat_type_hasher
: nofree_ptr_hash
<comdat_type_node
>
27965 static inline hashval_t
hash (const comdat_type_node
*);
27966 static inline bool equal (const comdat_type_node
*, const comdat_type_node
*);
27970 comdat_type_hasher::hash (const comdat_type_node
*type_node
)
27973 memcpy (&h
, type_node
->signature
, sizeof (h
));
27978 comdat_type_hasher::equal (const comdat_type_node
*type_node_1
,
27979 const comdat_type_node
*type_node_2
)
27981 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
27982 DWARF_TYPE_SIGNATURE_SIZE
));
27985 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
27986 to the location it would have been added, should we know its
27987 DECL_ASSEMBLER_NAME when we added other attributes. This will
27988 probably improve compactness of debug info, removing equivalent
27989 abbrevs, and hide any differences caused by deferring the
27990 computation of the assembler name, triggered by e.g. PCH. */
27993 move_linkage_attr (dw_die_ref die
)
27995 unsigned ix
= vec_safe_length (die
->die_attr
);
27996 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
27998 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
27999 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
28003 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
28005 if (prev
->dw_attr
== DW_AT_decl_line
28006 || prev
->dw_attr
== DW_AT_decl_column
28007 || prev
->dw_attr
== DW_AT_name
)
28011 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
28013 die
->die_attr
->pop ();
28014 die
->die_attr
->quick_insert (ix
, linkage
);
28018 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
28019 referenced from typed stack ops and count how often they are used. */
28022 mark_base_types (dw_loc_descr_ref loc
)
28024 dw_die_ref base_type
= NULL
;
28026 for (; loc
; loc
= loc
->dw_loc_next
)
28028 switch (loc
->dw_loc_opc
)
28030 case DW_OP_regval_type
:
28031 case DW_OP_deref_type
:
28032 case DW_OP_GNU_regval_type
:
28033 case DW_OP_GNU_deref_type
:
28034 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
28036 case DW_OP_convert
:
28037 case DW_OP_reinterpret
:
28038 case DW_OP_GNU_convert
:
28039 case DW_OP_GNU_reinterpret
:
28040 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
28043 case DW_OP_const_type
:
28044 case DW_OP_GNU_const_type
:
28045 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28047 case DW_OP_entry_value
:
28048 case DW_OP_GNU_entry_value
:
28049 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
28054 gcc_assert (base_type
->die_parent
== comp_unit_die ());
28055 if (base_type
->die_mark
)
28056 base_type
->die_mark
++;
28059 base_types
.safe_push (base_type
);
28060 base_type
->die_mark
= 1;
28065 /* Comparison function for sorting marked base types. */
28068 base_type_cmp (const void *x
, const void *y
)
28070 dw_die_ref dx
= *(const dw_die_ref
*) x
;
28071 dw_die_ref dy
= *(const dw_die_ref
*) y
;
28072 unsigned int byte_size1
, byte_size2
;
28073 unsigned int encoding1
, encoding2
;
28074 unsigned int align1
, align2
;
28075 if (dx
->die_mark
> dy
->die_mark
)
28077 if (dx
->die_mark
< dy
->die_mark
)
28079 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
28080 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
28081 if (byte_size1
< byte_size2
)
28083 if (byte_size1
> byte_size2
)
28085 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
28086 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
28087 if (encoding1
< encoding2
)
28089 if (encoding1
> encoding2
)
28091 align1
= get_AT_unsigned (dx
, DW_AT_alignment
);
28092 align2
= get_AT_unsigned (dy
, DW_AT_alignment
);
28093 if (align1
< align2
)
28095 if (align1
> align2
)
28100 /* Move base types marked by mark_base_types as early as possible
28101 in the CU, sorted by decreasing usage count both to make the
28102 uleb128 references as small as possible and to make sure they
28103 will have die_offset already computed by calc_die_sizes when
28104 sizes of typed stack loc ops is computed. */
28107 move_marked_base_types (void)
28110 dw_die_ref base_type
, die
, c
;
28112 if (base_types
.is_empty ())
28115 /* Sort by decreasing usage count, they will be added again in that
28117 base_types
.qsort (base_type_cmp
);
28118 die
= comp_unit_die ();
28119 c
= die
->die_child
;
28122 dw_die_ref prev
= c
;
28124 while (c
->die_mark
)
28126 remove_child_with_prev (c
, prev
);
28127 /* As base types got marked, there must be at least
28128 one node other than DW_TAG_base_type. */
28129 gcc_assert (die
->die_child
!= NULL
);
28133 while (c
!= die
->die_child
);
28134 gcc_assert (die
->die_child
);
28135 c
= die
->die_child
;
28136 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
28138 base_type
->die_mark
= 0;
28139 base_type
->die_sib
= c
->die_sib
;
28140 c
->die_sib
= base_type
;
28145 /* Helper function for resolve_addr, attempt to resolve
28146 one CONST_STRING, return true if successful. Similarly verify that
28147 SYMBOL_REFs refer to variables emitted in the current CU. */
28150 resolve_one_addr (rtx
*addr
)
28154 if (GET_CODE (rtl
) == CONST_STRING
)
28156 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
28157 tree t
= build_string (len
, XSTR (rtl
, 0));
28158 tree tlen
= size_int (len
- 1);
28160 = build_array_type (char_type_node
, build_index_type (tlen
));
28161 rtl
= lookup_constant_def (t
);
28162 if (!rtl
|| !MEM_P (rtl
))
28164 rtl
= XEXP (rtl
, 0);
28165 if (GET_CODE (rtl
) == SYMBOL_REF
28166 && SYMBOL_REF_DECL (rtl
)
28167 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
28169 vec_safe_push (used_rtx_array
, rtl
);
28174 if (GET_CODE (rtl
) == SYMBOL_REF
28175 && SYMBOL_REF_DECL (rtl
))
28177 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
28179 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
28182 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
28186 if (GET_CODE (rtl
) == CONST
)
28188 subrtx_ptr_iterator::array_type array
;
28189 FOR_EACH_SUBRTX_PTR (iter
, array
, &XEXP (rtl
, 0), ALL
)
28190 if (!resolve_one_addr (*iter
))
28197 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
28198 if possible, and create DW_TAG_dwarf_procedure that can be referenced
28199 from DW_OP_implicit_pointer if the string hasn't been seen yet. */
28202 string_cst_pool_decl (tree t
)
28204 rtx rtl
= output_constant_def (t
, 1);
28205 unsigned char *array
;
28206 dw_loc_descr_ref l
;
28211 if (!rtl
|| !MEM_P (rtl
))
28213 rtl
= XEXP (rtl
, 0);
28214 if (GET_CODE (rtl
) != SYMBOL_REF
28215 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
28218 decl
= SYMBOL_REF_DECL (rtl
);
28219 if (!lookup_decl_die (decl
))
28221 len
= TREE_STRING_LENGTH (t
);
28222 vec_safe_push (used_rtx_array
, rtl
);
28223 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
28224 array
= ggc_vec_alloc
<unsigned char> (len
);
28225 memcpy (array
, TREE_STRING_POINTER (t
), len
);
28226 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
28227 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
28228 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
28229 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
28230 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
28231 add_AT_loc (ref
, DW_AT_location
, l
);
28232 equate_decl_number_to_die (decl
, ref
);
28237 /* Helper function of resolve_addr_in_expr. LOC is
28238 a DW_OP_addr followed by DW_OP_stack_value, either at the start
28239 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
28240 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
28241 with DW_OP_implicit_pointer if possible
28242 and return true, if unsuccessful, return false. */
28245 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
28247 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
28248 HOST_WIDE_INT offset
= 0;
28249 dw_die_ref ref
= NULL
;
28252 if (GET_CODE (rtl
) == CONST
28253 && GET_CODE (XEXP (rtl
, 0)) == PLUS
28254 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
28256 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
28257 rtl
= XEXP (XEXP (rtl
, 0), 0);
28259 if (GET_CODE (rtl
) == CONST_STRING
)
28261 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
28262 tree t
= build_string (len
, XSTR (rtl
, 0));
28263 tree tlen
= size_int (len
- 1);
28266 = build_array_type (char_type_node
, build_index_type (tlen
));
28267 rtl
= string_cst_pool_decl (t
);
28271 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
28273 decl
= SYMBOL_REF_DECL (rtl
);
28274 if (VAR_P (decl
) && !DECL_EXTERNAL (decl
))
28276 ref
= lookup_decl_die (decl
);
28277 if (ref
&& (get_AT (ref
, DW_AT_location
)
28278 || get_AT (ref
, DW_AT_const_value
)))
28280 loc
->dw_loc_opc
= dwarf_OP (DW_OP_implicit_pointer
);
28281 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28282 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
28283 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
28284 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28285 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
28286 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
28294 /* Helper function for resolve_addr, handle one location
28295 expression, return false if at least one CONST_STRING or SYMBOL_REF in
28296 the location list couldn't be resolved. */
28299 resolve_addr_in_expr (dw_attr_node
*a
, dw_loc_descr_ref loc
)
28301 dw_loc_descr_ref keep
= NULL
;
28302 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
28303 switch (loc
->dw_loc_opc
)
28306 if (!resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
28309 || prev
->dw_loc_opc
== DW_OP_piece
28310 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
28311 && loc
->dw_loc_next
28312 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
28313 && (!dwarf_strict
|| dwarf_version
>= 5)
28314 && optimize_one_addr_into_implicit_ptr (loc
))
28319 case DW_OP_GNU_addr_index
:
28320 case DW_OP_GNU_const_index
:
28321 if (loc
->dw_loc_opc
== DW_OP_GNU_addr_index
28322 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
28324 rtx rtl
= loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
;
28325 if (!resolve_one_addr (&rtl
))
28327 remove_addr_table_entry (loc
->dw_loc_oprnd1
.val_entry
);
28328 loc
->dw_loc_oprnd1
.val_entry
28329 = add_addr_table_entry (rtl
, ate_kind_rtx
);
28332 case DW_OP_const4u
:
28333 case DW_OP_const8u
:
28335 && !resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
28338 case DW_OP_plus_uconst
:
28339 if (size_of_loc_descr (loc
)
28340 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
28342 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
28344 dw_loc_descr_ref repl
28345 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
28346 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
28347 add_loc_descr (&repl
, loc
->dw_loc_next
);
28351 case DW_OP_implicit_value
:
28352 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
28353 && !resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
))
28356 case DW_OP_implicit_pointer
:
28357 case DW_OP_GNU_implicit_pointer
:
28358 case DW_OP_GNU_parameter_ref
:
28359 case DW_OP_GNU_variable_value
:
28360 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
28363 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
28366 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28367 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
28368 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28370 if (loc
->dw_loc_opc
== DW_OP_GNU_variable_value
)
28373 && loc
->dw_loc_next
== NULL
28374 && AT_class (a
) == dw_val_class_loc
)
28375 switch (a
->dw_attr
)
28377 /* Following attributes allow both exprloc and reference,
28378 so if the whole expression is DW_OP_GNU_variable_value
28379 alone we could transform it into reference. */
28380 case DW_AT_byte_size
:
28381 case DW_AT_bit_size
:
28382 case DW_AT_lower_bound
:
28383 case DW_AT_upper_bound
:
28384 case DW_AT_bit_stride
:
28386 case DW_AT_allocated
:
28387 case DW_AT_associated
:
28388 case DW_AT_byte_stride
:
28389 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
28390 a
->dw_attr_val
.val_entry
= NULL
;
28391 a
->dw_attr_val
.v
.val_die_ref
.die
28392 = loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28393 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
28402 case DW_OP_const_type
:
28403 case DW_OP_regval_type
:
28404 case DW_OP_deref_type
:
28405 case DW_OP_convert
:
28406 case DW_OP_reinterpret
:
28407 case DW_OP_GNU_const_type
:
28408 case DW_OP_GNU_regval_type
:
28409 case DW_OP_GNU_deref_type
:
28410 case DW_OP_GNU_convert
:
28411 case DW_OP_GNU_reinterpret
:
28412 while (loc
->dw_loc_next
28413 && (loc
->dw_loc_next
->dw_loc_opc
== DW_OP_convert
28414 || loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
))
28416 dw_die_ref base1
, base2
;
28417 unsigned enc1
, enc2
, size1
, size2
;
28418 if (loc
->dw_loc_opc
== DW_OP_regval_type
28419 || loc
->dw_loc_opc
== DW_OP_deref_type
28420 || loc
->dw_loc_opc
== DW_OP_GNU_regval_type
28421 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
28422 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
28423 else if (loc
->dw_loc_oprnd1
.val_class
28424 == dw_val_class_unsigned_const
)
28427 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28428 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
28429 == dw_val_class_unsigned_const
)
28431 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28432 gcc_assert (base1
->die_tag
== DW_TAG_base_type
28433 && base2
->die_tag
== DW_TAG_base_type
);
28434 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
28435 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
28436 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
28437 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
28439 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
28440 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
28444 /* Optimize away next DW_OP_convert after
28445 adjusting LOC's base type die reference. */
28446 if (loc
->dw_loc_opc
== DW_OP_regval_type
28447 || loc
->dw_loc_opc
== DW_OP_deref_type
28448 || loc
->dw_loc_opc
== DW_OP_GNU_regval_type
28449 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
28450 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
28452 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
28453 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
28456 /* Don't change integer DW_OP_convert after e.g. floating
28457 point typed stack entry. */
28458 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
28459 keep
= loc
->dw_loc_next
;
28469 /* Helper function of resolve_addr. DIE had DW_AT_location of
28470 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
28471 and DW_OP_addr couldn't be resolved. resolve_addr has already
28472 removed the DW_AT_location attribute. This function attempts to
28473 add a new DW_AT_location attribute with DW_OP_implicit_pointer
28474 to it or DW_AT_const_value attribute, if possible. */
28477 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
28480 || lookup_decl_die (decl
) != die
28481 || DECL_EXTERNAL (decl
)
28482 || !TREE_STATIC (decl
)
28483 || DECL_INITIAL (decl
) == NULL_TREE
28484 || DECL_P (DECL_INITIAL (decl
))
28485 || get_AT (die
, DW_AT_const_value
))
28488 tree init
= DECL_INITIAL (decl
);
28489 HOST_WIDE_INT offset
= 0;
28490 /* For variables that have been optimized away and thus
28491 don't have a memory location, see if we can emit
28492 DW_AT_const_value instead. */
28493 if (tree_add_const_value_attribute (die
, init
))
28495 if (dwarf_strict
&& dwarf_version
< 5)
28497 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
28498 and ADDR_EXPR refers to a decl that has DW_AT_location or
28499 DW_AT_const_value (but isn't addressable, otherwise
28500 resolving the original DW_OP_addr wouldn't fail), see if
28501 we can add DW_OP_implicit_pointer. */
28503 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
28504 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
28506 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
28507 init
= TREE_OPERAND (init
, 0);
28510 if (TREE_CODE (init
) != ADDR_EXPR
)
28512 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
28513 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
28514 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
28515 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
28516 && TREE_OPERAND (init
, 0) != decl
))
28519 dw_loc_descr_ref l
;
28521 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
28523 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
28526 decl
= SYMBOL_REF_DECL (rtl
);
28529 decl
= TREE_OPERAND (init
, 0);
28530 ref
= lookup_decl_die (decl
);
28532 || (!get_AT (ref
, DW_AT_location
)
28533 && !get_AT (ref
, DW_AT_const_value
)))
28535 l
= new_loc_descr (dwarf_OP (DW_OP_implicit_pointer
), 0, offset
);
28536 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28537 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
28538 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28539 add_AT_loc (die
, DW_AT_location
, l
);
28543 /* Return NULL if l is a DWARF expression, or first op that is not
28544 valid DWARF expression. */
28546 static dw_loc_descr_ref
28547 non_dwarf_expression (dw_loc_descr_ref l
)
28551 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
28553 switch (l
->dw_loc_opc
)
28556 case DW_OP_implicit_value
:
28557 case DW_OP_stack_value
:
28558 case DW_OP_implicit_pointer
:
28559 case DW_OP_GNU_implicit_pointer
:
28560 case DW_OP_GNU_parameter_ref
:
28562 case DW_OP_bit_piece
:
28567 l
= l
->dw_loc_next
;
28572 /* Return adjusted copy of EXPR:
28573 If it is empty DWARF expression, return it.
28574 If it is valid non-empty DWARF expression,
28575 return copy of EXPR with DW_OP_deref appended to it.
28576 If it is DWARF expression followed by DW_OP_reg{N,x}, return
28577 copy of the DWARF expression with DW_OP_breg{N,x} <0> appended.
28578 If it is DWARF expression followed by DW_OP_stack_value, return
28579 copy of the DWARF expression without anything appended.
28580 Otherwise, return NULL. */
28582 static dw_loc_descr_ref
28583 copy_deref_exprloc (dw_loc_descr_ref expr
)
28585 dw_loc_descr_ref tail
= NULL
;
28590 dw_loc_descr_ref l
= non_dwarf_expression (expr
);
28591 if (l
&& l
->dw_loc_next
)
28596 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
28597 tail
= new_loc_descr ((enum dwarf_location_atom
)
28598 (DW_OP_breg0
+ (l
->dw_loc_opc
- DW_OP_reg0
)),
28601 switch (l
->dw_loc_opc
)
28604 tail
= new_loc_descr (DW_OP_bregx
,
28605 l
->dw_loc_oprnd1
.v
.val_unsigned
, 0);
28607 case DW_OP_stack_value
:
28614 tail
= new_loc_descr (DW_OP_deref
, 0, 0);
28616 dw_loc_descr_ref ret
= NULL
, *p
= &ret
;
28619 *p
= new_loc_descr (expr
->dw_loc_opc
, 0, 0);
28620 (*p
)->dw_loc_oprnd1
= expr
->dw_loc_oprnd1
;
28621 (*p
)->dw_loc_oprnd2
= expr
->dw_loc_oprnd2
;
28622 p
= &(*p
)->dw_loc_next
;
28623 expr
= expr
->dw_loc_next
;
28629 /* For DW_AT_string_length attribute with DW_OP_GNU_variable_value
28630 reference to a variable or argument, adjust it if needed and return:
28631 -1 if the DW_AT_string_length attribute and DW_AT_{string_length_,}byte_size
28632 attribute if present should be removed
28633 0 keep the attribute perhaps with minor modifications, no need to rescan
28634 1 if the attribute has been successfully adjusted. */
28637 optimize_string_length (dw_attr_node
*a
)
28639 dw_loc_descr_ref l
= AT_loc (a
), lv
;
28641 if (l
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
28643 tree decl
= l
->dw_loc_oprnd1
.v
.val_decl_ref
;
28644 die
= lookup_decl_die (decl
);
28647 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28648 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= die
;
28649 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28655 die
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28657 /* DWARF5 allows reference class, so we can then reference the DIE.
28658 Only do this for DW_OP_GNU_variable_value DW_OP_stack_value. */
28659 if (l
->dw_loc_next
!= NULL
&& dwarf_version
>= 5)
28661 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
28662 a
->dw_attr_val
.val_entry
= NULL
;
28663 a
->dw_attr_val
.v
.val_die_ref
.die
= die
;
28664 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
28668 dw_attr_node
*av
= get_AT (die
, DW_AT_location
);
28670 bool non_dwarf_expr
= false;
28673 return dwarf_strict
? -1 : 0;
28674 switch (AT_class (av
))
28676 case dw_val_class_loc_list
:
28677 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
28678 if (d
->expr
&& non_dwarf_expression (d
->expr
))
28679 non_dwarf_expr
= true;
28681 case dw_val_class_loc
:
28684 return dwarf_strict
? -1 : 0;
28685 if (non_dwarf_expression (lv
))
28686 non_dwarf_expr
= true;
28689 return dwarf_strict
? -1 : 0;
28692 /* If it is safe to transform DW_OP_GNU_variable_value DW_OP_stack_value
28693 into DW_OP_call4 or DW_OP_GNU_variable_value into
28694 DW_OP_call4 DW_OP_deref, do so. */
28695 if (!non_dwarf_expr
28696 && (l
->dw_loc_next
!= NULL
|| AT_class (av
) == dw_val_class_loc
))
28698 l
->dw_loc_opc
= DW_OP_call4
;
28699 if (l
->dw_loc_next
)
28700 l
->dw_loc_next
= NULL
;
28702 l
->dw_loc_next
= new_loc_descr (DW_OP_deref
, 0, 0);
28706 /* For DW_OP_GNU_variable_value DW_OP_stack_value, we can just
28707 copy over the DW_AT_location attribute from die to a. */
28708 if (l
->dw_loc_next
!= NULL
)
28710 a
->dw_attr_val
= av
->dw_attr_val
;
28714 dw_loc_list_ref list
, *p
;
28715 switch (AT_class (av
))
28717 case dw_val_class_loc_list
:
28720 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
28722 lv
= copy_deref_exprloc (d
->expr
);
28725 *p
= new_loc_list (lv
, d
->begin
, d
->end
, d
->section
);
28726 p
= &(*p
)->dw_loc_next
;
28728 else if (!dwarf_strict
&& d
->expr
)
28732 return dwarf_strict
? -1 : 0;
28733 a
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
28735 *AT_loc_list_ptr (a
) = list
;
28737 case dw_val_class_loc
:
28738 lv
= copy_deref_exprloc (AT_loc (av
));
28740 return dwarf_strict
? -1 : 0;
28741 a
->dw_attr_val
.v
.val_loc
= lv
;
28744 gcc_unreachable ();
28748 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
28749 an address in .rodata section if the string literal is emitted there,
28750 or remove the containing location list or replace DW_AT_const_value
28751 with DW_AT_location and empty location expression, if it isn't found
28752 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
28753 to something that has been emitted in the current CU. */
28756 resolve_addr (dw_die_ref die
)
28760 dw_loc_list_ref
*curr
, *start
, loc
;
28762 bool remove_AT_byte_size
= false;
28764 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
28765 switch (AT_class (a
))
28767 case dw_val_class_loc_list
:
28768 start
= curr
= AT_loc_list_ptr (a
);
28771 /* The same list can be referenced more than once. See if we have
28772 already recorded the result from a previous pass. */
28774 *curr
= loc
->dw_loc_next
;
28775 else if (!loc
->resolved_addr
)
28777 /* As things stand, we do not expect or allow one die to
28778 reference a suffix of another die's location list chain.
28779 References must be identical or completely separate.
28780 There is therefore no need to cache the result of this
28781 pass on any list other than the first; doing so
28782 would lead to unnecessary writes. */
28785 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
28786 if (!resolve_addr_in_expr (a
, (*curr
)->expr
))
28788 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
28789 dw_loc_descr_ref l
= (*curr
)->expr
;
28791 if (next
&& (*curr
)->ll_symbol
)
28793 gcc_assert (!next
->ll_symbol
);
28794 next
->ll_symbol
= (*curr
)->ll_symbol
;
28796 if (dwarf_split_debug_info
)
28797 remove_loc_list_addr_table_entries (l
);
28802 mark_base_types ((*curr
)->expr
);
28803 curr
= &(*curr
)->dw_loc_next
;
28807 loc
->resolved_addr
= 1;
28811 loc
->dw_loc_next
= *start
;
28816 remove_AT (die
, a
->dw_attr
);
28820 case dw_val_class_loc
:
28822 dw_loc_descr_ref l
= AT_loc (a
);
28823 /* DW_OP_GNU_variable_value DW_OP_stack_value or
28824 DW_OP_GNU_variable_value in DW_AT_string_length can be converted
28825 into DW_OP_call4 or DW_OP_call4 DW_OP_deref, which is standard
28826 DWARF4 unlike DW_OP_GNU_variable_value. Or for DWARF5
28827 DW_OP_GNU_variable_value DW_OP_stack_value can be replaced
28828 with DW_FORM_ref referencing the same DIE as
28829 DW_OP_GNU_variable_value used to reference. */
28830 if (a
->dw_attr
== DW_AT_string_length
28832 && l
->dw_loc_opc
== DW_OP_GNU_variable_value
28833 && (l
->dw_loc_next
== NULL
28834 || (l
->dw_loc_next
->dw_loc_next
== NULL
28835 && l
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
)))
28837 switch (optimize_string_length (a
))
28840 remove_AT (die
, a
->dw_attr
);
28842 /* If we drop DW_AT_string_length, we need to drop also
28843 DW_AT_{string_length_,}byte_size. */
28844 remove_AT_byte_size
= true;
28849 /* Even if we keep the optimized DW_AT_string_length,
28850 it might have changed AT_class, so process it again. */
28855 /* For -gdwarf-2 don't attempt to optimize
28856 DW_AT_data_member_location containing
28857 DW_OP_plus_uconst - older consumers might
28858 rely on it being that op instead of a more complex,
28859 but shorter, location description. */
28860 if ((dwarf_version
> 2
28861 || a
->dw_attr
!= DW_AT_data_member_location
28863 || l
->dw_loc_opc
!= DW_OP_plus_uconst
28864 || l
->dw_loc_next
!= NULL
)
28865 && !resolve_addr_in_expr (a
, l
))
28867 if (dwarf_split_debug_info
)
28868 remove_loc_list_addr_table_entries (l
);
28870 && l
->dw_loc_next
== NULL
28871 && l
->dw_loc_opc
== DW_OP_addr
28872 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
28873 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
28874 && a
->dw_attr
== DW_AT_location
)
28876 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
28877 remove_AT (die
, a
->dw_attr
);
28879 optimize_location_into_implicit_ptr (die
, decl
);
28882 if (a
->dw_attr
== DW_AT_string_length
)
28883 /* If we drop DW_AT_string_length, we need to drop also
28884 DW_AT_{string_length_,}byte_size. */
28885 remove_AT_byte_size
= true;
28886 remove_AT (die
, a
->dw_attr
);
28890 mark_base_types (l
);
28893 case dw_val_class_addr
:
28894 if (a
->dw_attr
== DW_AT_const_value
28895 && !resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
))
28897 if (AT_index (a
) != NOT_INDEXED
)
28898 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
28899 remove_AT (die
, a
->dw_attr
);
28902 if ((die
->die_tag
== DW_TAG_call_site
28903 && a
->dw_attr
== DW_AT_call_origin
)
28904 || (die
->die_tag
== DW_TAG_GNU_call_site
28905 && a
->dw_attr
== DW_AT_abstract_origin
))
28907 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
28908 dw_die_ref tdie
= lookup_decl_die (tdecl
);
28911 && DECL_EXTERNAL (tdecl
)
28912 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
28913 && (cdie
= lookup_context_die (DECL_CONTEXT (tdecl
))))
28915 dw_die_ref pdie
= cdie
;
28916 /* Make sure we don't add these DIEs into type units.
28917 We could emit skeleton DIEs for context (namespaces,
28918 outer structs/classes) and a skeleton DIE for the
28919 innermost context with DW_AT_signature pointing to the
28920 type unit. See PR78835. */
28921 while (pdie
&& pdie
->die_tag
!= DW_TAG_type_unit
)
28922 pdie
= pdie
->die_parent
;
28925 /* Creating a full DIE for tdecl is overly expensive and
28926 at this point even wrong when in the LTO phase
28927 as it can end up generating new type DIEs we didn't
28928 output and thus optimize_external_refs will crash. */
28929 tdie
= new_die (DW_TAG_subprogram
, cdie
, NULL_TREE
);
28930 add_AT_flag (tdie
, DW_AT_external
, 1);
28931 add_AT_flag (tdie
, DW_AT_declaration
, 1);
28932 add_linkage_attr (tdie
, tdecl
);
28933 add_name_and_src_coords_attributes (tdie
, tdecl
);
28934 equate_decl_number_to_die (tdecl
, tdie
);
28939 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
28940 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
28941 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
28945 if (AT_index (a
) != NOT_INDEXED
)
28946 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
28947 remove_AT (die
, a
->dw_attr
);
28956 if (remove_AT_byte_size
)
28957 remove_AT (die
, dwarf_version
>= 5
28958 ? DW_AT_string_length_byte_size
28959 : DW_AT_byte_size
);
28961 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
28964 /* Helper routines for optimize_location_lists.
28965 This pass tries to share identical local lists in .debug_loc
28968 /* Iteratively hash operands of LOC opcode into HSTATE. */
28971 hash_loc_operands (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
28973 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
28974 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
28976 switch (loc
->dw_loc_opc
)
28978 case DW_OP_const4u
:
28979 case DW_OP_const8u
:
28983 case DW_OP_const1u
:
28984 case DW_OP_const1s
:
28985 case DW_OP_const2u
:
28986 case DW_OP_const2s
:
28987 case DW_OP_const4s
:
28988 case DW_OP_const8s
:
28992 case DW_OP_plus_uconst
:
29028 case DW_OP_deref_size
:
29029 case DW_OP_xderef_size
:
29030 hstate
.add_object (val1
->v
.val_int
);
29037 gcc_assert (val1
->val_class
== dw_val_class_loc
);
29038 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
29039 hstate
.add_object (offset
);
29042 case DW_OP_implicit_value
:
29043 hstate
.add_object (val1
->v
.val_unsigned
);
29044 switch (val2
->val_class
)
29046 case dw_val_class_const
:
29047 hstate
.add_object (val2
->v
.val_int
);
29049 case dw_val_class_vec
:
29051 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
29052 unsigned int len
= val2
->v
.val_vec
.length
;
29054 hstate
.add_int (elt_size
);
29055 hstate
.add_int (len
);
29056 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
29059 case dw_val_class_const_double
:
29060 hstate
.add_object (val2
->v
.val_double
.low
);
29061 hstate
.add_object (val2
->v
.val_double
.high
);
29063 case dw_val_class_wide_int
:
29064 hstate
.add (val2
->v
.val_wide
->get_val (),
29065 get_full_len (*val2
->v
.val_wide
)
29066 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
29068 case dw_val_class_addr
:
29069 inchash::add_rtx (val2
->v
.val_addr
, hstate
);
29072 gcc_unreachable ();
29076 case DW_OP_bit_piece
:
29077 hstate
.add_object (val1
->v
.val_int
);
29078 hstate
.add_object (val2
->v
.val_int
);
29084 unsigned char dtprel
= 0xd1;
29085 hstate
.add_object (dtprel
);
29087 inchash::add_rtx (val1
->v
.val_addr
, hstate
);
29089 case DW_OP_GNU_addr_index
:
29090 case DW_OP_GNU_const_index
:
29094 unsigned char dtprel
= 0xd1;
29095 hstate
.add_object (dtprel
);
29097 inchash::add_rtx (val1
->val_entry
->addr
.rtl
, hstate
);
29100 case DW_OP_implicit_pointer
:
29101 case DW_OP_GNU_implicit_pointer
:
29102 hstate
.add_int (val2
->v
.val_int
);
29104 case DW_OP_entry_value
:
29105 case DW_OP_GNU_entry_value
:
29106 hstate
.add_object (val1
->v
.val_loc
);
29108 case DW_OP_regval_type
:
29109 case DW_OP_deref_type
:
29110 case DW_OP_GNU_regval_type
:
29111 case DW_OP_GNU_deref_type
:
29113 unsigned int byte_size
29114 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
29115 unsigned int encoding
29116 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
29117 hstate
.add_object (val1
->v
.val_int
);
29118 hstate
.add_object (byte_size
);
29119 hstate
.add_object (encoding
);
29122 case DW_OP_convert
:
29123 case DW_OP_reinterpret
:
29124 case DW_OP_GNU_convert
:
29125 case DW_OP_GNU_reinterpret
:
29126 if (val1
->val_class
== dw_val_class_unsigned_const
)
29128 hstate
.add_object (val1
->v
.val_unsigned
);
29132 case DW_OP_const_type
:
29133 case DW_OP_GNU_const_type
:
29135 unsigned int byte_size
29136 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
29137 unsigned int encoding
29138 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
29139 hstate
.add_object (byte_size
);
29140 hstate
.add_object (encoding
);
29141 if (loc
->dw_loc_opc
!= DW_OP_const_type
29142 && loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
29144 hstate
.add_object (val2
->val_class
);
29145 switch (val2
->val_class
)
29147 case dw_val_class_const
:
29148 hstate
.add_object (val2
->v
.val_int
);
29150 case dw_val_class_vec
:
29152 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
29153 unsigned int len
= val2
->v
.val_vec
.length
;
29155 hstate
.add_object (elt_size
);
29156 hstate
.add_object (len
);
29157 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
29160 case dw_val_class_const_double
:
29161 hstate
.add_object (val2
->v
.val_double
.low
);
29162 hstate
.add_object (val2
->v
.val_double
.high
);
29164 case dw_val_class_wide_int
:
29165 hstate
.add (val2
->v
.val_wide
->get_val (),
29166 get_full_len (*val2
->v
.val_wide
)
29167 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
29170 gcc_unreachable ();
29176 /* Other codes have no operands. */
29181 /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
29184 hash_locs (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
29186 dw_loc_descr_ref l
;
29187 bool sizes_computed
= false;
29188 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
29189 size_of_locs (loc
);
29191 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
29193 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
29194 hstate
.add_object (opc
);
29195 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
29197 size_of_locs (loc
);
29198 sizes_computed
= true;
29200 hash_loc_operands (l
, hstate
);
29204 /* Compute hash of the whole location list LIST_HEAD. */
29207 hash_loc_list (dw_loc_list_ref list_head
)
29209 dw_loc_list_ref curr
= list_head
;
29210 inchash::hash hstate
;
29212 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
29214 hstate
.add (curr
->begin
, strlen (curr
->begin
) + 1);
29215 hstate
.add (curr
->end
, strlen (curr
->end
) + 1);
29217 hstate
.add (curr
->section
, strlen (curr
->section
) + 1);
29218 hash_locs (curr
->expr
, hstate
);
29220 list_head
->hash
= hstate
.end ();
29223 /* Return true if X and Y opcodes have the same operands. */
29226 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
29228 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
29229 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
29230 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
29231 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
29233 switch (x
->dw_loc_opc
)
29235 case DW_OP_const4u
:
29236 case DW_OP_const8u
:
29240 case DW_OP_const1u
:
29241 case DW_OP_const1s
:
29242 case DW_OP_const2u
:
29243 case DW_OP_const2s
:
29244 case DW_OP_const4s
:
29245 case DW_OP_const8s
:
29249 case DW_OP_plus_uconst
:
29285 case DW_OP_deref_size
:
29286 case DW_OP_xderef_size
:
29287 return valx1
->v
.val_int
== valy1
->v
.val_int
;
29290 /* If splitting debug info, the use of DW_OP_GNU_addr_index
29291 can cause irrelevant differences in dw_loc_addr. */
29292 gcc_assert (valx1
->val_class
== dw_val_class_loc
29293 && valy1
->val_class
== dw_val_class_loc
29294 && (dwarf_split_debug_info
29295 || x
->dw_loc_addr
== y
->dw_loc_addr
));
29296 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
29297 case DW_OP_implicit_value
:
29298 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
29299 || valx2
->val_class
!= valy2
->val_class
)
29301 switch (valx2
->val_class
)
29303 case dw_val_class_const
:
29304 return valx2
->v
.val_int
== valy2
->v
.val_int
;
29305 case dw_val_class_vec
:
29306 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
29307 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
29308 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
29309 valx2
->v
.val_vec
.elt_size
29310 * valx2
->v
.val_vec
.length
) == 0;
29311 case dw_val_class_const_double
:
29312 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
29313 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
29314 case dw_val_class_wide_int
:
29315 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
29316 case dw_val_class_addr
:
29317 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
29319 gcc_unreachable ();
29322 case DW_OP_bit_piece
:
29323 return valx1
->v
.val_int
== valy1
->v
.val_int
29324 && valx2
->v
.val_int
== valy2
->v
.val_int
;
29327 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
29328 case DW_OP_GNU_addr_index
:
29329 case DW_OP_GNU_const_index
:
29331 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
29332 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
29333 return rtx_equal_p (ax1
, ay1
);
29335 case DW_OP_implicit_pointer
:
29336 case DW_OP_GNU_implicit_pointer
:
29337 return valx1
->val_class
== dw_val_class_die_ref
29338 && valx1
->val_class
== valy1
->val_class
29339 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
29340 && valx2
->v
.val_int
== valy2
->v
.val_int
;
29341 case DW_OP_entry_value
:
29342 case DW_OP_GNU_entry_value
:
29343 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
29344 case DW_OP_const_type
:
29345 case DW_OP_GNU_const_type
:
29346 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
29347 || valx2
->val_class
!= valy2
->val_class
)
29349 switch (valx2
->val_class
)
29351 case dw_val_class_const
:
29352 return valx2
->v
.val_int
== valy2
->v
.val_int
;
29353 case dw_val_class_vec
:
29354 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
29355 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
29356 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
29357 valx2
->v
.val_vec
.elt_size
29358 * valx2
->v
.val_vec
.length
) == 0;
29359 case dw_val_class_const_double
:
29360 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
29361 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
29362 case dw_val_class_wide_int
:
29363 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
29365 gcc_unreachable ();
29367 case DW_OP_regval_type
:
29368 case DW_OP_deref_type
:
29369 case DW_OP_GNU_regval_type
:
29370 case DW_OP_GNU_deref_type
:
29371 return valx1
->v
.val_int
== valy1
->v
.val_int
29372 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
29373 case DW_OP_convert
:
29374 case DW_OP_reinterpret
:
29375 case DW_OP_GNU_convert
:
29376 case DW_OP_GNU_reinterpret
:
29377 if (valx1
->val_class
!= valy1
->val_class
)
29379 if (valx1
->val_class
== dw_val_class_unsigned_const
)
29380 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
29381 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
29382 case DW_OP_GNU_parameter_ref
:
29383 return valx1
->val_class
== dw_val_class_die_ref
29384 && valx1
->val_class
== valy1
->val_class
29385 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
29387 /* Other codes have no operands. */
29392 /* Return true if DWARF location expressions X and Y are the same. */
29395 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
29397 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
29398 if (x
->dw_loc_opc
!= y
->dw_loc_opc
29399 || x
->dtprel
!= y
->dtprel
29400 || !compare_loc_operands (x
, y
))
29402 return x
== NULL
&& y
== NULL
;
29405 /* Hashtable helpers. */
29407 struct loc_list_hasher
: nofree_ptr_hash
<dw_loc_list_struct
>
29409 static inline hashval_t
hash (const dw_loc_list_struct
*);
29410 static inline bool equal (const dw_loc_list_struct
*,
29411 const dw_loc_list_struct
*);
29414 /* Return precomputed hash of location list X. */
29417 loc_list_hasher::hash (const dw_loc_list_struct
*x
)
29422 /* Return true if location lists A and B are the same. */
29425 loc_list_hasher::equal (const dw_loc_list_struct
*a
,
29426 const dw_loc_list_struct
*b
)
29430 if (a
->hash
!= b
->hash
)
29432 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
29433 if (strcmp (a
->begin
, b
->begin
) != 0
29434 || strcmp (a
->end
, b
->end
) != 0
29435 || (a
->section
== NULL
) != (b
->section
== NULL
)
29436 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
29437 || !compare_locs (a
->expr
, b
->expr
))
29439 return a
== NULL
&& b
== NULL
;
29442 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
29445 /* Recursively optimize location lists referenced from DIE
29446 children and share them whenever possible. */
29449 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type
*htab
)
29454 dw_loc_list_struct
**slot
;
29456 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
29457 if (AT_class (a
) == dw_val_class_loc_list
)
29459 dw_loc_list_ref list
= AT_loc_list (a
);
29460 /* TODO: perform some optimizations here, before hashing
29461 it and storing into the hash table. */
29462 hash_loc_list (list
);
29463 slot
= htab
->find_slot_with_hash (list
, list
->hash
, INSERT
);
29467 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
29470 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
29474 /* Recursively assign each location list a unique index into the debug_addr
29478 index_location_lists (dw_die_ref die
)
29484 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
29485 if (AT_class (a
) == dw_val_class_loc_list
)
29487 dw_loc_list_ref list
= AT_loc_list (a
);
29488 dw_loc_list_ref curr
;
29489 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
29491 /* Don't index an entry that has already been indexed
29492 or won't be output. */
29493 if (curr
->begin_entry
!= NULL
29494 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
29498 = add_addr_table_entry (xstrdup (curr
->begin
), ate_kind_label
);
29502 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
29505 /* Optimize location lists referenced from DIE
29506 children and share them whenever possible. */
29509 optimize_location_lists (dw_die_ref die
)
29511 loc_list_hash_type
htab (500);
29512 optimize_location_lists_1 (die
, &htab
);
29515 /* Traverse the limbo die list, and add parent/child links. The only
29516 dies without parents that should be here are concrete instances of
29517 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
29518 For concrete instances, we can get the parent die from the abstract
29522 flush_limbo_die_list (void)
29524 limbo_die_node
*node
;
29526 /* get_context_die calls force_decl_die, which can put new DIEs on the
29527 limbo list in LTO mode when nested functions are put in a different
29528 partition than that of their parent function. */
29529 while ((node
= limbo_die_list
))
29531 dw_die_ref die
= node
->die
;
29532 limbo_die_list
= node
->next
;
29534 if (die
->die_parent
== NULL
)
29536 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
29538 if (origin
&& origin
->die_parent
)
29539 add_child_die (origin
->die_parent
, die
);
29540 else if (is_cu_die (die
))
29542 else if (seen_error ())
29543 /* It's OK to be confused by errors in the input. */
29544 add_child_die (comp_unit_die (), die
);
29547 /* In certain situations, the lexical block containing a
29548 nested function can be optimized away, which results
29549 in the nested function die being orphaned. Likewise
29550 with the return type of that nested function. Force
29551 this to be a child of the containing function.
29553 It may happen that even the containing function got fully
29554 inlined and optimized out. In that case we are lost and
29555 assign the empty child. This should not be big issue as
29556 the function is likely unreachable too. */
29557 gcc_assert (node
->created_for
);
29559 if (DECL_P (node
->created_for
))
29560 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
29561 else if (TYPE_P (node
->created_for
))
29562 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
29564 origin
= comp_unit_die ();
29566 add_child_die (origin
, die
);
29572 /* Output stuff that dwarf requires at the end of every file,
29573 and generate the DWARF-2 debugging info. */
29576 dwarf2out_finish (const char *)
29578 comdat_type_node
*ctnode
;
29579 dw_die_ref main_comp_unit_die
;
29580 unsigned char checksum
[16];
29581 char dl_section_ref
[MAX_ARTIFICIAL_LABEL_BYTES
];
29583 /* Flush out any latecomers to the limbo party. */
29584 flush_limbo_die_list ();
29588 verify_die (comp_unit_die ());
29589 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
29590 verify_die (node
->die
);
29593 /* We shouldn't have any symbols with delayed asm names for
29594 DIEs generated after early finish. */
29595 gcc_assert (deferred_asm_name
== NULL
);
29597 gen_remaining_tmpl_value_param_die_attribute ();
29599 #if ENABLE_ASSERT_CHECKING
29601 dw_die_ref die
= comp_unit_die (), c
;
29602 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
29605 resolve_addr (comp_unit_die ());
29606 move_marked_base_types ();
29608 /* Initialize sections and labels used for actual assembler output. */
29609 init_sections_and_labels ();
29611 /* Traverse the DIE's and add sibling attributes to those DIE's that
29613 add_sibling_attributes (comp_unit_die ());
29614 limbo_die_node
*node
;
29615 for (node
= cu_die_list
; node
; node
= node
->next
)
29616 add_sibling_attributes (node
->die
);
29617 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
29618 add_sibling_attributes (ctnode
->root_die
);
29620 /* When splitting DWARF info, we put some attributes in the
29621 skeleton compile_unit DIE that remains in the .o, while
29622 most attributes go in the DWO compile_unit_die. */
29623 if (dwarf_split_debug_info
)
29625 limbo_die_node
*cu
;
29626 main_comp_unit_die
= gen_compile_unit_die (NULL
);
29627 if (dwarf_version
>= 5)
29628 main_comp_unit_die
->die_tag
= DW_TAG_skeleton_unit
;
29629 cu
= limbo_die_list
;
29630 gcc_assert (cu
->die
== main_comp_unit_die
);
29631 limbo_die_list
= limbo_die_list
->next
;
29632 cu
->next
= cu_die_list
;
29636 main_comp_unit_die
= comp_unit_die ();
29638 /* Output a terminator label for the .text section. */
29639 switch_to_section (text_section
);
29640 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
29641 if (cold_text_section
)
29643 switch_to_section (cold_text_section
);
29644 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
29647 /* We can only use the low/high_pc attributes if all of the code was
29649 if (!have_multiple_function_sections
29650 || (dwarf_version
< 3 && dwarf_strict
))
29652 /* Don't add if the CU has no associated code. */
29653 if (text_section_used
)
29654 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
29655 text_end_label
, true);
29661 bool range_list_added
= false;
29663 if (text_section_used
)
29664 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
29665 text_end_label
, &range_list_added
, true);
29666 if (cold_text_section_used
)
29667 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
29668 cold_end_label
, &range_list_added
, true);
29670 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
29672 if (DECL_IGNORED_P (fde
->decl
))
29674 if (!fde
->in_std_section
)
29675 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
29676 fde
->dw_fde_end
, &range_list_added
,
29678 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
29679 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
29680 fde
->dw_fde_second_end
, &range_list_added
,
29684 if (range_list_added
)
29686 /* We need to give .debug_loc and .debug_ranges an appropriate
29687 "base address". Use zero so that these addresses become
29688 absolute. Historically, we've emitted the unexpected
29689 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
29690 Emit both to give time for other tools to adapt. */
29691 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
29692 if (! dwarf_strict
&& dwarf_version
< 4)
29693 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
29699 /* AIX Assembler inserts the length, so adjust the reference to match the
29700 offset expected by debuggers. */
29701 strcpy (dl_section_ref
, debug_line_section_label
);
29702 if (XCOFF_DEBUGGING_INFO
)
29703 strcat (dl_section_ref
, DWARF_INITIAL_LENGTH_SIZE_STR
);
29705 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
29706 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
29710 add_AT_macptr (comp_unit_die (),
29711 dwarf_version
>= 5 ? DW_AT_macros
29712 : dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
29713 macinfo_section_label
);
29715 if (dwarf_split_debug_info
)
29717 if (have_location_lists
)
29719 if (dwarf_version
>= 5)
29720 add_AT_loclistsptr (comp_unit_die (), DW_AT_loclists_base
,
29721 loc_section_label
);
29722 /* optimize_location_lists calculates the size of the lists,
29723 so index them first, and assign indices to the entries.
29724 Although optimize_location_lists will remove entries from
29725 the table, it only does so for duplicates, and therefore
29726 only reduces ref_counts to 1. */
29727 index_location_lists (comp_unit_die ());
29730 if (addr_index_table
!= NULL
)
29732 unsigned int index
= 0;
29734 ->traverse_noresize
<unsigned int *, index_addr_table_entry
>
29740 if (have_location_lists
)
29742 optimize_location_lists (comp_unit_die ());
29743 /* And finally assign indexes to the entries for -gsplit-dwarf. */
29744 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
29745 assign_location_list_indexes (comp_unit_die ());
29748 save_macinfo_strings ();
29750 if (dwarf_split_debug_info
)
29752 unsigned int index
= 0;
29754 /* Add attributes common to skeleton compile_units and
29755 type_units. Because these attributes include strings, it
29756 must be done before freezing the string table. Top-level
29757 skeleton die attrs are added when the skeleton type unit is
29758 created, so ensure it is created by this point. */
29759 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
29760 debug_str_hash
->traverse_noresize
<unsigned int *, index_string
> (&index
);
29763 /* Output all of the compilation units. We put the main one last so that
29764 the offsets are available to output_pubnames. */
29765 for (node
= cu_die_list
; node
; node
= node
->next
)
29766 output_comp_unit (node
->die
, 0, NULL
);
29768 hash_table
<comdat_type_hasher
> comdat_type_table (100);
29769 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
29771 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
29773 /* Don't output duplicate types. */
29774 if (*slot
!= HTAB_EMPTY_ENTRY
)
29777 /* Add a pointer to the line table for the main compilation unit
29778 so that the debugger can make sense of DW_AT_decl_file
29780 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
29781 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
29782 (!dwarf_split_debug_info
29784 : debug_skeleton_line_section_label
));
29786 output_comdat_type_unit (ctnode
);
29790 /* The AT_pubnames attribute needs to go in all skeleton dies, including
29791 both the main_cu and all skeleton TUs. Making this call unconditional
29792 would end up either adding a second copy of the AT_pubnames attribute, or
29793 requiring a special case in add_top_level_skeleton_die_attrs. */
29794 if (!dwarf_split_debug_info
)
29795 add_AT_pubnames (comp_unit_die ());
29797 if (dwarf_split_debug_info
)
29800 struct md5_ctx ctx
;
29802 if (dwarf_version
>= 5 && !vec_safe_is_empty (ranges_table
))
29805 /* Compute a checksum of the comp_unit to use as the dwo_id. */
29806 md5_init_ctx (&ctx
);
29808 die_checksum (comp_unit_die (), &ctx
, &mark
);
29809 unmark_all_dies (comp_unit_die ());
29810 md5_finish_ctx (&ctx
, checksum
);
29812 if (dwarf_version
< 5)
29814 /* Use the first 8 bytes of the checksum as the dwo_id,
29815 and add it to both comp-unit DIEs. */
29816 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
29817 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
29820 /* Add the base offset of the ranges table to the skeleton
29822 if (!vec_safe_is_empty (ranges_table
))
29824 if (dwarf_version
>= 5)
29825 add_AT_lineptr (main_comp_unit_die
, DW_AT_rnglists_base
,
29826 ranges_base_label
);
29828 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
29829 ranges_section_label
);
29832 switch_to_section (debug_addr_section
);
29833 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
29834 output_addr_table ();
29837 /* Output the main compilation unit if non-empty or if .debug_macinfo
29838 or .debug_macro will be emitted. */
29839 output_comp_unit (comp_unit_die (), have_macinfo
,
29840 dwarf_split_debug_info
? checksum
: NULL
);
29842 if (dwarf_split_debug_info
&& info_section_emitted
)
29843 output_skeleton_debug_sections (main_comp_unit_die
, checksum
);
29845 /* Output the abbreviation table. */
29846 if (vec_safe_length (abbrev_die_table
) != 1)
29848 switch_to_section (debug_abbrev_section
);
29849 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
29850 output_abbrev_section ();
29853 /* Output location list section if necessary. */
29854 if (have_location_lists
)
29856 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
29857 char l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
29858 /* Output the location lists info. */
29859 switch_to_section (debug_loc_section
);
29860 if (dwarf_version
>= 5)
29862 ASM_GENERATE_INTERNAL_LABEL (l1
, DEBUG_LOC_SECTION_LABEL
, 1);
29863 ASM_GENERATE_INTERNAL_LABEL (l2
, DEBUG_LOC_SECTION_LABEL
, 2);
29864 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
29865 dw2_asm_output_data (4, 0xffffffff,
29866 "Initial length escape value indicating "
29867 "64-bit DWARF extension");
29868 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
29869 "Length of Location Lists");
29870 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
29871 dw2_asm_output_data (2, dwarf_version
, "DWARF Version");
29872 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
29873 dw2_asm_output_data (1, 0, "Segment Size");
29874 dw2_asm_output_data (4, dwarf_split_debug_info
? loc_list_idx
: 0,
29875 "Offset Entry Count");
29877 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
29878 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
29880 unsigned int save_loc_list_idx
= loc_list_idx
;
29882 output_loclists_offsets (comp_unit_die ());
29883 gcc_assert (save_loc_list_idx
== loc_list_idx
);
29885 output_location_lists (comp_unit_die ());
29886 if (dwarf_version
>= 5)
29887 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
29890 output_pubtables ();
29892 /* Output the address range information if a CU (.debug_info section)
29893 was emitted. We output an empty table even if we had no functions
29894 to put in it. This because the consumer has no way to tell the
29895 difference between an empty table that we omitted and failure to
29896 generate a table that would have contained data. */
29897 if (info_section_emitted
)
29899 switch_to_section (debug_aranges_section
);
29903 /* Output ranges section if necessary. */
29904 if (!vec_safe_is_empty (ranges_table
))
29906 if (dwarf_version
>= 5)
29907 output_rnglists ();
29912 /* Have to end the macro section. */
29915 switch_to_section (debug_macinfo_section
);
29916 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
29918 dw2_asm_output_data (1, 0, "End compilation unit");
29921 /* Output the source line correspondence table. We must do this
29922 even if there is no line information. Otherwise, on an empty
29923 translation unit, we will generate a present, but empty,
29924 .debug_info section. IRIX 6.5 `nm' will then complain when
29925 examining the file. This is done late so that any filenames
29926 used by the debug_info section are marked as 'used'. */
29927 switch_to_section (debug_line_section
);
29928 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
29929 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
29930 output_line_info (false);
29932 if (dwarf_split_debug_info
&& info_section_emitted
)
29934 switch_to_section (debug_skeleton_line_section
);
29935 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
29936 output_line_info (true);
29939 /* If we emitted any indirect strings, output the string table too. */
29940 if (debug_str_hash
|| skeleton_debug_str_hash
)
29941 output_indirect_strings ();
29942 if (debug_line_str_hash
)
29944 switch_to_section (debug_line_str_section
);
29945 const enum dwarf_form form
= DW_FORM_line_strp
;
29946 debug_line_str_hash
->traverse
<enum dwarf_form
,
29947 output_indirect_string
> (form
);
29951 /* Returns a hash value for X (which really is a variable_value_struct). */
29954 variable_value_hasher::hash (variable_value_struct
*x
)
29956 return (hashval_t
) x
->decl_id
;
29959 /* Return nonzero if decl_id of variable_value_struct X is the same as
29963 variable_value_hasher::equal (variable_value_struct
*x
, tree y
)
29965 return x
->decl_id
== DECL_UID (y
);
29968 /* Helper function for resolve_variable_value, handle
29969 DW_OP_GNU_variable_value in one location expression.
29970 Return true if exprloc has been changed into loclist. */
29973 resolve_variable_value_in_expr (dw_attr_node
*a
, dw_loc_descr_ref loc
)
29975 dw_loc_descr_ref next
;
29976 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= next
)
29978 next
= loc
->dw_loc_next
;
29979 if (loc
->dw_loc_opc
!= DW_OP_GNU_variable_value
29980 || loc
->dw_loc_oprnd1
.val_class
!= dw_val_class_decl_ref
)
29983 tree decl
= loc
->dw_loc_oprnd1
.v
.val_decl_ref
;
29984 if (DECL_CONTEXT (decl
) != current_function_decl
)
29987 dw_die_ref ref
= lookup_decl_die (decl
);
29990 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
29991 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
29992 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
29995 dw_loc_list_ref l
= loc_list_from_tree (decl
, 0, NULL
);
29998 if (l
->dw_loc_next
)
30000 if (AT_class (a
) != dw_val_class_loc
)
30002 switch (a
->dw_attr
)
30004 /* Following attributes allow both exprloc and loclist
30005 classes, so we can change them into a loclist. */
30006 case DW_AT_location
:
30007 case DW_AT_string_length
:
30008 case DW_AT_return_addr
:
30009 case DW_AT_data_member_location
:
30010 case DW_AT_frame_base
:
30011 case DW_AT_segment
:
30012 case DW_AT_static_link
:
30013 case DW_AT_use_location
:
30014 case DW_AT_vtable_elem_location
:
30017 prev
->dw_loc_next
= NULL
;
30018 prepend_loc_descr_to_each (l
, AT_loc (a
));
30021 add_loc_descr_to_each (l
, next
);
30022 a
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
30023 a
->dw_attr_val
.val_entry
= NULL
;
30024 a
->dw_attr_val
.v
.val_loc_list
= l
;
30025 have_location_lists
= true;
30027 /* Following attributes allow both exprloc and reference,
30028 so if the whole expression is DW_OP_GNU_variable_value alone
30029 we could transform it into reference. */
30030 case DW_AT_byte_size
:
30031 case DW_AT_bit_size
:
30032 case DW_AT_lower_bound
:
30033 case DW_AT_upper_bound
:
30034 case DW_AT_bit_stride
:
30036 case DW_AT_allocated
:
30037 case DW_AT_associated
:
30038 case DW_AT_byte_stride
:
30039 if (prev
== NULL
&& next
== NULL
)
30047 /* Create DW_TAG_variable that we can refer to. */
30048 gen_decl_die (decl
, NULL_TREE
, NULL
,
30049 lookup_decl_die (current_function_decl
));
30050 ref
= lookup_decl_die (decl
);
30053 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
30054 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
30055 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
30061 prev
->dw_loc_next
= l
->expr
;
30062 add_loc_descr (&prev
->dw_loc_next
, next
);
30063 free_loc_descr (loc
, NULL
);
30064 next
= prev
->dw_loc_next
;
30068 memcpy (loc
, l
->expr
, sizeof (dw_loc_descr_node
));
30069 add_loc_descr (&loc
, next
);
30077 /* Attempt to resolve DW_OP_GNU_variable_value using loc_list_from_tree. */
30080 resolve_variable_value (dw_die_ref die
)
30083 dw_loc_list_ref loc
;
30086 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
30087 switch (AT_class (a
))
30089 case dw_val_class_loc
:
30090 if (!resolve_variable_value_in_expr (a
, AT_loc (a
)))
30093 case dw_val_class_loc_list
:
30094 loc
= AT_loc_list (a
);
30096 for (; loc
; loc
= loc
->dw_loc_next
)
30097 resolve_variable_value_in_expr (a
, loc
->expr
);
30104 /* Attempt to optimize DW_OP_GNU_variable_value refering to
30105 temporaries in the current function. */
30108 resolve_variable_values (void)
30110 if (!variable_value_hash
|| !current_function_decl
)
30113 struct variable_value_struct
*node
30114 = variable_value_hash
->find_with_hash (current_function_decl
,
30115 DECL_UID (current_function_decl
));
30122 FOR_EACH_VEC_SAFE_ELT (node
->dies
, i
, die
)
30123 resolve_variable_value (die
);
30126 /* Helper function for note_variable_value, handle one location
30130 note_variable_value_in_expr (dw_die_ref die
, dw_loc_descr_ref loc
)
30132 for (; loc
; loc
= loc
->dw_loc_next
)
30133 if (loc
->dw_loc_opc
== DW_OP_GNU_variable_value
30134 && loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
30136 tree decl
= loc
->dw_loc_oprnd1
.v
.val_decl_ref
;
30137 dw_die_ref ref
= lookup_decl_die (decl
);
30140 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
30141 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
30142 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
30146 && DECL_CONTEXT (decl
)
30147 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
30148 && lookup_decl_die (DECL_CONTEXT (decl
)))
30150 if (!variable_value_hash
)
30151 variable_value_hash
30152 = hash_table
<variable_value_hasher
>::create_ggc (10);
30154 tree fndecl
= DECL_CONTEXT (decl
);
30155 struct variable_value_struct
*node
;
30156 struct variable_value_struct
**slot
30157 = variable_value_hash
->find_slot_with_hash (fndecl
,
30162 node
= ggc_cleared_alloc
<variable_value_struct
> ();
30163 node
->decl_id
= DECL_UID (fndecl
);
30169 vec_safe_push (node
->dies
, die
);
30174 /* Walk the tree DIE and note DIEs with DW_OP_GNU_variable_value still
30175 with dw_val_class_decl_ref operand. */
30178 note_variable_value (dw_die_ref die
)
30182 dw_loc_list_ref loc
;
30185 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
30186 switch (AT_class (a
))
30188 case dw_val_class_loc_list
:
30189 loc
= AT_loc_list (a
);
30191 if (!loc
->noted_variable_value
)
30193 loc
->noted_variable_value
= 1;
30194 for (; loc
; loc
= loc
->dw_loc_next
)
30195 note_variable_value_in_expr (die
, loc
->expr
);
30198 case dw_val_class_loc
:
30199 note_variable_value_in_expr (die
, AT_loc (a
));
30205 /* Mark children. */
30206 FOR_EACH_CHILD (die
, c
, note_variable_value (c
));
30209 /* Perform any cleanups needed after the early debug generation pass
30213 dwarf2out_early_finish (const char *filename
)
30217 /* PCH might result in DW_AT_producer string being restored from the
30218 header compilation, so always fill it with empty string initially
30219 and overwrite only here. */
30220 dw_attr_node
*producer
= get_AT (comp_unit_die (), DW_AT_producer
);
30221 producer_string
= gen_producer_string ();
30222 producer
->dw_attr_val
.v
.val_str
->refcount
--;
30223 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
30225 /* Add the name for the main input file now. We delayed this from
30226 dwarf2out_init to avoid complications with PCH. */
30227 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
30228 add_comp_dir_attribute (comp_unit_die ());
30230 /* When emitting DWARF5 .debug_line_str, move DW_AT_name and
30231 DW_AT_comp_dir into .debug_line_str section. */
30232 if (!DWARF2_ASM_LINE_DEBUG_INFO
30233 && dwarf_version
>= 5
30234 && DWARF5_USE_DEBUG_LINE_STR
)
30236 for (int i
= 0; i
< 2; i
++)
30238 dw_attr_node
*a
= get_AT (comp_unit_die (),
30239 i
? DW_AT_comp_dir
: DW_AT_name
);
30241 || AT_class (a
) != dw_val_class_str
30242 || strlen (AT_string (a
)) + 1 <= DWARF_OFFSET_SIZE
)
30245 if (! debug_line_str_hash
)
30246 debug_line_str_hash
30247 = hash_table
<indirect_string_hasher
>::create_ggc (10);
30249 struct indirect_string_node
*node
30250 = find_AT_string_in_table (AT_string (a
), debug_line_str_hash
);
30251 set_indirect_string (node
);
30252 node
->form
= DW_FORM_line_strp
;
30253 a
->dw_attr_val
.v
.val_str
->refcount
--;
30254 a
->dw_attr_val
.v
.val_str
= node
;
30258 /* With LTO early dwarf was really finished at compile-time, so make
30259 sure to adjust the phase after annotating the LTRANS CU DIE. */
30262 early_dwarf_finished
= true;
30266 /* Walk through the list of incomplete types again, trying once more to
30267 emit full debugging info for them. */
30268 retry_incomplete_types ();
30270 /* The point here is to flush out the limbo list so that it is empty
30271 and we don't need to stream it for LTO. */
30272 flush_limbo_die_list ();
30274 gen_scheduled_generic_parms_dies ();
30275 gen_remaining_tmpl_value_param_die_attribute ();
30277 /* Add DW_AT_linkage_name for all deferred DIEs. */
30278 for (limbo_die_node
*node
= deferred_asm_name
; node
; node
= node
->next
)
30280 tree decl
= node
->created_for
;
30281 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
30282 /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
30283 ended up in deferred_asm_name before we knew it was
30284 constant and never written to disk. */
30285 && DECL_ASSEMBLER_NAME (decl
))
30287 add_linkage_attr (node
->die
, decl
);
30288 move_linkage_attr (node
->die
);
30291 deferred_asm_name
= NULL
;
30293 if (flag_eliminate_unused_debug_types
)
30294 prune_unused_types ();
30296 /* Generate separate COMDAT sections for type DIEs. */
30297 if (use_debug_types
)
30299 break_out_comdat_types (comp_unit_die ());
30301 /* Each new type_unit DIE was added to the limbo die list when created.
30302 Since these have all been added to comdat_type_list, clear the
30304 limbo_die_list
= NULL
;
30306 /* For each new comdat type unit, copy declarations for incomplete
30307 types to make the new unit self-contained (i.e., no direct
30308 references to the main compile unit). */
30309 for (comdat_type_node
*ctnode
= comdat_type_list
;
30310 ctnode
!= NULL
; ctnode
= ctnode
->next
)
30311 copy_decls_for_unworthy_types (ctnode
->root_die
);
30312 copy_decls_for_unworthy_types (comp_unit_die ());
30314 /* In the process of copying declarations from one unit to another,
30315 we may have left some declarations behind that are no longer
30316 referenced. Prune them. */
30317 prune_unused_types ();
30320 /* Generate separate CUs for each of the include files we've seen.
30321 They will go into limbo_die_list and from there to cu_die_list. */
30322 if (flag_eliminate_dwarf2_dups
)
30324 gcc_assert (limbo_die_list
== NULL
);
30325 break_out_includes (comp_unit_die ());
30326 limbo_die_node
*cu
;
30327 while ((cu
= limbo_die_list
))
30329 limbo_die_list
= cu
->next
;
30330 cu
->next
= cu_die_list
;
30335 /* Traverse the DIE's and note DIEs with DW_OP_GNU_variable_value still
30336 with dw_val_class_decl_ref operand. */
30337 note_variable_value (comp_unit_die ());
30338 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
30339 note_variable_value (node
->die
);
30340 for (comdat_type_node
*ctnode
= comdat_type_list
; ctnode
!= NULL
;
30341 ctnode
= ctnode
->next
)
30342 note_variable_value (ctnode
->root_die
);
30343 for (limbo_die_node
*node
= limbo_die_list
; node
; node
= node
->next
)
30344 note_variable_value (node
->die
);
30346 /* The early debug phase is now finished. */
30347 early_dwarf_finished
= true;
30350 /* Reset all state within dwarf2out.c so that we can rerun the compiler
30351 within the same process. For use by toplev::finalize. */
30354 dwarf2out_c_finalize (void)
30356 last_var_location_insn
= NULL
;
30357 cached_next_real_insn
= NULL
;
30358 used_rtx_array
= NULL
;
30359 incomplete_types
= NULL
;
30360 decl_scope_table
= NULL
;
30361 debug_info_section
= NULL
;
30362 debug_skeleton_info_section
= NULL
;
30363 debug_abbrev_section
= NULL
;
30364 debug_skeleton_abbrev_section
= NULL
;
30365 debug_aranges_section
= NULL
;
30366 debug_addr_section
= NULL
;
30367 debug_macinfo_section
= NULL
;
30368 debug_line_section
= NULL
;
30369 debug_skeleton_line_section
= NULL
;
30370 debug_loc_section
= NULL
;
30371 debug_pubnames_section
= NULL
;
30372 debug_pubtypes_section
= NULL
;
30373 debug_str_section
= NULL
;
30374 debug_line_str_section
= NULL
;
30375 debug_str_dwo_section
= NULL
;
30376 debug_str_offsets_section
= NULL
;
30377 debug_ranges_section
= NULL
;
30378 debug_frame_section
= NULL
;
30380 debug_str_hash
= NULL
;
30381 debug_line_str_hash
= NULL
;
30382 skeleton_debug_str_hash
= NULL
;
30383 dw2_string_counter
= 0;
30384 have_multiple_function_sections
= false;
30385 text_section_used
= false;
30386 cold_text_section_used
= false;
30387 cold_text_section
= NULL
;
30388 current_unit_personality
= NULL
;
30390 early_dwarf
= false;
30391 early_dwarf_finished
= false;
30393 next_die_offset
= 0;
30394 single_comp_unit_die
= NULL
;
30395 comdat_type_list
= NULL
;
30396 limbo_die_list
= NULL
;
30398 decl_die_table
= NULL
;
30399 common_block_die_table
= NULL
;
30400 decl_loc_table
= NULL
;
30401 call_arg_locations
= NULL
;
30402 call_arg_loc_last
= NULL
;
30403 call_site_count
= -1;
30404 tail_call_site_count
= -1;
30405 cached_dw_loc_list_table
= NULL
;
30406 abbrev_die_table
= NULL
;
30407 delete dwarf_proc_stack_usage_map
;
30408 dwarf_proc_stack_usage_map
= NULL
;
30409 line_info_label_num
= 0;
30410 cur_line_info_table
= NULL
;
30411 text_section_line_info
= NULL
;
30412 cold_text_section_line_info
= NULL
;
30413 separate_line_info
= NULL
;
30414 info_section_emitted
= false;
30415 pubname_table
= NULL
;
30416 pubtype_table
= NULL
;
30417 macinfo_table
= NULL
;
30418 ranges_table
= NULL
;
30419 ranges_by_label
= NULL
;
30421 have_location_lists
= false;
30424 last_emitted_file
= NULL
;
30426 tmpl_value_parm_die_table
= NULL
;
30427 generic_type_instances
= NULL
;
30428 frame_pointer_fb_offset
= 0;
30429 frame_pointer_fb_offset_valid
= false;
30430 base_types
.release ();
30431 XDELETEVEC (producer_string
);
30432 producer_string
= NULL
;
30435 #include "gt-dwarf2out.h"