1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992-2016 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"
66 #include "stringpool.h"
67 #include "insn-config.h"
70 #include "diagnostic.h"
71 #include "fold-const.h"
72 #include "stor-layout.h"
80 #include "dwarf2out.h"
81 #include "dwarf2asm.h"
84 #include "tree-pretty-print.h"
86 #include "common/common-target.h"
87 #include "langhooks.h"
92 #include "gdb/gdb-index.h"
95 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
96 static rtx_insn
*last_var_location_insn
;
97 static rtx_insn
*cached_next_real_insn
;
98 static void dwarf2out_decl (tree
);
100 #ifndef XCOFF_DEBUGGING_INFO
101 #define XCOFF_DEBUGGING_INFO 0
104 #ifndef HAVE_XCOFF_DWARF_EXTRAS
105 #define HAVE_XCOFF_DWARF_EXTRAS 0
108 #ifdef VMS_DEBUGGING_INFO
109 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
111 /* Define this macro to be a nonzero value if the directory specifications
112 which are output in the debug info should end with a separator. */
113 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
114 /* Define this macro to evaluate to a nonzero value if GCC should refrain
115 from generating indirect strings in DWARF2 debug information, for instance
116 if your target is stuck with an old version of GDB that is unable to
117 process them properly or uses VMS Debug. */
118 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
120 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
121 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
124 /* ??? Poison these here until it can be done generically. They've been
125 totally replaced in this file; make sure it stays that way. */
126 #undef DWARF2_UNWIND_INFO
127 #undef DWARF2_FRAME_INFO
128 #if (GCC_VERSION >= 3000)
129 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
132 /* The size of the target's pointer type. */
134 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
137 /* Array of RTXes referenced by the debugging information, which therefore
138 must be kept around forever. */
139 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
141 /* A pointer to the base of a list of incomplete types which might be
142 completed at some later time. incomplete_types_list needs to be a
143 vec<tree, va_gc> *because we want to tell the garbage collector about
145 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
147 /* A pointer to the base of a table of references to declaration
148 scopes. This table is a display which tracks the nesting
149 of declaration scopes at the current scope and containing
150 scopes. This table is used to find the proper place to
151 define type declaration DIE's. */
152 static GTY(()) vec
<tree
, va_gc
> *decl_scope_table
;
154 /* Pointers to various DWARF2 sections. */
155 static GTY(()) section
*debug_info_section
;
156 static GTY(()) section
*debug_skeleton_info_section
;
157 static GTY(()) section
*debug_abbrev_section
;
158 static GTY(()) section
*debug_skeleton_abbrev_section
;
159 static GTY(()) section
*debug_aranges_section
;
160 static GTY(()) section
*debug_addr_section
;
161 static GTY(()) section
*debug_macinfo_section
;
162 static GTY(()) section
*debug_line_section
;
163 static GTY(()) section
*debug_skeleton_line_section
;
164 static GTY(()) section
*debug_loc_section
;
165 static GTY(()) section
*debug_pubnames_section
;
166 static GTY(()) section
*debug_pubtypes_section
;
167 static GTY(()) section
*debug_str_section
;
168 static GTY(()) section
*debug_str_dwo_section
;
169 static GTY(()) section
*debug_str_offsets_section
;
170 static GTY(()) section
*debug_ranges_section
;
171 static GTY(()) section
*debug_frame_section
;
173 /* Maximum size (in bytes) of an artificially generated label. */
174 #define MAX_ARTIFICIAL_LABEL_BYTES 30
176 /* According to the (draft) DWARF 3 specification, the initial length
177 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
178 bytes are 0xffffffff, followed by the length stored in the next 8
181 However, the SGI/MIPS ABI uses an initial length which is equal to
182 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
184 #ifndef DWARF_INITIAL_LENGTH_SIZE
185 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
188 /* Round SIZE up to the nearest BOUNDARY. */
189 #define DWARF_ROUND(SIZE,BOUNDARY) \
190 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
192 /* CIE identifier. */
193 #if HOST_BITS_PER_WIDE_INT >= 64
194 #define DWARF_CIE_ID \
195 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
197 #define DWARF_CIE_ID DW_CIE_ID
201 /* A vector for a table that contains frame description
202 information for each routine. */
203 #define NOT_INDEXED (-1U)
204 #define NO_INDEX_ASSIGNED (-2U)
206 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
208 struct GTY((for_user
)) indirect_string_node
{
210 unsigned int refcount
;
211 enum dwarf_form form
;
216 struct indirect_string_hasher
: ggc_ptr_hash
<indirect_string_node
>
218 typedef const char *compare_type
;
220 static hashval_t
hash (indirect_string_node
*);
221 static bool equal (indirect_string_node
*, const char *);
224 static GTY (()) hash_table
<indirect_string_hasher
> *debug_str_hash
;
226 /* With split_debug_info, both the comp_dir and dwo_name go in the
227 main object file, rather than the dwo, similar to the force_direct
228 parameter elsewhere but with additional complications:
230 1) The string is needed in both the main object file and the dwo.
231 That is, the comp_dir and dwo_name will appear in both places.
233 2) Strings can use three forms: DW_FORM_string, DW_FORM_strp or
234 DW_FORM_GNU_str_index.
236 3) GCC chooses the form to use late, depending on the size and
239 Rather than forcing the all debug string handling functions and
240 callers to deal with these complications, simply use a separate,
241 special-cased string table for any attribute that should go in the
242 main object file. This limits the complexity to just the places
245 static GTY (()) hash_table
<indirect_string_hasher
> *skeleton_debug_str_hash
;
247 static GTY(()) int dw2_string_counter
;
249 /* True if the compilation unit places functions in more than one section. */
250 static GTY(()) bool have_multiple_function_sections
= false;
252 /* Whether the default text and cold text sections have been used at all. */
254 static GTY(()) bool text_section_used
= false;
255 static GTY(()) bool cold_text_section_used
= false;
257 /* The default cold text section. */
258 static GTY(()) section
*cold_text_section
;
260 /* The DIE for C++14 'auto' in a function return type. */
261 static GTY(()) dw_die_ref auto_die
;
263 /* The DIE for C++14 'decltype(auto)' in a function return type. */
264 static GTY(()) dw_die_ref decltype_auto_die
;
266 /* Forward declarations for functions defined in this file. */
268 static char *stripattributes (const char *);
269 static void output_call_frame_info (int);
270 static void dwarf2out_note_section_used (void);
272 /* Personality decl of current unit. Used only when assembler does not support
274 static GTY(()) rtx current_unit_personality
;
276 /* Data and reference forms for relocatable data. */
277 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
278 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
280 #ifndef DEBUG_FRAME_SECTION
281 #define DEBUG_FRAME_SECTION ".debug_frame"
284 #ifndef FUNC_BEGIN_LABEL
285 #define FUNC_BEGIN_LABEL "LFB"
288 #ifndef FUNC_END_LABEL
289 #define FUNC_END_LABEL "LFE"
292 #ifndef PROLOGUE_END_LABEL
293 #define PROLOGUE_END_LABEL "LPE"
296 #ifndef EPILOGUE_BEGIN_LABEL
297 #define EPILOGUE_BEGIN_LABEL "LEB"
300 #ifndef FRAME_BEGIN_LABEL
301 #define FRAME_BEGIN_LABEL "Lframe"
303 #define CIE_AFTER_SIZE_LABEL "LSCIE"
304 #define CIE_END_LABEL "LECIE"
305 #define FDE_LABEL "LSFDE"
306 #define FDE_AFTER_SIZE_LABEL "LASFDE"
307 #define FDE_END_LABEL "LEFDE"
308 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
309 #define LINE_NUMBER_END_LABEL "LELT"
310 #define LN_PROLOG_AS_LABEL "LASLTP"
311 #define LN_PROLOG_END_LABEL "LELTP"
312 #define DIE_LABEL_PREFIX "DW"
314 /* Match the base name of a file to the base name of a compilation unit. */
317 matches_main_base (const char *path
)
319 /* Cache the last query. */
320 static const char *last_path
= NULL
;
321 static int last_match
= 0;
322 if (path
!= last_path
)
325 int length
= base_of_path (path
, &base
);
327 last_match
= (length
== main_input_baselength
328 && memcmp (base
, main_input_basename
, length
) == 0);
333 #ifdef DEBUG_DEBUG_STRUCT
336 dump_struct_debug (tree type
, enum debug_info_usage usage
,
337 enum debug_struct_file criterion
, int generic
,
338 int matches
, int result
)
340 /* Find the type name. */
341 tree type_decl
= TYPE_STUB_DECL (type
);
343 const char *name
= 0;
344 if (TREE_CODE (t
) == TYPE_DECL
)
347 name
= IDENTIFIER_POINTER (t
);
349 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
351 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
352 matches
? "bas" : "hdr",
353 generic
? "gen" : "ord",
354 usage
== DINFO_USAGE_DFN
? ";" :
355 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
357 (void*) type_decl
, name
);
360 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
361 dump_struct_debug (type, usage, criterion, generic, matches, result)
365 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
370 /* Get the number of HOST_WIDE_INTs needed to represent the precision
371 of the number. Some constants have a large uniform precision, so
372 we get the precision needed for the actual value of the number. */
375 get_full_len (const wide_int
&op
)
377 int prec
= wi::min_precision (op
, UNSIGNED
);
378 return ((prec
+ HOST_BITS_PER_WIDE_INT
- 1)
379 / HOST_BITS_PER_WIDE_INT
);
383 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
385 enum debug_struct_file criterion
;
387 bool generic
= lang_hooks
.types
.generic_p (type
);
390 criterion
= debug_struct_generic
[usage
];
392 criterion
= debug_struct_ordinary
[usage
];
394 if (criterion
== DINFO_STRUCT_FILE_NONE
)
395 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
396 if (criterion
== DINFO_STRUCT_FILE_ANY
)
397 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
399 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
401 if (type_decl
!= NULL
)
403 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
404 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
406 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
407 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
410 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
413 /* Return a pointer to a copy of the section string name S with all
414 attributes stripped off, and an asterisk prepended (for assemble_name). */
417 stripattributes (const char *s
)
419 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
424 while (*s
&& *s
!= ',')
431 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
432 switch to the data section instead, and write out a synthetic start label
433 for collect2 the first time around. */
436 switch_to_eh_frame_section (bool back ATTRIBUTE_UNUSED
)
438 if (eh_frame_section
== 0)
442 if (EH_TABLES_CAN_BE_READ_ONLY
)
448 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
450 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
452 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
455 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
456 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
457 && (per_encoding
& 0x70) != DW_EH_PE_absptr
458 && (per_encoding
& 0x70) != DW_EH_PE_aligned
459 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
460 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
461 ? 0 : SECTION_WRITE
);
464 flags
= SECTION_WRITE
;
466 #ifdef EH_FRAME_SECTION_NAME
467 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
469 eh_frame_section
= ((flags
== SECTION_WRITE
)
470 ? data_section
: readonly_data_section
);
471 #endif /* EH_FRAME_SECTION_NAME */
474 switch_to_section (eh_frame_section
);
476 #ifdef EH_FRAME_THROUGH_COLLECT2
477 /* We have no special eh_frame section. Emit special labels to guide
481 tree label
= get_file_function_name ("F");
482 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
483 targetm
.asm_out
.globalize_label (asm_out_file
,
484 IDENTIFIER_POINTER (label
));
485 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
490 /* Switch [BACK] to the eh or debug frame table section, depending on
494 switch_to_frame_table_section (int for_eh
, bool back
)
497 switch_to_eh_frame_section (back
);
500 if (!debug_frame_section
)
501 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
502 SECTION_DEBUG
, NULL
);
503 switch_to_section (debug_frame_section
);
507 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
509 enum dw_cfi_oprnd_type
510 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
515 case DW_CFA_GNU_window_save
:
516 case DW_CFA_remember_state
:
517 case DW_CFA_restore_state
:
518 return dw_cfi_oprnd_unused
;
521 case DW_CFA_advance_loc1
:
522 case DW_CFA_advance_loc2
:
523 case DW_CFA_advance_loc4
:
524 case DW_CFA_MIPS_advance_loc8
:
525 return dw_cfi_oprnd_addr
;
528 case DW_CFA_offset_extended
:
530 case DW_CFA_offset_extended_sf
:
531 case DW_CFA_def_cfa_sf
:
533 case DW_CFA_restore_extended
:
534 case DW_CFA_undefined
:
535 case DW_CFA_same_value
:
536 case DW_CFA_def_cfa_register
:
537 case DW_CFA_register
:
538 case DW_CFA_expression
:
539 return dw_cfi_oprnd_reg_num
;
541 case DW_CFA_def_cfa_offset
:
542 case DW_CFA_GNU_args_size
:
543 case DW_CFA_def_cfa_offset_sf
:
544 return dw_cfi_oprnd_offset
;
546 case DW_CFA_def_cfa_expression
:
547 return dw_cfi_oprnd_loc
;
554 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
556 enum dw_cfi_oprnd_type
557 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
562 case DW_CFA_def_cfa_sf
:
564 case DW_CFA_offset_extended_sf
:
565 case DW_CFA_offset_extended
:
566 return dw_cfi_oprnd_offset
;
568 case DW_CFA_register
:
569 return dw_cfi_oprnd_reg_num
;
571 case DW_CFA_expression
:
572 return dw_cfi_oprnd_loc
;
575 return dw_cfi_oprnd_unused
;
579 /* Output one FDE. */
582 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
583 char *section_start_label
, int fde_encoding
, char *augmentation
,
584 bool any_lsda_needed
, int lsda_encoding
)
586 const char *begin
, *end
;
587 static unsigned int j
;
590 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
592 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
594 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
595 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
596 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
598 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
599 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
600 " indicating 64-bit DWARF extension");
601 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
604 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
607 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
609 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
610 debug_frame_section
, "FDE CIE offset");
612 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
613 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
617 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
618 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
619 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
620 "FDE initial location");
621 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
622 end
, begin
, "FDE address range");
626 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
627 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
634 int size
= size_of_encoded_value (lsda_encoding
);
636 if (lsda_encoding
== DW_EH_PE_aligned
)
638 int offset
= ( 4 /* Length */
640 + 2 * size_of_encoded_value (fde_encoding
)
641 + 1 /* Augmentation size */ );
642 int pad
= -offset
& (PTR_SIZE
- 1);
645 gcc_assert (size_of_uleb128 (size
) == 1);
648 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
650 if (fde
->uses_eh_lsda
)
652 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
653 fde
->funcdef_number
);
654 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
655 gen_rtx_SYMBOL_REF (Pmode
, l1
),
657 "Language Specific Data Area");
661 if (lsda_encoding
== DW_EH_PE_aligned
)
662 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
663 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
664 "Language Specific Data Area (none)");
668 dw2_asm_output_data_uleb128 (0, "Augmentation size");
671 /* Loop through the Call Frame Instructions associated with this FDE. */
672 fde
->dw_fde_current_label
= begin
;
674 size_t from
, until
, i
;
677 until
= vec_safe_length (fde
->dw_fde_cfi
);
679 if (fde
->dw_fde_second_begin
== NULL
)
682 until
= fde
->dw_fde_switch_cfi_index
;
684 from
= fde
->dw_fde_switch_cfi_index
;
686 for (i
= from
; i
< until
; i
++)
687 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
690 /* If we are to emit a ref/link from function bodies to their frame tables,
691 do it now. This is typically performed to make sure that tables
692 associated with functions are dragged with them and not discarded in
693 garbage collecting links. We need to do this on a per function basis to
694 cope with -ffunction-sections. */
696 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
697 /* Switch to the function section, emit the ref to the tables, and
698 switch *back* into the table section. */
699 switch_to_section (function_section (fde
->decl
));
700 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
701 switch_to_frame_table_section (for_eh
, true);
704 /* Pad the FDE out to an address sized boundary. */
705 ASM_OUTPUT_ALIGN (asm_out_file
,
706 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
707 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
712 /* Return true if frame description entry FDE is needed for EH. */
715 fde_needed_for_eh_p (dw_fde_ref fde
)
717 if (flag_asynchronous_unwind_tables
)
720 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
723 if (fde
->uses_eh_lsda
)
726 /* If exceptions are enabled, we have collected nothrow info. */
727 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
733 /* Output the call frame information used to record information
734 that relates to calculating the frame pointer, and records the
735 location of saved registers. */
738 output_call_frame_info (int for_eh
)
743 char l1
[20], l2
[20], section_start_label
[20];
744 bool any_lsda_needed
= false;
745 char augmentation
[6];
746 int augmentation_size
;
747 int fde_encoding
= DW_EH_PE_absptr
;
748 int per_encoding
= DW_EH_PE_absptr
;
749 int lsda_encoding
= DW_EH_PE_absptr
;
751 rtx personality
= NULL
;
754 /* Don't emit a CIE if there won't be any FDEs. */
758 /* Nothing to do if the assembler's doing it all. */
759 if (dwarf2out_do_cfi_asm ())
762 /* If we don't have any functions we'll want to unwind out of, don't emit
763 any EH unwind information. If we make FDEs linkonce, we may have to
764 emit an empty label for an FDE that wouldn't otherwise be emitted. We
765 want to avoid having an FDE kept around when the function it refers to
766 is discarded. Example where this matters: a primary function template
767 in C++ requires EH information, an explicit specialization doesn't. */
770 bool any_eh_needed
= false;
772 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
774 if (fde
->uses_eh_lsda
)
775 any_eh_needed
= any_lsda_needed
= true;
776 else if (fde_needed_for_eh_p (fde
))
777 any_eh_needed
= true;
778 else if (TARGET_USES_WEAK_UNWIND_INFO
)
779 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
786 /* We're going to be generating comments, so turn on app. */
790 /* Switch to the proper frame section, first time. */
791 switch_to_frame_table_section (for_eh
, false);
793 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
794 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
796 /* Output the CIE. */
797 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
798 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
799 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
801 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
802 dw2_asm_output_data (4, 0xffffffff,
803 "Initial length escape value indicating 64-bit DWARF extension");
804 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
805 "Length of Common Information Entry");
807 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
809 /* Now that the CIE pointer is PC-relative for EH,
810 use 0 to identify the CIE. */
811 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
812 (for_eh
? 0 : DWARF_CIE_ID
),
813 "CIE Identifier Tag");
815 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
816 use CIE version 1, unless that would produce incorrect results
817 due to overflowing the return register column. */
818 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
820 if (return_reg
>= 256 || dwarf_version
> 2)
822 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
825 augmentation_size
= 0;
827 personality
= current_unit_personality
;
833 z Indicates that a uleb128 is present to size the
834 augmentation section.
835 L Indicates the encoding (and thus presence) of
836 an LSDA pointer in the FDE augmentation.
837 R Indicates a non-default pointer encoding for
839 P Indicates the presence of an encoding + language
840 personality routine in the CIE augmentation. */
842 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
843 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
844 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
846 p
= augmentation
+ 1;
850 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
851 assemble_external_libcall (personality
);
856 augmentation_size
+= 1;
858 if (fde_encoding
!= DW_EH_PE_absptr
)
861 augmentation_size
+= 1;
863 if (p
> augmentation
+ 1)
865 augmentation
[0] = 'z';
869 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
870 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
872 int offset
= ( 4 /* Length */
874 + 1 /* CIE version */
875 + strlen (augmentation
) + 1 /* Augmentation */
876 + size_of_uleb128 (1) /* Code alignment */
877 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
879 + 1 /* Augmentation size */
880 + 1 /* Personality encoding */ );
881 int pad
= -offset
& (PTR_SIZE
- 1);
883 augmentation_size
+= pad
;
885 /* Augmentations should be small, so there's scarce need to
886 iterate for a solution. Die if we exceed one uleb128 byte. */
887 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
891 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
892 if (dw_cie_version
>= 4)
894 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
895 dw2_asm_output_data (1, 0, "CIE Segment Size");
897 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
898 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
899 "CIE Data Alignment Factor");
901 if (dw_cie_version
== 1)
902 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
904 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
908 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
911 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
912 eh_data_format_name (per_encoding
));
913 dw2_asm_output_encoded_addr_rtx (per_encoding
,
919 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
920 eh_data_format_name (lsda_encoding
));
922 if (fde_encoding
!= DW_EH_PE_absptr
)
923 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
924 eh_data_format_name (fde_encoding
));
927 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
928 output_cfi (cfi
, NULL
, for_eh
);
930 /* Pad the CIE out to an address sized boundary. */
931 ASM_OUTPUT_ALIGN (asm_out_file
,
932 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
933 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
935 /* Loop through all of the FDE's. */
936 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
940 /* Don't emit EH unwind info for leaf functions that don't need it. */
941 if (for_eh
&& !fde_needed_for_eh_p (fde
))
944 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
945 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
946 augmentation
, any_lsda_needed
, lsda_encoding
);
949 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
950 dw2_asm_output_data (4, 0, "End of Table");
952 /* Turn off app to make assembly quicker. */
957 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
960 dwarf2out_do_cfi_startproc (bool second
)
964 rtx personality
= get_personality_function (current_function_decl
);
966 fprintf (asm_out_file
, "\t.cfi_startproc\n");
970 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
973 /* ??? The GAS support isn't entirely consistent. We have to
974 handle indirect support ourselves, but PC-relative is done
975 in the assembler. Further, the assembler can't handle any
976 of the weirder relocation types. */
977 if (enc
& DW_EH_PE_indirect
)
978 ref
= dw2_force_const_mem (ref
, true);
980 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
981 output_addr_const (asm_out_file
, ref
);
982 fputc ('\n', asm_out_file
);
985 if (crtl
->uses_eh_lsda
)
989 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
990 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
991 current_function_funcdef_no
);
992 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
993 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
995 if (enc
& DW_EH_PE_indirect
)
996 ref
= dw2_force_const_mem (ref
, true);
998 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
999 output_addr_const (asm_out_file
, ref
);
1000 fputc ('\n', asm_out_file
);
1004 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
1005 this allocation may be done before pass_final. */
1008 dwarf2out_alloc_current_fde (void)
1012 fde
= ggc_cleared_alloc
<dw_fde_node
> ();
1013 fde
->decl
= current_function_decl
;
1014 fde
->funcdef_number
= current_function_funcdef_no
;
1015 fde
->fde_index
= vec_safe_length (fde_vec
);
1016 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
1017 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
1018 fde
->nothrow
= crtl
->nothrow
;
1019 fde
->drap_reg
= INVALID_REGNUM
;
1020 fde
->vdrap_reg
= INVALID_REGNUM
;
1022 /* Record the FDE associated with this function. */
1024 vec_safe_push (fde_vec
, fde
);
1029 /* Output a marker (i.e. a label) for the beginning of a function, before
1033 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1034 const char *file ATTRIBUTE_UNUSED
)
1036 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1042 current_function_func_begin_label
= NULL
;
1044 do_frame
= dwarf2out_do_frame ();
1046 /* ??? current_function_func_begin_label is also used by except.c for
1047 call-site information. We must emit this label if it might be used. */
1049 && (!flag_exceptions
1050 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1053 fnsec
= function_section (current_function_decl
);
1054 switch_to_section (fnsec
);
1055 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1056 current_function_funcdef_no
);
1057 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1058 current_function_funcdef_no
);
1059 dup_label
= xstrdup (label
);
1060 current_function_func_begin_label
= dup_label
;
1062 /* We can elide the fde allocation if we're not emitting debug info. */
1066 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1067 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1068 would include pass_dwarf2_frame. If we've not created the FDE yet,
1072 fde
= dwarf2out_alloc_current_fde ();
1074 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1075 fde
->dw_fde_begin
= dup_label
;
1076 fde
->dw_fde_current_label
= dup_label
;
1077 fde
->in_std_section
= (fnsec
== text_section
1078 || (cold_text_section
&& fnsec
== cold_text_section
));
1080 /* We only want to output line number information for the genuine dwarf2
1081 prologue case, not the eh frame case. */
1082 #ifdef DWARF2_DEBUGGING_INFO
1084 dwarf2out_source_line (line
, file
, 0, true);
1087 if (dwarf2out_do_cfi_asm ())
1088 dwarf2out_do_cfi_startproc (false);
1091 rtx personality
= get_personality_function (current_function_decl
);
1092 if (!current_unit_personality
)
1093 current_unit_personality
= personality
;
1095 /* We cannot keep a current personality per function as without CFI
1096 asm, at the point where we emit the CFI data, there is no current
1097 function anymore. */
1098 if (personality
&& current_unit_personality
!= personality
)
1099 sorry ("multiple EH personalities are supported only with assemblers "
1100 "supporting .cfi_personality directive");
1104 /* Output a marker (i.e. a label) for the end of the generated code
1105 for a function prologue. This gets called *after* the prologue code has
1109 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1110 const char *file ATTRIBUTE_UNUSED
)
1112 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1114 /* Output a label to mark the endpoint of the code generated for this
1116 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1117 current_function_funcdef_no
);
1118 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1119 current_function_funcdef_no
);
1120 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1123 /* Output a marker (i.e. a label) for the beginning of the generated code
1124 for a function epilogue. This gets called *before* the prologue code has
1128 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1129 const char *file ATTRIBUTE_UNUSED
)
1131 dw_fde_ref fde
= cfun
->fde
;
1132 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1134 if (fde
->dw_fde_vms_begin_epilogue
)
1137 /* Output a label to mark the endpoint of the code generated for this
1139 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1140 current_function_funcdef_no
);
1141 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1142 current_function_funcdef_no
);
1143 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1146 /* Output a marker (i.e. a label) for the absolute end of the generated code
1147 for a function definition. This gets called *after* the epilogue code has
1151 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1152 const char *file ATTRIBUTE_UNUSED
)
1155 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1157 last_var_location_insn
= NULL
;
1158 cached_next_real_insn
= NULL
;
1160 if (dwarf2out_do_cfi_asm ())
1161 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1163 /* Output a label to mark the endpoint of the code generated for this
1165 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1166 current_function_funcdef_no
);
1167 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1169 gcc_assert (fde
!= NULL
);
1170 if (fde
->dw_fde_second_begin
== NULL
)
1171 fde
->dw_fde_end
= xstrdup (label
);
1175 dwarf2out_frame_finish (void)
1177 /* Output call frame information. */
1178 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1179 output_call_frame_info (0);
1181 /* Output another copy for the unwinder. */
1182 if ((flag_unwind_tables
|| flag_exceptions
)
1183 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1184 output_call_frame_info (1);
1187 /* Note that the current function section is being used for code. */
1190 dwarf2out_note_section_used (void)
1192 section
*sec
= current_function_section ();
1193 if (sec
== text_section
)
1194 text_section_used
= true;
1195 else if (sec
== cold_text_section
)
1196 cold_text_section_used
= true;
1199 static void var_location_switch_text_section (void);
1200 static void set_cur_line_info_table (section
*);
1203 dwarf2out_switch_text_section (void)
1206 dw_fde_ref fde
= cfun
->fde
;
1208 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1210 if (!in_cold_section_p
)
1212 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1213 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1214 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1218 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1219 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1220 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1222 have_multiple_function_sections
= true;
1224 /* There is no need to mark used sections when not debugging. */
1225 if (cold_text_section
!= NULL
)
1226 dwarf2out_note_section_used ();
1228 if (dwarf2out_do_cfi_asm ())
1229 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1231 /* Now do the real section switch. */
1232 sect
= current_function_section ();
1233 switch_to_section (sect
);
1235 fde
->second_in_std_section
1236 = (sect
== text_section
1237 || (cold_text_section
&& sect
== cold_text_section
));
1239 if (dwarf2out_do_cfi_asm ())
1240 dwarf2out_do_cfi_startproc (true);
1242 var_location_switch_text_section ();
1244 if (cold_text_section
!= NULL
)
1245 set_cur_line_info_table (sect
);
1248 /* And now, the subset of the debugging information support code necessary
1249 for emitting location expressions. */
1251 /* Data about a single source file. */
1252 struct GTY((for_user
)) dwarf_file_data
{
1253 const char * filename
;
1257 /* Describe an entry into the .debug_addr section. */
1261 ate_kind_rtx_dtprel
,
1265 struct GTY((for_user
)) addr_table_entry
{
1267 unsigned int refcount
;
1269 union addr_table_entry_struct_union
1271 rtx
GTY ((tag ("0"))) rtl
;
1272 char * GTY ((tag ("1"))) label
;
1274 GTY ((desc ("%1.kind"))) addr
;
1277 /* Location lists are ranges + location descriptions for that range,
1278 so you can track variables that are in different places over
1279 their entire life. */
1280 typedef struct GTY(()) dw_loc_list_struct
{
1281 dw_loc_list_ref dw_loc_next
;
1282 const char *begin
; /* Label and addr_entry for start of range */
1283 addr_table_entry
*begin_entry
;
1284 const char *end
; /* Label for end of range */
1285 char *ll_symbol
; /* Label for beginning of location list.
1286 Only on head of list */
1287 const char *section
; /* Section this loclist is relative to */
1288 dw_loc_descr_ref expr
;
1290 /* True if all addresses in this and subsequent lists are known to be
1293 /* True if this list has been replaced by dw_loc_next. */
1296 /* True if the range should be emitted even if begin and end
1301 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1302 static dw_loc_descr_ref
uint_loc_descriptor (unsigned HOST_WIDE_INT
);
1304 /* Convert a DWARF stack opcode into its string name. */
1307 dwarf_stack_op_name (unsigned int op
)
1309 const char *name
= get_DW_OP_name (op
);
1314 return "OP_<unknown>";
1317 /* Return a pointer to a newly allocated location description. Location
1318 descriptions are simple expression terms that can be strung
1319 together to form more complicated location (address) descriptions. */
1321 static inline dw_loc_descr_ref
1322 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1323 unsigned HOST_WIDE_INT oprnd2
)
1325 dw_loc_descr_ref descr
= ggc_cleared_alloc
<dw_loc_descr_node
> ();
1327 descr
->dw_loc_opc
= op
;
1328 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1329 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1330 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1331 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1332 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1333 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1338 /* Return a pointer to a newly allocated location description for
1341 static inline dw_loc_descr_ref
1342 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1345 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1348 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1351 /* Add a location description term to a location description expression. */
1354 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1356 dw_loc_descr_ref
*d
;
1358 /* Find the end of the chain. */
1359 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1365 /* Compare two location operands for exact equality. */
1368 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1370 if (a
->val_class
!= b
->val_class
)
1372 switch (a
->val_class
)
1374 case dw_val_class_none
:
1376 case dw_val_class_addr
:
1377 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1379 case dw_val_class_offset
:
1380 case dw_val_class_unsigned_const
:
1381 case dw_val_class_const
:
1382 case dw_val_class_range_list
:
1383 case dw_val_class_lineptr
:
1384 case dw_val_class_macptr
:
1385 /* These are all HOST_WIDE_INT, signed or unsigned. */
1386 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1388 case dw_val_class_loc
:
1389 return a
->v
.val_loc
== b
->v
.val_loc
;
1390 case dw_val_class_loc_list
:
1391 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1392 case dw_val_class_die_ref
:
1393 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1394 case dw_val_class_fde_ref
:
1395 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1396 case dw_val_class_lbl_id
:
1397 case dw_val_class_high_pc
:
1398 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1399 case dw_val_class_str
:
1400 return a
->v
.val_str
== b
->v
.val_str
;
1401 case dw_val_class_flag
:
1402 return a
->v
.val_flag
== b
->v
.val_flag
;
1403 case dw_val_class_file
:
1404 return a
->v
.val_file
== b
->v
.val_file
;
1405 case dw_val_class_decl_ref
:
1406 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1408 case dw_val_class_const_double
:
1409 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1410 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1412 case dw_val_class_wide_int
:
1413 return *a
->v
.val_wide
== *b
->v
.val_wide
;
1415 case dw_val_class_vec
:
1417 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1418 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1420 return (a_len
== b_len
1421 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1424 case dw_val_class_data8
:
1425 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1427 case dw_val_class_vms_delta
:
1428 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1429 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1431 case dw_val_class_discr_value
:
1432 return (a
->v
.val_discr_value
.pos
== b
->v
.val_discr_value
.pos
1433 && a
->v
.val_discr_value
.v
.uval
== b
->v
.val_discr_value
.v
.uval
);
1434 case dw_val_class_discr_list
:
1435 /* It makes no sense comparing two discriminant value lists. */
1441 /* Compare two location atoms for exact equality. */
1444 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1446 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1449 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1450 address size, but since we always allocate cleared storage it
1451 should be zero for other types of locations. */
1452 if (a
->dtprel
!= b
->dtprel
)
1455 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1456 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1459 /* Compare two complete location expressions for exact equality. */
1462 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1468 if (a
== NULL
|| b
== NULL
)
1470 if (!loc_descr_equal_p_1 (a
, b
))
1479 /* Add a constant OFFSET to a location expression. */
1482 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1484 dw_loc_descr_ref loc
;
1487 gcc_assert (*list_head
!= NULL
);
1492 /* Find the end of the chain. */
1493 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1497 if (loc
->dw_loc_opc
== DW_OP_fbreg
1498 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1499 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1500 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1501 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1503 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1504 offset. Don't optimize if an signed integer overflow would happen. */
1506 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1507 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1510 else if (offset
> 0)
1511 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1515 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1516 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1520 /* Add a constant OFFSET to a location list. */
1523 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1526 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1527 loc_descr_plus_const (&d
->expr
, offset
);
1530 #define DWARF_REF_SIZE \
1531 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1533 static unsigned long int get_base_type_offset (dw_die_ref
);
1535 /* Return the size of a location descriptor. */
1537 static unsigned long
1538 size_of_loc_descr (dw_loc_descr_ref loc
)
1540 unsigned long size
= 1;
1542 switch (loc
->dw_loc_opc
)
1545 size
+= DWARF2_ADDR_SIZE
;
1547 case DW_OP_GNU_addr_index
:
1548 case DW_OP_GNU_const_index
:
1549 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1550 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1569 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1572 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1577 case DW_OP_plus_uconst
:
1578 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1616 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1619 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1622 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1625 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1626 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1629 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1631 case DW_OP_bit_piece
:
1632 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1633 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1635 case DW_OP_deref_size
:
1636 case DW_OP_xderef_size
:
1645 case DW_OP_call_ref
:
1646 size
+= DWARF_REF_SIZE
;
1648 case DW_OP_implicit_value
:
1649 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1650 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1652 case DW_OP_GNU_implicit_pointer
:
1653 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1655 case DW_OP_GNU_entry_value
:
1657 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1658 size
+= size_of_uleb128 (op_size
) + op_size
;
1661 case DW_OP_GNU_const_type
:
1664 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1665 size
+= size_of_uleb128 (o
) + 1;
1666 switch (loc
->dw_loc_oprnd2
.val_class
)
1668 case dw_val_class_vec
:
1669 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1670 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1672 case dw_val_class_const
:
1673 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1675 case dw_val_class_const_double
:
1676 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1678 case dw_val_class_wide_int
:
1679 size
+= (get_full_len (*loc
->dw_loc_oprnd2
.v
.val_wide
)
1680 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
1687 case DW_OP_GNU_regval_type
:
1690 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1691 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1692 + size_of_uleb128 (o
);
1695 case DW_OP_GNU_deref_type
:
1698 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1699 size
+= 1 + size_of_uleb128 (o
);
1702 case DW_OP_GNU_convert
:
1703 case DW_OP_GNU_reinterpret
:
1704 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1705 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1709 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1710 size
+= size_of_uleb128 (o
);
1713 case DW_OP_GNU_parameter_ref
:
1723 /* Return the size of a series of location descriptors. */
1726 size_of_locs (dw_loc_descr_ref loc
)
1731 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1732 field, to avoid writing to a PCH file. */
1733 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1735 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1737 size
+= size_of_loc_descr (l
);
1742 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1744 l
->dw_loc_addr
= size
;
1745 size
+= size_of_loc_descr (l
);
1751 /* Return the size of the value in a DW_AT_discr_value attribute. */
1754 size_of_discr_value (dw_discr_value
*discr_value
)
1756 if (discr_value
->pos
)
1757 return size_of_uleb128 (discr_value
->v
.uval
);
1759 return size_of_sleb128 (discr_value
->v
.sval
);
1762 /* Return the size of the value in a DW_discr_list attribute. */
1765 size_of_discr_list (dw_discr_list_ref discr_list
)
1769 for (dw_discr_list_ref list
= discr_list
;
1771 list
= list
->dw_discr_next
)
1773 /* One byte for the discriminant value descriptor, and then one or two
1774 LEB128 numbers, depending on whether it's a single case label or a
1777 size
+= size_of_discr_value (&list
->dw_discr_lower_bound
);
1778 if (list
->dw_discr_range
!= 0)
1779 size
+= size_of_discr_value (&list
->dw_discr_upper_bound
);
1784 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1785 static void get_ref_die_offset_label (char *, dw_die_ref
);
1786 static unsigned long int get_ref_die_offset (dw_die_ref
);
1788 /* Output location description stack opcode's operands (if any).
1789 The for_eh_or_skip parameter controls whether register numbers are
1790 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1791 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1792 info). This should be suppressed for the cases that have not been converted
1793 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1796 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1798 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1799 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1801 switch (loc
->dw_loc_opc
)
1803 #ifdef DWARF2_DEBUGGING_INFO
1806 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1811 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1812 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1814 fputc ('\n', asm_out_file
);
1819 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1824 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1825 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1827 fputc ('\n', asm_out_file
);
1832 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1833 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1840 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1841 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1843 dw2_asm_output_data (2, offset
, NULL
);
1846 case DW_OP_implicit_value
:
1847 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1848 switch (val2
->val_class
)
1850 case dw_val_class_const
:
1851 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1853 case dw_val_class_vec
:
1855 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1856 unsigned int len
= val2
->v
.val_vec
.length
;
1860 if (elt_size
> sizeof (HOST_WIDE_INT
))
1865 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1868 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1869 "fp or vector constant word %u", i
);
1872 case dw_val_class_const_double
:
1874 unsigned HOST_WIDE_INT first
, second
;
1876 if (WORDS_BIG_ENDIAN
)
1878 first
= val2
->v
.val_double
.high
;
1879 second
= val2
->v
.val_double
.low
;
1883 first
= val2
->v
.val_double
.low
;
1884 second
= val2
->v
.val_double
.high
;
1886 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1888 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1892 case dw_val_class_wide_int
:
1895 int len
= get_full_len (*val2
->v
.val_wide
);
1896 if (WORDS_BIG_ENDIAN
)
1897 for (i
= len
- 1; i
>= 0; --i
)
1898 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1899 val2
->v
.val_wide
->elt (i
), NULL
);
1901 for (i
= 0; i
< len
; ++i
)
1902 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1903 val2
->v
.val_wide
->elt (i
), NULL
);
1906 case dw_val_class_addr
:
1907 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1908 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1923 case DW_OP_implicit_value
:
1924 /* We currently don't make any attempt to make sure these are
1925 aligned properly like we do for the main unwind info, so
1926 don't support emitting things larger than a byte if we're
1927 only doing unwinding. */
1932 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1935 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1938 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1941 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1943 case DW_OP_plus_uconst
:
1944 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1978 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1982 unsigned r
= val1
->v
.val_unsigned
;
1983 if (for_eh_or_skip
>= 0)
1984 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1985 gcc_assert (size_of_uleb128 (r
)
1986 == size_of_uleb128 (val1
->v
.val_unsigned
));
1987 dw2_asm_output_data_uleb128 (r
, NULL
);
1991 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1995 unsigned r
= val1
->v
.val_unsigned
;
1996 if (for_eh_or_skip
>= 0)
1997 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1998 gcc_assert (size_of_uleb128 (r
)
1999 == size_of_uleb128 (val1
->v
.val_unsigned
));
2000 dw2_asm_output_data_uleb128 (r
, NULL
);
2001 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2005 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2007 case DW_OP_bit_piece
:
2008 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2009 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
2011 case DW_OP_deref_size
:
2012 case DW_OP_xderef_size
:
2013 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2019 if (targetm
.asm_out
.output_dwarf_dtprel
)
2021 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
2024 fputc ('\n', asm_out_file
);
2031 #ifdef DWARF2_DEBUGGING_INFO
2032 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2039 case DW_OP_GNU_addr_index
:
2040 case DW_OP_GNU_const_index
:
2041 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
2042 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
2043 "(index into .debug_addr)");
2049 unsigned long die_offset
2050 = get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2051 /* Make sure the offset has been computed and that we can encode it as
2053 gcc_assert (die_offset
> 0
2054 && die_offset
<= (loc
->dw_loc_opc
== DW_OP_call2
)
2057 dw2_asm_output_data ((loc
->dw_loc_opc
== DW_OP_call2
) ? 2 : 4,
2062 case DW_OP_GNU_implicit_pointer
:
2064 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2065 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2066 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2067 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2068 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2069 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2073 case DW_OP_GNU_entry_value
:
2074 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
2075 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
2078 case DW_OP_GNU_const_type
:
2080 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
2082 dw2_asm_output_data_uleb128 (o
, NULL
);
2083 switch (val2
->val_class
)
2085 case dw_val_class_const
:
2086 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2087 dw2_asm_output_data (1, l
, NULL
);
2088 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
2090 case dw_val_class_vec
:
2092 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2093 unsigned int len
= val2
->v
.val_vec
.length
;
2098 dw2_asm_output_data (1, l
, NULL
);
2099 if (elt_size
> sizeof (HOST_WIDE_INT
))
2104 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2107 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2108 "fp or vector constant word %u", i
);
2111 case dw_val_class_const_double
:
2113 unsigned HOST_WIDE_INT first
, second
;
2114 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2116 dw2_asm_output_data (1, 2 * l
, NULL
);
2117 if (WORDS_BIG_ENDIAN
)
2119 first
= val2
->v
.val_double
.high
;
2120 second
= val2
->v
.val_double
.low
;
2124 first
= val2
->v
.val_double
.low
;
2125 second
= val2
->v
.val_double
.high
;
2127 dw2_asm_output_data (l
, first
, NULL
);
2128 dw2_asm_output_data (l
, second
, NULL
);
2131 case dw_val_class_wide_int
:
2134 int len
= get_full_len (*val2
->v
.val_wide
);
2135 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2137 dw2_asm_output_data (1, len
* l
, NULL
);
2138 if (WORDS_BIG_ENDIAN
)
2139 for (i
= len
- 1; i
>= 0; --i
)
2140 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2142 for (i
= 0; i
< len
; ++i
)
2143 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2151 case DW_OP_GNU_regval_type
:
2153 unsigned r
= val1
->v
.val_unsigned
;
2154 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2156 if (for_eh_or_skip
>= 0)
2158 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2159 gcc_assert (size_of_uleb128 (r
)
2160 == size_of_uleb128 (val1
->v
.val_unsigned
));
2162 dw2_asm_output_data_uleb128 (r
, NULL
);
2163 dw2_asm_output_data_uleb128 (o
, NULL
);
2166 case DW_OP_GNU_deref_type
:
2168 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2170 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2171 dw2_asm_output_data_uleb128 (o
, NULL
);
2174 case DW_OP_GNU_convert
:
2175 case DW_OP_GNU_reinterpret
:
2176 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2177 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2180 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2182 dw2_asm_output_data_uleb128 (o
, NULL
);
2186 case DW_OP_GNU_parameter_ref
:
2189 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2190 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2191 dw2_asm_output_data (4, o
, NULL
);
2196 /* Other codes have no operands. */
2201 /* Output a sequence of location operations.
2202 The for_eh_or_skip parameter controls whether register numbers are
2203 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2204 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2205 info). This should be suppressed for the cases that have not been converted
2206 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2209 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2211 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2213 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2214 /* Output the opcode. */
2215 if (for_eh_or_skip
>= 0
2216 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2218 unsigned r
= (opc
- DW_OP_breg0
);
2219 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2220 gcc_assert (r
<= 31);
2221 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2223 else if (for_eh_or_skip
>= 0
2224 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2226 unsigned r
= (opc
- DW_OP_reg0
);
2227 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2228 gcc_assert (r
<= 31);
2229 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2232 dw2_asm_output_data (1, opc
,
2233 "%s", dwarf_stack_op_name (opc
));
2235 /* Output the operand(s) (if any). */
2236 output_loc_operands (loc
, for_eh_or_skip
);
2240 /* Output location description stack opcode's operands (if any).
2241 The output is single bytes on a line, suitable for .cfi_escape. */
2244 output_loc_operands_raw (dw_loc_descr_ref loc
)
2246 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2247 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2249 switch (loc
->dw_loc_opc
)
2252 case DW_OP_GNU_addr_index
:
2253 case DW_OP_GNU_const_index
:
2254 case DW_OP_implicit_value
:
2255 /* We cannot output addresses in .cfi_escape, only bytes. */
2261 case DW_OP_deref_size
:
2262 case DW_OP_xderef_size
:
2263 fputc (',', asm_out_file
);
2264 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2269 fputc (',', asm_out_file
);
2270 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2275 fputc (',', asm_out_file
);
2276 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2281 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2282 fputc (',', asm_out_file
);
2283 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2291 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2292 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2294 fputc (',', asm_out_file
);
2295 dw2_asm_output_data_raw (2, offset
);
2301 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2302 gcc_assert (size_of_uleb128 (r
)
2303 == size_of_uleb128 (val1
->v
.val_unsigned
));
2304 fputc (',', asm_out_file
);
2305 dw2_asm_output_data_uleb128_raw (r
);
2310 case DW_OP_plus_uconst
:
2312 fputc (',', asm_out_file
);
2313 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2316 case DW_OP_bit_piece
:
2317 fputc (',', asm_out_file
);
2318 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2319 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2356 fputc (',', asm_out_file
);
2357 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2362 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2363 gcc_assert (size_of_uleb128 (r
)
2364 == size_of_uleb128 (val1
->v
.val_unsigned
));
2365 fputc (',', asm_out_file
);
2366 dw2_asm_output_data_uleb128_raw (r
);
2367 fputc (',', asm_out_file
);
2368 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2372 case DW_OP_GNU_implicit_pointer
:
2373 case DW_OP_GNU_entry_value
:
2374 case DW_OP_GNU_const_type
:
2375 case DW_OP_GNU_regval_type
:
2376 case DW_OP_GNU_deref_type
:
2377 case DW_OP_GNU_convert
:
2378 case DW_OP_GNU_reinterpret
:
2379 case DW_OP_GNU_parameter_ref
:
2384 /* Other codes have no operands. */
2390 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2394 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2395 /* Output the opcode. */
2396 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2398 unsigned r
= (opc
- DW_OP_breg0
);
2399 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2400 gcc_assert (r
<= 31);
2401 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2403 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2405 unsigned r
= (opc
- DW_OP_reg0
);
2406 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2407 gcc_assert (r
<= 31);
2408 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2410 /* Output the opcode. */
2411 fprintf (asm_out_file
, "%#x", opc
);
2412 output_loc_operands_raw (loc
);
2414 if (!loc
->dw_loc_next
)
2416 loc
= loc
->dw_loc_next
;
2418 fputc (',', asm_out_file
);
2422 /* This function builds a dwarf location descriptor sequence from a
2423 dw_cfa_location, adding the given OFFSET to the result of the
2426 struct dw_loc_descr_node
*
2427 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2429 struct dw_loc_descr_node
*head
, *tmp
;
2431 offset
+= cfa
->offset
;
2435 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2436 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2437 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2438 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2439 add_loc_descr (&head
, tmp
);
2442 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2443 add_loc_descr (&head
, tmp
);
2447 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2452 /* This function builds a dwarf location descriptor sequence for
2453 the address at OFFSET from the CFA when stack is aligned to
2456 struct dw_loc_descr_node
*
2457 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2458 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2460 struct dw_loc_descr_node
*head
;
2461 unsigned int dwarf_fp
2462 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2464 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2465 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2467 head
= new_reg_loc_descr (dwarf_fp
, 0);
2468 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2469 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2470 loc_descr_plus_const (&head
, offset
);
2473 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2477 /* And now, the support for symbolic debugging information. */
2479 /* .debug_str support. */
2481 static void dwarf2out_init (const char *);
2482 static void dwarf2out_finish (const char *);
2483 static void dwarf2out_early_finish (void);
2484 static void dwarf2out_assembly_start (void);
2485 static void dwarf2out_define (unsigned int, const char *);
2486 static void dwarf2out_undef (unsigned int, const char *);
2487 static void dwarf2out_start_source_file (unsigned, const char *);
2488 static void dwarf2out_end_source_file (unsigned);
2489 static void dwarf2out_function_decl (tree
);
2490 static void dwarf2out_begin_block (unsigned, unsigned);
2491 static void dwarf2out_end_block (unsigned, unsigned);
2492 static bool dwarf2out_ignore_block (const_tree
);
2493 static void dwarf2out_early_global_decl (tree
);
2494 static void dwarf2out_late_global_decl (tree
);
2495 static void dwarf2out_type_decl (tree
, int);
2496 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2497 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2499 static void dwarf2out_abstract_function (tree
);
2500 static void dwarf2out_var_location (rtx_insn
*);
2501 static void dwarf2out_size_function (tree
);
2502 static void dwarf2out_begin_function (tree
);
2503 static void dwarf2out_end_function (unsigned int);
2504 static void dwarf2out_register_main_translation_unit (tree unit
);
2505 static void dwarf2out_set_name (tree
, tree
);
2507 /* The debug hooks structure. */
2509 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2513 dwarf2out_early_finish
,
2514 dwarf2out_assembly_start
,
2517 dwarf2out_start_source_file
,
2518 dwarf2out_end_source_file
,
2519 dwarf2out_begin_block
,
2520 dwarf2out_end_block
,
2521 dwarf2out_ignore_block
,
2522 dwarf2out_source_line
,
2523 dwarf2out_begin_prologue
,
2524 #if VMS_DEBUGGING_INFO
2525 dwarf2out_vms_end_prologue
,
2526 dwarf2out_vms_begin_epilogue
,
2528 debug_nothing_int_charstar
,
2529 debug_nothing_int_charstar
,
2531 dwarf2out_end_epilogue
,
2532 dwarf2out_begin_function
,
2533 dwarf2out_end_function
, /* end_function */
2534 dwarf2out_register_main_translation_unit
,
2535 dwarf2out_function_decl
, /* function_decl */
2536 dwarf2out_early_global_decl
,
2537 dwarf2out_late_global_decl
,
2538 dwarf2out_type_decl
, /* type_decl */
2539 dwarf2out_imported_module_or_decl
,
2540 debug_nothing_tree
, /* deferred_inline_function */
2541 /* The DWARF 2 backend tries to reduce debugging bloat by not
2542 emitting the abstract description of inline functions until
2543 something tries to reference them. */
2544 dwarf2out_abstract_function
, /* outlining_inline_function */
2545 debug_nothing_rtx_code_label
, /* label */
2546 debug_nothing_int
, /* handle_pch */
2547 dwarf2out_var_location
,
2548 dwarf2out_size_function
, /* size_function */
2549 dwarf2out_switch_text_section
,
2551 1, /* start_end_main_source_file */
2552 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2555 const struct gcc_debug_hooks dwarf2_lineno_debug_hooks
=
2558 debug_nothing_charstar
,
2561 debug_nothing_int_charstar
,
2562 debug_nothing_int_charstar
,
2563 debug_nothing_int_charstar
,
2565 debug_nothing_int_int
, /* begin_block */
2566 debug_nothing_int_int
, /* end_block */
2567 debug_true_const_tree
, /* ignore_block */
2568 dwarf2out_source_line
, /* source_line */
2569 debug_nothing_int_charstar
, /* begin_prologue */
2570 debug_nothing_int_charstar
, /* end_prologue */
2571 debug_nothing_int_charstar
, /* begin_epilogue */
2572 debug_nothing_int_charstar
, /* end_epilogue */
2573 debug_nothing_tree
, /* begin_function */
2574 debug_nothing_int
, /* end_function */
2575 debug_nothing_tree
, /* register_main_translation_unit */
2576 debug_nothing_tree
, /* function_decl */
2577 debug_nothing_tree
, /* early_global_decl */
2578 debug_nothing_tree
, /* late_global_decl */
2579 debug_nothing_tree_int
, /* type_decl */
2580 debug_nothing_tree_tree_tree_bool
, /* imported_module_or_decl */
2581 debug_nothing_tree
, /* deferred_inline_function */
2582 debug_nothing_tree
, /* outlining_inline_function */
2583 debug_nothing_rtx_code_label
, /* label */
2584 debug_nothing_int
, /* handle_pch */
2585 debug_nothing_rtx_insn
, /* var_location */
2586 debug_nothing_tree
, /* size_function */
2587 debug_nothing_void
, /* switch_text_section */
2588 debug_nothing_tree_tree
, /* set_name */
2589 0, /* start_end_main_source_file */
2590 TYPE_SYMTAB_IS_ADDRESS
/* tree_type_symtab_field */
2593 /* NOTE: In the comments in this file, many references are made to
2594 "Debugging Information Entries". This term is abbreviated as `DIE'
2595 throughout the remainder of this file. */
2597 /* An internal representation of the DWARF output is built, and then
2598 walked to generate the DWARF debugging info. The walk of the internal
2599 representation is done after the entire program has been compiled.
2600 The types below are used to describe the internal representation. */
2602 /* Whether to put type DIEs into their own section .debug_types instead
2603 of making them part of the .debug_info section. Only supported for
2604 Dwarf V4 or higher and the user didn't disable them through
2605 -fno-debug-types-section. It is more efficient to put them in a
2606 separate comdat sections since the linker will then be able to
2607 remove duplicates. But not all tools support .debug_types sections
2610 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2612 /* Various DIE's use offsets relative to the beginning of the
2613 .debug_info section to refer to each other. */
2615 typedef long int dw_offset
;
2617 struct comdat_type_node
;
2619 /* The entries in the line_info table more-or-less mirror the opcodes
2620 that are used in the real dwarf line table. Arrays of these entries
2621 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2624 enum dw_line_info_opcode
{
2625 /* Emit DW_LNE_set_address; the operand is the label index. */
2628 /* Emit a row to the matrix with the given line. This may be done
2629 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2633 /* Emit a DW_LNS_set_file. */
2636 /* Emit a DW_LNS_set_column. */
2639 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2642 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2643 LI_set_prologue_end
,
2644 LI_set_epilogue_begin
,
2646 /* Emit a DW_LNE_set_discriminator. */
2647 LI_set_discriminator
2650 typedef struct GTY(()) dw_line_info_struct
{
2651 enum dw_line_info_opcode opcode
;
2653 } dw_line_info_entry
;
2656 struct GTY(()) dw_line_info_table
{
2657 /* The label that marks the end of this section. */
2658 const char *end_label
;
2660 /* The values for the last row of the matrix, as collected in the table.
2661 These are used to minimize the changes to the next row. */
2662 unsigned int file_num
;
2663 unsigned int line_num
;
2664 unsigned int column_num
;
2669 vec
<dw_line_info_entry
, va_gc
> *entries
;
2673 /* Each DIE attribute has a field specifying the attribute kind,
2674 a link to the next attribute in the chain, and an attribute value.
2675 Attributes are typically linked below the DIE they modify. */
2677 typedef struct GTY(()) dw_attr_struct
{
2678 enum dwarf_attribute dw_attr
;
2679 dw_val_node dw_attr_val
;
2684 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2685 The children of each node form a circular list linked by
2686 die_sib. die_child points to the node *before* the "first" child node. */
2688 typedef struct GTY((chain_circular ("%h.die_sib"), for_user
)) die_struct
{
2689 union die_symbol_or_type_node
2691 const char * GTY ((tag ("0"))) die_symbol
;
2692 comdat_type_node
*GTY ((tag ("1"))) die_type_node
;
2694 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2695 vec
<dw_attr_node
, va_gc
> *die_attr
;
2696 dw_die_ref die_parent
;
2697 dw_die_ref die_child
;
2699 dw_die_ref die_definition
; /* ref from a specification to its definition */
2700 dw_offset die_offset
;
2701 unsigned long die_abbrev
;
2703 unsigned int decl_id
;
2704 enum dwarf_tag die_tag
;
2705 /* Die is used and must not be pruned as unused. */
2706 BOOL_BITFIELD die_perennial_p
: 1;
2707 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2708 /* Lots of spare bits. */
2712 /* Set to TRUE while dwarf2out_early_global_decl is running. */
2713 static bool early_dwarf
;
2714 struct set_early_dwarf
{
2716 set_early_dwarf () : saved(early_dwarf
) { early_dwarf
= true; }
2717 ~set_early_dwarf () { early_dwarf
= saved
; }
2720 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2721 #define FOR_EACH_CHILD(die, c, expr) do { \
2722 c = die->die_child; \
2726 } while (c != die->die_child); \
2729 /* The pubname structure */
2731 typedef struct GTY(()) pubname_struct
{
2738 struct GTY(()) dw_ranges
{
2739 /* If this is positive, it's a block number, otherwise it's a
2740 bitwise-negated index into dw_ranges_by_label. */
2744 /* A structure to hold a macinfo entry. */
2746 typedef struct GTY(()) macinfo_struct
{
2748 unsigned HOST_WIDE_INT lineno
;
2754 struct GTY(()) dw_ranges_by_label
{
2759 /* The comdat type node structure. */
2760 struct GTY(()) comdat_type_node
2762 dw_die_ref root_die
;
2763 dw_die_ref type_die
;
2764 dw_die_ref skeleton_die
;
2765 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2766 comdat_type_node
*next
;
2769 /* A list of DIEs for which we can't determine ancestry (parent_die
2770 field) just yet. Later in dwarf2out_finish we will fill in the
2772 typedef struct GTY(()) limbo_die_struct
{
2774 /* The tree for which this DIE was created. We use this to
2775 determine ancestry later. */
2777 struct limbo_die_struct
*next
;
2781 typedef struct skeleton_chain_struct
2785 struct skeleton_chain_struct
*parent
;
2787 skeleton_chain_node
;
2789 /* Define a macro which returns nonzero for a TYPE_DECL which was
2790 implicitly generated for a type.
2792 Note that, unlike the C front-end (which generates a NULL named
2793 TYPE_DECL node for each complete tagged type, each array type,
2794 and each function type node created) the C++ front-end generates
2795 a _named_ TYPE_DECL node for each tagged type node created.
2796 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2797 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2798 front-end, but for each type, tagged or not. */
2800 #define TYPE_DECL_IS_STUB(decl) \
2801 (DECL_NAME (decl) == NULL_TREE \
2802 || (DECL_ARTIFICIAL (decl) \
2803 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2804 /* This is necessary for stub decls that \
2805 appear in nested inline functions. */ \
2806 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2807 && (decl_ultimate_origin (decl) \
2808 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2810 /* Information concerning the compilation unit's programming
2811 language, and compiler version. */
2813 /* Fixed size portion of the DWARF compilation unit header. */
2814 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2815 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2817 /* Fixed size portion of the DWARF comdat type unit header. */
2818 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2819 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2820 + DWARF_OFFSET_SIZE)
2822 /* Fixed size portion of public names info. */
2823 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2825 /* Fixed size portion of the address range info. */
2826 #define DWARF_ARANGES_HEADER_SIZE \
2827 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2828 DWARF2_ADDR_SIZE * 2) \
2829 - DWARF_INITIAL_LENGTH_SIZE)
2831 /* Size of padding portion in the address range info. It must be
2832 aligned to twice the pointer size. */
2833 #define DWARF_ARANGES_PAD_SIZE \
2834 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2835 DWARF2_ADDR_SIZE * 2) \
2836 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2838 /* Use assembler line directives if available. */
2839 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2840 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2841 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2843 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2847 /* Minimum line offset in a special line info. opcode.
2848 This value was chosen to give a reasonable range of values. */
2849 #define DWARF_LINE_BASE -10
2851 /* First special line opcode - leave room for the standard opcodes. */
2852 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2854 /* Range of line offsets in a special line info. opcode. */
2855 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2857 /* Flag that indicates the initial value of the is_stmt_start flag.
2858 In the present implementation, we do not mark any lines as
2859 the beginning of a source statement, because that information
2860 is not made available by the GCC front-end. */
2861 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2863 /* Maximum number of operations per instruction bundle. */
2864 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2865 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2868 /* This location is used by calc_die_sizes() to keep track
2869 the offset of each DIE within the .debug_info section. */
2870 static unsigned long next_die_offset
;
2872 /* Record the root of the DIE's built for the current compilation unit. */
2873 static GTY(()) dw_die_ref single_comp_unit_die
;
2875 /* A list of type DIEs that have been separated into comdat sections. */
2876 static GTY(()) comdat_type_node
*comdat_type_list
;
2878 /* A list of DIEs with a NULL parent waiting to be relocated. */
2879 static GTY(()) limbo_die_node
*limbo_die_list
;
2881 /* A list of DIEs for which we may have to generate
2882 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2883 static GTY(()) limbo_die_node
*deferred_asm_name
;
2885 struct dwarf_file_hasher
: ggc_ptr_hash
<dwarf_file_data
>
2887 typedef const char *compare_type
;
2889 static hashval_t
hash (dwarf_file_data
*);
2890 static bool equal (dwarf_file_data
*, const char *);
2893 /* Filenames referenced by this compilation unit. */
2894 static GTY(()) hash_table
<dwarf_file_hasher
> *file_table
;
2896 struct decl_die_hasher
: ggc_ptr_hash
<die_node
>
2898 typedef tree compare_type
;
2900 static hashval_t
hash (die_node
*);
2901 static bool equal (die_node
*, tree
);
2903 /* A hash table of references to DIE's that describe declarations.
2904 The key is a DECL_UID() which is a unique number identifying each decl. */
2905 static GTY (()) hash_table
<decl_die_hasher
> *decl_die_table
;
2907 struct block_die_hasher
: ggc_ptr_hash
<die_struct
>
2909 static hashval_t
hash (die_struct
*);
2910 static bool equal (die_struct
*, die_struct
*);
2913 /* A hash table of references to DIE's that describe COMMON blocks.
2914 The key is DECL_UID() ^ die_parent. */
2915 static GTY (()) hash_table
<block_die_hasher
> *common_block_die_table
;
2917 typedef struct GTY(()) die_arg_entry_struct
{
2923 /* Node of the variable location list. */
2924 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2925 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2926 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2927 in mode of the EXPR_LIST node and first EXPR_LIST operand
2928 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2929 location or NULL for padding. For larger bitsizes,
2930 mode is 0 and first operand is a CONCAT with bitsize
2931 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2932 NULL as second operand. */
2934 const char * GTY (()) label
;
2935 struct var_loc_node
* GTY (()) next
;
2938 /* Variable location list. */
2939 struct GTY ((for_user
)) var_loc_list_def
{
2940 struct var_loc_node
* GTY (()) first
;
2942 /* Pointer to the last but one or last element of the
2943 chained list. If the list is empty, both first and
2944 last are NULL, if the list contains just one node
2945 or the last node certainly is not redundant, it points
2946 to the last node, otherwise points to the last but one.
2947 Do not mark it for GC because it is marked through the chain. */
2948 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2950 /* Pointer to the last element before section switch,
2951 if NULL, either sections weren't switched or first
2952 is after section switch. */
2953 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2955 /* DECL_UID of the variable decl. */
2956 unsigned int decl_id
;
2958 typedef struct var_loc_list_def var_loc_list
;
2960 /* Call argument location list. */
2961 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2962 rtx
GTY (()) call_arg_loc_note
;
2963 const char * GTY (()) label
;
2964 tree
GTY (()) block
;
2966 rtx
GTY (()) symbol_ref
;
2967 struct call_arg_loc_node
* GTY (()) next
;
2971 struct decl_loc_hasher
: ggc_ptr_hash
<var_loc_list
>
2973 typedef const_tree compare_type
;
2975 static hashval_t
hash (var_loc_list
*);
2976 static bool equal (var_loc_list
*, const_tree
);
2979 /* Table of decl location linked lists. */
2980 static GTY (()) hash_table
<decl_loc_hasher
> *decl_loc_table
;
2982 /* Head and tail of call_arg_loc chain. */
2983 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2984 static struct call_arg_loc_node
*call_arg_loc_last
;
2986 /* Number of call sites in the current function. */
2987 static int call_site_count
= -1;
2988 /* Number of tail call sites in the current function. */
2989 static int tail_call_site_count
= -1;
2991 /* A cached location list. */
2992 struct GTY ((for_user
)) cached_dw_loc_list_def
{
2993 /* The DECL_UID of the decl that this entry describes. */
2994 unsigned int decl_id
;
2996 /* The cached location list. */
2997 dw_loc_list_ref loc_list
;
2999 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
3001 struct dw_loc_list_hasher
: ggc_ptr_hash
<cached_dw_loc_list
>
3004 typedef const_tree compare_type
;
3006 static hashval_t
hash (cached_dw_loc_list
*);
3007 static bool equal (cached_dw_loc_list
*, const_tree
);
3010 /* Table of cached location lists. */
3011 static GTY (()) hash_table
<dw_loc_list_hasher
> *cached_dw_loc_list_table
;
3013 /* A pointer to the base of a list of references to DIE's that
3014 are uniquely identified by their tag, presence/absence of
3015 children DIE's, and list of attribute/value pairs. */
3016 static GTY((length ("abbrev_die_table_allocated")))
3017 dw_die_ref
*abbrev_die_table
;
3019 /* Number of elements currently allocated for abbrev_die_table. */
3020 static GTY(()) unsigned abbrev_die_table_allocated
;
3022 /* Number of elements in abbrev_die_table currently in use. */
3023 static GTY(()) unsigned abbrev_die_table_in_use
;
3025 /* A hash map to remember the stack usage for DWARF procedures. The value
3026 stored is the stack size difference between before the DWARF procedure
3027 invokation and after it returned. In other words, for a DWARF procedure
3028 that consumes N stack slots and that pushes M ones, this stores M - N. */
3029 static hash_map
<dw_die_ref
, int> *dwarf_proc_stack_usage_map
;
3031 /* Size (in elements) of increments by which we may expand the
3032 abbrev_die_table. */
3033 #define ABBREV_DIE_TABLE_INCREMENT 256
3035 /* A global counter for generating labels for line number data. */
3036 static unsigned int line_info_label_num
;
3038 /* The current table to which we should emit line number information
3039 for the current function. This will be set up at the beginning of
3040 assembly for the function. */
3041 static GTY(()) dw_line_info_table
*cur_line_info_table
;
3043 /* The two default tables of line number info. */
3044 static GTY(()) dw_line_info_table
*text_section_line_info
;
3045 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
3047 /* The set of all non-default tables of line number info. */
3048 static GTY(()) vec
<dw_line_info_table
*, va_gc
> *separate_line_info
;
3050 /* A flag to tell pubnames/types export if there is an info section to
3052 static bool info_section_emitted
;
3054 /* A pointer to the base of a table that contains a list of publicly
3055 accessible names. */
3056 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
3058 /* A pointer to the base of a table that contains a list of publicly
3059 accessible types. */
3060 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
3062 /* A pointer to the base of a table that contains a list of macro
3063 defines/undefines (and file start/end markers). */
3064 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
3066 /* True if .debug_macinfo or .debug_macros section is going to be
3068 #define have_macinfo \
3069 ((!XCOFF_DEBUGGING_INFO || HAVE_XCOFF_DWARF_EXTRAS) \
3070 && debug_info_level >= DINFO_LEVEL_VERBOSE \
3071 && !macinfo_table->is_empty ())
3073 /* Array of dies for which we should generate .debug_ranges info. */
3074 static GTY ((length ("ranges_table_allocated"))) dw_ranges
*ranges_table
;
3076 /* Number of elements currently allocated for ranges_table. */
3077 static GTY(()) unsigned ranges_table_allocated
;
3079 /* Number of elements in ranges_table currently in use. */
3080 static GTY(()) unsigned ranges_table_in_use
;
3082 /* Array of pairs of labels referenced in ranges_table. */
3083 static GTY ((length ("ranges_by_label_allocated")))
3084 dw_ranges_by_label
*ranges_by_label
;
3086 /* Number of elements currently allocated for ranges_by_label. */
3087 static GTY(()) unsigned ranges_by_label_allocated
;
3089 /* Number of elements in ranges_by_label currently in use. */
3090 static GTY(()) unsigned ranges_by_label_in_use
;
3092 /* Size (in elements) of increments by which we may expand the
3094 #define RANGES_TABLE_INCREMENT 64
3096 /* Whether we have location lists that need outputting */
3097 static GTY(()) bool have_location_lists
;
3099 /* Unique label counter. */
3100 static GTY(()) unsigned int loclabel_num
;
3102 /* Unique label counter for point-of-call tables. */
3103 static GTY(()) unsigned int poc_label_num
;
3105 /* The last file entry emitted by maybe_emit_file(). */
3106 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
3108 /* Number of internal labels generated by gen_internal_sym(). */
3109 static GTY(()) int label_num
;
3111 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
3113 /* Instances of generic types for which we need to generate debug
3114 info that describe their generic parameters and arguments. That
3115 generation needs to happen once all types are properly laid out so
3116 we do it at the end of compilation. */
3117 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
3119 /* Offset from the "steady-state frame pointer" to the frame base,
3120 within the current function. */
3121 static HOST_WIDE_INT frame_pointer_fb_offset
;
3122 static bool frame_pointer_fb_offset_valid
;
3124 static vec
<dw_die_ref
> base_types
;
3126 /* Pointer to vector of DW_TAG_string_type DIEs that need finalization
3127 once all arguments are parsed. */
3128 static vec
<dw_die_ref
> *string_types
;
3130 /* Flags to represent a set of attribute classes for attributes that represent
3131 a scalar value (bounds, pointers, ...). */
3134 dw_scalar_form_constant
= 0x01,
3135 dw_scalar_form_exprloc
= 0x02,
3136 dw_scalar_form_reference
= 0x04
3139 /* Forward declarations for functions defined in this file. */
3141 static int is_pseudo_reg (const_rtx
);
3142 static tree
type_main_variant (tree
);
3143 static int is_tagged_type (const_tree
);
3144 static const char *dwarf_tag_name (unsigned);
3145 static const char *dwarf_attr_name (unsigned);
3146 static const char *dwarf_form_name (unsigned);
3147 static tree
decl_ultimate_origin (const_tree
);
3148 static tree
decl_class_context (tree
);
3149 static void add_dwarf_attr (dw_die_ref
, dw_attr_node
*);
3150 static inline enum dw_val_class
AT_class (dw_attr_node
*);
3151 static inline unsigned int AT_index (dw_attr_node
*);
3152 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3153 static inline unsigned AT_flag (dw_attr_node
*);
3154 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3155 static inline HOST_WIDE_INT
AT_int (dw_attr_node
*);
3156 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3157 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_node
*);
3158 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
3159 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
3160 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3161 unsigned int, unsigned char *);
3162 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
3163 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3164 static inline const char *AT_string (dw_attr_node
*);
3165 static enum dwarf_form
AT_string_form (dw_attr_node
*);
3166 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3167 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3168 static inline dw_die_ref
AT_ref (dw_attr_node
*);
3169 static inline int AT_ref_external (dw_attr_node
*);
3170 static inline void set_AT_ref_external (dw_attr_node
*, int);
3171 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3172 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3173 static inline dw_loc_descr_ref
AT_loc (dw_attr_node
*);
3174 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3176 static inline dw_loc_list_ref
AT_loc_list (dw_attr_node
*);
3177 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
3178 static void remove_addr_table_entry (addr_table_entry
*);
3179 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
3180 static inline rtx
AT_addr (dw_attr_node
*);
3181 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3182 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3183 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3184 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3185 unsigned HOST_WIDE_INT
);
3186 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3187 unsigned long, bool);
3188 static inline const char *AT_lbl (dw_attr_node
*);
3189 static dw_attr_node
*get_AT (dw_die_ref
, enum dwarf_attribute
);
3190 static const char *get_AT_low_pc (dw_die_ref
);
3191 static const char *get_AT_hi_pc (dw_die_ref
);
3192 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3193 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3194 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3195 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3196 static bool is_cxx (void);
3197 static bool is_fortran (void);
3198 static bool is_ada (void);
3199 static bool remove_AT (dw_die_ref
, enum dwarf_attribute
);
3200 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3201 static void add_child_die (dw_die_ref
, dw_die_ref
);
3202 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3203 static dw_die_ref
lookup_type_die (tree
);
3204 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3205 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3206 static void equate_type_number_to_die (tree
, dw_die_ref
);
3207 static dw_die_ref
lookup_decl_die (tree
);
3208 static var_loc_list
*lookup_decl_loc (const_tree
);
3209 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3210 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3211 static void print_spaces (FILE *);
3212 static void print_die (dw_die_ref
, FILE *);
3213 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3214 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3215 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3216 static void attr_checksum (dw_attr_node
*, struct md5_ctx
*, int *);
3217 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3218 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3219 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3220 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3221 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_node
*,
3222 struct md5_ctx
*, int *);
3223 struct checksum_attributes
;
3224 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3225 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3226 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3227 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3228 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3229 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3230 static int same_attr_p (dw_attr_node
*, dw_attr_node
*, int *);
3231 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3232 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3233 static void compute_section_prefix (dw_die_ref
);
3234 static int is_type_die (dw_die_ref
);
3235 static int is_comdat_die (dw_die_ref
);
3236 static int is_symbol_die (dw_die_ref
);
3237 static inline bool is_template_instantiation (dw_die_ref
);
3238 static void assign_symbol_names (dw_die_ref
);
3239 static void break_out_includes (dw_die_ref
);
3240 static int is_declaration_die (dw_die_ref
);
3241 static int should_move_die_to_comdat (dw_die_ref
);
3242 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3243 static dw_die_ref
clone_die (dw_die_ref
);
3244 static dw_die_ref
clone_tree (dw_die_ref
);
3245 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3246 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3247 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3248 static dw_die_ref
generate_skeleton (dw_die_ref
);
3249 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3252 static void break_out_comdat_types (dw_die_ref
);
3253 static void copy_decls_for_unworthy_types (dw_die_ref
);
3255 static void add_sibling_attributes (dw_die_ref
);
3256 static void output_location_lists (dw_die_ref
);
3257 static int constant_size (unsigned HOST_WIDE_INT
);
3258 static unsigned long size_of_die (dw_die_ref
);
3259 static void calc_die_sizes (dw_die_ref
);
3260 static void calc_base_type_die_sizes (void);
3261 static void mark_dies (dw_die_ref
);
3262 static void unmark_dies (dw_die_ref
);
3263 static void unmark_all_dies (dw_die_ref
);
3264 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3265 static unsigned long size_of_aranges (void);
3266 static enum dwarf_form
value_format (dw_attr_node
*);
3267 static void output_value_format (dw_attr_node
*);
3268 static void output_abbrev_section (void);
3269 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3270 static void output_die_symbol (dw_die_ref
);
3271 static void output_die (dw_die_ref
);
3272 static void output_compilation_unit_header (void);
3273 static void output_comp_unit (dw_die_ref
, int);
3274 static void output_comdat_type_unit (comdat_type_node
*);
3275 static const char *dwarf2_name (tree
, int);
3276 static void add_pubname (tree
, dw_die_ref
);
3277 static void add_enumerator_pubname (const char *, dw_die_ref
);
3278 static void add_pubname_string (const char *, dw_die_ref
);
3279 static void add_pubtype (tree
, dw_die_ref
);
3280 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3281 static void output_aranges (void);
3282 static unsigned int add_ranges_num (int);
3283 static unsigned int add_ranges (const_tree
);
3284 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3286 static void output_ranges (void);
3287 static dw_line_info_table
*new_line_info_table (void);
3288 static void output_line_info (bool);
3289 static void output_file_names (void);
3290 static dw_die_ref
base_type_die (tree
, bool);
3291 static int is_base_type (tree
);
3292 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, tree
, dw_die_ref
);
3293 static int decl_quals (const_tree
);
3294 static dw_die_ref
modified_type_die (tree
, int, bool, dw_die_ref
);
3295 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3296 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3297 static int type_is_enum (const_tree
);
3298 static unsigned int dbx_reg_number (const_rtx
);
3299 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3300 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3301 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3302 enum var_init_status
);
3303 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3304 enum var_init_status
);
3305 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3306 enum var_init_status
);
3307 static int is_based_loc (const_rtx
);
3308 static bool resolve_one_addr (rtx
*);
3309 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3310 enum var_init_status
);
3311 static dw_loc_descr_ref
loc_descriptor (rtx
, machine_mode mode
,
3312 enum var_init_status
);
3313 struct loc_descr_context
;
3314 static void add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
);
3315 static void add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
);
3316 static dw_loc_list_ref
loc_list_from_tree (tree
, int,
3317 const struct loc_descr_context
*);
3318 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int,
3319 const struct loc_descr_context
*);
3320 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3321 static tree
field_type (const_tree
);
3322 static unsigned int simple_type_align_in_bits (const_tree
);
3323 static unsigned int simple_decl_align_in_bits (const_tree
);
3324 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3326 static dw_loc_descr_ref
field_byte_offset (const_tree
, struct vlr_context
*,
3328 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3330 static void add_data_member_location_attribute (dw_die_ref
, tree
,
3331 struct vlr_context
*);
3332 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3333 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3334 static void insert_wide_int (const wide_int
&, unsigned char *, int);
3335 static void insert_float (const_rtx
, unsigned char *);
3336 static rtx
rtl_for_decl_location (tree
);
3337 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool);
3338 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3339 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3340 static void add_name_attribute (dw_die_ref
, const char *);
3341 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3342 static void add_comp_dir_attribute (dw_die_ref
);
3343 static void add_scalar_info (dw_die_ref
, enum dwarf_attribute
, tree
, int,
3344 const struct loc_descr_context
*);
3345 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
,
3346 const struct loc_descr_context
*);
3347 static void add_subscript_info (dw_die_ref
, tree
, bool);
3348 static void add_byte_size_attribute (dw_die_ref
, tree
);
3349 static inline void add_bit_offset_attribute (dw_die_ref
, tree
,
3350 struct vlr_context
*);
3351 static void add_bit_size_attribute (dw_die_ref
, tree
);
3352 static void add_prototyped_attribute (dw_die_ref
, tree
);
3353 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3354 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3355 static void add_src_coords_attributes (dw_die_ref
, tree
);
3356 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3357 static void add_discr_value (dw_die_ref
, dw_discr_value
*);
3358 static void add_discr_list (dw_die_ref
, dw_discr_list_ref
);
3359 static inline dw_discr_list_ref
AT_discr_list (dw_attr_node
*);
3360 static void push_decl_scope (tree
);
3361 static void pop_decl_scope (void);
3362 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3363 static inline int local_scope_p (dw_die_ref
);
3364 static inline int class_scope_p (dw_die_ref
);
3365 static inline int class_or_namespace_scope_p (dw_die_ref
);
3366 static void add_type_attribute (dw_die_ref
, tree
, int, bool, dw_die_ref
);
3367 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3368 static const char *type_tag (const_tree
);
3369 static tree
member_declared_type (const_tree
);
3371 static const char *decl_start_label (tree
);
3373 static void gen_array_type_die (tree
, dw_die_ref
);
3374 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3376 static void gen_entry_point_die (tree
, dw_die_ref
);
3378 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3379 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3380 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3381 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3382 static void gen_formal_types_die (tree
, dw_die_ref
);
3383 static void gen_subprogram_die (tree
, dw_die_ref
);
3384 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3385 static void gen_const_die (tree
, dw_die_ref
);
3386 static void gen_label_die (tree
, dw_die_ref
);
3387 static void gen_lexical_block_die (tree
, dw_die_ref
);
3388 static void gen_inlined_subroutine_die (tree
, dw_die_ref
);
3389 static void gen_field_die (tree
, struct vlr_context
*, dw_die_ref
);
3390 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3391 static dw_die_ref
gen_compile_unit_die (const char *);
3392 static void gen_inheritance_die (tree
, tree
, tree
, dw_die_ref
);
3393 static void gen_member_die (tree
, dw_die_ref
);
3394 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3395 enum debug_info_usage
);
3396 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3397 static void gen_typedef_die (tree
, dw_die_ref
);
3398 static void gen_type_die (tree
, dw_die_ref
);
3399 static void gen_block_die (tree
, dw_die_ref
);
3400 static void decls_for_scope (tree
, dw_die_ref
);
3401 static bool is_naming_typedef_decl (const_tree
);
3402 static inline dw_die_ref
get_context_die (tree
);
3403 static void gen_namespace_die (tree
, dw_die_ref
);
3404 static dw_die_ref
gen_namelist_decl (tree
, dw_die_ref
, tree
);
3405 static dw_die_ref
gen_decl_die (tree
, tree
, struct vlr_context
*, dw_die_ref
);
3406 static dw_die_ref
force_decl_die (tree
);
3407 static dw_die_ref
force_type_die (tree
);
3408 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3409 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3410 static struct dwarf_file_data
* lookup_filename (const char *);
3411 static void retry_incomplete_types (void);
3412 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3413 static void gen_generic_params_dies (tree
);
3414 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3415 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3416 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3417 static int file_info_cmp (const void *, const void *);
3418 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3419 const char *, const char *);
3420 static void output_loc_list (dw_loc_list_ref
);
3421 static char *gen_internal_sym (const char *);
3422 static bool want_pubnames (void);
3424 static void prune_unmark_dies (dw_die_ref
);
3425 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3426 static void prune_unused_types_mark (dw_die_ref
, int);
3427 static void prune_unused_types_walk (dw_die_ref
);
3428 static void prune_unused_types_walk_attribs (dw_die_ref
);
3429 static void prune_unused_types_prune (dw_die_ref
);
3430 static void prune_unused_types (void);
3431 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3432 static inline const char *AT_vms_delta1 (dw_attr_node
*);
3433 static inline const char *AT_vms_delta2 (dw_attr_node
*);
3434 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3435 const char *, const char *);
3436 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3437 static void gen_remaining_tmpl_value_param_die_attribute (void);
3438 static bool generic_type_p (tree
);
3439 static void schedule_generic_params_dies_gen (tree t
);
3440 static void gen_scheduled_generic_parms_dies (void);
3442 static const char *comp_dir_string (void);
3444 static void hash_loc_operands (dw_loc_descr_ref
, inchash::hash
&);
3446 /* enum for tracking thread-local variables whose address is really an offset
3447 relative to the TLS pointer, which will need link-time relocation, but will
3448 not need relocation by the DWARF consumer. */
3456 /* Return the operator to use for an address of a variable. For dtprel_true, we
3457 use DW_OP_const*. For regular variables, which need both link-time
3458 relocation and consumer-level relocation (e.g., to account for shared objects
3459 loaded at a random address), we use DW_OP_addr*. */
3461 static inline enum dwarf_location_atom
3462 dw_addr_op (enum dtprel_bool dtprel
)
3464 if (dtprel
== dtprel_true
)
3465 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3466 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3468 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3471 /* Return a pointer to a newly allocated address location description. If
3472 dwarf_split_debug_info is true, then record the address with the appropriate
3474 static inline dw_loc_descr_ref
3475 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3477 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3479 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3480 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3481 ref
->dtprel
= dtprel
;
3482 if (dwarf_split_debug_info
)
3483 ref
->dw_loc_oprnd1
.val_entry
3484 = add_addr_table_entry (addr
,
3485 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3487 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3492 /* Section names used to hold DWARF debugging information. */
3494 #ifndef DEBUG_INFO_SECTION
3495 #define DEBUG_INFO_SECTION ".debug_info"
3497 #ifndef DEBUG_DWO_INFO_SECTION
3498 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3500 #ifndef DEBUG_ABBREV_SECTION
3501 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3503 #ifndef DEBUG_DWO_ABBREV_SECTION
3504 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3506 #ifndef DEBUG_ARANGES_SECTION
3507 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3509 #ifndef DEBUG_ADDR_SECTION
3510 #define DEBUG_ADDR_SECTION ".debug_addr"
3512 #ifndef DEBUG_NORM_MACINFO_SECTION
3513 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3515 #ifndef DEBUG_DWO_MACINFO_SECTION
3516 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3518 #ifndef DEBUG_MACINFO_SECTION
3519 #define DEBUG_MACINFO_SECTION \
3520 (!dwarf_split_debug_info \
3521 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3523 #ifndef DEBUG_NORM_MACRO_SECTION
3524 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3526 #ifndef DEBUG_DWO_MACRO_SECTION
3527 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3529 #ifndef DEBUG_MACRO_SECTION
3530 #define DEBUG_MACRO_SECTION \
3531 (!dwarf_split_debug_info \
3532 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3534 #ifndef DEBUG_LINE_SECTION
3535 #define DEBUG_LINE_SECTION ".debug_line"
3537 #ifndef DEBUG_DWO_LINE_SECTION
3538 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3540 #ifndef DEBUG_LOC_SECTION
3541 #define DEBUG_LOC_SECTION ".debug_loc"
3543 #ifndef DEBUG_DWO_LOC_SECTION
3544 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3546 #ifndef DEBUG_PUBNAMES_SECTION
3547 #define DEBUG_PUBNAMES_SECTION \
3548 ((debug_generate_pub_sections == 2) \
3549 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3551 #ifndef DEBUG_PUBTYPES_SECTION
3552 #define DEBUG_PUBTYPES_SECTION \
3553 ((debug_generate_pub_sections == 2) \
3554 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3556 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3557 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3558 #ifndef DEBUG_STR_OFFSETS_SECTION
3559 #define DEBUG_STR_OFFSETS_SECTION \
3560 (!dwarf_split_debug_info \
3561 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3563 #ifndef DEBUG_STR_DWO_SECTION
3564 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3566 #ifndef DEBUG_STR_SECTION
3567 #define DEBUG_STR_SECTION ".debug_str"
3569 #ifndef DEBUG_RANGES_SECTION
3570 #define DEBUG_RANGES_SECTION ".debug_ranges"
3573 /* Standard ELF section names for compiled code and data. */
3574 #ifndef TEXT_SECTION_NAME
3575 #define TEXT_SECTION_NAME ".text"
3578 /* Section flags for .debug_macinfo/.debug_macro section. */
3579 #define DEBUG_MACRO_SECTION_FLAGS \
3580 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3582 /* Section flags for .debug_str section. */
3583 #define DEBUG_STR_SECTION_FLAGS \
3584 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3585 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3588 /* Section flags for .debug_str.dwo section. */
3589 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3591 /* Labels we insert at beginning sections we can reference instead of
3592 the section names themselves. */
3594 #ifndef TEXT_SECTION_LABEL
3595 #define TEXT_SECTION_LABEL "Ltext"
3597 #ifndef COLD_TEXT_SECTION_LABEL
3598 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3600 #ifndef DEBUG_LINE_SECTION_LABEL
3601 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3603 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3604 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3606 #ifndef DEBUG_INFO_SECTION_LABEL
3607 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3609 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3610 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3612 #ifndef DEBUG_ABBREV_SECTION_LABEL
3613 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3615 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3616 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3618 #ifndef DEBUG_ADDR_SECTION_LABEL
3619 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3621 #ifndef DEBUG_LOC_SECTION_LABEL
3622 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3624 #ifndef DEBUG_RANGES_SECTION_LABEL
3625 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3627 #ifndef DEBUG_MACINFO_SECTION_LABEL
3628 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3630 #ifndef DEBUG_MACRO_SECTION_LABEL
3631 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3633 #define SKELETON_COMP_DIE_ABBREV 1
3634 #define SKELETON_TYPE_DIE_ABBREV 2
3636 /* Definitions of defaults for formats and names of various special
3637 (artificial) labels which may be generated within this file (when the -g
3638 options is used and DWARF2_DEBUGGING_INFO is in effect.
3639 If necessary, these may be overridden from within the tm.h file, but
3640 typically, overriding these defaults is unnecessary. */
3642 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3643 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3644 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3645 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3646 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3647 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3648 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3649 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3650 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3651 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3652 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3653 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3654 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3655 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3657 #ifndef TEXT_END_LABEL
3658 #define TEXT_END_LABEL "Letext"
3660 #ifndef COLD_END_LABEL
3661 #define COLD_END_LABEL "Letext_cold"
3663 #ifndef BLOCK_BEGIN_LABEL
3664 #define BLOCK_BEGIN_LABEL "LBB"
3666 #ifndef BLOCK_END_LABEL
3667 #define BLOCK_END_LABEL "LBE"
3669 #ifndef LINE_CODE_LABEL
3670 #define LINE_CODE_LABEL "LM"
3674 /* Return the root of the DIE's built for the current compilation unit. */
3676 comp_unit_die (void)
3678 if (!single_comp_unit_die
)
3679 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3680 return single_comp_unit_die
;
3683 /* We allow a language front-end to designate a function that is to be
3684 called to "demangle" any name before it is put into a DIE. */
3686 static const char *(*demangle_name_func
) (const char *);
3689 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3691 demangle_name_func
= func
;
3694 /* Test if rtl node points to a pseudo register. */
3697 is_pseudo_reg (const_rtx rtl
)
3699 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3700 || (GET_CODE (rtl
) == SUBREG
3701 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3704 /* Return a reference to a type, with its const and volatile qualifiers
3708 type_main_variant (tree type
)
3710 type
= TYPE_MAIN_VARIANT (type
);
3712 /* ??? There really should be only one main variant among any group of
3713 variants of a given type (and all of the MAIN_VARIANT values for all
3714 members of the group should point to that one type) but sometimes the C
3715 front-end messes this up for array types, so we work around that bug
3717 if (TREE_CODE (type
) == ARRAY_TYPE
)
3718 while (type
!= TYPE_MAIN_VARIANT (type
))
3719 type
= TYPE_MAIN_VARIANT (type
);
3724 /* Return nonzero if the given type node represents a tagged type. */
3727 is_tagged_type (const_tree type
)
3729 enum tree_code code
= TREE_CODE (type
);
3731 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3732 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3735 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3738 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3740 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3743 /* Return die_offset of a DIE reference to a base type. */
3745 static unsigned long int
3746 get_base_type_offset (dw_die_ref ref
)
3748 if (ref
->die_offset
)
3749 return ref
->die_offset
;
3750 if (comp_unit_die ()->die_abbrev
)
3752 calc_base_type_die_sizes ();
3753 gcc_assert (ref
->die_offset
);
3755 return ref
->die_offset
;
3758 /* Return die_offset of a DIE reference other than base type. */
3760 static unsigned long int
3761 get_ref_die_offset (dw_die_ref ref
)
3763 gcc_assert (ref
->die_offset
);
3764 return ref
->die_offset
;
3767 /* Convert a DIE tag into its string name. */
3770 dwarf_tag_name (unsigned int tag
)
3772 const char *name
= get_DW_TAG_name (tag
);
3777 return "DW_TAG_<unknown>";
3780 /* Convert a DWARF attribute code into its string name. */
3783 dwarf_attr_name (unsigned int attr
)
3789 #if VMS_DEBUGGING_INFO
3790 case DW_AT_HP_prologue
:
3791 return "DW_AT_HP_prologue";
3793 case DW_AT_MIPS_loop_unroll_factor
:
3794 return "DW_AT_MIPS_loop_unroll_factor";
3797 #if VMS_DEBUGGING_INFO
3798 case DW_AT_HP_epilogue
:
3799 return "DW_AT_HP_epilogue";
3801 case DW_AT_MIPS_stride
:
3802 return "DW_AT_MIPS_stride";
3806 name
= get_DW_AT_name (attr
);
3811 return "DW_AT_<unknown>";
3814 /* Convert a DWARF value form code into its string name. */
3817 dwarf_form_name (unsigned int form
)
3819 const char *name
= get_DW_FORM_name (form
);
3824 return "DW_FORM_<unknown>";
3827 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3828 instance of an inlined instance of a decl which is local to an inline
3829 function, so we have to trace all of the way back through the origin chain
3830 to find out what sort of node actually served as the original seed for the
3834 decl_ultimate_origin (const_tree decl
)
3836 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3839 /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
3840 we're trying to output the abstract instance of this function. */
3841 if (DECL_ABSTRACT_P (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3844 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3845 most distant ancestor, this should never happen. */
3846 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3848 return DECL_ABSTRACT_ORIGIN (decl
);
3851 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3852 of a virtual function may refer to a base class, so we check the 'this'
3856 decl_class_context (tree decl
)
3858 tree context
= NULL_TREE
;
3860 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3861 context
= DECL_CONTEXT (decl
);
3863 context
= TYPE_MAIN_VARIANT
3864 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3866 if (context
&& !TYPE_P (context
))
3867 context
= NULL_TREE
;
3872 /* Add an attribute/value pair to a DIE. */
3875 add_dwarf_attr (dw_die_ref die
, dw_attr_node
*attr
)
3877 /* Maybe this should be an assert? */
3881 vec_safe_reserve (die
->die_attr
, 1);
3882 vec_safe_push (die
->die_attr
, *attr
);
3885 static inline enum dw_val_class
3886 AT_class (dw_attr_node
*a
)
3888 return a
->dw_attr_val
.val_class
;
3891 /* Return the index for any attribute that will be referenced with a
3892 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3893 are stored in dw_attr_val.v.val_str for reference counting
3896 static inline unsigned int
3897 AT_index (dw_attr_node
*a
)
3899 if (AT_class (a
) == dw_val_class_str
)
3900 return a
->dw_attr_val
.v
.val_str
->index
;
3901 else if (a
->dw_attr_val
.val_entry
!= NULL
)
3902 return a
->dw_attr_val
.val_entry
->index
;
3906 /* Add a flag value attribute to a DIE. */
3909 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3913 attr
.dw_attr
= attr_kind
;
3914 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3915 attr
.dw_attr_val
.val_entry
= NULL
;
3916 attr
.dw_attr_val
.v
.val_flag
= flag
;
3917 add_dwarf_attr (die
, &attr
);
3920 static inline unsigned
3921 AT_flag (dw_attr_node
*a
)
3923 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3924 return a
->dw_attr_val
.v
.val_flag
;
3927 /* Add a signed integer attribute value to a DIE. */
3930 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3934 attr
.dw_attr
= attr_kind
;
3935 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3936 attr
.dw_attr_val
.val_entry
= NULL
;
3937 attr
.dw_attr_val
.v
.val_int
= int_val
;
3938 add_dwarf_attr (die
, &attr
);
3941 static inline HOST_WIDE_INT
3942 AT_int (dw_attr_node
*a
)
3944 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3945 return a
->dw_attr_val
.v
.val_int
;
3948 /* Add an unsigned integer attribute value to a DIE. */
3951 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3952 unsigned HOST_WIDE_INT unsigned_val
)
3956 attr
.dw_attr
= attr_kind
;
3957 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3958 attr
.dw_attr_val
.val_entry
= NULL
;
3959 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3960 add_dwarf_attr (die
, &attr
);
3963 static inline unsigned HOST_WIDE_INT
3964 AT_unsigned (dw_attr_node
*a
)
3966 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3967 return a
->dw_attr_val
.v
.val_unsigned
;
3970 /* Add an unsigned wide integer attribute value to a DIE. */
3973 add_AT_wide (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3978 attr
.dw_attr
= attr_kind
;
3979 attr
.dw_attr_val
.val_class
= dw_val_class_wide_int
;
3980 attr
.dw_attr_val
.val_entry
= NULL
;
3981 attr
.dw_attr_val
.v
.val_wide
= ggc_alloc
<wide_int
> ();
3982 *attr
.dw_attr_val
.v
.val_wide
= w
;
3983 add_dwarf_attr (die
, &attr
);
3986 /* Add an unsigned double integer attribute value to a DIE. */
3989 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3990 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3994 attr
.dw_attr
= attr_kind
;
3995 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3996 attr
.dw_attr_val
.val_entry
= NULL
;
3997 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3998 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3999 add_dwarf_attr (die
, &attr
);
4002 /* Add a floating point attribute value to a DIE and return it. */
4005 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4006 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
4010 attr
.dw_attr
= attr_kind
;
4011 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
4012 attr
.dw_attr_val
.val_entry
= NULL
;
4013 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
4014 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
4015 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
4016 add_dwarf_attr (die
, &attr
);
4019 /* Add an 8-byte data attribute value to a DIE. */
4022 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4023 unsigned char data8
[8])
4027 attr
.dw_attr
= attr_kind
;
4028 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
4029 attr
.dw_attr_val
.val_entry
= NULL
;
4030 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
4031 add_dwarf_attr (die
, &attr
);
4034 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
4035 dwarf_split_debug_info, address attributes in dies destined for the
4036 final executable have force_direct set to avoid using indexed
4040 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
4046 lbl_id
= xstrdup (lbl_low
);
4047 attr
.dw_attr
= DW_AT_low_pc
;
4048 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4049 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4050 if (dwarf_split_debug_info
&& !force_direct
)
4051 attr
.dw_attr_val
.val_entry
4052 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4054 attr
.dw_attr_val
.val_entry
= NULL
;
4055 add_dwarf_attr (die
, &attr
);
4057 attr
.dw_attr
= DW_AT_high_pc
;
4058 if (dwarf_version
< 4)
4059 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4061 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
4062 lbl_id
= xstrdup (lbl_high
);
4063 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4064 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
4065 && dwarf_split_debug_info
&& !force_direct
)
4066 attr
.dw_attr_val
.val_entry
4067 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4069 attr
.dw_attr_val
.val_entry
= NULL
;
4070 add_dwarf_attr (die
, &attr
);
4073 /* Hash and equality functions for debug_str_hash. */
4076 indirect_string_hasher::hash (indirect_string_node
*x
)
4078 return htab_hash_string (x
->str
);
4082 indirect_string_hasher::equal (indirect_string_node
*x1
, const char *x2
)
4084 return strcmp (x1
->str
, x2
) == 0;
4087 /* Add STR to the given string hash table. */
4089 static struct indirect_string_node
*
4090 find_AT_string_in_table (const char *str
,
4091 hash_table
<indirect_string_hasher
> *table
)
4093 struct indirect_string_node
*node
;
4095 indirect_string_node
**slot
4096 = table
->find_slot_with_hash (str
, htab_hash_string (str
), INSERT
);
4099 node
= ggc_cleared_alloc
<indirect_string_node
> ();
4100 node
->str
= ggc_strdup (str
);
4110 /* Add STR to the indirect string hash table. */
4112 static struct indirect_string_node
*
4113 find_AT_string (const char *str
)
4115 if (! debug_str_hash
)
4116 debug_str_hash
= hash_table
<indirect_string_hasher
>::create_ggc (10);
4118 return find_AT_string_in_table (str
, debug_str_hash
);
4121 /* Add a string attribute value to a DIE. */
4124 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4127 struct indirect_string_node
*node
;
4129 node
= find_AT_string (str
);
4131 attr
.dw_attr
= attr_kind
;
4132 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4133 attr
.dw_attr_val
.val_entry
= NULL
;
4134 attr
.dw_attr_val
.v
.val_str
= node
;
4135 add_dwarf_attr (die
, &attr
);
4138 static inline const char *
4139 AT_string (dw_attr_node
*a
)
4141 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4142 return a
->dw_attr_val
.v
.val_str
->str
;
4145 /* Call this function directly to bypass AT_string_form's logic to put
4146 the string inline in the die. */
4149 set_indirect_string (struct indirect_string_node
*node
)
4152 /* Already indirect is a no op. */
4153 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
4155 gcc_assert (node
->label
);
4158 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4159 ++dw2_string_counter
;
4160 node
->label
= xstrdup (label
);
4162 if (!dwarf_split_debug_info
)
4164 node
->form
= DW_FORM_strp
;
4165 node
->index
= NOT_INDEXED
;
4169 node
->form
= DW_FORM_GNU_str_index
;
4170 node
->index
= NO_INDEX_ASSIGNED
;
4174 /* Find out whether a string should be output inline in DIE
4175 or out-of-line in .debug_str section. */
4177 static enum dwarf_form
4178 find_string_form (struct indirect_string_node
*node
)
4185 len
= strlen (node
->str
) + 1;
4187 /* If the string is shorter or equal to the size of the reference, it is
4188 always better to put it inline. */
4189 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4190 return node
->form
= DW_FORM_string
;
4192 /* If we cannot expect the linker to merge strings in .debug_str
4193 section, only put it into .debug_str if it is worth even in this
4195 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4196 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4197 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
4198 return node
->form
= DW_FORM_string
;
4200 set_indirect_string (node
);
4205 /* Find out whether the string referenced from the attribute should be
4206 output inline in DIE or out-of-line in .debug_str section. */
4208 static enum dwarf_form
4209 AT_string_form (dw_attr_node
*a
)
4211 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4212 return find_string_form (a
->dw_attr_val
.v
.val_str
);
4215 /* Add a DIE reference attribute value to a DIE. */
4218 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4221 gcc_checking_assert (targ_die
!= NULL
);
4223 /* With LTO we can end up trying to reference something we didn't create
4224 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4225 if (targ_die
== NULL
)
4228 attr
.dw_attr
= attr_kind
;
4229 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4230 attr
.dw_attr_val
.val_entry
= NULL
;
4231 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4232 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4233 add_dwarf_attr (die
, &attr
);
4236 /* Change DIE reference REF to point to NEW_DIE instead. */
4239 change_AT_die_ref (dw_attr_node
*ref
, dw_die_ref new_die
)
4241 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4242 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4243 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4246 /* Add an AT_specification attribute to a DIE, and also make the back
4247 pointer from the specification to the definition. */
4250 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4252 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4253 gcc_assert (!targ_die
->die_definition
);
4254 targ_die
->die_definition
= die
;
4257 static inline dw_die_ref
4258 AT_ref (dw_attr_node
*a
)
4260 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4261 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4265 AT_ref_external (dw_attr_node
*a
)
4267 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4268 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4274 set_AT_ref_external (dw_attr_node
*a
, int i
)
4276 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4277 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4280 /* Add an FDE reference attribute value to a DIE. */
4283 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4287 attr
.dw_attr
= attr_kind
;
4288 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4289 attr
.dw_attr_val
.val_entry
= NULL
;
4290 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4291 add_dwarf_attr (die
, &attr
);
4294 /* Add a location description attribute value to a DIE. */
4297 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4301 attr
.dw_attr
= attr_kind
;
4302 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4303 attr
.dw_attr_val
.val_entry
= NULL
;
4304 attr
.dw_attr_val
.v
.val_loc
= loc
;
4305 add_dwarf_attr (die
, &attr
);
4308 static inline dw_loc_descr_ref
4309 AT_loc (dw_attr_node
*a
)
4311 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4312 return a
->dw_attr_val
.v
.val_loc
;
4316 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4320 if (XCOFF_DEBUGGING_INFO
&& !HAVE_XCOFF_DWARF_EXTRAS
)
4323 attr
.dw_attr
= attr_kind
;
4324 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4325 attr
.dw_attr_val
.val_entry
= NULL
;
4326 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4327 add_dwarf_attr (die
, &attr
);
4328 have_location_lists
= true;
4331 static inline dw_loc_list_ref
4332 AT_loc_list (dw_attr_node
*a
)
4334 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4335 return a
->dw_attr_val
.v
.val_loc_list
;
4338 static inline dw_loc_list_ref
*
4339 AT_loc_list_ptr (dw_attr_node
*a
)
4341 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4342 return &a
->dw_attr_val
.v
.val_loc_list
;
4345 struct addr_hasher
: ggc_ptr_hash
<addr_table_entry
>
4347 static hashval_t
hash (addr_table_entry
*);
4348 static bool equal (addr_table_entry
*, addr_table_entry
*);
4351 /* Table of entries into the .debug_addr section. */
4353 static GTY (()) hash_table
<addr_hasher
> *addr_index_table
;
4355 /* Hash an address_table_entry. */
4358 addr_hasher::hash (addr_table_entry
*a
)
4360 inchash::hash hstate
;
4366 case ate_kind_rtx_dtprel
:
4369 case ate_kind_label
:
4370 return htab_hash_string (a
->addr
.label
);
4374 inchash::add_rtx (a
->addr
.rtl
, hstate
);
4375 return hstate
.end ();
4378 /* Determine equality for two address_table_entries. */
4381 addr_hasher::equal (addr_table_entry
*a1
, addr_table_entry
*a2
)
4383 if (a1
->kind
!= a2
->kind
)
4388 case ate_kind_rtx_dtprel
:
4389 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4390 case ate_kind_label
:
4391 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4397 /* Initialize an addr_table_entry. */
4400 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4406 case ate_kind_rtx_dtprel
:
4407 e
->addr
.rtl
= (rtx
) addr
;
4409 case ate_kind_label
:
4410 e
->addr
.label
= (char *) addr
;
4414 e
->index
= NO_INDEX_ASSIGNED
;
4417 /* Add attr to the address table entry to the table. Defer setting an
4418 index until output time. */
4420 static addr_table_entry
*
4421 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4423 addr_table_entry
*node
;
4424 addr_table_entry finder
;
4426 gcc_assert (dwarf_split_debug_info
);
4427 if (! addr_index_table
)
4428 addr_index_table
= hash_table
<addr_hasher
>::create_ggc (10);
4429 init_addr_table_entry (&finder
, kind
, addr
);
4430 addr_table_entry
**slot
= addr_index_table
->find_slot (&finder
, INSERT
);
4432 if (*slot
== HTAB_EMPTY_ENTRY
)
4434 node
= ggc_cleared_alloc
<addr_table_entry
> ();
4435 init_addr_table_entry (node
, kind
, addr
);
4445 /* Remove an entry from the addr table by decrementing its refcount.
4446 Strictly, decrementing the refcount would be enough, but the
4447 assertion that the entry is actually in the table has found
4451 remove_addr_table_entry (addr_table_entry
*entry
)
4453 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4454 /* After an index is assigned, the table is frozen. */
4455 gcc_assert (entry
->refcount
> 0 && entry
->index
== NO_INDEX_ASSIGNED
);
4459 /* Given a location list, remove all addresses it refers to from the
4463 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4465 for (; descr
; descr
= descr
->dw_loc_next
)
4466 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4468 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4469 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4473 /* A helper function for dwarf2out_finish called through
4474 htab_traverse. Assign an addr_table_entry its index. All entries
4475 must be collected into the table when this function is called,
4476 because the indexing code relies on htab_traverse to traverse nodes
4477 in the same order for each run. */
4480 index_addr_table_entry (addr_table_entry
**h
, unsigned int *index
)
4482 addr_table_entry
*node
= *h
;
4484 /* Don't index unreferenced nodes. */
4485 if (node
->refcount
== 0)
4488 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
4489 node
->index
= *index
;
4495 /* Add an address constant attribute value to a DIE. When using
4496 dwarf_split_debug_info, address attributes in dies destined for the
4497 final executable should be direct references--setting the parameter
4498 force_direct ensures this behavior. */
4501 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4506 attr
.dw_attr
= attr_kind
;
4507 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4508 attr
.dw_attr_val
.v
.val_addr
= addr
;
4509 if (dwarf_split_debug_info
&& !force_direct
)
4510 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4512 attr
.dw_attr_val
.val_entry
= NULL
;
4513 add_dwarf_attr (die
, &attr
);
4516 /* Get the RTX from to an address DIE attribute. */
4519 AT_addr (dw_attr_node
*a
)
4521 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4522 return a
->dw_attr_val
.v
.val_addr
;
4525 /* Add a file attribute value to a DIE. */
4528 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4529 struct dwarf_file_data
*fd
)
4533 attr
.dw_attr
= attr_kind
;
4534 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4535 attr
.dw_attr_val
.val_entry
= NULL
;
4536 attr
.dw_attr_val
.v
.val_file
= fd
;
4537 add_dwarf_attr (die
, &attr
);
4540 /* Get the dwarf_file_data from a file DIE attribute. */
4542 static inline struct dwarf_file_data
*
4543 AT_file (dw_attr_node
*a
)
4545 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4546 return a
->dw_attr_val
.v
.val_file
;
4549 /* Add a vms delta attribute value to a DIE. */
4552 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4553 const char *lbl1
, const char *lbl2
)
4557 attr
.dw_attr
= attr_kind
;
4558 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4559 attr
.dw_attr_val
.val_entry
= NULL
;
4560 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4561 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4562 add_dwarf_attr (die
, &attr
);
4565 /* Add a label identifier attribute value to a DIE. */
4568 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4573 attr
.dw_attr
= attr_kind
;
4574 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4575 attr
.dw_attr_val
.val_entry
= NULL
;
4576 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4577 if (dwarf_split_debug_info
)
4578 attr
.dw_attr_val
.val_entry
4579 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4581 add_dwarf_attr (die
, &attr
);
4584 /* Add a section offset attribute value to a DIE, an offset into the
4585 debug_line section. */
4588 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4593 attr
.dw_attr
= attr_kind
;
4594 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4595 attr
.dw_attr_val
.val_entry
= NULL
;
4596 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4597 add_dwarf_attr (die
, &attr
);
4600 /* Add a section offset attribute value to a DIE, an offset into the
4601 debug_macinfo section. */
4604 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4609 attr
.dw_attr
= attr_kind
;
4610 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4611 attr
.dw_attr_val
.val_entry
= NULL
;
4612 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4613 add_dwarf_attr (die
, &attr
);
4616 /* Add an offset attribute value to a DIE. */
4619 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4620 unsigned HOST_WIDE_INT offset
)
4624 attr
.dw_attr
= attr_kind
;
4625 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4626 attr
.dw_attr_val
.val_entry
= NULL
;
4627 attr
.dw_attr_val
.v
.val_offset
= offset
;
4628 add_dwarf_attr (die
, &attr
);
4631 /* Add a range_list attribute value to a DIE. When using
4632 dwarf_split_debug_info, address attributes in dies destined for the
4633 final executable should be direct references--setting the parameter
4634 force_direct ensures this behavior. */
4636 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4637 #define RELOCATED_OFFSET (NULL)
4640 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4641 long unsigned int offset
, bool force_direct
)
4645 attr
.dw_attr
= attr_kind
;
4646 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4647 /* For the range_list attribute, use val_entry to store whether the
4648 offset should follow split-debug-info or normal semantics. This
4649 value is read in output_range_list_offset. */
4650 if (dwarf_split_debug_info
&& !force_direct
)
4651 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4653 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4654 attr
.dw_attr_val
.v
.val_offset
= offset
;
4655 add_dwarf_attr (die
, &attr
);
4658 /* Return the start label of a delta attribute. */
4660 static inline const char *
4661 AT_vms_delta1 (dw_attr_node
*a
)
4663 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4664 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4667 /* Return the end label of a delta attribute. */
4669 static inline const char *
4670 AT_vms_delta2 (dw_attr_node
*a
)
4672 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4673 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4676 static inline const char *
4677 AT_lbl (dw_attr_node
*a
)
4679 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4680 || AT_class (a
) == dw_val_class_lineptr
4681 || AT_class (a
) == dw_val_class_macptr
4682 || AT_class (a
) == dw_val_class_high_pc
));
4683 return a
->dw_attr_val
.v
.val_lbl_id
;
4686 /* Get the attribute of type attr_kind. */
4688 static dw_attr_node
*
4689 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4693 dw_die_ref spec
= NULL
;
4698 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4699 if (a
->dw_attr
== attr_kind
)
4701 else if (a
->dw_attr
== DW_AT_specification
4702 || a
->dw_attr
== DW_AT_abstract_origin
)
4706 return get_AT (spec
, attr_kind
);
4711 /* Returns the parent of the declaration of DIE. */
4714 get_die_parent (dw_die_ref die
)
4721 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4722 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4725 return die
->die_parent
;
4728 /* Return the "low pc" attribute value, typically associated with a subprogram
4729 DIE. Return null if the "low pc" attribute is either not present, or if it
4730 cannot be represented as an assembler label identifier. */
4732 static inline const char *
4733 get_AT_low_pc (dw_die_ref die
)
4735 dw_attr_node
*a
= get_AT (die
, DW_AT_low_pc
);
4737 return a
? AT_lbl (a
) : NULL
;
4740 /* Return the "high pc" attribute value, typically associated with a subprogram
4741 DIE. Return null if the "high pc" attribute is either not present, or if it
4742 cannot be represented as an assembler label identifier. */
4744 static inline const char *
4745 get_AT_hi_pc (dw_die_ref die
)
4747 dw_attr_node
*a
= get_AT (die
, DW_AT_high_pc
);
4749 return a
? AT_lbl (a
) : NULL
;
4752 /* Return the value of the string attribute designated by ATTR_KIND, or
4753 NULL if it is not present. */
4755 static inline const char *
4756 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4758 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4760 return a
? AT_string (a
) : NULL
;
4763 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4764 if it is not present. */
4767 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4769 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4771 return a
? AT_flag (a
) : 0;
4774 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4775 if it is not present. */
4777 static inline unsigned
4778 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4780 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4782 return a
? AT_unsigned (a
) : 0;
4785 static inline dw_die_ref
4786 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4788 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4790 return a
? AT_ref (a
) : NULL
;
4793 static inline struct dwarf_file_data
*
4794 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4796 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4798 return a
? AT_file (a
) : NULL
;
4801 /* Return TRUE if the language is C++. */
4806 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4808 return (lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
4809 || lang
== DW_LANG_C_plus_plus_11
|| lang
== DW_LANG_C_plus_plus_14
);
4812 /* Return TRUE if the language is Java. */
4817 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4819 return lang
== DW_LANG_Java
;
4822 /* Return TRUE if the language is Fortran. */
4827 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4829 return (lang
== DW_LANG_Fortran77
4830 || lang
== DW_LANG_Fortran90
4831 || lang
== DW_LANG_Fortran95
4832 || lang
== DW_LANG_Fortran03
4833 || lang
== DW_LANG_Fortran08
);
4836 /* Return TRUE if the language is Ada. */
4841 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4843 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4846 /* Remove the specified attribute if present. Return TRUE if removal
4850 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4858 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4859 if (a
->dw_attr
== attr_kind
)
4861 if (AT_class (a
) == dw_val_class_str
)
4862 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4863 a
->dw_attr_val
.v
.val_str
->refcount
--;
4865 /* vec::ordered_remove should help reduce the number of abbrevs
4867 die
->die_attr
->ordered_remove (ix
);
4873 /* Remove CHILD from its parent. PREV must have the property that
4874 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4877 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4879 gcc_assert (child
->die_parent
== prev
->die_parent
);
4880 gcc_assert (prev
->die_sib
== child
);
4883 gcc_assert (child
->die_parent
->die_child
== child
);
4887 prev
->die_sib
= child
->die_sib
;
4888 if (child
->die_parent
->die_child
== child
)
4889 child
->die_parent
->die_child
= prev
;
4892 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4893 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4896 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4898 dw_die_ref parent
= old_child
->die_parent
;
4900 gcc_assert (parent
== prev
->die_parent
);
4901 gcc_assert (prev
->die_sib
== old_child
);
4903 new_child
->die_parent
= parent
;
4904 if (prev
== old_child
)
4906 gcc_assert (parent
->die_child
== old_child
);
4907 new_child
->die_sib
= new_child
;
4911 prev
->die_sib
= new_child
;
4912 new_child
->die_sib
= old_child
->die_sib
;
4914 if (old_child
->die_parent
->die_child
== old_child
)
4915 old_child
->die_parent
->die_child
= new_child
;
4918 /* Move all children from OLD_PARENT to NEW_PARENT. */
4921 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4924 new_parent
->die_child
= old_parent
->die_child
;
4925 old_parent
->die_child
= NULL
;
4926 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4929 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4933 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4939 dw_die_ref prev
= c
;
4941 while (c
->die_tag
== tag
)
4943 remove_child_with_prev (c
, prev
);
4944 c
->die_parent
= NULL
;
4945 /* Might have removed every child. */
4946 if (c
== c
->die_sib
)
4950 } while (c
!= die
->die_child
);
4953 /* Add a CHILD_DIE as the last child of DIE. */
4956 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4958 /* FIXME this should probably be an assert. */
4959 if (! die
|| ! child_die
)
4961 gcc_assert (die
!= child_die
);
4963 child_die
->die_parent
= die
;
4966 child_die
->die_sib
= die
->die_child
->die_sib
;
4967 die
->die_child
->die_sib
= child_die
;
4970 child_die
->die_sib
= child_die
;
4971 die
->die_child
= child_die
;
4974 /* Like add_child_die, but put CHILD_DIE after AFTER_DIE. */
4977 add_child_die_after (dw_die_ref die
, dw_die_ref child_die
,
4978 dw_die_ref after_die
)
4984 && die
!= child_die
);
4986 child_die
->die_parent
= die
;
4987 child_die
->die_sib
= after_die
->die_sib
;
4988 after_die
->die_sib
= child_die
;
4989 if (die
->die_child
== after_die
)
4990 die
->die_child
= child_die
;
4993 /* Unassociate CHILD from its parent, and make its parent be
4997 reparent_child (dw_die_ref child
, dw_die_ref new_parent
)
4999 for (dw_die_ref p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
5000 if (p
->die_sib
== child
)
5002 remove_child_with_prev (child
, p
);
5005 add_child_die (new_parent
, child
);
5008 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5009 is the specification, to the end of PARENT's list of children.
5010 This is done by removing and re-adding it. */
5013 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
5015 /* We want the declaration DIE from inside the class, not the
5016 specification DIE at toplevel. */
5017 if (child
->die_parent
!= parent
)
5019 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5025 gcc_assert (child
->die_parent
== parent
5026 || (child
->die_parent
5027 == get_AT_ref (parent
, DW_AT_specification
)));
5029 reparent_child (child
, parent
);
5032 /* Create and return a new die with a parent of PARENT_DIE. If
5033 PARENT_DIE is NULL, the new DIE is placed in limbo and an
5034 associated tree T must be supplied to determine parenthood
5037 static inline dw_die_ref
5038 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
5040 dw_die_ref die
= ggc_cleared_alloc
<die_node
> ();
5042 die
->die_tag
= tag_value
;
5044 if (parent_die
!= NULL
)
5045 add_child_die (parent_die
, die
);
5048 limbo_die_node
*limbo_node
;
5050 /* No DIEs created after early dwarf should end up in limbo,
5051 because the limbo list should not persist past LTO
5053 if (tag_value
!= DW_TAG_compile_unit
5054 /* These are allowed because they're generated while
5055 breaking out COMDAT units late. */
5056 && tag_value
!= DW_TAG_type_unit
5058 /* Allow nested functions to live in limbo because they will
5059 only temporarily live there, as decls_for_scope will fix
5061 && (TREE_CODE (t
) != FUNCTION_DECL
5062 || !decl_function_context (t
))
5063 /* Same as nested functions above but for types. Types that
5064 are local to a function will be fixed in
5066 && (!RECORD_OR_UNION_TYPE_P (t
)
5067 || !TYPE_CONTEXT (t
)
5068 || TREE_CODE (TYPE_CONTEXT (t
)) != FUNCTION_DECL
)
5069 /* FIXME debug-early: Allow late limbo DIE creation for LTO,
5070 especially in the ltrans stage, but once we implement LTO
5071 dwarf streaming, we should remove this exception. */
5074 fprintf (stderr
, "symbol ended up in limbo too late:");
5075 debug_generic_stmt (t
);
5079 limbo_node
= ggc_cleared_alloc
<limbo_die_node
> ();
5080 limbo_node
->die
= die
;
5081 limbo_node
->created_for
= t
;
5082 limbo_node
->next
= limbo_die_list
;
5083 limbo_die_list
= limbo_node
;
5089 /* Return the DIE associated with the given type specifier. */
5091 static inline dw_die_ref
5092 lookup_type_die (tree type
)
5094 return TYPE_SYMTAB_DIE (type
);
5097 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
5098 anonymous type named by the typedef TYPE_DIE, return the DIE of the
5099 anonymous type instead the one of the naming typedef. */
5101 static inline dw_die_ref
5102 strip_naming_typedef (tree type
, dw_die_ref type_die
)
5105 && TREE_CODE (type
) == RECORD_TYPE
5107 && type_die
->die_tag
== DW_TAG_typedef
5108 && is_naming_typedef_decl (TYPE_NAME (type
)))
5109 type_die
= get_AT_ref (type_die
, DW_AT_type
);
5113 /* Like lookup_type_die, but if type is an anonymous type named by a
5114 typedef[1], return the DIE of the anonymous type instead the one of
5115 the naming typedef. This is because in gen_typedef_die, we did
5116 equate the anonymous struct named by the typedef with the DIE of
5117 the naming typedef. So by default, lookup_type_die on an anonymous
5118 struct yields the DIE of the naming typedef.
5120 [1]: Read the comment of is_naming_typedef_decl to learn about what
5121 a naming typedef is. */
5123 static inline dw_die_ref
5124 lookup_type_die_strip_naming_typedef (tree type
)
5126 dw_die_ref die
= lookup_type_die (type
);
5127 return strip_naming_typedef (type
, die
);
5130 /* Equate a DIE to a given type specifier. */
5133 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5135 TYPE_SYMTAB_DIE (type
) = type_die
;
5138 /* Returns a hash value for X (which really is a die_struct). */
5141 decl_die_hasher::hash (die_node
*x
)
5143 return (hashval_t
) x
->decl_id
;
5146 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5149 decl_die_hasher::equal (die_node
*x
, tree y
)
5151 return (x
->decl_id
== DECL_UID (y
));
5154 /* Return the DIE associated with a given declaration. */
5156 static inline dw_die_ref
5157 lookup_decl_die (tree decl
)
5159 return decl_die_table
->find_with_hash (decl
, DECL_UID (decl
));
5162 /* Returns a hash value for X (which really is a var_loc_list). */
5165 decl_loc_hasher::hash (var_loc_list
*x
)
5167 return (hashval_t
) x
->decl_id
;
5170 /* Return nonzero if decl_id of var_loc_list X is the same as
5174 decl_loc_hasher::equal (var_loc_list
*x
, const_tree y
)
5176 return (x
->decl_id
== DECL_UID (y
));
5179 /* Return the var_loc list associated with a given declaration. */
5181 static inline var_loc_list
*
5182 lookup_decl_loc (const_tree decl
)
5184 if (!decl_loc_table
)
5186 return decl_loc_table
->find_with_hash (decl
, DECL_UID (decl
));
5189 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5192 dw_loc_list_hasher::hash (cached_dw_loc_list
*x
)
5194 return (hashval_t
) x
->decl_id
;
5197 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5201 dw_loc_list_hasher::equal (cached_dw_loc_list
*x
, const_tree y
)
5203 return (x
->decl_id
== DECL_UID (y
));
5206 /* Equate a DIE to a particular declaration. */
5209 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5211 unsigned int decl_id
= DECL_UID (decl
);
5213 *decl_die_table
->find_slot_with_hash (decl
, decl_id
, INSERT
) = decl_die
;
5214 decl_die
->decl_id
= decl_id
;
5217 /* Return how many bits covers PIECE EXPR_LIST. */
5219 static HOST_WIDE_INT
5220 decl_piece_bitsize (rtx piece
)
5222 int ret
= (int) GET_MODE (piece
);
5225 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
5226 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
5227 return INTVAL (XEXP (XEXP (piece
, 0), 0));
5230 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5233 decl_piece_varloc_ptr (rtx piece
)
5235 if ((int) GET_MODE (piece
))
5236 return &XEXP (piece
, 0);
5238 return &XEXP (XEXP (piece
, 0), 1);
5241 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5242 Next is the chain of following piece nodes. */
5244 static rtx_expr_list
*
5245 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
5247 if (bitsize
> 0 && bitsize
<= (int) MAX_MACHINE_MODE
)
5248 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
5250 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
5255 /* Return rtx that should be stored into loc field for
5256 LOC_NOTE and BITPOS/BITSIZE. */
5259 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
5260 HOST_WIDE_INT bitsize
)
5264 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
5266 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
5271 /* This function either modifies location piece list *DEST in
5272 place (if SRC and INNER is NULL), or copies location piece list
5273 *SRC to *DEST while modifying it. Location BITPOS is modified
5274 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5275 not copied and if needed some padding around it is added.
5276 When modifying in place, DEST should point to EXPR_LIST where
5277 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5278 to the start of the whole list and INNER points to the EXPR_LIST
5279 where earlier pieces cover PIECE_BITPOS bits. */
5282 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
5283 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
5284 HOST_WIDE_INT bitsize
, rtx loc_note
)
5287 bool copy
= inner
!= NULL
;
5291 /* First copy all nodes preceding the current bitpos. */
5292 while (src
!= inner
)
5294 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5295 decl_piece_bitsize (*src
), NULL_RTX
);
5296 dest
= &XEXP (*dest
, 1);
5297 src
= &XEXP (*src
, 1);
5300 /* Add padding if needed. */
5301 if (bitpos
!= piece_bitpos
)
5303 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5304 copy
? NULL_RTX
: *dest
);
5305 dest
= &XEXP (*dest
, 1);
5307 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5310 /* A piece with correct bitpos and bitsize already exist,
5311 just update the location for it and return. */
5312 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5315 /* Add the piece that changed. */
5316 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5317 dest
= &XEXP (*dest
, 1);
5318 /* Skip over pieces that overlap it. */
5319 diff
= bitpos
- piece_bitpos
+ bitsize
;
5322 while (diff
> 0 && *src
)
5325 diff
-= decl_piece_bitsize (piece
);
5327 src
= &XEXP (piece
, 1);
5330 *src
= XEXP (piece
, 1);
5331 free_EXPR_LIST_node (piece
);
5334 /* Add padding if needed. */
5335 if (diff
< 0 && *src
)
5339 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5340 dest
= &XEXP (*dest
, 1);
5344 /* Finally copy all nodes following it. */
5347 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5348 decl_piece_bitsize (*src
), NULL_RTX
);
5349 dest
= &XEXP (*dest
, 1);
5350 src
= &XEXP (*src
, 1);
5354 /* Add a variable location node to the linked list for DECL. */
5356 static struct var_loc_node
*
5357 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5359 unsigned int decl_id
;
5361 struct var_loc_node
*loc
= NULL
;
5362 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5364 if (TREE_CODE (decl
) == VAR_DECL
5365 && DECL_HAS_DEBUG_EXPR_P (decl
))
5367 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5368 if (handled_component_p (realdecl
)
5369 || (TREE_CODE (realdecl
) == MEM_REF
5370 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5372 HOST_WIDE_INT maxsize
;
5375 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
,
5377 if (!DECL_P (innerdecl
)
5378 || DECL_IGNORED_P (innerdecl
)
5379 || TREE_STATIC (innerdecl
)
5381 || bitpos
+ bitsize
> 256
5382 || bitsize
!= maxsize
)
5388 decl_id
= DECL_UID (decl
);
5390 = decl_loc_table
->find_slot_with_hash (decl
, decl_id
, INSERT
);
5393 temp
= ggc_cleared_alloc
<var_loc_list
> ();
5394 temp
->decl_id
= decl_id
;
5400 /* For PARM_DECLs try to keep around the original incoming value,
5401 even if that means we'll emit a zero-range .debug_loc entry. */
5403 && temp
->first
== temp
->last
5404 && TREE_CODE (decl
) == PARM_DECL
5405 && NOTE_P (temp
->first
->loc
)
5406 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5407 && DECL_INCOMING_RTL (decl
)
5408 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5409 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5410 == GET_CODE (DECL_INCOMING_RTL (decl
))
5411 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5413 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5414 NOTE_VAR_LOCATION_LOC (loc_note
))
5415 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5416 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5418 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5419 temp
->first
->next
= loc
;
5421 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5423 else if (temp
->last
)
5425 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5426 rtx
*piece_loc
= NULL
, last_loc_note
;
5427 HOST_WIDE_INT piece_bitpos
= 0;
5431 gcc_assert (last
->next
== NULL
);
5433 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5435 piece_loc
= &last
->loc
;
5438 HOST_WIDE_INT cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5439 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5441 piece_bitpos
+= cur_bitsize
;
5442 piece_loc
= &XEXP (*piece_loc
, 1);
5446 /* TEMP->LAST here is either pointer to the last but one or
5447 last element in the chained list, LAST is pointer to the
5449 if (label
&& strcmp (last
->label
, label
) == 0)
5451 /* For SRA optimized variables if there weren't any real
5452 insns since last note, just modify the last node. */
5453 if (piece_loc
!= NULL
)
5455 adjust_piece_list (piece_loc
, NULL
, NULL
,
5456 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5459 /* If the last note doesn't cover any instructions, remove it. */
5460 if (temp
->last
!= last
)
5462 temp
->last
->next
= NULL
;
5465 gcc_assert (strcmp (last
->label
, label
) != 0);
5469 gcc_assert (temp
->first
== temp
->last
5470 || (temp
->first
->next
== temp
->last
5471 && TREE_CODE (decl
) == PARM_DECL
));
5472 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5473 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5477 if (bitsize
== -1 && NOTE_P (last
->loc
))
5478 last_loc_note
= last
->loc
;
5479 else if (piece_loc
!= NULL
5480 && *piece_loc
!= NULL_RTX
5481 && piece_bitpos
== bitpos
5482 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5483 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5485 last_loc_note
= NULL_RTX
;
5486 /* If the current location is the same as the end of the list,
5487 and either both or neither of the locations is uninitialized,
5488 we have nothing to do. */
5489 if (last_loc_note
== NULL_RTX
5490 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5491 NOTE_VAR_LOCATION_LOC (loc_note
)))
5492 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5493 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5494 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5495 == VAR_INIT_STATUS_UNINITIALIZED
)
5496 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5497 == VAR_INIT_STATUS_UNINITIALIZED
))))
5499 /* Add LOC to the end of list and update LAST. If the last
5500 element of the list has been removed above, reuse its
5501 memory for the new node, otherwise allocate a new one. */
5505 memset (loc
, '\0', sizeof (*loc
));
5508 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5509 if (bitsize
== -1 || piece_loc
== NULL
)
5510 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5512 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5513 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5515 /* Ensure TEMP->LAST will point either to the new last but one
5516 element of the chain, or to the last element in it. */
5517 if (last
!= temp
->last
)
5525 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5528 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5533 /* Keep track of the number of spaces used to indent the
5534 output of the debugging routines that print the structure of
5535 the DIE internal representation. */
5536 static int print_indent
;
5538 /* Indent the line the number of spaces given by print_indent. */
5541 print_spaces (FILE *outfile
)
5543 fprintf (outfile
, "%*s", print_indent
, "");
5546 /* Print a type signature in hex. */
5549 print_signature (FILE *outfile
, char *sig
)
5553 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5554 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5558 print_discr_value (FILE *outfile
, dw_discr_value
*discr_value
)
5560 if (discr_value
->pos
)
5561 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, discr_value
->v
.sval
);
5563 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, discr_value
->v
.uval
);
5566 static void print_loc_descr (dw_loc_descr_ref
, FILE *);
5568 /* Print the value associated to the VAL DWARF value node to OUTFILE. If
5569 RECURSE, output location descriptor operations. */
5572 print_dw_val (dw_val_node
*val
, bool recurse
, FILE *outfile
)
5574 switch (val
->val_class
)
5576 case dw_val_class_addr
:
5577 fprintf (outfile
, "address");
5579 case dw_val_class_offset
:
5580 fprintf (outfile
, "offset");
5582 case dw_val_class_loc
:
5583 fprintf (outfile
, "location descriptor");
5584 if (val
->v
.val_loc
== NULL
)
5585 fprintf (outfile
, " -> <null>\n");
5588 fprintf (outfile
, ":\n");
5590 print_loc_descr (val
->v
.val_loc
, outfile
);
5594 fprintf (outfile
, " (%p)\n", (void *) val
->v
.val_loc
);
5596 case dw_val_class_loc_list
:
5597 fprintf (outfile
, "location list -> label:%s",
5598 val
->v
.val_loc_list
->ll_symbol
);
5600 case dw_val_class_range_list
:
5601 fprintf (outfile
, "range list");
5603 case dw_val_class_const
:
5604 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, val
->v
.val_int
);
5606 case dw_val_class_unsigned_const
:
5607 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, val
->v
.val_unsigned
);
5609 case dw_val_class_const_double
:
5610 fprintf (outfile
, "constant (" HOST_WIDE_INT_PRINT_DEC
","\
5611 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5612 val
->v
.val_double
.high
,
5613 val
->v
.val_double
.low
);
5615 case dw_val_class_wide_int
:
5617 int i
= val
->v
.val_wide
->get_len ();
5618 fprintf (outfile
, "constant (");
5620 if (val
->v
.val_wide
->elt (i
- 1) == 0)
5621 fprintf (outfile
, "0x");
5622 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
,
5623 val
->v
.val_wide
->elt (--i
));
5625 fprintf (outfile
, HOST_WIDE_INT_PRINT_PADDED_HEX
,
5626 val
->v
.val_wide
->elt (i
));
5627 fprintf (outfile
, ")");
5630 case dw_val_class_vec
:
5631 fprintf (outfile
, "floating-point or vector constant");
5633 case dw_val_class_flag
:
5634 fprintf (outfile
, "%u", val
->v
.val_flag
);
5636 case dw_val_class_die_ref
:
5637 if (val
->v
.val_die_ref
.die
!= NULL
)
5639 dw_die_ref die
= val
->v
.val_die_ref
.die
;
5641 if (die
->comdat_type_p
)
5643 fprintf (outfile
, "die -> signature: ");
5644 print_signature (outfile
,
5645 die
->die_id
.die_type_node
->signature
);
5647 else if (die
->die_id
.die_symbol
)
5648 fprintf (outfile
, "die -> label: %s", die
->die_id
.die_symbol
);
5650 fprintf (outfile
, "die -> %ld", die
->die_offset
);
5651 fprintf (outfile
, " (%p)", (void *) die
);
5654 fprintf (outfile
, "die -> <null>");
5656 case dw_val_class_vms_delta
:
5657 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5658 val
->v
.val_vms_delta
.lbl2
, val
->v
.val_vms_delta
.lbl1
);
5660 case dw_val_class_lbl_id
:
5661 case dw_val_class_lineptr
:
5662 case dw_val_class_macptr
:
5663 case dw_val_class_high_pc
:
5664 fprintf (outfile
, "label: %s", val
->v
.val_lbl_id
);
5666 case dw_val_class_str
:
5667 if (val
->v
.val_str
->str
!= NULL
)
5668 fprintf (outfile
, "\"%s\"", val
->v
.val_str
->str
);
5670 fprintf (outfile
, "<null>");
5672 case dw_val_class_file
:
5673 fprintf (outfile
, "\"%s\" (%d)", val
->v
.val_file
->filename
,
5674 val
->v
.val_file
->emitted_number
);
5676 case dw_val_class_data8
:
5680 for (i
= 0; i
< 8; i
++)
5681 fprintf (outfile
, "%02x", val
->v
.val_data8
[i
]);
5684 case dw_val_class_discr_value
:
5685 print_discr_value (outfile
, &val
->v
.val_discr_value
);
5687 case dw_val_class_discr_list
:
5688 for (dw_discr_list_ref node
= val
->v
.val_discr_list
;
5690 node
= node
->dw_discr_next
)
5692 if (node
->dw_discr_range
)
5694 fprintf (outfile
, " .. ");
5695 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
5696 print_discr_value (outfile
, &node
->dw_discr_upper_bound
);
5699 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
5701 if (node
->dw_discr_next
!= NULL
)
5702 fprintf (outfile
, " | ");
5709 /* Likewise, for a DIE attribute. */
5712 print_attribute (dw_attr_node
*a
, bool recurse
, FILE *outfile
)
5714 print_dw_val (&a
->dw_attr_val
, recurse
, outfile
);
5718 /* Print the list of operands in the LOC location description to OUTFILE. This
5719 routine is a debugging aid only. */
5722 print_loc_descr (dw_loc_descr_ref loc
, FILE *outfile
)
5724 dw_loc_descr_ref l
= loc
;
5728 print_spaces (outfile
);
5729 fprintf (outfile
, "<null>\n");
5733 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
5735 print_spaces (outfile
);
5736 fprintf (outfile
, "(%p) %s",
5738 dwarf_stack_op_name (l
->dw_loc_opc
));
5739 if (l
->dw_loc_oprnd1
.val_class
!= dw_val_class_none
)
5741 fprintf (outfile
, " ");
5742 print_dw_val (&l
->dw_loc_oprnd1
, false, outfile
);
5744 if (l
->dw_loc_oprnd2
.val_class
!= dw_val_class_none
)
5746 fprintf (outfile
, ", ");
5747 print_dw_val (&l
->dw_loc_oprnd2
, false, outfile
);
5749 fprintf (outfile
, "\n");
5753 /* Print the information associated with a given DIE, and its children.
5754 This routine is a debugging aid only. */
5757 print_die (dw_die_ref die
, FILE *outfile
)
5763 print_spaces (outfile
);
5764 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5765 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5767 print_spaces (outfile
);
5768 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5769 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5770 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5772 if (die
->comdat_type_p
)
5774 print_spaces (outfile
);
5775 fprintf (outfile
, " signature: ");
5776 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5777 fprintf (outfile
, "\n");
5780 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5782 print_spaces (outfile
);
5783 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5785 print_attribute (a
, true, outfile
);
5786 fprintf (outfile
, "\n");
5789 if (die
->die_child
!= NULL
)
5792 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5795 if (print_indent
== 0)
5796 fprintf (outfile
, "\n");
5799 /* Print the list of operations in the LOC location description. */
5802 debug_dwarf_loc_descr (dw_loc_descr_ref loc
)
5804 print_loc_descr (loc
, stderr
);
5807 /* Print the information collected for a given DIE. */
5810 debug_dwarf_die (dw_die_ref die
)
5812 print_die (die
, stderr
);
5816 debug (die_struct
&ref
)
5818 print_die (&ref
, stderr
);
5822 debug (die_struct
*ptr
)
5827 fprintf (stderr
, "<nil>\n");
5831 /* Print all DWARF information collected for the compilation unit.
5832 This routine is a debugging aid only. */
5838 print_die (comp_unit_die (), stderr
);
5841 /* Sanity checks on DIEs. */
5844 check_die (dw_die_ref die
)
5848 bool inline_found
= false;
5849 int n_location
= 0, n_low_pc
= 0, n_high_pc
= 0, n_artificial
= 0;
5850 int n_decl_line
= 0, n_decl_file
= 0;
5851 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5856 if (a
->dw_attr_val
.v
.val_unsigned
)
5857 inline_found
= true;
5859 case DW_AT_location
:
5868 case DW_AT_artificial
:
5871 case DW_AT_decl_line
:
5874 case DW_AT_decl_file
:
5881 if (n_location
> 1 || n_low_pc
> 1 || n_high_pc
> 1 || n_artificial
> 1
5882 || n_decl_line
> 1 || n_decl_file
> 1)
5884 fprintf (stderr
, "Duplicate attributes in DIE:\n");
5885 debug_dwarf_die (die
);
5890 /* A debugging information entry that is a member of an abstract
5891 instance tree [that has DW_AT_inline] should not contain any
5892 attributes which describe aspects of the subroutine which vary
5893 between distinct inlined expansions or distinct out-of-line
5895 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5896 gcc_assert (a
->dw_attr
!= DW_AT_low_pc
5897 && a
->dw_attr
!= DW_AT_high_pc
5898 && a
->dw_attr
!= DW_AT_location
5899 && a
->dw_attr
!= DW_AT_frame_base
5900 && a
->dw_attr
!= DW_AT_GNU_all_call_sites
);
5904 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5905 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5906 DIE that marks the start of the DIEs for this include file. */
5909 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5911 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5912 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5914 new_unit
->die_sib
= old_unit
;
5918 /* Close an include-file CU and reopen the enclosing one. */
5921 pop_compile_unit (dw_die_ref old_unit
)
5923 dw_die_ref new_unit
= old_unit
->die_sib
;
5925 old_unit
->die_sib
= NULL
;
5929 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5930 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5931 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5933 /* Calculate the checksum of a location expression. */
5936 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5939 inchash::hash hstate
;
5942 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5944 hash_loc_operands (loc
, hstate
);
5945 hash
= hstate
.end();
5949 /* Calculate the checksum of an attribute. */
5952 attr_checksum (dw_attr_node
*at
, struct md5_ctx
*ctx
, int *mark
)
5954 dw_loc_descr_ref loc
;
5957 CHECKSUM (at
->dw_attr
);
5959 /* We don't care that this was compiled with a different compiler
5960 snapshot; if the output is the same, that's what matters. */
5961 if (at
->dw_attr
== DW_AT_producer
)
5964 switch (AT_class (at
))
5966 case dw_val_class_const
:
5967 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5969 case dw_val_class_unsigned_const
:
5970 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5972 case dw_val_class_const_double
:
5973 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5975 case dw_val_class_wide_int
:
5976 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
5977 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
5978 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
5980 case dw_val_class_vec
:
5981 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5982 (at
->dw_attr_val
.v
.val_vec
.length
5983 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5985 case dw_val_class_flag
:
5986 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5988 case dw_val_class_str
:
5989 CHECKSUM_STRING (AT_string (at
));
5992 case dw_val_class_addr
:
5994 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5995 CHECKSUM_STRING (XSTR (r
, 0));
5998 case dw_val_class_offset
:
5999 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
6002 case dw_val_class_loc
:
6003 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6004 loc_checksum (loc
, ctx
);
6007 case dw_val_class_die_ref
:
6008 die_checksum (AT_ref (at
), ctx
, mark
);
6011 case dw_val_class_fde_ref
:
6012 case dw_val_class_vms_delta
:
6013 case dw_val_class_lbl_id
:
6014 case dw_val_class_lineptr
:
6015 case dw_val_class_macptr
:
6016 case dw_val_class_high_pc
:
6019 case dw_val_class_file
:
6020 CHECKSUM_STRING (AT_file (at
)->filename
);
6023 case dw_val_class_data8
:
6024 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6032 /* Calculate the checksum of a DIE. */
6035 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6041 /* To avoid infinite recursion. */
6044 CHECKSUM (die
->die_mark
);
6047 die
->die_mark
= ++(*mark
);
6049 CHECKSUM (die
->die_tag
);
6051 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6052 attr_checksum (a
, ctx
, mark
);
6054 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
6058 #undef CHECKSUM_BLOCK
6059 #undef CHECKSUM_STRING
6061 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
6062 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6063 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
6064 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
6065 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
6066 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
6067 #define CHECKSUM_ATTR(FOO) \
6068 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
6070 /* Calculate the checksum of a number in signed LEB128 format. */
6073 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
6080 byte
= (value
& 0x7f);
6082 more
= !((value
== 0 && (byte
& 0x40) == 0)
6083 || (value
== -1 && (byte
& 0x40) != 0));
6092 /* Calculate the checksum of a number in unsigned LEB128 format. */
6095 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
6099 unsigned char byte
= (value
& 0x7f);
6102 /* More bytes to follow. */
6110 /* Checksum the context of the DIE. This adds the names of any
6111 surrounding namespaces or structures to the checksum. */
6114 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
6118 int tag
= die
->die_tag
;
6120 if (tag
!= DW_TAG_namespace
6121 && tag
!= DW_TAG_structure_type
6122 && tag
!= DW_TAG_class_type
)
6125 name
= get_AT_string (die
, DW_AT_name
);
6127 spec
= get_AT_ref (die
, DW_AT_specification
);
6131 if (die
->die_parent
!= NULL
)
6132 checksum_die_context (die
->die_parent
, ctx
);
6134 CHECKSUM_ULEB128 ('C');
6135 CHECKSUM_ULEB128 (tag
);
6137 CHECKSUM_STRING (name
);
6140 /* Calculate the checksum of a location expression. */
6143 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
6145 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
6146 were emitted as a DW_FORM_sdata instead of a location expression. */
6147 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
6149 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6150 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
6154 /* Otherwise, just checksum the raw location expression. */
6157 inchash::hash hstate
;
6160 CHECKSUM_ULEB128 (loc
->dtprel
);
6161 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
6162 hash_loc_operands (loc
, hstate
);
6163 hash
= hstate
.end ();
6165 loc
= loc
->dw_loc_next
;
6169 /* Calculate the checksum of an attribute. */
6172 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_node
*at
,
6173 struct md5_ctx
*ctx
, int *mark
)
6175 dw_loc_descr_ref loc
;
6178 if (AT_class (at
) == dw_val_class_die_ref
)
6180 dw_die_ref target_die
= AT_ref (at
);
6182 /* For pointer and reference types, we checksum only the (qualified)
6183 name of the target type (if there is a name). For friend entries,
6184 we checksum only the (qualified) name of the target type or function.
6185 This allows the checksum to remain the same whether the target type
6186 is complete or not. */
6187 if ((at
->dw_attr
== DW_AT_type
6188 && (tag
== DW_TAG_pointer_type
6189 || tag
== DW_TAG_reference_type
6190 || tag
== DW_TAG_rvalue_reference_type
6191 || tag
== DW_TAG_ptr_to_member_type
))
6192 || (at
->dw_attr
== DW_AT_friend
6193 && tag
== DW_TAG_friend
))
6195 dw_attr_node
*name_attr
= get_AT (target_die
, DW_AT_name
);
6197 if (name_attr
!= NULL
)
6199 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6203 CHECKSUM_ULEB128 ('N');
6204 CHECKSUM_ULEB128 (at
->dw_attr
);
6205 if (decl
->die_parent
!= NULL
)
6206 checksum_die_context (decl
->die_parent
, ctx
);
6207 CHECKSUM_ULEB128 ('E');
6208 CHECKSUM_STRING (AT_string (name_attr
));
6213 /* For all other references to another DIE, we check to see if the
6214 target DIE has already been visited. If it has, we emit a
6215 backward reference; if not, we descend recursively. */
6216 if (target_die
->die_mark
> 0)
6218 CHECKSUM_ULEB128 ('R');
6219 CHECKSUM_ULEB128 (at
->dw_attr
);
6220 CHECKSUM_ULEB128 (target_die
->die_mark
);
6224 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6228 target_die
->die_mark
= ++(*mark
);
6229 CHECKSUM_ULEB128 ('T');
6230 CHECKSUM_ULEB128 (at
->dw_attr
);
6231 if (decl
->die_parent
!= NULL
)
6232 checksum_die_context (decl
->die_parent
, ctx
);
6233 die_checksum_ordered (target_die
, ctx
, mark
);
6238 CHECKSUM_ULEB128 ('A');
6239 CHECKSUM_ULEB128 (at
->dw_attr
);
6241 switch (AT_class (at
))
6243 case dw_val_class_const
:
6244 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6245 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
6248 case dw_val_class_unsigned_const
:
6249 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6250 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
6253 case dw_val_class_const_double
:
6254 CHECKSUM_ULEB128 (DW_FORM_block
);
6255 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
6256 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
6259 case dw_val_class_wide_int
:
6260 CHECKSUM_ULEB128 (DW_FORM_block
);
6261 CHECKSUM_ULEB128 (get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6262 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
6263 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
6264 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6265 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
6268 case dw_val_class_vec
:
6269 CHECKSUM_ULEB128 (DW_FORM_block
);
6270 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
6271 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
6272 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
6273 (at
->dw_attr_val
.v
.val_vec
.length
6274 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
6277 case dw_val_class_flag
:
6278 CHECKSUM_ULEB128 (DW_FORM_flag
);
6279 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
6282 case dw_val_class_str
:
6283 CHECKSUM_ULEB128 (DW_FORM_string
);
6284 CHECKSUM_STRING (AT_string (at
));
6287 case dw_val_class_addr
:
6289 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6290 CHECKSUM_ULEB128 (DW_FORM_string
);
6291 CHECKSUM_STRING (XSTR (r
, 0));
6294 case dw_val_class_offset
:
6295 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6296 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
6299 case dw_val_class_loc
:
6300 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6301 loc_checksum_ordered (loc
, ctx
);
6304 case dw_val_class_fde_ref
:
6305 case dw_val_class_lbl_id
:
6306 case dw_val_class_lineptr
:
6307 case dw_val_class_macptr
:
6308 case dw_val_class_high_pc
:
6311 case dw_val_class_file
:
6312 CHECKSUM_ULEB128 (DW_FORM_string
);
6313 CHECKSUM_STRING (AT_file (at
)->filename
);
6316 case dw_val_class_data8
:
6317 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6325 struct checksum_attributes
6327 dw_attr_node
*at_name
;
6328 dw_attr_node
*at_type
;
6329 dw_attr_node
*at_friend
;
6330 dw_attr_node
*at_accessibility
;
6331 dw_attr_node
*at_address_class
;
6332 dw_attr_node
*at_allocated
;
6333 dw_attr_node
*at_artificial
;
6334 dw_attr_node
*at_associated
;
6335 dw_attr_node
*at_binary_scale
;
6336 dw_attr_node
*at_bit_offset
;
6337 dw_attr_node
*at_bit_size
;
6338 dw_attr_node
*at_bit_stride
;
6339 dw_attr_node
*at_byte_size
;
6340 dw_attr_node
*at_byte_stride
;
6341 dw_attr_node
*at_const_value
;
6342 dw_attr_node
*at_containing_type
;
6343 dw_attr_node
*at_count
;
6344 dw_attr_node
*at_data_location
;
6345 dw_attr_node
*at_data_member_location
;
6346 dw_attr_node
*at_decimal_scale
;
6347 dw_attr_node
*at_decimal_sign
;
6348 dw_attr_node
*at_default_value
;
6349 dw_attr_node
*at_digit_count
;
6350 dw_attr_node
*at_discr
;
6351 dw_attr_node
*at_discr_list
;
6352 dw_attr_node
*at_discr_value
;
6353 dw_attr_node
*at_encoding
;
6354 dw_attr_node
*at_endianity
;
6355 dw_attr_node
*at_explicit
;
6356 dw_attr_node
*at_is_optional
;
6357 dw_attr_node
*at_location
;
6358 dw_attr_node
*at_lower_bound
;
6359 dw_attr_node
*at_mutable
;
6360 dw_attr_node
*at_ordering
;
6361 dw_attr_node
*at_picture_string
;
6362 dw_attr_node
*at_prototyped
;
6363 dw_attr_node
*at_small
;
6364 dw_attr_node
*at_segment
;
6365 dw_attr_node
*at_string_length
;
6366 dw_attr_node
*at_string_length_bit_size
;
6367 dw_attr_node
*at_string_length_byte_size
;
6368 dw_attr_node
*at_threads_scaled
;
6369 dw_attr_node
*at_upper_bound
;
6370 dw_attr_node
*at_use_location
;
6371 dw_attr_node
*at_use_UTF8
;
6372 dw_attr_node
*at_variable_parameter
;
6373 dw_attr_node
*at_virtuality
;
6374 dw_attr_node
*at_visibility
;
6375 dw_attr_node
*at_vtable_elem_location
;
6378 /* Collect the attributes that we will want to use for the checksum. */
6381 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
6386 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6397 attrs
->at_friend
= a
;
6399 case DW_AT_accessibility
:
6400 attrs
->at_accessibility
= a
;
6402 case DW_AT_address_class
:
6403 attrs
->at_address_class
= a
;
6405 case DW_AT_allocated
:
6406 attrs
->at_allocated
= a
;
6408 case DW_AT_artificial
:
6409 attrs
->at_artificial
= a
;
6411 case DW_AT_associated
:
6412 attrs
->at_associated
= a
;
6414 case DW_AT_binary_scale
:
6415 attrs
->at_binary_scale
= a
;
6417 case DW_AT_bit_offset
:
6418 attrs
->at_bit_offset
= a
;
6420 case DW_AT_bit_size
:
6421 attrs
->at_bit_size
= a
;
6423 case DW_AT_bit_stride
:
6424 attrs
->at_bit_stride
= a
;
6426 case DW_AT_byte_size
:
6427 attrs
->at_byte_size
= a
;
6429 case DW_AT_byte_stride
:
6430 attrs
->at_byte_stride
= a
;
6432 case DW_AT_const_value
:
6433 attrs
->at_const_value
= a
;
6435 case DW_AT_containing_type
:
6436 attrs
->at_containing_type
= a
;
6439 attrs
->at_count
= a
;
6441 case DW_AT_data_location
:
6442 attrs
->at_data_location
= a
;
6444 case DW_AT_data_member_location
:
6445 attrs
->at_data_member_location
= a
;
6447 case DW_AT_decimal_scale
:
6448 attrs
->at_decimal_scale
= a
;
6450 case DW_AT_decimal_sign
:
6451 attrs
->at_decimal_sign
= a
;
6453 case DW_AT_default_value
:
6454 attrs
->at_default_value
= a
;
6456 case DW_AT_digit_count
:
6457 attrs
->at_digit_count
= a
;
6460 attrs
->at_discr
= a
;
6462 case DW_AT_discr_list
:
6463 attrs
->at_discr_list
= a
;
6465 case DW_AT_discr_value
:
6466 attrs
->at_discr_value
= a
;
6468 case DW_AT_encoding
:
6469 attrs
->at_encoding
= a
;
6471 case DW_AT_endianity
:
6472 attrs
->at_endianity
= a
;
6474 case DW_AT_explicit
:
6475 attrs
->at_explicit
= a
;
6477 case DW_AT_is_optional
:
6478 attrs
->at_is_optional
= a
;
6480 case DW_AT_location
:
6481 attrs
->at_location
= a
;
6483 case DW_AT_lower_bound
:
6484 attrs
->at_lower_bound
= a
;
6487 attrs
->at_mutable
= a
;
6489 case DW_AT_ordering
:
6490 attrs
->at_ordering
= a
;
6492 case DW_AT_picture_string
:
6493 attrs
->at_picture_string
= a
;
6495 case DW_AT_prototyped
:
6496 attrs
->at_prototyped
= a
;
6499 attrs
->at_small
= a
;
6502 attrs
->at_segment
= a
;
6504 case DW_AT_string_length
:
6505 attrs
->at_string_length
= a
;
6507 case DW_AT_string_length_bit_size
:
6508 attrs
->at_string_length_bit_size
= a
;
6510 case DW_AT_string_length_byte_size
:
6511 attrs
->at_string_length_byte_size
= a
;
6513 case DW_AT_threads_scaled
:
6514 attrs
->at_threads_scaled
= a
;
6516 case DW_AT_upper_bound
:
6517 attrs
->at_upper_bound
= a
;
6519 case DW_AT_use_location
:
6520 attrs
->at_use_location
= a
;
6522 case DW_AT_use_UTF8
:
6523 attrs
->at_use_UTF8
= a
;
6525 case DW_AT_variable_parameter
:
6526 attrs
->at_variable_parameter
= a
;
6528 case DW_AT_virtuality
:
6529 attrs
->at_virtuality
= a
;
6531 case DW_AT_visibility
:
6532 attrs
->at_visibility
= a
;
6534 case DW_AT_vtable_elem_location
:
6535 attrs
->at_vtable_elem_location
= a
;
6543 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6546 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6550 struct checksum_attributes attrs
;
6552 CHECKSUM_ULEB128 ('D');
6553 CHECKSUM_ULEB128 (die
->die_tag
);
6555 memset (&attrs
, 0, sizeof (attrs
));
6557 decl
= get_AT_ref (die
, DW_AT_specification
);
6559 collect_checksum_attributes (&attrs
, decl
);
6560 collect_checksum_attributes (&attrs
, die
);
6562 CHECKSUM_ATTR (attrs
.at_name
);
6563 CHECKSUM_ATTR (attrs
.at_accessibility
);
6564 CHECKSUM_ATTR (attrs
.at_address_class
);
6565 CHECKSUM_ATTR (attrs
.at_allocated
);
6566 CHECKSUM_ATTR (attrs
.at_artificial
);
6567 CHECKSUM_ATTR (attrs
.at_associated
);
6568 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6569 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6570 CHECKSUM_ATTR (attrs
.at_bit_size
);
6571 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6572 CHECKSUM_ATTR (attrs
.at_byte_size
);
6573 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6574 CHECKSUM_ATTR (attrs
.at_const_value
);
6575 CHECKSUM_ATTR (attrs
.at_containing_type
);
6576 CHECKSUM_ATTR (attrs
.at_count
);
6577 CHECKSUM_ATTR (attrs
.at_data_location
);
6578 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6579 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6580 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6581 CHECKSUM_ATTR (attrs
.at_default_value
);
6582 CHECKSUM_ATTR (attrs
.at_digit_count
);
6583 CHECKSUM_ATTR (attrs
.at_discr
);
6584 CHECKSUM_ATTR (attrs
.at_discr_list
);
6585 CHECKSUM_ATTR (attrs
.at_discr_value
);
6586 CHECKSUM_ATTR (attrs
.at_encoding
);
6587 CHECKSUM_ATTR (attrs
.at_endianity
);
6588 CHECKSUM_ATTR (attrs
.at_explicit
);
6589 CHECKSUM_ATTR (attrs
.at_is_optional
);
6590 CHECKSUM_ATTR (attrs
.at_location
);
6591 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6592 CHECKSUM_ATTR (attrs
.at_mutable
);
6593 CHECKSUM_ATTR (attrs
.at_ordering
);
6594 CHECKSUM_ATTR (attrs
.at_picture_string
);
6595 CHECKSUM_ATTR (attrs
.at_prototyped
);
6596 CHECKSUM_ATTR (attrs
.at_small
);
6597 CHECKSUM_ATTR (attrs
.at_segment
);
6598 CHECKSUM_ATTR (attrs
.at_string_length
);
6599 CHECKSUM_ATTR (attrs
.at_string_length_bit_size
);
6600 CHECKSUM_ATTR (attrs
.at_string_length_byte_size
);
6601 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6602 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6603 CHECKSUM_ATTR (attrs
.at_use_location
);
6604 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6605 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6606 CHECKSUM_ATTR (attrs
.at_virtuality
);
6607 CHECKSUM_ATTR (attrs
.at_visibility
);
6608 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6609 CHECKSUM_ATTR (attrs
.at_type
);
6610 CHECKSUM_ATTR (attrs
.at_friend
);
6612 /* Checksum the child DIEs. */
6615 dw_attr_node
*name_attr
;
6618 name_attr
= get_AT (c
, DW_AT_name
);
6619 if (is_template_instantiation (c
))
6621 /* Ignore instantiations of member type and function templates. */
6623 else if (name_attr
!= NULL
6624 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
6626 /* Use a shallow checksum for named nested types and member
6628 CHECKSUM_ULEB128 ('S');
6629 CHECKSUM_ULEB128 (c
->die_tag
);
6630 CHECKSUM_STRING (AT_string (name_attr
));
6634 /* Use a deep checksum for other children. */
6635 /* Mark this DIE so it gets processed when unmarking. */
6636 if (c
->die_mark
== 0)
6638 die_checksum_ordered (c
, ctx
, mark
);
6640 } while (c
!= die
->die_child
);
6642 CHECKSUM_ULEB128 (0);
6645 /* Add a type name and tag to a hash. */
6647 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
6649 CHECKSUM_ULEB128 (tag
);
6650 CHECKSUM_STRING (name
);
6654 #undef CHECKSUM_STRING
6655 #undef CHECKSUM_ATTR
6656 #undef CHECKSUM_LEB128
6657 #undef CHECKSUM_ULEB128
6659 /* Generate the type signature for DIE. This is computed by generating an
6660 MD5 checksum over the DIE's tag, its relevant attributes, and its
6661 children. Attributes that are references to other DIEs are processed
6662 by recursion, using the MARK field to prevent infinite recursion.
6663 If the DIE is nested inside a namespace or another type, we also
6664 need to include that context in the signature. The lower 64 bits
6665 of the resulting MD5 checksum comprise the signature. */
6668 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6672 unsigned char checksum
[16];
6677 name
= get_AT_string (die
, DW_AT_name
);
6678 decl
= get_AT_ref (die
, DW_AT_specification
);
6679 parent
= get_die_parent (die
);
6681 /* First, compute a signature for just the type name (and its surrounding
6682 context, if any. This is stored in the type unit DIE for link-time
6683 ODR (one-definition rule) checking. */
6685 if (is_cxx () && name
!= NULL
)
6687 md5_init_ctx (&ctx
);
6689 /* Checksum the names of surrounding namespaces and structures. */
6691 checksum_die_context (parent
, &ctx
);
6693 /* Checksum the current DIE. */
6694 die_odr_checksum (die
->die_tag
, name
, &ctx
);
6695 md5_finish_ctx (&ctx
, checksum
);
6697 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6700 /* Next, compute the complete type signature. */
6702 md5_init_ctx (&ctx
);
6704 die
->die_mark
= mark
;
6706 /* Checksum the names of surrounding namespaces and structures. */
6708 checksum_die_context (parent
, &ctx
);
6710 /* Checksum the DIE and its children. */
6711 die_checksum_ordered (die
, &ctx
, &mark
);
6712 unmark_all_dies (die
);
6713 md5_finish_ctx (&ctx
, checksum
);
6715 /* Store the signature in the type node and link the type DIE and the
6716 type node together. */
6717 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6718 DWARF_TYPE_SIGNATURE_SIZE
);
6719 die
->comdat_type_p
= true;
6720 die
->die_id
.die_type_node
= type_node
;
6721 type_node
->type_die
= die
;
6723 /* If the DIE is a specification, link its declaration to the type node
6727 decl
->comdat_type_p
= true;
6728 decl
->die_id
.die_type_node
= type_node
;
6732 /* Do the location expressions look same? */
6734 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6736 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6737 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6738 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6741 /* Do the values look the same? */
6743 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6745 dw_loc_descr_ref loc1
, loc2
;
6748 if (v1
->val_class
!= v2
->val_class
)
6751 switch (v1
->val_class
)
6753 case dw_val_class_const
:
6754 return v1
->v
.val_int
== v2
->v
.val_int
;
6755 case dw_val_class_unsigned_const
:
6756 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6757 case dw_val_class_const_double
:
6758 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6759 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6760 case dw_val_class_wide_int
:
6761 return *v1
->v
.val_wide
== *v2
->v
.val_wide
;
6762 case dw_val_class_vec
:
6763 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6764 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6766 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6767 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6770 case dw_val_class_flag
:
6771 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6772 case dw_val_class_str
:
6773 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6775 case dw_val_class_addr
:
6776 r1
= v1
->v
.val_addr
;
6777 r2
= v2
->v
.val_addr
;
6778 if (GET_CODE (r1
) != GET_CODE (r2
))
6780 return !rtx_equal_p (r1
, r2
);
6782 case dw_val_class_offset
:
6783 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6785 case dw_val_class_loc
:
6786 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6788 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6789 if (!same_loc_p (loc1
, loc2
, mark
))
6791 return !loc1
&& !loc2
;
6793 case dw_val_class_die_ref
:
6794 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6796 case dw_val_class_fde_ref
:
6797 case dw_val_class_vms_delta
:
6798 case dw_val_class_lbl_id
:
6799 case dw_val_class_lineptr
:
6800 case dw_val_class_macptr
:
6801 case dw_val_class_high_pc
:
6804 case dw_val_class_file
:
6805 return v1
->v
.val_file
== v2
->v
.val_file
;
6807 case dw_val_class_data8
:
6808 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6815 /* Do the attributes look the same? */
6818 same_attr_p (dw_attr_node
*at1
, dw_attr_node
*at2
, int *mark
)
6820 if (at1
->dw_attr
!= at2
->dw_attr
)
6823 /* We don't care that this was compiled with a different compiler
6824 snapshot; if the output is the same, that's what matters. */
6825 if (at1
->dw_attr
== DW_AT_producer
)
6828 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6831 /* Do the dies look the same? */
6834 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6840 /* To avoid infinite recursion. */
6842 return die1
->die_mark
== die2
->die_mark
;
6843 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6845 if (die1
->die_tag
!= die2
->die_tag
)
6848 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6851 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6852 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6855 c1
= die1
->die_child
;
6856 c2
= die2
->die_child
;
6865 if (!same_die_p (c1
, c2
, mark
))
6869 if (c1
== die1
->die_child
)
6871 if (c2
== die2
->die_child
)
6881 /* Do the dies look the same? Wrapper around same_die_p. */
6884 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6887 int ret
= same_die_p (die1
, die2
, &mark
);
6889 unmark_all_dies (die1
);
6890 unmark_all_dies (die2
);
6895 /* The prefix to attach to symbols on DIEs in the current comdat debug
6897 static const char *comdat_symbol_id
;
6899 /* The index of the current symbol within the current comdat CU. */
6900 static unsigned int comdat_symbol_number
;
6902 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6903 children, and set comdat_symbol_id accordingly. */
6906 compute_section_prefix (dw_die_ref unit_die
)
6908 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6909 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6910 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6913 unsigned char checksum
[16];
6916 /* Compute the checksum of the DIE, then append part of it as hex digits to
6917 the name filename of the unit. */
6919 md5_init_ctx (&ctx
);
6921 die_checksum (unit_die
, &ctx
, &mark
);
6922 unmark_all_dies (unit_die
);
6923 md5_finish_ctx (&ctx
, checksum
);
6925 sprintf (name
, "%s.", base
);
6926 clean_symbol_name (name
);
6928 p
= name
+ strlen (name
);
6929 for (i
= 0; i
< 4; i
++)
6931 sprintf (p
, "%.2x", checksum
[i
]);
6935 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6936 comdat_symbol_number
= 0;
6939 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6942 is_type_die (dw_die_ref die
)
6944 switch (die
->die_tag
)
6946 case DW_TAG_array_type
:
6947 case DW_TAG_class_type
:
6948 case DW_TAG_interface_type
:
6949 case DW_TAG_enumeration_type
:
6950 case DW_TAG_pointer_type
:
6951 case DW_TAG_reference_type
:
6952 case DW_TAG_rvalue_reference_type
:
6953 case DW_TAG_string_type
:
6954 case DW_TAG_structure_type
:
6955 case DW_TAG_subroutine_type
:
6956 case DW_TAG_union_type
:
6957 case DW_TAG_ptr_to_member_type
:
6958 case DW_TAG_set_type
:
6959 case DW_TAG_subrange_type
:
6960 case DW_TAG_base_type
:
6961 case DW_TAG_const_type
:
6962 case DW_TAG_file_type
:
6963 case DW_TAG_packed_type
:
6964 case DW_TAG_volatile_type
:
6965 case DW_TAG_typedef
:
6972 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6973 Basically, we want to choose the bits that are likely to be shared between
6974 compilations (types) and leave out the bits that are specific to individual
6975 compilations (functions). */
6978 is_comdat_die (dw_die_ref c
)
6980 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6981 we do for stabs. The advantage is a greater likelihood of sharing between
6982 objects that don't include headers in the same order (and therefore would
6983 put the base types in a different comdat). jason 8/28/00 */
6985 if (c
->die_tag
== DW_TAG_base_type
)
6988 if (c
->die_tag
== DW_TAG_pointer_type
6989 || c
->die_tag
== DW_TAG_reference_type
6990 || c
->die_tag
== DW_TAG_rvalue_reference_type
6991 || c
->die_tag
== DW_TAG_const_type
6992 || c
->die_tag
== DW_TAG_volatile_type
)
6994 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6996 return t
? is_comdat_die (t
) : 0;
6999 return is_type_die (c
);
7002 /* Returns 1 iff C is the sort of DIE that might be referred to from another
7003 compilation unit. */
7006 is_symbol_die (dw_die_ref c
)
7008 return (is_type_die (c
)
7009 || is_declaration_die (c
)
7010 || c
->die_tag
== DW_TAG_namespace
7011 || c
->die_tag
== DW_TAG_module
);
7014 /* Returns true iff C is a compile-unit DIE. */
7017 is_cu_die (dw_die_ref c
)
7019 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
7022 /* Returns true iff C is a unit DIE of some sort. */
7025 is_unit_die (dw_die_ref c
)
7027 return c
&& (c
->die_tag
== DW_TAG_compile_unit
7028 || c
->die_tag
== DW_TAG_partial_unit
7029 || c
->die_tag
== DW_TAG_type_unit
);
7032 /* Returns true iff C is a namespace DIE. */
7035 is_namespace_die (dw_die_ref c
)
7037 return c
&& c
->die_tag
== DW_TAG_namespace
;
7040 /* Returns true iff C is a class or structure DIE. */
7043 is_class_die (dw_die_ref c
)
7045 return c
&& (c
->die_tag
== DW_TAG_class_type
7046 || c
->die_tag
== DW_TAG_structure_type
);
7049 /* Return non-zero if this DIE is a template parameter. */
7052 is_template_parameter (dw_die_ref die
)
7054 switch (die
->die_tag
)
7056 case DW_TAG_template_type_param
:
7057 case DW_TAG_template_value_param
:
7058 case DW_TAG_GNU_template_template_param
:
7059 case DW_TAG_GNU_template_parameter_pack
:
7066 /* Return non-zero if this DIE represents a template instantiation. */
7069 is_template_instantiation (dw_die_ref die
)
7073 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
7075 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
7080 gen_internal_sym (const char *prefix
)
7084 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
7085 return xstrdup (buf
);
7088 /* Assign symbols to all worthy DIEs under DIE. */
7091 assign_symbol_names (dw_die_ref die
)
7095 if (is_symbol_die (die
) && !die
->comdat_type_p
)
7097 if (comdat_symbol_id
)
7099 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
7101 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
7102 comdat_symbol_id
, comdat_symbol_number
++);
7103 die
->die_id
.die_symbol
= xstrdup (p
);
7106 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
7109 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
7112 struct cu_hash_table_entry
7115 unsigned min_comdat_num
, max_comdat_num
;
7116 struct cu_hash_table_entry
*next
;
7119 /* Helpers to manipulate hash table of CUs. */
7121 struct cu_hash_table_entry_hasher
: pointer_hash
<cu_hash_table_entry
>
7123 typedef die_struct
*compare_type
;
7124 static inline hashval_t
hash (const cu_hash_table_entry
*);
7125 static inline bool equal (const cu_hash_table_entry
*, const die_struct
*);
7126 static inline void remove (cu_hash_table_entry
*);
7130 cu_hash_table_entry_hasher::hash (const cu_hash_table_entry
*entry
)
7132 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
7136 cu_hash_table_entry_hasher::equal (const cu_hash_table_entry
*entry1
,
7137 const die_struct
*entry2
)
7139 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
7143 cu_hash_table_entry_hasher::remove (cu_hash_table_entry
*entry
)
7145 struct cu_hash_table_entry
*next
;
7155 typedef hash_table
<cu_hash_table_entry_hasher
> cu_hash_type
;
7157 /* Check whether we have already seen this CU and set up SYM_NUM
7160 check_duplicate_cu (dw_die_ref cu
, cu_hash_type
*htable
, unsigned int *sym_num
)
7162 struct cu_hash_table_entry dummy
;
7163 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
7165 dummy
.max_comdat_num
= 0;
7167 slot
= htable
->find_slot_with_hash (cu
,
7168 htab_hash_string (cu
->die_id
.die_symbol
),
7172 for (; entry
; last
= entry
, entry
= entry
->next
)
7174 if (same_die_p_wrap (cu
, entry
->cu
))
7180 *sym_num
= entry
->min_comdat_num
;
7184 entry
= XCNEW (struct cu_hash_table_entry
);
7186 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
7187 entry
->next
= *slot
;
7193 /* Record SYM_NUM to record of CU in HTABLE. */
7195 record_comdat_symbol_number (dw_die_ref cu
, cu_hash_type
*htable
,
7196 unsigned int sym_num
)
7198 struct cu_hash_table_entry
**slot
, *entry
;
7200 slot
= htable
->find_slot_with_hash (cu
,
7201 htab_hash_string (cu
->die_id
.die_symbol
),
7205 entry
->max_comdat_num
= sym_num
;
7208 /* Traverse the DIE (which is always comp_unit_die), and set up
7209 additional compilation units for each of the include files we see
7210 bracketed by BINCL/EINCL. */
7213 break_out_includes (dw_die_ref die
)
7216 dw_die_ref unit
= NULL
;
7217 limbo_die_node
*node
, **pnode
;
7221 dw_die_ref prev
= c
;
7223 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
7224 || (unit
&& is_comdat_die (c
)))
7226 dw_die_ref next
= c
->die_sib
;
7228 /* This DIE is for a secondary CU; remove it from the main one. */
7229 remove_child_with_prev (c
, prev
);
7231 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
7232 unit
= push_new_compile_unit (unit
, c
);
7233 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
7234 unit
= pop_compile_unit (unit
);
7236 add_child_die (unit
, c
);
7238 if (c
== die
->die_child
)
7241 } while (c
!= die
->die_child
);
7244 /* We can only use this in debugging, since the frontend doesn't check
7245 to make sure that we leave every include file we enter. */
7249 assign_symbol_names (die
);
7250 cu_hash_type
cu_hash_table (10);
7251 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
7257 compute_section_prefix (node
->die
);
7258 is_dupl
= check_duplicate_cu (node
->die
, &cu_hash_table
,
7259 &comdat_symbol_number
);
7260 assign_symbol_names (node
->die
);
7262 *pnode
= node
->next
;
7265 pnode
= &node
->next
;
7266 record_comdat_symbol_number (node
->die
, &cu_hash_table
,
7267 comdat_symbol_number
);
7272 /* Return non-zero if this DIE is a declaration. */
7275 is_declaration_die (dw_die_ref die
)
7280 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7281 if (a
->dw_attr
== DW_AT_declaration
)
7287 /* Return non-zero if this DIE is nested inside a subprogram. */
7290 is_nested_in_subprogram (dw_die_ref die
)
7292 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
7296 return local_scope_p (decl
);
7299 /* Return non-zero if this DIE contains a defining declaration of a
7303 contains_subprogram_definition (dw_die_ref die
)
7307 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
7309 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
7313 /* Return non-zero if this is a type DIE that should be moved to a
7314 COMDAT .debug_types section. */
7317 should_move_die_to_comdat (dw_die_ref die
)
7319 switch (die
->die_tag
)
7321 case DW_TAG_class_type
:
7322 case DW_TAG_structure_type
:
7323 case DW_TAG_enumeration_type
:
7324 case DW_TAG_union_type
:
7325 /* Don't move declarations, inlined instances, types nested in a
7326 subprogram, or types that contain subprogram definitions. */
7327 if (is_declaration_die (die
)
7328 || get_AT (die
, DW_AT_abstract_origin
)
7329 || is_nested_in_subprogram (die
)
7330 || contains_subprogram_definition (die
))
7333 case DW_TAG_array_type
:
7334 case DW_TAG_interface_type
:
7335 case DW_TAG_pointer_type
:
7336 case DW_TAG_reference_type
:
7337 case DW_TAG_rvalue_reference_type
:
7338 case DW_TAG_string_type
:
7339 case DW_TAG_subroutine_type
:
7340 case DW_TAG_ptr_to_member_type
:
7341 case DW_TAG_set_type
:
7342 case DW_TAG_subrange_type
:
7343 case DW_TAG_base_type
:
7344 case DW_TAG_const_type
:
7345 case DW_TAG_file_type
:
7346 case DW_TAG_packed_type
:
7347 case DW_TAG_volatile_type
:
7348 case DW_TAG_typedef
:
7354 /* Make a clone of DIE. */
7357 clone_die (dw_die_ref die
)
7363 clone
= ggc_cleared_alloc
<die_node
> ();
7364 clone
->die_tag
= die
->die_tag
;
7366 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7367 add_dwarf_attr (clone
, a
);
7372 /* Make a clone of the tree rooted at DIE. */
7375 clone_tree (dw_die_ref die
)
7378 dw_die_ref clone
= clone_die (die
);
7380 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
7385 /* Make a clone of DIE as a declaration. */
7388 clone_as_declaration (dw_die_ref die
)
7395 /* If the DIE is already a declaration, just clone it. */
7396 if (is_declaration_die (die
))
7397 return clone_die (die
);
7399 /* If the DIE is a specification, just clone its declaration DIE. */
7400 decl
= get_AT_ref (die
, DW_AT_specification
);
7403 clone
= clone_die (decl
);
7404 if (die
->comdat_type_p
)
7405 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7409 clone
= ggc_cleared_alloc
<die_node
> ();
7410 clone
->die_tag
= die
->die_tag
;
7412 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7414 /* We don't want to copy over all attributes.
7415 For example we don't want DW_AT_byte_size because otherwise we will no
7416 longer have a declaration and GDB will treat it as a definition. */
7420 case DW_AT_abstract_origin
:
7421 case DW_AT_artificial
:
7422 case DW_AT_containing_type
:
7423 case DW_AT_external
:
7426 case DW_AT_virtuality
:
7427 case DW_AT_linkage_name
:
7428 case DW_AT_MIPS_linkage_name
:
7429 add_dwarf_attr (clone
, a
);
7431 case DW_AT_byte_size
:
7437 if (die
->comdat_type_p
)
7438 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7440 add_AT_flag (clone
, DW_AT_declaration
, 1);
7445 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7447 struct decl_table_entry
7453 /* Helpers to manipulate hash table of copied declarations. */
7455 /* Hashtable helpers. */
7457 struct decl_table_entry_hasher
: free_ptr_hash
<decl_table_entry
>
7459 typedef die_struct
*compare_type
;
7460 static inline hashval_t
hash (const decl_table_entry
*);
7461 static inline bool equal (const decl_table_entry
*, const die_struct
*);
7465 decl_table_entry_hasher::hash (const decl_table_entry
*entry
)
7467 return htab_hash_pointer (entry
->orig
);
7471 decl_table_entry_hasher::equal (const decl_table_entry
*entry1
,
7472 const die_struct
*entry2
)
7474 return entry1
->orig
== entry2
;
7477 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
7479 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7480 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7481 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7482 to check if the ancestor has already been copied into UNIT. */
7485 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
,
7486 decl_hash_type
*decl_table
)
7488 dw_die_ref parent
= die
->die_parent
;
7489 dw_die_ref new_parent
= unit
;
7491 decl_table_entry
**slot
= NULL
;
7492 struct decl_table_entry
*entry
= NULL
;
7496 /* Check if the entry has already been copied to UNIT. */
7497 slot
= decl_table
->find_slot_with_hash (die
, htab_hash_pointer (die
),
7499 if (*slot
!= HTAB_EMPTY_ENTRY
)
7505 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7506 entry
= XCNEW (struct decl_table_entry
);
7514 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7517 if (!is_unit_die (parent
))
7518 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7521 copy
= clone_as_declaration (die
);
7522 add_child_die (new_parent
, copy
);
7526 /* Record the pointer to the copy. */
7532 /* Copy the declaration context to the new type unit DIE. This includes
7533 any surrounding namespace or type declarations. If the DIE has an
7534 AT_specification attribute, it also includes attributes and children
7535 attached to the specification, and returns a pointer to the original
7536 parent of the declaration DIE. Returns NULL otherwise. */
7539 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7542 dw_die_ref new_decl
;
7543 dw_die_ref orig_parent
= NULL
;
7545 decl
= get_AT_ref (die
, DW_AT_specification
);
7554 /* The original DIE will be changed to a declaration, and must
7555 be moved to be a child of the original declaration DIE. */
7556 orig_parent
= decl
->die_parent
;
7558 /* Copy the type node pointer from the new DIE to the original
7559 declaration DIE so we can forward references later. */
7560 decl
->comdat_type_p
= true;
7561 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7563 remove_AT (die
, DW_AT_specification
);
7565 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
7567 if (a
->dw_attr
!= DW_AT_name
7568 && a
->dw_attr
!= DW_AT_declaration
7569 && a
->dw_attr
!= DW_AT_external
)
7570 add_dwarf_attr (die
, a
);
7573 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
7576 if (decl
->die_parent
!= NULL
7577 && !is_unit_die (decl
->die_parent
))
7579 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
7580 if (new_decl
!= NULL
)
7582 remove_AT (new_decl
, DW_AT_signature
);
7583 add_AT_specification (die
, new_decl
);
7590 /* Generate the skeleton ancestor tree for the given NODE, then clone
7591 the DIE and add the clone into the tree. */
7594 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7596 if (node
->new_die
!= NULL
)
7599 node
->new_die
= clone_as_declaration (node
->old_die
);
7601 if (node
->parent
!= NULL
)
7603 generate_skeleton_ancestor_tree (node
->parent
);
7604 add_child_die (node
->parent
->new_die
, node
->new_die
);
7608 /* Generate a skeleton tree of DIEs containing any declarations that are
7609 found in the original tree. We traverse the tree looking for declaration
7610 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7613 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7615 skeleton_chain_node node
;
7618 dw_die_ref prev
= NULL
;
7619 dw_die_ref next
= NULL
;
7621 node
.parent
= parent
;
7623 first
= c
= parent
->old_die
->die_child
;
7627 if (prev
== NULL
|| prev
->die_sib
== c
)
7630 next
= (c
== first
? NULL
: c
->die_sib
);
7632 node
.new_die
= NULL
;
7633 if (is_declaration_die (c
))
7635 if (is_template_instantiation (c
))
7637 /* Instantiated templates do not need to be cloned into the
7638 type unit. Just move the DIE and its children back to
7639 the skeleton tree (in the main CU). */
7640 remove_child_with_prev (c
, prev
);
7641 add_child_die (parent
->new_die
, c
);
7646 /* Clone the existing DIE, move the original to the skeleton
7647 tree (which is in the main CU), and put the clone, with
7648 all the original's children, where the original came from
7649 (which is about to be moved to the type unit). */
7650 dw_die_ref clone
= clone_die (c
);
7651 move_all_children (c
, clone
);
7653 /* If the original has a DW_AT_object_pointer attribute,
7654 it would now point to a child DIE just moved to the
7655 cloned tree, so we need to remove that attribute from
7657 remove_AT (c
, DW_AT_object_pointer
);
7659 replace_child (c
, clone
, prev
);
7660 generate_skeleton_ancestor_tree (parent
);
7661 add_child_die (parent
->new_die
, c
);
7666 generate_skeleton_bottom_up (&node
);
7667 } while (next
!= NULL
);
7670 /* Wrapper function for generate_skeleton_bottom_up. */
7673 generate_skeleton (dw_die_ref die
)
7675 skeleton_chain_node node
;
7678 node
.new_die
= NULL
;
7681 /* If this type definition is nested inside another type,
7682 and is not an instantiation of a template, always leave
7683 at least a declaration in its place. */
7684 if (die
->die_parent
!= NULL
7685 && is_type_die (die
->die_parent
)
7686 && !is_template_instantiation (die
))
7687 node
.new_die
= clone_as_declaration (die
);
7689 generate_skeleton_bottom_up (&node
);
7690 return node
.new_die
;
7693 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7694 declaration. The original DIE is moved to a new compile unit so that
7695 existing references to it follow it to the new location. If any of the
7696 original DIE's descendants is a declaration, we need to replace the
7697 original DIE with a skeleton tree and move the declarations back into the
7701 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
7704 dw_die_ref skeleton
, orig_parent
;
7706 /* Copy the declaration context to the type unit DIE. If the returned
7707 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7709 orig_parent
= copy_declaration_context (unit
, child
);
7711 skeleton
= generate_skeleton (child
);
7712 if (skeleton
== NULL
)
7713 remove_child_with_prev (child
, prev
);
7716 skeleton
->comdat_type_p
= true;
7717 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
7719 /* If the original DIE was a specification, we need to put
7720 the skeleton under the parent DIE of the declaration.
7721 This leaves the original declaration in the tree, but
7722 it will be pruned later since there are no longer any
7723 references to it. */
7724 if (orig_parent
!= NULL
)
7726 remove_child_with_prev (child
, prev
);
7727 add_child_die (orig_parent
, skeleton
);
7730 replace_child (child
, skeleton
, prev
);
7737 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
7738 comdat_type_node
*type_node
,
7739 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
);
7741 /* Helper for copy_dwarf_procs_ref_in_dies. Make a copy of the DIE DWARF
7742 procedure, put it under TYPE_NODE and return the copy. Continue looking for
7743 DWARF procedure references in the DW_AT_location attribute. */
7746 copy_dwarf_procedure (dw_die_ref die
,
7747 comdat_type_node
*type_node
,
7748 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
7750 gcc_assert (die
->die_tag
== DW_TAG_dwarf_procedure
);
7752 /* DWARF procedures are not supposed to have children... */
7753 gcc_assert (die
->die_child
== NULL
);
7755 /* ... and they are supposed to have only one attribute: DW_AT_location. */
7756 gcc_assert (vec_safe_length (die
->die_attr
) == 1
7757 && ((*die
->die_attr
)[0].dw_attr
== DW_AT_location
));
7759 /* Do not copy more than once DWARF procedures. */
7761 dw_die_ref
&die_copy
= copied_dwarf_procs
.get_or_insert (die
, &existed
);
7765 die_copy
= clone_die (die
);
7766 add_child_die (type_node
->root_die
, die_copy
);
7767 copy_dwarf_procs_ref_in_attrs (die_copy
, type_node
, copied_dwarf_procs
);
7771 /* Helper for copy_dwarf_procs_ref_in_dies. Look for references to DWARF
7772 procedures in DIE's attributes. */
7775 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
7776 comdat_type_node
*type_node
,
7777 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
7782 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, i
, a
)
7784 dw_loc_descr_ref loc
;
7786 if (a
->dw_attr_val
.val_class
!= dw_val_class_loc
)
7789 for (loc
= a
->dw_attr_val
.v
.val_loc
; loc
!= NULL
; loc
= loc
->dw_loc_next
)
7791 switch (loc
->dw_loc_opc
)
7795 case DW_OP_call_ref
:
7796 gcc_assert (loc
->dw_loc_oprnd1
.val_class
7797 == dw_val_class_die_ref
);
7798 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
7799 = copy_dwarf_procedure (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
,
7801 copied_dwarf_procs
);
7810 /* Copy DWARF procedures that are referenced by the DIE tree to TREE_NODE and
7811 rewrite references to point to the copies.
7813 References are looked for in DIE's attributes and recursively in all its
7814 children attributes that are location descriptions. COPIED_DWARF_PROCS is a
7815 mapping from old DWARF procedures to their copy. It is used not to copy
7816 twice the same DWARF procedure under TYPE_NODE. */
7819 copy_dwarf_procs_ref_in_dies (dw_die_ref die
,
7820 comdat_type_node
*type_node
,
7821 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
7825 copy_dwarf_procs_ref_in_attrs (die
, type_node
, copied_dwarf_procs
);
7826 FOR_EACH_CHILD (die
, c
, copy_dwarf_procs_ref_in_dies (c
,
7828 copied_dwarf_procs
));
7831 /* Traverse the DIE and set up additional .debug_types sections for each
7832 type worthy of being placed in a COMDAT section. */
7835 break_out_comdat_types (dw_die_ref die
)
7839 dw_die_ref prev
= NULL
;
7840 dw_die_ref next
= NULL
;
7841 dw_die_ref unit
= NULL
;
7843 first
= c
= die
->die_child
;
7847 if (prev
== NULL
|| prev
->die_sib
== c
)
7850 next
= (c
== first
? NULL
: c
->die_sib
);
7851 if (should_move_die_to_comdat (c
))
7853 dw_die_ref replacement
;
7854 comdat_type_node
*type_node
;
7856 /* Break out nested types into their own type units. */
7857 break_out_comdat_types (c
);
7859 /* Create a new type unit DIE as the root for the new tree, and
7860 add it to the list of comdat types. */
7861 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7862 add_AT_unsigned (unit
, DW_AT_language
,
7863 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7864 type_node
= ggc_cleared_alloc
<comdat_type_node
> ();
7865 type_node
->root_die
= unit
;
7866 type_node
->next
= comdat_type_list
;
7867 comdat_type_list
= type_node
;
7869 /* Generate the type signature. */
7870 generate_type_signature (c
, type_node
);
7872 /* Copy the declaration context, attributes, and children of the
7873 declaration into the new type unit DIE, then remove this DIE
7874 from the main CU (or replace it with a skeleton if necessary). */
7875 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7876 type_node
->skeleton_die
= replacement
;
7878 /* Add the DIE to the new compunit. */
7879 add_child_die (unit
, c
);
7881 /* Types can reference DWARF procedures for type size or data location
7882 expressions. Calls in DWARF expressions cannot target procedures
7883 that are not in the same section. So we must copy DWARF procedures
7884 along with this type and then rewrite references to them. */
7885 hash_map
<dw_die_ref
, dw_die_ref
> copied_dwarf_procs
;
7886 copy_dwarf_procs_ref_in_dies (c
, type_node
, copied_dwarf_procs
);
7888 if (replacement
!= NULL
)
7891 else if (c
->die_tag
== DW_TAG_namespace
7892 || c
->die_tag
== DW_TAG_class_type
7893 || c
->die_tag
== DW_TAG_structure_type
7894 || c
->die_tag
== DW_TAG_union_type
)
7896 /* Look for nested types that can be broken out. */
7897 break_out_comdat_types (c
);
7899 } while (next
!= NULL
);
7902 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
7903 Enter all the cloned children into the hash table decl_table. */
7906 clone_tree_partial (dw_die_ref die
, decl_hash_type
*decl_table
)
7910 struct decl_table_entry
*entry
;
7911 decl_table_entry
**slot
;
7913 if (die
->die_tag
== DW_TAG_subprogram
)
7914 clone
= clone_as_declaration (die
);
7916 clone
= clone_die (die
);
7918 slot
= decl_table
->find_slot_with_hash (die
,
7919 htab_hash_pointer (die
), INSERT
);
7921 /* Assert that DIE isn't in the hash table yet. If it would be there
7922 before, the ancestors would be necessarily there as well, therefore
7923 clone_tree_partial wouldn't be called. */
7924 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7926 entry
= XCNEW (struct decl_table_entry
);
7928 entry
->copy
= clone
;
7931 if (die
->die_tag
!= DW_TAG_subprogram
)
7932 FOR_EACH_CHILD (die
, c
,
7933 add_child_die (clone
, clone_tree_partial (c
, decl_table
)));
7938 /* Walk the DIE and its children, looking for references to incomplete
7939 or trivial types that are unmarked (i.e., that are not in the current
7943 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type
*decl_table
)
7949 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7951 if (AT_class (a
) == dw_val_class_die_ref
)
7953 dw_die_ref targ
= AT_ref (a
);
7954 decl_table_entry
**slot
;
7955 struct decl_table_entry
*entry
;
7957 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7960 slot
= decl_table
->find_slot_with_hash (targ
,
7961 htab_hash_pointer (targ
),
7964 if (*slot
!= HTAB_EMPTY_ENTRY
)
7966 /* TARG has already been copied, so we just need to
7967 modify the reference to point to the copy. */
7969 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7973 dw_die_ref parent
= unit
;
7974 dw_die_ref copy
= clone_die (targ
);
7976 /* Record in DECL_TABLE that TARG has been copied.
7977 Need to do this now, before the recursive call,
7978 because DECL_TABLE may be expanded and SLOT
7979 would no longer be a valid pointer. */
7980 entry
= XCNEW (struct decl_table_entry
);
7985 /* If TARG is not a declaration DIE, we need to copy its
7987 if (!is_declaration_die (targ
))
7991 add_child_die (copy
,
7992 clone_tree_partial (c
, decl_table
)));
7995 /* Make sure the cloned tree is marked as part of the
7999 /* If TARG has surrounding context, copy its ancestor tree
8000 into the new type unit. */
8001 if (targ
->die_parent
!= NULL
8002 && !is_unit_die (targ
->die_parent
))
8003 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
8006 add_child_die (parent
, copy
);
8007 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
8009 /* Make sure the newly-copied DIE is walked. If it was
8010 installed in a previously-added context, it won't
8011 get visited otherwise. */
8014 /* Find the highest point of the newly-added tree,
8015 mark each node along the way, and walk from there. */
8016 parent
->die_mark
= 1;
8017 while (parent
->die_parent
8018 && parent
->die_parent
->die_mark
== 0)
8020 parent
= parent
->die_parent
;
8021 parent
->die_mark
= 1;
8023 copy_decls_walk (unit
, parent
, decl_table
);
8029 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
8032 /* Copy declarations for "unworthy" types into the new comdat section.
8033 Incomplete types, modified types, and certain other types aren't broken
8034 out into comdat sections of their own, so they don't have a signature,
8035 and we need to copy the declaration into the same section so that we
8036 don't have an external reference. */
8039 copy_decls_for_unworthy_types (dw_die_ref unit
)
8042 decl_hash_type
decl_table (10);
8043 copy_decls_walk (unit
, unit
, &decl_table
);
8047 /* Traverse the DIE and add a sibling attribute if it may have the
8048 effect of speeding up access to siblings. To save some space,
8049 avoid generating sibling attributes for DIE's without children. */
8052 add_sibling_attributes (dw_die_ref die
)
8056 if (! die
->die_child
)
8059 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
8060 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
8062 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
8065 /* Output all location lists for the DIE and its children. */
8068 output_location_lists (dw_die_ref die
)
8074 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8075 if (AT_class (a
) == dw_val_class_loc_list
)
8076 output_loc_list (AT_loc_list (a
));
8078 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
8081 /* We want to limit the number of external references, because they are
8082 larger than local references: a relocation takes multiple words, and
8083 even a sig8 reference is always eight bytes, whereas a local reference
8084 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
8085 So if we encounter multiple external references to the same type DIE, we
8086 make a local typedef stub for it and redirect all references there.
8088 This is the element of the hash table for keeping track of these
8098 /* Hashtable helpers. */
8100 struct external_ref_hasher
: free_ptr_hash
<external_ref
>
8102 static inline hashval_t
hash (const external_ref
*);
8103 static inline bool equal (const external_ref
*, const external_ref
*);
8107 external_ref_hasher::hash (const external_ref
*r
)
8109 dw_die_ref die
= r
->type
;
8112 /* We can't use the address of the DIE for hashing, because
8113 that will make the order of the stub DIEs non-deterministic. */
8114 if (! die
->comdat_type_p
)
8115 /* We have a symbol; use it to compute a hash. */
8116 h
= htab_hash_string (die
->die_id
.die_symbol
);
8119 /* We have a type signature; use a subset of the bits as the hash.
8120 The 8-byte signature is at least as large as hashval_t. */
8121 comdat_type_node
*type_node
= die
->die_id
.die_type_node
;
8122 memcpy (&h
, type_node
->signature
, sizeof (h
));
8128 external_ref_hasher::equal (const external_ref
*r1
, const external_ref
*r2
)
8130 return r1
->type
== r2
->type
;
8133 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
8135 /* Return a pointer to the external_ref for references to DIE. */
8137 static struct external_ref
*
8138 lookup_external_ref (external_ref_hash_type
*map
, dw_die_ref die
)
8140 struct external_ref ref
, *ref_p
;
8141 external_ref
**slot
;
8144 slot
= map
->find_slot (&ref
, INSERT
);
8145 if (*slot
!= HTAB_EMPTY_ENTRY
)
8148 ref_p
= XCNEW (struct external_ref
);
8154 /* Subroutine of optimize_external_refs, below.
8156 If we see a type skeleton, record it as our stub. If we see external
8157 references, remember how many we've seen. */
8160 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type
*map
)
8165 struct external_ref
*ref_p
;
8167 if (is_type_die (die
)
8168 && (c
= get_AT_ref (die
, DW_AT_signature
)))
8170 /* This is a local skeleton; use it for local references. */
8171 ref_p
= lookup_external_ref (map
, c
);
8175 /* Scan the DIE references, and remember any that refer to DIEs from
8176 other CUs (i.e. those which are not marked). */
8177 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8178 if (AT_class (a
) == dw_val_class_die_ref
8179 && (c
= AT_ref (a
))->die_mark
== 0
8182 ref_p
= lookup_external_ref (map
, c
);
8186 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
8189 /* htab_traverse callback function for optimize_external_refs, below. SLOT
8190 points to an external_ref, DATA is the CU we're processing. If we don't
8191 already have a local stub, and we have multiple refs, build a stub. */
8194 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
8196 struct external_ref
*ref_p
= *slot
;
8198 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
8200 /* We have multiple references to this type, so build a small stub.
8201 Both of these forms are a bit dodgy from the perspective of the
8202 DWARF standard, since technically they should have names. */
8203 dw_die_ref cu
= data
;
8204 dw_die_ref type
= ref_p
->type
;
8205 dw_die_ref stub
= NULL
;
8207 if (type
->comdat_type_p
)
8209 /* If we refer to this type via sig8, use AT_signature. */
8210 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
8211 add_AT_die_ref (stub
, DW_AT_signature
, type
);
8215 /* Otherwise, use a typedef with no name. */
8216 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
8217 add_AT_die_ref (stub
, DW_AT_type
, type
);
8226 /* DIE is a unit; look through all the DIE references to see if there are
8227 any external references to types, and if so, create local stubs for
8228 them which will be applied in build_abbrev_table. This is useful because
8229 references to local DIEs are smaller. */
8231 static external_ref_hash_type
*
8232 optimize_external_refs (dw_die_ref die
)
8234 external_ref_hash_type
*map
= new external_ref_hash_type (10);
8235 optimize_external_refs_1 (die
, map
);
8236 map
->traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
8240 /* The format of each DIE (and its attribute value pairs) is encoded in an
8241 abbreviation table. This routine builds the abbreviation table and assigns
8242 a unique abbreviation id for each abbreviation entry. The children of each
8243 die are visited recursively. */
8246 build_abbrev_table (dw_die_ref die
, external_ref_hash_type
*extern_map
)
8248 unsigned long abbrev_id
;
8249 unsigned int n_alloc
;
8254 /* Scan the DIE references, and replace any that refer to
8255 DIEs from other CUs (i.e. those which are not marked) with
8256 the local stubs we built in optimize_external_refs. */
8257 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8258 if (AT_class (a
) == dw_val_class_die_ref
8259 && (c
= AT_ref (a
))->die_mark
== 0)
8261 struct external_ref
*ref_p
;
8262 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
8264 ref_p
= lookup_external_ref (extern_map
, c
);
8265 if (ref_p
->stub
&& ref_p
->stub
!= die
)
8266 change_AT_die_ref (a
, ref_p
->stub
);
8268 /* We aren't changing this reference, so mark it external. */
8269 set_AT_ref_external (a
, 1);
8272 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8274 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
8275 dw_attr_node
*die_a
, *abbrev_a
;
8279 if (abbrev
->die_tag
!= die
->die_tag
)
8281 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
8284 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
8287 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
8289 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
8290 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
8291 || (value_format (abbrev_a
) != value_format (die_a
)))
8301 if (abbrev_id
>= abbrev_die_table_in_use
)
8303 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
8305 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
8306 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
8309 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
8310 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
8311 abbrev_die_table_allocated
= n_alloc
;
8314 ++abbrev_die_table_in_use
;
8315 abbrev_die_table
[abbrev_id
] = die
;
8318 die
->die_abbrev
= abbrev_id
;
8319 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
8322 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8325 constant_size (unsigned HOST_WIDE_INT value
)
8332 log
= floor_log2 (value
);
8335 log
= 1 << (floor_log2 (log
) + 1);
8340 /* Return the size of a DIE as it is represented in the
8341 .debug_info section. */
8343 static unsigned long
8344 size_of_die (dw_die_ref die
)
8346 unsigned long size
= 0;
8349 enum dwarf_form form
;
8351 size
+= size_of_uleb128 (die
->die_abbrev
);
8352 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8354 switch (AT_class (a
))
8356 case dw_val_class_addr
:
8357 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8359 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8360 size
+= size_of_uleb128 (AT_index (a
));
8363 size
+= DWARF2_ADDR_SIZE
;
8365 case dw_val_class_offset
:
8366 size
+= DWARF_OFFSET_SIZE
;
8368 case dw_val_class_loc
:
8370 unsigned long lsize
= size_of_locs (AT_loc (a
));
8373 if (dwarf_version
>= 4)
8374 size
+= size_of_uleb128 (lsize
);
8376 size
+= constant_size (lsize
);
8380 case dw_val_class_loc_list
:
8381 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8383 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8384 size
+= size_of_uleb128 (AT_index (a
));
8387 size
+= DWARF_OFFSET_SIZE
;
8389 case dw_val_class_range_list
:
8390 size
+= DWARF_OFFSET_SIZE
;
8392 case dw_val_class_const
:
8393 size
+= size_of_sleb128 (AT_int (a
));
8395 case dw_val_class_unsigned_const
:
8397 int csize
= constant_size (AT_unsigned (a
));
8398 if (dwarf_version
== 3
8399 && a
->dw_attr
== DW_AT_data_member_location
8401 size
+= size_of_uleb128 (AT_unsigned (a
));
8406 case dw_val_class_const_double
:
8407 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
8408 if (HOST_BITS_PER_WIDE_INT
>= 64)
8411 case dw_val_class_wide_int
:
8412 size
+= (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
8413 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
8414 if (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
8418 case dw_val_class_vec
:
8419 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
8420 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
8421 + a
->dw_attr_val
.v
.val_vec
.length
8422 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
8424 case dw_val_class_flag
:
8425 if (dwarf_version
>= 4)
8426 /* Currently all add_AT_flag calls pass in 1 as last argument,
8427 so DW_FORM_flag_present can be used. If that ever changes,
8428 we'll need to use DW_FORM_flag and have some optimization
8429 in build_abbrev_table that will change those to
8430 DW_FORM_flag_present if it is set to 1 in all DIEs using
8431 the same abbrev entry. */
8432 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8436 case dw_val_class_die_ref
:
8437 if (AT_ref_external (a
))
8439 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
8440 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
8441 is sized by target address length, whereas in DWARF3
8442 it's always sized as an offset. */
8443 if (use_debug_types
)
8444 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
8445 else if (dwarf_version
== 2)
8446 size
+= DWARF2_ADDR_SIZE
;
8448 size
+= DWARF_OFFSET_SIZE
;
8451 size
+= DWARF_OFFSET_SIZE
;
8453 case dw_val_class_fde_ref
:
8454 size
+= DWARF_OFFSET_SIZE
;
8456 case dw_val_class_lbl_id
:
8457 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8459 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8460 size
+= size_of_uleb128 (AT_index (a
));
8463 size
+= DWARF2_ADDR_SIZE
;
8465 case dw_val_class_lineptr
:
8466 case dw_val_class_macptr
:
8467 size
+= DWARF_OFFSET_SIZE
;
8469 case dw_val_class_str
:
8470 form
= AT_string_form (a
);
8471 if (form
== DW_FORM_strp
)
8472 size
+= DWARF_OFFSET_SIZE
;
8473 else if (form
== DW_FORM_GNU_str_index
)
8474 size
+= size_of_uleb128 (AT_index (a
));
8476 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
8478 case dw_val_class_file
:
8479 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
8481 case dw_val_class_data8
:
8484 case dw_val_class_vms_delta
:
8485 size
+= DWARF_OFFSET_SIZE
;
8487 case dw_val_class_high_pc
:
8488 size
+= DWARF2_ADDR_SIZE
;
8490 case dw_val_class_discr_value
:
8491 size
+= size_of_discr_value (&a
->dw_attr_val
.v
.val_discr_value
);
8493 case dw_val_class_discr_list
:
8495 unsigned block_size
= size_of_discr_list (AT_discr_list (a
));
8497 /* This is a block, so we have the block length and then its
8499 size
+= constant_size (block_size
) + block_size
;
8510 /* Size the debugging information associated with a given DIE. Visits the
8511 DIE's children recursively. Updates the global variable next_die_offset, on
8512 each time through. Uses the current value of next_die_offset to update the
8513 die_offset field in each DIE. */
8516 calc_die_sizes (dw_die_ref die
)
8520 gcc_assert (die
->die_offset
== 0
8521 || (unsigned long int) die
->die_offset
== next_die_offset
);
8522 die
->die_offset
= next_die_offset
;
8523 next_die_offset
+= size_of_die (die
);
8525 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
8527 if (die
->die_child
!= NULL
)
8528 /* Count the null byte used to terminate sibling lists. */
8529 next_die_offset
+= 1;
8532 /* Size just the base type children at the start of the CU.
8533 This is needed because build_abbrev needs to size locs
8534 and sizing of type based stack ops needs to know die_offset
8535 values for the base types. */
8538 calc_base_type_die_sizes (void)
8540 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8542 dw_die_ref base_type
;
8543 #if ENABLE_ASSERT_CHECKING
8544 dw_die_ref prev
= comp_unit_die ()->die_child
;
8547 die_offset
+= size_of_die (comp_unit_die ());
8548 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
8550 #if ENABLE_ASSERT_CHECKING
8551 gcc_assert (base_type
->die_offset
== 0
8552 && prev
->die_sib
== base_type
8553 && base_type
->die_child
== NULL
8554 && base_type
->die_abbrev
);
8557 base_type
->die_offset
= die_offset
;
8558 die_offset
+= size_of_die (base_type
);
8562 /* Set the marks for a die and its children. We do this so
8563 that we know whether or not a reference needs to use FORM_ref_addr; only
8564 DIEs in the same CU will be marked. We used to clear out the offset
8565 and use that as the flag, but ran into ordering problems. */
8568 mark_dies (dw_die_ref die
)
8572 gcc_assert (!die
->die_mark
);
8575 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
8578 /* Clear the marks for a die and its children. */
8581 unmark_dies (dw_die_ref die
)
8585 if (! use_debug_types
)
8586 gcc_assert (die
->die_mark
);
8589 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
8592 /* Clear the marks for a die, its children and referred dies. */
8595 unmark_all_dies (dw_die_ref die
)
8605 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
8607 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8608 if (AT_class (a
) == dw_val_class_die_ref
)
8609 unmark_all_dies (AT_ref (a
));
8612 /* Calculate if the entry should appear in the final output file. It may be
8613 from a pruned a type. */
8616 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
8618 /* By limiting gnu pubnames to definitions only, gold can generate a
8619 gdb index without entries for declarations, which don't include
8620 enough information to be useful. */
8621 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
8624 if (table
== pubname_table
)
8626 /* Enumerator names are part of the pubname table, but the
8627 parent DW_TAG_enumeration_type die may have been pruned.
8628 Don't output them if that is the case. */
8629 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
8630 (p
->die
->die_parent
== NULL
8631 || !p
->die
->die_parent
->die_perennial_p
))
8634 /* Everything else in the pubname table is included. */
8638 /* The pubtypes table shouldn't include types that have been
8640 return (p
->die
->die_offset
!= 0
8641 || !flag_eliminate_unused_debug_types
);
8644 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8645 generated for the compilation unit. */
8647 static unsigned long
8648 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
8653 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
8655 size
= DWARF_PUBNAMES_HEADER_SIZE
;
8656 FOR_EACH_VEC_ELT (*names
, i
, p
)
8657 if (include_pubname_in_output (names
, p
))
8658 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
8660 size
+= DWARF_OFFSET_SIZE
;
8664 /* Return the size of the information in the .debug_aranges section. */
8666 static unsigned long
8667 size_of_aranges (void)
8671 size
= DWARF_ARANGES_HEADER_SIZE
;
8673 /* Count the address/length pair for this compilation unit. */
8674 if (text_section_used
)
8675 size
+= 2 * DWARF2_ADDR_SIZE
;
8676 if (cold_text_section_used
)
8677 size
+= 2 * DWARF2_ADDR_SIZE
;
8678 if (have_multiple_function_sections
)
8683 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
8685 if (DECL_IGNORED_P (fde
->decl
))
8687 if (!fde
->in_std_section
)
8688 size
+= 2 * DWARF2_ADDR_SIZE
;
8689 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
8690 size
+= 2 * DWARF2_ADDR_SIZE
;
8694 /* Count the two zero words used to terminated the address range table. */
8695 size
+= 2 * DWARF2_ADDR_SIZE
;
8699 /* Select the encoding of an attribute value. */
8701 static enum dwarf_form
8702 value_format (dw_attr_node
*a
)
8704 switch (AT_class (a
))
8706 case dw_val_class_addr
:
8707 /* Only very few attributes allow DW_FORM_addr. */
8712 case DW_AT_entry_pc
:
8713 case DW_AT_trampoline
:
8714 return (AT_index (a
) == NOT_INDEXED
8715 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8719 switch (DWARF2_ADDR_SIZE
)
8722 return DW_FORM_data1
;
8724 return DW_FORM_data2
;
8726 return DW_FORM_data4
;
8728 return DW_FORM_data8
;
8732 case dw_val_class_range_list
:
8733 case dw_val_class_loc_list
:
8734 if (dwarf_version
>= 4)
8735 return DW_FORM_sec_offset
;
8737 case dw_val_class_vms_delta
:
8738 case dw_val_class_offset
:
8739 switch (DWARF_OFFSET_SIZE
)
8742 return DW_FORM_data4
;
8744 return DW_FORM_data8
;
8748 case dw_val_class_loc
:
8749 if (dwarf_version
>= 4)
8750 return DW_FORM_exprloc
;
8751 switch (constant_size (size_of_locs (AT_loc (a
))))
8754 return DW_FORM_block1
;
8756 return DW_FORM_block2
;
8758 return DW_FORM_block4
;
8762 case dw_val_class_const
:
8763 return DW_FORM_sdata
;
8764 case dw_val_class_unsigned_const
:
8765 switch (constant_size (AT_unsigned (a
)))
8768 return DW_FORM_data1
;
8770 return DW_FORM_data2
;
8772 /* In DWARF3 DW_AT_data_member_location with
8773 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8774 constant, so we need to use DW_FORM_udata if we need
8775 a large constant. */
8776 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8777 return DW_FORM_udata
;
8778 return DW_FORM_data4
;
8780 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8781 return DW_FORM_udata
;
8782 return DW_FORM_data8
;
8786 case dw_val_class_const_double
:
8787 switch (HOST_BITS_PER_WIDE_INT
)
8790 return DW_FORM_data2
;
8792 return DW_FORM_data4
;
8794 return DW_FORM_data8
;
8797 return DW_FORM_block1
;
8799 case dw_val_class_wide_int
:
8800 switch (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
)
8803 return DW_FORM_data1
;
8805 return DW_FORM_data2
;
8807 return DW_FORM_data4
;
8809 return DW_FORM_data8
;
8811 return DW_FORM_block1
;
8813 case dw_val_class_vec
:
8814 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
8815 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
8818 return DW_FORM_block1
;
8820 return DW_FORM_block2
;
8822 return DW_FORM_block4
;
8826 case dw_val_class_flag
:
8827 if (dwarf_version
>= 4)
8829 /* Currently all add_AT_flag calls pass in 1 as last argument,
8830 so DW_FORM_flag_present can be used. If that ever changes,
8831 we'll need to use DW_FORM_flag and have some optimization
8832 in build_abbrev_table that will change those to
8833 DW_FORM_flag_present if it is set to 1 in all DIEs using
8834 the same abbrev entry. */
8835 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8836 return DW_FORM_flag_present
;
8838 return DW_FORM_flag
;
8839 case dw_val_class_die_ref
:
8840 if (AT_ref_external (a
))
8841 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8844 case dw_val_class_fde_ref
:
8845 return DW_FORM_data
;
8846 case dw_val_class_lbl_id
:
8847 return (AT_index (a
) == NOT_INDEXED
8848 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8849 case dw_val_class_lineptr
:
8850 case dw_val_class_macptr
:
8851 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8852 case dw_val_class_str
:
8853 return AT_string_form (a
);
8854 case dw_val_class_file
:
8855 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8858 return DW_FORM_data1
;
8860 return DW_FORM_data2
;
8862 return DW_FORM_data4
;
8867 case dw_val_class_data8
:
8868 return DW_FORM_data8
;
8870 case dw_val_class_high_pc
:
8871 switch (DWARF2_ADDR_SIZE
)
8874 return DW_FORM_data1
;
8876 return DW_FORM_data2
;
8878 return DW_FORM_data4
;
8880 return DW_FORM_data8
;
8885 case dw_val_class_discr_value
:
8886 return (a
->dw_attr_val
.v
.val_discr_value
.pos
8889 case dw_val_class_discr_list
:
8890 switch (constant_size (size_of_discr_list (AT_discr_list (a
))))
8893 return DW_FORM_block1
;
8895 return DW_FORM_block2
;
8897 return DW_FORM_block4
;
8907 /* Output the encoding of an attribute value. */
8910 output_value_format (dw_attr_node
*a
)
8912 enum dwarf_form form
= value_format (a
);
8914 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8917 /* Given a die and id, produce the appropriate abbreviations. */
8920 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8923 dw_attr_node
*a_attr
;
8925 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8926 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8927 dwarf_tag_name (abbrev
->die_tag
));
8929 if (abbrev
->die_child
!= NULL
)
8930 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8932 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8934 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8936 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8937 dwarf_attr_name (a_attr
->dw_attr
));
8938 output_value_format (a_attr
);
8941 dw2_asm_output_data (1, 0, NULL
);
8942 dw2_asm_output_data (1, 0, NULL
);
8946 /* Output the .debug_abbrev section which defines the DIE abbreviation
8950 output_abbrev_section (void)
8952 unsigned long abbrev_id
;
8954 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8955 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8957 /* Terminate the table. */
8958 dw2_asm_output_data (1, 0, NULL
);
8961 /* Output a symbol we can use to refer to this DIE from another CU. */
8964 output_die_symbol (dw_die_ref die
)
8966 const char *sym
= die
->die_id
.die_symbol
;
8968 gcc_assert (!die
->comdat_type_p
);
8973 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8974 /* We make these global, not weak; if the target doesn't support
8975 .linkonce, it doesn't support combining the sections, so debugging
8977 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8979 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8982 /* Return a new location list, given the begin and end range, and the
8985 static inline dw_loc_list_ref
8986 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8987 const char *section
)
8989 dw_loc_list_ref retlist
= ggc_cleared_alloc
<dw_loc_list_node
> ();
8991 retlist
->begin
= begin
;
8992 retlist
->begin_entry
= NULL
;
8994 retlist
->expr
= expr
;
8995 retlist
->section
= section
;
9000 /* Generate a new internal symbol for this location list node, if it
9001 hasn't got one yet. */
9004 gen_llsym (dw_loc_list_ref list
)
9006 gcc_assert (!list
->ll_symbol
);
9007 list
->ll_symbol
= gen_internal_sym ("LLST");
9010 /* Output the location list given to us. */
9013 output_loc_list (dw_loc_list_ref list_head
)
9015 dw_loc_list_ref curr
= list_head
;
9017 if (list_head
->emitted
)
9019 list_head
->emitted
= true;
9021 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
9023 /* Walk the location list, and output each range + expression. */
9024 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
9027 /* Don't output an entry that starts and ends at the same address. */
9028 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
9030 size
= size_of_locs (curr
->expr
);
9031 /* If the expression is too large, drop it on the floor. We could
9032 perhaps put it into DW_TAG_dwarf_procedure and refer to that
9033 in the expression, but >= 64KB expressions for a single value
9034 in a single range are unlikely very useful. */
9037 if (dwarf_split_debug_info
)
9039 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
9040 "Location list start/length entry (%s)",
9041 list_head
->ll_symbol
);
9042 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
9043 "Location list range start index (%s)",
9045 /* The length field is 4 bytes. If we ever need to support
9046 an 8-byte length, we can add a new DW_LLE code or fall back
9047 to DW_LLE_GNU_start_end_entry. */
9048 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
9049 "Location list range length (%s)",
9050 list_head
->ll_symbol
);
9052 else if (!have_multiple_function_sections
)
9054 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
9055 "Location list begin address (%s)",
9056 list_head
->ll_symbol
);
9057 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
9058 "Location list end address (%s)",
9059 list_head
->ll_symbol
);
9063 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
9064 "Location list begin address (%s)",
9065 list_head
->ll_symbol
);
9066 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
9067 "Location list end address (%s)",
9068 list_head
->ll_symbol
);
9071 /* Output the block length for this list of location operations. */
9072 gcc_assert (size
<= 0xffff);
9073 dw2_asm_output_data (2, size
, "%s", "Location expression size");
9075 output_loc_sequence (curr
->expr
, -1);
9078 if (dwarf_split_debug_info
)
9079 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
9080 "Location list terminator (%s)",
9081 list_head
->ll_symbol
);
9084 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
9085 "Location list terminator begin (%s)",
9086 list_head
->ll_symbol
);
9087 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
9088 "Location list terminator end (%s)",
9089 list_head
->ll_symbol
);
9093 /* Output a range_list offset into the debug_range section. Emit a
9094 relocated reference if val_entry is NULL, otherwise, emit an
9095 indirect reference. */
9098 output_range_list_offset (dw_attr_node
*a
)
9100 const char *name
= dwarf_attr_name (a
->dw_attr
);
9102 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
9104 char *p
= strchr (ranges_section_label
, '\0');
9105 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
9106 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
9107 debug_ranges_section
, "%s", name
);
9111 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
9112 "%s (offset from %s)", name
, ranges_section_label
);
9115 /* Output the offset into the debug_loc section. */
9118 output_loc_list_offset (dw_attr_node
*a
)
9120 char *sym
= AT_loc_list (a
)->ll_symbol
;
9123 if (dwarf_split_debug_info
)
9124 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
9125 "%s", dwarf_attr_name (a
->dw_attr
));
9127 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
9128 "%s", dwarf_attr_name (a
->dw_attr
));
9131 /* Output an attribute's index or value appropriately. */
9134 output_attr_index_or_value (dw_attr_node
*a
)
9136 const char *name
= dwarf_attr_name (a
->dw_attr
);
9138 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
9140 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
9143 switch (AT_class (a
))
9145 case dw_val_class_addr
:
9146 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
9148 case dw_val_class_high_pc
:
9149 case dw_val_class_lbl_id
:
9150 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
9152 case dw_val_class_loc_list
:
9153 output_loc_list_offset (a
);
9160 /* Output a type signature. */
9163 output_signature (const char *sig
, const char *name
)
9167 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9168 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
9171 /* Output a discriminant value. */
9174 output_discr_value (dw_discr_value
*discr_value
, const char *name
)
9176 if (discr_value
->pos
)
9177 dw2_asm_output_data_uleb128 (discr_value
->v
.uval
, "%s", name
);
9179 dw2_asm_output_data_sleb128 (discr_value
->v
.sval
, "%s", name
);
9182 /* Output the DIE and its attributes. Called recursively to generate
9183 the definitions of each child DIE. */
9186 output_die (dw_die_ref die
)
9193 /* If someone in another CU might refer to us, set up a symbol for
9194 them to point to. */
9195 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
9196 output_die_symbol (die
);
9198 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
9199 (unsigned long)die
->die_offset
,
9200 dwarf_tag_name (die
->die_tag
));
9202 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9204 const char *name
= dwarf_attr_name (a
->dw_attr
);
9206 switch (AT_class (a
))
9208 case dw_val_class_addr
:
9209 output_attr_index_or_value (a
);
9212 case dw_val_class_offset
:
9213 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
9217 case dw_val_class_range_list
:
9218 output_range_list_offset (a
);
9221 case dw_val_class_loc
:
9222 size
= size_of_locs (AT_loc (a
));
9224 /* Output the block length for this list of location operations. */
9225 if (dwarf_version
>= 4)
9226 dw2_asm_output_data_uleb128 (size
, "%s", name
);
9228 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
9230 output_loc_sequence (AT_loc (a
), -1);
9233 case dw_val_class_const
:
9234 /* ??? It would be slightly more efficient to use a scheme like is
9235 used for unsigned constants below, but gdb 4.x does not sign
9236 extend. Gdb 5.x does sign extend. */
9237 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
9240 case dw_val_class_unsigned_const
:
9242 int csize
= constant_size (AT_unsigned (a
));
9243 if (dwarf_version
== 3
9244 && a
->dw_attr
== DW_AT_data_member_location
9246 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
9248 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
9252 case dw_val_class_const_double
:
9254 unsigned HOST_WIDE_INT first
, second
;
9256 if (HOST_BITS_PER_WIDE_INT
>= 64)
9257 dw2_asm_output_data (1,
9258 HOST_BITS_PER_DOUBLE_INT
9259 / HOST_BITS_PER_CHAR
,
9262 if (WORDS_BIG_ENDIAN
)
9264 first
= a
->dw_attr_val
.v
.val_double
.high
;
9265 second
= a
->dw_attr_val
.v
.val_double
.low
;
9269 first
= a
->dw_attr_val
.v
.val_double
.low
;
9270 second
= a
->dw_attr_val
.v
.val_double
.high
;
9273 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
9275 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
9280 case dw_val_class_wide_int
:
9283 int len
= get_full_len (*a
->dw_attr_val
.v
.val_wide
);
9284 int l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
9285 if (len
* HOST_BITS_PER_WIDE_INT
> 64)
9286 dw2_asm_output_data (1, get_full_len (*a
->dw_attr_val
.v
.val_wide
) * l
,
9289 if (WORDS_BIG_ENDIAN
)
9290 for (i
= len
- 1; i
>= 0; --i
)
9292 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
9297 for (i
= 0; i
< len
; ++i
)
9299 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
9306 case dw_val_class_vec
:
9308 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
9309 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
9313 dw2_asm_output_data (constant_size (len
* elt_size
),
9314 len
* elt_size
, "%s", name
);
9315 if (elt_size
> sizeof (HOST_WIDE_INT
))
9320 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
9323 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
9324 "fp or vector constant word %u", i
);
9328 case dw_val_class_flag
:
9329 if (dwarf_version
>= 4)
9331 /* Currently all add_AT_flag calls pass in 1 as last argument,
9332 so DW_FORM_flag_present can be used. If that ever changes,
9333 we'll need to use DW_FORM_flag and have some optimization
9334 in build_abbrev_table that will change those to
9335 DW_FORM_flag_present if it is set to 1 in all DIEs using
9336 the same abbrev entry. */
9337 gcc_assert (AT_flag (a
) == 1);
9339 fprintf (asm_out_file
, "\t\t\t%s %s\n",
9340 ASM_COMMENT_START
, name
);
9343 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
9346 case dw_val_class_loc_list
:
9347 output_attr_index_or_value (a
);
9350 case dw_val_class_die_ref
:
9351 if (AT_ref_external (a
))
9353 if (AT_ref (a
)->comdat_type_p
)
9355 comdat_type_node
*type_node
=
9356 AT_ref (a
)->die_id
.die_type_node
;
9358 gcc_assert (type_node
);
9359 output_signature (type_node
->signature
, name
);
9363 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
9367 /* In DWARF2, DW_FORM_ref_addr is sized by target address
9368 length, whereas in DWARF3 it's always sized as an
9370 if (dwarf_version
== 2)
9371 size
= DWARF2_ADDR_SIZE
;
9373 size
= DWARF_OFFSET_SIZE
;
9374 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
9380 gcc_assert (AT_ref (a
)->die_offset
);
9381 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
9386 case dw_val_class_fde_ref
:
9390 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
9391 a
->dw_attr_val
.v
.val_fde_index
* 2);
9392 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
9397 case dw_val_class_vms_delta
:
9398 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
9399 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
9400 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
9403 dw2_asm_output_delta (DWARF_OFFSET_SIZE
,
9404 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
9409 case dw_val_class_lbl_id
:
9410 output_attr_index_or_value (a
);
9413 case dw_val_class_lineptr
:
9414 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
9415 debug_line_section
, "%s", name
);
9418 case dw_val_class_macptr
:
9419 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
9420 debug_macinfo_section
, "%s", name
);
9423 case dw_val_class_str
:
9424 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
9425 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
9426 a
->dw_attr_val
.v
.val_str
->label
,
9428 "%s: \"%s\"", name
, AT_string (a
));
9429 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
9430 dw2_asm_output_data_uleb128 (AT_index (a
),
9431 "%s: \"%s\"", name
, AT_string (a
));
9433 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
9436 case dw_val_class_file
:
9438 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
9440 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
9441 a
->dw_attr_val
.v
.val_file
->filename
);
9445 case dw_val_class_data8
:
9449 for (i
= 0; i
< 8; i
++)
9450 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
9451 i
== 0 ? "%s" : NULL
, name
);
9455 case dw_val_class_high_pc
:
9456 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
9457 get_AT_low_pc (die
), "DW_AT_high_pc");
9460 case dw_val_class_discr_value
:
9461 output_discr_value (&a
->dw_attr_val
.v
.val_discr_value
, name
);
9464 case dw_val_class_discr_list
:
9466 dw_discr_list_ref list
= AT_discr_list (a
);
9467 const int size
= size_of_discr_list (list
);
9469 /* This is a block, so output its length first. */
9470 dw2_asm_output_data (constant_size (size
), size
,
9471 "%s: block size", name
);
9473 for (; list
!= NULL
; list
= list
->dw_discr_next
)
9475 /* One byte for the discriminant value descriptor, and then as
9476 many LEB128 numbers as required. */
9477 if (list
->dw_discr_range
)
9478 dw2_asm_output_data (1, DW_DSC_range
,
9479 "%s: DW_DSC_range", name
);
9481 dw2_asm_output_data (1, DW_DSC_label
,
9482 "%s: DW_DSC_label", name
);
9484 output_discr_value (&list
->dw_discr_lower_bound
, name
);
9485 if (list
->dw_discr_range
)
9486 output_discr_value (&list
->dw_discr_upper_bound
, name
);
9496 FOR_EACH_CHILD (die
, c
, output_die (c
));
9498 /* Add null byte to terminate sibling list. */
9499 if (die
->die_child
!= NULL
)
9500 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
9501 (unsigned long) die
->die_offset
);
9504 /* Output the compilation unit that appears at the beginning of the
9505 .debug_info section, and precedes the DIE descriptions. */
9508 output_compilation_unit_header (void)
9510 /* We don't support actual DWARFv5 units yet, we just use some
9511 DWARFv5 draft DIE tags in DWARFv4 format. */
9512 int ver
= dwarf_version
< 5 ? dwarf_version
: 4;
9514 if (!XCOFF_DEBUGGING_INFO
)
9516 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9517 dw2_asm_output_data (4, 0xffffffff,
9518 "Initial length escape value indicating 64-bit DWARF extension");
9519 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9520 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
9521 "Length of Compilation Unit Info");
9524 dw2_asm_output_data (2, ver
, "DWARF version number");
9525 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
9526 debug_abbrev_section
,
9527 "Offset Into Abbrev. Section");
9528 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9531 /* Output the compilation unit DIE and its children. */
9534 output_comp_unit (dw_die_ref die
, int output_if_empty
)
9536 const char *secname
, *oldsym
;
9539 /* Unless we are outputting main CU, we may throw away empty ones. */
9540 if (!output_if_empty
&& die
->die_child
== NULL
)
9543 /* Even if there are no children of this DIE, we must output the information
9544 about the compilation unit. Otherwise, on an empty translation unit, we
9545 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
9546 will then complain when examining the file. First mark all the DIEs in
9547 this CU so we know which get local refs. */
9550 external_ref_hash_type
*extern_map
= optimize_external_refs (die
);
9552 build_abbrev_table (die
, extern_map
);
9556 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9557 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
9558 calc_die_sizes (die
);
9560 oldsym
= die
->die_id
.die_symbol
;
9563 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
9565 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
9567 die
->die_id
.die_symbol
= NULL
;
9568 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9572 switch_to_section (debug_info_section
);
9573 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
9574 info_section_emitted
= true;
9577 /* Output debugging information. */
9578 output_compilation_unit_header ();
9581 /* Leave the marks on the main CU, so we can check them in
9586 die
->die_id
.die_symbol
= oldsym
;
9590 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
9591 and .debug_pubtypes. This is configured per-target, but can be
9592 overridden by the -gpubnames or -gno-pubnames options. */
9595 want_pubnames (void)
9597 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9599 if (debug_generate_pub_sections
!= -1)
9600 return debug_generate_pub_sections
;
9601 return targetm
.want_debug_pub_sections
;
9604 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
9607 add_AT_pubnames (dw_die_ref die
)
9609 if (want_pubnames ())
9610 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
9613 /* Add a string attribute value to a skeleton DIE. */
9616 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
9620 struct indirect_string_node
*node
;
9622 if (! skeleton_debug_str_hash
)
9623 skeleton_debug_str_hash
9624 = hash_table
<indirect_string_hasher
>::create_ggc (10);
9626 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
9627 find_string_form (node
);
9628 if (node
->form
== DW_FORM_GNU_str_index
)
9629 node
->form
= DW_FORM_strp
;
9631 attr
.dw_attr
= attr_kind
;
9632 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
9633 attr
.dw_attr_val
.val_entry
= NULL
;
9634 attr
.dw_attr_val
.v
.val_str
= node
;
9635 add_dwarf_attr (die
, &attr
);
9638 /* Helper function to generate top-level dies for skeleton debug_info and
9642 add_top_level_skeleton_die_attrs (dw_die_ref die
)
9644 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
9645 const char *comp_dir
= comp_dir_string ();
9647 add_skeleton_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
9648 if (comp_dir
!= NULL
)
9649 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
9650 add_AT_pubnames (die
);
9651 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
9654 /* Output skeleton debug sections that point to the dwo file. */
9657 output_skeleton_debug_sections (dw_die_ref comp_unit
)
9659 /* We don't support actual DWARFv5 units yet, we just use some
9660 DWARFv5 draft DIE tags in DWARFv4 format. */
9661 int ver
= dwarf_version
< 5 ? dwarf_version
: 4;
9663 /* These attributes will be found in the full debug_info section. */
9664 remove_AT (comp_unit
, DW_AT_producer
);
9665 remove_AT (comp_unit
, DW_AT_language
);
9667 switch_to_section (debug_skeleton_info_section
);
9668 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
9670 /* Produce the skeleton compilation-unit header. This one differs enough from
9671 a normal CU header that it's better not to call output_compilation_unit
9673 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9674 dw2_asm_output_data (4, 0xffffffff,
9675 "Initial length escape value indicating 64-bit DWARF extension");
9677 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9678 DWARF_COMPILE_UNIT_HEADER_SIZE
9679 - DWARF_INITIAL_LENGTH_SIZE
9680 + size_of_die (comp_unit
),
9681 "Length of Compilation Unit Info");
9682 dw2_asm_output_data (2, ver
, "DWARF version number");
9683 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
9684 debug_abbrev_section
,
9685 "Offset Into Abbrev. Section");
9686 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9688 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
9689 output_die (comp_unit
);
9691 /* Build the skeleton debug_abbrev section. */
9692 switch_to_section (debug_skeleton_abbrev_section
);
9693 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
9695 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
9697 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
9700 /* Output a comdat type unit DIE and its children. */
9703 output_comdat_type_unit (comdat_type_node
*node
)
9705 const char *secname
;
9708 #if defined (OBJECT_FORMAT_ELF)
9712 /* First mark all the DIEs in this CU so we know which get local refs. */
9713 mark_dies (node
->root_die
);
9715 external_ref_hash_type
*extern_map
= optimize_external_refs (node
->root_die
);
9717 build_abbrev_table (node
->root_die
, extern_map
);
9722 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9723 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
9724 calc_die_sizes (node
->root_die
);
9726 #if defined (OBJECT_FORMAT_ELF)
9727 if (!dwarf_split_debug_info
)
9728 secname
= ".debug_types";
9730 secname
= ".debug_types.dwo";
9732 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9733 sprintf (tmp
, "wt.");
9734 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9735 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9736 comdat_key
= get_identifier (tmp
);
9737 targetm
.asm_out
.named_section (secname
,
9738 SECTION_DEBUG
| SECTION_LINKONCE
,
9741 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9742 sprintf (tmp
, ".gnu.linkonce.wt.");
9743 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9744 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9746 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9749 /* Output debugging information. */
9750 output_compilation_unit_header ();
9751 output_signature (node
->signature
, "Type Signature");
9752 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
9753 "Offset to Type DIE");
9754 output_die (node
->root_die
);
9756 unmark_dies (node
->root_die
);
9759 /* Return the DWARF2/3 pubname associated with a decl. */
9762 dwarf2_name (tree decl
, int scope
)
9764 if (DECL_NAMELESS (decl
))
9766 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
9769 /* Add a new entry to .debug_pubnames if appropriate. */
9772 add_pubname_string (const char *str
, dw_die_ref die
)
9777 e
.name
= xstrdup (str
);
9778 vec_safe_push (pubname_table
, e
);
9782 add_pubname (tree decl
, dw_die_ref die
)
9784 if (!want_pubnames ())
9787 /* Don't add items to the table when we expect that the consumer will have
9788 just read the enclosing die. For example, if the consumer is looking at a
9789 class_member, it will either be inside the class already, or will have just
9790 looked up the class to find the member. Either way, searching the class is
9791 faster than searching the index. */
9792 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
9793 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9795 const char *name
= dwarf2_name (decl
, 1);
9798 add_pubname_string (name
, die
);
9802 /* Add an enumerator to the pubnames section. */
9805 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
9809 gcc_assert (scope_name
);
9810 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
9812 vec_safe_push (pubname_table
, e
);
9815 /* Add a new entry to .debug_pubtypes if appropriate. */
9818 add_pubtype (tree decl
, dw_die_ref die
)
9822 if (!want_pubnames ())
9825 if ((TREE_PUBLIC (decl
)
9826 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9827 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
9830 const char *scope_name
= "";
9831 const char *sep
= is_cxx () ? "::" : ".";
9834 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
9835 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
9837 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
9838 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
9839 scope_name
= concat (scope_name
, sep
, NULL
);
9845 name
= type_tag (decl
);
9847 name
= lang_hooks
.dwarf_name (decl
, 1);
9849 /* If we don't have a name for the type, there's no point in adding
9851 if (name
!= NULL
&& name
[0] != '\0')
9854 e
.name
= concat (scope_name
, name
, NULL
);
9855 vec_safe_push (pubtype_table
, e
);
9858 /* Although it might be more consistent to add the pubinfo for the
9859 enumerators as their dies are created, they should only be added if the
9860 enum type meets the criteria above. So rather than re-check the parent
9861 enum type whenever an enumerator die is created, just output them all
9862 here. This isn't protected by the name conditional because anonymous
9863 enums don't have names. */
9864 if (die
->die_tag
== DW_TAG_enumeration_type
)
9868 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
9873 /* Output a single entry in the pubnames table. */
9876 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
9878 dw_die_ref die
= entry
->die
;
9879 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
9881 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9883 if (debug_generate_pub_sections
== 2)
9885 /* This logic follows gdb's method for determining the value of the flag
9887 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
9888 switch (die
->die_tag
)
9890 case DW_TAG_typedef
:
9891 case DW_TAG_base_type
:
9892 case DW_TAG_subrange_type
:
9893 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9894 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9896 case DW_TAG_enumerator
:
9897 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9898 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9899 if (!is_cxx () && !is_java ())
9900 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9902 case DW_TAG_subprogram
:
9903 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9904 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
9906 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9908 case DW_TAG_constant
:
9909 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9910 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9911 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9913 case DW_TAG_variable
:
9914 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9915 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9916 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9918 case DW_TAG_namespace
:
9919 case DW_TAG_imported_declaration
:
9920 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9922 case DW_TAG_class_type
:
9923 case DW_TAG_interface_type
:
9924 case DW_TAG_structure_type
:
9925 case DW_TAG_union_type
:
9926 case DW_TAG_enumeration_type
:
9927 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9928 if (!is_cxx () && !is_java ())
9929 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9932 /* An unusual tag. Leave the flag-byte empty. */
9935 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
9939 dw2_asm_output_nstring (entry
->name
, -1, "external name");
9943 /* Output the public names table used to speed up access to externally
9944 visible names; or the public types table used to find type definitions. */
9947 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9950 unsigned long pubnames_length
= size_of_pubnames (names
);
9953 if (!XCOFF_DEBUGGING_INFO
)
9955 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9956 dw2_asm_output_data (4, 0xffffffff,
9957 "Initial length escape value indicating 64-bit DWARF extension");
9958 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
9962 /* Version number for pubnames/pubtypes is independent of dwarf version. */
9963 dw2_asm_output_data (2, 2, "DWARF Version");
9965 if (dwarf_split_debug_info
)
9966 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9967 debug_skeleton_info_section
,
9968 "Offset of Compilation Unit Info");
9970 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9972 "Offset of Compilation Unit Info");
9973 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
9974 "Compilation Unit Length");
9976 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9978 if (include_pubname_in_output (names
, pub
))
9980 dw_offset die_offset
= pub
->die
->die_offset
;
9982 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9983 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
9984 gcc_assert (pub
->die
->die_mark
);
9986 /* If we're putting types in their own .debug_types sections,
9987 the .debug_pubtypes table will still point to the compile
9988 unit (not the type unit), so we want to use the offset of
9989 the skeleton DIE (if there is one). */
9990 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9992 comdat_type_node
*type_node
= pub
->die
->die_id
.die_type_node
;
9994 if (type_node
!= NULL
)
9995 die_offset
= (type_node
->skeleton_die
!= NULL
9996 ? type_node
->skeleton_die
->die_offset
9997 : comp_unit_die ()->die_offset
);
10000 output_pubname (die_offset
, pub
);
10004 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
10007 /* Output public names and types tables if necessary. */
10010 output_pubtables (void)
10012 if (!want_pubnames () || !info_section_emitted
)
10015 switch_to_section (debug_pubnames_section
);
10016 output_pubnames (pubname_table
);
10017 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
10018 It shouldn't hurt to emit it always, since pure DWARF2 consumers
10019 simply won't look for the section. */
10020 switch_to_section (debug_pubtypes_section
);
10021 output_pubnames (pubtype_table
);
10025 /* Output the information that goes into the .debug_aranges table.
10026 Namely, define the beginning and ending address range of the
10027 text section generated for this compilation unit. */
10030 output_aranges (void)
10033 unsigned long aranges_length
= size_of_aranges ();
10035 if (!XCOFF_DEBUGGING_INFO
)
10037 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10038 dw2_asm_output_data (4, 0xffffffff,
10039 "Initial length escape value indicating 64-bit DWARF extension");
10040 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
10041 "Length of Address Ranges Info");
10044 /* Version number for aranges is still 2, even up to DWARF5. */
10045 dw2_asm_output_data (2, 2, "DWARF Version");
10046 if (dwarf_split_debug_info
)
10047 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
10048 debug_skeleton_info_section
,
10049 "Offset of Compilation Unit Info");
10051 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
10052 debug_info_section
,
10053 "Offset of Compilation Unit Info");
10054 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
10055 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
10057 /* We need to align to twice the pointer size here. */
10058 if (DWARF_ARANGES_PAD_SIZE
)
10060 /* Pad using a 2 byte words so that padding is correct for any
10062 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
10063 2 * DWARF2_ADDR_SIZE
);
10064 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
10065 dw2_asm_output_data (2, 0, NULL
);
10068 /* It is necessary not to output these entries if the sections were
10069 not used; if the sections were not used, the length will be 0 and
10070 the address may end up as 0 if the section is discarded by ld
10071 --gc-sections, leaving an invalid (0, 0) entry that can be
10072 confused with the terminator. */
10073 if (text_section_used
)
10075 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
10076 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
10077 text_section_label
, "Length");
10079 if (cold_text_section_used
)
10081 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
10083 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
10084 cold_text_section_label
, "Length");
10087 if (have_multiple_function_sections
)
10092 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
10094 if (DECL_IGNORED_P (fde
->decl
))
10096 if (!fde
->in_std_section
)
10098 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
10100 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
10101 fde
->dw_fde_begin
, "Length");
10103 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
10105 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
10107 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
10108 fde
->dw_fde_second_begin
, "Length");
10113 /* Output the terminator words. */
10114 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
10115 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
10118 /* Add a new entry to .debug_ranges. Return the offset at which it
10121 static unsigned int
10122 add_ranges_num (int num
)
10124 unsigned int in_use
= ranges_table_in_use
;
10126 if (in_use
== ranges_table_allocated
)
10128 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
10129 ranges_table
= GGC_RESIZEVEC (dw_ranges
, ranges_table
,
10130 ranges_table_allocated
);
10131 memset (ranges_table
+ ranges_table_in_use
, 0,
10132 RANGES_TABLE_INCREMENT
* sizeof (dw_ranges
));
10135 ranges_table
[in_use
].num
= num
;
10136 ranges_table_in_use
= in_use
+ 1;
10138 return in_use
* 2 * DWARF2_ADDR_SIZE
;
10141 /* Add a new entry to .debug_ranges corresponding to a block, or a
10142 range terminator if BLOCK is NULL. */
10144 static unsigned int
10145 add_ranges (const_tree block
)
10147 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
10150 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
10151 When using dwarf_split_debug_info, address attributes in dies destined
10152 for the final executable should be direct references--setting the
10153 parameter force_direct ensures this behavior. */
10156 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
10157 bool *added
, bool force_direct
)
10159 unsigned int in_use
= ranges_by_label_in_use
;
10160 unsigned int offset
;
10162 if (in_use
== ranges_by_label_allocated
)
10164 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
10165 ranges_by_label
= GGC_RESIZEVEC (dw_ranges_by_label
, ranges_by_label
,
10166 ranges_by_label_allocated
);
10167 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
10168 RANGES_TABLE_INCREMENT
* sizeof (dw_ranges_by_label
));
10171 ranges_by_label
[in_use
].begin
= begin
;
10172 ranges_by_label
[in_use
].end
= end
;
10173 ranges_by_label_in_use
= in_use
+ 1;
10175 offset
= add_ranges_num (-(int)in_use
- 1);
10178 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
10184 output_ranges (void)
10187 static const char *const start_fmt
= "Offset %#x";
10188 const char *fmt
= start_fmt
;
10190 for (i
= 0; i
< ranges_table_in_use
; i
++)
10192 int block_num
= ranges_table
[i
].num
;
10196 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
10197 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
10199 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
10200 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
10202 /* If all code is in the text section, then the compilation
10203 unit base address defaults to DW_AT_low_pc, which is the
10204 base of the text section. */
10205 if (!have_multiple_function_sections
)
10207 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
10208 text_section_label
,
10209 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
10210 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
10211 text_section_label
, NULL
);
10214 /* Otherwise, the compilation unit base address is zero,
10215 which allows us to use absolute addresses, and not worry
10216 about whether the target supports cross-section
10220 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
10221 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
10222 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
10228 /* Negative block_num stands for an index into ranges_by_label. */
10229 else if (block_num
< 0)
10231 int lab_idx
= - block_num
- 1;
10233 if (!have_multiple_function_sections
)
10235 gcc_unreachable ();
10237 /* If we ever use add_ranges_by_labels () for a single
10238 function section, all we have to do is to take out
10239 the #if 0 above. */
10240 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
10241 ranges_by_label
[lab_idx
].begin
,
10242 text_section_label
,
10243 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
10244 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
10245 ranges_by_label
[lab_idx
].end
,
10246 text_section_label
, NULL
);
10251 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
10252 ranges_by_label
[lab_idx
].begin
,
10253 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
10254 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
10255 ranges_by_label
[lab_idx
].end
,
10261 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
10262 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
10268 /* Data structure containing information about input files. */
10271 const char *path
; /* Complete file name. */
10272 const char *fname
; /* File name part. */
10273 int length
; /* Length of entire string. */
10274 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
10275 int dir_idx
; /* Index in directory table. */
10278 /* Data structure containing information about directories with source
10282 const char *path
; /* Path including directory name. */
10283 int length
; /* Path length. */
10284 int prefix
; /* Index of directory entry which is a prefix. */
10285 int count
; /* Number of files in this directory. */
10286 int dir_idx
; /* Index of directory used as base. */
10289 /* Callback function for file_info comparison. We sort by looking at
10290 the directories in the path. */
10293 file_info_cmp (const void *p1
, const void *p2
)
10295 const struct file_info
*const s1
= (const struct file_info
*) p1
;
10296 const struct file_info
*const s2
= (const struct file_info
*) p2
;
10297 const unsigned char *cp1
;
10298 const unsigned char *cp2
;
10300 /* Take care of file names without directories. We need to make sure that
10301 we return consistent values to qsort since some will get confused if
10302 we return the same value when identical operands are passed in opposite
10303 orders. So if neither has a directory, return 0 and otherwise return
10304 1 or -1 depending on which one has the directory. */
10305 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
10306 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
10308 cp1
= (const unsigned char *) s1
->path
;
10309 cp2
= (const unsigned char *) s2
->path
;
10315 /* Reached the end of the first path? If so, handle like above. */
10316 if ((cp1
== (const unsigned char *) s1
->fname
)
10317 || (cp2
== (const unsigned char *) s2
->fname
))
10318 return ((cp2
== (const unsigned char *) s2
->fname
)
10319 - (cp1
== (const unsigned char *) s1
->fname
));
10321 /* Character of current path component the same? */
10322 else if (*cp1
!= *cp2
)
10323 return *cp1
- *cp2
;
10327 struct file_name_acquire_data
10329 struct file_info
*files
;
10334 /* Traversal function for the hash table. */
10337 file_name_acquire (dwarf_file_data
**slot
, file_name_acquire_data
*fnad
)
10339 struct dwarf_file_data
*d
= *slot
;
10340 struct file_info
*fi
;
10343 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
10345 if (! d
->emitted_number
)
10348 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
10350 fi
= fnad
->files
+ fnad
->used_files
++;
10352 /* Skip all leading "./". */
10354 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
10357 /* Create a new array entry. */
10359 fi
->length
= strlen (f
);
10362 /* Search for the file name part. */
10363 f
= strrchr (f
, DIR_SEPARATOR
);
10364 #if defined (DIR_SEPARATOR_2)
10366 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
10370 if (f
== NULL
|| f
< g
)
10376 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
10380 /* Output the directory table and the file name table. We try to minimize
10381 the total amount of memory needed. A heuristic is used to avoid large
10382 slowdowns with many input files. */
10385 output_file_names (void)
10387 struct file_name_acquire_data fnad
;
10389 struct file_info
*files
;
10390 struct dir_info
*dirs
;
10398 if (!last_emitted_file
)
10400 dw2_asm_output_data (1, 0, "End directory table");
10401 dw2_asm_output_data (1, 0, "End file name table");
10405 numfiles
= last_emitted_file
->emitted_number
;
10407 /* Allocate the various arrays we need. */
10408 files
= XALLOCAVEC (struct file_info
, numfiles
);
10409 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
10411 fnad
.files
= files
;
10412 fnad
.used_files
= 0;
10413 fnad
.max_files
= numfiles
;
10414 file_table
->traverse
<file_name_acquire_data
*, file_name_acquire
> (&fnad
);
10415 gcc_assert (fnad
.used_files
== fnad
.max_files
);
10417 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
10419 /* Find all the different directories used. */
10420 dirs
[0].path
= files
[0].path
;
10421 dirs
[0].length
= files
[0].fname
- files
[0].path
;
10422 dirs
[0].prefix
= -1;
10424 dirs
[0].dir_idx
= 0;
10425 files
[0].dir_idx
= 0;
10428 for (i
= 1; i
< numfiles
; i
++)
10429 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
10430 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
10431 dirs
[ndirs
- 1].length
) == 0)
10433 /* Same directory as last entry. */
10434 files
[i
].dir_idx
= ndirs
- 1;
10435 ++dirs
[ndirs
- 1].count
;
10441 /* This is a new directory. */
10442 dirs
[ndirs
].path
= files
[i
].path
;
10443 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
10444 dirs
[ndirs
].count
= 1;
10445 dirs
[ndirs
].dir_idx
= ndirs
;
10446 files
[i
].dir_idx
= ndirs
;
10448 /* Search for a prefix. */
10449 dirs
[ndirs
].prefix
= -1;
10450 for (j
= 0; j
< ndirs
; j
++)
10451 if (dirs
[j
].length
< dirs
[ndirs
].length
10452 && dirs
[j
].length
> 1
10453 && (dirs
[ndirs
].prefix
== -1
10454 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
10455 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
10456 dirs
[ndirs
].prefix
= j
;
10461 /* Now to the actual work. We have to find a subset of the directories which
10462 allow expressing the file name using references to the directory table
10463 with the least amount of characters. We do not do an exhaustive search
10464 where we would have to check out every combination of every single
10465 possible prefix. Instead we use a heuristic which provides nearly optimal
10466 results in most cases and never is much off. */
10467 saved
= XALLOCAVEC (int, ndirs
);
10468 savehere
= XALLOCAVEC (int, ndirs
);
10470 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
10471 for (i
= 0; i
< ndirs
; i
++)
10476 /* We can always save some space for the current directory. But this
10477 does not mean it will be enough to justify adding the directory. */
10478 savehere
[i
] = dirs
[i
].length
;
10479 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
10481 for (j
= i
+ 1; j
< ndirs
; j
++)
10484 if (saved
[j
] < dirs
[i
].length
)
10486 /* Determine whether the dirs[i] path is a prefix of the
10490 k
= dirs
[j
].prefix
;
10491 while (k
!= -1 && k
!= (int) i
)
10492 k
= dirs
[k
].prefix
;
10496 /* Yes it is. We can possibly save some memory by
10497 writing the filenames in dirs[j] relative to
10499 savehere
[j
] = dirs
[i
].length
;
10500 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
10505 /* Check whether we can save enough to justify adding the dirs[i]
10507 if (total
> dirs
[i
].length
+ 1)
10509 /* It's worthwhile adding. */
10510 for (j
= i
; j
< ndirs
; j
++)
10511 if (savehere
[j
] > 0)
10513 /* Remember how much we saved for this directory so far. */
10514 saved
[j
] = savehere
[j
];
10516 /* Remember the prefix directory. */
10517 dirs
[j
].dir_idx
= i
;
10522 /* Emit the directory name table. */
10523 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
10524 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
10525 dw2_asm_output_nstring (dirs
[i
].path
,
10527 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
10528 "Directory Entry: %#x", i
+ idx_offset
);
10530 dw2_asm_output_data (1, 0, "End directory table");
10532 /* We have to emit them in the order of emitted_number since that's
10533 used in the debug info generation. To do this efficiently we
10534 generate a back-mapping of the indices first. */
10535 backmap
= XALLOCAVEC (int, numfiles
);
10536 for (i
= 0; i
< numfiles
; i
++)
10537 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
10539 /* Now write all the file names. */
10540 for (i
= 0; i
< numfiles
; i
++)
10542 int file_idx
= backmap
[i
];
10543 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
10545 #ifdef VMS_DEBUGGING_INFO
10546 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
10548 /* Setting these fields can lead to debugger miscomparisons,
10549 but VMS Debug requires them to be set correctly. */
10554 int maxfilelen
= strlen (files
[file_idx
].path
)
10555 + dirs
[dir_idx
].length
10556 + MAX_VMS_VERSION_LEN
+ 1;
10557 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
10559 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
10560 snprintf (filebuf
, maxfilelen
, "%s;%d",
10561 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
10563 dw2_asm_output_nstring
10564 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
10566 /* Include directory index. */
10567 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
10569 /* Modification time. */
10570 dw2_asm_output_data_uleb128
10571 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
10575 /* File length in bytes. */
10576 dw2_asm_output_data_uleb128
10577 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
10581 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
10582 "File Entry: %#x", (unsigned) i
+ 1);
10584 /* Include directory index. */
10585 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
10587 /* Modification time. */
10588 dw2_asm_output_data_uleb128 (0, NULL
);
10590 /* File length in bytes. */
10591 dw2_asm_output_data_uleb128 (0, NULL
);
10592 #endif /* VMS_DEBUGGING_INFO */
10595 dw2_asm_output_data (1, 0, "End file name table");
10599 /* Output one line number table into the .debug_line section. */
10602 output_one_line_info_table (dw_line_info_table
*table
)
10604 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10605 unsigned int current_line
= 1;
10606 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
10607 dw_line_info_entry
*ent
;
10610 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
10612 switch (ent
->opcode
)
10614 case LI_set_address
:
10615 /* ??? Unfortunately, we have little choice here currently, and
10616 must always use the most general form. GCC does not know the
10617 address delta itself, so we can't use DW_LNS_advance_pc. Many
10618 ports do have length attributes which will give an upper bound
10619 on the address range. We could perhaps use length attributes
10620 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
10621 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
10623 /* This can handle any delta. This takes
10624 4+DWARF2_ADDR_SIZE bytes. */
10625 dw2_asm_output_data (1, 0, "set address %s", line_label
);
10626 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10627 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10628 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
10632 if (ent
->val
== current_line
)
10634 /* We still need to start a new row, so output a copy insn. */
10635 dw2_asm_output_data (1, DW_LNS_copy
,
10636 "copy line %u", current_line
);
10640 int line_offset
= ent
->val
- current_line
;
10641 int line_delta
= line_offset
- DWARF_LINE_BASE
;
10643 current_line
= ent
->val
;
10644 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
10646 /* This can handle deltas from -10 to 234, using the current
10647 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
10648 This takes 1 byte. */
10649 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
10650 "line %u", current_line
);
10654 /* This can handle any delta. This takes at least 4 bytes,
10655 depending on the value being encoded. */
10656 dw2_asm_output_data (1, DW_LNS_advance_line
,
10657 "advance to line %u", current_line
);
10658 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
10659 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
10665 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
10666 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
10669 case LI_set_column
:
10670 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
10671 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
10674 case LI_negate_stmt
:
10675 current_is_stmt
= !current_is_stmt
;
10676 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
10677 "is_stmt %d", current_is_stmt
);
10680 case LI_set_prologue_end
:
10681 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
10682 "set prologue end");
10685 case LI_set_epilogue_begin
:
10686 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
10687 "set epilogue begin");
10690 case LI_set_discriminator
:
10691 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
10692 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
10693 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
10694 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
10699 /* Emit debug info for the address of the end of the table. */
10700 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
10701 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10702 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10703 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
10705 dw2_asm_output_data (1, 0, "end sequence");
10706 dw2_asm_output_data_uleb128 (1, NULL
);
10707 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
10710 /* Output the source line number correspondence information. This
10711 information goes into the .debug_line section. */
10714 output_line_info (bool prologue_only
)
10716 char l1
[20], l2
[20], p1
[20], p2
[20];
10717 /* We don't support DWARFv5 line tables yet. */
10718 int ver
= dwarf_version
< 5 ? dwarf_version
: 4;
10719 bool saw_one
= false;
10722 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
10723 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
10724 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
10725 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
10727 if (!XCOFF_DEBUGGING_INFO
)
10729 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10730 dw2_asm_output_data (4, 0xffffffff,
10731 "Initial length escape value indicating 64-bit DWARF extension");
10732 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
10733 "Length of Source Line Info");
10736 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
10738 dw2_asm_output_data (2, ver
, "DWARF Version");
10739 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
10740 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
10742 /* Define the architecture-dependent minimum instruction length (in bytes).
10743 In this implementation of DWARF, this field is used for information
10744 purposes only. Since GCC generates assembly language, we have no
10745 a priori knowledge of how many instruction bytes are generated for each
10746 source line, and therefore can use only the DW_LNE_set_address and
10747 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
10748 this as '1', which is "correct enough" for all architectures,
10749 and don't let the target override. */
10750 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
10753 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
10754 "Maximum Operations Per Instruction");
10755 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
10756 "Default is_stmt_start flag");
10757 dw2_asm_output_data (1, DWARF_LINE_BASE
,
10758 "Line Base Value (Special Opcodes)");
10759 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
10760 "Line Range Value (Special Opcodes)");
10761 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
10762 "Special Opcode Base");
10764 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
10769 case DW_LNS_advance_pc
:
10770 case DW_LNS_advance_line
:
10771 case DW_LNS_set_file
:
10772 case DW_LNS_set_column
:
10773 case DW_LNS_fixed_advance_pc
:
10774 case DW_LNS_set_isa
:
10782 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
10786 /* Write out the information about the files we use. */
10787 output_file_names ();
10788 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
10791 /* Output the marker for the end of the line number info. */
10792 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10796 if (separate_line_info
)
10798 dw_line_info_table
*table
;
10801 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
10804 output_one_line_info_table (table
);
10808 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
10810 output_one_line_info_table (cold_text_section_line_info
);
10814 /* ??? Some Darwin linkers crash on a .debug_line section with no
10815 sequences. Further, merely a DW_LNE_end_sequence entry is not
10816 sufficient -- the address column must also be initialized.
10817 Make sure to output at least one set_address/end_sequence pair,
10818 choosing .text since that section is always present. */
10819 if (text_section_line_info
->in_use
|| !saw_one
)
10820 output_one_line_info_table (text_section_line_info
);
10822 /* Output the marker for the end of the line number info. */
10823 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10826 /* Return true if DW_AT_endianity should be emitted according to REVERSE. */
10829 need_endianity_attribute_p (bool reverse
)
10831 return reverse
&& (dwarf_version
>= 3 || !dwarf_strict
);
10834 /* Given a pointer to a tree node for some base type, return a pointer to
10835 a DIE that describes the given type. REVERSE is true if the type is
10836 to be interpreted in the reverse storage order wrt the target order.
10838 This routine must only be called for GCC type nodes that correspond to
10839 Dwarf base (fundamental) types. */
10842 base_type_die (tree type
, bool reverse
)
10844 dw_die_ref base_type_result
;
10845 enum dwarf_type encoding
;
10846 bool fpt_used
= false;
10847 struct fixed_point_type_info fpt_info
;
10848 tree type_bias
= NULL_TREE
;
10850 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
10853 /* If this is a subtype that should not be emitted as a subrange type,
10854 use the base type. See subrange_type_for_debug_p. */
10855 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
10856 type
= TREE_TYPE (type
);
10858 switch (TREE_CODE (type
))
10861 if ((dwarf_version
>= 4 || !dwarf_strict
)
10862 && TYPE_NAME (type
)
10863 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10864 && DECL_IS_BUILTIN (TYPE_NAME (type
))
10865 && DECL_NAME (TYPE_NAME (type
)))
10867 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
10868 if (strcmp (name
, "char16_t") == 0
10869 || strcmp (name
, "char32_t") == 0)
10871 encoding
= DW_ATE_UTF
;
10875 if ((dwarf_version
>= 3 || !dwarf_strict
)
10876 && lang_hooks
.types
.get_fixed_point_type_info
)
10878 memset (&fpt_info
, 0, sizeof (fpt_info
));
10879 if (lang_hooks
.types
.get_fixed_point_type_info (type
, &fpt_info
))
10882 encoding
= ((TYPE_UNSIGNED (type
))
10883 ? DW_ATE_unsigned_fixed
10884 : DW_ATE_signed_fixed
);
10888 if (TYPE_STRING_FLAG (type
))
10890 if (TYPE_UNSIGNED (type
))
10891 encoding
= DW_ATE_unsigned_char
;
10893 encoding
= DW_ATE_signed_char
;
10895 else if (TYPE_UNSIGNED (type
))
10896 encoding
= DW_ATE_unsigned
;
10898 encoding
= DW_ATE_signed
;
10901 && lang_hooks
.types
.get_type_bias
)
10902 type_bias
= lang_hooks
.types
.get_type_bias (type
);
10906 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
10908 if (dwarf_version
>= 3 || !dwarf_strict
)
10909 encoding
= DW_ATE_decimal_float
;
10911 encoding
= DW_ATE_lo_user
;
10914 encoding
= DW_ATE_float
;
10917 case FIXED_POINT_TYPE
:
10918 if (!(dwarf_version
>= 3 || !dwarf_strict
))
10919 encoding
= DW_ATE_lo_user
;
10920 else if (TYPE_UNSIGNED (type
))
10921 encoding
= DW_ATE_unsigned_fixed
;
10923 encoding
= DW_ATE_signed_fixed
;
10926 /* Dwarf2 doesn't know anything about complex ints, so use
10927 a user defined type for it. */
10929 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
10930 encoding
= DW_ATE_complex_float
;
10932 encoding
= DW_ATE_lo_user
;
10936 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10937 encoding
= DW_ATE_boolean
;
10941 /* No other TREE_CODEs are Dwarf fundamental types. */
10942 gcc_unreachable ();
10945 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
10947 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
10948 int_size_in_bytes (type
));
10949 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
10951 if (need_endianity_attribute_p (reverse
))
10952 add_AT_unsigned (base_type_result
, DW_AT_endianity
,
10953 BYTES_BIG_ENDIAN
? DW_END_little
: DW_END_big
);
10957 switch (fpt_info
.scale_factor_kind
)
10959 case fixed_point_scale_factor_binary
:
10960 add_AT_int (base_type_result
, DW_AT_binary_scale
,
10961 fpt_info
.scale_factor
.binary
);
10964 case fixed_point_scale_factor_decimal
:
10965 add_AT_int (base_type_result
, DW_AT_decimal_scale
,
10966 fpt_info
.scale_factor
.decimal
);
10969 case fixed_point_scale_factor_arbitrary
:
10970 /* Arbitrary scale factors cannot be described in standard DWARF,
10974 /* Describe the scale factor as a rational constant. */
10975 const dw_die_ref scale_factor
10976 = new_die (DW_TAG_constant
, comp_unit_die (), type
);
10978 add_AT_unsigned (scale_factor
, DW_AT_GNU_numerator
,
10979 fpt_info
.scale_factor
.arbitrary
.numerator
);
10980 add_AT_int (scale_factor
, DW_AT_GNU_denominator
,
10981 fpt_info
.scale_factor
.arbitrary
.denominator
);
10983 add_AT_die_ref (base_type_result
, DW_AT_small
, scale_factor
);
10988 gcc_unreachable ();
10993 add_scalar_info (base_type_result
, DW_AT_GNU_bias
, type_bias
,
10994 dw_scalar_form_constant
10995 | dw_scalar_form_exprloc
10996 | dw_scalar_form_reference
,
10999 add_pubtype (type
, base_type_result
);
11001 return base_type_result
;
11004 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
11005 named 'auto' in its type: return true for it, false otherwise. */
11008 is_cxx_auto (tree type
)
11012 tree name
= TYPE_IDENTIFIER (type
);
11013 if (name
== get_identifier ("auto")
11014 || name
== get_identifier ("decltype(auto)"))
11020 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
11021 given input type is a Dwarf "fundamental" type. Otherwise return null. */
11024 is_base_type (tree type
)
11026 switch (TREE_CODE (type
))
11032 case FIXED_POINT_TYPE
:
11035 case POINTER_BOUNDS_TYPE
:
11041 case QUAL_UNION_TYPE
:
11042 case ENUMERAL_TYPE
:
11043 case FUNCTION_TYPE
:
11046 case REFERENCE_TYPE
:
11054 if (is_cxx_auto (type
))
11056 gcc_unreachable ();
11062 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
11063 node, return the size in bits for the type if it is a constant, or else
11064 return the alignment for the type if the type's size is not constant, or
11065 else return BITS_PER_WORD if the type actually turns out to be an
11066 ERROR_MARK node. */
11068 static inline unsigned HOST_WIDE_INT
11069 simple_type_size_in_bits (const_tree type
)
11071 if (TREE_CODE (type
) == ERROR_MARK
)
11072 return BITS_PER_WORD
;
11073 else if (TYPE_SIZE (type
) == NULL_TREE
)
11075 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
11076 return tree_to_uhwi (TYPE_SIZE (type
));
11078 return TYPE_ALIGN (type
);
11081 /* Similarly, but return an offset_int instead of UHWI. */
11083 static inline offset_int
11084 offset_int_type_size_in_bits (const_tree type
)
11086 if (TREE_CODE (type
) == ERROR_MARK
)
11087 return BITS_PER_WORD
;
11088 else if (TYPE_SIZE (type
) == NULL_TREE
)
11090 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
11091 return wi::to_offset (TYPE_SIZE (type
));
11093 return TYPE_ALIGN (type
);
11096 /* Given a pointer to a tree node for a subrange type, return a pointer
11097 to a DIE that describes the given type. */
11100 subrange_type_die (tree type
, tree low
, tree high
, tree bias
,
11101 dw_die_ref context_die
)
11103 dw_die_ref subrange_die
;
11104 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
11106 if (context_die
== NULL
)
11107 context_die
= comp_unit_die ();
11109 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
11111 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
11113 /* The size of the subrange type and its base type do not match,
11114 so we need to generate a size attribute for the subrange type. */
11115 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
11119 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
, NULL
);
11121 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
, NULL
);
11122 if (bias
&& !dwarf_strict
)
11123 add_scalar_info (subrange_die
, DW_AT_GNU_bias
, bias
,
11124 dw_scalar_form_constant
11125 | dw_scalar_form_exprloc
11126 | dw_scalar_form_reference
,
11129 return subrange_die
;
11132 /* Returns the (const and/or volatile) cv_qualifiers associated with
11133 the decl node. This will normally be augmented with the
11134 cv_qualifiers of the underlying type in add_type_attribute. */
11137 decl_quals (const_tree decl
)
11139 return ((TREE_READONLY (decl
)
11140 /* The C++ front-end correctly marks reference-typed
11141 variables as readonly, but from a language (and debug
11142 info) standpoint they are not const-qualified. */
11143 && TREE_CODE (TREE_TYPE (decl
)) != REFERENCE_TYPE
11144 ? TYPE_QUAL_CONST
: TYPE_UNQUALIFIED
)
11145 | (TREE_THIS_VOLATILE (decl
)
11146 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
));
11149 /* Determine the TYPE whose qualifiers match the largest strict subset
11150 of the given TYPE_QUALS, and return its qualifiers. Ignore all
11151 qualifiers outside QUAL_MASK. */
11154 get_nearest_type_subqualifiers (tree type
, int type_quals
, int qual_mask
)
11157 int best_rank
= 0, best_qual
= 0, max_rank
;
11159 type_quals
&= qual_mask
;
11160 max_rank
= popcount_hwi (type_quals
) - 1;
11162 for (t
= TYPE_MAIN_VARIANT (type
); t
&& best_rank
< max_rank
;
11163 t
= TYPE_NEXT_VARIANT (t
))
11165 int q
= TYPE_QUALS (t
) & qual_mask
;
11167 if ((q
& type_quals
) == q
&& q
!= type_quals
11168 && check_base_type (t
, type
))
11170 int rank
= popcount_hwi (q
);
11172 if (rank
> best_rank
)
11183 struct dwarf_qual_info_t
{ int q
; enum dwarf_tag t
; };
11184 static const dwarf_qual_info_t dwarf_qual_info
[] =
11186 { TYPE_QUAL_CONST
, DW_TAG_const_type
},
11187 { TYPE_QUAL_VOLATILE
, DW_TAG_volatile_type
},
11188 { TYPE_QUAL_RESTRICT
, DW_TAG_restrict_type
},
11189 { TYPE_QUAL_ATOMIC
, DW_TAG_atomic_type
}
11191 static const unsigned int dwarf_qual_info_size
11192 = sizeof (dwarf_qual_info
) / sizeof (dwarf_qual_info
[0]);
11194 /* If DIE is a qualified DIE of some base DIE with the same parent,
11195 return the base DIE, otherwise return NULL. Set MASK to the
11196 qualifiers added compared to the returned DIE. */
11199 qualified_die_p (dw_die_ref die
, int *mask
, unsigned int depth
)
11202 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
11203 if (die
->die_tag
== dwarf_qual_info
[i
].t
)
11205 if (i
== dwarf_qual_info_size
)
11207 if (vec_safe_length (die
->die_attr
) != 1)
11209 dw_die_ref type
= get_AT_ref (die
, DW_AT_type
);
11210 if (type
== NULL
|| type
->die_parent
!= die
->die_parent
)
11212 *mask
|= dwarf_qual_info
[i
].q
;
11215 dw_die_ref ret
= qualified_die_p (type
, mask
, depth
- 1);
11222 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
11223 entry that chains the modifiers specified by CV_QUALS in front of the
11224 given type. REVERSE is true if the type is to be interpreted in the
11225 reverse storage order wrt the target order. */
11228 modified_type_die (tree type
, int cv_quals
, bool reverse
,
11229 dw_die_ref context_die
)
11231 enum tree_code code
= TREE_CODE (type
);
11232 dw_die_ref mod_type_die
;
11233 dw_die_ref sub_die
= NULL
;
11234 tree item_type
= NULL
;
11235 tree qualified_type
;
11236 tree name
, low
, high
;
11237 dw_die_ref mod_scope
;
11238 /* Only these cv-qualifiers are currently handled. */
11239 const int cv_qual_mask
= (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
11240 | TYPE_QUAL_RESTRICT
| TYPE_QUAL_ATOMIC
);
11242 if (code
== ERROR_MARK
)
11245 if (lang_hooks
.types
.get_debug_type
)
11247 tree debug_type
= lang_hooks
.types
.get_debug_type (type
);
11249 if (debug_type
!= NULL_TREE
&& debug_type
!= type
)
11250 return modified_type_die (debug_type
, cv_quals
, reverse
, context_die
);
11253 cv_quals
&= cv_qual_mask
;
11255 /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
11256 tag modifier (and not an attribute) old consumers won't be able
11258 if (dwarf_version
< 3)
11259 cv_quals
&= ~TYPE_QUAL_RESTRICT
;
11261 /* Likewise for DW_TAG_atomic_type for DWARFv5. */
11262 if (dwarf_version
< 5)
11263 cv_quals
&= ~TYPE_QUAL_ATOMIC
;
11265 /* See if we already have the appropriately qualified variant of
11267 qualified_type
= get_qualified_type (type
, cv_quals
);
11269 if (qualified_type
== sizetype
11270 && TYPE_NAME (qualified_type
)
11271 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
11273 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
11275 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
11276 && TYPE_PRECISION (t
)
11277 == TYPE_PRECISION (qualified_type
)
11278 && TYPE_UNSIGNED (t
)
11279 == TYPE_UNSIGNED (qualified_type
));
11280 qualified_type
= t
;
11283 /* If we do, then we can just use its DIE, if it exists. */
11284 if (qualified_type
)
11286 mod_type_die
= lookup_type_die (qualified_type
);
11288 /* DW_AT_endianity doesn't come from a qualifier on the type. */
11290 && (!need_endianity_attribute_p (reverse
)
11291 || !is_base_type (type
)
11292 || get_AT_unsigned (mod_type_die
, DW_AT_endianity
)))
11293 return mod_type_die
;
11296 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
11298 /* Handle C typedef types. */
11299 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
11300 && !DECL_ARTIFICIAL (name
))
11302 tree dtype
= TREE_TYPE (name
);
11304 if (qualified_type
== dtype
)
11306 /* For a named type, use the typedef. */
11307 gen_type_die (qualified_type
, context_die
);
11308 return lookup_type_die (qualified_type
);
11312 int dquals
= TYPE_QUALS_NO_ADDR_SPACE (dtype
);
11313 dquals
&= cv_qual_mask
;
11314 if ((dquals
& ~cv_quals
) != TYPE_UNQUALIFIED
11315 || (cv_quals
== dquals
&& DECL_ORIGINAL_TYPE (name
) != type
))
11316 /* cv-unqualified version of named type. Just use
11317 the unnamed type to which it refers. */
11318 return modified_type_die (DECL_ORIGINAL_TYPE (name
), cv_quals
,
11319 reverse
, context_die
);
11320 /* Else cv-qualified version of named type; fall through. */
11324 mod_scope
= scope_die_for (type
, context_die
);
11328 int sub_quals
= 0, first_quals
= 0;
11330 dw_die_ref first
= NULL
, last
= NULL
;
11332 /* Determine a lesser qualified type that most closely matches
11333 this one. Then generate DW_TAG_* entries for the remaining
11335 sub_quals
= get_nearest_type_subqualifiers (type
, cv_quals
,
11337 if (sub_quals
&& use_debug_types
)
11339 bool needed
= false;
11340 /* If emitting type units, make sure the order of qualifiers
11341 is canonical. Thus, start from unqualified type if
11342 an earlier qualifier is missing in sub_quals, but some later
11343 one is present there. */
11344 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
11345 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
11347 else if (needed
&& (dwarf_qual_info
[i
].q
& cv_quals
))
11353 mod_type_die
= modified_type_die (type
, sub_quals
, reverse
, context_die
);
11354 if (mod_scope
&& mod_type_die
&& mod_type_die
->die_parent
== mod_scope
)
11356 /* As not all intermediate qualified DIEs have corresponding
11357 tree types, ensure that qualified DIEs in the same scope
11358 as their DW_AT_type are emitted after their DW_AT_type,
11359 only with other qualified DIEs for the same type possibly
11360 in between them. Determine the range of such qualified
11361 DIEs now (first being the base type, last being corresponding
11362 last qualified DIE for it). */
11363 unsigned int count
= 0;
11364 first
= qualified_die_p (mod_type_die
, &first_quals
,
11365 dwarf_qual_info_size
);
11367 first
= mod_type_die
;
11368 gcc_assert ((first_quals
& ~sub_quals
) == 0);
11369 for (count
= 0, last
= first
;
11370 count
< (1U << dwarf_qual_info_size
);
11371 count
++, last
= last
->die_sib
)
11374 if (last
== mod_scope
->die_child
)
11376 if (qualified_die_p (last
->die_sib
, &quals
, dwarf_qual_info_size
)
11382 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
11383 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
11386 if (first
&& first
!= last
)
11388 for (d
= first
->die_sib
; ; d
= d
->die_sib
)
11391 qualified_die_p (d
, &quals
, dwarf_qual_info_size
);
11392 if (quals
== (first_quals
| dwarf_qual_info
[i
].q
))
11408 d
= ggc_cleared_alloc
<die_node
> ();
11409 d
->die_tag
= dwarf_qual_info
[i
].t
;
11410 add_child_die_after (mod_scope
, d
, last
);
11414 d
= new_die (dwarf_qual_info
[i
].t
, mod_scope
, type
);
11416 add_AT_die_ref (d
, DW_AT_type
, mod_type_die
);
11418 first_quals
|= dwarf_qual_info
[i
].q
;
11421 else if (code
== POINTER_TYPE
|| code
== REFERENCE_TYPE
)
11423 dwarf_tag tag
= DW_TAG_pointer_type
;
11424 if (code
== REFERENCE_TYPE
)
11426 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
11427 tag
= DW_TAG_rvalue_reference_type
;
11429 tag
= DW_TAG_reference_type
;
11431 mod_type_die
= new_die (tag
, mod_scope
, type
);
11433 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
11434 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
11435 item_type
= TREE_TYPE (type
);
11437 addr_space_t as
= TYPE_ADDR_SPACE (item_type
);
11438 if (!ADDR_SPACE_GENERIC_P (as
))
11440 int action
= targetm
.addr_space
.debug (as
);
11443 /* Positive values indicate an address_class. */
11444 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, action
);
11448 /* Negative values indicate an (inverted) segment base reg. */
11450 = one_reg_loc_descriptor (~action
, VAR_INIT_STATUS_INITIALIZED
);
11451 add_AT_loc (mod_type_die
, DW_AT_segment
, d
);
11455 else if (code
== INTEGER_TYPE
11456 && TREE_TYPE (type
) != NULL_TREE
11457 && subrange_type_for_debug_p (type
, &low
, &high
))
11459 tree bias
= NULL_TREE
;
11460 if (lang_hooks
.types
.get_type_bias
)
11461 bias
= lang_hooks
.types
.get_type_bias (type
);
11462 mod_type_die
= subrange_type_die (type
, low
, high
, bias
, context_die
);
11463 item_type
= TREE_TYPE (type
);
11465 else if (is_base_type (type
))
11466 mod_type_die
= base_type_die (type
, reverse
);
11469 gen_type_die (type
, context_die
);
11471 /* We have to get the type_main_variant here (and pass that to the
11472 `lookup_type_die' routine) because the ..._TYPE node we have
11473 might simply be a *copy* of some original type node (where the
11474 copy was created to help us keep track of typedef names) and
11475 that copy might have a different TYPE_UID from the original
11477 if (TREE_CODE (type
) != VECTOR_TYPE
)
11478 return lookup_type_die (type_main_variant (type
));
11480 /* Vectors have the debugging information in the type,
11481 not the main variant. */
11482 return lookup_type_die (type
);
11485 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
11486 don't output a DW_TAG_typedef, since there isn't one in the
11487 user's program; just attach a DW_AT_name to the type.
11488 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
11489 if the base type already has the same name. */
11491 && ((TREE_CODE (name
) != TYPE_DECL
11492 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
11493 || (cv_quals
== TYPE_UNQUALIFIED
)))
11494 || (TREE_CODE (name
) == TYPE_DECL
11495 && TREE_TYPE (name
) == qualified_type
11496 && DECL_NAME (name
))))
11498 if (TREE_CODE (name
) == TYPE_DECL
)
11499 /* Could just call add_name_and_src_coords_attributes here,
11500 but since this is a builtin type it doesn't have any
11501 useful source coordinates anyway. */
11502 name
= DECL_NAME (name
);
11503 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
11505 /* This probably indicates a bug. */
11506 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
11508 name
= TYPE_IDENTIFIER (type
);
11509 add_name_attribute (mod_type_die
,
11510 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
11513 if (qualified_type
)
11514 equate_type_number_to_die (qualified_type
, mod_type_die
);
11517 /* We must do this after the equate_type_number_to_die call, in case
11518 this is a recursive type. This ensures that the modified_type_die
11519 recursion will terminate even if the type is recursive. Recursive
11520 types are possible in Ada. */
11521 sub_die
= modified_type_die (item_type
,
11522 TYPE_QUALS_NO_ADDR_SPACE (item_type
),
11526 if (sub_die
!= NULL
)
11527 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
11529 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
11530 if (TYPE_ARTIFICIAL (type
))
11531 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
11533 return mod_type_die
;
11536 /* Generate DIEs for the generic parameters of T.
11537 T must be either a generic type or a generic function.
11538 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
11541 gen_generic_params_dies (tree t
)
11545 dw_die_ref die
= NULL
;
11548 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
11552 die
= lookup_type_die (t
);
11553 else if (DECL_P (t
))
11554 die
= lookup_decl_die (t
);
11558 parms
= lang_hooks
.get_innermost_generic_parms (t
);
11560 /* T has no generic parameter. It means T is neither a generic type
11561 or function. End of story. */
11564 parms_num
= TREE_VEC_LENGTH (parms
);
11565 args
= lang_hooks
.get_innermost_generic_args (t
);
11566 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
11567 non_default
= int_cst_value (TREE_CHAIN (args
));
11569 non_default
= TREE_VEC_LENGTH (args
);
11570 for (i
= 0; i
< parms_num
; i
++)
11572 tree parm
, arg
, arg_pack_elems
;
11573 dw_die_ref parm_die
;
11575 parm
= TREE_VEC_ELT (parms
, i
);
11576 arg
= TREE_VEC_ELT (args
, i
);
11577 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
11578 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
11580 if (parm
&& TREE_VALUE (parm
) && arg
)
11582 /* If PARM represents a template parameter pack,
11583 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
11584 by DW_TAG_template_*_parameter DIEs for the argument
11585 pack elements of ARG. Note that ARG would then be
11586 an argument pack. */
11587 if (arg_pack_elems
)
11588 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
11592 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
11593 true /* emit name */, die
);
11594 if (i
>= non_default
)
11595 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
11600 /* Create and return a DIE for PARM which should be
11601 the representation of a generic type parameter.
11602 For instance, in the C++ front end, PARM would be a template parameter.
11603 ARG is the argument to PARM.
11604 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
11606 PARENT_DIE is the parent DIE which the new created DIE should be added to,
11607 as a child node. */
11610 generic_parameter_die (tree parm
, tree arg
,
11612 dw_die_ref parent_die
)
11614 dw_die_ref tmpl_die
= NULL
;
11615 const char *name
= NULL
;
11617 if (!parm
|| !DECL_NAME (parm
) || !arg
)
11620 /* We support non-type generic parameters and arguments,
11621 type generic parameters and arguments, as well as
11622 generic generic parameters (a.k.a. template template parameters in C++)
11624 if (TREE_CODE (parm
) == PARM_DECL
)
11625 /* PARM is a nontype generic parameter */
11626 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
11627 else if (TREE_CODE (parm
) == TYPE_DECL
)
11628 /* PARM is a type generic parameter. */
11629 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
11630 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
11631 /* PARM is a generic generic parameter.
11632 Its DIE is a GNU extension. It shall have a
11633 DW_AT_name attribute to represent the name of the template template
11634 parameter, and a DW_AT_GNU_template_name attribute to represent the
11635 name of the template template argument. */
11636 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
11639 gcc_unreachable ();
11645 /* If PARM is a generic parameter pack, it means we are
11646 emitting debug info for a template argument pack element.
11647 In other terms, ARG is a template argument pack element.
11648 In that case, we don't emit any DW_AT_name attribute for
11652 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
11654 add_AT_string (tmpl_die
, DW_AT_name
, name
);
11657 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
11659 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
11660 TMPL_DIE should have a child DW_AT_type attribute that is set
11661 to the type of the argument to PARM, which is ARG.
11662 If PARM is a type generic parameter, TMPL_DIE should have a
11663 child DW_AT_type that is set to ARG. */
11664 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
11665 add_type_attribute (tmpl_die
, tmpl_type
,
11666 (TREE_THIS_VOLATILE (tmpl_type
)
11667 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
),
11668 false, parent_die
);
11672 /* So TMPL_DIE is a DIE representing a
11673 a generic generic template parameter, a.k.a template template
11674 parameter in C++ and arg is a template. */
11676 /* The DW_AT_GNU_template_name attribute of the DIE must be set
11677 to the name of the argument. */
11678 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
11680 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
11683 if (TREE_CODE (parm
) == PARM_DECL
)
11684 /* So PARM is a non-type generic parameter.
11685 DWARF3 5.6.8 says we must set a DW_AT_const_value child
11686 attribute of TMPL_DIE which value represents the value
11688 We must be careful here:
11689 The value of ARG might reference some function decls.
11690 We might currently be emitting debug info for a generic
11691 type and types are emitted before function decls, we don't
11692 know if the function decls referenced by ARG will actually be
11693 emitted after cgraph computations.
11694 So must defer the generation of the DW_AT_const_value to
11695 after cgraph is ready. */
11696 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
11702 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
11703 PARM_PACK must be a template parameter pack. The returned DIE
11704 will be child DIE of PARENT_DIE. */
11707 template_parameter_pack_die (tree parm_pack
,
11708 tree parm_pack_args
,
11709 dw_die_ref parent_die
)
11714 gcc_assert (parent_die
&& parm_pack
);
11716 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
11717 add_name_and_src_coords_attributes (die
, parm_pack
);
11718 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
11719 generic_parameter_die (parm_pack
,
11720 TREE_VEC_ELT (parm_pack_args
, j
),
11721 false /* Don't emit DW_AT_name */,
11726 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
11727 an enumerated type. */
11730 type_is_enum (const_tree type
)
11732 return TREE_CODE (type
) == ENUMERAL_TYPE
;
11735 /* Return the DBX register number described by a given RTL node. */
11737 static unsigned int
11738 dbx_reg_number (const_rtx rtl
)
11740 unsigned regno
= REGNO (rtl
);
11742 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
11744 #ifdef LEAF_REG_REMAP
11745 if (crtl
->uses_only_leaf_regs
)
11747 int leaf_reg
= LEAF_REG_REMAP (regno
);
11748 if (leaf_reg
!= -1)
11749 regno
= (unsigned) leaf_reg
;
11753 regno
= DBX_REGISTER_NUMBER (regno
);
11754 gcc_assert (regno
!= INVALID_REGNUM
);
11758 /* Optionally add a DW_OP_piece term to a location description expression.
11759 DW_OP_piece is only added if the location description expression already
11760 doesn't end with DW_OP_piece. */
11763 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
11765 dw_loc_descr_ref loc
;
11767 if (*list_head
!= NULL
)
11769 /* Find the end of the chain. */
11770 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
11773 if (loc
->dw_loc_opc
!= DW_OP_piece
)
11774 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
11778 /* Return a location descriptor that designates a machine register or
11779 zero if there is none. */
11781 static dw_loc_descr_ref
11782 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
11786 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
11789 /* We only use "frame base" when we're sure we're talking about the
11790 post-prologue local stack frame. We do this by *not* running
11791 register elimination until this point, and recognizing the special
11792 argument pointer and soft frame pointer rtx's.
11793 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
11794 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
11795 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
11797 dw_loc_descr_ref result
= NULL
;
11799 if (dwarf_version
>= 4 || !dwarf_strict
)
11801 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
11804 add_loc_descr (&result
,
11805 new_loc_descr (DW_OP_stack_value
, 0, 0));
11810 regs
= targetm
.dwarf_register_span (rtl
);
11812 if (REG_NREGS (rtl
) > 1 || regs
)
11813 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
11816 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
11817 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
11819 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
11823 /* Return a location descriptor that designates a machine register for
11824 a given hard register number. */
11826 static dw_loc_descr_ref
11827 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
11829 dw_loc_descr_ref reg_loc_descr
;
11833 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
11835 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
11837 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11838 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11840 return reg_loc_descr
;
11843 /* Given an RTL of a register, return a location descriptor that
11844 designates a value that spans more than one register. */
11846 static dw_loc_descr_ref
11847 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
11848 enum var_init_status initialized
)
11851 dw_loc_descr_ref loc_result
= NULL
;
11853 /* Simple, contiguous registers. */
11854 if (regs
== NULL_RTX
)
11856 unsigned reg
= REGNO (rtl
);
11859 #ifdef LEAF_REG_REMAP
11860 if (crtl
->uses_only_leaf_regs
)
11862 int leaf_reg
= LEAF_REG_REMAP (reg
);
11863 if (leaf_reg
!= -1)
11864 reg
= (unsigned) leaf_reg
;
11868 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
11869 nregs
= REG_NREGS (rtl
);
11871 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
11876 dw_loc_descr_ref t
;
11878 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
11879 VAR_INIT_STATUS_INITIALIZED
);
11880 add_loc_descr (&loc_result
, t
);
11881 add_loc_descr_op_piece (&loc_result
, size
);
11887 /* Now onto stupid register sets in non contiguous locations. */
11889 gcc_assert (GET_CODE (regs
) == PARALLEL
);
11891 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
11894 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
11896 dw_loc_descr_ref t
;
11898 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
11899 VAR_INIT_STATUS_INITIALIZED
);
11900 add_loc_descr (&loc_result
, t
);
11901 add_loc_descr_op_piece (&loc_result
, size
);
11904 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11905 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11909 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
11911 /* Return a location descriptor that designates a constant i,
11912 as a compound operation from constant (i >> shift), constant shift
11915 static dw_loc_descr_ref
11916 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
11918 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
11919 add_loc_descr (&ret
, int_loc_descriptor (shift
));
11920 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11924 /* Return a location descriptor that designates a constant. */
11926 static dw_loc_descr_ref
11927 int_loc_descriptor (HOST_WIDE_INT i
)
11929 enum dwarf_location_atom op
;
11931 /* Pick the smallest representation of a constant, rather than just
11932 defaulting to the LEB encoding. */
11935 int clz
= clz_hwi (i
);
11936 int ctz
= ctz_hwi (i
);
11938 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
11939 else if (i
<= 0xff)
11940 op
= DW_OP_const1u
;
11941 else if (i
<= 0xffff)
11942 op
= DW_OP_const2u
;
11943 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11944 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11945 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
11946 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
11947 while DW_OP_const4u is 5 bytes. */
11948 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
11949 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11950 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11951 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
11952 while DW_OP_const4u is 5 bytes. */
11953 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
11954 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11955 op
= DW_OP_const4u
;
11956 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11957 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11958 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
11959 while DW_OP_constu of constant >= 0x100000000 takes at least
11961 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
11962 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11963 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
11964 >= HOST_BITS_PER_WIDE_INT
)
11965 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
11966 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
11967 while DW_OP_constu takes in this case at least 6 bytes. */
11968 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
11969 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11970 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11971 && size_of_uleb128 (i
) > 6)
11972 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
11973 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
11980 op
= DW_OP_const1s
;
11981 else if (i
>= -0x8000)
11982 op
= DW_OP_const2s
;
11983 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11985 if (size_of_int_loc_descriptor (i
) < 5)
11987 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11988 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11991 op
= DW_OP_const4s
;
11995 if (size_of_int_loc_descriptor (i
)
11996 < (unsigned long) 1 + size_of_sleb128 (i
))
11998 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11999 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12006 return new_loc_descr (op
, i
, 0);
12009 /* Likewise, for unsigned constants. */
12011 static dw_loc_descr_ref
12012 uint_loc_descriptor (unsigned HOST_WIDE_INT i
)
12014 const unsigned HOST_WIDE_INT max_int
= INTTYPE_MAXIMUM (HOST_WIDE_INT
);
12015 const unsigned HOST_WIDE_INT max_uint
12016 = INTTYPE_MAXIMUM (unsigned HOST_WIDE_INT
);
12018 /* If possible, use the clever signed constants handling. */
12020 return int_loc_descriptor ((HOST_WIDE_INT
) i
);
12022 /* Here, we are left with positive numbers that cannot be represented as
12023 HOST_WIDE_INT, i.e.:
12024 max (HOST_WIDE_INT) < i <= max (unsigned HOST_WIDE_INT)
12026 Using DW_OP_const4/8/./u operation to encode them consumes a lot of bytes
12027 whereas may be better to output a negative integer: thanks to integer
12028 wrapping, we know that:
12029 x = x - 2 ** DWARF2_ADDR_SIZE
12030 = x - 2 * (max (HOST_WIDE_INT) + 1)
12031 So numbers close to max (unsigned HOST_WIDE_INT) could be represented as
12032 small negative integers. Let's try that in cases it will clearly improve
12033 the encoding: there is no gain turning DW_OP_const4u into
12035 if (DWARF2_ADDR_SIZE
* 8 == HOST_BITS_PER_WIDE_INT
12036 && ((DWARF2_ADDR_SIZE
== 4 && i
> max_uint
- 0x8000)
12037 || (DWARF2_ADDR_SIZE
== 8 && i
> max_uint
- 0x80000000)))
12039 const unsigned HOST_WIDE_INT first_shift
= i
- max_int
- 1;
12041 /* Now, -1 < first_shift <= max (HOST_WIDE_INT)
12042 i.e. 0 <= first_shift <= max (HOST_WIDE_INT). */
12043 const HOST_WIDE_INT second_shift
12044 = (HOST_WIDE_INT
) first_shift
- (HOST_WIDE_INT
) max_int
- 1;
12046 /* So we finally have:
12047 -max (HOST_WIDE_INT) - 1 <= second_shift <= -1.
12048 i.e. min (HOST_WIDE_INT) <= second_shift < 0. */
12049 return int_loc_descriptor (second_shift
);
12052 /* Last chance: fallback to a simple constant operation. */
12053 return new_loc_descr
12054 ((HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
12060 /* Generate and return a location description that computes the unsigned
12061 comparison of the two stack top entries (a OP b where b is the top-most
12062 entry and a is the second one). The KIND of comparison can be LT_EXPR,
12063 LE_EXPR, GT_EXPR or GE_EXPR. */
12065 static dw_loc_descr_ref
12066 uint_comparison_loc_list (enum tree_code kind
)
12068 enum dwarf_location_atom op
, flip_op
;
12069 dw_loc_descr_ref ret
, bra_node
, jmp_node
, tmp
;
12086 gcc_unreachable ();
12089 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12090 jmp_node
= new_loc_descr (DW_OP_skip
, 0, 0);
12092 /* Until DWARFv4, operations all work on signed integers. It is nevertheless
12093 possible to perform unsigned comparisons: we just have to distinguish
12096 1. when a and b have the same sign (as signed integers); then we should
12097 return: a OP(signed) b;
12099 2. when a is a negative signed integer while b is a positive one, then a
12100 is a greater unsigned integer than b; likewise when a and b's roles
12103 So first, compare the sign of the two operands. */
12104 ret
= new_loc_descr (DW_OP_over
, 0, 0);
12105 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12106 add_loc_descr (&ret
, new_loc_descr (DW_OP_xor
, 0, 0));
12107 /* If they have different signs (i.e. they have different sign bits), then
12108 the stack top value has now the sign bit set and thus it's smaller than
12110 add_loc_descr (&ret
, new_loc_descr (DW_OP_lit0
, 0, 0));
12111 add_loc_descr (&ret
, new_loc_descr (DW_OP_lt
, 0, 0));
12112 add_loc_descr (&ret
, bra_node
);
12114 /* We are in case 1. At this point, we know both operands have the same
12115 sign, to it's safe to use the built-in signed comparison. */
12116 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
12117 add_loc_descr (&ret
, jmp_node
);
12119 /* We are in case 2. Here, we know both operands do not have the same sign,
12120 so we have to flip the signed comparison. */
12121 flip_op
= (kind
== LT_EXPR
|| kind
== LE_EXPR
) ? DW_OP_gt
: DW_OP_lt
;
12122 tmp
= new_loc_descr (flip_op
, 0, 0);
12123 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12124 bra_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
12125 add_loc_descr (&ret
, tmp
);
12127 /* This dummy operation is necessary to make the two branches join. */
12128 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
12129 jmp_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12130 jmp_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
12131 add_loc_descr (&ret
, tmp
);
12136 /* Likewise, but takes the location description lists (might be destructive on
12137 them). Return NULL if either is NULL or if concatenation fails. */
12139 static dw_loc_list_ref
12140 loc_list_from_uint_comparison (dw_loc_list_ref left
, dw_loc_list_ref right
,
12141 enum tree_code kind
)
12143 if (left
== NULL
|| right
== NULL
)
12146 add_loc_list (&left
, right
);
12150 add_loc_descr_to_each (left
, uint_comparison_loc_list (kind
));
12154 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
12155 without actually allocating it. */
12157 static unsigned long
12158 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
12160 return size_of_int_loc_descriptor (i
>> shift
)
12161 + size_of_int_loc_descriptor (shift
)
12165 /* Return size_of_locs (int_loc_descriptor (i)) without
12166 actually allocating it. */
12168 static unsigned long
12169 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
12178 else if (i
<= 0xff)
12180 else if (i
<= 0xffff)
12184 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
12185 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
12186 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
12188 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
12189 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
12190 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
12192 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
12194 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
12195 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
12196 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
12197 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
12199 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
12200 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
12201 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
12203 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
12204 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
12206 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
12215 else if (i
>= -0x8000)
12217 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
12219 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
12221 s
= size_of_int_loc_descriptor (-i
) + 1;
12229 unsigned long r
= 1 + size_of_sleb128 (i
);
12230 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
12232 s
= size_of_int_loc_descriptor (-i
) + 1;
12241 /* Return loc description representing "address" of integer value.
12242 This can appear only as toplevel expression. */
12244 static dw_loc_descr_ref
12245 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
12248 dw_loc_descr_ref loc_result
= NULL
;
12250 if (!(dwarf_version
>= 4 || !dwarf_strict
))
12253 litsize
= size_of_int_loc_descriptor (i
);
12254 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
12255 is more compact. For DW_OP_stack_value we need:
12256 litsize + 1 (DW_OP_stack_value)
12257 and for DW_OP_implicit_value:
12258 1 (DW_OP_implicit_value) + 1 (length) + size. */
12259 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
12261 loc_result
= int_loc_descriptor (i
);
12262 add_loc_descr (&loc_result
,
12263 new_loc_descr (DW_OP_stack_value
, 0, 0));
12267 loc_result
= new_loc_descr (DW_OP_implicit_value
,
12269 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12270 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
12274 /* Return a location descriptor that designates a base+offset location. */
12276 static dw_loc_descr_ref
12277 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
12278 enum var_init_status initialized
)
12280 unsigned int regno
;
12281 dw_loc_descr_ref result
;
12282 dw_fde_ref fde
= cfun
->fde
;
12284 /* We only use "frame base" when we're sure we're talking about the
12285 post-prologue local stack frame. We do this by *not* running
12286 register elimination until this point, and recognizing the special
12287 argument pointer and soft frame pointer rtx's. */
12288 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
12290 rtx elim
= (ira_use_lra_p
12291 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
12292 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
12296 if (GET_CODE (elim
) == PLUS
)
12298 offset
+= INTVAL (XEXP (elim
, 1));
12299 elim
= XEXP (elim
, 0);
12301 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
12302 && (elim
== hard_frame_pointer_rtx
12303 || elim
== stack_pointer_rtx
))
12304 || elim
== (frame_pointer_needed
12305 ? hard_frame_pointer_rtx
12306 : stack_pointer_rtx
));
12308 /* If drap register is used to align stack, use frame
12309 pointer + offset to access stack variables. If stack
12310 is aligned without drap, use stack pointer + offset to
12311 access stack variables. */
12312 if (crtl
->stack_realign_tried
12313 && reg
== frame_pointer_rtx
)
12316 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
12317 ? HARD_FRAME_POINTER_REGNUM
12319 return new_reg_loc_descr (base_reg
, offset
);
12322 gcc_assert (frame_pointer_fb_offset_valid
);
12323 offset
+= frame_pointer_fb_offset
;
12324 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
12328 regno
= REGNO (reg
);
12329 #ifdef LEAF_REG_REMAP
12330 if (crtl
->uses_only_leaf_regs
)
12332 int leaf_reg
= LEAF_REG_REMAP (regno
);
12333 if (leaf_reg
!= -1)
12334 regno
= (unsigned) leaf_reg
;
12337 regno
= DWARF_FRAME_REGNUM (regno
);
12339 if (!optimize
&& fde
12340 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
12342 /* Use cfa+offset to represent the location of arguments passed
12343 on the stack when drap is used to align stack.
12344 Only do this when not optimizing, for optimized code var-tracking
12345 is supposed to track where the arguments live and the register
12346 used as vdrap or drap in some spot might be used for something
12347 else in other part of the routine. */
12348 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
12352 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
12355 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
12357 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12358 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12363 /* Return true if this RTL expression describes a base+offset calculation. */
12366 is_based_loc (const_rtx rtl
)
12368 return (GET_CODE (rtl
) == PLUS
12369 && ((REG_P (XEXP (rtl
, 0))
12370 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
12371 && CONST_INT_P (XEXP (rtl
, 1)))));
12374 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
12377 static dw_loc_descr_ref
12378 tls_mem_loc_descriptor (rtx mem
)
12381 dw_loc_descr_ref loc_result
;
12383 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
12386 base
= get_base_address (MEM_EXPR (mem
));
12388 || TREE_CODE (base
) != VAR_DECL
12389 || !DECL_THREAD_LOCAL_P (base
))
12392 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1, NULL
);
12393 if (loc_result
== NULL
)
12396 if (MEM_OFFSET (mem
))
12397 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
12402 /* Output debug info about reason why we failed to expand expression as dwarf
12406 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
12408 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
12410 fprintf (dump_file
, "Failed to expand as dwarf: ");
12412 print_generic_expr (dump_file
, expr
, dump_flags
);
12415 fprintf (dump_file
, "\n");
12416 print_rtl (dump_file
, rtl
);
12418 fprintf (dump_file
, "\nReason: %s\n", reason
);
12422 /* Helper function for const_ok_for_output. */
12425 const_ok_for_output_1 (rtx rtl
)
12427 if (GET_CODE (rtl
) == UNSPEC
)
12429 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
12430 we can't express it in the debug info. */
12431 /* Don't complain about TLS UNSPECs, those are just too hard to
12432 delegitimize. Note this could be a non-decl SYMBOL_REF such as
12433 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
12434 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
12436 && (XVECLEN (rtl
, 0) == 0
12437 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
12438 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
))
12439 inform (current_function_decl
12440 ? DECL_SOURCE_LOCATION (current_function_decl
)
12441 : UNKNOWN_LOCATION
,
12442 #if NUM_UNSPEC_VALUES > 0
12443 "non-delegitimized UNSPEC %s (%d) found in variable location",
12444 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
12445 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
12448 "non-delegitimized UNSPEC %d found in variable location",
12451 expansion_failed (NULL_TREE
, rtl
,
12452 "UNSPEC hasn't been delegitimized.\n");
12456 if (targetm
.const_not_ok_for_debug_p (rtl
))
12458 expansion_failed (NULL_TREE
, rtl
,
12459 "Expression rejected for debug by the backend.\n");
12463 /* FIXME: Refer to PR60655. It is possible for simplification
12464 of rtl expressions in var tracking to produce such expressions.
12465 We should really identify / validate expressions
12466 enclosed in CONST that can be handled by assemblers on various
12467 targets and only handle legitimate cases here. */
12468 if (GET_CODE (rtl
) != SYMBOL_REF
)
12470 if (GET_CODE (rtl
) == NOT
)
12475 if (CONSTANT_POOL_ADDRESS_P (rtl
))
12478 get_pool_constant_mark (rtl
, &marked
);
12479 /* If all references to this pool constant were optimized away,
12480 it was not output and thus we can't represent it. */
12483 expansion_failed (NULL_TREE
, rtl
,
12484 "Constant was removed from constant pool.\n");
12489 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12492 /* Avoid references to external symbols in debug info, on several targets
12493 the linker might even refuse to link when linking a shared library,
12494 and in many other cases the relocations for .debug_info/.debug_loc are
12495 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
12496 to be defined within the same shared library or executable are fine. */
12497 if (SYMBOL_REF_EXTERNAL_P (rtl
))
12499 tree decl
= SYMBOL_REF_DECL (rtl
);
12501 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
12503 expansion_failed (NULL_TREE
, rtl
,
12504 "Symbol not defined in current TU.\n");
12512 /* Return true if constant RTL can be emitted in DW_OP_addr or
12513 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
12514 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
12517 const_ok_for_output (rtx rtl
)
12519 if (GET_CODE (rtl
) == SYMBOL_REF
)
12520 return const_ok_for_output_1 (rtl
);
12522 if (GET_CODE (rtl
) == CONST
)
12524 subrtx_var_iterator::array_type array
;
12525 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 0), ALL
)
12526 if (!const_ok_for_output_1 (*iter
))
12534 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
12535 if possible, NULL otherwise. */
12538 base_type_for_mode (machine_mode mode
, bool unsignedp
)
12540 dw_die_ref type_die
;
12541 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
12545 switch (TREE_CODE (type
))
12553 type_die
= lookup_type_die (type
);
12555 type_die
= modified_type_die (type
, TYPE_UNQUALIFIED
, false,
12557 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
12562 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
12563 type matching MODE, or, if MODE is narrower than or as wide as
12564 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
12567 static dw_loc_descr_ref
12568 convert_descriptor_to_mode (machine_mode mode
, dw_loc_descr_ref op
)
12570 machine_mode outer_mode
= mode
;
12571 dw_die_ref type_die
;
12572 dw_loc_descr_ref cvt
;
12574 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12576 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
12579 type_die
= base_type_for_mode (outer_mode
, 1);
12580 if (type_die
== NULL
)
12582 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12583 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12584 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12585 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12586 add_loc_descr (&op
, cvt
);
12590 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
12592 static dw_loc_descr_ref
12593 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
12594 dw_loc_descr_ref op1
)
12596 dw_loc_descr_ref ret
= op0
;
12597 add_loc_descr (&ret
, op1
);
12598 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
12599 if (STORE_FLAG_VALUE
!= 1)
12601 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
12602 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
12607 /* Return location descriptor for signed comparison OP RTL. */
12609 static dw_loc_descr_ref
12610 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
12611 machine_mode mem_mode
)
12613 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
12614 dw_loc_descr_ref op0
, op1
;
12617 if (op_mode
== VOIDmode
)
12618 op_mode
= GET_MODE (XEXP (rtl
, 1));
12619 if (op_mode
== VOIDmode
)
12623 && (!SCALAR_INT_MODE_P (op_mode
)
12624 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
12627 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
12628 VAR_INIT_STATUS_INITIALIZED
);
12629 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
12630 VAR_INIT_STATUS_INITIALIZED
);
12632 if (op0
== NULL
|| op1
== NULL
)
12635 if (!SCALAR_INT_MODE_P (op_mode
)
12636 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
12637 return compare_loc_descriptor (op
, op0
, op1
);
12639 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
12641 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
12642 dw_loc_descr_ref cvt
;
12644 if (type_die
== NULL
)
12646 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12647 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12648 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12649 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12650 add_loc_descr (&op0
, cvt
);
12651 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12652 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12653 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12654 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12655 add_loc_descr (&op1
, cvt
);
12656 return compare_loc_descriptor (op
, op0
, op1
);
12659 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
12660 /* For eq/ne, if the operands are known to be zero-extended,
12661 there is no need to do the fancy shifting up. */
12662 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
12664 dw_loc_descr_ref last0
, last1
;
12665 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
12667 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
12669 /* deref_size zero extends, and for constants we can check
12670 whether they are zero extended or not. */
12671 if (((last0
->dw_loc_opc
== DW_OP_deref_size
12672 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
12673 || (CONST_INT_P (XEXP (rtl
, 0))
12674 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
12675 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
12676 && ((last1
->dw_loc_opc
== DW_OP_deref_size
12677 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
12678 || (CONST_INT_P (XEXP (rtl
, 1))
12679 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
12680 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
12681 return compare_loc_descriptor (op
, op0
, op1
);
12683 /* EQ/NE comparison against constant in narrower type than
12684 DWARF2_ADDR_SIZE can be performed either as
12685 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
12688 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
12689 DW_OP_{eq,ne}. Pick whatever is shorter. */
12690 if (CONST_INT_P (XEXP (rtl
, 1))
12691 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
12692 && (size_of_int_loc_descriptor (shift
) + 1
12693 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
12694 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
12695 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
12696 & GET_MODE_MASK (op_mode
))))
12698 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
12699 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
12700 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
12701 & GET_MODE_MASK (op_mode
));
12702 return compare_loc_descriptor (op
, op0
, op1
);
12705 add_loc_descr (&op0
, int_loc_descriptor (shift
));
12706 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
12707 if (CONST_INT_P (XEXP (rtl
, 1)))
12708 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
12711 add_loc_descr (&op1
, int_loc_descriptor (shift
));
12712 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
12714 return compare_loc_descriptor (op
, op0
, op1
);
12717 /* Return location descriptor for unsigned comparison OP RTL. */
12719 static dw_loc_descr_ref
12720 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
12721 machine_mode mem_mode
)
12723 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
12724 dw_loc_descr_ref op0
, op1
;
12726 if (op_mode
== VOIDmode
)
12727 op_mode
= GET_MODE (XEXP (rtl
, 1));
12728 if (op_mode
== VOIDmode
)
12730 if (!SCALAR_INT_MODE_P (op_mode
))
12733 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
12736 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
12737 VAR_INIT_STATUS_INITIALIZED
);
12738 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
12739 VAR_INIT_STATUS_INITIALIZED
);
12741 if (op0
== NULL
|| op1
== NULL
)
12744 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
12746 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
12747 dw_loc_descr_ref last0
, last1
;
12748 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
12750 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
12752 if (CONST_INT_P (XEXP (rtl
, 0)))
12753 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
12754 /* deref_size zero extends, so no need to mask it again. */
12755 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
12756 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
12758 add_loc_descr (&op0
, int_loc_descriptor (mask
));
12759 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
12761 if (CONST_INT_P (XEXP (rtl
, 1)))
12762 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
12763 /* deref_size zero extends, so no need to mask it again. */
12764 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
12765 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
12767 add_loc_descr (&op1
, int_loc_descriptor (mask
));
12768 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
12771 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
12773 HOST_WIDE_INT bias
= 1;
12774 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
12775 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
12776 if (CONST_INT_P (XEXP (rtl
, 1)))
12777 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
12778 + INTVAL (XEXP (rtl
, 1)));
12780 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
12783 return compare_loc_descriptor (op
, op0
, op1
);
12786 /* Return location descriptor for {U,S}{MIN,MAX}. */
12788 static dw_loc_descr_ref
12789 minmax_loc_descriptor (rtx rtl
, machine_mode mode
,
12790 machine_mode mem_mode
)
12792 enum dwarf_location_atom op
;
12793 dw_loc_descr_ref op0
, op1
, ret
;
12794 dw_loc_descr_ref bra_node
, drop_node
;
12797 && (!SCALAR_INT_MODE_P (mode
)
12798 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
12801 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12802 VAR_INIT_STATUS_INITIALIZED
);
12803 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12804 VAR_INIT_STATUS_INITIALIZED
);
12806 if (op0
== NULL
|| op1
== NULL
)
12809 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
12810 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
12811 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
12812 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
12814 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12816 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
12817 add_loc_descr (&op0
, int_loc_descriptor (mask
));
12818 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
12819 add_loc_descr (&op1
, int_loc_descriptor (mask
));
12820 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
12822 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12824 HOST_WIDE_INT bias
= 1;
12825 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
12826 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
12827 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
12830 else if (!SCALAR_INT_MODE_P (mode
)
12831 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12833 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
12834 add_loc_descr (&op0
, int_loc_descriptor (shift
));
12835 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
12836 add_loc_descr (&op1
, int_loc_descriptor (shift
));
12837 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
12839 else if (SCALAR_INT_MODE_P (mode
)
12840 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12842 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
12843 dw_loc_descr_ref cvt
;
12844 if (type_die
== NULL
)
12846 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12847 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12848 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12849 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12850 add_loc_descr (&op0
, cvt
);
12851 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12852 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12853 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12854 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12855 add_loc_descr (&op1
, cvt
);
12858 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
12863 add_loc_descr (&ret
, op1
);
12864 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
12865 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12866 add_loc_descr (&ret
, bra_node
);
12867 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12868 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12869 add_loc_descr (&ret
, drop_node
);
12870 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12871 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12872 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
12873 && SCALAR_INT_MODE_P (mode
)
12874 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12875 ret
= convert_descriptor_to_mode (mode
, ret
);
12879 /* Helper function for mem_loc_descriptor. Perform OP binary op,
12880 but after converting arguments to type_die, afterwards
12881 convert back to unsigned. */
12883 static dw_loc_descr_ref
12884 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
12885 machine_mode mode
, machine_mode mem_mode
)
12887 dw_loc_descr_ref cvt
, op0
, op1
;
12889 if (type_die
== NULL
)
12891 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12892 VAR_INIT_STATUS_INITIALIZED
);
12893 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12894 VAR_INIT_STATUS_INITIALIZED
);
12895 if (op0
== NULL
|| op1
== NULL
)
12897 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12898 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12899 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12900 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12901 add_loc_descr (&op0
, cvt
);
12902 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12903 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12904 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12905 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12906 add_loc_descr (&op1
, cvt
);
12907 add_loc_descr (&op0
, op1
);
12908 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
12909 return convert_descriptor_to_mode (mode
, op0
);
12912 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
12913 const0 is DW_OP_lit0 or corresponding typed constant,
12914 const1 is DW_OP_lit1 or corresponding typed constant
12915 and constMSB is constant with just the MSB bit set
12917 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
12918 L1: const0 DW_OP_swap
12919 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
12920 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12925 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
12926 L1: const0 DW_OP_swap
12927 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
12928 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12933 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
12934 L1: const1 DW_OP_swap
12935 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
12936 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12940 static dw_loc_descr_ref
12941 clz_loc_descriptor (rtx rtl
, machine_mode mode
,
12942 machine_mode mem_mode
)
12944 dw_loc_descr_ref op0
, ret
, tmp
;
12945 HOST_WIDE_INT valv
;
12946 dw_loc_descr_ref l1jump
, l1label
;
12947 dw_loc_descr_ref l2jump
, l2label
;
12948 dw_loc_descr_ref l3jump
, l3label
;
12949 dw_loc_descr_ref l4jump
, l4label
;
12952 if (!SCALAR_INT_MODE_P (mode
)
12953 || GET_MODE (XEXP (rtl
, 0)) != mode
)
12956 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12957 VAR_INIT_STATUS_INITIALIZED
);
12961 if (GET_CODE (rtl
) == CLZ
)
12963 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
12964 valv
= GET_MODE_BITSIZE (mode
);
12966 else if (GET_CODE (rtl
) == FFS
)
12968 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
12969 valv
= GET_MODE_BITSIZE (mode
);
12970 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12971 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12972 add_loc_descr (&ret
, l1jump
);
12973 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
12974 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
12975 VAR_INIT_STATUS_INITIALIZED
);
12978 add_loc_descr (&ret
, tmp
);
12979 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12980 add_loc_descr (&ret
, l4jump
);
12981 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
12982 ? const1_rtx
: const0_rtx
,
12984 VAR_INIT_STATUS_INITIALIZED
);
12985 if (l1label
== NULL
)
12987 add_loc_descr (&ret
, l1label
);
12988 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12989 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
12990 add_loc_descr (&ret
, l2label
);
12991 if (GET_CODE (rtl
) != CLZ
)
12993 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
12994 msb
= GEN_INT (HOST_WIDE_INT_1U
12995 << (GET_MODE_BITSIZE (mode
) - 1));
12997 msb
= immed_wide_int_const
12998 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode
) - 1,
12999 GET_MODE_PRECISION (mode
)), mode
);
13000 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
13001 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
13002 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
13003 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
13005 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
13006 VAR_INIT_STATUS_INITIALIZED
);
13009 add_loc_descr (&ret
, tmp
);
13010 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
13011 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
13012 add_loc_descr (&ret
, l3jump
);
13013 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
13014 VAR_INIT_STATUS_INITIALIZED
);
13017 add_loc_descr (&ret
, tmp
);
13018 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
13019 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
13020 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
13021 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
13022 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
13023 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
13024 add_loc_descr (&ret
, l2jump
);
13025 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
13026 add_loc_descr (&ret
, l3label
);
13027 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
13028 add_loc_descr (&ret
, l4label
);
13029 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13030 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
13031 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13032 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
13033 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13034 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
13035 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13036 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
13040 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
13041 const1 is DW_OP_lit1 or corresponding typed constant):
13043 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
13044 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
13048 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
13049 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
13052 static dw_loc_descr_ref
13053 popcount_loc_descriptor (rtx rtl
, machine_mode mode
,
13054 machine_mode mem_mode
)
13056 dw_loc_descr_ref op0
, ret
, tmp
;
13057 dw_loc_descr_ref l1jump
, l1label
;
13058 dw_loc_descr_ref l2jump
, l2label
;
13060 if (!SCALAR_INT_MODE_P (mode
)
13061 || GET_MODE (XEXP (rtl
, 0)) != mode
)
13064 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13065 VAR_INIT_STATUS_INITIALIZED
);
13069 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
13070 VAR_INIT_STATUS_INITIALIZED
);
13073 add_loc_descr (&ret
, tmp
);
13074 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
13075 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
13076 add_loc_descr (&ret
, l1label
);
13077 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
13078 add_loc_descr (&ret
, l2jump
);
13079 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
13080 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
13081 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
13082 VAR_INIT_STATUS_INITIALIZED
);
13085 add_loc_descr (&ret
, tmp
);
13086 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
13087 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
13088 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
13089 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
13090 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
13091 VAR_INIT_STATUS_INITIALIZED
);
13092 add_loc_descr (&ret
, tmp
);
13093 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
13094 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
13095 add_loc_descr (&ret
, l1jump
);
13096 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
13097 add_loc_descr (&ret
, l2label
);
13098 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13099 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
13100 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13101 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
13105 /* BSWAP (constS is initial shift count, either 56 or 24):
13107 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
13108 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
13109 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
13110 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
13111 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
13113 static dw_loc_descr_ref
13114 bswap_loc_descriptor (rtx rtl
, machine_mode mode
,
13115 machine_mode mem_mode
)
13117 dw_loc_descr_ref op0
, ret
, tmp
;
13118 dw_loc_descr_ref l1jump
, l1label
;
13119 dw_loc_descr_ref l2jump
, l2label
;
13121 if (!SCALAR_INT_MODE_P (mode
)
13122 || BITS_PER_UNIT
!= 8
13123 || (GET_MODE_BITSIZE (mode
) != 32
13124 && GET_MODE_BITSIZE (mode
) != 64))
13127 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13128 VAR_INIT_STATUS_INITIALIZED
);
13133 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
13135 VAR_INIT_STATUS_INITIALIZED
);
13138 add_loc_descr (&ret
, tmp
);
13139 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
13140 VAR_INIT_STATUS_INITIALIZED
);
13143 add_loc_descr (&ret
, tmp
);
13144 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
13145 add_loc_descr (&ret
, l1label
);
13146 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
13148 VAR_INIT_STATUS_INITIALIZED
);
13149 add_loc_descr (&ret
, tmp
);
13150 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
13151 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
13152 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
13153 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
13154 VAR_INIT_STATUS_INITIALIZED
);
13157 add_loc_descr (&ret
, tmp
);
13158 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
13159 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
13160 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
13161 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
13162 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
13163 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
13164 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
13165 VAR_INIT_STATUS_INITIALIZED
);
13166 add_loc_descr (&ret
, tmp
);
13167 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
13168 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
13169 add_loc_descr (&ret
, l2jump
);
13170 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
13171 VAR_INIT_STATUS_INITIALIZED
);
13172 add_loc_descr (&ret
, tmp
);
13173 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
13174 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
13175 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
13176 add_loc_descr (&ret
, l1jump
);
13177 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
13178 add_loc_descr (&ret
, l2label
);
13179 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
13180 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
13181 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13182 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
13183 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13184 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
13188 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
13189 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
13190 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
13191 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
13193 ROTATERT is similar:
13194 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
13195 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
13196 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
13198 static dw_loc_descr_ref
13199 rotate_loc_descriptor (rtx rtl
, machine_mode mode
,
13200 machine_mode mem_mode
)
13202 rtx rtlop1
= XEXP (rtl
, 1);
13203 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
13206 if (!SCALAR_INT_MODE_P (mode
))
13209 if (GET_MODE (rtlop1
) != VOIDmode
13210 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
13211 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
13212 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13213 VAR_INIT_STATUS_INITIALIZED
);
13214 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
13215 VAR_INIT_STATUS_INITIALIZED
);
13216 if (op0
== NULL
|| op1
== NULL
)
13218 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
13219 for (i
= 0; i
< 2; i
++)
13221 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
13222 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
13224 VAR_INIT_STATUS_INITIALIZED
);
13225 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
13226 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
13228 : HOST_BITS_PER_WIDE_INT
== 64
13229 ? DW_OP_const8u
: DW_OP_constu
,
13230 GET_MODE_MASK (mode
), 0);
13233 if (mask
[i
] == NULL
)
13235 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
13238 add_loc_descr (&ret
, op1
);
13239 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
13240 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
13241 if (GET_CODE (rtl
) == ROTATERT
)
13243 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
13244 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
13245 GET_MODE_BITSIZE (mode
), 0));
13247 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
13248 if (mask
[0] != NULL
)
13249 add_loc_descr (&ret
, mask
[0]);
13250 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
13251 if (mask
[1] != NULL
)
13253 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
13254 add_loc_descr (&ret
, mask
[1]);
13255 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
13257 if (GET_CODE (rtl
) == ROTATE
)
13259 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
13260 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
13261 GET_MODE_BITSIZE (mode
), 0));
13263 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
13264 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
13268 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
13269 for DEBUG_PARAMETER_REF RTL. */
13271 static dw_loc_descr_ref
13272 parameter_ref_descriptor (rtx rtl
)
13274 dw_loc_descr_ref ret
;
13279 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
13280 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
13281 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
13284 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13285 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
13286 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13290 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
13291 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
13296 /* The following routine converts the RTL for a variable or parameter
13297 (resident in memory) into an equivalent Dwarf representation of a
13298 mechanism for getting the address of that same variable onto the top of a
13299 hypothetical "address evaluation" stack.
13301 When creating memory location descriptors, we are effectively transforming
13302 the RTL for a memory-resident object into its Dwarf postfix expression
13303 equivalent. This routine recursively descends an RTL tree, turning
13304 it into Dwarf postfix code as it goes.
13306 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
13308 MEM_MODE is the mode of the memory reference, needed to handle some
13309 autoincrement addressing modes.
13311 Return 0 if we can't represent the location. */
13314 mem_loc_descriptor (rtx rtl
, machine_mode mode
,
13315 machine_mode mem_mode
,
13316 enum var_init_status initialized
)
13318 dw_loc_descr_ref mem_loc_result
= NULL
;
13319 enum dwarf_location_atom op
;
13320 dw_loc_descr_ref op0
, op1
;
13321 rtx inner
= NULL_RTX
;
13323 if (mode
== VOIDmode
)
13324 mode
= GET_MODE (rtl
);
13326 /* Note that for a dynamically sized array, the location we will generate a
13327 description of here will be the lowest numbered location which is
13328 actually within the array. That's *not* necessarily the same as the
13329 zeroth element of the array. */
13331 rtl
= targetm
.delegitimize_address (rtl
);
13333 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
13336 switch (GET_CODE (rtl
))
13341 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
13344 /* The case of a subreg may arise when we have a local (register)
13345 variable or a formal (register) parameter which doesn't quite fill
13346 up an entire register. For now, just assume that it is
13347 legitimate to make the Dwarf info refer to the whole register which
13348 contains the given subreg. */
13349 if (!subreg_lowpart_p (rtl
))
13351 inner
= SUBREG_REG (rtl
);
13354 if (inner
== NULL_RTX
)
13355 inner
= XEXP (rtl
, 0);
13356 if (SCALAR_INT_MODE_P (mode
)
13357 && SCALAR_INT_MODE_P (GET_MODE (inner
))
13358 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13359 #ifdef POINTERS_EXTEND_UNSIGNED
13360 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
13363 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
13365 mem_loc_result
= mem_loc_descriptor (inner
,
13367 mem_mode
, initialized
);
13372 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
13374 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
13375 && (!SCALAR_INT_MODE_P (mode
)
13376 || !SCALAR_INT_MODE_P (GET_MODE (inner
))))
13380 dw_die_ref type_die
;
13381 dw_loc_descr_ref cvt
;
13383 mem_loc_result
= mem_loc_descriptor (inner
,
13385 mem_mode
, initialized
);
13386 if (mem_loc_result
== NULL
)
13388 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
13389 if (type_die
== NULL
)
13391 mem_loc_result
= NULL
;
13394 if (GET_MODE_SIZE (mode
)
13395 != GET_MODE_SIZE (GET_MODE (inner
)))
13396 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13398 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
13399 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13400 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13401 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13402 add_loc_descr (&mem_loc_result
, cvt
);
13403 if (SCALAR_INT_MODE_P (mode
)
13404 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
13406 /* Convert it to untyped afterwards. */
13407 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13408 add_loc_descr (&mem_loc_result
, cvt
);
13414 if (! SCALAR_INT_MODE_P (mode
)
13415 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
13416 && rtl
!= arg_pointer_rtx
13417 && rtl
!= frame_pointer_rtx
13418 #ifdef POINTERS_EXTEND_UNSIGNED
13419 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
13423 dw_die_ref type_die
;
13424 unsigned int dbx_regnum
;
13428 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
13430 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
13431 if (type_die
== NULL
)
13434 dbx_regnum
= dbx_reg_number (rtl
);
13435 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
13437 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
13439 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
13440 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
13441 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
13444 /* Whenever a register number forms a part of the description of the
13445 method for calculating the (dynamic) address of a memory resident
13446 object, DWARF rules require the register number be referred to as
13447 a "base register". This distinction is not based in any way upon
13448 what category of register the hardware believes the given register
13449 belongs to. This is strictly DWARF terminology we're dealing with
13450 here. Note that in cases where the location of a memory-resident
13451 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
13452 OP_CONST (0)) the actual DWARF location descriptor that we generate
13453 may just be OP_BASEREG (basereg). This may look deceptively like
13454 the object in question was allocated to a register (rather than in
13455 memory) so DWARF consumers need to be aware of the subtle
13456 distinction between OP_REG and OP_BASEREG. */
13457 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
13458 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
13459 else if (stack_realign_drap
13461 && crtl
->args
.internal_arg_pointer
== rtl
13462 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
13464 /* If RTL is internal_arg_pointer, which has been optimized
13465 out, use DRAP instead. */
13466 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
13467 VAR_INIT_STATUS_INITIALIZED
);
13473 if (!SCALAR_INT_MODE_P (mode
))
13475 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
13476 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13479 else if (GET_CODE (rtl
) == ZERO_EXTEND
13480 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13481 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
13482 < HOST_BITS_PER_WIDE_INT
13483 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
13484 to expand zero extend as two shifts instead of
13486 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
13488 machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
13489 mem_loc_result
= op0
;
13490 add_loc_descr (&mem_loc_result
,
13491 int_loc_descriptor (GET_MODE_MASK (imode
)));
13492 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
13494 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
13496 int shift
= DWARF2_ADDR_SIZE
13497 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
13498 shift
*= BITS_PER_UNIT
;
13499 if (GET_CODE (rtl
) == SIGN_EXTEND
)
13503 mem_loc_result
= op0
;
13504 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
13505 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
13506 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
13507 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13509 else if (!dwarf_strict
)
13511 dw_die_ref type_die1
, type_die2
;
13512 dw_loc_descr_ref cvt
;
13514 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
13515 GET_CODE (rtl
) == ZERO_EXTEND
);
13516 if (type_die1
== NULL
)
13518 type_die2
= base_type_for_mode (mode
, 1);
13519 if (type_die2
== NULL
)
13521 mem_loc_result
= op0
;
13522 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13523 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13524 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
13525 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13526 add_loc_descr (&mem_loc_result
, cvt
);
13527 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13528 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13529 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
13530 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13531 add_loc_descr (&mem_loc_result
, cvt
);
13537 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
13538 if (new_rtl
!= rtl
)
13540 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
13542 if (mem_loc_result
!= NULL
)
13543 return mem_loc_result
;
13546 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
13547 get_address_mode (rtl
), mode
,
13548 VAR_INIT_STATUS_INITIALIZED
);
13549 if (mem_loc_result
== NULL
)
13550 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
13551 if (mem_loc_result
!= NULL
)
13553 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
13554 || !SCALAR_INT_MODE_P(mode
))
13556 dw_die_ref type_die
;
13557 dw_loc_descr_ref deref
;
13562 = base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
13563 if (type_die
== NULL
)
13565 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
13566 GET_MODE_SIZE (mode
), 0);
13567 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
13568 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
13569 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
13570 add_loc_descr (&mem_loc_result
, deref
);
13572 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
13573 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
13575 add_loc_descr (&mem_loc_result
,
13576 new_loc_descr (DW_OP_deref_size
,
13577 GET_MODE_SIZE (mode
), 0));
13582 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
13585 /* Some ports can transform a symbol ref into a label ref, because
13586 the symbol ref is too far away and has to be dumped into a constant
13590 if (!SCALAR_INT_MODE_P (mode
)
13591 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
13592 #ifdef POINTERS_EXTEND_UNSIGNED
13593 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
13597 if (GET_CODE (rtl
) == SYMBOL_REF
13598 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
13600 dw_loc_descr_ref temp
;
13602 /* If this is not defined, we have no way to emit the data. */
13603 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
13606 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
13608 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
13609 add_loc_descr (&mem_loc_result
, temp
);
13614 if (!const_ok_for_output (rtl
))
13616 if (GET_CODE (rtl
) == CONST
)
13617 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13623 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13624 vec_safe_push (used_rtx_array
, rtl
);
13630 case DEBUG_IMPLICIT_PTR
:
13631 expansion_failed (NULL_TREE
, rtl
,
13632 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
13638 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
13640 if (!SCALAR_INT_MODE_P (mode
)
13641 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
13642 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
13643 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13646 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
13647 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
13649 op0
= one_reg_loc_descriptor (dbx_regnum
,
13650 VAR_INIT_STATUS_INITIALIZED
);
13653 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
13654 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
13656 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
13657 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13658 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
13662 gcc_unreachable ();
13665 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
13666 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13667 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
13670 case DEBUG_PARAMETER_REF
:
13671 mem_loc_result
= parameter_ref_descriptor (rtl
);
13675 /* Extract the PLUS expression nested inside and fall into
13676 PLUS code below. */
13677 rtl
= XEXP (rtl
, 1);
13682 /* Turn these into a PLUS expression and fall into the PLUS code
13684 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
13685 gen_int_mode (GET_CODE (rtl
) == PRE_INC
13686 ? GET_MODE_UNIT_SIZE (mem_mode
)
13687 : -GET_MODE_UNIT_SIZE (mem_mode
),
13694 if (is_based_loc (rtl
)
13695 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13696 || XEXP (rtl
, 0) == arg_pointer_rtx
13697 || XEXP (rtl
, 0) == frame_pointer_rtx
)
13698 && SCALAR_INT_MODE_P (mode
))
13699 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
13700 INTVAL (XEXP (rtl
, 1)),
13701 VAR_INIT_STATUS_INITIALIZED
);
13704 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13705 VAR_INIT_STATUS_INITIALIZED
);
13706 if (mem_loc_result
== 0)
13709 if (CONST_INT_P (XEXP (rtl
, 1))
13710 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
13711 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
13714 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13715 VAR_INIT_STATUS_INITIALIZED
);
13718 add_loc_descr (&mem_loc_result
, op1
);
13719 add_loc_descr (&mem_loc_result
,
13720 new_loc_descr (DW_OP_plus
, 0, 0));
13725 /* If a pseudo-reg is optimized away, it is possible for it to
13726 be replaced with a MEM containing a multiply or shift. */
13737 && SCALAR_INT_MODE_P (mode
)
13738 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
13740 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
13741 base_type_for_mode (mode
, 0),
13765 if (!SCALAR_INT_MODE_P (mode
))
13767 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13768 VAR_INIT_STATUS_INITIALIZED
);
13770 rtx rtlop1
= XEXP (rtl
, 1);
13771 if (GET_MODE (rtlop1
) != VOIDmode
13772 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
13773 < GET_MODE_BITSIZE (mode
))
13774 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
13775 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
13776 VAR_INIT_STATUS_INITIALIZED
);
13779 if (op0
== 0 || op1
== 0)
13782 mem_loc_result
= op0
;
13783 add_loc_descr (&mem_loc_result
, op1
);
13784 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13800 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13801 VAR_INIT_STATUS_INITIALIZED
);
13802 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13803 VAR_INIT_STATUS_INITIALIZED
);
13805 if (op0
== 0 || op1
== 0)
13808 mem_loc_result
= op0
;
13809 add_loc_descr (&mem_loc_result
, op1
);
13810 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13814 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
13816 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
13817 base_type_for_mode (mode
, 0),
13822 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13823 VAR_INIT_STATUS_INITIALIZED
);
13824 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13825 VAR_INIT_STATUS_INITIALIZED
);
13827 if (op0
== 0 || op1
== 0)
13830 mem_loc_result
= op0
;
13831 add_loc_descr (&mem_loc_result
, op1
);
13832 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
13833 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
13834 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
13835 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
13836 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
13840 if (!dwarf_strict
&& SCALAR_INT_MODE_P (mode
))
13842 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
13847 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
13848 base_type_for_mode (mode
, 1),
13866 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13867 VAR_INIT_STATUS_INITIALIZED
);
13872 mem_loc_result
= op0
;
13873 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13877 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13878 #ifdef POINTERS_EXTEND_UNSIGNED
13880 && mem_mode
!= VOIDmode
13881 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
13885 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
13889 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
13890 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
13892 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
13893 machine_mode amode
;
13894 if (type_die
== NULL
)
13896 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
13898 if (INTVAL (rtl
) >= 0
13899 && amode
!= BLKmode
13900 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
13901 /* const DW_OP_GNU_convert <XXX> vs.
13902 DW_OP_GNU_const_type <XXX, 1, const>. */
13903 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
13904 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
13906 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
13907 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13908 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13909 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13910 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13911 add_loc_descr (&mem_loc_result
, op0
);
13912 return mem_loc_result
;
13914 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
13916 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13917 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13918 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13919 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
13920 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13923 mem_loc_result
->dw_loc_oprnd2
.val_class
13924 = dw_val_class_const_double
;
13925 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
13926 = double_int::from_shwi (INTVAL (rtl
));
13934 dw_die_ref type_die
;
13936 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
13937 CONST_DOUBLE rtx could represent either a large integer
13938 or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
13939 the value is always a floating point constant.
13941 When it is an integer, a CONST_DOUBLE is used whenever
13942 the constant requires 2 HWIs to be adequately represented.
13943 We output CONST_DOUBLEs as blocks. */
13944 if (mode
== VOIDmode
13945 || (GET_MODE (rtl
) == VOIDmode
13946 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
13948 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
13949 if (type_die
== NULL
)
13951 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
13952 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13953 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13954 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13955 #if TARGET_SUPPORTS_WIDE_INT == 0
13956 if (!SCALAR_FLOAT_MODE_P (mode
))
13958 mem_loc_result
->dw_loc_oprnd2
.val_class
13959 = dw_val_class_const_double
;
13960 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
13961 = rtx_to_double_int (rtl
);
13966 unsigned int length
= GET_MODE_SIZE (mode
);
13967 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
13969 insert_float (rtl
, array
);
13970 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13971 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13972 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13973 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13978 case CONST_WIDE_INT
:
13981 dw_die_ref type_die
;
13983 type_die
= base_type_for_mode (mode
, SCALAR_INT_MODE_P (mode
));
13984 if (type_die
== NULL
)
13986 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
13987 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13988 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13989 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13990 mem_loc_result
->dw_loc_oprnd2
.val_class
13991 = dw_val_class_wide_int
;
13992 mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
13993 *mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= std::make_pair (rtl
, mode
);
13998 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
14002 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
14006 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
14010 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
14014 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
14018 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
14022 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
14026 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
14030 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
14034 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
14039 if (!SCALAR_INT_MODE_P (mode
))
14044 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
14049 if (CONST_INT_P (XEXP (rtl
, 1))
14050 && CONST_INT_P (XEXP (rtl
, 2))
14051 && ((unsigned) INTVAL (XEXP (rtl
, 1))
14052 + (unsigned) INTVAL (XEXP (rtl
, 2))
14053 <= GET_MODE_BITSIZE (mode
))
14054 && SCALAR_INT_MODE_P (mode
)
14055 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
14056 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
14059 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
14060 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
14063 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
14067 mem_loc_result
= op0
;
14068 size
= INTVAL (XEXP (rtl
, 1));
14069 shift
= INTVAL (XEXP (rtl
, 2));
14070 if (BITS_BIG_ENDIAN
)
14071 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
14073 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
14075 add_loc_descr (&mem_loc_result
,
14076 int_loc_descriptor (DWARF2_ADDR_SIZE
14078 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
14080 if (size
!= (int) DWARF2_ADDR_SIZE
)
14082 add_loc_descr (&mem_loc_result
,
14083 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
14084 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
14091 dw_loc_descr_ref op2
, bra_node
, drop_node
;
14092 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
14093 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
14094 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
14095 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
14096 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
14097 VAR_INIT_STATUS_INITIALIZED
);
14098 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
14099 VAR_INIT_STATUS_INITIALIZED
);
14100 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
14103 mem_loc_result
= op1
;
14104 add_loc_descr (&mem_loc_result
, op2
);
14105 add_loc_descr (&mem_loc_result
, op0
);
14106 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14107 add_loc_descr (&mem_loc_result
, bra_node
);
14108 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
14109 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
14110 add_loc_descr (&mem_loc_result
, drop_node
);
14111 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14112 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
14117 case FLOAT_TRUNCATE
:
14119 case UNSIGNED_FLOAT
:
14124 dw_die_ref type_die
;
14125 dw_loc_descr_ref cvt
;
14127 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
14128 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
14131 if (SCALAR_INT_MODE_P (GET_MODE (XEXP (rtl
, 0)))
14132 && (GET_CODE (rtl
) == FLOAT
14133 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
14134 <= DWARF2_ADDR_SIZE
))
14136 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
14137 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
14138 if (type_die
== NULL
)
14140 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
14141 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14142 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14143 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14144 add_loc_descr (&op0
, cvt
);
14146 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
14147 if (type_die
== NULL
)
14149 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
14150 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14151 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14152 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14153 add_loc_descr (&op0
, cvt
);
14154 if (SCALAR_INT_MODE_P (mode
)
14155 && (GET_CODE (rtl
) == FIX
14156 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
14158 op0
= convert_descriptor_to_mode (mode
, op0
);
14162 mem_loc_result
= op0
;
14169 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
14174 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
14178 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
14183 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
14187 /* In theory, we could implement the above. */
14188 /* DWARF cannot represent the unsigned compare operations
14213 case FRACT_CONVERT
:
14214 case UNSIGNED_FRACT_CONVERT
:
14216 case UNSIGNED_SAT_FRACT
:
14222 case VEC_DUPLICATE
:
14226 case STRICT_LOW_PART
:
14231 /* If delegitimize_address couldn't do anything with the UNSPEC, we
14232 can't express it in the debug info. This can happen e.g. with some
14237 resolve_one_addr (&rtl
);
14243 print_rtl (stderr
, rtl
);
14244 gcc_unreachable ();
14249 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14250 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14252 return mem_loc_result
;
14255 /* Return a descriptor that describes the concatenation of two locations.
14256 This is typically a complex variable. */
14258 static dw_loc_descr_ref
14259 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
14261 dw_loc_descr_ref cc_loc_result
= NULL
;
14262 dw_loc_descr_ref x0_ref
14263 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14264 dw_loc_descr_ref x1_ref
14265 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14267 if (x0_ref
== 0 || x1_ref
== 0)
14270 cc_loc_result
= x0_ref
;
14271 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
14273 add_loc_descr (&cc_loc_result
, x1_ref
);
14274 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
14276 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14277 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14279 return cc_loc_result
;
14282 /* Return a descriptor that describes the concatenation of N
14285 static dw_loc_descr_ref
14286 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
14289 dw_loc_descr_ref cc_loc_result
= NULL
;
14290 unsigned int n
= XVECLEN (concatn
, 0);
14292 for (i
= 0; i
< n
; ++i
)
14294 dw_loc_descr_ref ref
;
14295 rtx x
= XVECEXP (concatn
, 0, i
);
14297 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14301 add_loc_descr (&cc_loc_result
, ref
);
14302 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
14305 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14306 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14308 return cc_loc_result
;
14311 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
14312 for DEBUG_IMPLICIT_PTR RTL. */
14314 static dw_loc_descr_ref
14315 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
14317 dw_loc_descr_ref ret
;
14322 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
14323 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
14324 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
14325 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
14326 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
14327 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
14330 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14331 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
14332 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14336 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
14337 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
14342 /* Output a proper Dwarf location descriptor for a variable or parameter
14343 which is either allocated in a register or in a memory location. For a
14344 register, we just generate an OP_REG and the register number. For a
14345 memory location we provide a Dwarf postfix expression describing how to
14346 generate the (dynamic) address of the object onto the address stack.
14348 MODE is mode of the decl if this loc_descriptor is going to be used in
14349 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
14350 allowed, VOIDmode otherwise.
14352 If we don't know how to describe it, return 0. */
14354 static dw_loc_descr_ref
14355 loc_descriptor (rtx rtl
, machine_mode mode
,
14356 enum var_init_status initialized
)
14358 dw_loc_descr_ref loc_result
= NULL
;
14360 switch (GET_CODE (rtl
))
14363 /* The case of a subreg may arise when we have a local (register)
14364 variable or a formal (register) parameter which doesn't quite fill
14365 up an entire register. For now, just assume that it is
14366 legitimate to make the Dwarf info refer to the whole register which
14367 contains the given subreg. */
14368 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
14369 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
14370 GET_MODE (SUBREG_REG (rtl
)), initialized
);
14376 loc_result
= reg_loc_descriptor (rtl
, initialized
);
14380 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
14381 GET_MODE (rtl
), initialized
);
14382 if (loc_result
== NULL
)
14383 loc_result
= tls_mem_loc_descriptor (rtl
);
14384 if (loc_result
== NULL
)
14386 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
14387 if (new_rtl
!= rtl
)
14388 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
14393 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
14398 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
14403 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
14405 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
14406 if (GET_CODE (loc
) == EXPR_LIST
)
14407 loc
= XEXP (loc
, 0);
14408 loc_result
= loc_descriptor (loc
, mode
, initialized
);
14412 rtl
= XEXP (rtl
, 1);
14417 rtvec par_elems
= XVEC (rtl
, 0);
14418 int num_elem
= GET_NUM_ELEM (par_elems
);
14422 /* Create the first one, so we have something to add to. */
14423 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
14424 VOIDmode
, initialized
);
14425 if (loc_result
== NULL
)
14427 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
14428 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
14429 for (i
= 1; i
< num_elem
; i
++)
14431 dw_loc_descr_ref temp
;
14433 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
14434 VOIDmode
, initialized
);
14437 add_loc_descr (&loc_result
, temp
);
14438 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
14439 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
14445 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
14446 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
14451 if (mode
== VOIDmode
)
14452 mode
= GET_MODE (rtl
);
14454 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
14456 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
14458 /* Note that a CONST_DOUBLE rtx could represent either an integer
14459 or a floating-point constant. A CONST_DOUBLE is used whenever
14460 the constant requires more than one word in order to be
14461 adequately represented. We output CONST_DOUBLEs as blocks. */
14462 loc_result
= new_loc_descr (DW_OP_implicit_value
,
14463 GET_MODE_SIZE (mode
), 0);
14464 #if TARGET_SUPPORTS_WIDE_INT == 0
14465 if (!SCALAR_FLOAT_MODE_P (mode
))
14467 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
14468 loc_result
->dw_loc_oprnd2
.v
.val_double
14469 = rtx_to_double_int (rtl
);
14474 unsigned int length
= GET_MODE_SIZE (mode
);
14475 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
14477 insert_float (rtl
, array
);
14478 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
14479 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
14480 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
14481 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
14486 case CONST_WIDE_INT
:
14487 if (mode
== VOIDmode
)
14488 mode
= GET_MODE (rtl
);
14490 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
14492 loc_result
= new_loc_descr (DW_OP_implicit_value
,
14493 GET_MODE_SIZE (mode
), 0);
14494 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_wide_int
;
14495 loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
14496 *loc_result
->dw_loc_oprnd2
.v
.val_wide
= std::make_pair (rtl
, mode
);
14501 if (mode
== VOIDmode
)
14502 mode
= GET_MODE (rtl
);
14504 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
14506 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
14507 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
14508 unsigned char *array
14509 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
14512 machine_mode imode
= GET_MODE_INNER (mode
);
14514 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
14515 switch (GET_MODE_CLASS (mode
))
14517 case MODE_VECTOR_INT
:
14518 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14520 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14521 insert_wide_int (std::make_pair (elt
, imode
), p
, elt_size
);
14525 case MODE_VECTOR_FLOAT
:
14526 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14528 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14529 insert_float (elt
, p
);
14534 gcc_unreachable ();
14537 loc_result
= new_loc_descr (DW_OP_implicit_value
,
14538 length
* elt_size
, 0);
14539 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
14540 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
14541 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
14542 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
14547 if (mode
== VOIDmode
14548 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
14549 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
14550 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
14552 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
14557 if (!const_ok_for_output (rtl
))
14560 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
14561 && (dwarf_version
>= 4 || !dwarf_strict
))
14563 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
14564 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14565 vec_safe_push (used_rtx_array
, rtl
);
14569 case DEBUG_IMPLICIT_PTR
:
14570 loc_result
= implicit_ptr_descriptor (rtl
, 0);
14574 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
14575 && CONST_INT_P (XEXP (rtl
, 1)))
14578 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
14584 if ((SCALAR_INT_MODE_P (mode
)
14585 && GET_MODE (rtl
) == mode
14586 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
14587 && dwarf_version
>= 4)
14588 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
14590 /* Value expression. */
14591 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
14593 add_loc_descr (&loc_result
,
14594 new_loc_descr (DW_OP_stack_value
, 0, 0));
14602 /* We need to figure out what section we should use as the base for the
14603 address ranges where a given location is valid.
14604 1. If this particular DECL has a section associated with it, use that.
14605 2. If this function has a section associated with it, use that.
14606 3. Otherwise, use the text section.
14607 XXX: If you split a variable across multiple sections, we won't notice. */
14609 static const char *
14610 secname_for_decl (const_tree decl
)
14612 const char *secname
;
14614 if (VAR_OR_FUNCTION_DECL_P (decl
)
14615 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
) || TREE_STATIC (decl
))
14616 && DECL_SECTION_NAME (decl
))
14617 secname
= DECL_SECTION_NAME (decl
);
14618 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
14619 secname
= DECL_SECTION_NAME (current_function_decl
);
14620 else if (cfun
&& in_cold_section_p
)
14621 secname
= crtl
->subsections
.cold_section_label
;
14623 secname
= text_section_label
;
14628 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
14631 decl_by_reference_p (tree decl
)
14633 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
14634 || TREE_CODE (decl
) == VAR_DECL
)
14635 && DECL_BY_REFERENCE (decl
));
14638 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14641 static dw_loc_descr_ref
14642 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
14643 enum var_init_status initialized
)
14645 int have_address
= 0;
14646 dw_loc_descr_ref descr
;
14649 if (want_address
!= 2)
14651 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
14653 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
14655 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
14656 if (GET_CODE (varloc
) == EXPR_LIST
)
14657 varloc
= XEXP (varloc
, 0);
14658 mode
= GET_MODE (varloc
);
14659 if (MEM_P (varloc
))
14661 rtx addr
= XEXP (varloc
, 0);
14662 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
14663 mode
, initialized
);
14668 rtx x
= avoid_constant_pool_reference (varloc
);
14670 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
14675 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
14682 if (GET_CODE (varloc
) == VAR_LOCATION
)
14683 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
14685 mode
= DECL_MODE (loc
);
14686 descr
= loc_descriptor (varloc
, mode
, initialized
);
14693 if (want_address
== 2 && !have_address
14694 && (dwarf_version
>= 4 || !dwarf_strict
))
14696 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14698 expansion_failed (loc
, NULL_RTX
,
14699 "DWARF address size mismatch");
14702 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14705 /* Show if we can't fill the request for an address. */
14706 if (want_address
&& !have_address
)
14708 expansion_failed (loc
, NULL_RTX
,
14709 "Want address and only have value");
14713 /* If we've got an address and don't want one, dereference. */
14714 if (!want_address
&& have_address
)
14716 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14717 enum dwarf_location_atom op
;
14719 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14721 expansion_failed (loc
, NULL_RTX
,
14722 "DWARF address size mismatch");
14725 else if (size
== DWARF2_ADDR_SIZE
)
14728 op
= DW_OP_deref_size
;
14730 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
14736 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
14737 if it is not possible. */
14739 static dw_loc_descr_ref
14740 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
14742 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
14743 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
14744 else if (dwarf_version
>= 3 || !dwarf_strict
)
14745 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
14750 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14751 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
14753 static dw_loc_descr_ref
14754 dw_sra_loc_expr (tree decl
, rtx loc
)
14757 unsigned HOST_WIDE_INT padsize
= 0;
14758 dw_loc_descr_ref descr
, *descr_tail
;
14759 unsigned HOST_WIDE_INT decl_size
;
14761 enum var_init_status initialized
;
14763 if (DECL_SIZE (decl
) == NULL
14764 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
14767 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
14769 descr_tail
= &descr
;
14771 for (p
= loc
; p
; p
= XEXP (p
, 1))
14773 unsigned HOST_WIDE_INT bitsize
= decl_piece_bitsize (p
);
14774 rtx loc_note
= *decl_piece_varloc_ptr (p
);
14775 dw_loc_descr_ref cur_descr
;
14776 dw_loc_descr_ref
*tail
, last
= NULL
;
14777 unsigned HOST_WIDE_INT opsize
= 0;
14779 if (loc_note
== NULL_RTX
14780 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
14782 padsize
+= bitsize
;
14785 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
14786 varloc
= NOTE_VAR_LOCATION (loc_note
);
14787 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
14788 if (cur_descr
== NULL
)
14790 padsize
+= bitsize
;
14794 /* Check that cur_descr either doesn't use
14795 DW_OP_*piece operations, or their sum is equal
14796 to bitsize. Otherwise we can't embed it. */
14797 for (tail
= &cur_descr
; *tail
!= NULL
;
14798 tail
= &(*tail
)->dw_loc_next
)
14799 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
14801 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
14805 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
14807 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
14811 if (last
!= NULL
&& opsize
!= bitsize
)
14813 padsize
+= bitsize
;
14814 /* Discard the current piece of the descriptor and release any
14815 addr_table entries it uses. */
14816 remove_loc_list_addr_table_entries (cur_descr
);
14820 /* If there is a hole, add DW_OP_*piece after empty DWARF
14821 expression, which means that those bits are optimized out. */
14824 if (padsize
> decl_size
)
14826 remove_loc_list_addr_table_entries (cur_descr
);
14827 goto discard_descr
;
14829 decl_size
-= padsize
;
14830 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
14831 if (*descr_tail
== NULL
)
14833 remove_loc_list_addr_table_entries (cur_descr
);
14834 goto discard_descr
;
14836 descr_tail
= &(*descr_tail
)->dw_loc_next
;
14839 *descr_tail
= cur_descr
;
14841 if (bitsize
> decl_size
)
14842 goto discard_descr
;
14843 decl_size
-= bitsize
;
14846 HOST_WIDE_INT offset
= 0;
14847 if (GET_CODE (varloc
) == VAR_LOCATION
14848 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
14850 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
14851 if (GET_CODE (varloc
) == EXPR_LIST
)
14852 varloc
= XEXP (varloc
, 0);
14856 if (GET_CODE (varloc
) == CONST
14857 || GET_CODE (varloc
) == SIGN_EXTEND
14858 || GET_CODE (varloc
) == ZERO_EXTEND
)
14859 varloc
= XEXP (varloc
, 0);
14860 else if (GET_CODE (varloc
) == SUBREG
)
14861 varloc
= SUBREG_REG (varloc
);
14866 /* DW_OP_bit_size offset should be zero for register
14867 or implicit location descriptions and empty location
14868 descriptions, but for memory addresses needs big endian
14870 if (MEM_P (varloc
))
14872 unsigned HOST_WIDE_INT memsize
14873 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
14874 if (memsize
!= bitsize
)
14876 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
14877 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
14878 goto discard_descr
;
14879 if (memsize
< bitsize
)
14880 goto discard_descr
;
14881 if (BITS_BIG_ENDIAN
)
14882 offset
= memsize
- bitsize
;
14886 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
14887 if (*descr_tail
== NULL
)
14888 goto discard_descr
;
14889 descr_tail
= &(*descr_tail
)->dw_loc_next
;
14893 /* If there were any non-empty expressions, add padding till the end of
14895 if (descr
!= NULL
&& decl_size
!= 0)
14897 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
14898 if (*descr_tail
== NULL
)
14899 goto discard_descr
;
14904 /* Discard the descriptor and release any addr_table entries it uses. */
14905 remove_loc_list_addr_table_entries (descr
);
14909 /* Return the dwarf representation of the location list LOC_LIST of
14910 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
14913 static dw_loc_list_ref
14914 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
14916 const char *endname
, *secname
;
14918 enum var_init_status initialized
;
14919 struct var_loc_node
*node
;
14920 dw_loc_descr_ref descr
;
14921 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
14922 dw_loc_list_ref list
= NULL
;
14923 dw_loc_list_ref
*listp
= &list
;
14925 /* Now that we know what section we are using for a base,
14926 actually construct the list of locations.
14927 The first location information is what is passed to the
14928 function that creates the location list, and the remaining
14929 locations just get added on to that list.
14930 Note that we only know the start address for a location
14931 (IE location changes), so to build the range, we use
14932 the range [current location start, next location start].
14933 This means we have to special case the last node, and generate
14934 a range of [last location start, end of function label]. */
14936 secname
= secname_for_decl (decl
);
14938 for (node
= loc_list
->first
; node
; node
= node
->next
)
14939 if (GET_CODE (node
->loc
) == EXPR_LIST
14940 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
14942 if (GET_CODE (node
->loc
) == EXPR_LIST
)
14944 /* This requires DW_OP_{,bit_}piece, which is not usable
14945 inside DWARF expressions. */
14946 if (want_address
!= 2)
14948 descr
= dw_sra_loc_expr (decl
, node
->loc
);
14954 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
14955 varloc
= NOTE_VAR_LOCATION (node
->loc
);
14956 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
14960 bool range_across_switch
= false;
14961 /* If section switch happens in between node->label
14962 and node->next->label (or end of function) and
14963 we can't emit it as a single entry list,
14964 emit two ranges, first one ending at the end
14965 of first partition and second one starting at the
14966 beginning of second partition. */
14967 if (node
== loc_list
->last_before_switch
14968 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
14969 && current_function_decl
)
14971 endname
= cfun
->fde
->dw_fde_end
;
14972 range_across_switch
= true;
14974 /* The variable has a location between NODE->LABEL and
14975 NODE->NEXT->LABEL. */
14976 else if (node
->next
)
14977 endname
= node
->next
->label
;
14978 /* If the variable has a location at the last label
14979 it keeps its location until the end of function. */
14980 else if (!current_function_decl
)
14981 endname
= text_end_label
;
14984 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
14985 current_function_funcdef_no
);
14986 endname
= ggc_strdup (label_id
);
14989 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
14990 if (TREE_CODE (decl
) == PARM_DECL
14991 && node
== loc_list
->first
14992 && NOTE_P (node
->loc
)
14993 && strcmp (node
->label
, endname
) == 0)
14994 (*listp
)->force
= true;
14995 listp
= &(*listp
)->dw_loc_next
;
14997 if (range_across_switch
)
14999 if (GET_CODE (node
->loc
) == EXPR_LIST
)
15000 descr
= dw_sra_loc_expr (decl
, node
->loc
);
15003 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
15004 varloc
= NOTE_VAR_LOCATION (node
->loc
);
15005 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
15008 gcc_assert (descr
);
15009 /* The variable has a location between NODE->LABEL and
15010 NODE->NEXT->LABEL. */
15012 endname
= node
->next
->label
;
15014 endname
= cfun
->fde
->dw_fde_second_end
;
15015 *listp
= new_loc_list (descr
,
15016 cfun
->fde
->dw_fde_second_begin
,
15018 listp
= &(*listp
)->dw_loc_next
;
15023 /* Try to avoid the overhead of a location list emitting a location
15024 expression instead, but only if we didn't have more than one
15025 location entry in the first place. If some entries were not
15026 representable, we don't want to pretend a single entry that was
15027 applies to the entire scope in which the variable is
15029 if (list
&& loc_list
->first
->next
)
15035 /* Return if the loc_list has only single element and thus can be represented
15036 as location description. */
15039 single_element_loc_list_p (dw_loc_list_ref list
)
15041 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
15042 return !list
->ll_symbol
;
15045 /* To each location in list LIST add loc descr REF. */
15048 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
15050 dw_loc_descr_ref copy
;
15051 add_loc_descr (&list
->expr
, ref
);
15052 list
= list
->dw_loc_next
;
15055 copy
= ggc_alloc
<dw_loc_descr_node
> ();
15056 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
15057 add_loc_descr (&list
->expr
, copy
);
15058 while (copy
->dw_loc_next
)
15060 dw_loc_descr_ref new_copy
= ggc_alloc
<dw_loc_descr_node
> ();
15061 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
15062 copy
->dw_loc_next
= new_copy
;
15065 list
= list
->dw_loc_next
;
15069 /* Given two lists RET and LIST
15070 produce location list that is result of adding expression in LIST
15071 to expression in RET on each position in program.
15072 Might be destructive on both RET and LIST.
15074 TODO: We handle only simple cases of RET or LIST having at most one
15075 element. General case would inolve sorting the lists in program order
15076 and merging them that will need some additional work.
15077 Adding that will improve quality of debug info especially for SRA-ed
15081 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
15090 if (!list
->dw_loc_next
)
15092 add_loc_descr_to_each (*ret
, list
->expr
);
15095 if (!(*ret
)->dw_loc_next
)
15097 add_loc_descr_to_each (list
, (*ret
)->expr
);
15101 expansion_failed (NULL_TREE
, NULL_RTX
,
15102 "Don't know how to merge two non-trivial"
15103 " location lists.\n");
15108 /* LOC is constant expression. Try a luck, look it up in constant
15109 pool and return its loc_descr of its address. */
15111 static dw_loc_descr_ref
15112 cst_pool_loc_descr (tree loc
)
15114 /* Get an RTL for this, if something has been emitted. */
15115 rtx rtl
= lookup_constant_def (loc
);
15117 if (!rtl
|| !MEM_P (rtl
))
15122 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
15124 /* TODO: We might get more coverage if we was actually delaying expansion
15125 of all expressions till end of compilation when constant pools are fully
15127 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
15129 expansion_failed (loc
, NULL_RTX
,
15130 "CST value in contant pool but not marked.");
15133 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
15134 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
15137 /* Return dw_loc_list representing address of addr_expr LOC
15138 by looking for inner INDIRECT_REF expression and turning
15139 it into simple arithmetics.
15141 See loc_list_from_tree for the meaning of CONTEXT. */
15143 static dw_loc_list_ref
15144 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
,
15145 const loc_descr_context
*context
)
15148 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
15150 int unsignedp
, reversep
, volatilep
= 0;
15151 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
15153 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
15154 &bitsize
, &bitpos
, &offset
, &mode
,
15155 &unsignedp
, &reversep
, &volatilep
);
15157 if (bitpos
% BITS_PER_UNIT
)
15159 expansion_failed (loc
, NULL_RTX
, "bitfield access");
15162 if (!INDIRECT_REF_P (obj
))
15164 expansion_failed (obj
,
15165 NULL_RTX
, "no indirect ref in inner refrence");
15168 if (!offset
&& !bitpos
)
15169 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1,
15172 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
15173 && (dwarf_version
>= 4 || !dwarf_strict
))
15175 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0, context
);
15180 /* Variable offset. */
15181 list_ret1
= loc_list_from_tree (offset
, 0, context
);
15182 if (list_ret1
== 0)
15184 add_loc_list (&list_ret
, list_ret1
);
15187 add_loc_descr_to_each (list_ret
,
15188 new_loc_descr (DW_OP_plus
, 0, 0));
15190 bytepos
= bitpos
/ BITS_PER_UNIT
;
15192 add_loc_descr_to_each (list_ret
,
15193 new_loc_descr (DW_OP_plus_uconst
,
15195 else if (bytepos
< 0)
15196 loc_list_plus_const (list_ret
, bytepos
);
15197 add_loc_descr_to_each (list_ret
,
15198 new_loc_descr (DW_OP_stack_value
, 0, 0));
15203 /* Set LOC to the next operation that is not a DW_OP_nop operation. In the case
15204 all operations from LOC are nops, move to the last one. Insert in NOPS all
15205 operations that are skipped. */
15208 loc_descr_to_next_no_nop (dw_loc_descr_ref
&loc
,
15209 hash_set
<dw_loc_descr_ref
> &nops
)
15211 while (loc
->dw_loc_next
!= NULL
&& loc
->dw_loc_opc
== DW_OP_nop
)
15214 loc
= loc
->dw_loc_next
;
15218 /* Helper for loc_descr_without_nops: free the location description operation
15222 free_loc_descr (const dw_loc_descr_ref
&loc
, void *data ATTRIBUTE_UNUSED
)
15228 /* Remove all DW_OP_nop operations from LOC except, if it exists, the one that
15232 loc_descr_without_nops (dw_loc_descr_ref
&loc
)
15234 if (loc
->dw_loc_opc
== DW_OP_nop
&& loc
->dw_loc_next
== NULL
)
15237 /* Set of all DW_OP_nop operations we remove. */
15238 hash_set
<dw_loc_descr_ref
> nops
;
15240 /* First, strip all prefix NOP operations in order to keep the head of the
15241 operations list. */
15242 loc_descr_to_next_no_nop (loc
, nops
);
15244 for (dw_loc_descr_ref cur
= loc
; cur
!= NULL
;)
15246 /* For control flow operations: strip "prefix" nops in destination
15248 if (cur
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
)
15249 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd1
.v
.val_loc
, nops
);
15250 if (cur
->dw_loc_oprnd2
.val_class
== dw_val_class_loc
)
15251 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd2
.v
.val_loc
, nops
);
15253 /* Do the same for the operations that follow, then move to the next
15255 if (cur
->dw_loc_next
!= NULL
)
15256 loc_descr_to_next_no_nop (cur
->dw_loc_next
, nops
);
15257 cur
= cur
->dw_loc_next
;
15260 nops
.traverse
<void *, free_loc_descr
> (NULL
);
15264 struct dwarf_procedure_info
;
15266 /* Helper structure for location descriptions generation. */
15267 struct loc_descr_context
15269 /* The type that is implicitly referenced by DW_OP_push_object_address, or
15270 NULL_TREE if DW_OP_push_object_address in invalid for this location
15271 description. This is used when processing PLACEHOLDER_EXPR nodes. */
15273 /* The ..._DECL node that should be translated as a
15274 DW_OP_push_object_address operation. */
15276 /* Information about the DWARF procedure we are currently generating. NULL if
15277 we are not generating a DWARF procedure. */
15278 struct dwarf_procedure_info
*dpi
;
15281 /* DWARF procedures generation
15283 DWARF expressions (aka. location descriptions) are used to encode variable
15284 things such as sizes or offsets. Such computations can have redundant parts
15285 that can be factorized in order to reduce the size of the output debug
15286 information. This is the whole point of DWARF procedures.
15288 Thanks to stor-layout.c, size and offset expressions in GENERIC trees are
15289 already factorized into functions ("size functions") in order to handle very
15290 big and complex types. Such functions are quite simple: they have integral
15291 arguments, they return an integral result and their body contains only a
15292 return statement with arithmetic expressions. This is the only kind of
15293 function we are interested in translating into DWARF procedures, here.
15295 DWARF expressions and DWARF procedure are executed using a stack, so we have
15296 to define some calling convention for them to interact. Let's say that:
15298 - Before calling a DWARF procedure, DWARF expressions must push on the stack
15299 all arguments in reverse order (right-to-left) so that when the DWARF
15300 procedure execution starts, the first argument is the top of the stack.
15302 - Then, when returning, the DWARF procedure must have consumed all arguments
15303 on the stack, must have pushed the result and touched nothing else.
15305 - Each integral argument and the result are integral types can be hold in a
15308 - We call "frame offset" the number of stack slots that are "under DWARF
15309 procedure control": it includes the arguments slots, the temporaries and
15310 the result slot. Thus, it is equal to the number of arguments when the
15311 procedure execution starts and must be equal to one (the result) when it
15314 /* Helper structure used when generating operations for a DWARF procedure. */
15315 struct dwarf_procedure_info
15317 /* The FUNCTION_DECL node corresponding to the DWARF procedure that is
15318 currently translated. */
15320 /* The number of arguments FNDECL takes. */
15321 unsigned args_count
;
15324 /* Return a pointer to a newly created DIE node for a DWARF procedure. Add
15325 LOCATION as its DW_AT_location attribute. If FNDECL is not NULL_TREE,
15326 equate it to this DIE. */
15329 new_dwarf_proc_die (dw_loc_descr_ref location
, tree fndecl
,
15330 dw_die_ref parent_die
)
15332 dw_die_ref dwarf_proc_die
;
15334 if ((dwarf_version
< 3 && dwarf_strict
)
15335 || location
== NULL
)
15338 dwarf_proc_die
= new_die (DW_TAG_dwarf_procedure
, parent_die
, fndecl
);
15340 equate_decl_number_to_die (fndecl
, dwarf_proc_die
);
15341 add_AT_loc (dwarf_proc_die
, DW_AT_location
, location
);
15342 return dwarf_proc_die
;
15345 /* Return whether TYPE is a supported type as a DWARF procedure argument
15346 type or return type (we handle only scalar types and pointer types that
15347 aren't wider than the DWARF expression evaluation stack. */
15350 is_handled_procedure_type (tree type
)
15352 return ((INTEGRAL_TYPE_P (type
)
15353 || TREE_CODE (type
) == OFFSET_TYPE
15354 || TREE_CODE (type
) == POINTER_TYPE
)
15355 && int_size_in_bytes (type
) <= DWARF2_ADDR_SIZE
);
15358 /* Helper for resolve_args_picking: do the same but stop when coming across
15359 visited nodes. For each node we visit, register in FRAME_OFFSETS the frame
15360 offset *before* evaluating the corresponding operation. */
15363 resolve_args_picking_1 (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
15364 struct dwarf_procedure_info
*dpi
,
15365 hash_map
<dw_loc_descr_ref
, unsigned> &frame_offsets
)
15367 /* The "frame_offset" identifier is already used to name a macro... */
15368 unsigned frame_offset_
= initial_frame_offset
;
15369 dw_loc_descr_ref l
;
15371 for (l
= loc
; l
!= NULL
;)
15374 unsigned &l_frame_offset
= frame_offsets
.get_or_insert (l
, &existed
);
15376 /* If we already met this node, there is nothing to compute anymore. */
15379 /* Make sure that the stack size is consistent wherever the execution
15380 flow comes from. */
15381 gcc_assert ((unsigned) l_frame_offset
== frame_offset_
);
15384 l_frame_offset
= frame_offset_
;
15386 /* If needed, relocate the picking offset with respect to the frame
15388 if (l
->dw_loc_opc
== DW_OP_pick
&& l
->frame_offset_rel
)
15390 /* frame_offset_ is the size of the current stack frame, including
15391 incoming arguments. Besides, the arguments are pushed
15392 right-to-left. Thus, in order to access the Nth argument from
15393 this operation node, the picking has to skip temporaries *plus*
15394 one stack slot per argument (0 for the first one, 1 for the second
15397 The targetted argument number (N) is already set as the operand,
15398 and the number of temporaries can be computed with:
15399 frame_offsets_ - dpi->args_count */
15400 l
->dw_loc_oprnd1
.v
.val_unsigned
+= frame_offset_
- dpi
->args_count
;
15402 /* DW_OP_pick handles only offsets from 0 to 255 (inclusive)... */
15403 if (l
->dw_loc_oprnd1
.v
.val_unsigned
> 255)
15407 /* Update frame_offset according to the effect the current operation has
15409 switch (l
->dw_loc_opc
)
15417 case DW_OP_plus_uconst
:
15453 case DW_OP_deref_size
:
15455 case DW_OP_form_tls_address
:
15456 case DW_OP_bit_piece
:
15457 case DW_OP_implicit_value
:
15458 case DW_OP_stack_value
:
15462 case DW_OP_const1u
:
15463 case DW_OP_const1s
:
15464 case DW_OP_const2u
:
15465 case DW_OP_const2s
:
15466 case DW_OP_const4u
:
15467 case DW_OP_const4s
:
15468 case DW_OP_const8u
:
15469 case DW_OP_const8s
:
15540 case DW_OP_push_object_address
:
15541 case DW_OP_call_frame_cfa
:
15566 case DW_OP_xderef_size
:
15572 case DW_OP_call_ref
:
15574 dw_die_ref dwarf_proc
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
15575 int *stack_usage
= dwarf_proc_stack_usage_map
->get (dwarf_proc
);
15577 if (stack_usage
== NULL
)
15579 frame_offset_
+= *stack_usage
;
15583 case DW_OP_GNU_push_tls_address
:
15584 case DW_OP_GNU_uninit
:
15585 case DW_OP_GNU_encoded_addr
:
15586 case DW_OP_GNU_implicit_pointer
:
15587 case DW_OP_GNU_entry_value
:
15588 case DW_OP_GNU_const_type
:
15589 case DW_OP_GNU_regval_type
:
15590 case DW_OP_GNU_deref_type
:
15591 case DW_OP_GNU_convert
:
15592 case DW_OP_GNU_reinterpret
:
15593 case DW_OP_GNU_parameter_ref
:
15594 /* loc_list_from_tree will probably not output these operations for
15595 size functions, so assume they will not appear here. */
15596 /* Fall through... */
15599 gcc_unreachable ();
15602 /* Now, follow the control flow (except subroutine calls). */
15603 switch (l
->dw_loc_opc
)
15606 if (!resolve_args_picking_1 (l
->dw_loc_next
, frame_offset_
, dpi
,
15609 /* Fall through. */
15612 l
= l
->dw_loc_oprnd1
.v
.val_loc
;
15615 case DW_OP_stack_value
:
15619 l
= l
->dw_loc_next
;
15627 /* Make a DFS over operations reachable through LOC (i.e. follow branch
15628 operations) in order to resolve the operand of DW_OP_pick operations that
15629 target DWARF procedure arguments (DPI). INITIAL_FRAME_OFFSET is the frame
15630 offset *before* LOC is executed. Return if all relocations were
15634 resolve_args_picking (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
15635 struct dwarf_procedure_info
*dpi
)
15637 /* Associate to all visited operations the frame offset *before* evaluating
15639 hash_map
<dw_loc_descr_ref
, unsigned> frame_offsets
;
15641 return resolve_args_picking_1 (loc
, initial_frame_offset
, dpi
,
15645 /* Try to generate a DWARF procedure that computes the same result as FNDECL.
15646 Return NULL if it is not possible. */
15649 function_to_dwarf_procedure (tree fndecl
)
15651 struct loc_descr_context ctx
;
15652 struct dwarf_procedure_info dpi
;
15653 dw_die_ref dwarf_proc_die
;
15654 tree tree_body
= DECL_SAVED_TREE (fndecl
);
15655 dw_loc_descr_ref loc_body
, epilogue
;
15660 /* Do not generate multiple DWARF procedures for the same function
15662 dwarf_proc_die
= lookup_decl_die (fndecl
);
15663 if (dwarf_proc_die
!= NULL
)
15664 return dwarf_proc_die
;
15666 /* DWARF procedures are available starting with the DWARFv3 standard. */
15667 if (dwarf_version
< 3 && dwarf_strict
)
15670 /* We handle only functions for which we still have a body, that return a
15671 supported type and that takes arguments with supported types. Note that
15672 there is no point translating functions that return nothing. */
15673 if (tree_body
== NULL_TREE
15674 || DECL_RESULT (fndecl
) == NULL_TREE
15675 || !is_handled_procedure_type (TREE_TYPE (DECL_RESULT (fndecl
))))
15678 for (cursor
= DECL_ARGUMENTS (fndecl
);
15679 cursor
!= NULL_TREE
;
15680 cursor
= TREE_CHAIN (cursor
))
15681 if (!is_handled_procedure_type (TREE_TYPE (cursor
)))
15684 /* Match only "expr" in: RETURN_EXPR (MODIFY_EXPR (RESULT_DECL, expr)). */
15685 if (TREE_CODE (tree_body
) != RETURN_EXPR
)
15687 tree_body
= TREE_OPERAND (tree_body
, 0);
15688 if (TREE_CODE (tree_body
) != MODIFY_EXPR
15689 || TREE_OPERAND (tree_body
, 0) != DECL_RESULT (fndecl
))
15691 tree_body
= TREE_OPERAND (tree_body
, 1);
15693 /* Try to translate the body expression itself. Note that this will probably
15694 cause an infinite recursion if its call graph has a cycle. This is very
15695 unlikely for size functions, however, so don't bother with such things at
15697 ctx
.context_type
= NULL_TREE
;
15698 ctx
.base_decl
= NULL_TREE
;
15700 dpi
.fndecl
= fndecl
;
15701 dpi
.args_count
= list_length (DECL_ARGUMENTS (fndecl
));
15702 loc_body
= loc_descriptor_from_tree (tree_body
, 0, &ctx
);
15706 /* After evaluating all operands in "loc_body", we should still have on the
15707 stack all arguments plus the desired function result (top of the stack).
15708 Generate code in order to keep only the result in our stack frame. */
15710 for (i
= 0; i
< dpi
.args_count
; ++i
)
15712 dw_loc_descr_ref op_couple
= new_loc_descr (DW_OP_swap
, 0, 0);
15713 op_couple
->dw_loc_next
= new_loc_descr (DW_OP_drop
, 0, 0);
15714 op_couple
->dw_loc_next
->dw_loc_next
= epilogue
;
15715 epilogue
= op_couple
;
15717 add_loc_descr (&loc_body
, epilogue
);
15718 if (!resolve_args_picking (loc_body
, dpi
.args_count
, &dpi
))
15721 /* Trailing nops from loc_descriptor_from_tree (if any) cannot be removed
15722 because they are considered useful. Now there is an epilogue, they are
15723 not anymore, so give it another try. */
15724 loc_descr_without_nops (loc_body
);
15726 /* fndecl may be used both as a regular DW_TAG_subprogram DIE and as
15727 a DW_TAG_dwarf_procedure, so we may have a conflict, here. It's unlikely,
15728 though, given that size functions do not come from source, so they should
15729 not have a dedicated DW_TAG_subprogram DIE. */
15731 = new_dwarf_proc_die (loc_body
, fndecl
,
15732 get_context_die (DECL_CONTEXT (fndecl
)));
15734 /* The called DWARF procedure consumes one stack slot per argument and
15735 returns one stack slot. */
15736 dwarf_proc_stack_usage_map
->put (dwarf_proc_die
, 1 - dpi
.args_count
);
15738 return dwarf_proc_die
;
15742 /* Generate Dwarf location list representing LOC.
15743 If WANT_ADDRESS is false, expression computing LOC will be computed
15744 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
15745 if WANT_ADDRESS is 2, expression computing address useable in location
15746 will be returned (i.e. DW_OP_reg can be used
15747 to refer to register values).
15749 CONTEXT provides information to customize the location descriptions
15750 generation. Its context_type field specifies what type is implicitly
15751 referenced by DW_OP_push_object_address. If it is NULL_TREE, this operation
15752 will not be generated.
15754 Its DPI field determines whether we are generating a DWARF expression for a
15755 DWARF procedure, so PARM_DECL references are processed specifically.
15757 If CONTEXT is NULL, the behavior is the same as if context_type, base_decl
15758 and dpi fields were null. */
15760 static dw_loc_list_ref
15761 loc_list_from_tree_1 (tree loc
, int want_address
,
15762 const struct loc_descr_context
*context
)
15764 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
15765 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
15766 int have_address
= 0;
15767 enum dwarf_location_atom op
;
15769 /* ??? Most of the time we do not take proper care for sign/zero
15770 extending the values properly. Hopefully this won't be a real
15773 if (context
!= NULL
15774 && context
->base_decl
== loc
15775 && want_address
== 0)
15777 if (dwarf_version
>= 3 || !dwarf_strict
)
15778 return new_loc_list (new_loc_descr (DW_OP_push_object_address
, 0, 0),
15784 switch (TREE_CODE (loc
))
15787 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
15790 case PLACEHOLDER_EXPR
:
15791 /* This case involves extracting fields from an object to determine the
15792 position of other fields. It is supposed to appear only as the first
15793 operand of COMPONENT_REF nodes and to reference precisely the type
15794 that the context allows. */
15795 if (context
!= NULL
15796 && TREE_TYPE (loc
) == context
->context_type
15797 && want_address
>= 1)
15799 if (dwarf_version
>= 3 || !dwarf_strict
)
15801 ret
= new_loc_descr (DW_OP_push_object_address
, 0, 0);
15809 expansion_failed (loc
, NULL_RTX
,
15810 "PLACEHOLDER_EXPR for an unexpected type");
15815 const int nargs
= call_expr_nargs (loc
);
15816 tree callee
= get_callee_fndecl (loc
);
15818 dw_die_ref dwarf_proc
;
15820 if (callee
== NULL_TREE
)
15821 goto call_expansion_failed
;
15823 /* We handle only functions that return an integer. */
15824 if (!is_handled_procedure_type (TREE_TYPE (TREE_TYPE (callee
))))
15825 goto call_expansion_failed
;
15827 dwarf_proc
= function_to_dwarf_procedure (callee
);
15828 if (dwarf_proc
== NULL
)
15829 goto call_expansion_failed
;
15831 /* Evaluate arguments right-to-left so that the first argument will
15832 be the top-most one on the stack. */
15833 for (i
= nargs
- 1; i
>= 0; --i
)
15835 dw_loc_descr_ref loc_descr
15836 = loc_descriptor_from_tree (CALL_EXPR_ARG (loc
, i
), 0,
15839 if (loc_descr
== NULL
)
15840 goto call_expansion_failed
;
15842 add_loc_descr (&ret
, loc_descr
);
15845 ret1
= new_loc_descr (DW_OP_call4
, 0, 0);
15846 ret1
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15847 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.die
= dwarf_proc
;
15848 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15849 add_loc_descr (&ret
, ret1
);
15852 call_expansion_failed
:
15853 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
15854 /* There are no opcodes for these operations. */
15858 case PREINCREMENT_EXPR
:
15859 case PREDECREMENT_EXPR
:
15860 case POSTINCREMENT_EXPR
:
15861 case POSTDECREMENT_EXPR
:
15862 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
15863 /* There are no opcodes for these operations. */
15867 /* If we already want an address, see if there is INDIRECT_REF inside
15868 e.g. for &this->field. */
15871 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
15872 (loc
, want_address
== 2, context
);
15875 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
15876 && (ret
= cst_pool_loc_descr (loc
)))
15879 /* Otherwise, process the argument and look for the address. */
15880 if (!list_ret
&& !ret
)
15881 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 1, context
);
15885 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
15891 if (DECL_THREAD_LOCAL_P (loc
))
15894 enum dwarf_location_atom tls_op
;
15895 enum dtprel_bool dtprel
= dtprel_false
;
15897 if (targetm
.have_tls
)
15899 /* If this is not defined, we have no way to emit the
15901 if (!targetm
.asm_out
.output_dwarf_dtprel
)
15904 /* The way DW_OP_GNU_push_tls_address is specified, we
15905 can only look up addresses of objects in the current
15906 module. We used DW_OP_addr as first op, but that's
15907 wrong, because DW_OP_addr is relocated by the debug
15908 info consumer, while DW_OP_GNU_push_tls_address
15909 operand shouldn't be. */
15910 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
15912 dtprel
= dtprel_true
;
15913 tls_op
= DW_OP_GNU_push_tls_address
;
15917 if (!targetm
.emutls
.debug_form_tls_address
15918 || !(dwarf_version
>= 3 || !dwarf_strict
))
15920 /* We stuffed the control variable into the DECL_VALUE_EXPR
15921 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
15922 no longer appear in gimple code. We used the control
15923 variable in specific so that we could pick it up here. */
15924 loc
= DECL_VALUE_EXPR (loc
);
15925 tls_op
= DW_OP_form_tls_address
;
15928 rtl
= rtl_for_decl_location (loc
);
15929 if (rtl
== NULL_RTX
)
15934 rtl
= XEXP (rtl
, 0);
15935 if (! CONSTANT_P (rtl
))
15938 ret
= new_addr_loc_descr (rtl
, dtprel
);
15939 ret1
= new_loc_descr (tls_op
, 0, 0);
15940 add_loc_descr (&ret
, ret1
);
15948 if (context
!= NULL
&& context
->dpi
!= NULL
15949 && DECL_CONTEXT (loc
) == context
->dpi
->fndecl
)
15951 /* We are generating code for a DWARF procedure and we want to access
15952 one of its arguments: find the appropriate argument offset and let
15953 the resolve_args_picking pass compute the offset that complies
15954 with the stack frame size. */
15958 for (cursor
= DECL_ARGUMENTS (context
->dpi
->fndecl
);
15959 cursor
!= NULL_TREE
&& cursor
!= loc
;
15960 cursor
= TREE_CHAIN (cursor
), ++i
)
15962 /* If we are translating a DWARF procedure, all referenced parameters
15963 must belong to the current function. */
15964 gcc_assert (cursor
!= NULL_TREE
);
15966 ret
= new_loc_descr (DW_OP_pick
, i
, 0);
15967 ret
->frame_offset_rel
= 1;
15973 if (DECL_HAS_VALUE_EXPR_P (loc
))
15974 return loc_list_from_tree_1 (DECL_VALUE_EXPR (loc
),
15975 want_address
, context
);
15978 case FUNCTION_DECL
:
15981 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
15983 if (loc_list
&& loc_list
->first
)
15985 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
15986 have_address
= want_address
!= 0;
15989 rtl
= rtl_for_decl_location (loc
);
15990 if (rtl
== NULL_RTX
)
15992 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
15995 else if (CONST_INT_P (rtl
))
15997 HOST_WIDE_INT val
= INTVAL (rtl
);
15998 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
15999 val
&= GET_MODE_MASK (DECL_MODE (loc
));
16000 ret
= int_loc_descriptor (val
);
16002 else if (GET_CODE (rtl
) == CONST_STRING
)
16004 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
16007 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
16008 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
16011 machine_mode mode
, mem_mode
;
16013 /* Certain constructs can only be represented at top-level. */
16014 if (want_address
== 2)
16016 ret
= loc_descriptor (rtl
, VOIDmode
,
16017 VAR_INIT_STATUS_INITIALIZED
);
16022 mode
= GET_MODE (rtl
);
16023 mem_mode
= VOIDmode
;
16027 mode
= get_address_mode (rtl
);
16028 rtl
= XEXP (rtl
, 0);
16031 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
16032 VAR_INIT_STATUS_INITIALIZED
);
16035 expansion_failed (loc
, rtl
,
16036 "failed to produce loc descriptor for rtl");
16042 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
16049 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
16053 case TARGET_MEM_REF
:
16055 case DEBUG_EXPR_DECL
:
16058 case COMPOUND_EXPR
:
16059 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), want_address
,
16063 case VIEW_CONVERT_EXPR
:
16066 case NON_LVALUE_EXPR
:
16067 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), want_address
,
16070 case COMPONENT_REF
:
16071 case BIT_FIELD_REF
:
16073 case ARRAY_RANGE_REF
:
16074 case REALPART_EXPR
:
16075 case IMAGPART_EXPR
:
16078 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
16080 int unsignedp
, reversep
, volatilep
= 0;
16082 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
16083 &unsignedp
, &reversep
, &volatilep
);
16085 gcc_assert (obj
!= loc
);
16087 list_ret
= loc_list_from_tree_1 (obj
,
16089 && !bitpos
&& !offset
? 2 : 1,
16091 /* TODO: We can extract value of the small expression via shifting even
16092 for nonzero bitpos. */
16095 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
16097 expansion_failed (loc
, NULL_RTX
,
16098 "bitfield access");
16102 if (offset
!= NULL_TREE
)
16104 /* Variable offset. */
16105 list_ret1
= loc_list_from_tree_1 (offset
, 0, context
);
16106 if (list_ret1
== 0)
16108 add_loc_list (&list_ret
, list_ret1
);
16111 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
16114 bytepos
= bitpos
/ BITS_PER_UNIT
;
16116 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
16117 else if (bytepos
< 0)
16118 loc_list_plus_const (list_ret
, bytepos
);
16125 if ((want_address
|| !tree_fits_shwi_p (loc
))
16126 && (ret
= cst_pool_loc_descr (loc
)))
16128 else if (want_address
== 2
16129 && tree_fits_shwi_p (loc
)
16130 && (ret
= address_of_int_loc_descriptor
16131 (int_size_in_bytes (TREE_TYPE (loc
)),
16132 tree_to_shwi (loc
))))
16134 else if (tree_fits_shwi_p (loc
))
16135 ret
= int_loc_descriptor (tree_to_shwi (loc
));
16136 else if (tree_fits_uhwi_p (loc
))
16137 ret
= uint_loc_descriptor (tree_to_uhwi (loc
));
16140 expansion_failed (loc
, NULL_RTX
,
16141 "Integer operand is not host integer");
16150 if ((ret
= cst_pool_loc_descr (loc
)))
16152 else if (TREE_CODE (loc
) == CONSTRUCTOR
)
16154 tree type
= TREE_TYPE (loc
);
16155 unsigned HOST_WIDE_INT size
= int_size_in_bytes (type
);
16156 unsigned HOST_WIDE_INT offset
= 0;
16157 unsigned HOST_WIDE_INT cnt
;
16158 constructor_elt
*ce
;
16160 if (TREE_CODE (type
) == RECORD_TYPE
)
16162 /* This is very limited, but it's enough to output
16163 pointers to member functions, as long as the
16164 referenced function is defined in the current
16165 translation unit. */
16166 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (loc
), cnt
, ce
)
16168 tree val
= ce
->value
;
16170 tree field
= ce
->index
;
16175 if (!field
|| DECL_BIT_FIELD (field
))
16177 expansion_failed (loc
, NULL_RTX
,
16178 "bitfield in record type constructor");
16179 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
16184 HOST_WIDE_INT fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
16185 unsigned HOST_WIDE_INT pos
= int_byte_position (field
);
16186 gcc_assert (pos
+ fieldsize
<= size
);
16189 expansion_failed (loc
, NULL_RTX
,
16190 "out-of-order fields in record constructor");
16191 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
16197 ret1
= new_loc_descr (DW_OP_piece
, pos
- offset
, 0);
16198 add_loc_descr (&ret
, ret1
);
16201 if (val
&& fieldsize
!= 0)
16203 ret1
= loc_descriptor_from_tree (val
, want_address
, context
);
16206 expansion_failed (loc
, NULL_RTX
,
16207 "unsupported expression in field");
16208 size
= offset
= (unsigned HOST_WIDE_INT
)-1;
16212 add_loc_descr (&ret
, ret1
);
16216 ret1
= new_loc_descr (DW_OP_piece
, fieldsize
, 0);
16217 add_loc_descr (&ret
, ret1
);
16218 offset
= pos
+ fieldsize
;
16222 if (offset
!= size
)
16224 ret1
= new_loc_descr (DW_OP_piece
, size
- offset
, 0);
16225 add_loc_descr (&ret
, ret1
);
16229 have_address
= !!want_address
;
16232 expansion_failed (loc
, NULL_RTX
,
16233 "constructor of non-record type");
16236 /* We can construct small constants here using int_loc_descriptor. */
16237 expansion_failed (loc
, NULL_RTX
,
16238 "constructor or constant not in constant pool");
16241 case TRUTH_AND_EXPR
:
16242 case TRUTH_ANDIF_EXPR
:
16247 case TRUTH_XOR_EXPR
:
16252 case TRUTH_OR_EXPR
:
16253 case TRUTH_ORIF_EXPR
:
16258 case FLOOR_DIV_EXPR
:
16259 case CEIL_DIV_EXPR
:
16260 case ROUND_DIV_EXPR
:
16261 case TRUNC_DIV_EXPR
:
16262 case EXACT_DIV_EXPR
:
16263 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
16272 case FLOOR_MOD_EXPR
:
16273 case CEIL_MOD_EXPR
:
16274 case ROUND_MOD_EXPR
:
16275 case TRUNC_MOD_EXPR
:
16276 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
16281 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
16282 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
16283 if (list_ret
== 0 || list_ret1
== 0)
16286 add_loc_list (&list_ret
, list_ret1
);
16289 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
16290 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
16291 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
16292 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
16293 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
16305 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
16308 case POINTER_PLUS_EXPR
:
16311 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
16313 /* Big unsigned numbers can fit in HOST_WIDE_INT but it may be
16314 smarter to encode their opposite. The DW_OP_plus_uconst operation
16315 takes 1 + X bytes, X being the size of the ULEB128 addend. On the
16316 other hand, a "<push literal>; DW_OP_minus" pattern takes 1 + Y
16317 bytes, Y being the size of the operation that pushes the opposite
16318 of the addend. So let's choose the smallest representation. */
16319 const tree tree_addend
= TREE_OPERAND (loc
, 1);
16320 offset_int wi_addend
;
16321 HOST_WIDE_INT shwi_addend
;
16322 dw_loc_descr_ref loc_naddend
;
16324 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
16328 /* Try to get the literal to push. It is the opposite of the addend,
16329 so as we rely on wrapping during DWARF evaluation, first decode
16330 the literal as a "DWARF-sized" signed number. */
16331 wi_addend
= wi::to_offset (tree_addend
);
16332 wi_addend
= wi::sext (wi_addend
, DWARF2_ADDR_SIZE
* 8);
16333 shwi_addend
= wi_addend
.to_shwi ();
16334 loc_naddend
= (shwi_addend
!= INTTYPE_MINIMUM (HOST_WIDE_INT
))
16335 ? int_loc_descriptor (-shwi_addend
)
16338 if (loc_naddend
!= NULL
16339 && ((unsigned) size_of_uleb128 (shwi_addend
)
16340 > size_of_loc_descr (loc_naddend
)))
16342 add_loc_descr_to_each (list_ret
, loc_naddend
);
16343 add_loc_descr_to_each (list_ret
,
16344 new_loc_descr (DW_OP_minus
, 0, 0));
16348 for (dw_loc_descr_ref loc_cur
= loc_naddend
; loc_cur
!= NULL
; )
16350 loc_naddend
= loc_cur
;
16351 loc_cur
= loc_cur
->dw_loc_next
;
16352 ggc_free (loc_naddend
);
16354 loc_list_plus_const (list_ret
, wi_addend
.to_shwi ());
16364 goto do_comp_binop
;
16368 goto do_comp_binop
;
16372 goto do_comp_binop
;
16376 goto do_comp_binop
;
16379 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
16381 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
16382 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
16383 list_ret
= loc_list_from_uint_comparison (list_ret
, list_ret1
,
16399 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
16400 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
16401 if (list_ret
== 0 || list_ret1
== 0)
16404 add_loc_list (&list_ret
, list_ret1
);
16407 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
16410 case TRUTH_NOT_EXPR
:
16424 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
16428 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
16434 const enum tree_code code
=
16435 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
16437 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
16438 build2 (code
, integer_type_node
,
16439 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
16440 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
16447 dw_loc_descr_ref lhs
16448 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
16449 dw_loc_list_ref rhs
16450 = loc_list_from_tree_1 (TREE_OPERAND (loc
, 2), 0, context
);
16451 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
16453 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
16454 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
16457 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
16458 add_loc_descr_to_each (list_ret
, bra_node
);
16460 add_loc_list (&list_ret
, rhs
);
16461 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
16462 add_loc_descr_to_each (list_ret
, jump_node
);
16464 add_loc_descr_to_each (list_ret
, lhs
);
16465 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
16466 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
16468 /* ??? Need a node to point the skip at. Use a nop. */
16469 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
16470 add_loc_descr_to_each (list_ret
, tmp
);
16471 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
16472 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
16476 case FIX_TRUNC_EXPR
:
16480 /* Leave front-end specific codes as simply unknown. This comes
16481 up, for instance, with the C STMT_EXPR. */
16482 if ((unsigned int) TREE_CODE (loc
)
16483 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
16485 expansion_failed (loc
, NULL_RTX
,
16486 "language specific tree node");
16490 /* Otherwise this is a generic code; we should just lists all of
16491 these explicitly. We forgot one. */
16493 gcc_unreachable ();
16495 /* In a release build, we want to degrade gracefully: better to
16496 generate incomplete debugging information than to crash. */
16500 if (!ret
&& !list_ret
)
16503 if (want_address
== 2 && !have_address
16504 && (dwarf_version
>= 4 || !dwarf_strict
))
16506 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
16508 expansion_failed (loc
, NULL_RTX
,
16509 "DWARF address size mismatch");
16513 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
16515 add_loc_descr_to_each (list_ret
,
16516 new_loc_descr (DW_OP_stack_value
, 0, 0));
16519 /* Show if we can't fill the request for an address. */
16520 if (want_address
&& !have_address
)
16522 expansion_failed (loc
, NULL_RTX
,
16523 "Want address and only have value");
16527 gcc_assert (!ret
|| !list_ret
);
16529 /* If we've got an address and don't want one, dereference. */
16530 if (!want_address
&& have_address
)
16532 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
16534 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
16536 expansion_failed (loc
, NULL_RTX
,
16537 "DWARF address size mismatch");
16540 else if (size
== DWARF2_ADDR_SIZE
)
16543 op
= DW_OP_deref_size
;
16546 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
16548 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
16551 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
16556 /* Likewise, but strip useless DW_OP_nop operations in the resulting
16559 static dw_loc_list_ref
16560 loc_list_from_tree (tree loc
, int want_address
,
16561 const struct loc_descr_context
*context
)
16563 dw_loc_list_ref result
= loc_list_from_tree_1 (loc
, want_address
, context
);
16565 for (dw_loc_list_ref loc_cur
= result
;
16566 loc_cur
!= NULL
; loc_cur
=
16567 loc_cur
->dw_loc_next
)
16568 loc_descr_without_nops (loc_cur
->expr
);
16572 /* Same as above but return only single location expression. */
16573 static dw_loc_descr_ref
16574 loc_descriptor_from_tree (tree loc
, int want_address
,
16575 const struct loc_descr_context
*context
)
16577 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
, context
);
16580 if (ret
->dw_loc_next
)
16582 expansion_failed (loc
, NULL_RTX
,
16583 "Location list where only loc descriptor needed");
16589 /* Given a value, round it up to the lowest multiple of `boundary'
16590 which is not less than the value itself. */
16592 static inline HOST_WIDE_INT
16593 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
16595 return (((value
+ boundary
- 1) / boundary
) * boundary
);
16598 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
16599 pointer to the declared type for the relevant field variable, or return
16600 `integer_type_node' if the given node turns out to be an
16601 ERROR_MARK node. */
16604 field_type (const_tree decl
)
16608 if (TREE_CODE (decl
) == ERROR_MARK
)
16609 return integer_type_node
;
16611 type
= DECL_BIT_FIELD_TYPE (decl
);
16612 if (type
== NULL_TREE
)
16613 type
= TREE_TYPE (decl
);
16618 /* Given a pointer to a tree node, return the alignment in bits for
16619 it, or else return BITS_PER_WORD if the node actually turns out to
16620 be an ERROR_MARK node. */
16622 static inline unsigned
16623 simple_type_align_in_bits (const_tree type
)
16625 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
16628 static inline unsigned
16629 simple_decl_align_in_bits (const_tree decl
)
16631 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
16634 /* Return the result of rounding T up to ALIGN. */
16636 static inline offset_int
16637 round_up_to_align (const offset_int
&t
, unsigned int align
)
16639 return wi::udiv_trunc (t
+ align
- 1, align
) * align
;
16642 /* Compute the size of TYPE in bytes. If possible, return NULL and store the
16643 size as an integer constant in CST_SIZE. Otherwise, if possible, return a
16644 DWARF expression that computes the size. Return NULL and set CST_SIZE to -1
16645 if we fail to return the size in one of these two forms. */
16647 static dw_loc_descr_ref
16648 type_byte_size (const_tree type
, HOST_WIDE_INT
*cst_size
)
16651 struct loc_descr_context ctx
;
16653 /* Return a constant integer in priority, if possible. */
16654 *cst_size
= int_size_in_bytes (type
);
16655 if (*cst_size
!= -1)
16658 ctx
.context_type
= const_cast<tree
> (type
);
16659 ctx
.base_decl
= NULL_TREE
;
16662 type
= TYPE_MAIN_VARIANT (type
);
16663 tree_size
= TYPE_SIZE_UNIT (type
);
16664 return ((tree_size
!= NULL_TREE
)
16665 ? loc_descriptor_from_tree (tree_size
, 0, &ctx
)
16669 /* Helper structure for RECORD_TYPE processing. */
16672 /* Root RECORD_TYPE. It is needed to generate data member location
16673 descriptions in variable-length records (VLR), but also to cope with
16674 variants, which are composed of nested structures multiplexed with
16675 QUAL_UNION_TYPE nodes. Each time such a structure is passed to a
16676 function processing a FIELD_DECL, it is required to be non null. */
16678 /* When generating a variant part in a RECORD_TYPE (i.e. a nested
16679 QUAL_UNION_TYPE), this holds an expression that computes the offset for
16680 this variant part as part of the root record (in storage units). For
16681 regular records, it must be NULL_TREE. */
16682 tree variant_part_offset
;
16685 /* Given a pointer to a FIELD_DECL, compute the byte offset of the lowest
16686 addressed byte of the "containing object" for the given FIELD_DECL. If
16687 possible, return a native constant through CST_OFFSET (in which case NULL is
16688 returned); otherwise return a DWARF expression that computes the offset.
16690 Set *CST_OFFSET to 0 and return NULL if we are unable to determine what
16691 that offset is, either because the argument turns out to be a pointer to an
16692 ERROR_MARK node, or because the offset expression is too complex for us.
16694 CTX is required: see the comment for VLR_CONTEXT. */
16696 static dw_loc_descr_ref
16697 field_byte_offset (const_tree decl
, struct vlr_context
*ctx
,
16698 HOST_WIDE_INT
*cst_offset
)
16700 offset_int object_offset_in_bits
;
16701 offset_int object_offset_in_bytes
;
16702 offset_int bitpos_int
;
16703 bool is_byte_offset_cst
, is_bit_offset_cst
;
16705 dw_loc_list_ref loc_result
;
16709 if (TREE_CODE (decl
) == ERROR_MARK
)
16712 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
16714 is_bit_offset_cst
= TREE_CODE (DECL_FIELD_BIT_OFFSET (decl
)) != INTEGER_CST
;
16715 is_byte_offset_cst
= TREE_CODE (DECL_FIELD_OFFSET (decl
)) != INTEGER_CST
;
16717 /* We cannot handle variable bit offsets at the moment, so abort if it's the
16719 if (is_bit_offset_cst
)
16722 #ifdef PCC_BITFIELD_TYPE_MATTERS
16723 /* We used to handle only constant offsets in all cases. Now, we handle
16724 properly dynamic byte offsets only when PCC bitfield type doesn't
16726 if (PCC_BITFIELD_TYPE_MATTERS
&& is_byte_offset_cst
&& is_bit_offset_cst
)
16729 tree field_size_tree
;
16730 offset_int deepest_bitpos
;
16731 offset_int field_size_in_bits
;
16732 unsigned int type_align_in_bits
;
16733 unsigned int decl_align_in_bits
;
16734 offset_int type_size_in_bits
;
16736 bitpos_int
= wi::to_offset (bit_position (decl
));
16737 type
= field_type (decl
);
16738 type_size_in_bits
= offset_int_type_size_in_bits (type
);
16739 type_align_in_bits
= simple_type_align_in_bits (type
);
16741 field_size_tree
= DECL_SIZE (decl
);
16743 /* The size could be unspecified if there was an error, or for
16744 a flexible array member. */
16745 if (!field_size_tree
)
16746 field_size_tree
= bitsize_zero_node
;
16748 /* If the size of the field is not constant, use the type size. */
16749 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
16750 field_size_in_bits
= wi::to_offset (field_size_tree
);
16752 field_size_in_bits
= type_size_in_bits
;
16754 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
16756 /* The GCC front-end doesn't make any attempt to keep track of the
16757 starting bit offset (relative to the start of the containing
16758 structure type) of the hypothetical "containing object" for a
16759 bit-field. Thus, when computing the byte offset value for the
16760 start of the "containing object" of a bit-field, we must deduce
16761 this information on our own. This can be rather tricky to do in
16762 some cases. For example, handling the following structure type
16763 definition when compiling for an i386/i486 target (which only
16764 aligns long long's to 32-bit boundaries) can be very tricky:
16766 struct S { int field1; long long field2:31; };
16768 Fortunately, there is a simple rule-of-thumb which can be used
16769 in such cases. When compiling for an i386/i486, GCC will
16770 allocate 8 bytes for the structure shown above. It decides to
16771 do this based upon one simple rule for bit-field allocation.
16772 GCC allocates each "containing object" for each bit-field at
16773 the first (i.e. lowest addressed) legitimate alignment boundary
16774 (based upon the required minimum alignment for the declared
16775 type of the field) which it can possibly use, subject to the
16776 condition that there is still enough available space remaining
16777 in the containing object (when allocated at the selected point)
16778 to fully accommodate all of the bits of the bit-field itself.
16780 This simple rule makes it obvious why GCC allocates 8 bytes for
16781 each object of the structure type shown above. When looking
16782 for a place to allocate the "containing object" for `field2',
16783 the compiler simply tries to allocate a 64-bit "containing
16784 object" at each successive 32-bit boundary (starting at zero)
16785 until it finds a place to allocate that 64- bit field such that
16786 at least 31 contiguous (and previously unallocated) bits remain
16787 within that selected 64 bit field. (As it turns out, for the
16788 example above, the compiler finds it is OK to allocate the
16789 "containing object" 64-bit field at bit-offset zero within the
16792 Here we attempt to work backwards from the limited set of facts
16793 we're given, and we try to deduce from those facts, where GCC
16794 must have believed that the containing object started (within
16795 the structure type). The value we deduce is then used (by the
16796 callers of this routine) to generate DW_AT_location and
16797 DW_AT_bit_offset attributes for fields (both bit-fields and, in
16798 the case of DW_AT_location, regular fields as well). */
16800 /* Figure out the bit-distance from the start of the structure to
16801 the "deepest" bit of the bit-field. */
16802 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
16804 /* This is the tricky part. Use some fancy footwork to deduce
16805 where the lowest addressed bit of the containing object must
16807 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
16809 /* Round up to type_align by default. This works best for
16811 object_offset_in_bits
16812 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
16814 if (wi::gtu_p (object_offset_in_bits
, bitpos_int
))
16816 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
16818 /* Round up to decl_align instead. */
16819 object_offset_in_bits
16820 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
16823 #endif /* PCC_BITFIELD_TYPE_MATTERS */
16825 tree_result
= byte_position (decl
);
16826 if (ctx
->variant_part_offset
!= NULL_TREE
)
16827 tree_result
= fold (build2 (PLUS_EXPR
, TREE_TYPE (tree_result
),
16828 ctx
->variant_part_offset
, tree_result
));
16830 /* If the byte offset is a constant, it's simplier to handle a native
16831 constant rather than a DWARF expression. */
16832 if (TREE_CODE (tree_result
) == INTEGER_CST
)
16834 *cst_offset
= wi::to_offset (tree_result
).to_shwi ();
16837 struct loc_descr_context loc_ctx
= {
16838 ctx
->struct_type
, /* context_type */
16839 NULL_TREE
, /* base_decl */
16842 loc_result
= loc_list_from_tree (tree_result
, 0, &loc_ctx
);
16844 /* We want a DWARF expression: abort if we only have a location list with
16845 multiple elements. */
16846 if (!loc_result
|| !single_element_loc_list_p (loc_result
))
16849 return loc_result
->expr
;
16852 /* The following routines define various Dwarf attributes and any data
16853 associated with them. */
16855 /* Add a location description attribute value to a DIE.
16857 This emits location attributes suitable for whole variables and
16858 whole parameters. Note that the location attributes for struct fields are
16859 generated by the routine `data_member_location_attribute' below. */
16862 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
16863 dw_loc_list_ref descr
)
16867 if (single_element_loc_list_p (descr
))
16868 add_AT_loc (die
, attr_kind
, descr
->expr
);
16870 add_AT_loc_list (die
, attr_kind
, descr
);
16873 /* Add DW_AT_accessibility attribute to DIE if needed. */
16876 add_accessibility_attribute (dw_die_ref die
, tree decl
)
16878 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
16879 children, otherwise the default is DW_ACCESS_public. In DWARF2
16880 the default has always been DW_ACCESS_public. */
16881 if (TREE_PROTECTED (decl
))
16882 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
16883 else if (TREE_PRIVATE (decl
))
16885 if (dwarf_version
== 2
16886 || die
->die_parent
== NULL
16887 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
16888 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
16890 else if (dwarf_version
> 2
16892 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
16893 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
16896 /* Attach the specialized form of location attribute used for data members of
16897 struct and union types. In the special case of a FIELD_DECL node which
16898 represents a bit-field, the "offset" part of this special location
16899 descriptor must indicate the distance in bytes from the lowest-addressed
16900 byte of the containing struct or union type to the lowest-addressed byte of
16901 the "containing object" for the bit-field. (See the `field_byte_offset'
16904 For any given bit-field, the "containing object" is a hypothetical object
16905 (of some integral or enum type) within which the given bit-field lives. The
16906 type of this hypothetical "containing object" is always the same as the
16907 declared type of the individual bit-field itself (for GCC anyway... the
16908 DWARF spec doesn't actually mandate this). Note that it is the size (in
16909 bytes) of the hypothetical "containing object" which will be given in the
16910 DW_AT_byte_size attribute for this bit-field. (See the
16911 `byte_size_attribute' function below.) It is also used when calculating the
16912 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
16915 CTX is required: see the comment for VLR_CONTEXT. */
16918 add_data_member_location_attribute (dw_die_ref die
,
16920 struct vlr_context
*ctx
)
16922 HOST_WIDE_INT offset
;
16923 dw_loc_descr_ref loc_descr
= 0;
16925 if (TREE_CODE (decl
) == TREE_BINFO
)
16927 /* We're working on the TAG_inheritance for a base class. */
16928 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
16930 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
16931 aren't at a fixed offset from all (sub)objects of the same
16932 type. We need to extract the appropriate offset from our
16933 vtable. The following dwarf expression means
16935 BaseAddr = ObAddr + *((*ObAddr) - Offset)
16937 This is specific to the V3 ABI, of course. */
16939 dw_loc_descr_ref tmp
;
16941 /* Make a copy of the object address. */
16942 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
16943 add_loc_descr (&loc_descr
, tmp
);
16945 /* Extract the vtable address. */
16946 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
16947 add_loc_descr (&loc_descr
, tmp
);
16949 /* Calculate the address of the offset. */
16950 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
16951 gcc_assert (offset
< 0);
16953 tmp
= int_loc_descriptor (-offset
);
16954 add_loc_descr (&loc_descr
, tmp
);
16955 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
16956 add_loc_descr (&loc_descr
, tmp
);
16958 /* Extract the offset. */
16959 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
16960 add_loc_descr (&loc_descr
, tmp
);
16962 /* Add it to the object address. */
16963 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
16964 add_loc_descr (&loc_descr
, tmp
);
16967 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
16971 loc_descr
= field_byte_offset (decl
, ctx
, &offset
);
16973 /* If loc_descr is available then we know the field offset is dynamic.
16974 However, GDB does not handle dynamic field offsets very well at the
16976 if (loc_descr
!= NULL
&& gnat_encodings
!= DWARF_GNAT_ENCODINGS_MINIMAL
)
16982 /* Data member location evalutation starts with the base address on the
16983 stack. Compute the field offset and add it to this base address. */
16984 else if (loc_descr
!= NULL
)
16985 add_loc_descr (&loc_descr
, new_loc_descr (DW_OP_plus
, 0, 0));
16990 if (dwarf_version
> 2)
16992 /* Don't need to output a location expression, just the constant. */
16994 add_AT_int (die
, DW_AT_data_member_location
, offset
);
16996 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
17001 enum dwarf_location_atom op
;
17003 /* The DWARF2 standard says that we should assume that the structure
17004 address is already on the stack, so we can specify a structure
17005 field address by using DW_OP_plus_uconst. */
17006 op
= DW_OP_plus_uconst
;
17007 loc_descr
= new_loc_descr (op
, offset
, 0);
17011 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
17014 /* Writes integer values to dw_vec_const array. */
17017 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
17021 *dest
++ = val
& 0xff;
17027 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
17029 static HOST_WIDE_INT
17030 extract_int (const unsigned char *src
, unsigned int size
)
17032 HOST_WIDE_INT val
= 0;
17038 val
|= *--src
& 0xff;
17044 /* Writes wide_int values to dw_vec_const array. */
17047 insert_wide_int (const wide_int
&val
, unsigned char *dest
, int elt_size
)
17051 if (elt_size
<= HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
)
17053 insert_int ((HOST_WIDE_INT
) val
.elt (0), elt_size
, dest
);
17057 /* We'd have to extend this code to support odd sizes. */
17058 gcc_assert (elt_size
% (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
) == 0);
17060 int n
= elt_size
/ (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
17062 if (WORDS_BIG_ENDIAN
)
17063 for (i
= n
- 1; i
>= 0; i
--)
17065 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
17066 dest
+= sizeof (HOST_WIDE_INT
);
17069 for (i
= 0; i
< n
; i
++)
17071 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
17072 dest
+= sizeof (HOST_WIDE_INT
);
17076 /* Writes floating point values to dw_vec_const array. */
17079 insert_float (const_rtx rtl
, unsigned char *array
)
17084 real_to_target (val
, CONST_DOUBLE_REAL_VALUE (rtl
), GET_MODE (rtl
));
17086 /* real_to_target puts 32-bit pieces in each long. Pack them. */
17087 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
17089 insert_int (val
[i
], 4, array
);
17094 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
17095 does not have a "location" either in memory or in a register. These
17096 things can arise in GNU C when a constant is passed as an actual parameter
17097 to an inlined function. They can also arise in C++ where declared
17098 constants do not necessarily get memory "homes". */
17101 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
17103 switch (GET_CODE (rtl
))
17107 HOST_WIDE_INT val
= INTVAL (rtl
);
17110 add_AT_int (die
, DW_AT_const_value
, val
);
17112 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
17116 case CONST_WIDE_INT
:
17118 wide_int w1
= std::make_pair (rtl
, MAX_MODE_INT
);
17119 unsigned int prec
= MIN (wi::min_precision (w1
, UNSIGNED
),
17120 (unsigned int)CONST_WIDE_INT_NUNITS (rtl
) * HOST_BITS_PER_WIDE_INT
);
17121 wide_int w
= wi::zext (w1
, prec
);
17122 add_AT_wide (die
, DW_AT_const_value
, w
);
17127 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
17128 floating-point constant. A CONST_DOUBLE is used whenever the
17129 constant requires more than one word in order to be adequately
17132 machine_mode mode
= GET_MODE (rtl
);
17134 if (TARGET_SUPPORTS_WIDE_INT
== 0 && !SCALAR_FLOAT_MODE_P (mode
))
17135 add_AT_double (die
, DW_AT_const_value
,
17136 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
17139 unsigned int length
= GET_MODE_SIZE (mode
);
17140 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
17142 insert_float (rtl
, array
);
17143 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
17150 machine_mode mode
= GET_MODE (rtl
);
17151 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
17152 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
17153 unsigned char *array
17154 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
17157 machine_mode imode
= GET_MODE_INNER (mode
);
17159 switch (GET_MODE_CLASS (mode
))
17161 case MODE_VECTOR_INT
:
17162 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
17164 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
17165 insert_wide_int (std::make_pair (elt
, imode
), p
, elt_size
);
17169 case MODE_VECTOR_FLOAT
:
17170 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
17172 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
17173 insert_float (elt
, p
);
17178 gcc_unreachable ();
17181 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
17186 if (dwarf_version
>= 4 || !dwarf_strict
)
17188 dw_loc_descr_ref loc_result
;
17189 resolve_one_addr (&rtl
);
17191 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
17192 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
17193 add_AT_loc (die
, DW_AT_location
, loc_result
);
17194 vec_safe_push (used_rtx_array
, rtl
);
17200 if (CONSTANT_P (XEXP (rtl
, 0)))
17201 return add_const_value_attribute (die
, XEXP (rtl
, 0));
17204 if (!const_ok_for_output (rtl
))
17207 if (dwarf_version
>= 4 || !dwarf_strict
)
17212 /* In cases where an inlined instance of an inline function is passed
17213 the address of an `auto' variable (which is local to the caller) we
17214 can get a situation where the DECL_RTL of the artificial local
17215 variable (for the inlining) which acts as a stand-in for the
17216 corresponding formal parameter (of the inline function) will look
17217 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
17218 exactly a compile-time constant expression, but it isn't the address
17219 of the (artificial) local variable either. Rather, it represents the
17220 *value* which the artificial local variable always has during its
17221 lifetime. We currently have no way to represent such quasi-constant
17222 values in Dwarf, so for now we just punt and generate nothing. */
17230 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
17231 && MEM_READONLY_P (rtl
)
17232 && GET_MODE (rtl
) == BLKmode
)
17234 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
17240 /* No other kinds of rtx should be possible here. */
17241 gcc_unreachable ();
17246 /* Determine whether the evaluation of EXPR references any variables
17247 or functions which aren't otherwise used (and therefore may not be
17250 reference_to_unused (tree
* tp
, int * walk_subtrees
,
17251 void * data ATTRIBUTE_UNUSED
)
17253 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
17254 *walk_subtrees
= 0;
17256 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
17257 && ! TREE_ASM_WRITTEN (*tp
))
17259 /* ??? The C++ FE emits debug information for using decls, so
17260 putting gcc_unreachable here falls over. See PR31899. For now
17261 be conservative. */
17262 else if (!symtab
->global_info_ready
17263 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
17265 else if (TREE_CODE (*tp
) == VAR_DECL
)
17267 varpool_node
*node
= varpool_node::get (*tp
);
17268 if (!node
|| !node
->definition
)
17271 else if (TREE_CODE (*tp
) == FUNCTION_DECL
17272 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
17274 /* The call graph machinery must have finished analyzing,
17275 optimizing and gimplifying the CU by now.
17276 So if *TP has no call graph node associated
17277 to it, it means *TP will not be emitted. */
17278 if (!cgraph_node::get (*tp
))
17281 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
17287 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
17288 for use in a later add_const_value_attribute call. */
17291 rtl_for_decl_init (tree init
, tree type
)
17293 rtx rtl
= NULL_RTX
;
17297 /* If a variable is initialized with a string constant without embedded
17298 zeros, build CONST_STRING. */
17299 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
17301 tree enttype
= TREE_TYPE (type
);
17302 tree domain
= TYPE_DOMAIN (type
);
17303 machine_mode mode
= TYPE_MODE (enttype
);
17305 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
17307 && integer_zerop (TYPE_MIN_VALUE (domain
))
17308 && compare_tree_int (TYPE_MAX_VALUE (domain
),
17309 TREE_STRING_LENGTH (init
) - 1) == 0
17310 && ((size_t) TREE_STRING_LENGTH (init
)
17311 == strlen (TREE_STRING_POINTER (init
)) + 1))
17313 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
17314 ggc_strdup (TREE_STRING_POINTER (init
)));
17315 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
17316 MEM_READONLY_P (rtl
) = 1;
17319 /* Other aggregates, and complex values, could be represented using
17321 else if (AGGREGATE_TYPE_P (type
)
17322 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
17323 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
17324 || TREE_CODE (type
) == COMPLEX_TYPE
)
17326 /* Vectors only work if their mode is supported by the target.
17327 FIXME: generic vectors ought to work too. */
17328 else if (TREE_CODE (type
) == VECTOR_TYPE
17329 && !VECTOR_MODE_P (TYPE_MODE (type
)))
17331 /* If the initializer is something that we know will expand into an
17332 immediate RTL constant, expand it now. We must be careful not to
17333 reference variables which won't be output. */
17334 else if (initializer_constant_valid_p (init
, type
)
17335 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
17337 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
17339 if (TREE_CODE (type
) == VECTOR_TYPE
)
17340 switch (TREE_CODE (init
))
17345 if (TREE_CONSTANT (init
))
17347 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
17348 bool constant_p
= true;
17350 unsigned HOST_WIDE_INT ix
;
17352 /* Even when ctor is constant, it might contain non-*_CST
17353 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
17354 belong into VECTOR_CST nodes. */
17355 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
17356 if (!CONSTANT_CLASS_P (value
))
17358 constant_p
= false;
17364 init
= build_vector_from_ctor (type
, elts
);
17374 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
17376 /* If expand_expr returns a MEM, it wasn't immediate. */
17377 gcc_assert (!rtl
|| !MEM_P (rtl
));
17383 /* Generate RTL for the variable DECL to represent its location. */
17386 rtl_for_decl_location (tree decl
)
17390 /* Here we have to decide where we are going to say the parameter "lives"
17391 (as far as the debugger is concerned). We only have a couple of
17392 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
17394 DECL_RTL normally indicates where the parameter lives during most of the
17395 activation of the function. If optimization is enabled however, this
17396 could be either NULL or else a pseudo-reg. Both of those cases indicate
17397 that the parameter doesn't really live anywhere (as far as the code
17398 generation parts of GCC are concerned) during most of the function's
17399 activation. That will happen (for example) if the parameter is never
17400 referenced within the function.
17402 We could just generate a location descriptor here for all non-NULL
17403 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
17404 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
17405 where DECL_RTL is NULL or is a pseudo-reg.
17407 Note however that we can only get away with using DECL_INCOMING_RTL as
17408 a backup substitute for DECL_RTL in certain limited cases. In cases
17409 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
17410 we can be sure that the parameter was passed using the same type as it is
17411 declared to have within the function, and that its DECL_INCOMING_RTL
17412 points us to a place where a value of that type is passed.
17414 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
17415 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
17416 because in these cases DECL_INCOMING_RTL points us to a value of some
17417 type which is *different* from the type of the parameter itself. Thus,
17418 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
17419 such cases, the debugger would end up (for example) trying to fetch a
17420 `float' from a place which actually contains the first part of a
17421 `double'. That would lead to really incorrect and confusing
17422 output at debug-time.
17424 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
17425 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
17426 are a couple of exceptions however. On little-endian machines we can
17427 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
17428 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
17429 an integral type that is smaller than TREE_TYPE (decl). These cases arise
17430 when (on a little-endian machine) a non-prototyped function has a
17431 parameter declared to be of type `short' or `char'. In such cases,
17432 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
17433 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
17434 passed `int' value. If the debugger then uses that address to fetch
17435 a `short' or a `char' (on a little-endian machine) the result will be
17436 the correct data, so we allow for such exceptional cases below.
17438 Note that our goal here is to describe the place where the given formal
17439 parameter lives during most of the function's activation (i.e. between the
17440 end of the prologue and the start of the epilogue). We'll do that as best
17441 as we can. Note however that if the given formal parameter is modified
17442 sometime during the execution of the function, then a stack backtrace (at
17443 debug-time) will show the function as having been called with the *new*
17444 value rather than the value which was originally passed in. This happens
17445 rarely enough that it is not a major problem, but it *is* a problem, and
17446 I'd like to fix it.
17448 A future version of dwarf2out.c may generate two additional attributes for
17449 any given DW_TAG_formal_parameter DIE which will describe the "passed
17450 type" and the "passed location" for the given formal parameter in addition
17451 to the attributes we now generate to indicate the "declared type" and the
17452 "active location" for each parameter. This additional set of attributes
17453 could be used by debuggers for stack backtraces. Separately, note that
17454 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
17455 This happens (for example) for inlined-instances of inline function formal
17456 parameters which are never referenced. This really shouldn't be
17457 happening. All PARM_DECL nodes should get valid non-NULL
17458 DECL_INCOMING_RTL values. FIXME. */
17460 /* Use DECL_RTL as the "location" unless we find something better. */
17461 rtl
= DECL_RTL_IF_SET (decl
);
17463 /* When generating abstract instances, ignore everything except
17464 constants, symbols living in memory, and symbols living in
17465 fixed registers. */
17466 if (! reload_completed
)
17469 && (CONSTANT_P (rtl
)
17471 && CONSTANT_P (XEXP (rtl
, 0)))
17473 && TREE_CODE (decl
) == VAR_DECL
17474 && TREE_STATIC (decl
))))
17476 rtl
= targetm
.delegitimize_address (rtl
);
17481 else if (TREE_CODE (decl
) == PARM_DECL
)
17483 if (rtl
== NULL_RTX
17484 || is_pseudo_reg (rtl
)
17486 && is_pseudo_reg (XEXP (rtl
, 0))
17487 && DECL_INCOMING_RTL (decl
)
17488 && MEM_P (DECL_INCOMING_RTL (decl
))
17489 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
17491 tree declared_type
= TREE_TYPE (decl
);
17492 tree passed_type
= DECL_ARG_TYPE (decl
);
17493 machine_mode dmode
= TYPE_MODE (declared_type
);
17494 machine_mode pmode
= TYPE_MODE (passed_type
);
17496 /* This decl represents a formal parameter which was optimized out.
17497 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
17498 all cases where (rtl == NULL_RTX) just below. */
17499 if (dmode
== pmode
)
17500 rtl
= DECL_INCOMING_RTL (decl
);
17501 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
17502 && SCALAR_INT_MODE_P (dmode
)
17503 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
17504 && DECL_INCOMING_RTL (decl
))
17506 rtx inc
= DECL_INCOMING_RTL (decl
);
17509 else if (MEM_P (inc
))
17511 if (BYTES_BIG_ENDIAN
)
17512 rtl
= adjust_address_nv (inc
, dmode
,
17513 GET_MODE_SIZE (pmode
)
17514 - GET_MODE_SIZE (dmode
));
17521 /* If the parm was passed in registers, but lives on the stack, then
17522 make a big endian correction if the mode of the type of the
17523 parameter is not the same as the mode of the rtl. */
17524 /* ??? This is the same series of checks that are made in dbxout.c before
17525 we reach the big endian correction code there. It isn't clear if all
17526 of these checks are necessary here, but keeping them all is the safe
17528 else if (MEM_P (rtl
)
17529 && XEXP (rtl
, 0) != const0_rtx
17530 && ! CONSTANT_P (XEXP (rtl
, 0))
17531 /* Not passed in memory. */
17532 && !MEM_P (DECL_INCOMING_RTL (decl
))
17533 /* Not passed by invisible reference. */
17534 && (!REG_P (XEXP (rtl
, 0))
17535 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
17536 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
17537 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
17538 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
17541 /* Big endian correction check. */
17542 && BYTES_BIG_ENDIAN
17543 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
17544 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
17547 machine_mode addr_mode
= get_address_mode (rtl
);
17548 int offset
= (UNITS_PER_WORD
17549 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
17551 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
17552 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
17555 else if (TREE_CODE (decl
) == VAR_DECL
17558 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
17559 && BYTES_BIG_ENDIAN
)
17561 machine_mode addr_mode
= get_address_mode (rtl
);
17562 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
17563 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
17565 /* If a variable is declared "register" yet is smaller than
17566 a register, then if we store the variable to memory, it
17567 looks like we're storing a register-sized value, when in
17568 fact we are not. We need to adjust the offset of the
17569 storage location to reflect the actual value's bytes,
17570 else gdb will not be able to display it. */
17572 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
17573 plus_constant (addr_mode
, XEXP (rtl
, 0),
17577 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
17578 and will have been substituted directly into all expressions that use it.
17579 C does not have such a concept, but C++ and other languages do. */
17580 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
17581 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
17584 rtl
= targetm
.delegitimize_address (rtl
);
17586 /* If we don't look past the constant pool, we risk emitting a
17587 reference to a constant pool entry that isn't referenced from
17588 code, and thus is not emitted. */
17590 rtl
= avoid_constant_pool_reference (rtl
);
17592 /* Try harder to get a rtl. If this symbol ends up not being emitted
17593 in the current CU, resolve_addr will remove the expression referencing
17595 if (rtl
== NULL_RTX
17596 && TREE_CODE (decl
) == VAR_DECL
17597 && !DECL_EXTERNAL (decl
)
17598 && TREE_STATIC (decl
)
17599 && DECL_NAME (decl
)
17600 && !DECL_HARD_REGISTER (decl
)
17601 && DECL_MODE (decl
) != VOIDmode
)
17603 rtl
= make_decl_rtl_for_debug (decl
);
17605 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
17606 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
17613 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
17614 returned. If so, the decl for the COMMON block is returned, and the
17615 value is the offset into the common block for the symbol. */
17618 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
17620 tree val_expr
, cvar
;
17622 HOST_WIDE_INT bitsize
, bitpos
;
17624 int unsignedp
, reversep
, volatilep
= 0;
17626 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
17627 it does not have a value (the offset into the common area), or if it
17628 is thread local (as opposed to global) then it isn't common, and shouldn't
17629 be handled as such. */
17630 if (TREE_CODE (decl
) != VAR_DECL
17631 || !TREE_STATIC (decl
)
17632 || !DECL_HAS_VALUE_EXPR_P (decl
)
17636 val_expr
= DECL_VALUE_EXPR (decl
);
17637 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
17640 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
, &mode
,
17641 &unsignedp
, &reversep
, &volatilep
);
17643 if (cvar
== NULL_TREE
17644 || TREE_CODE (cvar
) != VAR_DECL
17645 || DECL_ARTIFICIAL (cvar
)
17646 || !TREE_PUBLIC (cvar
))
17650 if (offset
!= NULL
)
17652 if (!tree_fits_shwi_p (offset
))
17654 *value
= tree_to_shwi (offset
);
17657 *value
+= bitpos
/ BITS_PER_UNIT
;
17662 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
17663 data attribute for a variable or a parameter. We generate the
17664 DW_AT_const_value attribute only in those cases where the given variable
17665 or parameter does not have a true "location" either in memory or in a
17666 register. This can happen (for example) when a constant is passed as an
17667 actual argument in a call to an inline function. (It's possible that
17668 these things can crop up in other ways also.) Note that one type of
17669 constant value which can be passed into an inlined function is a constant
17670 pointer. This can happen for example if an actual argument in an inlined
17671 function call evaluates to a compile-time constant address.
17673 CACHE_P is true if it is worth caching the location list for DECL,
17674 so that future calls can reuse it rather than regenerate it from scratch.
17675 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
17676 since we will need to refer to them each time the function is inlined. */
17679 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
)
17682 dw_loc_list_ref list
;
17683 var_loc_list
*loc_list
;
17684 cached_dw_loc_list
*cache
;
17689 if (TREE_CODE (decl
) == ERROR_MARK
)
17692 if (get_AT (die
, DW_AT_location
)
17693 || get_AT (die
, DW_AT_const_value
))
17696 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
17697 || TREE_CODE (decl
) == RESULT_DECL
);
17699 /* Try to get some constant RTL for this decl, and use that as the value of
17702 rtl
= rtl_for_decl_location (decl
);
17703 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
17704 && add_const_value_attribute (die
, rtl
))
17707 /* See if we have single element location list that is equivalent to
17708 a constant value. That way we are better to use add_const_value_attribute
17709 rather than expanding constant value equivalent. */
17710 loc_list
= lookup_decl_loc (decl
);
17713 && loc_list
->first
->next
== NULL
17714 && NOTE_P (loc_list
->first
->loc
)
17715 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
17716 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
17718 struct var_loc_node
*node
;
17720 node
= loc_list
->first
;
17721 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
17722 if (GET_CODE (rtl
) == EXPR_LIST
)
17723 rtl
= XEXP (rtl
, 0);
17724 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
17725 && add_const_value_attribute (die
, rtl
))
17728 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
17729 list several times. See if we've already cached the contents. */
17731 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
17735 cache
= cached_dw_loc_list_table
->find_with_hash (decl
, DECL_UID (decl
));
17737 list
= cache
->loc_list
;
17741 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2,
17743 /* It is usually worth caching this result if the decl is from
17744 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
17745 if (cache_p
&& list
&& list
->dw_loc_next
)
17747 cached_dw_loc_list
**slot
17748 = cached_dw_loc_list_table
->find_slot_with_hash (decl
,
17751 cache
= ggc_cleared_alloc
<cached_dw_loc_list
> ();
17752 cache
->decl_id
= DECL_UID (decl
);
17753 cache
->loc_list
= list
;
17759 add_AT_location_description (die
, DW_AT_location
, list
);
17762 /* None of that worked, so it must not really have a location;
17763 try adding a constant value attribute from the DECL_INITIAL. */
17764 return tree_add_const_value_attribute_for_decl (die
, decl
);
17767 /* Helper function for tree_add_const_value_attribute. Natively encode
17768 initializer INIT into an array. Return true if successful. */
17771 native_encode_initializer (tree init
, unsigned char *array
, int size
)
17775 if (init
== NULL_TREE
)
17779 switch (TREE_CODE (init
))
17782 type
= TREE_TYPE (init
);
17783 if (TREE_CODE (type
) == ARRAY_TYPE
)
17785 tree enttype
= TREE_TYPE (type
);
17786 machine_mode mode
= TYPE_MODE (enttype
);
17788 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
17790 if (int_size_in_bytes (type
) != size
)
17792 if (size
> TREE_STRING_LENGTH (init
))
17794 memcpy (array
, TREE_STRING_POINTER (init
),
17795 TREE_STRING_LENGTH (init
));
17796 memset (array
+ TREE_STRING_LENGTH (init
),
17797 '\0', size
- TREE_STRING_LENGTH (init
));
17800 memcpy (array
, TREE_STRING_POINTER (init
), size
);
17805 type
= TREE_TYPE (init
);
17806 if (int_size_in_bytes (type
) != size
)
17808 if (TREE_CODE (type
) == ARRAY_TYPE
)
17810 HOST_WIDE_INT min_index
;
17811 unsigned HOST_WIDE_INT cnt
;
17812 int curpos
= 0, fieldsize
;
17813 constructor_elt
*ce
;
17815 if (TYPE_DOMAIN (type
) == NULL_TREE
17816 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))))
17819 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
17820 if (fieldsize
<= 0)
17823 min_index
= tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)));
17824 memset (array
, '\0', size
);
17825 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
17827 tree val
= ce
->value
;
17828 tree index
= ce
->index
;
17830 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
17831 pos
= (tree_to_shwi (TREE_OPERAND (index
, 0)) - min_index
)
17834 pos
= (tree_to_shwi (index
) - min_index
) * fieldsize
;
17839 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
17842 curpos
= pos
+ fieldsize
;
17843 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
17845 int count
= tree_to_shwi (TREE_OPERAND (index
, 1))
17846 - tree_to_shwi (TREE_OPERAND (index
, 0));
17847 while (count
-- > 0)
17850 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
17851 curpos
+= fieldsize
;
17854 gcc_assert (curpos
<= size
);
17858 else if (TREE_CODE (type
) == RECORD_TYPE
17859 || TREE_CODE (type
) == UNION_TYPE
)
17861 tree field
= NULL_TREE
;
17862 unsigned HOST_WIDE_INT cnt
;
17863 constructor_elt
*ce
;
17865 if (int_size_in_bytes (type
) != size
)
17868 if (TREE_CODE (type
) == RECORD_TYPE
)
17869 field
= TYPE_FIELDS (type
);
17871 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
17873 tree val
= ce
->value
;
17874 int pos
, fieldsize
;
17876 if (ce
->index
!= 0)
17882 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
17885 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
17886 && TYPE_DOMAIN (TREE_TYPE (field
))
17887 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
17889 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
17890 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field
)))
17892 fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
17893 pos
= int_byte_position (field
);
17894 gcc_assert (pos
+ fieldsize
<= size
);
17895 if (val
&& fieldsize
!= 0
17896 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
17902 case VIEW_CONVERT_EXPR
:
17903 case NON_LVALUE_EXPR
:
17904 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
17906 return native_encode_expr (init
, array
, size
) == size
;
17910 /* Attach a DW_AT_const_value attribute to DIE. The value of the
17911 attribute is the const value T. */
17914 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
17917 tree type
= TREE_TYPE (t
);
17920 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
17924 gcc_assert (!DECL_P (init
));
17926 rtl
= rtl_for_decl_init (init
, type
);
17928 return add_const_value_attribute (die
, rtl
);
17929 /* If the host and target are sane, try harder. */
17930 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
17931 && initializer_constant_valid_p (init
, type
))
17933 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
17934 if (size
> 0 && (int) size
== size
)
17936 unsigned char *array
= ggc_cleared_vec_alloc
<unsigned char> (size
);
17938 if (native_encode_initializer (init
, array
, size
))
17940 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
17949 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
17950 attribute is the const value of T, where T is an integral constant
17951 variable with static storage duration
17952 (so it can't be a PARM_DECL or a RESULT_DECL). */
17955 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
17959 || (TREE_CODE (decl
) != VAR_DECL
17960 && TREE_CODE (decl
) != CONST_DECL
)
17961 || (TREE_CODE (decl
) == VAR_DECL
17962 && !TREE_STATIC (decl
)))
17965 if (TREE_READONLY (decl
)
17966 && ! TREE_THIS_VOLATILE (decl
)
17967 && DECL_INITIAL (decl
))
17972 /* Don't add DW_AT_const_value if abstract origin already has one. */
17973 if (get_AT (var_die
, DW_AT_const_value
))
17976 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
17979 /* Convert the CFI instructions for the current function into a
17980 location list. This is used for DW_AT_frame_base when we targeting
17981 a dwarf2 consumer that does not support the dwarf3
17982 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
17985 static dw_loc_list_ref
17986 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
17990 dw_loc_list_ref list
, *list_tail
;
17992 dw_cfa_location last_cfa
, next_cfa
;
17993 const char *start_label
, *last_label
, *section
;
17994 dw_cfa_location remember
;
17997 gcc_assert (fde
!= NULL
);
17999 section
= secname_for_decl (current_function_decl
);
18003 memset (&next_cfa
, 0, sizeof (next_cfa
));
18004 next_cfa
.reg
= INVALID_REGNUM
;
18005 remember
= next_cfa
;
18007 start_label
= fde
->dw_fde_begin
;
18009 /* ??? Bald assumption that the CIE opcode list does not contain
18010 advance opcodes. */
18011 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
18012 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
18014 last_cfa
= next_cfa
;
18015 last_label
= start_label
;
18017 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
18019 /* If the first partition contained no CFI adjustments, the
18020 CIE opcodes apply to the whole first partition. */
18021 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
18022 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
18023 list_tail
=&(*list_tail
)->dw_loc_next
;
18024 start_label
= last_label
= fde
->dw_fde_second_begin
;
18027 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
18029 switch (cfi
->dw_cfi_opc
)
18031 case DW_CFA_set_loc
:
18032 case DW_CFA_advance_loc1
:
18033 case DW_CFA_advance_loc2
:
18034 case DW_CFA_advance_loc4
:
18035 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
18037 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
18038 start_label
, last_label
, section
);
18040 list_tail
= &(*list_tail
)->dw_loc_next
;
18041 last_cfa
= next_cfa
;
18042 start_label
= last_label
;
18044 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
18047 case DW_CFA_advance_loc
:
18048 /* The encoding is complex enough that we should never emit this. */
18049 gcc_unreachable ();
18052 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
18055 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
18057 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
18059 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
18060 start_label
, last_label
, section
);
18062 list_tail
= &(*list_tail
)->dw_loc_next
;
18063 last_cfa
= next_cfa
;
18064 start_label
= last_label
;
18066 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
18067 start_label
, fde
->dw_fde_end
, section
);
18068 list_tail
= &(*list_tail
)->dw_loc_next
;
18069 start_label
= last_label
= fde
->dw_fde_second_begin
;
18073 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
18075 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
18076 start_label
, last_label
, section
);
18077 list_tail
= &(*list_tail
)->dw_loc_next
;
18078 start_label
= last_label
;
18081 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
18083 fde
->dw_fde_second_begin
18084 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
18087 if (list
&& list
->dw_loc_next
)
18093 /* Compute a displacement from the "steady-state frame pointer" to the
18094 frame base (often the same as the CFA), and store it in
18095 frame_pointer_fb_offset. OFFSET is added to the displacement
18096 before the latter is negated. */
18099 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
18103 #ifdef FRAME_POINTER_CFA_OFFSET
18104 reg
= frame_pointer_rtx
;
18105 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
18107 reg
= arg_pointer_rtx
;
18108 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
18111 elim
= (ira_use_lra_p
18112 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
18113 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
18114 if (GET_CODE (elim
) == PLUS
)
18116 offset
+= INTVAL (XEXP (elim
, 1));
18117 elim
= XEXP (elim
, 0);
18120 frame_pointer_fb_offset
= -offset
;
18122 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
18123 in which to eliminate. This is because it's stack pointer isn't
18124 directly accessible as a register within the ISA. To work around
18125 this, assume that while we cannot provide a proper value for
18126 frame_pointer_fb_offset, we won't need one either. */
18127 frame_pointer_fb_offset_valid
18128 = ((SUPPORTS_STACK_ALIGNMENT
18129 && (elim
== hard_frame_pointer_rtx
18130 || elim
== stack_pointer_rtx
))
18131 || elim
== (frame_pointer_needed
18132 ? hard_frame_pointer_rtx
18133 : stack_pointer_rtx
));
18136 /* Generate a DW_AT_name attribute given some string value to be included as
18137 the value of the attribute. */
18140 add_name_attribute (dw_die_ref die
, const char *name_string
)
18142 if (name_string
!= NULL
&& *name_string
!= 0)
18144 if (demangle_name_func
)
18145 name_string
= (*demangle_name_func
) (name_string
);
18147 add_AT_string (die
, DW_AT_name
, name_string
);
18151 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
18152 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
18153 of TYPE accordingly.
18155 ??? This is a temporary measure until after we're able to generate
18156 regular DWARF for the complex Ada type system. */
18159 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
18160 dw_die_ref context_die
)
18163 dw_die_ref dtype_die
;
18165 if (!lang_hooks
.types
.descriptive_type
)
18168 dtype
= lang_hooks
.types
.descriptive_type (type
);
18172 dtype_die
= lookup_type_die (dtype
);
18175 gen_type_die (dtype
, context_die
);
18176 dtype_die
= lookup_type_die (dtype
);
18177 gcc_assert (dtype_die
);
18180 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
18183 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
18185 static const char *
18186 comp_dir_string (void)
18190 static const char *cached_wd
= NULL
;
18192 if (cached_wd
!= NULL
)
18195 wd
= get_src_pwd ();
18199 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
18203 wdlen
= strlen (wd
);
18204 wd1
= ggc_vec_alloc
<char> (wdlen
+ 2);
18206 wd1
[wdlen
] = DIR_SEPARATOR
;
18207 wd1
[wdlen
+ 1] = 0;
18211 cached_wd
= remap_debug_filename (wd
);
18215 /* Generate a DW_AT_comp_dir attribute for DIE. */
18218 add_comp_dir_attribute (dw_die_ref die
)
18220 const char * wd
= comp_dir_string ();
18222 add_AT_string (die
, DW_AT_comp_dir
, wd
);
18225 /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
18226 pointer computation, ...), output a representation for that bound according
18227 to the accepted FORMS (see enum dw_scalar_form) and add it to DIE. See
18228 loc_list_from_tree for the meaning of CONTEXT. */
18231 add_scalar_info (dw_die_ref die
, enum dwarf_attribute attr
, tree value
,
18232 int forms
, const struct loc_descr_context
*context
)
18234 dw_die_ref context_die
, decl_die
;
18235 dw_loc_list_ref list
;
18237 bool strip_conversions
= true;
18239 while (strip_conversions
)
18240 switch (TREE_CODE (value
))
18247 case VIEW_CONVERT_EXPR
:
18248 value
= TREE_OPERAND (value
, 0);
18252 strip_conversions
= false;
18256 /* If possible and permitted, output the attribute as a constant. */
18257 if ((forms
& dw_scalar_form_constant
) != 0
18258 && TREE_CODE (value
) == INTEGER_CST
)
18260 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (value
));
18262 /* If HOST_WIDE_INT is big enough then represent the bound as
18263 a constant value. We need to choose a form based on
18264 whether the type is signed or unsigned. We cannot just
18265 call add_AT_unsigned if the value itself is positive
18266 (add_AT_unsigned might add the unsigned value encoded as
18267 DW_FORM_data[1248]). Some DWARF consumers will lookup the
18268 bounds type and then sign extend any unsigned values found
18269 for signed types. This is needed only for
18270 DW_AT_{lower,upper}_bound, since for most other attributes,
18271 consumers will treat DW_FORM_data[1248] as unsigned values,
18272 regardless of the underlying type. */
18273 if (prec
<= HOST_BITS_PER_WIDE_INT
18274 || tree_fits_uhwi_p (value
))
18276 if (TYPE_UNSIGNED (TREE_TYPE (value
)))
18277 add_AT_unsigned (die
, attr
, TREE_INT_CST_LOW (value
));
18279 add_AT_int (die
, attr
, TREE_INT_CST_LOW (value
));
18282 /* Otherwise represent the bound as an unsigned value with
18283 the precision of its type. The precision and signedness
18284 of the type will be necessary to re-interpret it
18286 add_AT_wide (die
, attr
, value
);
18290 /* Otherwise, if it's possible and permitted too, output a reference to
18292 if ((forms
& dw_scalar_form_reference
) != 0)
18294 tree decl
= NULL_TREE
;
18296 /* Some type attributes reference an outer type. For instance, the upper
18297 bound of an array may reference an embedding record (this happens in
18299 if (TREE_CODE (value
) == COMPONENT_REF
18300 && TREE_CODE (TREE_OPERAND (value
, 0)) == PLACEHOLDER_EXPR
18301 && TREE_CODE (TREE_OPERAND (value
, 1)) == FIELD_DECL
)
18302 decl
= TREE_OPERAND (value
, 1);
18304 else if (TREE_CODE (value
) == VAR_DECL
18305 || TREE_CODE (value
) == PARM_DECL
18306 || TREE_CODE (value
) == RESULT_DECL
)
18309 if (decl
!= NULL_TREE
)
18311 dw_die_ref decl_die
= lookup_decl_die (decl
);
18313 /* ??? Can this happen, or should the variable have been bound
18314 first? Probably it can, since I imagine that we try to create
18315 the types of parameters in the order in which they exist in
18316 the list, and won't have created a forward reference to a
18317 later parameter. */
18318 if (decl_die
!= NULL
)
18320 add_AT_die_ref (die
, attr
, decl_die
);
18326 /* Last chance: try to create a stack operation procedure to evaluate the
18327 value. Do nothing if even that is not possible or permitted. */
18328 if ((forms
& dw_scalar_form_exprloc
) == 0)
18331 list
= loc_list_from_tree (value
, 2, context
);
18332 if (list
== NULL
|| single_element_loc_list_p (list
))
18334 /* If this attribute is not a reference nor constant, it is
18335 a DWARF expression rather than location description. For that
18336 loc_list_from_tree (value, 0, &context) is needed. */
18337 dw_loc_list_ref list2
= loc_list_from_tree (value
, 0, context
);
18338 if (list2
&& single_element_loc_list_p (list2
))
18340 add_AT_loc (die
, attr
, list2
->expr
);
18345 /* If that failed to give a single element location list, fall back to
18346 outputting this as a reference... still if permitted. */
18347 if (list
== NULL
|| (forms
& dw_scalar_form_reference
) == 0)
18350 if (current_function_decl
== 0)
18351 context_die
= comp_unit_die ();
18353 context_die
= lookup_decl_die (current_function_decl
);
18355 decl_die
= new_die (DW_TAG_variable
, context_die
, value
);
18356 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
18357 add_type_attribute (decl_die
, TREE_TYPE (value
), TYPE_QUAL_CONST
, false,
18359 add_AT_location_description (decl_die
, DW_AT_location
, list
);
18360 add_AT_die_ref (die
, attr
, decl_die
);
18363 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
18367 lower_bound_default (void)
18369 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
18375 case DW_LANG_C_plus_plus
:
18376 case DW_LANG_C_plus_plus_11
:
18377 case DW_LANG_C_plus_plus_14
:
18379 case DW_LANG_ObjC_plus_plus
:
18382 case DW_LANG_Fortran77
:
18383 case DW_LANG_Fortran90
:
18384 case DW_LANG_Fortran95
:
18385 case DW_LANG_Fortran03
:
18386 case DW_LANG_Fortran08
:
18390 case DW_LANG_Python
:
18391 return dwarf_version
>= 4 ? 0 : -1;
18392 case DW_LANG_Ada95
:
18393 case DW_LANG_Ada83
:
18394 case DW_LANG_Cobol74
:
18395 case DW_LANG_Cobol85
:
18396 case DW_LANG_Pascal83
:
18397 case DW_LANG_Modula2
:
18399 return dwarf_version
>= 4 ? 1 : -1;
18405 /* Given a tree node describing an array bound (either lower or upper) output
18406 a representation for that bound. */
18409 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
,
18410 tree bound
, const struct loc_descr_context
*context
)
18415 switch (TREE_CODE (bound
))
18417 /* Strip all conversions. */
18419 case VIEW_CONVERT_EXPR
:
18420 bound
= TREE_OPERAND (bound
, 0);
18423 /* All fixed-bounds are represented by INTEGER_CST nodes. Lower bounds
18424 are even omitted when they are the default. */
18426 /* If the value for this bound is the default one, we can even omit the
18428 if (bound_attr
== DW_AT_lower_bound
18429 && tree_fits_shwi_p (bound
)
18430 && (dflt
= lower_bound_default ()) != -1
18431 && tree_to_shwi (bound
) == dflt
)
18437 /* Because of the complex interaction there can be with other GNAT
18438 encodings, GDB isn't ready yet to handle proper DWARF description
18439 for self-referencial subrange bounds: let GNAT encodings do the
18440 magic in such a case. */
18441 if (gnat_encodings
!= DWARF_GNAT_ENCODINGS_MINIMAL
18442 && contains_placeholder_p (bound
))
18445 add_scalar_info (subrange_die
, bound_attr
, bound
,
18446 dw_scalar_form_constant
18447 | dw_scalar_form_exprloc
18448 | dw_scalar_form_reference
,
18454 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
18455 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
18456 Note that the block of subscript information for an array type also
18457 includes information about the element type of the given array type.
18459 This function reuses previously set type and bound information if
18463 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
18465 unsigned dimension_number
;
18467 dw_die_ref child
= type_die
->die_child
;
18469 for (dimension_number
= 0;
18470 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
18471 type
= TREE_TYPE (type
), dimension_number
++)
18473 tree domain
= TYPE_DOMAIN (type
);
18475 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
18478 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
18479 and (in GNU C only) variable bounds. Handle all three forms
18482 /* Find and reuse a previously generated DW_TAG_subrange_type if
18485 For multi-dimensional arrays, as we iterate through the
18486 various dimensions in the enclosing for loop above, we also
18487 iterate through the DIE children and pick at each
18488 DW_TAG_subrange_type previously generated (if available).
18489 Each child DW_TAG_subrange_type DIE describes the range of
18490 the current dimension. At this point we should have as many
18491 DW_TAG_subrange_type's as we have dimensions in the
18493 dw_die_ref subrange_die
= NULL
;
18497 child
= child
->die_sib
;
18498 if (child
->die_tag
== DW_TAG_subrange_type
)
18499 subrange_die
= child
;
18500 if (child
== type_die
->die_child
)
18502 /* If we wrapped around, stop looking next time. */
18506 if (child
->die_tag
== DW_TAG_subrange_type
)
18510 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
18514 /* We have an array type with specified bounds. */
18515 lower
= TYPE_MIN_VALUE (domain
);
18516 upper
= TYPE_MAX_VALUE (domain
);
18518 /* Define the index type. */
18519 if (TREE_TYPE (domain
)
18520 && !get_AT (subrange_die
, DW_AT_type
))
18522 /* ??? This is probably an Ada unnamed subrange type. Ignore the
18523 TREE_TYPE field. We can't emit debug info for this
18524 because it is an unnamed integral type. */
18525 if (TREE_CODE (domain
) == INTEGER_TYPE
18526 && TYPE_NAME (domain
) == NULL_TREE
18527 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
18528 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
18531 add_type_attribute (subrange_die
, TREE_TYPE (domain
),
18532 TYPE_UNQUALIFIED
, false, type_die
);
18535 /* ??? If upper is NULL, the array has unspecified length,
18536 but it does have a lower bound. This happens with Fortran
18538 Since the debugger is definitely going to need to know N
18539 to produce useful results, go ahead and output the lower
18540 bound solo, and hope the debugger can cope. */
18542 if (!get_AT (subrange_die
, DW_AT_lower_bound
))
18543 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
, NULL
);
18544 if (upper
&& !get_AT (subrange_die
, DW_AT_upper_bound
))
18545 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
, NULL
);
18548 /* Otherwise we have an array type with an unspecified length. The
18549 DWARF-2 spec does not say how to handle this; let's just leave out the
18554 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
18557 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
18559 dw_die_ref decl_die
;
18560 HOST_WIDE_INT size
;
18561 dw_loc_descr_ref size_expr
= NULL
;
18563 switch (TREE_CODE (tree_node
))
18568 case ENUMERAL_TYPE
:
18571 case QUAL_UNION_TYPE
:
18572 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
18573 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
18575 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
18578 size_expr
= type_byte_size (tree_node
, &size
);
18581 /* For a data member of a struct or union, the DW_AT_byte_size is
18582 generally given as the number of bytes normally allocated for an
18583 object of the *declared* type of the member itself. This is true
18584 even for bit-fields. */
18585 size
= int_size_in_bytes (field_type (tree_node
));
18588 gcc_unreachable ();
18591 /* Support for dynamically-sized objects was introduced by DWARFv3.
18592 At the moment, GDB does not handle variable byte sizes very well,
18594 if ((dwarf_version
>= 3 || !dwarf_strict
)
18595 && gnat_encodings
== DWARF_GNAT_ENCODINGS_MINIMAL
18596 && size_expr
!= NULL
)
18597 add_AT_loc (die
, DW_AT_byte_size
, size_expr
);
18599 /* Note that `size' might be -1 when we get to this point. If it is, that
18600 indicates that the byte size of the entity in question is variable and
18601 that we could not generate a DWARF expression that computes it. */
18603 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
18606 /* For a FIELD_DECL node which represents a bit-field, output an attribute
18607 which specifies the distance in bits from the highest order bit of the
18608 "containing object" for the bit-field to the highest order bit of the
18611 For any given bit-field, the "containing object" is a hypothetical object
18612 (of some integral or enum type) within which the given bit-field lives. The
18613 type of this hypothetical "containing object" is always the same as the
18614 declared type of the individual bit-field itself. The determination of the
18615 exact location of the "containing object" for a bit-field is rather
18616 complicated. It's handled by the `field_byte_offset' function (above).
18618 CTX is required: see the comment for VLR_CONTEXT.
18620 Note that it is the size (in bytes) of the hypothetical "containing object"
18621 which will be given in the DW_AT_byte_size attribute for this bit-field.
18622 (See `byte_size_attribute' above). */
18625 add_bit_offset_attribute (dw_die_ref die
, tree decl
, struct vlr_context
*ctx
)
18627 HOST_WIDE_INT object_offset_in_bytes
;
18628 tree original_type
= DECL_BIT_FIELD_TYPE (decl
);
18629 HOST_WIDE_INT bitpos_int
;
18630 HOST_WIDE_INT highest_order_object_bit_offset
;
18631 HOST_WIDE_INT highest_order_field_bit_offset
;
18632 HOST_WIDE_INT bit_offset
;
18634 field_byte_offset (decl
, ctx
, &object_offset_in_bytes
);
18636 /* Must be a field and a bit field. */
18637 gcc_assert (original_type
&& TREE_CODE (decl
) == FIELD_DECL
);
18639 /* We can't yet handle bit-fields whose offsets are variable, so if we
18640 encounter such things, just return without generating any attribute
18641 whatsoever. Likewise for variable or too large size. */
18642 if (! tree_fits_shwi_p (bit_position (decl
))
18643 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
18646 bitpos_int
= int_bit_position (decl
);
18648 /* Note that the bit offset is always the distance (in bits) from the
18649 highest-order bit of the "containing object" to the highest-order bit of
18650 the bit-field itself. Since the "high-order end" of any object or field
18651 is different on big-endian and little-endian machines, the computation
18652 below must take account of these differences. */
18653 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
18654 highest_order_field_bit_offset
= bitpos_int
;
18656 if (! BYTES_BIG_ENDIAN
)
18658 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
18659 highest_order_object_bit_offset
+=
18660 simple_type_size_in_bits (original_type
);
18664 = (! BYTES_BIG_ENDIAN
18665 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
18666 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
18668 if (bit_offset
< 0)
18669 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
18671 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
18674 /* For a FIELD_DECL node which represents a bit field, output an attribute
18675 which specifies the length in bits of the given field. */
18678 add_bit_size_attribute (dw_die_ref die
, tree decl
)
18680 /* Must be a field and a bit field. */
18681 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
18682 && DECL_BIT_FIELD_TYPE (decl
));
18684 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
18685 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
18688 /* If the compiled language is ANSI C, then add a 'prototyped'
18689 attribute, if arg types are given for the parameters of a function. */
18692 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
18694 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
18701 if (prototype_p (func_type
))
18702 add_AT_flag (die
, DW_AT_prototyped
, 1);
18709 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
18710 by looking in the type declaration, the object declaration equate table or
18711 the block mapping. */
18713 static inline dw_die_ref
18714 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
18716 dw_die_ref origin_die
= NULL
;
18718 if (TREE_CODE (origin
) != FUNCTION_DECL
18719 && TREE_CODE (origin
) != BLOCK
)
18721 /* We may have gotten separated from the block for the inlined
18722 function, if we're in an exception handler or some such; make
18723 sure that the abstract function has been written out.
18725 Doing this for nested functions is wrong, however; functions are
18726 distinct units, and our context might not even be inline. */
18730 fn
= TYPE_STUB_DECL (fn
);
18732 fn
= decl_function_context (fn
);
18734 dwarf2out_abstract_function (fn
);
18737 if (DECL_P (origin
))
18738 origin_die
= lookup_decl_die (origin
);
18739 else if (TYPE_P (origin
))
18740 origin_die
= lookup_type_die (origin
);
18741 else if (TREE_CODE (origin
) == BLOCK
)
18742 origin_die
= BLOCK_DIE (origin
);
18744 /* XXX: Functions that are never lowered don't always have correct block
18745 trees (in the case of java, they simply have no block tree, in some other
18746 languages). For these functions, there is nothing we can really do to
18747 output correct debug info for inlined functions in all cases. Rather
18748 than die, we'll just produce deficient debug info now, in that we will
18749 have variables without a proper abstract origin. In the future, when all
18750 functions are lowered, we should re-add a gcc_assert (origin_die)
18754 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
18758 /* We do not currently support the pure_virtual attribute. */
18761 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
18763 if (DECL_VINDEX (func_decl
))
18765 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
18767 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
18768 add_AT_loc (die
, DW_AT_vtable_elem_location
,
18769 new_loc_descr (DW_OP_constu
,
18770 tree_to_shwi (DECL_VINDEX (func_decl
)),
18773 /* GNU extension: Record what type this method came from originally. */
18774 if (debug_info_level
> DINFO_LEVEL_TERSE
18775 && DECL_CONTEXT (func_decl
))
18776 add_AT_die_ref (die
, DW_AT_containing_type
,
18777 lookup_type_die (DECL_CONTEXT (func_decl
)));
18781 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
18782 given decl. This used to be a vendor extension until after DWARF 4
18783 standardized it. */
18786 add_linkage_attr (dw_die_ref die
, tree decl
)
18788 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
18790 /* Mimic what assemble_name_raw does with a leading '*'. */
18791 if (name
[0] == '*')
18794 if (dwarf_version
>= 4)
18795 add_AT_string (die
, DW_AT_linkage_name
, name
);
18797 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
18800 /* Add source coordinate attributes for the given decl. */
18803 add_src_coords_attributes (dw_die_ref die
, tree decl
)
18805 expanded_location s
;
18807 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
18809 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18810 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
18811 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
18814 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
18817 add_linkage_name_raw (dw_die_ref die
, tree decl
)
18819 /* Defer until we have an assembler name set. */
18820 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
18822 limbo_die_node
*asm_name
;
18824 asm_name
= ggc_cleared_alloc
<limbo_die_node
> ();
18825 asm_name
->die
= die
;
18826 asm_name
->created_for
= decl
;
18827 asm_name
->next
= deferred_asm_name
;
18828 deferred_asm_name
= asm_name
;
18830 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
18831 add_linkage_attr (die
, decl
);
18834 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl if desired. */
18837 add_linkage_name (dw_die_ref die
, tree decl
)
18839 if (debug_info_level
> DINFO_LEVEL_NONE
18840 && (TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
18841 && TREE_PUBLIC (decl
)
18842 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
18843 && die
->die_tag
!= DW_TAG_member
)
18844 add_linkage_name_raw (die
, decl
);
18847 /* Add a DW_AT_name attribute and source coordinate attribute for the
18848 given decl, but only if it actually has a name. */
18851 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
18855 decl_name
= DECL_NAME (decl
);
18856 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
18858 const char *name
= dwarf2_name (decl
, 0);
18860 add_name_attribute (die
, name
);
18861 if (! DECL_ARTIFICIAL (decl
))
18862 add_src_coords_attributes (die
, decl
);
18864 add_linkage_name (die
, decl
);
18867 #ifdef VMS_DEBUGGING_INFO
18868 /* Get the function's name, as described by its RTL. This may be different
18869 from the DECL_NAME name used in the source file. */
18870 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
18872 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
18873 XEXP (DECL_RTL (decl
), 0), false);
18874 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
18876 #endif /* VMS_DEBUGGING_INFO */
18879 /* Add VALUE as a DW_AT_discr_value attribute to DIE. */
18882 add_discr_value (dw_die_ref die
, dw_discr_value
*value
)
18886 attr
.dw_attr
= DW_AT_discr_value
;
18887 attr
.dw_attr_val
.val_class
= dw_val_class_discr_value
;
18888 attr
.dw_attr_val
.val_entry
= NULL
;
18889 attr
.dw_attr_val
.v
.val_discr_value
.pos
= value
->pos
;
18891 attr
.dw_attr_val
.v
.val_discr_value
.v
.uval
= value
->v
.uval
;
18893 attr
.dw_attr_val
.v
.val_discr_value
.v
.sval
= value
->v
.sval
;
18894 add_dwarf_attr (die
, &attr
);
18897 /* Add DISCR_LIST as a DW_AT_discr_list to DIE. */
18900 add_discr_list (dw_die_ref die
, dw_discr_list_ref discr_list
)
18904 attr
.dw_attr
= DW_AT_discr_list
;
18905 attr
.dw_attr_val
.val_class
= dw_val_class_discr_list
;
18906 attr
.dw_attr_val
.val_entry
= NULL
;
18907 attr
.dw_attr_val
.v
.val_discr_list
= discr_list
;
18908 add_dwarf_attr (die
, &attr
);
18911 static inline dw_discr_list_ref
18912 AT_discr_list (dw_attr_node
*attr
)
18914 return attr
->dw_attr_val
.v
.val_discr_list
;
18917 #ifdef VMS_DEBUGGING_INFO
18918 /* Output the debug main pointer die for VMS */
18921 dwarf2out_vms_debug_main_pointer (void)
18923 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18926 /* Allocate the VMS debug main subprogram die. */
18927 die
= ggc_cleared_alloc
<die_node
> ();
18928 die
->die_tag
= DW_TAG_subprogram
;
18929 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
18930 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
18931 current_function_funcdef_no
);
18932 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
18934 /* Make it the first child of comp_unit_die (). */
18935 die
->die_parent
= comp_unit_die ();
18936 if (comp_unit_die ()->die_child
)
18938 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
18939 comp_unit_die ()->die_child
->die_sib
= die
;
18943 die
->die_sib
= die
;
18944 comp_unit_die ()->die_child
= die
;
18947 #endif /* VMS_DEBUGGING_INFO */
18949 /* Push a new declaration scope. */
18952 push_decl_scope (tree scope
)
18954 vec_safe_push (decl_scope_table
, scope
);
18957 /* Pop a declaration scope. */
18960 pop_decl_scope (void)
18962 decl_scope_table
->pop ();
18965 /* walk_tree helper function for uses_local_type, below. */
18968 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
18971 *walk_subtrees
= 0;
18974 tree name
= TYPE_NAME (*tp
);
18975 if (name
&& DECL_P (name
) && decl_function_context (name
))
18981 /* If TYPE involves a function-local type (including a local typedef to a
18982 non-local type), returns that type; otherwise returns NULL_TREE. */
18985 uses_local_type (tree type
)
18987 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
18991 /* Return the DIE for the scope that immediately contains this type.
18992 Non-named types that do not involve a function-local type get global
18993 scope. Named types nested in namespaces or other types get their
18994 containing scope. All other types (i.e. function-local named types) get
18995 the current active scope. */
18998 scope_die_for (tree t
, dw_die_ref context_die
)
19000 dw_die_ref scope_die
= NULL
;
19001 tree containing_scope
;
19003 /* Non-types always go in the current scope. */
19004 gcc_assert (TYPE_P (t
));
19006 /* Use the scope of the typedef, rather than the scope of the type
19008 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
19009 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
19011 containing_scope
= TYPE_CONTEXT (t
);
19013 /* Use the containing namespace if there is one. */
19014 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
19016 if (context_die
== lookup_decl_die (containing_scope
))
19018 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
19019 context_die
= get_context_die (containing_scope
);
19021 containing_scope
= NULL_TREE
;
19024 /* Ignore function type "scopes" from the C frontend. They mean that
19025 a tagged type is local to a parmlist of a function declarator, but
19026 that isn't useful to DWARF. */
19027 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
19028 containing_scope
= NULL_TREE
;
19030 if (SCOPE_FILE_SCOPE_P (containing_scope
))
19032 /* If T uses a local type keep it local as well, to avoid references
19033 to function-local DIEs from outside the function. */
19034 if (current_function_decl
&& uses_local_type (t
))
19035 scope_die
= context_die
;
19037 scope_die
= comp_unit_die ();
19039 else if (TYPE_P (containing_scope
))
19041 /* For types, we can just look up the appropriate DIE. */
19042 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19043 scope_die
= get_context_die (containing_scope
);
19046 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
19047 if (scope_die
== NULL
)
19048 scope_die
= comp_unit_die ();
19052 scope_die
= context_die
;
19057 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
19060 local_scope_p (dw_die_ref context_die
)
19062 for (; context_die
; context_die
= context_die
->die_parent
)
19063 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
19064 || context_die
->die_tag
== DW_TAG_subprogram
)
19070 /* Returns nonzero if CONTEXT_DIE is a class. */
19073 class_scope_p (dw_die_ref context_die
)
19075 return (context_die
19076 && (context_die
->die_tag
== DW_TAG_structure_type
19077 || context_die
->die_tag
== DW_TAG_class_type
19078 || context_die
->die_tag
== DW_TAG_interface_type
19079 || context_die
->die_tag
== DW_TAG_union_type
));
19082 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
19083 whether or not to treat a DIE in this context as a declaration. */
19086 class_or_namespace_scope_p (dw_die_ref context_die
)
19088 return (class_scope_p (context_die
)
19089 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
19092 /* Many forms of DIEs require a "type description" attribute. This
19093 routine locates the proper "type descriptor" die for the type given
19094 by 'type' plus any additional qualifiers given by 'cv_quals', and
19095 adds a DW_AT_type attribute below the given die. */
19098 add_type_attribute (dw_die_ref object_die
, tree type
, int cv_quals
,
19099 bool reverse
, dw_die_ref context_die
)
19101 enum tree_code code
= TREE_CODE (type
);
19102 dw_die_ref type_die
= NULL
;
19104 /* ??? If this type is an unnamed subrange type of an integral, floating-point
19105 or fixed-point type, use the inner type. This is because we have no
19106 support for unnamed types in base_type_die. This can happen if this is
19107 an Ada subrange type. Correct solution is emit a subrange type die. */
19108 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
19109 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
19110 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
19112 if (code
== ERROR_MARK
19113 /* Handle a special case. For functions whose return type is void, we
19114 generate *no* type attribute. (Note that no object may have type
19115 `void', so this only applies to function return types). */
19116 || code
== VOID_TYPE
)
19119 type_die
= modified_type_die (type
,
19120 cv_quals
| TYPE_QUALS_NO_ADDR_SPACE (type
),
19124 if (type_die
!= NULL
)
19125 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
19128 /* Given an object die, add the calling convention attribute for the
19129 function call type. */
19131 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
19133 enum dwarf_calling_convention value
= DW_CC_normal
;
19135 value
= ((enum dwarf_calling_convention
)
19136 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
19139 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
19141 /* DWARF 2 doesn't provide a way to identify a program's source-level
19142 entry point. DW_AT_calling_convention attributes are only meant
19143 to describe functions' calling conventions. However, lacking a
19144 better way to signal the Fortran main program, we used this for
19145 a long time, following existing custom. Now, DWARF 4 has
19146 DW_AT_main_subprogram, which we add below, but some tools still
19147 rely on the old way, which we thus keep. */
19148 value
= DW_CC_program
;
19150 if (dwarf_version
>= 4 || !dwarf_strict
)
19151 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
19154 /* Only add the attribute if the backend requests it, and
19155 is not DW_CC_normal. */
19156 if (value
&& (value
!= DW_CC_normal
))
19157 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
19160 /* Given a tree pointer to a struct, class, union, or enum type node, return
19161 a pointer to the (string) tag name for the given type, or zero if the type
19162 was declared without a tag. */
19164 static const char *
19165 type_tag (const_tree type
)
19167 const char *name
= 0;
19169 if (TYPE_NAME (type
) != 0)
19173 /* Find the IDENTIFIER_NODE for the type name. */
19174 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
19175 && !TYPE_NAMELESS (type
))
19176 t
= TYPE_NAME (type
);
19178 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
19179 a TYPE_DECL node, regardless of whether or not a `typedef' was
19181 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
19182 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
19184 /* We want to be extra verbose. Don't call dwarf_name if
19185 DECL_NAME isn't set. The default hook for decl_printable_name
19186 doesn't like that, and in this context it's correct to return
19187 0, instead of "<anonymous>" or the like. */
19188 if (DECL_NAME (TYPE_NAME (type
))
19189 && !DECL_NAMELESS (TYPE_NAME (type
)))
19190 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
19193 /* Now get the name as a string, or invent one. */
19194 if (!name
&& t
!= 0)
19195 name
= IDENTIFIER_POINTER (t
);
19198 return (name
== 0 || *name
== '\0') ? 0 : name
;
19201 /* Return the type associated with a data member, make a special check
19202 for bit field types. */
19205 member_declared_type (const_tree member
)
19207 return (DECL_BIT_FIELD_TYPE (member
)
19208 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
19211 /* Get the decl's label, as described by its RTL. This may be different
19212 from the DECL_NAME name used in the source file. */
19215 static const char *
19216 decl_start_label (tree decl
)
19219 const char *fnname
;
19221 x
= DECL_RTL (decl
);
19222 gcc_assert (MEM_P (x
));
19225 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
19227 fnname
= XSTR (x
, 0);
19232 /* For variable-length arrays that have been previously generated, but
19233 may be incomplete due to missing subscript info, fill the subscript
19234 info. Return TRUE if this is one of those cases. */
19236 fill_variable_array_bounds (tree type
)
19238 if (TREE_ASM_WRITTEN (type
)
19239 && TREE_CODE (type
) == ARRAY_TYPE
19240 && variably_modified_type_p (type
, NULL
))
19242 dw_die_ref array_die
= lookup_type_die (type
);
19245 add_subscript_info (array_die
, type
, !is_ada ());
19251 /* These routines generate the internal representation of the DIE's for
19252 the compilation unit. Debugging information is collected by walking
19253 the declaration trees passed in from dwarf2out_decl(). */
19256 gen_array_type_die (tree type
, dw_die_ref context_die
)
19258 dw_die_ref array_die
;
19260 /* GNU compilers represent multidimensional array types as sequences of one
19261 dimensional array types whose element types are themselves array types.
19262 We sometimes squish that down to a single array_type DIE with multiple
19263 subscripts in the Dwarf debugging info. The draft Dwarf specification
19264 say that we are allowed to do this kind of compression in C, because
19265 there is no difference between an array of arrays and a multidimensional
19266 array. We don't do this for Ada to remain as close as possible to the
19267 actual representation, which is especially important against the language
19268 flexibilty wrt arrays of variable size. */
19270 bool collapse_nested_arrays
= !is_ada ();
19272 if (fill_variable_array_bounds (type
))
19275 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
19278 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
19279 DW_TAG_string_type doesn't have DW_AT_type attribute). */
19280 if (TYPE_STRING_FLAG (type
)
19281 && TREE_CODE (type
) == ARRAY_TYPE
19283 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
19285 HOST_WIDE_INT size
;
19287 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
19288 add_name_attribute (array_die
, type_tag (type
));
19289 equate_type_number_to_die (type
, array_die
);
19290 size
= int_size_in_bytes (type
);
19292 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
19293 else if (TYPE_DOMAIN (type
) != NULL_TREE
19294 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
)
19296 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
19297 tree rszdecl
= szdecl
;
19298 HOST_WIDE_INT rsize
= 0;
19300 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
19301 if (!DECL_P (szdecl
))
19303 if (TREE_CODE (szdecl
) == INDIRECT_REF
19304 && DECL_P (TREE_OPERAND (szdecl
, 0)))
19306 rszdecl
= TREE_OPERAND (szdecl
, 0);
19307 rsize
= int_size_in_bytes (TREE_TYPE (rszdecl
));
19316 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2, NULL
);
19319 && current_function_decl
19320 && DECL_CONTEXT (rszdecl
) == current_function_decl
)
19322 dw_die_ref ref
= lookup_decl_die (rszdecl
);
19323 dw_loc_descr_ref l
= NULL
;
19326 l
= new_loc_descr (DW_OP_call4
, 0, 0);
19327 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
19328 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
19329 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
19331 else if (TREE_CODE (rszdecl
) == PARM_DECL
19334 l
= new_loc_descr (DW_OP_call4
, 0, 0);
19335 l
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
19336 l
->dw_loc_oprnd1
.v
.val_decl_ref
= rszdecl
;
19337 string_types
->safe_push (array_die
);
19339 if (l
&& rszdecl
!= szdecl
)
19341 if (rsize
== DWARF2_ADDR_SIZE
)
19342 add_loc_descr (&l
, new_loc_descr (DW_OP_deref
,
19345 add_loc_descr (&l
, new_loc_descr (DW_OP_deref_size
,
19349 loc
= new_loc_list (l
, NULL
, NULL
, NULL
);
19353 add_AT_location_description (array_die
, DW_AT_string_length
,
19355 if (size
!= DWARF2_ADDR_SIZE
)
19356 add_AT_unsigned (array_die
, dwarf_version
>= 5
19357 ? DW_AT_string_length_byte_size
19358 : DW_AT_byte_size
, size
);
19365 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
19366 add_name_attribute (array_die
, type_tag (type
));
19367 equate_type_number_to_die (type
, array_die
);
19369 if (TREE_CODE (type
) == VECTOR_TYPE
)
19370 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
19372 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
19374 && TREE_CODE (type
) == ARRAY_TYPE
19375 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
19376 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
19377 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
19380 /* We default the array ordering. SDB will probably do
19381 the right things even if DW_AT_ordering is not present. It's not even
19382 an issue until we start to get into multidimensional arrays anyway. If
19383 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
19384 then we'll have to put the DW_AT_ordering attribute back in. (But if
19385 and when we find out that we need to put these in, we will only do so
19386 for multidimensional arrays. */
19387 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
19390 if (TREE_CODE (type
) == VECTOR_TYPE
)
19392 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
19393 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
19394 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
, NULL
);
19395 add_bound_info (subrange_die
, DW_AT_upper_bound
,
19396 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1), NULL
);
19399 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
19401 /* Add representation of the type of the elements of this array type and
19402 emit the corresponding DIE if we haven't done it already. */
19403 element_type
= TREE_TYPE (type
);
19404 if (collapse_nested_arrays
)
19405 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
19407 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
19409 element_type
= TREE_TYPE (element_type
);
19412 add_type_attribute (array_die
, element_type
, TYPE_UNQUALIFIED
,
19413 TREE_CODE (type
) == ARRAY_TYPE
19414 && TYPE_REVERSE_STORAGE_ORDER (type
),
19417 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
19418 if (TYPE_ARTIFICIAL (type
))
19419 add_AT_flag (array_die
, DW_AT_artificial
, 1);
19421 if (get_AT (array_die
, DW_AT_name
))
19422 add_pubtype (type
, array_die
);
19425 /* After all arguments are created, adjust any DW_TAG_string_type
19426 DIEs DW_AT_string_length attributes. */
19429 adjust_string_types (void)
19431 dw_die_ref array_die
;
19433 FOR_EACH_VEC_ELT (*string_types
, i
, array_die
)
19435 dw_attr_node
*a
= get_AT (array_die
, DW_AT_string_length
);
19438 dw_loc_descr_ref loc
= AT_loc (a
);
19439 gcc_assert (loc
->dw_loc_opc
== DW_OP_call4
19440 && loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
);
19441 dw_die_ref ref
= lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
19444 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
19445 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
19446 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
19450 remove_AT (array_die
, DW_AT_string_length
);
19451 remove_AT (array_die
, dwarf_version
>= 5
19452 ? DW_AT_string_length_byte_size
19453 : DW_AT_byte_size
);
19458 /* This routine generates DIE for array with hidden descriptor, details
19459 are filled into *info by a langhook. */
19462 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
19463 dw_die_ref context_die
)
19465 const dw_die_ref scope_die
= scope_die_for (type
, context_die
);
19466 const dw_die_ref array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
19467 const struct loc_descr_context context
= { type
, info
->base_decl
, NULL
};
19470 add_name_attribute (array_die
, type_tag (type
));
19471 equate_type_number_to_die (type
, array_die
);
19473 if (info
->ndimensions
> 1)
19474 switch (info
->ordering
)
19476 case array_descr_ordering_row_major
:
19477 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
19479 case array_descr_ordering_column_major
:
19480 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
19486 if (dwarf_version
>= 3 || !dwarf_strict
)
19488 if (info
->data_location
)
19489 add_scalar_info (array_die
, DW_AT_data_location
, info
->data_location
,
19490 dw_scalar_form_exprloc
, &context
);
19491 if (info
->associated
)
19492 add_scalar_info (array_die
, DW_AT_associated
, info
->associated
,
19493 dw_scalar_form_constant
19494 | dw_scalar_form_exprloc
19495 | dw_scalar_form_reference
, &context
);
19496 if (info
->allocated
)
19497 add_scalar_info (array_die
, DW_AT_allocated
, info
->allocated
,
19498 dw_scalar_form_constant
19499 | dw_scalar_form_exprloc
19500 | dw_scalar_form_reference
, &context
);
19503 const enum dwarf_attribute attr
19504 = (info
->stride_in_bits
) ? DW_AT_bit_stride
: DW_AT_byte_stride
;
19506 = (info
->stride_in_bits
)
19507 ? dw_scalar_form_constant
19508 : (dw_scalar_form_constant
19509 | dw_scalar_form_exprloc
19510 | dw_scalar_form_reference
);
19512 add_scalar_info (array_die
, attr
, info
->stride
, forms
, &context
);
19516 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
19518 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
19520 dw_die_ref subrange_die
19521 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
19523 if (info
->dimen
[dim
].bounds_type
)
19524 add_type_attribute (subrange_die
,
19525 info
->dimen
[dim
].bounds_type
, TYPE_UNQUALIFIED
,
19526 false, context_die
);
19527 if (info
->dimen
[dim
].lower_bound
)
19528 add_bound_info (subrange_die
, DW_AT_lower_bound
,
19529 info
->dimen
[dim
].lower_bound
, &context
);
19530 if (info
->dimen
[dim
].upper_bound
)
19531 add_bound_info (subrange_die
, DW_AT_upper_bound
,
19532 info
->dimen
[dim
].upper_bound
, &context
);
19533 if ((dwarf_version
>= 3 || !dwarf_strict
) && info
->dimen
[dim
].stride
)
19534 add_scalar_info (subrange_die
, DW_AT_byte_stride
,
19535 info
->dimen
[dim
].stride
,
19536 dw_scalar_form_constant
19537 | dw_scalar_form_exprloc
19538 | dw_scalar_form_reference
,
19542 gen_type_die (info
->element_type
, context_die
);
19543 add_type_attribute (array_die
, info
->element_type
, TYPE_UNQUALIFIED
,
19544 TREE_CODE (type
) == ARRAY_TYPE
19545 && TYPE_REVERSE_STORAGE_ORDER (type
),
19548 if (get_AT (array_die
, DW_AT_name
))
19549 add_pubtype (type
, array_die
);
19554 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
19556 tree origin
= decl_ultimate_origin (decl
);
19557 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
19559 if (origin
!= NULL
)
19560 add_abstract_origin_attribute (decl_die
, origin
);
19563 add_name_and_src_coords_attributes (decl_die
, decl
);
19564 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
19565 TYPE_UNQUALIFIED
, false, context_die
);
19568 if (DECL_ABSTRACT_P (decl
))
19569 equate_decl_number_to_die (decl
, decl_die
);
19571 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
19575 /* Walk through the list of incomplete types again, trying once more to
19576 emit full debugging info for them. */
19579 retry_incomplete_types (void)
19584 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
19585 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
19586 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
19587 vec_safe_truncate (incomplete_types
, 0);
19590 /* Determine what tag to use for a record type. */
19592 static enum dwarf_tag
19593 record_type_tag (tree type
)
19595 if (! lang_hooks
.types
.classify_record
)
19596 return DW_TAG_structure_type
;
19598 switch (lang_hooks
.types
.classify_record (type
))
19600 case RECORD_IS_STRUCT
:
19601 return DW_TAG_structure_type
;
19603 case RECORD_IS_CLASS
:
19604 return DW_TAG_class_type
;
19606 case RECORD_IS_INTERFACE
:
19607 if (dwarf_version
>= 3 || !dwarf_strict
)
19608 return DW_TAG_interface_type
;
19609 return DW_TAG_structure_type
;
19612 gcc_unreachable ();
19616 /* Generate a DIE to represent an enumeration type. Note that these DIEs
19617 include all of the information about the enumeration values also. Each
19618 enumerated type name/value is listed as a child of the enumerated type
19622 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
19624 dw_die_ref type_die
= lookup_type_die (type
);
19626 if (type_die
== NULL
)
19628 type_die
= new_die (DW_TAG_enumeration_type
,
19629 scope_die_for (type
, context_die
), type
);
19630 equate_type_number_to_die (type
, type_die
);
19631 add_name_attribute (type_die
, type_tag (type
));
19632 if (dwarf_version
>= 4 || !dwarf_strict
)
19634 if (ENUM_IS_SCOPED (type
))
19635 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
19636 if (ENUM_IS_OPAQUE (type
))
19637 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19640 else if (! TYPE_SIZE (type
))
19643 remove_AT (type_die
, DW_AT_declaration
);
19645 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
19646 given enum type is incomplete, do not generate the DW_AT_byte_size
19647 attribute or the DW_AT_element_list attribute. */
19648 if (TYPE_SIZE (type
))
19652 TREE_ASM_WRITTEN (type
) = 1;
19653 add_byte_size_attribute (type_die
, type
);
19654 if (dwarf_version
>= 3 || !dwarf_strict
)
19656 tree underlying
= lang_hooks
.types
.enum_underlying_base_type (type
);
19657 add_type_attribute (type_die
, underlying
, TYPE_UNQUALIFIED
, false,
19660 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
19662 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
19663 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
19666 /* If the first reference to this type was as the return type of an
19667 inline function, then it may not have a parent. Fix this now. */
19668 if (type_die
->die_parent
== NULL
)
19669 add_child_die (scope_die_for (type
, context_die
), type_die
);
19671 for (link
= TYPE_VALUES (type
);
19672 link
!= NULL
; link
= TREE_CHAIN (link
))
19674 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
19675 tree value
= TREE_VALUE (link
);
19677 add_name_attribute (enum_die
,
19678 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
19680 if (TREE_CODE (value
) == CONST_DECL
)
19681 value
= DECL_INITIAL (value
);
19683 if (simple_type_size_in_bits (TREE_TYPE (value
))
19684 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
19686 /* For constant forms created by add_AT_unsigned DWARF
19687 consumers (GDB, elfutils, etc.) always zero extend
19688 the value. Only when the actual value is negative
19689 do we need to use add_AT_int to generate a constant
19690 form that can represent negative values. */
19691 HOST_WIDE_INT val
= TREE_INT_CST_LOW (value
);
19692 if (TYPE_UNSIGNED (TREE_TYPE (value
)) || val
>= 0)
19693 add_AT_unsigned (enum_die
, DW_AT_const_value
,
19694 (unsigned HOST_WIDE_INT
) val
);
19696 add_AT_int (enum_die
, DW_AT_const_value
, val
);
19699 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
19700 that here. TODO: This should be re-worked to use correct
19701 signed/unsigned double tags for all cases. */
19702 add_AT_wide (enum_die
, DW_AT_const_value
, value
);
19705 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
19706 if (TYPE_ARTIFICIAL (type
))
19707 add_AT_flag (type_die
, DW_AT_artificial
, 1);
19710 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19712 add_pubtype (type
, type_die
);
19717 /* Generate a DIE to represent either a real live formal parameter decl or to
19718 represent just the type of some formal parameter position in some function
19721 Note that this routine is a bit unusual because its argument may be a
19722 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
19723 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
19724 node. If it's the former then this function is being called to output a
19725 DIE to represent a formal parameter object (or some inlining thereof). If
19726 it's the latter, then this function is only being called to output a
19727 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
19728 argument type of some subprogram type.
19729 If EMIT_NAME_P is true, name and source coordinate attributes
19733 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
19734 dw_die_ref context_die
)
19736 tree node_or_origin
= node
? node
: origin
;
19737 tree ultimate_origin
;
19738 dw_die_ref parm_die
= NULL
;
19740 if (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)) == tcc_declaration
)
19742 parm_die
= lookup_decl_die (node
);
19744 /* If the contexts differ, we may not be talking about the same
19746 if (parm_die
&& parm_die
->die_parent
!= context_die
)
19748 if (!DECL_ABSTRACT_P (node
))
19750 /* This can happen when creating an inlined instance, in
19751 which case we need to create a new DIE that will get
19752 annotated with DW_AT_abstract_origin. */
19757 /* FIXME: Reuse DIE even with a differing context.
19759 This can happen when calling
19760 dwarf2out_abstract_function to build debug info for
19761 the abstract instance of a function for which we have
19762 already generated a DIE in
19763 dwarf2out_early_global_decl.
19765 Once we remove dwarf2out_abstract_function, we should
19766 have a call to gcc_unreachable here. */
19770 if (parm_die
&& parm_die
->die_parent
== NULL
)
19772 /* Check that parm_die already has the right attributes that
19773 we would have added below. If any attributes are
19774 missing, fall through to add them. */
19775 if (! DECL_ABSTRACT_P (node_or_origin
)
19776 && !get_AT (parm_die
, DW_AT_location
)
19777 && !get_AT (parm_die
, DW_AT_const_value
))
19778 /* We are missing location info, and are about to add it. */
19782 add_child_die (context_die
, parm_die
);
19788 /* If we have a previously generated DIE, use it, unless this is an
19789 concrete instance (origin != NULL), in which case we need a new
19790 DIE with a corresponding DW_AT_abstract_origin. */
19792 if (parm_die
&& origin
== NULL
)
19793 reusing_die
= true;
19796 parm_die
= new_die (DW_TAG_formal_parameter
, context_die
, node
);
19797 reusing_die
= false;
19800 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
19802 case tcc_declaration
:
19803 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
19804 if (node
|| ultimate_origin
)
19805 origin
= ultimate_origin
;
19810 if (origin
!= NULL
)
19811 add_abstract_origin_attribute (parm_die
, origin
);
19812 else if (emit_name_p
)
19813 add_name_and_src_coords_attributes (parm_die
, node
);
19815 || (! DECL_ABSTRACT_P (node_or_origin
)
19816 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
19817 decl_function_context
19818 (node_or_origin
))))
19820 tree type
= TREE_TYPE (node_or_origin
);
19821 if (decl_by_reference_p (node_or_origin
))
19822 add_type_attribute (parm_die
, TREE_TYPE (type
),
19824 false, context_die
);
19826 add_type_attribute (parm_die
, type
,
19827 decl_quals (node_or_origin
),
19828 false, context_die
);
19830 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
19831 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
19833 if (node
&& node
!= origin
)
19834 equate_decl_number_to_die (node
, parm_die
);
19835 if (! DECL_ABSTRACT_P (node_or_origin
))
19836 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
19842 /* We were called with some kind of a ..._TYPE node. */
19843 add_type_attribute (parm_die
, node_or_origin
, TYPE_UNQUALIFIED
, false,
19848 gcc_unreachable ();
19854 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
19855 children DW_TAG_formal_parameter DIEs representing the arguments of the
19858 PARM_PACK must be a function parameter pack.
19859 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
19860 must point to the subsequent arguments of the function PACK_ARG belongs to.
19861 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
19862 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
19863 following the last one for which a DIE was generated. */
19866 gen_formal_parameter_pack_die (tree parm_pack
,
19868 dw_die_ref subr_die
,
19872 dw_die_ref parm_pack_die
;
19874 gcc_assert (parm_pack
19875 && lang_hooks
.function_parameter_pack_p (parm_pack
)
19878 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
19879 add_src_coords_attributes (parm_pack_die
, parm_pack
);
19881 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
19883 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
19886 gen_formal_parameter_die (arg
, NULL
,
19887 false /* Don't emit name attribute. */,
19892 return parm_pack_die
;
19895 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
19896 at the end of an (ANSI prototyped) formal parameters list. */
19899 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
19901 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
19904 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
19905 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
19906 parameters as specified in some function type specification (except for
19907 those which appear as part of a function *definition*). */
19910 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
19913 tree formal_type
= NULL
;
19914 tree first_parm_type
;
19917 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
19919 arg
= DECL_ARGUMENTS (function_or_method_type
);
19920 function_or_method_type
= TREE_TYPE (function_or_method_type
);
19925 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
19927 /* Make our first pass over the list of formal parameter types and output a
19928 DW_TAG_formal_parameter DIE for each one. */
19929 for (link
= first_parm_type
; link
; )
19931 dw_die_ref parm_die
;
19933 formal_type
= TREE_VALUE (link
);
19934 if (formal_type
== void_type_node
)
19937 /* Output a (nameless) DIE to represent the formal parameter itself. */
19938 if (!POINTER_BOUNDS_TYPE_P (formal_type
))
19940 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
19941 true /* Emit name attribute. */,
19943 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
19944 && link
== first_parm_type
)
19946 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
19947 if (dwarf_version
>= 3 || !dwarf_strict
)
19948 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
19950 else if (arg
&& DECL_ARTIFICIAL (arg
))
19951 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
19954 link
= TREE_CHAIN (link
);
19956 arg
= DECL_CHAIN (arg
);
19959 /* If this function type has an ellipsis, add a
19960 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
19961 if (formal_type
!= void_type_node
)
19962 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
19964 /* Make our second (and final) pass over the list of formal parameter types
19965 and output DIEs to represent those types (as necessary). */
19966 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
19967 link
&& TREE_VALUE (link
);
19968 link
= TREE_CHAIN (link
))
19969 gen_type_die (TREE_VALUE (link
), context_die
);
19972 /* We want to generate the DIE for TYPE so that we can generate the
19973 die for MEMBER, which has been defined; we will need to refer back
19974 to the member declaration nested within TYPE. If we're trying to
19975 generate minimal debug info for TYPE, processing TYPE won't do the
19976 trick; we need to attach the member declaration by hand. */
19979 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
19981 gen_type_die (type
, context_die
);
19983 /* If we're trying to avoid duplicate debug info, we may not have
19984 emitted the member decl for this function. Emit it now. */
19985 if (TYPE_STUB_DECL (type
)
19986 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
19987 && ! lookup_decl_die (member
))
19989 dw_die_ref type_die
;
19990 gcc_assert (!decl_ultimate_origin (member
));
19992 push_decl_scope (type
);
19993 type_die
= lookup_type_die_strip_naming_typedef (type
);
19994 if (TREE_CODE (member
) == FUNCTION_DECL
)
19995 gen_subprogram_die (member
, type_die
);
19996 else if (TREE_CODE (member
) == FIELD_DECL
)
19998 /* Ignore the nameless fields that are used to skip bits but handle
19999 C++ anonymous unions and structs. */
20000 if (DECL_NAME (member
) != NULL_TREE
20001 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
20002 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
20004 struct vlr_context vlr_ctx
= {
20005 DECL_CONTEXT (member
), /* struct_type */
20006 NULL_TREE
/* variant_part_offset */
20008 gen_type_die (member_declared_type (member
), type_die
);
20009 gen_field_die (member
, &vlr_ctx
, type_die
);
20013 gen_variable_die (member
, NULL_TREE
, type_die
);
20019 /* Forward declare these functions, because they are mutually recursive
20020 with their set_block_* pairing functions. */
20021 static void set_decl_origin_self (tree
);
20022 static void set_decl_abstract_flags (tree
, vec
<tree
> &);
20024 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
20025 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
20026 that it points to the node itself, thus indicating that the node is its
20027 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
20028 the given node is NULL, recursively descend the decl/block tree which
20029 it is the root of, and for each other ..._DECL or BLOCK node contained
20030 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
20031 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
20032 values to point to themselves. */
20035 set_block_origin_self (tree stmt
)
20037 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
20039 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
20044 for (local_decl
= BLOCK_VARS (stmt
);
20045 local_decl
!= NULL_TREE
;
20046 local_decl
= DECL_CHAIN (local_decl
))
20047 /* Do not recurse on nested functions since the inlining status
20048 of parent and child can be different as per the DWARF spec. */
20049 if (TREE_CODE (local_decl
) != FUNCTION_DECL
20050 && !DECL_EXTERNAL (local_decl
))
20051 set_decl_origin_self (local_decl
);
20057 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
20058 subblock
!= NULL_TREE
;
20059 subblock
= BLOCK_CHAIN (subblock
))
20060 set_block_origin_self (subblock
); /* Recurse. */
20065 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
20066 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
20067 node to so that it points to the node itself, thus indicating that the
20068 node represents its own (abstract) origin. Additionally, if the
20069 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
20070 the decl/block tree of which the given node is the root of, and for
20071 each other ..._DECL or BLOCK node contained therein whose
20072 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
20073 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
20074 point to themselves. */
20077 set_decl_origin_self (tree decl
)
20079 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
20081 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
20082 if (TREE_CODE (decl
) == FUNCTION_DECL
)
20086 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
20087 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
20088 if (DECL_INITIAL (decl
) != NULL_TREE
20089 && DECL_INITIAL (decl
) != error_mark_node
)
20090 set_block_origin_self (DECL_INITIAL (decl
));
20095 /* Given a pointer to some BLOCK node, set the BLOCK_ABSTRACT flag to 1
20096 and if it wasn't 1 before, push it to abstract_vec vector.
20097 For all local decls and all local sub-blocks (recursively) do it
20101 set_block_abstract_flags (tree stmt
, vec
<tree
> &abstract_vec
)
20107 if (!BLOCK_ABSTRACT (stmt
))
20109 abstract_vec
.safe_push (stmt
);
20110 BLOCK_ABSTRACT (stmt
) = 1;
20113 for (local_decl
= BLOCK_VARS (stmt
);
20114 local_decl
!= NULL_TREE
;
20115 local_decl
= DECL_CHAIN (local_decl
))
20116 if (! DECL_EXTERNAL (local_decl
))
20117 set_decl_abstract_flags (local_decl
, abstract_vec
);
20119 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
20121 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
20122 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
20123 || TREE_CODE (local_decl
) == PARM_DECL
)
20124 set_decl_abstract_flags (local_decl
, abstract_vec
);
20127 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
20128 subblock
!= NULL_TREE
;
20129 subblock
= BLOCK_CHAIN (subblock
))
20130 set_block_abstract_flags (subblock
, abstract_vec
);
20133 /* Given a pointer to some ..._DECL node, set DECL_ABSTRACT_P flag on it
20134 to 1 and if it wasn't 1 before, push to abstract_vec vector.
20135 In the case where the decl is a FUNCTION_DECL also set the abstract
20136 flags for all of the parameters, local vars, local
20137 blocks and sub-blocks (recursively). */
20140 set_decl_abstract_flags (tree decl
, vec
<tree
> &abstract_vec
)
20142 if (!DECL_ABSTRACT_P (decl
))
20144 abstract_vec
.safe_push (decl
);
20145 DECL_ABSTRACT_P (decl
) = 1;
20148 if (TREE_CODE (decl
) == FUNCTION_DECL
)
20152 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
20153 if (!DECL_ABSTRACT_P (arg
))
20155 abstract_vec
.safe_push (arg
);
20156 DECL_ABSTRACT_P (arg
) = 1;
20158 if (DECL_INITIAL (decl
) != NULL_TREE
20159 && DECL_INITIAL (decl
) != error_mark_node
)
20160 set_block_abstract_flags (DECL_INITIAL (decl
), abstract_vec
);
20164 /* Generate the DWARF2 info for the "abstract" instance of a function which we
20165 may later generate inlined and/or out-of-line instances of.
20167 FIXME: In the early-dwarf world, this function, and most of the
20168 DECL_ABSTRACT code should be obsoleted. The early DIE _is_
20169 the abstract instance. All we would need to do is annotate
20170 the early DIE with the appropriate DW_AT_inline in late
20171 dwarf (perhaps in gen_inlined_subroutine_die).
20173 However, we can't do this yet, because LTO streaming of DIEs
20174 has not been implemented yet. */
20177 dwarf2out_abstract_function (tree decl
)
20179 dw_die_ref old_die
;
20182 hash_table
<decl_loc_hasher
> *old_decl_loc_table
;
20183 hash_table
<dw_loc_list_hasher
> *old_cached_dw_loc_list_table
;
20184 int old_call_site_count
, old_tail_call_site_count
;
20185 struct call_arg_loc_node
*old_call_arg_locations
;
20187 /* Make sure we have the actual abstract inline, not a clone. */
20188 decl
= DECL_ORIGIN (decl
);
20190 old_die
= lookup_decl_die (decl
);
20191 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
20192 /* We've already generated the abstract instance. */
20195 /* We can be called while recursively when seeing block defining inlined subroutine
20196 DIE. Be sure to not clobber the outer location table nor use it or we would
20197 get locations in abstract instantces. */
20198 old_decl_loc_table
= decl_loc_table
;
20199 decl_loc_table
= NULL
;
20200 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
20201 cached_dw_loc_list_table
= NULL
;
20202 old_call_arg_locations
= call_arg_locations
;
20203 call_arg_locations
= NULL
;
20204 old_call_site_count
= call_site_count
;
20205 call_site_count
= -1;
20206 old_tail_call_site_count
= tail_call_site_count
;
20207 tail_call_site_count
= -1;
20209 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
20210 we don't get confused by DECL_ABSTRACT_P. */
20211 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20213 context
= decl_class_context (decl
);
20215 gen_type_die_for_member
20216 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
20219 /* Pretend we've just finished compiling this function. */
20220 save_fn
= current_function_decl
;
20221 current_function_decl
= decl
;
20223 auto_vec
<tree
, 64> abstract_vec
;
20224 set_decl_abstract_flags (decl
, abstract_vec
);
20225 dwarf2out_decl (decl
);
20228 FOR_EACH_VEC_ELT (abstract_vec
, i
, t
)
20229 if (TREE_CODE (t
) == BLOCK
)
20230 BLOCK_ABSTRACT (t
) = 0;
20232 DECL_ABSTRACT_P (t
) = 0;
20234 current_function_decl
= save_fn
;
20235 decl_loc_table
= old_decl_loc_table
;
20236 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
20237 call_arg_locations
= old_call_arg_locations
;
20238 call_site_count
= old_call_site_count
;
20239 tail_call_site_count
= old_tail_call_site_count
;
20242 /* Helper function of premark_used_types() which gets called through
20245 Marks the DIE of a given type in *SLOT as perennial, so it never gets
20246 marked as unused by prune_unused_types. */
20249 premark_used_types_helper (tree
const &type
, void *)
20253 die
= lookup_type_die (type
);
20255 die
->die_perennial_p
= 1;
20259 /* Helper function of premark_types_used_by_global_vars which gets called
20260 through htab_traverse.
20262 Marks the DIE of a given type in *SLOT as perennial, so it never gets
20263 marked as unused by prune_unused_types. The DIE of the type is marked
20264 only if the global variable using the type will actually be emitted. */
20267 premark_types_used_by_global_vars_helper (types_used_by_vars_entry
**slot
,
20270 struct types_used_by_vars_entry
*entry
;
20273 entry
= (struct types_used_by_vars_entry
*) *slot
;
20274 gcc_assert (entry
->type
!= NULL
20275 && entry
->var_decl
!= NULL
);
20276 die
= lookup_type_die (entry
->type
);
20279 /* Ask cgraph if the global variable really is to be emitted.
20280 If yes, then we'll keep the DIE of ENTRY->TYPE. */
20281 varpool_node
*node
= varpool_node::get (entry
->var_decl
);
20282 if (node
&& node
->definition
)
20284 die
->die_perennial_p
= 1;
20285 /* Keep the parent DIEs as well. */
20286 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
20287 die
->die_perennial_p
= 1;
20293 /* Mark all members of used_types_hash as perennial. */
20296 premark_used_types (struct function
*fun
)
20298 if (fun
&& fun
->used_types_hash
)
20299 fun
->used_types_hash
->traverse
<void *, premark_used_types_helper
> (NULL
);
20302 /* Mark all members of types_used_by_vars_entry as perennial. */
20305 premark_types_used_by_global_vars (void)
20307 if (types_used_by_vars_hash
)
20308 types_used_by_vars_hash
20309 ->traverse
<void *, premark_types_used_by_global_vars_helper
> (NULL
);
20312 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
20313 for CA_LOC call arg loc node. */
20316 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
20317 struct call_arg_loc_node
*ca_loc
)
20319 dw_die_ref stmt_die
= NULL
, die
;
20320 tree block
= ca_loc
->block
;
20323 && block
!= DECL_INITIAL (decl
)
20324 && TREE_CODE (block
) == BLOCK
)
20326 stmt_die
= BLOCK_DIE (block
);
20329 block
= BLOCK_SUPERCONTEXT (block
);
20331 if (stmt_die
== NULL
)
20332 stmt_die
= subr_die
;
20333 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
20334 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
20335 if (ca_loc
->tail_call_p
)
20336 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
20337 if (ca_loc
->symbol_ref
)
20339 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
20341 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
20343 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
20348 /* Generate a DIE to represent a declared function (either file-scope or
20352 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
20354 tree origin
= decl_ultimate_origin (decl
);
20355 dw_die_ref subr_die
;
20356 dw_die_ref old_die
= lookup_decl_die (decl
);
20358 /* This function gets called multiple times for different stages of
20359 the debug process. For example, for func() in this code:
20363 void func() { ... }
20366 ...we get called 4 times. Twice in early debug and twice in
20372 1. Once while generating func() within the namespace. This is
20373 the declaration. The declaration bit below is set, as the
20374 context is the namespace.
20376 A new DIE will be generated with DW_AT_declaration set.
20378 2. Once for func() itself. This is the specification. The
20379 declaration bit below is clear as the context is the CU.
20381 We will use the cached DIE from (1) to create a new DIE with
20382 DW_AT_specification pointing to the declaration in (1).
20384 Late debug via rest_of_handle_final()
20385 -------------------------------------
20387 3. Once generating func() within the namespace. This is also the
20388 declaration, as in (1), but this time we will early exit below
20389 as we have a cached DIE and a declaration needs no additional
20390 annotations (no locations), as the source declaration line
20393 4. Once for func() itself. As in (2), this is the specification,
20394 but this time we will re-use the cached DIE, and just annotate
20395 it with the location information that should now be available.
20397 For something without namespaces, but with abstract instances, we
20398 are also called a multiple times:
20403 Base (); // constructor declaration (1)
20406 Base::Base () { } // constructor specification (2)
20411 1. Once for the Base() constructor by virtue of it being a
20412 member of the Base class. This is done via
20413 rest_of_type_compilation.
20415 This is a declaration, so a new DIE will be created with
20418 2. Once for the Base() constructor definition, but this time
20419 while generating the abstract instance of the base
20420 constructor (__base_ctor) which is being generated via early
20421 debug of reachable functions.
20423 Even though we have a cached version of the declaration (1),
20424 we will create a DW_AT_specification of the declaration DIE
20427 3. Once for the __base_ctor itself, but this time, we generate
20428 an DW_AT_abstract_origin version of the DW_AT_specification in
20431 Late debug via rest_of_handle_final
20432 -----------------------------------
20434 4. One final time for the __base_ctor (which will have a cached
20435 DIE with DW_AT_abstract_origin created in (3). This time,
20436 we will just annotate the location information now
20439 int declaration
= (current_function_decl
!= decl
20440 || class_or_namespace_scope_p (context_die
));
20442 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
20444 /* Now that the C++ front end lazily declares artificial member fns, we
20445 might need to retrofit the declaration into its class. */
20446 if (!declaration
&& !origin
&& !old_die
20447 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
20448 && !class_or_namespace_scope_p (context_die
)
20449 && debug_info_level
> DINFO_LEVEL_TERSE
)
20450 old_die
= force_decl_die (decl
);
20452 /* An inlined instance, tag a new DIE with DW_AT_abstract_origin. */
20453 if (origin
!= NULL
)
20455 gcc_assert (!declaration
|| local_scope_p (context_die
));
20457 /* Fixup die_parent for the abstract instance of a nested
20458 inline function. */
20459 if (old_die
&& old_die
->die_parent
== NULL
)
20460 add_child_die (context_die
, old_die
);
20462 if (old_die
&& get_AT_ref (old_die
, DW_AT_abstract_origin
))
20464 /* If we have a DW_AT_abstract_origin we have a working
20466 subr_die
= old_die
;
20470 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
20471 add_abstract_origin_attribute (subr_die
, origin
);
20472 /* This is where the actual code for a cloned function is.
20473 Let's emit linkage name attribute for it. This helps
20474 debuggers to e.g, set breakpoints into
20475 constructors/destructors when the user asks "break
20477 add_linkage_name (subr_die
, decl
);
20480 /* A cached copy, possibly from early dwarf generation. Reuse as
20481 much as possible. */
20484 /* A declaration that has been previously dumped needs no
20485 additional information. */
20489 if (!get_AT_flag (old_die
, DW_AT_declaration
)
20490 /* We can have a normal definition following an inline one in the
20491 case of redefinition of GNU C extern inlines.
20492 It seems reasonable to use AT_specification in this case. */
20493 && !get_AT (old_die
, DW_AT_inline
))
20495 /* Detect and ignore this case, where we are trying to output
20496 something we have already output. */
20497 if (get_AT (old_die
, DW_AT_low_pc
)
20498 || get_AT (old_die
, DW_AT_ranges
))
20501 /* If we have no location information, this must be a
20502 partially generated DIE from early dwarf generation.
20503 Fall through and generate it. */
20506 /* If the definition comes from the same place as the declaration,
20507 maybe use the old DIE. We always want the DIE for this function
20508 that has the *_pc attributes to be under comp_unit_die so the
20509 debugger can find it. We also need to do this for abstract
20510 instances of inlines, since the spec requires the out-of-line copy
20511 to have the same parent. For local class methods, this doesn't
20512 apply; we just use the old DIE. */
20513 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
20514 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
20515 if ((is_cu_die (old_die
->die_parent
)
20516 /* This condition fixes the inconsistency/ICE with the
20517 following Fortran test (or some derivative thereof) while
20518 building libgfortran:
20522 logical function funky (FLAG)
20527 || (old_die
->die_parent
20528 && old_die
->die_parent
->die_tag
== DW_TAG_module
)
20529 || context_die
== NULL
)
20530 && (DECL_ARTIFICIAL (decl
)
20531 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
20532 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
20533 == (unsigned) s
.line
))))
20535 subr_die
= old_die
;
20537 /* Clear out the declaration attribute, but leave the
20538 parameters so they can be augmented with location
20539 information later. Unless this was a declaration, in
20540 which case, wipe out the nameless parameters and recreate
20541 them further down. */
20542 if (remove_AT (subr_die
, DW_AT_declaration
))
20545 remove_AT (subr_die
, DW_AT_object_pointer
);
20546 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
20549 /* Make a specification pointing to the previously built
20553 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
20554 add_AT_specification (subr_die
, old_die
);
20555 add_pubname (decl
, subr_die
);
20556 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
20557 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
20558 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
20559 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
20561 /* If the prototype had an 'auto' or 'decltype(auto)' return type,
20562 emit the real type on the definition die. */
20563 if (is_cxx() && debug_info_level
> DINFO_LEVEL_TERSE
)
20565 dw_die_ref die
= get_AT_ref (old_die
, DW_AT_type
);
20566 if (die
== auto_die
|| die
== decltype_auto_die
)
20567 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
20568 TYPE_UNQUALIFIED
, false, context_die
);
20571 /* When we process the method declaration, we haven't seen
20572 the out-of-class defaulted definition yet, so we have to
20574 int defaulted
= lang_hooks
.decls
.function_decl_defaulted (decl
);
20575 if (defaulted
&& (dwarf_version
>= 5 || ! dwarf_strict
)
20576 && !get_AT (subr_die
, DW_AT_defaulted
))
20580 add_AT_unsigned (subr_die
, DW_AT_defaulted
,
20581 DW_DEFAULTED_out_of_class
);
20584 case 1: /* This must have been handled before. */
20586 gcc_unreachable ();
20590 /* Create a fresh DIE for anything else. */
20593 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
20595 if (TREE_PUBLIC (decl
))
20596 add_AT_flag (subr_die
, DW_AT_external
, 1);
20598 add_name_and_src_coords_attributes (subr_die
, decl
);
20599 add_pubname (decl
, subr_die
);
20600 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20602 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
20603 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
20604 TYPE_UNQUALIFIED
, false, context_die
);
20607 add_pure_or_virtual_attribute (subr_die
, decl
);
20608 if (DECL_ARTIFICIAL (decl
))
20609 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
20611 if (TREE_THIS_VOLATILE (decl
) && (dwarf_version
>= 5 || !dwarf_strict
))
20612 add_AT_flag (subr_die
, DW_AT_noreturn
, 1);
20614 add_accessibility_attribute (subr_die
, decl
);
20617 /* Unless we have an existing non-declaration DIE, equate the new
20619 if (!old_die
|| is_declaration_die (old_die
))
20620 equate_decl_number_to_die (decl
, subr_die
);
20624 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
20626 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
20628 /* If this is an explicit function declaration then generate
20629 a DW_AT_explicit attribute. */
20630 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
20631 && (dwarf_version
>= 3 || !dwarf_strict
))
20632 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
20634 /* If this is a C++11 deleted special function member then generate
20635 a DW_AT_deleted attribute. */
20636 if (lang_hooks
.decls
.function_decl_deleted_p (decl
)
20637 && (dwarf_version
>= 5 || ! dwarf_strict
))
20638 add_AT_flag (subr_die
, DW_AT_deleted
, 1);
20640 /* If this is a C++11 defaulted special function member then
20641 generate a DW_AT_GNU_defaulted attribute. */
20642 int defaulted
= lang_hooks
.decls
.function_decl_defaulted (decl
);
20643 if (defaulted
&& (dwarf_version
>= 5 || ! dwarf_strict
))
20647 add_AT_unsigned (subr_die
, DW_AT_defaulted
,
20648 DW_DEFAULTED_in_class
);
20651 /* It is likely that this will never hit, since we
20652 don't have the out-of-class definition yet when we
20653 process the class definition and the method
20654 declaration. We recheck elsewhere, but leave it
20655 here just in case. */
20657 add_AT_unsigned (subr_die
, DW_AT_defaulted
,
20658 DW_DEFAULTED_out_of_class
);
20662 gcc_unreachable ();
20666 /* Tag abstract instances with DW_AT_inline. */
20667 else if (DECL_ABSTRACT_P (decl
))
20669 if (DECL_DECLARED_INLINE_P (decl
))
20671 if (cgraph_function_possibly_inlined_p (decl
))
20672 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
20674 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
20678 if (cgraph_function_possibly_inlined_p (decl
))
20679 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
20681 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
20684 if (DECL_DECLARED_INLINE_P (decl
)
20685 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
20686 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
20688 /* For non DECL_EXTERNALs, if range information is available, fill
20689 the DIE with it. */
20690 else if (!DECL_EXTERNAL (decl
) && !early_dwarf
)
20692 HOST_WIDE_INT cfa_fb_offset
;
20694 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
20696 if (!flag_reorder_blocks_and_partition
)
20698 dw_fde_ref fde
= fun
->fde
;
20699 if (fde
->dw_fde_begin
)
20701 /* We have already generated the labels. */
20702 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
20703 fde
->dw_fde_end
, false);
20707 /* Create start/end labels and add the range. */
20708 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
20709 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
20710 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
20711 current_function_funcdef_no
);
20712 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
20713 current_function_funcdef_no
);
20714 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
20718 #if VMS_DEBUGGING_INFO
20719 /* HP OpenVMS Industry Standard 64: DWARF Extensions
20720 Section 2.3 Prologue and Epilogue Attributes:
20721 When a breakpoint is set on entry to a function, it is generally
20722 desirable for execution to be suspended, not on the very first
20723 instruction of the function, but rather at a point after the
20724 function's frame has been set up, after any language defined local
20725 declaration processing has been completed, and before execution of
20726 the first statement of the function begins. Debuggers generally
20727 cannot properly determine where this point is. Similarly for a
20728 breakpoint set on exit from a function. The prologue and epilogue
20729 attributes allow a compiler to communicate the location(s) to use. */
20732 if (fde
->dw_fde_vms_end_prologue
)
20733 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
20734 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
20736 if (fde
->dw_fde_vms_begin_epilogue
)
20737 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
20738 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
20745 /* Generate pubnames entries for the split function code ranges. */
20746 dw_fde_ref fde
= fun
->fde
;
20748 if (fde
->dw_fde_second_begin
)
20750 if (dwarf_version
>= 3 || !dwarf_strict
)
20752 /* We should use ranges for non-contiguous code section
20753 addresses. Use the actual code range for the initial
20754 section, since the HOT/COLD labels might precede an
20755 alignment offset. */
20756 bool range_list_added
= false;
20757 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
20758 fde
->dw_fde_end
, &range_list_added
,
20760 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
20761 fde
->dw_fde_second_end
,
20762 &range_list_added
, false);
20763 if (range_list_added
)
20768 /* There is no real support in DW2 for this .. so we make
20769 a work-around. First, emit the pub name for the segment
20770 containing the function label. Then make and emit a
20771 simplified subprogram DIE for the second segment with the
20772 name pre-fixed by __hot/cold_sect_of_. We use the same
20773 linkage name for the second die so that gdb will find both
20774 sections when given "b foo". */
20775 const char *name
= NULL
;
20776 tree decl_name
= DECL_NAME (decl
);
20777 dw_die_ref seg_die
;
20779 /* Do the 'primary' section. */
20780 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
20781 fde
->dw_fde_end
, false);
20783 /* Build a minimal DIE for the secondary section. */
20784 seg_die
= new_die (DW_TAG_subprogram
,
20785 subr_die
->die_parent
, decl
);
20787 if (TREE_PUBLIC (decl
))
20788 add_AT_flag (seg_die
, DW_AT_external
, 1);
20790 if (decl_name
!= NULL
20791 && IDENTIFIER_POINTER (decl_name
) != NULL
)
20793 name
= dwarf2_name (decl
, 1);
20794 if (! DECL_ARTIFICIAL (decl
))
20795 add_src_coords_attributes (seg_die
, decl
);
20797 add_linkage_name (seg_die
, decl
);
20799 gcc_assert (name
!= NULL
);
20800 add_pure_or_virtual_attribute (seg_die
, decl
);
20801 if (DECL_ARTIFICIAL (decl
))
20802 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
20804 name
= concat ("__second_sect_of_", name
, NULL
);
20805 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
20806 fde
->dw_fde_second_end
, false);
20807 add_name_attribute (seg_die
, name
);
20808 if (want_pubnames ())
20809 add_pubname_string (name
, seg_die
);
20813 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
20817 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
20819 /* We define the "frame base" as the function's CFA. This is more
20820 convenient for several reasons: (1) It's stable across the prologue
20821 and epilogue, which makes it better than just a frame pointer,
20822 (2) With dwarf3, there exists a one-byte encoding that allows us
20823 to reference the .debug_frame data by proxy, but failing that,
20824 (3) We can at least reuse the code inspection and interpretation
20825 code that determines the CFA position at various points in the
20827 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
20829 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
20830 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
20834 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
20835 if (list
->dw_loc_next
)
20836 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
20838 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
20841 /* Compute a displacement from the "steady-state frame pointer" to
20842 the CFA. The former is what all stack slots and argument slots
20843 will reference in the rtl; the latter is what we've told the
20844 debugger about. We'll need to adjust all frame_base references
20845 by this displacement. */
20846 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
20848 if (fun
->static_chain_decl
)
20850 /* DWARF requires here a location expression that computes the
20851 address of the enclosing subprogram's frame base. The machinery
20852 in tree-nested.c is supposed to store this specific address in the
20853 last field of the FRAME record. */
20854 const tree frame_type
20855 = TREE_TYPE (TREE_TYPE (fun
->static_chain_decl
));
20856 const tree fb_decl
= tree_last (TYPE_FIELDS (frame_type
));
20859 = build1 (INDIRECT_REF
, frame_type
, fun
->static_chain_decl
);
20860 fb_expr
= build3 (COMPONENT_REF
, TREE_TYPE (fb_decl
),
20861 fb_expr
, fb_decl
, NULL_TREE
);
20863 add_AT_location_description (subr_die
, DW_AT_static_link
,
20864 loc_list_from_tree (fb_expr
, 0, NULL
));
20868 /* Generate child dies for template paramaters. */
20869 if (early_dwarf
&& debug_info_level
> DINFO_LEVEL_TERSE
)
20870 gen_generic_params_dies (decl
);
20872 /* Now output descriptions of the arguments for this function. This gets
20873 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
20874 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
20875 `...' at the end of the formal parameter list. In order to find out if
20876 there was a trailing ellipsis or not, we must instead look at the type
20877 associated with the FUNCTION_DECL. This will be a node of type
20878 FUNCTION_TYPE. If the chain of type nodes hanging off of this
20879 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
20880 an ellipsis at the end. */
20882 /* In the case where we are describing a mere function declaration, all we
20883 need to do here (and all we *can* do here) is to describe the *types* of
20884 its formal parameters. */
20885 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20887 else if (declaration
)
20888 gen_formal_types_die (decl
, subr_die
);
20891 /* Generate DIEs to represent all known formal parameters. */
20892 tree parm
= DECL_ARGUMENTS (decl
);
20893 tree generic_decl
= early_dwarf
20894 ? lang_hooks
.decls
.get_generic_function_decl (decl
) : NULL
;
20895 tree generic_decl_parm
= generic_decl
20896 ? DECL_ARGUMENTS (generic_decl
)
20898 auto_vec
<dw_die_ref
> string_types_vec
;
20899 if (string_types
== NULL
)
20900 string_types
= &string_types_vec
;
20902 /* Now we want to walk the list of parameters of the function and
20903 emit their relevant DIEs.
20905 We consider the case of DECL being an instance of a generic function
20906 as well as it being a normal function.
20908 If DECL is an instance of a generic function we walk the
20909 parameters of the generic function declaration _and_ the parameters of
20910 DECL itself. This is useful because we want to emit specific DIEs for
20911 function parameter packs and those are declared as part of the
20912 generic function declaration. In that particular case,
20913 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
20914 That DIE has children DIEs representing the set of arguments
20915 of the pack. Note that the set of pack arguments can be empty.
20916 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
20919 Otherwise, we just consider the parameters of DECL. */
20920 while (generic_decl_parm
|| parm
)
20922 if (generic_decl_parm
20923 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
20924 gen_formal_parameter_pack_die (generic_decl_parm
,
20927 else if (parm
&& !POINTER_BOUNDS_P (parm
))
20929 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, NULL
, subr_die
);
20931 if (parm
== DECL_ARGUMENTS (decl
)
20932 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
20934 && (dwarf_version
>= 3 || !dwarf_strict
))
20935 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
20937 parm
= DECL_CHAIN (parm
);
20940 parm
= DECL_CHAIN (parm
);
20942 if (generic_decl_parm
)
20943 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
20946 /* Decide whether we need an unspecified_parameters DIE at the end.
20947 There are 2 more cases to do this for: 1) the ansi ... declaration -
20948 this is detectable when the end of the arg list is not a
20949 void_type_node 2) an unprototyped function declaration (not a
20950 definition). This just means that we have no info about the
20951 parameters at all. */
20954 if (prototype_p (TREE_TYPE (decl
)))
20956 /* This is the prototyped case, check for.... */
20957 if (stdarg_p (TREE_TYPE (decl
)))
20958 gen_unspecified_parameters_die (decl
, subr_die
);
20960 else if (DECL_INITIAL (decl
) == NULL_TREE
)
20961 gen_unspecified_parameters_die (decl
, subr_die
);
20964 /* Adjust DW_TAG_string_type DIEs if needed, now that all arguments
20966 if (string_types
== &string_types_vec
)
20968 adjust_string_types ();
20969 string_types
= NULL
;
20973 if (subr_die
!= old_die
)
20974 /* Add the calling convention attribute if requested. */
20975 add_calling_convention_attribute (subr_die
, decl
);
20977 /* Output Dwarf info for all of the stuff within the body of the function
20978 (if it has one - it may be just a declaration).
20980 OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
20981 a function. This BLOCK actually represents the outermost binding contour
20982 for the function, i.e. the contour in which the function's formal
20983 parameters and labels get declared. Curiously, it appears that the front
20984 end doesn't actually put the PARM_DECL nodes for the current function onto
20985 the BLOCK_VARS list for this outer scope, but are strung off of the
20986 DECL_ARGUMENTS list for the function instead.
20988 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
20989 the LABEL_DECL nodes for the function however, and we output DWARF info
20990 for those in decls_for_scope. Just within the `outer_scope' there will be
20991 a BLOCK node representing the function's outermost pair of curly braces,
20992 and any blocks used for the base and member initializers of a C++
20993 constructor function. */
20994 tree outer_scope
= DECL_INITIAL (decl
);
20995 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
20997 int call_site_note_count
= 0;
20998 int tail_call_site_note_count
= 0;
21000 /* Emit a DW_TAG_variable DIE for a named return value. */
21001 if (DECL_NAME (DECL_RESULT (decl
)))
21002 gen_decl_die (DECL_RESULT (decl
), NULL
, NULL
, subr_die
);
21004 /* The first time through decls_for_scope we will generate the
21005 DIEs for the locals. The second time, we fill in the
21007 decls_for_scope (outer_scope
, subr_die
);
21009 if (call_arg_locations
&& !dwarf_strict
)
21011 struct call_arg_loc_node
*ca_loc
;
21012 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
21014 dw_die_ref die
= NULL
;
21015 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
21018 for (arg
= (ca_loc
->call_arg_loc_note
!= NULL_RTX
21019 ? NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
)
21021 arg
; arg
= next_arg
)
21023 dw_loc_descr_ref reg
, val
;
21024 machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
21025 dw_die_ref cdie
, tdie
= NULL
;
21027 next_arg
= XEXP (arg
, 1);
21028 if (REG_P (XEXP (XEXP (arg
, 0), 0))
21030 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
21031 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
21032 && REGNO (XEXP (XEXP (arg
, 0), 0))
21033 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
21034 next_arg
= XEXP (next_arg
, 1);
21035 if (mode
== VOIDmode
)
21037 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
21038 if (mode
== VOIDmode
)
21039 mode
= GET_MODE (XEXP (arg
, 0));
21041 if (mode
== VOIDmode
|| mode
== BLKmode
)
21043 /* Get dynamic information about call target only if we
21044 have no static information: we cannot generate both
21045 DW_AT_abstract_origin and DW_AT_GNU_call_site_target
21047 if (ca_loc
->symbol_ref
== NULL_RTX
)
21049 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
21051 tloc
= XEXP (XEXP (arg
, 0), 1);
21054 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
21055 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
21057 tlocc
= XEXP (XEXP (arg
, 0), 1);
21062 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
21063 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
21064 VAR_INIT_STATUS_INITIALIZED
);
21065 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
21067 rtx mem
= XEXP (XEXP (arg
, 0), 0);
21068 reg
= mem_loc_descriptor (XEXP (mem
, 0),
21069 get_address_mode (mem
),
21071 VAR_INIT_STATUS_INITIALIZED
);
21073 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
21074 == DEBUG_PARAMETER_REF
)
21077 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
21078 tdie
= lookup_decl_die (tdecl
);
21085 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
21086 != DEBUG_PARAMETER_REF
)
21088 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
21090 VAR_INIT_STATUS_INITIALIZED
);
21094 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
21095 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
21098 add_AT_loc (cdie
, DW_AT_location
, reg
);
21099 else if (tdie
!= NULL
)
21100 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
21101 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
21102 if (next_arg
!= XEXP (arg
, 1))
21104 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
21105 if (mode
== VOIDmode
)
21106 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
21107 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
21110 VAR_INIT_STATUS_INITIALIZED
);
21112 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
21116 && (ca_loc
->symbol_ref
|| tloc
))
21117 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
21118 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
21120 dw_loc_descr_ref tval
= NULL
;
21122 if (tloc
!= NULL_RTX
)
21123 tval
= mem_loc_descriptor (tloc
,
21124 GET_MODE (tloc
) == VOIDmode
21125 ? Pmode
: GET_MODE (tloc
),
21127 VAR_INIT_STATUS_INITIALIZED
);
21129 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
21130 else if (tlocc
!= NULL_RTX
)
21132 tval
= mem_loc_descriptor (tlocc
,
21133 GET_MODE (tlocc
) == VOIDmode
21134 ? Pmode
: GET_MODE (tlocc
),
21136 VAR_INIT_STATUS_INITIALIZED
);
21138 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
21144 call_site_note_count
++;
21145 if (ca_loc
->tail_call_p
)
21146 tail_call_site_note_count
++;
21150 call_arg_locations
= NULL
;
21151 call_arg_loc_last
= NULL
;
21152 if (tail_call_site_count
>= 0
21153 && tail_call_site_count
== tail_call_site_note_count
21156 if (call_site_count
>= 0
21157 && call_site_count
== call_site_note_count
)
21158 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
21160 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
21162 call_site_count
= -1;
21163 tail_call_site_count
= -1;
21167 /* Returns a hash value for X (which really is a die_struct). */
21170 block_die_hasher::hash (die_struct
*d
)
21172 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
21175 /* Return nonzero if decl_id and die_parent of die_struct X is the same
21176 as decl_id and die_parent of die_struct Y. */
21179 block_die_hasher::equal (die_struct
*x
, die_struct
*y
)
21181 return x
->decl_id
== y
->decl_id
&& x
->die_parent
== y
->die_parent
;
21184 /* Return TRUE if DECL, which may have been previously generated as
21185 OLD_DIE, is a candidate for a DW_AT_specification. DECLARATION is
21186 true if decl (or its origin) is either an extern declaration or a
21187 class/namespace scoped declaration.
21189 The declare_in_namespace support causes us to get two DIEs for one
21190 variable, both of which are declarations. We want to avoid
21191 considering one to be a specification, so we must test for
21192 DECLARATION and DW_AT_declaration. */
21194 decl_will_get_specification_p (dw_die_ref old_die
, tree decl
, bool declaration
)
21196 return (old_die
&& TREE_STATIC (decl
) && !declaration
21197 && get_AT_flag (old_die
, DW_AT_declaration
) == 1);
21200 /* Return true if DECL is a local static. */
21203 local_function_static (tree decl
)
21205 gcc_assert (TREE_CODE (decl
) == VAR_DECL
);
21206 return TREE_STATIC (decl
)
21207 && DECL_CONTEXT (decl
)
21208 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
;
21211 /* Generate a DIE to represent a declared data object.
21212 Either DECL or ORIGIN must be non-null. */
21215 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
21217 HOST_WIDE_INT off
= 0;
21219 tree decl_or_origin
= decl
? decl
: origin
;
21220 tree ultimate_origin
;
21221 dw_die_ref var_die
;
21222 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
21223 dw_die_ref origin_die
= NULL
;
21224 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
21225 || class_or_namespace_scope_p (context_die
));
21226 bool specialization_p
= false;
21228 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
21229 if (decl
|| ultimate_origin
)
21230 origin
= ultimate_origin
;
21231 com_decl
= fortran_common (decl_or_origin
, &off
);
21233 /* Symbol in common gets emitted as a child of the common block, in the form
21234 of a data member. */
21237 dw_die_ref com_die
;
21238 dw_loc_list_ref loc
;
21239 die_node com_die_arg
;
21241 var_die
= lookup_decl_die (decl_or_origin
);
21244 if (get_AT (var_die
, DW_AT_location
) == NULL
)
21246 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2, NULL
);
21251 /* Optimize the common case. */
21252 if (single_element_loc_list_p (loc
)
21253 && loc
->expr
->dw_loc_opc
== DW_OP_addr
21254 && loc
->expr
->dw_loc_next
== NULL
21255 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
21258 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
21259 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
21260 = plus_constant (GET_MODE (x
), x
, off
);
21263 loc_list_plus_const (loc
, off
);
21265 add_AT_location_description (var_die
, DW_AT_location
, loc
);
21266 remove_AT (var_die
, DW_AT_declaration
);
21272 if (common_block_die_table
== NULL
)
21273 common_block_die_table
= hash_table
<block_die_hasher
>::create_ggc (10);
21275 com_die_arg
.decl_id
= DECL_UID (com_decl
);
21276 com_die_arg
.die_parent
= context_die
;
21277 com_die
= common_block_die_table
->find (&com_die_arg
);
21278 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
21279 if (com_die
== NULL
)
21282 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
21285 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
21286 add_name_and_src_coords_attributes (com_die
, com_decl
);
21289 add_AT_location_description (com_die
, DW_AT_location
, loc
);
21290 /* Avoid sharing the same loc descriptor between
21291 DW_TAG_common_block and DW_TAG_variable. */
21292 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
21294 else if (DECL_EXTERNAL (decl_or_origin
))
21295 add_AT_flag (com_die
, DW_AT_declaration
, 1);
21296 if (want_pubnames ())
21297 add_pubname_string (cnam
, com_die
); /* ??? needed? */
21298 com_die
->decl_id
= DECL_UID (com_decl
);
21299 slot
= common_block_die_table
->find_slot (com_die
, INSERT
);
21302 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
21304 add_AT_location_description (com_die
, DW_AT_location
, loc
);
21305 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
21306 remove_AT (com_die
, DW_AT_declaration
);
21308 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
21309 add_name_and_src_coords_attributes (var_die
, decl_or_origin
);
21310 add_type_attribute (var_die
, TREE_TYPE (decl_or_origin
),
21311 decl_quals (decl_or_origin
), false,
21313 add_AT_flag (var_die
, DW_AT_external
, 1);
21318 /* Optimize the common case. */
21319 if (single_element_loc_list_p (loc
)
21320 && loc
->expr
->dw_loc_opc
== DW_OP_addr
21321 && loc
->expr
->dw_loc_next
== NULL
21322 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
21324 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
21325 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
21326 = plus_constant (GET_MODE (x
), x
, off
);
21329 loc_list_plus_const (loc
, off
);
21331 add_AT_location_description (var_die
, DW_AT_location
, loc
);
21333 else if (DECL_EXTERNAL (decl_or_origin
))
21334 add_AT_flag (var_die
, DW_AT_declaration
, 1);
21336 equate_decl_number_to_die (decl
, var_die
);
21344 /* A declaration that has been previously dumped, needs no
21345 further annotations, since it doesn't need location on
21346 the second pass. */
21349 else if (decl_will_get_specification_p (old_die
, decl
, declaration
)
21350 && !get_AT (old_die
, DW_AT_specification
))
21352 /* Fall-thru so we can make a new variable die along with a
21353 DW_AT_specification. */
21355 else if (origin
&& old_die
->die_parent
!= context_die
)
21357 /* If we will be creating an inlined instance, we need a
21358 new DIE that will get annotated with
21359 DW_AT_abstract_origin. Clear things so we can get a
21361 gcc_assert (!DECL_ABSTRACT_P (decl
));
21366 /* If a DIE was dumped early, it still needs location info.
21367 Skip to where we fill the location bits. */
21369 goto gen_variable_die_location
;
21373 /* For static data members, the declaration in the class is supposed
21374 to have DW_TAG_member tag; the specification should still be
21375 DW_TAG_variable referencing the DW_TAG_member DIE. */
21376 if (declaration
&& class_scope_p (context_die
))
21377 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
21379 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
21381 if (origin
!= NULL
)
21382 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
21384 /* Loop unrolling can create multiple blocks that refer to the same
21385 static variable, so we must test for the DW_AT_declaration flag.
21387 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
21388 copy decls and set the DECL_ABSTRACT_P flag on them instead of
21391 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
21392 else if (decl_will_get_specification_p (old_die
, decl
, declaration
))
21394 /* This is a definition of a C++ class level static. */
21395 add_AT_specification (var_die
, old_die
);
21396 specialization_p
= true;
21397 if (DECL_NAME (decl
))
21399 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
21400 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
21402 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
21403 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
21405 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
21406 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
21408 if (old_die
->die_tag
== DW_TAG_member
)
21409 add_linkage_name (var_die
, decl
);
21413 add_name_and_src_coords_attributes (var_die
, decl
);
21415 if ((origin
== NULL
&& !specialization_p
)
21417 && !DECL_ABSTRACT_P (decl_or_origin
)
21418 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
21419 decl_function_context
21420 (decl_or_origin
))))
21422 tree type
= TREE_TYPE (decl_or_origin
);
21424 if (decl_by_reference_p (decl_or_origin
))
21425 add_type_attribute (var_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
21428 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
), false,
21432 if (origin
== NULL
&& !specialization_p
)
21434 if (TREE_PUBLIC (decl
))
21435 add_AT_flag (var_die
, DW_AT_external
, 1);
21437 if (DECL_ARTIFICIAL (decl
))
21438 add_AT_flag (var_die
, DW_AT_artificial
, 1);
21440 add_accessibility_attribute (var_die
, decl
);
21444 add_AT_flag (var_die
, DW_AT_declaration
, 1);
21446 if (decl
&& (DECL_ABSTRACT_P (decl
)
21447 || !old_die
|| is_declaration_die (old_die
)))
21448 equate_decl_number_to_die (decl
, var_die
);
21450 gen_variable_die_location
:
21452 && (! DECL_ABSTRACT_P (decl_or_origin
)
21453 /* Local static vars are shared between all clones/inlines,
21454 so emit DW_AT_location on the abstract DIE if DECL_RTL is
21456 || (TREE_CODE (decl_or_origin
) == VAR_DECL
21457 && TREE_STATIC (decl_or_origin
)
21458 && DECL_RTL_SET_P (decl_or_origin
)))
21459 /* When abstract origin already has DW_AT_location attribute, no need
21460 to add it again. */
21461 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
21464 add_pubname (decl_or_origin
, var_die
);
21466 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
21470 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
21473 /* Generate a DIE to represent a named constant. */
21476 gen_const_die (tree decl
, dw_die_ref context_die
)
21478 dw_die_ref const_die
;
21479 tree type
= TREE_TYPE (decl
);
21481 const_die
= lookup_decl_die (decl
);
21485 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
21486 equate_decl_number_to_die (decl
, const_die
);
21487 add_name_and_src_coords_attributes (const_die
, decl
);
21488 add_type_attribute (const_die
, type
, TYPE_QUAL_CONST
, false, context_die
);
21489 if (TREE_PUBLIC (decl
))
21490 add_AT_flag (const_die
, DW_AT_external
, 1);
21491 if (DECL_ARTIFICIAL (decl
))
21492 add_AT_flag (const_die
, DW_AT_artificial
, 1);
21493 tree_add_const_value_attribute_for_decl (const_die
, decl
);
21496 /* Generate a DIE to represent a label identifier. */
21499 gen_label_die (tree decl
, dw_die_ref context_die
)
21501 tree origin
= decl_ultimate_origin (decl
);
21502 dw_die_ref lbl_die
= lookup_decl_die (decl
);
21504 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21508 lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
21509 equate_decl_number_to_die (decl
, lbl_die
);
21511 if (origin
!= NULL
)
21512 add_abstract_origin_attribute (lbl_die
, origin
);
21514 add_name_and_src_coords_attributes (lbl_die
, decl
);
21517 if (DECL_ABSTRACT_P (decl
))
21518 equate_decl_number_to_die (decl
, lbl_die
);
21521 insn
= DECL_RTL_IF_SET (decl
);
21523 /* Deleted labels are programmer specified labels which have been
21524 eliminated because of various optimizations. We still emit them
21525 here so that it is possible to put breakpoints on them. */
21529 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
21531 /* When optimization is enabled (via -O) some parts of the compiler
21532 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
21533 represent source-level labels which were explicitly declared by
21534 the user. This really shouldn't be happening though, so catch
21535 it if it ever does happen. */
21536 gcc_assert (!as_a
<rtx_insn
*> (insn
)->deleted ());
21538 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
21539 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
21543 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
21544 && CODE_LABEL_NUMBER (insn
) != -1)
21546 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
21547 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
21552 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
21553 attributes to the DIE for a block STMT, to describe where the inlined
21554 function was called from. This is similar to add_src_coords_attributes. */
21557 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
21559 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
21561 if (dwarf_version
>= 3 || !dwarf_strict
)
21563 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
21564 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
21569 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
21570 Add low_pc and high_pc attributes to the DIE for a block STMT. */
21573 add_high_low_attributes (tree stmt
, dw_die_ref die
)
21575 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21577 if (BLOCK_FRAGMENT_CHAIN (stmt
)
21578 && (dwarf_version
>= 3 || !dwarf_strict
))
21580 tree chain
, superblock
= NULL_TREE
;
21582 dw_attr_node
*attr
= NULL
;
21584 if (inlined_function_outer_scope_p (stmt
))
21586 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
21587 BLOCK_NUMBER (stmt
));
21588 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
21591 /* Optimize duplicate .debug_ranges lists or even tails of
21592 lists. If this BLOCK has same ranges as its supercontext,
21593 lookup DW_AT_ranges attribute in the supercontext (and
21594 recursively so), verify that the ranges_table contains the
21595 right values and use it instead of adding a new .debug_range. */
21596 for (chain
= stmt
, pdie
= die
;
21597 BLOCK_SAME_RANGE (chain
);
21598 chain
= BLOCK_SUPERCONTEXT (chain
))
21600 dw_attr_node
*new_attr
;
21602 pdie
= pdie
->die_parent
;
21605 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
21607 new_attr
= get_AT (pdie
, DW_AT_ranges
);
21608 if (new_attr
== NULL
21609 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
21612 superblock
= BLOCK_SUPERCONTEXT (chain
);
21615 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
21616 / 2 / DWARF2_ADDR_SIZE
].num
21617 == BLOCK_NUMBER (superblock
))
21618 && BLOCK_FRAGMENT_CHAIN (superblock
))
21620 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
21621 / 2 / DWARF2_ADDR_SIZE
;
21622 unsigned long supercnt
= 0, thiscnt
= 0;
21623 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
21624 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
21627 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
21628 == BLOCK_NUMBER (chain
));
21630 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
21631 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
21632 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
21634 gcc_assert (supercnt
>= thiscnt
);
21635 add_AT_range_list (die
, DW_AT_ranges
,
21636 ((off
+ supercnt
- thiscnt
)
21637 * 2 * DWARF2_ADDR_SIZE
),
21642 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
21644 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
21647 add_ranges (chain
);
21648 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
21655 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
21656 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
21657 BLOCK_NUMBER (stmt
));
21658 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
21659 BLOCK_NUMBER (stmt
));
21660 add_AT_low_high_pc (die
, label
, label_high
, false);
21664 /* Generate a DIE for a lexical block. */
21667 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
)
21669 dw_die_ref old_die
= BLOCK_DIE (stmt
);
21670 dw_die_ref stmt_die
= NULL
;
21673 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
21674 BLOCK_DIE (stmt
) = stmt_die
;
21677 if (BLOCK_ABSTRACT (stmt
))
21681 /* This must have been generated early and it won't even
21682 need location information since it's a DW_AT_inline
21685 for (dw_die_ref c
= context_die
; c
; c
= c
->die_parent
)
21686 if (c
->die_tag
== DW_TAG_inlined_subroutine
21687 || c
->die_tag
== DW_TAG_subprogram
)
21689 gcc_assert (get_AT (c
, DW_AT_inline
));
21695 else if (BLOCK_ABSTRACT_ORIGIN (stmt
))
21697 /* If this is an inlined instance, create a new lexical die for
21698 anything below to attach DW_AT_abstract_origin to. */
21701 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
21702 BLOCK_DIE (stmt
) = stmt_die
;
21706 tree origin
= block_ultimate_origin (stmt
);
21707 if (origin
!= NULL_TREE
&& origin
!= stmt
)
21708 add_abstract_origin_attribute (stmt_die
, origin
);
21712 stmt_die
= old_die
;
21714 /* A non abstract block whose blocks have already been reordered
21715 should have the instruction range for this block. If so, set the
21716 high/low attributes. */
21717 if (!early_dwarf
&& !BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
21719 gcc_assert (stmt_die
);
21720 add_high_low_attributes (stmt
, stmt_die
);
21723 decls_for_scope (stmt
, stmt_die
);
21726 /* Generate a DIE for an inlined subprogram. */
21729 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
)
21733 /* The instance of function that is effectively being inlined shall not
21735 gcc_assert (! BLOCK_ABSTRACT (stmt
));
21737 decl
= block_ultimate_origin (stmt
);
21739 /* Make sure any inlined functions are known to be inlineable. */
21740 gcc_checking_assert (DECL_ABSTRACT_P (decl
)
21741 || cgraph_function_possibly_inlined_p (decl
));
21743 /* Emit info for the abstract instance first, if we haven't yet. We
21744 must emit this even if the block is abstract, otherwise when we
21745 emit the block below (or elsewhere), we may end up trying to emit
21746 a die whose origin die hasn't been emitted, and crashing. */
21747 dwarf2out_abstract_function (decl
);
21749 if (! BLOCK_ABSTRACT (stmt
))
21751 dw_die_ref subr_die
21752 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
21754 if (call_arg_locations
)
21755 BLOCK_DIE (stmt
) = subr_die
;
21756 add_abstract_origin_attribute (subr_die
, decl
);
21757 if (TREE_ASM_WRITTEN (stmt
))
21758 add_high_low_attributes (stmt
, subr_die
);
21759 add_call_src_coords_attributes (stmt
, subr_die
);
21761 decls_for_scope (stmt
, subr_die
);
21765 /* Generate a DIE for a field in a record, or structure. CTX is required: see
21766 the comment for VLR_CONTEXT. */
21769 gen_field_die (tree decl
, struct vlr_context
*ctx
, dw_die_ref context_die
)
21771 dw_die_ref decl_die
;
21773 if (TREE_TYPE (decl
) == error_mark_node
)
21776 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
21777 add_name_and_src_coords_attributes (decl_die
, decl
);
21778 add_type_attribute (decl_die
, member_declared_type (decl
), decl_quals (decl
),
21779 TYPE_REVERSE_STORAGE_ORDER (DECL_FIELD_CONTEXT (decl
)),
21782 if (DECL_BIT_FIELD_TYPE (decl
))
21784 add_byte_size_attribute (decl_die
, decl
);
21785 add_bit_size_attribute (decl_die
, decl
);
21786 add_bit_offset_attribute (decl_die
, decl
, ctx
);
21789 /* If we have a variant part offset, then we are supposed to process a member
21790 of a QUAL_UNION_TYPE, which is how we represent variant parts in
21792 gcc_assert (ctx
->variant_part_offset
== NULL_TREE
21793 || TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != QUAL_UNION_TYPE
);
21794 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
21795 add_data_member_location_attribute (decl_die
, decl
, ctx
);
21797 if (DECL_ARTIFICIAL (decl
))
21798 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
21800 add_accessibility_attribute (decl_die
, decl
);
21802 /* Equate decl number to die, so that we can look up this decl later on. */
21803 equate_decl_number_to_die (decl
, decl_die
);
21807 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
21808 Use modified_type_die instead.
21809 We keep this code here just in case these types of DIEs may be needed to
21810 represent certain things in other languages (e.g. Pascal) someday. */
21813 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
21816 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
21818 equate_type_number_to_die (type
, ptr_die
);
21819 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
21821 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
21824 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
21825 Use modified_type_die instead.
21826 We keep this code here just in case these types of DIEs may be needed to
21827 represent certain things in other languages (e.g. Pascal) someday. */
21830 gen_reference_type_die (tree type
, dw_die_ref context_die
)
21832 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
21834 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
21835 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
21837 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
21839 equate_type_number_to_die (type
, ref_die
);
21840 add_type_attribute (ref_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
21842 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
21846 /* Generate a DIE for a pointer to a member type. */
21849 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
21852 = new_die (DW_TAG_ptr_to_member_type
,
21853 scope_die_for (type
, context_die
), type
);
21855 equate_type_number_to_die (type
, ptr_die
);
21856 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
21857 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
21858 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
21862 static char *producer_string
;
21864 /* Return a heap allocated producer string including command line options
21865 if -grecord-gcc-switches. */
21868 gen_producer_string (void)
21871 auto_vec
<const char *> switches
;
21872 const char *language_string
= lang_hooks
.name
;
21873 char *producer
, *tail
;
21875 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
21876 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
21878 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
21879 switch (save_decoded_options
[j
].opt_index
)
21886 case OPT_auxbase_strip
:
21895 case OPT_SPECIAL_unknown
:
21896 case OPT_SPECIAL_ignore
:
21897 case OPT_SPECIAL_program_name
:
21898 case OPT_SPECIAL_input_file
:
21899 case OPT_grecord_gcc_switches
:
21900 case OPT_gno_record_gcc_switches
:
21901 case OPT__output_pch_
:
21902 case OPT_fdiagnostics_show_location_
:
21903 case OPT_fdiagnostics_show_option
:
21904 case OPT_fdiagnostics_show_caret
:
21905 case OPT_fdiagnostics_color_
:
21906 case OPT_fverbose_asm
:
21908 case OPT__sysroot_
:
21910 case OPT_nostdinc__
:
21911 case OPT_fpreprocessed
:
21912 case OPT_fltrans_output_list_
:
21913 case OPT_fresolution_
:
21914 case OPT_fdebug_prefix_map_
:
21915 /* Ignore these. */
21918 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
21919 & CL_NO_DWARF_RECORD
)
21921 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
21923 switch (save_decoded_options
[j
].canonical_option
[0][1])
21930 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
21937 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
21938 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
21942 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
21944 sprintf (tail
, "%s %s", language_string
, version_string
);
21947 FOR_EACH_VEC_ELT (switches
, j
, p
)
21951 memcpy (tail
+ 1, p
, len
);
21959 /* Given a C and/or C++ language/version string return the "highest".
21960 C++ is assumed to be "higher" than C in this case. Used for merging
21961 LTO translation unit languages. */
21962 static const char *
21963 highest_c_language (const char *lang1
, const char *lang2
)
21965 if (strcmp ("GNU C++14", lang1
) == 0 || strcmp ("GNU C++14", lang2
) == 0)
21966 return "GNU C++14";
21967 if (strcmp ("GNU C++11", lang1
) == 0 || strcmp ("GNU C++11", lang2
) == 0)
21968 return "GNU C++11";
21969 if (strcmp ("GNU C++98", lang1
) == 0 || strcmp ("GNU C++98", lang2
) == 0)
21970 return "GNU C++98";
21972 if (strcmp ("GNU C11", lang1
) == 0 || strcmp ("GNU C11", lang2
) == 0)
21974 if (strcmp ("GNU C99", lang1
) == 0 || strcmp ("GNU C99", lang2
) == 0)
21976 if (strcmp ("GNU C89", lang1
) == 0 || strcmp ("GNU C89", lang2
) == 0)
21979 gcc_unreachable ();
21983 /* Generate the DIE for the compilation unit. */
21986 gen_compile_unit_die (const char *filename
)
21989 const char *language_string
= lang_hooks
.name
;
21992 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
21996 add_name_attribute (die
, filename
);
21997 /* Don't add cwd for <built-in>. */
21998 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
21999 add_comp_dir_attribute (die
);
22002 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
22004 /* If our producer is LTO try to figure out a common language to use
22005 from the global list of translation units. */
22006 if (strcmp (language_string
, "GNU GIMPLE") == 0)
22010 const char *common_lang
= NULL
;
22012 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
22014 if (!TRANSLATION_UNIT_LANGUAGE (t
))
22017 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
22018 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
22020 else if (strncmp (common_lang
, "GNU C", 5) == 0
22021 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
22022 /* Mixing C and C++ is ok, use C++ in that case. */
22023 common_lang
= highest_c_language (common_lang
,
22024 TRANSLATION_UNIT_LANGUAGE (t
));
22027 /* Fall back to C. */
22028 common_lang
= NULL
;
22034 language_string
= common_lang
;
22037 language
= DW_LANG_C
;
22038 if (strncmp (language_string
, "GNU C", 5) == 0
22039 && ISDIGIT (language_string
[5]))
22041 language
= DW_LANG_C89
;
22042 if (dwarf_version
>= 3 || !dwarf_strict
)
22044 if (strcmp (language_string
, "GNU C89") != 0)
22045 language
= DW_LANG_C99
;
22047 if (dwarf_version
>= 5 /* || !dwarf_strict */)
22048 if (strcmp (language_string
, "GNU C11") == 0)
22049 language
= DW_LANG_C11
;
22052 else if (strncmp (language_string
, "GNU C++", 7) == 0)
22054 language
= DW_LANG_C_plus_plus
;
22055 if (dwarf_version
>= 5 /* || !dwarf_strict */)
22057 if (strcmp (language_string
, "GNU C++11") == 0)
22058 language
= DW_LANG_C_plus_plus_11
;
22059 else if (strcmp (language_string
, "GNU C++14") == 0)
22060 language
= DW_LANG_C_plus_plus_14
;
22063 else if (strcmp (language_string
, "GNU F77") == 0)
22064 language
= DW_LANG_Fortran77
;
22065 else if (strcmp (language_string
, "GNU Pascal") == 0)
22066 language
= DW_LANG_Pascal83
;
22067 else if (dwarf_version
>= 3 || !dwarf_strict
)
22069 if (strcmp (language_string
, "GNU Ada") == 0)
22070 language
= DW_LANG_Ada95
;
22071 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
22073 language
= DW_LANG_Fortran95
;
22074 if (dwarf_version
>= 5 /* || !dwarf_strict */)
22076 if (strcmp (language_string
, "GNU Fortran2003") == 0)
22077 language
= DW_LANG_Fortran03
;
22078 else if (strcmp (language_string
, "GNU Fortran2008") == 0)
22079 language
= DW_LANG_Fortran08
;
22082 else if (strcmp (language_string
, "GNU Java") == 0)
22083 language
= DW_LANG_Java
;
22084 else if (strcmp (language_string
, "GNU Objective-C") == 0)
22085 language
= DW_LANG_ObjC
;
22086 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
22087 language
= DW_LANG_ObjC_plus_plus
;
22088 else if (dwarf_version
>= 5 || !dwarf_strict
)
22090 if (strcmp (language_string
, "GNU Go") == 0)
22091 language
= DW_LANG_Go
;
22094 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
22095 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
22096 language
= DW_LANG_Fortran90
;
22098 add_AT_unsigned (die
, DW_AT_language
, language
);
22102 case DW_LANG_Fortran77
:
22103 case DW_LANG_Fortran90
:
22104 case DW_LANG_Fortran95
:
22105 case DW_LANG_Fortran03
:
22106 case DW_LANG_Fortran08
:
22107 /* Fortran has case insensitive identifiers and the front-end
22108 lowercases everything. */
22109 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
22112 /* The default DW_ID_case_sensitive doesn't need to be specified. */
22118 /* Generate the DIE for a base class. */
22121 gen_inheritance_die (tree binfo
, tree access
, tree type
,
22122 dw_die_ref context_die
)
22124 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
22125 struct vlr_context ctx
= { type
, NULL
};
22127 add_type_attribute (die
, BINFO_TYPE (binfo
), TYPE_UNQUALIFIED
, false,
22129 add_data_member_location_attribute (die
, binfo
, &ctx
);
22131 if (BINFO_VIRTUAL_P (binfo
))
22132 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
22134 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
22135 children, otherwise the default is DW_ACCESS_public. In DWARF2
22136 the default has always been DW_ACCESS_private. */
22137 if (access
== access_public_node
)
22139 if (dwarf_version
== 2
22140 || context_die
->die_tag
== DW_TAG_class_type
)
22141 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
22143 else if (access
== access_protected_node
)
22144 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
22145 else if (dwarf_version
> 2
22146 && context_die
->die_tag
!= DW_TAG_class_type
)
22147 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
22150 /* Return whether DECL is a FIELD_DECL that represents the variant part of a
22153 is_variant_part (tree decl
)
22155 return (TREE_CODE (decl
) == FIELD_DECL
22156 && TREE_CODE (TREE_TYPE (decl
)) == QUAL_UNION_TYPE
);
22159 /* Check that OPERAND is a reference to a field in STRUCT_TYPE. If it is,
22160 return the FIELD_DECL. Return NULL_TREE otherwise. */
22163 analyze_discr_in_predicate (tree operand
, tree struct_type
)
22165 bool continue_stripping
= true;
22166 while (continue_stripping
)
22167 switch (TREE_CODE (operand
))
22170 operand
= TREE_OPERAND (operand
, 0);
22173 continue_stripping
= false;
22177 /* Match field access to members of struct_type only. */
22178 if (TREE_CODE (operand
) == COMPONENT_REF
22179 && TREE_CODE (TREE_OPERAND (operand
, 0)) == PLACEHOLDER_EXPR
22180 && TREE_TYPE (TREE_OPERAND (operand
, 0)) == struct_type
22181 && TREE_CODE (TREE_OPERAND (operand
, 1)) == FIELD_DECL
)
22182 return TREE_OPERAND (operand
, 1);
22187 /* Check that SRC is a constant integer that can be represented as a native
22188 integer constant (either signed or unsigned). If so, store it into DEST and
22189 return true. Return false otherwise. */
22192 get_discr_value (tree src
, dw_discr_value
*dest
)
22194 bool is_unsigned
= TYPE_UNSIGNED (TREE_TYPE (src
));
22196 if (TREE_CODE (src
) != INTEGER_CST
22197 || !(is_unsigned
? tree_fits_uhwi_p (src
) : tree_fits_shwi_p (src
)))
22200 dest
->pos
= is_unsigned
;
22202 dest
->v
.uval
= tree_to_uhwi (src
);
22204 dest
->v
.sval
= tree_to_shwi (src
);
22209 /* Try to extract synthetic properties out of VARIANT_PART_DECL, which is a
22210 FIELD_DECL in STRUCT_TYPE that represents a variant part. If unsuccessful,
22211 store NULL_TREE in DISCR_DECL. Otherwise:
22213 - store the discriminant field in STRUCT_TYPE that controls the variant
22214 part to *DISCR_DECL
22216 - put in *DISCR_LISTS_P an array where for each variant, the item
22217 represents the corresponding matching list of discriminant values.
22219 - put in *DISCR_LISTS_LENGTH the number of variants, which is the size of
22222 Note that when the array is allocated (i.e. when the analysis is
22223 successful), it is up to the caller to free the array. */
22226 analyze_variants_discr (tree variant_part_decl
,
22229 dw_discr_list_ref
**discr_lists_p
,
22230 unsigned *discr_lists_length
)
22232 tree variant_part_type
= TREE_TYPE (variant_part_decl
);
22234 dw_discr_list_ref
*discr_lists
;
22237 /* Compute how many variants there are in this variant part. */
22238 *discr_lists_length
= 0;
22239 for (variant
= TYPE_FIELDS (variant_part_type
);
22240 variant
!= NULL_TREE
;
22241 variant
= DECL_CHAIN (variant
))
22242 ++*discr_lists_length
;
22244 *discr_decl
= NULL_TREE
;
22246 = (dw_discr_list_ref
*) xcalloc (*discr_lists_length
,
22247 sizeof (**discr_lists_p
));
22248 discr_lists
= *discr_lists_p
;
22250 /* And then analyze all variants to extract discriminant information for all
22251 of them. This analysis is conservative: as soon as we detect something we
22252 do not support, abort everything and pretend we found nothing. */
22253 for (variant
= TYPE_FIELDS (variant_part_type
), i
= 0;
22254 variant
!= NULL_TREE
;
22255 variant
= DECL_CHAIN (variant
), ++i
)
22257 tree match_expr
= DECL_QUALIFIER (variant
);
22259 /* Now, try to analyze the predicate and deduce a discriminant for
22261 if (match_expr
== boolean_true_node
)
22262 /* Typically happens for the default variant: it matches all cases that
22263 previous variants rejected. Don't output any matching value for
22267 /* The following loop tries to iterate over each discriminant
22268 possibility: single values or ranges. */
22269 while (match_expr
!= NULL_TREE
)
22271 tree next_round_match_expr
;
22272 tree candidate_discr
= NULL_TREE
;
22273 dw_discr_list_ref new_node
= NULL
;
22275 /* Possibilities are matched one after the other by nested
22276 TRUTH_ORIF_EXPR expressions. Process the current possibility and
22277 continue with the rest at next iteration. */
22278 if (TREE_CODE (match_expr
) == TRUTH_ORIF_EXPR
)
22280 next_round_match_expr
= TREE_OPERAND (match_expr
, 0);
22281 match_expr
= TREE_OPERAND (match_expr
, 1);
22284 next_round_match_expr
= NULL_TREE
;
22286 if (match_expr
== boolean_false_node
)
22287 /* This sub-expression matches nothing: just wait for the next
22291 else if (TREE_CODE (match_expr
) == EQ_EXPR
)
22293 /* We are matching: <discr_field> == <integer_cst>
22294 This sub-expression matches a single value. */
22295 tree integer_cst
= TREE_OPERAND (match_expr
, 1);
22298 = analyze_discr_in_predicate (TREE_OPERAND (match_expr
, 0),
22301 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
22302 if (!get_discr_value (integer_cst
,
22303 &new_node
->dw_discr_lower_bound
))
22305 new_node
->dw_discr_range
= false;
22308 else if (TREE_CODE (match_expr
) == TRUTH_ANDIF_EXPR
)
22310 /* We are matching:
22311 <discr_field> > <integer_cst>
22312 && <discr_field> < <integer_cst>.
22313 This sub-expression matches the range of values between the
22314 two matched integer constants. Note that comparisons can be
22315 inclusive or exclusive. */
22316 tree candidate_discr_1
, candidate_discr_2
;
22317 tree lower_cst
, upper_cst
;
22318 bool lower_cst_included
, upper_cst_included
;
22319 tree lower_op
= TREE_OPERAND (match_expr
, 0);
22320 tree upper_op
= TREE_OPERAND (match_expr
, 1);
22322 /* When the comparison is exclusive, the integer constant is not
22323 the discriminant range bound we are looking for: we will have
22324 to increment or decrement it. */
22325 if (TREE_CODE (lower_op
) == GE_EXPR
)
22326 lower_cst_included
= true;
22327 else if (TREE_CODE (lower_op
) == GT_EXPR
)
22328 lower_cst_included
= false;
22332 if (TREE_CODE (upper_op
) == LE_EXPR
)
22333 upper_cst_included
= true;
22334 else if (TREE_CODE (upper_op
) == LT_EXPR
)
22335 upper_cst_included
= false;
22339 /* Extract the discriminant from the first operand and check it
22340 is consistant with the same analysis in the second
22343 = analyze_discr_in_predicate (TREE_OPERAND (lower_op
, 0),
22346 = analyze_discr_in_predicate (TREE_OPERAND (upper_op
, 0),
22348 if (candidate_discr_1
== candidate_discr_2
)
22349 candidate_discr
= candidate_discr_1
;
22353 /* Extract bounds from both. */
22354 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
22355 lower_cst
= TREE_OPERAND (lower_op
, 1);
22356 upper_cst
= TREE_OPERAND (upper_op
, 1);
22358 if (!lower_cst_included
)
22360 = fold (build2 (PLUS_EXPR
, TREE_TYPE (lower_cst
),
22362 build_int_cst (TREE_TYPE (lower_cst
), 1)));
22363 if (!upper_cst_included
)
22365 = fold (build2 (MINUS_EXPR
, TREE_TYPE (upper_cst
),
22367 build_int_cst (TREE_TYPE (upper_cst
), 1)));
22369 if (!get_discr_value (lower_cst
,
22370 &new_node
->dw_discr_lower_bound
)
22371 || !get_discr_value (upper_cst
,
22372 &new_node
->dw_discr_upper_bound
))
22375 new_node
->dw_discr_range
= true;
22379 /* Unsupported sub-expression: we cannot determine the set of
22380 matching discriminant values. Abort everything. */
22383 /* If the discriminant info is not consistant with what we saw so
22384 far, consider the analysis failed and abort everything. */
22385 if (candidate_discr
== NULL_TREE
22386 || (*discr_decl
!= NULL_TREE
&& candidate_discr
!= *discr_decl
))
22389 *discr_decl
= candidate_discr
;
22391 if (new_node
!= NULL
)
22393 new_node
->dw_discr_next
= discr_lists
[i
];
22394 discr_lists
[i
] = new_node
;
22396 match_expr
= next_round_match_expr
;
22400 /* If we reach this point, we could match everything we were interested
22405 /* Clean all data structure and return no result. */
22406 free (*discr_lists_p
);
22407 *discr_lists_p
= NULL
;
22408 *discr_decl
= NULL_TREE
;
22411 /* Generate a DIE to represent VARIANT_PART_DECL, a variant part that is part
22412 of STRUCT_TYPE, a record type. This new DIE is emitted as the next child
22415 Variant parts are supposed to be implemented as a FIELD_DECL whose type is a
22416 QUAL_UNION_TYPE: this is the VARIANT_PART_DECL parameter. The members for
22417 this type, which are record types, represent the available variants and each
22418 has a DECL_QUALIFIER attribute. The discriminant and the discriminant
22419 values are inferred from these attributes.
22421 In trees, the offsets for the fields inside these sub-records are relative
22422 to the variant part itself, whereas the corresponding DIEs should have
22423 offset attributes that are relative to the embedding record base address.
22424 This is why the caller must provide a VARIANT_PART_OFFSET expression: it
22425 must be an expression that computes the offset of the variant part to
22426 describe in DWARF. */
22429 gen_variant_part (tree variant_part_decl
, struct vlr_context
*vlr_ctx
,
22430 dw_die_ref context_die
)
22432 const tree variant_part_type
= TREE_TYPE (variant_part_decl
);
22433 tree variant_part_offset
= vlr_ctx
->variant_part_offset
;
22434 struct loc_descr_context ctx
= {
22435 vlr_ctx
->struct_type
, /* context_type */
22436 NULL_TREE
, /* base_decl */
22440 /* The FIELD_DECL node in STRUCT_TYPE that acts as the discriminant, or
22441 NULL_TREE if there is no such field. */
22442 tree discr_decl
= NULL_TREE
;
22443 dw_discr_list_ref
*discr_lists
;
22444 unsigned discr_lists_length
= 0;
22447 dw_die_ref dwarf_proc_die
= NULL
;
22448 dw_die_ref variant_part_die
22449 = new_die (DW_TAG_variant_part
, context_die
, variant_part_type
);
22451 equate_decl_number_to_die (variant_part_decl
, variant_part_die
);
22453 analyze_variants_discr (variant_part_decl
, vlr_ctx
->struct_type
,
22454 &discr_decl
, &discr_lists
, &discr_lists_length
);
22456 if (discr_decl
!= NULL_TREE
)
22458 dw_die_ref discr_die
= lookup_decl_die (discr_decl
);
22461 add_AT_die_ref (variant_part_die
, DW_AT_discr
, discr_die
);
22463 /* We have no DIE for the discriminant, so just discard all
22464 discrimimant information in the output. */
22465 discr_decl
= NULL_TREE
;
22468 /* If the offset for this variant part is more complex than a constant,
22469 create a DWARF procedure for it so that we will not have to generate DWARF
22470 expressions for it for each member. */
22471 if (TREE_CODE (variant_part_offset
) != INTEGER_CST
22472 && (dwarf_version
>= 3 || !dwarf_strict
))
22474 const tree dwarf_proc_fndecl
22475 = build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, NULL_TREE
,
22476 build_function_type (TREE_TYPE (variant_part_offset
),
22478 const tree dwarf_proc_call
= build_call_expr (dwarf_proc_fndecl
, 0);
22479 const dw_loc_descr_ref dwarf_proc_body
22480 = loc_descriptor_from_tree (variant_part_offset
, 0, &ctx
);
22482 dwarf_proc_die
= new_dwarf_proc_die (dwarf_proc_body
,
22483 dwarf_proc_fndecl
, context_die
);
22484 if (dwarf_proc_die
!= NULL
)
22485 variant_part_offset
= dwarf_proc_call
;
22488 /* Output DIEs for all variants. */
22490 for (tree variant
= TYPE_FIELDS (variant_part_type
);
22491 variant
!= NULL_TREE
;
22492 variant
= DECL_CHAIN (variant
), ++i
)
22494 tree variant_type
= TREE_TYPE (variant
);
22495 dw_die_ref variant_die
;
22497 /* All variants (i.e. members of a variant part) are supposed to be
22498 encoded as structures. Sub-variant parts are QUAL_UNION_TYPE fields
22499 under these records. */
22500 gcc_assert (TREE_CODE (variant_type
) == RECORD_TYPE
);
22502 variant_die
= new_die (DW_TAG_variant
, variant_part_die
, variant_type
);
22503 equate_decl_number_to_die (variant
, variant_die
);
22505 /* Output discriminant values this variant matches, if any. */
22506 if (discr_decl
== NULL
|| discr_lists
[i
] == NULL
)
22507 /* In the case we have discriminant information at all, this is
22508 probably the default variant: as the standard says, don't
22509 output any discriminant value/list attribute. */
22511 else if (discr_lists
[i
]->dw_discr_next
== NULL
22512 && !discr_lists
[i
]->dw_discr_range
)
22513 /* If there is only one accepted value, don't bother outputting a
22515 add_discr_value (variant_die
, &discr_lists
[i
]->dw_discr_lower_bound
);
22517 add_discr_list (variant_die
, discr_lists
[i
]);
22519 for (tree member
= TYPE_FIELDS (variant_type
);
22520 member
!= NULL_TREE
;
22521 member
= DECL_CHAIN (member
))
22523 struct vlr_context vlr_sub_ctx
= {
22524 vlr_ctx
->struct_type
, /* struct_type */
22525 NULL
/* variant_part_offset */
22527 if (is_variant_part (member
))
22529 /* All offsets for fields inside variant parts are relative to
22530 the top-level embedding RECORD_TYPE's base address. On the
22531 other hand, offsets in GCC's types are relative to the
22532 nested-most variant part. So we have to sum offsets each time
22535 vlr_sub_ctx
.variant_part_offset
22536 = fold (build2 (PLUS_EXPR
, TREE_TYPE (variant_part_offset
),
22537 variant_part_offset
, byte_position (member
)));
22538 gen_variant_part (member
, &vlr_sub_ctx
, variant_die
);
22542 vlr_sub_ctx
.variant_part_offset
= variant_part_offset
;
22543 gen_decl_die (member
, NULL
, &vlr_sub_ctx
, variant_die
);
22548 free (discr_lists
);
22551 /* Generate a DIE for a class member. */
22554 gen_member_die (tree type
, dw_die_ref context_die
)
22557 tree binfo
= TYPE_BINFO (type
);
22560 /* If this is not an incomplete type, output descriptions of each of its
22561 members. Note that as we output the DIEs necessary to represent the
22562 members of this record or union type, we will also be trying to output
22563 DIEs to represent the *types* of those members. However the `type'
22564 function (above) will specifically avoid generating type DIEs for member
22565 types *within* the list of member DIEs for this (containing) type except
22566 for those types (of members) which are explicitly marked as also being
22567 members of this (containing) type themselves. The g++ front- end can
22568 force any given type to be treated as a member of some other (containing)
22569 type by setting the TYPE_CONTEXT of the given (member) type to point to
22570 the TREE node representing the appropriate (containing) type. */
22572 /* First output info about the base classes. */
22575 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
22579 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
22580 gen_inheritance_die (base
,
22581 (accesses
? (*accesses
)[i
] : access_public_node
),
22586 /* Now output info about the data members and type members. */
22587 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
22589 struct vlr_context vlr_ctx
= { type
, NULL_TREE
};
22591 /* If we thought we were generating minimal debug info for TYPE
22592 and then changed our minds, some of the member declarations
22593 may have already been defined. Don't define them again, but
22594 do put them in the right order. */
22596 child
= lookup_decl_die (member
);
22598 splice_child_die (context_die
, child
);
22600 /* Do not generate standard DWARF for variant parts if we are generating
22601 the corresponding GNAT encodings: DIEs generated for both would
22602 conflict in our mappings. */
22603 else if (is_variant_part (member
)
22604 && gnat_encodings
== DWARF_GNAT_ENCODINGS_MINIMAL
)
22606 vlr_ctx
.variant_part_offset
= byte_position (member
);
22607 gen_variant_part (member
, &vlr_ctx
, context_die
);
22611 vlr_ctx
.variant_part_offset
= NULL_TREE
;
22612 gen_decl_die (member
, NULL
, &vlr_ctx
, context_die
);
22616 /* We do not keep type methods in type variants. */
22617 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
22618 /* Now output info about the function members (if any). */
22619 if (TYPE_METHODS (type
) != error_mark_node
)
22620 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
22622 /* Don't include clones in the member list. */
22623 if (DECL_ABSTRACT_ORIGIN (member
))
22625 /* Nor constructors for anonymous classes. */
22626 if (DECL_ARTIFICIAL (member
)
22627 && dwarf2_name (member
, 0) == NULL
)
22630 child
= lookup_decl_die (member
);
22632 splice_child_die (context_die
, child
);
22634 gen_decl_die (member
, NULL
, NULL
, context_die
);
22638 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
22639 is set, we pretend that the type was never defined, so we only get the
22640 member DIEs needed by later specification DIEs. */
22643 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
22644 enum debug_info_usage usage
)
22646 if (TREE_ASM_WRITTEN (type
))
22648 /* Fill in the bound of variable-length fields in late dwarf if
22649 still incomplete. */
22650 if (!early_dwarf
&& variably_modified_type_p (type
, NULL
))
22651 for (tree member
= TYPE_FIELDS (type
);
22653 member
= DECL_CHAIN (member
))
22654 fill_variable_array_bounds (TREE_TYPE (member
));
22658 dw_die_ref type_die
= lookup_type_die (type
);
22659 dw_die_ref scope_die
= 0;
22661 int complete
= (TYPE_SIZE (type
)
22662 && (! TYPE_STUB_DECL (type
)
22663 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
22664 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
22665 complete
= complete
&& should_emit_struct_debug (type
, usage
);
22667 if (type_die
&& ! complete
)
22670 if (TYPE_CONTEXT (type
) != NULL_TREE
22671 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
22672 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
22675 scope_die
= scope_die_for (type
, context_die
);
22677 /* Generate child dies for template paramaters. */
22678 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
22679 schedule_generic_params_dies_gen (type
);
22681 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
22682 /* First occurrence of type or toplevel definition of nested class. */
22684 dw_die_ref old_die
= type_die
;
22686 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
22687 ? record_type_tag (type
) : DW_TAG_union_type
,
22689 equate_type_number_to_die (type
, type_die
);
22691 add_AT_specification (type_die
, old_die
);
22693 add_name_attribute (type_die
, type_tag (type
));
22696 remove_AT (type_die
, DW_AT_declaration
);
22698 /* If this type has been completed, then give it a byte_size attribute and
22699 then give a list of members. */
22700 if (complete
&& !ns_decl
)
22702 /* Prevent infinite recursion in cases where the type of some member of
22703 this type is expressed in terms of this type itself. */
22704 TREE_ASM_WRITTEN (type
) = 1;
22705 add_byte_size_attribute (type_die
, type
);
22706 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
22708 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
22709 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
22712 /* If the first reference to this type was as the return type of an
22713 inline function, then it may not have a parent. Fix this now. */
22714 if (type_die
->die_parent
== NULL
)
22715 add_child_die (scope_die
, type_die
);
22717 push_decl_scope (type
);
22718 gen_member_die (type
, type_die
);
22721 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
22722 if (TYPE_ARTIFICIAL (type
))
22723 add_AT_flag (type_die
, DW_AT_artificial
, 1);
22725 /* GNU extension: Record what type our vtable lives in. */
22726 if (TYPE_VFIELD (type
))
22728 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
22730 gen_type_die (vtype
, context_die
);
22731 add_AT_die_ref (type_die
, DW_AT_containing_type
,
22732 lookup_type_die (vtype
));
22737 add_AT_flag (type_die
, DW_AT_declaration
, 1);
22739 /* We don't need to do this for function-local types. */
22740 if (TYPE_STUB_DECL (type
)
22741 && ! decl_function_context (TYPE_STUB_DECL (type
)))
22742 vec_safe_push (incomplete_types
, type
);
22745 if (get_AT (type_die
, DW_AT_name
))
22746 add_pubtype (type
, type_die
);
22749 /* Generate a DIE for a subroutine _type_. */
22752 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
22754 tree return_type
= TREE_TYPE (type
);
22755 dw_die_ref subr_die
22756 = new_die (DW_TAG_subroutine_type
,
22757 scope_die_for (type
, context_die
), type
);
22759 equate_type_number_to_die (type
, subr_die
);
22760 add_prototyped_attribute (subr_die
, type
);
22761 add_type_attribute (subr_die
, return_type
, TYPE_UNQUALIFIED
, false,
22763 gen_formal_types_die (type
, subr_die
);
22765 if (get_AT (subr_die
, DW_AT_name
))
22766 add_pubtype (type
, subr_die
);
22769 /* Generate a DIE for a type definition. */
22772 gen_typedef_die (tree decl
, dw_die_ref context_die
)
22774 dw_die_ref type_die
;
22777 if (TREE_ASM_WRITTEN (decl
))
22779 if (DECL_ORIGINAL_TYPE (decl
))
22780 fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl
));
22784 TREE_ASM_WRITTEN (decl
) = 1;
22785 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
22786 origin
= decl_ultimate_origin (decl
);
22787 if (origin
!= NULL
)
22788 add_abstract_origin_attribute (type_die
, origin
);
22793 add_name_and_src_coords_attributes (type_die
, decl
);
22794 if (DECL_ORIGINAL_TYPE (decl
))
22796 type
= DECL_ORIGINAL_TYPE (decl
);
22798 if (type
== error_mark_node
)
22801 gcc_assert (type
!= TREE_TYPE (decl
));
22802 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
22806 type
= TREE_TYPE (decl
);
22808 if (type
== error_mark_node
)
22811 if (is_naming_typedef_decl (TYPE_NAME (type
)))
22813 /* Here, we are in the case of decl being a typedef naming
22814 an anonymous type, e.g:
22815 typedef struct {...} foo;
22816 In that case TREE_TYPE (decl) is not a typedef variant
22817 type and TYPE_NAME of the anonymous type is set to the
22818 TYPE_DECL of the typedef. This construct is emitted by
22821 TYPE is the anonymous struct named by the typedef
22822 DECL. As we need the DW_AT_type attribute of the
22823 DW_TAG_typedef to point to the DIE of TYPE, let's
22824 generate that DIE right away. add_type_attribute
22825 called below will then pick (via lookup_type_die) that
22826 anonymous struct DIE. */
22827 if (!TREE_ASM_WRITTEN (type
))
22828 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
22830 /* This is a GNU Extension. We are adding a
22831 DW_AT_linkage_name attribute to the DIE of the
22832 anonymous struct TYPE. The value of that attribute
22833 is the name of the typedef decl naming the anonymous
22834 struct. This greatly eases the work of consumers of
22835 this debug info. */
22836 add_linkage_name_raw (lookup_type_die (type
), decl
);
22840 add_type_attribute (type_die
, type
, decl_quals (decl
), false,
22843 if (is_naming_typedef_decl (decl
))
22844 /* We want that all subsequent calls to lookup_type_die with
22845 TYPE in argument yield the DW_TAG_typedef we have just
22847 equate_type_number_to_die (type
, type_die
);
22849 add_accessibility_attribute (type_die
, decl
);
22852 if (DECL_ABSTRACT_P (decl
))
22853 equate_decl_number_to_die (decl
, type_die
);
22855 if (get_AT (type_die
, DW_AT_name
))
22856 add_pubtype (decl
, type_die
);
22859 /* Generate a DIE for a struct, class, enum or union type. */
22862 gen_tagged_type_die (tree type
,
22863 dw_die_ref context_die
,
22864 enum debug_info_usage usage
)
22868 if (type
== NULL_TREE
22869 || !is_tagged_type (type
))
22872 if (TREE_ASM_WRITTEN (type
))
22874 /* If this is a nested type whose containing class hasn't been written
22875 out yet, writing it out will cover this one, too. This does not apply
22876 to instantiations of member class templates; they need to be added to
22877 the containing class as they are generated. FIXME: This hurts the
22878 idea of combining type decls from multiple TUs, since we can't predict
22879 what set of template instantiations we'll get. */
22880 else if (TYPE_CONTEXT (type
)
22881 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
22882 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
22884 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
22886 if (TREE_ASM_WRITTEN (type
))
22889 /* If that failed, attach ourselves to the stub. */
22890 push_decl_scope (TYPE_CONTEXT (type
));
22891 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
22894 else if (TYPE_CONTEXT (type
) != NULL_TREE
22895 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
22897 /* If this type is local to a function that hasn't been written
22898 out yet, use a NULL context for now; it will be fixed up in
22899 decls_for_scope. */
22900 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
22901 /* A declaration DIE doesn't count; nested types need to go in the
22903 if (context_die
&& is_declaration_die (context_die
))
22904 context_die
= NULL
;
22909 context_die
= declare_in_namespace (type
, context_die
);
22913 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
22915 /* This might have been written out by the call to
22916 declare_in_namespace. */
22917 if (!TREE_ASM_WRITTEN (type
))
22918 gen_enumeration_type_die (type
, context_die
);
22921 gen_struct_or_union_type_die (type
, context_die
, usage
);
22926 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
22927 it up if it is ever completed. gen_*_type_die will set it for us
22928 when appropriate. */
22931 /* Generate a type description DIE. */
22934 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
22935 enum debug_info_usage usage
)
22937 struct array_descr_info info
;
22939 if (type
== NULL_TREE
|| type
== error_mark_node
)
22942 if (flag_checking
&& type
)
22943 verify_type (type
);
22945 if (TYPE_NAME (type
) != NULL_TREE
22946 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
22947 && is_redundant_typedef (TYPE_NAME (type
))
22948 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
22949 /* The DECL of this type is a typedef we don't want to emit debug
22950 info for but we want debug info for its underlying typedef.
22951 This can happen for e.g, the injected-class-name of a C++
22953 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
22955 /* If TYPE is a typedef type variant, let's generate debug info
22956 for the parent typedef which TYPE is a type of. */
22957 if (typedef_variant_p (type
))
22959 if (TREE_ASM_WRITTEN (type
))
22962 /* Prevent broken recursion; we can't hand off to the same type. */
22963 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
22965 /* Give typedefs the right scope. */
22966 context_die
= scope_die_for (type
, context_die
);
22968 TREE_ASM_WRITTEN (type
) = 1;
22970 gen_decl_die (TYPE_NAME (type
), NULL
, NULL
, context_die
);
22974 /* If type is an anonymous tagged type named by a typedef, let's
22975 generate debug info for the typedef. */
22976 if (is_naming_typedef_decl (TYPE_NAME (type
)))
22978 /* Use the DIE of the containing namespace as the parent DIE of
22979 the type description DIE we want to generate. */
22980 if (DECL_CONTEXT (TYPE_NAME (type
))
22981 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
22982 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
22984 gen_decl_die (TYPE_NAME (type
), NULL
, NULL
, context_die
);
22988 /* We are going to output a DIE to represent the unqualified version
22989 of this type (i.e. without any const or volatile qualifiers) so
22990 get the main variant (i.e. the unqualified version) of this type
22991 now. (Vectors and arrays are special because the debugging info is in the
22992 cloned type itself). */
22993 if (TREE_CODE (type
) != VECTOR_TYPE
22994 && TREE_CODE (type
) != ARRAY_TYPE
)
22995 type
= type_main_variant (type
);
22997 /* If this is an array type with hidden descriptor, handle it first. */
22998 if (!TREE_ASM_WRITTEN (type
)
22999 && lang_hooks
.types
.get_array_descr_info
)
23001 memset (&info
, 0, sizeof (info
));
23002 if (lang_hooks
.types
.get_array_descr_info (type
, &info
))
23004 /* Fortran sometimes emits array types with no dimension. */
23005 gcc_assert (info
.ndimensions
>= 0
23006 && (info
.ndimensions
23007 <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN
));
23008 gen_descr_array_type_die (type
, &info
, context_die
);
23009 TREE_ASM_WRITTEN (type
) = 1;
23014 if (TREE_ASM_WRITTEN (type
))
23016 /* Variable-length types may be incomplete even if
23017 TREE_ASM_WRITTEN. For such types, fall through to
23018 gen_array_type_die() and possibly fill in
23019 DW_AT_{upper,lower}_bound attributes. */
23020 if ((TREE_CODE (type
) != ARRAY_TYPE
23021 && TREE_CODE (type
) != RECORD_TYPE
23022 && TREE_CODE (type
) != UNION_TYPE
23023 && TREE_CODE (type
) != QUAL_UNION_TYPE
)
23024 || !variably_modified_type_p (type
, NULL
))
23028 switch (TREE_CODE (type
))
23034 case REFERENCE_TYPE
:
23035 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
23036 ensures that the gen_type_die recursion will terminate even if the
23037 type is recursive. Recursive types are possible in Ada. */
23038 /* ??? We could perhaps do this for all types before the switch
23040 TREE_ASM_WRITTEN (type
) = 1;
23042 /* For these types, all that is required is that we output a DIE (or a
23043 set of DIEs) to represent the "basis" type. */
23044 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
23045 DINFO_USAGE_IND_USE
);
23049 /* This code is used for C++ pointer-to-data-member types.
23050 Output a description of the relevant class type. */
23051 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
23052 DINFO_USAGE_IND_USE
);
23054 /* Output a description of the type of the object pointed to. */
23055 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
23056 DINFO_USAGE_IND_USE
);
23058 /* Now output a DIE to represent this pointer-to-data-member type
23060 gen_ptr_to_mbr_type_die (type
, context_die
);
23063 case FUNCTION_TYPE
:
23064 /* Force out return type (in case it wasn't forced out already). */
23065 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
23066 DINFO_USAGE_DIR_USE
);
23067 gen_subroutine_type_die (type
, context_die
);
23071 /* Force out return type (in case it wasn't forced out already). */
23072 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
23073 DINFO_USAGE_DIR_USE
);
23074 gen_subroutine_type_die (type
, context_die
);
23079 gen_array_type_die (type
, context_die
);
23082 case ENUMERAL_TYPE
:
23085 case QUAL_UNION_TYPE
:
23086 gen_tagged_type_die (type
, context_die
, usage
);
23092 case FIXED_POINT_TYPE
:
23095 case POINTER_BOUNDS_TYPE
:
23096 /* No DIEs needed for fundamental types. */
23101 /* Just use DW_TAG_unspecified_type. */
23103 dw_die_ref type_die
= lookup_type_die (type
);
23104 if (type_die
== NULL
)
23106 tree name
= TYPE_IDENTIFIER (type
);
23107 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (),
23109 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
23110 equate_type_number_to_die (type
, type_die
);
23116 if (is_cxx_auto (type
))
23118 tree name
= TYPE_IDENTIFIER (type
);
23119 dw_die_ref
*die
= (name
== get_identifier ("auto")
23120 ? &auto_die
: &decltype_auto_die
);
23123 *die
= new_die (DW_TAG_unspecified_type
,
23124 comp_unit_die (), NULL_TREE
);
23125 add_name_attribute (*die
, IDENTIFIER_POINTER (name
));
23127 equate_type_number_to_die (type
, *die
);
23130 gcc_unreachable ();
23133 TREE_ASM_WRITTEN (type
) = 1;
23137 gen_type_die (tree type
, dw_die_ref context_die
)
23139 if (type
!= error_mark_node
)
23141 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
23144 dw_die_ref die
= lookup_type_die (type
);
23151 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
23152 things which are local to the given block. */
23155 gen_block_die (tree stmt
, dw_die_ref context_die
)
23157 int must_output_die
= 0;
23160 /* Ignore blocks that are NULL. */
23161 if (stmt
== NULL_TREE
)
23164 inlined_func
= inlined_function_outer_scope_p (stmt
);
23166 /* If the block is one fragment of a non-contiguous block, do not
23167 process the variables, since they will have been done by the
23168 origin block. Do process subblocks. */
23169 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
23173 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
23174 gen_block_die (sub
, context_die
);
23179 /* Determine if we need to output any Dwarf DIEs at all to represent this
23182 /* The outer scopes for inlinings *must* always be represented. We
23183 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
23184 must_output_die
= 1;
23187 /* Determine if this block directly contains any "significant"
23188 local declarations which we will need to output DIEs for. */
23189 if (debug_info_level
> DINFO_LEVEL_TERSE
)
23190 /* We are not in terse mode so *any* local declaration counts
23191 as being a "significant" one. */
23192 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
23193 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
23194 && (TREE_USED (stmt
)
23195 || TREE_ASM_WRITTEN (stmt
)
23196 || BLOCK_ABSTRACT (stmt
)));
23197 else if ((TREE_USED (stmt
)
23198 || TREE_ASM_WRITTEN (stmt
)
23199 || BLOCK_ABSTRACT (stmt
))
23200 && !dwarf2out_ignore_block (stmt
))
23201 must_output_die
= 1;
23204 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
23205 DIE for any block which contains no significant local declarations at
23206 all. Rather, in such cases we just call `decls_for_scope' so that any
23207 needed Dwarf info for any sub-blocks will get properly generated. Note
23208 that in terse mode, our definition of what constitutes a "significant"
23209 local declaration gets restricted to include only inlined function
23210 instances and local (nested) function definitions. */
23211 if (must_output_die
)
23215 /* If STMT block is abstract, that means we have been called
23216 indirectly from dwarf2out_abstract_function.
23217 That function rightfully marks the descendent blocks (of
23218 the abstract function it is dealing with) as being abstract,
23219 precisely to prevent us from emitting any
23220 DW_TAG_inlined_subroutine DIE as a descendent
23221 of an abstract function instance. So in that case, we should
23222 not call gen_inlined_subroutine_die.
23224 Later though, when cgraph asks dwarf2out to emit info
23225 for the concrete instance of the function decl into which
23226 the concrete instance of STMT got inlined, the later will lead
23227 to the generation of a DW_TAG_inlined_subroutine DIE. */
23228 if (! BLOCK_ABSTRACT (stmt
))
23229 gen_inlined_subroutine_die (stmt
, context_die
);
23232 gen_lexical_block_die (stmt
, context_die
);
23235 decls_for_scope (stmt
, context_die
);
23238 /* Process variable DECL (or variable with origin ORIGIN) within
23239 block STMT and add it to CONTEXT_DIE. */
23241 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
23244 tree decl_or_origin
= decl
? decl
: origin
;
23246 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
23247 die
= lookup_decl_die (decl_or_origin
);
23248 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
23249 && TYPE_DECL_IS_STUB (decl_or_origin
))
23250 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
23254 if (die
!= NULL
&& die
->die_parent
== NULL
)
23255 add_child_die (context_die
, die
);
23256 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
23259 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
23260 stmt
, context_die
);
23263 gen_decl_die (decl
, origin
, NULL
, context_die
);
23266 /* Generate all of the decls declared within a given scope and (recursively)
23267 all of its sub-blocks. */
23270 decls_for_scope (tree stmt
, dw_die_ref context_die
)
23276 /* Ignore NULL blocks. */
23277 if (stmt
== NULL_TREE
)
23280 /* Output the DIEs to represent all of the data objects and typedefs
23281 declared directly within this block but not within any nested
23282 sub-blocks. Also, nested function and tag DIEs have been
23283 generated with a parent of NULL; fix that up now. We don't
23284 have to do this if we're at -g1. */
23285 if (debug_info_level
> DINFO_LEVEL_TERSE
)
23287 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
23288 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
23289 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
23290 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
23294 /* Even if we're at -g1, we need to process the subblocks in order to get
23295 inlined call information. */
23297 /* Output the DIEs to represent all sub-blocks (and the items declared
23298 therein) of this block. */
23299 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
23301 subblocks
= BLOCK_CHAIN (subblocks
))
23302 gen_block_die (subblocks
, context_die
);
23305 /* Is this a typedef we can avoid emitting? */
23308 is_redundant_typedef (const_tree decl
)
23310 if (TYPE_DECL_IS_STUB (decl
))
23313 if (DECL_ARTIFICIAL (decl
)
23314 && DECL_CONTEXT (decl
)
23315 && is_tagged_type (DECL_CONTEXT (decl
))
23316 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
23317 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
23318 /* Also ignore the artificial member typedef for the class name. */
23324 /* Return TRUE if TYPE is a typedef that names a type for linkage
23325 purposes. This kind of typedefs is produced by the C++ FE for
23328 typedef struct {...} foo;
23330 In that case, there is no typedef variant type produced for foo.
23331 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
23335 is_naming_typedef_decl (const_tree decl
)
23337 if (decl
== NULL_TREE
23338 || TREE_CODE (decl
) != TYPE_DECL
23339 || DECL_NAMELESS (decl
)
23340 || !is_tagged_type (TREE_TYPE (decl
))
23341 || DECL_IS_BUILTIN (decl
)
23342 || is_redundant_typedef (decl
)
23343 /* It looks like Ada produces TYPE_DECLs that are very similar
23344 to C++ naming typedefs but that have different
23345 semantics. Let's be specific to c++ for now. */
23349 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
23350 && TYPE_NAME (TREE_TYPE (decl
)) == decl
23351 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
23352 != TYPE_NAME (TREE_TYPE (decl
))));
23355 /* Looks up the DIE for a context. */
23357 static inline dw_die_ref
23358 lookup_context_die (tree context
)
23362 /* Find die that represents this context. */
23363 if (TYPE_P (context
))
23365 context
= TYPE_MAIN_VARIANT (context
);
23366 dw_die_ref ctx
= lookup_type_die (context
);
23369 return strip_naming_typedef (context
, ctx
);
23372 return lookup_decl_die (context
);
23374 return comp_unit_die ();
23377 /* Returns the DIE for a context. */
23379 static inline dw_die_ref
23380 get_context_die (tree context
)
23384 /* Find die that represents this context. */
23385 if (TYPE_P (context
))
23387 context
= TYPE_MAIN_VARIANT (context
);
23388 return strip_naming_typedef (context
, force_type_die (context
));
23391 return force_decl_die (context
);
23393 return comp_unit_die ();
23396 /* Returns the DIE for decl. A DIE will always be returned. */
23399 force_decl_die (tree decl
)
23401 dw_die_ref decl_die
;
23402 unsigned saved_external_flag
;
23403 tree save_fn
= NULL_TREE
;
23404 decl_die
= lookup_decl_die (decl
);
23407 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
23409 decl_die
= lookup_decl_die (decl
);
23413 switch (TREE_CODE (decl
))
23415 case FUNCTION_DECL
:
23416 /* Clear current_function_decl, so that gen_subprogram_die thinks
23417 that this is a declaration. At this point, we just want to force
23418 declaration die. */
23419 save_fn
= current_function_decl
;
23420 current_function_decl
= NULL_TREE
;
23421 gen_subprogram_die (decl
, context_die
);
23422 current_function_decl
= save_fn
;
23426 /* Set external flag to force declaration die. Restore it after
23427 gen_decl_die() call. */
23428 saved_external_flag
= DECL_EXTERNAL (decl
);
23429 DECL_EXTERNAL (decl
) = 1;
23430 gen_decl_die (decl
, NULL
, NULL
, context_die
);
23431 DECL_EXTERNAL (decl
) = saved_external_flag
;
23434 case NAMESPACE_DECL
:
23435 if (dwarf_version
>= 3 || !dwarf_strict
)
23436 dwarf2out_decl (decl
);
23438 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
23439 decl_die
= comp_unit_die ();
23442 case TRANSLATION_UNIT_DECL
:
23443 decl_die
= comp_unit_die ();
23447 gcc_unreachable ();
23450 /* We should be able to find the DIE now. */
23452 decl_die
= lookup_decl_die (decl
);
23453 gcc_assert (decl_die
);
23459 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
23460 always returned. */
23463 force_type_die (tree type
)
23465 dw_die_ref type_die
;
23467 type_die
= lookup_type_die (type
);
23470 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
23472 type_die
= modified_type_die (type
, TYPE_QUALS_NO_ADDR_SPACE (type
),
23473 false, context_die
);
23474 gcc_assert (type_die
);
23479 /* Force out any required namespaces to be able to output DECL,
23480 and return the new context_die for it, if it's changed. */
23483 setup_namespace_context (tree thing
, dw_die_ref context_die
)
23485 tree context
= (DECL_P (thing
)
23486 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
23487 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
23488 /* Force out the namespace. */
23489 context_die
= force_decl_die (context
);
23491 return context_die
;
23494 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
23495 type) within its namespace, if appropriate.
23497 For compatibility with older debuggers, namespace DIEs only contain
23498 declarations; all definitions are emitted at CU scope, with
23499 DW_AT_specification pointing to the declaration (like with class
23503 declare_in_namespace (tree thing
, dw_die_ref context_die
)
23505 dw_die_ref ns_context
;
23507 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
23508 return context_die
;
23510 /* External declarations in the local scope only need to be emitted
23511 once, not once in the namespace and once in the scope.
23513 This avoids declaring the `extern' below in the
23514 namespace DIE as well as in the innermost scope:
23527 if (DECL_P (thing
) && DECL_EXTERNAL (thing
) && local_scope_p (context_die
))
23528 return context_die
;
23530 /* If this decl is from an inlined function, then don't try to emit it in its
23531 namespace, as we will get confused. It would have already been emitted
23532 when the abstract instance of the inline function was emitted anyways. */
23533 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
23534 return context_die
;
23536 ns_context
= setup_namespace_context (thing
, context_die
);
23538 if (ns_context
!= context_die
)
23542 if (DECL_P (thing
))
23543 gen_decl_die (thing
, NULL
, NULL
, ns_context
);
23545 gen_type_die (thing
, ns_context
);
23547 return context_die
;
23550 /* Generate a DIE for a namespace or namespace alias. */
23553 gen_namespace_die (tree decl
, dw_die_ref context_die
)
23555 dw_die_ref namespace_die
;
23557 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
23558 they are an alias of. */
23559 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
23561 /* Output a real namespace or module. */
23562 context_die
= setup_namespace_context (decl
, comp_unit_die ());
23563 namespace_die
= new_die (is_fortran ()
23564 ? DW_TAG_module
: DW_TAG_namespace
,
23565 context_die
, decl
);
23566 /* For Fortran modules defined in different CU don't add src coords. */
23567 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
23569 const char *name
= dwarf2_name (decl
, 0);
23571 add_name_attribute (namespace_die
, name
);
23574 add_name_and_src_coords_attributes (namespace_die
, decl
);
23575 if (DECL_EXTERNAL (decl
))
23576 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
23577 equate_decl_number_to_die (decl
, namespace_die
);
23581 /* Output a namespace alias. */
23583 /* Force out the namespace we are an alias of, if necessary. */
23584 dw_die_ref origin_die
23585 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
23587 if (DECL_FILE_SCOPE_P (decl
)
23588 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
23589 context_die
= setup_namespace_context (decl
, comp_unit_die ());
23590 /* Now create the namespace alias DIE. */
23591 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
23592 add_name_and_src_coords_attributes (namespace_die
, decl
);
23593 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
23594 equate_decl_number_to_die (decl
, namespace_die
);
23596 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
23597 if (want_pubnames ())
23598 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
23601 /* Generate Dwarf debug information for a decl described by DECL.
23602 The return value is currently only meaningful for PARM_DECLs,
23603 for all other decls it returns NULL.
23605 If DECL is a FIELD_DECL, CTX is required: see the comment for VLR_CONTEXT.
23606 It can be NULL otherwise. */
23609 gen_decl_die (tree decl
, tree origin
, struct vlr_context
*ctx
,
23610 dw_die_ref context_die
)
23612 tree decl_or_origin
= decl
? decl
: origin
;
23613 tree class_origin
= NULL
, ultimate_origin
;
23615 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
23618 /* Ignore pointer bounds decls. */
23619 if (DECL_P (decl_or_origin
)
23620 && TREE_TYPE (decl_or_origin
)
23621 && POINTER_BOUNDS_P (decl_or_origin
))
23624 switch (TREE_CODE (decl_or_origin
))
23630 if (!is_fortran () && !is_ada ())
23632 /* The individual enumerators of an enum type get output when we output
23633 the Dwarf representation of the relevant enum type itself. */
23637 /* Emit its type. */
23638 gen_type_die (TREE_TYPE (decl
), context_die
);
23640 /* And its containing namespace. */
23641 context_die
= declare_in_namespace (decl
, context_die
);
23643 gen_const_die (decl
, context_die
);
23646 case FUNCTION_DECL
:
23647 /* Don't output any DIEs to represent mere function declarations,
23648 unless they are class members or explicit block externs. */
23649 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
23650 && DECL_FILE_SCOPE_P (decl_or_origin
)
23651 && (current_function_decl
== NULL_TREE
23652 || DECL_ARTIFICIAL (decl_or_origin
)))
23657 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
23658 on local redeclarations of global functions. That seems broken. */
23659 if (current_function_decl
!= decl
)
23660 /* This is only a declaration. */;
23663 /* If we're emitting a clone, emit info for the abstract instance. */
23664 if (origin
|| DECL_ORIGIN (decl
) != decl
)
23665 dwarf2out_abstract_function (origin
23666 ? DECL_ORIGIN (origin
)
23667 : DECL_ABSTRACT_ORIGIN (decl
));
23669 /* If we're emitting an out-of-line copy of an inline function,
23670 emit info for the abstract instance and set up to refer to it. */
23671 else if (cgraph_function_possibly_inlined_p (decl
)
23672 && ! DECL_ABSTRACT_P (decl
)
23673 && ! class_or_namespace_scope_p (context_die
)
23674 /* dwarf2out_abstract_function won't emit a die if this is just
23675 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
23676 that case, because that works only if we have a die. */
23677 && DECL_INITIAL (decl
) != NULL_TREE
)
23679 dwarf2out_abstract_function (decl
);
23680 set_decl_origin_self (decl
);
23683 /* Otherwise we're emitting the primary DIE for this decl. */
23684 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
23686 /* Before we describe the FUNCTION_DECL itself, make sure that we
23687 have its containing type. */
23689 origin
= decl_class_context (decl
);
23690 if (origin
!= NULL_TREE
)
23691 gen_type_die (origin
, context_die
);
23693 /* And its return type. */
23694 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
23696 /* And its virtual context. */
23697 if (DECL_VINDEX (decl
) != NULL_TREE
)
23698 gen_type_die (DECL_CONTEXT (decl
), context_die
);
23700 /* Make sure we have a member DIE for decl. */
23701 if (origin
!= NULL_TREE
)
23702 gen_type_die_for_member (origin
, decl
, context_die
);
23704 /* And its containing namespace. */
23705 context_die
= declare_in_namespace (decl
, context_die
);
23708 /* Now output a DIE to represent the function itself. */
23710 gen_subprogram_die (decl
, context_die
);
23714 /* If we are in terse mode, don't generate any DIEs to represent any
23715 actual typedefs. */
23716 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
23719 /* In the special case of a TYPE_DECL node representing the declaration
23720 of some type tag, if the given TYPE_DECL is marked as having been
23721 instantiated from some other (original) TYPE_DECL node (e.g. one which
23722 was generated within the original definition of an inline function) we
23723 used to generate a special (abbreviated) DW_TAG_structure_type,
23724 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
23725 should be actually referencing those DIEs, as variable DIEs with that
23726 type would be emitted already in the abstract origin, so it was always
23727 removed during unused type prunning. Don't add anything in this
23729 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
23732 if (is_redundant_typedef (decl
))
23733 gen_type_die (TREE_TYPE (decl
), context_die
);
23735 /* Output a DIE to represent the typedef itself. */
23736 gen_typedef_die (decl
, context_die
);
23740 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
23741 gen_label_die (decl
, context_die
);
23746 /* If we are in terse mode, don't generate any DIEs to represent any
23747 variable declarations or definitions. */
23748 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
23751 /* Output any DIEs that are needed to specify the type of this data
23753 if (decl_by_reference_p (decl_or_origin
))
23754 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
23756 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
23758 /* And its containing type. */
23759 class_origin
= decl_class_context (decl_or_origin
);
23760 if (class_origin
!= NULL_TREE
)
23761 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
23763 /* And its containing namespace. */
23764 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
23766 /* Now output the DIE to represent the data object itself. This gets
23767 complicated because of the possibility that the VAR_DECL really
23768 represents an inlined instance of a formal parameter for an inline
23770 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
23771 if (ultimate_origin
!= NULL_TREE
23772 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
23773 gen_formal_parameter_die (decl
, origin
,
23774 true /* Emit name attribute. */,
23777 gen_variable_die (decl
, origin
, context_die
);
23781 gcc_assert (ctx
!= NULL
&& ctx
->struct_type
!= NULL
);
23782 /* Ignore the nameless fields that are used to skip bits but handle C++
23783 anonymous unions and structs. */
23784 if (DECL_NAME (decl
) != NULL_TREE
23785 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
23786 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
23788 gen_type_die (member_declared_type (decl
), context_die
);
23789 gen_field_die (decl
, ctx
, context_die
);
23794 if (DECL_BY_REFERENCE (decl_or_origin
))
23795 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
23797 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
23798 return gen_formal_parameter_die (decl
, origin
,
23799 true /* Emit name attribute. */,
23802 case NAMESPACE_DECL
:
23803 if (dwarf_version
>= 3 || !dwarf_strict
)
23804 gen_namespace_die (decl
, context_die
);
23807 case IMPORTED_DECL
:
23808 dwarf2out_imported_module_or_decl_1 (decl
, DECL_NAME (decl
),
23809 DECL_CONTEXT (decl
), context_die
);
23812 case NAMELIST_DECL
:
23813 gen_namelist_decl (DECL_NAME (decl
), context_die
,
23814 NAMELIST_DECL_ASSOCIATED_DECL (decl
));
23818 /* Probably some frontend-internal decl. Assume we don't care. */
23819 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
23826 /* Output initial debug information for global DECL. Called at the
23827 end of the parsing process.
23829 This is the initial debug generation process. As such, the DIEs
23830 generated may be incomplete. A later debug generation pass
23831 (dwarf2out_late_global_decl) will augment the information generated
23832 in this pass (e.g., with complete location info). */
23835 dwarf2out_early_global_decl (tree decl
)
23839 /* gen_decl_die() will set DECL_ABSTRACT because
23840 cgraph_function_possibly_inlined_p() returns true. This is in
23841 turn will cause DW_AT_inline attributes to be set.
23843 This happens because at early dwarf generation, there is no
23844 cgraph information, causing cgraph_function_possibly_inlined_p()
23845 to return true. Trick cgraph_function_possibly_inlined_p()
23846 while we generate dwarf early. */
23847 bool save
= symtab
->global_info_ready
;
23848 symtab
->global_info_ready
= true;
23850 /* We don't handle TYPE_DECLs. If required, they'll be reached via
23851 other DECLs and they can point to template types or other things
23852 that dwarf2out can't handle when done via dwarf2out_decl. */
23853 if (TREE_CODE (decl
) != TYPE_DECL
23854 && TREE_CODE (decl
) != PARM_DECL
)
23856 tree save_fndecl
= current_function_decl
;
23857 if (TREE_CODE (decl
) == FUNCTION_DECL
)
23859 /* No cfun means the symbol has no body, so there's nothing
23861 if (!DECL_STRUCT_FUNCTION (decl
))
23862 goto early_decl_exit
;
23864 current_function_decl
= decl
;
23866 dwarf2out_decl (decl
);
23867 if (TREE_CODE (decl
) == FUNCTION_DECL
)
23868 current_function_decl
= save_fndecl
;
23871 symtab
->global_info_ready
= save
;
23874 /* Output debug information for global decl DECL. Called from
23875 toplev.c after compilation proper has finished. */
23878 dwarf2out_late_global_decl (tree decl
)
23880 /* We have to generate early debug late for LTO. */
23882 dwarf2out_early_global_decl (decl
);
23884 /* Fill-in any location information we were unable to determine
23885 on the first pass. */
23886 if (TREE_CODE (decl
) == VAR_DECL
23887 && !POINTER_BOUNDS_P (decl
))
23889 dw_die_ref die
= lookup_decl_die (decl
);
23891 add_location_or_const_value_attribute (die
, decl
, false);
23895 /* Output debug information for type decl DECL. Called from toplev.c
23896 and from language front ends (to record built-in types). */
23898 dwarf2out_type_decl (tree decl
, int local
)
23903 dwarf2out_decl (decl
);
23907 /* Output debug information for imported module or decl DECL.
23908 NAME is non-NULL name in the lexical block if the decl has been renamed.
23909 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
23910 that DECL belongs to.
23911 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
23913 dwarf2out_imported_module_or_decl_1 (tree decl
,
23915 tree lexical_block
,
23916 dw_die_ref lexical_block_die
)
23918 expanded_location xloc
;
23919 dw_die_ref imported_die
= NULL
;
23920 dw_die_ref at_import_die
;
23922 if (TREE_CODE (decl
) == IMPORTED_DECL
)
23924 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
23925 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
23929 xloc
= expand_location (input_location
);
23931 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
23933 at_import_die
= force_type_die (TREE_TYPE (decl
));
23934 /* For namespace N { typedef void T; } using N::T; base_type_die
23935 returns NULL, but DW_TAG_imported_declaration requires
23936 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
23937 if (!at_import_die
)
23939 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
23940 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
23941 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
23942 gcc_assert (at_import_die
);
23947 at_import_die
= lookup_decl_die (decl
);
23948 if (!at_import_die
)
23950 /* If we're trying to avoid duplicate debug info, we may not have
23951 emitted the member decl for this field. Emit it now. */
23952 if (TREE_CODE (decl
) == FIELD_DECL
)
23954 tree type
= DECL_CONTEXT (decl
);
23956 if (TYPE_CONTEXT (type
)
23957 && TYPE_P (TYPE_CONTEXT (type
))
23958 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
23959 DINFO_USAGE_DIR_USE
))
23961 gen_type_die_for_member (type
, decl
,
23962 get_context_die (TYPE_CONTEXT (type
)));
23964 if (TREE_CODE (decl
) == NAMELIST_DECL
)
23965 at_import_die
= gen_namelist_decl (DECL_NAME (decl
),
23966 get_context_die (DECL_CONTEXT (decl
)),
23969 at_import_die
= force_decl_die (decl
);
23973 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
23975 if (dwarf_version
>= 3 || !dwarf_strict
)
23976 imported_die
= new_die (DW_TAG_imported_module
,
23983 imported_die
= new_die (DW_TAG_imported_declaration
,
23987 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
23988 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
23990 add_AT_string (imported_die
, DW_AT_name
,
23991 IDENTIFIER_POINTER (name
));
23992 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
23995 /* Output debug information for imported module or decl DECL.
23996 NAME is non-NULL name in context if the decl has been renamed.
23997 CHILD is true if decl is one of the renamed decls as part of
23998 importing whole module. */
24001 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
24004 /* dw_die_ref at_import_die; */
24005 dw_die_ref scope_die
;
24007 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
24014 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
24015 We need decl DIE for reference and scope die. First, get DIE for the decl
24018 /* Get the scope die for decl context. Use comp_unit_die for global module
24019 or decl. If die is not found for non globals, force new die. */
24021 && TYPE_P (context
)
24022 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
24025 if (!(dwarf_version
>= 3 || !dwarf_strict
))
24028 scope_die
= get_context_die (context
);
24032 gcc_assert (scope_die
->die_child
);
24033 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
24034 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
24035 scope_die
= scope_die
->die_child
;
24038 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
24039 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
24042 /* Output debug information for namelists. */
24045 gen_namelist_decl (tree name
, dw_die_ref scope_die
, tree item_decls
)
24047 dw_die_ref nml_die
, nml_item_die
, nml_item_ref_die
;
24051 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
24054 gcc_assert (scope_die
!= NULL
);
24055 nml_die
= new_die (DW_TAG_namelist
, scope_die
, NULL
);
24056 add_AT_string (nml_die
, DW_AT_name
, IDENTIFIER_POINTER (name
));
24058 /* If there are no item_decls, we have a nondefining namelist, e.g.
24059 with USE association; hence, set DW_AT_declaration. */
24060 if (item_decls
== NULL_TREE
)
24062 add_AT_flag (nml_die
, DW_AT_declaration
, 1);
24066 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls
), i
, value
)
24068 nml_item_ref_die
= lookup_decl_die (value
);
24069 if (!nml_item_ref_die
)
24070 nml_item_ref_die
= force_decl_die (value
);
24072 nml_item_die
= new_die (DW_TAG_namelist_item
, nml_die
, NULL
);
24073 add_AT_die_ref (nml_item_die
, DW_AT_namelist_items
, nml_item_ref_die
);
24079 /* Write the debugging output for DECL and return the DIE. */
24082 dwarf2out_decl (tree decl
)
24084 dw_die_ref context_die
= comp_unit_die ();
24086 switch (TREE_CODE (decl
))
24091 case FUNCTION_DECL
:
24092 /* What we would really like to do here is to filter out all mere
24093 file-scope declarations of file-scope functions which are never
24094 referenced later within this translation unit (and keep all of ones
24095 that *are* referenced later on) but we aren't clairvoyant, so we have
24096 no idea which functions will be referenced in the future (i.e. later
24097 on within the current translation unit). So here we just ignore all
24098 file-scope function declarations which are not also definitions. If
24099 and when the debugger needs to know something about these functions,
24100 it will have to hunt around and find the DWARF information associated
24101 with the definition of the function.
24103 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
24104 nodes represent definitions and which ones represent mere
24105 declarations. We have to check DECL_INITIAL instead. That's because
24106 the C front-end supports some weird semantics for "extern inline"
24107 function definitions. These can get inlined within the current
24108 translation unit (and thus, we need to generate Dwarf info for their
24109 abstract instances so that the Dwarf info for the concrete inlined
24110 instances can have something to refer to) but the compiler never
24111 generates any out-of-lines instances of such things (despite the fact
24112 that they *are* definitions).
24114 The important point is that the C front-end marks these "extern
24115 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
24116 them anyway. Note that the C++ front-end also plays some similar games
24117 for inline function definitions appearing within include files which
24118 also contain `#pragma interface' pragmas.
24120 If we are called from dwarf2out_abstract_function output a DIE
24121 anyway. We can end up here this way with early inlining and LTO
24122 where the inlined function is output in a different LTRANS unit
24124 if (DECL_INITIAL (decl
) == NULL_TREE
24125 && ! DECL_ABSTRACT_P (decl
))
24128 /* If we're a nested function, initially use a parent of NULL; if we're
24129 a plain function, this will be fixed up in decls_for_scope. If
24130 we're a method, it will be ignored, since we already have a DIE. */
24131 if (decl_function_context (decl
)
24132 /* But if we're in terse mode, we don't care about scope. */
24133 && debug_info_level
> DINFO_LEVEL_TERSE
)
24134 context_die
= NULL
;
24138 /* For local statics lookup proper context die. */
24139 if (local_function_static (decl
))
24140 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
24142 /* If we are in terse mode, don't generate any DIEs to represent any
24143 variable declarations or definitions. */
24144 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
24149 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
24151 if (!is_fortran () && !is_ada ())
24153 if (TREE_STATIC (decl
) && decl_function_context (decl
))
24154 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
24157 case NAMESPACE_DECL
:
24158 case IMPORTED_DECL
:
24159 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
24161 if (lookup_decl_die (decl
) != NULL
)
24166 /* Don't emit stubs for types unless they are needed by other DIEs. */
24167 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
24170 /* Don't bother trying to generate any DIEs to represent any of the
24171 normal built-in types for the language we are compiling. */
24172 if (DECL_IS_BUILTIN (decl
))
24175 /* If we are in terse mode, don't generate any DIEs for types. */
24176 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
24179 /* If we're a function-scope tag, initially use a parent of NULL;
24180 this will be fixed up in decls_for_scope. */
24181 if (decl_function_context (decl
))
24182 context_die
= NULL
;
24186 case NAMELIST_DECL
:
24193 gen_decl_die (decl
, NULL
, NULL
, context_die
);
24197 dw_die_ref die
= lookup_decl_die (decl
);
24203 /* Write the debugging output for DECL. */
24206 dwarf2out_function_decl (tree decl
)
24208 dwarf2out_decl (decl
);
24209 call_arg_locations
= NULL
;
24210 call_arg_loc_last
= NULL
;
24211 call_site_count
= -1;
24212 tail_call_site_count
= -1;
24213 decl_loc_table
->empty ();
24214 cached_dw_loc_list_table
->empty ();
24217 /* Output a marker (i.e. a label) for the beginning of the generated code for
24218 a lexical block. */
24221 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
24222 unsigned int blocknum
)
24224 switch_to_section (current_function_section ());
24225 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
24228 /* Output a marker (i.e. a label) for the end of the generated code for a
24232 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
24234 switch_to_section (current_function_section ());
24235 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
24238 /* Returns nonzero if it is appropriate not to emit any debugging
24239 information for BLOCK, because it doesn't contain any instructions.
24241 Don't allow this for blocks with nested functions or local classes
24242 as we would end up with orphans, and in the presence of scheduling
24243 we may end up calling them anyway. */
24246 dwarf2out_ignore_block (const_tree block
)
24251 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
24252 if (TREE_CODE (decl
) == FUNCTION_DECL
24253 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
24255 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
24257 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
24258 if (TREE_CODE (decl
) == FUNCTION_DECL
24259 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
24266 /* Hash table routines for file_hash. */
24269 dwarf_file_hasher::equal (dwarf_file_data
*p1
, const char *p2
)
24271 return filename_cmp (p1
->filename
, p2
) == 0;
24275 dwarf_file_hasher::hash (dwarf_file_data
*p
)
24277 return htab_hash_string (p
->filename
);
24280 /* Lookup FILE_NAME (in the list of filenames that we know about here in
24281 dwarf2out.c) and return its "index". The index of each (known) filename is
24282 just a unique number which is associated with only that one filename. We
24283 need such numbers for the sake of generating labels (in the .debug_sfnames
24284 section) and references to those files numbers (in the .debug_srcinfo
24285 and .debug_macinfo sections). If the filename given as an argument is not
24286 found in our current list, add it to the list and assign it the next
24287 available unique index number. */
24289 static struct dwarf_file_data
*
24290 lookup_filename (const char *file_name
)
24292 struct dwarf_file_data
* created
;
24297 dwarf_file_data
**slot
24298 = file_table
->find_slot_with_hash (file_name
, htab_hash_string (file_name
),
24303 created
= ggc_alloc
<dwarf_file_data
> ();
24304 created
->filename
= file_name
;
24305 created
->emitted_number
= 0;
24310 /* If the assembler will construct the file table, then translate the compiler
24311 internal file table number into the assembler file table number, and emit
24312 a .file directive if we haven't already emitted one yet. The file table
24313 numbers are different because we prune debug info for unused variables and
24314 types, which may include filenames. */
24317 maybe_emit_file (struct dwarf_file_data
* fd
)
24319 if (! fd
->emitted_number
)
24321 if (last_emitted_file
)
24322 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
24324 fd
->emitted_number
= 1;
24325 last_emitted_file
= fd
;
24327 if (DWARF2_ASM_LINE_DEBUG_INFO
)
24329 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
24330 output_quoted_string (asm_out_file
,
24331 remap_debug_filename (fd
->filename
));
24332 fputc ('\n', asm_out_file
);
24336 return fd
->emitted_number
;
24339 /* Schedule generation of a DW_AT_const_value attribute to DIE.
24340 That generation should happen after function debug info has been
24341 generated. The value of the attribute is the constant value of ARG. */
24344 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
24346 die_arg_entry entry
;
24351 gcc_assert (early_dwarf
);
24353 if (!tmpl_value_parm_die_table
)
24354 vec_alloc (tmpl_value_parm_die_table
, 32);
24358 vec_safe_push (tmpl_value_parm_die_table
, entry
);
24361 /* Return TRUE if T is an instance of generic type, FALSE
24365 generic_type_p (tree t
)
24367 if (t
== NULL_TREE
|| !TYPE_P (t
))
24369 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
24372 /* Schedule the generation of the generic parameter dies for the
24373 instance of generic type T. The proper generation itself is later
24374 done by gen_scheduled_generic_parms_dies. */
24377 schedule_generic_params_dies_gen (tree t
)
24379 if (!generic_type_p (t
))
24382 gcc_assert (early_dwarf
);
24384 if (!generic_type_instances
)
24385 vec_alloc (generic_type_instances
, 256);
24387 vec_safe_push (generic_type_instances
, t
);
24390 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
24391 by append_entry_to_tmpl_value_parm_die_table. This function must
24392 be called after function DIEs have been generated. */
24395 gen_remaining_tmpl_value_param_die_attribute (void)
24397 if (tmpl_value_parm_die_table
)
24402 /* We do this in two phases - first get the cases we can
24403 handle during early-finish, preserving those we cannot
24404 (containing symbolic constants where we don't yet know
24405 whether we are going to output the referenced symbols).
24406 For those we try again at late-finish. */
24408 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
24410 if (!tree_add_const_value_attribute (e
->die
, e
->arg
))
24412 dw_loc_descr_ref loc
= NULL
;
24413 if (dwarf_version
>= 5 || !dwarf_strict
)
24414 loc
= loc_descriptor_from_tree (e
->arg
, 2, NULL
);
24416 add_AT_loc (e
->die
, DW_AT_location
, loc
);
24418 (*tmpl_value_parm_die_table
)[j
++] = *e
;
24421 tmpl_value_parm_die_table
->truncate (j
);
24425 /* Generate generic parameters DIEs for instances of generic types
24426 that have been previously scheduled by
24427 schedule_generic_params_dies_gen. This function must be called
24428 after all the types of the CU have been laid out. */
24431 gen_scheduled_generic_parms_dies (void)
24436 if (!generic_type_instances
)
24439 /* We end up "recursing" into schedule_generic_params_dies_gen, so
24440 pretend this generation is part of "early dwarf" as well. */
24443 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
24444 if (COMPLETE_TYPE_P (t
))
24445 gen_generic_params_dies (t
);
24447 generic_type_instances
= NULL
;
24451 /* Replace DW_AT_name for the decl with name. */
24454 dwarf2out_set_name (tree decl
, tree name
)
24457 dw_attr_node
*attr
;
24460 die
= TYPE_SYMTAB_DIE (decl
);
24464 dname
= dwarf2_name (name
, 0);
24468 attr
= get_AT (die
, DW_AT_name
);
24471 struct indirect_string_node
*node
;
24473 node
= find_AT_string (dname
);
24474 /* replace the string. */
24475 attr
->dw_attr_val
.v
.val_str
= node
;
24479 add_name_attribute (die
, dname
);
24482 /* True if before or during processing of the first function being emitted. */
24483 static bool in_first_function_p
= true;
24484 /* True if loc_note during dwarf2out_var_location call might still be
24485 before first real instruction at address equal to .Ltext0. */
24486 static bool maybe_at_text_label_p
= true;
24487 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
24488 static unsigned int first_loclabel_num_not_at_text_label
;
24490 /* Called by the final INSN scan whenever we see a var location. We
24491 use it to drop labels in the right places, and throw the location in
24492 our lookup table. */
24495 dwarf2out_var_location (rtx_insn
*loc_note
)
24497 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
24498 struct var_loc_node
*newloc
;
24499 rtx_insn
*next_real
, *next_note
;
24500 rtx_insn
*call_insn
= NULL
;
24501 static const char *last_label
;
24502 static const char *last_postcall_label
;
24503 static bool last_in_cold_section_p
;
24504 static rtx_insn
*expected_next_loc_note
;
24508 if (!NOTE_P (loc_note
))
24510 if (CALL_P (loc_note
))
24513 if (SIBLING_CALL_P (loc_note
))
24514 tail_call_site_count
++;
24515 if (optimize
== 0 && !flag_var_tracking
)
24517 /* When the var-tracking pass is not running, there is no note
24518 for indirect calls whose target is compile-time known. In this
24519 case, process such calls specifically so that we generate call
24520 sites for them anyway. */
24521 rtx x
= PATTERN (loc_note
);
24522 if (GET_CODE (x
) == PARALLEL
)
24523 x
= XVECEXP (x
, 0, 0);
24524 if (GET_CODE (x
) == SET
)
24526 if (GET_CODE (x
) == CALL
)
24529 || GET_CODE (XEXP (x
, 0)) != SYMBOL_REF
24530 || !SYMBOL_REF_DECL (XEXP (x
, 0))
24531 || (TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0)))
24534 call_insn
= loc_note
;
24538 next_real
= next_real_insn (call_insn
);
24540 cached_next_real_insn
= NULL
;
24548 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
24549 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
24552 /* Optimize processing a large consecutive sequence of location
24553 notes so we don't spend too much time in next_real_insn. If the
24554 next insn is another location note, remember the next_real_insn
24555 calculation for next time. */
24556 next_real
= cached_next_real_insn
;
24559 if (expected_next_loc_note
!= loc_note
)
24563 next_note
= NEXT_INSN (loc_note
);
24565 || next_note
->deleted ()
24566 || ! NOTE_P (next_note
)
24567 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
24568 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
24572 next_real
= next_real_insn (loc_note
);
24576 expected_next_loc_note
= next_note
;
24577 cached_next_real_insn
= next_real
;
24580 cached_next_real_insn
= NULL
;
24582 /* If there are no instructions which would be affected by this note,
24583 don't do anything. */
24585 && next_real
== NULL_RTX
24586 && !NOTE_DURING_CALL_P (loc_note
))
24591 if (next_real
== NULL_RTX
)
24592 next_real
= get_last_insn ();
24594 /* If there were any real insns between note we processed last time
24595 and this note (or if it is the first note), clear
24596 last_{,postcall_}label so that they are not reused this time. */
24597 if (last_var_location_insn
== NULL_RTX
24598 || last_var_location_insn
!= next_real
24599 || last_in_cold_section_p
!= in_cold_section_p
)
24602 last_postcall_label
= NULL
;
24607 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
24608 newloc
= add_var_loc_to_decl (decl
, loc_note
,
24609 NOTE_DURING_CALL_P (loc_note
)
24610 ? last_postcall_label
: last_label
);
24611 if (newloc
== NULL
)
24620 /* If there were no real insns between note we processed last time
24621 and this note, use the label we emitted last time. Otherwise
24622 create a new label and emit it. */
24623 if (last_label
== NULL
)
24625 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
24626 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
24628 last_label
= ggc_strdup (loclabel
);
24629 /* See if loclabel might be equal to .Ltext0. If yes,
24630 bump first_loclabel_num_not_at_text_label. */
24631 if (!have_multiple_function_sections
24632 && in_first_function_p
24633 && maybe_at_text_label_p
)
24635 static rtx_insn
*last_start
;
24637 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
24638 if (insn
== last_start
)
24640 else if (!NONDEBUG_INSN_P (insn
))
24644 rtx body
= PATTERN (insn
);
24645 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
24647 /* Inline asm could occupy zero bytes. */
24648 else if (GET_CODE (body
) == ASM_INPUT
24649 || asm_noperands (body
) >= 0)
24651 #ifdef HAVE_attr_length
24652 else if (get_attr_min_length (insn
) == 0)
24657 /* Assume insn has non-zero length. */
24658 maybe_at_text_label_p
= false;
24662 if (maybe_at_text_label_p
)
24664 last_start
= loc_note
;
24665 first_loclabel_num_not_at_text_label
= loclabel_num
;
24670 gcc_assert ((loc_note
== NULL_RTX
&& call_insn
!= NULL_RTX
)
24671 || (loc_note
!= NULL_RTX
&& call_insn
== NULL_RTX
));
24675 struct call_arg_loc_node
*ca_loc
24676 = ggc_cleared_alloc
<call_arg_loc_node
> ();
24678 = loc_note
!= NULL_RTX
? prev_real_insn (loc_note
) : call_insn
;
24680 ca_loc
->call_arg_loc_note
= loc_note
;
24681 ca_loc
->next
= NULL
;
24682 ca_loc
->label
= last_label
;
24685 || (NONJUMP_INSN_P (prev
)
24686 && GET_CODE (PATTERN (prev
)) == SEQUENCE
24687 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
24688 if (!CALL_P (prev
))
24689 prev
= as_a
<rtx_sequence
*> (PATTERN (prev
))->insn (0);
24690 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
24692 /* Look for a SYMBOL_REF in the "prev" instruction. */
24693 rtx x
= get_call_rtx_from (PATTERN (prev
));
24696 /* Try to get the call symbol, if any. */
24697 if (MEM_P (XEXP (x
, 0)))
24699 /* First, look for a memory access to a symbol_ref. */
24700 if (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
24701 && SYMBOL_REF_DECL (XEXP (x
, 0))
24702 && TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0))) == FUNCTION_DECL
)
24703 ca_loc
->symbol_ref
= XEXP (x
, 0);
24704 /* Otherwise, look at a compile-time known user-level function
24708 && TREE_CODE (MEM_EXPR (x
)) == FUNCTION_DECL
)
24709 ca_loc
->symbol_ref
= XEXP (DECL_RTL (MEM_EXPR (x
)), 0);
24712 ca_loc
->block
= insn_scope (prev
);
24713 if (call_arg_locations
)
24714 call_arg_loc_last
->next
= ca_loc
;
24716 call_arg_locations
= ca_loc
;
24717 call_arg_loc_last
= ca_loc
;
24719 else if (loc_note
!= NULL_RTX
&& !NOTE_DURING_CALL_P (loc_note
))
24720 newloc
->label
= last_label
;
24723 if (!last_postcall_label
)
24725 sprintf (loclabel
, "%s-1", last_label
);
24726 last_postcall_label
= ggc_strdup (loclabel
);
24728 newloc
->label
= last_postcall_label
;
24731 last_var_location_insn
= next_real
;
24732 last_in_cold_section_p
= in_cold_section_p
;
24735 /* Called from finalize_size_functions for size functions so that their body
24736 can be encoded in the debug info to describe the layout of variable-length
24740 dwarf2out_size_function (tree decl
)
24742 function_to_dwarf_procedure (decl
);
24745 /* Note in one location list that text section has changed. */
24748 var_location_switch_text_section_1 (var_loc_list
**slot
, void *)
24750 var_loc_list
*list
= *slot
;
24752 list
->last_before_switch
24753 = list
->last
->next
? list
->last
->next
: list
->last
;
24757 /* Note in all location lists that text section has changed. */
24760 var_location_switch_text_section (void)
24762 if (decl_loc_table
== NULL
)
24765 decl_loc_table
->traverse
<void *, var_location_switch_text_section_1
> (NULL
);
24768 /* Create a new line number table. */
24770 static dw_line_info_table
*
24771 new_line_info_table (void)
24773 dw_line_info_table
*table
;
24775 table
= ggc_cleared_alloc
<dw_line_info_table
> ();
24776 table
->file_num
= 1;
24777 table
->line_num
= 1;
24778 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
24783 /* Lookup the "current" table into which we emit line info, so
24784 that we don't have to do it for every source line. */
24787 set_cur_line_info_table (section
*sec
)
24789 dw_line_info_table
*table
;
24791 if (sec
== text_section
)
24792 table
= text_section_line_info
;
24793 else if (sec
== cold_text_section
)
24795 table
= cold_text_section_line_info
;
24798 cold_text_section_line_info
= table
= new_line_info_table ();
24799 table
->end_label
= cold_end_label
;
24804 const char *end_label
;
24806 if (flag_reorder_blocks_and_partition
)
24808 if (in_cold_section_p
)
24809 end_label
= crtl
->subsections
.cold_section_end_label
;
24811 end_label
= crtl
->subsections
.hot_section_end_label
;
24815 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
24816 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
24817 current_function_funcdef_no
);
24818 end_label
= ggc_strdup (label
);
24821 table
= new_line_info_table ();
24822 table
->end_label
= end_label
;
24824 vec_safe_push (separate_line_info
, table
);
24827 if (DWARF2_ASM_LINE_DEBUG_INFO
)
24828 table
->is_stmt
= (cur_line_info_table
24829 ? cur_line_info_table
->is_stmt
24830 : DWARF_LINE_DEFAULT_IS_STMT_START
);
24831 cur_line_info_table
= table
;
24835 /* We need to reset the locations at the beginning of each
24836 function. We can't do this in the end_function hook, because the
24837 declarations that use the locations won't have been output when
24838 that hook is called. Also compute have_multiple_function_sections here. */
24841 dwarf2out_begin_function (tree fun
)
24843 section
*sec
= function_section (fun
);
24845 if (sec
!= text_section
)
24846 have_multiple_function_sections
= true;
24848 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
24850 gcc_assert (current_function_decl
== fun
);
24851 cold_text_section
= unlikely_text_section ();
24852 switch_to_section (cold_text_section
);
24853 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
24854 switch_to_section (sec
);
24857 dwarf2out_note_section_used ();
24858 call_site_count
= 0;
24859 tail_call_site_count
= 0;
24861 set_cur_line_info_table (sec
);
24864 /* Helper function of dwarf2out_end_function, called only after emitting
24865 the very first function into assembly. Check if some .debug_loc range
24866 might end with a .LVL* label that could be equal to .Ltext0.
24867 In that case we must force using absolute addresses in .debug_loc ranges,
24868 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
24869 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
24871 Set have_multiple_function_sections to true in that case and
24872 terminate htab traversal. */
24875 find_empty_loc_ranges_at_text_label (var_loc_list
**slot
, int)
24877 var_loc_list
*entry
= *slot
;
24878 struct var_loc_node
*node
;
24880 node
= entry
->first
;
24881 if (node
&& node
->next
&& node
->next
->label
)
24884 const char *label
= node
->next
->label
;
24885 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
24887 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
24889 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
24890 if (strcmp (label
, loclabel
) == 0)
24892 have_multiple_function_sections
= true;
24900 /* Hook called after emitting a function into assembly.
24901 This does something only for the very first function emitted. */
24904 dwarf2out_end_function (unsigned int)
24906 if (in_first_function_p
24907 && !have_multiple_function_sections
24908 && first_loclabel_num_not_at_text_label
24910 decl_loc_table
->traverse
<int, find_empty_loc_ranges_at_text_label
> (0);
24911 in_first_function_p
= false;
24912 maybe_at_text_label_p
= false;
24915 /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
24916 front-ends register a translation unit even before dwarf2out_init is
24918 static tree main_translation_unit
= NULL_TREE
;
24920 /* Hook called by front-ends after they built their main translation unit.
24921 Associate comp_unit_die to UNIT. */
24924 dwarf2out_register_main_translation_unit (tree unit
)
24926 gcc_assert (TREE_CODE (unit
) == TRANSLATION_UNIT_DECL
24927 && main_translation_unit
== NULL_TREE
);
24928 main_translation_unit
= unit
;
24929 /* If dwarf2out_init has not been called yet, it will perform the association
24930 itself looking at main_translation_unit. */
24931 if (decl_die_table
!= NULL
)
24932 equate_decl_number_to_die (unit
, comp_unit_die ());
24935 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
24938 push_dw_line_info_entry (dw_line_info_table
*table
,
24939 enum dw_line_info_opcode opcode
, unsigned int val
)
24941 dw_line_info_entry e
;
24944 vec_safe_push (table
->entries
, e
);
24947 /* Output a label to mark the beginning of a source code line entry
24948 and record information relating to this source line, in
24949 'line_info_table' for later output of the .debug_line section. */
24950 /* ??? The discriminator parameter ought to be unsigned. */
24953 dwarf2out_source_line (unsigned int line
, const char *filename
,
24954 int discriminator
, bool is_stmt
)
24956 unsigned int file_num
;
24957 dw_line_info_table
*table
;
24959 if (debug_info_level
< DINFO_LEVEL_TERSE
|| line
== 0)
24962 /* The discriminator column was added in dwarf4. Simplify the below
24963 by simply removing it if we're not supposed to output it. */
24964 if (dwarf_version
< 4 && dwarf_strict
)
24967 table
= cur_line_info_table
;
24968 file_num
= maybe_emit_file (lookup_filename (filename
));
24970 /* ??? TODO: Elide duplicate line number entries. Traditionally,
24971 the debugger has used the second (possibly duplicate) line number
24972 at the beginning of the function to mark the end of the prologue.
24973 We could eliminate any other duplicates within the function. For
24974 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
24975 that second line number entry. */
24976 /* Recall that this end-of-prologue indication is *not* the same thing
24977 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
24978 to which the hook corresponds, follows the last insn that was
24979 emitted by gen_prologue. What we need is to precede the first insn
24980 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
24981 insn that corresponds to something the user wrote. These may be
24982 very different locations once scheduling is enabled. */
24984 if (0 && file_num
== table
->file_num
24985 && line
== table
->line_num
24986 && discriminator
== table
->discrim_num
24987 && is_stmt
== table
->is_stmt
)
24990 switch_to_section (current_function_section ());
24992 /* If requested, emit something human-readable. */
24993 if (flag_debug_asm
)
24994 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
24996 if (DWARF2_ASM_LINE_DEBUG_INFO
)
24998 /* Emit the .loc directive understood by GNU as. */
24999 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
25000 file_num, line, is_stmt, discriminator */
25001 fputs ("\t.loc ", asm_out_file
);
25002 fprint_ul (asm_out_file
, file_num
);
25003 putc (' ', asm_out_file
);
25004 fprint_ul (asm_out_file
, line
);
25005 putc (' ', asm_out_file
);
25006 putc ('0', asm_out_file
);
25008 if (is_stmt
!= table
->is_stmt
)
25010 fputs (" is_stmt ", asm_out_file
);
25011 putc (is_stmt
? '1' : '0', asm_out_file
);
25013 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
25015 gcc_assert (discriminator
> 0);
25016 fputs (" discriminator ", asm_out_file
);
25017 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
25019 putc ('\n', asm_out_file
);
25023 unsigned int label_num
= ++line_info_label_num
;
25025 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
25027 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
25028 if (file_num
!= table
->file_num
)
25029 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
25030 if (discriminator
!= table
->discrim_num
)
25031 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
25032 if (is_stmt
!= table
->is_stmt
)
25033 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
25034 push_dw_line_info_entry (table
, LI_set_line
, line
);
25037 table
->file_num
= file_num
;
25038 table
->line_num
= line
;
25039 table
->discrim_num
= discriminator
;
25040 table
->is_stmt
= is_stmt
;
25041 table
->in_use
= true;
25044 /* Record the beginning of a new source file. */
25047 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
25049 if (flag_eliminate_dwarf2_dups
)
25051 /* Record the beginning of the file for break_out_includes. */
25052 dw_die_ref bincl_die
;
25054 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
25055 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
25058 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
25061 e
.code
= DW_MACINFO_start_file
;
25063 e
.info
= ggc_strdup (filename
);
25064 vec_safe_push (macinfo_table
, e
);
25068 /* Record the end of a source file. */
25071 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
25073 if (flag_eliminate_dwarf2_dups
)
25074 /* Record the end of the file for break_out_includes. */
25075 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
25077 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
25080 e
.code
= DW_MACINFO_end_file
;
25083 vec_safe_push (macinfo_table
, e
);
25087 /* Called from debug_define in toplev.c. The `buffer' parameter contains
25088 the tail part of the directive line, i.e. the part which is past the
25089 initial whitespace, #, whitespace, directive-name, whitespace part. */
25092 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
25093 const char *buffer ATTRIBUTE_UNUSED
)
25095 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
25098 /* Insert a dummy first entry to be able to optimize the whole
25099 predefined macro block using DW_MACRO_GNU_transparent_include. */
25100 if (macinfo_table
->is_empty () && lineno
<= 1)
25105 vec_safe_push (macinfo_table
, e
);
25107 e
.code
= DW_MACINFO_define
;
25109 e
.info
= ggc_strdup (buffer
);
25110 vec_safe_push (macinfo_table
, e
);
25114 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
25115 the tail part of the directive line, i.e. the part which is past the
25116 initial whitespace, #, whitespace, directive-name, whitespace part. */
25119 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
25120 const char *buffer ATTRIBUTE_UNUSED
)
25122 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
25125 /* Insert a dummy first entry to be able to optimize the whole
25126 predefined macro block using DW_MACRO_GNU_transparent_include. */
25127 if (macinfo_table
->is_empty () && lineno
<= 1)
25132 vec_safe_push (macinfo_table
, e
);
25134 e
.code
= DW_MACINFO_undef
;
25136 e
.info
= ggc_strdup (buffer
);
25137 vec_safe_push (macinfo_table
, e
);
25141 /* Helpers to manipulate hash table of CUs. */
25143 struct macinfo_entry_hasher
: nofree_ptr_hash
<macinfo_entry
>
25145 static inline hashval_t
hash (const macinfo_entry
*);
25146 static inline bool equal (const macinfo_entry
*, const macinfo_entry
*);
25150 macinfo_entry_hasher::hash (const macinfo_entry
*entry
)
25152 return htab_hash_string (entry
->info
);
25156 macinfo_entry_hasher::equal (const macinfo_entry
*entry1
,
25157 const macinfo_entry
*entry2
)
25159 return !strcmp (entry1
->info
, entry2
->info
);
25162 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
25164 /* Output a single .debug_macinfo entry. */
25167 output_macinfo_op (macinfo_entry
*ref
)
25171 struct indirect_string_node
*node
;
25172 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
25173 struct dwarf_file_data
*fd
;
25177 case DW_MACINFO_start_file
:
25178 fd
= lookup_filename (ref
->info
);
25179 file_num
= maybe_emit_file (fd
);
25180 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
25181 dw2_asm_output_data_uleb128 (ref
->lineno
,
25182 "Included from line number %lu",
25183 (unsigned long) ref
->lineno
);
25184 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
25186 case DW_MACINFO_end_file
:
25187 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
25189 case DW_MACINFO_define
:
25190 case DW_MACINFO_undef
:
25191 len
= strlen (ref
->info
) + 1;
25193 && len
> DWARF_OFFSET_SIZE
25194 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
25195 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
25197 ref
->code
= ref
->code
== DW_MACINFO_define
25198 ? DW_MACRO_GNU_define_indirect
25199 : DW_MACRO_GNU_undef_indirect
;
25200 output_macinfo_op (ref
);
25203 dw2_asm_output_data (1, ref
->code
,
25204 ref
->code
== DW_MACINFO_define
25205 ? "Define macro" : "Undefine macro");
25206 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
25207 (unsigned long) ref
->lineno
);
25208 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
25210 case DW_MACRO_GNU_define_indirect
:
25211 case DW_MACRO_GNU_undef_indirect
:
25212 node
= find_AT_string (ref
->info
);
25214 && ((node
->form
== DW_FORM_strp
)
25215 || (node
->form
== DW_FORM_GNU_str_index
)));
25216 dw2_asm_output_data (1, ref
->code
,
25217 ref
->code
== DW_MACRO_GNU_define_indirect
25218 ? "Define macro indirect"
25219 : "Undefine macro indirect");
25220 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
25221 (unsigned long) ref
->lineno
);
25222 if (node
->form
== DW_FORM_strp
)
25223 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
25224 debug_str_section
, "The macro: \"%s\"",
25227 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
25230 case DW_MACRO_GNU_transparent_include
:
25231 dw2_asm_output_data (1, ref
->code
, "Transparent include");
25232 ASM_GENERATE_INTERNAL_LABEL (label
,
25233 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
25234 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
25237 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
25238 ASM_COMMENT_START
, (unsigned long) ref
->code
);
25243 /* Attempt to make a sequence of define/undef macinfo ops shareable with
25244 other compilation unit .debug_macinfo sections. IDX is the first
25245 index of a define/undef, return the number of ops that should be
25246 emitted in a comdat .debug_macinfo section and emit
25247 a DW_MACRO_GNU_transparent_include entry referencing it.
25248 If the define/undef entry should be emitted normally, return 0. */
25251 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
25252 macinfo_hash_type
**macinfo_htab
)
25254 macinfo_entry
*first
, *second
, *cur
, *inc
;
25255 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
25256 unsigned char checksum
[16];
25257 struct md5_ctx ctx
;
25258 char *grp_name
, *tail
;
25260 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
25261 macinfo_entry
**slot
;
25263 first
= &(*macinfo_table
)[idx
];
25264 second
= &(*macinfo_table
)[idx
+ 1];
25266 /* Optimize only if there are at least two consecutive define/undef ops,
25267 and either all of them are before first DW_MACINFO_start_file
25268 with lineno {0,1} (i.e. predefined macro block), or all of them are
25269 in some included header file. */
25270 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
25272 if (vec_safe_is_empty (files
))
25274 if (first
->lineno
> 1 || second
->lineno
> 1)
25277 else if (first
->lineno
== 0)
25280 /* Find the last define/undef entry that can be grouped together
25281 with first and at the same time compute md5 checksum of their
25282 codes, linenumbers and strings. */
25283 md5_init_ctx (&ctx
);
25284 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
25285 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
25287 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
25291 unsigned char code
= cur
->code
;
25292 md5_process_bytes (&code
, 1, &ctx
);
25293 checksum_uleb128 (cur
->lineno
, &ctx
);
25294 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
25296 md5_finish_ctx (&ctx
, checksum
);
25299 /* From the containing include filename (if any) pick up just
25300 usable characters from its basename. */
25301 if (vec_safe_is_empty (files
))
25304 base
= lbasename (files
->last ().info
);
25305 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
25306 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
25307 encoded_filename_len
++;
25308 /* Count . at the end. */
25309 if (encoded_filename_len
)
25310 encoded_filename_len
++;
25312 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
25313 linebuf_len
= strlen (linebuf
);
25315 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
25316 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
25318 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
25319 tail
= grp_name
+ 4;
25320 if (encoded_filename_len
)
25322 for (i
= 0; base
[i
]; i
++)
25323 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
25327 memcpy (tail
, linebuf
, linebuf_len
);
25328 tail
+= linebuf_len
;
25330 for (i
= 0; i
< 16; i
++)
25331 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
25333 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
25334 in the empty vector entry before the first define/undef. */
25335 inc
= &(*macinfo_table
)[idx
- 1];
25336 inc
->code
= DW_MACRO_GNU_transparent_include
;
25338 inc
->info
= ggc_strdup (grp_name
);
25339 if (!*macinfo_htab
)
25340 *macinfo_htab
= new macinfo_hash_type (10);
25341 /* Avoid emitting duplicates. */
25342 slot
= (*macinfo_htab
)->find_slot (inc
, INSERT
);
25347 /* If such an entry has been used before, just emit
25348 a DW_MACRO_GNU_transparent_include op. */
25350 output_macinfo_op (inc
);
25351 /* And clear all macinfo_entry in the range to avoid emitting them
25352 in the second pass. */
25353 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
25362 inc
->lineno
= (*macinfo_htab
)->elements ();
25363 output_macinfo_op (inc
);
25368 /* Save any strings needed by the macinfo table in the debug str
25369 table. All strings must be collected into the table by the time
25370 index_string is called. */
25373 save_macinfo_strings (void)
25377 macinfo_entry
*ref
;
25379 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
25383 /* Match the logic in output_macinfo_op to decide on
25384 indirect strings. */
25385 case DW_MACINFO_define
:
25386 case DW_MACINFO_undef
:
25387 len
= strlen (ref
->info
) + 1;
25389 && len
> DWARF_OFFSET_SIZE
25390 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
25391 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
25392 set_indirect_string (find_AT_string (ref
->info
));
25394 case DW_MACRO_GNU_define_indirect
:
25395 case DW_MACRO_GNU_undef_indirect
:
25396 set_indirect_string (find_AT_string (ref
->info
));
25404 /* Output macinfo section(s). */
25407 output_macinfo (void)
25410 unsigned long length
= vec_safe_length (macinfo_table
);
25411 macinfo_entry
*ref
;
25412 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
25413 macinfo_hash_type
*macinfo_htab
= NULL
;
25418 /* output_macinfo* uses these interchangeably. */
25419 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
25420 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
25421 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
25422 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
25424 /* For .debug_macro emit the section header. */
25427 dw2_asm_output_data (2, 4, "DWARF macro version number");
25428 if (DWARF_OFFSET_SIZE
== 8)
25429 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
25431 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
25432 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
25433 (!dwarf_split_debug_info
? debug_line_section_label
25434 : debug_skeleton_line_section_label
),
25435 debug_line_section
, NULL
);
25438 /* In the first loop, it emits the primary .debug_macinfo section
25439 and after each emitted op the macinfo_entry is cleared.
25440 If a longer range of define/undef ops can be optimized using
25441 DW_MACRO_GNU_transparent_include, the
25442 DW_MACRO_GNU_transparent_include op is emitted and kept in
25443 the vector before the first define/undef in the range and the
25444 whole range of define/undef ops is not emitted and kept. */
25445 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
25449 case DW_MACINFO_start_file
:
25450 vec_safe_push (files
, *ref
);
25452 case DW_MACINFO_end_file
:
25453 if (!vec_safe_is_empty (files
))
25456 case DW_MACINFO_define
:
25457 case DW_MACINFO_undef
:
25459 && HAVE_COMDAT_GROUP
25460 && vec_safe_length (files
) != 1
25463 && (*macinfo_table
)[i
- 1].code
== 0)
25465 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
25474 /* A dummy entry may be inserted at the beginning to be able
25475 to optimize the whole block of predefined macros. */
25481 output_macinfo_op (ref
);
25489 delete macinfo_htab
;
25490 macinfo_htab
= NULL
;
25492 /* If any DW_MACRO_GNU_transparent_include were used, on those
25493 DW_MACRO_GNU_transparent_include entries terminate the
25494 current chain and switch to a new comdat .debug_macinfo
25495 section and emit the define/undef entries within it. */
25496 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
25501 case DW_MACRO_GNU_transparent_include
:
25503 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
25504 tree comdat_key
= get_identifier (ref
->info
);
25505 /* Terminate the previous .debug_macinfo section. */
25506 dw2_asm_output_data (1, 0, "End compilation unit");
25507 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
25509 | SECTION_LINKONCE
,
25511 ASM_GENERATE_INTERNAL_LABEL (label
,
25512 DEBUG_MACRO_SECTION_LABEL
,
25514 ASM_OUTPUT_LABEL (asm_out_file
, label
);
25517 dw2_asm_output_data (2, 4, "DWARF macro version number");
25518 if (DWARF_OFFSET_SIZE
== 8)
25519 dw2_asm_output_data (1, 1, "Flags: 64-bit");
25521 dw2_asm_output_data (1, 0, "Flags: 32-bit");
25524 case DW_MACINFO_define
:
25525 case DW_MACINFO_undef
:
25526 output_macinfo_op (ref
);
25531 gcc_unreachable ();
25535 /* Set up for Dwarf output at the start of compilation. */
25538 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
25540 /* This option is currently broken, see (PR53118 and PR46102). */
25541 if (flag_eliminate_dwarf2_dups
25542 && strstr (lang_hooks
.name
, "C++"))
25544 warning (0, "-feliminate-dwarf2-dups is broken for C++, ignoring");
25545 flag_eliminate_dwarf2_dups
= 0;
25548 /* Allocate the file_table. */
25549 file_table
= hash_table
<dwarf_file_hasher
>::create_ggc (50);
25551 #ifndef DWARF2_LINENO_DEBUGGING_INFO
25552 /* Allocate the decl_die_table. */
25553 decl_die_table
= hash_table
<decl_die_hasher
>::create_ggc (10);
25555 /* Allocate the decl_loc_table. */
25556 decl_loc_table
= hash_table
<decl_loc_hasher
>::create_ggc (10);
25558 /* Allocate the cached_dw_loc_list_table. */
25559 cached_dw_loc_list_table
= hash_table
<dw_loc_list_hasher
>::create_ggc (10);
25561 /* Allocate the initial hunk of the decl_scope_table. */
25562 vec_alloc (decl_scope_table
, 256);
25564 /* Allocate the initial hunk of the abbrev_die_table. */
25565 abbrev_die_table
= ggc_cleared_vec_alloc
<dw_die_ref
>
25566 (ABBREV_DIE_TABLE_INCREMENT
);
25567 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
25568 /* Zero-th entry is allocated, but unused. */
25569 abbrev_die_table_in_use
= 1;
25571 /* Allocate the dwarf_proc_stack_usage_map. */
25572 dwarf_proc_stack_usage_map
= new hash_map
<dw_die_ref
, int>;
25574 /* Allocate the pubtypes and pubnames vectors. */
25575 vec_alloc (pubname_table
, 32);
25576 vec_alloc (pubtype_table
, 32);
25578 vec_alloc (incomplete_types
, 64);
25580 vec_alloc (used_rtx_array
, 32);
25582 if (!dwarf_split_debug_info
)
25584 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
25585 SECTION_DEBUG
, NULL
);
25586 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
25587 SECTION_DEBUG
, NULL
);
25588 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
25589 SECTION_DEBUG
, NULL
);
25593 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
25594 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
25595 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
25596 SECTION_DEBUG
| SECTION_EXCLUDE
,
25598 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
25599 SECTION_DEBUG
, NULL
);
25600 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
25601 SECTION_DEBUG
, NULL
);
25602 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
25603 SECTION_DEBUG
, NULL
);
25604 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
25605 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
25607 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
25608 the main .o, but the skeleton_line goes into the split off dwo. */
25609 debug_skeleton_line_section
25610 = get_section (DEBUG_DWO_LINE_SECTION
,
25611 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
25612 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
25613 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
25614 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
25615 SECTION_DEBUG
| SECTION_EXCLUDE
,
25617 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
25618 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
25619 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
25620 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
25621 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
25622 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
25624 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
25625 SECTION_DEBUG
, NULL
);
25626 debug_macinfo_section
= get_section (dwarf_strict
25627 ? DEBUG_MACINFO_SECTION
25628 : DEBUG_MACRO_SECTION
,
25629 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
25630 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
25631 SECTION_DEBUG
, NULL
);
25632 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
25633 SECTION_DEBUG
, NULL
);
25634 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
25635 SECTION_DEBUG
, NULL
);
25636 debug_str_section
= get_section (DEBUG_STR_SECTION
,
25637 DEBUG_STR_SECTION_FLAGS
, NULL
);
25638 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
25639 SECTION_DEBUG
, NULL
);
25640 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
25641 SECTION_DEBUG
, NULL
);
25643 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
25644 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
25645 DEBUG_ABBREV_SECTION_LABEL
, 0);
25646 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
25647 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
25648 COLD_TEXT_SECTION_LABEL
, 0);
25649 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
25651 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
25652 DEBUG_INFO_SECTION_LABEL
, 0);
25653 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
25654 DEBUG_LINE_SECTION_LABEL
, 0);
25655 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
25656 DEBUG_RANGES_SECTION_LABEL
, 0);
25657 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
25658 DEBUG_ADDR_SECTION_LABEL
, 0);
25659 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
25661 ? DEBUG_MACINFO_SECTION_LABEL
25662 : DEBUG_MACRO_SECTION_LABEL
, 0);
25663 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
25665 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
25666 vec_alloc (macinfo_table
, 64);
25668 switch_to_section (text_section
);
25669 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
25672 /* Make sure the line number table for .text always exists. */
25673 text_section_line_info
= new_line_info_table ();
25674 text_section_line_info
->end_label
= text_end_label
;
25676 #ifdef DWARF2_LINENO_DEBUGGING_INFO
25677 cur_line_info_table
= text_section_line_info
;
25680 /* If front-ends already registered a main translation unit but we were not
25681 ready to perform the association, do this now. */
25682 if (main_translation_unit
!= NULL_TREE
)
25683 equate_decl_number_to_die (main_translation_unit
, comp_unit_die ());
25686 /* Called before compile () starts outputtting functions, variables
25687 and toplevel asms into assembly. */
25690 dwarf2out_assembly_start (void)
25692 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
25693 && dwarf2out_do_cfi_asm ()
25694 && (!(flag_unwind_tables
|| flag_exceptions
)
25695 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
25696 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
25699 /* A helper function for dwarf2out_finish called through
25700 htab_traverse. Assign a string its index. All strings must be
25701 collected into the table by the time index_string is called,
25702 because the indexing code relies on htab_traverse to traverse nodes
25703 in the same order for each run. */
25706 index_string (indirect_string_node
**h
, unsigned int *index
)
25708 indirect_string_node
*node
= *h
;
25710 find_string_form (node
);
25711 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
25713 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
25714 node
->index
= *index
;
25720 /* A helper function for output_indirect_strings called through
25721 htab_traverse. Output the offset to a string and update the
25725 output_index_string_offset (indirect_string_node
**h
, unsigned int *offset
)
25727 indirect_string_node
*node
= *h
;
25729 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
25731 /* Assert that this node has been assigned an index. */
25732 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
25733 && node
->index
!= NOT_INDEXED
);
25734 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
25735 "indexed string 0x%x: %s", node
->index
, node
->str
);
25736 *offset
+= strlen (node
->str
) + 1;
25741 /* A helper function for dwarf2out_finish called through
25742 htab_traverse. Output the indexed string. */
25745 output_index_string (indirect_string_node
**h
, unsigned int *cur_idx
)
25747 struct indirect_string_node
*node
= *h
;
25749 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
25751 /* Assert that the strings are output in the same order as their
25752 indexes were assigned. */
25753 gcc_assert (*cur_idx
== node
->index
);
25754 assemble_string (node
->str
, strlen (node
->str
) + 1);
25760 /* A helper function for dwarf2out_finish called through
25761 htab_traverse. Emit one queued .debug_str string. */
25764 output_indirect_string (indirect_string_node
**h
, void *)
25766 struct indirect_string_node
*node
= *h
;
25768 node
->form
= find_string_form (node
);
25769 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
25771 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
25772 assemble_string (node
->str
, strlen (node
->str
) + 1);
25778 /* Output the indexed string table. */
25781 output_indirect_strings (void)
25783 switch_to_section (debug_str_section
);
25784 if (!dwarf_split_debug_info
)
25785 debug_str_hash
->traverse
<void *, output_indirect_string
> (NULL
);
25788 unsigned int offset
= 0;
25789 unsigned int cur_idx
= 0;
25791 skeleton_debug_str_hash
->traverse
<void *, output_indirect_string
> (NULL
);
25793 switch_to_section (debug_str_offsets_section
);
25794 debug_str_hash
->traverse_noresize
25795 <unsigned int *, output_index_string_offset
> (&offset
);
25796 switch_to_section (debug_str_dwo_section
);
25797 debug_str_hash
->traverse_noresize
<unsigned int *, output_index_string
>
25802 /* Callback for htab_traverse to assign an index to an entry in the
25803 table, and to write that entry to the .debug_addr section. */
25806 output_addr_table_entry (addr_table_entry
**slot
, unsigned int *cur_index
)
25808 addr_table_entry
*entry
= *slot
;
25810 if (entry
->refcount
== 0)
25812 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
25813 || entry
->index
== NOT_INDEXED
);
25817 gcc_assert (entry
->index
== *cur_index
);
25820 switch (entry
->kind
)
25823 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
25824 "0x%x", entry
->index
);
25826 case ate_kind_rtx_dtprel
:
25827 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
25828 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
25831 fputc ('\n', asm_out_file
);
25833 case ate_kind_label
:
25834 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
25835 "0x%x", entry
->index
);
25838 gcc_unreachable ();
25843 /* Produce the .debug_addr section. */
25846 output_addr_table (void)
25848 unsigned int index
= 0;
25849 if (addr_index_table
== NULL
|| addr_index_table
->size () == 0)
25852 switch_to_section (debug_addr_section
);
25854 ->traverse_noresize
<unsigned int *, output_addr_table_entry
> (&index
);
25857 #if ENABLE_ASSERT_CHECKING
25858 /* Verify that all marks are clear. */
25861 verify_marks_clear (dw_die_ref die
)
25865 gcc_assert (! die
->die_mark
);
25866 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
25868 #endif /* ENABLE_ASSERT_CHECKING */
25870 /* Clear the marks for a die and its children.
25871 Be cool if the mark isn't set. */
25874 prune_unmark_dies (dw_die_ref die
)
25880 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
25883 /* Given LOC that is referenced by a DIE we're marking as used, find all
25884 referenced DWARF procedures it references and mark them as used. */
25887 prune_unused_types_walk_loc_descr (dw_loc_descr_ref loc
)
25889 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
25890 switch (loc
->dw_loc_opc
)
25892 case DW_OP_GNU_implicit_pointer
:
25893 case DW_OP_GNU_convert
:
25894 case DW_OP_GNU_reinterpret
:
25895 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
)
25896 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
25900 case DW_OP_call_ref
:
25901 case DW_OP_GNU_const_type
:
25902 case DW_OP_GNU_parameter_ref
:
25903 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
);
25904 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
25906 case DW_OP_GNU_regval_type
:
25907 case DW_OP_GNU_deref_type
:
25908 gcc_assert (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_die_ref
);
25909 prune_unused_types_mark (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
, 1);
25911 case DW_OP_GNU_entry_value
:
25912 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
);
25913 prune_unused_types_walk_loc_descr (loc
->dw_loc_oprnd1
.v
.val_loc
);
25920 /* Given DIE that we're marking as used, find any other dies
25921 it references as attributes and mark them as used. */
25924 prune_unused_types_walk_attribs (dw_die_ref die
)
25929 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
25931 switch (AT_class (a
))
25933 /* Make sure DWARF procedures referenced by location descriptions will
25935 case dw_val_class_loc
:
25936 prune_unused_types_walk_loc_descr (AT_loc (a
));
25938 case dw_val_class_loc_list
:
25939 for (dw_loc_list_ref list
= AT_loc_list (a
);
25941 list
= list
->dw_loc_next
)
25942 prune_unused_types_walk_loc_descr (list
->expr
);
25945 case dw_val_class_die_ref
:
25946 /* A reference to another DIE.
25947 Make sure that it will get emitted.
25948 If it was broken out into a comdat group, don't follow it. */
25949 if (! AT_ref (a
)->comdat_type_p
25950 || a
->dw_attr
== DW_AT_specification
)
25951 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
25954 case dw_val_class_str
:
25955 /* Set the string's refcount to 0 so that prune_unused_types_mark
25956 accounts properly for it. */
25957 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
25966 /* Mark the generic parameters and arguments children DIEs of DIE. */
25969 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
25973 if (die
== NULL
|| die
->die_child
== NULL
)
25975 c
= die
->die_child
;
25978 if (is_template_parameter (c
))
25979 prune_unused_types_mark (c
, 1);
25981 } while (c
&& c
!= die
->die_child
);
25984 /* Mark DIE as being used. If DOKIDS is true, then walk down
25985 to DIE's children. */
25988 prune_unused_types_mark (dw_die_ref die
, int dokids
)
25992 if (die
->die_mark
== 0)
25994 /* We haven't done this node yet. Mark it as used. */
25996 /* If this is the DIE of a generic type instantiation,
25997 mark the children DIEs that describe its generic parms and
25999 prune_unused_types_mark_generic_parms_dies (die
);
26001 /* We also have to mark its parents as used.
26002 (But we don't want to mark our parent's kids due to this,
26003 unless it is a class.) */
26004 if (die
->die_parent
)
26005 prune_unused_types_mark (die
->die_parent
,
26006 class_scope_p (die
->die_parent
));
26008 /* Mark any referenced nodes. */
26009 prune_unused_types_walk_attribs (die
);
26011 /* If this node is a specification,
26012 also mark the definition, if it exists. */
26013 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
26014 prune_unused_types_mark (die
->die_definition
, 1);
26017 if (dokids
&& die
->die_mark
!= 2)
26019 /* We need to walk the children, but haven't done so yet.
26020 Remember that we've walked the kids. */
26023 /* If this is an array type, we need to make sure our
26024 kids get marked, even if they're types. If we're
26025 breaking out types into comdat sections, do this
26026 for all type definitions. */
26027 if (die
->die_tag
== DW_TAG_array_type
26028 || (use_debug_types
26029 && is_type_die (die
) && ! is_declaration_die (die
)))
26030 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
26032 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
26036 /* For local classes, look if any static member functions were emitted
26037 and if so, mark them. */
26040 prune_unused_types_walk_local_classes (dw_die_ref die
)
26044 if (die
->die_mark
== 2)
26047 switch (die
->die_tag
)
26049 case DW_TAG_structure_type
:
26050 case DW_TAG_union_type
:
26051 case DW_TAG_class_type
:
26054 case DW_TAG_subprogram
:
26055 if (!get_AT_flag (die
, DW_AT_declaration
)
26056 || die
->die_definition
!= NULL
)
26057 prune_unused_types_mark (die
, 1);
26064 /* Mark children. */
26065 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
26068 /* Walk the tree DIE and mark types that we actually use. */
26071 prune_unused_types_walk (dw_die_ref die
)
26075 /* Don't do anything if this node is already marked and
26076 children have been marked as well. */
26077 if (die
->die_mark
== 2)
26080 switch (die
->die_tag
)
26082 case DW_TAG_structure_type
:
26083 case DW_TAG_union_type
:
26084 case DW_TAG_class_type
:
26085 if (die
->die_perennial_p
)
26088 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
26089 if (c
->die_tag
== DW_TAG_subprogram
)
26092 /* Finding used static member functions inside of classes
26093 is needed just for local classes, because for other classes
26094 static member function DIEs with DW_AT_specification
26095 are emitted outside of the DW_TAG_*_type. If we ever change
26096 it, we'd need to call this even for non-local classes. */
26098 prune_unused_types_walk_local_classes (die
);
26100 /* It's a type node --- don't mark it. */
26103 case DW_TAG_const_type
:
26104 case DW_TAG_packed_type
:
26105 case DW_TAG_pointer_type
:
26106 case DW_TAG_reference_type
:
26107 case DW_TAG_rvalue_reference_type
:
26108 case DW_TAG_volatile_type
:
26109 case DW_TAG_typedef
:
26110 case DW_TAG_array_type
:
26111 case DW_TAG_interface_type
:
26112 case DW_TAG_friend
:
26113 case DW_TAG_enumeration_type
:
26114 case DW_TAG_subroutine_type
:
26115 case DW_TAG_string_type
:
26116 case DW_TAG_set_type
:
26117 case DW_TAG_subrange_type
:
26118 case DW_TAG_ptr_to_member_type
:
26119 case DW_TAG_file_type
:
26120 /* Type nodes are useful only when other DIEs reference them --- don't
26124 case DW_TAG_dwarf_procedure
:
26125 /* Likewise for DWARF procedures. */
26127 if (die
->die_perennial_p
)
26133 /* Mark everything else. */
26137 if (die
->die_mark
== 0)
26141 /* Now, mark any dies referenced from here. */
26142 prune_unused_types_walk_attribs (die
);
26147 /* Mark children. */
26148 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
26151 /* Increment the string counts on strings referred to from DIE's
26155 prune_unused_types_update_strings (dw_die_ref die
)
26160 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
26161 if (AT_class (a
) == dw_val_class_str
)
26163 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
26165 /* Avoid unnecessarily putting strings that are used less than
26166 twice in the hash table. */
26168 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
26170 indirect_string_node
**slot
26171 = debug_str_hash
->find_slot_with_hash (s
->str
,
26172 htab_hash_string (s
->str
),
26174 gcc_assert (*slot
== NULL
);
26180 /* Remove from the tree DIE any dies that aren't marked. */
26183 prune_unused_types_prune (dw_die_ref die
)
26187 gcc_assert (die
->die_mark
);
26188 prune_unused_types_update_strings (die
);
26190 if (! die
->die_child
)
26193 c
= die
->die_child
;
26195 dw_die_ref prev
= c
;
26196 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
26197 if (c
== die
->die_child
)
26199 /* No marked children between 'prev' and the end of the list. */
26201 /* No marked children at all. */
26202 die
->die_child
= NULL
;
26205 prev
->die_sib
= c
->die_sib
;
26206 die
->die_child
= prev
;
26211 if (c
!= prev
->die_sib
)
26213 prune_unused_types_prune (c
);
26214 } while (c
!= die
->die_child
);
26217 /* Remove dies representing declarations that we never use. */
26220 prune_unused_types (void)
26223 limbo_die_node
*node
;
26224 comdat_type_node
*ctnode
;
26225 pubname_entry
*pub
;
26226 dw_die_ref base_type
;
26228 #if ENABLE_ASSERT_CHECKING
26229 /* All the marks should already be clear. */
26230 verify_marks_clear (comp_unit_die ());
26231 for (node
= limbo_die_list
; node
; node
= node
->next
)
26232 verify_marks_clear (node
->die
);
26233 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
26234 verify_marks_clear (ctnode
->root_die
);
26235 #endif /* ENABLE_ASSERT_CHECKING */
26237 /* Mark types that are used in global variables. */
26238 premark_types_used_by_global_vars ();
26240 /* Set the mark on nodes that are actually used. */
26241 prune_unused_types_walk (comp_unit_die ());
26242 for (node
= limbo_die_list
; node
; node
= node
->next
)
26243 prune_unused_types_walk (node
->die
);
26244 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
26246 prune_unused_types_walk (ctnode
->root_die
);
26247 prune_unused_types_mark (ctnode
->type_die
, 1);
26250 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
26251 are unusual in that they are pubnames that are the children of pubtypes.
26252 They should only be marked via their parent DW_TAG_enumeration_type die,
26253 not as roots in themselves. */
26254 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
26255 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
26256 prune_unused_types_mark (pub
->die
, 1);
26257 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
26258 prune_unused_types_mark (base_type
, 1);
26260 if (debug_str_hash
)
26261 debug_str_hash
->empty ();
26262 if (skeleton_debug_str_hash
)
26263 skeleton_debug_str_hash
->empty ();
26264 prune_unused_types_prune (comp_unit_die ());
26265 for (limbo_die_node
**pnode
= &limbo_die_list
; *pnode
; )
26268 if (!node
->die
->die_mark
)
26269 *pnode
= node
->next
;
26272 prune_unused_types_prune (node
->die
);
26273 pnode
= &node
->next
;
26276 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
26277 prune_unused_types_prune (ctnode
->root_die
);
26279 /* Leave the marks clear. */
26280 prune_unmark_dies (comp_unit_die ());
26281 for (node
= limbo_die_list
; node
; node
= node
->next
)
26282 prune_unmark_dies (node
->die
);
26283 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
26284 prune_unmark_dies (ctnode
->root_die
);
26287 /* Set the parameter to true if there are any relative pathnames in
26290 file_table_relative_p (dwarf_file_data
**slot
, bool *p
)
26292 struct dwarf_file_data
*d
= *slot
;
26293 if (!IS_ABSOLUTE_PATH (d
->filename
))
26301 /* Helpers to manipulate hash table of comdat type units. */
26303 struct comdat_type_hasher
: nofree_ptr_hash
<comdat_type_node
>
26305 static inline hashval_t
hash (const comdat_type_node
*);
26306 static inline bool equal (const comdat_type_node
*, const comdat_type_node
*);
26310 comdat_type_hasher::hash (const comdat_type_node
*type_node
)
26313 memcpy (&h
, type_node
->signature
, sizeof (h
));
26318 comdat_type_hasher::equal (const comdat_type_node
*type_node_1
,
26319 const comdat_type_node
*type_node_2
)
26321 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
26322 DWARF_TYPE_SIGNATURE_SIZE
));
26325 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
26326 to the location it would have been added, should we know its
26327 DECL_ASSEMBLER_NAME when we added other attributes. This will
26328 probably improve compactness of debug info, removing equivalent
26329 abbrevs, and hide any differences caused by deferring the
26330 computation of the assembler name, triggered by e.g. PCH. */
26333 move_linkage_attr (dw_die_ref die
)
26335 unsigned ix
= vec_safe_length (die
->die_attr
);
26336 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
26338 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
26339 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
26343 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
26345 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
26349 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
26351 die
->die_attr
->pop ();
26352 die
->die_attr
->quick_insert (ix
, linkage
);
26356 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
26357 referenced from typed stack ops and count how often they are used. */
26360 mark_base_types (dw_loc_descr_ref loc
)
26362 dw_die_ref base_type
= NULL
;
26364 for (; loc
; loc
= loc
->dw_loc_next
)
26366 switch (loc
->dw_loc_opc
)
26368 case DW_OP_GNU_regval_type
:
26369 case DW_OP_GNU_deref_type
:
26370 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
26372 case DW_OP_GNU_convert
:
26373 case DW_OP_GNU_reinterpret
:
26374 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
26377 case DW_OP_GNU_const_type
:
26378 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
26380 case DW_OP_GNU_entry_value
:
26381 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
26386 gcc_assert (base_type
->die_parent
== comp_unit_die ());
26387 if (base_type
->die_mark
)
26388 base_type
->die_mark
++;
26391 base_types
.safe_push (base_type
);
26392 base_type
->die_mark
= 1;
26397 /* Comparison function for sorting marked base types. */
26400 base_type_cmp (const void *x
, const void *y
)
26402 dw_die_ref dx
= *(const dw_die_ref
*) x
;
26403 dw_die_ref dy
= *(const dw_die_ref
*) y
;
26404 unsigned int byte_size1
, byte_size2
;
26405 unsigned int encoding1
, encoding2
;
26406 if (dx
->die_mark
> dy
->die_mark
)
26408 if (dx
->die_mark
< dy
->die_mark
)
26410 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
26411 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
26412 if (byte_size1
< byte_size2
)
26414 if (byte_size1
> byte_size2
)
26416 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
26417 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
26418 if (encoding1
< encoding2
)
26420 if (encoding1
> encoding2
)
26425 /* Move base types marked by mark_base_types as early as possible
26426 in the CU, sorted by decreasing usage count both to make the
26427 uleb128 references as small as possible and to make sure they
26428 will have die_offset already computed by calc_die_sizes when
26429 sizes of typed stack loc ops is computed. */
26432 move_marked_base_types (void)
26435 dw_die_ref base_type
, die
, c
;
26437 if (base_types
.is_empty ())
26440 /* Sort by decreasing usage count, they will be added again in that
26442 base_types
.qsort (base_type_cmp
);
26443 die
= comp_unit_die ();
26444 c
= die
->die_child
;
26447 dw_die_ref prev
= c
;
26449 while (c
->die_mark
)
26451 remove_child_with_prev (c
, prev
);
26452 /* As base types got marked, there must be at least
26453 one node other than DW_TAG_base_type. */
26454 gcc_assert (c
!= c
->die_sib
);
26458 while (c
!= die
->die_child
);
26459 gcc_assert (die
->die_child
);
26460 c
= die
->die_child
;
26461 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
26463 base_type
->die_mark
= 0;
26464 base_type
->die_sib
= c
->die_sib
;
26465 c
->die_sib
= base_type
;
26470 /* Helper function for resolve_addr, attempt to resolve
26471 one CONST_STRING, return true if successful. Similarly verify that
26472 SYMBOL_REFs refer to variables emitted in the current CU. */
26475 resolve_one_addr (rtx
*addr
)
26479 if (GET_CODE (rtl
) == CONST_STRING
)
26481 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
26482 tree t
= build_string (len
, XSTR (rtl
, 0));
26483 tree tlen
= size_int (len
- 1);
26485 = build_array_type (char_type_node
, build_index_type (tlen
));
26486 rtl
= lookup_constant_def (t
);
26487 if (!rtl
|| !MEM_P (rtl
))
26489 rtl
= XEXP (rtl
, 0);
26490 if (GET_CODE (rtl
) == SYMBOL_REF
26491 && SYMBOL_REF_DECL (rtl
)
26492 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
26494 vec_safe_push (used_rtx_array
, rtl
);
26499 if (GET_CODE (rtl
) == SYMBOL_REF
26500 && SYMBOL_REF_DECL (rtl
))
26502 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
26504 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
26507 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
26511 if (GET_CODE (rtl
) == CONST
)
26513 subrtx_ptr_iterator::array_type array
;
26514 FOR_EACH_SUBRTX_PTR (iter
, array
, &XEXP (rtl
, 0), ALL
)
26515 if (!resolve_one_addr (*iter
))
26522 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
26523 if possible, and create DW_TAG_dwarf_procedure that can be referenced
26524 from DW_OP_GNU_implicit_pointer if the string hasn't been seen yet. */
26527 string_cst_pool_decl (tree t
)
26529 rtx rtl
= output_constant_def (t
, 1);
26530 unsigned char *array
;
26531 dw_loc_descr_ref l
;
26536 if (!rtl
|| !MEM_P (rtl
))
26538 rtl
= XEXP (rtl
, 0);
26539 if (GET_CODE (rtl
) != SYMBOL_REF
26540 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
26543 decl
= SYMBOL_REF_DECL (rtl
);
26544 if (!lookup_decl_die (decl
))
26546 len
= TREE_STRING_LENGTH (t
);
26547 vec_safe_push (used_rtx_array
, rtl
);
26548 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
26549 array
= ggc_vec_alloc
<unsigned char> (len
);
26550 memcpy (array
, TREE_STRING_POINTER (t
), len
);
26551 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
26552 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
26553 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
26554 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
26555 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
26556 add_AT_loc (ref
, DW_AT_location
, l
);
26557 equate_decl_number_to_die (decl
, ref
);
26562 /* Helper function of resolve_addr_in_expr. LOC is
26563 a DW_OP_addr followed by DW_OP_stack_value, either at the start
26564 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
26565 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
26566 with DW_OP_GNU_implicit_pointer if possible
26567 and return true, if unsuccessful, return false. */
26570 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
26572 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
26573 HOST_WIDE_INT offset
= 0;
26574 dw_die_ref ref
= NULL
;
26577 if (GET_CODE (rtl
) == CONST
26578 && GET_CODE (XEXP (rtl
, 0)) == PLUS
26579 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
26581 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
26582 rtl
= XEXP (XEXP (rtl
, 0), 0);
26584 if (GET_CODE (rtl
) == CONST_STRING
)
26586 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
26587 tree t
= build_string (len
, XSTR (rtl
, 0));
26588 tree tlen
= size_int (len
- 1);
26591 = build_array_type (char_type_node
, build_index_type (tlen
));
26592 rtl
= string_cst_pool_decl (t
);
26596 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
26598 decl
= SYMBOL_REF_DECL (rtl
);
26599 if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
))
26601 ref
= lookup_decl_die (decl
);
26602 if (ref
&& (get_AT (ref
, DW_AT_location
)
26603 || get_AT (ref
, DW_AT_const_value
)))
26605 loc
->dw_loc_opc
= DW_OP_GNU_implicit_pointer
;
26606 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
26607 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
26608 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
26609 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
26610 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
26611 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
26619 /* Helper function for resolve_addr, handle one location
26620 expression, return false if at least one CONST_STRING or SYMBOL_REF in
26621 the location list couldn't be resolved. */
26624 resolve_addr_in_expr (dw_loc_descr_ref loc
)
26626 dw_loc_descr_ref keep
= NULL
;
26627 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
26628 switch (loc
->dw_loc_opc
)
26631 if (!resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
26634 || prev
->dw_loc_opc
== DW_OP_piece
26635 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
26636 && loc
->dw_loc_next
26637 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
26639 && optimize_one_addr_into_implicit_ptr (loc
))
26644 case DW_OP_GNU_addr_index
:
26645 case DW_OP_GNU_const_index
:
26646 if (loc
->dw_loc_opc
== DW_OP_GNU_addr_index
26647 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
26649 rtx rtl
= loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
;
26650 if (!resolve_one_addr (&rtl
))
26652 remove_addr_table_entry (loc
->dw_loc_oprnd1
.val_entry
);
26653 loc
->dw_loc_oprnd1
.val_entry
=
26654 add_addr_table_entry (rtl
, ate_kind_rtx
);
26657 case DW_OP_const4u
:
26658 case DW_OP_const8u
:
26660 && !resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
26663 case DW_OP_plus_uconst
:
26664 if (size_of_loc_descr (loc
)
26665 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
26667 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
26669 dw_loc_descr_ref repl
26670 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
26671 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
26672 add_loc_descr (&repl
, loc
->dw_loc_next
);
26676 case DW_OP_implicit_value
:
26677 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
26678 && !resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
))
26681 case DW_OP_GNU_implicit_pointer
:
26682 case DW_OP_GNU_parameter_ref
:
26683 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
26686 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
26689 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
26690 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
26691 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
26694 case DW_OP_GNU_const_type
:
26695 case DW_OP_GNU_regval_type
:
26696 case DW_OP_GNU_deref_type
:
26697 case DW_OP_GNU_convert
:
26698 case DW_OP_GNU_reinterpret
:
26699 while (loc
->dw_loc_next
26700 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
26702 dw_die_ref base1
, base2
;
26703 unsigned enc1
, enc2
, size1
, size2
;
26704 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
26705 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
26706 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
26707 else if (loc
->dw_loc_oprnd1
.val_class
26708 == dw_val_class_unsigned_const
)
26711 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
26712 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
26713 == dw_val_class_unsigned_const
)
26715 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
26716 gcc_assert (base1
->die_tag
== DW_TAG_base_type
26717 && base2
->die_tag
== DW_TAG_base_type
);
26718 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
26719 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
26720 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
26721 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
26723 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
26724 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
26728 /* Optimize away next DW_OP_GNU_convert after
26729 adjusting LOC's base type die reference. */
26730 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
26731 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
26732 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
26734 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
26735 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
26738 /* Don't change integer DW_OP_GNU_convert after e.g. floating
26739 point typed stack entry. */
26740 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
26741 keep
= loc
->dw_loc_next
;
26751 /* Helper function of resolve_addr. DIE had DW_AT_location of
26752 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
26753 and DW_OP_addr couldn't be resolved. resolve_addr has already
26754 removed the DW_AT_location attribute. This function attempts to
26755 add a new DW_AT_location attribute with DW_OP_GNU_implicit_pointer
26756 to it or DW_AT_const_value attribute, if possible. */
26759 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
26761 if (TREE_CODE (decl
) != VAR_DECL
26762 || lookup_decl_die (decl
) != die
26763 || DECL_EXTERNAL (decl
)
26764 || !TREE_STATIC (decl
)
26765 || DECL_INITIAL (decl
) == NULL_TREE
26766 || DECL_P (DECL_INITIAL (decl
))
26767 || get_AT (die
, DW_AT_const_value
))
26770 tree init
= DECL_INITIAL (decl
);
26771 HOST_WIDE_INT offset
= 0;
26772 /* For variables that have been optimized away and thus
26773 don't have a memory location, see if we can emit
26774 DW_AT_const_value instead. */
26775 if (tree_add_const_value_attribute (die
, init
))
26779 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
26780 and ADDR_EXPR refers to a decl that has DW_AT_location or
26781 DW_AT_const_value (but isn't addressable, otherwise
26782 resolving the original DW_OP_addr wouldn't fail), see if
26783 we can add DW_OP_GNU_implicit_pointer. */
26785 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
26786 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
26788 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
26789 init
= TREE_OPERAND (init
, 0);
26792 if (TREE_CODE (init
) != ADDR_EXPR
)
26794 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
26795 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
26796 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
26797 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
26798 && TREE_OPERAND (init
, 0) != decl
))
26801 dw_loc_descr_ref l
;
26803 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
26805 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
26808 decl
= SYMBOL_REF_DECL (rtl
);
26811 decl
= TREE_OPERAND (init
, 0);
26812 ref
= lookup_decl_die (decl
);
26814 || (!get_AT (ref
, DW_AT_location
)
26815 && !get_AT (ref
, DW_AT_const_value
)))
26817 l
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
26818 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
26819 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
26820 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
26821 add_AT_loc (die
, DW_AT_location
, l
);
26825 /* Return NULL if l is a DWARF expression, or first op that is not
26826 valid DWARF expression. */
26828 static dw_loc_descr_ref
26829 non_dwarf_expression (dw_loc_descr_ref l
)
26833 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
26835 switch (l
->dw_loc_opc
)
26838 case DW_OP_implicit_value
:
26839 case DW_OP_stack_value
:
26840 case DW_OP_GNU_implicit_pointer
:
26841 case DW_OP_GNU_parameter_ref
:
26843 case DW_OP_bit_piece
:
26848 l
= l
->dw_loc_next
;
26853 /* Return adjusted copy of EXPR:
26854 If it is empty DWARF expression, return it.
26855 If it is valid non-empty DWARF expression,
26856 return copy of EXPR with copy of DEREF appended to it.
26857 If it is DWARF expression followed by DW_OP_reg{N,x}, return
26858 copy of the DWARF expression with DW_OP_breg{N,x} <0> appended
26860 If it is DWARF expression followed by DW_OP_stack_value, return
26861 copy of the DWARF expression without anything appended.
26862 Otherwise, return NULL. */
26864 static dw_loc_descr_ref
26865 copy_deref_exprloc (dw_loc_descr_ref expr
, dw_loc_descr_ref deref
)
26871 dw_loc_descr_ref l
= non_dwarf_expression (expr
);
26872 if (l
&& l
->dw_loc_next
)
26877 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
26878 deref
= new_loc_descr ((enum dwarf_location_atom
)
26879 (DW_OP_breg0
+ (l
->dw_loc_opc
- DW_OP_reg0
)),
26882 switch (l
->dw_loc_opc
)
26885 deref
= new_loc_descr (DW_OP_bregx
,
26886 l
->dw_loc_oprnd1
.v
.val_unsigned
, 0);
26888 case DW_OP_stack_value
:
26896 deref
= new_loc_descr (deref
->dw_loc_opc
,
26897 deref
->dw_loc_oprnd1
.v
.val_int
, 0);
26899 dw_loc_descr_ref ret
= NULL
, *p
= &ret
;
26902 *p
= new_loc_descr (expr
->dw_loc_opc
, 0, 0);
26903 (*p
)->dw_loc_oprnd1
= expr
->dw_loc_oprnd1
;
26904 (*p
)->dw_loc_oprnd2
= expr
->dw_loc_oprnd2
;
26905 p
= &(*p
)->dw_loc_next
;
26906 expr
= expr
->dw_loc_next
;
26912 /* For DW_AT_string_length attribute with DW_OP_call4 reference to a variable
26913 or argument, adjust it if needed and return:
26914 -1 if the DW_AT_string_length attribute and DW_AT_{string_length_,}byte_size
26915 attribute if present should be removed
26916 0 keep the attribute as is if the referenced var or argument has
26917 only DWARF expression that covers all ranges
26918 1 if the attribute has been successfully adjusted. */
26921 optimize_string_length (dw_attr_node
*a
)
26923 dw_loc_descr_ref l
= AT_loc (a
), lv
;
26924 dw_die_ref die
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
26925 dw_attr_node
*av
= get_AT (die
, DW_AT_location
);
26927 bool non_dwarf_expr
= false;
26931 switch (AT_class (av
))
26933 case dw_val_class_loc_list
:
26934 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
26935 if (d
->expr
&& non_dwarf_expression (d
->expr
))
26936 non_dwarf_expr
= true;
26938 case dw_val_class_loc
:
26942 if (non_dwarf_expression (lv
))
26943 non_dwarf_expr
= true;
26949 /* If it is safe to keep DW_OP_call4 in, keep it. */
26950 if (!non_dwarf_expr
26951 && (l
->dw_loc_next
== NULL
|| AT_class (av
) == dw_val_class_loc
))
26954 /* If not dereferencing the DW_OP_call4 afterwards, we can just
26955 copy over the DW_AT_location attribute from die to a. */
26956 if (l
->dw_loc_next
== NULL
)
26958 a
->dw_attr_val
= av
->dw_attr_val
;
26962 dw_loc_list_ref list
, *p
;
26963 switch (AT_class (av
))
26965 case dw_val_class_loc_list
:
26968 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
26970 lv
= copy_deref_exprloc (d
->expr
, l
->dw_loc_next
);
26973 *p
= new_loc_list (lv
, d
->begin
, d
->end
, d
->section
);
26974 p
= &(*p
)->dw_loc_next
;
26979 a
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
26981 *AT_loc_list_ptr (a
) = list
;
26983 case dw_val_class_loc
:
26984 lv
= copy_deref_exprloc (AT_loc (av
), l
->dw_loc_next
);
26987 a
->dw_attr_val
.v
.val_loc
= lv
;
26990 gcc_unreachable ();
26994 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
26995 an address in .rodata section if the string literal is emitted there,
26996 or remove the containing location list or replace DW_AT_const_value
26997 with DW_AT_location and empty location expression, if it isn't found
26998 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
26999 to something that has been emitted in the current CU. */
27002 resolve_addr (dw_die_ref die
)
27006 dw_loc_list_ref
*curr
, *start
, loc
;
27008 bool remove_AT_byte_size
= false;
27010 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
27011 switch (AT_class (a
))
27013 case dw_val_class_loc_list
:
27014 start
= curr
= AT_loc_list_ptr (a
);
27017 /* The same list can be referenced more than once. See if we have
27018 already recorded the result from a previous pass. */
27020 *curr
= loc
->dw_loc_next
;
27021 else if (!loc
->resolved_addr
)
27023 /* As things stand, we do not expect or allow one die to
27024 reference a suffix of another die's location list chain.
27025 References must be identical or completely separate.
27026 There is therefore no need to cache the result of this
27027 pass on any list other than the first; doing so
27028 would lead to unnecessary writes. */
27031 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
27032 if (!resolve_addr_in_expr ((*curr
)->expr
))
27034 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
27035 dw_loc_descr_ref l
= (*curr
)->expr
;
27037 if (next
&& (*curr
)->ll_symbol
)
27039 gcc_assert (!next
->ll_symbol
);
27040 next
->ll_symbol
= (*curr
)->ll_symbol
;
27042 if (dwarf_split_debug_info
)
27043 remove_loc_list_addr_table_entries (l
);
27048 mark_base_types ((*curr
)->expr
);
27049 curr
= &(*curr
)->dw_loc_next
;
27053 loc
->resolved_addr
= 1;
27057 loc
->dw_loc_next
= *start
;
27062 remove_AT (die
, a
->dw_attr
);
27066 case dw_val_class_loc
:
27068 dw_loc_descr_ref l
= AT_loc (a
);
27069 /* Using DW_OP_call4 or DW_OP_call4 DW_OP_deref in
27070 DW_AT_string_length is only a rough approximation; unfortunately
27071 DW_AT_string_length can't be a reference to a DIE. DW_OP_call4
27072 needs a DWARF expression, while DW_AT_location of the referenced
27073 variable or argument might be any location description. */
27074 if (a
->dw_attr
== DW_AT_string_length
27076 && l
->dw_loc_opc
== DW_OP_call4
27077 && l
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
27078 && (l
->dw_loc_next
== NULL
27079 || (l
->dw_loc_next
->dw_loc_next
== NULL
27080 && (l
->dw_loc_next
->dw_loc_opc
== DW_OP_deref
27081 || l
->dw_loc_next
->dw_loc_opc
!= DW_OP_deref_size
))))
27083 switch (optimize_string_length (a
))
27086 remove_AT (die
, a
->dw_attr
);
27088 /* If we drop DW_AT_string_length, we need to drop also
27089 DW_AT_{string_length_,}byte_size. */
27090 remove_AT_byte_size
= true;
27095 /* Even if we keep the optimized DW_AT_string_length,
27096 it might have changed AT_class, so process it again. */
27101 /* For -gdwarf-2 don't attempt to optimize
27102 DW_AT_data_member_location containing
27103 DW_OP_plus_uconst - older consumers might
27104 rely on it being that op instead of a more complex,
27105 but shorter, location description. */
27106 if ((dwarf_version
> 2
27107 || a
->dw_attr
!= DW_AT_data_member_location
27109 || l
->dw_loc_opc
!= DW_OP_plus_uconst
27110 || l
->dw_loc_next
!= NULL
)
27111 && !resolve_addr_in_expr (l
))
27113 if (dwarf_split_debug_info
)
27114 remove_loc_list_addr_table_entries (l
);
27116 && l
->dw_loc_next
== NULL
27117 && l
->dw_loc_opc
== DW_OP_addr
27118 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
27119 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
27120 && a
->dw_attr
== DW_AT_location
)
27122 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
27123 remove_AT (die
, a
->dw_attr
);
27125 optimize_location_into_implicit_ptr (die
, decl
);
27128 remove_AT (die
, a
->dw_attr
);
27132 mark_base_types (l
);
27135 case dw_val_class_addr
:
27136 if (a
->dw_attr
== DW_AT_const_value
27137 && !resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
))
27139 if (AT_index (a
) != NOT_INDEXED
)
27140 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
27141 remove_AT (die
, a
->dw_attr
);
27144 if (die
->die_tag
== DW_TAG_GNU_call_site
27145 && a
->dw_attr
== DW_AT_abstract_origin
)
27147 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
27148 dw_die_ref tdie
= lookup_decl_die (tdecl
);
27151 && DECL_EXTERNAL (tdecl
)
27152 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
27153 && (cdie
= lookup_context_die (DECL_CONTEXT (tdecl
))))
27155 /* Creating a full DIE for tdecl is overly expensive and
27156 at this point even wrong when in the LTO phase
27157 as it can end up generating new type DIEs we didn't
27158 output and thus optimize_external_refs will crash. */
27159 tdie
= new_die (DW_TAG_subprogram
, cdie
, NULL_TREE
);
27160 add_AT_flag (tdie
, DW_AT_external
, 1);
27161 add_AT_flag (tdie
, DW_AT_declaration
, 1);
27162 add_linkage_attr (tdie
, tdecl
);
27163 add_name_and_src_coords_attributes (tdie
, tdecl
);
27164 equate_decl_number_to_die (tdecl
, tdie
);
27168 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
27169 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
27170 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
27174 if (AT_index (a
) != NOT_INDEXED
)
27175 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
27176 remove_AT (die
, a
->dw_attr
);
27185 if (remove_AT_byte_size
)
27186 remove_AT (die
, dwarf_version
>= 5
27187 ? DW_AT_string_length_byte_size
27188 : DW_AT_byte_size
);
27190 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
27193 /* Helper routines for optimize_location_lists.
27194 This pass tries to share identical local lists in .debug_loc
27197 /* Iteratively hash operands of LOC opcode into HSTATE. */
27200 hash_loc_operands (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
27202 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
27203 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
27205 switch (loc
->dw_loc_opc
)
27207 case DW_OP_const4u
:
27208 case DW_OP_const8u
:
27212 case DW_OP_const1u
:
27213 case DW_OP_const1s
:
27214 case DW_OP_const2u
:
27215 case DW_OP_const2s
:
27216 case DW_OP_const4s
:
27217 case DW_OP_const8s
:
27221 case DW_OP_plus_uconst
:
27257 case DW_OP_deref_size
:
27258 case DW_OP_xderef_size
:
27259 hstate
.add_object (val1
->v
.val_int
);
27266 gcc_assert (val1
->val_class
== dw_val_class_loc
);
27267 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
27268 hstate
.add_object (offset
);
27271 case DW_OP_implicit_value
:
27272 hstate
.add_object (val1
->v
.val_unsigned
);
27273 switch (val2
->val_class
)
27275 case dw_val_class_const
:
27276 hstate
.add_object (val2
->v
.val_int
);
27278 case dw_val_class_vec
:
27280 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
27281 unsigned int len
= val2
->v
.val_vec
.length
;
27283 hstate
.add_int (elt_size
);
27284 hstate
.add_int (len
);
27285 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
27288 case dw_val_class_const_double
:
27289 hstate
.add_object (val2
->v
.val_double
.low
);
27290 hstate
.add_object (val2
->v
.val_double
.high
);
27292 case dw_val_class_wide_int
:
27293 hstate
.add (val2
->v
.val_wide
->get_val (),
27294 get_full_len (*val2
->v
.val_wide
)
27295 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
27297 case dw_val_class_addr
:
27298 inchash::add_rtx (val2
->v
.val_addr
, hstate
);
27301 gcc_unreachable ();
27305 case DW_OP_bit_piece
:
27306 hstate
.add_object (val1
->v
.val_int
);
27307 hstate
.add_object (val2
->v
.val_int
);
27313 unsigned char dtprel
= 0xd1;
27314 hstate
.add_object (dtprel
);
27316 inchash::add_rtx (val1
->v
.val_addr
, hstate
);
27318 case DW_OP_GNU_addr_index
:
27319 case DW_OP_GNU_const_index
:
27323 unsigned char dtprel
= 0xd1;
27324 hstate
.add_object (dtprel
);
27326 inchash::add_rtx (val1
->val_entry
->addr
.rtl
, hstate
);
27329 case DW_OP_GNU_implicit_pointer
:
27330 hstate
.add_int (val2
->v
.val_int
);
27332 case DW_OP_GNU_entry_value
:
27333 hstate
.add_object (val1
->v
.val_loc
);
27335 case DW_OP_GNU_regval_type
:
27336 case DW_OP_GNU_deref_type
:
27338 unsigned int byte_size
27339 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
27340 unsigned int encoding
27341 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
27342 hstate
.add_object (val1
->v
.val_int
);
27343 hstate
.add_object (byte_size
);
27344 hstate
.add_object (encoding
);
27347 case DW_OP_GNU_convert
:
27348 case DW_OP_GNU_reinterpret
:
27349 if (val1
->val_class
== dw_val_class_unsigned_const
)
27351 hstate
.add_object (val1
->v
.val_unsigned
);
27355 case DW_OP_GNU_const_type
:
27357 unsigned int byte_size
27358 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
27359 unsigned int encoding
27360 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
27361 hstate
.add_object (byte_size
);
27362 hstate
.add_object (encoding
);
27363 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
27365 hstate
.add_object (val2
->val_class
);
27366 switch (val2
->val_class
)
27368 case dw_val_class_const
:
27369 hstate
.add_object (val2
->v
.val_int
);
27371 case dw_val_class_vec
:
27373 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
27374 unsigned int len
= val2
->v
.val_vec
.length
;
27376 hstate
.add_object (elt_size
);
27377 hstate
.add_object (len
);
27378 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
27381 case dw_val_class_const_double
:
27382 hstate
.add_object (val2
->v
.val_double
.low
);
27383 hstate
.add_object (val2
->v
.val_double
.high
);
27385 case dw_val_class_wide_int
:
27386 hstate
.add (val2
->v
.val_wide
->get_val (),
27387 get_full_len (*val2
->v
.val_wide
)
27388 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
27391 gcc_unreachable ();
27397 /* Other codes have no operands. */
27402 /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
27405 hash_locs (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
27407 dw_loc_descr_ref l
;
27408 bool sizes_computed
= false;
27409 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
27410 size_of_locs (loc
);
27412 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
27414 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
27415 hstate
.add_object (opc
);
27416 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
27418 size_of_locs (loc
);
27419 sizes_computed
= true;
27421 hash_loc_operands (l
, hstate
);
27425 /* Compute hash of the whole location list LIST_HEAD. */
27428 hash_loc_list (dw_loc_list_ref list_head
)
27430 dw_loc_list_ref curr
= list_head
;
27431 inchash::hash hstate
;
27433 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
27435 hstate
.add (curr
->begin
, strlen (curr
->begin
) + 1);
27436 hstate
.add (curr
->end
, strlen (curr
->end
) + 1);
27438 hstate
.add (curr
->section
, strlen (curr
->section
) + 1);
27439 hash_locs (curr
->expr
, hstate
);
27441 list_head
->hash
= hstate
.end ();
27444 /* Return true if X and Y opcodes have the same operands. */
27447 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
27449 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
27450 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
27451 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
27452 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
27454 switch (x
->dw_loc_opc
)
27456 case DW_OP_const4u
:
27457 case DW_OP_const8u
:
27461 case DW_OP_const1u
:
27462 case DW_OP_const1s
:
27463 case DW_OP_const2u
:
27464 case DW_OP_const2s
:
27465 case DW_OP_const4s
:
27466 case DW_OP_const8s
:
27470 case DW_OP_plus_uconst
:
27506 case DW_OP_deref_size
:
27507 case DW_OP_xderef_size
:
27508 return valx1
->v
.val_int
== valy1
->v
.val_int
;
27511 /* If splitting debug info, the use of DW_OP_GNU_addr_index
27512 can cause irrelevant differences in dw_loc_addr. */
27513 gcc_assert (valx1
->val_class
== dw_val_class_loc
27514 && valy1
->val_class
== dw_val_class_loc
27515 && (dwarf_split_debug_info
27516 || x
->dw_loc_addr
== y
->dw_loc_addr
));
27517 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
27518 case DW_OP_implicit_value
:
27519 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
27520 || valx2
->val_class
!= valy2
->val_class
)
27522 switch (valx2
->val_class
)
27524 case dw_val_class_const
:
27525 return valx2
->v
.val_int
== valy2
->v
.val_int
;
27526 case dw_val_class_vec
:
27527 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
27528 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
27529 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
27530 valx2
->v
.val_vec
.elt_size
27531 * valx2
->v
.val_vec
.length
) == 0;
27532 case dw_val_class_const_double
:
27533 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
27534 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
27535 case dw_val_class_wide_int
:
27536 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
27537 case dw_val_class_addr
:
27538 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
27540 gcc_unreachable ();
27543 case DW_OP_bit_piece
:
27544 return valx1
->v
.val_int
== valy1
->v
.val_int
27545 && valx2
->v
.val_int
== valy2
->v
.val_int
;
27548 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
27549 case DW_OP_GNU_addr_index
:
27550 case DW_OP_GNU_const_index
:
27552 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
27553 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
27554 return rtx_equal_p (ax1
, ay1
);
27556 case DW_OP_GNU_implicit_pointer
:
27557 return valx1
->val_class
== dw_val_class_die_ref
27558 && valx1
->val_class
== valy1
->val_class
27559 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
27560 && valx2
->v
.val_int
== valy2
->v
.val_int
;
27561 case DW_OP_GNU_entry_value
:
27562 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
27563 case DW_OP_GNU_const_type
:
27564 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
27565 || valx2
->val_class
!= valy2
->val_class
)
27567 switch (valx2
->val_class
)
27569 case dw_val_class_const
:
27570 return valx2
->v
.val_int
== valy2
->v
.val_int
;
27571 case dw_val_class_vec
:
27572 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
27573 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
27574 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
27575 valx2
->v
.val_vec
.elt_size
27576 * valx2
->v
.val_vec
.length
) == 0;
27577 case dw_val_class_const_double
:
27578 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
27579 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
27580 case dw_val_class_wide_int
:
27581 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
27583 gcc_unreachable ();
27585 case DW_OP_GNU_regval_type
:
27586 case DW_OP_GNU_deref_type
:
27587 return valx1
->v
.val_int
== valy1
->v
.val_int
27588 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
27589 case DW_OP_GNU_convert
:
27590 case DW_OP_GNU_reinterpret
:
27591 if (valx1
->val_class
!= valy1
->val_class
)
27593 if (valx1
->val_class
== dw_val_class_unsigned_const
)
27594 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
27595 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
27596 case DW_OP_GNU_parameter_ref
:
27597 return valx1
->val_class
== dw_val_class_die_ref
27598 && valx1
->val_class
== valy1
->val_class
27599 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
27601 /* Other codes have no operands. */
27606 /* Return true if DWARF location expressions X and Y are the same. */
27609 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
27611 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
27612 if (x
->dw_loc_opc
!= y
->dw_loc_opc
27613 || x
->dtprel
!= y
->dtprel
27614 || !compare_loc_operands (x
, y
))
27616 return x
== NULL
&& y
== NULL
;
27619 /* Hashtable helpers. */
27621 struct loc_list_hasher
: nofree_ptr_hash
<dw_loc_list_struct
>
27623 static inline hashval_t
hash (const dw_loc_list_struct
*);
27624 static inline bool equal (const dw_loc_list_struct
*,
27625 const dw_loc_list_struct
*);
27628 /* Return precomputed hash of location list X. */
27631 loc_list_hasher::hash (const dw_loc_list_struct
*x
)
27636 /* Return true if location lists A and B are the same. */
27639 loc_list_hasher::equal (const dw_loc_list_struct
*a
,
27640 const dw_loc_list_struct
*b
)
27644 if (a
->hash
!= b
->hash
)
27646 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
27647 if (strcmp (a
->begin
, b
->begin
) != 0
27648 || strcmp (a
->end
, b
->end
) != 0
27649 || (a
->section
== NULL
) != (b
->section
== NULL
)
27650 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
27651 || !compare_locs (a
->expr
, b
->expr
))
27653 return a
== NULL
&& b
== NULL
;
27656 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
27659 /* Recursively optimize location lists referenced from DIE
27660 children and share them whenever possible. */
27663 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type
*htab
)
27668 dw_loc_list_struct
**slot
;
27670 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
27671 if (AT_class (a
) == dw_val_class_loc_list
)
27673 dw_loc_list_ref list
= AT_loc_list (a
);
27674 /* TODO: perform some optimizations here, before hashing
27675 it and storing into the hash table. */
27676 hash_loc_list (list
);
27677 slot
= htab
->find_slot_with_hash (list
, list
->hash
, INSERT
);
27681 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
27684 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
27688 /* Recursively assign each location list a unique index into the debug_addr
27692 index_location_lists (dw_die_ref die
)
27698 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
27699 if (AT_class (a
) == dw_val_class_loc_list
)
27701 dw_loc_list_ref list
= AT_loc_list (a
);
27702 dw_loc_list_ref curr
;
27703 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
27705 /* Don't index an entry that has already been indexed
27706 or won't be output. */
27707 if (curr
->begin_entry
!= NULL
27708 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
27712 = add_addr_table_entry (xstrdup (curr
->begin
),
27717 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
27720 /* Optimize location lists referenced from DIE
27721 children and share them whenever possible. */
27724 optimize_location_lists (dw_die_ref die
)
27726 loc_list_hash_type
htab (500);
27727 optimize_location_lists_1 (die
, &htab
);
27730 /* Traverse the limbo die list, and add parent/child links. The only
27731 dies without parents that should be here are concrete instances of
27732 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
27733 For concrete instances, we can get the parent die from the abstract
27737 flush_limbo_die_list (void)
27739 limbo_die_node
*node
;
27741 /* get_context_die calls force_decl_die, which can put new DIEs on the
27742 limbo list in LTO mode when nested functions are put in a different
27743 partition than that of their parent function. */
27744 while ((node
= limbo_die_list
))
27746 dw_die_ref die
= node
->die
;
27747 limbo_die_list
= node
->next
;
27749 if (die
->die_parent
== NULL
)
27751 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
27753 if (origin
&& origin
->die_parent
)
27754 add_child_die (origin
->die_parent
, die
);
27755 else if (is_cu_die (die
))
27757 else if (seen_error ())
27758 /* It's OK to be confused by errors in the input. */
27759 add_child_die (comp_unit_die (), die
);
27762 /* In certain situations, the lexical block containing a
27763 nested function can be optimized away, which results
27764 in the nested function die being orphaned. Likewise
27765 with the return type of that nested function. Force
27766 this to be a child of the containing function.
27768 It may happen that even the containing function got fully
27769 inlined and optimized out. In that case we are lost and
27770 assign the empty child. This should not be big issue as
27771 the function is likely unreachable too. */
27772 gcc_assert (node
->created_for
);
27774 if (DECL_P (node
->created_for
))
27775 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
27776 else if (TYPE_P (node
->created_for
))
27777 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
27779 origin
= comp_unit_die ();
27781 add_child_die (origin
, die
);
27787 /* Output stuff that dwarf requires at the end of every file,
27788 and generate the DWARF-2 debugging info. */
27791 dwarf2out_finish (const char *filename
)
27793 comdat_type_node
*ctnode
;
27794 dw_die_ref main_comp_unit_die
;
27796 /* Flush out any latecomers to the limbo party. */
27797 flush_limbo_die_list ();
27799 /* We shouldn't have any symbols with delayed asm names for
27800 DIEs generated after early finish. */
27801 gcc_assert (deferred_asm_name
== NULL
);
27803 /* PCH might result in DW_AT_producer string being restored from the
27804 header compilation, so always fill it with empty string initially
27805 and overwrite only here. */
27806 dw_attr_node
*producer
= get_AT (comp_unit_die (), DW_AT_producer
);
27807 producer_string
= gen_producer_string ();
27808 producer
->dw_attr_val
.v
.val_str
->refcount
--;
27809 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
27811 gen_remaining_tmpl_value_param_die_attribute ();
27813 /* Add the name for the main input file now. We delayed this from
27814 dwarf2out_init to avoid complications with PCH.
27815 For LTO produced units use a fixed artificial name to avoid
27816 leaking tempfile names into the dwarf. */
27818 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
27820 add_name_attribute (comp_unit_die (), "<artificial>");
27821 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
27822 add_comp_dir_attribute (comp_unit_die ());
27823 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
27826 file_table
->traverse
<bool *, file_table_relative_p
> (&p
);
27828 add_comp_dir_attribute (comp_unit_die ());
27831 #if ENABLE_ASSERT_CHECKING
27833 dw_die_ref die
= comp_unit_die (), c
;
27834 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
27837 resolve_addr (comp_unit_die ());
27838 move_marked_base_types ();
27840 if (flag_eliminate_unused_debug_types
)
27841 prune_unused_types ();
27843 /* Generate separate COMDAT sections for type DIEs. */
27844 if (use_debug_types
)
27846 break_out_comdat_types (comp_unit_die ());
27848 /* Each new type_unit DIE was added to the limbo die list when created.
27849 Since these have all been added to comdat_type_list, clear the
27851 limbo_die_list
= NULL
;
27853 /* For each new comdat type unit, copy declarations for incomplete
27854 types to make the new unit self-contained (i.e., no direct
27855 references to the main compile unit). */
27856 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
27857 copy_decls_for_unworthy_types (ctnode
->root_die
);
27858 copy_decls_for_unworthy_types (comp_unit_die ());
27860 /* In the process of copying declarations from one unit to another,
27861 we may have left some declarations behind that are no longer
27862 referenced. Prune them. */
27863 prune_unused_types ();
27866 /* Generate separate CUs for each of the include files we've seen.
27867 They will go into limbo_die_list. */
27868 if (flag_eliminate_dwarf2_dups
)
27869 break_out_includes (comp_unit_die ());
27871 /* Traverse the DIE's and add sibling attributes to those DIE's that
27873 add_sibling_attributes (comp_unit_die ());
27874 limbo_die_node
*node
;
27875 for (node
= limbo_die_list
; node
; node
= node
->next
)
27876 add_sibling_attributes (node
->die
);
27877 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
27878 add_sibling_attributes (ctnode
->root_die
);
27880 /* When splitting DWARF info, we put some attributes in the
27881 skeleton compile_unit DIE that remains in the .o, while
27882 most attributes go in the DWO compile_unit_die. */
27883 if (dwarf_split_debug_info
)
27884 main_comp_unit_die
= gen_compile_unit_die (NULL
);
27886 main_comp_unit_die
= comp_unit_die ();
27888 /* Output a terminator label for the .text section. */
27889 switch_to_section (text_section
);
27890 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
27891 if (cold_text_section
)
27893 switch_to_section (cold_text_section
);
27894 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
27897 /* We can only use the low/high_pc attributes if all of the code was
27899 if (!have_multiple_function_sections
27900 || (dwarf_version
< 3 && dwarf_strict
))
27902 /* Don't add if the CU has no associated code. */
27903 if (text_section_used
)
27904 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
27905 text_end_label
, true);
27911 bool range_list_added
= false;
27913 if (text_section_used
)
27914 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
27915 text_end_label
, &range_list_added
, true);
27916 if (cold_text_section_used
)
27917 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
27918 cold_end_label
, &range_list_added
, true);
27920 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
27922 if (DECL_IGNORED_P (fde
->decl
))
27924 if (!fde
->in_std_section
)
27925 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
27926 fde
->dw_fde_end
, &range_list_added
,
27928 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
27929 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
27930 fde
->dw_fde_second_end
, &range_list_added
,
27934 if (range_list_added
)
27936 /* We need to give .debug_loc and .debug_ranges an appropriate
27937 "base address". Use zero so that these addresses become
27938 absolute. Historically, we've emitted the unexpected
27939 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
27940 Emit both to give time for other tools to adapt. */
27941 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
27942 if (! dwarf_strict
&& dwarf_version
< 4)
27943 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
27949 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
27950 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
27951 debug_line_section_label
);
27954 add_AT_macptr (comp_unit_die (),
27955 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
27956 macinfo_section_label
);
27958 if (dwarf_split_debug_info
)
27960 /* optimize_location_lists calculates the size of the lists,
27961 so index them first, and assign indices to the entries.
27962 Although optimize_location_lists will remove entries from
27963 the table, it only does so for duplicates, and therefore
27964 only reduces ref_counts to 1. */
27965 index_location_lists (comp_unit_die ());
27967 if (addr_index_table
!= NULL
)
27969 unsigned int index
= 0;
27971 ->traverse_noresize
<unsigned int *, index_addr_table_entry
>
27976 if (have_location_lists
)
27977 optimize_location_lists (comp_unit_die ());
27979 save_macinfo_strings ();
27981 if (dwarf_split_debug_info
)
27983 unsigned int index
= 0;
27985 /* Add attributes common to skeleton compile_units and
27986 type_units. Because these attributes include strings, it
27987 must be done before freezing the string table. Top-level
27988 skeleton die attrs are added when the skeleton type unit is
27989 created, so ensure it is created by this point. */
27990 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
27991 debug_str_hash
->traverse_noresize
<unsigned int *, index_string
> (&index
);
27994 /* Output all of the compilation units. We put the main one last so that
27995 the offsets are available to output_pubnames. */
27996 for (node
= limbo_die_list
; node
; node
= node
->next
)
27997 output_comp_unit (node
->die
, 0);
27999 hash_table
<comdat_type_hasher
> comdat_type_table (100);
28000 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
28002 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
28004 /* Don't output duplicate types. */
28005 if (*slot
!= HTAB_EMPTY_ENTRY
)
28008 /* Add a pointer to the line table for the main compilation unit
28009 so that the debugger can make sense of DW_AT_decl_file
28011 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
28012 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
28013 (!dwarf_split_debug_info
28014 ? debug_line_section_label
28015 : debug_skeleton_line_section_label
));
28017 output_comdat_type_unit (ctnode
);
28021 /* The AT_pubnames attribute needs to go in all skeleton dies, including
28022 both the main_cu and all skeleton TUs. Making this call unconditional
28023 would end up either adding a second copy of the AT_pubnames attribute, or
28024 requiring a special case in add_top_level_skeleton_die_attrs. */
28025 if (!dwarf_split_debug_info
)
28026 add_AT_pubnames (comp_unit_die ());
28028 if (dwarf_split_debug_info
)
28031 unsigned char checksum
[16];
28032 struct md5_ctx ctx
;
28034 /* Compute a checksum of the comp_unit to use as the dwo_id. */
28035 md5_init_ctx (&ctx
);
28037 die_checksum (comp_unit_die (), &ctx
, &mark
);
28038 unmark_all_dies (comp_unit_die ());
28039 md5_finish_ctx (&ctx
, checksum
);
28041 /* Use the first 8 bytes of the checksum as the dwo_id,
28042 and add it to both comp-unit DIEs. */
28043 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
28044 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
28046 /* Add the base offset of the ranges table to the skeleton
28048 if (ranges_table_in_use
)
28049 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
28050 ranges_section_label
);
28052 switch_to_section (debug_addr_section
);
28053 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
28054 output_addr_table ();
28057 /* Output the main compilation unit if non-empty or if .debug_macinfo
28058 or .debug_macro will be emitted. */
28059 output_comp_unit (comp_unit_die (), have_macinfo
);
28061 if (dwarf_split_debug_info
&& info_section_emitted
)
28062 output_skeleton_debug_sections (main_comp_unit_die
);
28064 /* Output the abbreviation table. */
28065 if (abbrev_die_table_in_use
!= 1)
28067 switch_to_section (debug_abbrev_section
);
28068 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
28069 output_abbrev_section ();
28072 /* Output location list section if necessary. */
28073 if (have_location_lists
)
28075 /* Output the location lists info. */
28076 switch_to_section (debug_loc_section
);
28077 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
28078 output_location_lists (comp_unit_die ());
28081 output_pubtables ();
28083 /* Output the address range information if a CU (.debug_info section)
28084 was emitted. We output an empty table even if we had no functions
28085 to put in it. This because the consumer has no way to tell the
28086 difference between an empty table that we omitted and failure to
28087 generate a table that would have contained data. */
28088 if (info_section_emitted
)
28090 switch_to_section (debug_aranges_section
);
28094 /* Output ranges section if necessary. */
28095 if (ranges_table_in_use
)
28097 switch_to_section (debug_ranges_section
);
28098 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
28102 /* Have to end the macro section. */
28105 switch_to_section (debug_macinfo_section
);
28106 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
28108 dw2_asm_output_data (1, 0, "End compilation unit");
28111 /* Output the source line correspondence table. We must do this
28112 even if there is no line information. Otherwise, on an empty
28113 translation unit, we will generate a present, but empty,
28114 .debug_info section. IRIX 6.5 `nm' will then complain when
28115 examining the file. This is done late so that any filenames
28116 used by the debug_info section are marked as 'used'. */
28117 switch_to_section (debug_line_section
);
28118 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
28119 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
28120 output_line_info (false);
28122 if (dwarf_split_debug_info
&& info_section_emitted
)
28124 switch_to_section (debug_skeleton_line_section
);
28125 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
28126 output_line_info (true);
28129 /* If we emitted any indirect strings, output the string table too. */
28130 if (debug_str_hash
|| skeleton_debug_str_hash
)
28131 output_indirect_strings ();
28134 /* Perform any cleanups needed after the early debug generation pass
28138 dwarf2out_early_finish (void)
28140 /* Walk through the list of incomplete types again, trying once more to
28141 emit full debugging info for them. */
28142 retry_incomplete_types ();
28144 /* The point here is to flush out the limbo list so that it is empty
28145 and we don't need to stream it for LTO. */
28146 flush_limbo_die_list ();
28148 gen_scheduled_generic_parms_dies ();
28149 gen_remaining_tmpl_value_param_die_attribute ();
28151 /* Add DW_AT_linkage_name for all deferred DIEs. */
28152 for (limbo_die_node
*node
= deferred_asm_name
; node
; node
= node
->next
)
28154 tree decl
= node
->created_for
;
28155 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
28156 /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
28157 ended up in deferred_asm_name before we knew it was
28158 constant and never written to disk. */
28159 && DECL_ASSEMBLER_NAME (decl
))
28161 add_linkage_attr (node
->die
, decl
);
28162 move_linkage_attr (node
->die
);
28165 deferred_asm_name
= NULL
;
28168 /* Reset all state within dwarf2out.c so that we can rerun the compiler
28169 within the same process. For use by toplev::finalize. */
28172 dwarf2out_c_finalize (void)
28174 last_var_location_insn
= NULL
;
28175 cached_next_real_insn
= NULL
;
28176 used_rtx_array
= NULL
;
28177 incomplete_types
= NULL
;
28178 decl_scope_table
= NULL
;
28179 debug_info_section
= NULL
;
28180 debug_skeleton_info_section
= NULL
;
28181 debug_abbrev_section
= NULL
;
28182 debug_skeleton_abbrev_section
= NULL
;
28183 debug_aranges_section
= NULL
;
28184 debug_addr_section
= NULL
;
28185 debug_macinfo_section
= NULL
;
28186 debug_line_section
= NULL
;
28187 debug_skeleton_line_section
= NULL
;
28188 debug_loc_section
= NULL
;
28189 debug_pubnames_section
= NULL
;
28190 debug_pubtypes_section
= NULL
;
28191 debug_str_section
= NULL
;
28192 debug_str_dwo_section
= NULL
;
28193 debug_str_offsets_section
= NULL
;
28194 debug_ranges_section
= NULL
;
28195 debug_frame_section
= NULL
;
28197 debug_str_hash
= NULL
;
28198 skeleton_debug_str_hash
= NULL
;
28199 dw2_string_counter
= 0;
28200 have_multiple_function_sections
= false;
28201 text_section_used
= false;
28202 cold_text_section_used
= false;
28203 cold_text_section
= NULL
;
28204 current_unit_personality
= NULL
;
28206 next_die_offset
= 0;
28207 single_comp_unit_die
= NULL
;
28208 comdat_type_list
= NULL
;
28209 limbo_die_list
= NULL
;
28211 decl_die_table
= NULL
;
28212 common_block_die_table
= NULL
;
28213 decl_loc_table
= NULL
;
28214 call_arg_locations
= NULL
;
28215 call_arg_loc_last
= NULL
;
28216 call_site_count
= -1;
28217 tail_call_site_count
= -1;
28218 cached_dw_loc_list_table
= NULL
;
28219 abbrev_die_table
= NULL
;
28220 abbrev_die_table_allocated
= 0;
28221 abbrev_die_table_in_use
= 0;
28222 delete dwarf_proc_stack_usage_map
;
28223 dwarf_proc_stack_usage_map
= NULL
;
28224 line_info_label_num
= 0;
28225 cur_line_info_table
= NULL
;
28226 text_section_line_info
= NULL
;
28227 cold_text_section_line_info
= NULL
;
28228 separate_line_info
= NULL
;
28229 info_section_emitted
= false;
28230 pubname_table
= NULL
;
28231 pubtype_table
= NULL
;
28232 macinfo_table
= NULL
;
28233 ranges_table
= NULL
;
28234 ranges_table_allocated
= 0;
28235 ranges_table_in_use
= 0;
28236 ranges_by_label
= 0;
28237 ranges_by_label_allocated
= 0;
28238 ranges_by_label_in_use
= 0;
28239 have_location_lists
= false;
28242 last_emitted_file
= NULL
;
28244 tmpl_value_parm_die_table
= NULL
;
28245 generic_type_instances
= NULL
;
28246 frame_pointer_fb_offset
= 0;
28247 frame_pointer_fb_offset_valid
= false;
28248 base_types
.release ();
28249 XDELETEVEC (producer_string
);
28250 producer_string
= NULL
;
28253 #include "gt-dwarf2out.h"