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"
96 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
97 static rtx_insn
*last_var_location_insn
;
98 static rtx_insn
*cached_next_real_insn
;
99 static void dwarf2out_decl (tree
);
101 #ifndef XCOFF_DEBUGGING_INFO
102 #define XCOFF_DEBUGGING_INFO 0
105 #ifndef HAVE_XCOFF_DWARF_EXTRAS
106 #define HAVE_XCOFF_DWARF_EXTRAS 0
109 #ifdef VMS_DEBUGGING_INFO
110 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
112 /* Define this macro to be a nonzero value if the directory specifications
113 which are output in the debug info should end with a separator. */
114 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
115 /* Define this macro to evaluate to a nonzero value if GCC should refrain
116 from generating indirect strings in DWARF2 debug information, for instance
117 if your target is stuck with an old version of GDB that is unable to
118 process them properly or uses VMS Debug. */
119 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
121 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
122 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
125 /* ??? Poison these here until it can be done generically. They've been
126 totally replaced in this file; make sure it stays that way. */
127 #undef DWARF2_UNWIND_INFO
128 #undef DWARF2_FRAME_INFO
129 #if (GCC_VERSION >= 3000)
130 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
133 /* The size of the target's pointer type. */
135 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
138 /* Array of RTXes referenced by the debugging information, which therefore
139 must be kept around forever. */
140 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
142 /* A pointer to the base of a list of incomplete types which might be
143 completed at some later time. incomplete_types_list needs to be a
144 vec<tree, va_gc> *because we want to tell the garbage collector about
146 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
148 /* A pointer to the base of a table of references to declaration
149 scopes. This table is a display which tracks the nesting
150 of declaration scopes at the current scope and containing
151 scopes. This table is used to find the proper place to
152 define type declaration DIE's. */
153 static GTY(()) vec
<tree
, va_gc
> *decl_scope_table
;
155 /* Pointers to various DWARF2 sections. */
156 static GTY(()) section
*debug_info_section
;
157 static GTY(()) section
*debug_skeleton_info_section
;
158 static GTY(()) section
*debug_abbrev_section
;
159 static GTY(()) section
*debug_skeleton_abbrev_section
;
160 static GTY(()) section
*debug_aranges_section
;
161 static GTY(()) section
*debug_addr_section
;
162 static GTY(()) section
*debug_macinfo_section
;
163 static const char *debug_macinfo_section_name
;
164 static GTY(()) section
*debug_line_section
;
165 static GTY(()) section
*debug_skeleton_line_section
;
166 static GTY(()) section
*debug_loc_section
;
167 static GTY(()) section
*debug_pubnames_section
;
168 static GTY(()) section
*debug_pubtypes_section
;
169 static GTY(()) section
*debug_str_section
;
170 static GTY(()) section
*debug_line_str_section
;
171 static GTY(()) section
*debug_str_dwo_section
;
172 static GTY(()) section
*debug_str_offsets_section
;
173 static GTY(()) section
*debug_ranges_section
;
174 static GTY(()) section
*debug_frame_section
;
176 /* Maximum size (in bytes) of an artificially generated label. */
177 #define MAX_ARTIFICIAL_LABEL_BYTES 30
179 /* According to the (draft) DWARF 3 specification, the initial length
180 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
181 bytes are 0xffffffff, followed by the length stored in the next 8
184 However, the SGI/MIPS ABI uses an initial length which is equal to
185 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
187 #ifndef DWARF_INITIAL_LENGTH_SIZE
188 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
191 /* Round SIZE up to the nearest BOUNDARY. */
192 #define DWARF_ROUND(SIZE,BOUNDARY) \
193 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
195 /* CIE identifier. */
196 #if HOST_BITS_PER_WIDE_INT >= 64
197 #define DWARF_CIE_ID \
198 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
200 #define DWARF_CIE_ID DW_CIE_ID
204 /* A vector for a table that contains frame description
205 information for each routine. */
206 #define NOT_INDEXED (-1U)
207 #define NO_INDEX_ASSIGNED (-2U)
209 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
211 struct GTY((for_user
)) indirect_string_node
{
213 unsigned int refcount
;
214 enum dwarf_form form
;
219 struct indirect_string_hasher
: ggc_ptr_hash
<indirect_string_node
>
221 typedef const char *compare_type
;
223 static hashval_t
hash (indirect_string_node
*);
224 static bool equal (indirect_string_node
*, const char *);
227 static GTY (()) hash_table
<indirect_string_hasher
> *debug_str_hash
;
229 static GTY (()) hash_table
<indirect_string_hasher
> *debug_line_str_hash
;
231 /* With split_debug_info, both the comp_dir and dwo_name go in the
232 main object file, rather than the dwo, similar to the force_direct
233 parameter elsewhere but with additional complications:
235 1) The string is needed in both the main object file and the dwo.
236 That is, the comp_dir and dwo_name will appear in both places.
238 2) Strings can use four forms: DW_FORM_string, DW_FORM_strp,
239 DW_FORM_line_strp or DW_FORM_GNU_str_index.
241 3) GCC chooses the form to use late, depending on the size and
244 Rather than forcing the all debug string handling functions and
245 callers to deal with these complications, simply use a separate,
246 special-cased string table for any attribute that should go in the
247 main object file. This limits the complexity to just the places
250 static GTY (()) hash_table
<indirect_string_hasher
> *skeleton_debug_str_hash
;
252 static GTY(()) int dw2_string_counter
;
254 /* True if the compilation unit places functions in more than one section. */
255 static GTY(()) bool have_multiple_function_sections
= false;
257 /* Whether the default text and cold text sections have been used at all. */
259 static GTY(()) bool text_section_used
= false;
260 static GTY(()) bool cold_text_section_used
= false;
262 /* The default cold text section. */
263 static GTY(()) section
*cold_text_section
;
265 /* The DIE for C++14 'auto' in a function return type. */
266 static GTY(()) dw_die_ref auto_die
;
268 /* The DIE for C++14 'decltype(auto)' in a function return type. */
269 static GTY(()) dw_die_ref decltype_auto_die
;
271 /* Forward declarations for functions defined in this file. */
273 static void output_call_frame_info (int);
274 static void dwarf2out_note_section_used (void);
276 /* Personality decl of current unit. Used only when assembler does not support
278 static GTY(()) rtx current_unit_personality
;
280 /* .debug_rnglists next index. */
281 static unsigned int rnglist_idx
;
283 /* Data and reference forms for relocatable data. */
284 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
285 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
287 #ifndef DEBUG_FRAME_SECTION
288 #define DEBUG_FRAME_SECTION ".debug_frame"
291 #ifndef FUNC_BEGIN_LABEL
292 #define FUNC_BEGIN_LABEL "LFB"
295 #ifndef FUNC_END_LABEL
296 #define FUNC_END_LABEL "LFE"
299 #ifndef PROLOGUE_END_LABEL
300 #define PROLOGUE_END_LABEL "LPE"
303 #ifndef EPILOGUE_BEGIN_LABEL
304 #define EPILOGUE_BEGIN_LABEL "LEB"
307 #ifndef FRAME_BEGIN_LABEL
308 #define FRAME_BEGIN_LABEL "Lframe"
310 #define CIE_AFTER_SIZE_LABEL "LSCIE"
311 #define CIE_END_LABEL "LECIE"
312 #define FDE_LABEL "LSFDE"
313 #define FDE_AFTER_SIZE_LABEL "LASFDE"
314 #define FDE_END_LABEL "LEFDE"
315 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
316 #define LINE_NUMBER_END_LABEL "LELT"
317 #define LN_PROLOG_AS_LABEL "LASLTP"
318 #define LN_PROLOG_END_LABEL "LELTP"
319 #define DIE_LABEL_PREFIX "DW"
321 /* Match the base name of a file to the base name of a compilation unit. */
324 matches_main_base (const char *path
)
326 /* Cache the last query. */
327 static const char *last_path
= NULL
;
328 static int last_match
= 0;
329 if (path
!= last_path
)
332 int length
= base_of_path (path
, &base
);
334 last_match
= (length
== main_input_baselength
335 && memcmp (base
, main_input_basename
, length
) == 0);
340 #ifdef DEBUG_DEBUG_STRUCT
343 dump_struct_debug (tree type
, enum debug_info_usage usage
,
344 enum debug_struct_file criterion
, int generic
,
345 int matches
, int result
)
347 /* Find the type name. */
348 tree type_decl
= TYPE_STUB_DECL (type
);
350 const char *name
= 0;
351 if (TREE_CODE (t
) == TYPE_DECL
)
354 name
= IDENTIFIER_POINTER (t
);
356 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
358 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
359 matches
? "bas" : "hdr",
360 generic
? "gen" : "ord",
361 usage
== DINFO_USAGE_DFN
? ";" :
362 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
364 (void*) type_decl
, name
);
367 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
368 dump_struct_debug (type, usage, criterion, generic, matches, result)
372 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
377 /* Get the number of HOST_WIDE_INTs needed to represent the precision
378 of the number. Some constants have a large uniform precision, so
379 we get the precision needed for the actual value of the number. */
382 get_full_len (const wide_int
&op
)
384 int prec
= wi::min_precision (op
, UNSIGNED
);
385 return ((prec
+ HOST_BITS_PER_WIDE_INT
- 1)
386 / HOST_BITS_PER_WIDE_INT
);
390 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
392 enum debug_struct_file criterion
;
394 bool generic
= lang_hooks
.types
.generic_p (type
);
397 criterion
= debug_struct_generic
[usage
];
399 criterion
= debug_struct_ordinary
[usage
];
401 if (criterion
== DINFO_STRUCT_FILE_NONE
)
402 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
403 if (criterion
== DINFO_STRUCT_FILE_ANY
)
404 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
406 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
408 if (type_decl
!= NULL
)
410 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
411 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
413 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
414 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
417 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
420 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
421 switch to the data section instead, and write out a synthetic start label
422 for collect2 the first time around. */
425 switch_to_eh_frame_section (bool back ATTRIBUTE_UNUSED
)
427 if (eh_frame_section
== 0)
431 if (EH_TABLES_CAN_BE_READ_ONLY
)
437 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
439 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
441 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
444 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
445 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
446 && (per_encoding
& 0x70) != DW_EH_PE_absptr
447 && (per_encoding
& 0x70) != DW_EH_PE_aligned
448 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
449 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
450 ? 0 : SECTION_WRITE
);
453 flags
= SECTION_WRITE
;
455 #ifdef EH_FRAME_SECTION_NAME
456 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
458 eh_frame_section
= ((flags
== SECTION_WRITE
)
459 ? data_section
: readonly_data_section
);
460 #endif /* EH_FRAME_SECTION_NAME */
463 switch_to_section (eh_frame_section
);
465 #ifdef EH_FRAME_THROUGH_COLLECT2
466 /* We have no special eh_frame section. Emit special labels to guide
470 tree label
= get_file_function_name ("F");
471 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
472 targetm
.asm_out
.globalize_label (asm_out_file
,
473 IDENTIFIER_POINTER (label
));
474 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
479 /* Switch [BACK] to the eh or debug frame table section, depending on
483 switch_to_frame_table_section (int for_eh
, bool back
)
486 switch_to_eh_frame_section (back
);
489 if (!debug_frame_section
)
490 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
491 SECTION_DEBUG
, NULL
);
492 switch_to_section (debug_frame_section
);
496 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
498 enum dw_cfi_oprnd_type
499 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
504 case DW_CFA_GNU_window_save
:
505 case DW_CFA_remember_state
:
506 case DW_CFA_restore_state
:
507 return dw_cfi_oprnd_unused
;
510 case DW_CFA_advance_loc1
:
511 case DW_CFA_advance_loc2
:
512 case DW_CFA_advance_loc4
:
513 case DW_CFA_MIPS_advance_loc8
:
514 return dw_cfi_oprnd_addr
;
517 case DW_CFA_offset_extended
:
519 case DW_CFA_offset_extended_sf
:
520 case DW_CFA_def_cfa_sf
:
522 case DW_CFA_restore_extended
:
523 case DW_CFA_undefined
:
524 case DW_CFA_same_value
:
525 case DW_CFA_def_cfa_register
:
526 case DW_CFA_register
:
527 case DW_CFA_expression
:
528 case DW_CFA_val_expression
:
529 return dw_cfi_oprnd_reg_num
;
531 case DW_CFA_def_cfa_offset
:
532 case DW_CFA_GNU_args_size
:
533 case DW_CFA_def_cfa_offset_sf
:
534 return dw_cfi_oprnd_offset
;
536 case DW_CFA_def_cfa_expression
:
537 return dw_cfi_oprnd_loc
;
544 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
546 enum dw_cfi_oprnd_type
547 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
552 case DW_CFA_def_cfa_sf
:
554 case DW_CFA_offset_extended_sf
:
555 case DW_CFA_offset_extended
:
556 return dw_cfi_oprnd_offset
;
558 case DW_CFA_register
:
559 return dw_cfi_oprnd_reg_num
;
561 case DW_CFA_expression
:
562 case DW_CFA_val_expression
:
563 return dw_cfi_oprnd_loc
;
566 return dw_cfi_oprnd_unused
;
570 /* Output one FDE. */
573 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
574 char *section_start_label
, int fde_encoding
, char *augmentation
,
575 bool any_lsda_needed
, int lsda_encoding
)
577 const char *begin
, *end
;
578 static unsigned int j
;
579 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
581 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
583 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
585 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
586 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
587 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
589 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
590 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
591 " indicating 64-bit DWARF extension");
592 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
595 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
598 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
600 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
601 debug_frame_section
, "FDE CIE offset");
603 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
604 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
608 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
609 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
610 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
611 "FDE initial location");
612 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
613 end
, begin
, "FDE address range");
617 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
618 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
625 int size
= size_of_encoded_value (lsda_encoding
);
627 if (lsda_encoding
== DW_EH_PE_aligned
)
629 int offset
= ( 4 /* Length */
631 + 2 * size_of_encoded_value (fde_encoding
)
632 + 1 /* Augmentation size */ );
633 int pad
= -offset
& (PTR_SIZE
- 1);
636 gcc_assert (size_of_uleb128 (size
) == 1);
639 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
641 if (fde
->uses_eh_lsda
)
643 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
644 fde
->funcdef_number
);
645 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
646 gen_rtx_SYMBOL_REF (Pmode
, l1
),
648 "Language Specific Data Area");
652 if (lsda_encoding
== DW_EH_PE_aligned
)
653 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
654 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
655 "Language Specific Data Area (none)");
659 dw2_asm_output_data_uleb128 (0, "Augmentation size");
662 /* Loop through the Call Frame Instructions associated with this FDE. */
663 fde
->dw_fde_current_label
= begin
;
665 size_t from
, until
, i
;
668 until
= vec_safe_length (fde
->dw_fde_cfi
);
670 if (fde
->dw_fde_second_begin
== NULL
)
673 until
= fde
->dw_fde_switch_cfi_index
;
675 from
= fde
->dw_fde_switch_cfi_index
;
677 for (i
= from
; i
< until
; i
++)
678 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
681 /* If we are to emit a ref/link from function bodies to their frame tables,
682 do it now. This is typically performed to make sure that tables
683 associated with functions are dragged with them and not discarded in
684 garbage collecting links. We need to do this on a per function basis to
685 cope with -ffunction-sections. */
687 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
688 /* Switch to the function section, emit the ref to the tables, and
689 switch *back* into the table section. */
690 switch_to_section (function_section (fde
->decl
));
691 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
692 switch_to_frame_table_section (for_eh
, true);
695 /* Pad the FDE out to an address sized boundary. */
696 ASM_OUTPUT_ALIGN (asm_out_file
,
697 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
698 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
703 /* Return true if frame description entry FDE is needed for EH. */
706 fde_needed_for_eh_p (dw_fde_ref fde
)
708 if (flag_asynchronous_unwind_tables
)
711 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
714 if (fde
->uses_eh_lsda
)
717 /* If exceptions are enabled, we have collected nothrow info. */
718 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
724 /* Output the call frame information used to record information
725 that relates to calculating the frame pointer, and records the
726 location of saved registers. */
729 output_call_frame_info (int for_eh
)
734 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
735 char section_start_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
736 bool any_lsda_needed
= false;
737 char augmentation
[6];
738 int augmentation_size
;
739 int fde_encoding
= DW_EH_PE_absptr
;
740 int per_encoding
= DW_EH_PE_absptr
;
741 int lsda_encoding
= DW_EH_PE_absptr
;
743 rtx personality
= NULL
;
746 /* Don't emit a CIE if there won't be any FDEs. */
750 /* Nothing to do if the assembler's doing it all. */
751 if (dwarf2out_do_cfi_asm ())
754 /* If we don't have any functions we'll want to unwind out of, don't emit
755 any EH unwind information. If we make FDEs linkonce, we may have to
756 emit an empty label for an FDE that wouldn't otherwise be emitted. We
757 want to avoid having an FDE kept around when the function it refers to
758 is discarded. Example where this matters: a primary function template
759 in C++ requires EH information, an explicit specialization doesn't. */
762 bool any_eh_needed
= false;
764 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
766 if (fde
->uses_eh_lsda
)
767 any_eh_needed
= any_lsda_needed
= true;
768 else if (fde_needed_for_eh_p (fde
))
769 any_eh_needed
= true;
770 else if (TARGET_USES_WEAK_UNWIND_INFO
)
771 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
778 /* We're going to be generating comments, so turn on app. */
782 /* Switch to the proper frame section, first time. */
783 switch_to_frame_table_section (for_eh
, false);
785 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
786 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
788 /* Output the CIE. */
789 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
790 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
791 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
793 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
794 dw2_asm_output_data (4, 0xffffffff,
795 "Initial length escape value indicating 64-bit DWARF extension");
796 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
797 "Length of Common Information Entry");
799 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
801 /* Now that the CIE pointer is PC-relative for EH,
802 use 0 to identify the CIE. */
803 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
804 (for_eh
? 0 : DWARF_CIE_ID
),
805 "CIE Identifier Tag");
807 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
808 use CIE version 1, unless that would produce incorrect results
809 due to overflowing the return register column. */
810 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
812 if (return_reg
>= 256 || dwarf_version
> 2)
814 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
817 augmentation_size
= 0;
819 personality
= current_unit_personality
;
825 z Indicates that a uleb128 is present to size the
826 augmentation section.
827 L Indicates the encoding (and thus presence) of
828 an LSDA pointer in the FDE augmentation.
829 R Indicates a non-default pointer encoding for
831 P Indicates the presence of an encoding + language
832 personality routine in the CIE augmentation. */
834 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
835 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
836 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
838 p
= augmentation
+ 1;
842 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
843 assemble_external_libcall (personality
);
848 augmentation_size
+= 1;
850 if (fde_encoding
!= DW_EH_PE_absptr
)
853 augmentation_size
+= 1;
855 if (p
> augmentation
+ 1)
857 augmentation
[0] = 'z';
861 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
862 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
864 int offset
= ( 4 /* Length */
866 + 1 /* CIE version */
867 + strlen (augmentation
) + 1 /* Augmentation */
868 + size_of_uleb128 (1) /* Code alignment */
869 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
871 + 1 /* Augmentation size */
872 + 1 /* Personality encoding */ );
873 int pad
= -offset
& (PTR_SIZE
- 1);
875 augmentation_size
+= pad
;
877 /* Augmentations should be small, so there's scarce need to
878 iterate for a solution. Die if we exceed one uleb128 byte. */
879 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
883 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
884 if (dw_cie_version
>= 4)
886 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
887 dw2_asm_output_data (1, 0, "CIE Segment Size");
889 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
890 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
891 "CIE Data Alignment Factor");
893 if (dw_cie_version
== 1)
894 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
896 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
900 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
903 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
904 eh_data_format_name (per_encoding
));
905 dw2_asm_output_encoded_addr_rtx (per_encoding
,
911 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
912 eh_data_format_name (lsda_encoding
));
914 if (fde_encoding
!= DW_EH_PE_absptr
)
915 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
916 eh_data_format_name (fde_encoding
));
919 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
920 output_cfi (cfi
, NULL
, for_eh
);
922 /* Pad the CIE out to an address sized boundary. */
923 ASM_OUTPUT_ALIGN (asm_out_file
,
924 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
925 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
927 /* Loop through all of the FDE's. */
928 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
932 /* Don't emit EH unwind info for leaf functions that don't need it. */
933 if (for_eh
&& !fde_needed_for_eh_p (fde
))
936 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
937 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
938 augmentation
, any_lsda_needed
, lsda_encoding
);
941 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
942 dw2_asm_output_data (4, 0, "End of Table");
944 /* Turn off app to make assembly quicker. */
949 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
952 dwarf2out_do_cfi_startproc (bool second
)
956 rtx personality
= get_personality_function (current_function_decl
);
958 fprintf (asm_out_file
, "\t.cfi_startproc\n");
962 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
965 /* ??? The GAS support isn't entirely consistent. We have to
966 handle indirect support ourselves, but PC-relative is done
967 in the assembler. Further, the assembler can't handle any
968 of the weirder relocation types. */
969 if (enc
& DW_EH_PE_indirect
)
970 ref
= dw2_force_const_mem (ref
, true);
972 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
973 output_addr_const (asm_out_file
, ref
);
974 fputc ('\n', asm_out_file
);
977 if (crtl
->uses_eh_lsda
)
979 char lab
[MAX_ARTIFICIAL_LABEL_BYTES
];
981 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
982 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
983 current_function_funcdef_no
);
984 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
985 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
987 if (enc
& DW_EH_PE_indirect
)
988 ref
= dw2_force_const_mem (ref
, true);
990 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
991 output_addr_const (asm_out_file
, ref
);
992 fputc ('\n', asm_out_file
);
996 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
997 this allocation may be done before pass_final. */
1000 dwarf2out_alloc_current_fde (void)
1004 fde
= ggc_cleared_alloc
<dw_fde_node
> ();
1005 fde
->decl
= current_function_decl
;
1006 fde
->funcdef_number
= current_function_funcdef_no
;
1007 fde
->fde_index
= vec_safe_length (fde_vec
);
1008 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
1009 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
1010 fde
->nothrow
= crtl
->nothrow
;
1011 fde
->drap_reg
= INVALID_REGNUM
;
1012 fde
->vdrap_reg
= INVALID_REGNUM
;
1014 /* Record the FDE associated with this function. */
1016 vec_safe_push (fde_vec
, fde
);
1021 /* Output a marker (i.e. a label) for the beginning of a function, before
1025 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1026 const char *file ATTRIBUTE_UNUSED
)
1028 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1034 current_function_func_begin_label
= NULL
;
1036 do_frame
= dwarf2out_do_frame ();
1038 /* ??? current_function_func_begin_label is also used by except.c for
1039 call-site information. We must emit this label if it might be used. */
1041 && (!flag_exceptions
1042 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1045 fnsec
= function_section (current_function_decl
);
1046 switch_to_section (fnsec
);
1047 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1048 current_function_funcdef_no
);
1049 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1050 current_function_funcdef_no
);
1051 dup_label
= xstrdup (label
);
1052 current_function_func_begin_label
= dup_label
;
1054 /* We can elide the fde allocation if we're not emitting debug info. */
1058 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1059 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1060 would include pass_dwarf2_frame. If we've not created the FDE yet,
1064 fde
= dwarf2out_alloc_current_fde ();
1066 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1067 fde
->dw_fde_begin
= dup_label
;
1068 fde
->dw_fde_current_label
= dup_label
;
1069 fde
->in_std_section
= (fnsec
== text_section
1070 || (cold_text_section
&& fnsec
== cold_text_section
));
1072 /* We only want to output line number information for the genuine dwarf2
1073 prologue case, not the eh frame case. */
1074 #ifdef DWARF2_DEBUGGING_INFO
1076 dwarf2out_source_line (line
, file
, 0, true);
1079 if (dwarf2out_do_cfi_asm ())
1080 dwarf2out_do_cfi_startproc (false);
1083 rtx personality
= get_personality_function (current_function_decl
);
1084 if (!current_unit_personality
)
1085 current_unit_personality
= personality
;
1087 /* We cannot keep a current personality per function as without CFI
1088 asm, at the point where we emit the CFI data, there is no current
1089 function anymore. */
1090 if (personality
&& current_unit_personality
!= personality
)
1091 sorry ("multiple EH personalities are supported only with assemblers "
1092 "supporting .cfi_personality directive");
1096 /* Output a marker (i.e. a label) for the end of the generated code
1097 for a function prologue. This gets called *after* the prologue code has
1101 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1102 const char *file ATTRIBUTE_UNUSED
)
1104 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1106 /* Output a label to mark the endpoint of the code generated for this
1108 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1109 current_function_funcdef_no
);
1110 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1111 current_function_funcdef_no
);
1112 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1115 /* Output a marker (i.e. a label) for the beginning of the generated code
1116 for a function epilogue. This gets called *before* the prologue code has
1120 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1121 const char *file ATTRIBUTE_UNUSED
)
1123 dw_fde_ref fde
= cfun
->fde
;
1124 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1126 if (fde
->dw_fde_vms_begin_epilogue
)
1129 /* Output a label to mark the endpoint of the code generated for this
1131 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1132 current_function_funcdef_no
);
1133 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1134 current_function_funcdef_no
);
1135 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1138 /* Output a marker (i.e. a label) for the absolute end of the generated code
1139 for a function definition. This gets called *after* the epilogue code has
1143 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1144 const char *file ATTRIBUTE_UNUSED
)
1147 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1149 last_var_location_insn
= NULL
;
1150 cached_next_real_insn
= NULL
;
1152 if (dwarf2out_do_cfi_asm ())
1153 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1155 /* Output a label to mark the endpoint of the code generated for this
1157 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1158 current_function_funcdef_no
);
1159 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1161 gcc_assert (fde
!= NULL
);
1162 if (fde
->dw_fde_second_begin
== NULL
)
1163 fde
->dw_fde_end
= xstrdup (label
);
1167 dwarf2out_frame_finish (void)
1169 /* Output call frame information. */
1170 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1171 output_call_frame_info (0);
1173 /* Output another copy for the unwinder. */
1174 if ((flag_unwind_tables
|| flag_exceptions
)
1175 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1176 output_call_frame_info (1);
1179 /* Note that the current function section is being used for code. */
1182 dwarf2out_note_section_used (void)
1184 section
*sec
= current_function_section ();
1185 if (sec
== text_section
)
1186 text_section_used
= true;
1187 else if (sec
== cold_text_section
)
1188 cold_text_section_used
= true;
1191 static void var_location_switch_text_section (void);
1192 static void set_cur_line_info_table (section
*);
1195 dwarf2out_switch_text_section (void)
1198 dw_fde_ref fde
= cfun
->fde
;
1200 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1202 if (!in_cold_section_p
)
1204 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1205 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1206 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1210 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1211 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1212 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1214 have_multiple_function_sections
= true;
1216 /* There is no need to mark used sections when not debugging. */
1217 if (cold_text_section
!= NULL
)
1218 dwarf2out_note_section_used ();
1220 if (dwarf2out_do_cfi_asm ())
1221 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1223 /* Now do the real section switch. */
1224 sect
= current_function_section ();
1225 switch_to_section (sect
);
1227 fde
->second_in_std_section
1228 = (sect
== text_section
1229 || (cold_text_section
&& sect
== cold_text_section
));
1231 if (dwarf2out_do_cfi_asm ())
1232 dwarf2out_do_cfi_startproc (true);
1234 var_location_switch_text_section ();
1236 if (cold_text_section
!= NULL
)
1237 set_cur_line_info_table (sect
);
1240 /* And now, the subset of the debugging information support code necessary
1241 for emitting location expressions. */
1243 /* Data about a single source file. */
1244 struct GTY((for_user
)) dwarf_file_data
{
1245 const char * filename
;
1249 /* Describe an entry into the .debug_addr section. */
1253 ate_kind_rtx_dtprel
,
1257 struct GTY((for_user
)) addr_table_entry
{
1259 unsigned int refcount
;
1261 union addr_table_entry_struct_union
1263 rtx
GTY ((tag ("0"))) rtl
;
1264 char * GTY ((tag ("1"))) label
;
1266 GTY ((desc ("%1.kind"))) addr
;
1269 /* Location lists are ranges + location descriptions for that range,
1270 so you can track variables that are in different places over
1271 their entire life. */
1272 typedef struct GTY(()) dw_loc_list_struct
{
1273 dw_loc_list_ref dw_loc_next
;
1274 const char *begin
; /* Label and addr_entry for start of range */
1275 addr_table_entry
*begin_entry
;
1276 const char *end
; /* Label for end of range */
1277 char *ll_symbol
; /* Label for beginning of location list.
1278 Only on head of list */
1279 const char *section
; /* Section this loclist is relative to */
1280 dw_loc_descr_ref expr
;
1282 /* True if all addresses in this and subsequent lists are known to be
1285 /* True if this list has been replaced by dw_loc_next. */
1287 /* True if it has been emitted into .debug_loc* / .debug_loclists*
1289 unsigned char emitted
: 1;
1290 /* True if hash field is index rather than hash value. */
1291 unsigned char num_assigned
: 1;
1292 /* True if .debug_loclists.dwo offset has been emitted for it already. */
1293 unsigned char offset_emitted
: 1;
1294 /* True if the range should be emitted even if begin and end
1299 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1300 static dw_loc_descr_ref
uint_loc_descriptor (unsigned HOST_WIDE_INT
);
1302 /* Convert a DWARF stack opcode into its string name. */
1305 dwarf_stack_op_name (unsigned int op
)
1307 const char *name
= get_DW_OP_name (op
);
1312 return "OP_<unknown>";
1315 /* Return a pointer to a newly allocated location description. Location
1316 descriptions are simple expression terms that can be strung
1317 together to form more complicated location (address) descriptions. */
1319 static inline dw_loc_descr_ref
1320 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1321 unsigned HOST_WIDE_INT oprnd2
)
1323 dw_loc_descr_ref descr
= ggc_cleared_alloc
<dw_loc_descr_node
> ();
1325 descr
->dw_loc_opc
= op
;
1326 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1327 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1328 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1329 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1330 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1331 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1336 /* Return a pointer to a newly allocated location description for
1339 static inline dw_loc_descr_ref
1340 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1343 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1346 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1349 /* Add a location description term to a location description expression. */
1352 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1354 dw_loc_descr_ref
*d
;
1356 /* Find the end of the chain. */
1357 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1363 /* Compare two location operands for exact equality. */
1366 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1368 if (a
->val_class
!= b
->val_class
)
1370 switch (a
->val_class
)
1372 case dw_val_class_none
:
1374 case dw_val_class_addr
:
1375 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1377 case dw_val_class_offset
:
1378 case dw_val_class_unsigned_const
:
1379 case dw_val_class_const
:
1380 case dw_val_class_unsigned_const_implicit
:
1381 case dw_val_class_const_implicit
:
1382 case dw_val_class_range_list
:
1383 /* These are all HOST_WIDE_INT, signed or unsigned. */
1384 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1386 case dw_val_class_loc
:
1387 return a
->v
.val_loc
== b
->v
.val_loc
;
1388 case dw_val_class_loc_list
:
1389 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1390 case dw_val_class_die_ref
:
1391 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1392 case dw_val_class_fde_ref
:
1393 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1394 case dw_val_class_lbl_id
:
1395 case dw_val_class_lineptr
:
1396 case dw_val_class_macptr
:
1397 case dw_val_class_loclistsptr
:
1398 case dw_val_class_high_pc
:
1399 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1400 case dw_val_class_str
:
1401 return a
->v
.val_str
== b
->v
.val_str
;
1402 case dw_val_class_flag
:
1403 return a
->v
.val_flag
== b
->v
.val_flag
;
1404 case dw_val_class_file
:
1405 case dw_val_class_file_implicit
:
1406 return a
->v
.val_file
== b
->v
.val_file
;
1407 case dw_val_class_decl_ref
:
1408 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1410 case dw_val_class_const_double
:
1411 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1412 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1414 case dw_val_class_wide_int
:
1415 return *a
->v
.val_wide
== *b
->v
.val_wide
;
1417 case dw_val_class_vec
:
1419 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1420 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1422 return (a_len
== b_len
1423 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1426 case dw_val_class_data8
:
1427 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1429 case dw_val_class_vms_delta
:
1430 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1431 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1433 case dw_val_class_discr_value
:
1434 return (a
->v
.val_discr_value
.pos
== b
->v
.val_discr_value
.pos
1435 && a
->v
.val_discr_value
.v
.uval
== b
->v
.val_discr_value
.v
.uval
);
1436 case dw_val_class_discr_list
:
1437 /* It makes no sense comparing two discriminant value lists. */
1443 /* Compare two location atoms for exact equality. */
1446 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1448 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1451 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1452 address size, but since we always allocate cleared storage it
1453 should be zero for other types of locations. */
1454 if (a
->dtprel
!= b
->dtprel
)
1457 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1458 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1461 /* Compare two complete location expressions for exact equality. */
1464 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1470 if (a
== NULL
|| b
== NULL
)
1472 if (!loc_descr_equal_p_1 (a
, b
))
1481 /* Add a constant OFFSET to a location expression. */
1484 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1486 dw_loc_descr_ref loc
;
1489 gcc_assert (*list_head
!= NULL
);
1494 /* Find the end of the chain. */
1495 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1499 if (loc
->dw_loc_opc
== DW_OP_fbreg
1500 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1501 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1502 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1503 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1505 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1506 offset. Don't optimize if an signed integer overflow would happen. */
1508 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1509 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1512 else if (offset
> 0)
1513 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1518 = uint_loc_descriptor (-(unsigned HOST_WIDE_INT
) offset
);
1519 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1523 /* Add a constant OFFSET to a location list. */
1526 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1529 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1530 loc_descr_plus_const (&d
->expr
, offset
);
1533 #define DWARF_REF_SIZE \
1534 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1536 /* The number of bits that can be encoded by largest DW_FORM_dataN.
1537 In DWARF4 and earlier it is DW_FORM_data8 with 64 bits, in DWARF5
1538 DW_FORM_data16 with 128 bits. */
1539 #define DWARF_LARGEST_DATA_FORM_BITS \
1540 (dwarf_version >= 5 ? 128 : 64)
1542 /* Utility inline function for construction of ops that were GNU extension
1544 static inline enum dwarf_location_atom
1545 dwarf_OP (enum dwarf_location_atom op
)
1549 case DW_OP_implicit_pointer
:
1550 if (dwarf_version
< 5)
1551 return DW_OP_GNU_implicit_pointer
;
1554 case DW_OP_entry_value
:
1555 if (dwarf_version
< 5)
1556 return DW_OP_GNU_entry_value
;
1559 case DW_OP_const_type
:
1560 if (dwarf_version
< 5)
1561 return DW_OP_GNU_const_type
;
1564 case DW_OP_regval_type
:
1565 if (dwarf_version
< 5)
1566 return DW_OP_GNU_regval_type
;
1569 case DW_OP_deref_type
:
1570 if (dwarf_version
< 5)
1571 return DW_OP_GNU_deref_type
;
1575 if (dwarf_version
< 5)
1576 return DW_OP_GNU_convert
;
1579 case DW_OP_reinterpret
:
1580 if (dwarf_version
< 5)
1581 return DW_OP_GNU_reinterpret
;
1590 /* Similarly for attributes. */
1591 static inline enum dwarf_attribute
1592 dwarf_AT (enum dwarf_attribute at
)
1596 case DW_AT_call_return_pc
:
1597 if (dwarf_version
< 5)
1598 return DW_AT_low_pc
;
1601 case DW_AT_call_tail_call
:
1602 if (dwarf_version
< 5)
1603 return DW_AT_GNU_tail_call
;
1606 case DW_AT_call_origin
:
1607 if (dwarf_version
< 5)
1608 return DW_AT_abstract_origin
;
1611 case DW_AT_call_target
:
1612 if (dwarf_version
< 5)
1613 return DW_AT_GNU_call_site_target
;
1616 case DW_AT_call_target_clobbered
:
1617 if (dwarf_version
< 5)
1618 return DW_AT_GNU_call_site_target_clobbered
;
1621 case DW_AT_call_parameter
:
1622 if (dwarf_version
< 5)
1623 return DW_AT_abstract_origin
;
1626 case DW_AT_call_value
:
1627 if (dwarf_version
< 5)
1628 return DW_AT_GNU_call_site_value
;
1631 case DW_AT_call_data_value
:
1632 if (dwarf_version
< 5)
1633 return DW_AT_GNU_call_site_data_value
;
1636 case DW_AT_call_all_calls
:
1637 if (dwarf_version
< 5)
1638 return DW_AT_GNU_all_call_sites
;
1641 case DW_AT_call_all_tail_calls
:
1642 if (dwarf_version
< 5)
1643 return DW_AT_GNU_all_tail_call_sites
;
1646 case DW_AT_dwo_name
:
1647 if (dwarf_version
< 5)
1648 return DW_AT_GNU_dwo_name
;
1657 /* And similarly for tags. */
1658 static inline enum dwarf_tag
1659 dwarf_TAG (enum dwarf_tag tag
)
1663 case DW_TAG_call_site
:
1664 if (dwarf_version
< 5)
1665 return DW_TAG_GNU_call_site
;
1668 case DW_TAG_call_site_parameter
:
1669 if (dwarf_version
< 5)
1670 return DW_TAG_GNU_call_site_parameter
;
1679 static unsigned long int get_base_type_offset (dw_die_ref
);
1681 /* Return the size of a location descriptor. */
1683 static unsigned long
1684 size_of_loc_descr (dw_loc_descr_ref loc
)
1686 unsigned long size
= 1;
1688 switch (loc
->dw_loc_opc
)
1691 size
+= DWARF2_ADDR_SIZE
;
1693 case DW_OP_GNU_addr_index
:
1694 case DW_OP_GNU_const_index
:
1695 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1696 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1715 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1718 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1723 case DW_OP_plus_uconst
:
1724 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1762 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1765 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1768 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1771 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1772 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1775 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1777 case DW_OP_bit_piece
:
1778 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1779 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1781 case DW_OP_deref_size
:
1782 case DW_OP_xderef_size
:
1791 case DW_OP_call_ref
:
1792 size
+= DWARF_REF_SIZE
;
1794 case DW_OP_implicit_value
:
1795 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1796 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1798 case DW_OP_implicit_pointer
:
1799 case DW_OP_GNU_implicit_pointer
:
1800 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1802 case DW_OP_entry_value
:
1803 case DW_OP_GNU_entry_value
:
1805 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1806 size
+= size_of_uleb128 (op_size
) + op_size
;
1809 case DW_OP_const_type
:
1810 case DW_OP_GNU_const_type
:
1813 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1814 size
+= size_of_uleb128 (o
) + 1;
1815 switch (loc
->dw_loc_oprnd2
.val_class
)
1817 case dw_val_class_vec
:
1818 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1819 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1821 case dw_val_class_const
:
1822 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1824 case dw_val_class_const_double
:
1825 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1827 case dw_val_class_wide_int
:
1828 size
+= (get_full_len (*loc
->dw_loc_oprnd2
.v
.val_wide
)
1829 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
1836 case DW_OP_regval_type
:
1837 case DW_OP_GNU_regval_type
:
1840 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1841 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1842 + size_of_uleb128 (o
);
1845 case DW_OP_deref_type
:
1846 case DW_OP_GNU_deref_type
:
1849 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1850 size
+= 1 + size_of_uleb128 (o
);
1854 case DW_OP_reinterpret
:
1855 case DW_OP_GNU_convert
:
1856 case DW_OP_GNU_reinterpret
:
1857 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1858 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1862 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1863 size
+= size_of_uleb128 (o
);
1866 case DW_OP_GNU_parameter_ref
:
1876 /* Return the size of a series of location descriptors. */
1879 size_of_locs (dw_loc_descr_ref loc
)
1884 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1885 field, to avoid writing to a PCH file. */
1886 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1888 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1890 size
+= size_of_loc_descr (l
);
1895 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1897 l
->dw_loc_addr
= size
;
1898 size
+= size_of_loc_descr (l
);
1904 /* Return the size of the value in a DW_AT_discr_value attribute. */
1907 size_of_discr_value (dw_discr_value
*discr_value
)
1909 if (discr_value
->pos
)
1910 return size_of_uleb128 (discr_value
->v
.uval
);
1912 return size_of_sleb128 (discr_value
->v
.sval
);
1915 /* Return the size of the value in a DW_AT_discr_list attribute. */
1918 size_of_discr_list (dw_discr_list_ref discr_list
)
1922 for (dw_discr_list_ref list
= discr_list
;
1924 list
= list
->dw_discr_next
)
1926 /* One byte for the discriminant value descriptor, and then one or two
1927 LEB128 numbers, depending on whether it's a single case label or a
1930 size
+= size_of_discr_value (&list
->dw_discr_lower_bound
);
1931 if (list
->dw_discr_range
!= 0)
1932 size
+= size_of_discr_value (&list
->dw_discr_upper_bound
);
1937 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1938 static void get_ref_die_offset_label (char *, dw_die_ref
);
1939 static unsigned long int get_ref_die_offset (dw_die_ref
);
1941 /* Output location description stack opcode's operands (if any).
1942 The for_eh_or_skip parameter controls whether register numbers are
1943 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1944 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1945 info). This should be suppressed for the cases that have not been converted
1946 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1949 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1951 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1952 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1954 switch (loc
->dw_loc_opc
)
1956 #ifdef DWARF2_DEBUGGING_INFO
1959 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1964 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1965 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1967 fputc ('\n', asm_out_file
);
1972 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1977 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1978 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1980 fputc ('\n', asm_out_file
);
1985 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1986 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1993 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1994 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1996 dw2_asm_output_data (2, offset
, NULL
);
1999 case DW_OP_implicit_value
:
2000 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2001 switch (val2
->val_class
)
2003 case dw_val_class_const
:
2004 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
2006 case dw_val_class_vec
:
2008 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2009 unsigned int len
= val2
->v
.val_vec
.length
;
2013 if (elt_size
> sizeof (HOST_WIDE_INT
))
2018 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2021 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2022 "fp or vector constant word %u", i
);
2025 case dw_val_class_const_double
:
2027 unsigned HOST_WIDE_INT first
, second
;
2029 if (WORDS_BIG_ENDIAN
)
2031 first
= val2
->v
.val_double
.high
;
2032 second
= val2
->v
.val_double
.low
;
2036 first
= val2
->v
.val_double
.low
;
2037 second
= val2
->v
.val_double
.high
;
2039 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2041 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2045 case dw_val_class_wide_int
:
2048 int len
= get_full_len (*val2
->v
.val_wide
);
2049 if (WORDS_BIG_ENDIAN
)
2050 for (i
= len
- 1; i
>= 0; --i
)
2051 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2052 val2
->v
.val_wide
->elt (i
), NULL
);
2054 for (i
= 0; i
< len
; ++i
)
2055 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
2056 val2
->v
.val_wide
->elt (i
), NULL
);
2059 case dw_val_class_addr
:
2060 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
2061 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
2076 case DW_OP_implicit_value
:
2077 /* We currently don't make any attempt to make sure these are
2078 aligned properly like we do for the main unwind info, so
2079 don't support emitting things larger than a byte if we're
2080 only doing unwinding. */
2085 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2088 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2091 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2094 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2096 case DW_OP_plus_uconst
:
2097 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2131 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2135 unsigned r
= val1
->v
.val_unsigned
;
2136 if (for_eh_or_skip
>= 0)
2137 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2138 gcc_assert (size_of_uleb128 (r
)
2139 == size_of_uleb128 (val1
->v
.val_unsigned
));
2140 dw2_asm_output_data_uleb128 (r
, NULL
);
2144 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2148 unsigned r
= val1
->v
.val_unsigned
;
2149 if (for_eh_or_skip
>= 0)
2150 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2151 gcc_assert (size_of_uleb128 (r
)
2152 == size_of_uleb128 (val1
->v
.val_unsigned
));
2153 dw2_asm_output_data_uleb128 (r
, NULL
);
2154 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2158 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2160 case DW_OP_bit_piece
:
2161 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2162 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
2164 case DW_OP_deref_size
:
2165 case DW_OP_xderef_size
:
2166 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2172 if (targetm
.asm_out
.output_dwarf_dtprel
)
2174 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
2177 fputc ('\n', asm_out_file
);
2184 #ifdef DWARF2_DEBUGGING_INFO
2185 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2192 case DW_OP_GNU_addr_index
:
2193 case DW_OP_GNU_const_index
:
2194 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
2195 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
2196 "(index into .debug_addr)");
2202 unsigned long die_offset
2203 = get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2204 /* Make sure the offset has been computed and that we can encode it as
2206 gcc_assert (die_offset
> 0
2207 && die_offset
<= (loc
->dw_loc_opc
== DW_OP_call2
2210 dw2_asm_output_data ((loc
->dw_loc_opc
== DW_OP_call2
) ? 2 : 4,
2215 case DW_OP_implicit_pointer
:
2216 case DW_OP_GNU_implicit_pointer
:
2218 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2219 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2220 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2221 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2222 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2223 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2227 case DW_OP_entry_value
:
2228 case DW_OP_GNU_entry_value
:
2229 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
2230 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
2233 case DW_OP_const_type
:
2234 case DW_OP_GNU_const_type
:
2236 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
2238 dw2_asm_output_data_uleb128 (o
, NULL
);
2239 switch (val2
->val_class
)
2241 case dw_val_class_const
:
2242 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2243 dw2_asm_output_data (1, l
, NULL
);
2244 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
2246 case dw_val_class_vec
:
2248 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2249 unsigned int len
= val2
->v
.val_vec
.length
;
2254 dw2_asm_output_data (1, l
, NULL
);
2255 if (elt_size
> sizeof (HOST_WIDE_INT
))
2260 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2263 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2264 "fp or vector constant word %u", i
);
2267 case dw_val_class_const_double
:
2269 unsigned HOST_WIDE_INT first
, second
;
2270 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2272 dw2_asm_output_data (1, 2 * l
, NULL
);
2273 if (WORDS_BIG_ENDIAN
)
2275 first
= val2
->v
.val_double
.high
;
2276 second
= val2
->v
.val_double
.low
;
2280 first
= val2
->v
.val_double
.low
;
2281 second
= val2
->v
.val_double
.high
;
2283 dw2_asm_output_data (l
, first
, NULL
);
2284 dw2_asm_output_data (l
, second
, NULL
);
2287 case dw_val_class_wide_int
:
2290 int len
= get_full_len (*val2
->v
.val_wide
);
2291 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2293 dw2_asm_output_data (1, len
* l
, NULL
);
2294 if (WORDS_BIG_ENDIAN
)
2295 for (i
= len
- 1; i
>= 0; --i
)
2296 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2298 for (i
= 0; i
< len
; ++i
)
2299 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2307 case DW_OP_regval_type
:
2308 case DW_OP_GNU_regval_type
:
2310 unsigned r
= val1
->v
.val_unsigned
;
2311 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2313 if (for_eh_or_skip
>= 0)
2315 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2316 gcc_assert (size_of_uleb128 (r
)
2317 == size_of_uleb128 (val1
->v
.val_unsigned
));
2319 dw2_asm_output_data_uleb128 (r
, NULL
);
2320 dw2_asm_output_data_uleb128 (o
, NULL
);
2323 case DW_OP_deref_type
:
2324 case DW_OP_GNU_deref_type
:
2326 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2328 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2329 dw2_asm_output_data_uleb128 (o
, NULL
);
2333 case DW_OP_reinterpret
:
2334 case DW_OP_GNU_convert
:
2335 case DW_OP_GNU_reinterpret
:
2336 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2337 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2340 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2342 dw2_asm_output_data_uleb128 (o
, NULL
);
2346 case DW_OP_GNU_parameter_ref
:
2349 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2350 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2351 dw2_asm_output_data (4, o
, NULL
);
2356 /* Other codes have no operands. */
2361 /* Output a sequence of location operations.
2362 The for_eh_or_skip parameter controls whether register numbers are
2363 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2364 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2365 info). This should be suppressed for the cases that have not been converted
2366 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2369 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2371 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2373 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2374 /* Output the opcode. */
2375 if (for_eh_or_skip
>= 0
2376 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2378 unsigned r
= (opc
- DW_OP_breg0
);
2379 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2380 gcc_assert (r
<= 31);
2381 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2383 else if (for_eh_or_skip
>= 0
2384 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2386 unsigned r
= (opc
- DW_OP_reg0
);
2387 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2388 gcc_assert (r
<= 31);
2389 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2392 dw2_asm_output_data (1, opc
,
2393 "%s", dwarf_stack_op_name (opc
));
2395 /* Output the operand(s) (if any). */
2396 output_loc_operands (loc
, for_eh_or_skip
);
2400 /* Output location description stack opcode's operands (if any).
2401 The output is single bytes on a line, suitable for .cfi_escape. */
2404 output_loc_operands_raw (dw_loc_descr_ref loc
)
2406 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2407 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2409 switch (loc
->dw_loc_opc
)
2412 case DW_OP_GNU_addr_index
:
2413 case DW_OP_GNU_const_index
:
2414 case DW_OP_implicit_value
:
2415 /* We cannot output addresses in .cfi_escape, only bytes. */
2421 case DW_OP_deref_size
:
2422 case DW_OP_xderef_size
:
2423 fputc (',', asm_out_file
);
2424 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2429 fputc (',', asm_out_file
);
2430 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2435 fputc (',', asm_out_file
);
2436 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2441 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2442 fputc (',', asm_out_file
);
2443 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2451 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2452 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2454 fputc (',', asm_out_file
);
2455 dw2_asm_output_data_raw (2, offset
);
2461 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2462 gcc_assert (size_of_uleb128 (r
)
2463 == size_of_uleb128 (val1
->v
.val_unsigned
));
2464 fputc (',', asm_out_file
);
2465 dw2_asm_output_data_uleb128_raw (r
);
2470 case DW_OP_plus_uconst
:
2472 fputc (',', asm_out_file
);
2473 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2476 case DW_OP_bit_piece
:
2477 fputc (',', asm_out_file
);
2478 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2479 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2516 fputc (',', asm_out_file
);
2517 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2522 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2523 gcc_assert (size_of_uleb128 (r
)
2524 == size_of_uleb128 (val1
->v
.val_unsigned
));
2525 fputc (',', asm_out_file
);
2526 dw2_asm_output_data_uleb128_raw (r
);
2527 fputc (',', asm_out_file
);
2528 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2532 case DW_OP_implicit_pointer
:
2533 case DW_OP_entry_value
:
2534 case DW_OP_const_type
:
2535 case DW_OP_regval_type
:
2536 case DW_OP_deref_type
:
2538 case DW_OP_reinterpret
:
2539 case DW_OP_GNU_implicit_pointer
:
2540 case DW_OP_GNU_entry_value
:
2541 case DW_OP_GNU_const_type
:
2542 case DW_OP_GNU_regval_type
:
2543 case DW_OP_GNU_deref_type
:
2544 case DW_OP_GNU_convert
:
2545 case DW_OP_GNU_reinterpret
:
2546 case DW_OP_GNU_parameter_ref
:
2551 /* Other codes have no operands. */
2557 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2561 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2562 /* Output the opcode. */
2563 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2565 unsigned r
= (opc
- DW_OP_breg0
);
2566 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2567 gcc_assert (r
<= 31);
2568 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2570 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2572 unsigned r
= (opc
- DW_OP_reg0
);
2573 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2574 gcc_assert (r
<= 31);
2575 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2577 /* Output the opcode. */
2578 fprintf (asm_out_file
, "%#x", opc
);
2579 output_loc_operands_raw (loc
);
2581 if (!loc
->dw_loc_next
)
2583 loc
= loc
->dw_loc_next
;
2585 fputc (',', asm_out_file
);
2589 /* This function builds a dwarf location descriptor sequence from a
2590 dw_cfa_location, adding the given OFFSET to the result of the
2593 struct dw_loc_descr_node
*
2594 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2596 struct dw_loc_descr_node
*head
, *tmp
;
2598 offset
+= cfa
->offset
;
2602 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2603 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2604 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2605 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2606 add_loc_descr (&head
, tmp
);
2609 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2610 add_loc_descr (&head
, tmp
);
2614 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2619 /* This function builds a dwarf location descriptor sequence for
2620 the address at OFFSET from the CFA when stack is aligned to
2623 struct dw_loc_descr_node
*
2624 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2625 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2627 struct dw_loc_descr_node
*head
;
2628 unsigned int dwarf_fp
2629 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2631 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2632 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2634 head
= new_reg_loc_descr (dwarf_fp
, 0);
2635 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2636 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2637 loc_descr_plus_const (&head
, offset
);
2640 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2644 /* And now, the support for symbolic debugging information. */
2646 /* .debug_str support. */
2648 static void dwarf2out_init (const char *);
2649 static void dwarf2out_finish (const char *);
2650 static void dwarf2out_early_finish (const char *);
2651 static void dwarf2out_assembly_start (void);
2652 static void dwarf2out_define (unsigned int, const char *);
2653 static void dwarf2out_undef (unsigned int, const char *);
2654 static void dwarf2out_start_source_file (unsigned, const char *);
2655 static void dwarf2out_end_source_file (unsigned);
2656 static void dwarf2out_function_decl (tree
);
2657 static void dwarf2out_begin_block (unsigned, unsigned);
2658 static void dwarf2out_end_block (unsigned, unsigned);
2659 static bool dwarf2out_ignore_block (const_tree
);
2660 static void dwarf2out_early_global_decl (tree
);
2661 static void dwarf2out_late_global_decl (tree
);
2662 static void dwarf2out_type_decl (tree
, int);
2663 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2664 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2666 static void dwarf2out_abstract_function (tree
);
2667 static void dwarf2out_var_location (rtx_insn
*);
2668 static void dwarf2out_size_function (tree
);
2669 static void dwarf2out_begin_function (tree
);
2670 static void dwarf2out_end_function (unsigned int);
2671 static void dwarf2out_register_main_translation_unit (tree unit
);
2672 static void dwarf2out_set_name (tree
, tree
);
2674 /* The debug hooks structure. */
2676 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2680 dwarf2out_early_finish
,
2681 dwarf2out_assembly_start
,
2684 dwarf2out_start_source_file
,
2685 dwarf2out_end_source_file
,
2686 dwarf2out_begin_block
,
2687 dwarf2out_end_block
,
2688 dwarf2out_ignore_block
,
2689 dwarf2out_source_line
,
2690 dwarf2out_begin_prologue
,
2691 #if VMS_DEBUGGING_INFO
2692 dwarf2out_vms_end_prologue
,
2693 dwarf2out_vms_begin_epilogue
,
2695 debug_nothing_int_charstar
,
2696 debug_nothing_int_charstar
,
2698 dwarf2out_end_epilogue
,
2699 dwarf2out_begin_function
,
2700 dwarf2out_end_function
, /* end_function */
2701 dwarf2out_register_main_translation_unit
,
2702 dwarf2out_function_decl
, /* function_decl */
2703 dwarf2out_early_global_decl
,
2704 dwarf2out_late_global_decl
,
2705 dwarf2out_type_decl
, /* type_decl */
2706 dwarf2out_imported_module_or_decl
,
2707 debug_nothing_tree
, /* deferred_inline_function */
2708 /* The DWARF 2 backend tries to reduce debugging bloat by not
2709 emitting the abstract description of inline functions until
2710 something tries to reference them. */
2711 dwarf2out_abstract_function
, /* outlining_inline_function */
2712 debug_nothing_rtx_code_label
, /* label */
2713 debug_nothing_int
, /* handle_pch */
2714 dwarf2out_var_location
,
2715 dwarf2out_size_function
, /* size_function */
2716 dwarf2out_switch_text_section
,
2718 1, /* start_end_main_source_file */
2719 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2722 const struct gcc_debug_hooks dwarf2_lineno_debug_hooks
=
2725 debug_nothing_charstar
,
2726 debug_nothing_charstar
,
2727 dwarf2out_assembly_start
,
2728 debug_nothing_int_charstar
,
2729 debug_nothing_int_charstar
,
2730 debug_nothing_int_charstar
,
2732 debug_nothing_int_int
, /* begin_block */
2733 debug_nothing_int_int
, /* end_block */
2734 debug_true_const_tree
, /* ignore_block */
2735 dwarf2out_source_line
, /* source_line */
2736 debug_nothing_int_charstar
, /* begin_prologue */
2737 debug_nothing_int_charstar
, /* end_prologue */
2738 debug_nothing_int_charstar
, /* begin_epilogue */
2739 debug_nothing_int_charstar
, /* end_epilogue */
2740 debug_nothing_tree
, /* begin_function */
2741 debug_nothing_int
, /* end_function */
2742 debug_nothing_tree
, /* register_main_translation_unit */
2743 debug_nothing_tree
, /* function_decl */
2744 debug_nothing_tree
, /* early_global_decl */
2745 debug_nothing_tree
, /* late_global_decl */
2746 debug_nothing_tree_int
, /* type_decl */
2747 debug_nothing_tree_tree_tree_bool
, /* imported_module_or_decl */
2748 debug_nothing_tree
, /* deferred_inline_function */
2749 debug_nothing_tree
, /* outlining_inline_function */
2750 debug_nothing_rtx_code_label
, /* label */
2751 debug_nothing_int
, /* handle_pch */
2752 debug_nothing_rtx_insn
, /* var_location */
2753 debug_nothing_tree
, /* size_function */
2754 debug_nothing_void
, /* switch_text_section */
2755 debug_nothing_tree_tree
, /* set_name */
2756 0, /* start_end_main_source_file */
2757 TYPE_SYMTAB_IS_ADDRESS
/* tree_type_symtab_field */
2760 /* NOTE: In the comments in this file, many references are made to
2761 "Debugging Information Entries". This term is abbreviated as `DIE'
2762 throughout the remainder of this file. */
2764 /* An internal representation of the DWARF output is built, and then
2765 walked to generate the DWARF debugging info. The walk of the internal
2766 representation is done after the entire program has been compiled.
2767 The types below are used to describe the internal representation. */
2769 /* Whether to put type DIEs into their own section .debug_types instead
2770 of making them part of the .debug_info section. Only supported for
2771 Dwarf V4 or higher and the user didn't disable them through
2772 -fno-debug-types-section. It is more efficient to put them in a
2773 separate comdat sections since the linker will then be able to
2774 remove duplicates. But not all tools support .debug_types sections
2775 yet. For Dwarf V5 or higher .debug_types doesn't exist any more,
2776 it is DW_UT_type unit type in .debug_info section. */
2778 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2780 /* Various DIE's use offsets relative to the beginning of the
2781 .debug_info section to refer to each other. */
2783 typedef long int dw_offset
;
2785 struct comdat_type_node
;
2787 /* The entries in the line_info table more-or-less mirror the opcodes
2788 that are used in the real dwarf line table. Arrays of these entries
2789 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2792 enum dw_line_info_opcode
{
2793 /* Emit DW_LNE_set_address; the operand is the label index. */
2796 /* Emit a row to the matrix with the given line. This may be done
2797 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2801 /* Emit a DW_LNS_set_file. */
2804 /* Emit a DW_LNS_set_column. */
2807 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2810 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2811 LI_set_prologue_end
,
2812 LI_set_epilogue_begin
,
2814 /* Emit a DW_LNE_set_discriminator. */
2815 LI_set_discriminator
2818 typedef struct GTY(()) dw_line_info_struct
{
2819 enum dw_line_info_opcode opcode
;
2821 } dw_line_info_entry
;
2824 struct GTY(()) dw_line_info_table
{
2825 /* The label that marks the end of this section. */
2826 const char *end_label
;
2828 /* The values for the last row of the matrix, as collected in the table.
2829 These are used to minimize the changes to the next row. */
2830 unsigned int file_num
;
2831 unsigned int line_num
;
2832 unsigned int column_num
;
2837 vec
<dw_line_info_entry
, va_gc
> *entries
;
2841 /* Each DIE attribute has a field specifying the attribute kind,
2842 a link to the next attribute in the chain, and an attribute value.
2843 Attributes are typically linked below the DIE they modify. */
2845 typedef struct GTY(()) dw_attr_struct
{
2846 enum dwarf_attribute dw_attr
;
2847 dw_val_node dw_attr_val
;
2852 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2853 The children of each node form a circular list linked by
2854 die_sib. die_child points to the node *before* the "first" child node. */
2856 typedef struct GTY((chain_circular ("%h.die_sib"), for_user
)) die_struct
{
2857 union die_symbol_or_type_node
2859 const char * GTY ((tag ("0"))) die_symbol
;
2860 comdat_type_node
*GTY ((tag ("1"))) die_type_node
;
2862 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2863 vec
<dw_attr_node
, va_gc
> *die_attr
;
2864 dw_die_ref die_parent
;
2865 dw_die_ref die_child
;
2867 dw_die_ref die_definition
; /* ref from a specification to its definition */
2868 dw_offset die_offset
;
2869 unsigned long die_abbrev
;
2871 unsigned int decl_id
;
2872 enum dwarf_tag die_tag
;
2873 /* Die is used and must not be pruned as unused. */
2874 BOOL_BITFIELD die_perennial_p
: 1;
2875 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2876 /* Whether this DIE was removed from the DIE tree, for example via
2877 prune_unused_types. We don't consider those present from the
2878 DIE lookup routines. */
2879 BOOL_BITFIELD removed
: 1;
2880 /* Lots of spare bits. */
2884 /* Set to TRUE while dwarf2out_early_global_decl is running. */
2885 static bool early_dwarf
;
2886 static bool early_dwarf_finished
;
2887 struct set_early_dwarf
{
2889 set_early_dwarf () : saved(early_dwarf
)
2891 gcc_assert (! early_dwarf_finished
);
2894 ~set_early_dwarf () { early_dwarf
= saved
; }
2897 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2898 #define FOR_EACH_CHILD(die, c, expr) do { \
2899 c = die->die_child; \
2903 } while (c != die->die_child); \
2906 /* The pubname structure */
2908 typedef struct GTY(()) pubname_struct
{
2915 struct GTY(()) dw_ranges
{
2917 /* If this is positive, it's a block number, otherwise it's a
2918 bitwise-negated index into dw_ranges_by_label. */
2920 /* Index for the range list for DW_FORM_rnglistx. */
2921 unsigned int idx
: 31;
2922 /* True if this range might be possibly in a different section
2923 from previous entry. */
2924 unsigned int maybe_new_sec
: 1;
2927 /* A structure to hold a macinfo entry. */
2929 typedef struct GTY(()) macinfo_struct
{
2931 unsigned HOST_WIDE_INT lineno
;
2937 struct GTY(()) dw_ranges_by_label
{
2942 /* The comdat type node structure. */
2943 struct GTY(()) comdat_type_node
2945 dw_die_ref root_die
;
2946 dw_die_ref type_die
;
2947 dw_die_ref skeleton_die
;
2948 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2949 comdat_type_node
*next
;
2952 /* A list of DIEs for which we can't determine ancestry (parent_die
2953 field) just yet. Later in dwarf2out_finish we will fill in the
2955 typedef struct GTY(()) limbo_die_struct
{
2957 /* The tree for which this DIE was created. We use this to
2958 determine ancestry later. */
2960 struct limbo_die_struct
*next
;
2964 typedef struct skeleton_chain_struct
2968 struct skeleton_chain_struct
*parent
;
2970 skeleton_chain_node
;
2972 /* Define a macro which returns nonzero for a TYPE_DECL which was
2973 implicitly generated for a type.
2975 Note that, unlike the C front-end (which generates a NULL named
2976 TYPE_DECL node for each complete tagged type, each array type,
2977 and each function type node created) the C++ front-end generates
2978 a _named_ TYPE_DECL node for each tagged type node created.
2979 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2980 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2981 front-end, but for each type, tagged or not. */
2983 #define TYPE_DECL_IS_STUB(decl) \
2984 (DECL_NAME (decl) == NULL_TREE \
2985 || (DECL_ARTIFICIAL (decl) \
2986 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2987 /* This is necessary for stub decls that \
2988 appear in nested inline functions. */ \
2989 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2990 && (decl_ultimate_origin (decl) \
2991 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2993 /* Information concerning the compilation unit's programming
2994 language, and compiler version. */
2996 /* Fixed size portion of the DWARF compilation unit header. */
2997 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2998 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE \
2999 + (dwarf_version >= 5 ? 4 : 3))
3001 /* Fixed size portion of the DWARF comdat type unit header. */
3002 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
3003 (DWARF_COMPILE_UNIT_HEADER_SIZE \
3004 + DWARF_TYPE_SIGNATURE_SIZE + DWARF_OFFSET_SIZE)
3006 /* Fixed size portion of the DWARF skeleton compilation unit header. */
3007 #define DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE \
3008 (DWARF_COMPILE_UNIT_HEADER_SIZE + (dwarf_version >= 5 ? 8 : 0))
3010 /* Fixed size portion of public names info. */
3011 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3013 /* Fixed size portion of the address range info. */
3014 #define DWARF_ARANGES_HEADER_SIZE \
3015 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3016 DWARF2_ADDR_SIZE * 2) \
3017 - DWARF_INITIAL_LENGTH_SIZE)
3019 /* Size of padding portion in the address range info. It must be
3020 aligned to twice the pointer size. */
3021 #define DWARF_ARANGES_PAD_SIZE \
3022 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3023 DWARF2_ADDR_SIZE * 2) \
3024 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3026 /* Use assembler line directives if available. */
3027 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3028 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3029 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3031 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3035 /* Minimum line offset in a special line info. opcode.
3036 This value was chosen to give a reasonable range of values. */
3037 #define DWARF_LINE_BASE -10
3039 /* First special line opcode - leave room for the standard opcodes. */
3040 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
3042 /* Range of line offsets in a special line info. opcode. */
3043 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3045 /* Flag that indicates the initial value of the is_stmt_start flag.
3046 In the present implementation, we do not mark any lines as
3047 the beginning of a source statement, because that information
3048 is not made available by the GCC front-end. */
3049 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3051 /* Maximum number of operations per instruction bundle. */
3052 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
3053 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
3056 /* This location is used by calc_die_sizes() to keep track
3057 the offset of each DIE within the .debug_info section. */
3058 static unsigned long next_die_offset
;
3060 /* Record the root of the DIE's built for the current compilation unit. */
3061 static GTY(()) dw_die_ref single_comp_unit_die
;
3063 /* A list of type DIEs that have been separated into comdat sections. */
3064 static GTY(()) comdat_type_node
*comdat_type_list
;
3066 /* A list of CU DIEs that have been separated. */
3067 static GTY(()) limbo_die_node
*cu_die_list
;
3069 /* A list of DIEs with a NULL parent waiting to be relocated. */
3070 static GTY(()) limbo_die_node
*limbo_die_list
;
3072 /* A list of DIEs for which we may have to generate
3073 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
3074 static GTY(()) limbo_die_node
*deferred_asm_name
;
3076 struct dwarf_file_hasher
: ggc_ptr_hash
<dwarf_file_data
>
3078 typedef const char *compare_type
;
3080 static hashval_t
hash (dwarf_file_data
*);
3081 static bool equal (dwarf_file_data
*, const char *);
3084 /* Filenames referenced by this compilation unit. */
3085 static GTY(()) hash_table
<dwarf_file_hasher
> *file_table
;
3087 struct decl_die_hasher
: ggc_ptr_hash
<die_node
>
3089 typedef tree compare_type
;
3091 static hashval_t
hash (die_node
*);
3092 static bool equal (die_node
*, tree
);
3094 /* A hash table of references to DIE's that describe declarations.
3095 The key is a DECL_UID() which is a unique number identifying each decl. */
3096 static GTY (()) hash_table
<decl_die_hasher
> *decl_die_table
;
3098 struct block_die_hasher
: ggc_ptr_hash
<die_struct
>
3100 static hashval_t
hash (die_struct
*);
3101 static bool equal (die_struct
*, die_struct
*);
3104 /* A hash table of references to DIE's that describe COMMON blocks.
3105 The key is DECL_UID() ^ die_parent. */
3106 static GTY (()) hash_table
<block_die_hasher
> *common_block_die_table
;
3108 typedef struct GTY(()) die_arg_entry_struct
{
3114 /* Node of the variable location list. */
3115 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
3116 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
3117 EXPR_LIST chain. For small bitsizes, bitsize is encoded
3118 in mode of the EXPR_LIST node and first EXPR_LIST operand
3119 is either NOTE_INSN_VAR_LOCATION for a piece with a known
3120 location or NULL for padding. For larger bitsizes,
3121 mode is 0 and first operand is a CONCAT with bitsize
3122 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
3123 NULL as second operand. */
3125 const char * GTY (()) label
;
3126 struct var_loc_node
* GTY (()) next
;
3129 /* Variable location list. */
3130 struct GTY ((for_user
)) var_loc_list_def
{
3131 struct var_loc_node
* GTY (()) first
;
3133 /* Pointer to the last but one or last element of the
3134 chained list. If the list is empty, both first and
3135 last are NULL, if the list contains just one node
3136 or the last node certainly is not redundant, it points
3137 to the last node, otherwise points to the last but one.
3138 Do not mark it for GC because it is marked through the chain. */
3139 struct var_loc_node
* GTY ((skip ("%h"))) last
;
3141 /* Pointer to the last element before section switch,
3142 if NULL, either sections weren't switched or first
3143 is after section switch. */
3144 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
3146 /* DECL_UID of the variable decl. */
3147 unsigned int decl_id
;
3149 typedef struct var_loc_list_def var_loc_list
;
3151 /* Call argument location list. */
3152 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
3153 rtx
GTY (()) call_arg_loc_note
;
3154 const char * GTY (()) label
;
3155 tree
GTY (()) block
;
3157 rtx
GTY (()) symbol_ref
;
3158 struct call_arg_loc_node
* GTY (()) next
;
3162 struct decl_loc_hasher
: ggc_ptr_hash
<var_loc_list
>
3164 typedef const_tree compare_type
;
3166 static hashval_t
hash (var_loc_list
*);
3167 static bool equal (var_loc_list
*, const_tree
);
3170 /* Table of decl location linked lists. */
3171 static GTY (()) hash_table
<decl_loc_hasher
> *decl_loc_table
;
3173 /* Head and tail of call_arg_loc chain. */
3174 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
3175 static struct call_arg_loc_node
*call_arg_loc_last
;
3177 /* Number of call sites in the current function. */
3178 static int call_site_count
= -1;
3179 /* Number of tail call sites in the current function. */
3180 static int tail_call_site_count
= -1;
3182 /* A cached location list. */
3183 struct GTY ((for_user
)) cached_dw_loc_list_def
{
3184 /* The DECL_UID of the decl that this entry describes. */
3185 unsigned int decl_id
;
3187 /* The cached location list. */
3188 dw_loc_list_ref loc_list
;
3190 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
3192 struct dw_loc_list_hasher
: ggc_ptr_hash
<cached_dw_loc_list
>
3195 typedef const_tree compare_type
;
3197 static hashval_t
hash (cached_dw_loc_list
*);
3198 static bool equal (cached_dw_loc_list
*, const_tree
);
3201 /* Table of cached location lists. */
3202 static GTY (()) hash_table
<dw_loc_list_hasher
> *cached_dw_loc_list_table
;
3204 /* A vector of references to DIE's that are uniquely identified by their tag,
3205 presence/absence of children DIE's, and list of attribute/value pairs. */
3206 static GTY(()) vec
<dw_die_ref
, va_gc
> *abbrev_die_table
;
3208 /* A hash map to remember the stack usage for DWARF procedures. The value
3209 stored is the stack size difference between before the DWARF procedure
3210 invokation and after it returned. In other words, for a DWARF procedure
3211 that consumes N stack slots and that pushes M ones, this stores M - N. */
3212 static hash_map
<dw_die_ref
, int> *dwarf_proc_stack_usage_map
;
3214 /* A global counter for generating labels for line number data. */
3215 static unsigned int line_info_label_num
;
3217 /* The current table to which we should emit line number information
3218 for the current function. This will be set up at the beginning of
3219 assembly for the function. */
3220 static GTY(()) dw_line_info_table
*cur_line_info_table
;
3222 /* The two default tables of line number info. */
3223 static GTY(()) dw_line_info_table
*text_section_line_info
;
3224 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
3226 /* The set of all non-default tables of line number info. */
3227 static GTY(()) vec
<dw_line_info_table
*, va_gc
> *separate_line_info
;
3229 /* A flag to tell pubnames/types export if there is an info section to
3231 static bool info_section_emitted
;
3233 /* A pointer to the base of a table that contains a list of publicly
3234 accessible names. */
3235 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
3237 /* A pointer to the base of a table that contains a list of publicly
3238 accessible types. */
3239 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
3241 /* A pointer to the base of a table that contains a list of macro
3242 defines/undefines (and file start/end markers). */
3243 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
3245 /* True if .debug_macinfo or .debug_macros section is going to be
3247 #define have_macinfo \
3248 ((!XCOFF_DEBUGGING_INFO || HAVE_XCOFF_DWARF_EXTRAS) \
3249 && debug_info_level >= DINFO_LEVEL_VERBOSE \
3250 && !macinfo_table->is_empty ())
3252 /* Vector of dies for which we should generate .debug_ranges info. */
3253 static GTY (()) vec
<dw_ranges
, va_gc
> *ranges_table
;
3255 /* Vector of pairs of labels referenced in ranges_table. */
3256 static GTY (()) vec
<dw_ranges_by_label
, va_gc
> *ranges_by_label
;
3258 /* Whether we have location lists that need outputting */
3259 static GTY(()) bool have_location_lists
;
3261 /* Unique label counter. */
3262 static GTY(()) unsigned int loclabel_num
;
3264 /* Unique label counter for point-of-call tables. */
3265 static GTY(()) unsigned int poc_label_num
;
3267 /* The last file entry emitted by maybe_emit_file(). */
3268 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
3270 /* Number of internal labels generated by gen_internal_sym(). */
3271 static GTY(()) int label_num
;
3273 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
3275 /* Instances of generic types for which we need to generate debug
3276 info that describe their generic parameters and arguments. That
3277 generation needs to happen once all types are properly laid out so
3278 we do it at the end of compilation. */
3279 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
3281 /* Offset from the "steady-state frame pointer" to the frame base,
3282 within the current function. */
3283 static HOST_WIDE_INT frame_pointer_fb_offset
;
3284 static bool frame_pointer_fb_offset_valid
;
3286 static vec
<dw_die_ref
> base_types
;
3288 /* Pointer to vector of DW_TAG_string_type DIEs that need finalization
3289 once all arguments are parsed. */
3290 static vec
<dw_die_ref
> *string_types
;
3292 /* Flags to represent a set of attribute classes for attributes that represent
3293 a scalar value (bounds, pointers, ...). */
3296 dw_scalar_form_constant
= 0x01,
3297 dw_scalar_form_exprloc
= 0x02,
3298 dw_scalar_form_reference
= 0x04
3301 /* Forward declarations for functions defined in this file. */
3303 static int is_pseudo_reg (const_rtx
);
3304 static tree
type_main_variant (tree
);
3305 static int is_tagged_type (const_tree
);
3306 static const char *dwarf_tag_name (unsigned);
3307 static const char *dwarf_attr_name (unsigned);
3308 static const char *dwarf_form_name (unsigned);
3309 static tree
decl_ultimate_origin (const_tree
);
3310 static tree
decl_class_context (tree
);
3311 static void add_dwarf_attr (dw_die_ref
, dw_attr_node
*);
3312 static inline enum dw_val_class
AT_class (dw_attr_node
*);
3313 static inline unsigned int AT_index (dw_attr_node
*);
3314 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3315 static inline unsigned AT_flag (dw_attr_node
*);
3316 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3317 static inline HOST_WIDE_INT
AT_int (dw_attr_node
*);
3318 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3319 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_node
*);
3320 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
3321 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
3322 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3323 unsigned int, unsigned char *);
3324 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
3325 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3326 static inline const char *AT_string (dw_attr_node
*);
3327 static enum dwarf_form
AT_string_form (dw_attr_node
*);
3328 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3329 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3330 static inline dw_die_ref
AT_ref (dw_attr_node
*);
3331 static inline int AT_ref_external (dw_attr_node
*);
3332 static inline void set_AT_ref_external (dw_attr_node
*, int);
3333 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3334 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3335 static inline dw_loc_descr_ref
AT_loc (dw_attr_node
*);
3336 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3338 static inline dw_loc_list_ref
AT_loc_list (dw_attr_node
*);
3339 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
3340 static void remove_addr_table_entry (addr_table_entry
*);
3341 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
3342 static inline rtx
AT_addr (dw_attr_node
*);
3343 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3344 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3345 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3346 static void add_AT_loclistsptr (dw_die_ref
, enum dwarf_attribute
,
3348 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3349 unsigned HOST_WIDE_INT
);
3350 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3351 unsigned long, bool);
3352 static inline const char *AT_lbl (dw_attr_node
*);
3353 static dw_attr_node
*get_AT (dw_die_ref
, enum dwarf_attribute
);
3354 static const char *get_AT_low_pc (dw_die_ref
);
3355 static const char *get_AT_hi_pc (dw_die_ref
);
3356 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3357 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3358 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3359 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3360 static bool is_cxx (void);
3361 static bool is_cxx (const_tree
);
3362 static bool is_fortran (void);
3363 static bool is_ada (void);
3364 static bool remove_AT (dw_die_ref
, enum dwarf_attribute
);
3365 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3366 static void add_child_die (dw_die_ref
, dw_die_ref
);
3367 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3368 static dw_die_ref
lookup_type_die (tree
);
3369 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3370 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3371 static void equate_type_number_to_die (tree
, dw_die_ref
);
3372 static dw_die_ref
lookup_decl_die (tree
);
3373 static var_loc_list
*lookup_decl_loc (const_tree
);
3374 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3375 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3376 static void print_spaces (FILE *);
3377 static void print_die (dw_die_ref
, FILE *);
3378 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3379 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3380 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3381 static void attr_checksum (dw_attr_node
*, struct md5_ctx
*, int *);
3382 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3383 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3384 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3385 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3386 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_node
*,
3387 struct md5_ctx
*, int *);
3388 struct checksum_attributes
;
3389 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3390 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3391 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3392 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3393 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3394 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3395 static int same_attr_p (dw_attr_node
*, dw_attr_node
*, int *);
3396 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3397 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3398 static void compute_section_prefix (dw_die_ref
);
3399 static int is_type_die (dw_die_ref
);
3400 static int is_comdat_die (dw_die_ref
);
3401 static int is_symbol_die (dw_die_ref
);
3402 static inline bool is_template_instantiation (dw_die_ref
);
3403 static void assign_symbol_names (dw_die_ref
);
3404 static void break_out_includes (dw_die_ref
);
3405 static int is_declaration_die (dw_die_ref
);
3406 static int should_move_die_to_comdat (dw_die_ref
);
3407 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3408 static dw_die_ref
clone_die (dw_die_ref
);
3409 static dw_die_ref
clone_tree (dw_die_ref
);
3410 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3411 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3412 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3413 static dw_die_ref
generate_skeleton (dw_die_ref
);
3414 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3417 static void break_out_comdat_types (dw_die_ref
);
3418 static void copy_decls_for_unworthy_types (dw_die_ref
);
3420 static void add_sibling_attributes (dw_die_ref
);
3421 static void output_location_lists (dw_die_ref
);
3422 static int constant_size (unsigned HOST_WIDE_INT
);
3423 static unsigned long size_of_die (dw_die_ref
);
3424 static void calc_die_sizes (dw_die_ref
);
3425 static void calc_base_type_die_sizes (void);
3426 static void mark_dies (dw_die_ref
);
3427 static void unmark_dies (dw_die_ref
);
3428 static void unmark_all_dies (dw_die_ref
);
3429 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3430 static unsigned long size_of_aranges (void);
3431 static enum dwarf_form
value_format (dw_attr_node
*);
3432 static void output_value_format (dw_attr_node
*);
3433 static void output_abbrev_section (void);
3434 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3435 static void output_die_symbol (dw_die_ref
);
3436 static void output_die (dw_die_ref
);
3437 static void output_compilation_unit_header (enum dwarf_unit_type
);
3438 static void output_comp_unit (dw_die_ref
, int, const unsigned char *);
3439 static void output_comdat_type_unit (comdat_type_node
*);
3440 static const char *dwarf2_name (tree
, int);
3441 static void add_pubname (tree
, dw_die_ref
);
3442 static void add_enumerator_pubname (const char *, dw_die_ref
);
3443 static void add_pubname_string (const char *, dw_die_ref
);
3444 static void add_pubtype (tree
, dw_die_ref
);
3445 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3446 static void output_aranges (void);
3447 static unsigned int add_ranges (const_tree
, bool = false);
3448 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3450 static void output_ranges (void);
3451 static dw_line_info_table
*new_line_info_table (void);
3452 static void output_line_info (bool);
3453 static void output_file_names (void);
3454 static dw_die_ref
base_type_die (tree
, bool);
3455 static int is_base_type (tree
);
3456 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, tree
, dw_die_ref
);
3457 static int decl_quals (const_tree
);
3458 static dw_die_ref
modified_type_die (tree
, int, bool, dw_die_ref
);
3459 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3460 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3461 static int type_is_enum (const_tree
);
3462 static unsigned int dbx_reg_number (const_rtx
);
3463 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3464 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3465 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3466 enum var_init_status
);
3467 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3468 enum var_init_status
);
3469 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3470 enum var_init_status
);
3471 static int is_based_loc (const_rtx
);
3472 static bool resolve_one_addr (rtx
*);
3473 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3474 enum var_init_status
);
3475 static dw_loc_descr_ref
loc_descriptor (rtx
, machine_mode mode
,
3476 enum var_init_status
);
3477 struct loc_descr_context
;
3478 static void add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
);
3479 static void add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
);
3480 static dw_loc_list_ref
loc_list_from_tree (tree
, int,
3481 struct loc_descr_context
*);
3482 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int,
3483 struct loc_descr_context
*);
3484 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3485 static tree
field_type (const_tree
);
3486 static unsigned int simple_type_align_in_bits (const_tree
);
3487 static unsigned int simple_decl_align_in_bits (const_tree
);
3488 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3490 static dw_loc_descr_ref
field_byte_offset (const_tree
, struct vlr_context
*,
3492 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3494 static void add_data_member_location_attribute (dw_die_ref
, tree
,
3495 struct vlr_context
*);
3496 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3497 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3498 static void insert_wide_int (const wide_int
&, unsigned char *, int);
3499 static void insert_float (const_rtx
, unsigned char *);
3500 static rtx
rtl_for_decl_location (tree
);
3501 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool);
3502 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3503 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3504 static void add_name_attribute (dw_die_ref
, const char *);
3505 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3506 static void add_comp_dir_attribute (dw_die_ref
);
3507 static void add_scalar_info (dw_die_ref
, enum dwarf_attribute
, tree
, int,
3508 struct loc_descr_context
*);
3509 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
,
3510 struct loc_descr_context
*);
3511 static void add_subscript_info (dw_die_ref
, tree
, bool);
3512 static void add_byte_size_attribute (dw_die_ref
, tree
);
3513 static inline void add_bit_offset_attribute (dw_die_ref
, tree
,
3514 struct vlr_context
*);
3515 static void add_bit_size_attribute (dw_die_ref
, tree
);
3516 static void add_prototyped_attribute (dw_die_ref
, tree
);
3517 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3518 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3519 static void add_src_coords_attributes (dw_die_ref
, tree
);
3520 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
, bool = false);
3521 static void add_discr_value (dw_die_ref
, dw_discr_value
*);
3522 static void add_discr_list (dw_die_ref
, dw_discr_list_ref
);
3523 static inline dw_discr_list_ref
AT_discr_list (dw_attr_node
*);
3524 static void push_decl_scope (tree
);
3525 static void pop_decl_scope (void);
3526 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3527 static inline int local_scope_p (dw_die_ref
);
3528 static inline int class_scope_p (dw_die_ref
);
3529 static inline int class_or_namespace_scope_p (dw_die_ref
);
3530 static void add_type_attribute (dw_die_ref
, tree
, int, bool, dw_die_ref
);
3531 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3532 static const char *type_tag (const_tree
);
3533 static tree
member_declared_type (const_tree
);
3535 static const char *decl_start_label (tree
);
3537 static void gen_array_type_die (tree
, dw_die_ref
);
3538 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3540 static void gen_entry_point_die (tree
, dw_die_ref
);
3542 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3543 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3544 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3545 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3546 static void gen_formal_types_die (tree
, dw_die_ref
);
3547 static void gen_subprogram_die (tree
, dw_die_ref
);
3548 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3549 static void gen_const_die (tree
, dw_die_ref
);
3550 static void gen_label_die (tree
, dw_die_ref
);
3551 static void gen_lexical_block_die (tree
, dw_die_ref
);
3552 static void gen_inlined_subroutine_die (tree
, dw_die_ref
);
3553 static void gen_field_die (tree
, struct vlr_context
*, dw_die_ref
);
3554 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3555 static dw_die_ref
gen_compile_unit_die (const char *);
3556 static void gen_inheritance_die (tree
, tree
, tree
, dw_die_ref
);
3557 static void gen_member_die (tree
, dw_die_ref
);
3558 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3559 enum debug_info_usage
);
3560 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3561 static void gen_typedef_die (tree
, dw_die_ref
);
3562 static void gen_type_die (tree
, dw_die_ref
);
3563 static void gen_block_die (tree
, dw_die_ref
);
3564 static void decls_for_scope (tree
, dw_die_ref
);
3565 static bool is_naming_typedef_decl (const_tree
);
3566 static inline dw_die_ref
get_context_die (tree
);
3567 static void gen_namespace_die (tree
, dw_die_ref
);
3568 static dw_die_ref
gen_namelist_decl (tree
, dw_die_ref
, tree
);
3569 static dw_die_ref
gen_decl_die (tree
, tree
, struct vlr_context
*, dw_die_ref
);
3570 static dw_die_ref
force_decl_die (tree
);
3571 static dw_die_ref
force_type_die (tree
);
3572 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3573 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3574 static struct dwarf_file_data
* lookup_filename (const char *);
3575 static void retry_incomplete_types (void);
3576 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3577 static void gen_generic_params_dies (tree
);
3578 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3579 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3580 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3581 static int file_info_cmp (const void *, const void *);
3582 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3583 const char *, const char *);
3584 static void output_loc_list (dw_loc_list_ref
);
3585 static char *gen_internal_sym (const char *);
3586 static bool want_pubnames (void);
3588 static void prune_unmark_dies (dw_die_ref
);
3589 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3590 static void prune_unused_types_mark (dw_die_ref
, int);
3591 static void prune_unused_types_walk (dw_die_ref
);
3592 static void prune_unused_types_walk_attribs (dw_die_ref
);
3593 static void prune_unused_types_prune (dw_die_ref
);
3594 static void prune_unused_types (void);
3595 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3596 static inline const char *AT_vms_delta1 (dw_attr_node
*);
3597 static inline const char *AT_vms_delta2 (dw_attr_node
*);
3598 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3599 const char *, const char *);
3600 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3601 static void gen_remaining_tmpl_value_param_die_attribute (void);
3602 static bool generic_type_p (tree
);
3603 static void schedule_generic_params_dies_gen (tree t
);
3604 static void gen_scheduled_generic_parms_dies (void);
3606 static const char *comp_dir_string (void);
3608 static void hash_loc_operands (dw_loc_descr_ref
, inchash::hash
&);
3610 /* enum for tracking thread-local variables whose address is really an offset
3611 relative to the TLS pointer, which will need link-time relocation, but will
3612 not need relocation by the DWARF consumer. */
3620 /* Return the operator to use for an address of a variable. For dtprel_true, we
3621 use DW_OP_const*. For regular variables, which need both link-time
3622 relocation and consumer-level relocation (e.g., to account for shared objects
3623 loaded at a random address), we use DW_OP_addr*. */
3625 static inline enum dwarf_location_atom
3626 dw_addr_op (enum dtprel_bool dtprel
)
3628 if (dtprel
== dtprel_true
)
3629 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3630 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3632 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3635 /* Return a pointer to a newly allocated address location description. If
3636 dwarf_split_debug_info is true, then record the address with the appropriate
3638 static inline dw_loc_descr_ref
3639 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3641 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3643 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3644 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3645 ref
->dtprel
= dtprel
;
3646 if (dwarf_split_debug_info
)
3647 ref
->dw_loc_oprnd1
.val_entry
3648 = add_addr_table_entry (addr
,
3649 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3651 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3656 /* Section names used to hold DWARF debugging information. */
3658 #ifndef DEBUG_INFO_SECTION
3659 #define DEBUG_INFO_SECTION ".debug_info"
3661 #ifndef DEBUG_DWO_INFO_SECTION
3662 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3664 #ifndef DEBUG_ABBREV_SECTION
3665 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3667 #ifndef DEBUG_DWO_ABBREV_SECTION
3668 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3670 #ifndef DEBUG_ARANGES_SECTION
3671 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3673 #ifndef DEBUG_ADDR_SECTION
3674 #define DEBUG_ADDR_SECTION ".debug_addr"
3676 #ifndef DEBUG_MACINFO_SECTION
3677 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3679 #ifndef DEBUG_DWO_MACINFO_SECTION
3680 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3682 #ifndef DEBUG_DWO_MACRO_SECTION
3683 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3685 #ifndef DEBUG_MACRO_SECTION
3686 #define DEBUG_MACRO_SECTION ".debug_macro"
3688 #ifndef DEBUG_LINE_SECTION
3689 #define DEBUG_LINE_SECTION ".debug_line"
3691 #ifndef DEBUG_DWO_LINE_SECTION
3692 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3694 #ifndef DEBUG_LOC_SECTION
3695 #define DEBUG_LOC_SECTION ".debug_loc"
3697 #ifndef DEBUG_DWO_LOC_SECTION
3698 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3700 #ifndef DEBUG_LOCLISTS_SECTION
3701 #define DEBUG_LOCLISTS_SECTION ".debug_loclists"
3703 #ifndef DEBUG_DWO_LOCLISTS_SECTION
3704 #define DEBUG_DWO_LOCLISTS_SECTION ".debug_loclists.dwo"
3706 #ifndef DEBUG_PUBNAMES_SECTION
3707 #define DEBUG_PUBNAMES_SECTION \
3708 ((debug_generate_pub_sections == 2) \
3709 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3711 #ifndef DEBUG_PUBTYPES_SECTION
3712 #define DEBUG_PUBTYPES_SECTION \
3713 ((debug_generate_pub_sections == 2) \
3714 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3716 #ifndef DEBUG_STR_OFFSETS_SECTION
3717 #define DEBUG_STR_OFFSETS_SECTION ".debug_str_offsets"
3719 #ifndef DEBUG_DWO_STR_OFFSETS_SECTION
3720 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3722 #ifndef DEBUG_STR_DWO_SECTION
3723 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3725 #ifndef DEBUG_STR_SECTION
3726 #define DEBUG_STR_SECTION ".debug_str"
3728 #ifndef DEBUG_RANGES_SECTION
3729 #define DEBUG_RANGES_SECTION ".debug_ranges"
3731 #ifndef DEBUG_RNGLISTS_SECTION
3732 #define DEBUG_RNGLISTS_SECTION ".debug_rnglists"
3734 #ifndef DEBUG_LINE_STR_SECTION
3735 #define DEBUG_LINE_STR_SECTION ".debug_line_str"
3738 /* Standard ELF section names for compiled code and data. */
3739 #ifndef TEXT_SECTION_NAME
3740 #define TEXT_SECTION_NAME ".text"
3743 /* Section flags for .debug_str section. */
3744 #define DEBUG_STR_SECTION_FLAGS \
3745 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3746 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3749 /* Section flags for .debug_str.dwo section. */
3750 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3752 /* Labels we insert at beginning sections we can reference instead of
3753 the section names themselves. */
3755 #ifndef TEXT_SECTION_LABEL
3756 #define TEXT_SECTION_LABEL "Ltext"
3758 #ifndef COLD_TEXT_SECTION_LABEL
3759 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3761 #ifndef DEBUG_LINE_SECTION_LABEL
3762 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3764 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3765 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3767 #ifndef DEBUG_INFO_SECTION_LABEL
3768 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3770 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3771 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3773 #ifndef DEBUG_ABBREV_SECTION_LABEL
3774 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3776 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3777 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3779 #ifndef DEBUG_ADDR_SECTION_LABEL
3780 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3782 #ifndef DEBUG_LOC_SECTION_LABEL
3783 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3785 #ifndef DEBUG_RANGES_SECTION_LABEL
3786 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3788 #ifndef DEBUG_MACINFO_SECTION_LABEL
3789 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3791 #ifndef DEBUG_MACRO_SECTION_LABEL
3792 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3794 #define SKELETON_COMP_DIE_ABBREV 1
3795 #define SKELETON_TYPE_DIE_ABBREV 2
3797 /* Definitions of defaults for formats and names of various special
3798 (artificial) labels which may be generated within this file (when the -g
3799 options is used and DWARF2_DEBUGGING_INFO is in effect.
3800 If necessary, these may be overridden from within the tm.h file, but
3801 typically, overriding these defaults is unnecessary. */
3803 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3804 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3805 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3806 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3807 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3808 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3809 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3810 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3811 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3812 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3813 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3814 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3815 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3816 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3817 static char ranges_base_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3819 #ifndef TEXT_END_LABEL
3820 #define TEXT_END_LABEL "Letext"
3822 #ifndef COLD_END_LABEL
3823 #define COLD_END_LABEL "Letext_cold"
3825 #ifndef BLOCK_BEGIN_LABEL
3826 #define BLOCK_BEGIN_LABEL "LBB"
3828 #ifndef BLOCK_END_LABEL
3829 #define BLOCK_END_LABEL "LBE"
3831 #ifndef LINE_CODE_LABEL
3832 #define LINE_CODE_LABEL "LM"
3836 /* Return the root of the DIE's built for the current compilation unit. */
3838 comp_unit_die (void)
3840 if (!single_comp_unit_die
)
3841 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3842 return single_comp_unit_die
;
3845 /* We allow a language front-end to designate a function that is to be
3846 called to "demangle" any name before it is put into a DIE. */
3848 static const char *(*demangle_name_func
) (const char *);
3851 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3853 demangle_name_func
= func
;
3856 /* Test if rtl node points to a pseudo register. */
3859 is_pseudo_reg (const_rtx rtl
)
3861 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3862 || (GET_CODE (rtl
) == SUBREG
3863 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3866 /* Return a reference to a type, with its const and volatile qualifiers
3870 type_main_variant (tree type
)
3872 type
= TYPE_MAIN_VARIANT (type
);
3874 /* ??? There really should be only one main variant among any group of
3875 variants of a given type (and all of the MAIN_VARIANT values for all
3876 members of the group should point to that one type) but sometimes the C
3877 front-end messes this up for array types, so we work around that bug
3879 if (TREE_CODE (type
) == ARRAY_TYPE
)
3880 while (type
!= TYPE_MAIN_VARIANT (type
))
3881 type
= TYPE_MAIN_VARIANT (type
);
3886 /* Return nonzero if the given type node represents a tagged type. */
3889 is_tagged_type (const_tree type
)
3891 enum tree_code code
= TREE_CODE (type
);
3893 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3894 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3897 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3900 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3902 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3905 /* Return die_offset of a DIE reference to a base type. */
3907 static unsigned long int
3908 get_base_type_offset (dw_die_ref ref
)
3910 if (ref
->die_offset
)
3911 return ref
->die_offset
;
3912 if (comp_unit_die ()->die_abbrev
)
3914 calc_base_type_die_sizes ();
3915 gcc_assert (ref
->die_offset
);
3917 return ref
->die_offset
;
3920 /* Return die_offset of a DIE reference other than base type. */
3922 static unsigned long int
3923 get_ref_die_offset (dw_die_ref ref
)
3925 gcc_assert (ref
->die_offset
);
3926 return ref
->die_offset
;
3929 /* Convert a DIE tag into its string name. */
3932 dwarf_tag_name (unsigned int tag
)
3934 const char *name
= get_DW_TAG_name (tag
);
3939 return "DW_TAG_<unknown>";
3942 /* Convert a DWARF attribute code into its string name. */
3945 dwarf_attr_name (unsigned int attr
)
3951 #if VMS_DEBUGGING_INFO
3952 case DW_AT_HP_prologue
:
3953 return "DW_AT_HP_prologue";
3955 case DW_AT_MIPS_loop_unroll_factor
:
3956 return "DW_AT_MIPS_loop_unroll_factor";
3959 #if VMS_DEBUGGING_INFO
3960 case DW_AT_HP_epilogue
:
3961 return "DW_AT_HP_epilogue";
3963 case DW_AT_MIPS_stride
:
3964 return "DW_AT_MIPS_stride";
3968 name
= get_DW_AT_name (attr
);
3973 return "DW_AT_<unknown>";
3976 /* Convert a DWARF value form code into its string name. */
3979 dwarf_form_name (unsigned int form
)
3981 const char *name
= get_DW_FORM_name (form
);
3986 return "DW_FORM_<unknown>";
3989 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3990 instance of an inlined instance of a decl which is local to an inline
3991 function, so we have to trace all of the way back through the origin chain
3992 to find out what sort of node actually served as the original seed for the
3996 decl_ultimate_origin (const_tree decl
)
3998 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
4001 /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
4002 we're trying to output the abstract instance of this function. */
4003 if (DECL_ABSTRACT_P (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4006 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4007 most distant ancestor, this should never happen. */
4008 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
4010 return DECL_ABSTRACT_ORIGIN (decl
);
4013 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4014 of a virtual function may refer to a base class, so we check the 'this'
4018 decl_class_context (tree decl
)
4020 tree context
= NULL_TREE
;
4022 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4023 context
= DECL_CONTEXT (decl
);
4025 context
= TYPE_MAIN_VARIANT
4026 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4028 if (context
&& !TYPE_P (context
))
4029 context
= NULL_TREE
;
4034 /* Add an attribute/value pair to a DIE. */
4037 add_dwarf_attr (dw_die_ref die
, dw_attr_node
*attr
)
4039 /* Maybe this should be an assert? */
4043 vec_safe_reserve (die
->die_attr
, 1);
4044 vec_safe_push (die
->die_attr
, *attr
);
4047 static inline enum dw_val_class
4048 AT_class (dw_attr_node
*a
)
4050 return a
->dw_attr_val
.val_class
;
4053 /* Return the index for any attribute that will be referenced with a
4054 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
4055 are stored in dw_attr_val.v.val_str for reference counting
4058 static inline unsigned int
4059 AT_index (dw_attr_node
*a
)
4061 if (AT_class (a
) == dw_val_class_str
)
4062 return a
->dw_attr_val
.v
.val_str
->index
;
4063 else if (a
->dw_attr_val
.val_entry
!= NULL
)
4064 return a
->dw_attr_val
.val_entry
->index
;
4068 /* Add a flag value attribute to a DIE. */
4071 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
4075 attr
.dw_attr
= attr_kind
;
4076 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
4077 attr
.dw_attr_val
.val_entry
= NULL
;
4078 attr
.dw_attr_val
.v
.val_flag
= flag
;
4079 add_dwarf_attr (die
, &attr
);
4082 static inline unsigned
4083 AT_flag (dw_attr_node
*a
)
4085 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
4086 return a
->dw_attr_val
.v
.val_flag
;
4089 /* Add a signed integer attribute value to a DIE. */
4092 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
4096 attr
.dw_attr
= attr_kind
;
4097 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
4098 attr
.dw_attr_val
.val_entry
= NULL
;
4099 attr
.dw_attr_val
.v
.val_int
= int_val
;
4100 add_dwarf_attr (die
, &attr
);
4103 static inline HOST_WIDE_INT
4104 AT_int (dw_attr_node
*a
)
4106 gcc_assert (a
&& (AT_class (a
) == dw_val_class_const
4107 || AT_class (a
) == dw_val_class_const_implicit
));
4108 return a
->dw_attr_val
.v
.val_int
;
4111 /* Add an unsigned integer attribute value to a DIE. */
4114 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4115 unsigned HOST_WIDE_INT unsigned_val
)
4119 attr
.dw_attr
= attr_kind
;
4120 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4121 attr
.dw_attr_val
.val_entry
= NULL
;
4122 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4123 add_dwarf_attr (die
, &attr
);
4126 static inline unsigned HOST_WIDE_INT
4127 AT_unsigned (dw_attr_node
*a
)
4129 gcc_assert (a
&& (AT_class (a
) == dw_val_class_unsigned_const
4130 || AT_class (a
) == dw_val_class_unsigned_const_implicit
));
4131 return a
->dw_attr_val
.v
.val_unsigned
;
4134 /* Add an unsigned wide integer attribute value to a DIE. */
4137 add_AT_wide (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4142 attr
.dw_attr
= attr_kind
;
4143 attr
.dw_attr_val
.val_class
= dw_val_class_wide_int
;
4144 attr
.dw_attr_val
.val_entry
= NULL
;
4145 attr
.dw_attr_val
.v
.val_wide
= ggc_alloc
<wide_int
> ();
4146 *attr
.dw_attr_val
.v
.val_wide
= w
;
4147 add_dwarf_attr (die
, &attr
);
4150 /* Add an unsigned double integer attribute value to a DIE. */
4153 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4154 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
4158 attr
.dw_attr
= attr_kind
;
4159 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
4160 attr
.dw_attr_val
.val_entry
= NULL
;
4161 attr
.dw_attr_val
.v
.val_double
.high
= high
;
4162 attr
.dw_attr_val
.v
.val_double
.low
= low
;
4163 add_dwarf_attr (die
, &attr
);
4166 /* Add a floating point attribute value to a DIE and return it. */
4169 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4170 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
4174 attr
.dw_attr
= attr_kind
;
4175 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
4176 attr
.dw_attr_val
.val_entry
= NULL
;
4177 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
4178 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
4179 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
4180 add_dwarf_attr (die
, &attr
);
4183 /* Add an 8-byte data attribute value to a DIE. */
4186 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4187 unsigned char data8
[8])
4191 attr
.dw_attr
= attr_kind
;
4192 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
4193 attr
.dw_attr_val
.val_entry
= NULL
;
4194 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
4195 add_dwarf_attr (die
, &attr
);
4198 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
4199 dwarf_split_debug_info, address attributes in dies destined for the
4200 final executable have force_direct set to avoid using indexed
4204 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
4210 lbl_id
= xstrdup (lbl_low
);
4211 attr
.dw_attr
= DW_AT_low_pc
;
4212 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4213 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4214 if (dwarf_split_debug_info
&& !force_direct
)
4215 attr
.dw_attr_val
.val_entry
4216 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4218 attr
.dw_attr_val
.val_entry
= NULL
;
4219 add_dwarf_attr (die
, &attr
);
4221 attr
.dw_attr
= DW_AT_high_pc
;
4222 if (dwarf_version
< 4)
4223 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4225 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
4226 lbl_id
= xstrdup (lbl_high
);
4227 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4228 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
4229 && dwarf_split_debug_info
&& !force_direct
)
4230 attr
.dw_attr_val
.val_entry
4231 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4233 attr
.dw_attr_val
.val_entry
= NULL
;
4234 add_dwarf_attr (die
, &attr
);
4237 /* Hash and equality functions for debug_str_hash. */
4240 indirect_string_hasher::hash (indirect_string_node
*x
)
4242 return htab_hash_string (x
->str
);
4246 indirect_string_hasher::equal (indirect_string_node
*x1
, const char *x2
)
4248 return strcmp (x1
->str
, x2
) == 0;
4251 /* Add STR to the given string hash table. */
4253 static struct indirect_string_node
*
4254 find_AT_string_in_table (const char *str
,
4255 hash_table
<indirect_string_hasher
> *table
)
4257 struct indirect_string_node
*node
;
4259 indirect_string_node
**slot
4260 = table
->find_slot_with_hash (str
, htab_hash_string (str
), INSERT
);
4263 node
= ggc_cleared_alloc
<indirect_string_node
> ();
4264 node
->str
= ggc_strdup (str
);
4274 /* Add STR to the indirect string hash table. */
4276 static struct indirect_string_node
*
4277 find_AT_string (const char *str
)
4279 if (! debug_str_hash
)
4280 debug_str_hash
= hash_table
<indirect_string_hasher
>::create_ggc (10);
4282 return find_AT_string_in_table (str
, debug_str_hash
);
4285 /* Add a string attribute value to a DIE. */
4288 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4291 struct indirect_string_node
*node
;
4293 node
= find_AT_string (str
);
4295 attr
.dw_attr
= attr_kind
;
4296 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4297 attr
.dw_attr_val
.val_entry
= NULL
;
4298 attr
.dw_attr_val
.v
.val_str
= node
;
4299 add_dwarf_attr (die
, &attr
);
4302 static inline const char *
4303 AT_string (dw_attr_node
*a
)
4305 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4306 return a
->dw_attr_val
.v
.val_str
->str
;
4309 /* Call this function directly to bypass AT_string_form's logic to put
4310 the string inline in the die. */
4313 set_indirect_string (struct indirect_string_node
*node
)
4315 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4316 /* Already indirect is a no op. */
4317 if (node
->form
== DW_FORM_strp
4318 || node
->form
== DW_FORM_line_strp
4319 || node
->form
== DW_FORM_GNU_str_index
)
4321 gcc_assert (node
->label
);
4324 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4325 ++dw2_string_counter
;
4326 node
->label
= xstrdup (label
);
4328 if (!dwarf_split_debug_info
)
4330 node
->form
= DW_FORM_strp
;
4331 node
->index
= NOT_INDEXED
;
4335 node
->form
= DW_FORM_GNU_str_index
;
4336 node
->index
= NO_INDEX_ASSIGNED
;
4340 /* Find out whether a string should be output inline in DIE
4341 or out-of-line in .debug_str section. */
4343 static enum dwarf_form
4344 find_string_form (struct indirect_string_node
*node
)
4351 len
= strlen (node
->str
) + 1;
4353 /* If the string is shorter or equal to the size of the reference, it is
4354 always better to put it inline. */
4355 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4356 return node
->form
= DW_FORM_string
;
4358 /* If we cannot expect the linker to merge strings in .debug_str
4359 section, only put it into .debug_str if it is worth even in this
4361 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4362 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4363 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
4364 return node
->form
= DW_FORM_string
;
4366 set_indirect_string (node
);
4371 /* Find out whether the string referenced from the attribute should be
4372 output inline in DIE or out-of-line in .debug_str section. */
4374 static enum dwarf_form
4375 AT_string_form (dw_attr_node
*a
)
4377 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4378 return find_string_form (a
->dw_attr_val
.v
.val_str
);
4381 /* Add a DIE reference attribute value to a DIE. */
4384 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4387 gcc_checking_assert (targ_die
!= NULL
);
4389 /* With LTO we can end up trying to reference something we didn't create
4390 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4391 if (targ_die
== NULL
)
4394 attr
.dw_attr
= attr_kind
;
4395 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4396 attr
.dw_attr_val
.val_entry
= NULL
;
4397 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4398 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4399 add_dwarf_attr (die
, &attr
);
4402 /* Change DIE reference REF to point to NEW_DIE instead. */
4405 change_AT_die_ref (dw_attr_node
*ref
, dw_die_ref new_die
)
4407 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4408 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4409 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4412 /* Add an AT_specification attribute to a DIE, and also make the back
4413 pointer from the specification to the definition. */
4416 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4418 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4419 gcc_assert (!targ_die
->die_definition
);
4420 targ_die
->die_definition
= die
;
4423 static inline dw_die_ref
4424 AT_ref (dw_attr_node
*a
)
4426 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4427 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4431 AT_ref_external (dw_attr_node
*a
)
4433 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4434 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4440 set_AT_ref_external (dw_attr_node
*a
, int i
)
4442 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4443 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4446 /* Add an FDE reference attribute value to a DIE. */
4449 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4453 attr
.dw_attr
= attr_kind
;
4454 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4455 attr
.dw_attr_val
.val_entry
= NULL
;
4456 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4457 add_dwarf_attr (die
, &attr
);
4460 /* Add a location description attribute value to a DIE. */
4463 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4467 attr
.dw_attr
= attr_kind
;
4468 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4469 attr
.dw_attr_val
.val_entry
= NULL
;
4470 attr
.dw_attr_val
.v
.val_loc
= loc
;
4471 add_dwarf_attr (die
, &attr
);
4474 static inline dw_loc_descr_ref
4475 AT_loc (dw_attr_node
*a
)
4477 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4478 return a
->dw_attr_val
.v
.val_loc
;
4482 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4486 if (XCOFF_DEBUGGING_INFO
&& !HAVE_XCOFF_DWARF_EXTRAS
)
4489 attr
.dw_attr
= attr_kind
;
4490 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4491 attr
.dw_attr_val
.val_entry
= NULL
;
4492 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4493 add_dwarf_attr (die
, &attr
);
4494 have_location_lists
= true;
4497 static inline dw_loc_list_ref
4498 AT_loc_list (dw_attr_node
*a
)
4500 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4501 return a
->dw_attr_val
.v
.val_loc_list
;
4504 static inline dw_loc_list_ref
*
4505 AT_loc_list_ptr (dw_attr_node
*a
)
4507 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4508 return &a
->dw_attr_val
.v
.val_loc_list
;
4511 struct addr_hasher
: ggc_ptr_hash
<addr_table_entry
>
4513 static hashval_t
hash (addr_table_entry
*);
4514 static bool equal (addr_table_entry
*, addr_table_entry
*);
4517 /* Table of entries into the .debug_addr section. */
4519 static GTY (()) hash_table
<addr_hasher
> *addr_index_table
;
4521 /* Hash an address_table_entry. */
4524 addr_hasher::hash (addr_table_entry
*a
)
4526 inchash::hash hstate
;
4532 case ate_kind_rtx_dtprel
:
4535 case ate_kind_label
:
4536 return htab_hash_string (a
->addr
.label
);
4540 inchash::add_rtx (a
->addr
.rtl
, hstate
);
4541 return hstate
.end ();
4544 /* Determine equality for two address_table_entries. */
4547 addr_hasher::equal (addr_table_entry
*a1
, addr_table_entry
*a2
)
4549 if (a1
->kind
!= a2
->kind
)
4554 case ate_kind_rtx_dtprel
:
4555 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4556 case ate_kind_label
:
4557 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4563 /* Initialize an addr_table_entry. */
4566 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4572 case ate_kind_rtx_dtprel
:
4573 e
->addr
.rtl
= (rtx
) addr
;
4575 case ate_kind_label
:
4576 e
->addr
.label
= (char *) addr
;
4580 e
->index
= NO_INDEX_ASSIGNED
;
4583 /* Add attr to the address table entry to the table. Defer setting an
4584 index until output time. */
4586 static addr_table_entry
*
4587 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4589 addr_table_entry
*node
;
4590 addr_table_entry finder
;
4592 gcc_assert (dwarf_split_debug_info
);
4593 if (! addr_index_table
)
4594 addr_index_table
= hash_table
<addr_hasher
>::create_ggc (10);
4595 init_addr_table_entry (&finder
, kind
, addr
);
4596 addr_table_entry
**slot
= addr_index_table
->find_slot (&finder
, INSERT
);
4598 if (*slot
== HTAB_EMPTY_ENTRY
)
4600 node
= ggc_cleared_alloc
<addr_table_entry
> ();
4601 init_addr_table_entry (node
, kind
, addr
);
4611 /* Remove an entry from the addr table by decrementing its refcount.
4612 Strictly, decrementing the refcount would be enough, but the
4613 assertion that the entry is actually in the table has found
4617 remove_addr_table_entry (addr_table_entry
*entry
)
4619 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4620 /* After an index is assigned, the table is frozen. */
4621 gcc_assert (entry
->refcount
> 0 && entry
->index
== NO_INDEX_ASSIGNED
);
4625 /* Given a location list, remove all addresses it refers to from the
4629 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4631 for (; descr
; descr
= descr
->dw_loc_next
)
4632 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4634 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4635 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4639 /* A helper function for dwarf2out_finish called through
4640 htab_traverse. Assign an addr_table_entry its index. All entries
4641 must be collected into the table when this function is called,
4642 because the indexing code relies on htab_traverse to traverse nodes
4643 in the same order for each run. */
4646 index_addr_table_entry (addr_table_entry
**h
, unsigned int *index
)
4648 addr_table_entry
*node
= *h
;
4650 /* Don't index unreferenced nodes. */
4651 if (node
->refcount
== 0)
4654 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
4655 node
->index
= *index
;
4661 /* Add an address constant attribute value to a DIE. When using
4662 dwarf_split_debug_info, address attributes in dies destined for the
4663 final executable should be direct references--setting the parameter
4664 force_direct ensures this behavior. */
4667 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4672 attr
.dw_attr
= attr_kind
;
4673 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4674 attr
.dw_attr_val
.v
.val_addr
= addr
;
4675 if (dwarf_split_debug_info
&& !force_direct
)
4676 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4678 attr
.dw_attr_val
.val_entry
= NULL
;
4679 add_dwarf_attr (die
, &attr
);
4682 /* Get the RTX from to an address DIE attribute. */
4685 AT_addr (dw_attr_node
*a
)
4687 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4688 return a
->dw_attr_val
.v
.val_addr
;
4691 /* Add a file attribute value to a DIE. */
4694 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4695 struct dwarf_file_data
*fd
)
4699 attr
.dw_attr
= attr_kind
;
4700 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4701 attr
.dw_attr_val
.val_entry
= NULL
;
4702 attr
.dw_attr_val
.v
.val_file
= fd
;
4703 add_dwarf_attr (die
, &attr
);
4706 /* Get the dwarf_file_data from a file DIE attribute. */
4708 static inline struct dwarf_file_data
*
4709 AT_file (dw_attr_node
*a
)
4711 gcc_assert (a
&& (AT_class (a
) == dw_val_class_file
4712 || AT_class (a
) == dw_val_class_file_implicit
));
4713 return a
->dw_attr_val
.v
.val_file
;
4716 /* Add a vms delta attribute value to a DIE. */
4719 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4720 const char *lbl1
, const char *lbl2
)
4724 attr
.dw_attr
= attr_kind
;
4725 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4726 attr
.dw_attr_val
.val_entry
= NULL
;
4727 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4728 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4729 add_dwarf_attr (die
, &attr
);
4732 /* Add a label identifier attribute value to a DIE. */
4735 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4740 attr
.dw_attr
= attr_kind
;
4741 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4742 attr
.dw_attr_val
.val_entry
= NULL
;
4743 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4744 if (dwarf_split_debug_info
)
4745 attr
.dw_attr_val
.val_entry
4746 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4748 add_dwarf_attr (die
, &attr
);
4751 /* Add a section offset attribute value to a DIE, an offset into the
4752 debug_line section. */
4755 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4760 attr
.dw_attr
= attr_kind
;
4761 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4762 attr
.dw_attr_val
.val_entry
= NULL
;
4763 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4764 add_dwarf_attr (die
, &attr
);
4767 /* Add a section offset attribute value to a DIE, an offset into the
4768 debug_loclists section. */
4771 add_AT_loclistsptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4776 attr
.dw_attr
= attr_kind
;
4777 attr
.dw_attr_val
.val_class
= dw_val_class_loclistsptr
;
4778 attr
.dw_attr_val
.val_entry
= NULL
;
4779 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4780 add_dwarf_attr (die
, &attr
);
4783 /* Add a section offset attribute value to a DIE, an offset into the
4784 debug_macinfo section. */
4787 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4792 attr
.dw_attr
= attr_kind
;
4793 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4794 attr
.dw_attr_val
.val_entry
= NULL
;
4795 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4796 add_dwarf_attr (die
, &attr
);
4799 /* Add an offset attribute value to a DIE. */
4802 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4803 unsigned HOST_WIDE_INT offset
)
4807 attr
.dw_attr
= attr_kind
;
4808 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4809 attr
.dw_attr_val
.val_entry
= NULL
;
4810 attr
.dw_attr_val
.v
.val_offset
= offset
;
4811 add_dwarf_attr (die
, &attr
);
4814 /* Add a range_list attribute value to a DIE. When using
4815 dwarf_split_debug_info, address attributes in dies destined for the
4816 final executable should be direct references--setting the parameter
4817 force_direct ensures this behavior. */
4819 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4820 #define RELOCATED_OFFSET (NULL)
4823 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4824 long unsigned int offset
, bool force_direct
)
4828 attr
.dw_attr
= attr_kind
;
4829 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4830 /* For the range_list attribute, use val_entry to store whether the
4831 offset should follow split-debug-info or normal semantics. This
4832 value is read in output_range_list_offset. */
4833 if (dwarf_split_debug_info
&& !force_direct
)
4834 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4836 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4837 attr
.dw_attr_val
.v
.val_offset
= offset
;
4838 add_dwarf_attr (die
, &attr
);
4841 /* Return the start label of a delta attribute. */
4843 static inline const char *
4844 AT_vms_delta1 (dw_attr_node
*a
)
4846 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4847 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4850 /* Return the end label of a delta attribute. */
4852 static inline const char *
4853 AT_vms_delta2 (dw_attr_node
*a
)
4855 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4856 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4859 static inline const char *
4860 AT_lbl (dw_attr_node
*a
)
4862 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4863 || AT_class (a
) == dw_val_class_lineptr
4864 || AT_class (a
) == dw_val_class_macptr
4865 || AT_class (a
) == dw_val_class_loclistsptr
4866 || AT_class (a
) == dw_val_class_high_pc
));
4867 return a
->dw_attr_val
.v
.val_lbl_id
;
4870 /* Get the attribute of type attr_kind. */
4872 static dw_attr_node
*
4873 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4877 dw_die_ref spec
= NULL
;
4882 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4883 if (a
->dw_attr
== attr_kind
)
4885 else if (a
->dw_attr
== DW_AT_specification
4886 || a
->dw_attr
== DW_AT_abstract_origin
)
4890 return get_AT (spec
, attr_kind
);
4895 /* Returns the parent of the declaration of DIE. */
4898 get_die_parent (dw_die_ref die
)
4905 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4906 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4909 return die
->die_parent
;
4912 /* Return the "low pc" attribute value, typically associated with a subprogram
4913 DIE. Return null if the "low pc" attribute is either not present, or if it
4914 cannot be represented as an assembler label identifier. */
4916 static inline const char *
4917 get_AT_low_pc (dw_die_ref die
)
4919 dw_attr_node
*a
= get_AT (die
, DW_AT_low_pc
);
4921 return a
? AT_lbl (a
) : NULL
;
4924 /* Return the "high pc" attribute value, typically associated with a subprogram
4925 DIE. Return null if the "high pc" attribute is either not present, or if it
4926 cannot be represented as an assembler label identifier. */
4928 static inline const char *
4929 get_AT_hi_pc (dw_die_ref die
)
4931 dw_attr_node
*a
= get_AT (die
, DW_AT_high_pc
);
4933 return a
? AT_lbl (a
) : NULL
;
4936 /* Return the value of the string attribute designated by ATTR_KIND, or
4937 NULL if it is not present. */
4939 static inline const char *
4940 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4942 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4944 return a
? AT_string (a
) : NULL
;
4947 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4948 if it is not present. */
4951 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4953 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4955 return a
? AT_flag (a
) : 0;
4958 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4959 if it is not present. */
4961 static inline unsigned
4962 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4964 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4966 return a
? AT_unsigned (a
) : 0;
4969 static inline dw_die_ref
4970 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4972 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4974 return a
? AT_ref (a
) : NULL
;
4977 static inline struct dwarf_file_data
*
4978 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4980 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4982 return a
? AT_file (a
) : NULL
;
4985 /* Return TRUE if the language is C++. */
4990 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4992 return (lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
4993 || lang
== DW_LANG_C_plus_plus_11
|| lang
== DW_LANG_C_plus_plus_14
);
4996 /* Return TRUE if DECL was created by the C++ frontend. */
4999 is_cxx (const_tree decl
)
5003 const_tree context
= decl
;
5004 while (context
&& TREE_CODE (context
) != TRANSLATION_UNIT_DECL
)
5006 if (TREE_CODE (context
) == BLOCK
)
5007 context
= BLOCK_SUPERCONTEXT (context
);
5009 context
= get_containing_scope (context
);
5011 if (context
&& TRANSLATION_UNIT_LANGUAGE (context
))
5012 return strncmp (TRANSLATION_UNIT_LANGUAGE (context
), "GNU C++", 7) == 0;
5017 /* Return TRUE if the language is Java. */
5022 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5024 return lang
== DW_LANG_Java
;
5027 /* Return TRUE if the language is Fortran. */
5032 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5034 return (lang
== DW_LANG_Fortran77
5035 || lang
== DW_LANG_Fortran90
5036 || lang
== DW_LANG_Fortran95
5037 || lang
== DW_LANG_Fortran03
5038 || lang
== DW_LANG_Fortran08
);
5041 /* Return TRUE if the language is Ada. */
5046 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
5048 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
5051 /* Remove the specified attribute if present. Return TRUE if removal
5055 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5063 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5064 if (a
->dw_attr
== attr_kind
)
5066 if (AT_class (a
) == dw_val_class_str
)
5067 if (a
->dw_attr_val
.v
.val_str
->refcount
)
5068 a
->dw_attr_val
.v
.val_str
->refcount
--;
5070 /* vec::ordered_remove should help reduce the number of abbrevs
5072 die
->die_attr
->ordered_remove (ix
);
5078 /* Remove CHILD from its parent. PREV must have the property that
5079 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
5082 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
5084 gcc_assert (child
->die_parent
== prev
->die_parent
);
5085 gcc_assert (prev
->die_sib
== child
);
5088 gcc_assert (child
->die_parent
->die_child
== child
);
5092 prev
->die_sib
= child
->die_sib
;
5093 if (child
->die_parent
->die_child
== child
)
5094 child
->die_parent
->die_child
= prev
;
5095 child
->die_sib
= NULL
;
5098 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
5099 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
5102 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
5104 dw_die_ref parent
= old_child
->die_parent
;
5106 gcc_assert (parent
== prev
->die_parent
);
5107 gcc_assert (prev
->die_sib
== old_child
);
5109 new_child
->die_parent
= parent
;
5110 if (prev
== old_child
)
5112 gcc_assert (parent
->die_child
== old_child
);
5113 new_child
->die_sib
= new_child
;
5117 prev
->die_sib
= new_child
;
5118 new_child
->die_sib
= old_child
->die_sib
;
5120 if (old_child
->die_parent
->die_child
== old_child
)
5121 old_child
->die_parent
->die_child
= new_child
;
5122 old_child
->die_sib
= NULL
;
5125 /* Move all children from OLD_PARENT to NEW_PARENT. */
5128 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
5131 new_parent
->die_child
= old_parent
->die_child
;
5132 old_parent
->die_child
= NULL
;
5133 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
5136 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
5140 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
5146 dw_die_ref prev
= c
;
5148 while (c
->die_tag
== tag
)
5150 remove_child_with_prev (c
, prev
);
5151 c
->die_parent
= NULL
;
5152 /* Might have removed every child. */
5153 if (die
->die_child
== NULL
)
5157 } while (c
!= die
->die_child
);
5160 /* Add a CHILD_DIE as the last child of DIE. */
5163 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
5165 /* FIXME this should probably be an assert. */
5166 if (! die
|| ! child_die
)
5168 gcc_assert (die
!= child_die
);
5170 child_die
->die_parent
= die
;
5173 child_die
->die_sib
= die
->die_child
->die_sib
;
5174 die
->die_child
->die_sib
= child_die
;
5177 child_die
->die_sib
= child_die
;
5178 die
->die_child
= child_die
;
5181 /* Like add_child_die, but put CHILD_DIE after AFTER_DIE. */
5184 add_child_die_after (dw_die_ref die
, dw_die_ref child_die
,
5185 dw_die_ref after_die
)
5191 && die
!= child_die
);
5193 child_die
->die_parent
= die
;
5194 child_die
->die_sib
= after_die
->die_sib
;
5195 after_die
->die_sib
= child_die
;
5196 if (die
->die_child
== after_die
)
5197 die
->die_child
= child_die
;
5200 /* Unassociate CHILD from its parent, and make its parent be
5204 reparent_child (dw_die_ref child
, dw_die_ref new_parent
)
5206 for (dw_die_ref p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
5207 if (p
->die_sib
== child
)
5209 remove_child_with_prev (child
, p
);
5212 add_child_die (new_parent
, child
);
5215 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5216 is the specification, to the end of PARENT's list of children.
5217 This is done by removing and re-adding it. */
5220 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
5222 /* We want the declaration DIE from inside the class, not the
5223 specification DIE at toplevel. */
5224 if (child
->die_parent
!= parent
)
5226 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5232 gcc_assert (child
->die_parent
== parent
5233 || (child
->die_parent
5234 == get_AT_ref (parent
, DW_AT_specification
)));
5236 reparent_child (child
, parent
);
5239 /* Create and return a new die with a parent of PARENT_DIE. If
5240 PARENT_DIE is NULL, the new DIE is placed in limbo and an
5241 associated tree T must be supplied to determine parenthood
5244 static inline dw_die_ref
5245 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
5247 dw_die_ref die
= ggc_cleared_alloc
<die_node
> ();
5249 die
->die_tag
= tag_value
;
5251 if (parent_die
!= NULL
)
5252 add_child_die (parent_die
, die
);
5255 limbo_die_node
*limbo_node
;
5257 /* No DIEs created after early dwarf should end up in limbo,
5258 because the limbo list should not persist past LTO
5260 if (tag_value
!= DW_TAG_compile_unit
5261 /* These are allowed because they're generated while
5262 breaking out COMDAT units late. */
5263 && tag_value
!= DW_TAG_type_unit
5264 && tag_value
!= DW_TAG_skeleton_unit
5266 /* Allow nested functions to live in limbo because they will
5267 only temporarily live there, as decls_for_scope will fix
5269 && (TREE_CODE (t
) != FUNCTION_DECL
5270 || !decl_function_context (t
))
5271 /* Same as nested functions above but for types. Types that
5272 are local to a function will be fixed in
5274 && (!RECORD_OR_UNION_TYPE_P (t
)
5275 || !TYPE_CONTEXT (t
)
5276 || TREE_CODE (TYPE_CONTEXT (t
)) != FUNCTION_DECL
)
5277 /* FIXME debug-early: Allow late limbo DIE creation for LTO,
5278 especially in the ltrans stage, but once we implement LTO
5279 dwarf streaming, we should remove this exception. */
5282 fprintf (stderr
, "symbol ended up in limbo too late:");
5283 debug_generic_stmt (t
);
5287 limbo_node
= ggc_cleared_alloc
<limbo_die_node
> ();
5288 limbo_node
->die
= die
;
5289 limbo_node
->created_for
= t
;
5290 limbo_node
->next
= limbo_die_list
;
5291 limbo_die_list
= limbo_node
;
5297 /* Return the DIE associated with the given type specifier. */
5299 static inline dw_die_ref
5300 lookup_type_die (tree type
)
5302 dw_die_ref die
= TYPE_SYMTAB_DIE (type
);
5303 if (die
&& die
->removed
)
5305 TYPE_SYMTAB_DIE (type
) = NULL
;
5311 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
5312 anonymous type named by the typedef TYPE_DIE, return the DIE of the
5313 anonymous type instead the one of the naming typedef. */
5315 static inline dw_die_ref
5316 strip_naming_typedef (tree type
, dw_die_ref type_die
)
5319 && TREE_CODE (type
) == RECORD_TYPE
5321 && type_die
->die_tag
== DW_TAG_typedef
5322 && is_naming_typedef_decl (TYPE_NAME (type
)))
5323 type_die
= get_AT_ref (type_die
, DW_AT_type
);
5327 /* Like lookup_type_die, but if type is an anonymous type named by a
5328 typedef[1], return the DIE of the anonymous type instead the one of
5329 the naming typedef. This is because in gen_typedef_die, we did
5330 equate the anonymous struct named by the typedef with the DIE of
5331 the naming typedef. So by default, lookup_type_die on an anonymous
5332 struct yields the DIE of the naming typedef.
5334 [1]: Read the comment of is_naming_typedef_decl to learn about what
5335 a naming typedef is. */
5337 static inline dw_die_ref
5338 lookup_type_die_strip_naming_typedef (tree type
)
5340 dw_die_ref die
= lookup_type_die (type
);
5341 return strip_naming_typedef (type
, die
);
5344 /* Equate a DIE to a given type specifier. */
5347 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5349 TYPE_SYMTAB_DIE (type
) = type_die
;
5352 /* Returns a hash value for X (which really is a die_struct). */
5355 decl_die_hasher::hash (die_node
*x
)
5357 return (hashval_t
) x
->decl_id
;
5360 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5363 decl_die_hasher::equal (die_node
*x
, tree y
)
5365 return (x
->decl_id
== DECL_UID (y
));
5368 /* Return the DIE associated with a given declaration. */
5370 static inline dw_die_ref
5371 lookup_decl_die (tree decl
)
5373 dw_die_ref
*die
= decl_die_table
->find_slot_with_hash (decl
, DECL_UID (decl
),
5377 if ((*die
)->removed
)
5379 decl_die_table
->clear_slot (die
);
5385 /* Returns a hash value for X (which really is a var_loc_list). */
5388 decl_loc_hasher::hash (var_loc_list
*x
)
5390 return (hashval_t
) x
->decl_id
;
5393 /* Return nonzero if decl_id of var_loc_list X is the same as
5397 decl_loc_hasher::equal (var_loc_list
*x
, const_tree y
)
5399 return (x
->decl_id
== DECL_UID (y
));
5402 /* Return the var_loc list associated with a given declaration. */
5404 static inline var_loc_list
*
5405 lookup_decl_loc (const_tree decl
)
5407 if (!decl_loc_table
)
5409 return decl_loc_table
->find_with_hash (decl
, DECL_UID (decl
));
5412 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5415 dw_loc_list_hasher::hash (cached_dw_loc_list
*x
)
5417 return (hashval_t
) x
->decl_id
;
5420 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5424 dw_loc_list_hasher::equal (cached_dw_loc_list
*x
, const_tree y
)
5426 return (x
->decl_id
== DECL_UID (y
));
5429 /* Equate a DIE to a particular declaration. */
5432 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5434 unsigned int decl_id
= DECL_UID (decl
);
5436 *decl_die_table
->find_slot_with_hash (decl
, decl_id
, INSERT
) = decl_die
;
5437 decl_die
->decl_id
= decl_id
;
5440 /* Return how many bits covers PIECE EXPR_LIST. */
5442 static HOST_WIDE_INT
5443 decl_piece_bitsize (rtx piece
)
5445 int ret
= (int) GET_MODE (piece
);
5448 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
5449 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
5450 return INTVAL (XEXP (XEXP (piece
, 0), 0));
5453 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5456 decl_piece_varloc_ptr (rtx piece
)
5458 if ((int) GET_MODE (piece
))
5459 return &XEXP (piece
, 0);
5461 return &XEXP (XEXP (piece
, 0), 1);
5464 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5465 Next is the chain of following piece nodes. */
5467 static rtx_expr_list
*
5468 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
5470 if (bitsize
> 0 && bitsize
<= (int) MAX_MACHINE_MODE
)
5471 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
5473 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
5478 /* Return rtx that should be stored into loc field for
5479 LOC_NOTE and BITPOS/BITSIZE. */
5482 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
5483 HOST_WIDE_INT bitsize
)
5487 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
5489 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
5494 /* This function either modifies location piece list *DEST in
5495 place (if SRC and INNER is NULL), or copies location piece list
5496 *SRC to *DEST while modifying it. Location BITPOS is modified
5497 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5498 not copied and if needed some padding around it is added.
5499 When modifying in place, DEST should point to EXPR_LIST where
5500 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5501 to the start of the whole list and INNER points to the EXPR_LIST
5502 where earlier pieces cover PIECE_BITPOS bits. */
5505 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
5506 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
5507 HOST_WIDE_INT bitsize
, rtx loc_note
)
5510 bool copy
= inner
!= NULL
;
5514 /* First copy all nodes preceding the current bitpos. */
5515 while (src
!= inner
)
5517 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5518 decl_piece_bitsize (*src
), NULL_RTX
);
5519 dest
= &XEXP (*dest
, 1);
5520 src
= &XEXP (*src
, 1);
5523 /* Add padding if needed. */
5524 if (bitpos
!= piece_bitpos
)
5526 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5527 copy
? NULL_RTX
: *dest
);
5528 dest
= &XEXP (*dest
, 1);
5530 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5533 /* A piece with correct bitpos and bitsize already exist,
5534 just update the location for it and return. */
5535 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5538 /* Add the piece that changed. */
5539 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5540 dest
= &XEXP (*dest
, 1);
5541 /* Skip over pieces that overlap it. */
5542 diff
= bitpos
- piece_bitpos
+ bitsize
;
5545 while (diff
> 0 && *src
)
5548 diff
-= decl_piece_bitsize (piece
);
5550 src
= &XEXP (piece
, 1);
5553 *src
= XEXP (piece
, 1);
5554 free_EXPR_LIST_node (piece
);
5557 /* Add padding if needed. */
5558 if (diff
< 0 && *src
)
5562 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5563 dest
= &XEXP (*dest
, 1);
5567 /* Finally copy all nodes following it. */
5570 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5571 decl_piece_bitsize (*src
), NULL_RTX
);
5572 dest
= &XEXP (*dest
, 1);
5573 src
= &XEXP (*src
, 1);
5577 /* Add a variable location node to the linked list for DECL. */
5579 static struct var_loc_node
*
5580 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5582 unsigned int decl_id
;
5584 struct var_loc_node
*loc
= NULL
;
5585 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5587 if (VAR_P (decl
) && DECL_HAS_DEBUG_EXPR_P (decl
))
5589 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5590 if (handled_component_p (realdecl
)
5591 || (TREE_CODE (realdecl
) == MEM_REF
5592 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5594 HOST_WIDE_INT maxsize
;
5597 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
,
5599 if (!DECL_P (innerdecl
)
5600 || DECL_IGNORED_P (innerdecl
)
5601 || TREE_STATIC (innerdecl
)
5603 || bitpos
+ bitsize
> 256
5604 || bitsize
!= maxsize
)
5610 decl_id
= DECL_UID (decl
);
5612 = decl_loc_table
->find_slot_with_hash (decl
, decl_id
, INSERT
);
5615 temp
= ggc_cleared_alloc
<var_loc_list
> ();
5616 temp
->decl_id
= decl_id
;
5622 /* For PARM_DECLs try to keep around the original incoming value,
5623 even if that means we'll emit a zero-range .debug_loc entry. */
5625 && temp
->first
== temp
->last
5626 && TREE_CODE (decl
) == PARM_DECL
5627 && NOTE_P (temp
->first
->loc
)
5628 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5629 && DECL_INCOMING_RTL (decl
)
5630 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5631 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5632 == GET_CODE (DECL_INCOMING_RTL (decl
))
5633 && prev_real_insn (as_a
<rtx_insn
*> (temp
->first
->loc
)) == NULL_RTX
5635 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5636 NOTE_VAR_LOCATION_LOC (loc_note
))
5637 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5638 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5640 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5641 temp
->first
->next
= loc
;
5643 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5645 else if (temp
->last
)
5647 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5648 rtx
*piece_loc
= NULL
, last_loc_note
;
5649 HOST_WIDE_INT piece_bitpos
= 0;
5653 gcc_assert (last
->next
== NULL
);
5655 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5657 piece_loc
= &last
->loc
;
5660 HOST_WIDE_INT cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5661 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5663 piece_bitpos
+= cur_bitsize
;
5664 piece_loc
= &XEXP (*piece_loc
, 1);
5668 /* TEMP->LAST here is either pointer to the last but one or
5669 last element in the chained list, LAST is pointer to the
5671 if (label
&& strcmp (last
->label
, label
) == 0)
5673 /* For SRA optimized variables if there weren't any real
5674 insns since last note, just modify the last node. */
5675 if (piece_loc
!= NULL
)
5677 adjust_piece_list (piece_loc
, NULL
, NULL
,
5678 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5681 /* If the last note doesn't cover any instructions, remove it. */
5682 if (temp
->last
!= last
)
5684 temp
->last
->next
= NULL
;
5687 gcc_assert (strcmp (last
->label
, label
) != 0);
5691 gcc_assert (temp
->first
== temp
->last
5692 || (temp
->first
->next
== temp
->last
5693 && TREE_CODE (decl
) == PARM_DECL
));
5694 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5695 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5699 if (bitsize
== -1 && NOTE_P (last
->loc
))
5700 last_loc_note
= last
->loc
;
5701 else if (piece_loc
!= NULL
5702 && *piece_loc
!= NULL_RTX
5703 && piece_bitpos
== bitpos
5704 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5705 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5707 last_loc_note
= NULL_RTX
;
5708 /* If the current location is the same as the end of the list,
5709 and either both or neither of the locations is uninitialized,
5710 we have nothing to do. */
5711 if (last_loc_note
== NULL_RTX
5712 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5713 NOTE_VAR_LOCATION_LOC (loc_note
)))
5714 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5715 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5716 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5717 == VAR_INIT_STATUS_UNINITIALIZED
)
5718 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5719 == VAR_INIT_STATUS_UNINITIALIZED
))))
5721 /* Add LOC to the end of list and update LAST. If the last
5722 element of the list has been removed above, reuse its
5723 memory for the new node, otherwise allocate a new one. */
5727 memset (loc
, '\0', sizeof (*loc
));
5730 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5731 if (bitsize
== -1 || piece_loc
== NULL
)
5732 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5734 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5735 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5737 /* Ensure TEMP->LAST will point either to the new last but one
5738 element of the chain, or to the last element in it. */
5739 if (last
!= temp
->last
)
5747 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5750 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5755 /* Keep track of the number of spaces used to indent the
5756 output of the debugging routines that print the structure of
5757 the DIE internal representation. */
5758 static int print_indent
;
5760 /* Indent the line the number of spaces given by print_indent. */
5763 print_spaces (FILE *outfile
)
5765 fprintf (outfile
, "%*s", print_indent
, "");
5768 /* Print a type signature in hex. */
5771 print_signature (FILE *outfile
, char *sig
)
5775 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5776 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5780 print_discr_value (FILE *outfile
, dw_discr_value
*discr_value
)
5782 if (discr_value
->pos
)
5783 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, discr_value
->v
.sval
);
5785 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, discr_value
->v
.uval
);
5788 static void print_loc_descr (dw_loc_descr_ref
, FILE *);
5790 /* Print the value associated to the VAL DWARF value node to OUTFILE. If
5791 RECURSE, output location descriptor operations. */
5794 print_dw_val (dw_val_node
*val
, bool recurse
, FILE *outfile
)
5796 switch (val
->val_class
)
5798 case dw_val_class_addr
:
5799 fprintf (outfile
, "address");
5801 case dw_val_class_offset
:
5802 fprintf (outfile
, "offset");
5804 case dw_val_class_loc
:
5805 fprintf (outfile
, "location descriptor");
5806 if (val
->v
.val_loc
== NULL
)
5807 fprintf (outfile
, " -> <null>\n");
5810 fprintf (outfile
, ":\n");
5812 print_loc_descr (val
->v
.val_loc
, outfile
);
5816 fprintf (outfile
, " (%p)\n", (void *) val
->v
.val_loc
);
5818 case dw_val_class_loc_list
:
5819 fprintf (outfile
, "location list -> label:%s",
5820 val
->v
.val_loc_list
->ll_symbol
);
5822 case dw_val_class_range_list
:
5823 fprintf (outfile
, "range list");
5825 case dw_val_class_const
:
5826 case dw_val_class_const_implicit
:
5827 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, val
->v
.val_int
);
5829 case dw_val_class_unsigned_const
:
5830 case dw_val_class_unsigned_const_implicit
:
5831 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, val
->v
.val_unsigned
);
5833 case dw_val_class_const_double
:
5834 fprintf (outfile
, "constant (" HOST_WIDE_INT_PRINT_DEC
","\
5835 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5836 val
->v
.val_double
.high
,
5837 val
->v
.val_double
.low
);
5839 case dw_val_class_wide_int
:
5841 int i
= val
->v
.val_wide
->get_len ();
5842 fprintf (outfile
, "constant (");
5844 if (val
->v
.val_wide
->elt (i
- 1) == 0)
5845 fprintf (outfile
, "0x");
5846 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
,
5847 val
->v
.val_wide
->elt (--i
));
5849 fprintf (outfile
, HOST_WIDE_INT_PRINT_PADDED_HEX
,
5850 val
->v
.val_wide
->elt (i
));
5851 fprintf (outfile
, ")");
5854 case dw_val_class_vec
:
5855 fprintf (outfile
, "floating-point or vector constant");
5857 case dw_val_class_flag
:
5858 fprintf (outfile
, "%u", val
->v
.val_flag
);
5860 case dw_val_class_die_ref
:
5861 if (val
->v
.val_die_ref
.die
!= NULL
)
5863 dw_die_ref die
= val
->v
.val_die_ref
.die
;
5865 if (die
->comdat_type_p
)
5867 fprintf (outfile
, "die -> signature: ");
5868 print_signature (outfile
,
5869 die
->die_id
.die_type_node
->signature
);
5871 else if (die
->die_id
.die_symbol
)
5872 fprintf (outfile
, "die -> label: %s", die
->die_id
.die_symbol
);
5874 fprintf (outfile
, "die -> %ld", die
->die_offset
);
5875 fprintf (outfile
, " (%p)", (void *) die
);
5878 fprintf (outfile
, "die -> <null>");
5880 case dw_val_class_vms_delta
:
5881 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5882 val
->v
.val_vms_delta
.lbl2
, val
->v
.val_vms_delta
.lbl1
);
5884 case dw_val_class_lbl_id
:
5885 case dw_val_class_lineptr
:
5886 case dw_val_class_macptr
:
5887 case dw_val_class_loclistsptr
:
5888 case dw_val_class_high_pc
:
5889 fprintf (outfile
, "label: %s", val
->v
.val_lbl_id
);
5891 case dw_val_class_str
:
5892 if (val
->v
.val_str
->str
!= NULL
)
5893 fprintf (outfile
, "\"%s\"", val
->v
.val_str
->str
);
5895 fprintf (outfile
, "<null>");
5897 case dw_val_class_file
:
5898 case dw_val_class_file_implicit
:
5899 fprintf (outfile
, "\"%s\" (%d)", val
->v
.val_file
->filename
,
5900 val
->v
.val_file
->emitted_number
);
5902 case dw_val_class_data8
:
5906 for (i
= 0; i
< 8; i
++)
5907 fprintf (outfile
, "%02x", val
->v
.val_data8
[i
]);
5910 case dw_val_class_discr_value
:
5911 print_discr_value (outfile
, &val
->v
.val_discr_value
);
5913 case dw_val_class_discr_list
:
5914 for (dw_discr_list_ref node
= val
->v
.val_discr_list
;
5916 node
= node
->dw_discr_next
)
5918 if (node
->dw_discr_range
)
5920 fprintf (outfile
, " .. ");
5921 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
5922 print_discr_value (outfile
, &node
->dw_discr_upper_bound
);
5925 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
5927 if (node
->dw_discr_next
!= NULL
)
5928 fprintf (outfile
, " | ");
5935 /* Likewise, for a DIE attribute. */
5938 print_attribute (dw_attr_node
*a
, bool recurse
, FILE *outfile
)
5940 print_dw_val (&a
->dw_attr_val
, recurse
, outfile
);
5944 /* Print the list of operands in the LOC location description to OUTFILE. This
5945 routine is a debugging aid only. */
5948 print_loc_descr (dw_loc_descr_ref loc
, FILE *outfile
)
5950 dw_loc_descr_ref l
= loc
;
5954 print_spaces (outfile
);
5955 fprintf (outfile
, "<null>\n");
5959 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
5961 print_spaces (outfile
);
5962 fprintf (outfile
, "(%p) %s",
5964 dwarf_stack_op_name (l
->dw_loc_opc
));
5965 if (l
->dw_loc_oprnd1
.val_class
!= dw_val_class_none
)
5967 fprintf (outfile
, " ");
5968 print_dw_val (&l
->dw_loc_oprnd1
, false, outfile
);
5970 if (l
->dw_loc_oprnd2
.val_class
!= dw_val_class_none
)
5972 fprintf (outfile
, ", ");
5973 print_dw_val (&l
->dw_loc_oprnd2
, false, outfile
);
5975 fprintf (outfile
, "\n");
5979 /* Print the information associated with a given DIE, and its children.
5980 This routine is a debugging aid only. */
5983 print_die (dw_die_ref die
, FILE *outfile
)
5989 print_spaces (outfile
);
5990 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5991 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5993 print_spaces (outfile
);
5994 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5995 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5996 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5998 if (die
->comdat_type_p
)
6000 print_spaces (outfile
);
6001 fprintf (outfile
, " signature: ");
6002 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
6003 fprintf (outfile
, "\n");
6006 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6008 print_spaces (outfile
);
6009 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
6011 print_attribute (a
, true, outfile
);
6012 fprintf (outfile
, "\n");
6015 if (die
->die_child
!= NULL
)
6018 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
6021 if (print_indent
== 0)
6022 fprintf (outfile
, "\n");
6025 /* Print the list of operations in the LOC location description. */
6028 debug_dwarf_loc_descr (dw_loc_descr_ref loc
)
6030 print_loc_descr (loc
, stderr
);
6033 /* Print the information collected for a given DIE. */
6036 debug_dwarf_die (dw_die_ref die
)
6038 print_die (die
, stderr
);
6042 debug (die_struct
&ref
)
6044 print_die (&ref
, stderr
);
6048 debug (die_struct
*ptr
)
6053 fprintf (stderr
, "<nil>\n");
6057 /* Print all DWARF information collected for the compilation unit.
6058 This routine is a debugging aid only. */
6064 print_die (comp_unit_die (), stderr
);
6067 /* Verify the DIE tree structure. */
6070 verify_die (dw_die_ref die
)
6072 gcc_assert (!die
->die_mark
);
6073 if (die
->die_parent
== NULL
6074 && die
->die_sib
== NULL
)
6076 /* Verify the die_sib list is cyclic. */
6083 while (x
&& !x
->die_mark
);
6084 gcc_assert (x
== die
);
6088 /* Verify all dies have the same parent. */
6089 gcc_assert (x
->die_parent
== die
->die_parent
);
6092 /* Verify the child has the proper parent and recurse. */
6093 gcc_assert (x
->die_child
->die_parent
== x
);
6094 verify_die (x
->die_child
);
6099 while (x
&& x
->die_mark
);
6102 /* Sanity checks on DIEs. */
6105 check_die (dw_die_ref die
)
6109 bool inline_found
= false;
6110 int n_location
= 0, n_low_pc
= 0, n_high_pc
= 0, n_artificial
= 0;
6111 int n_decl_line
= 0, n_decl_file
= 0;
6112 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6117 if (a
->dw_attr_val
.v
.val_unsigned
)
6118 inline_found
= true;
6120 case DW_AT_location
:
6129 case DW_AT_artificial
:
6132 case DW_AT_decl_line
:
6135 case DW_AT_decl_file
:
6142 if (n_location
> 1 || n_low_pc
> 1 || n_high_pc
> 1 || n_artificial
> 1
6143 || n_decl_line
> 1 || n_decl_file
> 1)
6145 fprintf (stderr
, "Duplicate attributes in DIE:\n");
6146 debug_dwarf_die (die
);
6151 /* A debugging information entry that is a member of an abstract
6152 instance tree [that has DW_AT_inline] should not contain any
6153 attributes which describe aspects of the subroutine which vary
6154 between distinct inlined expansions or distinct out-of-line
6156 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6157 gcc_assert (a
->dw_attr
!= DW_AT_low_pc
6158 && a
->dw_attr
!= DW_AT_high_pc
6159 && a
->dw_attr
!= DW_AT_location
6160 && a
->dw_attr
!= DW_AT_frame_base
6161 && a
->dw_attr
!= DW_AT_call_all_calls
6162 && a
->dw_attr
!= DW_AT_GNU_all_call_sites
);
6166 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
6167 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
6168 DIE that marks the start of the DIEs for this include file. */
6171 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
6173 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
6174 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
6176 new_unit
->die_sib
= old_unit
;
6180 /* Close an include-file CU and reopen the enclosing one. */
6183 pop_compile_unit (dw_die_ref old_unit
)
6185 dw_die_ref new_unit
= old_unit
->die_sib
;
6187 old_unit
->die_sib
= NULL
;
6191 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6192 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
6193 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
6195 /* Calculate the checksum of a location expression. */
6198 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
6201 inchash::hash hstate
;
6204 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
6206 hash_loc_operands (loc
, hstate
);
6207 hash
= hstate
.end();
6211 /* Calculate the checksum of an attribute. */
6214 attr_checksum (dw_attr_node
*at
, struct md5_ctx
*ctx
, int *mark
)
6216 dw_loc_descr_ref loc
;
6219 CHECKSUM (at
->dw_attr
);
6221 /* We don't care that this was compiled with a different compiler
6222 snapshot; if the output is the same, that's what matters. */
6223 if (at
->dw_attr
== DW_AT_producer
)
6226 switch (AT_class (at
))
6228 case dw_val_class_const
:
6229 case dw_val_class_const_implicit
:
6230 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
6232 case dw_val_class_unsigned_const
:
6233 case dw_val_class_unsigned_const_implicit
:
6234 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
6236 case dw_val_class_const_double
:
6237 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
6239 case dw_val_class_wide_int
:
6240 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
6241 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6242 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
6244 case dw_val_class_vec
:
6245 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
6246 (at
->dw_attr_val
.v
.val_vec
.length
6247 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
6249 case dw_val_class_flag
:
6250 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
6252 case dw_val_class_str
:
6253 CHECKSUM_STRING (AT_string (at
));
6256 case dw_val_class_addr
:
6258 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6259 CHECKSUM_STRING (XSTR (r
, 0));
6262 case dw_val_class_offset
:
6263 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
6266 case dw_val_class_loc
:
6267 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6268 loc_checksum (loc
, ctx
);
6271 case dw_val_class_die_ref
:
6272 die_checksum (AT_ref (at
), ctx
, mark
);
6275 case dw_val_class_fde_ref
:
6276 case dw_val_class_vms_delta
:
6277 case dw_val_class_lbl_id
:
6278 case dw_val_class_lineptr
:
6279 case dw_val_class_macptr
:
6280 case dw_val_class_loclistsptr
:
6281 case dw_val_class_high_pc
:
6284 case dw_val_class_file
:
6285 case dw_val_class_file_implicit
:
6286 CHECKSUM_STRING (AT_file (at
)->filename
);
6289 case dw_val_class_data8
:
6290 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6298 /* Calculate the checksum of a DIE. */
6301 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6307 /* To avoid infinite recursion. */
6310 CHECKSUM (die
->die_mark
);
6313 die
->die_mark
= ++(*mark
);
6315 CHECKSUM (die
->die_tag
);
6317 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6318 attr_checksum (a
, ctx
, mark
);
6320 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
6324 #undef CHECKSUM_BLOCK
6325 #undef CHECKSUM_STRING
6327 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
6328 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6329 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
6330 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
6331 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
6332 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
6333 #define CHECKSUM_ATTR(FOO) \
6334 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
6336 /* Calculate the checksum of a number in signed LEB128 format. */
6339 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
6346 byte
= (value
& 0x7f);
6348 more
= !((value
== 0 && (byte
& 0x40) == 0)
6349 || (value
== -1 && (byte
& 0x40) != 0));
6358 /* Calculate the checksum of a number in unsigned LEB128 format. */
6361 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
6365 unsigned char byte
= (value
& 0x7f);
6368 /* More bytes to follow. */
6376 /* Checksum the context of the DIE. This adds the names of any
6377 surrounding namespaces or structures to the checksum. */
6380 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
6384 int tag
= die
->die_tag
;
6386 if (tag
!= DW_TAG_namespace
6387 && tag
!= DW_TAG_structure_type
6388 && tag
!= DW_TAG_class_type
)
6391 name
= get_AT_string (die
, DW_AT_name
);
6393 spec
= get_AT_ref (die
, DW_AT_specification
);
6397 if (die
->die_parent
!= NULL
)
6398 checksum_die_context (die
->die_parent
, ctx
);
6400 CHECKSUM_ULEB128 ('C');
6401 CHECKSUM_ULEB128 (tag
);
6403 CHECKSUM_STRING (name
);
6406 /* Calculate the checksum of a location expression. */
6409 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
6411 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
6412 were emitted as a DW_FORM_sdata instead of a location expression. */
6413 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
6415 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6416 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
6420 /* Otherwise, just checksum the raw location expression. */
6423 inchash::hash hstate
;
6426 CHECKSUM_ULEB128 (loc
->dtprel
);
6427 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
6428 hash_loc_operands (loc
, hstate
);
6429 hash
= hstate
.end ();
6431 loc
= loc
->dw_loc_next
;
6435 /* Calculate the checksum of an attribute. */
6438 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_node
*at
,
6439 struct md5_ctx
*ctx
, int *mark
)
6441 dw_loc_descr_ref loc
;
6444 if (AT_class (at
) == dw_val_class_die_ref
)
6446 dw_die_ref target_die
= AT_ref (at
);
6448 /* For pointer and reference types, we checksum only the (qualified)
6449 name of the target type (if there is a name). For friend entries,
6450 we checksum only the (qualified) name of the target type or function.
6451 This allows the checksum to remain the same whether the target type
6452 is complete or not. */
6453 if ((at
->dw_attr
== DW_AT_type
6454 && (tag
== DW_TAG_pointer_type
6455 || tag
== DW_TAG_reference_type
6456 || tag
== DW_TAG_rvalue_reference_type
6457 || tag
== DW_TAG_ptr_to_member_type
))
6458 || (at
->dw_attr
== DW_AT_friend
6459 && tag
== DW_TAG_friend
))
6461 dw_attr_node
*name_attr
= get_AT (target_die
, DW_AT_name
);
6463 if (name_attr
!= NULL
)
6465 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6469 CHECKSUM_ULEB128 ('N');
6470 CHECKSUM_ULEB128 (at
->dw_attr
);
6471 if (decl
->die_parent
!= NULL
)
6472 checksum_die_context (decl
->die_parent
, ctx
);
6473 CHECKSUM_ULEB128 ('E');
6474 CHECKSUM_STRING (AT_string (name_attr
));
6479 /* For all other references to another DIE, we check to see if the
6480 target DIE has already been visited. If it has, we emit a
6481 backward reference; if not, we descend recursively. */
6482 if (target_die
->die_mark
> 0)
6484 CHECKSUM_ULEB128 ('R');
6485 CHECKSUM_ULEB128 (at
->dw_attr
);
6486 CHECKSUM_ULEB128 (target_die
->die_mark
);
6490 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6494 target_die
->die_mark
= ++(*mark
);
6495 CHECKSUM_ULEB128 ('T');
6496 CHECKSUM_ULEB128 (at
->dw_attr
);
6497 if (decl
->die_parent
!= NULL
)
6498 checksum_die_context (decl
->die_parent
, ctx
);
6499 die_checksum_ordered (target_die
, ctx
, mark
);
6504 CHECKSUM_ULEB128 ('A');
6505 CHECKSUM_ULEB128 (at
->dw_attr
);
6507 switch (AT_class (at
))
6509 case dw_val_class_const
:
6510 case dw_val_class_const_implicit
:
6511 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6512 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
6515 case dw_val_class_unsigned_const
:
6516 case dw_val_class_unsigned_const_implicit
:
6517 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6518 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
6521 case dw_val_class_const_double
:
6522 CHECKSUM_ULEB128 (DW_FORM_block
);
6523 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
6524 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
6527 case dw_val_class_wide_int
:
6528 CHECKSUM_ULEB128 (DW_FORM_block
);
6529 CHECKSUM_ULEB128 (get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6530 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
6531 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
6532 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6533 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
6536 case dw_val_class_vec
:
6537 CHECKSUM_ULEB128 (DW_FORM_block
);
6538 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
6539 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
6540 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
6541 (at
->dw_attr_val
.v
.val_vec
.length
6542 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
6545 case dw_val_class_flag
:
6546 CHECKSUM_ULEB128 (DW_FORM_flag
);
6547 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
6550 case dw_val_class_str
:
6551 CHECKSUM_ULEB128 (DW_FORM_string
);
6552 CHECKSUM_STRING (AT_string (at
));
6555 case dw_val_class_addr
:
6557 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6558 CHECKSUM_ULEB128 (DW_FORM_string
);
6559 CHECKSUM_STRING (XSTR (r
, 0));
6562 case dw_val_class_offset
:
6563 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6564 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
6567 case dw_val_class_loc
:
6568 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6569 loc_checksum_ordered (loc
, ctx
);
6572 case dw_val_class_fde_ref
:
6573 case dw_val_class_lbl_id
:
6574 case dw_val_class_lineptr
:
6575 case dw_val_class_macptr
:
6576 case dw_val_class_loclistsptr
:
6577 case dw_val_class_high_pc
:
6580 case dw_val_class_file
:
6581 case dw_val_class_file_implicit
:
6582 CHECKSUM_ULEB128 (DW_FORM_string
);
6583 CHECKSUM_STRING (AT_file (at
)->filename
);
6586 case dw_val_class_data8
:
6587 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6595 struct checksum_attributes
6597 dw_attr_node
*at_name
;
6598 dw_attr_node
*at_type
;
6599 dw_attr_node
*at_friend
;
6600 dw_attr_node
*at_accessibility
;
6601 dw_attr_node
*at_address_class
;
6602 dw_attr_node
*at_allocated
;
6603 dw_attr_node
*at_artificial
;
6604 dw_attr_node
*at_associated
;
6605 dw_attr_node
*at_binary_scale
;
6606 dw_attr_node
*at_bit_offset
;
6607 dw_attr_node
*at_bit_size
;
6608 dw_attr_node
*at_bit_stride
;
6609 dw_attr_node
*at_byte_size
;
6610 dw_attr_node
*at_byte_stride
;
6611 dw_attr_node
*at_const_value
;
6612 dw_attr_node
*at_containing_type
;
6613 dw_attr_node
*at_count
;
6614 dw_attr_node
*at_data_location
;
6615 dw_attr_node
*at_data_member_location
;
6616 dw_attr_node
*at_decimal_scale
;
6617 dw_attr_node
*at_decimal_sign
;
6618 dw_attr_node
*at_default_value
;
6619 dw_attr_node
*at_digit_count
;
6620 dw_attr_node
*at_discr
;
6621 dw_attr_node
*at_discr_list
;
6622 dw_attr_node
*at_discr_value
;
6623 dw_attr_node
*at_encoding
;
6624 dw_attr_node
*at_endianity
;
6625 dw_attr_node
*at_explicit
;
6626 dw_attr_node
*at_is_optional
;
6627 dw_attr_node
*at_location
;
6628 dw_attr_node
*at_lower_bound
;
6629 dw_attr_node
*at_mutable
;
6630 dw_attr_node
*at_ordering
;
6631 dw_attr_node
*at_picture_string
;
6632 dw_attr_node
*at_prototyped
;
6633 dw_attr_node
*at_small
;
6634 dw_attr_node
*at_segment
;
6635 dw_attr_node
*at_string_length
;
6636 dw_attr_node
*at_string_length_bit_size
;
6637 dw_attr_node
*at_string_length_byte_size
;
6638 dw_attr_node
*at_threads_scaled
;
6639 dw_attr_node
*at_upper_bound
;
6640 dw_attr_node
*at_use_location
;
6641 dw_attr_node
*at_use_UTF8
;
6642 dw_attr_node
*at_variable_parameter
;
6643 dw_attr_node
*at_virtuality
;
6644 dw_attr_node
*at_visibility
;
6645 dw_attr_node
*at_vtable_elem_location
;
6648 /* Collect the attributes that we will want to use for the checksum. */
6651 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
6656 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6667 attrs
->at_friend
= a
;
6669 case DW_AT_accessibility
:
6670 attrs
->at_accessibility
= a
;
6672 case DW_AT_address_class
:
6673 attrs
->at_address_class
= a
;
6675 case DW_AT_allocated
:
6676 attrs
->at_allocated
= a
;
6678 case DW_AT_artificial
:
6679 attrs
->at_artificial
= a
;
6681 case DW_AT_associated
:
6682 attrs
->at_associated
= a
;
6684 case DW_AT_binary_scale
:
6685 attrs
->at_binary_scale
= a
;
6687 case DW_AT_bit_offset
:
6688 attrs
->at_bit_offset
= a
;
6690 case DW_AT_bit_size
:
6691 attrs
->at_bit_size
= a
;
6693 case DW_AT_bit_stride
:
6694 attrs
->at_bit_stride
= a
;
6696 case DW_AT_byte_size
:
6697 attrs
->at_byte_size
= a
;
6699 case DW_AT_byte_stride
:
6700 attrs
->at_byte_stride
= a
;
6702 case DW_AT_const_value
:
6703 attrs
->at_const_value
= a
;
6705 case DW_AT_containing_type
:
6706 attrs
->at_containing_type
= a
;
6709 attrs
->at_count
= a
;
6711 case DW_AT_data_location
:
6712 attrs
->at_data_location
= a
;
6714 case DW_AT_data_member_location
:
6715 attrs
->at_data_member_location
= a
;
6717 case DW_AT_decimal_scale
:
6718 attrs
->at_decimal_scale
= a
;
6720 case DW_AT_decimal_sign
:
6721 attrs
->at_decimal_sign
= a
;
6723 case DW_AT_default_value
:
6724 attrs
->at_default_value
= a
;
6726 case DW_AT_digit_count
:
6727 attrs
->at_digit_count
= a
;
6730 attrs
->at_discr
= a
;
6732 case DW_AT_discr_list
:
6733 attrs
->at_discr_list
= a
;
6735 case DW_AT_discr_value
:
6736 attrs
->at_discr_value
= a
;
6738 case DW_AT_encoding
:
6739 attrs
->at_encoding
= a
;
6741 case DW_AT_endianity
:
6742 attrs
->at_endianity
= a
;
6744 case DW_AT_explicit
:
6745 attrs
->at_explicit
= a
;
6747 case DW_AT_is_optional
:
6748 attrs
->at_is_optional
= a
;
6750 case DW_AT_location
:
6751 attrs
->at_location
= a
;
6753 case DW_AT_lower_bound
:
6754 attrs
->at_lower_bound
= a
;
6757 attrs
->at_mutable
= a
;
6759 case DW_AT_ordering
:
6760 attrs
->at_ordering
= a
;
6762 case DW_AT_picture_string
:
6763 attrs
->at_picture_string
= a
;
6765 case DW_AT_prototyped
:
6766 attrs
->at_prototyped
= a
;
6769 attrs
->at_small
= a
;
6772 attrs
->at_segment
= a
;
6774 case DW_AT_string_length
:
6775 attrs
->at_string_length
= a
;
6777 case DW_AT_string_length_bit_size
:
6778 attrs
->at_string_length_bit_size
= a
;
6780 case DW_AT_string_length_byte_size
:
6781 attrs
->at_string_length_byte_size
= a
;
6783 case DW_AT_threads_scaled
:
6784 attrs
->at_threads_scaled
= a
;
6786 case DW_AT_upper_bound
:
6787 attrs
->at_upper_bound
= a
;
6789 case DW_AT_use_location
:
6790 attrs
->at_use_location
= a
;
6792 case DW_AT_use_UTF8
:
6793 attrs
->at_use_UTF8
= a
;
6795 case DW_AT_variable_parameter
:
6796 attrs
->at_variable_parameter
= a
;
6798 case DW_AT_virtuality
:
6799 attrs
->at_virtuality
= a
;
6801 case DW_AT_visibility
:
6802 attrs
->at_visibility
= a
;
6804 case DW_AT_vtable_elem_location
:
6805 attrs
->at_vtable_elem_location
= a
;
6813 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6816 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6820 struct checksum_attributes attrs
;
6822 CHECKSUM_ULEB128 ('D');
6823 CHECKSUM_ULEB128 (die
->die_tag
);
6825 memset (&attrs
, 0, sizeof (attrs
));
6827 decl
= get_AT_ref (die
, DW_AT_specification
);
6829 collect_checksum_attributes (&attrs
, decl
);
6830 collect_checksum_attributes (&attrs
, die
);
6832 CHECKSUM_ATTR (attrs
.at_name
);
6833 CHECKSUM_ATTR (attrs
.at_accessibility
);
6834 CHECKSUM_ATTR (attrs
.at_address_class
);
6835 CHECKSUM_ATTR (attrs
.at_allocated
);
6836 CHECKSUM_ATTR (attrs
.at_artificial
);
6837 CHECKSUM_ATTR (attrs
.at_associated
);
6838 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6839 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6840 CHECKSUM_ATTR (attrs
.at_bit_size
);
6841 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6842 CHECKSUM_ATTR (attrs
.at_byte_size
);
6843 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6844 CHECKSUM_ATTR (attrs
.at_const_value
);
6845 CHECKSUM_ATTR (attrs
.at_containing_type
);
6846 CHECKSUM_ATTR (attrs
.at_count
);
6847 CHECKSUM_ATTR (attrs
.at_data_location
);
6848 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6849 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6850 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6851 CHECKSUM_ATTR (attrs
.at_default_value
);
6852 CHECKSUM_ATTR (attrs
.at_digit_count
);
6853 CHECKSUM_ATTR (attrs
.at_discr
);
6854 CHECKSUM_ATTR (attrs
.at_discr_list
);
6855 CHECKSUM_ATTR (attrs
.at_discr_value
);
6856 CHECKSUM_ATTR (attrs
.at_encoding
);
6857 CHECKSUM_ATTR (attrs
.at_endianity
);
6858 CHECKSUM_ATTR (attrs
.at_explicit
);
6859 CHECKSUM_ATTR (attrs
.at_is_optional
);
6860 CHECKSUM_ATTR (attrs
.at_location
);
6861 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6862 CHECKSUM_ATTR (attrs
.at_mutable
);
6863 CHECKSUM_ATTR (attrs
.at_ordering
);
6864 CHECKSUM_ATTR (attrs
.at_picture_string
);
6865 CHECKSUM_ATTR (attrs
.at_prototyped
);
6866 CHECKSUM_ATTR (attrs
.at_small
);
6867 CHECKSUM_ATTR (attrs
.at_segment
);
6868 CHECKSUM_ATTR (attrs
.at_string_length
);
6869 CHECKSUM_ATTR (attrs
.at_string_length_bit_size
);
6870 CHECKSUM_ATTR (attrs
.at_string_length_byte_size
);
6871 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6872 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6873 CHECKSUM_ATTR (attrs
.at_use_location
);
6874 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6875 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6876 CHECKSUM_ATTR (attrs
.at_virtuality
);
6877 CHECKSUM_ATTR (attrs
.at_visibility
);
6878 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6879 CHECKSUM_ATTR (attrs
.at_type
);
6880 CHECKSUM_ATTR (attrs
.at_friend
);
6882 /* Checksum the child DIEs. */
6885 dw_attr_node
*name_attr
;
6888 name_attr
= get_AT (c
, DW_AT_name
);
6889 if (is_template_instantiation (c
))
6891 /* Ignore instantiations of member type and function templates. */
6893 else if (name_attr
!= NULL
6894 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
6896 /* Use a shallow checksum for named nested types and member
6898 CHECKSUM_ULEB128 ('S');
6899 CHECKSUM_ULEB128 (c
->die_tag
);
6900 CHECKSUM_STRING (AT_string (name_attr
));
6904 /* Use a deep checksum for other children. */
6905 /* Mark this DIE so it gets processed when unmarking. */
6906 if (c
->die_mark
== 0)
6908 die_checksum_ordered (c
, ctx
, mark
);
6910 } while (c
!= die
->die_child
);
6912 CHECKSUM_ULEB128 (0);
6915 /* Add a type name and tag to a hash. */
6917 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
6919 CHECKSUM_ULEB128 (tag
);
6920 CHECKSUM_STRING (name
);
6924 #undef CHECKSUM_STRING
6925 #undef CHECKSUM_ATTR
6926 #undef CHECKSUM_LEB128
6927 #undef CHECKSUM_ULEB128
6929 /* Generate the type signature for DIE. This is computed by generating an
6930 MD5 checksum over the DIE's tag, its relevant attributes, and its
6931 children. Attributes that are references to other DIEs are processed
6932 by recursion, using the MARK field to prevent infinite recursion.
6933 If the DIE is nested inside a namespace or another type, we also
6934 need to include that context in the signature. The lower 64 bits
6935 of the resulting MD5 checksum comprise the signature. */
6938 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6942 unsigned char checksum
[16];
6947 name
= get_AT_string (die
, DW_AT_name
);
6948 decl
= get_AT_ref (die
, DW_AT_specification
);
6949 parent
= get_die_parent (die
);
6951 /* First, compute a signature for just the type name (and its surrounding
6952 context, if any. This is stored in the type unit DIE for link-time
6953 ODR (one-definition rule) checking. */
6955 if (is_cxx () && name
!= NULL
)
6957 md5_init_ctx (&ctx
);
6959 /* Checksum the names of surrounding namespaces and structures. */
6961 checksum_die_context (parent
, &ctx
);
6963 /* Checksum the current DIE. */
6964 die_odr_checksum (die
->die_tag
, name
, &ctx
);
6965 md5_finish_ctx (&ctx
, checksum
);
6967 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6970 /* Next, compute the complete type signature. */
6972 md5_init_ctx (&ctx
);
6974 die
->die_mark
= mark
;
6976 /* Checksum the names of surrounding namespaces and structures. */
6978 checksum_die_context (parent
, &ctx
);
6980 /* Checksum the DIE and its children. */
6981 die_checksum_ordered (die
, &ctx
, &mark
);
6982 unmark_all_dies (die
);
6983 md5_finish_ctx (&ctx
, checksum
);
6985 /* Store the signature in the type node and link the type DIE and the
6986 type node together. */
6987 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6988 DWARF_TYPE_SIGNATURE_SIZE
);
6989 die
->comdat_type_p
= true;
6990 die
->die_id
.die_type_node
= type_node
;
6991 type_node
->type_die
= die
;
6993 /* If the DIE is a specification, link its declaration to the type node
6997 decl
->comdat_type_p
= true;
6998 decl
->die_id
.die_type_node
= type_node
;
7002 /* Do the location expressions look same? */
7004 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
7006 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
7007 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
7008 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
7011 /* Do the values look the same? */
7013 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
7015 dw_loc_descr_ref loc1
, loc2
;
7018 if (v1
->val_class
!= v2
->val_class
)
7021 switch (v1
->val_class
)
7023 case dw_val_class_const
:
7024 case dw_val_class_const_implicit
:
7025 return v1
->v
.val_int
== v2
->v
.val_int
;
7026 case dw_val_class_unsigned_const
:
7027 case dw_val_class_unsigned_const_implicit
:
7028 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
7029 case dw_val_class_const_double
:
7030 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
7031 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
7032 case dw_val_class_wide_int
:
7033 return *v1
->v
.val_wide
== *v2
->v
.val_wide
;
7034 case dw_val_class_vec
:
7035 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
7036 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
7038 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
7039 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
7042 case dw_val_class_flag
:
7043 return v1
->v
.val_flag
== v2
->v
.val_flag
;
7044 case dw_val_class_str
:
7045 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
7047 case dw_val_class_addr
:
7048 r1
= v1
->v
.val_addr
;
7049 r2
= v2
->v
.val_addr
;
7050 if (GET_CODE (r1
) != GET_CODE (r2
))
7052 return !rtx_equal_p (r1
, r2
);
7054 case dw_val_class_offset
:
7055 return v1
->v
.val_offset
== v2
->v
.val_offset
;
7057 case dw_val_class_loc
:
7058 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
7060 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
7061 if (!same_loc_p (loc1
, loc2
, mark
))
7063 return !loc1
&& !loc2
;
7065 case dw_val_class_die_ref
:
7066 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
7068 case dw_val_class_fde_ref
:
7069 case dw_val_class_vms_delta
:
7070 case dw_val_class_lbl_id
:
7071 case dw_val_class_lineptr
:
7072 case dw_val_class_macptr
:
7073 case dw_val_class_loclistsptr
:
7074 case dw_val_class_high_pc
:
7077 case dw_val_class_file
:
7078 case dw_val_class_file_implicit
:
7079 return v1
->v
.val_file
== v2
->v
.val_file
;
7081 case dw_val_class_data8
:
7082 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
7089 /* Do the attributes look the same? */
7092 same_attr_p (dw_attr_node
*at1
, dw_attr_node
*at2
, int *mark
)
7094 if (at1
->dw_attr
!= at2
->dw_attr
)
7097 /* We don't care that this was compiled with a different compiler
7098 snapshot; if the output is the same, that's what matters. */
7099 if (at1
->dw_attr
== DW_AT_producer
)
7102 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
7105 /* Do the dies look the same? */
7108 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
7114 /* To avoid infinite recursion. */
7116 return die1
->die_mark
== die2
->die_mark
;
7117 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
7119 if (die1
->die_tag
!= die2
->die_tag
)
7122 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
7125 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
7126 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
7129 c1
= die1
->die_child
;
7130 c2
= die2
->die_child
;
7139 if (!same_die_p (c1
, c2
, mark
))
7143 if (c1
== die1
->die_child
)
7145 if (c2
== die2
->die_child
)
7155 /* Do the dies look the same? Wrapper around same_die_p. */
7158 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
7161 int ret
= same_die_p (die1
, die2
, &mark
);
7163 unmark_all_dies (die1
);
7164 unmark_all_dies (die2
);
7169 /* The prefix to attach to symbols on DIEs in the current comdat debug
7171 static const char *comdat_symbol_id
;
7173 /* The index of the current symbol within the current comdat CU. */
7174 static unsigned int comdat_symbol_number
;
7176 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
7177 children, and set comdat_symbol_id accordingly. */
7180 compute_section_prefix (dw_die_ref unit_die
)
7182 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
7183 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
7184 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
7187 unsigned char checksum
[16];
7190 /* Compute the checksum of the DIE, then append part of it as hex digits to
7191 the name filename of the unit. */
7193 md5_init_ctx (&ctx
);
7195 die_checksum (unit_die
, &ctx
, &mark
);
7196 unmark_all_dies (unit_die
);
7197 md5_finish_ctx (&ctx
, checksum
);
7199 sprintf (name
, "%s.", base
);
7200 clean_symbol_name (name
);
7202 p
= name
+ strlen (name
);
7203 for (i
= 0; i
< 4; i
++)
7205 sprintf (p
, "%.2x", checksum
[i
]);
7209 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
7210 comdat_symbol_number
= 0;
7213 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
7216 is_type_die (dw_die_ref die
)
7218 switch (die
->die_tag
)
7220 case DW_TAG_array_type
:
7221 case DW_TAG_class_type
:
7222 case DW_TAG_interface_type
:
7223 case DW_TAG_enumeration_type
:
7224 case DW_TAG_pointer_type
:
7225 case DW_TAG_reference_type
:
7226 case DW_TAG_rvalue_reference_type
:
7227 case DW_TAG_string_type
:
7228 case DW_TAG_structure_type
:
7229 case DW_TAG_subroutine_type
:
7230 case DW_TAG_union_type
:
7231 case DW_TAG_ptr_to_member_type
:
7232 case DW_TAG_set_type
:
7233 case DW_TAG_subrange_type
:
7234 case DW_TAG_base_type
:
7235 case DW_TAG_const_type
:
7236 case DW_TAG_file_type
:
7237 case DW_TAG_packed_type
:
7238 case DW_TAG_volatile_type
:
7239 case DW_TAG_typedef
:
7246 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
7247 Basically, we want to choose the bits that are likely to be shared between
7248 compilations (types) and leave out the bits that are specific to individual
7249 compilations (functions). */
7252 is_comdat_die (dw_die_ref c
)
7254 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
7255 we do for stabs. The advantage is a greater likelihood of sharing between
7256 objects that don't include headers in the same order (and therefore would
7257 put the base types in a different comdat). jason 8/28/00 */
7259 if (c
->die_tag
== DW_TAG_base_type
)
7262 if (c
->die_tag
== DW_TAG_pointer_type
7263 || c
->die_tag
== DW_TAG_reference_type
7264 || c
->die_tag
== DW_TAG_rvalue_reference_type
7265 || c
->die_tag
== DW_TAG_const_type
7266 || c
->die_tag
== DW_TAG_volatile_type
)
7268 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
7270 return t
? is_comdat_die (t
) : 0;
7273 return is_type_die (c
);
7276 /* Returns 1 iff C is the sort of DIE that might be referred to from another
7277 compilation unit. */
7280 is_symbol_die (dw_die_ref c
)
7282 return (is_type_die (c
)
7283 || is_declaration_die (c
)
7284 || c
->die_tag
== DW_TAG_namespace
7285 || c
->die_tag
== DW_TAG_module
);
7288 /* Returns true iff C is a compile-unit DIE. */
7291 is_cu_die (dw_die_ref c
)
7293 return c
&& (c
->die_tag
== DW_TAG_compile_unit
7294 || c
->die_tag
== DW_TAG_skeleton_unit
);
7297 /* Returns true iff C is a unit DIE of some sort. */
7300 is_unit_die (dw_die_ref c
)
7302 return c
&& (c
->die_tag
== DW_TAG_compile_unit
7303 || c
->die_tag
== DW_TAG_partial_unit
7304 || c
->die_tag
== DW_TAG_type_unit
7305 || c
->die_tag
== DW_TAG_skeleton_unit
);
7308 /* Returns true iff C is a namespace DIE. */
7311 is_namespace_die (dw_die_ref c
)
7313 return c
&& c
->die_tag
== DW_TAG_namespace
;
7316 /* Returns true iff C is a class or structure DIE. */
7319 is_class_die (dw_die_ref c
)
7321 return c
&& (c
->die_tag
== DW_TAG_class_type
7322 || c
->die_tag
== DW_TAG_structure_type
);
7325 /* Return non-zero if this DIE is a template parameter. */
7328 is_template_parameter (dw_die_ref die
)
7330 switch (die
->die_tag
)
7332 case DW_TAG_template_type_param
:
7333 case DW_TAG_template_value_param
:
7334 case DW_TAG_GNU_template_template_param
:
7335 case DW_TAG_GNU_template_parameter_pack
:
7342 /* Return non-zero if this DIE represents a template instantiation. */
7345 is_template_instantiation (dw_die_ref die
)
7349 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
7351 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
7356 gen_internal_sym (const char *prefix
)
7358 char buf
[MAX_ARTIFICIAL_LABEL_BYTES
];
7360 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
7361 return xstrdup (buf
);
7364 /* Assign symbols to all worthy DIEs under DIE. */
7367 assign_symbol_names (dw_die_ref die
)
7371 if (is_symbol_die (die
) && !die
->comdat_type_p
)
7373 if (comdat_symbol_id
)
7375 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
7377 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
7378 comdat_symbol_id
, comdat_symbol_number
++);
7379 die
->die_id
.die_symbol
= xstrdup (p
);
7382 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
7385 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
7388 struct cu_hash_table_entry
7391 unsigned min_comdat_num
, max_comdat_num
;
7392 struct cu_hash_table_entry
*next
;
7395 /* Helpers to manipulate hash table of CUs. */
7397 struct cu_hash_table_entry_hasher
: pointer_hash
<cu_hash_table_entry
>
7399 typedef die_struct
*compare_type
;
7400 static inline hashval_t
hash (const cu_hash_table_entry
*);
7401 static inline bool equal (const cu_hash_table_entry
*, const die_struct
*);
7402 static inline void remove (cu_hash_table_entry
*);
7406 cu_hash_table_entry_hasher::hash (const cu_hash_table_entry
*entry
)
7408 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
7412 cu_hash_table_entry_hasher::equal (const cu_hash_table_entry
*entry1
,
7413 const die_struct
*entry2
)
7415 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
7419 cu_hash_table_entry_hasher::remove (cu_hash_table_entry
*entry
)
7421 struct cu_hash_table_entry
*next
;
7431 typedef hash_table
<cu_hash_table_entry_hasher
> cu_hash_type
;
7433 /* Check whether we have already seen this CU and set up SYM_NUM
7436 check_duplicate_cu (dw_die_ref cu
, cu_hash_type
*htable
, unsigned int *sym_num
)
7438 struct cu_hash_table_entry dummy
;
7439 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
7441 dummy
.max_comdat_num
= 0;
7443 slot
= htable
->find_slot_with_hash (cu
,
7444 htab_hash_string (cu
->die_id
.die_symbol
),
7448 for (; entry
; last
= entry
, entry
= entry
->next
)
7450 if (same_die_p_wrap (cu
, entry
->cu
))
7456 *sym_num
= entry
->min_comdat_num
;
7460 entry
= XCNEW (struct cu_hash_table_entry
);
7462 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
7463 entry
->next
= *slot
;
7469 /* Record SYM_NUM to record of CU in HTABLE. */
7471 record_comdat_symbol_number (dw_die_ref cu
, cu_hash_type
*htable
,
7472 unsigned int sym_num
)
7474 struct cu_hash_table_entry
**slot
, *entry
;
7476 slot
= htable
->find_slot_with_hash (cu
,
7477 htab_hash_string (cu
->die_id
.die_symbol
),
7481 entry
->max_comdat_num
= sym_num
;
7484 /* Traverse the DIE (which is always comp_unit_die), and set up
7485 additional compilation units for each of the include files we see
7486 bracketed by BINCL/EINCL. */
7489 break_out_includes (dw_die_ref die
)
7492 dw_die_ref unit
= NULL
;
7493 limbo_die_node
*node
, **pnode
;
7497 dw_die_ref prev
= c
;
7499 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
7500 || (unit
&& is_comdat_die (c
)))
7502 dw_die_ref next
= c
->die_sib
;
7504 /* This DIE is for a secondary CU; remove it from the main one. */
7505 remove_child_with_prev (c
, prev
);
7507 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
7508 unit
= push_new_compile_unit (unit
, c
);
7509 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
7510 unit
= pop_compile_unit (unit
);
7512 add_child_die (unit
, c
);
7514 if (c
== die
->die_child
)
7517 } while (c
!= die
->die_child
);
7520 /* We can only use this in debugging, since the frontend doesn't check
7521 to make sure that we leave every include file we enter. */
7525 assign_symbol_names (die
);
7526 cu_hash_type
cu_hash_table (10);
7527 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
7533 compute_section_prefix (node
->die
);
7534 is_dupl
= check_duplicate_cu (node
->die
, &cu_hash_table
,
7535 &comdat_symbol_number
);
7536 assign_symbol_names (node
->die
);
7538 *pnode
= node
->next
;
7541 pnode
= &node
->next
;
7542 record_comdat_symbol_number (node
->die
, &cu_hash_table
,
7543 comdat_symbol_number
);
7548 /* Return non-zero if this DIE is a declaration. */
7551 is_declaration_die (dw_die_ref die
)
7556 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7557 if (a
->dw_attr
== DW_AT_declaration
)
7563 /* Return non-zero if this DIE is nested inside a subprogram. */
7566 is_nested_in_subprogram (dw_die_ref die
)
7568 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
7572 return local_scope_p (decl
);
7575 /* Return non-zero if this DIE contains a defining declaration of a
7579 contains_subprogram_definition (dw_die_ref die
)
7583 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
7585 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
7589 /* Return non-zero if this is a type DIE that should be moved to a
7590 COMDAT .debug_types section or .debug_info section with DW_UT_*type
7594 should_move_die_to_comdat (dw_die_ref die
)
7596 switch (die
->die_tag
)
7598 case DW_TAG_class_type
:
7599 case DW_TAG_structure_type
:
7600 case DW_TAG_enumeration_type
:
7601 case DW_TAG_union_type
:
7602 /* Don't move declarations, inlined instances, types nested in a
7603 subprogram, or types that contain subprogram definitions. */
7604 if (is_declaration_die (die
)
7605 || get_AT (die
, DW_AT_abstract_origin
)
7606 || is_nested_in_subprogram (die
)
7607 || contains_subprogram_definition (die
))
7610 case DW_TAG_array_type
:
7611 case DW_TAG_interface_type
:
7612 case DW_TAG_pointer_type
:
7613 case DW_TAG_reference_type
:
7614 case DW_TAG_rvalue_reference_type
:
7615 case DW_TAG_string_type
:
7616 case DW_TAG_subroutine_type
:
7617 case DW_TAG_ptr_to_member_type
:
7618 case DW_TAG_set_type
:
7619 case DW_TAG_subrange_type
:
7620 case DW_TAG_base_type
:
7621 case DW_TAG_const_type
:
7622 case DW_TAG_file_type
:
7623 case DW_TAG_packed_type
:
7624 case DW_TAG_volatile_type
:
7625 case DW_TAG_typedef
:
7631 /* Make a clone of DIE. */
7634 clone_die (dw_die_ref die
)
7640 clone
= ggc_cleared_alloc
<die_node
> ();
7641 clone
->die_tag
= die
->die_tag
;
7643 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7644 add_dwarf_attr (clone
, a
);
7649 /* Make a clone of the tree rooted at DIE. */
7652 clone_tree (dw_die_ref die
)
7655 dw_die_ref clone
= clone_die (die
);
7657 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
7662 /* Make a clone of DIE as a declaration. */
7665 clone_as_declaration (dw_die_ref die
)
7672 /* If the DIE is already a declaration, just clone it. */
7673 if (is_declaration_die (die
))
7674 return clone_die (die
);
7676 /* If the DIE is a specification, just clone its declaration DIE. */
7677 decl
= get_AT_ref (die
, DW_AT_specification
);
7680 clone
= clone_die (decl
);
7681 if (die
->comdat_type_p
)
7682 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7686 clone
= ggc_cleared_alloc
<die_node
> ();
7687 clone
->die_tag
= die
->die_tag
;
7689 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7691 /* We don't want to copy over all attributes.
7692 For example we don't want DW_AT_byte_size because otherwise we will no
7693 longer have a declaration and GDB will treat it as a definition. */
7697 case DW_AT_abstract_origin
:
7698 case DW_AT_artificial
:
7699 case DW_AT_containing_type
:
7700 case DW_AT_external
:
7703 case DW_AT_virtuality
:
7704 case DW_AT_linkage_name
:
7705 case DW_AT_MIPS_linkage_name
:
7706 add_dwarf_attr (clone
, a
);
7708 case DW_AT_byte_size
:
7714 if (die
->comdat_type_p
)
7715 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7717 add_AT_flag (clone
, DW_AT_declaration
, 1);
7722 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7724 struct decl_table_entry
7730 /* Helpers to manipulate hash table of copied declarations. */
7732 /* Hashtable helpers. */
7734 struct decl_table_entry_hasher
: free_ptr_hash
<decl_table_entry
>
7736 typedef die_struct
*compare_type
;
7737 static inline hashval_t
hash (const decl_table_entry
*);
7738 static inline bool equal (const decl_table_entry
*, const die_struct
*);
7742 decl_table_entry_hasher::hash (const decl_table_entry
*entry
)
7744 return htab_hash_pointer (entry
->orig
);
7748 decl_table_entry_hasher::equal (const decl_table_entry
*entry1
,
7749 const die_struct
*entry2
)
7751 return entry1
->orig
== entry2
;
7754 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
7756 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7757 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7758 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7759 to check if the ancestor has already been copied into UNIT. */
7762 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
,
7763 decl_hash_type
*decl_table
)
7765 dw_die_ref parent
= die
->die_parent
;
7766 dw_die_ref new_parent
= unit
;
7768 decl_table_entry
**slot
= NULL
;
7769 struct decl_table_entry
*entry
= NULL
;
7773 /* Check if the entry has already been copied to UNIT. */
7774 slot
= decl_table
->find_slot_with_hash (die
, htab_hash_pointer (die
),
7776 if (*slot
!= HTAB_EMPTY_ENTRY
)
7782 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7783 entry
= XCNEW (struct decl_table_entry
);
7791 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7794 if (!is_unit_die (parent
))
7795 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7798 copy
= clone_as_declaration (die
);
7799 add_child_die (new_parent
, copy
);
7803 /* Record the pointer to the copy. */
7809 /* Copy the declaration context to the new type unit DIE. This includes
7810 any surrounding namespace or type declarations. If the DIE has an
7811 AT_specification attribute, it also includes attributes and children
7812 attached to the specification, and returns a pointer to the original
7813 parent of the declaration DIE. Returns NULL otherwise. */
7816 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7819 dw_die_ref new_decl
;
7820 dw_die_ref orig_parent
= NULL
;
7822 decl
= get_AT_ref (die
, DW_AT_specification
);
7831 /* The original DIE will be changed to a declaration, and must
7832 be moved to be a child of the original declaration DIE. */
7833 orig_parent
= decl
->die_parent
;
7835 /* Copy the type node pointer from the new DIE to the original
7836 declaration DIE so we can forward references later. */
7837 decl
->comdat_type_p
= true;
7838 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7840 remove_AT (die
, DW_AT_specification
);
7842 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
7844 if (a
->dw_attr
!= DW_AT_name
7845 && a
->dw_attr
!= DW_AT_declaration
7846 && a
->dw_attr
!= DW_AT_external
)
7847 add_dwarf_attr (die
, a
);
7850 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
7853 if (decl
->die_parent
!= NULL
7854 && !is_unit_die (decl
->die_parent
))
7856 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
7857 if (new_decl
!= NULL
)
7859 remove_AT (new_decl
, DW_AT_signature
);
7860 add_AT_specification (die
, new_decl
);
7867 /* Generate the skeleton ancestor tree for the given NODE, then clone
7868 the DIE and add the clone into the tree. */
7871 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7873 if (node
->new_die
!= NULL
)
7876 node
->new_die
= clone_as_declaration (node
->old_die
);
7878 if (node
->parent
!= NULL
)
7880 generate_skeleton_ancestor_tree (node
->parent
);
7881 add_child_die (node
->parent
->new_die
, node
->new_die
);
7885 /* Generate a skeleton tree of DIEs containing any declarations that are
7886 found in the original tree. We traverse the tree looking for declaration
7887 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7890 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7892 skeleton_chain_node node
;
7895 dw_die_ref prev
= NULL
;
7896 dw_die_ref next
= NULL
;
7898 node
.parent
= parent
;
7900 first
= c
= parent
->old_die
->die_child
;
7904 if (prev
== NULL
|| prev
->die_sib
== c
)
7907 next
= (c
== first
? NULL
: c
->die_sib
);
7909 node
.new_die
= NULL
;
7910 if (is_declaration_die (c
))
7912 if (is_template_instantiation (c
))
7914 /* Instantiated templates do not need to be cloned into the
7915 type unit. Just move the DIE and its children back to
7916 the skeleton tree (in the main CU). */
7917 remove_child_with_prev (c
, prev
);
7918 add_child_die (parent
->new_die
, c
);
7923 /* Clone the existing DIE, move the original to the skeleton
7924 tree (which is in the main CU), and put the clone, with
7925 all the original's children, where the original came from
7926 (which is about to be moved to the type unit). */
7927 dw_die_ref clone
= clone_die (c
);
7928 move_all_children (c
, clone
);
7930 /* If the original has a DW_AT_object_pointer attribute,
7931 it would now point to a child DIE just moved to the
7932 cloned tree, so we need to remove that attribute from
7934 remove_AT (c
, DW_AT_object_pointer
);
7936 replace_child (c
, clone
, prev
);
7937 generate_skeleton_ancestor_tree (parent
);
7938 add_child_die (parent
->new_die
, c
);
7943 generate_skeleton_bottom_up (&node
);
7944 } while (next
!= NULL
);
7947 /* Wrapper function for generate_skeleton_bottom_up. */
7950 generate_skeleton (dw_die_ref die
)
7952 skeleton_chain_node node
;
7955 node
.new_die
= NULL
;
7958 /* If this type definition is nested inside another type,
7959 and is not an instantiation of a template, always leave
7960 at least a declaration in its place. */
7961 if (die
->die_parent
!= NULL
7962 && is_type_die (die
->die_parent
)
7963 && !is_template_instantiation (die
))
7964 node
.new_die
= clone_as_declaration (die
);
7966 generate_skeleton_bottom_up (&node
);
7967 return node
.new_die
;
7970 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7971 declaration. The original DIE is moved to a new compile unit so that
7972 existing references to it follow it to the new location. If any of the
7973 original DIE's descendants is a declaration, we need to replace the
7974 original DIE with a skeleton tree and move the declarations back into the
7978 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
7981 dw_die_ref skeleton
, orig_parent
;
7983 /* Copy the declaration context to the type unit DIE. If the returned
7984 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7986 orig_parent
= copy_declaration_context (unit
, child
);
7988 skeleton
= generate_skeleton (child
);
7989 if (skeleton
== NULL
)
7990 remove_child_with_prev (child
, prev
);
7993 skeleton
->comdat_type_p
= true;
7994 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
7996 /* If the original DIE was a specification, we need to put
7997 the skeleton under the parent DIE of the declaration.
7998 This leaves the original declaration in the tree, but
7999 it will be pruned later since there are no longer any
8000 references to it. */
8001 if (orig_parent
!= NULL
)
8003 remove_child_with_prev (child
, prev
);
8004 add_child_die (orig_parent
, skeleton
);
8007 replace_child (child
, skeleton
, prev
);
8014 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
8015 comdat_type_node
*type_node
,
8016 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
);
8018 /* Helper for copy_dwarf_procs_ref_in_dies. Make a copy of the DIE DWARF
8019 procedure, put it under TYPE_NODE and return the copy. Continue looking for
8020 DWARF procedure references in the DW_AT_location attribute. */
8023 copy_dwarf_procedure (dw_die_ref die
,
8024 comdat_type_node
*type_node
,
8025 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8027 gcc_assert (die
->die_tag
== DW_TAG_dwarf_procedure
);
8029 /* DWARF procedures are not supposed to have children... */
8030 gcc_assert (die
->die_child
== NULL
);
8032 /* ... and they are supposed to have only one attribute: DW_AT_location. */
8033 gcc_assert (vec_safe_length (die
->die_attr
) == 1
8034 && ((*die
->die_attr
)[0].dw_attr
== DW_AT_location
));
8036 /* Do not copy more than once DWARF procedures. */
8038 dw_die_ref
&die_copy
= copied_dwarf_procs
.get_or_insert (die
, &existed
);
8042 die_copy
= clone_die (die
);
8043 add_child_die (type_node
->root_die
, die_copy
);
8044 copy_dwarf_procs_ref_in_attrs (die_copy
, type_node
, copied_dwarf_procs
);
8048 /* Helper for copy_dwarf_procs_ref_in_dies. Look for references to DWARF
8049 procedures in DIE's attributes. */
8052 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
8053 comdat_type_node
*type_node
,
8054 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8059 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, i
, a
)
8061 dw_loc_descr_ref loc
;
8063 if (a
->dw_attr_val
.val_class
!= dw_val_class_loc
)
8066 for (loc
= a
->dw_attr_val
.v
.val_loc
; loc
!= NULL
; loc
= loc
->dw_loc_next
)
8068 switch (loc
->dw_loc_opc
)
8072 case DW_OP_call_ref
:
8073 gcc_assert (loc
->dw_loc_oprnd1
.val_class
8074 == dw_val_class_die_ref
);
8075 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
8076 = copy_dwarf_procedure (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
,
8078 copied_dwarf_procs
);
8087 /* Copy DWARF procedures that are referenced by the DIE tree to TREE_NODE and
8088 rewrite references to point to the copies.
8090 References are looked for in DIE's attributes and recursively in all its
8091 children attributes that are location descriptions. COPIED_DWARF_PROCS is a
8092 mapping from old DWARF procedures to their copy. It is used not to copy
8093 twice the same DWARF procedure under TYPE_NODE. */
8096 copy_dwarf_procs_ref_in_dies (dw_die_ref die
,
8097 comdat_type_node
*type_node
,
8098 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
8102 copy_dwarf_procs_ref_in_attrs (die
, type_node
, copied_dwarf_procs
);
8103 FOR_EACH_CHILD (die
, c
, copy_dwarf_procs_ref_in_dies (c
,
8105 copied_dwarf_procs
));
8108 /* Traverse the DIE and set up additional .debug_types or .debug_info
8109 DW_UT_*type sections for each type worthy of being placed in a COMDAT
8113 break_out_comdat_types (dw_die_ref die
)
8117 dw_die_ref prev
= NULL
;
8118 dw_die_ref next
= NULL
;
8119 dw_die_ref unit
= NULL
;
8121 first
= c
= die
->die_child
;
8125 if (prev
== NULL
|| prev
->die_sib
== c
)
8128 next
= (c
== first
? NULL
: c
->die_sib
);
8129 if (should_move_die_to_comdat (c
))
8131 dw_die_ref replacement
;
8132 comdat_type_node
*type_node
;
8134 /* Break out nested types into their own type units. */
8135 break_out_comdat_types (c
);
8137 /* Create a new type unit DIE as the root for the new tree, and
8138 add it to the list of comdat types. */
8139 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8140 add_AT_unsigned (unit
, DW_AT_language
,
8141 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
8142 type_node
= ggc_cleared_alloc
<comdat_type_node
> ();
8143 type_node
->root_die
= unit
;
8144 type_node
->next
= comdat_type_list
;
8145 comdat_type_list
= type_node
;
8147 /* Generate the type signature. */
8148 generate_type_signature (c
, type_node
);
8150 /* Copy the declaration context, attributes, and children of the
8151 declaration into the new type unit DIE, then remove this DIE
8152 from the main CU (or replace it with a skeleton if necessary). */
8153 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
8154 type_node
->skeleton_die
= replacement
;
8156 /* Add the DIE to the new compunit. */
8157 add_child_die (unit
, c
);
8159 /* Types can reference DWARF procedures for type size or data location
8160 expressions. Calls in DWARF expressions cannot target procedures
8161 that are not in the same section. So we must copy DWARF procedures
8162 along with this type and then rewrite references to them. */
8163 hash_map
<dw_die_ref
, dw_die_ref
> copied_dwarf_procs
;
8164 copy_dwarf_procs_ref_in_dies (c
, type_node
, copied_dwarf_procs
);
8166 if (replacement
!= NULL
)
8169 else if (c
->die_tag
== DW_TAG_namespace
8170 || c
->die_tag
== DW_TAG_class_type
8171 || c
->die_tag
== DW_TAG_structure_type
8172 || c
->die_tag
== DW_TAG_union_type
)
8174 /* Look for nested types that can be broken out. */
8175 break_out_comdat_types (c
);
8177 } while (next
!= NULL
);
8180 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
8181 Enter all the cloned children into the hash table decl_table. */
8184 clone_tree_partial (dw_die_ref die
, decl_hash_type
*decl_table
)
8188 struct decl_table_entry
*entry
;
8189 decl_table_entry
**slot
;
8191 if (die
->die_tag
== DW_TAG_subprogram
)
8192 clone
= clone_as_declaration (die
);
8194 clone
= clone_die (die
);
8196 slot
= decl_table
->find_slot_with_hash (die
,
8197 htab_hash_pointer (die
), INSERT
);
8199 /* Assert that DIE isn't in the hash table yet. If it would be there
8200 before, the ancestors would be necessarily there as well, therefore
8201 clone_tree_partial wouldn't be called. */
8202 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
8204 entry
= XCNEW (struct decl_table_entry
);
8206 entry
->copy
= clone
;
8209 if (die
->die_tag
!= DW_TAG_subprogram
)
8210 FOR_EACH_CHILD (die
, c
,
8211 add_child_die (clone
, clone_tree_partial (c
, decl_table
)));
8216 /* Walk the DIE and its children, looking for references to incomplete
8217 or trivial types that are unmarked (i.e., that are not in the current
8221 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type
*decl_table
)
8227 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8229 if (AT_class (a
) == dw_val_class_die_ref
)
8231 dw_die_ref targ
= AT_ref (a
);
8232 decl_table_entry
**slot
;
8233 struct decl_table_entry
*entry
;
8235 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
8238 slot
= decl_table
->find_slot_with_hash (targ
,
8239 htab_hash_pointer (targ
),
8242 if (*slot
!= HTAB_EMPTY_ENTRY
)
8244 /* TARG has already been copied, so we just need to
8245 modify the reference to point to the copy. */
8247 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
8251 dw_die_ref parent
= unit
;
8252 dw_die_ref copy
= clone_die (targ
);
8254 /* Record in DECL_TABLE that TARG has been copied.
8255 Need to do this now, before the recursive call,
8256 because DECL_TABLE may be expanded and SLOT
8257 would no longer be a valid pointer. */
8258 entry
= XCNEW (struct decl_table_entry
);
8263 /* If TARG is not a declaration DIE, we need to copy its
8265 if (!is_declaration_die (targ
))
8269 add_child_die (copy
,
8270 clone_tree_partial (c
, decl_table
)));
8273 /* Make sure the cloned tree is marked as part of the
8277 /* If TARG has surrounding context, copy its ancestor tree
8278 into the new type unit. */
8279 if (targ
->die_parent
!= NULL
8280 && !is_unit_die (targ
->die_parent
))
8281 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
8284 add_child_die (parent
, copy
);
8285 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
8287 /* Make sure the newly-copied DIE is walked. If it was
8288 installed in a previously-added context, it won't
8289 get visited otherwise. */
8292 /* Find the highest point of the newly-added tree,
8293 mark each node along the way, and walk from there. */
8294 parent
->die_mark
= 1;
8295 while (parent
->die_parent
8296 && parent
->die_parent
->die_mark
== 0)
8298 parent
= parent
->die_parent
;
8299 parent
->die_mark
= 1;
8301 copy_decls_walk (unit
, parent
, decl_table
);
8307 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
8310 /* Copy declarations for "unworthy" types into the new comdat section.
8311 Incomplete types, modified types, and certain other types aren't broken
8312 out into comdat sections of their own, so they don't have a signature,
8313 and we need to copy the declaration into the same section so that we
8314 don't have an external reference. */
8317 copy_decls_for_unworthy_types (dw_die_ref unit
)
8320 decl_hash_type
decl_table (10);
8321 copy_decls_walk (unit
, unit
, &decl_table
);
8325 /* Traverse the DIE and add a sibling attribute if it may have the
8326 effect of speeding up access to siblings. To save some space,
8327 avoid generating sibling attributes for DIE's without children. */
8330 add_sibling_attributes (dw_die_ref die
)
8334 if (! die
->die_child
)
8337 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
8338 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
8340 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
8343 /* Output all location lists for the DIE and its children. */
8346 output_location_lists (dw_die_ref die
)
8352 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8353 if (AT_class (a
) == dw_val_class_loc_list
)
8354 output_loc_list (AT_loc_list (a
));
8356 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
8359 /* During assign_location_list_indexes and output_loclists_offset the
8360 current index, after it the number of assigned indexes (i.e. how
8361 large the .debug_loclists* offset table should be). */
8362 static unsigned int loc_list_idx
;
8364 /* Output all location list offsets for the DIE and its children. */
8367 output_loclists_offsets (dw_die_ref die
)
8373 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8374 if (AT_class (a
) == dw_val_class_loc_list
)
8376 dw_loc_list_ref l
= AT_loc_list (a
);
8377 if (l
->offset_emitted
)
8379 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l
->ll_symbol
,
8380 loc_section_label
, NULL
);
8381 gcc_assert (l
->hash
== loc_list_idx
);
8383 l
->offset_emitted
= true;
8386 FOR_EACH_CHILD (die
, c
, output_loclists_offsets (c
));
8389 /* Recursively set indexes of location lists. */
8392 assign_location_list_indexes (dw_die_ref die
)
8398 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8399 if (AT_class (a
) == dw_val_class_loc_list
)
8401 dw_loc_list_ref list
= AT_loc_list (a
);
8402 if (!list
->num_assigned
)
8404 list
->num_assigned
= true;
8405 list
->hash
= loc_list_idx
++;
8409 FOR_EACH_CHILD (die
, c
, assign_location_list_indexes (c
));
8412 /* We want to limit the number of external references, because they are
8413 larger than local references: a relocation takes multiple words, and
8414 even a sig8 reference is always eight bytes, whereas a local reference
8415 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
8416 So if we encounter multiple external references to the same type DIE, we
8417 make a local typedef stub for it and redirect all references there.
8419 This is the element of the hash table for keeping track of these
8429 /* Hashtable helpers. */
8431 struct external_ref_hasher
: free_ptr_hash
<external_ref
>
8433 static inline hashval_t
hash (const external_ref
*);
8434 static inline bool equal (const external_ref
*, const external_ref
*);
8438 external_ref_hasher::hash (const external_ref
*r
)
8440 dw_die_ref die
= r
->type
;
8443 /* We can't use the address of the DIE for hashing, because
8444 that will make the order of the stub DIEs non-deterministic. */
8445 if (! die
->comdat_type_p
)
8446 /* We have a symbol; use it to compute a hash. */
8447 h
= htab_hash_string (die
->die_id
.die_symbol
);
8450 /* We have a type signature; use a subset of the bits as the hash.
8451 The 8-byte signature is at least as large as hashval_t. */
8452 comdat_type_node
*type_node
= die
->die_id
.die_type_node
;
8453 memcpy (&h
, type_node
->signature
, sizeof (h
));
8459 external_ref_hasher::equal (const external_ref
*r1
, const external_ref
*r2
)
8461 return r1
->type
== r2
->type
;
8464 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
8466 /* Return a pointer to the external_ref for references to DIE. */
8468 static struct external_ref
*
8469 lookup_external_ref (external_ref_hash_type
*map
, dw_die_ref die
)
8471 struct external_ref ref
, *ref_p
;
8472 external_ref
**slot
;
8475 slot
= map
->find_slot (&ref
, INSERT
);
8476 if (*slot
!= HTAB_EMPTY_ENTRY
)
8479 ref_p
= XCNEW (struct external_ref
);
8485 /* Subroutine of optimize_external_refs, below.
8487 If we see a type skeleton, record it as our stub. If we see external
8488 references, remember how many we've seen. */
8491 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type
*map
)
8496 struct external_ref
*ref_p
;
8498 if (is_type_die (die
)
8499 && (c
= get_AT_ref (die
, DW_AT_signature
)))
8501 /* This is a local skeleton; use it for local references. */
8502 ref_p
= lookup_external_ref (map
, c
);
8506 /* Scan the DIE references, and remember any that refer to DIEs from
8507 other CUs (i.e. those which are not marked). */
8508 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8509 if (AT_class (a
) == dw_val_class_die_ref
8510 && (c
= AT_ref (a
))->die_mark
== 0
8513 ref_p
= lookup_external_ref (map
, c
);
8517 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
8520 /* htab_traverse callback function for optimize_external_refs, below. SLOT
8521 points to an external_ref, DATA is the CU we're processing. If we don't
8522 already have a local stub, and we have multiple refs, build a stub. */
8525 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
8527 struct external_ref
*ref_p
= *slot
;
8529 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
8531 /* We have multiple references to this type, so build a small stub.
8532 Both of these forms are a bit dodgy from the perspective of the
8533 DWARF standard, since technically they should have names. */
8534 dw_die_ref cu
= data
;
8535 dw_die_ref type
= ref_p
->type
;
8536 dw_die_ref stub
= NULL
;
8538 if (type
->comdat_type_p
)
8540 /* If we refer to this type via sig8, use AT_signature. */
8541 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
8542 add_AT_die_ref (stub
, DW_AT_signature
, type
);
8546 /* Otherwise, use a typedef with no name. */
8547 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
8548 add_AT_die_ref (stub
, DW_AT_type
, type
);
8557 /* DIE is a unit; look through all the DIE references to see if there are
8558 any external references to types, and if so, create local stubs for
8559 them which will be applied in build_abbrev_table. This is useful because
8560 references to local DIEs are smaller. */
8562 static external_ref_hash_type
*
8563 optimize_external_refs (dw_die_ref die
)
8565 external_ref_hash_type
*map
= new external_ref_hash_type (10);
8566 optimize_external_refs_1 (die
, map
);
8567 map
->traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
8571 /* The following 3 variables are temporaries that are computed only during the
8572 build_abbrev_table call and used and released during the following
8573 optimize_abbrev_table call. */
8575 /* First abbrev_id that can be optimized based on usage. */
8576 static unsigned int abbrev_opt_start
;
8578 /* Maximum abbrev_id of a base type plus one (we can't optimize DIEs with
8579 abbrev_id smaller than this, because they must be already sized
8580 during build_abbrev_table). */
8581 static unsigned int abbrev_opt_base_type_end
;
8583 /* Vector of usage counts during build_abbrev_table. Indexed by
8584 abbrev_id - abbrev_opt_start. */
8585 static vec
<unsigned int> abbrev_usage_count
;
8587 /* Vector of all DIEs added with die_abbrev >= abbrev_opt_start. */
8588 static vec
<dw_die_ref
> sorted_abbrev_dies
;
8590 /* The format of each DIE (and its attribute value pairs) is encoded in an
8591 abbreviation table. This routine builds the abbreviation table and assigns
8592 a unique abbreviation id for each abbreviation entry. The children of each
8593 die are visited recursively. */
8596 build_abbrev_table (dw_die_ref die
, external_ref_hash_type
*extern_map
)
8598 unsigned int abbrev_id
= 0;
8604 /* Scan the DIE references, and replace any that refer to
8605 DIEs from other CUs (i.e. those which are not marked) with
8606 the local stubs we built in optimize_external_refs. */
8607 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8608 if (AT_class (a
) == dw_val_class_die_ref
8609 && (c
= AT_ref (a
))->die_mark
== 0)
8611 struct external_ref
*ref_p
;
8612 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
8614 ref_p
= lookup_external_ref (extern_map
, c
);
8615 if (ref_p
->stub
&& ref_p
->stub
!= die
)
8616 change_AT_die_ref (a
, ref_p
->stub
);
8618 /* We aren't changing this reference, so mark it external. */
8619 set_AT_ref_external (a
, 1);
8622 FOR_EACH_VEC_SAFE_ELT (abbrev_die_table
, abbrev_id
, abbrev
)
8624 dw_attr_node
*die_a
, *abbrev_a
;
8630 if (abbrev
->die_tag
!= die
->die_tag
)
8632 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
8635 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
8638 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
8640 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
8641 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
8642 || (value_format (abbrev_a
) != value_format (die_a
)))
8652 if (abbrev_id
>= vec_safe_length (abbrev_die_table
))
8654 vec_safe_push (abbrev_die_table
, die
);
8655 if (abbrev_opt_start
)
8656 abbrev_usage_count
.safe_push (0);
8658 if (abbrev_opt_start
&& abbrev_id
>= abbrev_opt_start
)
8660 abbrev_usage_count
[abbrev_id
- abbrev_opt_start
]++;
8661 sorted_abbrev_dies
.safe_push (die
);
8664 die
->die_abbrev
= abbrev_id
;
8665 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
8668 /* Callback function for sorted_abbrev_dies vector sorting. We sort
8669 by die_abbrev's usage count, from the most commonly used
8670 abbreviation to the least. */
8673 die_abbrev_cmp (const void *p1
, const void *p2
)
8675 dw_die_ref die1
= *(const dw_die_ref
*) p1
;
8676 dw_die_ref die2
= *(const dw_die_ref
*) p2
;
8678 gcc_checking_assert (die1
->die_abbrev
>= abbrev_opt_start
);
8679 gcc_checking_assert (die2
->die_abbrev
>= abbrev_opt_start
);
8681 if (die1
->die_abbrev
>= abbrev_opt_base_type_end
8682 && die2
->die_abbrev
>= abbrev_opt_base_type_end
)
8684 if (abbrev_usage_count
[die1
->die_abbrev
- abbrev_opt_start
]
8685 > abbrev_usage_count
[die2
->die_abbrev
- abbrev_opt_start
])
8687 if (abbrev_usage_count
[die1
->die_abbrev
- abbrev_opt_start
]
8688 < abbrev_usage_count
[die2
->die_abbrev
- abbrev_opt_start
])
8692 /* Stabilize the sort. */
8693 if (die1
->die_abbrev
< die2
->die_abbrev
)
8695 if (die1
->die_abbrev
> die2
->die_abbrev
)
8701 /* Convert dw_val_class_const and dw_val_class_unsigned_const class attributes
8702 of DIEs in between sorted_abbrev_dies[first_id] and abbrev_dies[end_id - 1]
8703 into dw_val_class_const_implicit or
8704 dw_val_class_unsigned_const_implicit. */
8707 optimize_implicit_const (unsigned int first_id
, unsigned int end
,
8708 vec
<bool> &implicit_consts
)
8710 /* It never makes sense if there is just one DIE using the abbreviation. */
8711 if (end
< first_id
+ 2)
8716 dw_die_ref die
= sorted_abbrev_dies
[first_id
];
8717 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8718 if (implicit_consts
[ix
])
8720 enum dw_val_class new_class
= dw_val_class_none
;
8721 switch (AT_class (a
))
8723 case dw_val_class_unsigned_const
:
8724 if ((HOST_WIDE_INT
) AT_unsigned (a
) < 0)
8727 /* The .debug_abbrev section will grow by
8728 size_of_sleb128 (AT_unsigned (a)) and we avoid the constants
8729 in all the DIEs using that abbreviation. */
8730 if (constant_size (AT_unsigned (a
)) * (end
- first_id
)
8731 <= (unsigned) size_of_sleb128 (AT_unsigned (a
)))
8734 new_class
= dw_val_class_unsigned_const_implicit
;
8737 case dw_val_class_const
:
8738 new_class
= dw_val_class_const_implicit
;
8741 case dw_val_class_file
:
8742 new_class
= dw_val_class_file_implicit
;
8748 for (i
= first_id
; i
< end
; i
++)
8749 (*sorted_abbrev_dies
[i
]->die_attr
)[ix
].dw_attr_val
.val_class
8754 /* Attempt to optimize abbreviation table from abbrev_opt_start
8755 abbreviation above. */
8758 optimize_abbrev_table (void)
8760 if (abbrev_opt_start
8761 && vec_safe_length (abbrev_die_table
) > abbrev_opt_start
8762 && (dwarf_version
>= 5 || vec_safe_length (abbrev_die_table
) > 127))
8764 auto_vec
<bool, 32> implicit_consts
;
8765 sorted_abbrev_dies
.qsort (die_abbrev_cmp
);
8767 unsigned int abbrev_id
= abbrev_opt_start
- 1;
8768 unsigned int first_id
= ~0U;
8769 unsigned int last_abbrev_id
= 0;
8772 if (abbrev_opt_base_type_end
> abbrev_opt_start
)
8773 abbrev_id
= abbrev_opt_base_type_end
- 1;
8774 /* Reassign abbreviation ids from abbrev_opt_start above, so that
8775 most commonly used abbreviations come first. */
8776 FOR_EACH_VEC_ELT (sorted_abbrev_dies
, i
, die
)
8781 /* If calc_base_type_die_sizes has been called, the CU and
8782 base types after it can't be optimized, because we've already
8783 calculated their DIE offsets. We've sorted them first. */
8784 if (die
->die_abbrev
< abbrev_opt_base_type_end
)
8786 if (die
->die_abbrev
!= last_abbrev_id
)
8788 last_abbrev_id
= die
->die_abbrev
;
8789 if (dwarf_version
>= 5 && first_id
!= ~0U)
8790 optimize_implicit_const (first_id
, i
, implicit_consts
);
8792 (*abbrev_die_table
)[abbrev_id
] = die
;
8793 if (dwarf_version
>= 5)
8796 implicit_consts
.truncate (0);
8798 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8799 switch (AT_class (a
))
8801 case dw_val_class_const
:
8802 case dw_val_class_unsigned_const
:
8803 case dw_val_class_file
:
8804 implicit_consts
.safe_push (true);
8807 implicit_consts
.safe_push (false);
8812 else if (dwarf_version
>= 5)
8814 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8815 if (!implicit_consts
[ix
])
8819 dw_attr_node
*other_a
8820 = &(*(*abbrev_die_table
)[abbrev_id
]->die_attr
)[ix
];
8821 if (!dw_val_equal_p (&a
->dw_attr_val
,
8822 &other_a
->dw_attr_val
))
8823 implicit_consts
[ix
] = false;
8826 die
->die_abbrev
= abbrev_id
;
8828 gcc_assert (abbrev_id
== vec_safe_length (abbrev_die_table
) - 1);
8829 if (dwarf_version
>= 5 && first_id
!= ~0U)
8830 optimize_implicit_const (first_id
, i
, implicit_consts
);
8833 abbrev_opt_start
= 0;
8834 abbrev_opt_base_type_end
= 0;
8835 abbrev_usage_count
.release ();
8836 sorted_abbrev_dies
.release ();
8839 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8842 constant_size (unsigned HOST_WIDE_INT value
)
8849 log
= floor_log2 (value
);
8852 log
= 1 << (floor_log2 (log
) + 1);
8857 /* Return the size of a DIE as it is represented in the
8858 .debug_info section. */
8860 static unsigned long
8861 size_of_die (dw_die_ref die
)
8863 unsigned long size
= 0;
8866 enum dwarf_form form
;
8868 size
+= size_of_uleb128 (die
->die_abbrev
);
8869 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8871 switch (AT_class (a
))
8873 case dw_val_class_addr
:
8874 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8876 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8877 size
+= size_of_uleb128 (AT_index (a
));
8880 size
+= DWARF2_ADDR_SIZE
;
8882 case dw_val_class_offset
:
8883 size
+= DWARF_OFFSET_SIZE
;
8885 case dw_val_class_loc
:
8887 unsigned long lsize
= size_of_locs (AT_loc (a
));
8890 if (dwarf_version
>= 4)
8891 size
+= size_of_uleb128 (lsize
);
8893 size
+= constant_size (lsize
);
8897 case dw_val_class_loc_list
:
8898 if (dwarf_split_debug_info
&& dwarf_version
>= 5)
8900 gcc_assert (AT_loc_list (a
)->num_assigned
);
8901 size
+= size_of_uleb128 (AT_loc_list (a
)->hash
);
8904 size
+= DWARF_OFFSET_SIZE
;
8906 case dw_val_class_range_list
:
8907 if (value_format (a
) == DW_FORM_rnglistx
)
8909 gcc_assert (rnglist_idx
);
8910 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
8911 size
+= size_of_uleb128 (r
->idx
);
8914 size
+= DWARF_OFFSET_SIZE
;
8916 case dw_val_class_const
:
8917 size
+= size_of_sleb128 (AT_int (a
));
8919 case dw_val_class_unsigned_const
:
8921 int csize
= constant_size (AT_unsigned (a
));
8922 if (dwarf_version
== 3
8923 && a
->dw_attr
== DW_AT_data_member_location
8925 size
+= size_of_uleb128 (AT_unsigned (a
));
8930 case dw_val_class_const_implicit
:
8931 case dw_val_class_unsigned_const_implicit
:
8932 case dw_val_class_file_implicit
:
8933 /* These occupy no size in the DIE, just an extra sleb128 in
8936 case dw_val_class_const_double
:
8937 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
8938 if (HOST_BITS_PER_WIDE_INT
>= DWARF_LARGEST_DATA_FORM_BITS
)
8941 case dw_val_class_wide_int
:
8942 size
+= (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
8943 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
8944 if (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
8945 * HOST_BITS_PER_WIDE_INT
> DWARF_LARGEST_DATA_FORM_BITS
)
8948 case dw_val_class_vec
:
8949 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
8950 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
8951 + a
->dw_attr_val
.v
.val_vec
.length
8952 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
8954 case dw_val_class_flag
:
8955 if (dwarf_version
>= 4)
8956 /* Currently all add_AT_flag calls pass in 1 as last argument,
8957 so DW_FORM_flag_present can be used. If that ever changes,
8958 we'll need to use DW_FORM_flag and have some optimization
8959 in build_abbrev_table that will change those to
8960 DW_FORM_flag_present if it is set to 1 in all DIEs using
8961 the same abbrev entry. */
8962 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8966 case dw_val_class_die_ref
:
8967 if (AT_ref_external (a
))
8969 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
8970 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
8971 is sized by target address length, whereas in DWARF3
8972 it's always sized as an offset. */
8973 if (use_debug_types
)
8974 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
8975 else if (dwarf_version
== 2)
8976 size
+= DWARF2_ADDR_SIZE
;
8978 size
+= DWARF_OFFSET_SIZE
;
8981 size
+= DWARF_OFFSET_SIZE
;
8983 case dw_val_class_fde_ref
:
8984 size
+= DWARF_OFFSET_SIZE
;
8986 case dw_val_class_lbl_id
:
8987 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8989 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8990 size
+= size_of_uleb128 (AT_index (a
));
8993 size
+= DWARF2_ADDR_SIZE
;
8995 case dw_val_class_lineptr
:
8996 case dw_val_class_macptr
:
8997 case dw_val_class_loclistsptr
:
8998 size
+= DWARF_OFFSET_SIZE
;
9000 case dw_val_class_str
:
9001 form
= AT_string_form (a
);
9002 if (form
== DW_FORM_strp
|| form
== DW_FORM_line_strp
)
9003 size
+= DWARF_OFFSET_SIZE
;
9004 else if (form
== DW_FORM_GNU_str_index
)
9005 size
+= size_of_uleb128 (AT_index (a
));
9007 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
9009 case dw_val_class_file
:
9010 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
9012 case dw_val_class_data8
:
9015 case dw_val_class_vms_delta
:
9016 size
+= DWARF_OFFSET_SIZE
;
9018 case dw_val_class_high_pc
:
9019 size
+= DWARF2_ADDR_SIZE
;
9021 case dw_val_class_discr_value
:
9022 size
+= size_of_discr_value (&a
->dw_attr_val
.v
.val_discr_value
);
9024 case dw_val_class_discr_list
:
9026 unsigned block_size
= size_of_discr_list (AT_discr_list (a
));
9028 /* This is a block, so we have the block length and then its
9030 size
+= constant_size (block_size
) + block_size
;
9041 /* Size the debugging information associated with a given DIE. Visits the
9042 DIE's children recursively. Updates the global variable next_die_offset, on
9043 each time through. Uses the current value of next_die_offset to update the
9044 die_offset field in each DIE. */
9047 calc_die_sizes (dw_die_ref die
)
9051 gcc_assert (die
->die_offset
== 0
9052 || (unsigned long int) die
->die_offset
== next_die_offset
);
9053 die
->die_offset
= next_die_offset
;
9054 next_die_offset
+= size_of_die (die
);
9056 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
9058 if (die
->die_child
!= NULL
)
9059 /* Count the null byte used to terminate sibling lists. */
9060 next_die_offset
+= 1;
9063 /* Size just the base type children at the start of the CU.
9064 This is needed because build_abbrev needs to size locs
9065 and sizing of type based stack ops needs to know die_offset
9066 values for the base types. */
9069 calc_base_type_die_sizes (void)
9071 unsigned long die_offset
= (dwarf_split_debug_info
9072 ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
9073 : DWARF_COMPILE_UNIT_HEADER_SIZE
);
9075 dw_die_ref base_type
;
9076 #if ENABLE_ASSERT_CHECKING
9077 dw_die_ref prev
= comp_unit_die ()->die_child
;
9080 die_offset
+= size_of_die (comp_unit_die ());
9081 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
9083 #if ENABLE_ASSERT_CHECKING
9084 gcc_assert (base_type
->die_offset
== 0
9085 && prev
->die_sib
== base_type
9086 && base_type
->die_child
== NULL
9087 && base_type
->die_abbrev
);
9090 if (abbrev_opt_start
9091 && base_type
->die_abbrev
>= abbrev_opt_base_type_end
)
9092 abbrev_opt_base_type_end
= base_type
->die_abbrev
+ 1;
9093 base_type
->die_offset
= die_offset
;
9094 die_offset
+= size_of_die (base_type
);
9098 /* Set the marks for a die and its children. We do this so
9099 that we know whether or not a reference needs to use FORM_ref_addr; only
9100 DIEs in the same CU will be marked. We used to clear out the offset
9101 and use that as the flag, but ran into ordering problems. */
9104 mark_dies (dw_die_ref die
)
9108 gcc_assert (!die
->die_mark
);
9111 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
9114 /* Clear the marks for a die and its children. */
9117 unmark_dies (dw_die_ref die
)
9121 if (! use_debug_types
)
9122 gcc_assert (die
->die_mark
);
9125 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
9128 /* Clear the marks for a die, its children and referred dies. */
9131 unmark_all_dies (dw_die_ref die
)
9141 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
9143 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9144 if (AT_class (a
) == dw_val_class_die_ref
)
9145 unmark_all_dies (AT_ref (a
));
9148 /* Calculate if the entry should appear in the final output file. It may be
9149 from a pruned a type. */
9152 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
9154 /* By limiting gnu pubnames to definitions only, gold can generate a
9155 gdb index without entries for declarations, which don't include
9156 enough information to be useful. */
9157 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
9160 if (table
== pubname_table
)
9162 /* Enumerator names are part of the pubname table, but the
9163 parent DW_TAG_enumeration_type die may have been pruned.
9164 Don't output them if that is the case. */
9165 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
9166 (p
->die
->die_parent
== NULL
9167 || !p
->die
->die_parent
->die_perennial_p
))
9170 /* Everything else in the pubname table is included. */
9174 /* The pubtypes table shouldn't include types that have been
9176 return (p
->die
->die_offset
!= 0
9177 || !flag_eliminate_unused_debug_types
);
9180 /* Return the size of the .debug_pubnames or .debug_pubtypes table
9181 generated for the compilation unit. */
9183 static unsigned long
9184 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9189 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
9191 size
= DWARF_PUBNAMES_HEADER_SIZE
;
9192 FOR_EACH_VEC_ELT (*names
, i
, p
)
9193 if (include_pubname_in_output (names
, p
))
9194 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
9196 size
+= DWARF_OFFSET_SIZE
;
9200 /* Return the size of the information in the .debug_aranges section. */
9202 static unsigned long
9203 size_of_aranges (void)
9207 size
= DWARF_ARANGES_HEADER_SIZE
;
9209 /* Count the address/length pair for this compilation unit. */
9210 if (text_section_used
)
9211 size
+= 2 * DWARF2_ADDR_SIZE
;
9212 if (cold_text_section_used
)
9213 size
+= 2 * DWARF2_ADDR_SIZE
;
9214 if (have_multiple_function_sections
)
9219 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9221 if (DECL_IGNORED_P (fde
->decl
))
9223 if (!fde
->in_std_section
)
9224 size
+= 2 * DWARF2_ADDR_SIZE
;
9225 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9226 size
+= 2 * DWARF2_ADDR_SIZE
;
9230 /* Count the two zero words used to terminated the address range table. */
9231 size
+= 2 * DWARF2_ADDR_SIZE
;
9235 /* Select the encoding of an attribute value. */
9237 static enum dwarf_form
9238 value_format (dw_attr_node
*a
)
9240 switch (AT_class (a
))
9242 case dw_val_class_addr
:
9243 /* Only very few attributes allow DW_FORM_addr. */
9248 case DW_AT_entry_pc
:
9249 case DW_AT_trampoline
:
9250 return (AT_index (a
) == NOT_INDEXED
9251 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
9255 switch (DWARF2_ADDR_SIZE
)
9258 return DW_FORM_data1
;
9260 return DW_FORM_data2
;
9262 return DW_FORM_data4
;
9264 return DW_FORM_data8
;
9268 case dw_val_class_loc_list
:
9269 if (dwarf_split_debug_info
9270 && dwarf_version
>= 5
9271 && AT_loc_list (a
)->num_assigned
)
9272 return DW_FORM_loclistx
;
9274 case dw_val_class_range_list
:
9275 /* For range lists in DWARF 5, use DW_FORM_rnglistx from .debug_info.dwo
9276 but in .debug_info use DW_FORM_sec_offset, which is shorter if we
9277 care about sizes of .debug* sections in shared libraries and
9278 executables and don't take into account relocations that affect just
9279 relocatable objects - for DW_FORM_rnglistx we'd have to emit offset
9280 table in the .debug_rnglists section. */
9281 if (dwarf_split_debug_info
9282 && dwarf_version
>= 5
9283 && AT_class (a
) == dw_val_class_range_list
9285 && a
->dw_attr_val
.val_entry
!= RELOCATED_OFFSET
)
9286 return DW_FORM_rnglistx
;
9287 if (dwarf_version
>= 4)
9288 return DW_FORM_sec_offset
;
9290 case dw_val_class_vms_delta
:
9291 case dw_val_class_offset
:
9292 switch (DWARF_OFFSET_SIZE
)
9295 return DW_FORM_data4
;
9297 return DW_FORM_data8
;
9301 case dw_val_class_loc
:
9302 if (dwarf_version
>= 4)
9303 return DW_FORM_exprloc
;
9304 switch (constant_size (size_of_locs (AT_loc (a
))))
9307 return DW_FORM_block1
;
9309 return DW_FORM_block2
;
9311 return DW_FORM_block4
;
9315 case dw_val_class_const
:
9316 return DW_FORM_sdata
;
9317 case dw_val_class_unsigned_const
:
9318 switch (constant_size (AT_unsigned (a
)))
9321 return DW_FORM_data1
;
9323 return DW_FORM_data2
;
9325 /* In DWARF3 DW_AT_data_member_location with
9326 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
9327 constant, so we need to use DW_FORM_udata if we need
9328 a large constant. */
9329 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
9330 return DW_FORM_udata
;
9331 return DW_FORM_data4
;
9333 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
9334 return DW_FORM_udata
;
9335 return DW_FORM_data8
;
9339 case dw_val_class_const_implicit
:
9340 case dw_val_class_unsigned_const_implicit
:
9341 case dw_val_class_file_implicit
:
9342 return DW_FORM_implicit_const
;
9343 case dw_val_class_const_double
:
9344 switch (HOST_BITS_PER_WIDE_INT
)
9347 return DW_FORM_data2
;
9349 return DW_FORM_data4
;
9351 return DW_FORM_data8
;
9353 if (dwarf_version
>= 5)
9354 return DW_FORM_data16
;
9357 return DW_FORM_block1
;
9359 case dw_val_class_wide_int
:
9360 switch (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
)
9363 return DW_FORM_data1
;
9365 return DW_FORM_data2
;
9367 return DW_FORM_data4
;
9369 return DW_FORM_data8
;
9371 if (dwarf_version
>= 5)
9372 return DW_FORM_data16
;
9375 return DW_FORM_block1
;
9377 case dw_val_class_vec
:
9378 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
9379 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
9382 return DW_FORM_block1
;
9384 return DW_FORM_block2
;
9386 return DW_FORM_block4
;
9390 case dw_val_class_flag
:
9391 if (dwarf_version
>= 4)
9393 /* Currently all add_AT_flag calls pass in 1 as last argument,
9394 so DW_FORM_flag_present can be used. If that ever changes,
9395 we'll need to use DW_FORM_flag and have some optimization
9396 in build_abbrev_table that will change those to
9397 DW_FORM_flag_present if it is set to 1 in all DIEs using
9398 the same abbrev entry. */
9399 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
9400 return DW_FORM_flag_present
;
9402 return DW_FORM_flag
;
9403 case dw_val_class_die_ref
:
9404 if (AT_ref_external (a
))
9405 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
9408 case dw_val_class_fde_ref
:
9409 return DW_FORM_data
;
9410 case dw_val_class_lbl_id
:
9411 return (AT_index (a
) == NOT_INDEXED
9412 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
9413 case dw_val_class_lineptr
:
9414 case dw_val_class_macptr
:
9415 case dw_val_class_loclistsptr
:
9416 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
9417 case dw_val_class_str
:
9418 return AT_string_form (a
);
9419 case dw_val_class_file
:
9420 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
9423 return DW_FORM_data1
;
9425 return DW_FORM_data2
;
9427 return DW_FORM_data4
;
9432 case dw_val_class_data8
:
9433 return DW_FORM_data8
;
9435 case dw_val_class_high_pc
:
9436 switch (DWARF2_ADDR_SIZE
)
9439 return DW_FORM_data1
;
9441 return DW_FORM_data2
;
9443 return DW_FORM_data4
;
9445 return DW_FORM_data8
;
9450 case dw_val_class_discr_value
:
9451 return (a
->dw_attr_val
.v
.val_discr_value
.pos
9454 case dw_val_class_discr_list
:
9455 switch (constant_size (size_of_discr_list (AT_discr_list (a
))))
9458 return DW_FORM_block1
;
9460 return DW_FORM_block2
;
9462 return DW_FORM_block4
;
9472 /* Output the encoding of an attribute value. */
9475 output_value_format (dw_attr_node
*a
)
9477 enum dwarf_form form
= value_format (a
);
9479 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
9482 /* Given a die and id, produce the appropriate abbreviations. */
9485 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
9488 dw_attr_node
*a_attr
;
9490 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
9491 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
9492 dwarf_tag_name (abbrev
->die_tag
));
9494 if (abbrev
->die_child
!= NULL
)
9495 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
9497 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
9499 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
9501 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
9502 dwarf_attr_name (a_attr
->dw_attr
));
9503 output_value_format (a_attr
);
9504 if (value_format (a_attr
) == DW_FORM_implicit_const
)
9506 if (AT_class (a_attr
) == dw_val_class_file_implicit
)
9508 int f
= maybe_emit_file (a_attr
->dw_attr_val
.v
.val_file
);
9509 const char *filename
= a_attr
->dw_attr_val
.v
.val_file
->filename
;
9510 dw2_asm_output_data_sleb128 (f
, "(%s)", filename
);
9513 dw2_asm_output_data_sleb128 (a_attr
->dw_attr_val
.v
.val_int
, NULL
);
9517 dw2_asm_output_data (1, 0, NULL
);
9518 dw2_asm_output_data (1, 0, NULL
);
9522 /* Output the .debug_abbrev section which defines the DIE abbreviation
9526 output_abbrev_section (void)
9528 unsigned int abbrev_id
;
9531 FOR_EACH_VEC_SAFE_ELT (abbrev_die_table
, abbrev_id
, abbrev
)
9533 output_die_abbrevs (abbrev_id
, abbrev
);
9535 /* Terminate the table. */
9536 dw2_asm_output_data (1, 0, NULL
);
9539 /* Output a symbol we can use to refer to this DIE from another CU. */
9542 output_die_symbol (dw_die_ref die
)
9544 const char *sym
= die
->die_id
.die_symbol
;
9546 gcc_assert (!die
->comdat_type_p
);
9551 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
9552 /* We make these global, not weak; if the target doesn't support
9553 .linkonce, it doesn't support combining the sections, so debugging
9555 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
9557 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
9560 /* Return a new location list, given the begin and end range, and the
9563 static inline dw_loc_list_ref
9564 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
9565 const char *section
)
9567 dw_loc_list_ref retlist
= ggc_cleared_alloc
<dw_loc_list_node
> ();
9569 retlist
->begin
= begin
;
9570 retlist
->begin_entry
= NULL
;
9572 retlist
->expr
= expr
;
9573 retlist
->section
= section
;
9578 /* Generate a new internal symbol for this location list node, if it
9579 hasn't got one yet. */
9582 gen_llsym (dw_loc_list_ref list
)
9584 gcc_assert (!list
->ll_symbol
);
9585 list
->ll_symbol
= gen_internal_sym ("LLST");
9588 /* Output the location list given to us. */
9591 output_loc_list (dw_loc_list_ref list_head
)
9593 if (list_head
->emitted
)
9595 list_head
->emitted
= true;
9597 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
9599 dw_loc_list_ref curr
= list_head
;
9600 const char *last_section
= NULL
;
9601 const char *base_label
= NULL
;
9603 /* Walk the location list, and output each range + expression. */
9604 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
9607 /* Don't output an entry that starts and ends at the same address. */
9608 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
9610 size
= size_of_locs (curr
->expr
);
9611 /* If the expression is too large, drop it on the floor. We could
9612 perhaps put it into DW_TAG_dwarf_procedure and refer to that
9613 in the expression, but >= 64KB expressions for a single value
9614 in a single range are unlikely very useful. */
9615 if (dwarf_version
< 5 && size
> 0xffff)
9617 if (dwarf_version
>= 5)
9619 if (dwarf_split_debug_info
)
9621 /* For -gsplit-dwarf, emit DW_LLE_starx_length, which has
9622 uleb128 index into .debug_addr and uleb128 length. */
9623 dw2_asm_output_data (1, DW_LLE_startx_length
,
9624 "DW_LLE_startx_length (%s)",
9625 list_head
->ll_symbol
);
9626 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
9627 "Location list range start index "
9628 "(%s)", curr
->begin
);
9629 /* FIXME: This will ICE ifndef HAVE_AS_LEB128.
9630 For that case we probably need to emit DW_LLE_startx_endx,
9631 but we'd need 2 .debug_addr entries rather than just one. */
9632 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->begin
,
9633 "Location list length (%s)",
9634 list_head
->ll_symbol
);
9636 else if (!have_multiple_function_sections
&& HAVE_AS_LEB128
)
9638 /* If all code is in .text section, the base address is
9639 already provided by the CU attributes. Use
9640 DW_LLE_offset_pair where both addresses are uleb128 encoded
9641 offsets against that base. */
9642 dw2_asm_output_data (1, DW_LLE_offset_pair
,
9643 "DW_LLE_offset_pair (%s)",
9644 list_head
->ll_symbol
);
9645 dw2_asm_output_delta_uleb128 (curr
->begin
, curr
->section
,
9646 "Location list begin address (%s)",
9647 list_head
->ll_symbol
);
9648 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->section
,
9649 "Location list end address (%s)",
9650 list_head
->ll_symbol
);
9652 else if (HAVE_AS_LEB128
)
9654 /* Otherwise, find out how many consecutive entries could share
9655 the same base entry. If just one, emit DW_LLE_start_length,
9656 otherwise emit DW_LLE_base_address for the base address
9657 followed by a series of DW_LLE_offset_pair. */
9658 if (last_section
== NULL
|| curr
->section
!= last_section
)
9660 dw_loc_list_ref curr2
;
9661 for (curr2
= curr
->dw_loc_next
; curr2
!= NULL
;
9662 curr2
= curr2
->dw_loc_next
)
9664 if (strcmp (curr2
->begin
, curr2
->end
) == 0
9669 if (curr2
== NULL
|| curr
->section
!= curr2
->section
)
9670 last_section
= NULL
;
9673 last_section
= curr
->section
;
9674 base_label
= curr
->begin
;
9675 dw2_asm_output_data (1, DW_LLE_base_address
,
9676 "DW_LLE_base_address (%s)",
9677 list_head
->ll_symbol
);
9678 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, base_label
,
9679 "Base address (%s)",
9680 list_head
->ll_symbol
);
9683 /* Only one entry with the same base address. Use
9684 DW_LLE_start_length with absolute address and uleb128
9686 if (last_section
== NULL
)
9688 dw2_asm_output_data (1, DW_LLE_start_length
,
9689 "DW_LLE_start_length (%s)",
9690 list_head
->ll_symbol
);
9691 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
9692 "Location list begin address (%s)",
9693 list_head
->ll_symbol
);
9694 dw2_asm_output_delta_uleb128 (curr
->end
, curr
->begin
,
9695 "Location list length "
9696 "(%s)", list_head
->ll_symbol
);
9698 /* Otherwise emit DW_LLE_offset_pair, relative to above emitted
9699 DW_LLE_base_address. */
9702 dw2_asm_output_data (1, DW_LLE_offset_pair
,
9703 "DW_LLE_offset_pair (%s)",
9704 list_head
->ll_symbol
);
9705 dw2_asm_output_delta_uleb128 (curr
->begin
, base_label
,
9706 "Location list begin address "
9707 "(%s)", list_head
->ll_symbol
);
9708 dw2_asm_output_delta_uleb128 (curr
->end
, base_label
,
9709 "Location list end address "
9710 "(%s)", list_head
->ll_symbol
);
9713 /* The assembler does not support .uleb128 directive. Emit
9714 DW_LLE_start_end with a pair of absolute addresses. */
9717 dw2_asm_output_data (1, DW_LLE_start_end
,
9718 "DW_LLE_start_end (%s)",
9719 list_head
->ll_symbol
);
9720 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
9721 "Location list begin address (%s)",
9722 list_head
->ll_symbol
);
9723 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
9724 "Location list end address (%s)",
9725 list_head
->ll_symbol
);
9728 else if (dwarf_split_debug_info
)
9730 /* For -gsplit-dwarf -gdwarf-{2,3,4} emit index into .debug_addr
9731 and 4 byte length. */
9732 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
9733 "Location list start/length entry (%s)",
9734 list_head
->ll_symbol
);
9735 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
9736 "Location list range start index (%s)",
9738 /* The length field is 4 bytes. If we ever need to support
9739 an 8-byte length, we can add a new DW_LLE code or fall back
9740 to DW_LLE_GNU_start_end_entry. */
9741 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
9742 "Location list range length (%s)",
9743 list_head
->ll_symbol
);
9745 else if (!have_multiple_function_sections
)
9747 /* Pair of relative addresses against start of text section. */
9748 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
9749 "Location list begin address (%s)",
9750 list_head
->ll_symbol
);
9751 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
9752 "Location list end address (%s)",
9753 list_head
->ll_symbol
);
9757 /* Pair of absolute addresses. */
9758 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
9759 "Location list begin address (%s)",
9760 list_head
->ll_symbol
);
9761 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
9762 "Location list end address (%s)",
9763 list_head
->ll_symbol
);
9766 /* Output the block length for this list of location operations. */
9767 if (dwarf_version
>= 5)
9768 dw2_asm_output_data_uleb128 (size
, "Location expression size");
9771 gcc_assert (size
<= 0xffff);
9772 dw2_asm_output_data (2, size
, "Location expression size");
9775 output_loc_sequence (curr
->expr
, -1);
9778 /* And finally list termination. */
9779 if (dwarf_version
>= 5)
9780 dw2_asm_output_data (1, DW_LLE_end_of_list
,
9781 "DW_LLE_end_of_list (%s)", list_head
->ll_symbol
);
9782 else if (dwarf_split_debug_info
)
9783 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
9784 "Location list terminator (%s)",
9785 list_head
->ll_symbol
);
9788 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
9789 "Location list terminator begin (%s)",
9790 list_head
->ll_symbol
);
9791 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
9792 "Location list terminator end (%s)",
9793 list_head
->ll_symbol
);
9797 /* Output a range_list offset into the .debug_ranges or .debug_rnglists
9798 section. Emit a relocated reference if val_entry is NULL, otherwise,
9799 emit an indirect reference. */
9802 output_range_list_offset (dw_attr_node
*a
)
9804 const char *name
= dwarf_attr_name (a
->dw_attr
);
9806 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
9808 if (dwarf_version
>= 5)
9810 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
9811 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, r
->label
,
9812 debug_ranges_section
, "%s", name
);
9816 char *p
= strchr (ranges_section_label
, '\0');
9817 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
9818 a
->dw_attr_val
.v
.val_offset
* 2 * DWARF2_ADDR_SIZE
);
9819 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
9820 debug_ranges_section
, "%s", name
);
9824 else if (dwarf_version
>= 5)
9826 dw_ranges
*r
= &(*ranges_table
)[a
->dw_attr_val
.v
.val_offset
];
9827 gcc_assert (rnglist_idx
);
9828 dw2_asm_output_data_uleb128 (r
->idx
, "%s", name
);
9831 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9832 a
->dw_attr_val
.v
.val_offset
* 2 * DWARF2_ADDR_SIZE
,
9833 "%s (offset from %s)", name
, ranges_section_label
);
9836 /* Output the offset into the debug_loc section. */
9839 output_loc_list_offset (dw_attr_node
*a
)
9841 char *sym
= AT_loc_list (a
)->ll_symbol
;
9844 if (!dwarf_split_debug_info
)
9845 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
9846 "%s", dwarf_attr_name (a
->dw_attr
));
9847 else if (dwarf_version
>= 5)
9849 gcc_assert (AT_loc_list (a
)->num_assigned
);
9850 dw2_asm_output_data_uleb128 (AT_loc_list (a
)->hash
, "%s (%s)",
9851 dwarf_attr_name (a
->dw_attr
),
9855 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
9856 "%s", dwarf_attr_name (a
->dw_attr
));
9859 /* Output an attribute's index or value appropriately. */
9862 output_attr_index_or_value (dw_attr_node
*a
)
9864 const char *name
= dwarf_attr_name (a
->dw_attr
);
9866 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
9868 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
9871 switch (AT_class (a
))
9873 case dw_val_class_addr
:
9874 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
9876 case dw_val_class_high_pc
:
9877 case dw_val_class_lbl_id
:
9878 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
9885 /* Output a type signature. */
9888 output_signature (const char *sig
, const char *name
)
9892 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9893 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
9896 /* Output a discriminant value. */
9899 output_discr_value (dw_discr_value
*discr_value
, const char *name
)
9901 if (discr_value
->pos
)
9902 dw2_asm_output_data_uleb128 (discr_value
->v
.uval
, "%s", name
);
9904 dw2_asm_output_data_sleb128 (discr_value
->v
.sval
, "%s", name
);
9907 /* Output the DIE and its attributes. Called recursively to generate
9908 the definitions of each child DIE. */
9911 output_die (dw_die_ref die
)
9918 /* If someone in another CU might refer to us, set up a symbol for
9919 them to point to. */
9920 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
9921 output_die_symbol (die
);
9923 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
9924 (unsigned long)die
->die_offset
,
9925 dwarf_tag_name (die
->die_tag
));
9927 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9929 const char *name
= dwarf_attr_name (a
->dw_attr
);
9931 switch (AT_class (a
))
9933 case dw_val_class_addr
:
9934 output_attr_index_or_value (a
);
9937 case dw_val_class_offset
:
9938 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
9942 case dw_val_class_range_list
:
9943 output_range_list_offset (a
);
9946 case dw_val_class_loc
:
9947 size
= size_of_locs (AT_loc (a
));
9949 /* Output the block length for this list of location operations. */
9950 if (dwarf_version
>= 4)
9951 dw2_asm_output_data_uleb128 (size
, "%s", name
);
9953 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
9955 output_loc_sequence (AT_loc (a
), -1);
9958 case dw_val_class_const
:
9959 /* ??? It would be slightly more efficient to use a scheme like is
9960 used for unsigned constants below, but gdb 4.x does not sign
9961 extend. Gdb 5.x does sign extend. */
9962 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
9965 case dw_val_class_unsigned_const
:
9967 int csize
= constant_size (AT_unsigned (a
));
9968 if (dwarf_version
== 3
9969 && a
->dw_attr
== DW_AT_data_member_location
9971 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
9973 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
9977 case dw_val_class_const_implicit
:
9979 fprintf (asm_out_file
, "\t\t\t%s %s ("
9980 HOST_WIDE_INT_PRINT_DEC
")\n",
9981 ASM_COMMENT_START
, name
, AT_int (a
));
9984 case dw_val_class_unsigned_const_implicit
:
9986 fprintf (asm_out_file
, "\t\t\t%s %s ("
9987 HOST_WIDE_INT_PRINT_HEX
")\n",
9988 ASM_COMMENT_START
, name
, AT_unsigned (a
));
9991 case dw_val_class_const_double
:
9993 unsigned HOST_WIDE_INT first
, second
;
9995 if (HOST_BITS_PER_WIDE_INT
>= DWARF_LARGEST_DATA_FORM_BITS
)
9996 dw2_asm_output_data (1,
9997 HOST_BITS_PER_DOUBLE_INT
9998 / HOST_BITS_PER_CHAR
,
10001 if (WORDS_BIG_ENDIAN
)
10003 first
= a
->dw_attr_val
.v
.val_double
.high
;
10004 second
= a
->dw_attr_val
.v
.val_double
.low
;
10008 first
= a
->dw_attr_val
.v
.val_double
.low
;
10009 second
= a
->dw_attr_val
.v
.val_double
.high
;
10012 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
10013 first
, "%s", name
);
10014 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
10019 case dw_val_class_wide_int
:
10022 int len
= get_full_len (*a
->dw_attr_val
.v
.val_wide
);
10023 int l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
10024 if (len
* HOST_BITS_PER_WIDE_INT
> DWARF_LARGEST_DATA_FORM_BITS
)
10025 dw2_asm_output_data (1, get_full_len (*a
->dw_attr_val
.v
.val_wide
)
10028 if (WORDS_BIG_ENDIAN
)
10029 for (i
= len
- 1; i
>= 0; --i
)
10031 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
10036 for (i
= 0; i
< len
; ++i
)
10038 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
10045 case dw_val_class_vec
:
10047 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
10048 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
10052 dw2_asm_output_data (constant_size (len
* elt_size
),
10053 len
* elt_size
, "%s", name
);
10054 if (elt_size
> sizeof (HOST_WIDE_INT
))
10059 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
10061 i
++, p
+= elt_size
)
10062 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
10063 "fp or vector constant word %u", i
);
10067 case dw_val_class_flag
:
10068 if (dwarf_version
>= 4)
10070 /* Currently all add_AT_flag calls pass in 1 as last argument,
10071 so DW_FORM_flag_present can be used. If that ever changes,
10072 we'll need to use DW_FORM_flag and have some optimization
10073 in build_abbrev_table that will change those to
10074 DW_FORM_flag_present if it is set to 1 in all DIEs using
10075 the same abbrev entry. */
10076 gcc_assert (AT_flag (a
) == 1);
10077 if (flag_debug_asm
)
10078 fprintf (asm_out_file
, "\t\t\t%s %s\n",
10079 ASM_COMMENT_START
, name
);
10082 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
10085 case dw_val_class_loc_list
:
10086 output_loc_list_offset (a
);
10089 case dw_val_class_die_ref
:
10090 if (AT_ref_external (a
))
10092 if (AT_ref (a
)->comdat_type_p
)
10094 comdat_type_node
*type_node
10095 = AT_ref (a
)->die_id
.die_type_node
;
10097 gcc_assert (type_node
);
10098 output_signature (type_node
->signature
, name
);
10102 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
10106 /* In DWARF2, DW_FORM_ref_addr is sized by target address
10107 length, whereas in DWARF3 it's always sized as an
10109 if (dwarf_version
== 2)
10110 size
= DWARF2_ADDR_SIZE
;
10112 size
= DWARF_OFFSET_SIZE
;
10113 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
10119 gcc_assert (AT_ref (a
)->die_offset
);
10120 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
10125 case dw_val_class_fde_ref
:
10127 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
10129 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
10130 a
->dw_attr_val
.v
.val_fde_index
* 2);
10131 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
10136 case dw_val_class_vms_delta
:
10137 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
10138 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
10139 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
10142 dw2_asm_output_delta (DWARF_OFFSET_SIZE
,
10143 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
10148 case dw_val_class_lbl_id
:
10149 output_attr_index_or_value (a
);
10152 case dw_val_class_lineptr
:
10153 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
10154 debug_line_section
, "%s", name
);
10157 case dw_val_class_macptr
:
10158 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
10159 debug_macinfo_section
, "%s", name
);
10162 case dw_val_class_loclistsptr
:
10163 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
10164 debug_loc_section
, "%s", name
);
10167 case dw_val_class_str
:
10168 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
10169 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
10170 a
->dw_attr_val
.v
.val_str
->label
,
10172 "%s: \"%s\"", name
, AT_string (a
));
10173 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_line_strp
)
10174 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
10175 a
->dw_attr_val
.v
.val_str
->label
,
10176 debug_line_str_section
,
10177 "%s: \"%s\"", name
, AT_string (a
));
10178 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
10179 dw2_asm_output_data_uleb128 (AT_index (a
),
10180 "%s: \"%s\"", name
, AT_string (a
));
10182 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
10185 case dw_val_class_file
:
10187 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
10189 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
10190 a
->dw_attr_val
.v
.val_file
->filename
);
10194 case dw_val_class_file_implicit
:
10195 if (flag_debug_asm
)
10196 fprintf (asm_out_file
, "\t\t\t%s %s (%d, %s)\n",
10197 ASM_COMMENT_START
, name
,
10198 maybe_emit_file (a
->dw_attr_val
.v
.val_file
),
10199 a
->dw_attr_val
.v
.val_file
->filename
);
10202 case dw_val_class_data8
:
10206 for (i
= 0; i
< 8; i
++)
10207 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
10208 i
== 0 ? "%s" : NULL
, name
);
10212 case dw_val_class_high_pc
:
10213 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
10214 get_AT_low_pc (die
), "DW_AT_high_pc");
10217 case dw_val_class_discr_value
:
10218 output_discr_value (&a
->dw_attr_val
.v
.val_discr_value
, name
);
10221 case dw_val_class_discr_list
:
10223 dw_discr_list_ref list
= AT_discr_list (a
);
10224 const int size
= size_of_discr_list (list
);
10226 /* This is a block, so output its length first. */
10227 dw2_asm_output_data (constant_size (size
), size
,
10228 "%s: block size", name
);
10230 for (; list
!= NULL
; list
= list
->dw_discr_next
)
10232 /* One byte for the discriminant value descriptor, and then as
10233 many LEB128 numbers as required. */
10234 if (list
->dw_discr_range
)
10235 dw2_asm_output_data (1, DW_DSC_range
,
10236 "%s: DW_DSC_range", name
);
10238 dw2_asm_output_data (1, DW_DSC_label
,
10239 "%s: DW_DSC_label", name
);
10241 output_discr_value (&list
->dw_discr_lower_bound
, name
);
10242 if (list
->dw_discr_range
)
10243 output_discr_value (&list
->dw_discr_upper_bound
, name
);
10249 gcc_unreachable ();
10253 FOR_EACH_CHILD (die
, c
, output_die (c
));
10255 /* Add null byte to terminate sibling list. */
10256 if (die
->die_child
!= NULL
)
10257 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
10258 (unsigned long) die
->die_offset
);
10261 /* Output the compilation unit that appears at the beginning of the
10262 .debug_info section, and precedes the DIE descriptions. */
10265 output_compilation_unit_header (enum dwarf_unit_type ut
)
10267 if (!XCOFF_DEBUGGING_INFO
)
10269 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10270 dw2_asm_output_data (4, 0xffffffff,
10271 "Initial length escape value indicating 64-bit DWARF extension");
10272 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
10273 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
10274 "Length of Compilation Unit Info");
10277 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
10278 if (dwarf_version
>= 5)
10283 case DW_UT_compile
: name
= "DW_UT_compile"; break;
10284 case DW_UT_type
: name
= "DW_UT_type"; break;
10285 case DW_UT_split_compile
: name
= "DW_UT_split_compile"; break;
10286 case DW_UT_split_type
: name
= "DW_UT_split_type"; break;
10287 default: gcc_unreachable ();
10289 dw2_asm_output_data (1, ut
, name
);
10290 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10292 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
10293 debug_abbrev_section
,
10294 "Offset Into Abbrev. Section");
10295 if (dwarf_version
< 5)
10296 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10299 /* Output the compilation unit DIE and its children. */
10302 output_comp_unit (dw_die_ref die
, int output_if_empty
,
10303 const unsigned char *dwo_id
)
10305 const char *secname
, *oldsym
;
10308 /* Unless we are outputting main CU, we may throw away empty ones. */
10309 if (!output_if_empty
&& die
->die_child
== NULL
)
10312 /* Even if there are no children of this DIE, we must output the information
10313 about the compilation unit. Otherwise, on an empty translation unit, we
10314 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
10315 will then complain when examining the file. First mark all the DIEs in
10316 this CU so we know which get local refs. */
10319 external_ref_hash_type
*extern_map
= optimize_external_refs (die
);
10321 /* For now, optimize only the main CU, in order to optimize the rest
10322 we'd need to see all of them earlier. Leave the rest for post-linking
10324 if (die
== comp_unit_die ())
10325 abbrev_opt_start
= vec_safe_length (abbrev_die_table
);
10327 build_abbrev_table (die
, extern_map
);
10329 optimize_abbrev_table ();
10333 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
10334 next_die_offset
= (dwo_id
10335 ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
10336 : DWARF_COMPILE_UNIT_HEADER_SIZE
);
10337 calc_die_sizes (die
);
10339 oldsym
= die
->die_id
.die_symbol
;
10342 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
10344 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
10346 die
->die_id
.die_symbol
= NULL
;
10347 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
10351 switch_to_section (debug_info_section
);
10352 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
10353 info_section_emitted
= true;
10356 /* Output debugging information. */
10357 output_compilation_unit_header (dwo_id
10358 ? DW_UT_split_compile
: DW_UT_compile
);
10359 if (dwarf_version
>= 5)
10361 if (dwo_id
!= NULL
)
10362 for (int i
= 0; i
< 8; i
++)
10363 dw2_asm_output_data (1, dwo_id
[i
], i
== 0 ? "DWO id" : NULL
);
10367 /* Leave the marks on the main CU, so we can check them in
10368 output_pubnames. */
10372 die
->die_id
.die_symbol
= oldsym
;
10376 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
10377 and .debug_pubtypes. This is configured per-target, but can be
10378 overridden by the -gpubnames or -gno-pubnames options. */
10381 want_pubnames (void)
10383 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
10385 if (debug_generate_pub_sections
!= -1)
10386 return debug_generate_pub_sections
;
10387 return targetm
.want_debug_pub_sections
;
10390 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
10393 add_AT_pubnames (dw_die_ref die
)
10395 if (want_pubnames ())
10396 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
10399 /* Add a string attribute value to a skeleton DIE. */
10402 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
10406 struct indirect_string_node
*node
;
10408 if (! skeleton_debug_str_hash
)
10409 skeleton_debug_str_hash
10410 = hash_table
<indirect_string_hasher
>::create_ggc (10);
10412 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
10413 find_string_form (node
);
10414 if (node
->form
== DW_FORM_GNU_str_index
)
10415 node
->form
= DW_FORM_strp
;
10417 attr
.dw_attr
= attr_kind
;
10418 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
10419 attr
.dw_attr_val
.val_entry
= NULL
;
10420 attr
.dw_attr_val
.v
.val_str
= node
;
10421 add_dwarf_attr (die
, &attr
);
10424 /* Helper function to generate top-level dies for skeleton debug_info and
10428 add_top_level_skeleton_die_attrs (dw_die_ref die
)
10430 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
10431 const char *comp_dir
= comp_dir_string ();
10433 add_skeleton_AT_string (die
, dwarf_AT (DW_AT_dwo_name
), dwo_file_name
);
10434 if (comp_dir
!= NULL
)
10435 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
10436 add_AT_pubnames (die
);
10437 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
10440 /* Output skeleton debug sections that point to the dwo file. */
10443 output_skeleton_debug_sections (dw_die_ref comp_unit
,
10444 const unsigned char *dwo_id
)
10446 /* These attributes will be found in the full debug_info section. */
10447 remove_AT (comp_unit
, DW_AT_producer
);
10448 remove_AT (comp_unit
, DW_AT_language
);
10450 switch_to_section (debug_skeleton_info_section
);
10451 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
10453 /* Produce the skeleton compilation-unit header. This one differs enough from
10454 a normal CU header that it's better not to call output_compilation_unit
10456 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10457 dw2_asm_output_data (4, 0xffffffff,
10458 "Initial length escape value indicating 64-bit "
10459 "DWARF extension");
10461 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
10462 DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
10463 - DWARF_INITIAL_LENGTH_SIZE
10464 + size_of_die (comp_unit
),
10465 "Length of Compilation Unit Info");
10466 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
10467 if (dwarf_version
>= 5)
10469 dw2_asm_output_data (1, DW_UT_skeleton
, "DW_UT_skeleton");
10470 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10472 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
10473 debug_skeleton_abbrev_section
,
10474 "Offset Into Abbrev. Section");
10475 if (dwarf_version
< 5)
10476 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
10478 for (int i
= 0; i
< 8; i
++)
10479 dw2_asm_output_data (1, dwo_id
[i
], i
== 0 ? "DWO id" : NULL
);
10481 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
10482 output_die (comp_unit
);
10484 /* Build the skeleton debug_abbrev section. */
10485 switch_to_section (debug_skeleton_abbrev_section
);
10486 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
10488 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
10490 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
10493 /* Output a comdat type unit DIE and its children. */
10496 output_comdat_type_unit (comdat_type_node
*node
)
10498 const char *secname
;
10501 #if defined (OBJECT_FORMAT_ELF)
10505 /* First mark all the DIEs in this CU so we know which get local refs. */
10506 mark_dies (node
->root_die
);
10508 external_ref_hash_type
*extern_map
= optimize_external_refs (node
->root_die
);
10510 build_abbrev_table (node
->root_die
, extern_map
);
10515 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
10516 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
10517 calc_die_sizes (node
->root_die
);
10519 #if defined (OBJECT_FORMAT_ELF)
10520 if (dwarf_version
>= 5)
10522 if (!dwarf_split_debug_info
)
10523 secname
= ".debug_info";
10525 secname
= ".debug_info.dwo";
10527 else if (!dwarf_split_debug_info
)
10528 secname
= ".debug_types";
10530 secname
= ".debug_types.dwo";
10532 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
10533 sprintf (tmp
, dwarf_version
>= 5 ? "wi." : "wt.");
10534 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
10535 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
10536 comdat_key
= get_identifier (tmp
);
10537 targetm
.asm_out
.named_section (secname
,
10538 SECTION_DEBUG
| SECTION_LINKONCE
,
10541 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
10542 sprintf (tmp
, (dwarf_version
>= 5
10543 ? ".gnu.linkonce.wi." : ".gnu.linkonce.wt."));
10544 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
10545 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
10547 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
10550 /* Output debugging information. */
10551 output_compilation_unit_header (dwarf_split_debug_info
10552 ? DW_UT_split_type
: DW_UT_type
);
10553 output_signature (node
->signature
, "Type Signature");
10554 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
10555 "Offset to Type DIE");
10556 output_die (node
->root_die
);
10558 unmark_dies (node
->root_die
);
10561 /* Return the DWARF2/3 pubname associated with a decl. */
10563 static const char *
10564 dwarf2_name (tree decl
, int scope
)
10566 if (DECL_NAMELESS (decl
))
10568 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
10571 /* Add a new entry to .debug_pubnames if appropriate. */
10574 add_pubname_string (const char *str
, dw_die_ref die
)
10579 e
.name
= xstrdup (str
);
10580 vec_safe_push (pubname_table
, e
);
10584 add_pubname (tree decl
, dw_die_ref die
)
10586 if (!want_pubnames ())
10589 /* Don't add items to the table when we expect that the consumer will have
10590 just read the enclosing die. For example, if the consumer is looking at a
10591 class_member, it will either be inside the class already, or will have just
10592 looked up the class to find the member. Either way, searching the class is
10593 faster than searching the index. */
10594 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
10595 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
10597 const char *name
= dwarf2_name (decl
, 1);
10600 add_pubname_string (name
, die
);
10604 /* Add an enumerator to the pubnames section. */
10607 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
10611 gcc_assert (scope_name
);
10612 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
10614 vec_safe_push (pubname_table
, e
);
10617 /* Add a new entry to .debug_pubtypes if appropriate. */
10620 add_pubtype (tree decl
, dw_die_ref die
)
10624 if (!want_pubnames ())
10627 if ((TREE_PUBLIC (decl
)
10628 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
10629 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
10632 const char *scope_name
= "";
10633 const char *sep
= is_cxx () ? "::" : ".";
10636 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
10637 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
10639 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
10640 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
10641 scope_name
= concat (scope_name
, sep
, NULL
);
10647 name
= type_tag (decl
);
10649 name
= lang_hooks
.dwarf_name (decl
, 1);
10651 /* If we don't have a name for the type, there's no point in adding
10652 it to the table. */
10653 if (name
!= NULL
&& name
[0] != '\0')
10656 e
.name
= concat (scope_name
, name
, NULL
);
10657 vec_safe_push (pubtype_table
, e
);
10660 /* Although it might be more consistent to add the pubinfo for the
10661 enumerators as their dies are created, they should only be added if the
10662 enum type meets the criteria above. So rather than re-check the parent
10663 enum type whenever an enumerator die is created, just output them all
10664 here. This isn't protected by the name conditional because anonymous
10665 enums don't have names. */
10666 if (die
->die_tag
== DW_TAG_enumeration_type
)
10670 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
10675 /* Output a single entry in the pubnames table. */
10678 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
10680 dw_die_ref die
= entry
->die
;
10681 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
10683 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
10685 if (debug_generate_pub_sections
== 2)
10687 /* This logic follows gdb's method for determining the value of the flag
10689 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
10690 switch (die
->die_tag
)
10692 case DW_TAG_typedef
:
10693 case DW_TAG_base_type
:
10694 case DW_TAG_subrange_type
:
10695 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
10696 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
10698 case DW_TAG_enumerator
:
10699 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10700 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
10701 if (!is_cxx () && !is_java ())
10702 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
10704 case DW_TAG_subprogram
:
10705 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10706 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
10708 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
10710 case DW_TAG_constant
:
10711 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10712 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
10713 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
10715 case DW_TAG_variable
:
10716 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
10717 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
10718 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
10720 case DW_TAG_namespace
:
10721 case DW_TAG_imported_declaration
:
10722 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
10724 case DW_TAG_class_type
:
10725 case DW_TAG_interface_type
:
10726 case DW_TAG_structure_type
:
10727 case DW_TAG_union_type
:
10728 case DW_TAG_enumeration_type
:
10729 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
10730 if (!is_cxx () && !is_java ())
10731 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
10734 /* An unusual tag. Leave the flag-byte empty. */
10737 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
10738 "GDB-index flags");
10741 dw2_asm_output_nstring (entry
->name
, -1, "external name");
10745 /* Output the public names table used to speed up access to externally
10746 visible names; or the public types table used to find type definitions. */
10749 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
10752 unsigned long pubnames_length
= size_of_pubnames (names
);
10753 pubname_entry
*pub
;
10755 if (!XCOFF_DEBUGGING_INFO
)
10757 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10758 dw2_asm_output_data (4, 0xffffffff,
10759 "Initial length escape value indicating 64-bit DWARF extension");
10760 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
10761 "Pub Info Length");
10764 /* Version number for pubnames/pubtypes is independent of dwarf version. */
10765 dw2_asm_output_data (2, 2, "DWARF Version");
10767 if (dwarf_split_debug_info
)
10768 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
10769 debug_skeleton_info_section
,
10770 "Offset of Compilation Unit Info");
10772 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
10773 debug_info_section
,
10774 "Offset of Compilation Unit Info");
10775 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
10776 "Compilation Unit Length");
10778 FOR_EACH_VEC_ELT (*names
, i
, pub
)
10780 if (include_pubname_in_output (names
, pub
))
10782 dw_offset die_offset
= pub
->die
->die_offset
;
10784 /* We shouldn't see pubnames for DIEs outside of the main CU. */
10785 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
10786 gcc_assert (pub
->die
->die_mark
);
10788 /* If we're putting types in their own .debug_types sections,
10789 the .debug_pubtypes table will still point to the compile
10790 unit (not the type unit), so we want to use the offset of
10791 the skeleton DIE (if there is one). */
10792 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
10794 comdat_type_node
*type_node
= pub
->die
->die_id
.die_type_node
;
10796 if (type_node
!= NULL
)
10797 die_offset
= (type_node
->skeleton_die
!= NULL
10798 ? type_node
->skeleton_die
->die_offset
10799 : comp_unit_die ()->die_offset
);
10802 output_pubname (die_offset
, pub
);
10806 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
10809 /* Output public names and types tables if necessary. */
10812 output_pubtables (void)
10814 if (!want_pubnames () || !info_section_emitted
)
10817 switch_to_section (debug_pubnames_section
);
10818 output_pubnames (pubname_table
);
10819 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
10820 It shouldn't hurt to emit it always, since pure DWARF2 consumers
10821 simply won't look for the section. */
10822 switch_to_section (debug_pubtypes_section
);
10823 output_pubnames (pubtype_table
);
10827 /* Output the information that goes into the .debug_aranges table.
10828 Namely, define the beginning and ending address range of the
10829 text section generated for this compilation unit. */
10832 output_aranges (void)
10835 unsigned long aranges_length
= size_of_aranges ();
10837 if (!XCOFF_DEBUGGING_INFO
)
10839 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10840 dw2_asm_output_data (4, 0xffffffff,
10841 "Initial length escape value indicating 64-bit DWARF extension");
10842 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
10843 "Length of Address Ranges Info");
10846 /* Version number for aranges is still 2, even up to DWARF5. */
10847 dw2_asm_output_data (2, 2, "DWARF Version");
10848 if (dwarf_split_debug_info
)
10849 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
10850 debug_skeleton_info_section
,
10851 "Offset of Compilation Unit Info");
10853 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
10854 debug_info_section
,
10855 "Offset of Compilation Unit Info");
10856 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
10857 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
10859 /* We need to align to twice the pointer size here. */
10860 if (DWARF_ARANGES_PAD_SIZE
)
10862 /* Pad using a 2 byte words so that padding is correct for any
10864 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
10865 2 * DWARF2_ADDR_SIZE
);
10866 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
10867 dw2_asm_output_data (2, 0, NULL
);
10870 /* It is necessary not to output these entries if the sections were
10871 not used; if the sections were not used, the length will be 0 and
10872 the address may end up as 0 if the section is discarded by ld
10873 --gc-sections, leaving an invalid (0, 0) entry that can be
10874 confused with the terminator. */
10875 if (text_section_used
)
10877 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
10878 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
10879 text_section_label
, "Length");
10881 if (cold_text_section_used
)
10883 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
10885 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
10886 cold_text_section_label
, "Length");
10889 if (have_multiple_function_sections
)
10894 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
10896 if (DECL_IGNORED_P (fde
->decl
))
10898 if (!fde
->in_std_section
)
10900 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
10902 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
10903 fde
->dw_fde_begin
, "Length");
10905 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
10907 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
10909 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
10910 fde
->dw_fde_second_begin
, "Length");
10915 /* Output the terminator words. */
10916 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
10917 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
10920 /* Add a new entry to .debug_ranges. Return its index into
10921 ranges_table vector. */
10923 static unsigned int
10924 add_ranges_num (int num
, bool maybe_new_sec
)
10926 dw_ranges r
= { NULL
, num
, 0, maybe_new_sec
};
10927 vec_safe_push (ranges_table
, r
);
10928 return vec_safe_length (ranges_table
) - 1;
10931 /* Add a new entry to .debug_ranges corresponding to a block, or a
10932 range terminator if BLOCK is NULL. MAYBE_NEW_SEC is true if
10933 this entry might be in a different section from previous range. */
10935 static unsigned int
10936 add_ranges (const_tree block
, bool maybe_new_sec
)
10938 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0, maybe_new_sec
);
10941 /* Note that (*rnglist_table)[offset] is either a head of a rnglist
10942 chain, or middle entry of a chain that will be directly referred to. */
10945 note_rnglist_head (unsigned int offset
)
10947 if (dwarf_version
< 5 || (*ranges_table
)[offset
].label
)
10949 (*ranges_table
)[offset
].label
= gen_internal_sym ("LLRL");
10952 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
10953 When using dwarf_split_debug_info, address attributes in dies destined
10954 for the final executable should be direct references--setting the
10955 parameter force_direct ensures this behavior. */
10958 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
10959 bool *added
, bool force_direct
)
10961 unsigned int in_use
= vec_safe_length (ranges_by_label
);
10962 unsigned int offset
;
10963 dw_ranges_by_label rbl
= { begin
, end
};
10964 vec_safe_push (ranges_by_label
, rbl
);
10965 offset
= add_ranges_num (-(int)in_use
- 1, true);
10968 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
10970 note_rnglist_head (offset
);
10974 /* Emit .debug_ranges section. */
10977 output_ranges (void)
10980 static const char *const start_fmt
= "Offset %#x";
10981 const char *fmt
= start_fmt
;
10984 switch_to_section (debug_ranges_section
);
10985 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
10986 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
10988 int block_num
= r
->num
;
10992 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
10993 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
10995 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
10996 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
10998 /* If all code is in the text section, then the compilation
10999 unit base address defaults to DW_AT_low_pc, which is the
11000 base of the text section. */
11001 if (!have_multiple_function_sections
)
11003 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
11004 text_section_label
,
11005 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11006 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
11007 text_section_label
, NULL
);
11010 /* Otherwise, the compilation unit base address is zero,
11011 which allows us to use absolute addresses, and not worry
11012 about whether the target supports cross-section
11016 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11017 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11018 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
11024 /* Negative block_num stands for an index into ranges_by_label. */
11025 else if (block_num
< 0)
11027 int lab_idx
= - block_num
- 1;
11029 if (!have_multiple_function_sections
)
11031 gcc_unreachable ();
11033 /* If we ever use add_ranges_by_labels () for a single
11034 function section, all we have to do is to take out
11035 the #if 0 above. */
11036 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11037 (*ranges_by_label
)[lab_idx
].begin
,
11038 text_section_label
,
11039 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11040 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
11041 (*ranges_by_label
)[lab_idx
].end
,
11042 text_section_label
, NULL
);
11047 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11048 (*ranges_by_label
)[lab_idx
].begin
,
11049 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
11050 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
11051 (*ranges_by_label
)[lab_idx
].end
,
11057 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11058 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
11064 /* Non-zero if .debug_line_str should be used for .debug_line section
11065 strings or strings that are likely shareable with those. */
11066 #define DWARF5_USE_DEBUG_LINE_STR \
11067 (!DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET \
11068 && (DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) != 0 \
11069 /* FIXME: there is no .debug_line_str.dwo section, \
11070 for -gsplit-dwarf we should use DW_FORM_strx instead. */ \
11071 && !dwarf_split_debug_info)
11073 /* Assign .debug_rnglists indexes. */
11076 index_rnglists (void)
11081 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11083 r
->idx
= rnglist_idx
++;
11086 /* Emit .debug_rnglists section. */
11089 output_rnglists (void)
11093 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
11094 char l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
11095 char basebuf
[MAX_ARTIFICIAL_LABEL_BYTES
];
11097 switch_to_section (debug_ranges_section
);
11098 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
11099 ASM_GENERATE_INTERNAL_LABEL (l1
, DEBUG_RANGES_SECTION_LABEL
, 2);
11100 ASM_GENERATE_INTERNAL_LABEL (l2
, DEBUG_RANGES_SECTION_LABEL
, 3);
11101 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11102 dw2_asm_output_data (4, 0xffffffff,
11103 "Initial length escape value indicating "
11104 "64-bit DWARF extension");
11105 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
11106 "Length of Range Lists");
11107 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
11108 dw2_asm_output_data (2, dwarf_version
, "DWARF Version");
11109 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
11110 dw2_asm_output_data (1, 0, "Segment Size");
11111 /* Emit the offset table only for -gsplit-dwarf. If we don't care
11112 about relocation sizes and primarily care about the size of .debug*
11113 sections in linked shared libraries and executables, then
11114 the offset table plus corresponding DW_FORM_rnglistx uleb128 indexes
11115 into it are usually larger than just DW_FORM_sec_offset offsets
11116 into the .debug_rnglists section. */
11117 dw2_asm_output_data (4, dwarf_split_debug_info
? rnglist_idx
: 0,
11118 "Offset Entry Count");
11119 if (dwarf_split_debug_info
)
11121 ASM_OUTPUT_LABEL (asm_out_file
, ranges_base_label
);
11122 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11124 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, r
->label
,
11125 ranges_base_label
, NULL
);
11128 const char *lab
= "";
11129 unsigned int len
= vec_safe_length (ranges_table
);
11130 const char *base
= NULL
;
11131 FOR_EACH_VEC_SAFE_ELT (ranges_table
, i
, r
)
11133 int block_num
= r
->num
;
11137 ASM_OUTPUT_LABEL (asm_out_file
, r
->label
);
11140 if (HAVE_AS_LEB128
&& (r
->label
|| r
->maybe_new_sec
))
11144 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11145 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
11147 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
11148 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
11150 if (HAVE_AS_LEB128
)
11152 /* If all code is in the text section, then the compilation
11153 unit base address defaults to DW_AT_low_pc, which is the
11154 base of the text section. */
11155 if (!have_multiple_function_sections
)
11157 dw2_asm_output_data (1, DW_RLE_offset_pair
,
11158 "DW_RLE_offset_pair (%s)", lab
);
11159 dw2_asm_output_delta_uleb128 (blabel
, text_section_label
,
11160 "Range begin address (%s)", lab
);
11161 dw2_asm_output_delta_uleb128 (elabel
, text_section_label
,
11162 "Range end address (%s)", lab
);
11167 dw_ranges
*r2
= NULL
;
11169 r2
= &(*ranges_table
)[i
+ 1];
11172 && r2
->label
== NULL
11173 && !r2
->maybe_new_sec
)
11175 dw2_asm_output_data (1, DW_RLE_base_address
,
11176 "DW_RLE_base_address (%s)", lab
);
11177 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11178 "Base address (%s)", lab
);
11179 strcpy (basebuf
, blabel
);
11185 dw2_asm_output_data (1, DW_RLE_offset_pair
,
11186 "DW_RLE_offset_pair (%s)", lab
);
11187 dw2_asm_output_delta_uleb128 (blabel
, base
,
11188 "Range begin address (%s)", lab
);
11189 dw2_asm_output_delta_uleb128 (elabel
, base
,
11190 "Range end address (%s)", lab
);
11193 dw2_asm_output_data (1, DW_RLE_start_length
,
11194 "DW_RLE_start_length (%s)", lab
);
11195 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11196 "Range begin address (%s)", lab
);
11197 dw2_asm_output_delta_uleb128 (elabel
, blabel
,
11198 "Range length (%s)", lab
);
11202 dw2_asm_output_data (1, DW_RLE_start_end
,
11203 "DW_RLE_start_end (%s)", lab
);
11204 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11205 "Range begin address (%s)", lab
);
11206 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
,
11207 "Range end address (%s)", lab
);
11211 /* Negative block_num stands for an index into ranges_by_label. */
11212 else if (block_num
< 0)
11214 int lab_idx
= - block_num
- 1;
11215 const char *blabel
= (*ranges_by_label
)[lab_idx
].begin
;
11216 const char *elabel
= (*ranges_by_label
)[lab_idx
].end
;
11218 if (!have_multiple_function_sections
)
11219 gcc_unreachable ();
11220 if (HAVE_AS_LEB128
)
11222 dw2_asm_output_data (1, DW_RLE_start_length
,
11223 "DW_RLE_start_length (%s)", lab
);
11224 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11225 "Range begin address (%s)", lab
);
11226 dw2_asm_output_delta_uleb128 (elabel
, blabel
,
11227 "Range length (%s)", lab
);
11231 dw2_asm_output_data (1, DW_RLE_start_end
,
11232 "DW_RLE_start_end (%s)", lab
);
11233 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
11234 "Range begin address (%s)", lab
);
11235 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
,
11236 "Range end address (%s)", lab
);
11240 dw2_asm_output_data (1, DW_RLE_end_of_list
,
11241 "DW_RLE_end_of_list (%s)", lab
);
11243 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
11246 /* Data structure containing information about input files. */
11249 const char *path
; /* Complete file name. */
11250 const char *fname
; /* File name part. */
11251 int length
; /* Length of entire string. */
11252 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
11253 int dir_idx
; /* Index in directory table. */
11256 /* Data structure containing information about directories with source
11260 const char *path
; /* Path including directory name. */
11261 int length
; /* Path length. */
11262 int prefix
; /* Index of directory entry which is a prefix. */
11263 int count
; /* Number of files in this directory. */
11264 int dir_idx
; /* Index of directory used as base. */
11267 /* Callback function for file_info comparison. We sort by looking at
11268 the directories in the path. */
11271 file_info_cmp (const void *p1
, const void *p2
)
11273 const struct file_info
*const s1
= (const struct file_info
*) p1
;
11274 const struct file_info
*const s2
= (const struct file_info
*) p2
;
11275 const unsigned char *cp1
;
11276 const unsigned char *cp2
;
11278 /* Take care of file names without directories. We need to make sure that
11279 we return consistent values to qsort since some will get confused if
11280 we return the same value when identical operands are passed in opposite
11281 orders. So if neither has a directory, return 0 and otherwise return
11282 1 or -1 depending on which one has the directory. */
11283 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
11284 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
11286 cp1
= (const unsigned char *) s1
->path
;
11287 cp2
= (const unsigned char *) s2
->path
;
11293 /* Reached the end of the first path? If so, handle like above. */
11294 if ((cp1
== (const unsigned char *) s1
->fname
)
11295 || (cp2
== (const unsigned char *) s2
->fname
))
11296 return ((cp2
== (const unsigned char *) s2
->fname
)
11297 - (cp1
== (const unsigned char *) s1
->fname
));
11299 /* Character of current path component the same? */
11300 else if (*cp1
!= *cp2
)
11301 return *cp1
- *cp2
;
11305 struct file_name_acquire_data
11307 struct file_info
*files
;
11312 /* Traversal function for the hash table. */
11315 file_name_acquire (dwarf_file_data
**slot
, file_name_acquire_data
*fnad
)
11317 struct dwarf_file_data
*d
= *slot
;
11318 struct file_info
*fi
;
11321 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
11323 if (! d
->emitted_number
)
11326 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
11328 fi
= fnad
->files
+ fnad
->used_files
++;
11330 /* Skip all leading "./". */
11332 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
11335 /* Create a new array entry. */
11337 fi
->length
= strlen (f
);
11340 /* Search for the file name part. */
11341 f
= strrchr (f
, DIR_SEPARATOR
);
11342 #if defined (DIR_SEPARATOR_2)
11344 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
11348 if (f
== NULL
|| f
< g
)
11354 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
11358 /* Helper function for output_file_names. Emit a FORM encoded
11359 string STR, with assembly comment start ENTRY_KIND and
11363 output_line_string (enum dwarf_form form
, const char *str
,
11364 const char *entry_kind
, unsigned int idx
)
11368 case DW_FORM_string
:
11369 dw2_asm_output_nstring (str
, -1, "%s: %#x", entry_kind
, idx
);
11371 case DW_FORM_line_strp
:
11372 if (!debug_line_str_hash
)
11373 debug_line_str_hash
11374 = hash_table
<indirect_string_hasher
>::create_ggc (10);
11376 struct indirect_string_node
*node
;
11377 node
= find_AT_string_in_table (str
, debug_line_str_hash
);
11378 set_indirect_string (node
);
11380 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
11381 debug_line_str_section
, "%s: %#x: \"%s\"",
11382 entry_kind
, 0, node
->str
);
11385 gcc_unreachable ();
11389 /* Output the directory table and the file name table. We try to minimize
11390 the total amount of memory needed. A heuristic is used to avoid large
11391 slowdowns with many input files. */
11394 output_file_names (void)
11396 struct file_name_acquire_data fnad
;
11398 struct file_info
*files
;
11399 struct dir_info
*dirs
;
11407 if (!last_emitted_file
)
11409 if (dwarf_version
>= 5)
11411 dw2_asm_output_data (1, 0, "Directory entry format count");
11412 dw2_asm_output_data_uleb128 (0, "Directories count");
11413 dw2_asm_output_data (1, 0, "File name entry format count");
11414 dw2_asm_output_data_uleb128 (0, "File names count");
11418 dw2_asm_output_data (1, 0, "End directory table");
11419 dw2_asm_output_data (1, 0, "End file name table");
11424 numfiles
= last_emitted_file
->emitted_number
;
11426 /* Allocate the various arrays we need. */
11427 files
= XALLOCAVEC (struct file_info
, numfiles
);
11428 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
11430 fnad
.files
= files
;
11431 fnad
.used_files
= 0;
11432 fnad
.max_files
= numfiles
;
11433 file_table
->traverse
<file_name_acquire_data
*, file_name_acquire
> (&fnad
);
11434 gcc_assert (fnad
.used_files
== fnad
.max_files
);
11436 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
11438 /* Find all the different directories used. */
11439 dirs
[0].path
= files
[0].path
;
11440 dirs
[0].length
= files
[0].fname
- files
[0].path
;
11441 dirs
[0].prefix
= -1;
11443 dirs
[0].dir_idx
= 0;
11444 files
[0].dir_idx
= 0;
11447 for (i
= 1; i
< numfiles
; i
++)
11448 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
11449 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
11450 dirs
[ndirs
- 1].length
) == 0)
11452 /* Same directory as last entry. */
11453 files
[i
].dir_idx
= ndirs
- 1;
11454 ++dirs
[ndirs
- 1].count
;
11460 /* This is a new directory. */
11461 dirs
[ndirs
].path
= files
[i
].path
;
11462 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
11463 dirs
[ndirs
].count
= 1;
11464 dirs
[ndirs
].dir_idx
= ndirs
;
11465 files
[i
].dir_idx
= ndirs
;
11467 /* Search for a prefix. */
11468 dirs
[ndirs
].prefix
= -1;
11469 for (j
= 0; j
< ndirs
; j
++)
11470 if (dirs
[j
].length
< dirs
[ndirs
].length
11471 && dirs
[j
].length
> 1
11472 && (dirs
[ndirs
].prefix
== -1
11473 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
11474 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
11475 dirs
[ndirs
].prefix
= j
;
11480 /* Now to the actual work. We have to find a subset of the directories which
11481 allow expressing the file name using references to the directory table
11482 with the least amount of characters. We do not do an exhaustive search
11483 where we would have to check out every combination of every single
11484 possible prefix. Instead we use a heuristic which provides nearly optimal
11485 results in most cases and never is much off. */
11486 saved
= XALLOCAVEC (int, ndirs
);
11487 savehere
= XALLOCAVEC (int, ndirs
);
11489 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
11490 for (i
= 0; i
< ndirs
; i
++)
11495 /* We can always save some space for the current directory. But this
11496 does not mean it will be enough to justify adding the directory. */
11497 savehere
[i
] = dirs
[i
].length
;
11498 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
11500 for (j
= i
+ 1; j
< ndirs
; j
++)
11503 if (saved
[j
] < dirs
[i
].length
)
11505 /* Determine whether the dirs[i] path is a prefix of the
11509 k
= dirs
[j
].prefix
;
11510 while (k
!= -1 && k
!= (int) i
)
11511 k
= dirs
[k
].prefix
;
11515 /* Yes it is. We can possibly save some memory by
11516 writing the filenames in dirs[j] relative to
11518 savehere
[j
] = dirs
[i
].length
;
11519 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
11524 /* Check whether we can save enough to justify adding the dirs[i]
11526 if (total
> dirs
[i
].length
+ 1)
11528 /* It's worthwhile adding. */
11529 for (j
= i
; j
< ndirs
; j
++)
11530 if (savehere
[j
] > 0)
11532 /* Remember how much we saved for this directory so far. */
11533 saved
[j
] = savehere
[j
];
11535 /* Remember the prefix directory. */
11536 dirs
[j
].dir_idx
= i
;
11541 /* Emit the directory name table. */
11542 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
11543 enum dwarf_form str_form
= DW_FORM_string
;
11544 enum dwarf_form idx_form
= DW_FORM_udata
;
11545 if (dwarf_version
>= 5)
11547 const char *comp_dir
= comp_dir_string ();
11548 if (comp_dir
== NULL
)
11550 dw2_asm_output_data (1, 1, "Directory entry format count");
11551 if (DWARF5_USE_DEBUG_LINE_STR
)
11552 str_form
= DW_FORM_line_strp
;
11553 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
11554 dw2_asm_output_data_uleb128 (str_form
, get_DW_FORM_name (str_form
));
11555 dw2_asm_output_data_uleb128 (ndirs
+ idx_offset
, "Directories count");
11556 if (str_form
== DW_FORM_string
)
11558 dw2_asm_output_nstring (comp_dir
, -1, "Directory Entry: %#x", 0);
11559 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
11560 dw2_asm_output_nstring (dirs
[i
].path
,
11562 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
11563 "Directory Entry: %#x", i
+ idx_offset
);
11567 output_line_string (str_form
, comp_dir
, "Directory Entry", 0);
11568 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
11571 = ggc_alloc_string (dirs
[i
].path
,
11573 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
);
11574 output_line_string (str_form
, str
, "Directory Entry",
11575 (unsigned) i
+ idx_offset
);
11581 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
11582 dw2_asm_output_nstring (dirs
[i
].path
,
11584 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
11585 "Directory Entry: %#x", i
+ idx_offset
);
11587 dw2_asm_output_data (1, 0, "End directory table");
11590 /* We have to emit them in the order of emitted_number since that's
11591 used in the debug info generation. To do this efficiently we
11592 generate a back-mapping of the indices first. */
11593 backmap
= XALLOCAVEC (int, numfiles
);
11594 for (i
= 0; i
< numfiles
; i
++)
11595 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
11597 if (dwarf_version
>= 5)
11599 const char *filename0
= get_AT_string (comp_unit_die (), DW_AT_name
);
11600 if (filename0
== NULL
)
11602 /* DW_LNCT_directory_index can use DW_FORM_udata, DW_FORM_data1 and
11603 DW_FORM_data2. Choose one based on the number of directories
11604 and how much space would they occupy in each encoding.
11605 If we have at most 256 directories, all indexes fit into
11606 a single byte, so DW_FORM_data1 is most compact (if there
11607 are at most 128 directories, DW_FORM_udata would be as
11608 compact as that, but not shorter and slower to decode). */
11609 if (ndirs
+ idx_offset
<= 256)
11610 idx_form
= DW_FORM_data1
;
11611 /* If there are more than 65536 directories, we have to use
11612 DW_FORM_udata, DW_FORM_data2 can't refer to them.
11613 Otherwise, compute what space would occupy if all the indexes
11614 used DW_FORM_udata - sum - and compare that to how large would
11615 be DW_FORM_data2 encoding, and pick the more efficient one. */
11616 else if (ndirs
+ idx_offset
<= 65536)
11618 unsigned HOST_WIDE_INT sum
= 1;
11619 for (i
= 0; i
< numfiles
; i
++)
11621 int file_idx
= backmap
[i
];
11622 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
11623 sum
+= size_of_uleb128 (dir_idx
);
11625 if (sum
>= HOST_WIDE_INT_UC (2) * (numfiles
+ 1))
11626 idx_form
= DW_FORM_data2
;
11628 #ifdef VMS_DEBUGGING_INFO
11629 dw2_asm_output_data (1, 4, "File name entry format count");
11631 dw2_asm_output_data (1, 2, "File name entry format count");
11633 dw2_asm_output_data_uleb128 (DW_LNCT_path
, "DW_LNCT_path");
11634 dw2_asm_output_data_uleb128 (str_form
, get_DW_FORM_name (str_form
));
11635 dw2_asm_output_data_uleb128 (DW_LNCT_directory_index
,
11636 "DW_LNCT_directory_index");
11637 dw2_asm_output_data_uleb128 (idx_form
, get_DW_FORM_name (idx_form
));
11638 #ifdef VMS_DEBUGGING_INFO
11639 dw2_asm_output_data_uleb128 (DW_LNCT_timestamp
, "DW_LNCT_timestamp");
11640 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
11641 dw2_asm_output_data_uleb128 (DW_LNCT_size
, "DW_LNCT_size");
11642 dw2_asm_output_data_uleb128 (DW_FORM_udata
, "DW_FORM_udata");
11644 dw2_asm_output_data_uleb128 (numfiles
+ 1, "File names count");
11646 output_line_string (str_form
, filename0
, "File Entry", 0);
11648 /* Include directory index. */
11649 if (dwarf_version
>= 5 && idx_form
!= DW_FORM_udata
)
11650 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
11653 dw2_asm_output_data_uleb128 (0, NULL
);
11655 #ifdef VMS_DEBUGGING_INFO
11656 dw2_asm_output_data_uleb128 (0, NULL
);
11657 dw2_asm_output_data_uleb128 (0, NULL
);
11661 /* Now write all the file names. */
11662 for (i
= 0; i
< numfiles
; i
++)
11664 int file_idx
= backmap
[i
];
11665 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
11667 #ifdef VMS_DEBUGGING_INFO
11668 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
11670 /* Setting these fields can lead to debugger miscomparisons,
11671 but VMS Debug requires them to be set correctly. */
11676 int maxfilelen
= (strlen (files
[file_idx
].path
)
11677 + dirs
[dir_idx
].length
11678 + MAX_VMS_VERSION_LEN
+ 1);
11679 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
11681 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
11682 snprintf (filebuf
, maxfilelen
, "%s;%d",
11683 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
11685 output_line_string (str_form
, filebuf
, "File Entry", (unsigned) i
+ 1);
11687 /* Include directory index. */
11688 if (dwarf_version
>= 5 && idx_form
!= DW_FORM_udata
)
11689 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
11690 dir_idx
+ idx_offset
, NULL
);
11692 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
11694 /* Modification time. */
11695 dw2_asm_output_data_uleb128 ((vms_file_stats_name (files
[file_idx
].path
,
11696 &cdt
, 0, 0, 0) == 0)
11699 /* File length in bytes. */
11700 dw2_asm_output_data_uleb128 ((vms_file_stats_name (files
[file_idx
].path
,
11701 0, &siz
, 0, 0) == 0)
11704 output_line_string (str_form
,
11705 files
[file_idx
].path
+ dirs
[dir_idx
].length
,
11706 "File Entry", (unsigned) i
+ 1);
11708 /* Include directory index. */
11709 if (dwarf_version
>= 5 && idx_form
!= DW_FORM_udata
)
11710 dw2_asm_output_data (idx_form
== DW_FORM_data1
? 1 : 2,
11711 dir_idx
+ idx_offset
, NULL
);
11713 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
11715 if (dwarf_version
>= 5)
11718 /* Modification time. */
11719 dw2_asm_output_data_uleb128 (0, NULL
);
11721 /* File length in bytes. */
11722 dw2_asm_output_data_uleb128 (0, NULL
);
11723 #endif /* VMS_DEBUGGING_INFO */
11726 if (dwarf_version
< 5)
11727 dw2_asm_output_data (1, 0, "End file name table");
11731 /* Output one line number table into the .debug_line section. */
11734 output_one_line_info_table (dw_line_info_table
*table
)
11736 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
11737 unsigned int current_line
= 1;
11738 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
11739 dw_line_info_entry
*ent
;
11742 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
11744 switch (ent
->opcode
)
11746 case LI_set_address
:
11747 /* ??? Unfortunately, we have little choice here currently, and
11748 must always use the most general form. GCC does not know the
11749 address delta itself, so we can't use DW_LNS_advance_pc. Many
11750 ports do have length attributes which will give an upper bound
11751 on the address range. We could perhaps use length attributes
11752 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
11753 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
11755 /* This can handle any delta. This takes
11756 4+DWARF2_ADDR_SIZE bytes. */
11757 dw2_asm_output_data (1, 0, "set address %s", line_label
);
11758 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
11759 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
11760 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
11764 if (ent
->val
== current_line
)
11766 /* We still need to start a new row, so output a copy insn. */
11767 dw2_asm_output_data (1, DW_LNS_copy
,
11768 "copy line %u", current_line
);
11772 int line_offset
= ent
->val
- current_line
;
11773 int line_delta
= line_offset
- DWARF_LINE_BASE
;
11775 current_line
= ent
->val
;
11776 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
11778 /* This can handle deltas from -10 to 234, using the current
11779 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
11780 This takes 1 byte. */
11781 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
11782 "line %u", current_line
);
11786 /* This can handle any delta. This takes at least 4 bytes,
11787 depending on the value being encoded. */
11788 dw2_asm_output_data (1, DW_LNS_advance_line
,
11789 "advance to line %u", current_line
);
11790 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
11791 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
11797 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
11798 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
11801 case LI_set_column
:
11802 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
11803 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
11806 case LI_negate_stmt
:
11807 current_is_stmt
= !current_is_stmt
;
11808 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
11809 "is_stmt %d", current_is_stmt
);
11812 case LI_set_prologue_end
:
11813 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
11814 "set prologue end");
11817 case LI_set_epilogue_begin
:
11818 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
11819 "set epilogue begin");
11822 case LI_set_discriminator
:
11823 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
11824 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
11825 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
11826 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
11831 /* Emit debug info for the address of the end of the table. */
11832 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
11833 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
11834 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
11835 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
11837 dw2_asm_output_data (1, 0, "end sequence");
11838 dw2_asm_output_data_uleb128 (1, NULL
);
11839 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
11842 /* Output the source line number correspondence information. This
11843 information goes into the .debug_line section. */
11846 output_line_info (bool prologue_only
)
11848 static unsigned int generation
;
11849 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
], l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
11850 char p1
[MAX_ARTIFICIAL_LABEL_BYTES
], p2
[MAX_ARTIFICIAL_LABEL_BYTES
];
11851 bool saw_one
= false;
11854 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, generation
);
11855 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, generation
);
11856 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, generation
);
11857 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, generation
++);
11859 if (!XCOFF_DEBUGGING_INFO
)
11861 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
11862 dw2_asm_output_data (4, 0xffffffff,
11863 "Initial length escape value indicating 64-bit DWARF extension");
11864 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
11865 "Length of Source Line Info");
11868 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
11870 dw2_asm_output_data (2, dwarf_version
, "DWARF Version");
11871 if (dwarf_version
>= 5)
11873 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
11874 dw2_asm_output_data (1, 0, "Segment Size");
11876 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
11877 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
11879 /* Define the architecture-dependent minimum instruction length (in bytes).
11880 In this implementation of DWARF, this field is used for information
11881 purposes only. Since GCC generates assembly language, we have no
11882 a priori knowledge of how many instruction bytes are generated for each
11883 source line, and therefore can use only the DW_LNE_set_address and
11884 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
11885 this as '1', which is "correct enough" for all architectures,
11886 and don't let the target override. */
11887 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
11889 if (dwarf_version
>= 4)
11890 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
11891 "Maximum Operations Per Instruction");
11892 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
11893 "Default is_stmt_start flag");
11894 dw2_asm_output_data (1, DWARF_LINE_BASE
,
11895 "Line Base Value (Special Opcodes)");
11896 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
11897 "Line Range Value (Special Opcodes)");
11898 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
11899 "Special Opcode Base");
11901 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
11906 case DW_LNS_advance_pc
:
11907 case DW_LNS_advance_line
:
11908 case DW_LNS_set_file
:
11909 case DW_LNS_set_column
:
11910 case DW_LNS_fixed_advance_pc
:
11911 case DW_LNS_set_isa
:
11919 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
11923 /* Write out the information about the files we use. */
11924 output_file_names ();
11925 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
11928 /* Output the marker for the end of the line number info. */
11929 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
11933 if (separate_line_info
)
11935 dw_line_info_table
*table
;
11938 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
11941 output_one_line_info_table (table
);
11945 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
11947 output_one_line_info_table (cold_text_section_line_info
);
11951 /* ??? Some Darwin linkers crash on a .debug_line section with no
11952 sequences. Further, merely a DW_LNE_end_sequence entry is not
11953 sufficient -- the address column must also be initialized.
11954 Make sure to output at least one set_address/end_sequence pair,
11955 choosing .text since that section is always present. */
11956 if (text_section_line_info
->in_use
|| !saw_one
)
11957 output_one_line_info_table (text_section_line_info
);
11959 /* Output the marker for the end of the line number info. */
11960 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
11963 /* Return true if DW_AT_endianity should be emitted according to REVERSE. */
11966 need_endianity_attribute_p (bool reverse
)
11968 return reverse
&& (dwarf_version
>= 3 || !dwarf_strict
);
11971 /* Given a pointer to a tree node for some base type, return a pointer to
11972 a DIE that describes the given type. REVERSE is true if the type is
11973 to be interpreted in the reverse storage order wrt the target order.
11975 This routine must only be called for GCC type nodes that correspond to
11976 Dwarf base (fundamental) types. */
11979 base_type_die (tree type
, bool reverse
)
11981 dw_die_ref base_type_result
;
11982 enum dwarf_type encoding
;
11983 bool fpt_used
= false;
11984 struct fixed_point_type_info fpt_info
;
11985 tree type_bias
= NULL_TREE
;
11987 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
11990 /* If this is a subtype that should not be emitted as a subrange type,
11991 use the base type. See subrange_type_for_debug_p. */
11992 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
11993 type
= TREE_TYPE (type
);
11995 switch (TREE_CODE (type
))
11998 if ((dwarf_version
>= 4 || !dwarf_strict
)
11999 && TYPE_NAME (type
)
12000 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
12001 && DECL_IS_BUILTIN (TYPE_NAME (type
))
12002 && DECL_NAME (TYPE_NAME (type
)))
12004 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
12005 if (strcmp (name
, "char16_t") == 0
12006 || strcmp (name
, "char32_t") == 0)
12008 encoding
= DW_ATE_UTF
;
12012 if ((dwarf_version
>= 3 || !dwarf_strict
)
12013 && lang_hooks
.types
.get_fixed_point_type_info
)
12015 memset (&fpt_info
, 0, sizeof (fpt_info
));
12016 if (lang_hooks
.types
.get_fixed_point_type_info (type
, &fpt_info
))
12019 encoding
= ((TYPE_UNSIGNED (type
))
12020 ? DW_ATE_unsigned_fixed
12021 : DW_ATE_signed_fixed
);
12025 if (TYPE_STRING_FLAG (type
))
12027 if (TYPE_UNSIGNED (type
))
12028 encoding
= DW_ATE_unsigned_char
;
12030 encoding
= DW_ATE_signed_char
;
12032 else if (TYPE_UNSIGNED (type
))
12033 encoding
= DW_ATE_unsigned
;
12035 encoding
= DW_ATE_signed
;
12038 && lang_hooks
.types
.get_type_bias
)
12039 type_bias
= lang_hooks
.types
.get_type_bias (type
);
12043 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
12045 if (dwarf_version
>= 3 || !dwarf_strict
)
12046 encoding
= DW_ATE_decimal_float
;
12048 encoding
= DW_ATE_lo_user
;
12051 encoding
= DW_ATE_float
;
12054 case FIXED_POINT_TYPE
:
12055 if (!(dwarf_version
>= 3 || !dwarf_strict
))
12056 encoding
= DW_ATE_lo_user
;
12057 else if (TYPE_UNSIGNED (type
))
12058 encoding
= DW_ATE_unsigned_fixed
;
12060 encoding
= DW_ATE_signed_fixed
;
12063 /* Dwarf2 doesn't know anything about complex ints, so use
12064 a user defined type for it. */
12066 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
12067 encoding
= DW_ATE_complex_float
;
12069 encoding
= DW_ATE_lo_user
;
12073 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12074 encoding
= DW_ATE_boolean
;
12078 /* No other TREE_CODEs are Dwarf fundamental types. */
12079 gcc_unreachable ();
12082 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
12084 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
12085 int_size_in_bytes (type
));
12086 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
12088 if (need_endianity_attribute_p (reverse
))
12089 add_AT_unsigned (base_type_result
, DW_AT_endianity
,
12090 BYTES_BIG_ENDIAN
? DW_END_little
: DW_END_big
);
12094 switch (fpt_info
.scale_factor_kind
)
12096 case fixed_point_scale_factor_binary
:
12097 add_AT_int (base_type_result
, DW_AT_binary_scale
,
12098 fpt_info
.scale_factor
.binary
);
12101 case fixed_point_scale_factor_decimal
:
12102 add_AT_int (base_type_result
, DW_AT_decimal_scale
,
12103 fpt_info
.scale_factor
.decimal
);
12106 case fixed_point_scale_factor_arbitrary
:
12107 /* Arbitrary scale factors cannot be described in standard DWARF,
12111 /* Describe the scale factor as a rational constant. */
12112 const dw_die_ref scale_factor
12113 = new_die (DW_TAG_constant
, comp_unit_die (), type
);
12115 add_AT_unsigned (scale_factor
, DW_AT_GNU_numerator
,
12116 fpt_info
.scale_factor
.arbitrary
.numerator
);
12117 add_AT_int (scale_factor
, DW_AT_GNU_denominator
,
12118 fpt_info
.scale_factor
.arbitrary
.denominator
);
12120 add_AT_die_ref (base_type_result
, DW_AT_small
, scale_factor
);
12125 gcc_unreachable ();
12130 add_scalar_info (base_type_result
, DW_AT_GNU_bias
, type_bias
,
12131 dw_scalar_form_constant
12132 | dw_scalar_form_exprloc
12133 | dw_scalar_form_reference
,
12136 add_pubtype (type
, base_type_result
);
12138 return base_type_result
;
12141 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
12142 named 'auto' in its type: return true for it, false otherwise. */
12145 is_cxx_auto (tree type
)
12149 tree name
= TYPE_IDENTIFIER (type
);
12150 if (name
== get_identifier ("auto")
12151 || name
== get_identifier ("decltype(auto)"))
12157 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12158 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12161 is_base_type (tree type
)
12163 switch (TREE_CODE (type
))
12169 case FIXED_POINT_TYPE
:
12172 case POINTER_BOUNDS_TYPE
:
12178 case QUAL_UNION_TYPE
:
12179 case ENUMERAL_TYPE
:
12180 case FUNCTION_TYPE
:
12183 case REFERENCE_TYPE
:
12191 if (is_cxx_auto (type
))
12193 gcc_unreachable ();
12199 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12200 node, return the size in bits for the type if it is a constant, or else
12201 return the alignment for the type if the type's size is not constant, or
12202 else return BITS_PER_WORD if the type actually turns out to be an
12203 ERROR_MARK node. */
12205 static inline unsigned HOST_WIDE_INT
12206 simple_type_size_in_bits (const_tree type
)
12208 if (TREE_CODE (type
) == ERROR_MARK
)
12209 return BITS_PER_WORD
;
12210 else if (TYPE_SIZE (type
) == NULL_TREE
)
12212 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
12213 return tree_to_uhwi (TYPE_SIZE (type
));
12215 return TYPE_ALIGN (type
);
12218 /* Similarly, but return an offset_int instead of UHWI. */
12220 static inline offset_int
12221 offset_int_type_size_in_bits (const_tree type
)
12223 if (TREE_CODE (type
) == ERROR_MARK
)
12224 return BITS_PER_WORD
;
12225 else if (TYPE_SIZE (type
) == NULL_TREE
)
12227 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
12228 return wi::to_offset (TYPE_SIZE (type
));
12230 return TYPE_ALIGN (type
);
12233 /* Given a pointer to a tree node for a subrange type, return a pointer
12234 to a DIE that describes the given type. */
12237 subrange_type_die (tree type
, tree low
, tree high
, tree bias
,
12238 dw_die_ref context_die
)
12240 dw_die_ref subrange_die
;
12241 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
12243 if (context_die
== NULL
)
12244 context_die
= comp_unit_die ();
12246 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
12248 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
12250 /* The size of the subrange type and its base type do not match,
12251 so we need to generate a size attribute for the subrange type. */
12252 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
12256 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
, NULL
);
12258 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
, NULL
);
12259 if (bias
&& !dwarf_strict
)
12260 add_scalar_info (subrange_die
, DW_AT_GNU_bias
, bias
,
12261 dw_scalar_form_constant
12262 | dw_scalar_form_exprloc
12263 | dw_scalar_form_reference
,
12266 return subrange_die
;
12269 /* Returns the (const and/or volatile) cv_qualifiers associated with
12270 the decl node. This will normally be augmented with the
12271 cv_qualifiers of the underlying type in add_type_attribute. */
12274 decl_quals (const_tree decl
)
12276 return ((TREE_READONLY (decl
)
12277 /* The C++ front-end correctly marks reference-typed
12278 variables as readonly, but from a language (and debug
12279 info) standpoint they are not const-qualified. */
12280 && TREE_CODE (TREE_TYPE (decl
)) != REFERENCE_TYPE
12281 ? TYPE_QUAL_CONST
: TYPE_UNQUALIFIED
)
12282 | (TREE_THIS_VOLATILE (decl
)
12283 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
));
12286 /* Determine the TYPE whose qualifiers match the largest strict subset
12287 of the given TYPE_QUALS, and return its qualifiers. Ignore all
12288 qualifiers outside QUAL_MASK. */
12291 get_nearest_type_subqualifiers (tree type
, int type_quals
, int qual_mask
)
12294 int best_rank
= 0, best_qual
= 0, max_rank
;
12296 type_quals
&= qual_mask
;
12297 max_rank
= popcount_hwi (type_quals
) - 1;
12299 for (t
= TYPE_MAIN_VARIANT (type
); t
&& best_rank
< max_rank
;
12300 t
= TYPE_NEXT_VARIANT (t
))
12302 int q
= TYPE_QUALS (t
) & qual_mask
;
12304 if ((q
& type_quals
) == q
&& q
!= type_quals
12305 && check_base_type (t
, type
))
12307 int rank
= popcount_hwi (q
);
12309 if (rank
> best_rank
)
12320 struct dwarf_qual_info_t
{ int q
; enum dwarf_tag t
; };
12321 static const dwarf_qual_info_t dwarf_qual_info
[] =
12323 { TYPE_QUAL_CONST
, DW_TAG_const_type
},
12324 { TYPE_QUAL_VOLATILE
, DW_TAG_volatile_type
},
12325 { TYPE_QUAL_RESTRICT
, DW_TAG_restrict_type
},
12326 { TYPE_QUAL_ATOMIC
, DW_TAG_atomic_type
}
12328 static const unsigned int dwarf_qual_info_size
12329 = sizeof (dwarf_qual_info
) / sizeof (dwarf_qual_info
[0]);
12331 /* If DIE is a qualified DIE of some base DIE with the same parent,
12332 return the base DIE, otherwise return NULL. Set MASK to the
12333 qualifiers added compared to the returned DIE. */
12336 qualified_die_p (dw_die_ref die
, int *mask
, unsigned int depth
)
12339 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
12340 if (die
->die_tag
== dwarf_qual_info
[i
].t
)
12342 if (i
== dwarf_qual_info_size
)
12344 if (vec_safe_length (die
->die_attr
) != 1)
12346 dw_die_ref type
= get_AT_ref (die
, DW_AT_type
);
12347 if (type
== NULL
|| type
->die_parent
!= die
->die_parent
)
12349 *mask
|= dwarf_qual_info
[i
].q
;
12352 dw_die_ref ret
= qualified_die_p (type
, mask
, depth
- 1);
12359 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12360 entry that chains the modifiers specified by CV_QUALS in front of the
12361 given type. REVERSE is true if the type is to be interpreted in the
12362 reverse storage order wrt the target order. */
12365 modified_type_die (tree type
, int cv_quals
, bool reverse
,
12366 dw_die_ref context_die
)
12368 enum tree_code code
= TREE_CODE (type
);
12369 dw_die_ref mod_type_die
;
12370 dw_die_ref sub_die
= NULL
;
12371 tree item_type
= NULL
;
12372 tree qualified_type
;
12373 tree name
, low
, high
;
12374 dw_die_ref mod_scope
;
12375 /* Only these cv-qualifiers are currently handled. */
12376 const int cv_qual_mask
= (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
12377 | TYPE_QUAL_RESTRICT
| TYPE_QUAL_ATOMIC
);
12379 if (code
== ERROR_MARK
)
12382 if (lang_hooks
.types
.get_debug_type
)
12384 tree debug_type
= lang_hooks
.types
.get_debug_type (type
);
12386 if (debug_type
!= NULL_TREE
&& debug_type
!= type
)
12387 return modified_type_die (debug_type
, cv_quals
, reverse
, context_die
);
12390 cv_quals
&= cv_qual_mask
;
12392 /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
12393 tag modifier (and not an attribute) old consumers won't be able
12395 if (dwarf_version
< 3)
12396 cv_quals
&= ~TYPE_QUAL_RESTRICT
;
12398 /* Likewise for DW_TAG_atomic_type for DWARFv5. */
12399 if (dwarf_version
< 5)
12400 cv_quals
&= ~TYPE_QUAL_ATOMIC
;
12402 /* See if we already have the appropriately qualified variant of
12404 qualified_type
= get_qualified_type (type
, cv_quals
);
12406 if (qualified_type
== sizetype
12407 && TYPE_NAME (qualified_type
)
12408 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
12410 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
12412 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
12413 && TYPE_PRECISION (t
)
12414 == TYPE_PRECISION (qualified_type
)
12415 && TYPE_UNSIGNED (t
)
12416 == TYPE_UNSIGNED (qualified_type
));
12417 qualified_type
= t
;
12420 /* If we do, then we can just use its DIE, if it exists. */
12421 if (qualified_type
)
12423 mod_type_die
= lookup_type_die (qualified_type
);
12425 /* DW_AT_endianity doesn't come from a qualifier on the type. */
12427 && (!need_endianity_attribute_p (reverse
)
12428 || !is_base_type (type
)
12429 || get_AT_unsigned (mod_type_die
, DW_AT_endianity
)))
12430 return mod_type_die
;
12433 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
12435 /* Handle C typedef types. */
12436 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
12437 && !DECL_ARTIFICIAL (name
))
12439 tree dtype
= TREE_TYPE (name
);
12441 if (qualified_type
== dtype
)
12443 /* For a named type, use the typedef. */
12444 gen_type_die (qualified_type
, context_die
);
12445 return lookup_type_die (qualified_type
);
12449 int dquals
= TYPE_QUALS_NO_ADDR_SPACE (dtype
);
12450 dquals
&= cv_qual_mask
;
12451 if ((dquals
& ~cv_quals
) != TYPE_UNQUALIFIED
12452 || (cv_quals
== dquals
&& DECL_ORIGINAL_TYPE (name
) != type
))
12453 /* cv-unqualified version of named type. Just use
12454 the unnamed type to which it refers. */
12455 return modified_type_die (DECL_ORIGINAL_TYPE (name
), cv_quals
,
12456 reverse
, context_die
);
12457 /* Else cv-qualified version of named type; fall through. */
12461 mod_scope
= scope_die_for (type
, context_die
);
12465 int sub_quals
= 0, first_quals
= 0;
12467 dw_die_ref first
= NULL
, last
= NULL
;
12469 /* Determine a lesser qualified type that most closely matches
12470 this one. Then generate DW_TAG_* entries for the remaining
12472 sub_quals
= get_nearest_type_subqualifiers (type
, cv_quals
,
12474 if (sub_quals
&& use_debug_types
)
12476 bool needed
= false;
12477 /* If emitting type units, make sure the order of qualifiers
12478 is canonical. Thus, start from unqualified type if
12479 an earlier qualifier is missing in sub_quals, but some later
12480 one is present there. */
12481 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
12482 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
12484 else if (needed
&& (dwarf_qual_info
[i
].q
& cv_quals
))
12490 mod_type_die
= modified_type_die (type
, sub_quals
, reverse
, context_die
);
12491 if (mod_scope
&& mod_type_die
&& mod_type_die
->die_parent
== mod_scope
)
12493 /* As not all intermediate qualified DIEs have corresponding
12494 tree types, ensure that qualified DIEs in the same scope
12495 as their DW_AT_type are emitted after their DW_AT_type,
12496 only with other qualified DIEs for the same type possibly
12497 in between them. Determine the range of such qualified
12498 DIEs now (first being the base type, last being corresponding
12499 last qualified DIE for it). */
12500 unsigned int count
= 0;
12501 first
= qualified_die_p (mod_type_die
, &first_quals
,
12502 dwarf_qual_info_size
);
12504 first
= mod_type_die
;
12505 gcc_assert ((first_quals
& ~sub_quals
) == 0);
12506 for (count
= 0, last
= first
;
12507 count
< (1U << dwarf_qual_info_size
);
12508 count
++, last
= last
->die_sib
)
12511 if (last
== mod_scope
->die_child
)
12513 if (qualified_die_p (last
->die_sib
, &quals
, dwarf_qual_info_size
)
12519 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
12520 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
12523 if (first
&& first
!= last
)
12525 for (d
= first
->die_sib
; ; d
= d
->die_sib
)
12528 qualified_die_p (d
, &quals
, dwarf_qual_info_size
);
12529 if (quals
== (first_quals
| dwarf_qual_info
[i
].q
))
12545 d
= ggc_cleared_alloc
<die_node
> ();
12546 d
->die_tag
= dwarf_qual_info
[i
].t
;
12547 add_child_die_after (mod_scope
, d
, last
);
12551 d
= new_die (dwarf_qual_info
[i
].t
, mod_scope
, type
);
12553 add_AT_die_ref (d
, DW_AT_type
, mod_type_die
);
12555 first_quals
|= dwarf_qual_info
[i
].q
;
12558 else if (code
== POINTER_TYPE
|| code
== REFERENCE_TYPE
)
12560 dwarf_tag tag
= DW_TAG_pointer_type
;
12561 if (code
== REFERENCE_TYPE
)
12563 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
12564 tag
= DW_TAG_rvalue_reference_type
;
12566 tag
= DW_TAG_reference_type
;
12568 mod_type_die
= new_die (tag
, mod_scope
, type
);
12570 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
12571 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
12572 item_type
= TREE_TYPE (type
);
12574 addr_space_t as
= TYPE_ADDR_SPACE (item_type
);
12575 if (!ADDR_SPACE_GENERIC_P (as
))
12577 int action
= targetm
.addr_space
.debug (as
);
12580 /* Positive values indicate an address_class. */
12581 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, action
);
12585 /* Negative values indicate an (inverted) segment base reg. */
12587 = one_reg_loc_descriptor (~action
, VAR_INIT_STATUS_INITIALIZED
);
12588 add_AT_loc (mod_type_die
, DW_AT_segment
, d
);
12592 else if (code
== INTEGER_TYPE
12593 && TREE_TYPE (type
) != NULL_TREE
12594 && subrange_type_for_debug_p (type
, &low
, &high
))
12596 tree bias
= NULL_TREE
;
12597 if (lang_hooks
.types
.get_type_bias
)
12598 bias
= lang_hooks
.types
.get_type_bias (type
);
12599 mod_type_die
= subrange_type_die (type
, low
, high
, bias
, context_die
);
12600 item_type
= TREE_TYPE (type
);
12602 else if (is_base_type (type
))
12603 mod_type_die
= base_type_die (type
, reverse
);
12606 gen_type_die (type
, context_die
);
12608 /* We have to get the type_main_variant here (and pass that to the
12609 `lookup_type_die' routine) because the ..._TYPE node we have
12610 might simply be a *copy* of some original type node (where the
12611 copy was created to help us keep track of typedef names) and
12612 that copy might have a different TYPE_UID from the original
12614 if (TREE_CODE (type
) == FUNCTION_TYPE
12615 || TREE_CODE (type
) == METHOD_TYPE
)
12617 /* For function/method types, can't just use type_main_variant here,
12618 because that can have different ref-qualifiers for C++,
12619 but try to canonicalize. */
12620 tree main
= TYPE_MAIN_VARIANT (type
);
12621 for (tree t
= main
; t
; t
= TYPE_NEXT_VARIANT (t
))
12622 if (check_base_type (t
, main
) && check_lang_type (t
, type
))
12623 return lookup_type_die (t
);
12624 return lookup_type_die (type
);
12626 else if (TREE_CODE (type
) != VECTOR_TYPE
12627 && TREE_CODE (type
) != ARRAY_TYPE
)
12628 return lookup_type_die (type_main_variant (type
));
12630 /* Vectors have the debugging information in the type,
12631 not the main variant. */
12632 return lookup_type_die (type
);
12635 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
12636 don't output a DW_TAG_typedef, since there isn't one in the
12637 user's program; just attach a DW_AT_name to the type.
12638 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
12639 if the base type already has the same name. */
12641 && ((TREE_CODE (name
) != TYPE_DECL
12642 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
12643 || (cv_quals
== TYPE_UNQUALIFIED
)))
12644 || (TREE_CODE (name
) == TYPE_DECL
12645 && TREE_TYPE (name
) == qualified_type
12646 && DECL_NAME (name
))))
12648 if (TREE_CODE (name
) == TYPE_DECL
)
12649 /* Could just call add_name_and_src_coords_attributes here,
12650 but since this is a builtin type it doesn't have any
12651 useful source coordinates anyway. */
12652 name
= DECL_NAME (name
);
12653 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
12655 /* This probably indicates a bug. */
12656 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
12658 name
= TYPE_IDENTIFIER (type
);
12659 add_name_attribute (mod_type_die
,
12660 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
12663 if (qualified_type
)
12664 equate_type_number_to_die (qualified_type
, mod_type_die
);
12667 /* We must do this after the equate_type_number_to_die call, in case
12668 this is a recursive type. This ensures that the modified_type_die
12669 recursion will terminate even if the type is recursive. Recursive
12670 types are possible in Ada. */
12671 sub_die
= modified_type_die (item_type
,
12672 TYPE_QUALS_NO_ADDR_SPACE (item_type
),
12676 if (sub_die
!= NULL
)
12677 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
12679 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
12680 if (TYPE_ARTIFICIAL (type
))
12681 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
12683 return mod_type_die
;
12686 /* Generate DIEs for the generic parameters of T.
12687 T must be either a generic type or a generic function.
12688 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
12691 gen_generic_params_dies (tree t
)
12695 dw_die_ref die
= NULL
;
12698 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
12702 die
= lookup_type_die (t
);
12703 else if (DECL_P (t
))
12704 die
= lookup_decl_die (t
);
12708 parms
= lang_hooks
.get_innermost_generic_parms (t
);
12710 /* T has no generic parameter. It means T is neither a generic type
12711 or function. End of story. */
12714 parms_num
= TREE_VEC_LENGTH (parms
);
12715 args
= lang_hooks
.get_innermost_generic_args (t
);
12716 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
12717 non_default
= int_cst_value (TREE_CHAIN (args
));
12719 non_default
= TREE_VEC_LENGTH (args
);
12720 for (i
= 0; i
< parms_num
; i
++)
12722 tree parm
, arg
, arg_pack_elems
;
12723 dw_die_ref parm_die
;
12725 parm
= TREE_VEC_ELT (parms
, i
);
12726 arg
= TREE_VEC_ELT (args
, i
);
12727 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
12728 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
12730 if (parm
&& TREE_VALUE (parm
) && arg
)
12732 /* If PARM represents a template parameter pack,
12733 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
12734 by DW_TAG_template_*_parameter DIEs for the argument
12735 pack elements of ARG. Note that ARG would then be
12736 an argument pack. */
12737 if (arg_pack_elems
)
12738 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
12742 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
12743 true /* emit name */, die
);
12744 if (i
>= non_default
)
12745 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
12750 /* Create and return a DIE for PARM which should be
12751 the representation of a generic type parameter.
12752 For instance, in the C++ front end, PARM would be a template parameter.
12753 ARG is the argument to PARM.
12754 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
12756 PARENT_DIE is the parent DIE which the new created DIE should be added to,
12757 as a child node. */
12760 generic_parameter_die (tree parm
, tree arg
,
12762 dw_die_ref parent_die
)
12764 dw_die_ref tmpl_die
= NULL
;
12765 const char *name
= NULL
;
12767 if (!parm
|| !DECL_NAME (parm
) || !arg
)
12770 /* We support non-type generic parameters and arguments,
12771 type generic parameters and arguments, as well as
12772 generic generic parameters (a.k.a. template template parameters in C++)
12774 if (TREE_CODE (parm
) == PARM_DECL
)
12775 /* PARM is a nontype generic parameter */
12776 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
12777 else if (TREE_CODE (parm
) == TYPE_DECL
)
12778 /* PARM is a type generic parameter. */
12779 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
12780 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
12781 /* PARM is a generic generic parameter.
12782 Its DIE is a GNU extension. It shall have a
12783 DW_AT_name attribute to represent the name of the template template
12784 parameter, and a DW_AT_GNU_template_name attribute to represent the
12785 name of the template template argument. */
12786 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
12789 gcc_unreachable ();
12795 /* If PARM is a generic parameter pack, it means we are
12796 emitting debug info for a template argument pack element.
12797 In other terms, ARG is a template argument pack element.
12798 In that case, we don't emit any DW_AT_name attribute for
12802 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
12804 add_AT_string (tmpl_die
, DW_AT_name
, name
);
12807 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
12809 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
12810 TMPL_DIE should have a child DW_AT_type attribute that is set
12811 to the type of the argument to PARM, which is ARG.
12812 If PARM is a type generic parameter, TMPL_DIE should have a
12813 child DW_AT_type that is set to ARG. */
12814 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
12815 add_type_attribute (tmpl_die
, tmpl_type
,
12816 (TREE_THIS_VOLATILE (tmpl_type
)
12817 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
),
12818 false, parent_die
);
12822 /* So TMPL_DIE is a DIE representing a
12823 a generic generic template parameter, a.k.a template template
12824 parameter in C++ and arg is a template. */
12826 /* The DW_AT_GNU_template_name attribute of the DIE must be set
12827 to the name of the argument. */
12828 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
12830 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
12833 if (TREE_CODE (parm
) == PARM_DECL
)
12834 /* So PARM is a non-type generic parameter.
12835 DWARF3 5.6.8 says we must set a DW_AT_const_value child
12836 attribute of TMPL_DIE which value represents the value
12838 We must be careful here:
12839 The value of ARG might reference some function decls.
12840 We might currently be emitting debug info for a generic
12841 type and types are emitted before function decls, we don't
12842 know if the function decls referenced by ARG will actually be
12843 emitted after cgraph computations.
12844 So must defer the generation of the DW_AT_const_value to
12845 after cgraph is ready. */
12846 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
12852 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
12853 PARM_PACK must be a template parameter pack. The returned DIE
12854 will be child DIE of PARENT_DIE. */
12857 template_parameter_pack_die (tree parm_pack
,
12858 tree parm_pack_args
,
12859 dw_die_ref parent_die
)
12864 gcc_assert (parent_die
&& parm_pack
);
12866 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
12867 add_name_and_src_coords_attributes (die
, parm_pack
);
12868 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
12869 generic_parameter_die (parm_pack
,
12870 TREE_VEC_ELT (parm_pack_args
, j
),
12871 false /* Don't emit DW_AT_name */,
12876 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
12877 an enumerated type. */
12880 type_is_enum (const_tree type
)
12882 return TREE_CODE (type
) == ENUMERAL_TYPE
;
12885 /* Return the DBX register number described by a given RTL node. */
12887 static unsigned int
12888 dbx_reg_number (const_rtx rtl
)
12890 unsigned regno
= REGNO (rtl
);
12892 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
12894 #ifdef LEAF_REG_REMAP
12895 if (crtl
->uses_only_leaf_regs
)
12897 int leaf_reg
= LEAF_REG_REMAP (regno
);
12898 if (leaf_reg
!= -1)
12899 regno
= (unsigned) leaf_reg
;
12903 regno
= DBX_REGISTER_NUMBER (regno
);
12904 gcc_assert (regno
!= INVALID_REGNUM
);
12908 /* Optionally add a DW_OP_piece term to a location description expression.
12909 DW_OP_piece is only added if the location description expression already
12910 doesn't end with DW_OP_piece. */
12913 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
12915 dw_loc_descr_ref loc
;
12917 if (*list_head
!= NULL
)
12919 /* Find the end of the chain. */
12920 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
12923 if (loc
->dw_loc_opc
!= DW_OP_piece
)
12924 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
12928 /* Return a location descriptor that designates a machine register or
12929 zero if there is none. */
12931 static dw_loc_descr_ref
12932 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
12936 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
12939 /* We only use "frame base" when we're sure we're talking about the
12940 post-prologue local stack frame. We do this by *not* running
12941 register elimination until this point, and recognizing the special
12942 argument pointer and soft frame pointer rtx's.
12943 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
12944 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
12945 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
12947 dw_loc_descr_ref result
= NULL
;
12949 if (dwarf_version
>= 4 || !dwarf_strict
)
12951 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
12954 add_loc_descr (&result
,
12955 new_loc_descr (DW_OP_stack_value
, 0, 0));
12960 regs
= targetm
.dwarf_register_span (rtl
);
12962 if (REG_NREGS (rtl
) > 1 || regs
)
12963 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
12966 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
12967 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12969 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
12973 /* Return a location descriptor that designates a machine register for
12974 a given hard register number. */
12976 static dw_loc_descr_ref
12977 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
12979 dw_loc_descr_ref reg_loc_descr
;
12983 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
12985 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
12987 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12988 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12990 return reg_loc_descr
;
12993 /* Given an RTL of a register, return a location descriptor that
12994 designates a value that spans more than one register. */
12996 static dw_loc_descr_ref
12997 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
12998 enum var_init_status initialized
)
13001 dw_loc_descr_ref loc_result
= NULL
;
13003 /* Simple, contiguous registers. */
13004 if (regs
== NULL_RTX
)
13006 unsigned reg
= REGNO (rtl
);
13009 #ifdef LEAF_REG_REMAP
13010 if (crtl
->uses_only_leaf_regs
)
13012 int leaf_reg
= LEAF_REG_REMAP (reg
);
13013 if (leaf_reg
!= -1)
13014 reg
= (unsigned) leaf_reg
;
13018 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
13019 nregs
= REG_NREGS (rtl
);
13021 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
13026 dw_loc_descr_ref t
;
13028 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
13029 VAR_INIT_STATUS_INITIALIZED
);
13030 add_loc_descr (&loc_result
, t
);
13031 add_loc_descr_op_piece (&loc_result
, size
);
13037 /* Now onto stupid register sets in non contiguous locations. */
13039 gcc_assert (GET_CODE (regs
) == PARALLEL
);
13041 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
13044 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
13046 dw_loc_descr_ref t
;
13048 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
13049 VAR_INIT_STATUS_INITIALIZED
);
13050 add_loc_descr (&loc_result
, t
);
13051 add_loc_descr_op_piece (&loc_result
, size
);
13054 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13055 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13059 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
13061 /* Return a location descriptor that designates a constant i,
13062 as a compound operation from constant (i >> shift), constant shift
13065 static dw_loc_descr_ref
13066 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
13068 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
13069 add_loc_descr (&ret
, int_loc_descriptor (shift
));
13070 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
13074 /* Return a location descriptor that designates a constant. */
13076 static dw_loc_descr_ref
13077 int_loc_descriptor (HOST_WIDE_INT i
)
13079 enum dwarf_location_atom op
;
13081 /* Pick the smallest representation of a constant, rather than just
13082 defaulting to the LEB encoding. */
13085 int clz
= clz_hwi (i
);
13086 int ctz
= ctz_hwi (i
);
13088 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
13089 else if (i
<= 0xff)
13090 op
= DW_OP_const1u
;
13091 else if (i
<= 0xffff)
13092 op
= DW_OP_const2u
;
13093 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
13094 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
13095 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
13096 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
13097 while DW_OP_const4u is 5 bytes. */
13098 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
13099 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13100 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
13101 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
13102 while DW_OP_const4u is 5 bytes. */
13103 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
13105 else if (DWARF2_ADDR_SIZE
== 4 && i
> 0x7fffffff
13106 && size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
)
13109 /* As i >= 2**31, the double cast above will yield a negative number.
13110 Since wrapping is defined in DWARF expressions we can output big
13111 positive integers as small negative ones, regardless of the size
13114 Here, since the evaluator will handle 32-bit values and since i >=
13115 2**31, we know it's going to be interpreted as a negative literal:
13116 store it this way if we can do better than 5 bytes this way. */
13117 return int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
);
13119 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
13120 op
= DW_OP_const4u
;
13122 /* Past this point, i >= 0x100000000 and thus DW_OP_constu will take at
13123 least 6 bytes: see if we can do better before falling back to it. */
13124 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13125 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
13126 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes. */
13127 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
13128 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
13129 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
13130 >= HOST_BITS_PER_WIDE_INT
)
13131 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
13132 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes. */
13133 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
13134 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
13135 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
13136 && size_of_uleb128 (i
) > 6)
13137 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
13138 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
13145 op
= DW_OP_const1s
;
13146 else if (i
>= -0x8000)
13147 op
= DW_OP_const2s
;
13148 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
13150 if (size_of_int_loc_descriptor (i
) < 5)
13152 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
13153 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
13156 op
= DW_OP_const4s
;
13160 if (size_of_int_loc_descriptor (i
)
13161 < (unsigned long) 1 + size_of_sleb128 (i
))
13163 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
13164 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
13171 return new_loc_descr (op
, i
, 0);
13174 /* Likewise, for unsigned constants. */
13176 static dw_loc_descr_ref
13177 uint_loc_descriptor (unsigned HOST_WIDE_INT i
)
13179 const unsigned HOST_WIDE_INT max_int
= INTTYPE_MAXIMUM (HOST_WIDE_INT
);
13180 const unsigned HOST_WIDE_INT max_uint
13181 = INTTYPE_MAXIMUM (unsigned HOST_WIDE_INT
);
13183 /* If possible, use the clever signed constants handling. */
13185 return int_loc_descriptor ((HOST_WIDE_INT
) i
);
13187 /* Here, we are left with positive numbers that cannot be represented as
13188 HOST_WIDE_INT, i.e.:
13189 max (HOST_WIDE_INT) < i <= max (unsigned HOST_WIDE_INT)
13191 Using DW_OP_const4/8/./u operation to encode them consumes a lot of bytes
13192 whereas may be better to output a negative integer: thanks to integer
13193 wrapping, we know that:
13194 x = x - 2 ** DWARF2_ADDR_SIZE
13195 = x - 2 * (max (HOST_WIDE_INT) + 1)
13196 So numbers close to max (unsigned HOST_WIDE_INT) could be represented as
13197 small negative integers. Let's try that in cases it will clearly improve
13198 the encoding: there is no gain turning DW_OP_const4u into
13200 if (DWARF2_ADDR_SIZE
* 8 == HOST_BITS_PER_WIDE_INT
13201 && ((DWARF2_ADDR_SIZE
== 4 && i
> max_uint
- 0x8000)
13202 || (DWARF2_ADDR_SIZE
== 8 && i
> max_uint
- 0x80000000)))
13204 const unsigned HOST_WIDE_INT first_shift
= i
- max_int
- 1;
13206 /* Now, -1 < first_shift <= max (HOST_WIDE_INT)
13207 i.e. 0 <= first_shift <= max (HOST_WIDE_INT). */
13208 const HOST_WIDE_INT second_shift
13209 = (HOST_WIDE_INT
) first_shift
- (HOST_WIDE_INT
) max_int
- 1;
13211 /* So we finally have:
13212 -max (HOST_WIDE_INT) - 1 <= second_shift <= -1.
13213 i.e. min (HOST_WIDE_INT) <= second_shift < 0. */
13214 return int_loc_descriptor (second_shift
);
13217 /* Last chance: fallback to a simple constant operation. */
13218 return new_loc_descr
13219 ((HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
13225 /* Generate and return a location description that computes the unsigned
13226 comparison of the two stack top entries (a OP b where b is the top-most
13227 entry and a is the second one). The KIND of comparison can be LT_EXPR,
13228 LE_EXPR, GT_EXPR or GE_EXPR. */
13230 static dw_loc_descr_ref
13231 uint_comparison_loc_list (enum tree_code kind
)
13233 enum dwarf_location_atom op
, flip_op
;
13234 dw_loc_descr_ref ret
, bra_node
, jmp_node
, tmp
;
13251 gcc_unreachable ();
13254 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
13255 jmp_node
= new_loc_descr (DW_OP_skip
, 0, 0);
13257 /* Until DWARFv4, operations all work on signed integers. It is nevertheless
13258 possible to perform unsigned comparisons: we just have to distinguish
13261 1. when a and b have the same sign (as signed integers); then we should
13262 return: a OP(signed) b;
13264 2. when a is a negative signed integer while b is a positive one, then a
13265 is a greater unsigned integer than b; likewise when a and b's roles
13268 So first, compare the sign of the two operands. */
13269 ret
= new_loc_descr (DW_OP_over
, 0, 0);
13270 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
13271 add_loc_descr (&ret
, new_loc_descr (DW_OP_xor
, 0, 0));
13272 /* If they have different signs (i.e. they have different sign bits), then
13273 the stack top value has now the sign bit set and thus it's smaller than
13275 add_loc_descr (&ret
, new_loc_descr (DW_OP_lit0
, 0, 0));
13276 add_loc_descr (&ret
, new_loc_descr (DW_OP_lt
, 0, 0));
13277 add_loc_descr (&ret
, bra_node
);
13279 /* We are in case 1. At this point, we know both operands have the same
13280 sign, to it's safe to use the built-in signed comparison. */
13281 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
13282 add_loc_descr (&ret
, jmp_node
);
13284 /* We are in case 2. Here, we know both operands do not have the same sign,
13285 so we have to flip the signed comparison. */
13286 flip_op
= (kind
== LT_EXPR
|| kind
== LE_EXPR
) ? DW_OP_gt
: DW_OP_lt
;
13287 tmp
= new_loc_descr (flip_op
, 0, 0);
13288 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13289 bra_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
13290 add_loc_descr (&ret
, tmp
);
13292 /* This dummy operation is necessary to make the two branches join. */
13293 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
13294 jmp_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13295 jmp_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
13296 add_loc_descr (&ret
, tmp
);
13301 /* Likewise, but takes the location description lists (might be destructive on
13302 them). Return NULL if either is NULL or if concatenation fails. */
13304 static dw_loc_list_ref
13305 loc_list_from_uint_comparison (dw_loc_list_ref left
, dw_loc_list_ref right
,
13306 enum tree_code kind
)
13308 if (left
== NULL
|| right
== NULL
)
13311 add_loc_list (&left
, right
);
13315 add_loc_descr_to_each (left
, uint_comparison_loc_list (kind
));
13319 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
13320 without actually allocating it. */
13322 static unsigned long
13323 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
13325 return size_of_int_loc_descriptor (i
>> shift
)
13326 + size_of_int_loc_descriptor (shift
)
13330 /* Return size_of_locs (int_loc_descriptor (i)) without
13331 actually allocating it. */
13333 static unsigned long
13334 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
13343 else if (i
<= 0xff)
13345 else if (i
<= 0xffff)
13349 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
13350 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
13351 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13353 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13354 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
13355 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13357 else if (DWARF2_ADDR_SIZE
== 4 && i
> 0x7fffffff
13358 && size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
)
13360 return size_of_int_loc_descriptor ((HOST_WIDE_INT
) (int32_t) i
);
13361 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
13363 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
13364 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
13365 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
13366 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13368 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
13369 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
13370 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13372 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
13373 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
13375 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
13384 else if (i
>= -0x8000)
13386 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
13388 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
13390 s
= size_of_int_loc_descriptor (-i
) + 1;
13398 unsigned long r
= 1 + size_of_sleb128 (i
);
13399 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
13401 s
= size_of_int_loc_descriptor (-i
) + 1;
13410 /* Return loc description representing "address" of integer value.
13411 This can appear only as toplevel expression. */
13413 static dw_loc_descr_ref
13414 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
13417 dw_loc_descr_ref loc_result
= NULL
;
13419 if (!(dwarf_version
>= 4 || !dwarf_strict
))
13422 litsize
= size_of_int_loc_descriptor (i
);
13423 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13424 is more compact. For DW_OP_stack_value we need:
13425 litsize + 1 (DW_OP_stack_value)
13426 and for DW_OP_implicit_value:
13427 1 (DW_OP_implicit_value) + 1 (length) + size. */
13428 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
13430 loc_result
= int_loc_descriptor (i
);
13431 add_loc_descr (&loc_result
,
13432 new_loc_descr (DW_OP_stack_value
, 0, 0));
13436 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13438 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13439 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
13443 /* Return a location descriptor that designates a base+offset location. */
13445 static dw_loc_descr_ref
13446 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
13447 enum var_init_status initialized
)
13449 unsigned int regno
;
13450 dw_loc_descr_ref result
;
13451 dw_fde_ref fde
= cfun
->fde
;
13453 /* We only use "frame base" when we're sure we're talking about the
13454 post-prologue local stack frame. We do this by *not* running
13455 register elimination until this point, and recognizing the special
13456 argument pointer and soft frame pointer rtx's. */
13457 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
13459 rtx elim
= (ira_use_lra_p
13460 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
13461 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
13465 if (GET_CODE (elim
) == PLUS
)
13467 offset
+= INTVAL (XEXP (elim
, 1));
13468 elim
= XEXP (elim
, 0);
13470 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13471 && (elim
== hard_frame_pointer_rtx
13472 || elim
== stack_pointer_rtx
))
13473 || elim
== (frame_pointer_needed
13474 ? hard_frame_pointer_rtx
13475 : stack_pointer_rtx
));
13477 /* If drap register is used to align stack, use frame
13478 pointer + offset to access stack variables. If stack
13479 is aligned without drap, use stack pointer + offset to
13480 access stack variables. */
13481 if (crtl
->stack_realign_tried
13482 && reg
== frame_pointer_rtx
)
13485 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
13486 ? HARD_FRAME_POINTER_REGNUM
13488 return new_reg_loc_descr (base_reg
, offset
);
13491 gcc_assert (frame_pointer_fb_offset_valid
);
13492 offset
+= frame_pointer_fb_offset
;
13493 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
13497 regno
= REGNO (reg
);
13498 #ifdef LEAF_REG_REMAP
13499 if (crtl
->uses_only_leaf_regs
)
13501 int leaf_reg
= LEAF_REG_REMAP (regno
);
13502 if (leaf_reg
!= -1)
13503 regno
= (unsigned) leaf_reg
;
13506 regno
= DWARF_FRAME_REGNUM (regno
);
13508 if (!optimize
&& fde
13509 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
13511 /* Use cfa+offset to represent the location of arguments passed
13512 on the stack when drap is used to align stack.
13513 Only do this when not optimizing, for optimized code var-tracking
13514 is supposed to track where the arguments live and the register
13515 used as vdrap or drap in some spot might be used for something
13516 else in other part of the routine. */
13517 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
13521 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
13524 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
13526 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13527 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13532 /* Return true if this RTL expression describes a base+offset calculation. */
13535 is_based_loc (const_rtx rtl
)
13537 return (GET_CODE (rtl
) == PLUS
13538 && ((REG_P (XEXP (rtl
, 0))
13539 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
13540 && CONST_INT_P (XEXP (rtl
, 1)))));
13543 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13546 static dw_loc_descr_ref
13547 tls_mem_loc_descriptor (rtx mem
)
13550 dw_loc_descr_ref loc_result
;
13552 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
13555 base
= get_base_address (MEM_EXPR (mem
));
13558 || !DECL_THREAD_LOCAL_P (base
))
13561 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1, NULL
);
13562 if (loc_result
== NULL
)
13565 if (MEM_OFFSET (mem
))
13566 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
13571 /* Output debug info about reason why we failed to expand expression as dwarf
13575 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
13577 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
13579 fprintf (dump_file
, "Failed to expand as dwarf: ");
13581 print_generic_expr (dump_file
, expr
, dump_flags
);
13584 fprintf (dump_file
, "\n");
13585 print_rtl (dump_file
, rtl
);
13587 fprintf (dump_file
, "\nReason: %s\n", reason
);
13591 /* Helper function for const_ok_for_output. */
13594 const_ok_for_output_1 (rtx rtl
)
13596 if (GET_CODE (rtl
) == UNSPEC
)
13598 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
13599 we can't express it in the debug info. */
13600 /* Don't complain about TLS UNSPECs, those are just too hard to
13601 delegitimize. Note this could be a non-decl SYMBOL_REF such as
13602 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
13603 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
13605 && (XVECLEN (rtl
, 0) == 0
13606 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
13607 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
))
13608 inform (current_function_decl
13609 ? DECL_SOURCE_LOCATION (current_function_decl
)
13610 : UNKNOWN_LOCATION
,
13611 #if NUM_UNSPEC_VALUES > 0
13612 "non-delegitimized UNSPEC %s (%d) found in variable location",
13613 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
13614 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
13617 "non-delegitimized UNSPEC %d found in variable location",
13620 expansion_failed (NULL_TREE
, rtl
,
13621 "UNSPEC hasn't been delegitimized.\n");
13625 if (targetm
.const_not_ok_for_debug_p (rtl
))
13627 expansion_failed (NULL_TREE
, rtl
,
13628 "Expression rejected for debug by the backend.\n");
13632 /* FIXME: Refer to PR60655. It is possible for simplification
13633 of rtl expressions in var tracking to produce such expressions.
13634 We should really identify / validate expressions
13635 enclosed in CONST that can be handled by assemblers on various
13636 targets and only handle legitimate cases here. */
13637 if (GET_CODE (rtl
) != SYMBOL_REF
)
13639 if (GET_CODE (rtl
) == NOT
)
13644 if (CONSTANT_POOL_ADDRESS_P (rtl
))
13647 get_pool_constant_mark (rtl
, &marked
);
13648 /* If all references to this pool constant were optimized away,
13649 it was not output and thus we can't represent it. */
13652 expansion_failed (NULL_TREE
, rtl
,
13653 "Constant was removed from constant pool.\n");
13658 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
13661 /* Avoid references to external symbols in debug info, on several targets
13662 the linker might even refuse to link when linking a shared library,
13663 and in many other cases the relocations for .debug_info/.debug_loc are
13664 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13665 to be defined within the same shared library or executable are fine. */
13666 if (SYMBOL_REF_EXTERNAL_P (rtl
))
13668 tree decl
= SYMBOL_REF_DECL (rtl
);
13670 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
13672 expansion_failed (NULL_TREE
, rtl
,
13673 "Symbol not defined in current TU.\n");
13681 /* Return true if constant RTL can be emitted in DW_OP_addr or
13682 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13683 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13686 const_ok_for_output (rtx rtl
)
13688 if (GET_CODE (rtl
) == SYMBOL_REF
)
13689 return const_ok_for_output_1 (rtl
);
13691 if (GET_CODE (rtl
) == CONST
)
13693 subrtx_var_iterator::array_type array
;
13694 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 0), ALL
)
13695 if (!const_ok_for_output_1 (*iter
))
13703 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
13704 if possible, NULL otherwise. */
13707 base_type_for_mode (machine_mode mode
, bool unsignedp
)
13709 dw_die_ref type_die
;
13710 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
13714 switch (TREE_CODE (type
))
13722 type_die
= lookup_type_die (type
);
13724 type_die
= modified_type_die (type
, TYPE_UNQUALIFIED
, false,
13726 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
13731 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
13732 type matching MODE, or, if MODE is narrower than or as wide as
13733 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
13736 static dw_loc_descr_ref
13737 convert_descriptor_to_mode (machine_mode mode
, dw_loc_descr_ref op
)
13739 machine_mode outer_mode
= mode
;
13740 dw_die_ref type_die
;
13741 dw_loc_descr_ref cvt
;
13743 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
13745 add_loc_descr (&op
, new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0));
13748 type_die
= base_type_for_mode (outer_mode
, 1);
13749 if (type_die
== NULL
)
13751 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
13752 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13753 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13754 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13755 add_loc_descr (&op
, cvt
);
13759 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
13761 static dw_loc_descr_ref
13762 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
13763 dw_loc_descr_ref op1
)
13765 dw_loc_descr_ref ret
= op0
;
13766 add_loc_descr (&ret
, op1
);
13767 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
13768 if (STORE_FLAG_VALUE
!= 1)
13770 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
13771 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
13776 /* Return location descriptor for signed comparison OP RTL. */
13778 static dw_loc_descr_ref
13779 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
13780 machine_mode mem_mode
)
13782 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
13783 dw_loc_descr_ref op0
, op1
;
13786 if (op_mode
== VOIDmode
)
13787 op_mode
= GET_MODE (XEXP (rtl
, 1));
13788 if (op_mode
== VOIDmode
)
13792 && dwarf_version
< 5
13793 && (!SCALAR_INT_MODE_P (op_mode
)
13794 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
13797 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
13798 VAR_INIT_STATUS_INITIALIZED
);
13799 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
13800 VAR_INIT_STATUS_INITIALIZED
);
13802 if (op0
== NULL
|| op1
== NULL
)
13805 if (!SCALAR_INT_MODE_P (op_mode
)
13806 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
13807 return compare_loc_descriptor (op
, op0
, op1
);
13809 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
13811 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
13812 dw_loc_descr_ref cvt
;
13814 if (type_die
== NULL
)
13816 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
13817 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13818 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13819 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13820 add_loc_descr (&op0
, cvt
);
13821 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
13822 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13823 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13824 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13825 add_loc_descr (&op1
, cvt
);
13826 return compare_loc_descriptor (op
, op0
, op1
);
13829 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
13830 /* For eq/ne, if the operands are known to be zero-extended,
13831 there is no need to do the fancy shifting up. */
13832 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
13834 dw_loc_descr_ref last0
, last1
;
13835 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
13837 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
13839 /* deref_size zero extends, and for constants we can check
13840 whether they are zero extended or not. */
13841 if (((last0
->dw_loc_opc
== DW_OP_deref_size
13842 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
13843 || (CONST_INT_P (XEXP (rtl
, 0))
13844 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
13845 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
13846 && ((last1
->dw_loc_opc
== DW_OP_deref_size
13847 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
13848 || (CONST_INT_P (XEXP (rtl
, 1))
13849 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
13850 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
13851 return compare_loc_descriptor (op
, op0
, op1
);
13853 /* EQ/NE comparison against constant in narrower type than
13854 DWARF2_ADDR_SIZE can be performed either as
13855 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
13858 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
13859 DW_OP_{eq,ne}. Pick whatever is shorter. */
13860 if (CONST_INT_P (XEXP (rtl
, 1))
13861 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
13862 && (size_of_int_loc_descriptor (shift
) + 1
13863 + size_of_int_loc_descriptor (UINTVAL (XEXP (rtl
, 1)) << shift
)
13864 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
13865 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
13866 & GET_MODE_MASK (op_mode
))))
13868 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
13869 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
13870 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
13871 & GET_MODE_MASK (op_mode
));
13872 return compare_loc_descriptor (op
, op0
, op1
);
13875 add_loc_descr (&op0
, int_loc_descriptor (shift
));
13876 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
13877 if (CONST_INT_P (XEXP (rtl
, 1)))
13878 op1
= int_loc_descriptor (UINTVAL (XEXP (rtl
, 1)) << shift
);
13881 add_loc_descr (&op1
, int_loc_descriptor (shift
));
13882 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
13884 return compare_loc_descriptor (op
, op0
, op1
);
13887 /* Return location descriptor for unsigned comparison OP RTL. */
13889 static dw_loc_descr_ref
13890 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
13891 machine_mode mem_mode
)
13893 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
13894 dw_loc_descr_ref op0
, op1
;
13896 if (op_mode
== VOIDmode
)
13897 op_mode
= GET_MODE (XEXP (rtl
, 1));
13898 if (op_mode
== VOIDmode
)
13900 if (!SCALAR_INT_MODE_P (op_mode
))
13904 && dwarf_version
< 5
13905 && GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
13908 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
13909 VAR_INIT_STATUS_INITIALIZED
);
13910 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
13911 VAR_INIT_STATUS_INITIALIZED
);
13913 if (op0
== NULL
|| op1
== NULL
)
13916 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
13918 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
13919 dw_loc_descr_ref last0
, last1
;
13920 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
13922 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
13924 if (CONST_INT_P (XEXP (rtl
, 0)))
13925 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
13926 /* deref_size zero extends, so no need to mask it again. */
13927 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
13928 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
13930 add_loc_descr (&op0
, int_loc_descriptor (mask
));
13931 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
13933 if (CONST_INT_P (XEXP (rtl
, 1)))
13934 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
13935 /* deref_size zero extends, so no need to mask it again. */
13936 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
13937 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
13939 add_loc_descr (&op1
, int_loc_descriptor (mask
));
13940 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
13943 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
13945 HOST_WIDE_INT bias
= 1;
13946 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
13947 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
13948 if (CONST_INT_P (XEXP (rtl
, 1)))
13949 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
13950 + INTVAL (XEXP (rtl
, 1)));
13952 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
13955 return compare_loc_descriptor (op
, op0
, op1
);
13958 /* Return location descriptor for {U,S}{MIN,MAX}. */
13960 static dw_loc_descr_ref
13961 minmax_loc_descriptor (rtx rtl
, machine_mode mode
,
13962 machine_mode mem_mode
)
13964 enum dwarf_location_atom op
;
13965 dw_loc_descr_ref op0
, op1
, ret
;
13966 dw_loc_descr_ref bra_node
, drop_node
;
13969 && dwarf_version
< 5
13970 && (!SCALAR_INT_MODE_P (mode
)
13971 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
13974 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13975 VAR_INIT_STATUS_INITIALIZED
);
13976 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13977 VAR_INIT_STATUS_INITIALIZED
);
13979 if (op0
== NULL
|| op1
== NULL
)
13982 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
13983 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
13984 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
13985 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
13987 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
13989 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
13990 add_loc_descr (&op0
, int_loc_descriptor (mask
));
13991 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
13992 add_loc_descr (&op1
, int_loc_descriptor (mask
));
13993 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
13995 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
13997 HOST_WIDE_INT bias
= 1;
13998 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
13999 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14000 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
14003 else if (!SCALAR_INT_MODE_P (mode
)
14004 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
14006 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
14007 add_loc_descr (&op0
, int_loc_descriptor (shift
));
14008 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
14009 add_loc_descr (&op1
, int_loc_descriptor (shift
));
14010 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
14012 else if (SCALAR_INT_MODE_P (mode
)
14013 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
14015 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
14016 dw_loc_descr_ref cvt
;
14017 if (type_die
== NULL
)
14019 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14020 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14021 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14022 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14023 add_loc_descr (&op0
, cvt
);
14024 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14025 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14026 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14027 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14028 add_loc_descr (&op1
, cvt
);
14031 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
14036 add_loc_descr (&ret
, op1
);
14037 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
14038 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14039 add_loc_descr (&ret
, bra_node
);
14040 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14041 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
14042 add_loc_descr (&ret
, drop_node
);
14043 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14044 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
14045 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
14046 && SCALAR_INT_MODE_P (mode
)
14047 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
14048 ret
= convert_descriptor_to_mode (mode
, ret
);
14052 /* Helper function for mem_loc_descriptor. Perform OP binary op,
14053 but after converting arguments to type_die, afterwards
14054 convert back to unsigned. */
14056 static dw_loc_descr_ref
14057 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
14058 machine_mode mode
, machine_mode mem_mode
)
14060 dw_loc_descr_ref cvt
, op0
, op1
;
14062 if (type_die
== NULL
)
14064 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14065 VAR_INIT_STATUS_INITIALIZED
);
14066 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
14067 VAR_INIT_STATUS_INITIALIZED
);
14068 if (op0
== NULL
|| op1
== NULL
)
14070 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14071 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14072 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14073 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14074 add_loc_descr (&op0
, cvt
);
14075 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14076 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14077 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14078 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14079 add_loc_descr (&op1
, cvt
);
14080 add_loc_descr (&op0
, op1
);
14081 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
14082 return convert_descriptor_to_mode (mode
, op0
);
14085 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
14086 const0 is DW_OP_lit0 or corresponding typed constant,
14087 const1 is DW_OP_lit1 or corresponding typed constant
14088 and constMSB is constant with just the MSB bit set
14090 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
14091 L1: const0 DW_OP_swap
14092 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
14093 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14098 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
14099 L1: const0 DW_OP_swap
14100 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
14101 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14106 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
14107 L1: const1 DW_OP_swap
14108 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
14109 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
14113 static dw_loc_descr_ref
14114 clz_loc_descriptor (rtx rtl
, machine_mode mode
,
14115 machine_mode mem_mode
)
14117 dw_loc_descr_ref op0
, ret
, tmp
;
14118 HOST_WIDE_INT valv
;
14119 dw_loc_descr_ref l1jump
, l1label
;
14120 dw_loc_descr_ref l2jump
, l2label
;
14121 dw_loc_descr_ref l3jump
, l3label
;
14122 dw_loc_descr_ref l4jump
, l4label
;
14125 if (!SCALAR_INT_MODE_P (mode
)
14126 || GET_MODE (XEXP (rtl
, 0)) != mode
)
14129 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14130 VAR_INIT_STATUS_INITIALIZED
);
14134 if (GET_CODE (rtl
) == CLZ
)
14136 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
14137 valv
= GET_MODE_BITSIZE (mode
);
14139 else if (GET_CODE (rtl
) == FFS
)
14141 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
14142 valv
= GET_MODE_BITSIZE (mode
);
14143 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
14144 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14145 add_loc_descr (&ret
, l1jump
);
14146 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
14147 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
14148 VAR_INIT_STATUS_INITIALIZED
);
14151 add_loc_descr (&ret
, tmp
);
14152 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14153 add_loc_descr (&ret
, l4jump
);
14154 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
14155 ? const1_rtx
: const0_rtx
,
14157 VAR_INIT_STATUS_INITIALIZED
);
14158 if (l1label
== NULL
)
14160 add_loc_descr (&ret
, l1label
);
14161 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14162 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
14163 add_loc_descr (&ret
, l2label
);
14164 if (GET_CODE (rtl
) != CLZ
)
14166 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
14167 msb
= GEN_INT (HOST_WIDE_INT_1U
14168 << (GET_MODE_BITSIZE (mode
) - 1));
14170 msb
= immed_wide_int_const
14171 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode
) - 1,
14172 GET_MODE_PRECISION (mode
)), mode
);
14173 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
14174 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
14175 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
14176 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
14178 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
14179 VAR_INIT_STATUS_INITIALIZED
);
14182 add_loc_descr (&ret
, tmp
);
14183 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
14184 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14185 add_loc_descr (&ret
, l3jump
);
14186 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
14187 VAR_INIT_STATUS_INITIALIZED
);
14190 add_loc_descr (&ret
, tmp
);
14191 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
14192 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
14193 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14194 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
14195 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14196 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14197 add_loc_descr (&ret
, l2jump
);
14198 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
14199 add_loc_descr (&ret
, l3label
);
14200 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
14201 add_loc_descr (&ret
, l4label
);
14202 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14203 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
14204 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14205 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
14206 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14207 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
14208 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14209 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
14213 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
14214 const1 is DW_OP_lit1 or corresponding typed constant):
14216 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
14217 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
14221 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
14222 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
14225 static dw_loc_descr_ref
14226 popcount_loc_descriptor (rtx rtl
, machine_mode mode
,
14227 machine_mode mem_mode
)
14229 dw_loc_descr_ref op0
, ret
, tmp
;
14230 dw_loc_descr_ref l1jump
, l1label
;
14231 dw_loc_descr_ref l2jump
, l2label
;
14233 if (!SCALAR_INT_MODE_P (mode
)
14234 || GET_MODE (XEXP (rtl
, 0)) != mode
)
14237 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14238 VAR_INIT_STATUS_INITIALIZED
);
14242 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
14243 VAR_INIT_STATUS_INITIALIZED
);
14246 add_loc_descr (&ret
, tmp
);
14247 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14248 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
14249 add_loc_descr (&ret
, l1label
);
14250 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14251 add_loc_descr (&ret
, l2jump
);
14252 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
14253 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
14254 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
14255 VAR_INIT_STATUS_INITIALIZED
);
14258 add_loc_descr (&ret
, tmp
);
14259 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
14260 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
14261 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
14262 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14263 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
14264 VAR_INIT_STATUS_INITIALIZED
);
14265 add_loc_descr (&ret
, tmp
);
14266 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
14267 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14268 add_loc_descr (&ret
, l1jump
);
14269 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
14270 add_loc_descr (&ret
, l2label
);
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
;
14278 /* BSWAP (constS is initial shift count, either 56 or 24):
14280 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
14281 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
14282 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
14283 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
14284 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
14286 static dw_loc_descr_ref
14287 bswap_loc_descriptor (rtx rtl
, machine_mode mode
,
14288 machine_mode mem_mode
)
14290 dw_loc_descr_ref op0
, ret
, tmp
;
14291 dw_loc_descr_ref l1jump
, l1label
;
14292 dw_loc_descr_ref l2jump
, l2label
;
14294 if (!SCALAR_INT_MODE_P (mode
)
14295 || BITS_PER_UNIT
!= 8
14296 || (GET_MODE_BITSIZE (mode
) != 32
14297 && GET_MODE_BITSIZE (mode
) != 64))
14300 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14301 VAR_INIT_STATUS_INITIALIZED
);
14306 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
14308 VAR_INIT_STATUS_INITIALIZED
);
14311 add_loc_descr (&ret
, tmp
);
14312 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
14313 VAR_INIT_STATUS_INITIALIZED
);
14316 add_loc_descr (&ret
, tmp
);
14317 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
14318 add_loc_descr (&ret
, l1label
);
14319 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
14321 VAR_INIT_STATUS_INITIALIZED
);
14322 add_loc_descr (&ret
, tmp
);
14323 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
14324 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14325 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
14326 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
14327 VAR_INIT_STATUS_INITIALIZED
);
14330 add_loc_descr (&ret
, tmp
);
14331 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
14332 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
14333 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
14334 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
14335 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14336 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
14337 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
14338 VAR_INIT_STATUS_INITIALIZED
);
14339 add_loc_descr (&ret
, tmp
);
14340 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
14341 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
14342 add_loc_descr (&ret
, l2jump
);
14343 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
14344 VAR_INIT_STATUS_INITIALIZED
);
14345 add_loc_descr (&ret
, tmp
);
14346 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14347 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14348 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
14349 add_loc_descr (&ret
, l1jump
);
14350 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
14351 add_loc_descr (&ret
, l2label
);
14352 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14353 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
14354 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14355 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
14356 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14357 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
14361 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
14362 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
14363 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
14364 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
14366 ROTATERT is similar:
14367 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
14368 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
14369 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
14371 static dw_loc_descr_ref
14372 rotate_loc_descriptor (rtx rtl
, machine_mode mode
,
14373 machine_mode mem_mode
)
14375 rtx rtlop1
= XEXP (rtl
, 1);
14376 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
14379 if (!SCALAR_INT_MODE_P (mode
))
14382 if (GET_MODE (rtlop1
) != VOIDmode
14383 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
14384 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
14385 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14386 VAR_INIT_STATUS_INITIALIZED
);
14387 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
14388 VAR_INIT_STATUS_INITIALIZED
);
14389 if (op0
== NULL
|| op1
== NULL
)
14391 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
14392 for (i
= 0; i
< 2; i
++)
14394 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
14395 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
14397 VAR_INIT_STATUS_INITIALIZED
);
14398 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
14399 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
14401 : HOST_BITS_PER_WIDE_INT
== 64
14402 ? DW_OP_const8u
: DW_OP_constu
,
14403 GET_MODE_MASK (mode
), 0);
14406 if (mask
[i
] == NULL
)
14408 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
14411 add_loc_descr (&ret
, op1
);
14412 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
14413 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
14414 if (GET_CODE (rtl
) == ROTATERT
)
14416 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
14417 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
14418 GET_MODE_BITSIZE (mode
), 0));
14420 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
14421 if (mask
[0] != NULL
)
14422 add_loc_descr (&ret
, mask
[0]);
14423 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
14424 if (mask
[1] != NULL
)
14426 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14427 add_loc_descr (&ret
, mask
[1]);
14428 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
14430 if (GET_CODE (rtl
) == ROTATE
)
14432 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
14433 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
14434 GET_MODE_BITSIZE (mode
), 0));
14436 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
14437 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
14441 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
14442 for DEBUG_PARAMETER_REF RTL. */
14444 static dw_loc_descr_ref
14445 parameter_ref_descriptor (rtx rtl
)
14447 dw_loc_descr_ref ret
;
14452 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
14453 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
14454 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
14457 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14458 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
14459 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14463 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
14464 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
14469 /* The following routine converts the RTL for a variable or parameter
14470 (resident in memory) into an equivalent Dwarf representation of a
14471 mechanism for getting the address of that same variable onto the top of a
14472 hypothetical "address evaluation" stack.
14474 When creating memory location descriptors, we are effectively transforming
14475 the RTL for a memory-resident object into its Dwarf postfix expression
14476 equivalent. This routine recursively descends an RTL tree, turning
14477 it into Dwarf postfix code as it goes.
14479 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
14481 MEM_MODE is the mode of the memory reference, needed to handle some
14482 autoincrement addressing modes.
14484 Return 0 if we can't represent the location. */
14487 mem_loc_descriptor (rtx rtl
, machine_mode mode
,
14488 machine_mode mem_mode
,
14489 enum var_init_status initialized
)
14491 dw_loc_descr_ref mem_loc_result
= NULL
;
14492 enum dwarf_location_atom op
;
14493 dw_loc_descr_ref op0
, op1
;
14494 rtx inner
= NULL_RTX
;
14496 if (mode
== VOIDmode
)
14497 mode
= GET_MODE (rtl
);
14499 /* Note that for a dynamically sized array, the location we will generate a
14500 description of here will be the lowest numbered location which is
14501 actually within the array. That's *not* necessarily the same as the
14502 zeroth element of the array. */
14504 rtl
= targetm
.delegitimize_address (rtl
);
14506 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
14509 switch (GET_CODE (rtl
))
14514 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
14517 /* The case of a subreg may arise when we have a local (register)
14518 variable or a formal (register) parameter which doesn't quite fill
14519 up an entire register. For now, just assume that it is
14520 legitimate to make the Dwarf info refer to the whole register which
14521 contains the given subreg. */
14522 if (!subreg_lowpart_p (rtl
))
14524 inner
= SUBREG_REG (rtl
);
14527 if (inner
== NULL_RTX
)
14528 inner
= XEXP (rtl
, 0);
14529 if (SCALAR_INT_MODE_P (mode
)
14530 && SCALAR_INT_MODE_P (GET_MODE (inner
))
14531 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
14532 #ifdef POINTERS_EXTEND_UNSIGNED
14533 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
14536 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
14538 mem_loc_result
= mem_loc_descriptor (inner
,
14540 mem_mode
, initialized
);
14543 if (dwarf_strict
&& dwarf_version
< 5)
14545 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
14547 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
14548 && (!SCALAR_INT_MODE_P (mode
)
14549 || !SCALAR_INT_MODE_P (GET_MODE (inner
))))
14553 dw_die_ref type_die
;
14554 dw_loc_descr_ref cvt
;
14556 mem_loc_result
= mem_loc_descriptor (inner
,
14558 mem_mode
, initialized
);
14559 if (mem_loc_result
== NULL
)
14561 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
14562 if (type_die
== NULL
)
14564 mem_loc_result
= NULL
;
14567 if (GET_MODE_SIZE (mode
)
14568 != GET_MODE_SIZE (GET_MODE (inner
)))
14569 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14571 cvt
= new_loc_descr (dwarf_OP (DW_OP_reinterpret
), 0, 0);
14572 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14573 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14574 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14575 add_loc_descr (&mem_loc_result
, cvt
);
14576 if (SCALAR_INT_MODE_P (mode
)
14577 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
14579 /* Convert it to untyped afterwards. */
14580 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14581 add_loc_descr (&mem_loc_result
, cvt
);
14587 if (! SCALAR_INT_MODE_P (mode
)
14588 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
14589 && rtl
!= arg_pointer_rtx
14590 && rtl
!= frame_pointer_rtx
14591 #ifdef POINTERS_EXTEND_UNSIGNED
14592 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
14596 dw_die_ref type_die
;
14597 unsigned int dbx_regnum
;
14599 if (dwarf_strict
&& dwarf_version
< 5)
14601 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
14603 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
14604 if (type_die
== NULL
)
14607 dbx_regnum
= dbx_reg_number (rtl
);
14608 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
14610 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_regval_type
),
14612 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
14613 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
14614 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
14617 /* Whenever a register number forms a part of the description of the
14618 method for calculating the (dynamic) address of a memory resident
14619 object, DWARF rules require the register number be referred to as
14620 a "base register". This distinction is not based in any way upon
14621 what category of register the hardware believes the given register
14622 belongs to. This is strictly DWARF terminology we're dealing with
14623 here. Note that in cases where the location of a memory-resident
14624 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
14625 OP_CONST (0)) the actual DWARF location descriptor that we generate
14626 may just be OP_BASEREG (basereg). This may look deceptively like
14627 the object in question was allocated to a register (rather than in
14628 memory) so DWARF consumers need to be aware of the subtle
14629 distinction between OP_REG and OP_BASEREG. */
14630 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
14631 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
14632 else if (stack_realign_drap
14634 && crtl
->args
.internal_arg_pointer
== rtl
14635 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
14637 /* If RTL is internal_arg_pointer, which has been optimized
14638 out, use DRAP instead. */
14639 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
14640 VAR_INIT_STATUS_INITIALIZED
);
14646 if (!SCALAR_INT_MODE_P (mode
))
14648 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
14649 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
14652 else if (GET_CODE (rtl
) == ZERO_EXTEND
14653 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
14654 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
14655 < HOST_BITS_PER_WIDE_INT
14656 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
14657 to expand zero extend as two shifts instead of
14659 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
14661 machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
14662 mem_loc_result
= op0
;
14663 add_loc_descr (&mem_loc_result
,
14664 int_loc_descriptor (GET_MODE_MASK (imode
)));
14665 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
14667 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
14669 int shift
= DWARF2_ADDR_SIZE
14670 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
14671 shift
*= BITS_PER_UNIT
;
14672 if (GET_CODE (rtl
) == SIGN_EXTEND
)
14676 mem_loc_result
= op0
;
14677 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
14678 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
14679 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
14680 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
14682 else if (!dwarf_strict
|| dwarf_version
>= 5)
14684 dw_die_ref type_die1
, type_die2
;
14685 dw_loc_descr_ref cvt
;
14687 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
14688 GET_CODE (rtl
) == ZERO_EXTEND
);
14689 if (type_die1
== NULL
)
14691 type_die2
= base_type_for_mode (mode
, 1);
14692 if (type_die2
== NULL
)
14694 mem_loc_result
= op0
;
14695 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14696 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14697 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
14698 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14699 add_loc_descr (&mem_loc_result
, cvt
);
14700 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
14701 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14702 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
14703 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14704 add_loc_descr (&mem_loc_result
, cvt
);
14710 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
14711 if (new_rtl
!= rtl
)
14713 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
14715 if (mem_loc_result
!= NULL
)
14716 return mem_loc_result
;
14719 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
14720 get_address_mode (rtl
), mode
,
14721 VAR_INIT_STATUS_INITIALIZED
);
14722 if (mem_loc_result
== NULL
)
14723 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
14724 if (mem_loc_result
!= NULL
)
14726 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
14727 || !SCALAR_INT_MODE_P(mode
))
14729 dw_die_ref type_die
;
14730 dw_loc_descr_ref deref
;
14732 if (dwarf_strict
&& dwarf_version
< 5)
14735 = base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
14736 if (type_die
== NULL
)
14738 deref
= new_loc_descr (dwarf_OP (DW_OP_deref_type
),
14739 GET_MODE_SIZE (mode
), 0);
14740 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
14741 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
14742 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
14743 add_loc_descr (&mem_loc_result
, deref
);
14745 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
14746 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
14748 add_loc_descr (&mem_loc_result
,
14749 new_loc_descr (DW_OP_deref_size
,
14750 GET_MODE_SIZE (mode
), 0));
14755 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
14758 /* Some ports can transform a symbol ref into a label ref, because
14759 the symbol ref is too far away and has to be dumped into a constant
14763 if (!SCALAR_INT_MODE_P (mode
)
14764 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
14765 #ifdef POINTERS_EXTEND_UNSIGNED
14766 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
14770 if (GET_CODE (rtl
) == SYMBOL_REF
14771 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
14773 dw_loc_descr_ref temp
;
14775 /* If this is not defined, we have no way to emit the data. */
14776 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
14779 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
14781 /* We check for DWARF 5 here because gdb did not implement
14782 DW_OP_form_tls_address until after 7.12. */
14783 mem_loc_result
= new_loc_descr ((dwarf_version
>= 5
14784 ? DW_OP_form_tls_address
14785 : DW_OP_GNU_push_tls_address
),
14787 add_loc_descr (&mem_loc_result
, temp
);
14792 if (!const_ok_for_output (rtl
))
14794 if (GET_CODE (rtl
) == CONST
)
14795 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14801 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
14802 vec_safe_push (used_rtx_array
, rtl
);
14808 case DEBUG_IMPLICIT_PTR
:
14809 expansion_failed (NULL_TREE
, rtl
,
14810 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
14814 if (dwarf_strict
&& dwarf_version
< 5)
14816 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
14818 if (!SCALAR_INT_MODE_P (mode
)
14819 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
14820 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
14821 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14824 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
14825 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
14827 op0
= one_reg_loc_descriptor (dbx_regnum
,
14828 VAR_INIT_STATUS_INITIALIZED
);
14831 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
14832 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
14834 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
14835 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14836 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
14840 gcc_unreachable ();
14843 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_entry_value
), 0, 0);
14844 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14845 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
14848 case DEBUG_PARAMETER_REF
:
14849 mem_loc_result
= parameter_ref_descriptor (rtl
);
14853 /* Extract the PLUS expression nested inside and fall into
14854 PLUS code below. */
14855 rtl
= XEXP (rtl
, 1);
14860 /* Turn these into a PLUS expression and fall into the PLUS code
14862 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
14863 gen_int_mode (GET_CODE (rtl
) == PRE_INC
14864 ? GET_MODE_UNIT_SIZE (mem_mode
)
14865 : -GET_MODE_UNIT_SIZE (mem_mode
),
14872 if (is_based_loc (rtl
)
14873 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
14874 || XEXP (rtl
, 0) == arg_pointer_rtx
14875 || XEXP (rtl
, 0) == frame_pointer_rtx
)
14876 && SCALAR_INT_MODE_P (mode
))
14877 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
14878 INTVAL (XEXP (rtl
, 1)),
14879 VAR_INIT_STATUS_INITIALIZED
);
14882 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14883 VAR_INIT_STATUS_INITIALIZED
);
14884 if (mem_loc_result
== 0)
14887 if (CONST_INT_P (XEXP (rtl
, 1))
14888 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
14889 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
14892 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
14893 VAR_INIT_STATUS_INITIALIZED
);
14896 add_loc_descr (&mem_loc_result
, op1
);
14897 add_loc_descr (&mem_loc_result
,
14898 new_loc_descr (DW_OP_plus
, 0, 0));
14903 /* If a pseudo-reg is optimized away, it is possible for it to
14904 be replaced with a MEM containing a multiply or shift. */
14914 if ((!dwarf_strict
|| dwarf_version
>= 5)
14915 && SCALAR_INT_MODE_P (mode
)
14916 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
14918 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
14919 base_type_for_mode (mode
, 0),
14943 if (!SCALAR_INT_MODE_P (mode
))
14945 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14946 VAR_INIT_STATUS_INITIALIZED
);
14948 rtx rtlop1
= XEXP (rtl
, 1);
14949 if (GET_MODE (rtlop1
) != VOIDmode
14950 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
14951 < GET_MODE_BITSIZE (mode
))
14952 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
14953 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
14954 VAR_INIT_STATUS_INITIALIZED
);
14957 if (op0
== 0 || op1
== 0)
14960 mem_loc_result
= op0
;
14961 add_loc_descr (&mem_loc_result
, op1
);
14962 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
14978 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
14979 VAR_INIT_STATUS_INITIALIZED
);
14980 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
14981 VAR_INIT_STATUS_INITIALIZED
);
14983 if (op0
== 0 || op1
== 0)
14986 mem_loc_result
= op0
;
14987 add_loc_descr (&mem_loc_result
, op1
);
14988 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
14992 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
14993 && (!dwarf_strict
|| dwarf_version
>= 5))
14995 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
14996 base_type_for_mode (mode
, 0),
15001 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15002 VAR_INIT_STATUS_INITIALIZED
);
15003 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15004 VAR_INIT_STATUS_INITIALIZED
);
15006 if (op0
== 0 || op1
== 0)
15009 mem_loc_result
= op0
;
15010 add_loc_descr (&mem_loc_result
, op1
);
15011 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
15012 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
15013 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
15014 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
15015 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
15019 if ((!dwarf_strict
|| dwarf_version
>= 5)
15020 && SCALAR_INT_MODE_P (mode
))
15022 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
15027 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
15028 base_type_for_mode (mode
, 1),
15046 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
15047 VAR_INIT_STATUS_INITIALIZED
);
15052 mem_loc_result
= op0
;
15053 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15057 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
15058 #ifdef POINTERS_EXTEND_UNSIGNED
15060 && mem_mode
!= VOIDmode
15061 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
15065 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
15068 if ((!dwarf_strict
|| dwarf_version
>= 5)
15069 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
15070 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
15072 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
15073 machine_mode amode
;
15074 if (type_die
== NULL
)
15076 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
15078 if (INTVAL (rtl
) >= 0
15079 && amode
!= BLKmode
15080 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
15081 /* const DW_OP_convert <XXX> vs.
15082 DW_OP_const_type <XXX, 1, const>. */
15083 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
15084 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
15086 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
15087 op0
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15088 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15089 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15090 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15091 add_loc_descr (&mem_loc_result
, op0
);
15092 return mem_loc_result
;
15094 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0,
15096 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15097 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15098 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15099 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
15100 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
15103 mem_loc_result
->dw_loc_oprnd2
.val_class
15104 = dw_val_class_const_double
;
15105 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
15106 = double_int::from_shwi (INTVAL (rtl
));
15112 if (!dwarf_strict
|| dwarf_version
>= 5)
15114 dw_die_ref type_die
;
15116 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
15117 CONST_DOUBLE rtx could represent either a large integer
15118 or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
15119 the value is always a floating point constant.
15121 When it is an integer, a CONST_DOUBLE is used whenever
15122 the constant requires 2 HWIs to be adequately represented.
15123 We output CONST_DOUBLEs as blocks. */
15124 if (mode
== VOIDmode
15125 || (GET_MODE (rtl
) == VOIDmode
15126 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
15128 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
15129 if (type_die
== NULL
)
15131 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0, 0);
15132 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15133 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15134 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15135 #if TARGET_SUPPORTS_WIDE_INT == 0
15136 if (!SCALAR_FLOAT_MODE_P (mode
))
15138 mem_loc_result
->dw_loc_oprnd2
.val_class
15139 = dw_val_class_const_double
;
15140 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
15141 = rtx_to_double_int (rtl
);
15146 unsigned int length
= GET_MODE_SIZE (mode
);
15147 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
15149 insert_float (rtl
, array
);
15150 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
15151 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
15152 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
15153 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
15158 case CONST_WIDE_INT
:
15159 if (!dwarf_strict
|| dwarf_version
>= 5)
15161 dw_die_ref type_die
;
15163 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
15164 if (type_die
== NULL
)
15166 mem_loc_result
= new_loc_descr (dwarf_OP (DW_OP_const_type
), 0, 0);
15167 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15168 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15169 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15170 mem_loc_result
->dw_loc_oprnd2
.val_class
15171 = dw_val_class_wide_int
;
15172 mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
15173 *mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= rtx_mode_t (rtl
, mode
);
15178 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
15182 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
15186 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
15190 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
15194 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
15198 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
15202 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
15206 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
15210 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
15214 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
15219 if (!SCALAR_INT_MODE_P (mode
))
15224 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
15229 if (CONST_INT_P (XEXP (rtl
, 1))
15230 && CONST_INT_P (XEXP (rtl
, 2))
15231 && ((unsigned) INTVAL (XEXP (rtl
, 1))
15232 + (unsigned) INTVAL (XEXP (rtl
, 2))
15233 <= GET_MODE_BITSIZE (mode
))
15234 && SCALAR_INT_MODE_P (mode
)
15235 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
15236 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
15239 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
15240 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
15243 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
15247 mem_loc_result
= op0
;
15248 size
= INTVAL (XEXP (rtl
, 1));
15249 shift
= INTVAL (XEXP (rtl
, 2));
15250 if (BITS_BIG_ENDIAN
)
15251 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
15253 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
15255 add_loc_descr (&mem_loc_result
,
15256 int_loc_descriptor (DWARF2_ADDR_SIZE
15258 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
15260 if (size
!= (int) DWARF2_ADDR_SIZE
)
15262 add_loc_descr (&mem_loc_result
,
15263 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
15264 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
15271 dw_loc_descr_ref op2
, bra_node
, drop_node
;
15272 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
15273 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
15274 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
15275 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
15276 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
15277 VAR_INIT_STATUS_INITIALIZED
);
15278 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
15279 VAR_INIT_STATUS_INITIALIZED
);
15280 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
15283 mem_loc_result
= op1
;
15284 add_loc_descr (&mem_loc_result
, op2
);
15285 add_loc_descr (&mem_loc_result
, op0
);
15286 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
15287 add_loc_descr (&mem_loc_result
, bra_node
);
15288 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
15289 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
15290 add_loc_descr (&mem_loc_result
, drop_node
);
15291 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15292 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
15297 case FLOAT_TRUNCATE
:
15299 case UNSIGNED_FLOAT
:
15302 if (!dwarf_strict
|| dwarf_version
>= 5)
15304 dw_die_ref type_die
;
15305 dw_loc_descr_ref cvt
;
15307 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
15308 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
15311 if (SCALAR_INT_MODE_P (GET_MODE (XEXP (rtl
, 0)))
15312 && (GET_CODE (rtl
) == FLOAT
15313 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
15314 <= DWARF2_ADDR_SIZE
))
15316 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
15317 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
15318 if (type_die
== NULL
)
15320 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15321 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15322 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15323 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15324 add_loc_descr (&op0
, cvt
);
15326 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
15327 if (type_die
== NULL
)
15329 cvt
= new_loc_descr (dwarf_OP (DW_OP_convert
), 0, 0);
15330 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15331 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
15332 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15333 add_loc_descr (&op0
, cvt
);
15334 if (SCALAR_INT_MODE_P (mode
)
15335 && (GET_CODE (rtl
) == FIX
15336 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
15338 op0
= convert_descriptor_to_mode (mode
, op0
);
15342 mem_loc_result
= op0
;
15349 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
15354 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
15358 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
15363 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
15367 /* In theory, we could implement the above. */
15368 /* DWARF cannot represent the unsigned compare operations
15393 case FRACT_CONVERT
:
15394 case UNSIGNED_FRACT_CONVERT
:
15396 case UNSIGNED_SAT_FRACT
:
15402 case VEC_DUPLICATE
:
15406 case STRICT_LOW_PART
:
15411 /* If delegitimize_address couldn't do anything with the UNSPEC, we
15412 can't express it in the debug info. This can happen e.g. with some
15417 resolve_one_addr (&rtl
);
15420 /* RTL sequences inside PARALLEL record a series of DWARF operations for
15421 the expression. An UNSPEC rtx represents a raw DWARF operation,
15422 new_loc_descr is called for it to build the operation directly.
15423 Otherwise mem_loc_descriptor is called recursively. */
15427 dw_loc_descr_ref exp_result
= NULL
;
15429 for (; index
< XVECLEN (rtl
, 0); index
++)
15431 rtx elem
= XVECEXP (rtl
, 0, index
);
15432 if (GET_CODE (elem
) == UNSPEC
)
15434 /* Each DWARF operation UNSPEC contain two operands, if
15435 one operand is not used for the operation, const0_rtx is
15437 gcc_assert (XVECLEN (elem
, 0) == 2);
15439 HOST_WIDE_INT dw_op
= XINT (elem
, 1);
15440 HOST_WIDE_INT oprnd1
= INTVAL (XVECEXP (elem
, 0, 0));
15441 HOST_WIDE_INT oprnd2
= INTVAL (XVECEXP (elem
, 0, 1));
15443 = new_loc_descr ((enum dwarf_location_atom
) dw_op
, oprnd1
,
15448 = mem_loc_descriptor (elem
, mode
, mem_mode
,
15449 VAR_INIT_STATUS_INITIALIZED
);
15451 if (!mem_loc_result
)
15452 mem_loc_result
= exp_result
;
15454 add_loc_descr (&mem_loc_result
, exp_result
);
15463 print_rtl (stderr
, rtl
);
15464 gcc_unreachable ();
15469 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
15470 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
15472 return mem_loc_result
;
15475 /* Return a descriptor that describes the concatenation of two locations.
15476 This is typically a complex variable. */
15478 static dw_loc_descr_ref
15479 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
15481 dw_loc_descr_ref cc_loc_result
= NULL
;
15482 dw_loc_descr_ref x0_ref
15483 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15484 dw_loc_descr_ref x1_ref
15485 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15487 if (x0_ref
== 0 || x1_ref
== 0)
15490 cc_loc_result
= x0_ref
;
15491 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
15493 add_loc_descr (&cc_loc_result
, x1_ref
);
15494 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
15496 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
15497 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
15499 return cc_loc_result
;
15502 /* Return a descriptor that describes the concatenation of N
15505 static dw_loc_descr_ref
15506 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
15509 dw_loc_descr_ref cc_loc_result
= NULL
;
15510 unsigned int n
= XVECLEN (concatn
, 0);
15512 for (i
= 0; i
< n
; ++i
)
15514 dw_loc_descr_ref ref
;
15515 rtx x
= XVECEXP (concatn
, 0, i
);
15517 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
15521 add_loc_descr (&cc_loc_result
, ref
);
15522 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
15525 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
15526 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
15528 return cc_loc_result
;
15531 /* Helper function for loc_descriptor. Return DW_OP_implicit_pointer
15532 for DEBUG_IMPLICIT_PTR RTL. */
15534 static dw_loc_descr_ref
15535 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
15537 dw_loc_descr_ref ret
;
15540 if (dwarf_strict
&& dwarf_version
< 5)
15542 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
15543 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
15544 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
15545 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
15546 ret
= new_loc_descr (dwarf_OP (DW_OP_implicit_pointer
), 0, offset
);
15547 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
15550 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15551 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
15552 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15556 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
15557 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
15562 /* Output a proper Dwarf location descriptor for a variable or parameter
15563 which is either allocated in a register or in a memory location. For a
15564 register, we just generate an OP_REG and the register number. For a
15565 memory location we provide a Dwarf postfix expression describing how to
15566 generate the (dynamic) address of the object onto the address stack.
15568 MODE is mode of the decl if this loc_descriptor is going to be used in
15569 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
15570 allowed, VOIDmode otherwise.
15572 If we don't know how to describe it, return 0. */
15574 static dw_loc_descr_ref
15575 loc_descriptor (rtx rtl
, machine_mode mode
,
15576 enum var_init_status initialized
)
15578 dw_loc_descr_ref loc_result
= NULL
;
15580 switch (GET_CODE (rtl
))
15583 /* The case of a subreg may arise when we have a local (register)
15584 variable or a formal (register) parameter which doesn't quite fill
15585 up an entire register. For now, just assume that it is
15586 legitimate to make the Dwarf info refer to the whole register which
15587 contains the given subreg. */
15588 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
15589 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
15590 GET_MODE (SUBREG_REG (rtl
)), initialized
);
15596 loc_result
= reg_loc_descriptor (rtl
, initialized
);
15600 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
15601 GET_MODE (rtl
), initialized
);
15602 if (loc_result
== NULL
)
15603 loc_result
= tls_mem_loc_descriptor (rtl
);
15604 if (loc_result
== NULL
)
15606 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
15607 if (new_rtl
!= rtl
)
15608 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
15613 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
15618 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
15623 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
15625 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
15626 if (GET_CODE (loc
) == EXPR_LIST
)
15627 loc
= XEXP (loc
, 0);
15628 loc_result
= loc_descriptor (loc
, mode
, initialized
);
15632 rtl
= XEXP (rtl
, 1);
15637 rtvec par_elems
= XVEC (rtl
, 0);
15638 int num_elem
= GET_NUM_ELEM (par_elems
);
15642 /* Create the first one, so we have something to add to. */
15643 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
15644 VOIDmode
, initialized
);
15645 if (loc_result
== NULL
)
15647 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
15648 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
15649 for (i
= 1; i
< num_elem
; i
++)
15651 dw_loc_descr_ref temp
;
15653 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
15654 VOIDmode
, initialized
);
15657 add_loc_descr (&loc_result
, temp
);
15658 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
15659 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
15665 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
15666 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
15671 if (mode
== VOIDmode
)
15672 mode
= GET_MODE (rtl
);
15674 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
15676 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
15678 /* Note that a CONST_DOUBLE rtx could represent either an integer
15679 or a floating-point constant. A CONST_DOUBLE is used whenever
15680 the constant requires more than one word in order to be
15681 adequately represented. We output CONST_DOUBLEs as blocks. */
15682 loc_result
= new_loc_descr (DW_OP_implicit_value
,
15683 GET_MODE_SIZE (mode
), 0);
15684 #if TARGET_SUPPORTS_WIDE_INT == 0
15685 if (!SCALAR_FLOAT_MODE_P (mode
))
15687 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
15688 loc_result
->dw_loc_oprnd2
.v
.val_double
15689 = rtx_to_double_int (rtl
);
15694 unsigned int length
= GET_MODE_SIZE (mode
);
15695 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
15697 insert_float (rtl
, array
);
15698 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
15699 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
15700 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
15701 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
15706 case CONST_WIDE_INT
:
15707 if (mode
== VOIDmode
)
15708 mode
= GET_MODE (rtl
);
15710 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
15712 loc_result
= new_loc_descr (DW_OP_implicit_value
,
15713 GET_MODE_SIZE (mode
), 0);
15714 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_wide_int
;
15715 loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
15716 *loc_result
->dw_loc_oprnd2
.v
.val_wide
= rtx_mode_t (rtl
, mode
);
15721 if (mode
== VOIDmode
)
15722 mode
= GET_MODE (rtl
);
15724 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
15726 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
15727 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
15728 unsigned char *array
15729 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
15732 machine_mode imode
= GET_MODE_INNER (mode
);
15734 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
15735 switch (GET_MODE_CLASS (mode
))
15737 case MODE_VECTOR_INT
:
15738 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15740 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15741 insert_wide_int (rtx_mode_t (elt
, imode
), p
, elt_size
);
15745 case MODE_VECTOR_FLOAT
:
15746 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15748 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15749 insert_float (elt
, p
);
15754 gcc_unreachable ();
15757 loc_result
= new_loc_descr (DW_OP_implicit_value
,
15758 length
* elt_size
, 0);
15759 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
15760 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
15761 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
15762 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
15767 if (mode
== VOIDmode
15768 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
15769 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
15770 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
15772 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
15777 if (!const_ok_for_output (rtl
))
15781 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
15782 && (dwarf_version
>= 4 || !dwarf_strict
))
15784 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
15785 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15786 vec_safe_push (used_rtx_array
, rtl
);
15790 case DEBUG_IMPLICIT_PTR
:
15791 loc_result
= implicit_ptr_descriptor (rtl
, 0);
15795 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
15796 && CONST_INT_P (XEXP (rtl
, 1)))
15799 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
15805 if ((SCALAR_INT_MODE_P (mode
)
15806 && GET_MODE (rtl
) == mode
15807 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
15808 && dwarf_version
>= 4)
15809 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
15811 /* Value expression. */
15812 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
15814 add_loc_descr (&loc_result
,
15815 new_loc_descr (DW_OP_stack_value
, 0, 0));
15823 /* We need to figure out what section we should use as the base for the
15824 address ranges where a given location is valid.
15825 1. If this particular DECL has a section associated with it, use that.
15826 2. If this function has a section associated with it, use that.
15827 3. Otherwise, use the text section.
15828 XXX: If you split a variable across multiple sections, we won't notice. */
15830 static const char *
15831 secname_for_decl (const_tree decl
)
15833 const char *secname
;
15835 if (VAR_OR_FUNCTION_DECL_P (decl
)
15836 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
) || TREE_STATIC (decl
))
15837 && DECL_SECTION_NAME (decl
))
15838 secname
= DECL_SECTION_NAME (decl
);
15839 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
15840 secname
= DECL_SECTION_NAME (current_function_decl
);
15841 else if (cfun
&& in_cold_section_p
)
15842 secname
= crtl
->subsections
.cold_section_label
;
15844 secname
= text_section_label
;
15849 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
15852 decl_by_reference_p (tree decl
)
15854 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
15856 && DECL_BY_REFERENCE (decl
));
15859 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
15862 static dw_loc_descr_ref
15863 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
15864 enum var_init_status initialized
)
15866 int have_address
= 0;
15867 dw_loc_descr_ref descr
;
15870 if (want_address
!= 2)
15872 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
15874 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
15876 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
15877 if (GET_CODE (varloc
) == EXPR_LIST
)
15878 varloc
= XEXP (varloc
, 0);
15879 mode
= GET_MODE (varloc
);
15880 if (MEM_P (varloc
))
15882 rtx addr
= XEXP (varloc
, 0);
15883 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
15884 mode
, initialized
);
15889 rtx x
= avoid_constant_pool_reference (varloc
);
15891 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
15896 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
15903 if (GET_CODE (varloc
) == VAR_LOCATION
)
15904 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
15906 mode
= DECL_MODE (loc
);
15907 descr
= loc_descriptor (varloc
, mode
, initialized
);
15914 if (want_address
== 2 && !have_address
15915 && (dwarf_version
>= 4 || !dwarf_strict
))
15917 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
15919 expansion_failed (loc
, NULL_RTX
,
15920 "DWARF address size mismatch");
15923 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15926 /* Show if we can't fill the request for an address. */
15927 if (want_address
&& !have_address
)
15929 expansion_failed (loc
, NULL_RTX
,
15930 "Want address and only have value");
15934 /* If we've got an address and don't want one, dereference. */
15935 if (!want_address
&& have_address
)
15937 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
15938 enum dwarf_location_atom op
;
15940 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
15942 expansion_failed (loc
, NULL_RTX
,
15943 "DWARF address size mismatch");
15946 else if (size
== DWARF2_ADDR_SIZE
)
15949 op
= DW_OP_deref_size
;
15951 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
15957 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
15958 if it is not possible. */
15960 static dw_loc_descr_ref
15961 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
15963 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
15964 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
15965 else if (dwarf_version
>= 3 || !dwarf_strict
)
15966 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
15971 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
15972 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
15974 static dw_loc_descr_ref
15975 dw_sra_loc_expr (tree decl
, rtx loc
)
15978 unsigned HOST_WIDE_INT padsize
= 0;
15979 dw_loc_descr_ref descr
, *descr_tail
;
15980 unsigned HOST_WIDE_INT decl_size
;
15982 enum var_init_status initialized
;
15984 if (DECL_SIZE (decl
) == NULL
15985 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
15988 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
15990 descr_tail
= &descr
;
15992 for (p
= loc
; p
; p
= XEXP (p
, 1))
15994 unsigned HOST_WIDE_INT bitsize
= decl_piece_bitsize (p
);
15995 rtx loc_note
= *decl_piece_varloc_ptr (p
);
15996 dw_loc_descr_ref cur_descr
;
15997 dw_loc_descr_ref
*tail
, last
= NULL
;
15998 unsigned HOST_WIDE_INT opsize
= 0;
16000 if (loc_note
== NULL_RTX
16001 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
16003 padsize
+= bitsize
;
16006 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
16007 varloc
= NOTE_VAR_LOCATION (loc_note
);
16008 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
16009 if (cur_descr
== NULL
)
16011 padsize
+= bitsize
;
16015 /* Check that cur_descr either doesn't use
16016 DW_OP_*piece operations, or their sum is equal
16017 to bitsize. Otherwise we can't embed it. */
16018 for (tail
= &cur_descr
; *tail
!= NULL
;
16019 tail
= &(*tail
)->dw_loc_next
)
16020 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
16022 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
16026 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
16028 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
16032 if (last
!= NULL
&& opsize
!= bitsize
)
16034 padsize
+= bitsize
;
16035 /* Discard the current piece of the descriptor and release any
16036 addr_table entries it uses. */
16037 remove_loc_list_addr_table_entries (cur_descr
);
16041 /* If there is a hole, add DW_OP_*piece after empty DWARF
16042 expression, which means that those bits are optimized out. */
16045 if (padsize
> decl_size
)
16047 remove_loc_list_addr_table_entries (cur_descr
);
16048 goto discard_descr
;
16050 decl_size
-= padsize
;
16051 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
16052 if (*descr_tail
== NULL
)
16054 remove_loc_list_addr_table_entries (cur_descr
);
16055 goto discard_descr
;
16057 descr_tail
= &(*descr_tail
)->dw_loc_next
;
16060 *descr_tail
= cur_descr
;
16062 if (bitsize
> decl_size
)
16063 goto discard_descr
;
16064 decl_size
-= bitsize
;
16067 HOST_WIDE_INT offset
= 0;
16068 if (GET_CODE (varloc
) == VAR_LOCATION
16069 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
16071 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
16072 if (GET_CODE (varloc
) == EXPR_LIST
)
16073 varloc
= XEXP (varloc
, 0);
16077 if (GET_CODE (varloc
) == CONST
16078 || GET_CODE (varloc
) == SIGN_EXTEND
16079 || GET_CODE (varloc
) == ZERO_EXTEND
)
16080 varloc
= XEXP (varloc
, 0);
16081 else if (GET_CODE (varloc
) == SUBREG
)
16082 varloc
= SUBREG_REG (varloc
);
16087 /* DW_OP_bit_size offset should be zero for register
16088 or implicit location descriptions and empty location
16089 descriptions, but for memory addresses needs big endian
16091 if (MEM_P (varloc
))
16093 unsigned HOST_WIDE_INT memsize
16094 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
16095 if (memsize
!= bitsize
)
16097 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
16098 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
16099 goto discard_descr
;
16100 if (memsize
< bitsize
)
16101 goto discard_descr
;
16102 if (BITS_BIG_ENDIAN
)
16103 offset
= memsize
- bitsize
;
16107 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
16108 if (*descr_tail
== NULL
)
16109 goto discard_descr
;
16110 descr_tail
= &(*descr_tail
)->dw_loc_next
;
16114 /* If there were any non-empty expressions, add padding till the end of
16116 if (descr
!= NULL
&& decl_size
!= 0)
16118 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
16119 if (*descr_tail
== NULL
)
16120 goto discard_descr
;
16125 /* Discard the descriptor and release any addr_table entries it uses. */
16126 remove_loc_list_addr_table_entries (descr
);
16130 /* Return the dwarf representation of the location list LOC_LIST of
16131 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
16134 static dw_loc_list_ref
16135 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
16137 const char *endname
, *secname
;
16139 enum var_init_status initialized
;
16140 struct var_loc_node
*node
;
16141 dw_loc_descr_ref descr
;
16142 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
16143 dw_loc_list_ref list
= NULL
;
16144 dw_loc_list_ref
*listp
= &list
;
16146 /* Now that we know what section we are using for a base,
16147 actually construct the list of locations.
16148 The first location information is what is passed to the
16149 function that creates the location list, and the remaining
16150 locations just get added on to that list.
16151 Note that we only know the start address for a location
16152 (IE location changes), so to build the range, we use
16153 the range [current location start, next location start].
16154 This means we have to special case the last node, and generate
16155 a range of [last location start, end of function label]. */
16157 secname
= secname_for_decl (decl
);
16159 for (node
= loc_list
->first
; node
; node
= node
->next
)
16160 if (GET_CODE (node
->loc
) == EXPR_LIST
16161 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
16163 if (GET_CODE (node
->loc
) == EXPR_LIST
)
16165 /* This requires DW_OP_{,bit_}piece, which is not usable
16166 inside DWARF expressions. */
16167 if (want_address
!= 2)
16169 descr
= dw_sra_loc_expr (decl
, node
->loc
);
16175 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
16176 varloc
= NOTE_VAR_LOCATION (node
->loc
);
16177 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
16181 bool range_across_switch
= false;
16182 /* If section switch happens in between node->label
16183 and node->next->label (or end of function) and
16184 we can't emit it as a single entry list,
16185 emit two ranges, first one ending at the end
16186 of first partition and second one starting at the
16187 beginning of second partition. */
16188 if (node
== loc_list
->last_before_switch
16189 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
16190 && current_function_decl
)
16192 endname
= cfun
->fde
->dw_fde_end
;
16193 range_across_switch
= true;
16195 /* The variable has a location between NODE->LABEL and
16196 NODE->NEXT->LABEL. */
16197 else if (node
->next
)
16198 endname
= node
->next
->label
;
16199 /* If the variable has a location at the last label
16200 it keeps its location until the end of function. */
16201 else if (!current_function_decl
)
16202 endname
= text_end_label
;
16205 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
16206 current_function_funcdef_no
);
16207 endname
= ggc_strdup (label_id
);
16210 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
16211 if (TREE_CODE (decl
) == PARM_DECL
16212 && node
== loc_list
->first
16213 && NOTE_P (node
->loc
)
16214 && strcmp (node
->label
, endname
) == 0)
16215 (*listp
)->force
= true;
16216 listp
= &(*listp
)->dw_loc_next
;
16218 if (range_across_switch
)
16220 if (GET_CODE (node
->loc
) == EXPR_LIST
)
16221 descr
= dw_sra_loc_expr (decl
, node
->loc
);
16224 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
16225 varloc
= NOTE_VAR_LOCATION (node
->loc
);
16226 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
16229 gcc_assert (descr
);
16230 /* The variable has a location between NODE->LABEL and
16231 NODE->NEXT->LABEL. */
16233 endname
= node
->next
->label
;
16235 endname
= cfun
->fde
->dw_fde_second_end
;
16236 *listp
= new_loc_list (descr
,
16237 cfun
->fde
->dw_fde_second_begin
,
16239 listp
= &(*listp
)->dw_loc_next
;
16244 /* Try to avoid the overhead of a location list emitting a location
16245 expression instead, but only if we didn't have more than one
16246 location entry in the first place. If some entries were not
16247 representable, we don't want to pretend a single entry that was
16248 applies to the entire scope in which the variable is
16250 if (list
&& loc_list
->first
->next
)
16256 /* Return if the loc_list has only single element and thus can be represented
16257 as location description. */
16260 single_element_loc_list_p (dw_loc_list_ref list
)
16262 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
16263 return !list
->ll_symbol
;
16266 /* To each location in list LIST add loc descr REF. */
16269 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
16271 dw_loc_descr_ref copy
;
16272 add_loc_descr (&list
->expr
, ref
);
16273 list
= list
->dw_loc_next
;
16276 copy
= ggc_alloc
<dw_loc_descr_node
> ();
16277 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
16278 add_loc_descr (&list
->expr
, copy
);
16279 while (copy
->dw_loc_next
)
16281 dw_loc_descr_ref new_copy
= ggc_alloc
<dw_loc_descr_node
> ();
16282 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
16283 copy
->dw_loc_next
= new_copy
;
16286 list
= list
->dw_loc_next
;
16290 /* Given two lists RET and LIST
16291 produce location list that is result of adding expression in LIST
16292 to expression in RET on each position in program.
16293 Might be destructive on both RET and LIST.
16295 TODO: We handle only simple cases of RET or LIST having at most one
16296 element. General case would inolve sorting the lists in program order
16297 and merging them that will need some additional work.
16298 Adding that will improve quality of debug info especially for SRA-ed
16302 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
16311 if (!list
->dw_loc_next
)
16313 add_loc_descr_to_each (*ret
, list
->expr
);
16316 if (!(*ret
)->dw_loc_next
)
16318 add_loc_descr_to_each (list
, (*ret
)->expr
);
16322 expansion_failed (NULL_TREE
, NULL_RTX
,
16323 "Don't know how to merge two non-trivial"
16324 " location lists.\n");
16329 /* LOC is constant expression. Try a luck, look it up in constant
16330 pool and return its loc_descr of its address. */
16332 static dw_loc_descr_ref
16333 cst_pool_loc_descr (tree loc
)
16335 /* Get an RTL for this, if something has been emitted. */
16336 rtx rtl
= lookup_constant_def (loc
);
16338 if (!rtl
|| !MEM_P (rtl
))
16343 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
16345 /* TODO: We might get more coverage if we was actually delaying expansion
16346 of all expressions till end of compilation when constant pools are fully
16348 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
16350 expansion_failed (loc
, NULL_RTX
,
16351 "CST value in contant pool but not marked.");
16354 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
16355 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
16358 /* Return dw_loc_list representing address of addr_expr LOC
16359 by looking for inner INDIRECT_REF expression and turning
16360 it into simple arithmetics.
16362 See loc_list_from_tree for the meaning of CONTEXT. */
16364 static dw_loc_list_ref
16365 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
,
16366 loc_descr_context
*context
)
16369 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
16371 int unsignedp
, reversep
, volatilep
= 0;
16372 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
16374 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
16375 &bitsize
, &bitpos
, &offset
, &mode
,
16376 &unsignedp
, &reversep
, &volatilep
);
16378 if (bitpos
% BITS_PER_UNIT
)
16380 expansion_failed (loc
, NULL_RTX
, "bitfield access");
16383 if (!INDIRECT_REF_P (obj
))
16385 expansion_failed (obj
,
16386 NULL_RTX
, "no indirect ref in inner refrence");
16389 if (!offset
&& !bitpos
)
16390 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1,
16393 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
16394 && (dwarf_version
>= 4 || !dwarf_strict
))
16396 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0, context
);
16401 /* Variable offset. */
16402 list_ret1
= loc_list_from_tree (offset
, 0, context
);
16403 if (list_ret1
== 0)
16405 add_loc_list (&list_ret
, list_ret1
);
16408 add_loc_descr_to_each (list_ret
,
16409 new_loc_descr (DW_OP_plus
, 0, 0));
16411 bytepos
= bitpos
/ BITS_PER_UNIT
;
16413 add_loc_descr_to_each (list_ret
,
16414 new_loc_descr (DW_OP_plus_uconst
,
16416 else if (bytepos
< 0)
16417 loc_list_plus_const (list_ret
, bytepos
);
16418 add_loc_descr_to_each (list_ret
,
16419 new_loc_descr (DW_OP_stack_value
, 0, 0));
16424 /* Set LOC to the next operation that is not a DW_OP_nop operation. In the case
16425 all operations from LOC are nops, move to the last one. Insert in NOPS all
16426 operations that are skipped. */
16429 loc_descr_to_next_no_nop (dw_loc_descr_ref
&loc
,
16430 hash_set
<dw_loc_descr_ref
> &nops
)
16432 while (loc
->dw_loc_next
!= NULL
&& loc
->dw_loc_opc
== DW_OP_nop
)
16435 loc
= loc
->dw_loc_next
;
16439 /* Helper for loc_descr_without_nops: free the location description operation
16443 free_loc_descr (const dw_loc_descr_ref
&loc
, void *data ATTRIBUTE_UNUSED
)
16449 /* Remove all DW_OP_nop operations from LOC except, if it exists, the one that
16453 loc_descr_without_nops (dw_loc_descr_ref
&loc
)
16455 if (loc
->dw_loc_opc
== DW_OP_nop
&& loc
->dw_loc_next
== NULL
)
16458 /* Set of all DW_OP_nop operations we remove. */
16459 hash_set
<dw_loc_descr_ref
> nops
;
16461 /* First, strip all prefix NOP operations in order to keep the head of the
16462 operations list. */
16463 loc_descr_to_next_no_nop (loc
, nops
);
16465 for (dw_loc_descr_ref cur
= loc
; cur
!= NULL
;)
16467 /* For control flow operations: strip "prefix" nops in destination
16469 if (cur
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
)
16470 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd1
.v
.val_loc
, nops
);
16471 if (cur
->dw_loc_oprnd2
.val_class
== dw_val_class_loc
)
16472 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd2
.v
.val_loc
, nops
);
16474 /* Do the same for the operations that follow, then move to the next
16476 if (cur
->dw_loc_next
!= NULL
)
16477 loc_descr_to_next_no_nop (cur
->dw_loc_next
, nops
);
16478 cur
= cur
->dw_loc_next
;
16481 nops
.traverse
<void *, free_loc_descr
> (NULL
);
16485 struct dwarf_procedure_info
;
16487 /* Helper structure for location descriptions generation. */
16488 struct loc_descr_context
16490 /* The type that is implicitly referenced by DW_OP_push_object_address, or
16491 NULL_TREE if DW_OP_push_object_address in invalid for this location
16492 description. This is used when processing PLACEHOLDER_EXPR nodes. */
16494 /* The ..._DECL node that should be translated as a
16495 DW_OP_push_object_address operation. */
16497 /* Information about the DWARF procedure we are currently generating. NULL if
16498 we are not generating a DWARF procedure. */
16499 struct dwarf_procedure_info
*dpi
;
16500 /* True if integral PLACEHOLDER_EXPR stands for the first argument passed
16501 by consumer. Used for DW_TAG_generic_subrange attributes. */
16502 bool placeholder_arg
;
16503 /* True if PLACEHOLDER_EXPR has been seen. */
16504 bool placeholder_seen
;
16507 /* DWARF procedures generation
16509 DWARF expressions (aka. location descriptions) are used to encode variable
16510 things such as sizes or offsets. Such computations can have redundant parts
16511 that can be factorized in order to reduce the size of the output debug
16512 information. This is the whole point of DWARF procedures.
16514 Thanks to stor-layout.c, size and offset expressions in GENERIC trees are
16515 already factorized into functions ("size functions") in order to handle very
16516 big and complex types. Such functions are quite simple: they have integral
16517 arguments, they return an integral result and their body contains only a
16518 return statement with arithmetic expressions. This is the only kind of
16519 function we are interested in translating into DWARF procedures, here.
16521 DWARF expressions and DWARF procedure are executed using a stack, so we have
16522 to define some calling convention for them to interact. Let's say that:
16524 - Before calling a DWARF procedure, DWARF expressions must push on the stack
16525 all arguments in reverse order (right-to-left) so that when the DWARF
16526 procedure execution starts, the first argument is the top of the stack.
16528 - Then, when returning, the DWARF procedure must have consumed all arguments
16529 on the stack, must have pushed the result and touched nothing else.
16531 - Each integral argument and the result are integral types can be hold in a
16534 - We call "frame offset" the number of stack slots that are "under DWARF
16535 procedure control": it includes the arguments slots, the temporaries and
16536 the result slot. Thus, it is equal to the number of arguments when the
16537 procedure execution starts and must be equal to one (the result) when it
16540 /* Helper structure used when generating operations for a DWARF procedure. */
16541 struct dwarf_procedure_info
16543 /* The FUNCTION_DECL node corresponding to the DWARF procedure that is
16544 currently translated. */
16546 /* The number of arguments FNDECL takes. */
16547 unsigned args_count
;
16550 /* Return a pointer to a newly created DIE node for a DWARF procedure. Add
16551 LOCATION as its DW_AT_location attribute. If FNDECL is not NULL_TREE,
16552 equate it to this DIE. */
16555 new_dwarf_proc_die (dw_loc_descr_ref location
, tree fndecl
,
16556 dw_die_ref parent_die
)
16558 dw_die_ref dwarf_proc_die
;
16560 if ((dwarf_version
< 3 && dwarf_strict
)
16561 || location
== NULL
)
16564 dwarf_proc_die
= new_die (DW_TAG_dwarf_procedure
, parent_die
, fndecl
);
16566 equate_decl_number_to_die (fndecl
, dwarf_proc_die
);
16567 add_AT_loc (dwarf_proc_die
, DW_AT_location
, location
);
16568 return dwarf_proc_die
;
16571 /* Return whether TYPE is a supported type as a DWARF procedure argument
16572 type or return type (we handle only scalar types and pointer types that
16573 aren't wider than the DWARF expression evaluation stack. */
16576 is_handled_procedure_type (tree type
)
16578 return ((INTEGRAL_TYPE_P (type
)
16579 || TREE_CODE (type
) == OFFSET_TYPE
16580 || TREE_CODE (type
) == POINTER_TYPE
)
16581 && int_size_in_bytes (type
) <= DWARF2_ADDR_SIZE
);
16584 /* Helper for resolve_args_picking: do the same but stop when coming across
16585 visited nodes. For each node we visit, register in FRAME_OFFSETS the frame
16586 offset *before* evaluating the corresponding operation. */
16589 resolve_args_picking_1 (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
16590 struct dwarf_procedure_info
*dpi
,
16591 hash_map
<dw_loc_descr_ref
, unsigned> &frame_offsets
)
16593 /* The "frame_offset" identifier is already used to name a macro... */
16594 unsigned frame_offset_
= initial_frame_offset
;
16595 dw_loc_descr_ref l
;
16597 for (l
= loc
; l
!= NULL
;)
16600 unsigned &l_frame_offset
= frame_offsets
.get_or_insert (l
, &existed
);
16602 /* If we already met this node, there is nothing to compute anymore. */
16605 /* Make sure that the stack size is consistent wherever the execution
16606 flow comes from. */
16607 gcc_assert ((unsigned) l_frame_offset
== frame_offset_
);
16610 l_frame_offset
= frame_offset_
;
16612 /* If needed, relocate the picking offset with respect to the frame
16614 if (l
->frame_offset_rel
)
16616 unsigned HOST_WIDE_INT off
;
16617 switch (l
->dw_loc_opc
)
16620 off
= l
->dw_loc_oprnd1
.v
.val_unsigned
;
16629 gcc_unreachable ();
16631 /* frame_offset_ is the size of the current stack frame, including
16632 incoming arguments. Besides, the arguments are pushed
16633 right-to-left. Thus, in order to access the Nth argument from
16634 this operation node, the picking has to skip temporaries *plus*
16635 one stack slot per argument (0 for the first one, 1 for the second
16638 The targetted argument number (N) is already set as the operand,
16639 and the number of temporaries can be computed with:
16640 frame_offsets_ - dpi->args_count */
16641 off
+= frame_offset_
- dpi
->args_count
;
16643 /* DW_OP_pick handles only offsets from 0 to 255 (inclusive)... */
16649 l
->dw_loc_opc
= DW_OP_dup
;
16650 l
->dw_loc_oprnd1
.v
.val_unsigned
= 0;
16654 l
->dw_loc_opc
= DW_OP_over
;
16655 l
->dw_loc_oprnd1
.v
.val_unsigned
= 0;
16659 l
->dw_loc_opc
= DW_OP_pick
;
16660 l
->dw_loc_oprnd1
.v
.val_unsigned
= off
;
16664 /* Update frame_offset according to the effect the current operation has
16666 switch (l
->dw_loc_opc
)
16674 case DW_OP_plus_uconst
:
16710 case DW_OP_deref_size
:
16712 case DW_OP_bit_piece
:
16713 case DW_OP_implicit_value
:
16714 case DW_OP_stack_value
:
16718 case DW_OP_const1u
:
16719 case DW_OP_const1s
:
16720 case DW_OP_const2u
:
16721 case DW_OP_const2s
:
16722 case DW_OP_const4u
:
16723 case DW_OP_const4s
:
16724 case DW_OP_const8u
:
16725 case DW_OP_const8s
:
16796 case DW_OP_push_object_address
:
16797 case DW_OP_call_frame_cfa
:
16822 case DW_OP_xderef_size
:
16828 case DW_OP_call_ref
:
16830 dw_die_ref dwarf_proc
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
16831 int *stack_usage
= dwarf_proc_stack_usage_map
->get (dwarf_proc
);
16833 if (stack_usage
== NULL
)
16835 frame_offset_
+= *stack_usage
;
16839 case DW_OP_implicit_pointer
:
16840 case DW_OP_entry_value
:
16841 case DW_OP_const_type
:
16842 case DW_OP_regval_type
:
16843 case DW_OP_deref_type
:
16844 case DW_OP_convert
:
16845 case DW_OP_reinterpret
:
16846 case DW_OP_form_tls_address
:
16847 case DW_OP_GNU_push_tls_address
:
16848 case DW_OP_GNU_uninit
:
16849 case DW_OP_GNU_encoded_addr
:
16850 case DW_OP_GNU_implicit_pointer
:
16851 case DW_OP_GNU_entry_value
:
16852 case DW_OP_GNU_const_type
:
16853 case DW_OP_GNU_regval_type
:
16854 case DW_OP_GNU_deref_type
:
16855 case DW_OP_GNU_convert
:
16856 case DW_OP_GNU_reinterpret
:
16857 case DW_OP_GNU_parameter_ref
:
16858 /* loc_list_from_tree will probably not output these operations for
16859 size functions, so assume they will not appear here. */
16860 /* Fall through... */
16863 gcc_unreachable ();
16866 /* Now, follow the control flow (except subroutine calls). */
16867 switch (l
->dw_loc_opc
)
16870 if (!resolve_args_picking_1 (l
->dw_loc_next
, frame_offset_
, dpi
,
16873 /* Fall through. */
16876 l
= l
->dw_loc_oprnd1
.v
.val_loc
;
16879 case DW_OP_stack_value
:
16883 l
= l
->dw_loc_next
;
16891 /* Make a DFS over operations reachable through LOC (i.e. follow branch
16892 operations) in order to resolve the operand of DW_OP_pick operations that
16893 target DWARF procedure arguments (DPI). INITIAL_FRAME_OFFSET is the frame
16894 offset *before* LOC is executed. Return if all relocations were
16898 resolve_args_picking (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
16899 struct dwarf_procedure_info
*dpi
)
16901 /* Associate to all visited operations the frame offset *before* evaluating
16903 hash_map
<dw_loc_descr_ref
, unsigned> frame_offsets
;
16905 return resolve_args_picking_1 (loc
, initial_frame_offset
, dpi
,
16909 /* Try to generate a DWARF procedure that computes the same result as FNDECL.
16910 Return NULL if it is not possible. */
16913 function_to_dwarf_procedure (tree fndecl
)
16915 struct loc_descr_context ctx
;
16916 struct dwarf_procedure_info dpi
;
16917 dw_die_ref dwarf_proc_die
;
16918 tree tree_body
= DECL_SAVED_TREE (fndecl
);
16919 dw_loc_descr_ref loc_body
, epilogue
;
16924 /* Do not generate multiple DWARF procedures for the same function
16926 dwarf_proc_die
= lookup_decl_die (fndecl
);
16927 if (dwarf_proc_die
!= NULL
)
16928 return dwarf_proc_die
;
16930 /* DWARF procedures are available starting with the DWARFv3 standard. */
16931 if (dwarf_version
< 3 && dwarf_strict
)
16934 /* We handle only functions for which we still have a body, that return a
16935 supported type and that takes arguments with supported types. Note that
16936 there is no point translating functions that return nothing. */
16937 if (tree_body
== NULL_TREE
16938 || DECL_RESULT (fndecl
) == NULL_TREE
16939 || !is_handled_procedure_type (TREE_TYPE (DECL_RESULT (fndecl
))))
16942 for (cursor
= DECL_ARGUMENTS (fndecl
);
16943 cursor
!= NULL_TREE
;
16944 cursor
= TREE_CHAIN (cursor
))
16945 if (!is_handled_procedure_type (TREE_TYPE (cursor
)))
16948 /* Match only "expr" in: RETURN_EXPR (MODIFY_EXPR (RESULT_DECL, expr)). */
16949 if (TREE_CODE (tree_body
) != RETURN_EXPR
)
16951 tree_body
= TREE_OPERAND (tree_body
, 0);
16952 if (TREE_CODE (tree_body
) != MODIFY_EXPR
16953 || TREE_OPERAND (tree_body
, 0) != DECL_RESULT (fndecl
))
16955 tree_body
= TREE_OPERAND (tree_body
, 1);
16957 /* Try to translate the body expression itself. Note that this will probably
16958 cause an infinite recursion if its call graph has a cycle. This is very
16959 unlikely for size functions, however, so don't bother with such things at
16961 ctx
.context_type
= NULL_TREE
;
16962 ctx
.base_decl
= NULL_TREE
;
16964 ctx
.placeholder_arg
= false;
16965 ctx
.placeholder_seen
= false;
16966 dpi
.fndecl
= fndecl
;
16967 dpi
.args_count
= list_length (DECL_ARGUMENTS (fndecl
));
16968 loc_body
= loc_descriptor_from_tree (tree_body
, 0, &ctx
);
16972 /* After evaluating all operands in "loc_body", we should still have on the
16973 stack all arguments plus the desired function result (top of the stack).
16974 Generate code in order to keep only the result in our stack frame. */
16976 for (i
= 0; i
< dpi
.args_count
; ++i
)
16978 dw_loc_descr_ref op_couple
= new_loc_descr (DW_OP_swap
, 0, 0);
16979 op_couple
->dw_loc_next
= new_loc_descr (DW_OP_drop
, 0, 0);
16980 op_couple
->dw_loc_next
->dw_loc_next
= epilogue
;
16981 epilogue
= op_couple
;
16983 add_loc_descr (&loc_body
, epilogue
);
16984 if (!resolve_args_picking (loc_body
, dpi
.args_count
, &dpi
))
16987 /* Trailing nops from loc_descriptor_from_tree (if any) cannot be removed
16988 because they are considered useful. Now there is an epilogue, they are
16989 not anymore, so give it another try. */
16990 loc_descr_without_nops (loc_body
);
16992 /* fndecl may be used both as a regular DW_TAG_subprogram DIE and as
16993 a DW_TAG_dwarf_procedure, so we may have a conflict, here. It's unlikely,
16994 though, given that size functions do not come from source, so they should
16995 not have a dedicated DW_TAG_subprogram DIE. */
16997 = new_dwarf_proc_die (loc_body
, fndecl
,
16998 get_context_die (DECL_CONTEXT (fndecl
)));
17000 /* The called DWARF procedure consumes one stack slot per argument and
17001 returns one stack slot. */
17002 dwarf_proc_stack_usage_map
->put (dwarf_proc_die
, 1 - dpi
.args_count
);
17004 return dwarf_proc_die
;
17008 /* Generate Dwarf location list representing LOC.
17009 If WANT_ADDRESS is false, expression computing LOC will be computed
17010 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
17011 if WANT_ADDRESS is 2, expression computing address useable in location
17012 will be returned (i.e. DW_OP_reg can be used
17013 to refer to register values).
17015 CONTEXT provides information to customize the location descriptions
17016 generation. Its context_type field specifies what type is implicitly
17017 referenced by DW_OP_push_object_address. If it is NULL_TREE, this operation
17018 will not be generated.
17020 Its DPI field determines whether we are generating a DWARF expression for a
17021 DWARF procedure, so PARM_DECL references are processed specifically.
17023 If CONTEXT is NULL, the behavior is the same as if context_type, base_decl
17024 and dpi fields were null. */
17026 static dw_loc_list_ref
17027 loc_list_from_tree_1 (tree loc
, int want_address
,
17028 struct loc_descr_context
*context
)
17030 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
17031 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
17032 int have_address
= 0;
17033 enum dwarf_location_atom op
;
17035 /* ??? Most of the time we do not take proper care for sign/zero
17036 extending the values properly. Hopefully this won't be a real
17039 if (context
!= NULL
17040 && context
->base_decl
== loc
17041 && want_address
== 0)
17043 if (dwarf_version
>= 3 || !dwarf_strict
)
17044 return new_loc_list (new_loc_descr (DW_OP_push_object_address
, 0, 0),
17050 switch (TREE_CODE (loc
))
17053 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
17056 case PLACEHOLDER_EXPR
:
17057 /* This case involves extracting fields from an object to determine the
17058 position of other fields. It is supposed to appear only as the first
17059 operand of COMPONENT_REF nodes and to reference precisely the type
17060 that the context allows. */
17061 if (context
!= NULL
17062 && TREE_TYPE (loc
) == context
->context_type
17063 && want_address
>= 1)
17065 if (dwarf_version
>= 3 || !dwarf_strict
)
17067 ret
= new_loc_descr (DW_OP_push_object_address
, 0, 0);
17074 /* For DW_TAG_generic_subrange attributes, PLACEHOLDER_EXPR stands for
17075 the single argument passed by consumer. */
17076 else if (context
!= NULL
17077 && context
->placeholder_arg
17078 && INTEGRAL_TYPE_P (TREE_TYPE (loc
))
17079 && want_address
== 0)
17081 ret
= new_loc_descr (DW_OP_pick
, 0, 0);
17082 ret
->frame_offset_rel
= 1;
17083 context
->placeholder_seen
= true;
17087 expansion_failed (loc
, NULL_RTX
,
17088 "PLACEHOLDER_EXPR for an unexpected type");
17093 const int nargs
= call_expr_nargs (loc
);
17094 tree callee
= get_callee_fndecl (loc
);
17096 dw_die_ref dwarf_proc
;
17098 if (callee
== NULL_TREE
)
17099 goto call_expansion_failed
;
17101 /* We handle only functions that return an integer. */
17102 if (!is_handled_procedure_type (TREE_TYPE (TREE_TYPE (callee
))))
17103 goto call_expansion_failed
;
17105 dwarf_proc
= function_to_dwarf_procedure (callee
);
17106 if (dwarf_proc
== NULL
)
17107 goto call_expansion_failed
;
17109 /* Evaluate arguments right-to-left so that the first argument will
17110 be the top-most one on the stack. */
17111 for (i
= nargs
- 1; i
>= 0; --i
)
17113 dw_loc_descr_ref loc_descr
17114 = loc_descriptor_from_tree (CALL_EXPR_ARG (loc
, i
), 0,
17117 if (loc_descr
== NULL
)
17118 goto call_expansion_failed
;
17120 add_loc_descr (&ret
, loc_descr
);
17123 ret1
= new_loc_descr (DW_OP_call4
, 0, 0);
17124 ret1
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
17125 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.die
= dwarf_proc
;
17126 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
17127 add_loc_descr (&ret
, ret1
);
17130 call_expansion_failed
:
17131 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
17132 /* There are no opcodes for these operations. */
17136 case PREINCREMENT_EXPR
:
17137 case PREDECREMENT_EXPR
:
17138 case POSTINCREMENT_EXPR
:
17139 case POSTDECREMENT_EXPR
:
17140 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
17141 /* There are no opcodes for these operations. */
17145 /* If we already want an address, see if there is INDIRECT_REF inside
17146 e.g. for &this->field. */
17149 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
17150 (loc
, want_address
== 2, context
);
17153 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
17154 && (ret
= cst_pool_loc_descr (loc
)))
17157 /* Otherwise, process the argument and look for the address. */
17158 if (!list_ret
&& !ret
)
17159 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 1, context
);
17163 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
17169 if (DECL_THREAD_LOCAL_P (loc
))
17172 enum dwarf_location_atom tls_op
;
17173 enum dtprel_bool dtprel
= dtprel_false
;
17175 if (targetm
.have_tls
)
17177 /* If this is not defined, we have no way to emit the
17179 if (!targetm
.asm_out
.output_dwarf_dtprel
)
17182 /* The way DW_OP_GNU_push_tls_address is specified, we
17183 can only look up addresses of objects in the current
17184 module. We used DW_OP_addr as first op, but that's
17185 wrong, because DW_OP_addr is relocated by the debug
17186 info consumer, while DW_OP_GNU_push_tls_address
17187 operand shouldn't be. */
17188 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
17190 dtprel
= dtprel_true
;
17191 /* We check for DWARF 5 here because gdb did not implement
17192 DW_OP_form_tls_address until after 7.12. */
17193 tls_op
= (dwarf_version
>= 5 ? DW_OP_form_tls_address
17194 : DW_OP_GNU_push_tls_address
);
17198 if (!targetm
.emutls
.debug_form_tls_address
17199 || !(dwarf_version
>= 3 || !dwarf_strict
))
17201 /* We stuffed the control variable into the DECL_VALUE_EXPR
17202 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
17203 no longer appear in gimple code. We used the control
17204 variable in specific so that we could pick it up here. */
17205 loc
= DECL_VALUE_EXPR (loc
);
17206 tls_op
= DW_OP_form_tls_address
;
17209 rtl
= rtl_for_decl_location (loc
);
17210 if (rtl
== NULL_RTX
)
17215 rtl
= XEXP (rtl
, 0);
17216 if (! CONSTANT_P (rtl
))
17219 ret
= new_addr_loc_descr (rtl
, dtprel
);
17220 ret1
= new_loc_descr (tls_op
, 0, 0);
17221 add_loc_descr (&ret
, ret1
);
17229 if (context
!= NULL
&& context
->dpi
!= NULL
17230 && DECL_CONTEXT (loc
) == context
->dpi
->fndecl
)
17232 /* We are generating code for a DWARF procedure and we want to access
17233 one of its arguments: find the appropriate argument offset and let
17234 the resolve_args_picking pass compute the offset that complies
17235 with the stack frame size. */
17239 for (cursor
= DECL_ARGUMENTS (context
->dpi
->fndecl
);
17240 cursor
!= NULL_TREE
&& cursor
!= loc
;
17241 cursor
= TREE_CHAIN (cursor
), ++i
)
17243 /* If we are translating a DWARF procedure, all referenced parameters
17244 must belong to the current function. */
17245 gcc_assert (cursor
!= NULL_TREE
);
17247 ret
= new_loc_descr (DW_OP_pick
, i
, 0);
17248 ret
->frame_offset_rel
= 1;
17254 if (DECL_HAS_VALUE_EXPR_P (loc
))
17255 return loc_list_from_tree_1 (DECL_VALUE_EXPR (loc
),
17256 want_address
, context
);
17259 case FUNCTION_DECL
:
17262 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
17264 if (loc_list
&& loc_list
->first
)
17266 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
17267 have_address
= want_address
!= 0;
17270 rtl
= rtl_for_decl_location (loc
);
17271 if (rtl
== NULL_RTX
)
17273 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
17276 else if (CONST_INT_P (rtl
))
17278 HOST_WIDE_INT val
= INTVAL (rtl
);
17279 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
17280 val
&= GET_MODE_MASK (DECL_MODE (loc
));
17281 ret
= int_loc_descriptor (val
);
17283 else if (GET_CODE (rtl
) == CONST_STRING
)
17285 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
17288 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
17289 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
17292 machine_mode mode
, mem_mode
;
17294 /* Certain constructs can only be represented at top-level. */
17295 if (want_address
== 2)
17297 ret
= loc_descriptor (rtl
, VOIDmode
,
17298 VAR_INIT_STATUS_INITIALIZED
);
17303 mode
= GET_MODE (rtl
);
17304 mem_mode
= VOIDmode
;
17308 mode
= get_address_mode (rtl
);
17309 rtl
= XEXP (rtl
, 0);
17312 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
17313 VAR_INIT_STATUS_INITIALIZED
);
17316 expansion_failed (loc
, rtl
,
17317 "failed to produce loc descriptor for rtl");
17323 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
17330 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17334 case TARGET_MEM_REF
:
17336 case DEBUG_EXPR_DECL
:
17339 case COMPOUND_EXPR
:
17340 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), want_address
,
17344 case VIEW_CONVERT_EXPR
:
17347 case NON_LVALUE_EXPR
:
17348 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), want_address
,
17351 case COMPONENT_REF
:
17352 case BIT_FIELD_REF
:
17354 case ARRAY_RANGE_REF
:
17355 case REALPART_EXPR
:
17356 case IMAGPART_EXPR
:
17359 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
17361 int unsignedp
, reversep
, volatilep
= 0;
17363 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
17364 &unsignedp
, &reversep
, &volatilep
);
17366 gcc_assert (obj
!= loc
);
17368 list_ret
= loc_list_from_tree_1 (obj
,
17370 && !bitpos
&& !offset
? 2 : 1,
17372 /* TODO: We can extract value of the small expression via shifting even
17373 for nonzero bitpos. */
17376 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
17378 expansion_failed (loc
, NULL_RTX
,
17379 "bitfield access");
17383 if (offset
!= NULL_TREE
)
17385 /* Variable offset. */
17386 list_ret1
= loc_list_from_tree_1 (offset
, 0, context
);
17387 if (list_ret1
== 0)
17389 add_loc_list (&list_ret
, list_ret1
);
17392 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
17395 bytepos
= bitpos
/ BITS_PER_UNIT
;
17397 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
17398 else if (bytepos
< 0)
17399 loc_list_plus_const (list_ret
, bytepos
);
17406 if ((want_address
|| !tree_fits_shwi_p (loc
))
17407 && (ret
= cst_pool_loc_descr (loc
)))
17409 else if (want_address
== 2
17410 && tree_fits_shwi_p (loc
)
17411 && (ret
= address_of_int_loc_descriptor
17412 (int_size_in_bytes (TREE_TYPE (loc
)),
17413 tree_to_shwi (loc
))))
17415 else if (tree_fits_shwi_p (loc
))
17416 ret
= int_loc_descriptor (tree_to_shwi (loc
));
17417 else if (tree_fits_uhwi_p (loc
))
17418 ret
= uint_loc_descriptor (tree_to_uhwi (loc
));
17421 expansion_failed (loc
, NULL_RTX
,
17422 "Integer operand is not host integer");
17431 if ((ret
= cst_pool_loc_descr (loc
)))
17433 else if (TREE_CODE (loc
) == CONSTRUCTOR
)
17435 tree type
= TREE_TYPE (loc
);
17436 unsigned HOST_WIDE_INT size
= int_size_in_bytes (type
);
17437 unsigned HOST_WIDE_INT offset
= 0;
17438 unsigned HOST_WIDE_INT cnt
;
17439 constructor_elt
*ce
;
17441 if (TREE_CODE (type
) == RECORD_TYPE
)
17443 /* This is very limited, but it's enough to output
17444 pointers to member functions, as long as the
17445 referenced function is defined in the current
17446 translation unit. */
17447 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (loc
), cnt
, ce
)
17449 tree val
= ce
->value
;
17451 tree field
= ce
->index
;
17456 if (!field
|| DECL_BIT_FIELD (field
))
17458 expansion_failed (loc
, NULL_RTX
,
17459 "bitfield in record type constructor");
17460 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
17465 HOST_WIDE_INT fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
17466 unsigned HOST_WIDE_INT pos
= int_byte_position (field
);
17467 gcc_assert (pos
+ fieldsize
<= size
);
17470 expansion_failed (loc
, NULL_RTX
,
17471 "out-of-order fields in record constructor");
17472 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
17478 ret1
= new_loc_descr (DW_OP_piece
, pos
- offset
, 0);
17479 add_loc_descr (&ret
, ret1
);
17482 if (val
&& fieldsize
!= 0)
17484 ret1
= loc_descriptor_from_tree (val
, want_address
, context
);
17487 expansion_failed (loc
, NULL_RTX
,
17488 "unsupported expression in field");
17489 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
17493 add_loc_descr (&ret
, ret1
);
17497 ret1
= new_loc_descr (DW_OP_piece
, fieldsize
, 0);
17498 add_loc_descr (&ret
, ret1
);
17499 offset
= pos
+ fieldsize
;
17503 if (offset
!= size
)
17505 ret1
= new_loc_descr (DW_OP_piece
, size
- offset
, 0);
17506 add_loc_descr (&ret
, ret1
);
17510 have_address
= !!want_address
;
17513 expansion_failed (loc
, NULL_RTX
,
17514 "constructor of non-record type");
17517 /* We can construct small constants here using int_loc_descriptor. */
17518 expansion_failed (loc
, NULL_RTX
,
17519 "constructor or constant not in constant pool");
17522 case TRUTH_AND_EXPR
:
17523 case TRUTH_ANDIF_EXPR
:
17528 case TRUTH_XOR_EXPR
:
17533 case TRUTH_OR_EXPR
:
17534 case TRUTH_ORIF_EXPR
:
17539 case FLOOR_DIV_EXPR
:
17540 case CEIL_DIV_EXPR
:
17541 case ROUND_DIV_EXPR
:
17542 case TRUNC_DIV_EXPR
:
17543 case EXACT_DIV_EXPR
:
17544 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
17553 case FLOOR_MOD_EXPR
:
17554 case CEIL_MOD_EXPR
:
17555 case ROUND_MOD_EXPR
:
17556 case TRUNC_MOD_EXPR
:
17557 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
17562 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17563 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
17564 if (list_ret
== 0 || list_ret1
== 0)
17567 add_loc_list (&list_ret
, list_ret1
);
17570 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
17571 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
17572 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
17573 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
17574 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
17586 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
17589 case POINTER_PLUS_EXPR
:
17592 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
17594 /* Big unsigned numbers can fit in HOST_WIDE_INT but it may be
17595 smarter to encode their opposite. The DW_OP_plus_uconst operation
17596 takes 1 + X bytes, X being the size of the ULEB128 addend. On the
17597 other hand, a "<push literal>; DW_OP_minus" pattern takes 1 + Y
17598 bytes, Y being the size of the operation that pushes the opposite
17599 of the addend. So let's choose the smallest representation. */
17600 const tree tree_addend
= TREE_OPERAND (loc
, 1);
17601 offset_int wi_addend
;
17602 HOST_WIDE_INT shwi_addend
;
17603 dw_loc_descr_ref loc_naddend
;
17605 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17609 /* Try to get the literal to push. It is the opposite of the addend,
17610 so as we rely on wrapping during DWARF evaluation, first decode
17611 the literal as a "DWARF-sized" signed number. */
17612 wi_addend
= wi::to_offset (tree_addend
);
17613 wi_addend
= wi::sext (wi_addend
, DWARF2_ADDR_SIZE
* 8);
17614 shwi_addend
= wi_addend
.to_shwi ();
17615 loc_naddend
= (shwi_addend
!= INTTYPE_MINIMUM (HOST_WIDE_INT
))
17616 ? int_loc_descriptor (-shwi_addend
)
17619 if (loc_naddend
!= NULL
17620 && ((unsigned) size_of_uleb128 (shwi_addend
)
17621 > size_of_loc_descr (loc_naddend
)))
17623 add_loc_descr_to_each (list_ret
, loc_naddend
);
17624 add_loc_descr_to_each (list_ret
,
17625 new_loc_descr (DW_OP_minus
, 0, 0));
17629 for (dw_loc_descr_ref loc_cur
= loc_naddend
; loc_cur
!= NULL
; )
17631 loc_naddend
= loc_cur
;
17632 loc_cur
= loc_cur
->dw_loc_next
;
17633 ggc_free (loc_naddend
);
17635 loc_list_plus_const (list_ret
, wi_addend
.to_shwi ());
17645 goto do_comp_binop
;
17649 goto do_comp_binop
;
17653 goto do_comp_binop
;
17657 goto do_comp_binop
;
17660 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
17662 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
17663 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
17664 list_ret
= loc_list_from_uint_comparison (list_ret
, list_ret1
,
17680 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17681 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
17682 if (list_ret
== 0 || list_ret1
== 0)
17685 add_loc_list (&list_ret
, list_ret1
);
17688 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
17691 case TRUTH_NOT_EXPR
:
17705 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17709 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
17715 const enum tree_code code
=
17716 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
17718 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
17719 build2 (code
, integer_type_node
,
17720 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
17721 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
17728 dw_loc_descr_ref lhs
17729 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
17730 dw_loc_list_ref rhs
17731 = loc_list_from_tree_1 (TREE_OPERAND (loc
, 2), 0, context
);
17732 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
17734 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
17735 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
17738 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
17739 add_loc_descr_to_each (list_ret
, bra_node
);
17741 add_loc_list (&list_ret
, rhs
);
17742 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
17743 add_loc_descr_to_each (list_ret
, jump_node
);
17745 add_loc_descr_to_each (list_ret
, lhs
);
17746 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
17747 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
17749 /* ??? Need a node to point the skip at. Use a nop. */
17750 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
17751 add_loc_descr_to_each (list_ret
, tmp
);
17752 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
17753 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
17757 case FIX_TRUNC_EXPR
:
17761 /* Leave front-end specific codes as simply unknown. This comes
17762 up, for instance, with the C STMT_EXPR. */
17763 if ((unsigned int) TREE_CODE (loc
)
17764 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
17766 expansion_failed (loc
, NULL_RTX
,
17767 "language specific tree node");
17771 /* Otherwise this is a generic code; we should just lists all of
17772 these explicitly. We forgot one. */
17774 gcc_unreachable ();
17776 /* In a release build, we want to degrade gracefully: better to
17777 generate incomplete debugging information than to crash. */
17781 if (!ret
&& !list_ret
)
17784 if (want_address
== 2 && !have_address
17785 && (dwarf_version
>= 4 || !dwarf_strict
))
17787 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
17789 expansion_failed (loc
, NULL_RTX
,
17790 "DWARF address size mismatch");
17794 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
17796 add_loc_descr_to_each (list_ret
,
17797 new_loc_descr (DW_OP_stack_value
, 0, 0));
17800 /* Show if we can't fill the request for an address. */
17801 if (want_address
&& !have_address
)
17803 expansion_failed (loc
, NULL_RTX
,
17804 "Want address and only have value");
17808 gcc_assert (!ret
|| !list_ret
);
17810 /* If we've got an address and don't want one, dereference. */
17811 if (!want_address
&& have_address
)
17813 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
17815 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
17817 expansion_failed (loc
, NULL_RTX
,
17818 "DWARF address size mismatch");
17821 else if (size
== DWARF2_ADDR_SIZE
)
17824 op
= DW_OP_deref_size
;
17827 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
17829 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
17832 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
17837 /* Likewise, but strip useless DW_OP_nop operations in the resulting
17840 static dw_loc_list_ref
17841 loc_list_from_tree (tree loc
, int want_address
,
17842 struct loc_descr_context
*context
)
17844 dw_loc_list_ref result
= loc_list_from_tree_1 (loc
, want_address
, context
);
17846 for (dw_loc_list_ref loc_cur
= result
;
17847 loc_cur
!= NULL
; loc_cur
=
17848 loc_cur
->dw_loc_next
)
17849 loc_descr_without_nops (loc_cur
->expr
);
17853 /* Same as above but return only single location expression. */
17854 static dw_loc_descr_ref
17855 loc_descriptor_from_tree (tree loc
, int want_address
,
17856 struct loc_descr_context
*context
)
17858 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
, context
);
17861 if (ret
->dw_loc_next
)
17863 expansion_failed (loc
, NULL_RTX
,
17864 "Location list where only loc descriptor needed");
17870 /* Given a value, round it up to the lowest multiple of `boundary'
17871 which is not less than the value itself. */
17873 static inline HOST_WIDE_INT
17874 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
17876 return (((value
+ boundary
- 1) / boundary
) * boundary
);
17879 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
17880 pointer to the declared type for the relevant field variable, or return
17881 `integer_type_node' if the given node turns out to be an
17882 ERROR_MARK node. */
17885 field_type (const_tree decl
)
17889 if (TREE_CODE (decl
) == ERROR_MARK
)
17890 return integer_type_node
;
17892 type
= DECL_BIT_FIELD_TYPE (decl
);
17893 if (type
== NULL_TREE
)
17894 type
= TREE_TYPE (decl
);
17899 /* Given a pointer to a tree node, return the alignment in bits for
17900 it, or else return BITS_PER_WORD if the node actually turns out to
17901 be an ERROR_MARK node. */
17903 static inline unsigned
17904 simple_type_align_in_bits (const_tree type
)
17906 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
17909 static inline unsigned
17910 simple_decl_align_in_bits (const_tree decl
)
17912 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
17915 /* Return the result of rounding T up to ALIGN. */
17917 static inline offset_int
17918 round_up_to_align (const offset_int
&t
, unsigned int align
)
17920 return wi::udiv_trunc (t
+ align
- 1, align
) * align
;
17923 /* Compute the size of TYPE in bytes. If possible, return NULL and store the
17924 size as an integer constant in CST_SIZE. Otherwise, if possible, return a
17925 DWARF expression that computes the size. Return NULL and set CST_SIZE to -1
17926 if we fail to return the size in one of these two forms. */
17928 static dw_loc_descr_ref
17929 type_byte_size (const_tree type
, HOST_WIDE_INT
*cst_size
)
17932 struct loc_descr_context ctx
;
17934 /* Return a constant integer in priority, if possible. */
17935 *cst_size
= int_size_in_bytes (type
);
17936 if (*cst_size
!= -1)
17939 ctx
.context_type
= const_cast<tree
> (type
);
17940 ctx
.base_decl
= NULL_TREE
;
17942 ctx
.placeholder_arg
= false;
17943 ctx
.placeholder_seen
= false;
17945 type
= TYPE_MAIN_VARIANT (type
);
17946 tree_size
= TYPE_SIZE_UNIT (type
);
17947 return ((tree_size
!= NULL_TREE
)
17948 ? loc_descriptor_from_tree (tree_size
, 0, &ctx
)
17952 /* Helper structure for RECORD_TYPE processing. */
17955 /* Root RECORD_TYPE. It is needed to generate data member location
17956 descriptions in variable-length records (VLR), but also to cope with
17957 variants, which are composed of nested structures multiplexed with
17958 QUAL_UNION_TYPE nodes. Each time such a structure is passed to a
17959 function processing a FIELD_DECL, it is required to be non null. */
17961 /* When generating a variant part in a RECORD_TYPE (i.e. a nested
17962 QUAL_UNION_TYPE), this holds an expression that computes the offset for
17963 this variant part as part of the root record (in storage units). For
17964 regular records, it must be NULL_TREE. */
17965 tree variant_part_offset
;
17968 /* Given a pointer to a FIELD_DECL, compute the byte offset of the lowest
17969 addressed byte of the "containing object" for the given FIELD_DECL. If
17970 possible, return a native constant through CST_OFFSET (in which case NULL is
17971 returned); otherwise return a DWARF expression that computes the offset.
17973 Set *CST_OFFSET to 0 and return NULL if we are unable to determine what
17974 that offset is, either because the argument turns out to be a pointer to an
17975 ERROR_MARK node, or because the offset expression is too complex for us.
17977 CTX is required: see the comment for VLR_CONTEXT. */
17979 static dw_loc_descr_ref
17980 field_byte_offset (const_tree decl
, struct vlr_context
*ctx
,
17981 HOST_WIDE_INT
*cst_offset
)
17983 offset_int object_offset_in_bits
;
17984 offset_int object_offset_in_bytes
;
17985 offset_int bitpos_int
;
17986 bool is_byte_offset_cst
, is_bit_offset_cst
;
17988 dw_loc_list_ref loc_result
;
17992 if (TREE_CODE (decl
) == ERROR_MARK
)
17995 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
17997 is_bit_offset_cst
= TREE_CODE (DECL_FIELD_BIT_OFFSET (decl
)) != INTEGER_CST
;
17998 is_byte_offset_cst
= TREE_CODE (DECL_FIELD_OFFSET (decl
)) != INTEGER_CST
;
18000 /* We cannot handle variable bit offsets at the moment, so abort if it's the
18002 if (is_bit_offset_cst
)
18005 #ifdef PCC_BITFIELD_TYPE_MATTERS
18006 /* We used to handle only constant offsets in all cases. Now, we handle
18007 properly dynamic byte offsets only when PCC bitfield type doesn't
18009 if (PCC_BITFIELD_TYPE_MATTERS
&& is_byte_offset_cst
&& is_bit_offset_cst
)
18012 tree field_size_tree
;
18013 offset_int deepest_bitpos
;
18014 offset_int field_size_in_bits
;
18015 unsigned int type_align_in_bits
;
18016 unsigned int decl_align_in_bits
;
18017 offset_int type_size_in_bits
;
18019 bitpos_int
= wi::to_offset (bit_position (decl
));
18020 type
= field_type (decl
);
18021 type_size_in_bits
= offset_int_type_size_in_bits (type
);
18022 type_align_in_bits
= simple_type_align_in_bits (type
);
18024 field_size_tree
= DECL_SIZE (decl
);
18026 /* The size could be unspecified if there was an error, or for
18027 a flexible array member. */
18028 if (!field_size_tree
)
18029 field_size_tree
= bitsize_zero_node
;
18031 /* If the size of the field is not constant, use the type size. */
18032 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
18033 field_size_in_bits
= wi::to_offset (field_size_tree
);
18035 field_size_in_bits
= type_size_in_bits
;
18037 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
18039 /* The GCC front-end doesn't make any attempt to keep track of the
18040 starting bit offset (relative to the start of the containing
18041 structure type) of the hypothetical "containing object" for a
18042 bit-field. Thus, when computing the byte offset value for the
18043 start of the "containing object" of a bit-field, we must deduce
18044 this information on our own. This can be rather tricky to do in
18045 some cases. For example, handling the following structure type
18046 definition when compiling for an i386/i486 target (which only
18047 aligns long long's to 32-bit boundaries) can be very tricky:
18049 struct S { int field1; long long field2:31; };
18051 Fortunately, there is a simple rule-of-thumb which can be used
18052 in such cases. When compiling for an i386/i486, GCC will
18053 allocate 8 bytes for the structure shown above. It decides to
18054 do this based upon one simple rule for bit-field allocation.
18055 GCC allocates each "containing object" for each bit-field at
18056 the first (i.e. lowest addressed) legitimate alignment boundary
18057 (based upon the required minimum alignment for the declared
18058 type of the field) which it can possibly use, subject to the
18059 condition that there is still enough available space remaining
18060 in the containing object (when allocated at the selected point)
18061 to fully accommodate all of the bits of the bit-field itself.
18063 This simple rule makes it obvious why GCC allocates 8 bytes for
18064 each object of the structure type shown above. When looking
18065 for a place to allocate the "containing object" for `field2',
18066 the compiler simply tries to allocate a 64-bit "containing
18067 object" at each successive 32-bit boundary (starting at zero)
18068 until it finds a place to allocate that 64- bit field such that
18069 at least 31 contiguous (and previously unallocated) bits remain
18070 within that selected 64 bit field. (As it turns out, for the
18071 example above, the compiler finds it is OK to allocate the
18072 "containing object" 64-bit field at bit-offset zero within the
18075 Here we attempt to work backwards from the limited set of facts
18076 we're given, and we try to deduce from those facts, where GCC
18077 must have believed that the containing object started (within
18078 the structure type). The value we deduce is then used (by the
18079 callers of this routine) to generate DW_AT_location and
18080 DW_AT_bit_offset attributes for fields (both bit-fields and, in
18081 the case of DW_AT_location, regular fields as well). */
18083 /* Figure out the bit-distance from the start of the structure to
18084 the "deepest" bit of the bit-field. */
18085 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
18087 /* This is the tricky part. Use some fancy footwork to deduce
18088 where the lowest addressed bit of the containing object must
18090 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
18092 /* Round up to type_align by default. This works best for
18094 object_offset_in_bits
18095 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
18097 if (wi::gtu_p (object_offset_in_bits
, bitpos_int
))
18099 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
18101 /* Round up to decl_align instead. */
18102 object_offset_in_bits
18103 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
18106 #endif /* PCC_BITFIELD_TYPE_MATTERS */
18108 tree_result
= byte_position (decl
);
18109 if (ctx
->variant_part_offset
!= NULL_TREE
)
18110 tree_result
= fold (build2 (PLUS_EXPR
, TREE_TYPE (tree_result
),
18111 ctx
->variant_part_offset
, tree_result
));
18113 /* If the byte offset is a constant, it's simplier to handle a native
18114 constant rather than a DWARF expression. */
18115 if (TREE_CODE (tree_result
) == INTEGER_CST
)
18117 *cst_offset
= wi::to_offset (tree_result
).to_shwi ();
18120 struct loc_descr_context loc_ctx
= {
18121 ctx
->struct_type
, /* context_type */
18122 NULL_TREE
, /* base_decl */
18124 false, /* placeholder_arg */
18125 false /* placeholder_seen */
18127 loc_result
= loc_list_from_tree (tree_result
, 0, &loc_ctx
);
18129 /* We want a DWARF expression: abort if we only have a location list with
18130 multiple elements. */
18131 if (!loc_result
|| !single_element_loc_list_p (loc_result
))
18134 return loc_result
->expr
;
18137 /* The following routines define various Dwarf attributes and any data
18138 associated with them. */
18140 /* Add a location description attribute value to a DIE.
18142 This emits location attributes suitable for whole variables and
18143 whole parameters. Note that the location attributes for struct fields are
18144 generated by the routine `data_member_location_attribute' below. */
18147 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
18148 dw_loc_list_ref descr
)
18152 if (single_element_loc_list_p (descr
))
18153 add_AT_loc (die
, attr_kind
, descr
->expr
);
18155 add_AT_loc_list (die
, attr_kind
, descr
);
18158 /* Add DW_AT_accessibility attribute to DIE if needed. */
18161 add_accessibility_attribute (dw_die_ref die
, tree decl
)
18163 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
18164 children, otherwise the default is DW_ACCESS_public. In DWARF2
18165 the default has always been DW_ACCESS_public. */
18166 if (TREE_PROTECTED (decl
))
18167 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
18168 else if (TREE_PRIVATE (decl
))
18170 if (dwarf_version
== 2
18171 || die
->die_parent
== NULL
18172 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
18173 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
18175 else if (dwarf_version
> 2
18177 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
18178 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
18181 /* Attach the specialized form of location attribute used for data members of
18182 struct and union types. In the special case of a FIELD_DECL node which
18183 represents a bit-field, the "offset" part of this special location
18184 descriptor must indicate the distance in bytes from the lowest-addressed
18185 byte of the containing struct or union type to the lowest-addressed byte of
18186 the "containing object" for the bit-field. (See the `field_byte_offset'
18189 For any given bit-field, the "containing object" is a hypothetical object
18190 (of some integral or enum type) within which the given bit-field lives. The
18191 type of this hypothetical "containing object" is always the same as the
18192 declared type of the individual bit-field itself (for GCC anyway... the
18193 DWARF spec doesn't actually mandate this). Note that it is the size (in
18194 bytes) of the hypothetical "containing object" which will be given in the
18195 DW_AT_byte_size attribute for this bit-field. (See the
18196 `byte_size_attribute' function below.) It is also used when calculating the
18197 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
18200 CTX is required: see the comment for VLR_CONTEXT. */
18203 add_data_member_location_attribute (dw_die_ref die
,
18205 struct vlr_context
*ctx
)
18207 HOST_WIDE_INT offset
;
18208 dw_loc_descr_ref loc_descr
= 0;
18210 if (TREE_CODE (decl
) == TREE_BINFO
)
18212 /* We're working on the TAG_inheritance for a base class. */
18213 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
18215 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
18216 aren't at a fixed offset from all (sub)objects of the same
18217 type. We need to extract the appropriate offset from our
18218 vtable. The following dwarf expression means
18220 BaseAddr = ObAddr + *((*ObAddr) - Offset)
18222 This is specific to the V3 ABI, of course. */
18224 dw_loc_descr_ref tmp
;
18226 /* Make a copy of the object address. */
18227 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
18228 add_loc_descr (&loc_descr
, tmp
);
18230 /* Extract the vtable address. */
18231 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
18232 add_loc_descr (&loc_descr
, tmp
);
18234 /* Calculate the address of the offset. */
18235 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
18236 gcc_assert (offset
< 0);
18238 tmp
= int_loc_descriptor (-offset
);
18239 add_loc_descr (&loc_descr
, tmp
);
18240 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
18241 add_loc_descr (&loc_descr
, tmp
);
18243 /* Extract the offset. */
18244 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
18245 add_loc_descr (&loc_descr
, tmp
);
18247 /* Add it to the object address. */
18248 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
18249 add_loc_descr (&loc_descr
, tmp
);
18252 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
18256 loc_descr
= field_byte_offset (decl
, ctx
, &offset
);
18258 /* If loc_descr is available then we know the field offset is dynamic.
18259 However, GDB does not handle dynamic field offsets very well at the
18261 if (loc_descr
!= NULL
&& gnat_encodings
!= DWARF_GNAT_ENCODINGS_MINIMAL
)
18267 /* Data member location evalutation starts with the base address on the
18268 stack. Compute the field offset and add it to this base address. */
18269 else if (loc_descr
!= NULL
)
18270 add_loc_descr (&loc_descr
, new_loc_descr (DW_OP_plus
, 0, 0));
18275 if (dwarf_version
> 2)
18277 /* Don't need to output a location expression, just the constant. */
18279 add_AT_int (die
, DW_AT_data_member_location
, offset
);
18281 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
18286 enum dwarf_location_atom op
;
18288 /* The DWARF2 standard says that we should assume that the structure
18289 address is already on the stack, so we can specify a structure
18290 field address by using DW_OP_plus_uconst. */
18291 op
= DW_OP_plus_uconst
;
18292 loc_descr
= new_loc_descr (op
, offset
, 0);
18296 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
18299 /* Writes integer values to dw_vec_const array. */
18302 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
18306 *dest
++ = val
& 0xff;
18312 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
18314 static HOST_WIDE_INT
18315 extract_int (const unsigned char *src
, unsigned int size
)
18317 HOST_WIDE_INT val
= 0;
18323 val
|= *--src
& 0xff;
18329 /* Writes wide_int values to dw_vec_const array. */
18332 insert_wide_int (const wide_int
&val
, unsigned char *dest
, int elt_size
)
18336 if (elt_size
<= HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
)
18338 insert_int ((HOST_WIDE_INT
) val
.elt (0), elt_size
, dest
);
18342 /* We'd have to extend this code to support odd sizes. */
18343 gcc_assert (elt_size
% (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
) == 0);
18345 int n
= elt_size
/ (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
18347 if (WORDS_BIG_ENDIAN
)
18348 for (i
= n
- 1; i
>= 0; i
--)
18350 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
18351 dest
+= sizeof (HOST_WIDE_INT
);
18354 for (i
= 0; i
< n
; i
++)
18356 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
18357 dest
+= sizeof (HOST_WIDE_INT
);
18361 /* Writes floating point values to dw_vec_const array. */
18364 insert_float (const_rtx rtl
, unsigned char *array
)
18369 real_to_target (val
, CONST_DOUBLE_REAL_VALUE (rtl
), GET_MODE (rtl
));
18371 /* real_to_target puts 32-bit pieces in each long. Pack them. */
18372 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
18374 insert_int (val
[i
], 4, array
);
18379 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
18380 does not have a "location" either in memory or in a register. These
18381 things can arise in GNU C when a constant is passed as an actual parameter
18382 to an inlined function. They can also arise in C++ where declared
18383 constants do not necessarily get memory "homes". */
18386 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
18388 switch (GET_CODE (rtl
))
18392 HOST_WIDE_INT val
= INTVAL (rtl
);
18395 add_AT_int (die
, DW_AT_const_value
, val
);
18397 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
18401 case CONST_WIDE_INT
:
18403 wide_int w1
= rtx_mode_t (rtl
, MAX_MODE_INT
);
18404 unsigned int prec
= MIN (wi::min_precision (w1
, UNSIGNED
),
18405 (unsigned int)CONST_WIDE_INT_NUNITS (rtl
) * HOST_BITS_PER_WIDE_INT
);
18406 wide_int w
= wi::zext (w1
, prec
);
18407 add_AT_wide (die
, DW_AT_const_value
, w
);
18412 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
18413 floating-point constant. A CONST_DOUBLE is used whenever the
18414 constant requires more than one word in order to be adequately
18417 machine_mode mode
= GET_MODE (rtl
);
18419 if (TARGET_SUPPORTS_WIDE_INT
== 0 && !SCALAR_FLOAT_MODE_P (mode
))
18420 add_AT_double (die
, DW_AT_const_value
,
18421 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
18424 unsigned int length
= GET_MODE_SIZE (mode
);
18425 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
18427 insert_float (rtl
, array
);
18428 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
18435 machine_mode mode
= GET_MODE (rtl
);
18436 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
18437 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
18438 unsigned char *array
18439 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
18442 machine_mode imode
= GET_MODE_INNER (mode
);
18444 switch (GET_MODE_CLASS (mode
))
18446 case MODE_VECTOR_INT
:
18447 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
18449 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
18450 insert_wide_int (rtx_mode_t (elt
, imode
), p
, elt_size
);
18454 case MODE_VECTOR_FLOAT
:
18455 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
18457 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
18458 insert_float (elt
, p
);
18463 gcc_unreachable ();
18466 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
18471 if (dwarf_version
>= 4 || !dwarf_strict
)
18473 dw_loc_descr_ref loc_result
;
18474 resolve_one_addr (&rtl
);
18476 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
18477 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
18478 add_AT_loc (die
, DW_AT_location
, loc_result
);
18479 vec_safe_push (used_rtx_array
, rtl
);
18485 if (CONSTANT_P (XEXP (rtl
, 0)))
18486 return add_const_value_attribute (die
, XEXP (rtl
, 0));
18489 if (!const_ok_for_output (rtl
))
18493 if (dwarf_version
>= 4 || !dwarf_strict
)
18498 /* In cases where an inlined instance of an inline function is passed
18499 the address of an `auto' variable (which is local to the caller) we
18500 can get a situation where the DECL_RTL of the artificial local
18501 variable (for the inlining) which acts as a stand-in for the
18502 corresponding formal parameter (of the inline function) will look
18503 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
18504 exactly a compile-time constant expression, but it isn't the address
18505 of the (artificial) local variable either. Rather, it represents the
18506 *value* which the artificial local variable always has during its
18507 lifetime. We currently have no way to represent such quasi-constant
18508 values in Dwarf, so for now we just punt and generate nothing. */
18516 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
18517 && MEM_READONLY_P (rtl
)
18518 && GET_MODE (rtl
) == BLKmode
)
18520 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
18526 /* No other kinds of rtx should be possible here. */
18527 gcc_unreachable ();
18532 /* Determine whether the evaluation of EXPR references any variables
18533 or functions which aren't otherwise used (and therefore may not be
18536 reference_to_unused (tree
* tp
, int * walk_subtrees
,
18537 void * data ATTRIBUTE_UNUSED
)
18539 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
18540 *walk_subtrees
= 0;
18542 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
18543 && ! TREE_ASM_WRITTEN (*tp
))
18545 /* ??? The C++ FE emits debug information for using decls, so
18546 putting gcc_unreachable here falls over. See PR31899. For now
18547 be conservative. */
18548 else if (!symtab
->global_info_ready
&& VAR_OR_FUNCTION_DECL_P (*tp
))
18550 else if (VAR_P (*tp
))
18552 varpool_node
*node
= varpool_node::get (*tp
);
18553 if (!node
|| !node
->definition
)
18556 else if (TREE_CODE (*tp
) == FUNCTION_DECL
18557 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
18559 /* The call graph machinery must have finished analyzing,
18560 optimizing and gimplifying the CU by now.
18561 So if *TP has no call graph node associated
18562 to it, it means *TP will not be emitted. */
18563 if (!cgraph_node::get (*tp
))
18566 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
18572 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
18573 for use in a later add_const_value_attribute call. */
18576 rtl_for_decl_init (tree init
, tree type
)
18578 rtx rtl
= NULL_RTX
;
18582 /* If a variable is initialized with a string constant without embedded
18583 zeros, build CONST_STRING. */
18584 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
18586 tree enttype
= TREE_TYPE (type
);
18587 tree domain
= TYPE_DOMAIN (type
);
18588 machine_mode mode
= TYPE_MODE (enttype
);
18590 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
18592 && integer_zerop (TYPE_MIN_VALUE (domain
))
18593 && compare_tree_int (TYPE_MAX_VALUE (domain
),
18594 TREE_STRING_LENGTH (init
) - 1) == 0
18595 && ((size_t) TREE_STRING_LENGTH (init
)
18596 == strlen (TREE_STRING_POINTER (init
)) + 1))
18598 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
18599 ggc_strdup (TREE_STRING_POINTER (init
)));
18600 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
18601 MEM_READONLY_P (rtl
) = 1;
18604 /* Other aggregates, and complex values, could be represented using
18606 else if (AGGREGATE_TYPE_P (type
)
18607 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
18608 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
18609 || TREE_CODE (type
) == COMPLEX_TYPE
)
18611 /* Vectors only work if their mode is supported by the target.
18612 FIXME: generic vectors ought to work too. */
18613 else if (TREE_CODE (type
) == VECTOR_TYPE
18614 && !VECTOR_MODE_P (TYPE_MODE (type
)))
18616 /* If the initializer is something that we know will expand into an
18617 immediate RTL constant, expand it now. We must be careful not to
18618 reference variables which won't be output. */
18619 else if (initializer_constant_valid_p (init
, type
)
18620 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
18622 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
18624 if (TREE_CODE (type
) == VECTOR_TYPE
)
18625 switch (TREE_CODE (init
))
18630 if (TREE_CONSTANT (init
))
18632 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
18633 bool constant_p
= true;
18635 unsigned HOST_WIDE_INT ix
;
18637 /* Even when ctor is constant, it might contain non-*_CST
18638 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
18639 belong into VECTOR_CST nodes. */
18640 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
18641 if (!CONSTANT_CLASS_P (value
))
18643 constant_p
= false;
18649 init
= build_vector_from_ctor (type
, elts
);
18659 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
18661 /* If expand_expr returns a MEM, it wasn't immediate. */
18662 gcc_assert (!rtl
|| !MEM_P (rtl
));
18668 /* Generate RTL for the variable DECL to represent its location. */
18671 rtl_for_decl_location (tree decl
)
18675 /* Here we have to decide where we are going to say the parameter "lives"
18676 (as far as the debugger is concerned). We only have a couple of
18677 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
18679 DECL_RTL normally indicates where the parameter lives during most of the
18680 activation of the function. If optimization is enabled however, this
18681 could be either NULL or else a pseudo-reg. Both of those cases indicate
18682 that the parameter doesn't really live anywhere (as far as the code
18683 generation parts of GCC are concerned) during most of the function's
18684 activation. That will happen (for example) if the parameter is never
18685 referenced within the function.
18687 We could just generate a location descriptor here for all non-NULL
18688 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
18689 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
18690 where DECL_RTL is NULL or is a pseudo-reg.
18692 Note however that we can only get away with using DECL_INCOMING_RTL as
18693 a backup substitute for DECL_RTL in certain limited cases. In cases
18694 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
18695 we can be sure that the parameter was passed using the same type as it is
18696 declared to have within the function, and that its DECL_INCOMING_RTL
18697 points us to a place where a value of that type is passed.
18699 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
18700 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
18701 because in these cases DECL_INCOMING_RTL points us to a value of some
18702 type which is *different* from the type of the parameter itself. Thus,
18703 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
18704 such cases, the debugger would end up (for example) trying to fetch a
18705 `float' from a place which actually contains the first part of a
18706 `double'. That would lead to really incorrect and confusing
18707 output at debug-time.
18709 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
18710 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
18711 are a couple of exceptions however. On little-endian machines we can
18712 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
18713 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
18714 an integral type that is smaller than TREE_TYPE (decl). These cases arise
18715 when (on a little-endian machine) a non-prototyped function has a
18716 parameter declared to be of type `short' or `char'. In such cases,
18717 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
18718 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
18719 passed `int' value. If the debugger then uses that address to fetch
18720 a `short' or a `char' (on a little-endian machine) the result will be
18721 the correct data, so we allow for such exceptional cases below.
18723 Note that our goal here is to describe the place where the given formal
18724 parameter lives during most of the function's activation (i.e. between the
18725 end of the prologue and the start of the epilogue). We'll do that as best
18726 as we can. Note however that if the given formal parameter is modified
18727 sometime during the execution of the function, then a stack backtrace (at
18728 debug-time) will show the function as having been called with the *new*
18729 value rather than the value which was originally passed in. This happens
18730 rarely enough that it is not a major problem, but it *is* a problem, and
18731 I'd like to fix it.
18733 A future version of dwarf2out.c may generate two additional attributes for
18734 any given DW_TAG_formal_parameter DIE which will describe the "passed
18735 type" and the "passed location" for the given formal parameter in addition
18736 to the attributes we now generate to indicate the "declared type" and the
18737 "active location" for each parameter. This additional set of attributes
18738 could be used by debuggers for stack backtraces. Separately, note that
18739 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
18740 This happens (for example) for inlined-instances of inline function formal
18741 parameters which are never referenced. This really shouldn't be
18742 happening. All PARM_DECL nodes should get valid non-NULL
18743 DECL_INCOMING_RTL values. FIXME. */
18745 /* Use DECL_RTL as the "location" unless we find something better. */
18746 rtl
= DECL_RTL_IF_SET (decl
);
18748 /* When generating abstract instances, ignore everything except
18749 constants, symbols living in memory, and symbols living in
18750 fixed registers. */
18751 if (! reload_completed
)
18754 && (CONSTANT_P (rtl
)
18756 && CONSTANT_P (XEXP (rtl
, 0)))
18759 && TREE_STATIC (decl
))))
18761 rtl
= targetm
.delegitimize_address (rtl
);
18766 else if (TREE_CODE (decl
) == PARM_DECL
)
18768 if (rtl
== NULL_RTX
18769 || is_pseudo_reg (rtl
)
18771 && is_pseudo_reg (XEXP (rtl
, 0))
18772 && DECL_INCOMING_RTL (decl
)
18773 && MEM_P (DECL_INCOMING_RTL (decl
))
18774 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
18776 tree declared_type
= TREE_TYPE (decl
);
18777 tree passed_type
= DECL_ARG_TYPE (decl
);
18778 machine_mode dmode
= TYPE_MODE (declared_type
);
18779 machine_mode pmode
= TYPE_MODE (passed_type
);
18781 /* This decl represents a formal parameter which was optimized out.
18782 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
18783 all cases where (rtl == NULL_RTX) just below. */
18784 if (dmode
== pmode
)
18785 rtl
= DECL_INCOMING_RTL (decl
);
18786 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
18787 && SCALAR_INT_MODE_P (dmode
)
18788 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
18789 && DECL_INCOMING_RTL (decl
))
18791 rtx inc
= DECL_INCOMING_RTL (decl
);
18794 else if (MEM_P (inc
))
18796 if (BYTES_BIG_ENDIAN
)
18797 rtl
= adjust_address_nv (inc
, dmode
,
18798 GET_MODE_SIZE (pmode
)
18799 - GET_MODE_SIZE (dmode
));
18806 /* If the parm was passed in registers, but lives on the stack, then
18807 make a big endian correction if the mode of the type of the
18808 parameter is not the same as the mode of the rtl. */
18809 /* ??? This is the same series of checks that are made in dbxout.c before
18810 we reach the big endian correction code there. It isn't clear if all
18811 of these checks are necessary here, but keeping them all is the safe
18813 else if (MEM_P (rtl
)
18814 && XEXP (rtl
, 0) != const0_rtx
18815 && ! CONSTANT_P (XEXP (rtl
, 0))
18816 /* Not passed in memory. */
18817 && !MEM_P (DECL_INCOMING_RTL (decl
))
18818 /* Not passed by invisible reference. */
18819 && (!REG_P (XEXP (rtl
, 0))
18820 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
18821 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
18822 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
18823 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
18826 /* Big endian correction check. */
18827 && BYTES_BIG_ENDIAN
18828 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
18829 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
18832 machine_mode addr_mode
= get_address_mode (rtl
);
18833 int offset
= (UNITS_PER_WORD
18834 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
18836 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
18837 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
18840 else if (VAR_P (decl
)
18843 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
18844 && BYTES_BIG_ENDIAN
)
18846 machine_mode addr_mode
= get_address_mode (rtl
);
18847 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
18848 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
18850 /* If a variable is declared "register" yet is smaller than
18851 a register, then if we store the variable to memory, it
18852 looks like we're storing a register-sized value, when in
18853 fact we are not. We need to adjust the offset of the
18854 storage location to reflect the actual value's bytes,
18855 else gdb will not be able to display it. */
18857 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
18858 plus_constant (addr_mode
, XEXP (rtl
, 0),
18862 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
18863 and will have been substituted directly into all expressions that use it.
18864 C does not have such a concept, but C++ and other languages do. */
18865 if (!rtl
&& VAR_P (decl
) && DECL_INITIAL (decl
))
18866 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
18869 rtl
= targetm
.delegitimize_address (rtl
);
18871 /* If we don't look past the constant pool, we risk emitting a
18872 reference to a constant pool entry that isn't referenced from
18873 code, and thus is not emitted. */
18875 rtl
= avoid_constant_pool_reference (rtl
);
18877 /* Try harder to get a rtl. If this symbol ends up not being emitted
18878 in the current CU, resolve_addr will remove the expression referencing
18880 if (rtl
== NULL_RTX
18882 && !DECL_EXTERNAL (decl
)
18883 && TREE_STATIC (decl
)
18884 && DECL_NAME (decl
)
18885 && !DECL_HARD_REGISTER (decl
)
18886 && DECL_MODE (decl
) != VOIDmode
)
18888 rtl
= make_decl_rtl_for_debug (decl
);
18890 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
18891 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
18898 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
18899 returned. If so, the decl for the COMMON block is returned, and the
18900 value is the offset into the common block for the symbol. */
18903 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
18905 tree val_expr
, cvar
;
18907 HOST_WIDE_INT bitsize
, bitpos
;
18909 int unsignedp
, reversep
, volatilep
= 0;
18911 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
18912 it does not have a value (the offset into the common area), or if it
18913 is thread local (as opposed to global) then it isn't common, and shouldn't
18914 be handled as such. */
18916 || !TREE_STATIC (decl
)
18917 || !DECL_HAS_VALUE_EXPR_P (decl
)
18921 val_expr
= DECL_VALUE_EXPR (decl
);
18922 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
18925 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
, &mode
,
18926 &unsignedp
, &reversep
, &volatilep
);
18928 if (cvar
== NULL_TREE
18930 || DECL_ARTIFICIAL (cvar
)
18931 || !TREE_PUBLIC (cvar
))
18935 if (offset
!= NULL
)
18937 if (!tree_fits_shwi_p (offset
))
18939 *value
= tree_to_shwi (offset
);
18942 *value
+= bitpos
/ BITS_PER_UNIT
;
18947 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
18948 data attribute for a variable or a parameter. We generate the
18949 DW_AT_const_value attribute only in those cases where the given variable
18950 or parameter does not have a true "location" either in memory or in a
18951 register. This can happen (for example) when a constant is passed as an
18952 actual argument in a call to an inline function. (It's possible that
18953 these things can crop up in other ways also.) Note that one type of
18954 constant value which can be passed into an inlined function is a constant
18955 pointer. This can happen for example if an actual argument in an inlined
18956 function call evaluates to a compile-time constant address.
18958 CACHE_P is true if it is worth caching the location list for DECL,
18959 so that future calls can reuse it rather than regenerate it from scratch.
18960 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
18961 since we will need to refer to them each time the function is inlined. */
18964 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
)
18967 dw_loc_list_ref list
;
18968 var_loc_list
*loc_list
;
18969 cached_dw_loc_list
*cache
;
18974 if (TREE_CODE (decl
) == ERROR_MARK
)
18977 if (get_AT (die
, DW_AT_location
)
18978 || get_AT (die
, DW_AT_const_value
))
18981 gcc_assert (VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
18982 || TREE_CODE (decl
) == RESULT_DECL
);
18984 /* Try to get some constant RTL for this decl, and use that as the value of
18987 rtl
= rtl_for_decl_location (decl
);
18988 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
18989 && add_const_value_attribute (die
, rtl
))
18992 /* See if we have single element location list that is equivalent to
18993 a constant value. That way we are better to use add_const_value_attribute
18994 rather than expanding constant value equivalent. */
18995 loc_list
= lookup_decl_loc (decl
);
18998 && loc_list
->first
->next
== NULL
18999 && NOTE_P (loc_list
->first
->loc
)
19000 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
19001 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
19003 struct var_loc_node
*node
;
19005 node
= loc_list
->first
;
19006 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
19007 if (GET_CODE (rtl
) == EXPR_LIST
)
19008 rtl
= XEXP (rtl
, 0);
19009 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
19010 && add_const_value_attribute (die
, rtl
))
19013 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
19014 list several times. See if we've already cached the contents. */
19016 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
19020 cache
= cached_dw_loc_list_table
->find_with_hash (decl
, DECL_UID (decl
));
19022 list
= cache
->loc_list
;
19026 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2,
19028 /* It is usually worth caching this result if the decl is from
19029 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
19030 if (cache_p
&& list
&& list
->dw_loc_next
)
19032 cached_dw_loc_list
**slot
19033 = cached_dw_loc_list_table
->find_slot_with_hash (decl
,
19036 cache
= ggc_cleared_alloc
<cached_dw_loc_list
> ();
19037 cache
->decl_id
= DECL_UID (decl
);
19038 cache
->loc_list
= list
;
19044 add_AT_location_description (die
, DW_AT_location
, list
);
19047 /* None of that worked, so it must not really have a location;
19048 try adding a constant value attribute from the DECL_INITIAL. */
19049 return tree_add_const_value_attribute_for_decl (die
, decl
);
19052 /* Helper function for tree_add_const_value_attribute. Natively encode
19053 initializer INIT into an array. Return true if successful. */
19056 native_encode_initializer (tree init
, unsigned char *array
, int size
)
19060 if (init
== NULL_TREE
)
19064 switch (TREE_CODE (init
))
19067 type
= TREE_TYPE (init
);
19068 if (TREE_CODE (type
) == ARRAY_TYPE
)
19070 tree enttype
= TREE_TYPE (type
);
19071 machine_mode mode
= TYPE_MODE (enttype
);
19073 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
19075 if (int_size_in_bytes (type
) != size
)
19077 if (size
> TREE_STRING_LENGTH (init
))
19079 memcpy (array
, TREE_STRING_POINTER (init
),
19080 TREE_STRING_LENGTH (init
));
19081 memset (array
+ TREE_STRING_LENGTH (init
),
19082 '\0', size
- TREE_STRING_LENGTH (init
));
19085 memcpy (array
, TREE_STRING_POINTER (init
), size
);
19090 type
= TREE_TYPE (init
);
19091 if (int_size_in_bytes (type
) != size
)
19093 if (TREE_CODE (type
) == ARRAY_TYPE
)
19095 HOST_WIDE_INT min_index
;
19096 unsigned HOST_WIDE_INT cnt
;
19097 int curpos
= 0, fieldsize
;
19098 constructor_elt
*ce
;
19100 if (TYPE_DOMAIN (type
) == NULL_TREE
19101 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))))
19104 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
19105 if (fieldsize
<= 0)
19108 min_index
= tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)));
19109 memset (array
, '\0', size
);
19110 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
19112 tree val
= ce
->value
;
19113 tree index
= ce
->index
;
19115 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
19116 pos
= (tree_to_shwi (TREE_OPERAND (index
, 0)) - min_index
)
19119 pos
= (tree_to_shwi (index
) - min_index
) * fieldsize
;
19124 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
19127 curpos
= pos
+ fieldsize
;
19128 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
19130 int count
= tree_to_shwi (TREE_OPERAND (index
, 1))
19131 - tree_to_shwi (TREE_OPERAND (index
, 0));
19132 while (count
-- > 0)
19135 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
19136 curpos
+= fieldsize
;
19139 gcc_assert (curpos
<= size
);
19143 else if (TREE_CODE (type
) == RECORD_TYPE
19144 || TREE_CODE (type
) == UNION_TYPE
)
19146 tree field
= NULL_TREE
;
19147 unsigned HOST_WIDE_INT cnt
;
19148 constructor_elt
*ce
;
19150 if (int_size_in_bytes (type
) != size
)
19153 if (TREE_CODE (type
) == RECORD_TYPE
)
19154 field
= TYPE_FIELDS (type
);
19156 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
19158 tree val
= ce
->value
;
19159 int pos
, fieldsize
;
19161 if (ce
->index
!= 0)
19167 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
19170 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
19171 && TYPE_DOMAIN (TREE_TYPE (field
))
19172 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
19174 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
19175 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field
)))
19177 fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
19178 pos
= int_byte_position (field
);
19179 gcc_assert (pos
+ fieldsize
<= size
);
19180 if (val
&& fieldsize
!= 0
19181 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
19187 case VIEW_CONVERT_EXPR
:
19188 case NON_LVALUE_EXPR
:
19189 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
19191 return native_encode_expr (init
, array
, size
) == size
;
19195 /* Attach a DW_AT_const_value attribute to DIE. The value of the
19196 attribute is the const value T. */
19199 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
19202 tree type
= TREE_TYPE (t
);
19205 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
19209 gcc_assert (!DECL_P (init
));
19213 rtl
= rtl_for_decl_init (init
, type
);
19215 return add_const_value_attribute (die
, rtl
);
19217 /* If the host and target are sane, try harder. */
19218 if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
19219 && initializer_constant_valid_p (init
, type
))
19221 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
19222 if (size
> 0 && (int) size
== size
)
19224 unsigned char *array
= ggc_cleared_vec_alloc
<unsigned char> (size
);
19226 if (native_encode_initializer (init
, array
, size
))
19228 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
19237 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
19238 attribute is the const value of T, where T is an integral constant
19239 variable with static storage duration
19240 (so it can't be a PARM_DECL or a RESULT_DECL). */
19243 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
19247 || (!VAR_P (decl
) && TREE_CODE (decl
) != CONST_DECL
)
19248 || (VAR_P (decl
) && !TREE_STATIC (decl
)))
19251 if (TREE_READONLY (decl
)
19252 && ! TREE_THIS_VOLATILE (decl
)
19253 && DECL_INITIAL (decl
))
19258 /* Don't add DW_AT_const_value if abstract origin already has one. */
19259 if (get_AT (var_die
, DW_AT_const_value
))
19262 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
19265 /* Convert the CFI instructions for the current function into a
19266 location list. This is used for DW_AT_frame_base when we targeting
19267 a dwarf2 consumer that does not support the dwarf3
19268 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
19271 static dw_loc_list_ref
19272 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
19276 dw_loc_list_ref list
, *list_tail
;
19278 dw_cfa_location last_cfa
, next_cfa
;
19279 const char *start_label
, *last_label
, *section
;
19280 dw_cfa_location remember
;
19283 gcc_assert (fde
!= NULL
);
19285 section
= secname_for_decl (current_function_decl
);
19289 memset (&next_cfa
, 0, sizeof (next_cfa
));
19290 next_cfa
.reg
= INVALID_REGNUM
;
19291 remember
= next_cfa
;
19293 start_label
= fde
->dw_fde_begin
;
19295 /* ??? Bald assumption that the CIE opcode list does not contain
19296 advance opcodes. */
19297 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
19298 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
19300 last_cfa
= next_cfa
;
19301 last_label
= start_label
;
19303 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
19305 /* If the first partition contained no CFI adjustments, the
19306 CIE opcodes apply to the whole first partition. */
19307 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19308 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
19309 list_tail
=&(*list_tail
)->dw_loc_next
;
19310 start_label
= last_label
= fde
->dw_fde_second_begin
;
19313 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
19315 switch (cfi
->dw_cfi_opc
)
19317 case DW_CFA_set_loc
:
19318 case DW_CFA_advance_loc1
:
19319 case DW_CFA_advance_loc2
:
19320 case DW_CFA_advance_loc4
:
19321 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
19323 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19324 start_label
, last_label
, section
);
19326 list_tail
= &(*list_tail
)->dw_loc_next
;
19327 last_cfa
= next_cfa
;
19328 start_label
= last_label
;
19330 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
19333 case DW_CFA_advance_loc
:
19334 /* The encoding is complex enough that we should never emit this. */
19335 gcc_unreachable ();
19338 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
19341 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
19343 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
19345 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19346 start_label
, last_label
, section
);
19348 list_tail
= &(*list_tail
)->dw_loc_next
;
19349 last_cfa
= next_cfa
;
19350 start_label
= last_label
;
19352 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19353 start_label
, fde
->dw_fde_end
, section
);
19354 list_tail
= &(*list_tail
)->dw_loc_next
;
19355 start_label
= last_label
= fde
->dw_fde_second_begin
;
19359 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
19361 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
19362 start_label
, last_label
, section
);
19363 list_tail
= &(*list_tail
)->dw_loc_next
;
19364 start_label
= last_label
;
19367 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
19369 fde
->dw_fde_second_begin
19370 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
19373 if (list
&& list
->dw_loc_next
)
19379 /* Compute a displacement from the "steady-state frame pointer" to the
19380 frame base (often the same as the CFA), and store it in
19381 frame_pointer_fb_offset. OFFSET is added to the displacement
19382 before the latter is negated. */
19385 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
19389 #ifdef FRAME_POINTER_CFA_OFFSET
19390 reg
= frame_pointer_rtx
;
19391 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
19393 reg
= arg_pointer_rtx
;
19394 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
19397 elim
= (ira_use_lra_p
19398 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
19399 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
19400 if (GET_CODE (elim
) == PLUS
)
19402 offset
+= INTVAL (XEXP (elim
, 1));
19403 elim
= XEXP (elim
, 0);
19406 frame_pointer_fb_offset
= -offset
;
19408 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
19409 in which to eliminate. This is because it's stack pointer isn't
19410 directly accessible as a register within the ISA. To work around
19411 this, assume that while we cannot provide a proper value for
19412 frame_pointer_fb_offset, we won't need one either. */
19413 frame_pointer_fb_offset_valid
19414 = ((SUPPORTS_STACK_ALIGNMENT
19415 && (elim
== hard_frame_pointer_rtx
19416 || elim
== stack_pointer_rtx
))
19417 || elim
== (frame_pointer_needed
19418 ? hard_frame_pointer_rtx
19419 : stack_pointer_rtx
));
19422 /* Generate a DW_AT_name attribute given some string value to be included as
19423 the value of the attribute. */
19426 add_name_attribute (dw_die_ref die
, const char *name_string
)
19428 if (name_string
!= NULL
&& *name_string
!= 0)
19430 if (demangle_name_func
)
19431 name_string
= (*demangle_name_func
) (name_string
);
19433 add_AT_string (die
, DW_AT_name
, name_string
);
19437 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
19438 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
19439 of TYPE accordingly.
19441 ??? This is a temporary measure until after we're able to generate
19442 regular DWARF for the complex Ada type system. */
19445 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
19446 dw_die_ref context_die
)
19449 dw_die_ref dtype_die
;
19451 if (!lang_hooks
.types
.descriptive_type
)
19454 dtype
= lang_hooks
.types
.descriptive_type (type
);
19458 dtype_die
= lookup_type_die (dtype
);
19461 gen_type_die (dtype
, context_die
);
19462 dtype_die
= lookup_type_die (dtype
);
19463 gcc_assert (dtype_die
);
19466 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
19469 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
19471 static const char *
19472 comp_dir_string (void)
19476 static const char *cached_wd
= NULL
;
19478 if (cached_wd
!= NULL
)
19481 wd
= get_src_pwd ();
19485 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
19489 wdlen
= strlen (wd
);
19490 wd1
= ggc_vec_alloc
<char> (wdlen
+ 2);
19492 wd1
[wdlen
] = DIR_SEPARATOR
;
19493 wd1
[wdlen
+ 1] = 0;
19497 cached_wd
= remap_debug_filename (wd
);
19501 /* Generate a DW_AT_comp_dir attribute for DIE. */
19504 add_comp_dir_attribute (dw_die_ref die
)
19506 const char * wd
= comp_dir_string ();
19508 add_AT_string (die
, DW_AT_comp_dir
, wd
);
19511 /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
19512 pointer computation, ...), output a representation for that bound according
19513 to the accepted FORMS (see enum dw_scalar_form) and add it to DIE. See
19514 loc_list_from_tree for the meaning of CONTEXT. */
19517 add_scalar_info (dw_die_ref die
, enum dwarf_attribute attr
, tree value
,
19518 int forms
, struct loc_descr_context
*context
)
19520 dw_die_ref context_die
, decl_die
;
19521 dw_loc_list_ref list
;
19522 bool strip_conversions
= true;
19523 bool placeholder_seen
= false;
19525 while (strip_conversions
)
19526 switch (TREE_CODE (value
))
19533 case VIEW_CONVERT_EXPR
:
19534 value
= TREE_OPERAND (value
, 0);
19538 strip_conversions
= false;
19542 /* If possible and permitted, output the attribute as a constant. */
19543 if ((forms
& dw_scalar_form_constant
) != 0
19544 && TREE_CODE (value
) == INTEGER_CST
)
19546 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (value
));
19548 /* If HOST_WIDE_INT is big enough then represent the bound as
19549 a constant value. We need to choose a form based on
19550 whether the type is signed or unsigned. We cannot just
19551 call add_AT_unsigned if the value itself is positive
19552 (add_AT_unsigned might add the unsigned value encoded as
19553 DW_FORM_data[1248]). Some DWARF consumers will lookup the
19554 bounds type and then sign extend any unsigned values found
19555 for signed types. This is needed only for
19556 DW_AT_{lower,upper}_bound, since for most other attributes,
19557 consumers will treat DW_FORM_data[1248] as unsigned values,
19558 regardless of the underlying type. */
19559 if (prec
<= HOST_BITS_PER_WIDE_INT
19560 || tree_fits_uhwi_p (value
))
19562 if (TYPE_UNSIGNED (TREE_TYPE (value
)))
19563 add_AT_unsigned (die
, attr
, TREE_INT_CST_LOW (value
));
19565 add_AT_int (die
, attr
, TREE_INT_CST_LOW (value
));
19568 /* Otherwise represent the bound as an unsigned value with
19569 the precision of its type. The precision and signedness
19570 of the type will be necessary to re-interpret it
19572 add_AT_wide (die
, attr
, value
);
19576 /* Otherwise, if it's possible and permitted too, output a reference to
19578 if ((forms
& dw_scalar_form_reference
) != 0)
19580 tree decl
= NULL_TREE
;
19582 /* Some type attributes reference an outer type. For instance, the upper
19583 bound of an array may reference an embedding record (this happens in
19585 if (TREE_CODE (value
) == COMPONENT_REF
19586 && TREE_CODE (TREE_OPERAND (value
, 0)) == PLACEHOLDER_EXPR
19587 && TREE_CODE (TREE_OPERAND (value
, 1)) == FIELD_DECL
)
19588 decl
= TREE_OPERAND (value
, 1);
19590 else if (VAR_P (value
)
19591 || TREE_CODE (value
) == PARM_DECL
19592 || TREE_CODE (value
) == RESULT_DECL
)
19595 if (decl
!= NULL_TREE
)
19597 dw_die_ref decl_die
= lookup_decl_die (decl
);
19599 /* ??? Can this happen, or should the variable have been bound
19600 first? Probably it can, since I imagine that we try to create
19601 the types of parameters in the order in which they exist in
19602 the list, and won't have created a forward reference to a
19603 later parameter. */
19604 if (decl_die
!= NULL
)
19606 add_AT_die_ref (die
, attr
, decl_die
);
19612 /* Last chance: try to create a stack operation procedure to evaluate the
19613 value. Do nothing if even that is not possible or permitted. */
19614 if ((forms
& dw_scalar_form_exprloc
) == 0)
19617 list
= loc_list_from_tree (value
, 2, context
);
19618 if (context
&& context
->placeholder_arg
)
19620 placeholder_seen
= context
->placeholder_seen
;
19621 context
->placeholder_seen
= false;
19623 if (list
== NULL
|| single_element_loc_list_p (list
))
19625 /* If this attribute is not a reference nor constant, it is
19626 a DWARF expression rather than location description. For that
19627 loc_list_from_tree (value, 0, &context) is needed. */
19628 dw_loc_list_ref list2
= loc_list_from_tree (value
, 0, context
);
19629 if (list2
&& single_element_loc_list_p (list2
))
19631 if (placeholder_seen
)
19633 struct dwarf_procedure_info dpi
;
19634 dpi
.fndecl
= NULL_TREE
;
19635 dpi
.args_count
= 1;
19636 if (!resolve_args_picking (list2
->expr
, 1, &dpi
))
19639 add_AT_loc (die
, attr
, list2
->expr
);
19644 /* If that failed to give a single element location list, fall back to
19645 outputting this as a reference... still if permitted. */
19647 || (forms
& dw_scalar_form_reference
) == 0
19648 || placeholder_seen
)
19651 if (current_function_decl
== 0)
19652 context_die
= comp_unit_die ();
19654 context_die
= lookup_decl_die (current_function_decl
);
19656 decl_die
= new_die (DW_TAG_variable
, context_die
, value
);
19657 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
19658 add_type_attribute (decl_die
, TREE_TYPE (value
), TYPE_QUAL_CONST
, false,
19660 add_AT_location_description (decl_die
, DW_AT_location
, list
);
19661 add_AT_die_ref (die
, attr
, decl_die
);
19664 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
19668 lower_bound_default (void)
19670 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
19676 case DW_LANG_C_plus_plus
:
19677 case DW_LANG_C_plus_plus_11
:
19678 case DW_LANG_C_plus_plus_14
:
19680 case DW_LANG_ObjC_plus_plus
:
19683 case DW_LANG_Fortran77
:
19684 case DW_LANG_Fortran90
:
19685 case DW_LANG_Fortran95
:
19686 case DW_LANG_Fortran03
:
19687 case DW_LANG_Fortran08
:
19691 case DW_LANG_Python
:
19692 return dwarf_version
>= 4 ? 0 : -1;
19693 case DW_LANG_Ada95
:
19694 case DW_LANG_Ada83
:
19695 case DW_LANG_Cobol74
:
19696 case DW_LANG_Cobol85
:
19697 case DW_LANG_Pascal83
:
19698 case DW_LANG_Modula2
:
19700 return dwarf_version
>= 4 ? 1 : -1;
19706 /* Given a tree node describing an array bound (either lower or upper) output
19707 a representation for that bound. */
19710 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
,
19711 tree bound
, struct loc_descr_context
*context
)
19716 switch (TREE_CODE (bound
))
19718 /* Strip all conversions. */
19720 case VIEW_CONVERT_EXPR
:
19721 bound
= TREE_OPERAND (bound
, 0);
19724 /* All fixed-bounds are represented by INTEGER_CST nodes. Lower bounds
19725 are even omitted when they are the default. */
19727 /* If the value for this bound is the default one, we can even omit the
19729 if (bound_attr
== DW_AT_lower_bound
19730 && tree_fits_shwi_p (bound
)
19731 && (dflt
= lower_bound_default ()) != -1
19732 && tree_to_shwi (bound
) == dflt
)
19738 /* Because of the complex interaction there can be with other GNAT
19739 encodings, GDB isn't ready yet to handle proper DWARF description
19740 for self-referencial subrange bounds: let GNAT encodings do the
19741 magic in such a case. */
19743 && gnat_encodings
!= DWARF_GNAT_ENCODINGS_MINIMAL
19744 && contains_placeholder_p (bound
))
19747 add_scalar_info (subrange_die
, bound_attr
, bound
,
19748 dw_scalar_form_constant
19749 | dw_scalar_form_exprloc
19750 | dw_scalar_form_reference
,
19756 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
19757 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
19758 Note that the block of subscript information for an array type also
19759 includes information about the element type of the given array type.
19761 This function reuses previously set type and bound information if
19765 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
19767 unsigned dimension_number
;
19769 dw_die_ref child
= type_die
->die_child
;
19771 for (dimension_number
= 0;
19772 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
19773 type
= TREE_TYPE (type
), dimension_number
++)
19775 tree domain
= TYPE_DOMAIN (type
);
19777 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
19780 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
19781 and (in GNU C only) variable bounds. Handle all three forms
19784 /* Find and reuse a previously generated DW_TAG_subrange_type if
19787 For multi-dimensional arrays, as we iterate through the
19788 various dimensions in the enclosing for loop above, we also
19789 iterate through the DIE children and pick at each
19790 DW_TAG_subrange_type previously generated (if available).
19791 Each child DW_TAG_subrange_type DIE describes the range of
19792 the current dimension. At this point we should have as many
19793 DW_TAG_subrange_type's as we have dimensions in the
19795 dw_die_ref subrange_die
= NULL
;
19799 child
= child
->die_sib
;
19800 if (child
->die_tag
== DW_TAG_subrange_type
)
19801 subrange_die
= child
;
19802 if (child
== type_die
->die_child
)
19804 /* If we wrapped around, stop looking next time. */
19808 if (child
->die_tag
== DW_TAG_subrange_type
)
19812 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
19816 /* We have an array type with specified bounds. */
19817 lower
= TYPE_MIN_VALUE (domain
);
19818 upper
= TYPE_MAX_VALUE (domain
);
19820 /* Define the index type. */
19821 if (TREE_TYPE (domain
)
19822 && !get_AT (subrange_die
, DW_AT_type
))
19824 /* ??? This is probably an Ada unnamed subrange type. Ignore the
19825 TREE_TYPE field. We can't emit debug info for this
19826 because it is an unnamed integral type. */
19827 if (TREE_CODE (domain
) == INTEGER_TYPE
19828 && TYPE_NAME (domain
) == NULL_TREE
19829 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
19830 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
19833 add_type_attribute (subrange_die
, TREE_TYPE (domain
),
19834 TYPE_UNQUALIFIED
, false, type_die
);
19837 /* ??? If upper is NULL, the array has unspecified length,
19838 but it does have a lower bound. This happens with Fortran
19840 Since the debugger is definitely going to need to know N
19841 to produce useful results, go ahead and output the lower
19842 bound solo, and hope the debugger can cope. */
19844 if (!get_AT (subrange_die
, DW_AT_lower_bound
))
19845 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
, NULL
);
19846 if (upper
&& !get_AT (subrange_die
, DW_AT_upper_bound
))
19847 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
, NULL
);
19850 /* Otherwise we have an array type with an unspecified length. The
19851 DWARF-2 spec does not say how to handle this; let's just leave out the
19856 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
19859 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
19861 dw_die_ref decl_die
;
19862 HOST_WIDE_INT size
;
19863 dw_loc_descr_ref size_expr
= NULL
;
19865 switch (TREE_CODE (tree_node
))
19870 case ENUMERAL_TYPE
:
19873 case QUAL_UNION_TYPE
:
19874 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
19875 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
19877 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
19880 size_expr
= type_byte_size (tree_node
, &size
);
19883 /* For a data member of a struct or union, the DW_AT_byte_size is
19884 generally given as the number of bytes normally allocated for an
19885 object of the *declared* type of the member itself. This is true
19886 even for bit-fields. */
19887 size
= int_size_in_bytes (field_type (tree_node
));
19890 gcc_unreachable ();
19893 /* Support for dynamically-sized objects was introduced by DWARFv3.
19894 At the moment, GDB does not handle variable byte sizes very well,
19896 if ((dwarf_version
>= 3 || !dwarf_strict
)
19897 && gnat_encodings
== DWARF_GNAT_ENCODINGS_MINIMAL
19898 && size_expr
!= NULL
)
19899 add_AT_loc (die
, DW_AT_byte_size
, size_expr
);
19901 /* Note that `size' might be -1 when we get to this point. If it is, that
19902 indicates that the byte size of the entity in question is variable and
19903 that we could not generate a DWARF expression that computes it. */
19905 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
19908 /* For a FIELD_DECL node which represents a bit-field, output an attribute
19909 which specifies the distance in bits from the highest order bit of the
19910 "containing object" for the bit-field to the highest order bit of the
19913 For any given bit-field, the "containing object" is a hypothetical object
19914 (of some integral or enum type) within which the given bit-field lives. The
19915 type of this hypothetical "containing object" is always the same as the
19916 declared type of the individual bit-field itself. The determination of the
19917 exact location of the "containing object" for a bit-field is rather
19918 complicated. It's handled by the `field_byte_offset' function (above).
19920 CTX is required: see the comment for VLR_CONTEXT.
19922 Note that it is the size (in bytes) of the hypothetical "containing object"
19923 which will be given in the DW_AT_byte_size attribute for this bit-field.
19924 (See `byte_size_attribute' above). */
19927 add_bit_offset_attribute (dw_die_ref die
, tree decl
, struct vlr_context
*ctx
)
19929 HOST_WIDE_INT object_offset_in_bytes
;
19930 tree original_type
= DECL_BIT_FIELD_TYPE (decl
);
19931 HOST_WIDE_INT bitpos_int
;
19932 HOST_WIDE_INT highest_order_object_bit_offset
;
19933 HOST_WIDE_INT highest_order_field_bit_offset
;
19934 HOST_WIDE_INT bit_offset
;
19936 field_byte_offset (decl
, ctx
, &object_offset_in_bytes
);
19938 /* Must be a field and a bit field. */
19939 gcc_assert (original_type
&& TREE_CODE (decl
) == FIELD_DECL
);
19941 /* We can't yet handle bit-fields whose offsets are variable, so if we
19942 encounter such things, just return without generating any attribute
19943 whatsoever. Likewise for variable or too large size. */
19944 if (! tree_fits_shwi_p (bit_position (decl
))
19945 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
19948 bitpos_int
= int_bit_position (decl
);
19950 /* Note that the bit offset is always the distance (in bits) from the
19951 highest-order bit of the "containing object" to the highest-order bit of
19952 the bit-field itself. Since the "high-order end" of any object or field
19953 is different on big-endian and little-endian machines, the computation
19954 below must take account of these differences. */
19955 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
19956 highest_order_field_bit_offset
= bitpos_int
;
19958 if (! BYTES_BIG_ENDIAN
)
19960 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
19961 highest_order_object_bit_offset
+=
19962 simple_type_size_in_bits (original_type
);
19966 = (! BYTES_BIG_ENDIAN
19967 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
19968 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
19970 if (bit_offset
< 0)
19971 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
19973 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
19976 /* For a FIELD_DECL node which represents a bit field, output an attribute
19977 which specifies the length in bits of the given field. */
19980 add_bit_size_attribute (dw_die_ref die
, tree decl
)
19982 /* Must be a field and a bit field. */
19983 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
19984 && DECL_BIT_FIELD_TYPE (decl
));
19986 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
19987 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
19990 /* If the compiled language is ANSI C, then add a 'prototyped'
19991 attribute, if arg types are given for the parameters of a function. */
19994 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
19996 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
20003 if (prototype_p (func_type
))
20004 add_AT_flag (die
, DW_AT_prototyped
, 1);
20011 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
20012 by looking in the type declaration, the object declaration equate table or
20013 the block mapping. */
20015 static inline dw_die_ref
20016 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
20018 dw_die_ref origin_die
= NULL
;
20020 if (TREE_CODE (origin
) != FUNCTION_DECL
20021 && TREE_CODE (origin
) != BLOCK
)
20023 /* We may have gotten separated from the block for the inlined
20024 function, if we're in an exception handler or some such; make
20025 sure that the abstract function has been written out.
20027 Doing this for nested functions is wrong, however; functions are
20028 distinct units, and our context might not even be inline. */
20032 fn
= TYPE_STUB_DECL (fn
);
20034 fn
= decl_function_context (fn
);
20036 dwarf2out_abstract_function (fn
);
20039 if (DECL_P (origin
))
20040 origin_die
= lookup_decl_die (origin
);
20041 else if (TYPE_P (origin
))
20042 origin_die
= lookup_type_die (origin
);
20043 else if (TREE_CODE (origin
) == BLOCK
)
20044 origin_die
= BLOCK_DIE (origin
);
20046 /* XXX: Functions that are never lowered don't always have correct block
20047 trees (in the case of java, they simply have no block tree, in some other
20048 languages). For these functions, there is nothing we can really do to
20049 output correct debug info for inlined functions in all cases. Rather
20050 than die, we'll just produce deficient debug info now, in that we will
20051 have variables without a proper abstract origin. In the future, when all
20052 functions are lowered, we should re-add a gcc_assert (origin_die)
20056 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
20060 /* We do not currently support the pure_virtual attribute. */
20063 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
20065 if (DECL_VINDEX (func_decl
))
20067 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
20069 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
20070 add_AT_loc (die
, DW_AT_vtable_elem_location
,
20071 new_loc_descr (DW_OP_constu
,
20072 tree_to_shwi (DECL_VINDEX (func_decl
)),
20075 /* GNU extension: Record what type this method came from originally. */
20076 if (debug_info_level
> DINFO_LEVEL_TERSE
20077 && DECL_CONTEXT (func_decl
))
20078 add_AT_die_ref (die
, DW_AT_containing_type
,
20079 lookup_type_die (DECL_CONTEXT (func_decl
)));
20083 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
20084 given decl. This used to be a vendor extension until after DWARF 4
20085 standardized it. */
20088 add_linkage_attr (dw_die_ref die
, tree decl
)
20090 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
20092 /* Mimic what assemble_name_raw does with a leading '*'. */
20093 if (name
[0] == '*')
20096 if (dwarf_version
>= 4)
20097 add_AT_string (die
, DW_AT_linkage_name
, name
);
20099 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
20102 /* Add source coordinate attributes for the given decl. */
20105 add_src_coords_attributes (dw_die_ref die
, tree decl
)
20107 expanded_location s
;
20109 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
20111 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
20112 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
20113 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
20116 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
20119 add_linkage_name_raw (dw_die_ref die
, tree decl
)
20121 /* Defer until we have an assembler name set. */
20122 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
20124 limbo_die_node
*asm_name
;
20126 asm_name
= ggc_cleared_alloc
<limbo_die_node
> ();
20127 asm_name
->die
= die
;
20128 asm_name
->created_for
= decl
;
20129 asm_name
->next
= deferred_asm_name
;
20130 deferred_asm_name
= asm_name
;
20132 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
20133 add_linkage_attr (die
, decl
);
20136 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl if desired. */
20139 add_linkage_name (dw_die_ref die
, tree decl
)
20141 if (debug_info_level
> DINFO_LEVEL_NONE
20142 && VAR_OR_FUNCTION_DECL_P (decl
)
20143 && TREE_PUBLIC (decl
)
20144 && !(VAR_P (decl
) && DECL_REGISTER (decl
))
20145 && die
->die_tag
!= DW_TAG_member
)
20146 add_linkage_name_raw (die
, decl
);
20149 /* Add a DW_AT_name attribute and source coordinate attribute for the
20150 given decl, but only if it actually has a name. */
20153 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
,
20154 bool no_linkage_name
)
20158 decl_name
= DECL_NAME (decl
);
20159 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
20161 const char *name
= dwarf2_name (decl
, 0);
20163 add_name_attribute (die
, name
);
20164 if (! DECL_ARTIFICIAL (decl
))
20165 add_src_coords_attributes (die
, decl
);
20167 if (!no_linkage_name
)
20168 add_linkage_name (die
, decl
);
20171 #ifdef VMS_DEBUGGING_INFO
20172 /* Get the function's name, as described by its RTL. This may be different
20173 from the DECL_NAME name used in the source file. */
20174 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
20176 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
20177 XEXP (DECL_RTL (decl
), 0), false);
20178 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
20180 #endif /* VMS_DEBUGGING_INFO */
20183 /* Add VALUE as a DW_AT_discr_value attribute to DIE. */
20186 add_discr_value (dw_die_ref die
, dw_discr_value
*value
)
20190 attr
.dw_attr
= DW_AT_discr_value
;
20191 attr
.dw_attr_val
.val_class
= dw_val_class_discr_value
;
20192 attr
.dw_attr_val
.val_entry
= NULL
;
20193 attr
.dw_attr_val
.v
.val_discr_value
.pos
= value
->pos
;
20195 attr
.dw_attr_val
.v
.val_discr_value
.v
.uval
= value
->v
.uval
;
20197 attr
.dw_attr_val
.v
.val_discr_value
.v
.sval
= value
->v
.sval
;
20198 add_dwarf_attr (die
, &attr
);
20201 /* Add DISCR_LIST as a DW_AT_discr_list to DIE. */
20204 add_discr_list (dw_die_ref die
, dw_discr_list_ref discr_list
)
20208 attr
.dw_attr
= DW_AT_discr_list
;
20209 attr
.dw_attr_val
.val_class
= dw_val_class_discr_list
;
20210 attr
.dw_attr_val
.val_entry
= NULL
;
20211 attr
.dw_attr_val
.v
.val_discr_list
= discr_list
;
20212 add_dwarf_attr (die
, &attr
);
20215 static inline dw_discr_list_ref
20216 AT_discr_list (dw_attr_node
*attr
)
20218 return attr
->dw_attr_val
.v
.val_discr_list
;
20221 #ifdef VMS_DEBUGGING_INFO
20222 /* Output the debug main pointer die for VMS */
20225 dwarf2out_vms_debug_main_pointer (void)
20227 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20230 /* Allocate the VMS debug main subprogram die. */
20231 die
= ggc_cleared_alloc
<die_node
> ();
20232 die
->die_tag
= DW_TAG_subprogram
;
20233 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
20234 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
20235 current_function_funcdef_no
);
20236 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
20238 /* Make it the first child of comp_unit_die (). */
20239 die
->die_parent
= comp_unit_die ();
20240 if (comp_unit_die ()->die_child
)
20242 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
20243 comp_unit_die ()->die_child
->die_sib
= die
;
20247 die
->die_sib
= die
;
20248 comp_unit_die ()->die_child
= die
;
20251 #endif /* VMS_DEBUGGING_INFO */
20253 /* Push a new declaration scope. */
20256 push_decl_scope (tree scope
)
20258 vec_safe_push (decl_scope_table
, scope
);
20261 /* Pop a declaration scope. */
20264 pop_decl_scope (void)
20266 decl_scope_table
->pop ();
20269 /* walk_tree helper function for uses_local_type, below. */
20272 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
20275 *walk_subtrees
= 0;
20278 tree name
= TYPE_NAME (*tp
);
20279 if (name
&& DECL_P (name
) && decl_function_context (name
))
20285 /* If TYPE involves a function-local type (including a local typedef to a
20286 non-local type), returns that type; otherwise returns NULL_TREE. */
20289 uses_local_type (tree type
)
20291 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
20295 /* Return the DIE for the scope that immediately contains this type.
20296 Non-named types that do not involve a function-local type get global
20297 scope. Named types nested in namespaces or other types get their
20298 containing scope. All other types (i.e. function-local named types) get
20299 the current active scope. */
20302 scope_die_for (tree t
, dw_die_ref context_die
)
20304 dw_die_ref scope_die
= NULL
;
20305 tree containing_scope
;
20307 /* Non-types always go in the current scope. */
20308 gcc_assert (TYPE_P (t
));
20310 /* Use the scope of the typedef, rather than the scope of the type
20312 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
20313 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
20315 containing_scope
= TYPE_CONTEXT (t
);
20317 /* Use the containing namespace if there is one. */
20318 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
20320 if (context_die
== lookup_decl_die (containing_scope
))
20322 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
20323 context_die
= get_context_die (containing_scope
);
20325 containing_scope
= NULL_TREE
;
20328 /* Ignore function type "scopes" from the C frontend. They mean that
20329 a tagged type is local to a parmlist of a function declarator, but
20330 that isn't useful to DWARF. */
20331 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
20332 containing_scope
= NULL_TREE
;
20334 if (SCOPE_FILE_SCOPE_P (containing_scope
))
20336 /* If T uses a local type keep it local as well, to avoid references
20337 to function-local DIEs from outside the function. */
20338 if (current_function_decl
&& uses_local_type (t
))
20339 scope_die
= context_die
;
20341 scope_die
= comp_unit_die ();
20343 else if (TYPE_P (containing_scope
))
20345 /* For types, we can just look up the appropriate DIE. */
20346 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20347 scope_die
= get_context_die (containing_scope
);
20350 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
20351 if (scope_die
== NULL
)
20352 scope_die
= comp_unit_die ();
20356 scope_die
= context_die
;
20361 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
20364 local_scope_p (dw_die_ref context_die
)
20366 for (; context_die
; context_die
= context_die
->die_parent
)
20367 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
20368 || context_die
->die_tag
== DW_TAG_subprogram
)
20374 /* Returns nonzero if CONTEXT_DIE is a class. */
20377 class_scope_p (dw_die_ref context_die
)
20379 return (context_die
20380 && (context_die
->die_tag
== DW_TAG_structure_type
20381 || context_die
->die_tag
== DW_TAG_class_type
20382 || context_die
->die_tag
== DW_TAG_interface_type
20383 || context_die
->die_tag
== DW_TAG_union_type
));
20386 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
20387 whether or not to treat a DIE in this context as a declaration. */
20390 class_or_namespace_scope_p (dw_die_ref context_die
)
20392 return (class_scope_p (context_die
)
20393 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
20396 /* Many forms of DIEs require a "type description" attribute. This
20397 routine locates the proper "type descriptor" die for the type given
20398 by 'type' plus any additional qualifiers given by 'cv_quals', and
20399 adds a DW_AT_type attribute below the given die. */
20402 add_type_attribute (dw_die_ref object_die
, tree type
, int cv_quals
,
20403 bool reverse
, dw_die_ref context_die
)
20405 enum tree_code code
= TREE_CODE (type
);
20406 dw_die_ref type_die
= NULL
;
20408 /* ??? If this type is an unnamed subrange type of an integral, floating-point
20409 or fixed-point type, use the inner type. This is because we have no
20410 support for unnamed types in base_type_die. This can happen if this is
20411 an Ada subrange type. Correct solution is emit a subrange type die. */
20412 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
20413 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
20414 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
20416 if (code
== ERROR_MARK
20417 /* Handle a special case. For functions whose return type is void, we
20418 generate *no* type attribute. (Note that no object may have type
20419 `void', so this only applies to function return types). */
20420 || code
== VOID_TYPE
)
20423 type_die
= modified_type_die (type
,
20424 cv_quals
| TYPE_QUALS_NO_ADDR_SPACE (type
),
20428 if (type_die
!= NULL
)
20429 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
20432 /* Given an object die, add the calling convention attribute for the
20433 function call type. */
20435 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
20437 enum dwarf_calling_convention value
= DW_CC_normal
;
20439 value
= ((enum dwarf_calling_convention
)
20440 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
20443 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
20445 /* DWARF 2 doesn't provide a way to identify a program's source-level
20446 entry point. DW_AT_calling_convention attributes are only meant
20447 to describe functions' calling conventions. However, lacking a
20448 better way to signal the Fortran main program, we used this for
20449 a long time, following existing custom. Now, DWARF 4 has
20450 DW_AT_main_subprogram, which we add below, but some tools still
20451 rely on the old way, which we thus keep. */
20452 value
= DW_CC_program
;
20454 if (dwarf_version
>= 4 || !dwarf_strict
)
20455 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
20458 /* Only add the attribute if the backend requests it, and
20459 is not DW_CC_normal. */
20460 if (value
&& (value
!= DW_CC_normal
))
20461 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
20464 /* Given a tree pointer to a struct, class, union, or enum type node, return
20465 a pointer to the (string) tag name for the given type, or zero if the type
20466 was declared without a tag. */
20468 static const char *
20469 type_tag (const_tree type
)
20471 const char *name
= 0;
20473 if (TYPE_NAME (type
) != 0)
20477 /* Find the IDENTIFIER_NODE for the type name. */
20478 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
20479 && !TYPE_NAMELESS (type
))
20480 t
= TYPE_NAME (type
);
20482 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
20483 a TYPE_DECL node, regardless of whether or not a `typedef' was
20485 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
20486 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
20488 /* We want to be extra verbose. Don't call dwarf_name if
20489 DECL_NAME isn't set. The default hook for decl_printable_name
20490 doesn't like that, and in this context it's correct to return
20491 0, instead of "<anonymous>" or the like. */
20492 if (DECL_NAME (TYPE_NAME (type
))
20493 && !DECL_NAMELESS (TYPE_NAME (type
)))
20494 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
20497 /* Now get the name as a string, or invent one. */
20498 if (!name
&& t
!= 0)
20499 name
= IDENTIFIER_POINTER (t
);
20502 return (name
== 0 || *name
== '\0') ? 0 : name
;
20505 /* Return the type associated with a data member, make a special check
20506 for bit field types. */
20509 member_declared_type (const_tree member
)
20511 return (DECL_BIT_FIELD_TYPE (member
)
20512 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
20515 /* Get the decl's label, as described by its RTL. This may be different
20516 from the DECL_NAME name used in the source file. */
20519 static const char *
20520 decl_start_label (tree decl
)
20523 const char *fnname
;
20525 x
= DECL_RTL (decl
);
20526 gcc_assert (MEM_P (x
));
20529 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
20531 fnname
= XSTR (x
, 0);
20536 /* For variable-length arrays that have been previously generated, but
20537 may be incomplete due to missing subscript info, fill the subscript
20538 info. Return TRUE if this is one of those cases. */
20540 fill_variable_array_bounds (tree type
)
20542 if (TREE_ASM_WRITTEN (type
)
20543 && TREE_CODE (type
) == ARRAY_TYPE
20544 && variably_modified_type_p (type
, NULL
))
20546 dw_die_ref array_die
= lookup_type_die (type
);
20549 add_subscript_info (array_die
, type
, !is_ada ());
20555 /* These routines generate the internal representation of the DIE's for
20556 the compilation unit. Debugging information is collected by walking
20557 the declaration trees passed in from dwarf2out_decl(). */
20560 gen_array_type_die (tree type
, dw_die_ref context_die
)
20562 dw_die_ref array_die
;
20564 /* GNU compilers represent multidimensional array types as sequences of one
20565 dimensional array types whose element types are themselves array types.
20566 We sometimes squish that down to a single array_type DIE with multiple
20567 subscripts in the Dwarf debugging info. The draft Dwarf specification
20568 say that we are allowed to do this kind of compression in C, because
20569 there is no difference between an array of arrays and a multidimensional
20570 array. We don't do this for Ada to remain as close as possible to the
20571 actual representation, which is especially important against the language
20572 flexibilty wrt arrays of variable size. */
20574 bool collapse_nested_arrays
= !is_ada ();
20576 if (fill_variable_array_bounds (type
))
20579 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
20582 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
20583 DW_TAG_string_type doesn't have DW_AT_type attribute). */
20584 if (TYPE_STRING_FLAG (type
)
20585 && TREE_CODE (type
) == ARRAY_TYPE
20587 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
20589 HOST_WIDE_INT size
;
20591 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
20592 add_name_attribute (array_die
, type_tag (type
));
20593 equate_type_number_to_die (type
, array_die
);
20594 size
= int_size_in_bytes (type
);
20596 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
20597 else if (TYPE_DOMAIN (type
) != NULL_TREE
20598 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
)
20600 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
20601 tree rszdecl
= szdecl
;
20602 HOST_WIDE_INT rsize
= 0;
20604 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
20605 if (!DECL_P (szdecl
))
20607 if (TREE_CODE (szdecl
) == INDIRECT_REF
20608 && DECL_P (TREE_OPERAND (szdecl
, 0)))
20610 rszdecl
= TREE_OPERAND (szdecl
, 0);
20611 rsize
= int_size_in_bytes (TREE_TYPE (rszdecl
));
20620 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2, NULL
);
20623 && current_function_decl
20624 && DECL_CONTEXT (rszdecl
) == current_function_decl
)
20626 dw_die_ref ref
= lookup_decl_die (rszdecl
);
20627 dw_loc_descr_ref l
= NULL
;
20630 l
= new_loc_descr (DW_OP_call4
, 0, 0);
20631 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
20632 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
20633 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
20635 else if (TREE_CODE (rszdecl
) == PARM_DECL
20638 l
= new_loc_descr (DW_OP_call4
, 0, 0);
20639 l
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
20640 l
->dw_loc_oprnd1
.v
.val_decl_ref
= rszdecl
;
20641 string_types
->safe_push (array_die
);
20643 if (l
&& rszdecl
!= szdecl
)
20645 if (rsize
== DWARF2_ADDR_SIZE
)
20646 add_loc_descr (&l
, new_loc_descr (DW_OP_deref
,
20649 add_loc_descr (&l
, new_loc_descr (DW_OP_deref_size
,
20653 loc
= new_loc_list (l
, NULL
, NULL
, NULL
);
20657 add_AT_location_description (array_die
, DW_AT_string_length
,
20659 if (size
!= DWARF2_ADDR_SIZE
)
20660 add_AT_unsigned (array_die
, dwarf_version
>= 5
20661 ? DW_AT_string_length_byte_size
20662 : DW_AT_byte_size
, size
);
20669 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
20670 add_name_attribute (array_die
, type_tag (type
));
20671 equate_type_number_to_die (type
, array_die
);
20673 if (TREE_CODE (type
) == VECTOR_TYPE
)
20674 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
20676 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
20678 && TREE_CODE (type
) == ARRAY_TYPE
20679 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
20680 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
20681 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
20684 /* We default the array ordering. SDB will probably do
20685 the right things even if DW_AT_ordering is not present. It's not even
20686 an issue until we start to get into multidimensional arrays anyway. If
20687 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
20688 then we'll have to put the DW_AT_ordering attribute back in. (But if
20689 and when we find out that we need to put these in, we will only do so
20690 for multidimensional arrays. */
20691 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
20694 if (TREE_CODE (type
) == VECTOR_TYPE
)
20696 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
20697 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
20698 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
, NULL
);
20699 add_bound_info (subrange_die
, DW_AT_upper_bound
,
20700 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1), NULL
);
20703 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
20705 /* Add representation of the type of the elements of this array type and
20706 emit the corresponding DIE if we haven't done it already. */
20707 element_type
= TREE_TYPE (type
);
20708 if (collapse_nested_arrays
)
20709 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
20711 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
20713 element_type
= TREE_TYPE (element_type
);
20716 add_type_attribute (array_die
, element_type
, TYPE_UNQUALIFIED
,
20717 TREE_CODE (type
) == ARRAY_TYPE
20718 && TYPE_REVERSE_STORAGE_ORDER (type
),
20721 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
20722 if (TYPE_ARTIFICIAL (type
))
20723 add_AT_flag (array_die
, DW_AT_artificial
, 1);
20725 if (get_AT (array_die
, DW_AT_name
))
20726 add_pubtype (type
, array_die
);
20729 /* After all arguments are created, adjust any DW_TAG_string_type
20730 DIEs DW_AT_string_length attributes. */
20733 adjust_string_types (void)
20735 dw_die_ref array_die
;
20737 FOR_EACH_VEC_ELT (*string_types
, i
, array_die
)
20739 dw_attr_node
*a
= get_AT (array_die
, DW_AT_string_length
);
20742 dw_loc_descr_ref loc
= AT_loc (a
);
20743 gcc_assert (loc
->dw_loc_opc
== DW_OP_call4
20744 && loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
);
20745 dw_die_ref ref
= lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
20748 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
20749 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
20750 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
20754 remove_AT (array_die
, DW_AT_string_length
);
20755 remove_AT (array_die
, dwarf_version
>= 5
20756 ? DW_AT_string_length_byte_size
20757 : DW_AT_byte_size
);
20762 /* This routine generates DIE for array with hidden descriptor, details
20763 are filled into *info by a langhook. */
20766 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
20767 dw_die_ref context_die
)
20769 const dw_die_ref scope_die
= scope_die_for (type
, context_die
);
20770 const dw_die_ref array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
20771 struct loc_descr_context context
= { type
, info
->base_decl
, NULL
,
20773 enum dwarf_tag subrange_tag
= DW_TAG_subrange_type
;
20776 add_name_attribute (array_die
, type_tag (type
));
20777 equate_type_number_to_die (type
, array_die
);
20779 if (info
->ndimensions
> 1)
20780 switch (info
->ordering
)
20782 case array_descr_ordering_row_major
:
20783 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
20785 case array_descr_ordering_column_major
:
20786 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
20792 if (dwarf_version
>= 3 || !dwarf_strict
)
20794 if (info
->data_location
)
20795 add_scalar_info (array_die
, DW_AT_data_location
, info
->data_location
,
20796 dw_scalar_form_exprloc
, &context
);
20797 if (info
->associated
)
20798 add_scalar_info (array_die
, DW_AT_associated
, info
->associated
,
20799 dw_scalar_form_constant
20800 | dw_scalar_form_exprloc
20801 | dw_scalar_form_reference
, &context
);
20802 if (info
->allocated
)
20803 add_scalar_info (array_die
, DW_AT_allocated
, info
->allocated
,
20804 dw_scalar_form_constant
20805 | dw_scalar_form_exprloc
20806 | dw_scalar_form_reference
, &context
);
20809 const enum dwarf_attribute attr
20810 = (info
->stride_in_bits
) ? DW_AT_bit_stride
: DW_AT_byte_stride
;
20812 = (info
->stride_in_bits
)
20813 ? dw_scalar_form_constant
20814 : (dw_scalar_form_constant
20815 | dw_scalar_form_exprloc
20816 | dw_scalar_form_reference
);
20818 add_scalar_info (array_die
, attr
, info
->stride
, forms
, &context
);
20821 if (dwarf_version
>= 5)
20825 add_scalar_info (array_die
, DW_AT_rank
, info
->rank
,
20826 dw_scalar_form_constant
20827 | dw_scalar_form_exprloc
, &context
);
20828 subrange_tag
= DW_TAG_generic_subrange
;
20829 context
.placeholder_arg
= true;
20833 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
20835 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
20837 dw_die_ref subrange_die
= new_die (subrange_tag
, array_die
, NULL
);
20839 if (info
->dimen
[dim
].bounds_type
)
20840 add_type_attribute (subrange_die
,
20841 info
->dimen
[dim
].bounds_type
, TYPE_UNQUALIFIED
,
20842 false, context_die
);
20843 if (info
->dimen
[dim
].lower_bound
)
20844 add_bound_info (subrange_die
, DW_AT_lower_bound
,
20845 info
->dimen
[dim
].lower_bound
, &context
);
20846 if (info
->dimen
[dim
].upper_bound
)
20847 add_bound_info (subrange_die
, DW_AT_upper_bound
,
20848 info
->dimen
[dim
].upper_bound
, &context
);
20849 if ((dwarf_version
>= 3 || !dwarf_strict
) && info
->dimen
[dim
].stride
)
20850 add_scalar_info (subrange_die
, DW_AT_byte_stride
,
20851 info
->dimen
[dim
].stride
,
20852 dw_scalar_form_constant
20853 | dw_scalar_form_exprloc
20854 | dw_scalar_form_reference
,
20858 gen_type_die (info
->element_type
, context_die
);
20859 add_type_attribute (array_die
, info
->element_type
, TYPE_UNQUALIFIED
,
20860 TREE_CODE (type
) == ARRAY_TYPE
20861 && TYPE_REVERSE_STORAGE_ORDER (type
),
20864 if (get_AT (array_die
, DW_AT_name
))
20865 add_pubtype (type
, array_die
);
20870 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
20872 tree origin
= decl_ultimate_origin (decl
);
20873 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
20875 if (origin
!= NULL
)
20876 add_abstract_origin_attribute (decl_die
, origin
);
20879 add_name_and_src_coords_attributes (decl_die
, decl
);
20880 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
20881 TYPE_UNQUALIFIED
, false, context_die
);
20884 if (DECL_ABSTRACT_P (decl
))
20885 equate_decl_number_to_die (decl
, decl_die
);
20887 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
20891 /* Walk through the list of incomplete types again, trying once more to
20892 emit full debugging info for them. */
20895 retry_incomplete_types (void)
20900 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
20901 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
20902 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
20903 vec_safe_truncate (incomplete_types
, 0);
20906 /* Determine what tag to use for a record type. */
20908 static enum dwarf_tag
20909 record_type_tag (tree type
)
20911 if (! lang_hooks
.types
.classify_record
)
20912 return DW_TAG_structure_type
;
20914 switch (lang_hooks
.types
.classify_record (type
))
20916 case RECORD_IS_STRUCT
:
20917 return DW_TAG_structure_type
;
20919 case RECORD_IS_CLASS
:
20920 return DW_TAG_class_type
;
20922 case RECORD_IS_INTERFACE
:
20923 if (dwarf_version
>= 3 || !dwarf_strict
)
20924 return DW_TAG_interface_type
;
20925 return DW_TAG_structure_type
;
20928 gcc_unreachable ();
20932 /* Generate a DIE to represent an enumeration type. Note that these DIEs
20933 include all of the information about the enumeration values also. Each
20934 enumerated type name/value is listed as a child of the enumerated type
20938 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
20940 dw_die_ref type_die
= lookup_type_die (type
);
20942 if (type_die
== NULL
)
20944 type_die
= new_die (DW_TAG_enumeration_type
,
20945 scope_die_for (type
, context_die
), type
);
20946 equate_type_number_to_die (type
, type_die
);
20947 add_name_attribute (type_die
, type_tag (type
));
20948 if (dwarf_version
>= 4 || !dwarf_strict
)
20950 if (ENUM_IS_SCOPED (type
))
20951 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
20952 if (ENUM_IS_OPAQUE (type
))
20953 add_AT_flag (type_die
, DW_AT_declaration
, 1);
20956 add_AT_unsigned (type_die
, DW_AT_encoding
,
20957 TYPE_UNSIGNED (type
)
20961 else if (! TYPE_SIZE (type
))
20964 remove_AT (type_die
, DW_AT_declaration
);
20966 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
20967 given enum type is incomplete, do not generate the DW_AT_byte_size
20968 attribute or the DW_AT_element_list attribute. */
20969 if (TYPE_SIZE (type
))
20973 TREE_ASM_WRITTEN (type
) = 1;
20974 add_byte_size_attribute (type_die
, type
);
20975 if (dwarf_version
>= 3 || !dwarf_strict
)
20977 tree underlying
= lang_hooks
.types
.enum_underlying_base_type (type
);
20978 add_type_attribute (type_die
, underlying
, TYPE_UNQUALIFIED
, false,
20981 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
20983 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
20984 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
20987 /* If the first reference to this type was as the return type of an
20988 inline function, then it may not have a parent. Fix this now. */
20989 if (type_die
->die_parent
== NULL
)
20990 add_child_die (scope_die_for (type
, context_die
), type_die
);
20992 for (link
= TYPE_VALUES (type
);
20993 link
!= NULL
; link
= TREE_CHAIN (link
))
20995 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
20996 tree value
= TREE_VALUE (link
);
20998 add_name_attribute (enum_die
,
20999 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
21001 if (TREE_CODE (value
) == CONST_DECL
)
21002 value
= DECL_INITIAL (value
);
21004 if (simple_type_size_in_bits (TREE_TYPE (value
))
21005 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
21007 /* For constant forms created by add_AT_unsigned DWARF
21008 consumers (GDB, elfutils, etc.) always zero extend
21009 the value. Only when the actual value is negative
21010 do we need to use add_AT_int to generate a constant
21011 form that can represent negative values. */
21012 HOST_WIDE_INT val
= TREE_INT_CST_LOW (value
);
21013 if (TYPE_UNSIGNED (TREE_TYPE (value
)) || val
>= 0)
21014 add_AT_unsigned (enum_die
, DW_AT_const_value
,
21015 (unsigned HOST_WIDE_INT
) val
);
21017 add_AT_int (enum_die
, DW_AT_const_value
, val
);
21020 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
21021 that here. TODO: This should be re-worked to use correct
21022 signed/unsigned double tags for all cases. */
21023 add_AT_wide (enum_die
, DW_AT_const_value
, value
);
21026 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
21027 if (TYPE_ARTIFICIAL (type
))
21028 add_AT_flag (type_die
, DW_AT_artificial
, 1);
21031 add_AT_flag (type_die
, DW_AT_declaration
, 1);
21033 add_pubtype (type
, type_die
);
21038 /* Generate a DIE to represent either a real live formal parameter decl or to
21039 represent just the type of some formal parameter position in some function
21042 Note that this routine is a bit unusual because its argument may be a
21043 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
21044 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
21045 node. If it's the former then this function is being called to output a
21046 DIE to represent a formal parameter object (or some inlining thereof). If
21047 it's the latter, then this function is only being called to output a
21048 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
21049 argument type of some subprogram type.
21050 If EMIT_NAME_P is true, name and source coordinate attributes
21054 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
21055 dw_die_ref context_die
)
21057 tree node_or_origin
= node
? node
: origin
;
21058 tree ultimate_origin
;
21059 dw_die_ref parm_die
= NULL
;
21061 if (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)) == tcc_declaration
)
21063 parm_die
= lookup_decl_die (node
);
21065 /* If the contexts differ, we may not be talking about the same
21067 if (parm_die
&& parm_die
->die_parent
!= context_die
)
21069 if (!DECL_ABSTRACT_P (node
))
21071 /* This can happen when creating an inlined instance, in
21072 which case we need to create a new DIE that will get
21073 annotated with DW_AT_abstract_origin. */
21078 /* FIXME: Reuse DIE even with a differing context.
21080 This can happen when calling
21081 dwarf2out_abstract_function to build debug info for
21082 the abstract instance of a function for which we have
21083 already generated a DIE in
21084 dwarf2out_early_global_decl.
21086 Once we remove dwarf2out_abstract_function, we should
21087 have a call to gcc_unreachable here. */
21091 if (parm_die
&& parm_die
->die_parent
== NULL
)
21093 /* Check that parm_die already has the right attributes that
21094 we would have added below. If any attributes are
21095 missing, fall through to add them. */
21096 if (! DECL_ABSTRACT_P (node_or_origin
)
21097 && !get_AT (parm_die
, DW_AT_location
)
21098 && !get_AT (parm_die
, DW_AT_const_value
))
21099 /* We are missing location info, and are about to add it. */
21103 add_child_die (context_die
, parm_die
);
21109 /* If we have a previously generated DIE, use it, unless this is an
21110 concrete instance (origin != NULL), in which case we need a new
21111 DIE with a corresponding DW_AT_abstract_origin. */
21113 if (parm_die
&& origin
== NULL
)
21114 reusing_die
= true;
21117 parm_die
= new_die (DW_TAG_formal_parameter
, context_die
, node
);
21118 reusing_die
= false;
21121 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
21123 case tcc_declaration
:
21124 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
21125 if (node
|| ultimate_origin
)
21126 origin
= ultimate_origin
;
21131 if (origin
!= NULL
)
21132 add_abstract_origin_attribute (parm_die
, origin
);
21133 else if (emit_name_p
)
21134 add_name_and_src_coords_attributes (parm_die
, node
);
21136 || (! DECL_ABSTRACT_P (node_or_origin
)
21137 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
21138 decl_function_context
21139 (node_or_origin
))))
21141 tree type
= TREE_TYPE (node_or_origin
);
21142 if (decl_by_reference_p (node_or_origin
))
21143 add_type_attribute (parm_die
, TREE_TYPE (type
),
21145 false, context_die
);
21147 add_type_attribute (parm_die
, type
,
21148 decl_quals (node_or_origin
),
21149 false, context_die
);
21151 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
21152 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
21154 if (node
&& node
!= origin
)
21155 equate_decl_number_to_die (node
, parm_die
);
21156 if (! DECL_ABSTRACT_P (node_or_origin
))
21157 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
21163 /* We were called with some kind of a ..._TYPE node. */
21164 add_type_attribute (parm_die
, node_or_origin
, TYPE_UNQUALIFIED
, false,
21169 gcc_unreachable ();
21175 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
21176 children DW_TAG_formal_parameter DIEs representing the arguments of the
21179 PARM_PACK must be a function parameter pack.
21180 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
21181 must point to the subsequent arguments of the function PACK_ARG belongs to.
21182 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
21183 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
21184 following the last one for which a DIE was generated. */
21187 gen_formal_parameter_pack_die (tree parm_pack
,
21189 dw_die_ref subr_die
,
21193 dw_die_ref parm_pack_die
;
21195 gcc_assert (parm_pack
21196 && lang_hooks
.function_parameter_pack_p (parm_pack
)
21199 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
21200 add_src_coords_attributes (parm_pack_die
, parm_pack
);
21202 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
21204 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
21207 gen_formal_parameter_die (arg
, NULL
,
21208 false /* Don't emit name attribute. */,
21213 return parm_pack_die
;
21216 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
21217 at the end of an (ANSI prototyped) formal parameters list. */
21220 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
21222 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
21225 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
21226 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
21227 parameters as specified in some function type specification (except for
21228 those which appear as part of a function *definition*). */
21231 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
21234 tree formal_type
= NULL
;
21235 tree first_parm_type
;
21238 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
21240 arg
= DECL_ARGUMENTS (function_or_method_type
);
21241 function_or_method_type
= TREE_TYPE (function_or_method_type
);
21246 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
21248 /* Make our first pass over the list of formal parameter types and output a
21249 DW_TAG_formal_parameter DIE for each one. */
21250 for (link
= first_parm_type
; link
; )
21252 dw_die_ref parm_die
;
21254 formal_type
= TREE_VALUE (link
);
21255 if (formal_type
== void_type_node
)
21258 /* Output a (nameless) DIE to represent the formal parameter itself. */
21259 if (!POINTER_BOUNDS_TYPE_P (formal_type
))
21261 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
21262 true /* Emit name attribute. */,
21264 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
21265 && link
== first_parm_type
)
21267 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
21268 if (dwarf_version
>= 3 || !dwarf_strict
)
21269 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
21271 else if (arg
&& DECL_ARTIFICIAL (arg
))
21272 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
21275 link
= TREE_CHAIN (link
);
21277 arg
= DECL_CHAIN (arg
);
21280 /* If this function type has an ellipsis, add a
21281 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
21282 if (formal_type
!= void_type_node
)
21283 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
21285 /* Make our second (and final) pass over the list of formal parameter types
21286 and output DIEs to represent those types (as necessary). */
21287 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
21288 link
&& TREE_VALUE (link
);
21289 link
= TREE_CHAIN (link
))
21290 gen_type_die (TREE_VALUE (link
), context_die
);
21293 /* We want to generate the DIE for TYPE so that we can generate the
21294 die for MEMBER, which has been defined; we will need to refer back
21295 to the member declaration nested within TYPE. If we're trying to
21296 generate minimal debug info for TYPE, processing TYPE won't do the
21297 trick; we need to attach the member declaration by hand. */
21300 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
21302 gen_type_die (type
, context_die
);
21304 /* If we're trying to avoid duplicate debug info, we may not have
21305 emitted the member decl for this function. Emit it now. */
21306 if (TYPE_STUB_DECL (type
)
21307 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
21308 && ! lookup_decl_die (member
))
21310 dw_die_ref type_die
;
21311 gcc_assert (!decl_ultimate_origin (member
));
21313 push_decl_scope (type
);
21314 type_die
= lookup_type_die_strip_naming_typedef (type
);
21315 if (TREE_CODE (member
) == FUNCTION_DECL
)
21316 gen_subprogram_die (member
, type_die
);
21317 else if (TREE_CODE (member
) == FIELD_DECL
)
21319 /* Ignore the nameless fields that are used to skip bits but handle
21320 C++ anonymous unions and structs. */
21321 if (DECL_NAME (member
) != NULL_TREE
21322 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
21323 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
21325 struct vlr_context vlr_ctx
= {
21326 DECL_CONTEXT (member
), /* struct_type */
21327 NULL_TREE
/* variant_part_offset */
21329 gen_type_die (member_declared_type (member
), type_die
);
21330 gen_field_die (member
, &vlr_ctx
, type_die
);
21334 gen_variable_die (member
, NULL_TREE
, type_die
);
21340 /* Forward declare these functions, because they are mutually recursive
21341 with their set_block_* pairing functions. */
21342 static void set_decl_origin_self (tree
);
21343 static void set_decl_abstract_flags (tree
, vec
<tree
> &);
21345 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
21346 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
21347 that it points to the node itself, thus indicating that the node is its
21348 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
21349 the given node is NULL, recursively descend the decl/block tree which
21350 it is the root of, and for each other ..._DECL or BLOCK node contained
21351 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
21352 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
21353 values to point to themselves. */
21356 set_block_origin_self (tree stmt
)
21358 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
21360 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
21365 for (local_decl
= BLOCK_VARS (stmt
);
21366 local_decl
!= NULL_TREE
;
21367 local_decl
= DECL_CHAIN (local_decl
))
21368 /* Do not recurse on nested functions since the inlining status
21369 of parent and child can be different as per the DWARF spec. */
21370 if (TREE_CODE (local_decl
) != FUNCTION_DECL
21371 && !DECL_EXTERNAL (local_decl
))
21372 set_decl_origin_self (local_decl
);
21378 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
21379 subblock
!= NULL_TREE
;
21380 subblock
= BLOCK_CHAIN (subblock
))
21381 set_block_origin_self (subblock
); /* Recurse. */
21386 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
21387 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
21388 node to so that it points to the node itself, thus indicating that the
21389 node represents its own (abstract) origin. Additionally, if the
21390 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
21391 the decl/block tree of which the given node is the root of, and for
21392 each other ..._DECL or BLOCK node contained therein whose
21393 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
21394 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
21395 point to themselves. */
21398 set_decl_origin_self (tree decl
)
21400 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
21402 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
21403 if (TREE_CODE (decl
) == FUNCTION_DECL
)
21407 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
21408 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
21409 if (DECL_INITIAL (decl
) != NULL_TREE
21410 && DECL_INITIAL (decl
) != error_mark_node
)
21411 set_block_origin_self (DECL_INITIAL (decl
));
21416 /* Given a pointer to some BLOCK node, set the BLOCK_ABSTRACT flag to 1
21417 and if it wasn't 1 before, push it to abstract_vec vector.
21418 For all local decls and all local sub-blocks (recursively) do it
21422 set_block_abstract_flags (tree stmt
, vec
<tree
> &abstract_vec
)
21428 if (!BLOCK_ABSTRACT (stmt
))
21430 abstract_vec
.safe_push (stmt
);
21431 BLOCK_ABSTRACT (stmt
) = 1;
21434 for (local_decl
= BLOCK_VARS (stmt
);
21435 local_decl
!= NULL_TREE
;
21436 local_decl
= DECL_CHAIN (local_decl
))
21437 if (! DECL_EXTERNAL (local_decl
))
21438 set_decl_abstract_flags (local_decl
, abstract_vec
);
21440 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
21442 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
21443 if ((VAR_P (local_decl
) && !TREE_STATIC (local_decl
))
21444 || TREE_CODE (local_decl
) == PARM_DECL
)
21445 set_decl_abstract_flags (local_decl
, abstract_vec
);
21448 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
21449 subblock
!= NULL_TREE
;
21450 subblock
= BLOCK_CHAIN (subblock
))
21451 set_block_abstract_flags (subblock
, abstract_vec
);
21454 /* Given a pointer to some ..._DECL node, set DECL_ABSTRACT_P flag on it
21455 to 1 and if it wasn't 1 before, push to abstract_vec vector.
21456 In the case where the decl is a FUNCTION_DECL also set the abstract
21457 flags for all of the parameters, local vars, local
21458 blocks and sub-blocks (recursively). */
21461 set_decl_abstract_flags (tree decl
, vec
<tree
> &abstract_vec
)
21463 if (!DECL_ABSTRACT_P (decl
))
21465 abstract_vec
.safe_push (decl
);
21466 DECL_ABSTRACT_P (decl
) = 1;
21469 if (TREE_CODE (decl
) == FUNCTION_DECL
)
21473 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
21474 if (!DECL_ABSTRACT_P (arg
))
21476 abstract_vec
.safe_push (arg
);
21477 DECL_ABSTRACT_P (arg
) = 1;
21479 if (DECL_INITIAL (decl
) != NULL_TREE
21480 && DECL_INITIAL (decl
) != error_mark_node
)
21481 set_block_abstract_flags (DECL_INITIAL (decl
), abstract_vec
);
21485 /* Generate the DWARF2 info for the "abstract" instance of a function which we
21486 may later generate inlined and/or out-of-line instances of.
21488 FIXME: In the early-dwarf world, this function, and most of the
21489 DECL_ABSTRACT code should be obsoleted. The early DIE _is_
21490 the abstract instance. All we would need to do is annotate
21491 the early DIE with the appropriate DW_AT_inline in late
21492 dwarf (perhaps in gen_inlined_subroutine_die).
21494 However, we can't do this yet, because LTO streaming of DIEs
21495 has not been implemented yet. */
21498 dwarf2out_abstract_function (tree decl
)
21500 dw_die_ref old_die
;
21503 hash_table
<decl_loc_hasher
> *old_decl_loc_table
;
21504 hash_table
<dw_loc_list_hasher
> *old_cached_dw_loc_list_table
;
21505 int old_call_site_count
, old_tail_call_site_count
;
21506 struct call_arg_loc_node
*old_call_arg_locations
;
21508 /* Make sure we have the actual abstract inline, not a clone. */
21509 decl
= DECL_ORIGIN (decl
);
21511 old_die
= lookup_decl_die (decl
);
21512 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
21513 /* We've already generated the abstract instance. */
21516 /* We can be called while recursively when seeing block defining inlined subroutine
21517 DIE. Be sure to not clobber the outer location table nor use it or we would
21518 get locations in abstract instantces. */
21519 old_decl_loc_table
= decl_loc_table
;
21520 decl_loc_table
= NULL
;
21521 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
21522 cached_dw_loc_list_table
= NULL
;
21523 old_call_arg_locations
= call_arg_locations
;
21524 call_arg_locations
= NULL
;
21525 old_call_site_count
= call_site_count
;
21526 call_site_count
= -1;
21527 old_tail_call_site_count
= tail_call_site_count
;
21528 tail_call_site_count
= -1;
21530 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
21531 we don't get confused by DECL_ABSTRACT_P. */
21532 if (debug_info_level
> DINFO_LEVEL_TERSE
)
21534 context
= decl_class_context (decl
);
21536 gen_type_die_for_member
21537 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
21540 /* Pretend we've just finished compiling this function. */
21541 save_fn
= current_function_decl
;
21542 current_function_decl
= decl
;
21544 auto_vec
<tree
, 64> abstract_vec
;
21545 set_decl_abstract_flags (decl
, abstract_vec
);
21546 dwarf2out_decl (decl
);
21549 FOR_EACH_VEC_ELT (abstract_vec
, i
, t
)
21550 if (TREE_CODE (t
) == BLOCK
)
21551 BLOCK_ABSTRACT (t
) = 0;
21553 DECL_ABSTRACT_P (t
) = 0;
21555 current_function_decl
= save_fn
;
21556 decl_loc_table
= old_decl_loc_table
;
21557 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
21558 call_arg_locations
= old_call_arg_locations
;
21559 call_site_count
= old_call_site_count
;
21560 tail_call_site_count
= old_tail_call_site_count
;
21563 /* Helper function of premark_used_types() which gets called through
21566 Marks the DIE of a given type in *SLOT as perennial, so it never gets
21567 marked as unused by prune_unused_types. */
21570 premark_used_types_helper (tree
const &type
, void *)
21574 die
= lookup_type_die (type
);
21576 die
->die_perennial_p
= 1;
21580 /* Helper function of premark_types_used_by_global_vars which gets called
21581 through htab_traverse.
21583 Marks the DIE of a given type in *SLOT as perennial, so it never gets
21584 marked as unused by prune_unused_types. The DIE of the type is marked
21585 only if the global variable using the type will actually be emitted. */
21588 premark_types_used_by_global_vars_helper (types_used_by_vars_entry
**slot
,
21591 struct types_used_by_vars_entry
*entry
;
21594 entry
= (struct types_used_by_vars_entry
*) *slot
;
21595 gcc_assert (entry
->type
!= NULL
21596 && entry
->var_decl
!= NULL
);
21597 die
= lookup_type_die (entry
->type
);
21600 /* Ask cgraph if the global variable really is to be emitted.
21601 If yes, then we'll keep the DIE of ENTRY->TYPE. */
21602 varpool_node
*node
= varpool_node::get (entry
->var_decl
);
21603 if (node
&& node
->definition
)
21605 die
->die_perennial_p
= 1;
21606 /* Keep the parent DIEs as well. */
21607 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
21608 die
->die_perennial_p
= 1;
21614 /* Mark all members of used_types_hash as perennial. */
21617 premark_used_types (struct function
*fun
)
21619 if (fun
&& fun
->used_types_hash
)
21620 fun
->used_types_hash
->traverse
<void *, premark_used_types_helper
> (NULL
);
21623 /* Mark all members of types_used_by_vars_entry as perennial. */
21626 premark_types_used_by_global_vars (void)
21628 if (types_used_by_vars_hash
)
21629 types_used_by_vars_hash
21630 ->traverse
<void *, premark_types_used_by_global_vars_helper
> (NULL
);
21633 /* Generate a DW_TAG_call_site DIE in function DECL under SUBR_DIE
21634 for CA_LOC call arg loc node. */
21637 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
21638 struct call_arg_loc_node
*ca_loc
)
21640 dw_die_ref stmt_die
= NULL
, die
;
21641 tree block
= ca_loc
->block
;
21644 && block
!= DECL_INITIAL (decl
)
21645 && TREE_CODE (block
) == BLOCK
)
21647 stmt_die
= BLOCK_DIE (block
);
21650 block
= BLOCK_SUPERCONTEXT (block
);
21652 if (stmt_die
== NULL
)
21653 stmt_die
= subr_die
;
21654 die
= new_die (dwarf_TAG (DW_TAG_call_site
), stmt_die
, NULL_TREE
);
21655 add_AT_lbl_id (die
, dwarf_AT (DW_AT_call_return_pc
), ca_loc
->label
);
21656 if (ca_loc
->tail_call_p
)
21657 add_AT_flag (die
, dwarf_AT (DW_AT_call_tail_call
), 1);
21658 if (ca_loc
->symbol_ref
)
21660 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
21662 add_AT_die_ref (die
, dwarf_AT (DW_AT_call_origin
), tdie
);
21664 add_AT_addr (die
, dwarf_AT (DW_AT_call_origin
), ca_loc
->symbol_ref
,
21670 /* Generate a DIE to represent a declared function (either file-scope or
21674 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
21676 tree origin
= decl_ultimate_origin (decl
);
21677 dw_die_ref subr_die
;
21678 dw_die_ref old_die
= lookup_decl_die (decl
);
21680 /* This function gets called multiple times for different stages of
21681 the debug process. For example, for func() in this code:
21685 void func() { ... }
21688 ...we get called 4 times. Twice in early debug and twice in
21694 1. Once while generating func() within the namespace. This is
21695 the declaration. The declaration bit below is set, as the
21696 context is the namespace.
21698 A new DIE will be generated with DW_AT_declaration set.
21700 2. Once for func() itself. This is the specification. The
21701 declaration bit below is clear as the context is the CU.
21703 We will use the cached DIE from (1) to create a new DIE with
21704 DW_AT_specification pointing to the declaration in (1).
21706 Late debug via rest_of_handle_final()
21707 -------------------------------------
21709 3. Once generating func() within the namespace. This is also the
21710 declaration, as in (1), but this time we will early exit below
21711 as we have a cached DIE and a declaration needs no additional
21712 annotations (no locations), as the source declaration line
21715 4. Once for func() itself. As in (2), this is the specification,
21716 but this time we will re-use the cached DIE, and just annotate
21717 it with the location information that should now be available.
21719 For something without namespaces, but with abstract instances, we
21720 are also called a multiple times:
21725 Base (); // constructor declaration (1)
21728 Base::Base () { } // constructor specification (2)
21733 1. Once for the Base() constructor by virtue of it being a
21734 member of the Base class. This is done via
21735 rest_of_type_compilation.
21737 This is a declaration, so a new DIE will be created with
21740 2. Once for the Base() constructor definition, but this time
21741 while generating the abstract instance of the base
21742 constructor (__base_ctor) which is being generated via early
21743 debug of reachable functions.
21745 Even though we have a cached version of the declaration (1),
21746 we will create a DW_AT_specification of the declaration DIE
21749 3. Once for the __base_ctor itself, but this time, we generate
21750 an DW_AT_abstract_origin version of the DW_AT_specification in
21753 Late debug via rest_of_handle_final
21754 -----------------------------------
21756 4. One final time for the __base_ctor (which will have a cached
21757 DIE with DW_AT_abstract_origin created in (3). This time,
21758 we will just annotate the location information now
21761 int declaration
= (current_function_decl
!= decl
21762 || class_or_namespace_scope_p (context_die
));
21764 /* Now that the C++ front end lazily declares artificial member fns, we
21765 might need to retrofit the declaration into its class. */
21766 if (!declaration
&& !origin
&& !old_die
21767 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
21768 && !class_or_namespace_scope_p (context_die
)
21769 && debug_info_level
> DINFO_LEVEL_TERSE
)
21770 old_die
= force_decl_die (decl
);
21772 /* An inlined instance, tag a new DIE with DW_AT_abstract_origin. */
21773 if (origin
!= NULL
)
21775 gcc_assert (!declaration
|| local_scope_p (context_die
));
21777 /* Fixup die_parent for the abstract instance of a nested
21778 inline function. */
21779 if (old_die
&& old_die
->die_parent
== NULL
)
21780 add_child_die (context_die
, old_die
);
21782 if (old_die
&& get_AT_ref (old_die
, DW_AT_abstract_origin
))
21784 /* If we have a DW_AT_abstract_origin we have a working
21786 subr_die
= old_die
;
21790 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
21791 add_abstract_origin_attribute (subr_die
, origin
);
21792 /* This is where the actual code for a cloned function is.
21793 Let's emit linkage name attribute for it. This helps
21794 debuggers to e.g, set breakpoints into
21795 constructors/destructors when the user asks "break
21797 add_linkage_name (subr_die
, decl
);
21800 /* A cached copy, possibly from early dwarf generation. Reuse as
21801 much as possible. */
21804 /* A declaration that has been previously dumped needs no
21805 additional information. */
21809 if (!get_AT_flag (old_die
, DW_AT_declaration
)
21810 /* We can have a normal definition following an inline one in the
21811 case of redefinition of GNU C extern inlines.
21812 It seems reasonable to use AT_specification in this case. */
21813 && !get_AT (old_die
, DW_AT_inline
))
21815 /* Detect and ignore this case, where we are trying to output
21816 something we have already output. */
21817 if (get_AT (old_die
, DW_AT_low_pc
)
21818 || get_AT (old_die
, DW_AT_ranges
))
21821 /* If we have no location information, this must be a
21822 partially generated DIE from early dwarf generation.
21823 Fall through and generate it. */
21826 /* If the definition comes from the same place as the declaration,
21827 maybe use the old DIE. We always want the DIE for this function
21828 that has the *_pc attributes to be under comp_unit_die so the
21829 debugger can find it. We also need to do this for abstract
21830 instances of inlines, since the spec requires the out-of-line copy
21831 to have the same parent. For local class methods, this doesn't
21832 apply; we just use the old DIE. */
21833 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
21834 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
21835 if ((is_cu_die (old_die
->die_parent
)
21836 /* This condition fixes the inconsistency/ICE with the
21837 following Fortran test (or some derivative thereof) while
21838 building libgfortran:
21842 logical function funky (FLAG)
21847 || (old_die
->die_parent
21848 && old_die
->die_parent
->die_tag
== DW_TAG_module
)
21849 || context_die
== NULL
)
21850 && (DECL_ARTIFICIAL (decl
)
21851 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
21852 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
21853 == (unsigned) s
.line
))))
21855 subr_die
= old_die
;
21857 /* Clear out the declaration attribute, but leave the
21858 parameters so they can be augmented with location
21859 information later. Unless this was a declaration, in
21860 which case, wipe out the nameless parameters and recreate
21861 them further down. */
21862 if (remove_AT (subr_die
, DW_AT_declaration
))
21865 remove_AT (subr_die
, DW_AT_object_pointer
);
21866 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
21869 /* Make a specification pointing to the previously built
21873 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
21874 add_AT_specification (subr_die
, old_die
);
21875 add_pubname (decl
, subr_die
);
21876 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
21877 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
21878 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
21879 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
21881 /* If the prototype had an 'auto' or 'decltype(auto)' return type,
21882 emit the real type on the definition die. */
21883 if (is_cxx() && debug_info_level
> DINFO_LEVEL_TERSE
)
21885 dw_die_ref die
= get_AT_ref (old_die
, DW_AT_type
);
21886 if (die
== auto_die
|| die
== decltype_auto_die
)
21887 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
21888 TYPE_UNQUALIFIED
, false, context_die
);
21891 /* When we process the method declaration, we haven't seen
21892 the out-of-class defaulted definition yet, so we have to
21894 if ((dwarf_version
>= 5 || ! dwarf_strict
)
21895 && !get_AT (subr_die
, DW_AT_defaulted
))
21898 = lang_hooks
.decls
.decl_dwarf_attribute (decl
,
21900 if (defaulted
!= -1)
21902 /* Other values must have been handled before. */
21903 gcc_assert (defaulted
== DW_DEFAULTED_out_of_class
);
21904 add_AT_unsigned (subr_die
, DW_AT_defaulted
, defaulted
);
21909 /* Create a fresh DIE for anything else. */
21912 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
21914 if (TREE_PUBLIC (decl
))
21915 add_AT_flag (subr_die
, DW_AT_external
, 1);
21917 add_name_and_src_coords_attributes (subr_die
, decl
);
21918 add_pubname (decl
, subr_die
);
21919 if (debug_info_level
> DINFO_LEVEL_TERSE
)
21921 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
21922 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
21923 TYPE_UNQUALIFIED
, false, context_die
);
21926 add_pure_or_virtual_attribute (subr_die
, decl
);
21927 if (DECL_ARTIFICIAL (decl
))
21928 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
21930 if (TREE_THIS_VOLATILE (decl
) && (dwarf_version
>= 5 || !dwarf_strict
))
21931 add_AT_flag (subr_die
, DW_AT_noreturn
, 1);
21933 add_accessibility_attribute (subr_die
, decl
);
21936 /* Unless we have an existing non-declaration DIE, equate the new
21938 if (!old_die
|| is_declaration_die (old_die
))
21939 equate_decl_number_to_die (decl
, subr_die
);
21943 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
21945 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
21947 /* If this is an explicit function declaration then generate
21948 a DW_AT_explicit attribute. */
21949 if ((dwarf_version
>= 3 || !dwarf_strict
)
21950 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
21951 DW_AT_explicit
) == 1)
21952 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
21954 /* If this is a C++11 deleted special function member then generate
21955 a DW_AT_deleted attribute. */
21956 if ((dwarf_version
>= 5 || !dwarf_strict
)
21957 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
21958 DW_AT_deleted
) == 1)
21959 add_AT_flag (subr_die
, DW_AT_deleted
, 1);
21961 /* If this is a C++11 defaulted special function member then
21962 generate a DW_AT_defaulted attribute. */
21963 if (dwarf_version
>= 5 || !dwarf_strict
)
21966 = lang_hooks
.decls
.decl_dwarf_attribute (decl
,
21968 if (defaulted
!= -1)
21969 add_AT_unsigned (subr_die
, DW_AT_defaulted
, defaulted
);
21972 /* If this is a C++11 non-static member function with & ref-qualifier
21973 then generate a DW_AT_reference attribute. */
21974 if ((dwarf_version
>= 5 || !dwarf_strict
)
21975 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
21976 DW_AT_reference
) == 1)
21977 add_AT_flag (subr_die
, DW_AT_reference
, 1);
21979 /* If this is a C++11 non-static member function with &&
21980 ref-qualifier then generate a DW_AT_reference attribute. */
21981 if ((dwarf_version
>= 5 || !dwarf_strict
)
21982 && lang_hooks
.decls
.decl_dwarf_attribute (decl
,
21983 DW_AT_rvalue_reference
)
21985 add_AT_flag (subr_die
, DW_AT_rvalue_reference
, 1);
21988 /* Tag abstract instances with DW_AT_inline. */
21989 else if (DECL_ABSTRACT_P (decl
))
21991 if (DECL_DECLARED_INLINE_P (decl
))
21993 if (cgraph_function_possibly_inlined_p (decl
))
21994 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
21996 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
22000 if (cgraph_function_possibly_inlined_p (decl
))
22001 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
22003 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
22006 if (DECL_DECLARED_INLINE_P (decl
)
22007 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
22008 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
22010 /* For non DECL_EXTERNALs, if range information is available, fill
22011 the DIE with it. */
22012 else if (!DECL_EXTERNAL (decl
) && !early_dwarf
)
22014 HOST_WIDE_INT cfa_fb_offset
;
22016 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
22018 if (!flag_reorder_blocks_and_partition
)
22020 dw_fde_ref fde
= fun
->fde
;
22021 if (fde
->dw_fde_begin
)
22023 /* We have already generated the labels. */
22024 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
22025 fde
->dw_fde_end
, false);
22029 /* Create start/end labels and add the range. */
22030 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
22031 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
22032 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
22033 current_function_funcdef_no
);
22034 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
22035 current_function_funcdef_no
);
22036 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
22040 #if VMS_DEBUGGING_INFO
22041 /* HP OpenVMS Industry Standard 64: DWARF Extensions
22042 Section 2.3 Prologue and Epilogue Attributes:
22043 When a breakpoint is set on entry to a function, it is generally
22044 desirable for execution to be suspended, not on the very first
22045 instruction of the function, but rather at a point after the
22046 function's frame has been set up, after any language defined local
22047 declaration processing has been completed, and before execution of
22048 the first statement of the function begins. Debuggers generally
22049 cannot properly determine where this point is. Similarly for a
22050 breakpoint set on exit from a function. The prologue and epilogue
22051 attributes allow a compiler to communicate the location(s) to use. */
22054 if (fde
->dw_fde_vms_end_prologue
)
22055 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
22056 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
22058 if (fde
->dw_fde_vms_begin_epilogue
)
22059 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
22060 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
22067 /* Generate pubnames entries for the split function code ranges. */
22068 dw_fde_ref fde
= fun
->fde
;
22070 if (fde
->dw_fde_second_begin
)
22072 if (dwarf_version
>= 3 || !dwarf_strict
)
22074 /* We should use ranges for non-contiguous code section
22075 addresses. Use the actual code range for the initial
22076 section, since the HOT/COLD labels might precede an
22077 alignment offset. */
22078 bool range_list_added
= false;
22079 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
22080 fde
->dw_fde_end
, &range_list_added
,
22082 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
22083 fde
->dw_fde_second_end
,
22084 &range_list_added
, false);
22085 if (range_list_added
)
22090 /* There is no real support in DW2 for this .. so we make
22091 a work-around. First, emit the pub name for the segment
22092 containing the function label. Then make and emit a
22093 simplified subprogram DIE for the second segment with the
22094 name pre-fixed by __hot/cold_sect_of_. We use the same
22095 linkage name for the second die so that gdb will find both
22096 sections when given "b foo". */
22097 const char *name
= NULL
;
22098 tree decl_name
= DECL_NAME (decl
);
22099 dw_die_ref seg_die
;
22101 /* Do the 'primary' section. */
22102 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
22103 fde
->dw_fde_end
, false);
22105 /* Build a minimal DIE for the secondary section. */
22106 seg_die
= new_die (DW_TAG_subprogram
,
22107 subr_die
->die_parent
, decl
);
22109 if (TREE_PUBLIC (decl
))
22110 add_AT_flag (seg_die
, DW_AT_external
, 1);
22112 if (decl_name
!= NULL
22113 && IDENTIFIER_POINTER (decl_name
) != NULL
)
22115 name
= dwarf2_name (decl
, 1);
22116 if (! DECL_ARTIFICIAL (decl
))
22117 add_src_coords_attributes (seg_die
, decl
);
22119 add_linkage_name (seg_die
, decl
);
22121 gcc_assert (name
!= NULL
);
22122 add_pure_or_virtual_attribute (seg_die
, decl
);
22123 if (DECL_ARTIFICIAL (decl
))
22124 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
22126 name
= concat ("__second_sect_of_", name
, NULL
);
22127 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
22128 fde
->dw_fde_second_end
, false);
22129 add_name_attribute (seg_die
, name
);
22130 if (want_pubnames ())
22131 add_pubname_string (name
, seg_die
);
22135 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
22139 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
22141 /* We define the "frame base" as the function's CFA. This is more
22142 convenient for several reasons: (1) It's stable across the prologue
22143 and epilogue, which makes it better than just a frame pointer,
22144 (2) With dwarf3, there exists a one-byte encoding that allows us
22145 to reference the .debug_frame data by proxy, but failing that,
22146 (3) We can at least reuse the code inspection and interpretation
22147 code that determines the CFA position at various points in the
22149 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
22151 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
22152 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
22156 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
22157 if (list
->dw_loc_next
)
22158 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
22160 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
22163 /* Compute a displacement from the "steady-state frame pointer" to
22164 the CFA. The former is what all stack slots and argument slots
22165 will reference in the rtl; the latter is what we've told the
22166 debugger about. We'll need to adjust all frame_base references
22167 by this displacement. */
22168 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
22170 if (fun
->static_chain_decl
)
22172 /* DWARF requires here a location expression that computes the
22173 address of the enclosing subprogram's frame base. The machinery
22174 in tree-nested.c is supposed to store this specific address in the
22175 last field of the FRAME record. */
22176 const tree frame_type
22177 = TREE_TYPE (TREE_TYPE (fun
->static_chain_decl
));
22178 const tree fb_decl
= tree_last (TYPE_FIELDS (frame_type
));
22181 = build1 (INDIRECT_REF
, frame_type
, fun
->static_chain_decl
);
22182 fb_expr
= build3 (COMPONENT_REF
, TREE_TYPE (fb_decl
),
22183 fb_expr
, fb_decl
, NULL_TREE
);
22185 add_AT_location_description (subr_die
, DW_AT_static_link
,
22186 loc_list_from_tree (fb_expr
, 0, NULL
));
22190 /* Generate child dies for template paramaters. */
22191 if (early_dwarf
&& debug_info_level
> DINFO_LEVEL_TERSE
)
22192 gen_generic_params_dies (decl
);
22194 /* Now output descriptions of the arguments for this function. This gets
22195 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
22196 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
22197 `...' at the end of the formal parameter list. In order to find out if
22198 there was a trailing ellipsis or not, we must instead look at the type
22199 associated with the FUNCTION_DECL. This will be a node of type
22200 FUNCTION_TYPE. If the chain of type nodes hanging off of this
22201 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
22202 an ellipsis at the end. */
22204 /* In the case where we are describing a mere function declaration, all we
22205 need to do here (and all we *can* do here) is to describe the *types* of
22206 its formal parameters. */
22207 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
22209 else if (declaration
)
22210 gen_formal_types_die (decl
, subr_die
);
22213 /* Generate DIEs to represent all known formal parameters. */
22214 tree parm
= DECL_ARGUMENTS (decl
);
22215 tree generic_decl
= early_dwarf
22216 ? lang_hooks
.decls
.get_generic_function_decl (decl
) : NULL
;
22217 tree generic_decl_parm
= generic_decl
22218 ? DECL_ARGUMENTS (generic_decl
)
22220 auto_vec
<dw_die_ref
> string_types_vec
;
22221 if (string_types
== NULL
)
22222 string_types
= &string_types_vec
;
22224 /* Now we want to walk the list of parameters of the function and
22225 emit their relevant DIEs.
22227 We consider the case of DECL being an instance of a generic function
22228 as well as it being a normal function.
22230 If DECL is an instance of a generic function we walk the
22231 parameters of the generic function declaration _and_ the parameters of
22232 DECL itself. This is useful because we want to emit specific DIEs for
22233 function parameter packs and those are declared as part of the
22234 generic function declaration. In that particular case,
22235 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
22236 That DIE has children DIEs representing the set of arguments
22237 of the pack. Note that the set of pack arguments can be empty.
22238 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
22241 Otherwise, we just consider the parameters of DECL. */
22242 while (generic_decl_parm
|| parm
)
22244 if (generic_decl_parm
22245 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
22246 gen_formal_parameter_pack_die (generic_decl_parm
,
22249 else if (parm
&& !POINTER_BOUNDS_P (parm
))
22251 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, NULL
, subr_die
);
22253 if (parm
== DECL_ARGUMENTS (decl
)
22254 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
22256 && (dwarf_version
>= 3 || !dwarf_strict
))
22257 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
22259 parm
= DECL_CHAIN (parm
);
22262 parm
= DECL_CHAIN (parm
);
22264 if (generic_decl_parm
)
22265 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
22268 /* Decide whether we need an unspecified_parameters DIE at the end.
22269 There are 2 more cases to do this for: 1) the ansi ... declaration -
22270 this is detectable when the end of the arg list is not a
22271 void_type_node 2) an unprototyped function declaration (not a
22272 definition). This just means that we have no info about the
22273 parameters at all. */
22276 if (prototype_p (TREE_TYPE (decl
)))
22278 /* This is the prototyped case, check for.... */
22279 if (stdarg_p (TREE_TYPE (decl
)))
22280 gen_unspecified_parameters_die (decl
, subr_die
);
22282 else if (DECL_INITIAL (decl
) == NULL_TREE
)
22283 gen_unspecified_parameters_die (decl
, subr_die
);
22286 /* Adjust DW_TAG_string_type DIEs if needed, now that all arguments
22288 if (string_types
== &string_types_vec
)
22290 adjust_string_types ();
22291 string_types
= NULL
;
22295 if (subr_die
!= old_die
)
22296 /* Add the calling convention attribute if requested. */
22297 add_calling_convention_attribute (subr_die
, decl
);
22299 /* Output Dwarf info for all of the stuff within the body of the function
22300 (if it has one - it may be just a declaration).
22302 OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
22303 a function. This BLOCK actually represents the outermost binding contour
22304 for the function, i.e. the contour in which the function's formal
22305 parameters and labels get declared. Curiously, it appears that the front
22306 end doesn't actually put the PARM_DECL nodes for the current function onto
22307 the BLOCK_VARS list for this outer scope, but are strung off of the
22308 DECL_ARGUMENTS list for the function instead.
22310 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
22311 the LABEL_DECL nodes for the function however, and we output DWARF info
22312 for those in decls_for_scope. Just within the `outer_scope' there will be
22313 a BLOCK node representing the function's outermost pair of curly braces,
22314 and any blocks used for the base and member initializers of a C++
22315 constructor function. */
22316 tree outer_scope
= DECL_INITIAL (decl
);
22317 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
22319 int call_site_note_count
= 0;
22320 int tail_call_site_note_count
= 0;
22322 /* Emit a DW_TAG_variable DIE for a named return value. */
22323 if (DECL_NAME (DECL_RESULT (decl
)))
22324 gen_decl_die (DECL_RESULT (decl
), NULL
, NULL
, subr_die
);
22326 /* The first time through decls_for_scope we will generate the
22327 DIEs for the locals. The second time, we fill in the
22329 decls_for_scope (outer_scope
, subr_die
);
22331 if (call_arg_locations
&& (!dwarf_strict
|| dwarf_version
>= 5))
22333 struct call_arg_loc_node
*ca_loc
;
22334 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
22336 dw_die_ref die
= NULL
;
22337 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
22340 for (arg
= (ca_loc
->call_arg_loc_note
!= NULL_RTX
22341 ? NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
)
22343 arg
; arg
= next_arg
)
22345 dw_loc_descr_ref reg
, val
;
22346 machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
22347 dw_die_ref cdie
, tdie
= NULL
;
22349 next_arg
= XEXP (arg
, 1);
22350 if (REG_P (XEXP (XEXP (arg
, 0), 0))
22352 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
22353 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
22354 && REGNO (XEXP (XEXP (arg
, 0), 0))
22355 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
22356 next_arg
= XEXP (next_arg
, 1);
22357 if (mode
== VOIDmode
)
22359 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
22360 if (mode
== VOIDmode
)
22361 mode
= GET_MODE (XEXP (arg
, 0));
22363 if (mode
== VOIDmode
|| mode
== BLKmode
)
22365 /* Get dynamic information about call target only if we
22366 have no static information: we cannot generate both
22367 DW_AT_call_origin and DW_AT_call_target
22369 if (ca_loc
->symbol_ref
== NULL_RTX
)
22371 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
22373 tloc
= XEXP (XEXP (arg
, 0), 1);
22376 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
22377 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
22379 tlocc
= XEXP (XEXP (arg
, 0), 1);
22384 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
22385 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
22386 VAR_INIT_STATUS_INITIALIZED
);
22387 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
22389 rtx mem
= XEXP (XEXP (arg
, 0), 0);
22390 reg
= mem_loc_descriptor (XEXP (mem
, 0),
22391 get_address_mode (mem
),
22393 VAR_INIT_STATUS_INITIALIZED
);
22395 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
22396 == DEBUG_PARAMETER_REF
)
22399 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
22400 tdie
= lookup_decl_die (tdecl
);
22407 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
22408 != DEBUG_PARAMETER_REF
)
22410 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
22412 VAR_INIT_STATUS_INITIALIZED
);
22416 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
22417 cdie
= new_die (dwarf_TAG (DW_TAG_call_site_parameter
), die
,
22420 add_AT_loc (cdie
, DW_AT_location
, reg
);
22421 else if (tdie
!= NULL
)
22422 add_AT_die_ref (cdie
, dwarf_AT (DW_AT_call_parameter
),
22424 add_AT_loc (cdie
, dwarf_AT (DW_AT_call_value
), val
);
22425 if (next_arg
!= XEXP (arg
, 1))
22427 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
22428 if (mode
== VOIDmode
)
22429 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
22430 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
22433 VAR_INIT_STATUS_INITIALIZED
);
22435 add_AT_loc (cdie
, dwarf_AT (DW_AT_call_data_value
),
22440 && (ca_loc
->symbol_ref
|| tloc
))
22441 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
22442 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
22444 dw_loc_descr_ref tval
= NULL
;
22446 if (tloc
!= NULL_RTX
)
22447 tval
= mem_loc_descriptor (tloc
,
22448 GET_MODE (tloc
) == VOIDmode
22449 ? Pmode
: GET_MODE (tloc
),
22451 VAR_INIT_STATUS_INITIALIZED
);
22453 add_AT_loc (die
, dwarf_AT (DW_AT_call_target
), tval
);
22454 else if (tlocc
!= NULL_RTX
)
22456 tval
= mem_loc_descriptor (tlocc
,
22457 GET_MODE (tlocc
) == VOIDmode
22458 ? Pmode
: GET_MODE (tlocc
),
22460 VAR_INIT_STATUS_INITIALIZED
);
22463 dwarf_AT (DW_AT_call_target_clobbered
),
22469 call_site_note_count
++;
22470 if (ca_loc
->tail_call_p
)
22471 tail_call_site_note_count
++;
22475 call_arg_locations
= NULL
;
22476 call_arg_loc_last
= NULL
;
22477 if (tail_call_site_count
>= 0
22478 && tail_call_site_count
== tail_call_site_note_count
22479 && (!dwarf_strict
|| dwarf_version
>= 5))
22481 if (call_site_count
>= 0
22482 && call_site_count
== call_site_note_count
)
22483 add_AT_flag (subr_die
, dwarf_AT (DW_AT_call_all_calls
), 1);
22485 add_AT_flag (subr_die
, dwarf_AT (DW_AT_call_all_tail_calls
), 1);
22487 call_site_count
= -1;
22488 tail_call_site_count
= -1;
22491 /* Mark used types after we have created DIEs for the functions scopes. */
22492 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
22495 /* Returns a hash value for X (which really is a die_struct). */
22498 block_die_hasher::hash (die_struct
*d
)
22500 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
22503 /* Return nonzero if decl_id and die_parent of die_struct X is the same
22504 as decl_id and die_parent of die_struct Y. */
22507 block_die_hasher::equal (die_struct
*x
, die_struct
*y
)
22509 return x
->decl_id
== y
->decl_id
&& x
->die_parent
== y
->die_parent
;
22512 /* Return TRUE if DECL, which may have been previously generated as
22513 OLD_DIE, is a candidate for a DW_AT_specification. DECLARATION is
22514 true if decl (or its origin) is either an extern declaration or a
22515 class/namespace scoped declaration.
22517 The declare_in_namespace support causes us to get two DIEs for one
22518 variable, both of which are declarations. We want to avoid
22519 considering one to be a specification, so we must test for
22520 DECLARATION and DW_AT_declaration. */
22522 decl_will_get_specification_p (dw_die_ref old_die
, tree decl
, bool declaration
)
22524 return (old_die
&& TREE_STATIC (decl
) && !declaration
22525 && get_AT_flag (old_die
, DW_AT_declaration
) == 1);
22528 /* Return true if DECL is a local static. */
22531 local_function_static (tree decl
)
22533 gcc_assert (VAR_P (decl
));
22534 return TREE_STATIC (decl
)
22535 && DECL_CONTEXT (decl
)
22536 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
;
22539 /* Generate a DIE to represent a declared data object.
22540 Either DECL or ORIGIN must be non-null. */
22543 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
22545 HOST_WIDE_INT off
= 0;
22547 tree decl_or_origin
= decl
? decl
: origin
;
22548 tree ultimate_origin
;
22549 dw_die_ref var_die
;
22550 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
22551 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
22552 || class_or_namespace_scope_p (context_die
));
22553 bool specialization_p
= false;
22554 bool no_linkage_name
= false;
22556 /* While C++ inline static data members have definitions inside of the
22557 class, force the first DIE to be a declaration, then let gen_member_die
22558 reparent it to the class context and call gen_variable_die again
22559 to create the outside of the class DIE for the definition. */
22563 && DECL_CONTEXT (decl
)
22564 && TYPE_P (DECL_CONTEXT (decl
))
22565 && lang_hooks
.decls
.decl_dwarf_attribute (decl
, DW_AT_inline
) != -1)
22567 declaration
= true;
22568 no_linkage_name
= true;
22571 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
22572 if (decl
|| ultimate_origin
)
22573 origin
= ultimate_origin
;
22574 com_decl
= fortran_common (decl_or_origin
, &off
);
22576 /* Symbol in common gets emitted as a child of the common block, in the form
22577 of a data member. */
22580 dw_die_ref com_die
;
22581 dw_loc_list_ref loc
= NULL
;
22582 die_node com_die_arg
;
22584 var_die
= lookup_decl_die (decl_or_origin
);
22587 if (! early_dwarf
&& get_AT (var_die
, DW_AT_location
) == NULL
)
22589 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2, NULL
);
22594 /* Optimize the common case. */
22595 if (single_element_loc_list_p (loc
)
22596 && loc
->expr
->dw_loc_opc
== DW_OP_addr
22597 && loc
->expr
->dw_loc_next
== NULL
22598 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
22601 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
22602 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
22603 = plus_constant (GET_MODE (x
), x
, off
);
22606 loc_list_plus_const (loc
, off
);
22608 add_AT_location_description (var_die
, DW_AT_location
, loc
);
22609 remove_AT (var_die
, DW_AT_declaration
);
22615 if (common_block_die_table
== NULL
)
22616 common_block_die_table
= hash_table
<block_die_hasher
>::create_ggc (10);
22618 com_die_arg
.decl_id
= DECL_UID (com_decl
);
22619 com_die_arg
.die_parent
= context_die
;
22620 com_die
= common_block_die_table
->find (&com_die_arg
);
22622 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
22623 if (com_die
== NULL
)
22626 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
22629 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
22630 add_name_and_src_coords_attributes (com_die
, com_decl
);
22633 add_AT_location_description (com_die
, DW_AT_location
, loc
);
22634 /* Avoid sharing the same loc descriptor between
22635 DW_TAG_common_block and DW_TAG_variable. */
22636 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
22638 else if (DECL_EXTERNAL (decl_or_origin
))
22639 add_AT_flag (com_die
, DW_AT_declaration
, 1);
22640 if (want_pubnames ())
22641 add_pubname_string (cnam
, com_die
); /* ??? needed? */
22642 com_die
->decl_id
= DECL_UID (com_decl
);
22643 slot
= common_block_die_table
->find_slot (com_die
, INSERT
);
22646 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
22648 add_AT_location_description (com_die
, DW_AT_location
, loc
);
22649 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
22650 remove_AT (com_die
, DW_AT_declaration
);
22652 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
22653 add_name_and_src_coords_attributes (var_die
, decl_or_origin
);
22654 add_type_attribute (var_die
, TREE_TYPE (decl_or_origin
),
22655 decl_quals (decl_or_origin
), false,
22657 add_AT_flag (var_die
, DW_AT_external
, 1);
22662 /* Optimize the common case. */
22663 if (single_element_loc_list_p (loc
)
22664 && loc
->expr
->dw_loc_opc
== DW_OP_addr
22665 && loc
->expr
->dw_loc_next
== NULL
22666 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
22668 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
22669 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
22670 = plus_constant (GET_MODE (x
), x
, off
);
22673 loc_list_plus_const (loc
, off
);
22675 add_AT_location_description (var_die
, DW_AT_location
, loc
);
22677 else if (DECL_EXTERNAL (decl_or_origin
))
22678 add_AT_flag (var_die
, DW_AT_declaration
, 1);
22680 equate_decl_number_to_die (decl
, var_die
);
22688 /* A declaration that has been previously dumped, needs no
22689 further annotations, since it doesn't need location on
22690 the second pass. */
22693 else if (decl_will_get_specification_p (old_die
, decl
, declaration
)
22694 && !get_AT (old_die
, DW_AT_specification
))
22696 /* Fall-thru so we can make a new variable die along with a
22697 DW_AT_specification. */
22699 else if (origin
&& old_die
->die_parent
!= context_die
)
22701 /* If we will be creating an inlined instance, we need a
22702 new DIE that will get annotated with
22703 DW_AT_abstract_origin. Clear things so we can get a
22705 gcc_assert (!DECL_ABSTRACT_P (decl
));
22710 /* If a DIE was dumped early, it still needs location info.
22711 Skip to where we fill the location bits. */
22713 goto gen_variable_die_location
;
22717 /* For static data members, the declaration in the class is supposed
22718 to have DW_TAG_member tag; the specification should still be
22719 DW_TAG_variable referencing the DW_TAG_member DIE. */
22720 if (declaration
&& class_scope_p (context_die
))
22721 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
22723 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
22725 if (origin
!= NULL
)
22726 add_abstract_origin_attribute (var_die
, origin
);
22728 /* Loop unrolling can create multiple blocks that refer to the same
22729 static variable, so we must test for the DW_AT_declaration flag.
22731 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
22732 copy decls and set the DECL_ABSTRACT_P flag on them instead of
22735 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
22736 else if (decl_will_get_specification_p (old_die
, decl
, declaration
))
22738 /* This is a definition of a C++ class level static. */
22739 add_AT_specification (var_die
, old_die
);
22740 specialization_p
= true;
22741 if (DECL_NAME (decl
))
22743 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
22744 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
22746 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
22747 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
22749 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
22750 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
22752 if (old_die
->die_tag
== DW_TAG_member
)
22753 add_linkage_name (var_die
, decl
);
22757 add_name_and_src_coords_attributes (var_die
, decl
, no_linkage_name
);
22759 if ((origin
== NULL
&& !specialization_p
)
22761 && !DECL_ABSTRACT_P (decl_or_origin
)
22762 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
22763 decl_function_context
22764 (decl_or_origin
))))
22766 tree type
= TREE_TYPE (decl_or_origin
);
22768 if (decl_by_reference_p (decl_or_origin
))
22769 add_type_attribute (var_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
22772 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
), false,
22776 if (origin
== NULL
&& !specialization_p
)
22778 if (TREE_PUBLIC (decl
))
22779 add_AT_flag (var_die
, DW_AT_external
, 1);
22781 if (DECL_ARTIFICIAL (decl
))
22782 add_AT_flag (var_die
, DW_AT_artificial
, 1);
22784 add_accessibility_attribute (var_die
, decl
);
22788 add_AT_flag (var_die
, DW_AT_declaration
, 1);
22790 if (decl
&& (DECL_ABSTRACT_P (decl
)
22791 || !old_die
|| is_declaration_die (old_die
)))
22792 equate_decl_number_to_die (decl
, var_die
);
22794 gen_variable_die_location
:
22796 && (! DECL_ABSTRACT_P (decl_or_origin
)
22797 /* Local static vars are shared between all clones/inlines,
22798 so emit DW_AT_location on the abstract DIE if DECL_RTL is
22800 || (VAR_P (decl_or_origin
)
22801 && TREE_STATIC (decl_or_origin
)
22802 && DECL_RTL_SET_P (decl_or_origin
))))
22805 add_pubname (decl_or_origin
, var_die
);
22807 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
22811 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
22813 if ((dwarf_version
>= 4 || !dwarf_strict
)
22814 && lang_hooks
.decls
.decl_dwarf_attribute (decl_or_origin
,
22815 DW_AT_const_expr
) == 1
22816 && !get_AT (var_die
, DW_AT_const_expr
)
22817 && !specialization_p
)
22818 add_AT_flag (var_die
, DW_AT_const_expr
, 1);
22822 int inl
= lang_hooks
.decls
.decl_dwarf_attribute (decl_or_origin
,
22825 && !get_AT (var_die
, DW_AT_inline
)
22826 && !specialization_p
)
22827 add_AT_unsigned (var_die
, DW_AT_inline
, inl
);
22831 /* Generate a DIE to represent a named constant. */
22834 gen_const_die (tree decl
, dw_die_ref context_die
)
22836 dw_die_ref const_die
;
22837 tree type
= TREE_TYPE (decl
);
22839 const_die
= lookup_decl_die (decl
);
22843 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
22844 equate_decl_number_to_die (decl
, const_die
);
22845 add_name_and_src_coords_attributes (const_die
, decl
);
22846 add_type_attribute (const_die
, type
, TYPE_QUAL_CONST
, false, context_die
);
22847 if (TREE_PUBLIC (decl
))
22848 add_AT_flag (const_die
, DW_AT_external
, 1);
22849 if (DECL_ARTIFICIAL (decl
))
22850 add_AT_flag (const_die
, DW_AT_artificial
, 1);
22851 tree_add_const_value_attribute_for_decl (const_die
, decl
);
22854 /* Generate a DIE to represent a label identifier. */
22857 gen_label_die (tree decl
, dw_die_ref context_die
)
22859 tree origin
= decl_ultimate_origin (decl
);
22860 dw_die_ref lbl_die
= lookup_decl_die (decl
);
22862 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
22866 lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
22867 equate_decl_number_to_die (decl
, lbl_die
);
22869 if (origin
!= NULL
)
22870 add_abstract_origin_attribute (lbl_die
, origin
);
22872 add_name_and_src_coords_attributes (lbl_die
, decl
);
22875 if (DECL_ABSTRACT_P (decl
))
22876 equate_decl_number_to_die (decl
, lbl_die
);
22877 else if (! early_dwarf
)
22879 insn
= DECL_RTL_IF_SET (decl
);
22881 /* Deleted labels are programmer specified labels which have been
22882 eliminated because of various optimizations. We still emit them
22883 here so that it is possible to put breakpoints on them. */
22887 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
22889 /* When optimization is enabled (via -O) some parts of the compiler
22890 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
22891 represent source-level labels which were explicitly declared by
22892 the user. This really shouldn't be happening though, so catch
22893 it if it ever does happen. */
22894 gcc_assert (!as_a
<rtx_insn
*> (insn
)->deleted ());
22896 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
22897 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
22901 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
22902 && CODE_LABEL_NUMBER (insn
) != -1)
22904 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
22905 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
22910 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
22911 attributes to the DIE for a block STMT, to describe where the inlined
22912 function was called from. This is similar to add_src_coords_attributes. */
22915 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
22917 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
22919 if (dwarf_version
>= 3 || !dwarf_strict
)
22921 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
22922 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
22927 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
22928 Add low_pc and high_pc attributes to the DIE for a block STMT. */
22931 add_high_low_attributes (tree stmt
, dw_die_ref die
)
22933 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
22935 if (BLOCK_FRAGMENT_CHAIN (stmt
)
22936 && (dwarf_version
>= 3 || !dwarf_strict
))
22938 tree chain
, superblock
= NULL_TREE
;
22940 dw_attr_node
*attr
= NULL
;
22942 if (inlined_function_outer_scope_p (stmt
))
22944 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
22945 BLOCK_NUMBER (stmt
));
22946 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
22949 /* Optimize duplicate .debug_ranges lists or even tails of
22950 lists. If this BLOCK has same ranges as its supercontext,
22951 lookup DW_AT_ranges attribute in the supercontext (and
22952 recursively so), verify that the ranges_table contains the
22953 right values and use it instead of adding a new .debug_range. */
22954 for (chain
= stmt
, pdie
= die
;
22955 BLOCK_SAME_RANGE (chain
);
22956 chain
= BLOCK_SUPERCONTEXT (chain
))
22958 dw_attr_node
*new_attr
;
22960 pdie
= pdie
->die_parent
;
22963 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
22965 new_attr
= get_AT (pdie
, DW_AT_ranges
);
22966 if (new_attr
== NULL
22967 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
22970 superblock
= BLOCK_SUPERCONTEXT (chain
);
22973 && ((*ranges_table
)[attr
->dw_attr_val
.v
.val_offset
].num
22974 == BLOCK_NUMBER (superblock
))
22975 && BLOCK_FRAGMENT_CHAIN (superblock
))
22977 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
;
22978 unsigned long supercnt
= 0, thiscnt
= 0;
22979 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
22980 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
22983 gcc_checking_assert ((*ranges_table
)[off
+ supercnt
].num
22984 == BLOCK_NUMBER (chain
));
22986 gcc_checking_assert ((*ranges_table
)[off
+ supercnt
+ 1].num
== 0);
22987 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
22988 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
22990 gcc_assert (supercnt
>= thiscnt
);
22991 add_AT_range_list (die
, DW_AT_ranges
, off
+ supercnt
- thiscnt
,
22993 note_rnglist_head (off
+ supercnt
- thiscnt
);
22997 unsigned int offset
= add_ranges (stmt
, true);
22998 add_AT_range_list (die
, DW_AT_ranges
, offset
, false);
22999 note_rnglist_head (offset
);
23001 bool prev_in_cold
= BLOCK_IN_COLD_SECTION_P (stmt
);
23002 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
23005 add_ranges (chain
, prev_in_cold
!= BLOCK_IN_COLD_SECTION_P (chain
));
23006 prev_in_cold
= BLOCK_IN_COLD_SECTION_P (chain
);
23007 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
23014 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
23015 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
23016 BLOCK_NUMBER (stmt
));
23017 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
23018 BLOCK_NUMBER (stmt
));
23019 add_AT_low_high_pc (die
, label
, label_high
, false);
23023 /* Generate a DIE for a lexical block. */
23026 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
)
23028 dw_die_ref old_die
= BLOCK_DIE (stmt
);
23029 dw_die_ref stmt_die
= NULL
;
23032 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
23033 BLOCK_DIE (stmt
) = stmt_die
;
23036 if (BLOCK_ABSTRACT (stmt
))
23040 /* This must have been generated early and it won't even
23041 need location information since it's a DW_AT_inline
23044 for (dw_die_ref c
= context_die
; c
; c
= c
->die_parent
)
23045 if (c
->die_tag
== DW_TAG_inlined_subroutine
23046 || c
->die_tag
== DW_TAG_subprogram
)
23048 gcc_assert (get_AT (c
, DW_AT_inline
));
23054 else if (BLOCK_ABSTRACT_ORIGIN (stmt
))
23056 /* If this is an inlined instance, create a new lexical die for
23057 anything below to attach DW_AT_abstract_origin to. */
23060 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
23061 BLOCK_DIE (stmt
) = stmt_die
;
23065 tree origin
= block_ultimate_origin (stmt
);
23066 if (origin
!= NULL_TREE
&& origin
!= stmt
)
23067 add_abstract_origin_attribute (stmt_die
, origin
);
23071 stmt_die
= old_die
;
23073 /* A non abstract block whose blocks have already been reordered
23074 should have the instruction range for this block. If so, set the
23075 high/low attributes. */
23076 if (!early_dwarf
&& !BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
23078 gcc_assert (stmt_die
);
23079 add_high_low_attributes (stmt
, stmt_die
);
23082 decls_for_scope (stmt
, stmt_die
);
23085 /* Generate a DIE for an inlined subprogram. */
23088 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
)
23092 /* The instance of function that is effectively being inlined shall not
23094 gcc_assert (! BLOCK_ABSTRACT (stmt
));
23096 decl
= block_ultimate_origin (stmt
);
23098 /* Make sure any inlined functions are known to be inlineable. */
23099 gcc_checking_assert (DECL_ABSTRACT_P (decl
)
23100 || cgraph_function_possibly_inlined_p (decl
));
23102 /* Emit info for the abstract instance first, if we haven't yet. We
23103 must emit this even if the block is abstract, otherwise when we
23104 emit the block below (or elsewhere), we may end up trying to emit
23105 a die whose origin die hasn't been emitted, and crashing. */
23106 dwarf2out_abstract_function (decl
);
23108 if (! BLOCK_ABSTRACT (stmt
))
23110 dw_die_ref subr_die
23111 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
23113 if (call_arg_locations
)
23114 BLOCK_DIE (stmt
) = subr_die
;
23115 add_abstract_origin_attribute (subr_die
, decl
);
23116 if (TREE_ASM_WRITTEN (stmt
))
23117 add_high_low_attributes (stmt
, subr_die
);
23118 add_call_src_coords_attributes (stmt
, subr_die
);
23120 decls_for_scope (stmt
, subr_die
);
23124 /* Generate a DIE for a field in a record, or structure. CTX is required: see
23125 the comment for VLR_CONTEXT. */
23128 gen_field_die (tree decl
, struct vlr_context
*ctx
, dw_die_ref context_die
)
23130 dw_die_ref decl_die
;
23132 if (TREE_TYPE (decl
) == error_mark_node
)
23135 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
23136 add_name_and_src_coords_attributes (decl_die
, decl
);
23137 add_type_attribute (decl_die
, member_declared_type (decl
), decl_quals (decl
),
23138 TYPE_REVERSE_STORAGE_ORDER (DECL_FIELD_CONTEXT (decl
)),
23141 if (DECL_BIT_FIELD_TYPE (decl
))
23143 add_byte_size_attribute (decl_die
, decl
);
23144 add_bit_size_attribute (decl_die
, decl
);
23145 add_bit_offset_attribute (decl_die
, decl
, ctx
);
23148 /* If we have a variant part offset, then we are supposed to process a member
23149 of a QUAL_UNION_TYPE, which is how we represent variant parts in
23151 gcc_assert (ctx
->variant_part_offset
== NULL_TREE
23152 || TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != QUAL_UNION_TYPE
);
23153 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
23154 add_data_member_location_attribute (decl_die
, decl
, ctx
);
23156 if (DECL_ARTIFICIAL (decl
))
23157 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
23159 add_accessibility_attribute (decl_die
, decl
);
23161 /* Equate decl number to die, so that we can look up this decl later on. */
23162 equate_decl_number_to_die (decl
, decl_die
);
23166 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
23167 Use modified_type_die instead.
23168 We keep this code here just in case these types of DIEs may be needed to
23169 represent certain things in other languages (e.g. Pascal) someday. */
23172 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
23175 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
23177 equate_type_number_to_die (type
, ptr_die
);
23178 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
23180 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
23183 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
23184 Use modified_type_die instead.
23185 We keep this code here just in case these types of DIEs may be needed to
23186 represent certain things in other languages (e.g. Pascal) someday. */
23189 gen_reference_type_die (tree type
, dw_die_ref context_die
)
23191 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
23193 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
23194 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
23196 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
23198 equate_type_number_to_die (type
, ref_die
);
23199 add_type_attribute (ref_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
23201 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
23205 /* Generate a DIE for a pointer to a member type. TYPE can be an
23206 OFFSET_TYPE, for a pointer to data member, or a RECORD_TYPE, for a
23207 pointer to member function. */
23210 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
23212 if (lookup_type_die (type
))
23215 dw_die_ref ptr_die
= new_die (DW_TAG_ptr_to_member_type
,
23216 scope_die_for (type
, context_die
), type
);
23218 equate_type_number_to_die (type
, ptr_die
);
23219 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
23220 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
23221 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
23224 if (TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
23225 && TREE_CODE (TREE_TYPE (type
)) != METHOD_TYPE
)
23227 dw_loc_descr_ref op
= new_loc_descr (DW_OP_plus
, 0, 0);
23228 add_AT_loc (ptr_die
, DW_AT_use_location
, op
);
23232 static char *producer_string
;
23234 /* Return a heap allocated producer string including command line options
23235 if -grecord-gcc-switches. */
23238 gen_producer_string (void)
23241 auto_vec
<const char *> switches
;
23242 const char *language_string
= lang_hooks
.name
;
23243 char *producer
, *tail
;
23245 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
23246 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
23248 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
23249 switch (save_decoded_options
[j
].opt_index
)
23256 case OPT_auxbase_strip
:
23265 case OPT_SPECIAL_unknown
:
23266 case OPT_SPECIAL_ignore
:
23267 case OPT_SPECIAL_program_name
:
23268 case OPT_SPECIAL_input_file
:
23269 case OPT_grecord_gcc_switches
:
23270 case OPT_gno_record_gcc_switches
:
23271 case OPT__output_pch_
:
23272 case OPT_fdiagnostics_show_location_
:
23273 case OPT_fdiagnostics_show_option
:
23274 case OPT_fdiagnostics_show_caret
:
23275 case OPT_fdiagnostics_color_
:
23276 case OPT_fverbose_asm
:
23278 case OPT__sysroot_
:
23280 case OPT_nostdinc__
:
23281 case OPT_fpreprocessed
:
23282 case OPT_fltrans_output_list_
:
23283 case OPT_fresolution_
:
23284 case OPT_fdebug_prefix_map_
:
23285 /* Ignore these. */
23288 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
23289 & CL_NO_DWARF_RECORD
)
23291 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
23293 switch (save_decoded_options
[j
].canonical_option
[0][1])
23300 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
23307 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
23308 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
23312 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
23314 sprintf (tail
, "%s %s", language_string
, version_string
);
23317 FOR_EACH_VEC_ELT (switches
, j
, p
)
23321 memcpy (tail
+ 1, p
, len
);
23329 /* Given a C and/or C++ language/version string return the "highest".
23330 C++ is assumed to be "higher" than C in this case. Used for merging
23331 LTO translation unit languages. */
23332 static const char *
23333 highest_c_language (const char *lang1
, const char *lang2
)
23335 if (strcmp ("GNU C++14", lang1
) == 0 || strcmp ("GNU C++14", lang2
) == 0)
23336 return "GNU C++14";
23337 if (strcmp ("GNU C++11", lang1
) == 0 || strcmp ("GNU C++11", lang2
) == 0)
23338 return "GNU C++11";
23339 if (strcmp ("GNU C++98", lang1
) == 0 || strcmp ("GNU C++98", lang2
) == 0)
23340 return "GNU C++98";
23342 if (strcmp ("GNU C11", lang1
) == 0 || strcmp ("GNU C11", lang2
) == 0)
23344 if (strcmp ("GNU C99", lang1
) == 0 || strcmp ("GNU C99", lang2
) == 0)
23346 if (strcmp ("GNU C89", lang1
) == 0 || strcmp ("GNU C89", lang2
) == 0)
23349 gcc_unreachable ();
23353 /* Generate the DIE for the compilation unit. */
23356 gen_compile_unit_die (const char *filename
)
23359 const char *language_string
= lang_hooks
.name
;
23362 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
23366 add_name_attribute (die
, filename
);
23367 /* Don't add cwd for <built-in>. */
23368 if (filename
[0] != '<')
23369 add_comp_dir_attribute (die
);
23372 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
23374 /* If our producer is LTO try to figure out a common language to use
23375 from the global list of translation units. */
23376 if (strcmp (language_string
, "GNU GIMPLE") == 0)
23380 const char *common_lang
= NULL
;
23382 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
23384 if (!TRANSLATION_UNIT_LANGUAGE (t
))
23387 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
23388 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
23390 else if (strncmp (common_lang
, "GNU C", 5) == 0
23391 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
23392 /* Mixing C and C++ is ok, use C++ in that case. */
23393 common_lang
= highest_c_language (common_lang
,
23394 TRANSLATION_UNIT_LANGUAGE (t
));
23397 /* Fall back to C. */
23398 common_lang
= NULL
;
23404 language_string
= common_lang
;
23407 language
= DW_LANG_C
;
23408 if (strncmp (language_string
, "GNU C", 5) == 0
23409 && ISDIGIT (language_string
[5]))
23411 language
= DW_LANG_C89
;
23412 if (dwarf_version
>= 3 || !dwarf_strict
)
23414 if (strcmp (language_string
, "GNU C89") != 0)
23415 language
= DW_LANG_C99
;
23417 if (dwarf_version
>= 5 /* || !dwarf_strict */)
23418 if (strcmp (language_string
, "GNU C11") == 0)
23419 language
= DW_LANG_C11
;
23422 else if (strncmp (language_string
, "GNU C++", 7) == 0)
23424 language
= DW_LANG_C_plus_plus
;
23425 if (dwarf_version
>= 5 /* || !dwarf_strict */)
23427 if (strcmp (language_string
, "GNU C++11") == 0)
23428 language
= DW_LANG_C_plus_plus_11
;
23429 else if (strcmp (language_string
, "GNU C++14") == 0)
23430 language
= DW_LANG_C_plus_plus_14
;
23433 else if (strcmp (language_string
, "GNU F77") == 0)
23434 language
= DW_LANG_Fortran77
;
23435 else if (strcmp (language_string
, "GNU Pascal") == 0)
23436 language
= DW_LANG_Pascal83
;
23437 else if (dwarf_version
>= 3 || !dwarf_strict
)
23439 if (strcmp (language_string
, "GNU Ada") == 0)
23440 language
= DW_LANG_Ada95
;
23441 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
23443 language
= DW_LANG_Fortran95
;
23444 if (dwarf_version
>= 5 /* || !dwarf_strict */)
23446 if (strcmp (language_string
, "GNU Fortran2003") == 0)
23447 language
= DW_LANG_Fortran03
;
23448 else if (strcmp (language_string
, "GNU Fortran2008") == 0)
23449 language
= DW_LANG_Fortran08
;
23452 else if (strcmp (language_string
, "GNU Java") == 0)
23453 language
= DW_LANG_Java
;
23454 else if (strcmp (language_string
, "GNU Objective-C") == 0)
23455 language
= DW_LANG_ObjC
;
23456 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
23457 language
= DW_LANG_ObjC_plus_plus
;
23458 else if (dwarf_version
>= 5 || !dwarf_strict
)
23460 if (strcmp (language_string
, "GNU Go") == 0)
23461 language
= DW_LANG_Go
;
23464 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
23465 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
23466 language
= DW_LANG_Fortran90
;
23468 add_AT_unsigned (die
, DW_AT_language
, language
);
23472 case DW_LANG_Fortran77
:
23473 case DW_LANG_Fortran90
:
23474 case DW_LANG_Fortran95
:
23475 case DW_LANG_Fortran03
:
23476 case DW_LANG_Fortran08
:
23477 /* Fortran has case insensitive identifiers and the front-end
23478 lowercases everything. */
23479 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
23482 /* The default DW_ID_case_sensitive doesn't need to be specified. */
23488 /* Generate the DIE for a base class. */
23491 gen_inheritance_die (tree binfo
, tree access
, tree type
,
23492 dw_die_ref context_die
)
23494 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
23495 struct vlr_context ctx
= { type
, NULL
};
23497 add_type_attribute (die
, BINFO_TYPE (binfo
), TYPE_UNQUALIFIED
, false,
23499 add_data_member_location_attribute (die
, binfo
, &ctx
);
23501 if (BINFO_VIRTUAL_P (binfo
))
23502 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
23504 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
23505 children, otherwise the default is DW_ACCESS_public. In DWARF2
23506 the default has always been DW_ACCESS_private. */
23507 if (access
== access_public_node
)
23509 if (dwarf_version
== 2
23510 || context_die
->die_tag
== DW_TAG_class_type
)
23511 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
23513 else if (access
== access_protected_node
)
23514 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
23515 else if (dwarf_version
> 2
23516 && context_die
->die_tag
!= DW_TAG_class_type
)
23517 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
23520 /* Return whether DECL is a FIELD_DECL that represents the variant part of a
23523 is_variant_part (tree decl
)
23525 return (TREE_CODE (decl
) == FIELD_DECL
23526 && TREE_CODE (TREE_TYPE (decl
)) == QUAL_UNION_TYPE
);
23529 /* Check that OPERAND is a reference to a field in STRUCT_TYPE. If it is,
23530 return the FIELD_DECL. Return NULL_TREE otherwise. */
23533 analyze_discr_in_predicate (tree operand
, tree struct_type
)
23535 bool continue_stripping
= true;
23536 while (continue_stripping
)
23537 switch (TREE_CODE (operand
))
23540 operand
= TREE_OPERAND (operand
, 0);
23543 continue_stripping
= false;
23547 /* Match field access to members of struct_type only. */
23548 if (TREE_CODE (operand
) == COMPONENT_REF
23549 && TREE_CODE (TREE_OPERAND (operand
, 0)) == PLACEHOLDER_EXPR
23550 && TREE_TYPE (TREE_OPERAND (operand
, 0)) == struct_type
23551 && TREE_CODE (TREE_OPERAND (operand
, 1)) == FIELD_DECL
)
23552 return TREE_OPERAND (operand
, 1);
23557 /* Check that SRC is a constant integer that can be represented as a native
23558 integer constant (either signed or unsigned). If so, store it into DEST and
23559 return true. Return false otherwise. */
23562 get_discr_value (tree src
, dw_discr_value
*dest
)
23564 bool is_unsigned
= TYPE_UNSIGNED (TREE_TYPE (src
));
23566 if (TREE_CODE (src
) != INTEGER_CST
23567 || !(is_unsigned
? tree_fits_uhwi_p (src
) : tree_fits_shwi_p (src
)))
23570 dest
->pos
= is_unsigned
;
23572 dest
->v
.uval
= tree_to_uhwi (src
);
23574 dest
->v
.sval
= tree_to_shwi (src
);
23579 /* Try to extract synthetic properties out of VARIANT_PART_DECL, which is a
23580 FIELD_DECL in STRUCT_TYPE that represents a variant part. If unsuccessful,
23581 store NULL_TREE in DISCR_DECL. Otherwise:
23583 - store the discriminant field in STRUCT_TYPE that controls the variant
23584 part to *DISCR_DECL
23586 - put in *DISCR_LISTS_P an array where for each variant, the item
23587 represents the corresponding matching list of discriminant values.
23589 - put in *DISCR_LISTS_LENGTH the number of variants, which is the size of
23592 Note that when the array is allocated (i.e. when the analysis is
23593 successful), it is up to the caller to free the array. */
23596 analyze_variants_discr (tree variant_part_decl
,
23599 dw_discr_list_ref
**discr_lists_p
,
23600 unsigned *discr_lists_length
)
23602 tree variant_part_type
= TREE_TYPE (variant_part_decl
);
23604 dw_discr_list_ref
*discr_lists
;
23607 /* Compute how many variants there are in this variant part. */
23608 *discr_lists_length
= 0;
23609 for (variant
= TYPE_FIELDS (variant_part_type
);
23610 variant
!= NULL_TREE
;
23611 variant
= DECL_CHAIN (variant
))
23612 ++*discr_lists_length
;
23614 *discr_decl
= NULL_TREE
;
23616 = (dw_discr_list_ref
*) xcalloc (*discr_lists_length
,
23617 sizeof (**discr_lists_p
));
23618 discr_lists
= *discr_lists_p
;
23620 /* And then analyze all variants to extract discriminant information for all
23621 of them. This analysis is conservative: as soon as we detect something we
23622 do not support, abort everything and pretend we found nothing. */
23623 for (variant
= TYPE_FIELDS (variant_part_type
), i
= 0;
23624 variant
!= NULL_TREE
;
23625 variant
= DECL_CHAIN (variant
), ++i
)
23627 tree match_expr
= DECL_QUALIFIER (variant
);
23629 /* Now, try to analyze the predicate and deduce a discriminant for
23631 if (match_expr
== boolean_true_node
)
23632 /* Typically happens for the default variant: it matches all cases that
23633 previous variants rejected. Don't output any matching value for
23637 /* The following loop tries to iterate over each discriminant
23638 possibility: single values or ranges. */
23639 while (match_expr
!= NULL_TREE
)
23641 tree next_round_match_expr
;
23642 tree candidate_discr
= NULL_TREE
;
23643 dw_discr_list_ref new_node
= NULL
;
23645 /* Possibilities are matched one after the other by nested
23646 TRUTH_ORIF_EXPR expressions. Process the current possibility and
23647 continue with the rest at next iteration. */
23648 if (TREE_CODE (match_expr
) == TRUTH_ORIF_EXPR
)
23650 next_round_match_expr
= TREE_OPERAND (match_expr
, 0);
23651 match_expr
= TREE_OPERAND (match_expr
, 1);
23654 next_round_match_expr
= NULL_TREE
;
23656 if (match_expr
== boolean_false_node
)
23657 /* This sub-expression matches nothing: just wait for the next
23661 else if (TREE_CODE (match_expr
) == EQ_EXPR
)
23663 /* We are matching: <discr_field> == <integer_cst>
23664 This sub-expression matches a single value. */
23665 tree integer_cst
= TREE_OPERAND (match_expr
, 1);
23668 = analyze_discr_in_predicate (TREE_OPERAND (match_expr
, 0),
23671 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
23672 if (!get_discr_value (integer_cst
,
23673 &new_node
->dw_discr_lower_bound
))
23675 new_node
->dw_discr_range
= false;
23678 else if (TREE_CODE (match_expr
) == TRUTH_ANDIF_EXPR
)
23680 /* We are matching:
23681 <discr_field> > <integer_cst>
23682 && <discr_field> < <integer_cst>.
23683 This sub-expression matches the range of values between the
23684 two matched integer constants. Note that comparisons can be
23685 inclusive or exclusive. */
23686 tree candidate_discr_1
, candidate_discr_2
;
23687 tree lower_cst
, upper_cst
;
23688 bool lower_cst_included
, upper_cst_included
;
23689 tree lower_op
= TREE_OPERAND (match_expr
, 0);
23690 tree upper_op
= TREE_OPERAND (match_expr
, 1);
23692 /* When the comparison is exclusive, the integer constant is not
23693 the discriminant range bound we are looking for: we will have
23694 to increment or decrement it. */
23695 if (TREE_CODE (lower_op
) == GE_EXPR
)
23696 lower_cst_included
= true;
23697 else if (TREE_CODE (lower_op
) == GT_EXPR
)
23698 lower_cst_included
= false;
23702 if (TREE_CODE (upper_op
) == LE_EXPR
)
23703 upper_cst_included
= true;
23704 else if (TREE_CODE (upper_op
) == LT_EXPR
)
23705 upper_cst_included
= false;
23709 /* Extract the discriminant from the first operand and check it
23710 is consistant with the same analysis in the second
23713 = analyze_discr_in_predicate (TREE_OPERAND (lower_op
, 0),
23716 = analyze_discr_in_predicate (TREE_OPERAND (upper_op
, 0),
23718 if (candidate_discr_1
== candidate_discr_2
)
23719 candidate_discr
= candidate_discr_1
;
23723 /* Extract bounds from both. */
23724 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
23725 lower_cst
= TREE_OPERAND (lower_op
, 1);
23726 upper_cst
= TREE_OPERAND (upper_op
, 1);
23728 if (!lower_cst_included
)
23730 = fold (build2 (PLUS_EXPR
, TREE_TYPE (lower_cst
),
23732 build_int_cst (TREE_TYPE (lower_cst
), 1)));
23733 if (!upper_cst_included
)
23735 = fold (build2 (MINUS_EXPR
, TREE_TYPE (upper_cst
),
23737 build_int_cst (TREE_TYPE (upper_cst
), 1)));
23739 if (!get_discr_value (lower_cst
,
23740 &new_node
->dw_discr_lower_bound
)
23741 || !get_discr_value (upper_cst
,
23742 &new_node
->dw_discr_upper_bound
))
23745 new_node
->dw_discr_range
= true;
23749 /* Unsupported sub-expression: we cannot determine the set of
23750 matching discriminant values. Abort everything. */
23753 /* If the discriminant info is not consistant with what we saw so
23754 far, consider the analysis failed and abort everything. */
23755 if (candidate_discr
== NULL_TREE
23756 || (*discr_decl
!= NULL_TREE
&& candidate_discr
!= *discr_decl
))
23759 *discr_decl
= candidate_discr
;
23761 if (new_node
!= NULL
)
23763 new_node
->dw_discr_next
= discr_lists
[i
];
23764 discr_lists
[i
] = new_node
;
23766 match_expr
= next_round_match_expr
;
23770 /* If we reach this point, we could match everything we were interested
23775 /* Clean all data structure and return no result. */
23776 free (*discr_lists_p
);
23777 *discr_lists_p
= NULL
;
23778 *discr_decl
= NULL_TREE
;
23781 /* Generate a DIE to represent VARIANT_PART_DECL, a variant part that is part
23782 of STRUCT_TYPE, a record type. This new DIE is emitted as the next child
23785 Variant parts are supposed to be implemented as a FIELD_DECL whose type is a
23786 QUAL_UNION_TYPE: this is the VARIANT_PART_DECL parameter. The members for
23787 this type, which are record types, represent the available variants and each
23788 has a DECL_QUALIFIER attribute. The discriminant and the discriminant
23789 values are inferred from these attributes.
23791 In trees, the offsets for the fields inside these sub-records are relative
23792 to the variant part itself, whereas the corresponding DIEs should have
23793 offset attributes that are relative to the embedding record base address.
23794 This is why the caller must provide a VARIANT_PART_OFFSET expression: it
23795 must be an expression that computes the offset of the variant part to
23796 describe in DWARF. */
23799 gen_variant_part (tree variant_part_decl
, struct vlr_context
*vlr_ctx
,
23800 dw_die_ref context_die
)
23802 const tree variant_part_type
= TREE_TYPE (variant_part_decl
);
23803 tree variant_part_offset
= vlr_ctx
->variant_part_offset
;
23804 struct loc_descr_context ctx
= {
23805 vlr_ctx
->struct_type
, /* context_type */
23806 NULL_TREE
, /* base_decl */
23808 false, /* placeholder_arg */
23809 false /* placeholder_seen */
23812 /* The FIELD_DECL node in STRUCT_TYPE that acts as the discriminant, or
23813 NULL_TREE if there is no such field. */
23814 tree discr_decl
= NULL_TREE
;
23815 dw_discr_list_ref
*discr_lists
;
23816 unsigned discr_lists_length
= 0;
23819 dw_die_ref dwarf_proc_die
= NULL
;
23820 dw_die_ref variant_part_die
23821 = new_die (DW_TAG_variant_part
, context_die
, variant_part_type
);
23823 equate_decl_number_to_die (variant_part_decl
, variant_part_die
);
23825 analyze_variants_discr (variant_part_decl
, vlr_ctx
->struct_type
,
23826 &discr_decl
, &discr_lists
, &discr_lists_length
);
23828 if (discr_decl
!= NULL_TREE
)
23830 dw_die_ref discr_die
= lookup_decl_die (discr_decl
);
23833 add_AT_die_ref (variant_part_die
, DW_AT_discr
, discr_die
);
23835 /* We have no DIE for the discriminant, so just discard all
23836 discrimimant information in the output. */
23837 discr_decl
= NULL_TREE
;
23840 /* If the offset for this variant part is more complex than a constant,
23841 create a DWARF procedure for it so that we will not have to generate DWARF
23842 expressions for it for each member. */
23843 if (TREE_CODE (variant_part_offset
) != INTEGER_CST
23844 && (dwarf_version
>= 3 || !dwarf_strict
))
23846 const tree dwarf_proc_fndecl
23847 = build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, NULL_TREE
,
23848 build_function_type (TREE_TYPE (variant_part_offset
),
23850 const tree dwarf_proc_call
= build_call_expr (dwarf_proc_fndecl
, 0);
23851 const dw_loc_descr_ref dwarf_proc_body
23852 = loc_descriptor_from_tree (variant_part_offset
, 0, &ctx
);
23854 dwarf_proc_die
= new_dwarf_proc_die (dwarf_proc_body
,
23855 dwarf_proc_fndecl
, context_die
);
23856 if (dwarf_proc_die
!= NULL
)
23857 variant_part_offset
= dwarf_proc_call
;
23860 /* Output DIEs for all variants. */
23862 for (tree variant
= TYPE_FIELDS (variant_part_type
);
23863 variant
!= NULL_TREE
;
23864 variant
= DECL_CHAIN (variant
), ++i
)
23866 tree variant_type
= TREE_TYPE (variant
);
23867 dw_die_ref variant_die
;
23869 /* All variants (i.e. members of a variant part) are supposed to be
23870 encoded as structures. Sub-variant parts are QUAL_UNION_TYPE fields
23871 under these records. */
23872 gcc_assert (TREE_CODE (variant_type
) == RECORD_TYPE
);
23874 variant_die
= new_die (DW_TAG_variant
, variant_part_die
, variant_type
);
23875 equate_decl_number_to_die (variant
, variant_die
);
23877 /* Output discriminant values this variant matches, if any. */
23878 if (discr_decl
== NULL
|| discr_lists
[i
] == NULL
)
23879 /* In the case we have discriminant information at all, this is
23880 probably the default variant: as the standard says, don't
23881 output any discriminant value/list attribute. */
23883 else if (discr_lists
[i
]->dw_discr_next
== NULL
23884 && !discr_lists
[i
]->dw_discr_range
)
23885 /* If there is only one accepted value, don't bother outputting a
23887 add_discr_value (variant_die
, &discr_lists
[i
]->dw_discr_lower_bound
);
23889 add_discr_list (variant_die
, discr_lists
[i
]);
23891 for (tree member
= TYPE_FIELDS (variant_type
);
23892 member
!= NULL_TREE
;
23893 member
= DECL_CHAIN (member
))
23895 struct vlr_context vlr_sub_ctx
= {
23896 vlr_ctx
->struct_type
, /* struct_type */
23897 NULL
/* variant_part_offset */
23899 if (is_variant_part (member
))
23901 /* All offsets for fields inside variant parts are relative to
23902 the top-level embedding RECORD_TYPE's base address. On the
23903 other hand, offsets in GCC's types are relative to the
23904 nested-most variant part. So we have to sum offsets each time
23907 vlr_sub_ctx
.variant_part_offset
23908 = fold (build2 (PLUS_EXPR
, TREE_TYPE (variant_part_offset
),
23909 variant_part_offset
, byte_position (member
)));
23910 gen_variant_part (member
, &vlr_sub_ctx
, variant_die
);
23914 vlr_sub_ctx
.variant_part_offset
= variant_part_offset
;
23915 gen_decl_die (member
, NULL
, &vlr_sub_ctx
, variant_die
);
23920 free (discr_lists
);
23923 /* Generate a DIE for a class member. */
23926 gen_member_die (tree type
, dw_die_ref context_die
)
23929 tree binfo
= TYPE_BINFO (type
);
23932 /* If this is not an incomplete type, output descriptions of each of its
23933 members. Note that as we output the DIEs necessary to represent the
23934 members of this record or union type, we will also be trying to output
23935 DIEs to represent the *types* of those members. However the `type'
23936 function (above) will specifically avoid generating type DIEs for member
23937 types *within* the list of member DIEs for this (containing) type except
23938 for those types (of members) which are explicitly marked as also being
23939 members of this (containing) type themselves. The g++ front- end can
23940 force any given type to be treated as a member of some other (containing)
23941 type by setting the TYPE_CONTEXT of the given (member) type to point to
23942 the TREE node representing the appropriate (containing) type. */
23944 /* First output info about the base classes. */
23947 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
23951 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
23952 gen_inheritance_die (base
,
23953 (accesses
? (*accesses
)[i
] : access_public_node
),
23958 /* Now output info about the data members and type members. */
23959 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
23961 struct vlr_context vlr_ctx
= { type
, NULL_TREE
};
23963 /* If we thought we were generating minimal debug info for TYPE
23964 and then changed our minds, some of the member declarations
23965 may have already been defined. Don't define them again, but
23966 do put them in the right order. */
23968 child
= lookup_decl_die (member
);
23971 /* Handle inline static data members, which only have in-class
23973 if (child
->die_tag
== DW_TAG_variable
23974 && child
->die_parent
== comp_unit_die ()
23975 && get_AT (child
, DW_AT_specification
) == NULL
)
23977 reparent_child (child
, context_die
);
23978 child
->die_tag
= DW_TAG_member
;
23981 splice_child_die (context_die
, child
);
23984 /* Do not generate standard DWARF for variant parts if we are generating
23985 the corresponding GNAT encodings: DIEs generated for both would
23986 conflict in our mappings. */
23987 else if (is_variant_part (member
)
23988 && gnat_encodings
== DWARF_GNAT_ENCODINGS_MINIMAL
)
23990 vlr_ctx
.variant_part_offset
= byte_position (member
);
23991 gen_variant_part (member
, &vlr_ctx
, context_die
);
23995 vlr_ctx
.variant_part_offset
= NULL_TREE
;
23996 gen_decl_die (member
, NULL
, &vlr_ctx
, context_die
);
23999 /* For C++ inline static data members emit immediately a DW_TAG_variable
24000 DIE that will refer to that DW_TAG_member through
24001 DW_AT_specification. */
24002 if (TREE_STATIC (member
)
24003 && (lang_hooks
.decls
.decl_dwarf_attribute (member
, DW_AT_inline
)
24006 int old_extern
= DECL_EXTERNAL (member
);
24007 DECL_EXTERNAL (member
) = 0;
24008 gen_decl_die (member
, NULL
, NULL
, comp_unit_die ());
24009 DECL_EXTERNAL (member
) = old_extern
;
24013 /* We do not keep type methods in type variants. */
24014 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
24015 /* Now output info about the function members (if any). */
24016 if (TYPE_METHODS (type
) != error_mark_node
)
24017 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
24019 /* Don't include clones in the member list. */
24020 if (DECL_ABSTRACT_ORIGIN (member
))
24022 /* Nor constructors for anonymous classes. */
24023 if (DECL_ARTIFICIAL (member
)
24024 && dwarf2_name (member
, 0) == NULL
)
24027 child
= lookup_decl_die (member
);
24029 splice_child_die (context_die
, child
);
24031 gen_decl_die (member
, NULL
, NULL
, context_die
);
24035 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
24036 is set, we pretend that the type was never defined, so we only get the
24037 member DIEs needed by later specification DIEs. */
24040 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
24041 enum debug_info_usage usage
)
24043 if (TREE_ASM_WRITTEN (type
))
24045 /* Fill in the bound of variable-length fields in late dwarf if
24046 still incomplete. */
24047 if (!early_dwarf
&& variably_modified_type_p (type
, NULL
))
24048 for (tree member
= TYPE_FIELDS (type
);
24050 member
= DECL_CHAIN (member
))
24051 fill_variable_array_bounds (TREE_TYPE (member
));
24055 dw_die_ref type_die
= lookup_type_die (type
);
24056 dw_die_ref scope_die
= 0;
24058 int complete
= (TYPE_SIZE (type
)
24059 && (! TYPE_STUB_DECL (type
)
24060 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
24061 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
24062 complete
= complete
&& should_emit_struct_debug (type
, usage
);
24064 if (type_die
&& ! complete
)
24067 if (TYPE_CONTEXT (type
) != NULL_TREE
24068 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
24069 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
24072 scope_die
= scope_die_for (type
, context_die
);
24074 /* Generate child dies for template paramaters. */
24075 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
24076 schedule_generic_params_dies_gen (type
);
24078 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
24079 /* First occurrence of type or toplevel definition of nested class. */
24081 dw_die_ref old_die
= type_die
;
24083 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
24084 ? record_type_tag (type
) : DW_TAG_union_type
,
24086 equate_type_number_to_die (type
, type_die
);
24088 add_AT_specification (type_die
, old_die
);
24090 add_name_attribute (type_die
, type_tag (type
));
24093 remove_AT (type_die
, DW_AT_declaration
);
24095 /* If this type has been completed, then give it a byte_size attribute and
24096 then give a list of members. */
24097 if (complete
&& !ns_decl
)
24099 /* Prevent infinite recursion in cases where the type of some member of
24100 this type is expressed in terms of this type itself. */
24101 TREE_ASM_WRITTEN (type
) = 1;
24102 add_byte_size_attribute (type_die
, type
);
24103 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
24105 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
24106 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
24109 /* If the first reference to this type was as the return type of an
24110 inline function, then it may not have a parent. Fix this now. */
24111 if (type_die
->die_parent
== NULL
)
24112 add_child_die (scope_die
, type_die
);
24114 push_decl_scope (type
);
24115 gen_member_die (type
, type_die
);
24118 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
24119 if (TYPE_ARTIFICIAL (type
))
24120 add_AT_flag (type_die
, DW_AT_artificial
, 1);
24122 /* GNU extension: Record what type our vtable lives in. */
24123 if (TYPE_VFIELD (type
))
24125 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
24127 gen_type_die (vtype
, context_die
);
24128 add_AT_die_ref (type_die
, DW_AT_containing_type
,
24129 lookup_type_die (vtype
));
24134 add_AT_flag (type_die
, DW_AT_declaration
, 1);
24136 /* We don't need to do this for function-local types. */
24137 if (TYPE_STUB_DECL (type
)
24138 && ! decl_function_context (TYPE_STUB_DECL (type
)))
24139 vec_safe_push (incomplete_types
, type
);
24142 if (get_AT (type_die
, DW_AT_name
))
24143 add_pubtype (type
, type_die
);
24146 /* Generate a DIE for a subroutine _type_. */
24149 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
24151 tree return_type
= TREE_TYPE (type
);
24152 dw_die_ref subr_die
24153 = new_die (DW_TAG_subroutine_type
,
24154 scope_die_for (type
, context_die
), type
);
24156 equate_type_number_to_die (type
, subr_die
);
24157 add_prototyped_attribute (subr_die
, type
);
24158 add_type_attribute (subr_die
, return_type
, TYPE_UNQUALIFIED
, false,
24160 gen_formal_types_die (type
, subr_die
);
24162 if (get_AT (subr_die
, DW_AT_name
))
24163 add_pubtype (type
, subr_die
);
24164 if ((dwarf_version
>= 5 || !dwarf_strict
)
24165 && lang_hooks
.types
.type_dwarf_attribute (type
, DW_AT_reference
) != -1)
24166 add_AT_flag (subr_die
, DW_AT_reference
, 1);
24167 if ((dwarf_version
>= 5 || !dwarf_strict
)
24168 && lang_hooks
.types
.type_dwarf_attribute (type
,
24169 DW_AT_rvalue_reference
) != -1)
24170 add_AT_flag (subr_die
, DW_AT_rvalue_reference
, 1);
24173 /* Generate a DIE for a type definition. */
24176 gen_typedef_die (tree decl
, dw_die_ref context_die
)
24178 dw_die_ref type_die
;
24181 if (TREE_ASM_WRITTEN (decl
))
24183 if (DECL_ORIGINAL_TYPE (decl
))
24184 fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl
));
24188 TREE_ASM_WRITTEN (decl
) = 1;
24189 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
24190 origin
= decl_ultimate_origin (decl
);
24191 if (origin
!= NULL
)
24192 add_abstract_origin_attribute (type_die
, origin
);
24197 add_name_and_src_coords_attributes (type_die
, decl
);
24198 if (DECL_ORIGINAL_TYPE (decl
))
24200 type
= DECL_ORIGINAL_TYPE (decl
);
24202 if (type
== error_mark_node
)
24205 gcc_assert (type
!= TREE_TYPE (decl
));
24206 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
24210 type
= TREE_TYPE (decl
);
24212 if (type
== error_mark_node
)
24215 if (is_naming_typedef_decl (TYPE_NAME (type
)))
24217 /* Here, we are in the case of decl being a typedef naming
24218 an anonymous type, e.g:
24219 typedef struct {...} foo;
24220 In that case TREE_TYPE (decl) is not a typedef variant
24221 type and TYPE_NAME of the anonymous type is set to the
24222 TYPE_DECL of the typedef. This construct is emitted by
24225 TYPE is the anonymous struct named by the typedef
24226 DECL. As we need the DW_AT_type attribute of the
24227 DW_TAG_typedef to point to the DIE of TYPE, let's
24228 generate that DIE right away. add_type_attribute
24229 called below will then pick (via lookup_type_die) that
24230 anonymous struct DIE. */
24231 if (!TREE_ASM_WRITTEN (type
))
24232 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
24234 /* This is a GNU Extension. We are adding a
24235 DW_AT_linkage_name attribute to the DIE of the
24236 anonymous struct TYPE. The value of that attribute
24237 is the name of the typedef decl naming the anonymous
24238 struct. This greatly eases the work of consumers of
24239 this debug info. */
24240 add_linkage_name_raw (lookup_type_die (type
), decl
);
24244 add_type_attribute (type_die
, type
, decl_quals (decl
), false,
24247 if (is_naming_typedef_decl (decl
))
24248 /* We want that all subsequent calls to lookup_type_die with
24249 TYPE in argument yield the DW_TAG_typedef we have just
24251 equate_type_number_to_die (type
, type_die
);
24253 add_accessibility_attribute (type_die
, decl
);
24256 if (DECL_ABSTRACT_P (decl
))
24257 equate_decl_number_to_die (decl
, type_die
);
24259 if (get_AT (type_die
, DW_AT_name
))
24260 add_pubtype (decl
, type_die
);
24263 /* Generate a DIE for a struct, class, enum or union type. */
24266 gen_tagged_type_die (tree type
,
24267 dw_die_ref context_die
,
24268 enum debug_info_usage usage
)
24272 if (type
== NULL_TREE
24273 || !is_tagged_type (type
))
24276 if (TREE_ASM_WRITTEN (type
))
24278 /* If this is a nested type whose containing class hasn't been written
24279 out yet, writing it out will cover this one, too. This does not apply
24280 to instantiations of member class templates; they need to be added to
24281 the containing class as they are generated. FIXME: This hurts the
24282 idea of combining type decls from multiple TUs, since we can't predict
24283 what set of template instantiations we'll get. */
24284 else if (TYPE_CONTEXT (type
)
24285 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
24286 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
24288 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
24290 if (TREE_ASM_WRITTEN (type
))
24293 /* If that failed, attach ourselves to the stub. */
24294 push_decl_scope (TYPE_CONTEXT (type
));
24295 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
24298 else if (TYPE_CONTEXT (type
) != NULL_TREE
24299 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
24301 /* If this type is local to a function that hasn't been written
24302 out yet, use a NULL context for now; it will be fixed up in
24303 decls_for_scope. */
24304 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
24305 /* A declaration DIE doesn't count; nested types need to go in the
24307 if (context_die
&& is_declaration_die (context_die
))
24308 context_die
= NULL
;
24313 context_die
= declare_in_namespace (type
, context_die
);
24317 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
24319 /* This might have been written out by the call to
24320 declare_in_namespace. */
24321 if (!TREE_ASM_WRITTEN (type
))
24322 gen_enumeration_type_die (type
, context_die
);
24325 gen_struct_or_union_type_die (type
, context_die
, usage
);
24330 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
24331 it up if it is ever completed. gen_*_type_die will set it for us
24332 when appropriate. */
24335 /* Generate a type description DIE. */
24338 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
24339 enum debug_info_usage usage
)
24341 struct array_descr_info info
;
24343 if (type
== NULL_TREE
|| type
== error_mark_node
)
24346 if (flag_checking
&& type
)
24347 verify_type (type
);
24349 if (TYPE_NAME (type
) != NULL_TREE
24350 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
24351 && is_redundant_typedef (TYPE_NAME (type
))
24352 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
24353 /* The DECL of this type is a typedef we don't want to emit debug
24354 info for but we want debug info for its underlying typedef.
24355 This can happen for e.g, the injected-class-name of a C++
24357 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
24359 /* If TYPE is a typedef type variant, let's generate debug info
24360 for the parent typedef which TYPE is a type of. */
24361 if (typedef_variant_p (type
))
24363 if (TREE_ASM_WRITTEN (type
))
24366 /* Prevent broken recursion; we can't hand off to the same type. */
24367 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
24369 /* Give typedefs the right scope. */
24370 context_die
= scope_die_for (type
, context_die
);
24372 TREE_ASM_WRITTEN (type
) = 1;
24374 gen_decl_die (TYPE_NAME (type
), NULL
, NULL
, context_die
);
24378 /* If type is an anonymous tagged type named by a typedef, let's
24379 generate debug info for the typedef. */
24380 if (is_naming_typedef_decl (TYPE_NAME (type
)))
24382 /* Use the DIE of the containing namespace as the parent DIE of
24383 the type description DIE we want to generate. */
24384 if (DECL_CONTEXT (TYPE_NAME (type
))
24385 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
24386 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
24388 gen_decl_die (TYPE_NAME (type
), NULL
, NULL
, context_die
);
24392 if (lang_hooks
.types
.get_debug_type
)
24394 tree debug_type
= lang_hooks
.types
.get_debug_type (type
);
24396 if (debug_type
!= NULL_TREE
&& debug_type
!= type
)
24398 gen_type_die_with_usage (debug_type
, context_die
, usage
);
24403 /* We are going to output a DIE to represent the unqualified version
24404 of this type (i.e. without any const or volatile qualifiers) so
24405 get the main variant (i.e. the unqualified version) of this type
24406 now. (Vectors and arrays are special because the debugging info is in the
24407 cloned type itself. Similarly function/method types can contain extra
24408 ref-qualification). */
24409 if (TREE_CODE (type
) == FUNCTION_TYPE
24410 || TREE_CODE (type
) == METHOD_TYPE
)
24412 /* For function/method types, can't use type_main_variant here,
24413 because that can have different ref-qualifiers for C++,
24414 but try to canonicalize. */
24415 tree main
= TYPE_MAIN_VARIANT (type
);
24416 for (tree t
= main
; t
; t
= TYPE_NEXT_VARIANT (t
))
24417 if (check_base_type (t
, main
) && check_lang_type (t
, type
))
24420 else if (TREE_CODE (type
) != VECTOR_TYPE
24421 && TREE_CODE (type
) != ARRAY_TYPE
)
24422 type
= type_main_variant (type
);
24424 /* If this is an array type with hidden descriptor, handle it first. */
24425 if (!TREE_ASM_WRITTEN (type
)
24426 && lang_hooks
.types
.get_array_descr_info
)
24428 memset (&info
, 0, sizeof (info
));
24429 if (lang_hooks
.types
.get_array_descr_info (type
, &info
))
24431 /* Fortran sometimes emits array types with no dimension. */
24432 gcc_assert (info
.ndimensions
>= 0
24433 && (info
.ndimensions
24434 <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN
));
24435 gen_descr_array_type_die (type
, &info
, context_die
);
24436 TREE_ASM_WRITTEN (type
) = 1;
24441 if (TREE_ASM_WRITTEN (type
))
24443 /* Variable-length types may be incomplete even if
24444 TREE_ASM_WRITTEN. For such types, fall through to
24445 gen_array_type_die() and possibly fill in
24446 DW_AT_{upper,lower}_bound attributes. */
24447 if ((TREE_CODE (type
) != ARRAY_TYPE
24448 && TREE_CODE (type
) != RECORD_TYPE
24449 && TREE_CODE (type
) != UNION_TYPE
24450 && TREE_CODE (type
) != QUAL_UNION_TYPE
)
24451 || !variably_modified_type_p (type
, NULL
))
24455 switch (TREE_CODE (type
))
24461 case REFERENCE_TYPE
:
24462 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
24463 ensures that the gen_type_die recursion will terminate even if the
24464 type is recursive. Recursive types are possible in Ada. */
24465 /* ??? We could perhaps do this for all types before the switch
24467 TREE_ASM_WRITTEN (type
) = 1;
24469 /* For these types, all that is required is that we output a DIE (or a
24470 set of DIEs) to represent the "basis" type. */
24471 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24472 DINFO_USAGE_IND_USE
);
24476 /* This code is used for C++ pointer-to-data-member types.
24477 Output a description of the relevant class type. */
24478 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
24479 DINFO_USAGE_IND_USE
);
24481 /* Output a description of the type of the object pointed to. */
24482 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24483 DINFO_USAGE_IND_USE
);
24485 /* Now output a DIE to represent this pointer-to-data-member type
24487 gen_ptr_to_mbr_type_die (type
, context_die
);
24490 case FUNCTION_TYPE
:
24491 /* Force out return type (in case it wasn't forced out already). */
24492 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24493 DINFO_USAGE_DIR_USE
);
24494 gen_subroutine_type_die (type
, context_die
);
24498 /* Force out return type (in case it wasn't forced out already). */
24499 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
24500 DINFO_USAGE_DIR_USE
);
24501 gen_subroutine_type_die (type
, context_die
);
24506 gen_array_type_die (type
, context_die
);
24509 case ENUMERAL_TYPE
:
24512 case QUAL_UNION_TYPE
:
24513 gen_tagged_type_die (type
, context_die
, usage
);
24519 case FIXED_POINT_TYPE
:
24522 case POINTER_BOUNDS_TYPE
:
24523 /* No DIEs needed for fundamental types. */
24528 /* Just use DW_TAG_unspecified_type. */
24530 dw_die_ref type_die
= lookup_type_die (type
);
24531 if (type_die
== NULL
)
24533 tree name
= TYPE_IDENTIFIER (type
);
24534 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (),
24536 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
24537 equate_type_number_to_die (type
, type_die
);
24543 if (is_cxx_auto (type
))
24545 tree name
= TYPE_IDENTIFIER (type
);
24546 dw_die_ref
*die
= (name
== get_identifier ("auto")
24547 ? &auto_die
: &decltype_auto_die
);
24550 *die
= new_die (DW_TAG_unspecified_type
,
24551 comp_unit_die (), NULL_TREE
);
24552 add_name_attribute (*die
, IDENTIFIER_POINTER (name
));
24554 equate_type_number_to_die (type
, *die
);
24557 gcc_unreachable ();
24560 TREE_ASM_WRITTEN (type
) = 1;
24564 gen_type_die (tree type
, dw_die_ref context_die
)
24566 if (type
!= error_mark_node
)
24568 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
24571 dw_die_ref die
= lookup_type_die (type
);
24578 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
24579 things which are local to the given block. */
24582 gen_block_die (tree stmt
, dw_die_ref context_die
)
24584 int must_output_die
= 0;
24587 /* Ignore blocks that are NULL. */
24588 if (stmt
== NULL_TREE
)
24591 inlined_func
= inlined_function_outer_scope_p (stmt
);
24593 /* If the block is one fragment of a non-contiguous block, do not
24594 process the variables, since they will have been done by the
24595 origin block. Do process subblocks. */
24596 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
24600 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
24601 gen_block_die (sub
, context_die
);
24606 /* Determine if we need to output any Dwarf DIEs at all to represent this
24609 /* The outer scopes for inlinings *must* always be represented. We
24610 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
24611 must_output_die
= 1;
24614 /* Determine if this block directly contains any "significant"
24615 local declarations which we will need to output DIEs for. */
24616 if (debug_info_level
> DINFO_LEVEL_TERSE
)
24617 /* We are not in terse mode so *any* local declaration counts
24618 as being a "significant" one. */
24619 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
24620 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
24621 && (TREE_USED (stmt
)
24622 || TREE_ASM_WRITTEN (stmt
)
24623 || BLOCK_ABSTRACT (stmt
)));
24624 else if ((TREE_USED (stmt
)
24625 || TREE_ASM_WRITTEN (stmt
)
24626 || BLOCK_ABSTRACT (stmt
))
24627 && !dwarf2out_ignore_block (stmt
))
24628 must_output_die
= 1;
24631 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
24632 DIE for any block which contains no significant local declarations at
24633 all. Rather, in such cases we just call `decls_for_scope' so that any
24634 needed Dwarf info for any sub-blocks will get properly generated. Note
24635 that in terse mode, our definition of what constitutes a "significant"
24636 local declaration gets restricted to include only inlined function
24637 instances and local (nested) function definitions. */
24638 if (must_output_die
)
24642 /* If STMT block is abstract, that means we have been called
24643 indirectly from dwarf2out_abstract_function.
24644 That function rightfully marks the descendent blocks (of
24645 the abstract function it is dealing with) as being abstract,
24646 precisely to prevent us from emitting any
24647 DW_TAG_inlined_subroutine DIE as a descendent
24648 of an abstract function instance. So in that case, we should
24649 not call gen_inlined_subroutine_die.
24651 Later though, when cgraph asks dwarf2out to emit info
24652 for the concrete instance of the function decl into which
24653 the concrete instance of STMT got inlined, the later will lead
24654 to the generation of a DW_TAG_inlined_subroutine DIE. */
24655 if (! BLOCK_ABSTRACT (stmt
))
24656 gen_inlined_subroutine_die (stmt
, context_die
);
24659 gen_lexical_block_die (stmt
, context_die
);
24662 decls_for_scope (stmt
, context_die
);
24665 /* Process variable DECL (or variable with origin ORIGIN) within
24666 block STMT and add it to CONTEXT_DIE. */
24668 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
24671 tree decl_or_origin
= decl
? decl
: origin
;
24673 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
24674 die
= lookup_decl_die (decl_or_origin
);
24675 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
)
24677 if (TYPE_DECL_IS_STUB (decl_or_origin
))
24678 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
24680 die
= lookup_decl_die (decl_or_origin
);
24681 /* Avoid re-creating the DIE late if it was optimized as unused early. */
24682 if (! die
&& ! early_dwarf
)
24688 if (die
!= NULL
&& die
->die_parent
== NULL
)
24689 add_child_die (context_die
, die
);
24690 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
24693 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
24694 stmt
, context_die
);
24697 gen_decl_die (decl
, origin
, NULL
, context_die
);
24700 /* Generate all of the decls declared within a given scope and (recursively)
24701 all of its sub-blocks. */
24704 decls_for_scope (tree stmt
, dw_die_ref context_die
)
24710 /* Ignore NULL blocks. */
24711 if (stmt
== NULL_TREE
)
24714 /* Output the DIEs to represent all of the data objects and typedefs
24715 declared directly within this block but not within any nested
24716 sub-blocks. Also, nested function and tag DIEs have been
24717 generated with a parent of NULL; fix that up now. We don't
24718 have to do this if we're at -g1. */
24719 if (debug_info_level
> DINFO_LEVEL_TERSE
)
24721 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
24722 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
24723 /* BLOCK_NONLOCALIZED_VARs simply generate DIE stubs with abstract
24724 origin - avoid doing this twice as we have no good way to see
24725 if we've done it once already. */
24727 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
24728 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
24732 /* Even if we're at -g1, we need to process the subblocks in order to get
24733 inlined call information. */
24735 /* Output the DIEs to represent all sub-blocks (and the items declared
24736 therein) of this block. */
24737 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
24739 subblocks
= BLOCK_CHAIN (subblocks
))
24740 gen_block_die (subblocks
, context_die
);
24743 /* Is this a typedef we can avoid emitting? */
24746 is_redundant_typedef (const_tree decl
)
24748 if (TYPE_DECL_IS_STUB (decl
))
24751 if (DECL_ARTIFICIAL (decl
)
24752 && DECL_CONTEXT (decl
)
24753 && is_tagged_type (DECL_CONTEXT (decl
))
24754 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
24755 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
24756 /* Also ignore the artificial member typedef for the class name. */
24762 /* Return TRUE if TYPE is a typedef that names a type for linkage
24763 purposes. This kind of typedefs is produced by the C++ FE for
24766 typedef struct {...} foo;
24768 In that case, there is no typedef variant type produced for foo.
24769 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
24773 is_naming_typedef_decl (const_tree decl
)
24775 if (decl
== NULL_TREE
24776 || TREE_CODE (decl
) != TYPE_DECL
24777 || DECL_NAMELESS (decl
)
24778 || !is_tagged_type (TREE_TYPE (decl
))
24779 || DECL_IS_BUILTIN (decl
)
24780 || is_redundant_typedef (decl
)
24781 /* It looks like Ada produces TYPE_DECLs that are very similar
24782 to C++ naming typedefs but that have different
24783 semantics. Let's be specific to c++ for now. */
24787 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
24788 && TYPE_NAME (TREE_TYPE (decl
)) == decl
24789 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
24790 != TYPE_NAME (TREE_TYPE (decl
))));
24793 /* Looks up the DIE for a context. */
24795 static inline dw_die_ref
24796 lookup_context_die (tree context
)
24800 /* Find die that represents this context. */
24801 if (TYPE_P (context
))
24803 context
= TYPE_MAIN_VARIANT (context
);
24804 dw_die_ref ctx
= lookup_type_die (context
);
24807 return strip_naming_typedef (context
, ctx
);
24810 return lookup_decl_die (context
);
24812 return comp_unit_die ();
24815 /* Returns the DIE for a context. */
24817 static inline dw_die_ref
24818 get_context_die (tree context
)
24822 /* Find die that represents this context. */
24823 if (TYPE_P (context
))
24825 context
= TYPE_MAIN_VARIANT (context
);
24826 return strip_naming_typedef (context
, force_type_die (context
));
24829 return force_decl_die (context
);
24831 return comp_unit_die ();
24834 /* Returns the DIE for decl. A DIE will always be returned. */
24837 force_decl_die (tree decl
)
24839 dw_die_ref decl_die
;
24840 unsigned saved_external_flag
;
24841 tree save_fn
= NULL_TREE
;
24842 decl_die
= lookup_decl_die (decl
);
24845 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
24847 decl_die
= lookup_decl_die (decl
);
24851 switch (TREE_CODE (decl
))
24853 case FUNCTION_DECL
:
24854 /* Clear current_function_decl, so that gen_subprogram_die thinks
24855 that this is a declaration. At this point, we just want to force
24856 declaration die. */
24857 save_fn
= current_function_decl
;
24858 current_function_decl
= NULL_TREE
;
24859 gen_subprogram_die (decl
, context_die
);
24860 current_function_decl
= save_fn
;
24864 /* Set external flag to force declaration die. Restore it after
24865 gen_decl_die() call. */
24866 saved_external_flag
= DECL_EXTERNAL (decl
);
24867 DECL_EXTERNAL (decl
) = 1;
24868 gen_decl_die (decl
, NULL
, NULL
, context_die
);
24869 DECL_EXTERNAL (decl
) = saved_external_flag
;
24872 case NAMESPACE_DECL
:
24873 if (dwarf_version
>= 3 || !dwarf_strict
)
24874 dwarf2out_decl (decl
);
24876 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
24877 decl_die
= comp_unit_die ();
24880 case TRANSLATION_UNIT_DECL
:
24881 decl_die
= comp_unit_die ();
24885 gcc_unreachable ();
24888 /* We should be able to find the DIE now. */
24890 decl_die
= lookup_decl_die (decl
);
24891 gcc_assert (decl_die
);
24897 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
24898 always returned. */
24901 force_type_die (tree type
)
24903 dw_die_ref type_die
;
24905 type_die
= lookup_type_die (type
);
24908 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
24910 type_die
= modified_type_die (type
, TYPE_QUALS_NO_ADDR_SPACE (type
),
24911 false, context_die
);
24912 gcc_assert (type_die
);
24917 /* Force out any required namespaces to be able to output DECL,
24918 and return the new context_die for it, if it's changed. */
24921 setup_namespace_context (tree thing
, dw_die_ref context_die
)
24923 tree context
= (DECL_P (thing
)
24924 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
24925 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
24926 /* Force out the namespace. */
24927 context_die
= force_decl_die (context
);
24929 return context_die
;
24932 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
24933 type) within its namespace, if appropriate.
24935 For compatibility with older debuggers, namespace DIEs only contain
24936 declarations; all definitions are emitted at CU scope, with
24937 DW_AT_specification pointing to the declaration (like with class
24941 declare_in_namespace (tree thing
, dw_die_ref context_die
)
24943 dw_die_ref ns_context
;
24945 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
24946 return context_die
;
24948 /* External declarations in the local scope only need to be emitted
24949 once, not once in the namespace and once in the scope.
24951 This avoids declaring the `extern' below in the
24952 namespace DIE as well as in the innermost scope:
24965 if (DECL_P (thing
) && DECL_EXTERNAL (thing
) && local_scope_p (context_die
))
24966 return context_die
;
24968 /* If this decl is from an inlined function, then don't try to emit it in its
24969 namespace, as we will get confused. It would have already been emitted
24970 when the abstract instance of the inline function was emitted anyways. */
24971 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
24972 return context_die
;
24974 ns_context
= setup_namespace_context (thing
, context_die
);
24976 if (ns_context
!= context_die
)
24980 if (DECL_P (thing
))
24981 gen_decl_die (thing
, NULL
, NULL
, ns_context
);
24983 gen_type_die (thing
, ns_context
);
24985 return context_die
;
24988 /* Generate a DIE for a namespace or namespace alias. */
24991 gen_namespace_die (tree decl
, dw_die_ref context_die
)
24993 dw_die_ref namespace_die
;
24995 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
24996 they are an alias of. */
24997 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
24999 /* Output a real namespace or module. */
25000 context_die
= setup_namespace_context (decl
, comp_unit_die ());
25001 namespace_die
= new_die (is_fortran ()
25002 ? DW_TAG_module
: DW_TAG_namespace
,
25003 context_die
, decl
);
25004 /* For Fortran modules defined in different CU don't add src coords. */
25005 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
25007 const char *name
= dwarf2_name (decl
, 0);
25009 add_name_attribute (namespace_die
, name
);
25012 add_name_and_src_coords_attributes (namespace_die
, decl
);
25013 if (DECL_EXTERNAL (decl
))
25014 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
25015 equate_decl_number_to_die (decl
, namespace_die
);
25019 /* Output a namespace alias. */
25021 /* Force out the namespace we are an alias of, if necessary. */
25022 dw_die_ref origin_die
25023 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
25025 if (DECL_FILE_SCOPE_P (decl
)
25026 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
25027 context_die
= setup_namespace_context (decl
, comp_unit_die ());
25028 /* Now create the namespace alias DIE. */
25029 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
25030 add_name_and_src_coords_attributes (namespace_die
, decl
);
25031 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
25032 equate_decl_number_to_die (decl
, namespace_die
);
25034 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
25035 if (want_pubnames ())
25036 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
25039 /* Generate Dwarf debug information for a decl described by DECL.
25040 The return value is currently only meaningful for PARM_DECLs,
25041 for all other decls it returns NULL.
25043 If DECL is a FIELD_DECL, CTX is required: see the comment for VLR_CONTEXT.
25044 It can be NULL otherwise. */
25047 gen_decl_die (tree decl
, tree origin
, struct vlr_context
*ctx
,
25048 dw_die_ref context_die
)
25050 tree decl_or_origin
= decl
? decl
: origin
;
25051 tree class_origin
= NULL
, ultimate_origin
;
25053 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
25056 /* Ignore pointer bounds decls. */
25057 if (DECL_P (decl_or_origin
)
25058 && TREE_TYPE (decl_or_origin
)
25059 && POINTER_BOUNDS_P (decl_or_origin
))
25062 switch (TREE_CODE (decl_or_origin
))
25068 if (!is_fortran () && !is_ada ())
25070 /* The individual enumerators of an enum type get output when we output
25071 the Dwarf representation of the relevant enum type itself. */
25075 /* Emit its type. */
25076 gen_type_die (TREE_TYPE (decl
), context_die
);
25078 /* And its containing namespace. */
25079 context_die
= declare_in_namespace (decl
, context_die
);
25081 gen_const_die (decl
, context_die
);
25084 case FUNCTION_DECL
:
25085 /* Don't output any DIEs to represent mere function declarations,
25086 unless they are class members or explicit block externs. */
25087 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
25088 && DECL_FILE_SCOPE_P (decl_or_origin
)
25089 && (current_function_decl
== NULL_TREE
25090 || DECL_ARTIFICIAL (decl_or_origin
)))
25095 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
25096 on local redeclarations of global functions. That seems broken. */
25097 if (current_function_decl
!= decl
)
25098 /* This is only a declaration. */;
25101 /* If we're emitting a clone, emit info for the abstract instance. */
25102 if (origin
|| DECL_ORIGIN (decl
) != decl
)
25103 dwarf2out_abstract_function (origin
25104 ? DECL_ORIGIN (origin
)
25105 : DECL_ABSTRACT_ORIGIN (decl
));
25107 /* If we're emitting an out-of-line copy of an inline function,
25108 emit info for the abstract instance and set up to refer to it. */
25109 else if (cgraph_function_possibly_inlined_p (decl
)
25110 && ! DECL_ABSTRACT_P (decl
)
25111 && ! class_or_namespace_scope_p (context_die
)
25112 /* dwarf2out_abstract_function won't emit a die if this is just
25113 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
25114 that case, because that works only if we have a die. */
25115 && DECL_INITIAL (decl
) != NULL_TREE
)
25117 dwarf2out_abstract_function (decl
);
25118 set_decl_origin_self (decl
);
25121 /* Otherwise we're emitting the primary DIE for this decl. */
25122 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
25124 /* Before we describe the FUNCTION_DECL itself, make sure that we
25125 have its containing type. */
25127 origin
= decl_class_context (decl
);
25128 if (origin
!= NULL_TREE
)
25129 gen_type_die (origin
, context_die
);
25131 /* And its return type. */
25132 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
25134 /* And its virtual context. */
25135 if (DECL_VINDEX (decl
) != NULL_TREE
)
25136 gen_type_die (DECL_CONTEXT (decl
), context_die
);
25138 /* Make sure we have a member DIE for decl. */
25139 if (origin
!= NULL_TREE
)
25140 gen_type_die_for_member (origin
, decl
, context_die
);
25142 /* And its containing namespace. */
25143 context_die
= declare_in_namespace (decl
, context_die
);
25146 /* Now output a DIE to represent the function itself. */
25148 gen_subprogram_die (decl
, context_die
);
25152 /* If we are in terse mode, don't generate any DIEs to represent any
25153 actual typedefs. */
25154 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25157 /* In the special case of a TYPE_DECL node representing the declaration
25158 of some type tag, if the given TYPE_DECL is marked as having been
25159 instantiated from some other (original) TYPE_DECL node (e.g. one which
25160 was generated within the original definition of an inline function) we
25161 used to generate a special (abbreviated) DW_TAG_structure_type,
25162 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
25163 should be actually referencing those DIEs, as variable DIEs with that
25164 type would be emitted already in the abstract origin, so it was always
25165 removed during unused type prunning. Don't add anything in this
25167 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
25170 if (is_redundant_typedef (decl
))
25171 gen_type_die (TREE_TYPE (decl
), context_die
);
25173 /* Output a DIE to represent the typedef itself. */
25174 gen_typedef_die (decl
, context_die
);
25178 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
25179 gen_label_die (decl
, context_die
);
25184 /* If we are in terse mode, don't generate any DIEs to represent any
25185 variable declarations or definitions. */
25186 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25189 /* Output any DIEs that are needed to specify the type of this data
25191 if (decl_by_reference_p (decl_or_origin
))
25192 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
25194 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
25196 /* And its containing type. */
25197 class_origin
= decl_class_context (decl_or_origin
);
25198 if (class_origin
!= NULL_TREE
)
25199 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
25201 /* And its containing namespace. */
25202 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
25204 /* Now output the DIE to represent the data object itself. This gets
25205 complicated because of the possibility that the VAR_DECL really
25206 represents an inlined instance of a formal parameter for an inline
25208 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
25209 if (ultimate_origin
!= NULL_TREE
25210 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
25211 gen_formal_parameter_die (decl
, origin
,
25212 true /* Emit name attribute. */,
25215 gen_variable_die (decl
, origin
, context_die
);
25219 gcc_assert (ctx
!= NULL
&& ctx
->struct_type
!= NULL
);
25220 /* Ignore the nameless fields that are used to skip bits but handle C++
25221 anonymous unions and structs. */
25222 if (DECL_NAME (decl
) != NULL_TREE
25223 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
25224 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
25226 gen_type_die (member_declared_type (decl
), context_die
);
25227 gen_field_die (decl
, ctx
, context_die
);
25232 if (DECL_BY_REFERENCE (decl_or_origin
))
25233 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
25235 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
25236 return gen_formal_parameter_die (decl
, origin
,
25237 true /* Emit name attribute. */,
25240 case NAMESPACE_DECL
:
25241 if (dwarf_version
>= 3 || !dwarf_strict
)
25242 gen_namespace_die (decl
, context_die
);
25245 case IMPORTED_DECL
:
25246 dwarf2out_imported_module_or_decl_1 (decl
, DECL_NAME (decl
),
25247 DECL_CONTEXT (decl
), context_die
);
25250 case NAMELIST_DECL
:
25251 gen_namelist_decl (DECL_NAME (decl
), context_die
,
25252 NAMELIST_DECL_ASSOCIATED_DECL (decl
));
25256 /* Probably some frontend-internal decl. Assume we don't care. */
25257 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
25264 /* Output initial debug information for global DECL. Called at the
25265 end of the parsing process.
25267 This is the initial debug generation process. As such, the DIEs
25268 generated may be incomplete. A later debug generation pass
25269 (dwarf2out_late_global_decl) will augment the information generated
25270 in this pass (e.g., with complete location info). */
25273 dwarf2out_early_global_decl (tree decl
)
25277 /* gen_decl_die() will set DECL_ABSTRACT because
25278 cgraph_function_possibly_inlined_p() returns true. This is in
25279 turn will cause DW_AT_inline attributes to be set.
25281 This happens because at early dwarf generation, there is no
25282 cgraph information, causing cgraph_function_possibly_inlined_p()
25283 to return true. Trick cgraph_function_possibly_inlined_p()
25284 while we generate dwarf early. */
25285 bool save
= symtab
->global_info_ready
;
25286 symtab
->global_info_ready
= true;
25288 /* We don't handle TYPE_DECLs. If required, they'll be reached via
25289 other DECLs and they can point to template types or other things
25290 that dwarf2out can't handle when done via dwarf2out_decl. */
25291 if (TREE_CODE (decl
) != TYPE_DECL
25292 && TREE_CODE (decl
) != PARM_DECL
)
25294 tree save_fndecl
= current_function_decl
;
25295 if (TREE_CODE (decl
) == FUNCTION_DECL
)
25297 /* No cfun means the symbol has no body, so there's nothing
25299 if (!DECL_STRUCT_FUNCTION (decl
))
25300 goto early_decl_exit
;
25302 /* For nested functions, make sure we have DIEs for the parents first
25303 so that all nested DIEs are generated at the proper scope in the
25305 tree context
= decl_function_context (decl
);
25306 if (context
!= NULL
&& lookup_decl_die (context
) == NULL
)
25308 current_function_decl
= context
;
25309 dwarf2out_decl (context
);
25312 current_function_decl
= decl
;
25314 dwarf2out_decl (decl
);
25315 if (TREE_CODE (decl
) == FUNCTION_DECL
)
25316 current_function_decl
= save_fndecl
;
25319 symtab
->global_info_ready
= save
;
25322 /* Output debug information for global decl DECL. Called from
25323 toplev.c after compilation proper has finished. */
25326 dwarf2out_late_global_decl (tree decl
)
25328 /* Fill-in any location information we were unable to determine
25329 on the first pass. */
25330 if (VAR_P (decl
) && !POINTER_BOUNDS_P (decl
))
25332 dw_die_ref die
= lookup_decl_die (decl
);
25334 /* We have to generate early debug late for LTO. */
25335 if (! die
&& in_lto_p
)
25337 dwarf2out_decl (decl
);
25338 die
= lookup_decl_die (decl
);
25343 /* We get called via the symtab code invoking late_global_decl
25344 for symbols that are optimized out. Do not add locations
25346 varpool_node
*node
= varpool_node::get (decl
);
25347 if (! node
|| ! node
->definition
)
25348 tree_add_const_value_attribute_for_decl (die
, decl
);
25350 add_location_or_const_value_attribute (die
, decl
, false);
25355 /* Output debug information for type decl DECL. Called from toplev.c
25356 and from language front ends (to record built-in types). */
25358 dwarf2out_type_decl (tree decl
, int local
)
25363 dwarf2out_decl (decl
);
25367 /* Output debug information for imported module or decl DECL.
25368 NAME is non-NULL name in the lexical block if the decl has been renamed.
25369 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
25370 that DECL belongs to.
25371 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
25373 dwarf2out_imported_module_or_decl_1 (tree decl
,
25375 tree lexical_block
,
25376 dw_die_ref lexical_block_die
)
25378 expanded_location xloc
;
25379 dw_die_ref imported_die
= NULL
;
25380 dw_die_ref at_import_die
;
25382 if (TREE_CODE (decl
) == IMPORTED_DECL
)
25384 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
25385 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
25389 xloc
= expand_location (input_location
);
25391 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
25393 at_import_die
= force_type_die (TREE_TYPE (decl
));
25394 /* For namespace N { typedef void T; } using N::T; base_type_die
25395 returns NULL, but DW_TAG_imported_declaration requires
25396 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
25397 if (!at_import_die
)
25399 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
25400 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
25401 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
25402 gcc_assert (at_import_die
);
25407 at_import_die
= lookup_decl_die (decl
);
25408 if (!at_import_die
)
25410 /* If we're trying to avoid duplicate debug info, we may not have
25411 emitted the member decl for this field. Emit it now. */
25412 if (TREE_CODE (decl
) == FIELD_DECL
)
25414 tree type
= DECL_CONTEXT (decl
);
25416 if (TYPE_CONTEXT (type
)
25417 && TYPE_P (TYPE_CONTEXT (type
))
25418 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
25419 DINFO_USAGE_DIR_USE
))
25421 gen_type_die_for_member (type
, decl
,
25422 get_context_die (TYPE_CONTEXT (type
)));
25424 if (TREE_CODE (decl
) == NAMELIST_DECL
)
25425 at_import_die
= gen_namelist_decl (DECL_NAME (decl
),
25426 get_context_die (DECL_CONTEXT (decl
)),
25429 at_import_die
= force_decl_die (decl
);
25433 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
25435 if (dwarf_version
>= 3 || !dwarf_strict
)
25436 imported_die
= new_die (DW_TAG_imported_module
,
25443 imported_die
= new_die (DW_TAG_imported_declaration
,
25447 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
25448 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
25450 add_AT_string (imported_die
, DW_AT_name
,
25451 IDENTIFIER_POINTER (name
));
25452 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
25455 /* Output debug information for imported module or decl DECL.
25456 NAME is non-NULL name in context if the decl has been renamed.
25457 CHILD is true if decl is one of the renamed decls as part of
25458 importing whole module. */
25461 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
25464 /* dw_die_ref at_import_die; */
25465 dw_die_ref scope_die
;
25467 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25474 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
25475 We need decl DIE for reference and scope die. First, get DIE for the decl
25478 /* Get the scope die for decl context. Use comp_unit_die for global module
25479 or decl. If die is not found for non globals, force new die. */
25481 && TYPE_P (context
)
25482 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
25485 scope_die
= get_context_die (context
);
25489 /* DW_TAG_imported_module was introduced in the DWARFv3 specification, so
25490 there is nothing we can do, here. */
25491 if (dwarf_version
< 3 && dwarf_strict
)
25494 gcc_assert (scope_die
->die_child
);
25495 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
25496 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
25497 scope_die
= scope_die
->die_child
;
25500 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
25501 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
25504 /* Output debug information for namelists. */
25507 gen_namelist_decl (tree name
, dw_die_ref scope_die
, tree item_decls
)
25509 dw_die_ref nml_die
, nml_item_die
, nml_item_ref_die
;
25513 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25516 gcc_assert (scope_die
!= NULL
);
25517 nml_die
= new_die (DW_TAG_namelist
, scope_die
, NULL
);
25518 add_AT_string (nml_die
, DW_AT_name
, IDENTIFIER_POINTER (name
));
25520 /* If there are no item_decls, we have a nondefining namelist, e.g.
25521 with USE association; hence, set DW_AT_declaration. */
25522 if (item_decls
== NULL_TREE
)
25524 add_AT_flag (nml_die
, DW_AT_declaration
, 1);
25528 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls
), i
, value
)
25530 nml_item_ref_die
= lookup_decl_die (value
);
25531 if (!nml_item_ref_die
)
25532 nml_item_ref_die
= force_decl_die (value
);
25534 nml_item_die
= new_die (DW_TAG_namelist_item
, nml_die
, NULL
);
25535 add_AT_die_ref (nml_item_die
, DW_AT_namelist_items
, nml_item_ref_die
);
25541 /* Write the debugging output for DECL and return the DIE. */
25544 dwarf2out_decl (tree decl
)
25546 dw_die_ref context_die
= comp_unit_die ();
25548 switch (TREE_CODE (decl
))
25553 case FUNCTION_DECL
:
25554 /* What we would really like to do here is to filter out all mere
25555 file-scope declarations of file-scope functions which are never
25556 referenced later within this translation unit (and keep all of ones
25557 that *are* referenced later on) but we aren't clairvoyant, so we have
25558 no idea which functions will be referenced in the future (i.e. later
25559 on within the current translation unit). So here we just ignore all
25560 file-scope function declarations which are not also definitions. If
25561 and when the debugger needs to know something about these functions,
25562 it will have to hunt around and find the DWARF information associated
25563 with the definition of the function.
25565 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
25566 nodes represent definitions and which ones represent mere
25567 declarations. We have to check DECL_INITIAL instead. That's because
25568 the C front-end supports some weird semantics for "extern inline"
25569 function definitions. These can get inlined within the current
25570 translation unit (and thus, we need to generate Dwarf info for their
25571 abstract instances so that the Dwarf info for the concrete inlined
25572 instances can have something to refer to) but the compiler never
25573 generates any out-of-lines instances of such things (despite the fact
25574 that they *are* definitions).
25576 The important point is that the C front-end marks these "extern
25577 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
25578 them anyway. Note that the C++ front-end also plays some similar games
25579 for inline function definitions appearing within include files which
25580 also contain `#pragma interface' pragmas.
25582 If we are called from dwarf2out_abstract_function output a DIE
25583 anyway. We can end up here this way with early inlining and LTO
25584 where the inlined function is output in a different LTRANS unit
25586 if (DECL_INITIAL (decl
) == NULL_TREE
25587 && ! DECL_ABSTRACT_P (decl
))
25590 /* If we're a nested function, initially use a parent of NULL; if we're
25591 a plain function, this will be fixed up in decls_for_scope. If
25592 we're a method, it will be ignored, since we already have a DIE. */
25593 if (decl_function_context (decl
)
25594 /* But if we're in terse mode, we don't care about scope. */
25595 && debug_info_level
> DINFO_LEVEL_TERSE
)
25596 context_die
= NULL
;
25600 /* For local statics lookup proper context die. */
25601 if (local_function_static (decl
))
25602 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
25604 /* If we are in terse mode, don't generate any DIEs to represent any
25605 variable declarations or definitions. */
25606 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25611 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25613 if (!is_fortran () && !is_ada ())
25615 if (TREE_STATIC (decl
) && decl_function_context (decl
))
25616 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
25619 case NAMESPACE_DECL
:
25620 case IMPORTED_DECL
:
25621 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25623 if (lookup_decl_die (decl
) != NULL
)
25628 /* Don't emit stubs for types unless they are needed by other DIEs. */
25629 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
25632 /* Don't bother trying to generate any DIEs to represent any of the
25633 normal built-in types for the language we are compiling. */
25634 if (DECL_IS_BUILTIN (decl
))
25637 /* If we are in terse mode, don't generate any DIEs for types. */
25638 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
25641 /* If we're a function-scope tag, initially use a parent of NULL;
25642 this will be fixed up in decls_for_scope. */
25643 if (decl_function_context (decl
))
25644 context_die
= NULL
;
25648 case NAMELIST_DECL
:
25655 gen_decl_die (decl
, NULL
, NULL
, context_die
);
25659 dw_die_ref die
= lookup_decl_die (decl
);
25665 /* Write the debugging output for DECL. */
25668 dwarf2out_function_decl (tree decl
)
25670 dwarf2out_decl (decl
);
25671 call_arg_locations
= NULL
;
25672 call_arg_loc_last
= NULL
;
25673 call_site_count
= -1;
25674 tail_call_site_count
= -1;
25675 decl_loc_table
->empty ();
25676 cached_dw_loc_list_table
->empty ();
25679 /* Output a marker (i.e. a label) for the beginning of the generated code for
25680 a lexical block. */
25683 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
25684 unsigned int blocknum
)
25686 switch_to_section (current_function_section ());
25687 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
25690 /* Output a marker (i.e. a label) for the end of the generated code for a
25694 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
25696 switch_to_section (current_function_section ());
25697 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
25700 /* Returns nonzero if it is appropriate not to emit any debugging
25701 information for BLOCK, because it doesn't contain any instructions.
25703 Don't allow this for blocks with nested functions or local classes
25704 as we would end up with orphans, and in the presence of scheduling
25705 we may end up calling them anyway. */
25708 dwarf2out_ignore_block (const_tree block
)
25713 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
25714 if (TREE_CODE (decl
) == FUNCTION_DECL
25715 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
25717 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
25719 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
25720 if (TREE_CODE (decl
) == FUNCTION_DECL
25721 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
25728 /* Hash table routines for file_hash. */
25731 dwarf_file_hasher::equal (dwarf_file_data
*p1
, const char *p2
)
25733 return filename_cmp (p1
->filename
, p2
) == 0;
25737 dwarf_file_hasher::hash (dwarf_file_data
*p
)
25739 return htab_hash_string (p
->filename
);
25742 /* Lookup FILE_NAME (in the list of filenames that we know about here in
25743 dwarf2out.c) and return its "index". The index of each (known) filename is
25744 just a unique number which is associated with only that one filename. We
25745 need such numbers for the sake of generating labels (in the .debug_sfnames
25746 section) and references to those files numbers (in the .debug_srcinfo
25747 and .debug_macinfo sections). If the filename given as an argument is not
25748 found in our current list, add it to the list and assign it the next
25749 available unique index number. */
25751 static struct dwarf_file_data
*
25752 lookup_filename (const char *file_name
)
25754 struct dwarf_file_data
* created
;
25759 dwarf_file_data
**slot
25760 = file_table
->find_slot_with_hash (file_name
, htab_hash_string (file_name
),
25765 created
= ggc_alloc
<dwarf_file_data
> ();
25766 created
->filename
= file_name
;
25767 created
->emitted_number
= 0;
25772 /* If the assembler will construct the file table, then translate the compiler
25773 internal file table number into the assembler file table number, and emit
25774 a .file directive if we haven't already emitted one yet. The file table
25775 numbers are different because we prune debug info for unused variables and
25776 types, which may include filenames. */
25779 maybe_emit_file (struct dwarf_file_data
* fd
)
25781 if (! fd
->emitted_number
)
25783 if (last_emitted_file
)
25784 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
25786 fd
->emitted_number
= 1;
25787 last_emitted_file
= fd
;
25789 if (DWARF2_ASM_LINE_DEBUG_INFO
)
25791 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
25792 output_quoted_string (asm_out_file
,
25793 remap_debug_filename (fd
->filename
));
25794 fputc ('\n', asm_out_file
);
25798 return fd
->emitted_number
;
25801 /* Schedule generation of a DW_AT_const_value attribute to DIE.
25802 That generation should happen after function debug info has been
25803 generated. The value of the attribute is the constant value of ARG. */
25806 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
25808 die_arg_entry entry
;
25813 gcc_assert (early_dwarf
);
25815 if (!tmpl_value_parm_die_table
)
25816 vec_alloc (tmpl_value_parm_die_table
, 32);
25820 vec_safe_push (tmpl_value_parm_die_table
, entry
);
25823 /* Return TRUE if T is an instance of generic type, FALSE
25827 generic_type_p (tree t
)
25829 if (t
== NULL_TREE
|| !TYPE_P (t
))
25831 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
25834 /* Schedule the generation of the generic parameter dies for the
25835 instance of generic type T. The proper generation itself is later
25836 done by gen_scheduled_generic_parms_dies. */
25839 schedule_generic_params_dies_gen (tree t
)
25841 if (!generic_type_p (t
))
25844 gcc_assert (early_dwarf
);
25846 if (!generic_type_instances
)
25847 vec_alloc (generic_type_instances
, 256);
25849 vec_safe_push (generic_type_instances
, t
);
25852 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
25853 by append_entry_to_tmpl_value_parm_die_table. This function must
25854 be called after function DIEs have been generated. */
25857 gen_remaining_tmpl_value_param_die_attribute (void)
25859 if (tmpl_value_parm_die_table
)
25864 /* We do this in two phases - first get the cases we can
25865 handle during early-finish, preserving those we cannot
25866 (containing symbolic constants where we don't yet know
25867 whether we are going to output the referenced symbols).
25868 For those we try again at late-finish. */
25870 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
25872 if (!tree_add_const_value_attribute (e
->die
, e
->arg
))
25874 dw_loc_descr_ref loc
= NULL
;
25876 && (dwarf_version
>= 5 || !dwarf_strict
))
25877 loc
= loc_descriptor_from_tree (e
->arg
, 2, NULL
);
25879 add_AT_loc (e
->die
, DW_AT_location
, loc
);
25881 (*tmpl_value_parm_die_table
)[j
++] = *e
;
25884 tmpl_value_parm_die_table
->truncate (j
);
25888 /* Generate generic parameters DIEs for instances of generic types
25889 that have been previously scheduled by
25890 schedule_generic_params_dies_gen. This function must be called
25891 after all the types of the CU have been laid out. */
25894 gen_scheduled_generic_parms_dies (void)
25899 if (!generic_type_instances
)
25902 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
25903 if (COMPLETE_TYPE_P (t
))
25904 gen_generic_params_dies (t
);
25906 generic_type_instances
= NULL
;
25910 /* Replace DW_AT_name for the decl with name. */
25913 dwarf2out_set_name (tree decl
, tree name
)
25916 dw_attr_node
*attr
;
25919 die
= TYPE_SYMTAB_DIE (decl
);
25923 dname
= dwarf2_name (name
, 0);
25927 attr
= get_AT (die
, DW_AT_name
);
25930 struct indirect_string_node
*node
;
25932 node
= find_AT_string (dname
);
25933 /* replace the string. */
25934 attr
->dw_attr_val
.v
.val_str
= node
;
25938 add_name_attribute (die
, dname
);
25941 /* True if before or during processing of the first function being emitted. */
25942 static bool in_first_function_p
= true;
25943 /* True if loc_note during dwarf2out_var_location call might still be
25944 before first real instruction at address equal to .Ltext0. */
25945 static bool maybe_at_text_label_p
= true;
25946 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
25947 static unsigned int first_loclabel_num_not_at_text_label
;
25949 /* Called by the final INSN scan whenever we see a var location. We
25950 use it to drop labels in the right places, and throw the location in
25951 our lookup table. */
25954 dwarf2out_var_location (rtx_insn
*loc_note
)
25956 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
25957 struct var_loc_node
*newloc
;
25958 rtx_insn
*next_real
, *next_note
;
25959 rtx_insn
*call_insn
= NULL
;
25960 static const char *last_label
;
25961 static const char *last_postcall_label
;
25962 static bool last_in_cold_section_p
;
25963 static rtx_insn
*expected_next_loc_note
;
25967 if (!NOTE_P (loc_note
))
25969 if (CALL_P (loc_note
))
25972 if (SIBLING_CALL_P (loc_note
))
25973 tail_call_site_count
++;
25974 if (optimize
== 0 && !flag_var_tracking
)
25976 /* When the var-tracking pass is not running, there is no note
25977 for indirect calls whose target is compile-time known. In this
25978 case, process such calls specifically so that we generate call
25979 sites for them anyway. */
25980 rtx x
= PATTERN (loc_note
);
25981 if (GET_CODE (x
) == PARALLEL
)
25982 x
= XVECEXP (x
, 0, 0);
25983 if (GET_CODE (x
) == SET
)
25985 if (GET_CODE (x
) == CALL
)
25988 || GET_CODE (XEXP (x
, 0)) != SYMBOL_REF
25989 || !SYMBOL_REF_DECL (XEXP (x
, 0))
25990 || (TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0)))
25993 call_insn
= loc_note
;
25997 next_real
= next_real_insn (call_insn
);
25999 cached_next_real_insn
= NULL
;
26007 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
26008 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
26011 /* Optimize processing a large consecutive sequence of location
26012 notes so we don't spend too much time in next_real_insn. If the
26013 next insn is another location note, remember the next_real_insn
26014 calculation for next time. */
26015 next_real
= cached_next_real_insn
;
26018 if (expected_next_loc_note
!= loc_note
)
26022 next_note
= NEXT_INSN (loc_note
);
26024 || next_note
->deleted ()
26025 || ! NOTE_P (next_note
)
26026 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
26027 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
26031 next_real
= next_real_insn (loc_note
);
26035 expected_next_loc_note
= next_note
;
26036 cached_next_real_insn
= next_real
;
26039 cached_next_real_insn
= NULL
;
26041 /* If there are no instructions which would be affected by this note,
26042 don't do anything. */
26044 && next_real
== NULL_RTX
26045 && !NOTE_DURING_CALL_P (loc_note
))
26050 if (next_real
== NULL_RTX
)
26051 next_real
= get_last_insn ();
26053 /* If there were any real insns between note we processed last time
26054 and this note (or if it is the first note), clear
26055 last_{,postcall_}label so that they are not reused this time. */
26056 if (last_var_location_insn
== NULL_RTX
26057 || last_var_location_insn
!= next_real
26058 || last_in_cold_section_p
!= in_cold_section_p
)
26061 last_postcall_label
= NULL
;
26066 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
26067 newloc
= add_var_loc_to_decl (decl
, loc_note
,
26068 NOTE_DURING_CALL_P (loc_note
)
26069 ? last_postcall_label
: last_label
);
26070 if (newloc
== NULL
)
26079 /* If there were no real insns between note we processed last time
26080 and this note, use the label we emitted last time. Otherwise
26081 create a new label and emit it. */
26082 if (last_label
== NULL
)
26084 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
26085 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
26087 last_label
= ggc_strdup (loclabel
);
26088 /* See if loclabel might be equal to .Ltext0. If yes,
26089 bump first_loclabel_num_not_at_text_label. */
26090 if (!have_multiple_function_sections
26091 && in_first_function_p
26092 && maybe_at_text_label_p
)
26094 static rtx_insn
*last_start
;
26096 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
26097 if (insn
== last_start
)
26099 else if (!NONDEBUG_INSN_P (insn
))
26103 rtx body
= PATTERN (insn
);
26104 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
26106 /* Inline asm could occupy zero bytes. */
26107 else if (GET_CODE (body
) == ASM_INPUT
26108 || asm_noperands (body
) >= 0)
26110 #ifdef HAVE_attr_length
26111 else if (get_attr_min_length (insn
) == 0)
26116 /* Assume insn has non-zero length. */
26117 maybe_at_text_label_p
= false;
26121 if (maybe_at_text_label_p
)
26123 last_start
= loc_note
;
26124 first_loclabel_num_not_at_text_label
= loclabel_num
;
26129 gcc_assert ((loc_note
== NULL_RTX
&& call_insn
!= NULL_RTX
)
26130 || (loc_note
!= NULL_RTX
&& call_insn
== NULL_RTX
));
26134 struct call_arg_loc_node
*ca_loc
26135 = ggc_cleared_alloc
<call_arg_loc_node
> ();
26137 = loc_note
!= NULL_RTX
? prev_real_insn (loc_note
) : call_insn
;
26139 ca_loc
->call_arg_loc_note
= loc_note
;
26140 ca_loc
->next
= NULL
;
26141 ca_loc
->label
= last_label
;
26144 || (NONJUMP_INSN_P (prev
)
26145 && GET_CODE (PATTERN (prev
)) == SEQUENCE
26146 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
26147 if (!CALL_P (prev
))
26148 prev
= as_a
<rtx_sequence
*> (PATTERN (prev
))->insn (0);
26149 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
26151 /* Look for a SYMBOL_REF in the "prev" instruction. */
26152 rtx x
= get_call_rtx_from (PATTERN (prev
));
26155 /* Try to get the call symbol, if any. */
26156 if (MEM_P (XEXP (x
, 0)))
26158 /* First, look for a memory access to a symbol_ref. */
26159 if (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
26160 && SYMBOL_REF_DECL (XEXP (x
, 0))
26161 && TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0))) == FUNCTION_DECL
)
26162 ca_loc
->symbol_ref
= XEXP (x
, 0);
26163 /* Otherwise, look at a compile-time known user-level function
26167 && TREE_CODE (MEM_EXPR (x
)) == FUNCTION_DECL
)
26168 ca_loc
->symbol_ref
= XEXP (DECL_RTL (MEM_EXPR (x
)), 0);
26171 ca_loc
->block
= insn_scope (prev
);
26172 if (call_arg_locations
)
26173 call_arg_loc_last
->next
= ca_loc
;
26175 call_arg_locations
= ca_loc
;
26176 call_arg_loc_last
= ca_loc
;
26178 else if (loc_note
!= NULL_RTX
&& !NOTE_DURING_CALL_P (loc_note
))
26179 newloc
->label
= last_label
;
26182 if (!last_postcall_label
)
26184 sprintf (loclabel
, "%s-1", last_label
);
26185 last_postcall_label
= ggc_strdup (loclabel
);
26187 newloc
->label
= last_postcall_label
;
26190 last_var_location_insn
= next_real
;
26191 last_in_cold_section_p
= in_cold_section_p
;
26194 /* Called from finalize_size_functions for size functions so that their body
26195 can be encoded in the debug info to describe the layout of variable-length
26199 dwarf2out_size_function (tree decl
)
26201 function_to_dwarf_procedure (decl
);
26204 /* Note in one location list that text section has changed. */
26207 var_location_switch_text_section_1 (var_loc_list
**slot
, void *)
26209 var_loc_list
*list
= *slot
;
26211 list
->last_before_switch
26212 = list
->last
->next
? list
->last
->next
: list
->last
;
26216 /* Note in all location lists that text section has changed. */
26219 var_location_switch_text_section (void)
26221 if (decl_loc_table
== NULL
)
26224 decl_loc_table
->traverse
<void *, var_location_switch_text_section_1
> (NULL
);
26227 /* Create a new line number table. */
26229 static dw_line_info_table
*
26230 new_line_info_table (void)
26232 dw_line_info_table
*table
;
26234 table
= ggc_cleared_alloc
<dw_line_info_table
> ();
26235 table
->file_num
= 1;
26236 table
->line_num
= 1;
26237 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
26242 /* Lookup the "current" table into which we emit line info, so
26243 that we don't have to do it for every source line. */
26246 set_cur_line_info_table (section
*sec
)
26248 dw_line_info_table
*table
;
26250 if (sec
== text_section
)
26251 table
= text_section_line_info
;
26252 else if (sec
== cold_text_section
)
26254 table
= cold_text_section_line_info
;
26257 cold_text_section_line_info
= table
= new_line_info_table ();
26258 table
->end_label
= cold_end_label
;
26263 const char *end_label
;
26265 if (flag_reorder_blocks_and_partition
)
26267 if (in_cold_section_p
)
26268 end_label
= crtl
->subsections
.cold_section_end_label
;
26270 end_label
= crtl
->subsections
.hot_section_end_label
;
26274 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
26275 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
26276 current_function_funcdef_no
);
26277 end_label
= ggc_strdup (label
);
26280 table
= new_line_info_table ();
26281 table
->end_label
= end_label
;
26283 vec_safe_push (separate_line_info
, table
);
26286 if (DWARF2_ASM_LINE_DEBUG_INFO
)
26287 table
->is_stmt
= (cur_line_info_table
26288 ? cur_line_info_table
->is_stmt
26289 : DWARF_LINE_DEFAULT_IS_STMT_START
);
26290 cur_line_info_table
= table
;
26294 /* We need to reset the locations at the beginning of each
26295 function. We can't do this in the end_function hook, because the
26296 declarations that use the locations won't have been output when
26297 that hook is called. Also compute have_multiple_function_sections here. */
26300 dwarf2out_begin_function (tree fun
)
26302 section
*sec
= function_section (fun
);
26304 if (sec
!= text_section
)
26305 have_multiple_function_sections
= true;
26307 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
26309 gcc_assert (current_function_decl
== fun
);
26310 cold_text_section
= unlikely_text_section ();
26311 switch_to_section (cold_text_section
);
26312 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
26313 switch_to_section (sec
);
26316 dwarf2out_note_section_used ();
26317 call_site_count
= 0;
26318 tail_call_site_count
= 0;
26320 set_cur_line_info_table (sec
);
26323 /* Helper function of dwarf2out_end_function, called only after emitting
26324 the very first function into assembly. Check if some .debug_loc range
26325 might end with a .LVL* label that could be equal to .Ltext0.
26326 In that case we must force using absolute addresses in .debug_loc ranges,
26327 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
26328 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
26330 Set have_multiple_function_sections to true in that case and
26331 terminate htab traversal. */
26334 find_empty_loc_ranges_at_text_label (var_loc_list
**slot
, int)
26336 var_loc_list
*entry
= *slot
;
26337 struct var_loc_node
*node
;
26339 node
= entry
->first
;
26340 if (node
&& node
->next
&& node
->next
->label
)
26343 const char *label
= node
->next
->label
;
26344 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
26346 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
26348 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
26349 if (strcmp (label
, loclabel
) == 0)
26351 have_multiple_function_sections
= true;
26359 /* Hook called after emitting a function into assembly.
26360 This does something only for the very first function emitted. */
26363 dwarf2out_end_function (unsigned int)
26365 if (in_first_function_p
26366 && !have_multiple_function_sections
26367 && first_loclabel_num_not_at_text_label
26369 decl_loc_table
->traverse
<int, find_empty_loc_ranges_at_text_label
> (0);
26370 in_first_function_p
= false;
26371 maybe_at_text_label_p
= false;
26374 /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
26375 front-ends register a translation unit even before dwarf2out_init is
26377 static tree main_translation_unit
= NULL_TREE
;
26379 /* Hook called by front-ends after they built their main translation unit.
26380 Associate comp_unit_die to UNIT. */
26383 dwarf2out_register_main_translation_unit (tree unit
)
26385 gcc_assert (TREE_CODE (unit
) == TRANSLATION_UNIT_DECL
26386 && main_translation_unit
== NULL_TREE
);
26387 main_translation_unit
= unit
;
26388 /* If dwarf2out_init has not been called yet, it will perform the association
26389 itself looking at main_translation_unit. */
26390 if (decl_die_table
!= NULL
)
26391 equate_decl_number_to_die (unit
, comp_unit_die ());
26394 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
26397 push_dw_line_info_entry (dw_line_info_table
*table
,
26398 enum dw_line_info_opcode opcode
, unsigned int val
)
26400 dw_line_info_entry e
;
26403 vec_safe_push (table
->entries
, e
);
26406 /* Output a label to mark the beginning of a source code line entry
26407 and record information relating to this source line, in
26408 'line_info_table' for later output of the .debug_line section. */
26409 /* ??? The discriminator parameter ought to be unsigned. */
26412 dwarf2out_source_line (unsigned int line
, const char *filename
,
26413 int discriminator
, bool is_stmt
)
26415 unsigned int file_num
;
26416 dw_line_info_table
*table
;
26418 if (debug_info_level
< DINFO_LEVEL_TERSE
|| line
== 0)
26421 /* The discriminator column was added in dwarf4. Simplify the below
26422 by simply removing it if we're not supposed to output it. */
26423 if (dwarf_version
< 4 && dwarf_strict
)
26426 table
= cur_line_info_table
;
26427 file_num
= maybe_emit_file (lookup_filename (filename
));
26429 /* ??? TODO: Elide duplicate line number entries. Traditionally,
26430 the debugger has used the second (possibly duplicate) line number
26431 at the beginning of the function to mark the end of the prologue.
26432 We could eliminate any other duplicates within the function. For
26433 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
26434 that second line number entry. */
26435 /* Recall that this end-of-prologue indication is *not* the same thing
26436 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
26437 to which the hook corresponds, follows the last insn that was
26438 emitted by gen_prologue. What we need is to precede the first insn
26439 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
26440 insn that corresponds to something the user wrote. These may be
26441 very different locations once scheduling is enabled. */
26443 if (0 && file_num
== table
->file_num
26444 && line
== table
->line_num
26445 && discriminator
== table
->discrim_num
26446 && is_stmt
== table
->is_stmt
)
26449 switch_to_section (current_function_section ());
26451 /* If requested, emit something human-readable. */
26452 if (flag_debug_asm
)
26453 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
26455 if (DWARF2_ASM_LINE_DEBUG_INFO
)
26457 /* Emit the .loc directive understood by GNU as. */
26458 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
26459 file_num, line, is_stmt, discriminator */
26460 fputs ("\t.loc ", asm_out_file
);
26461 fprint_ul (asm_out_file
, file_num
);
26462 putc (' ', asm_out_file
);
26463 fprint_ul (asm_out_file
, line
);
26464 putc (' ', asm_out_file
);
26465 putc ('0', asm_out_file
);
26467 if (is_stmt
!= table
->is_stmt
)
26469 fputs (" is_stmt ", asm_out_file
);
26470 putc (is_stmt
? '1' : '0', asm_out_file
);
26472 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
26474 gcc_assert (discriminator
> 0);
26475 fputs (" discriminator ", asm_out_file
);
26476 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
26478 putc ('\n', asm_out_file
);
26482 unsigned int label_num
= ++line_info_label_num
;
26484 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
26486 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
26487 if (file_num
!= table
->file_num
)
26488 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
26489 if (discriminator
!= table
->discrim_num
)
26490 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
26491 if (is_stmt
!= table
->is_stmt
)
26492 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
26493 push_dw_line_info_entry (table
, LI_set_line
, line
);
26496 table
->file_num
= file_num
;
26497 table
->line_num
= line
;
26498 table
->discrim_num
= discriminator
;
26499 table
->is_stmt
= is_stmt
;
26500 table
->in_use
= true;
26503 /* Record the beginning of a new source file. */
26506 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
26508 if (flag_eliminate_dwarf2_dups
)
26510 /* Record the beginning of the file for break_out_includes. */
26511 dw_die_ref bincl_die
;
26513 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
26514 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
26517 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26520 e
.code
= DW_MACINFO_start_file
;
26522 e
.info
= ggc_strdup (filename
);
26523 vec_safe_push (macinfo_table
, e
);
26527 /* Record the end of a source file. */
26530 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
26532 if (flag_eliminate_dwarf2_dups
)
26533 /* Record the end of the file for break_out_includes. */
26534 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
26536 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26539 e
.code
= DW_MACINFO_end_file
;
26542 vec_safe_push (macinfo_table
, e
);
26546 /* Called from debug_define in toplev.c. The `buffer' parameter contains
26547 the tail part of the directive line, i.e. the part which is past the
26548 initial whitespace, #, whitespace, directive-name, whitespace part. */
26551 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
26552 const char *buffer ATTRIBUTE_UNUSED
)
26554 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26557 /* Insert a dummy first entry to be able to optimize the whole
26558 predefined macro block using DW_MACRO_import. */
26559 if (macinfo_table
->is_empty () && lineno
<= 1)
26564 vec_safe_push (macinfo_table
, e
);
26566 e
.code
= DW_MACINFO_define
;
26568 e
.info
= ggc_strdup (buffer
);
26569 vec_safe_push (macinfo_table
, e
);
26573 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
26574 the tail part of the directive line, i.e. the part which is past the
26575 initial whitespace, #, whitespace, directive-name, whitespace part. */
26578 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
26579 const char *buffer ATTRIBUTE_UNUSED
)
26581 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
26584 /* Insert a dummy first entry to be able to optimize the whole
26585 predefined macro block using DW_MACRO_import. */
26586 if (macinfo_table
->is_empty () && lineno
<= 1)
26591 vec_safe_push (macinfo_table
, e
);
26593 e
.code
= DW_MACINFO_undef
;
26595 e
.info
= ggc_strdup (buffer
);
26596 vec_safe_push (macinfo_table
, e
);
26600 /* Helpers to manipulate hash table of CUs. */
26602 struct macinfo_entry_hasher
: nofree_ptr_hash
<macinfo_entry
>
26604 static inline hashval_t
hash (const macinfo_entry
*);
26605 static inline bool equal (const macinfo_entry
*, const macinfo_entry
*);
26609 macinfo_entry_hasher::hash (const macinfo_entry
*entry
)
26611 return htab_hash_string (entry
->info
);
26615 macinfo_entry_hasher::equal (const macinfo_entry
*entry1
,
26616 const macinfo_entry
*entry2
)
26618 return !strcmp (entry1
->info
, entry2
->info
);
26621 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
26623 /* Output a single .debug_macinfo entry. */
26626 output_macinfo_op (macinfo_entry
*ref
)
26630 struct indirect_string_node
*node
;
26631 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
26632 struct dwarf_file_data
*fd
;
26636 case DW_MACINFO_start_file
:
26637 fd
= lookup_filename (ref
->info
);
26638 file_num
= maybe_emit_file (fd
);
26639 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
26640 dw2_asm_output_data_uleb128 (ref
->lineno
,
26641 "Included from line number %lu",
26642 (unsigned long) ref
->lineno
);
26643 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
26645 case DW_MACINFO_end_file
:
26646 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
26648 case DW_MACINFO_define
:
26649 case DW_MACINFO_undef
:
26650 len
= strlen (ref
->info
) + 1;
26652 && len
> DWARF_OFFSET_SIZE
26653 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
26654 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
26656 ref
->code
= ref
->code
== DW_MACINFO_define
26657 ? DW_MACRO_define_strp
: DW_MACRO_undef_strp
;
26658 output_macinfo_op (ref
);
26661 dw2_asm_output_data (1, ref
->code
,
26662 ref
->code
== DW_MACINFO_define
26663 ? "Define macro" : "Undefine macro");
26664 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
26665 (unsigned long) ref
->lineno
);
26666 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
26668 case DW_MACRO_define_strp
:
26669 case DW_MACRO_undef_strp
:
26670 node
= find_AT_string (ref
->info
);
26672 && (node
->form
== DW_FORM_strp
26673 || node
->form
== DW_FORM_GNU_str_index
));
26674 dw2_asm_output_data (1, ref
->code
,
26675 ref
->code
== DW_MACRO_define_strp
26676 ? "Define macro strp"
26677 : "Undefine macro strp");
26678 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
26679 (unsigned long) ref
->lineno
);
26680 if (node
->form
== DW_FORM_strp
)
26681 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
26682 debug_str_section
, "The macro: \"%s\"",
26685 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
26688 case DW_MACRO_import
:
26689 dw2_asm_output_data (1, ref
->code
, "Import");
26690 ASM_GENERATE_INTERNAL_LABEL (label
,
26691 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
26692 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
26695 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
26696 ASM_COMMENT_START
, (unsigned long) ref
->code
);
26701 /* Attempt to make a sequence of define/undef macinfo ops shareable with
26702 other compilation unit .debug_macinfo sections. IDX is the first
26703 index of a define/undef, return the number of ops that should be
26704 emitted in a comdat .debug_macinfo section and emit
26705 a DW_MACRO_import entry referencing it.
26706 If the define/undef entry should be emitted normally, return 0. */
26709 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
26710 macinfo_hash_type
**macinfo_htab
)
26712 macinfo_entry
*first
, *second
, *cur
, *inc
;
26713 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
26714 unsigned char checksum
[16];
26715 struct md5_ctx ctx
;
26716 char *grp_name
, *tail
;
26718 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
26719 macinfo_entry
**slot
;
26721 first
= &(*macinfo_table
)[idx
];
26722 second
= &(*macinfo_table
)[idx
+ 1];
26724 /* Optimize only if there are at least two consecutive define/undef ops,
26725 and either all of them are before first DW_MACINFO_start_file
26726 with lineno {0,1} (i.e. predefined macro block), or all of them are
26727 in some included header file. */
26728 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
26730 if (vec_safe_is_empty (files
))
26732 if (first
->lineno
> 1 || second
->lineno
> 1)
26735 else if (first
->lineno
== 0)
26738 /* Find the last define/undef entry that can be grouped together
26739 with first and at the same time compute md5 checksum of their
26740 codes, linenumbers and strings. */
26741 md5_init_ctx (&ctx
);
26742 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
26743 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
26745 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
26749 unsigned char code
= cur
->code
;
26750 md5_process_bytes (&code
, 1, &ctx
);
26751 checksum_uleb128 (cur
->lineno
, &ctx
);
26752 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
26754 md5_finish_ctx (&ctx
, checksum
);
26757 /* From the containing include filename (if any) pick up just
26758 usable characters from its basename. */
26759 if (vec_safe_is_empty (files
))
26762 base
= lbasename (files
->last ().info
);
26763 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
26764 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
26765 encoded_filename_len
++;
26766 /* Count . at the end. */
26767 if (encoded_filename_len
)
26768 encoded_filename_len
++;
26770 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
26771 linebuf_len
= strlen (linebuf
);
26773 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
26774 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
26776 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
26777 tail
= grp_name
+ 4;
26778 if (encoded_filename_len
)
26780 for (i
= 0; base
[i
]; i
++)
26781 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
26785 memcpy (tail
, linebuf
, linebuf_len
);
26786 tail
+= linebuf_len
;
26788 for (i
= 0; i
< 16; i
++)
26789 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
26791 /* Construct a macinfo_entry for DW_MACRO_import
26792 in the empty vector entry before the first define/undef. */
26793 inc
= &(*macinfo_table
)[idx
- 1];
26794 inc
->code
= DW_MACRO_import
;
26796 inc
->info
= ggc_strdup (grp_name
);
26797 if (!*macinfo_htab
)
26798 *macinfo_htab
= new macinfo_hash_type (10);
26799 /* Avoid emitting duplicates. */
26800 slot
= (*macinfo_htab
)->find_slot (inc
, INSERT
);
26805 /* If such an entry has been used before, just emit
26806 a DW_MACRO_import op. */
26808 output_macinfo_op (inc
);
26809 /* And clear all macinfo_entry in the range to avoid emitting them
26810 in the second pass. */
26811 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
26820 inc
->lineno
= (*macinfo_htab
)->elements ();
26821 output_macinfo_op (inc
);
26826 /* Save any strings needed by the macinfo table in the debug str
26827 table. All strings must be collected into the table by the time
26828 index_string is called. */
26831 save_macinfo_strings (void)
26835 macinfo_entry
*ref
;
26837 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
26841 /* Match the logic in output_macinfo_op to decide on
26842 indirect strings. */
26843 case DW_MACINFO_define
:
26844 case DW_MACINFO_undef
:
26845 len
= strlen (ref
->info
) + 1;
26847 && len
> DWARF_OFFSET_SIZE
26848 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
26849 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
26850 set_indirect_string (find_AT_string (ref
->info
));
26852 case DW_MACRO_define_strp
:
26853 case DW_MACRO_undef_strp
:
26854 set_indirect_string (find_AT_string (ref
->info
));
26862 /* Output macinfo section(s). */
26865 output_macinfo (void)
26868 unsigned long length
= vec_safe_length (macinfo_table
);
26869 macinfo_entry
*ref
;
26870 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
26871 macinfo_hash_type
*macinfo_htab
= NULL
;
26876 /* output_macinfo* uses these interchangeably. */
26877 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_define
26878 && (int) DW_MACINFO_undef
== (int) DW_MACRO_undef
26879 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_start_file
26880 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_end_file
);
26882 /* For .debug_macro emit the section header. */
26883 if (!dwarf_strict
|| dwarf_version
>= 5)
26885 dw2_asm_output_data (2, dwarf_version
>= 5 ? 5 : 4,
26886 "DWARF macro version number");
26887 if (DWARF_OFFSET_SIZE
== 8)
26888 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
26890 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
26891 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
26892 (!dwarf_split_debug_info
? debug_line_section_label
26893 : debug_skeleton_line_section_label
),
26894 debug_line_section
, NULL
);
26897 /* In the first loop, it emits the primary .debug_macinfo section
26898 and after each emitted op the macinfo_entry is cleared.
26899 If a longer range of define/undef ops can be optimized using
26900 DW_MACRO_import, the DW_MACRO_import op is emitted and kept in
26901 the vector before the first define/undef in the range and the
26902 whole range of define/undef ops is not emitted and kept. */
26903 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
26907 case DW_MACINFO_start_file
:
26908 vec_safe_push (files
, *ref
);
26910 case DW_MACINFO_end_file
:
26911 if (!vec_safe_is_empty (files
))
26914 case DW_MACINFO_define
:
26915 case DW_MACINFO_undef
:
26916 if ((!dwarf_strict
|| dwarf_version
>= 5)
26917 && HAVE_COMDAT_GROUP
26918 && vec_safe_length (files
) != 1
26921 && (*macinfo_table
)[i
- 1].code
== 0)
26923 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
26932 /* A dummy entry may be inserted at the beginning to be able
26933 to optimize the whole block of predefined macros. */
26939 output_macinfo_op (ref
);
26947 delete macinfo_htab
;
26948 macinfo_htab
= NULL
;
26950 /* If any DW_MACRO_import were used, on those DW_MACRO_import entries
26951 terminate the current chain and switch to a new comdat .debug_macinfo
26952 section and emit the define/undef entries within it. */
26953 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
26958 case DW_MACRO_import
:
26960 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
26961 tree comdat_key
= get_identifier (ref
->info
);
26962 /* Terminate the previous .debug_macinfo section. */
26963 dw2_asm_output_data (1, 0, "End compilation unit");
26964 targetm
.asm_out
.named_section (debug_macinfo_section_name
,
26966 | SECTION_LINKONCE
,
26968 ASM_GENERATE_INTERNAL_LABEL (label
,
26969 DEBUG_MACRO_SECTION_LABEL
,
26971 ASM_OUTPUT_LABEL (asm_out_file
, label
);
26974 dw2_asm_output_data (2, dwarf_version
>= 5 ? 5 : 4,
26975 "DWARF macro version number");
26976 if (DWARF_OFFSET_SIZE
== 8)
26977 dw2_asm_output_data (1, 1, "Flags: 64-bit");
26979 dw2_asm_output_data (1, 0, "Flags: 32-bit");
26982 case DW_MACINFO_define
:
26983 case DW_MACINFO_undef
:
26984 output_macinfo_op (ref
);
26989 gcc_unreachable ();
26993 /* Initialize the various sections and labels for dwarf output. */
26996 init_sections_and_labels (void)
26998 if (!dwarf_split_debug_info
)
27000 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
27001 SECTION_DEBUG
, NULL
);
27002 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
27003 SECTION_DEBUG
, NULL
);
27004 debug_loc_section
= get_section (dwarf_version
>= 5
27005 ? DEBUG_LOCLISTS_SECTION
27006 : DEBUG_LOC_SECTION
,
27007 SECTION_DEBUG
, NULL
);
27008 debug_macinfo_section_name
27009 = (dwarf_strict
&& dwarf_version
< 5)
27010 ? DEBUG_MACINFO_SECTION
: DEBUG_MACRO_SECTION
;
27011 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
27012 SECTION_DEBUG
, NULL
);
27016 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
27017 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27018 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
27019 SECTION_DEBUG
| SECTION_EXCLUDE
,
27021 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
27022 SECTION_DEBUG
, NULL
);
27023 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
27024 SECTION_DEBUG
, NULL
);
27025 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
27026 SECTION_DEBUG
, NULL
);
27027 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
27028 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
27030 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
27031 the main .o, but the skeleton_line goes into the split off dwo. */
27032 debug_skeleton_line_section
27033 = get_section (DEBUG_DWO_LINE_SECTION
,
27034 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27035 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
27036 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
27037 debug_str_offsets_section
= get_section (DEBUG_DWO_STR_OFFSETS_SECTION
,
27038 SECTION_DEBUG
| SECTION_EXCLUDE
,
27040 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
27041 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
27042 debug_loc_section
= get_section (dwarf_version
>= 5
27043 ? DEBUG_DWO_LOCLISTS_SECTION
27044 : DEBUG_DWO_LOC_SECTION
,
27045 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
27046 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
27047 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
27048 debug_macinfo_section_name
27049 = (dwarf_strict
&& dwarf_version
< 5)
27050 ? DEBUG_DWO_MACINFO_SECTION
: DEBUG_DWO_MACRO_SECTION
;
27051 debug_macinfo_section
= get_section (debug_macinfo_section_name
,
27052 SECTION_DEBUG
| SECTION_EXCLUDE
,
27055 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
27056 SECTION_DEBUG
, NULL
);
27057 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
27058 SECTION_DEBUG
, NULL
);
27059 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
27060 SECTION_DEBUG
, NULL
);
27061 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
27062 SECTION_DEBUG
, NULL
);
27063 debug_str_section
= get_section (DEBUG_STR_SECTION
,
27064 DEBUG_STR_SECTION_FLAGS
, NULL
);
27065 if (!dwarf_split_debug_info
&& !DWARF2_ASM_LINE_DEBUG_INFO
)
27066 debug_line_str_section
= get_section (DEBUG_LINE_STR_SECTION
,
27067 DEBUG_STR_SECTION_FLAGS
, NULL
);
27069 debug_ranges_section
= get_section (dwarf_version
>= 5
27070 ? DEBUG_RNGLISTS_SECTION
27071 : DEBUG_RANGES_SECTION
,
27072 SECTION_DEBUG
, NULL
);
27073 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
27074 SECTION_DEBUG
, NULL
);
27076 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
27077 DEBUG_ABBREV_SECTION_LABEL
, 0);
27078 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
27079 DEBUG_INFO_SECTION_LABEL
, 0);
27080 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
27081 DEBUG_LINE_SECTION_LABEL
, 0);
27082 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
27083 DEBUG_RANGES_SECTION_LABEL
, 0);
27084 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
27085 ASM_GENERATE_INTERNAL_LABEL (ranges_base_label
,
27086 DEBUG_RANGES_SECTION_LABEL
, 1);
27087 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
27088 DEBUG_ADDR_SECTION_LABEL
, 0);
27089 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
27090 (dwarf_strict
&& dwarf_version
< 5)
27091 ? DEBUG_MACINFO_SECTION_LABEL
27092 : DEBUG_MACRO_SECTION_LABEL
, 0);
27093 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
27096 /* Set up for Dwarf output at the start of compilation. */
27099 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
27101 /* This option is currently broken, see (PR53118 and PR46102). */
27102 if (flag_eliminate_dwarf2_dups
27103 && strstr (lang_hooks
.name
, "C++"))
27105 warning (0, "-feliminate-dwarf2-dups is broken for C++, ignoring");
27106 flag_eliminate_dwarf2_dups
= 0;
27109 /* Allocate the file_table. */
27110 file_table
= hash_table
<dwarf_file_hasher
>::create_ggc (50);
27112 #ifndef DWARF2_LINENO_DEBUGGING_INFO
27113 /* Allocate the decl_die_table. */
27114 decl_die_table
= hash_table
<decl_die_hasher
>::create_ggc (10);
27116 /* Allocate the decl_loc_table. */
27117 decl_loc_table
= hash_table
<decl_loc_hasher
>::create_ggc (10);
27119 /* Allocate the cached_dw_loc_list_table. */
27120 cached_dw_loc_list_table
= hash_table
<dw_loc_list_hasher
>::create_ggc (10);
27122 /* Allocate the initial hunk of the decl_scope_table. */
27123 vec_alloc (decl_scope_table
, 256);
27125 /* Allocate the initial hunk of the abbrev_die_table. */
27126 vec_alloc (abbrev_die_table
, 256);
27127 /* Zero-th entry is allocated, but unused. */
27128 abbrev_die_table
->quick_push (NULL
);
27130 /* Allocate the dwarf_proc_stack_usage_map. */
27131 dwarf_proc_stack_usage_map
= new hash_map
<dw_die_ref
, int>;
27133 /* Allocate the pubtypes and pubnames vectors. */
27134 vec_alloc (pubname_table
, 32);
27135 vec_alloc (pubtype_table
, 32);
27137 vec_alloc (incomplete_types
, 64);
27139 vec_alloc (used_rtx_array
, 32);
27141 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
27142 vec_alloc (macinfo_table
, 64);
27145 /* If front-ends already registered a main translation unit but we were not
27146 ready to perform the association, do this now. */
27147 if (main_translation_unit
!= NULL_TREE
)
27148 equate_decl_number_to_die (main_translation_unit
, comp_unit_die ());
27151 /* Called before compile () starts outputtting functions, variables
27152 and toplevel asms into assembly. */
27155 dwarf2out_assembly_start (void)
27157 #ifndef DWARF2_LINENO_DEBUGGING_INFO
27158 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
27159 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
27160 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
27161 COLD_TEXT_SECTION_LABEL
, 0);
27162 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
27164 switch_to_section (text_section
);
27165 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
27168 /* Make sure the line number table for .text always exists. */
27169 text_section_line_info
= new_line_info_table ();
27170 text_section_line_info
->end_label
= text_end_label
;
27172 #ifdef DWARF2_LINENO_DEBUGGING_INFO
27173 cur_line_info_table
= text_section_line_info
;
27176 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
27177 && dwarf2out_do_cfi_asm ()
27178 && (!(flag_unwind_tables
|| flag_exceptions
)
27179 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
27180 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
27183 /* A helper function for dwarf2out_finish called through
27184 htab_traverse. Assign a string its index. All strings must be
27185 collected into the table by the time index_string is called,
27186 because the indexing code relies on htab_traverse to traverse nodes
27187 in the same order for each run. */
27190 index_string (indirect_string_node
**h
, unsigned int *index
)
27192 indirect_string_node
*node
= *h
;
27194 find_string_form (node
);
27195 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
27197 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
27198 node
->index
= *index
;
27204 /* A helper function for output_indirect_strings called through
27205 htab_traverse. Output the offset to a string and update the
27209 output_index_string_offset (indirect_string_node
**h
, unsigned int *offset
)
27211 indirect_string_node
*node
= *h
;
27213 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
27215 /* Assert that this node has been assigned an index. */
27216 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
27217 && node
->index
!= NOT_INDEXED
);
27218 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
27219 "indexed string 0x%x: %s", node
->index
, node
->str
);
27220 *offset
+= strlen (node
->str
) + 1;
27225 /* A helper function for dwarf2out_finish called through
27226 htab_traverse. Output the indexed string. */
27229 output_index_string (indirect_string_node
**h
, unsigned int *cur_idx
)
27231 struct indirect_string_node
*node
= *h
;
27233 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
27235 /* Assert that the strings are output in the same order as their
27236 indexes were assigned. */
27237 gcc_assert (*cur_idx
== node
->index
);
27238 assemble_string (node
->str
, strlen (node
->str
) + 1);
27244 /* A helper function for dwarf2out_finish called through
27245 htab_traverse. Emit one queued .debug_str string. */
27248 output_indirect_string (indirect_string_node
**h
, enum dwarf_form form
)
27250 struct indirect_string_node
*node
= *h
;
27252 node
->form
= find_string_form (node
);
27253 if (node
->form
== form
&& node
->refcount
> 0)
27255 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
27256 assemble_string (node
->str
, strlen (node
->str
) + 1);
27262 /* Output the indexed string table. */
27265 output_indirect_strings (void)
27267 switch_to_section (debug_str_section
);
27268 if (!dwarf_split_debug_info
)
27269 debug_str_hash
->traverse
<enum dwarf_form
,
27270 output_indirect_string
> (DW_FORM_strp
);
27273 unsigned int offset
= 0;
27274 unsigned int cur_idx
= 0;
27276 skeleton_debug_str_hash
->traverse
<enum dwarf_form
,
27277 output_indirect_string
> (DW_FORM_strp
);
27279 switch_to_section (debug_str_offsets_section
);
27280 debug_str_hash
->traverse_noresize
27281 <unsigned int *, output_index_string_offset
> (&offset
);
27282 switch_to_section (debug_str_dwo_section
);
27283 debug_str_hash
->traverse_noresize
<unsigned int *, output_index_string
>
27288 /* Callback for htab_traverse to assign an index to an entry in the
27289 table, and to write that entry to the .debug_addr section. */
27292 output_addr_table_entry (addr_table_entry
**slot
, unsigned int *cur_index
)
27294 addr_table_entry
*entry
= *slot
;
27296 if (entry
->refcount
== 0)
27298 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
27299 || entry
->index
== NOT_INDEXED
);
27303 gcc_assert (entry
->index
== *cur_index
);
27306 switch (entry
->kind
)
27309 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
27310 "0x%x", entry
->index
);
27312 case ate_kind_rtx_dtprel
:
27313 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
27314 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
27317 fputc ('\n', asm_out_file
);
27319 case ate_kind_label
:
27320 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
27321 "0x%x", entry
->index
);
27324 gcc_unreachable ();
27329 /* Produce the .debug_addr section. */
27332 output_addr_table (void)
27334 unsigned int index
= 0;
27335 if (addr_index_table
== NULL
|| addr_index_table
->size () == 0)
27338 switch_to_section (debug_addr_section
);
27340 ->traverse_noresize
<unsigned int *, output_addr_table_entry
> (&index
);
27343 #if ENABLE_ASSERT_CHECKING
27344 /* Verify that all marks are clear. */
27347 verify_marks_clear (dw_die_ref die
)
27351 gcc_assert (! die
->die_mark
);
27352 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
27354 #endif /* ENABLE_ASSERT_CHECKING */
27356 /* Clear the marks for a die and its children.
27357 Be cool if the mark isn't set. */
27360 prune_unmark_dies (dw_die_ref die
)
27366 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
27369 /* Given LOC that is referenced by a DIE we're marking as used, find all
27370 referenced DWARF procedures it references and mark them as used. */
27373 prune_unused_types_walk_loc_descr (dw_loc_descr_ref loc
)
27375 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
27376 switch (loc
->dw_loc_opc
)
27378 case DW_OP_implicit_pointer
:
27379 case DW_OP_convert
:
27380 case DW_OP_reinterpret
:
27381 case DW_OP_GNU_implicit_pointer
:
27382 case DW_OP_GNU_convert
:
27383 case DW_OP_GNU_reinterpret
:
27384 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
)
27385 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
27389 case DW_OP_call_ref
:
27390 case DW_OP_const_type
:
27391 case DW_OP_GNU_const_type
:
27392 case DW_OP_GNU_parameter_ref
:
27393 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
);
27394 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
27396 case DW_OP_regval_type
:
27397 case DW_OP_deref_type
:
27398 case DW_OP_GNU_regval_type
:
27399 case DW_OP_GNU_deref_type
:
27400 gcc_assert (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_die_ref
);
27401 prune_unused_types_mark (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
, 1);
27403 case DW_OP_entry_value
:
27404 case DW_OP_GNU_entry_value
:
27405 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
);
27406 prune_unused_types_walk_loc_descr (loc
->dw_loc_oprnd1
.v
.val_loc
);
27413 /* Given DIE that we're marking as used, find any other dies
27414 it references as attributes and mark them as used. */
27417 prune_unused_types_walk_attribs (dw_die_ref die
)
27422 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
27424 switch (AT_class (a
))
27426 /* Make sure DWARF procedures referenced by location descriptions will
27428 case dw_val_class_loc
:
27429 prune_unused_types_walk_loc_descr (AT_loc (a
));
27431 case dw_val_class_loc_list
:
27432 for (dw_loc_list_ref list
= AT_loc_list (a
);
27434 list
= list
->dw_loc_next
)
27435 prune_unused_types_walk_loc_descr (list
->expr
);
27438 case dw_val_class_die_ref
:
27439 /* A reference to another DIE.
27440 Make sure that it will get emitted.
27441 If it was broken out into a comdat group, don't follow it. */
27442 if (! AT_ref (a
)->comdat_type_p
27443 || a
->dw_attr
== DW_AT_specification
)
27444 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
27447 case dw_val_class_str
:
27448 /* Set the string's refcount to 0 so that prune_unused_types_mark
27449 accounts properly for it. */
27450 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
27459 /* Mark the generic parameters and arguments children DIEs of DIE. */
27462 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
27466 if (die
== NULL
|| die
->die_child
== NULL
)
27468 c
= die
->die_child
;
27471 if (is_template_parameter (c
))
27472 prune_unused_types_mark (c
, 1);
27474 } while (c
&& c
!= die
->die_child
);
27477 /* Mark DIE as being used. If DOKIDS is true, then walk down
27478 to DIE's children. */
27481 prune_unused_types_mark (dw_die_ref die
, int dokids
)
27485 if (die
->die_mark
== 0)
27487 /* We haven't done this node yet. Mark it as used. */
27489 /* If this is the DIE of a generic type instantiation,
27490 mark the children DIEs that describe its generic parms and
27492 prune_unused_types_mark_generic_parms_dies (die
);
27494 /* We also have to mark its parents as used.
27495 (But we don't want to mark our parent's kids due to this,
27496 unless it is a class.) */
27497 if (die
->die_parent
)
27498 prune_unused_types_mark (die
->die_parent
,
27499 class_scope_p (die
->die_parent
));
27501 /* Mark any referenced nodes. */
27502 prune_unused_types_walk_attribs (die
);
27504 /* If this node is a specification,
27505 also mark the definition, if it exists. */
27506 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
27507 prune_unused_types_mark (die
->die_definition
, 1);
27510 if (dokids
&& die
->die_mark
!= 2)
27512 /* We need to walk the children, but haven't done so yet.
27513 Remember that we've walked the kids. */
27516 /* If this is an array type, we need to make sure our
27517 kids get marked, even if they're types. If we're
27518 breaking out types into comdat sections, do this
27519 for all type definitions. */
27520 if (die
->die_tag
== DW_TAG_array_type
27521 || (use_debug_types
27522 && is_type_die (die
) && ! is_declaration_die (die
)))
27523 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
27525 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
27529 /* For local classes, look if any static member functions were emitted
27530 and if so, mark them. */
27533 prune_unused_types_walk_local_classes (dw_die_ref die
)
27537 if (die
->die_mark
== 2)
27540 switch (die
->die_tag
)
27542 case DW_TAG_structure_type
:
27543 case DW_TAG_union_type
:
27544 case DW_TAG_class_type
:
27547 case DW_TAG_subprogram
:
27548 if (!get_AT_flag (die
, DW_AT_declaration
)
27549 || die
->die_definition
!= NULL
)
27550 prune_unused_types_mark (die
, 1);
27557 /* Mark children. */
27558 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
27561 /* Walk the tree DIE and mark types that we actually use. */
27564 prune_unused_types_walk (dw_die_ref die
)
27568 /* Don't do anything if this node is already marked and
27569 children have been marked as well. */
27570 if (die
->die_mark
== 2)
27573 switch (die
->die_tag
)
27575 case DW_TAG_structure_type
:
27576 case DW_TAG_union_type
:
27577 case DW_TAG_class_type
:
27578 if (die
->die_perennial_p
)
27581 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
27582 if (c
->die_tag
== DW_TAG_subprogram
)
27585 /* Finding used static member functions inside of classes
27586 is needed just for local classes, because for other classes
27587 static member function DIEs with DW_AT_specification
27588 are emitted outside of the DW_TAG_*_type. If we ever change
27589 it, we'd need to call this even for non-local classes. */
27591 prune_unused_types_walk_local_classes (die
);
27593 /* It's a type node --- don't mark it. */
27596 case DW_TAG_const_type
:
27597 case DW_TAG_packed_type
:
27598 case DW_TAG_pointer_type
:
27599 case DW_TAG_reference_type
:
27600 case DW_TAG_rvalue_reference_type
:
27601 case DW_TAG_volatile_type
:
27602 case DW_TAG_typedef
:
27603 case DW_TAG_array_type
:
27604 case DW_TAG_interface_type
:
27605 case DW_TAG_friend
:
27606 case DW_TAG_enumeration_type
:
27607 case DW_TAG_subroutine_type
:
27608 case DW_TAG_string_type
:
27609 case DW_TAG_set_type
:
27610 case DW_TAG_subrange_type
:
27611 case DW_TAG_ptr_to_member_type
:
27612 case DW_TAG_file_type
:
27613 /* Type nodes are useful only when other DIEs reference them --- don't
27617 case DW_TAG_dwarf_procedure
:
27618 /* Likewise for DWARF procedures. */
27620 if (die
->die_perennial_p
)
27626 /* Mark everything else. */
27630 if (die
->die_mark
== 0)
27634 /* Now, mark any dies referenced from here. */
27635 prune_unused_types_walk_attribs (die
);
27640 /* Mark children. */
27641 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
27644 /* Increment the string counts on strings referred to from DIE's
27648 prune_unused_types_update_strings (dw_die_ref die
)
27653 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
27654 if (AT_class (a
) == dw_val_class_str
)
27656 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
27658 /* Avoid unnecessarily putting strings that are used less than
27659 twice in the hash table. */
27661 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
27663 indirect_string_node
**slot
27664 = debug_str_hash
->find_slot_with_hash (s
->str
,
27665 htab_hash_string (s
->str
),
27667 gcc_assert (*slot
== NULL
);
27673 /* Mark DIE and its children as removed. */
27676 mark_removed (dw_die_ref die
)
27679 die
->removed
= true;
27680 FOR_EACH_CHILD (die
, c
, mark_removed (c
));
27683 /* Remove from the tree DIE any dies that aren't marked. */
27686 prune_unused_types_prune (dw_die_ref die
)
27690 gcc_assert (die
->die_mark
);
27691 prune_unused_types_update_strings (die
);
27693 if (! die
->die_child
)
27696 c
= die
->die_child
;
27698 dw_die_ref prev
= c
, next
;
27699 for (c
= c
->die_sib
; ! c
->die_mark
; c
= next
)
27700 if (c
== die
->die_child
)
27702 /* No marked children between 'prev' and the end of the list. */
27704 /* No marked children at all. */
27705 die
->die_child
= NULL
;
27708 prev
->die_sib
= c
->die_sib
;
27709 die
->die_child
= prev
;
27722 if (c
!= prev
->die_sib
)
27724 prune_unused_types_prune (c
);
27725 } while (c
!= die
->die_child
);
27728 /* Remove dies representing declarations that we never use. */
27731 prune_unused_types (void)
27734 limbo_die_node
*node
;
27735 comdat_type_node
*ctnode
;
27736 pubname_entry
*pub
;
27737 dw_die_ref base_type
;
27739 #if ENABLE_ASSERT_CHECKING
27740 /* All the marks should already be clear. */
27741 verify_marks_clear (comp_unit_die ());
27742 for (node
= limbo_die_list
; node
; node
= node
->next
)
27743 verify_marks_clear (node
->die
);
27744 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
27745 verify_marks_clear (ctnode
->root_die
);
27746 #endif /* ENABLE_ASSERT_CHECKING */
27748 /* Mark types that are used in global variables. */
27749 premark_types_used_by_global_vars ();
27751 /* Set the mark on nodes that are actually used. */
27752 prune_unused_types_walk (comp_unit_die ());
27753 for (node
= limbo_die_list
; node
; node
= node
->next
)
27754 prune_unused_types_walk (node
->die
);
27755 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
27757 prune_unused_types_walk (ctnode
->root_die
);
27758 prune_unused_types_mark (ctnode
->type_die
, 1);
27761 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
27762 are unusual in that they are pubnames that are the children of pubtypes.
27763 They should only be marked via their parent DW_TAG_enumeration_type die,
27764 not as roots in themselves. */
27765 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
27766 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
27767 prune_unused_types_mark (pub
->die
, 1);
27768 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
27769 prune_unused_types_mark (base_type
, 1);
27771 if (debug_str_hash
)
27772 debug_str_hash
->empty ();
27773 if (skeleton_debug_str_hash
)
27774 skeleton_debug_str_hash
->empty ();
27775 prune_unused_types_prune (comp_unit_die ());
27776 for (limbo_die_node
**pnode
= &limbo_die_list
; *pnode
; )
27779 if (!node
->die
->die_mark
)
27780 *pnode
= node
->next
;
27783 prune_unused_types_prune (node
->die
);
27784 pnode
= &node
->next
;
27787 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
27788 prune_unused_types_prune (ctnode
->root_die
);
27790 /* Leave the marks clear. */
27791 prune_unmark_dies (comp_unit_die ());
27792 for (node
= limbo_die_list
; node
; node
= node
->next
)
27793 prune_unmark_dies (node
->die
);
27794 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
27795 prune_unmark_dies (ctnode
->root_die
);
27798 /* Helpers to manipulate hash table of comdat type units. */
27800 struct comdat_type_hasher
: nofree_ptr_hash
<comdat_type_node
>
27802 static inline hashval_t
hash (const comdat_type_node
*);
27803 static inline bool equal (const comdat_type_node
*, const comdat_type_node
*);
27807 comdat_type_hasher::hash (const comdat_type_node
*type_node
)
27810 memcpy (&h
, type_node
->signature
, sizeof (h
));
27815 comdat_type_hasher::equal (const comdat_type_node
*type_node_1
,
27816 const comdat_type_node
*type_node_2
)
27818 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
27819 DWARF_TYPE_SIGNATURE_SIZE
));
27822 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
27823 to the location it would have been added, should we know its
27824 DECL_ASSEMBLER_NAME when we added other attributes. This will
27825 probably improve compactness of debug info, removing equivalent
27826 abbrevs, and hide any differences caused by deferring the
27827 computation of the assembler name, triggered by e.g. PCH. */
27830 move_linkage_attr (dw_die_ref die
)
27832 unsigned ix
= vec_safe_length (die
->die_attr
);
27833 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
27835 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
27836 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
27840 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
27842 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
27846 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
27848 die
->die_attr
->pop ();
27849 die
->die_attr
->quick_insert (ix
, linkage
);
27853 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
27854 referenced from typed stack ops and count how often they are used. */
27857 mark_base_types (dw_loc_descr_ref loc
)
27859 dw_die_ref base_type
= NULL
;
27861 for (; loc
; loc
= loc
->dw_loc_next
)
27863 switch (loc
->dw_loc_opc
)
27865 case DW_OP_regval_type
:
27866 case DW_OP_deref_type
:
27867 case DW_OP_GNU_regval_type
:
27868 case DW_OP_GNU_deref_type
:
27869 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
27871 case DW_OP_convert
:
27872 case DW_OP_reinterpret
:
27873 case DW_OP_GNU_convert
:
27874 case DW_OP_GNU_reinterpret
:
27875 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
27878 case DW_OP_const_type
:
27879 case DW_OP_GNU_const_type
:
27880 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
27882 case DW_OP_entry_value
:
27883 case DW_OP_GNU_entry_value
:
27884 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
27889 gcc_assert (base_type
->die_parent
== comp_unit_die ());
27890 if (base_type
->die_mark
)
27891 base_type
->die_mark
++;
27894 base_types
.safe_push (base_type
);
27895 base_type
->die_mark
= 1;
27900 /* Comparison function for sorting marked base types. */
27903 base_type_cmp (const void *x
, const void *y
)
27905 dw_die_ref dx
= *(const dw_die_ref
*) x
;
27906 dw_die_ref dy
= *(const dw_die_ref
*) y
;
27907 unsigned int byte_size1
, byte_size2
;
27908 unsigned int encoding1
, encoding2
;
27909 if (dx
->die_mark
> dy
->die_mark
)
27911 if (dx
->die_mark
< dy
->die_mark
)
27913 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
27914 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
27915 if (byte_size1
< byte_size2
)
27917 if (byte_size1
> byte_size2
)
27919 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
27920 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
27921 if (encoding1
< encoding2
)
27923 if (encoding1
> encoding2
)
27928 /* Move base types marked by mark_base_types as early as possible
27929 in the CU, sorted by decreasing usage count both to make the
27930 uleb128 references as small as possible and to make sure they
27931 will have die_offset already computed by calc_die_sizes when
27932 sizes of typed stack loc ops is computed. */
27935 move_marked_base_types (void)
27938 dw_die_ref base_type
, die
, c
;
27940 if (base_types
.is_empty ())
27943 /* Sort by decreasing usage count, they will be added again in that
27945 base_types
.qsort (base_type_cmp
);
27946 die
= comp_unit_die ();
27947 c
= die
->die_child
;
27950 dw_die_ref prev
= c
;
27952 while (c
->die_mark
)
27954 remove_child_with_prev (c
, prev
);
27955 /* As base types got marked, there must be at least
27956 one node other than DW_TAG_base_type. */
27957 gcc_assert (die
->die_child
!= NULL
);
27961 while (c
!= die
->die_child
);
27962 gcc_assert (die
->die_child
);
27963 c
= die
->die_child
;
27964 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
27966 base_type
->die_mark
= 0;
27967 base_type
->die_sib
= c
->die_sib
;
27968 c
->die_sib
= base_type
;
27973 /* Helper function for resolve_addr, attempt to resolve
27974 one CONST_STRING, return true if successful. Similarly verify that
27975 SYMBOL_REFs refer to variables emitted in the current CU. */
27978 resolve_one_addr (rtx
*addr
)
27982 if (GET_CODE (rtl
) == CONST_STRING
)
27984 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
27985 tree t
= build_string (len
, XSTR (rtl
, 0));
27986 tree tlen
= size_int (len
- 1);
27988 = build_array_type (char_type_node
, build_index_type (tlen
));
27989 rtl
= lookup_constant_def (t
);
27990 if (!rtl
|| !MEM_P (rtl
))
27992 rtl
= XEXP (rtl
, 0);
27993 if (GET_CODE (rtl
) == SYMBOL_REF
27994 && SYMBOL_REF_DECL (rtl
)
27995 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
27997 vec_safe_push (used_rtx_array
, rtl
);
28002 if (GET_CODE (rtl
) == SYMBOL_REF
28003 && SYMBOL_REF_DECL (rtl
))
28005 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
28007 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
28010 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
28014 if (GET_CODE (rtl
) == CONST
)
28016 subrtx_ptr_iterator::array_type array
;
28017 FOR_EACH_SUBRTX_PTR (iter
, array
, &XEXP (rtl
, 0), ALL
)
28018 if (!resolve_one_addr (*iter
))
28025 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
28026 if possible, and create DW_TAG_dwarf_procedure that can be referenced
28027 from DW_OP_implicit_pointer if the string hasn't been seen yet. */
28030 string_cst_pool_decl (tree t
)
28032 rtx rtl
= output_constant_def (t
, 1);
28033 unsigned char *array
;
28034 dw_loc_descr_ref l
;
28039 if (!rtl
|| !MEM_P (rtl
))
28041 rtl
= XEXP (rtl
, 0);
28042 if (GET_CODE (rtl
) != SYMBOL_REF
28043 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
28046 decl
= SYMBOL_REF_DECL (rtl
);
28047 if (!lookup_decl_die (decl
))
28049 len
= TREE_STRING_LENGTH (t
);
28050 vec_safe_push (used_rtx_array
, rtl
);
28051 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
28052 array
= ggc_vec_alloc
<unsigned char> (len
);
28053 memcpy (array
, TREE_STRING_POINTER (t
), len
);
28054 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
28055 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
28056 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
28057 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
28058 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
28059 add_AT_loc (ref
, DW_AT_location
, l
);
28060 equate_decl_number_to_die (decl
, ref
);
28065 /* Helper function of resolve_addr_in_expr. LOC is
28066 a DW_OP_addr followed by DW_OP_stack_value, either at the start
28067 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
28068 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
28069 with DW_OP_implicit_pointer if possible
28070 and return true, if unsuccessful, return false. */
28073 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
28075 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
28076 HOST_WIDE_INT offset
= 0;
28077 dw_die_ref ref
= NULL
;
28080 if (GET_CODE (rtl
) == CONST
28081 && GET_CODE (XEXP (rtl
, 0)) == PLUS
28082 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
28084 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
28085 rtl
= XEXP (XEXP (rtl
, 0), 0);
28087 if (GET_CODE (rtl
) == CONST_STRING
)
28089 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
28090 tree t
= build_string (len
, XSTR (rtl
, 0));
28091 tree tlen
= size_int (len
- 1);
28094 = build_array_type (char_type_node
, build_index_type (tlen
));
28095 rtl
= string_cst_pool_decl (t
);
28099 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
28101 decl
= SYMBOL_REF_DECL (rtl
);
28102 if (VAR_P (decl
) && !DECL_EXTERNAL (decl
))
28104 ref
= lookup_decl_die (decl
);
28105 if (ref
&& (get_AT (ref
, DW_AT_location
)
28106 || get_AT (ref
, DW_AT_const_value
)))
28108 loc
->dw_loc_opc
= dwarf_OP (DW_OP_implicit_pointer
);
28109 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28110 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
28111 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
28112 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28113 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
28114 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
28122 /* Helper function for resolve_addr, handle one location
28123 expression, return false if at least one CONST_STRING or SYMBOL_REF in
28124 the location list couldn't be resolved. */
28127 resolve_addr_in_expr (dw_loc_descr_ref loc
)
28129 dw_loc_descr_ref keep
= NULL
;
28130 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
28131 switch (loc
->dw_loc_opc
)
28134 if (!resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
28137 || prev
->dw_loc_opc
== DW_OP_piece
28138 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
28139 && loc
->dw_loc_next
28140 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
28141 && (!dwarf_strict
|| dwarf_version
>= 5)
28142 && optimize_one_addr_into_implicit_ptr (loc
))
28147 case DW_OP_GNU_addr_index
:
28148 case DW_OP_GNU_const_index
:
28149 if (loc
->dw_loc_opc
== DW_OP_GNU_addr_index
28150 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
28152 rtx rtl
= loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
;
28153 if (!resolve_one_addr (&rtl
))
28155 remove_addr_table_entry (loc
->dw_loc_oprnd1
.val_entry
);
28156 loc
->dw_loc_oprnd1
.val_entry
28157 = add_addr_table_entry (rtl
, ate_kind_rtx
);
28160 case DW_OP_const4u
:
28161 case DW_OP_const8u
:
28163 && !resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
28166 case DW_OP_plus_uconst
:
28167 if (size_of_loc_descr (loc
)
28168 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
28170 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
28172 dw_loc_descr_ref repl
28173 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
28174 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
28175 add_loc_descr (&repl
, loc
->dw_loc_next
);
28179 case DW_OP_implicit_value
:
28180 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
28181 && !resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
))
28184 case DW_OP_implicit_pointer
:
28185 case DW_OP_GNU_implicit_pointer
:
28186 case DW_OP_GNU_parameter_ref
:
28187 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
28190 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
28193 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28194 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
28195 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28198 case DW_OP_const_type
:
28199 case DW_OP_regval_type
:
28200 case DW_OP_deref_type
:
28201 case DW_OP_convert
:
28202 case DW_OP_reinterpret
:
28203 case DW_OP_GNU_const_type
:
28204 case DW_OP_GNU_regval_type
:
28205 case DW_OP_GNU_deref_type
:
28206 case DW_OP_GNU_convert
:
28207 case DW_OP_GNU_reinterpret
:
28208 while (loc
->dw_loc_next
28209 && (loc
->dw_loc_next
->dw_loc_opc
== DW_OP_convert
28210 || loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
))
28212 dw_die_ref base1
, base2
;
28213 unsigned enc1
, enc2
, size1
, size2
;
28214 if (loc
->dw_loc_opc
== DW_OP_regval_type
28215 || loc
->dw_loc_opc
== DW_OP_deref_type
28216 || loc
->dw_loc_opc
== DW_OP_GNU_regval_type
28217 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
28218 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
28219 else if (loc
->dw_loc_oprnd1
.val_class
28220 == dw_val_class_unsigned_const
)
28223 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28224 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
28225 == dw_val_class_unsigned_const
)
28227 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28228 gcc_assert (base1
->die_tag
== DW_TAG_base_type
28229 && base2
->die_tag
== DW_TAG_base_type
);
28230 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
28231 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
28232 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
28233 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
28235 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
28236 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
28240 /* Optimize away next DW_OP_convert after
28241 adjusting LOC's base type die reference. */
28242 if (loc
->dw_loc_opc
== DW_OP_regval_type
28243 || loc
->dw_loc_opc
== DW_OP_deref_type
28244 || loc
->dw_loc_opc
== DW_OP_GNU_regval_type
28245 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
28246 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
28248 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
28249 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
28252 /* Don't change integer DW_OP_convert after e.g. floating
28253 point typed stack entry. */
28254 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
28255 keep
= loc
->dw_loc_next
;
28265 /* Helper function of resolve_addr. DIE had DW_AT_location of
28266 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
28267 and DW_OP_addr couldn't be resolved. resolve_addr has already
28268 removed the DW_AT_location attribute. This function attempts to
28269 add a new DW_AT_location attribute with DW_OP_implicit_pointer
28270 to it or DW_AT_const_value attribute, if possible. */
28273 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
28276 || lookup_decl_die (decl
) != die
28277 || DECL_EXTERNAL (decl
)
28278 || !TREE_STATIC (decl
)
28279 || DECL_INITIAL (decl
) == NULL_TREE
28280 || DECL_P (DECL_INITIAL (decl
))
28281 || get_AT (die
, DW_AT_const_value
))
28284 tree init
= DECL_INITIAL (decl
);
28285 HOST_WIDE_INT offset
= 0;
28286 /* For variables that have been optimized away and thus
28287 don't have a memory location, see if we can emit
28288 DW_AT_const_value instead. */
28289 if (tree_add_const_value_attribute (die
, init
))
28291 if (dwarf_strict
&& dwarf_version
< 5)
28293 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
28294 and ADDR_EXPR refers to a decl that has DW_AT_location or
28295 DW_AT_const_value (but isn't addressable, otherwise
28296 resolving the original DW_OP_addr wouldn't fail), see if
28297 we can add DW_OP_implicit_pointer. */
28299 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
28300 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
28302 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
28303 init
= TREE_OPERAND (init
, 0);
28306 if (TREE_CODE (init
) != ADDR_EXPR
)
28308 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
28309 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
28310 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
28311 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
28312 && TREE_OPERAND (init
, 0) != decl
))
28315 dw_loc_descr_ref l
;
28317 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
28319 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
28322 decl
= SYMBOL_REF_DECL (rtl
);
28325 decl
= TREE_OPERAND (init
, 0);
28326 ref
= lookup_decl_die (decl
);
28328 || (!get_AT (ref
, DW_AT_location
)
28329 && !get_AT (ref
, DW_AT_const_value
)))
28331 l
= new_loc_descr (dwarf_OP (DW_OP_implicit_pointer
), 0, offset
);
28332 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
28333 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
28334 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
28335 add_AT_loc (die
, DW_AT_location
, l
);
28339 /* Return NULL if l is a DWARF expression, or first op that is not
28340 valid DWARF expression. */
28342 static dw_loc_descr_ref
28343 non_dwarf_expression (dw_loc_descr_ref l
)
28347 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
28349 switch (l
->dw_loc_opc
)
28352 case DW_OP_implicit_value
:
28353 case DW_OP_stack_value
:
28354 case DW_OP_implicit_pointer
:
28355 case DW_OP_GNU_implicit_pointer
:
28356 case DW_OP_GNU_parameter_ref
:
28358 case DW_OP_bit_piece
:
28363 l
= l
->dw_loc_next
;
28368 /* Return adjusted copy of EXPR:
28369 If it is empty DWARF expression, return it.
28370 If it is valid non-empty DWARF expression,
28371 return copy of EXPR with copy of DEREF appended to it.
28372 If it is DWARF expression followed by DW_OP_reg{N,x}, return
28373 copy of the DWARF expression with DW_OP_breg{N,x} <0> appended
28375 If it is DWARF expression followed by DW_OP_stack_value, return
28376 copy of the DWARF expression without anything appended.
28377 Otherwise, return NULL. */
28379 static dw_loc_descr_ref
28380 copy_deref_exprloc (dw_loc_descr_ref expr
, dw_loc_descr_ref deref
)
28386 dw_loc_descr_ref l
= non_dwarf_expression (expr
);
28387 if (l
&& l
->dw_loc_next
)
28392 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
28393 deref
= new_loc_descr ((enum dwarf_location_atom
)
28394 (DW_OP_breg0
+ (l
->dw_loc_opc
- DW_OP_reg0
)),
28397 switch (l
->dw_loc_opc
)
28400 deref
= new_loc_descr (DW_OP_bregx
,
28401 l
->dw_loc_oprnd1
.v
.val_unsigned
, 0);
28403 case DW_OP_stack_value
:
28411 deref
= new_loc_descr (deref
->dw_loc_opc
,
28412 deref
->dw_loc_oprnd1
.v
.val_int
, 0);
28414 dw_loc_descr_ref ret
= NULL
, *p
= &ret
;
28417 *p
= new_loc_descr (expr
->dw_loc_opc
, 0, 0);
28418 (*p
)->dw_loc_oprnd1
= expr
->dw_loc_oprnd1
;
28419 (*p
)->dw_loc_oprnd2
= expr
->dw_loc_oprnd2
;
28420 p
= &(*p
)->dw_loc_next
;
28421 expr
= expr
->dw_loc_next
;
28427 /* For DW_AT_string_length attribute with DW_OP_call4 reference to a variable
28428 or argument, adjust it if needed and return:
28429 -1 if the DW_AT_string_length attribute and DW_AT_{string_length_,}byte_size
28430 attribute if present should be removed
28431 0 keep the attribute as is if the referenced var or argument has
28432 only DWARF expression that covers all ranges
28433 1 if the attribute has been successfully adjusted. */
28436 optimize_string_length (dw_attr_node
*a
)
28438 dw_loc_descr_ref l
= AT_loc (a
), lv
;
28439 dw_die_ref die
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
28440 dw_attr_node
*av
= get_AT (die
, DW_AT_location
);
28442 bool non_dwarf_expr
= false;
28446 switch (AT_class (av
))
28448 case dw_val_class_loc_list
:
28449 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
28450 if (d
->expr
&& non_dwarf_expression (d
->expr
))
28451 non_dwarf_expr
= true;
28453 case dw_val_class_loc
:
28457 if (non_dwarf_expression (lv
))
28458 non_dwarf_expr
= true;
28464 /* If it is safe to keep DW_OP_call4 in, keep it. */
28465 if (!non_dwarf_expr
28466 && (l
->dw_loc_next
== NULL
|| AT_class (av
) == dw_val_class_loc
))
28469 /* If not dereferencing the DW_OP_call4 afterwards, we can just
28470 copy over the DW_AT_location attribute from die to a. */
28471 if (l
->dw_loc_next
== NULL
)
28473 a
->dw_attr_val
= av
->dw_attr_val
;
28477 dw_loc_list_ref list
, *p
;
28478 switch (AT_class (av
))
28480 case dw_val_class_loc_list
:
28483 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
28485 lv
= copy_deref_exprloc (d
->expr
, l
->dw_loc_next
);
28488 *p
= new_loc_list (lv
, d
->begin
, d
->end
, d
->section
);
28489 p
= &(*p
)->dw_loc_next
;
28494 a
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
28496 *AT_loc_list_ptr (a
) = list
;
28498 case dw_val_class_loc
:
28499 lv
= copy_deref_exprloc (AT_loc (av
), l
->dw_loc_next
);
28502 a
->dw_attr_val
.v
.val_loc
= lv
;
28505 gcc_unreachable ();
28509 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
28510 an address in .rodata section if the string literal is emitted there,
28511 or remove the containing location list or replace DW_AT_const_value
28512 with DW_AT_location and empty location expression, if it isn't found
28513 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
28514 to something that has been emitted in the current CU. */
28517 resolve_addr (dw_die_ref die
)
28521 dw_loc_list_ref
*curr
, *start
, loc
;
28523 bool remove_AT_byte_size
= false;
28525 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
28526 switch (AT_class (a
))
28528 case dw_val_class_loc_list
:
28529 start
= curr
= AT_loc_list_ptr (a
);
28532 /* The same list can be referenced more than once. See if we have
28533 already recorded the result from a previous pass. */
28535 *curr
= loc
->dw_loc_next
;
28536 else if (!loc
->resolved_addr
)
28538 /* As things stand, we do not expect or allow one die to
28539 reference a suffix of another die's location list chain.
28540 References must be identical or completely separate.
28541 There is therefore no need to cache the result of this
28542 pass on any list other than the first; doing so
28543 would lead to unnecessary writes. */
28546 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
28547 if (!resolve_addr_in_expr ((*curr
)->expr
))
28549 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
28550 dw_loc_descr_ref l
= (*curr
)->expr
;
28552 if (next
&& (*curr
)->ll_symbol
)
28554 gcc_assert (!next
->ll_symbol
);
28555 next
->ll_symbol
= (*curr
)->ll_symbol
;
28557 if (dwarf_split_debug_info
)
28558 remove_loc_list_addr_table_entries (l
);
28563 mark_base_types ((*curr
)->expr
);
28564 curr
= &(*curr
)->dw_loc_next
;
28568 loc
->resolved_addr
= 1;
28572 loc
->dw_loc_next
= *start
;
28577 remove_AT (die
, a
->dw_attr
);
28581 case dw_val_class_loc
:
28583 dw_loc_descr_ref l
= AT_loc (a
);
28584 /* Using DW_OP_call4 or DW_OP_call4 DW_OP_deref in
28585 DW_AT_string_length is only a rough approximation; unfortunately
28586 DW_AT_string_length can't be a reference to a DIE. DW_OP_call4
28587 needs a DWARF expression, while DW_AT_location of the referenced
28588 variable or argument might be any location description. */
28589 if (a
->dw_attr
== DW_AT_string_length
28591 && l
->dw_loc_opc
== DW_OP_call4
28592 && l
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
28593 && (l
->dw_loc_next
== NULL
28594 || (l
->dw_loc_next
->dw_loc_next
== NULL
28595 && (l
->dw_loc_next
->dw_loc_opc
== DW_OP_deref
28596 || l
->dw_loc_next
->dw_loc_opc
!= DW_OP_deref_size
))))
28598 switch (optimize_string_length (a
))
28601 remove_AT (die
, a
->dw_attr
);
28603 /* If we drop DW_AT_string_length, we need to drop also
28604 DW_AT_{string_length_,}byte_size. */
28605 remove_AT_byte_size
= true;
28610 /* Even if we keep the optimized DW_AT_string_length,
28611 it might have changed AT_class, so process it again. */
28616 /* For -gdwarf-2 don't attempt to optimize
28617 DW_AT_data_member_location containing
28618 DW_OP_plus_uconst - older consumers might
28619 rely on it being that op instead of a more complex,
28620 but shorter, location description. */
28621 if ((dwarf_version
> 2
28622 || a
->dw_attr
!= DW_AT_data_member_location
28624 || l
->dw_loc_opc
!= DW_OP_plus_uconst
28625 || l
->dw_loc_next
!= NULL
)
28626 && !resolve_addr_in_expr (l
))
28628 if (dwarf_split_debug_info
)
28629 remove_loc_list_addr_table_entries (l
);
28631 && l
->dw_loc_next
== NULL
28632 && l
->dw_loc_opc
== DW_OP_addr
28633 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
28634 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
28635 && a
->dw_attr
== DW_AT_location
)
28637 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
28638 remove_AT (die
, a
->dw_attr
);
28640 optimize_location_into_implicit_ptr (die
, decl
);
28643 remove_AT (die
, a
->dw_attr
);
28647 mark_base_types (l
);
28650 case dw_val_class_addr
:
28651 if (a
->dw_attr
== DW_AT_const_value
28652 && !resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
))
28654 if (AT_index (a
) != NOT_INDEXED
)
28655 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
28656 remove_AT (die
, a
->dw_attr
);
28659 if ((die
->die_tag
== DW_TAG_call_site
28660 && a
->dw_attr
== DW_AT_call_origin
)
28661 || (die
->die_tag
== DW_TAG_GNU_call_site
28662 && a
->dw_attr
== DW_AT_abstract_origin
))
28664 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
28665 dw_die_ref tdie
= lookup_decl_die (tdecl
);
28668 && DECL_EXTERNAL (tdecl
)
28669 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
28670 && (cdie
= lookup_context_die (DECL_CONTEXT (tdecl
))))
28672 /* Creating a full DIE for tdecl is overly expensive and
28673 at this point even wrong when in the LTO phase
28674 as it can end up generating new type DIEs we didn't
28675 output and thus optimize_external_refs will crash. */
28676 tdie
= new_die (DW_TAG_subprogram
, cdie
, NULL_TREE
);
28677 add_AT_flag (tdie
, DW_AT_external
, 1);
28678 add_AT_flag (tdie
, DW_AT_declaration
, 1);
28679 add_linkage_attr (tdie
, tdecl
);
28680 add_name_and_src_coords_attributes (tdie
, tdecl
);
28681 equate_decl_number_to_die (tdecl
, tdie
);
28685 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
28686 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
28687 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
28691 if (AT_index (a
) != NOT_INDEXED
)
28692 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
28693 remove_AT (die
, a
->dw_attr
);
28702 if (remove_AT_byte_size
)
28703 remove_AT (die
, dwarf_version
>= 5
28704 ? DW_AT_string_length_byte_size
28705 : DW_AT_byte_size
);
28707 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
28710 /* Helper routines for optimize_location_lists.
28711 This pass tries to share identical local lists in .debug_loc
28714 /* Iteratively hash operands of LOC opcode into HSTATE. */
28717 hash_loc_operands (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
28719 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
28720 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
28722 switch (loc
->dw_loc_opc
)
28724 case DW_OP_const4u
:
28725 case DW_OP_const8u
:
28729 case DW_OP_const1u
:
28730 case DW_OP_const1s
:
28731 case DW_OP_const2u
:
28732 case DW_OP_const2s
:
28733 case DW_OP_const4s
:
28734 case DW_OP_const8s
:
28738 case DW_OP_plus_uconst
:
28774 case DW_OP_deref_size
:
28775 case DW_OP_xderef_size
:
28776 hstate
.add_object (val1
->v
.val_int
);
28783 gcc_assert (val1
->val_class
== dw_val_class_loc
);
28784 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
28785 hstate
.add_object (offset
);
28788 case DW_OP_implicit_value
:
28789 hstate
.add_object (val1
->v
.val_unsigned
);
28790 switch (val2
->val_class
)
28792 case dw_val_class_const
:
28793 hstate
.add_object (val2
->v
.val_int
);
28795 case dw_val_class_vec
:
28797 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
28798 unsigned int len
= val2
->v
.val_vec
.length
;
28800 hstate
.add_int (elt_size
);
28801 hstate
.add_int (len
);
28802 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
28805 case dw_val_class_const_double
:
28806 hstate
.add_object (val2
->v
.val_double
.low
);
28807 hstate
.add_object (val2
->v
.val_double
.high
);
28809 case dw_val_class_wide_int
:
28810 hstate
.add (val2
->v
.val_wide
->get_val (),
28811 get_full_len (*val2
->v
.val_wide
)
28812 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
28814 case dw_val_class_addr
:
28815 inchash::add_rtx (val2
->v
.val_addr
, hstate
);
28818 gcc_unreachable ();
28822 case DW_OP_bit_piece
:
28823 hstate
.add_object (val1
->v
.val_int
);
28824 hstate
.add_object (val2
->v
.val_int
);
28830 unsigned char dtprel
= 0xd1;
28831 hstate
.add_object (dtprel
);
28833 inchash::add_rtx (val1
->v
.val_addr
, hstate
);
28835 case DW_OP_GNU_addr_index
:
28836 case DW_OP_GNU_const_index
:
28840 unsigned char dtprel
= 0xd1;
28841 hstate
.add_object (dtprel
);
28843 inchash::add_rtx (val1
->val_entry
->addr
.rtl
, hstate
);
28846 case DW_OP_implicit_pointer
:
28847 case DW_OP_GNU_implicit_pointer
:
28848 hstate
.add_int (val2
->v
.val_int
);
28850 case DW_OP_entry_value
:
28851 case DW_OP_GNU_entry_value
:
28852 hstate
.add_object (val1
->v
.val_loc
);
28854 case DW_OP_regval_type
:
28855 case DW_OP_deref_type
:
28856 case DW_OP_GNU_regval_type
:
28857 case DW_OP_GNU_deref_type
:
28859 unsigned int byte_size
28860 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
28861 unsigned int encoding
28862 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
28863 hstate
.add_object (val1
->v
.val_int
);
28864 hstate
.add_object (byte_size
);
28865 hstate
.add_object (encoding
);
28868 case DW_OP_convert
:
28869 case DW_OP_reinterpret
:
28870 case DW_OP_GNU_convert
:
28871 case DW_OP_GNU_reinterpret
:
28872 if (val1
->val_class
== dw_val_class_unsigned_const
)
28874 hstate
.add_object (val1
->v
.val_unsigned
);
28878 case DW_OP_const_type
:
28879 case DW_OP_GNU_const_type
:
28881 unsigned int byte_size
28882 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
28883 unsigned int encoding
28884 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
28885 hstate
.add_object (byte_size
);
28886 hstate
.add_object (encoding
);
28887 if (loc
->dw_loc_opc
!= DW_OP_const_type
28888 && loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
28890 hstate
.add_object (val2
->val_class
);
28891 switch (val2
->val_class
)
28893 case dw_val_class_const
:
28894 hstate
.add_object (val2
->v
.val_int
);
28896 case dw_val_class_vec
:
28898 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
28899 unsigned int len
= val2
->v
.val_vec
.length
;
28901 hstate
.add_object (elt_size
);
28902 hstate
.add_object (len
);
28903 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
28906 case dw_val_class_const_double
:
28907 hstate
.add_object (val2
->v
.val_double
.low
);
28908 hstate
.add_object (val2
->v
.val_double
.high
);
28910 case dw_val_class_wide_int
:
28911 hstate
.add (val2
->v
.val_wide
->get_val (),
28912 get_full_len (*val2
->v
.val_wide
)
28913 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
28916 gcc_unreachable ();
28922 /* Other codes have no operands. */
28927 /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
28930 hash_locs (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
28932 dw_loc_descr_ref l
;
28933 bool sizes_computed
= false;
28934 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
28935 size_of_locs (loc
);
28937 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
28939 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
28940 hstate
.add_object (opc
);
28941 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
28943 size_of_locs (loc
);
28944 sizes_computed
= true;
28946 hash_loc_operands (l
, hstate
);
28950 /* Compute hash of the whole location list LIST_HEAD. */
28953 hash_loc_list (dw_loc_list_ref list_head
)
28955 dw_loc_list_ref curr
= list_head
;
28956 inchash::hash hstate
;
28958 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
28960 hstate
.add (curr
->begin
, strlen (curr
->begin
) + 1);
28961 hstate
.add (curr
->end
, strlen (curr
->end
) + 1);
28963 hstate
.add (curr
->section
, strlen (curr
->section
) + 1);
28964 hash_locs (curr
->expr
, hstate
);
28966 list_head
->hash
= hstate
.end ();
28969 /* Return true if X and Y opcodes have the same operands. */
28972 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
28974 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
28975 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
28976 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
28977 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
28979 switch (x
->dw_loc_opc
)
28981 case DW_OP_const4u
:
28982 case DW_OP_const8u
:
28986 case DW_OP_const1u
:
28987 case DW_OP_const1s
:
28988 case DW_OP_const2u
:
28989 case DW_OP_const2s
:
28990 case DW_OP_const4s
:
28991 case DW_OP_const8s
:
28995 case DW_OP_plus_uconst
:
29031 case DW_OP_deref_size
:
29032 case DW_OP_xderef_size
:
29033 return valx1
->v
.val_int
== valy1
->v
.val_int
;
29036 /* If splitting debug info, the use of DW_OP_GNU_addr_index
29037 can cause irrelevant differences in dw_loc_addr. */
29038 gcc_assert (valx1
->val_class
== dw_val_class_loc
29039 && valy1
->val_class
== dw_val_class_loc
29040 && (dwarf_split_debug_info
29041 || x
->dw_loc_addr
== y
->dw_loc_addr
));
29042 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
29043 case DW_OP_implicit_value
:
29044 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
29045 || valx2
->val_class
!= valy2
->val_class
)
29047 switch (valx2
->val_class
)
29049 case dw_val_class_const
:
29050 return valx2
->v
.val_int
== valy2
->v
.val_int
;
29051 case dw_val_class_vec
:
29052 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
29053 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
29054 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
29055 valx2
->v
.val_vec
.elt_size
29056 * valx2
->v
.val_vec
.length
) == 0;
29057 case dw_val_class_const_double
:
29058 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
29059 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
29060 case dw_val_class_wide_int
:
29061 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
29062 case dw_val_class_addr
:
29063 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
29065 gcc_unreachable ();
29068 case DW_OP_bit_piece
:
29069 return valx1
->v
.val_int
== valy1
->v
.val_int
29070 && valx2
->v
.val_int
== valy2
->v
.val_int
;
29073 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
29074 case DW_OP_GNU_addr_index
:
29075 case DW_OP_GNU_const_index
:
29077 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
29078 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
29079 return rtx_equal_p (ax1
, ay1
);
29081 case DW_OP_implicit_pointer
:
29082 case DW_OP_GNU_implicit_pointer
:
29083 return valx1
->val_class
== dw_val_class_die_ref
29084 && valx1
->val_class
== valy1
->val_class
29085 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
29086 && valx2
->v
.val_int
== valy2
->v
.val_int
;
29087 case DW_OP_entry_value
:
29088 case DW_OP_GNU_entry_value
:
29089 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
29090 case DW_OP_const_type
:
29091 case DW_OP_GNU_const_type
:
29092 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
29093 || valx2
->val_class
!= valy2
->val_class
)
29095 switch (valx2
->val_class
)
29097 case dw_val_class_const
:
29098 return valx2
->v
.val_int
== valy2
->v
.val_int
;
29099 case dw_val_class_vec
:
29100 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
29101 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
29102 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
29103 valx2
->v
.val_vec
.elt_size
29104 * valx2
->v
.val_vec
.length
) == 0;
29105 case dw_val_class_const_double
:
29106 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
29107 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
29108 case dw_val_class_wide_int
:
29109 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
29111 gcc_unreachable ();
29113 case DW_OP_regval_type
:
29114 case DW_OP_deref_type
:
29115 case DW_OP_GNU_regval_type
:
29116 case DW_OP_GNU_deref_type
:
29117 return valx1
->v
.val_int
== valy1
->v
.val_int
29118 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
29119 case DW_OP_convert
:
29120 case DW_OP_reinterpret
:
29121 case DW_OP_GNU_convert
:
29122 case DW_OP_GNU_reinterpret
:
29123 if (valx1
->val_class
!= valy1
->val_class
)
29125 if (valx1
->val_class
== dw_val_class_unsigned_const
)
29126 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
29127 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
29128 case DW_OP_GNU_parameter_ref
:
29129 return valx1
->val_class
== dw_val_class_die_ref
29130 && valx1
->val_class
== valy1
->val_class
29131 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
29133 /* Other codes have no operands. */
29138 /* Return true if DWARF location expressions X and Y are the same. */
29141 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
29143 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
29144 if (x
->dw_loc_opc
!= y
->dw_loc_opc
29145 || x
->dtprel
!= y
->dtprel
29146 || !compare_loc_operands (x
, y
))
29148 return x
== NULL
&& y
== NULL
;
29151 /* Hashtable helpers. */
29153 struct loc_list_hasher
: nofree_ptr_hash
<dw_loc_list_struct
>
29155 static inline hashval_t
hash (const dw_loc_list_struct
*);
29156 static inline bool equal (const dw_loc_list_struct
*,
29157 const dw_loc_list_struct
*);
29160 /* Return precomputed hash of location list X. */
29163 loc_list_hasher::hash (const dw_loc_list_struct
*x
)
29168 /* Return true if location lists A and B are the same. */
29171 loc_list_hasher::equal (const dw_loc_list_struct
*a
,
29172 const dw_loc_list_struct
*b
)
29176 if (a
->hash
!= b
->hash
)
29178 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
29179 if (strcmp (a
->begin
, b
->begin
) != 0
29180 || strcmp (a
->end
, b
->end
) != 0
29181 || (a
->section
== NULL
) != (b
->section
== NULL
)
29182 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
29183 || !compare_locs (a
->expr
, b
->expr
))
29185 return a
== NULL
&& b
== NULL
;
29188 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
29191 /* Recursively optimize location lists referenced from DIE
29192 children and share them whenever possible. */
29195 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type
*htab
)
29200 dw_loc_list_struct
**slot
;
29202 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
29203 if (AT_class (a
) == dw_val_class_loc_list
)
29205 dw_loc_list_ref list
= AT_loc_list (a
);
29206 /* TODO: perform some optimizations here, before hashing
29207 it and storing into the hash table. */
29208 hash_loc_list (list
);
29209 slot
= htab
->find_slot_with_hash (list
, list
->hash
, INSERT
);
29213 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
29216 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
29220 /* Recursively assign each location list a unique index into the debug_addr
29224 index_location_lists (dw_die_ref die
)
29230 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
29231 if (AT_class (a
) == dw_val_class_loc_list
)
29233 dw_loc_list_ref list
= AT_loc_list (a
);
29234 dw_loc_list_ref curr
;
29235 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
29237 /* Don't index an entry that has already been indexed
29238 or won't be output. */
29239 if (curr
->begin_entry
!= NULL
29240 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
29244 = add_addr_table_entry (xstrdup (curr
->begin
), ate_kind_label
);
29248 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
29251 /* Optimize location lists referenced from DIE
29252 children and share them whenever possible. */
29255 optimize_location_lists (dw_die_ref die
)
29257 loc_list_hash_type
htab (500);
29258 optimize_location_lists_1 (die
, &htab
);
29261 /* Traverse the limbo die list, and add parent/child links. The only
29262 dies without parents that should be here are concrete instances of
29263 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
29264 For concrete instances, we can get the parent die from the abstract
29268 flush_limbo_die_list (void)
29270 limbo_die_node
*node
;
29272 /* get_context_die calls force_decl_die, which can put new DIEs on the
29273 limbo list in LTO mode when nested functions are put in a different
29274 partition than that of their parent function. */
29275 while ((node
= limbo_die_list
))
29277 dw_die_ref die
= node
->die
;
29278 limbo_die_list
= node
->next
;
29280 if (die
->die_parent
== NULL
)
29282 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
29284 if (origin
&& origin
->die_parent
)
29285 add_child_die (origin
->die_parent
, die
);
29286 else if (is_cu_die (die
))
29288 else if (seen_error ())
29289 /* It's OK to be confused by errors in the input. */
29290 add_child_die (comp_unit_die (), die
);
29293 /* In certain situations, the lexical block containing a
29294 nested function can be optimized away, which results
29295 in the nested function die being orphaned. Likewise
29296 with the return type of that nested function. Force
29297 this to be a child of the containing function.
29299 It may happen that even the containing function got fully
29300 inlined and optimized out. In that case we are lost and
29301 assign the empty child. This should not be big issue as
29302 the function is likely unreachable too. */
29303 gcc_assert (node
->created_for
);
29305 if (DECL_P (node
->created_for
))
29306 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
29307 else if (TYPE_P (node
->created_for
))
29308 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
29310 origin
= comp_unit_die ();
29312 add_child_die (origin
, die
);
29318 /* Output stuff that dwarf requires at the end of every file,
29319 and generate the DWARF-2 debugging info. */
29322 dwarf2out_finish (const char *)
29324 comdat_type_node
*ctnode
;
29325 dw_die_ref main_comp_unit_die
;
29326 unsigned char checksum
[16];
29328 /* Flush out any latecomers to the limbo party. */
29329 flush_limbo_die_list ();
29333 verify_die (comp_unit_die ());
29334 for (limbo_die_node
*node
= cu_die_list
; node
; node
= node
->next
)
29335 verify_die (node
->die
);
29338 /* We shouldn't have any symbols with delayed asm names for
29339 DIEs generated after early finish. */
29340 gcc_assert (deferred_asm_name
== NULL
);
29342 gen_remaining_tmpl_value_param_die_attribute ();
29344 #if ENABLE_ASSERT_CHECKING
29346 dw_die_ref die
= comp_unit_die (), c
;
29347 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
29350 resolve_addr (comp_unit_die ());
29351 move_marked_base_types ();
29353 /* Initialize sections and labels used for actual assembler output. */
29354 init_sections_and_labels ();
29356 /* Traverse the DIE's and add sibling attributes to those DIE's that
29358 add_sibling_attributes (comp_unit_die ());
29359 limbo_die_node
*node
;
29360 for (node
= cu_die_list
; node
; node
= node
->next
)
29361 add_sibling_attributes (node
->die
);
29362 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
29363 add_sibling_attributes (ctnode
->root_die
);
29365 /* When splitting DWARF info, we put some attributes in the
29366 skeleton compile_unit DIE that remains in the .o, while
29367 most attributes go in the DWO compile_unit_die. */
29368 if (dwarf_split_debug_info
)
29370 limbo_die_node
*cu
;
29371 main_comp_unit_die
= gen_compile_unit_die (NULL
);
29372 if (dwarf_version
>= 5)
29373 main_comp_unit_die
->die_tag
= DW_TAG_skeleton_unit
;
29374 cu
= limbo_die_list
;
29375 gcc_assert (cu
->die
== main_comp_unit_die
);
29376 limbo_die_list
= limbo_die_list
->next
;
29377 cu
->next
= cu_die_list
;
29381 main_comp_unit_die
= comp_unit_die ();
29383 /* Output a terminator label for the .text section. */
29384 switch_to_section (text_section
);
29385 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
29386 if (cold_text_section
)
29388 switch_to_section (cold_text_section
);
29389 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
29392 /* We can only use the low/high_pc attributes if all of the code was
29394 if (!have_multiple_function_sections
29395 || (dwarf_version
< 3 && dwarf_strict
))
29397 /* Don't add if the CU has no associated code. */
29398 if (text_section_used
)
29399 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
29400 text_end_label
, true);
29406 bool range_list_added
= false;
29408 if (text_section_used
)
29409 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
29410 text_end_label
, &range_list_added
, true);
29411 if (cold_text_section_used
)
29412 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
29413 cold_end_label
, &range_list_added
, true);
29415 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
29417 if (DECL_IGNORED_P (fde
->decl
))
29419 if (!fde
->in_std_section
)
29420 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
29421 fde
->dw_fde_end
, &range_list_added
,
29423 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
29424 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
29425 fde
->dw_fde_second_end
, &range_list_added
,
29429 if (range_list_added
)
29431 /* We need to give .debug_loc and .debug_ranges an appropriate
29432 "base address". Use zero so that these addresses become
29433 absolute. Historically, we've emitted the unexpected
29434 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
29435 Emit both to give time for other tools to adapt. */
29436 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
29437 if (! dwarf_strict
&& dwarf_version
< 4)
29438 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
29444 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
29445 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
29446 debug_line_section_label
);
29449 add_AT_macptr (comp_unit_die (),
29450 dwarf_version
>= 5 ? DW_AT_macros
29451 : dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
29452 macinfo_section_label
);
29454 if (dwarf_split_debug_info
)
29456 if (have_location_lists
)
29458 if (dwarf_version
>= 5)
29459 add_AT_loclistsptr (comp_unit_die (), DW_AT_loclists_base
,
29460 loc_section_label
);
29461 /* optimize_location_lists calculates the size of the lists,
29462 so index them first, and assign indices to the entries.
29463 Although optimize_location_lists will remove entries from
29464 the table, it only does so for duplicates, and therefore
29465 only reduces ref_counts to 1. */
29466 index_location_lists (comp_unit_die ());
29469 if (addr_index_table
!= NULL
)
29471 unsigned int index
= 0;
29473 ->traverse_noresize
<unsigned int *, index_addr_table_entry
>
29479 if (have_location_lists
)
29481 optimize_location_lists (comp_unit_die ());
29482 /* And finally assign indexes to the entries for -gsplit-dwarf. */
29483 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
29484 assign_location_list_indexes (comp_unit_die ());
29487 save_macinfo_strings ();
29489 if (dwarf_split_debug_info
)
29491 unsigned int index
= 0;
29493 /* Add attributes common to skeleton compile_units and
29494 type_units. Because these attributes include strings, it
29495 must be done before freezing the string table. Top-level
29496 skeleton die attrs are added when the skeleton type unit is
29497 created, so ensure it is created by this point. */
29498 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
29499 debug_str_hash
->traverse_noresize
<unsigned int *, index_string
> (&index
);
29502 /* Output all of the compilation units. We put the main one last so that
29503 the offsets are available to output_pubnames. */
29504 for (node
= cu_die_list
; node
; node
= node
->next
)
29505 output_comp_unit (node
->die
, 0, NULL
);
29507 hash_table
<comdat_type_hasher
> comdat_type_table (100);
29508 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
29510 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
29512 /* Don't output duplicate types. */
29513 if (*slot
!= HTAB_EMPTY_ENTRY
)
29516 /* Add a pointer to the line table for the main compilation unit
29517 so that the debugger can make sense of DW_AT_decl_file
29519 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
29520 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
29521 (!dwarf_split_debug_info
29522 ? debug_line_section_label
29523 : debug_skeleton_line_section_label
));
29525 output_comdat_type_unit (ctnode
);
29529 /* The AT_pubnames attribute needs to go in all skeleton dies, including
29530 both the main_cu and all skeleton TUs. Making this call unconditional
29531 would end up either adding a second copy of the AT_pubnames attribute, or
29532 requiring a special case in add_top_level_skeleton_die_attrs. */
29533 if (!dwarf_split_debug_info
)
29534 add_AT_pubnames (comp_unit_die ());
29536 if (dwarf_split_debug_info
)
29539 struct md5_ctx ctx
;
29541 if (dwarf_version
>= 5 && !vec_safe_is_empty (ranges_table
))
29544 /* Compute a checksum of the comp_unit to use as the dwo_id. */
29545 md5_init_ctx (&ctx
);
29547 die_checksum (comp_unit_die (), &ctx
, &mark
);
29548 unmark_all_dies (comp_unit_die ());
29549 md5_finish_ctx (&ctx
, checksum
);
29551 if (dwarf_version
< 5)
29553 /* Use the first 8 bytes of the checksum as the dwo_id,
29554 and add it to both comp-unit DIEs. */
29555 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
29556 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
29559 /* Add the base offset of the ranges table to the skeleton
29561 if (!vec_safe_is_empty (ranges_table
))
29563 if (dwarf_version
>= 5)
29564 add_AT_lineptr (main_comp_unit_die
, DW_AT_rnglists_base
,
29565 ranges_base_label
);
29567 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
29568 ranges_section_label
);
29571 switch_to_section (debug_addr_section
);
29572 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
29573 output_addr_table ();
29576 /* Output the main compilation unit if non-empty or if .debug_macinfo
29577 or .debug_macro will be emitted. */
29578 output_comp_unit (comp_unit_die (), have_macinfo
,
29579 dwarf_split_debug_info
? checksum
: NULL
);
29581 if (dwarf_split_debug_info
&& info_section_emitted
)
29582 output_skeleton_debug_sections (main_comp_unit_die
, checksum
);
29584 /* Output the abbreviation table. */
29585 if (vec_safe_length (abbrev_die_table
) != 1)
29587 switch_to_section (debug_abbrev_section
);
29588 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
29589 output_abbrev_section ();
29592 /* Output location list section if necessary. */
29593 if (have_location_lists
)
29595 char l1
[MAX_ARTIFICIAL_LABEL_BYTES
];
29596 char l2
[MAX_ARTIFICIAL_LABEL_BYTES
];
29597 /* Output the location lists info. */
29598 switch_to_section (debug_loc_section
);
29599 if (dwarf_version
>= 5)
29601 ASM_GENERATE_INTERNAL_LABEL (l1
, DEBUG_LOC_SECTION_LABEL
, 1);
29602 ASM_GENERATE_INTERNAL_LABEL (l2
, DEBUG_LOC_SECTION_LABEL
, 2);
29603 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
29604 dw2_asm_output_data (4, 0xffffffff,
29605 "Initial length escape value indicating "
29606 "64-bit DWARF extension");
29607 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
29608 "Length of Location Lists");
29609 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
29610 dw2_asm_output_data (2, dwarf_version
, "DWARF Version");
29611 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Address Size");
29612 dw2_asm_output_data (1, 0, "Segment Size");
29613 dw2_asm_output_data (4, dwarf_split_debug_info
? loc_list_idx
: 0,
29614 "Offset Entry Count");
29616 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
29617 if (dwarf_version
>= 5 && dwarf_split_debug_info
)
29619 unsigned int save_loc_list_idx
= loc_list_idx
;
29621 output_loclists_offsets (comp_unit_die ());
29622 gcc_assert (save_loc_list_idx
== loc_list_idx
);
29624 output_location_lists (comp_unit_die ());
29625 if (dwarf_version
>= 5)
29626 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
29629 output_pubtables ();
29631 /* Output the address range information if a CU (.debug_info section)
29632 was emitted. We output an empty table even if we had no functions
29633 to put in it. This because the consumer has no way to tell the
29634 difference between an empty table that we omitted and failure to
29635 generate a table that would have contained data. */
29636 if (info_section_emitted
)
29638 switch_to_section (debug_aranges_section
);
29642 /* Output ranges section if necessary. */
29643 if (!vec_safe_is_empty (ranges_table
))
29645 if (dwarf_version
>= 5)
29646 output_rnglists ();
29651 /* Have to end the macro section. */
29654 switch_to_section (debug_macinfo_section
);
29655 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
29657 dw2_asm_output_data (1, 0, "End compilation unit");
29660 /* Output the source line correspondence table. We must do this
29661 even if there is no line information. Otherwise, on an empty
29662 translation unit, we will generate a present, but empty,
29663 .debug_info section. IRIX 6.5 `nm' will then complain when
29664 examining the file. This is done late so that any filenames
29665 used by the debug_info section are marked as 'used'. */
29666 switch_to_section (debug_line_section
);
29667 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
29668 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
29669 output_line_info (false);
29671 if (dwarf_split_debug_info
&& info_section_emitted
)
29673 switch_to_section (debug_skeleton_line_section
);
29674 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
29675 output_line_info (true);
29678 /* If we emitted any indirect strings, output the string table too. */
29679 if (debug_str_hash
|| skeleton_debug_str_hash
)
29680 output_indirect_strings ();
29681 if (debug_line_str_hash
)
29683 switch_to_section (debug_line_str_section
);
29684 const enum dwarf_form form
= DW_FORM_line_strp
;
29685 debug_line_str_hash
->traverse
<enum dwarf_form
,
29686 output_indirect_string
> (form
);
29690 /* Perform any cleanups needed after the early debug generation pass
29694 dwarf2out_early_finish (const char *filename
)
29698 /* PCH might result in DW_AT_producer string being restored from the
29699 header compilation, so always fill it with empty string initially
29700 and overwrite only here. */
29701 dw_attr_node
*producer
= get_AT (comp_unit_die (), DW_AT_producer
);
29702 producer_string
= gen_producer_string ();
29703 producer
->dw_attr_val
.v
.val_str
->refcount
--;
29704 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
29706 /* Add the name for the main input file now. We delayed this from
29707 dwarf2out_init to avoid complications with PCH. */
29708 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
29709 add_comp_dir_attribute (comp_unit_die ());
29711 /* When emitting DWARF5 .debug_line_str, move DW_AT_name and
29712 DW_AT_comp_dir into .debug_line_str section. */
29713 if (!DWARF2_ASM_LINE_DEBUG_INFO
29714 && dwarf_version
>= 5
29715 && DWARF5_USE_DEBUG_LINE_STR
)
29717 for (int i
= 0; i
< 2; i
++)
29719 dw_attr_node
*a
= get_AT (comp_unit_die (),
29720 i
? DW_AT_comp_dir
: DW_AT_name
);
29722 || AT_class (a
) != dw_val_class_str
29723 || strlen (AT_string (a
)) + 1 <= DWARF_OFFSET_SIZE
)
29726 if (! debug_line_str_hash
)
29727 debug_line_str_hash
29728 = hash_table
<indirect_string_hasher
>::create_ggc (10);
29730 struct indirect_string_node
*node
29731 = find_AT_string_in_table (AT_string (a
), debug_line_str_hash
);
29732 set_indirect_string (node
);
29733 node
->form
= DW_FORM_line_strp
;
29734 a
->dw_attr_val
.v
.val_str
->refcount
--;
29735 a
->dw_attr_val
.v
.val_str
= node
;
29739 /* With LTO early dwarf was really finished at compile-time, so make
29740 sure to adjust the phase after annotating the LTRANS CU DIE. */
29743 early_dwarf_finished
= true;
29747 /* Walk through the list of incomplete types again, trying once more to
29748 emit full debugging info for them. */
29749 retry_incomplete_types ();
29751 /* The point here is to flush out the limbo list so that it is empty
29752 and we don't need to stream it for LTO. */
29753 flush_limbo_die_list ();
29755 gen_scheduled_generic_parms_dies ();
29756 gen_remaining_tmpl_value_param_die_attribute ();
29758 /* Add DW_AT_linkage_name for all deferred DIEs. */
29759 for (limbo_die_node
*node
= deferred_asm_name
; node
; node
= node
->next
)
29761 tree decl
= node
->created_for
;
29762 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
29763 /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
29764 ended up in deferred_asm_name before we knew it was
29765 constant and never written to disk. */
29766 && DECL_ASSEMBLER_NAME (decl
))
29768 add_linkage_attr (node
->die
, decl
);
29769 move_linkage_attr (node
->die
);
29772 deferred_asm_name
= NULL
;
29774 if (flag_eliminate_unused_debug_types
)
29775 prune_unused_types ();
29777 /* Generate separate COMDAT sections for type DIEs. */
29778 if (use_debug_types
)
29780 break_out_comdat_types (comp_unit_die ());
29782 /* Each new type_unit DIE was added to the limbo die list when created.
29783 Since these have all been added to comdat_type_list, clear the
29785 limbo_die_list
= NULL
;
29787 /* For each new comdat type unit, copy declarations for incomplete
29788 types to make the new unit self-contained (i.e., no direct
29789 references to the main compile unit). */
29790 for (comdat_type_node
*ctnode
= comdat_type_list
;
29791 ctnode
!= NULL
; ctnode
= ctnode
->next
)
29792 copy_decls_for_unworthy_types (ctnode
->root_die
);
29793 copy_decls_for_unworthy_types (comp_unit_die ());
29795 /* In the process of copying declarations from one unit to another,
29796 we may have left some declarations behind that are no longer
29797 referenced. Prune them. */
29798 prune_unused_types ();
29801 /* Generate separate CUs for each of the include files we've seen.
29802 They will go into limbo_die_list and from there to cu_die_list. */
29803 if (flag_eliminate_dwarf2_dups
)
29805 gcc_assert (limbo_die_list
== NULL
);
29806 break_out_includes (comp_unit_die ());
29807 limbo_die_node
*cu
;
29808 while ((cu
= limbo_die_list
))
29810 limbo_die_list
= cu
->next
;
29811 cu
->next
= cu_die_list
;
29816 /* The early debug phase is now finished. */
29817 early_dwarf_finished
= true;
29820 /* Reset all state within dwarf2out.c so that we can rerun the compiler
29821 within the same process. For use by toplev::finalize. */
29824 dwarf2out_c_finalize (void)
29826 last_var_location_insn
= NULL
;
29827 cached_next_real_insn
= NULL
;
29828 used_rtx_array
= NULL
;
29829 incomplete_types
= NULL
;
29830 decl_scope_table
= NULL
;
29831 debug_info_section
= NULL
;
29832 debug_skeleton_info_section
= NULL
;
29833 debug_abbrev_section
= NULL
;
29834 debug_skeleton_abbrev_section
= NULL
;
29835 debug_aranges_section
= NULL
;
29836 debug_addr_section
= NULL
;
29837 debug_macinfo_section
= NULL
;
29838 debug_line_section
= NULL
;
29839 debug_skeleton_line_section
= NULL
;
29840 debug_loc_section
= NULL
;
29841 debug_pubnames_section
= NULL
;
29842 debug_pubtypes_section
= NULL
;
29843 debug_str_section
= NULL
;
29844 debug_line_str_section
= NULL
;
29845 debug_str_dwo_section
= NULL
;
29846 debug_str_offsets_section
= NULL
;
29847 debug_ranges_section
= NULL
;
29848 debug_frame_section
= NULL
;
29850 debug_str_hash
= NULL
;
29851 debug_line_str_hash
= NULL
;
29852 skeleton_debug_str_hash
= NULL
;
29853 dw2_string_counter
= 0;
29854 have_multiple_function_sections
= false;
29855 text_section_used
= false;
29856 cold_text_section_used
= false;
29857 cold_text_section
= NULL
;
29858 current_unit_personality
= NULL
;
29860 early_dwarf
= false;
29861 early_dwarf_finished
= false;
29863 next_die_offset
= 0;
29864 single_comp_unit_die
= NULL
;
29865 comdat_type_list
= NULL
;
29866 limbo_die_list
= NULL
;
29868 decl_die_table
= NULL
;
29869 common_block_die_table
= NULL
;
29870 decl_loc_table
= NULL
;
29871 call_arg_locations
= NULL
;
29872 call_arg_loc_last
= NULL
;
29873 call_site_count
= -1;
29874 tail_call_site_count
= -1;
29875 cached_dw_loc_list_table
= NULL
;
29876 abbrev_die_table
= NULL
;
29877 delete dwarf_proc_stack_usage_map
;
29878 dwarf_proc_stack_usage_map
= NULL
;
29879 line_info_label_num
= 0;
29880 cur_line_info_table
= NULL
;
29881 text_section_line_info
= NULL
;
29882 cold_text_section_line_info
= NULL
;
29883 separate_line_info
= NULL
;
29884 info_section_emitted
= false;
29885 pubname_table
= NULL
;
29886 pubtype_table
= NULL
;
29887 macinfo_table
= NULL
;
29888 ranges_table
= NULL
;
29889 ranges_by_label
= NULL
;
29891 have_location_lists
= false;
29894 last_emitted_file
= NULL
;
29896 tmpl_value_parm_die_table
= NULL
;
29897 generic_type_instances
= NULL
;
29898 frame_pointer_fb_offset
= 0;
29899 frame_pointer_fb_offset_valid
= false;
29900 base_types
.release ();
29901 XDELETEVEC (producer_string
);
29902 producer_string
= NULL
;
29905 #include "gt-dwarf2out.h"